]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - super0.c
imsm: fix num_domains
[thirdparty/mdadm.git] / super0.c
index 99aa3d885be595f507ea130f5aa9f7890264b9b7..3f02ed403435bcaf4c5196e931539627c7ba8495 100644 (file)
--- a/super0.c
+++ b/super0.c
@@ -93,7 +93,7 @@ static void examine_super0(struct supertype *st, char *homehost)
        char *c;
 
        printf("          Magic : %08x\n", sb->md_magic);
-       printf("        Version : %02d.%02d.%02d\n", sb->major_version, sb->minor_version,
+       printf("        Version : %d.%02d.%02d\n", sb->major_version, sb->minor_version,
               sb->patch_version);
        if (sb->minor_version >= 90) {
                printf("           UUID : %08x:%08x:%08x:%08x", sb->set_uuid0, sb->set_uuid1,
@@ -188,10 +188,9 @@ static void examine_super0(struct supertype *st, char *homehost)
                printf("         Layout : %s\n", c?c:"-unknown-");
        }
        if (sb->level == 10) {
-               printf("         Layout : near=%d, %s=%d\n",
-                      sb->layout&255,
-                      (sb->layout&0x10000)?"offset":"far",
-                      (sb->layout>>8)&255);
+               printf("         Layout :");
+               print_r10_layout(sb->layout);
+               printf("\n");
        }
        switch(sb->level) {
        case 0:
@@ -233,7 +232,7 @@ static void examine_super0(struct supertype *st, char *homehost)
        }
 }
 
-static void brief_examine_super0(struct supertype *st)
+static void brief_examine_super0(struct supertype *st, int verbose)
 {
        mdp_super_t *sb = st->sb;
        char *c=map_num(pers, sb->level);
@@ -241,14 +240,18 @@ static void brief_examine_super0(struct supertype *st)
 
        sprintf(devname, "/dev/md%d", sb->md_minor);
 
-       printf("ARRAY %s level=%s num-devices=%d UUID=",
-              devname,
-              c?c:"-unknown-", sb->raid_disks);
+       if (verbose) {
+               printf("ARRAY %s level=%s num-devices=%d",
+                      devname,
+                      c?c:"-unknown-", sb->raid_disks);
+       } else
+               printf("ARRAY %s", devname);
+
        if (sb->minor_version >= 90)
-               printf("%08x:%08x:%08x:%08x", sb->set_uuid0, sb->set_uuid1,
+               printf(" UUID=%08x:%08x:%08x:%08x", sb->set_uuid0, sb->set_uuid1,
                       sb->set_uuid2, sb->set_uuid3);
        else
-               printf("%08x", sb->set_uuid0);
+               printf(" UUID=%08x", sb->set_uuid0);
        printf("\n");
 }
 
@@ -301,18 +304,6 @@ static void brief_detail_super0(struct supertype *st)
        else
                printf("%08x", sb->set_uuid0);
 }
-
-static void export_detail_super0(struct supertype *st)
-{
-       mdp_super_t *sb = st->sb;
-       printf("MD_UUID=");
-       if (sb->minor_version >= 90)
-               printf("%08x:%08x:%08x:%08x", sb->set_uuid0, sb->set_uuid1,
-                      sb->set_uuid2, sb->set_uuid3);
-       else
-               printf("%08x", sb->set_uuid0);
-       printf("\n");
-}
 #endif
 
 static int match_home0(struct supertype *st, char *homehost)
@@ -558,7 +549,11 @@ static int init_super0(struct supertype *st, mdu_array_info_t *info,
        mdp_super_t *sb;
        int spares;
 
-       posix_memalign((void**)&sb, 512, MD_SB_BYTES + sizeof(bitmap_super_t));
+       if (posix_memalign((void**)&sb, 4096,
+                          MD_SB_BYTES + ROUND_UP(sizeof(bitmap_super_t), 4096)) != 0) {
+               fprintf(stderr, Name ": %s could not allocate superblock\n", __func__);
+               return 0;
+       }
        memset(sb, 0, MD_SB_BYTES + sizeof(bitmap_super_t));
 
        st->sb = sb;
@@ -637,7 +632,7 @@ struct devinfo {
 
 #ifndef MDASSEMBLE
 /* Add a device to the superblock being created */
-static void add_to_super0(struct supertype *st, mdu_disk_info_t *dinfo,
+static int add_to_super0(struct supertype *st, mdu_disk_info_t *dinfo,
                          int fd, char *devname)
 {
        mdp_super_t *sb = st->sb;
@@ -662,6 +657,8 @@ static void add_to_super0(struct supertype *st, mdu_disk_info_t *dinfo,
        di->disk = *dinfo;
        di->next = NULL;
        *dip = di;
+
+       return 0;
 }
 #endif
 
@@ -690,8 +687,8 @@ static int store_super0(struct supertype *st, int fd)
        if (super->state & (1<<MD_SB_BITMAP_PRESENT)) {
                struct bitmap_super_s * bm = (struct bitmap_super_s*)(super+1);
                if (__le32_to_cpu(bm->magic) == BITMAP_MAGIC)
-                       if (write(fd, bm, ROUND_UP(sizeof(*bm),512)) != 
-                           ROUND_UP(sizeof(*bm),512))
+                       if (write(fd, bm, ROUND_UP(sizeof(*bm),4096)) != 
+                           ROUND_UP(sizeof(*bm),4096))
                            return 5;
        }
 
@@ -751,8 +748,13 @@ static int compare_super0(struct supertype *st, struct supertype *tst)
        if (second->md_magic != MD_SB_MAGIC)
                return 1;
        if (!first) {
-               posix_memalign((void**)&first, 512, 
-                              MD_SB_BYTES + sizeof(struct bitmap_super_s));
+               if (posix_memalign((void**)&first, 4096,
+                            MD_SB_BYTES + 
+                            ROUND_UP(sizeof(struct bitmap_super_s), 4096)) != 0) {
+                       fprintf(stderr, Name
+                               ": %s could not allocate superblock\n", __func__);
+                       return 1;
+               }
                memcpy(first, second, MD_SB_BYTES + sizeof(struct bitmap_super_s));
                st->sb = first;
                return 0;
@@ -821,7 +823,13 @@ static int load_super0(struct supertype *st, int fd, char *devname)
                return 1;
        }
 
-       posix_memalign((void**)&super, 512, MD_SB_BYTES + sizeof(bitmap_super_t)+512);
+       if (posix_memalign((void**)&super, 4096,
+                          MD_SB_BYTES +
+                          ROUND_UP(sizeof(bitmap_super_t), 4096)) != 0) {
+               fprintf(stderr, Name
+                       ": %s could not allocate superblock\n", __func__);
+               return 1;
+       }
 
        if (read(fd, super, sizeof(*super)) != MD_SB_BYTES) {
                if (devname)
@@ -865,8 +873,8 @@ static int load_super0(struct supertype *st, int fd, char *devname)
         * valid.  If it doesn't clear the bit.  An --assemble --force
         * should get that written out.
         */
-       if (read(fd, super+1, ROUND_UP(sizeof(struct bitmap_super_s),512))
-           != ROUND_UP(sizeof(struct bitmap_super_s),512))
+       if (read(fd, super+1, ROUND_UP(sizeof(struct bitmap_super_s),4096))
+           != ROUND_UP(sizeof(struct bitmap_super_s),4096))
                goto no_bitmap;
 
        uuid_from_super0(st, uuid);
@@ -893,6 +901,9 @@ static struct supertype *match_metadata_desc0(char *arg)
        st->minor_version = 90;
        st->max_devs = MD_SB_DISKS;
        st->sb = NULL;
+       /* we sometimes get 00.90 */
+       while (arg[0] == '0' && arg[1] == '0')
+               arg++;
        if (strcmp(arg, "0") == 0 ||
            strcmp(arg, "0.90") == 0 ||
            strcmp(arg, "default") == 0 ||
@@ -994,8 +1005,8 @@ static int write_bitmap0(struct supertype *st, int fd)
        int rv = 0;
 
        int towrite, n;
-       char abuf[4096+512];
-       char *buf = (char*)(((long)(abuf+512))&~511UL);
+       char abuf[4096+4096];
+       char *buf = (char*)(((long)(abuf+4096))&~4095L);
 
        if (!get_dev_size(fd, NULL, &dsize))
                return 1;
@@ -1053,7 +1064,7 @@ static int validate_geometry0(struct supertype *st, int level,
                return 0;
        if (raiddisks > MD_SB_DISKS)
                return 0;
-       if (size > (0x7fffffffULL<<10))
+       if (size > (0x7fffffffULL<<9))
                return 0;
        if (!subdev)
                return 1;
@@ -1074,7 +1085,7 @@ static int validate_geometry0(struct supertype *st, int level,
 
        if (ldsize < MD_RESERVED_SECTORS * 512)
                return 0;
-       if (size > (0x7fffffffULL<<10))
+       if (size > (0x7fffffffULL<<9))
                return 0;
        *freesize = MD_NEW_SIZE_SECTORS(ldsize >> 9);
        return 1;
@@ -1088,7 +1099,6 @@ struct superswitch super0 = {
        .export_examine_super = export_examine_super0,
        .detail_super = detail_super0,
        .brief_detail_super = brief_detail_super0,
-       .export_detail_super = export_detail_super0,
        .write_init_super = write_init_super0,
        .validate_geometry = validate_geometry0,
        .add_to_super = add_to_super0,
@@ -1107,4 +1117,5 @@ struct superswitch super0 = {
        .locate_bitmap = locate_bitmap0,
        .write_bitmap = write_bitmap0,
        .free_super = free_super0,
+       .name = "0.90",
 };