__u8 num_members; /* number of member disks */
__u8 reserved[3];
__u32 filler[7]; /* expansion area */
+#define IMSM_ORD_REBUILD (1 << 24)
__u32 disk_ord_tbl[1]; /* disk_ord_tbl[num_members],
- top byte special */
+ * top byte contains some flags
+ */
} __attribute__ ((packed));
struct imsm_vol {
{
__u32 *ord_tbl = &map->disk_ord_tbl[slot];
- /* top byte is 'special' */
+ /* top byte identifies disk under rebuild
+ * why not just use the USABLE bit... oh well.
+ */
return __le32_to_cpu(*ord_tbl & ~(0xff << 24));
}
+static __u32 get_imsm_ord_tbl_ent(struct imsm_dev *dev, int slot)
+{
+ struct imsm_map *map;
+
+ if (dev->vol.migr_state)
+ map = get_imsm_map(dev, 0);
+ else
+ map = get_imsm_map(dev, 1);
+
+ return map->disk_ord_tbl[slot];
+}
+
static int get_imsm_raid_level(struct imsm_map *map)
{
if (map->raid_level == 1) {
this = malloc(sizeof(*this));
memset(this, 0, sizeof(*this));
this->next = rest;
- rest = this;
this->array.level = get_imsm_raid_level(map);
this->array.raid_disks = map->num_members;
this->array.chunk_size = __le16_to_cpu(map->blocks_per_strip) << 9;
this->array.state = !vol->dirty;
this->container_member = i;
- if (map->map_state == IMSM_T_STATE_UNINITIALIZED || dev->vol.dirty)
+ if (map->map_state == IMSM_T_STATE_UNINITIALIZED ||
+ dev->vol.dirty || dev->vol.migr_state)
this->resync_start = 0;
else
this->resync_start = ~0ULL;
struct mdinfo *info_d;
struct dl *d;
int idx;
+ int skip;
__u32 s;
+ __u32 ord;
+ skip = 0;
idx = get_imsm_disk_idx(map, slot);
+ ord = get_imsm_ord_tbl_ent(dev, slot);
for (d = super->disks; d ; d = d->next)
if (d->index == idx)
break;
if (d == NULL)
- break; /* shouldn't this be continue ?? */
+ skip = 1;
+
+ s = d ? __le32_to_cpu(d->disk.status) : 0;
+ if (s & FAILED_DISK)
+ skip = 1;
+ if (!(s & USABLE_DISK))
+ skip = 1;
+ if (ord & IMSM_ORD_REBUILD)
+ skip = 1;
+
+ /*
+ * if we skip some disks the array will be assmebled degraded;
+ * reset resync start to avoid a dirty-degraded situation
+ *
+ * FIXME handle dirty degraded
+ */
+ if (skip && !dev->vol.dirty)
+ this->resync_start = ~0ULL;
+ if (skip)
+ continue;
info_d = malloc(sizeof(*info_d));
- if (!info_d)
- break; /* ditto ?? */
+ if (!info_d) {
+ fprintf(stderr, Name ": failed to allocate disk"
+ " for volume %s\n", (char *) dev->volume);
+ free(this);
+ this = rest;
+ break;
+ }
memset(info_d, 0, sizeof(*info_d));
info_d->next = this->devs;
this->devs = info_d;
- s = __le32_to_cpu(d->disk.status);
-
info_d->disk.number = d->index;
info_d->disk.major = d->major;
info_d->disk.minor = d->minor;
info_d->disk.raid_disk = slot;
- info_d->disk.state = s & CONFIGURED_DISK ? (1 << MD_DISK_ACTIVE) : 0;
- info_d->disk.state |= s & FAILED_DISK ? (1 << MD_DISK_FAULTY) : 0;
- info_d->disk.state |= s & USABLE_DISK ? (1 << MD_DISK_SYNC) : 0;
this->array.working_disks++;
if (d->devname)
strcpy(info_d->name, d->devname);
}
+ rest = this;
}
return rest;
disk = get_imsm_disk(super, idx);
if (__le32_to_cpu(disk->status) & FAILED_DISK)
failed++;
+ else if (!(__le32_to_cpu(disk->status) & USABLE_DISK))
+ failed++;
}
return failed;
}
-static void imsm_set_array_state(struct active_array *a, int consistent)
+static int imsm_set_array_state(struct active_array *a, int consistent)
{
int inst = a->info.container_member;
struct intel_super *super = a->container->sb;
if (consistent && !dev->vol.dirty &&
(dev->vol.migr_state || map_state != IMSM_T_STATE_NORMAL))
a->resync_start = 0ULL;
+ if (consistent == 2 && a->resync_start != ~0ULL)
+ consistent = 0;
if (a->resync_start == ~0ULL) {
/* complete recovery or initial resync */
dev->vol.dirty = dirty;
super->updates_pending++;
}
+ return consistent;
}
static void imsm_set_disk(struct active_array *a, int n, int state)
int j;
int found;
__u32 array_start;
+ __u32 status;
struct dl *dl;
for (dl = super->disks; dl; dl = dl->next) {
if (d)
continue;
+ /* skip marked in use or failed drives */
+ status = __le32_to_cpu(dl->disk.status);
+ if (status & FAILED_DISK || status & CONFIGURED_DISK) {
+ dprintf("%x:%x status ( %s%s)\n",
+ dl->major, dl->minor,
+ status & FAILED_DISK ? "failed " : "",
+ status & CONFIGURED_DISK ? "configured " : "");
+ continue;
+ }
+
/* Does this unused device have the requisite free space?
* We need a->info.component_size sectors
*/