]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - super-intel.c
imsm: fix imsm_map.num_domains
[thirdparty/mdadm.git] / super-intel.c
index 541365965448819c8db4dd696212f64a858e7fab..9b8cea21957fabf44048c85cee242365fc71b7fd 100644 (file)
@@ -679,7 +679,7 @@ static void examine_super_imsm(struct supertype *st, char *homehost)
        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,
@@ -705,7 +705,7 @@ static void examine_super_imsm(struct supertype *st, char *homehost)
 
                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++) {
@@ -728,27 +728,42 @@ static void brief_examine_super_imsm(struct supertype *st)
                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);
 }
 
@@ -757,7 +772,7 @@ static void brief_detail_super_imsm(struct supertype *st)
        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);
 }
 
@@ -1731,7 +1746,8 @@ static int parse_raid_devices(struct intel_super *super)
                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;
@@ -2175,13 +2191,12 @@ static __u16 info_to_blocks_per_strip(mdu_array_info_t *info)
        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;
 }
@@ -2258,6 +2273,7 @@ static int init_super_imsm_volume(struct supertype *st, mdu_array_info_t *info,
        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 "
@@ -2333,7 +2349,6 @@ static int init_super_imsm_volume(struct supertype *st, mdu_array_info_t *info,
        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;
@@ -2348,8 +2363,10 @@ static int init_super_imsm_volume(struct supertype *st, mdu_array_info_t *info,
                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++) {
@@ -4367,7 +4384,9 @@ static void imsm_prepare_update(struct supertype *st,
                        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;
        }
 }
@@ -4429,6 +4448,7 @@ struct superswitch super_imsm = {
 #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,