int fd;
int extent_cnt;
struct extent *e; /* for determining freespace @ create */
+ int raiddisk; /* slot to fill in autolayout */
} *disks;
struct dl *add; /* list of disks to add while mdmon active */
struct dl *missing; /* disks removed while we weren't looking */
printf(" Family : %08x\n", __le32_to_cpu(mpb->family_num));
printf(" Generation : %08x\n", __le32_to_cpu(mpb->generation_num));
getinfo_super_imsm(st, &info);
- fname_from_uuid(st, &info, nbuf,'-');
+ fname_from_uuid(st, &info, nbuf, ':');
printf(" UUID : %s\n", nbuf + 5);
sum = __le32_to_cpu(mpb->check_sum);
printf(" Checksum : %08x %s\n", sum,
super->current_vol = i;
getinfo_super_imsm(st, &info);
- fname_from_uuid(st, &info, nbuf, '-');
+ fname_from_uuid(st, &info, nbuf, ':');
print_imsm_dev(dev, nbuf + 5, super->disks->index);
}
for (i = 0; i < mpb->num_disks; i++) {
return;
getinfo_super_imsm(st, &info);
- fname_from_uuid(st, &info, nbuf,'-');
+ fname_from_uuid(st, &info, nbuf, ':');
printf("ARRAY metadata=imsm auto=md UUID=%s\n", nbuf + 5);
for (i = 0; i < super->anchor->num_raid_devs; i++) {
struct imsm_dev *dev = get_imsm_dev(super, i);
super->current_vol = i;
getinfo_super_imsm(st, &info);
- fname_from_uuid(st, &info, nbuf1,'-');
+ fname_from_uuid(st, &info, nbuf1, ':');
printf("ARRAY /dev/md/%.16s container=%s\n"
" member=%d auto=mdp UUID=%s\n",
dev->volume, nbuf + 5, i, nbuf1 + 5);
}
}
+static void export_examine_super_imsm(struct supertype *st)
+{
+ struct intel_super *super = st->sb;
+ struct imsm_super *mpb = super->anchor;
+ struct mdinfo info;
+ char nbuf[64];
+
+ getinfo_super_imsm(st, &info);
+ fname_from_uuid(st, &info, nbuf, ':');
+ printf("MD_METADATA=imsm\n");
+ printf("MD_LEVEL=container\n");
+ printf("MD_UUID=%s\n", nbuf+5);
+ printf("MD_DEVICES=%u\n", mpb->num_disks);
+}
+
static void detail_super_imsm(struct supertype *st, char *homehost)
{
struct mdinfo info;
char nbuf[64];
getinfo_super_imsm(st, &info);
- fname_from_uuid(st, &info, nbuf,'-');
+ fname_from_uuid(st, &info, nbuf, ':');
printf("\n UUID : %s\n", nbuf + 5);
}
struct mdinfo info;
char nbuf[64];
getinfo_super_imsm(st, &info);
- fname_from_uuid(st, &info, nbuf,'-');
+ fname_from_uuid(st, &info, nbuf, ':');
printf(" UUID=%s", nbuf + 5);
}
imsm_orom_has_raid1e(orom) ? " raid1e" : "",
imsm_orom_has_raid10(orom) ? " raid10" : "",
imsm_orom_has_raid5(orom) ? " raid5" : "");
+ printf(" Chunk Sizes :%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
+ imsm_orom_has_chunk(orom, 2) ? " 2k" : "",
+ imsm_orom_has_chunk(orom, 4) ? " 4k" : "",
+ imsm_orom_has_chunk(orom, 8) ? " 8k" : "",
+ imsm_orom_has_chunk(orom, 16) ? " 16k" : "",
+ imsm_orom_has_chunk(orom, 32) ? " 32k" : "",
+ imsm_orom_has_chunk(orom, 64) ? " 64k" : "",
+ imsm_orom_has_chunk(orom, 128) ? " 128k" : "",
+ imsm_orom_has_chunk(orom, 256) ? " 256k" : "",
+ imsm_orom_has_chunk(orom, 512) ? " 512k" : "",
+ imsm_orom_has_chunk(orom, 1024*1) ? " 1M" : "",
+ imsm_orom_has_chunk(orom, 1024*2) ? " 2M" : "",
+ imsm_orom_has_chunk(orom, 1024*4) ? " 4M" : "",
+ imsm_orom_has_chunk(orom, 1024*8) ? " 8M" : "",
+ imsm_orom_has_chunk(orom, 1024*16) ? " 16M" : "",
+ imsm_orom_has_chunk(orom, 1024*32) ? " 32M" : "",
+ imsm_orom_has_chunk(orom, 1024*64) ? " 64M" : "");
printf(" Max Disks : %d\n", orom->tds);
printf(" Max Volumes : %d\n", orom->vpa);
printf(" I/O Controller : %s\n", hba_path);
struct intel_super *super = st->sb;
struct imsm_dev *dev = get_imsm_dev(super, super->current_vol);
struct imsm_map *map = get_imsm_map(dev, 0);
+ struct dl *dl;
+ for (dl = super->disks; dl; dl = dl->next)
+ if (dl->raiddisk == info->disk.raid_disk)
+ break;
info->container_member = super->current_vol;
info->array.raid_disks = map->num_members;
info->array.level = get_imsm_raid_level(map);
info->disk.major = 0;
info->disk.minor = 0;
+ if (dl) {
+ info->disk.major = dl->major;
+ info->disk.minor = dl->minor;
+ }
info->data_offset = __le32_to_cpu(map->pba_of_lba0);
info->component_size = __le32_to_cpu(map->blocks_per_member);
int rv;
int rsp_len;
int len;
- char *c, *rsp_buf;
+ char *dest;
+ char *src;
+ char *rsp_buf;
+ int i;
memset(scsi_serial, 0, sizeof(scsi_serial));
return rv;
}
- /* trim leading whitespace */
rsp_len = scsi_serial[3];
if (!rsp_len) {
if (devname)
return 2;
}
rsp_buf = (char *) &scsi_serial[4];
- c = rsp_buf;
- while (isspace(*c))
- c++;
- /* truncate len to the end of rsp_buf if necessary */
- if (c + MAX_RAID_SERIAL_LEN > rsp_buf + rsp_len)
- len = rsp_len - (c - rsp_buf);
- else
+ /* trim all whitespace and non-printable characters and convert
+ * ':' to ';'
+ */
+ for (i = 0, dest = rsp_buf; i < rsp_len; i++) {
+ src = &rsp_buf[i];
+ if (*src > 0x20) {
+ /* ':' is reserved for use in placeholder serial
+ * numbers for missing disks
+ */
+ if (*src == ':')
+ *dest++ = ';';
+ else
+ *dest++ = *src;
+ }
+ }
+ len = dest - rsp_buf;
+ dest = rsp_buf;
+
+ /* truncate leading characters */
+ if (len > MAX_RAID_SERIAL_LEN) {
+ dest += len - MAX_RAID_SERIAL_LEN;
len = MAX_RAID_SERIAL_LEN;
+ }
- /* initialize the buffer and copy rsp_buf characters */
memset(serial, 0, MAX_RAID_SERIAL_LEN);
- memcpy(serial, c, len);
-
- /* trim trailing whitespace starting with the last character copied */
- c = (char *) &serial[len - 1];
- while (isspace(*c) || *c == '\0')
- *c-- = '\0';
+ memcpy(serial, dest, len);
return 0;
}
if (posix_memalign(&buf, 512, len) != 0)
return 1;
- memcpy(buf, super->buf, len);
+ memcpy(buf, super->buf, super->len);
+ memset(buf + super->len, 0, len - super->len);
free(super->buf);
super->buf = buf;
super->len = len;
sectors = mpb_sectors(anchor) - 1;
free(anchor);
if (!sectors) {
+ check_sum = __gen_imsm_checksum(super->anchor);
+ if (check_sum != __le32_to_cpu(super->anchor->check_sum)) {
+ if (devname)
+ fprintf(stderr,
+ Name ": IMSM checksum %x != %x on %s\n",
+ check_sum,
+ __le32_to_cpu(super->anchor->check_sum),
+ devname);
+ return 2;
+ }
+
rc = load_imsm_disk(fd, super, devname, 0);
if (rc == 0)
rc = parse_raid_devices(super);
Name ": IMSM checksum %x != %x on %s\n",
check_sum, __le32_to_cpu(super->anchor->check_sum),
devname);
- return 2;
+ return 3;
}
/* FIXME the BBM log is disk specific so we cannot use this global
char nm[20];
int dfd;
int rv;
+ int devnum = fd2devnum(fd);
+ int retry;
+ enum sysfs_read_flags flags;
+
+ flags = GET_LEVEL|GET_VERSION|GET_DEVS|GET_STATE;
+ if (mdmon_running(devnum))
+ flags |= SKIP_GONE_DEVS;
- /* check if this disk is a member of an active array */
- sra = sysfs_read(fd, 0, GET_LEVEL|GET_VERSION|GET_DEVS|GET_STATE);
+ /* check if 'fd' an opened container */
+ sra = sysfs_read(fd, 0, flags);
if (!sra)
return 1;
return 2;
}
rv = load_imsm_mpb(dfd, super, NULL);
+
+ /* retry the load if we might have raced against mdmon */
+ if (rv == 3 && mdmon_running(devnum))
+ for (retry = 0; retry < 3; retry++) {
+ usleep(3000);
+ rv = load_imsm_mpb(dfd, super, NULL);
+ if (rv != 3)
+ break;
+ }
if (!keep_fd)
close(dfd);
if (rv == 0) {
}
} else {
free_imsm(super);
- return 2;
+ return rv;
}
}
}
*sbp = super;
- st->container_dev = fd2devnum(fd);
+ st->container_dev = devnum;
if (st->ss == NULL) {
st->ss = &super_imsm;
st->minor_version = 0;
return info->chunk_size >> 9;
}
-static __u32 info_to_num_data_stripes(mdu_array_info_t *info)
+static __u32 info_to_num_data_stripes(mdu_array_info_t *info, int num_domains)
{
__u32 num_stripes;
num_stripes = (info->size * 2) / info_to_blocks_per_strip(info);
- if (info->level == 1)
- num_stripes /= 2;
+ num_stripes /= num_domains;
return num_stripes;
}
int i;
unsigned long long array_blocks;
size_t size_old, size_new;
+ __u32 num_data_stripes;
if (super->orom && mpb->num_raid_devs >= super->orom->vpa) {
fprintf(stderr, Name": This imsm-container already has the "
map->pba_of_lba0 = __cpu_to_le32(super->create_offset);
map->blocks_per_member = __cpu_to_le32(info_to_blocks_per_member(info));
map->blocks_per_strip = __cpu_to_le16(info_to_blocks_per_strip(info));
- map->num_data_stripes = __cpu_to_le32(info_to_num_data_stripes(info));
map->failed_disk_num = ~0;
map->map_state = info->level ? IMSM_T_STATE_UNINITIALIZED :
IMSM_T_STATE_NORMAL;
map->num_domains = info->raid_disks / 2;
} else {
map->raid_level = info->level;
- map->num_domains = !!map->raid_level;
+ map->num_domains = 1;
}
+ num_data_stripes = info_to_num_data_stripes(info, map->num_domains);
+ map->num_data_stripes = __cpu_to_le32(num_data_stripes);
map->num_members = info->raid_disks;
for (i = 0; i < map->num_members; i++) {
return 1;
}
- for (dl = super->disks; dl ; dl = dl->next)
- if (dl->major == dk->major &&
- dl->minor == dk->minor)
- break;
+ if (fd == -1) {
+ /* we're doing autolayout so grab the pre-marked (in
+ * validate_geometry) raid_disk
+ */
+ for (dl = super->disks; dl; dl = dl->next)
+ if (dl->raiddisk == dk->raid_disk)
+ break;
+ } else {
+ for (dl = super->disks; dl ; dl = dl->next)
+ if (dl->major == dk->major &&
+ dl->minor == dk->minor)
+ break;
+ }
if (!dl) {
fprintf(stderr, Name ": %s is not a member of the same container\n", devname);
int i, j;
int start_extent;
unsigned long long pos;
- unsigned long long start;
+ unsigned long long start = 0;
unsigned long long maxsize;
unsigned long reserve;
return 1;
}
+static int reserve_space(struct supertype *st, int raiddisks,
+ unsigned long long size, int chunk,
+ unsigned long long *freesize)
+{
+ struct intel_super *super = st->sb;
+ struct imsm_super *mpb = super->anchor;
+ struct dl *dl;
+ int i;
+ int extent_cnt;
+ struct extent *e;
+ unsigned long long maxsize;
+ unsigned long long minsize;
+ int cnt;
+ int used;
+
+ /* find the largest common start free region of the possible disks */
+ used = 0;
+ extent_cnt = 0;
+ cnt = 0;
+ for (dl = super->disks; dl; dl = dl->next) {
+ dl->raiddisk = -1;
+
+ if (dl->index >= 0)
+ used++;
+
+ /* don't activate new spares if we are orom constrained
+ * and there is already a volume active in the container
+ */
+ if (super->orom && dl->index < 0 && mpb->num_raid_devs)
+ continue;
+
+ e = get_extents(super, dl);
+ if (!e)
+ continue;
+ for (i = 1; e[i-1].size; i++)
+ ;
+ dl->e = e;
+ dl->extent_cnt = i;
+ extent_cnt += i;
+ cnt++;
+ }
+
+ maxsize = merge_extents(super, extent_cnt);
+ minsize = size;
+ if (size == 0)
+ minsize = chunk;
+
+ if (cnt < raiddisks ||
+ (super->orom && used && used != raiddisks) ||
+ maxsize < minsize) {
+ fprintf(stderr, Name ": not enough devices with space to create array.\n");
+ return 0; /* No enough free spaces large enough */
+ }
+
+ if (size == 0) {
+ size = maxsize;
+ if (chunk) {
+ size /= chunk;
+ size *= chunk;
+ }
+ }
+
+ cnt = 0;
+ for (dl = super->disks; dl; dl = dl->next)
+ if (dl->e)
+ dl->raiddisk = cnt++;
+
+ *freesize = size;
+
+ return 1;
+}
+
static int validate_geometry_imsm(struct supertype *st, int level, int layout,
int raiddisks, int chunk, unsigned long long size,
char *dev, unsigned long long *freesize,
if (!dev) {
if (st->sb && freesize) {
- /* Should do auto-layout here */
- fprintf(stderr, Name ": IMSM does not support auto-layout yet\n");
- return 0;
+ /* we are being asked to automatically layout a
+ * new volume based on the current contents of
+ * the container. If the the parameters can be
+ * satisfied reserve_space will record the disks,
+ * start offset, and size of the volume to be
+ * created. add_to_super and getinfo_super
+ * detect when autolayout is in progress.
+ */
+ return reserve_space(st, raiddisks, size, chunk, freesize);
}
return 1;
}
free(super->next_buf);
super->next_len = buf_len;
- if (posix_memalign(&super->next_buf, 512, buf_len) != 0)
+ if (posix_memalign(&super->next_buf, 512, buf_len) == 0)
+ memset(super->next_buf, 0, buf_len);
+ else
super->next_buf = NULL;
}
}
#ifndef MDASSEMBLE
.examine_super = examine_super_imsm,
.brief_examine_super = brief_examine_super_imsm,
+ .export_examine_super = export_examine_super_imsm,
.detail_super = detail_super_imsm,
.brief_detail_super = brief_detail_super_imsm,
.write_init_super = write_init_super_imsm,