summaryrefslogtreecommitdiffstats
path: root/super-intel.c
diff options
context:
space:
mode:
Diffstat (limited to 'super-intel.c')
-rw-r--r--super-intel.c333
1 files changed, 297 insertions, 36 deletions
diff --git a/super-intel.c b/super-intel.c
index d6d8b09..daf811f 100644
--- a/super-intel.c
+++ b/super-intel.c
@@ -282,6 +282,8 @@ struct extent {
enum imsm_update_type {
update_activate_spare,
update_create_array,
+ update_kill_array,
+ update_rename_array,
update_add_disk,
};
@@ -303,6 +305,17 @@ struct imsm_update_create_array {
struct imsm_dev dev;
};
+struct imsm_update_kill_array {
+ enum imsm_update_type type;
+ int dev_idx;
+};
+
+struct imsm_update_rename_array {
+ enum imsm_update_type type;
+ __u8 name[MAX_RAID_SERIAL_LEN];
+ int dev_idx;
+};
+
struct imsm_update_add_disk {
enum imsm_update_type type;
};
@@ -639,7 +652,7 @@ static __u64 blocks_per_migr_unit(struct imsm_dev *dev);
static void print_imsm_dev(struct imsm_dev *dev, char *uuid, int disk_idx)
{
__u64 sz;
- int slot;
+ int slot, i;
struct imsm_map *map = get_imsm_map(dev, 0);
__u32 ord;
@@ -648,6 +661,12 @@ static void print_imsm_dev(struct imsm_dev *dev, char *uuid, int disk_idx)
printf(" UUID : %s\n", uuid);
printf(" RAID Level : %d\n", get_imsm_raid_level(map));
printf(" Members : %d\n", map->num_members);
+ printf(" Slots : [");
+ for (i = 0; i < map->num_members; i++) {
+ ord = get_imsm_ord_tbl_ent(dev, i);
+ printf("%s", ord & IMSM_ORD_REBUILD ? "_" : "U");
+ }
+ printf("]\n");
slot = get_imsm_disk_slot(map, disk_idx);
if (slot >= 0) {
ord = get_imsm_ord_tbl_ent(dev, slot);
@@ -2747,14 +2766,9 @@ static int load_super_imsm_all(struct supertype *st, int fd, void **sbp,
int retry;
int err = 0;
int i;
- enum sysfs_read_flags flags;
-
- flags = GET_LEVEL|GET_VERSION|GET_DEVS|GET_STATE;
- if (mdmon_running(devnum))
- flags |= SKIP_GONE_DEVS;
/* check if 'fd' an opened container */
- sra = sysfs_read(fd, 0, flags);
+ sra = sysfs_read(fd, 0, GET_LEVEL|GET_VERSION|GET_DEVS|GET_STATE);
if (!sra)
return 1;
@@ -2812,11 +2826,20 @@ static int load_super_imsm_all(struct supertype *st, int fd, void **sbp,
}
if (st->subarray[0]) {
- if (atoi(st->subarray) <= super->anchor->num_raid_devs)
- super->current_vol = atoi(st->subarray);
+ unsigned long val;
+ char *ep;
+
+ err = 1;
+ val = strtoul(st->subarray, &ep, 10);
+ if (*ep != '\0') {
+ free_imsm(super);
+ goto error;
+ }
+
+ if (val < super->anchor->num_raid_devs)
+ super->current_vol = val;
else {
free_imsm(super);
- err = 1;
goto error;
}
}
@@ -2883,8 +2906,17 @@ static int load_super_imsm(struct supertype *st, int fd, char *devname)
}
if (st->subarray[0]) {
- if (atoi(st->subarray) <= super->anchor->num_raid_devs)
- super->current_vol = atoi(st->subarray);
+ unsigned long val;
+ char *ep;
+
+ val = strtoul(st->subarray, &ep, 10);
+ if (*ep != '\0') {
+ free_imsm(super);
+ return 1;
+ }
+
+ if (val < super->anchor->num_raid_devs)
+ super->current_vol = val;
else {
free_imsm(super);
return 1;
@@ -2974,6 +3006,30 @@ static void imsm_update_version_info(struct intel_super *super)
}
}
+static int check_name(struct intel_super *super, char *name, int quiet)
+{
+ struct imsm_super *mpb = super->anchor;
+ char *reason = NULL;
+ int i;
+
+ if (strlen(name) > MAX_RAID_SERIAL_LEN)
+ reason = "must be 16 characters or less";
+
+ for (i = 0; i < mpb->num_raid_devs; i++) {
+ struct imsm_dev *dev = get_imsm_dev(super, i);
+
+ if (strncmp((char *) dev->volume, name, MAX_RAID_SERIAL_LEN) == 0) {
+ reason = "already exists";
+ break;
+ }
+ }
+
+ if (reason && !quiet)
+ fprintf(stderr, Name ": imsm volume name %s\n", reason);
+
+ return !reason;
+}
+
static int init_super_imsm_volume(struct supertype *st, mdu_array_info_t *info,
unsigned long long size, char *name,
char *homehost, int *uuid)
@@ -3025,16 +3081,8 @@ static int init_super_imsm_volume(struct supertype *st, mdu_array_info_t *info,
if (super->current_vol == 0)
mpb->num_disks = 0;
- for (i = 0; i < super->current_vol; i++) {
- dev = get_imsm_dev(super, i);
- if (strncmp((char *) dev->volume, name,
- MAX_RAID_SERIAL_LEN) == 0) {
- fprintf(stderr, Name": '%s' is already defined for this container\n",
- name);
- return 0;
- }
- }
-
+ if (!check_name(super, name, 0))
+ return 0;
sprintf(st->subarray, "%d", idx);
dv = malloc(sizeof(*dv));
if (!dv) {
@@ -4066,6 +4114,140 @@ static int validate_geometry_imsm(struct supertype *st, int level, int layout,
close(cfd);
return 0;
}
+
+static int default_chunk_imsm(struct supertype *st)
+{
+ struct intel_super *super = st->sb;
+
+ if (!super->orom)
+ return 0;
+
+ return imsm_orom_default_chunk(super->orom);
+}
+
+static void handle_missing(struct intel_super *super, struct imsm_dev *dev);
+
+static int kill_subarray_imsm(struct supertype *st)
+{
+ /* remove the subarray currently referenced by ->current_vol */
+ __u8 i;
+ struct intel_dev **dp;
+ struct intel_super *super = st->sb;
+ __u8 current_vol = super->current_vol;
+ struct imsm_super *mpb = super->anchor;
+
+ if (super->current_vol < 0)
+ return 2;
+ super->current_vol = -1; /* invalidate subarray cursor */
+
+ /* block deletions that would change the uuid of active subarrays
+ *
+ * FIXME when immutable ids are available, but note that we'll
+ * also need to fixup the invalidated/active subarray indexes in
+ * mdstat
+ */
+ for (i = 0; i < mpb->num_raid_devs; i++) {
+ char subarray[4];
+
+ if (i < current_vol)
+ continue;
+ sprintf(subarray, "%u", i);
+ if (is_subarray_active(subarray, st->devname)) {
+ fprintf(stderr,
+ Name ": deleting subarray-%d would change the UUID of active subarray-%d, aborting\n",
+ current_vol, i);
+
+ return 2;
+ }
+ }
+
+ if (st->update_tail) {
+ struct imsm_update_kill_array *u = malloc(sizeof(*u));
+
+ if (!u)
+ return 2;
+ u->type = update_kill_array;
+ u->dev_idx = current_vol;
+ append_metadata_update(st, u, sizeof(*u));
+
+ return 0;
+ }
+
+ for (dp = &super->devlist; *dp;)
+ if ((*dp)->index == current_vol) {
+ *dp = (*dp)->next;
+ } else {
+ handle_missing(super, (*dp)->dev);
+ if ((*dp)->index > current_vol)
+ (*dp)->index--;
+ dp = &(*dp)->next;
+ }
+
+ /* no more raid devices, all active components are now spares,
+ * but of course failed are still failed
+ */
+ if (--mpb->num_raid_devs == 0) {
+ struct dl *d;
+
+ for (d = super->disks; d; d = d->next)
+ if (d->index > -2) {
+ d->index = -1;
+ d->disk.status = SPARE_DISK;
+ }
+ }
+
+ super->updates_pending++;
+
+ return 0;
+}
+
+static int update_subarray_imsm(struct supertype *st, char *update, mddev_ident_t ident)
+{
+ /* update the subarray currently referenced by ->current_vol */
+ struct intel_super *super = st->sb;
+ struct imsm_super *mpb = super->anchor;
+
+ if (super->current_vol < 0)
+ return 2;
+
+ if (strcmp(update, "name") == 0) {
+ char *name = ident->name;
+
+ if (is_subarray_active(st->subarray, st->devname)) {
+ fprintf(stderr,
+ Name ": Unable to update name of active subarray\n");
+ return 2;
+ }
+
+ if (!check_name(super, name, 0))
+ return 2;
+
+ if (st->update_tail) {
+ struct imsm_update_rename_array *u = malloc(sizeof(*u));
+
+ if (!u)
+ return 2;
+ u->type = update_rename_array;
+ u->dev_idx = super->current_vol;
+ snprintf((char *) u->name, MAX_RAID_SERIAL_LEN, "%s", name);
+ append_metadata_update(st, u, sizeof(*u));
+ } else {
+ struct imsm_dev *dev;
+ int i;
+
+ dev = get_imsm_dev(super, super->current_vol);
+ snprintf((char *) dev->volume, MAX_RAID_SERIAL_LEN, "%s", name);
+ for (i = 0; i < mpb->num_raid_devs; i++) {
+ dev = get_imsm_dev(super, i);
+ handle_missing(super, dev);
+ }
+ super->updates_pending++;
+ }
+ } else
+ return 2;
+
+ return 0;
+}
#endif /* MDASSEMBLE */
static int is_rebuilding(struct imsm_dev *dev)
@@ -4415,6 +4597,24 @@ static void mark_missing(struct imsm_dev *dev, struct imsm_disk *disk, int idx)
memmove(&disk->serial[0], &disk->serial[1], MAX_RAID_SERIAL_LEN - 1);
}
+static void handle_missing(struct intel_super *super, struct imsm_dev *dev)
+{
+ __u8 map_state;
+ struct dl *dl;
+ int failed;
+
+ if (!super->missing)
+ return;
+ failed = imsm_count_failed(super, dev);
+ map_state = imsm_check_degraded(super, dev, failed);
+
+ dprintf("imsm: mark missing\n");
+ end_migration(dev, map_state);
+ for (dl = super->missing; dl; dl = dl->next)
+ mark_missing(dev, &dl->disk, dl->index);
+ super->updates_pending++;
+}
+
/* Handle dirty -> clean transititions and resync. Degraded and rebuild
* states are handled in imsm_set_disk() with one exception, when a
* resync is stopped due to a new failure this routine will set the
@@ -4431,15 +4631,8 @@ static int imsm_set_array_state(struct active_array *a, int consistent)
__u32 blocks_per_unit;
/* before we activate this array handle any missing disks */
- if (consistent == 2 && super->missing) {
- struct dl *dl;
-
- dprintf("imsm: mark missing\n");
- end_migration(dev, map_state);
- for (dl = super->missing; dl; dl = dl->next)
- mark_missing(dev, &dl->disk, dl->index);
- super->updates_pending++;
- }
+ if (consistent == 2)
+ handle_missing(super, dev);
if (consistent == 2 &&
(!is_resync_complete(&a->info) ||
@@ -4456,6 +4649,7 @@ static int imsm_set_array_state(struct active_array *a, int consistent)
dprintf("imsm: mark resync done\n");
end_migration(dev, map_state);
super->updates_pending++;
+ a->last_checkpoint = 0;
}
} else if (!is_resyncing(dev) && !failed) {
/* mark the start of the init process if nothing is failed */
@@ -4469,14 +4663,11 @@ static int imsm_set_array_state(struct active_array *a, int consistent)
/* check if we can update curr_migr_unit from resync_start, recovery_start */
blocks_per_unit = blocks_per_migr_unit(dev);
- if (blocks_per_unit && failed <= 1) {
+ if (blocks_per_unit) {
__u32 units32;
__u64 units;
- if (migr_type(dev) == MIGR_REBUILD)
- units = min_recovery_start(&a->info) / blocks_per_unit;
- else
- units = a->info.resync_start / blocks_per_unit;
+ units = a->last_checkpoint / blocks_per_unit;
units32 = units;
/* check that we did not overflow 32-bits, and that
@@ -4548,17 +4739,20 @@ static void imsm_set_disk(struct active_array *a, int n, int state)
map = get_imsm_map(dev, 0);
map->failed_disk_num = ~0;
super->updates_pending++;
+ a->last_checkpoint = 0;
} else if (map_state == IMSM_T_STATE_DEGRADED &&
map->map_state != map_state &&
!dev->vol.migr_state) {
dprintf("imsm: mark degraded\n");
map->map_state = map_state;
super->updates_pending++;
+ a->last_checkpoint = 0;
} else if (map_state == IMSM_T_STATE_FAILED &&
map->map_state != map_state) {
dprintf("imsm: mark failed\n");
end_migration(dev, map_state);
super->updates_pending++;
+ a->last_checkpoint = 0;
}
}
@@ -5135,6 +5329,70 @@ static void imsm_process_update(struct supertype *st,
}
break;
}
+ case update_kill_array: {
+ struct imsm_update_kill_array *u = (void *) update->buf;
+ int victim = u->dev_idx;
+ struct active_array *a;
+ struct intel_dev **dp;
+ struct imsm_dev *dev;
+
+ /* sanity check that we are not affecting the uuid of
+ * active arrays, or deleting an active array
+ *
+ * FIXME when immutable ids are available, but note that
+ * we'll also need to fixup the invalidated/active
+ * subarray indexes in mdstat
+ */
+ for (a = st->arrays; a; a = a->next)
+ if (a->info.container_member >= victim)
+ break;
+ /* by definition if mdmon is running at least one array
+ * is active in the container, so checking
+ * mpb->num_raid_devs is just extra paranoia
+ */
+ dev = get_imsm_dev(super, victim);
+ if (a || !dev || mpb->num_raid_devs == 1) {
+ dprintf("failed to delete subarray-%d\n", victim);
+ break;
+ }
+
+ for (dp = &super->devlist; *dp;)
+ if ((*dp)->index == super->current_vol) {
+ *dp = (*dp)->next;
+ } else {
+ if ((*dp)->index > victim)
+ (*dp)->index--;
+ dp = &(*dp)->next;
+ }
+ mpb->num_raid_devs--;
+ super->updates_pending++;
+ break;
+ }
+ case update_rename_array: {
+ struct imsm_update_rename_array *u = (void *) update->buf;
+ char name[MAX_RAID_SERIAL_LEN+1];
+ int target = u->dev_idx;
+ struct active_array *a;
+ struct imsm_dev *dev;
+
+ /* sanity check that we are not affecting the uuid of
+ * an active array
+ */
+ snprintf(name, MAX_RAID_SERIAL_LEN, "%s", (char *) u->name);
+ name[MAX_RAID_SERIAL_LEN] = '\0';
+ for (a = st->arrays; a; a = a->next)
+ if (a->info.container_member == target)
+ break;
+ dev = get_imsm_dev(super, u->dev_idx);
+ if (a || !dev || !check_name(super, name, 1)) {
+ dprintf("failed to rename subarray-%d\n", target);
+ break;
+ }
+
+ snprintf((char *) dev->volume, MAX_RAID_SERIAL_LEN, name);
+ super->updates_pending++;
+ break;
+ }
case update_add_disk:
/* we may be able to repair some arrays if disks are
@@ -5308,8 +5566,11 @@ struct superswitch super_imsm = {
.brief_detail_super = brief_detail_super_imsm,
.write_init_super = write_init_super_imsm,
.validate_geometry = validate_geometry_imsm,
+ .default_chunk = default_chunk_imsm,
.add_to_super = add_to_super_imsm,
.detail_platform = detail_platform_imsm,
+ .kill_subarray = kill_subarray_imsm,
+ .update_subarray = update_subarray_imsm,
#endif
.match_home = match_home_imsm,
.uuid_from_super= uuid_from_super_imsm,