]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Grow: allow --grow --continue to work for native metadata.
authorNeilBrown <neilb@suse.de>
Tue, 9 Oct 2012 02:54:59 +0000 (13:54 +1100)
committerNeilBrown <neilb@suse.de>
Thu, 18 Oct 2012 04:40:01 +0000 (15:40 +1100)
As it was the code would crash due to "mdstat" being NULL.
Code is now more sane, but hasn't been tested on an array that
needs to grow.

Signed-off-by: NeilBrown <neilb@suse.de>
Grow.c

diff --git a/Grow.c b/Grow.c
index 7a46e78094ad62ec2803104af5dfa401771d58a7..dbd4ae53ead0ca709279d25292c22a5b33663af6 100644 (file)
--- a/Grow.c
+++ b/Grow.c
@@ -3993,15 +3993,49 @@ int Grow_continue_command(char *devname, int fd,
        }
        dprintf("Grow continue is run for ");
        if (st->ss->external == 0) {
+               int d;
                dprintf("native array (%s)\n", devname);
-               if (ioctl(fd, GET_ARRAY_INFO, &array) < 0) {
+               if (ioctl(fd, GET_ARRAY_INFO, &array.array) < 0) {
                        fprintf(stderr, Name ": %s is not an active md array -"
                                " aborting\n", devname);
                        ret_val = 1;
                        goto Grow_continue_command_exit;
                }
                content = &array;
-               sysfs_init(content, fd, st->devnum);
+               /* Need to load a superblock.
+                * FIXME we should really get what we need from
+                * sysfs
+                */
+               for (d = 0; d < MAX_DISKS; d++) {
+                       mdu_disk_info_t disk;
+                       char *dv;
+                       int err;
+                       disk.number = d;
+                       if (ioctl(fd, GET_DISK_INFO, &disk) < 0)
+                               continue;
+                       if (disk.major == 0 && disk.minor == 0)
+                               continue;
+                       if ((disk.state & (1 << MD_DISK_ACTIVE)) == 0)
+                               continue;
+                       dv = map_dev(disk.major, disk.minor, 1);
+                       if (!dv)
+                               continue;
+                       fd2 = dev_open(dv, O_RDONLY);
+                       if (fd2 < 0)
+                               continue;
+                       err = st->ss->load_super(st, fd2, NULL);
+                       close(fd2);
+                       if (err)
+                               continue;
+                       break;
+               }
+               if (d == MAX_DISKS) {
+                       fprintf(stderr, Name ": Unable to load metadata for %s\n",
+                               devname);
+                       ret_val = 1;
+                       goto Grow_continue_command_exit;
+               }
+               st->ss->getinfo_super(st, content, NULL);
        } else {
                int container_dev;
 
@@ -4114,8 +4148,7 @@ int Grow_continue_command(char *devname, int fd,
        /* verify that array under reshape is started from
         * correct position
         */
-       if (verify_reshape_position(content,
-                                   map_name(pers, mdstat->level)) < 0) {
+       if (verify_reshape_position(content, content->array.level) < 0) {
                ret_val = 1;
                goto Grow_continue_command_exit;
        }