]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - super0.c
Fix --grow --add for linear arrays.
[thirdparty/mdadm.git] / super0.c
index 2408c25b971e0b633cf382b34b846cc59a211741..30da8aa22c95dc28d5caf844ef972cff3019fb4d 100644 (file)
--- a/super0.c
+++ b/super0.c
@@ -110,6 +110,9 @@ static void examine_super0(void *sbv, char *homehost)
        } else
                printf("           UUID : %08x\n", sb->set_uuid0);
 
+       if (sb->not_persistent)
+               printf("           Eedk : not persistent\n");
+
        atime = sb->ctime;
        printf("  Creation Time : %.24s\n", ctime(&atime));
        c=map_num(pers, sb->level);
@@ -277,6 +280,18 @@ static void brief_detail_super0(void *sbv)
        else
                printf("%08x", sb->set_uuid0);
 }
+
+static void export_super0(void *sbv)
+{
+       mdp_super_t *sb = sbv;
+       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(void *sbv, char *homehost)
@@ -444,7 +459,16 @@ static int update_super0(struct mdinfo *info, void *sbv, char *update,
                        rv = 1;
                }
        }
-       if (strcmp(update, "grow") == 0) {
+       if (strcmp(update, "linear-grow-new") == 0) {
+               memset(&sb->disks[info->disk.number], 0, sizeof(sb->disks[0]));
+               sb->disks[info->disk.number].number = info->disk.number;
+               sb->disks[info->disk.number].major = info->disk.major;
+               sb->disks[info->disk.number].minor = info->disk.minor;
+               sb->disks[info->disk.number].raid_disk = info->disk.raid_disk;
+               sb->disks[info->disk.number].state = info->disk.state;
+               sb->this_disk = sb->disks[info->disk.number];
+       }
+       if (strcmp(update, "linear-grow-update") == 0) {
                sb->raid_disks = info->array.raid_disks;
                sb->nr_disks = info->array.nr_disks;
                sb->active_disks = info->array.active_disks;
@@ -455,8 +479,6 @@ static int update_super0(struct mdinfo *info, void *sbv, char *update,
                sb->disks[info->disk.number].minor = info->disk.minor;
                sb->disks[info->disk.number].raid_disk = info->disk.raid_disk;
                sb->disks[info->disk.number].state = info->disk.state;
-               if (sb->this_disk.number == info->disk.number)
-                       sb->this_disk = sb->disks[info->disk.number];
        }
        if (strcmp(update, "resync") == 0) {
                /* make sure resync happens */
@@ -505,11 +527,11 @@ static int update_super0(struct mdinfo *info, void *sbv, char *update,
 
 
 static int init_super0(struct supertype *st, void **sbp, mdu_array_info_t *info,
-                      unsigned long long size, char *ignored_name, char *homehost)
+                      unsigned long long size, char *ignored_name, char *homehost,
+                      int *uuid)
 {
        mdp_super_t *sb = malloc(MD_SB_BYTES + sizeof(bitmap_super_t));
        int spares;
-       int rfd;
        memset(sb, 0, MD_SB_BYTES + sizeof(bitmap_super_t));
 
        if (info->major_version == -1) {
@@ -525,14 +547,11 @@ static int init_super0(struct supertype *st, void **sbp, mdu_array_info_t *info,
                return 0;
        }
 
-       rfd = open("/dev/urandom", O_RDONLY);
        sb->md_magic = MD_SB_MAGIC;
        sb->major_version = 0;
        sb->minor_version = 90;
        sb->patch_version = 0;
        sb->gvalid_words = 0; /* ignored */
-       if (rfd < 0 || read(rfd, &sb->set_uuid0, 4) != 4)
-               sb->set_uuid0 = random();
        sb->ctime = time(0);
        sb->level = info->level;
        if (size != info->size)
@@ -542,13 +561,23 @@ static int init_super0(struct supertype *st, void **sbp, mdu_array_info_t *info,
        sb->raid_disks = info->raid_disks;
        sb->md_minor = info->md_minor;
        sb->not_persistent = 0;
-       if (rfd < 0 || read(rfd, &sb->set_uuid1, 12) != 12) {
-               sb->set_uuid1 = random();
-               sb->set_uuid2 = random();
-               sb->set_uuid3 = random();
+       if (uuid) {
+               sb->set_uuid0 = uuid[0];
+               sb->set_uuid1 = uuid[1];
+               sb->set_uuid2 = uuid[2];
+               sb->set_uuid3 = uuid[3];
+       } else {
+               int rfd = open("/dev/urandom", O_RDONLY);
+               if (rfd < 0 || read(rfd, &sb->set_uuid0, 4) != 4)
+                       sb->set_uuid0 = random();
+               if (rfd < 0 || read(rfd, &sb->set_uuid1, 12) != 12) {
+                       sb->set_uuid1 = random();
+                       sb->set_uuid2 = random();
+                       sb->set_uuid3 = random();
+               }
+               if (rfd >= 0)
+                       close(rfd);
        }
-       if (rfd >= 0)
-               close(rfd);
        if (homehost) {
                char buf[20];
                char *hash = sha1_buffer(homehost,
@@ -588,20 +617,12 @@ static void add_to_super0(void *sbv, mdu_disk_info_t *dinfo)
 
 static int store_super0(struct supertype *st, int fd, void *sbv)
 {
-       unsigned long size;
        unsigned long long dsize;
        unsigned long long offset;
        mdp_super_t *super = sbv;
-    
-#ifdef BLKGETSIZE64
-       if (ioctl(fd, BLKGETSIZE64, &dsize) != 0)
-#endif
-       {
-               if (ioctl(fd, BLKGETSIZE, &size))
-                       return 1;
-               else
-                       dsize = ((unsigned long long)size)<<9;
-       }
+
+       if (!get_dev_size(fd, NULL, &dsize))
+               return 1;
 
        if (dsize < MD_RESERVED_SECTORS*2*512)
                return 2;
@@ -701,30 +722,20 @@ static int load_super0(struct supertype *st, int fd, void **sbp, char *devname)
         *  1 on cannot get superblock
         *  2 on superblock meaningless
         */
-       unsigned long size;
        unsigned long long dsize;
        unsigned long long offset;
        mdp_super_t *super;
        int uuid[4];
        struct bitmap_super_s *bsb;
     
-#ifdef BLKGETSIZE64
-       if (ioctl(fd, BLKGETSIZE64, &dsize) != 0)
-#endif
-       {
-               if (ioctl(fd, BLKGETSIZE, &size)) {
-                       if (devname)
-                               fprintf(stderr, Name ": cannot find device size for %s: %s\n",
-                                       devname, strerror(errno));
-                       return 1;
-               } else
-                       dsize = size << 9;
-       }
+       if (!get_dev_size(fd, devname, &dsize))
+               return 1;
 
-       if (dsize < MD_RESERVED_SECTORS*2) {
+       if (dsize < MD_RESERVED_SECTORS*512 * 2) {
                if (devname)
-                       fprintf(stderr, Name ": %s is too small for md: size is %ld sectors.\n",
-                               devname, size);
+                       fprintf(stderr, Name
+                           ": %s is too small for md: size is %llu sectors.\n",
+                               devname, dsize);
                return 1;
        }
 
@@ -877,19 +888,12 @@ static int add_internal_bitmap0(struct supertype *st, void *sbv, int *chunkp,
 void locate_bitmap0(struct supertype *st, int fd, void *sbv)
 {
        unsigned long long dsize;
-       unsigned long size;
        unsigned long long offset;
-#ifdef BLKGETSIZE64
-       if (ioctl(fd, BLKGETSIZE64, &dsize) != 0)
-#endif
-       {
-               if (ioctl(fd, BLKGETSIZE, &size))
-                       return;
-               else
-                       dsize = ((unsigned long long)size)<<9;
-       }
 
-       if (dsize < MD_RESERVED_SECTORS*2)
+       if (!get_dev_size(fd, NULL, &dsize))
+               return;
+
+       if (dsize < MD_RESERVED_SECTORS*512 * 2)
                return;
 
        offset = MD_NEW_SIZE_SECTORS(dsize>>9);
@@ -903,7 +907,6 @@ void locate_bitmap0(struct supertype *st, int fd, void *sbv)
 
 int write_bitmap0(struct supertype *st, int fd, void *sbv)
 {
-       unsigned long size;
        unsigned long long dsize;
        unsigned long long offset;
        mdp_super_t *sb = sbv;
@@ -913,17 +916,11 @@ int write_bitmap0(struct supertype *st, int fd, void *sbv)
        int towrite, n;
        char buf[4096];
 
-#ifdef BLKGETSIZE64
-       if (ioctl(fd, BLKGETSIZE64, &dsize) != 0)
-#endif
-       {
-               if (ioctl(fd, BLKGETSIZE, &size))
-                       return 1;
-               else
-                       dsize = ((unsigned long long)size)<<9;
-       }
+       if (!get_dev_size(fd, NULL, &dsize))
+               return 1;
+
 
-       if (dsize < MD_RESERVED_SECTORS*2)
+       if (dsize < MD_RESERVED_SECTORS*512 * 2)
        return -1;
 
        offset = MD_NEW_SIZE_SECTORS(dsize>>9);
@@ -962,6 +959,7 @@ struct superswitch super0 = {
        .brief_examine_super = brief_examine_super0,
        .detail_super = detail_super0,
        .brief_detail_super = brief_detail_super0,
+       .export_super = export_super0,
 #endif
        .match_home = match_home0,
        .uuid_from_super = uuid_from_super0,