]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Grow.c
Incremental: Use md_array_active() where applicable
[thirdparty/mdadm.git] / Grow.c
diff --git a/Grow.c b/Grow.c
index af8d5205848007dbd5fca12ce2e7dc85bb90d3e6..c6967ed1c9c7715a6b2c4ff5e1c05747c0261137 100755 (executable)
--- a/Grow.c
+++ b/Grow.c
@@ -288,16 +288,9 @@ int Grow_addbitmap(char *devname, int fd, struct context *c, struct shape *s)
        struct supertype *st;
        char *subarray = NULL;
        int major = BITMAP_MAJOR_HI;
-       int vers = md_get_version(fd);
        unsigned long long bitmapsize, array_size;
        struct mdinfo *mdi;
 
-       if (vers < 9003) {
-               major = BITMAP_MAJOR_HOSTENDIAN;
-               pr_err("Warning - bitmaps created on this kernel are not portable\n"
-                       "  between different architectures.  Consider upgrading the Linux kernel.\n");
-       }
-
        /*
         * We only ever get called if s->bitmap_file is != NULL, so this check
         * is just here to quiet down static code checkers.
@@ -455,7 +448,10 @@ int Grow_addbitmap(char *devname, int fd, struct context *c, struct shape *s)
                }
                if (offset_setable) {
                        st->ss->getinfo_super(st, mdi, NULL);
-                       sysfs_init(mdi, fd, NULL);
+                       if (sysfs_init(mdi, fd, NULL)) {
+                               pr_err("failed to intialize sysfs.\n");
+                               free(mdi);
+                       }
                        rv = sysfs_set_num_signed(mdi, NULL, "bitmap/location",
                                                  mdi->bitmap_offset);
                        free(mdi);
@@ -1834,7 +1830,7 @@ int Grow_reshape(char *devname, int fd,
         * pre-requisite spare devices (mdmon owns final validation)
         */
        if (st->ss->external) {
-               int rv;
+               int retval;
 
                if (subarray) {
                        container = st->container_devnm;
@@ -1852,9 +1848,9 @@ int Grow_reshape(char *devname, int fd,
                        return 1;
                }
 
-               rv = st->ss->load_container(st, cfd, NULL);
+               retval = st->ss->load_container(st, cfd, NULL);
 
-               if (rv) {
+               if (retval) {
                        pr_err("Cannot read superblock for %s\n",
                                devname);
                        free(subarray);
@@ -1982,15 +1978,7 @@ int Grow_reshape(char *devname, int fd,
                 * understands '0' to mean 'max'.
                 */
                min_csize = 0;
-               rv = 0;
                for (mdi = sra->devs; mdi; mdi = mdi->next) {
-                       if (sysfs_set_num(sra, mdi, "size",
-                                         s->size == MAX_SIZE ? 0 : s->size) < 0) {
-                               /* Probably kernel refusing to let us
-                                * reduce the size - not an error.
-                                */
-                               break;
-                       }
                        if (array.not_persistent == 0 &&
                            array.major_version == 0 &&
                            get_linux_version() < 3001000) {
@@ -2005,10 +1993,6 @@ int Grow_reshape(char *devname, int fd,
                                }
                        }
                }
-               if (rv) {
-                       pr_err("Cannot set size on array members.\n");
-                       goto size_change_error;
-               }
                if (min_csize && s->size > min_csize) {
                        pr_err("Cannot safely make this array use more than 2TB per device on this kernel.\n");
                        rv = 1;
@@ -2161,7 +2145,11 @@ size_change_error:
 
        memset(&info, 0, sizeof(info));
        info.array = array;
-       sysfs_init(&info, fd, NULL);
+       if (sysfs_init(&info, fd, NULL)) {
+               pr_err("failed to intialize sysfs.\n");
+               rv = 1;
+               goto release;
+       }
        strcpy(info.text_version, sra->text_version);
        info.component_size = s->size*2;
        info.new_level = s->level;
@@ -2882,7 +2870,11 @@ static int impose_level(int fd, int level, char *devname, int verbose)
        char *c;
        struct mdu_array_info_s array;
        struct mdinfo info;
-       sysfs_init(&info, fd, NULL);
+
+       if (sysfs_init(&info, fd, NULL)) {
+               pr_err("failed to intialize sysfs.\n");
+               return  1;
+       }
 
        md_get_array_info(fd, &array);
        if (level == 0 &&
@@ -3190,7 +3182,12 @@ static int reshape_array(char *container, int fd, char *devname,
                struct mdinfo *d;
 
                if (info2) {
-                       sysfs_init(info2, fd, st->devnm);
+                       if (sysfs_init(info2, fd, st->devnm)) {
+                               pr_err("unable to initialize sysfs for %s",
+                                      st->devnm);
+                               free(info2);
+                               goto release;
+                       }
                        /* When increasing number of devices, we need to set
                         * new raid_disks before adding these, or they might
                         * be rejected.
@@ -3789,7 +3786,12 @@ int reshape_container(char *container, char *devname,
                }
                strcpy(last_devnm, mdstat->devnm);
 
-               sysfs_init(content, fd, mdstat->devnm);
+               if (sysfs_init(content, fd, mdstat->devnm)) {
+                       pr_err("Unable to initialize sysfs for %s\n",
+                              mdstat->devnm);
+                       rv = 1;
+                       break;
+               }
 
                if (mdmon_running(container))
                        flush_mdmon(container);
@@ -5000,6 +5002,7 @@ int Grow_continue_command(char *devname, int fd,
                        goto Grow_continue_command_exit;
                }
                content = &array;
+               sysfs_init(content, fd, NULL);
                /* Need to load a superblock.
                 * FIXME we should really get what we need from
                 * sysfs
@@ -5122,7 +5125,13 @@ int Grow_continue_command(char *devname, int fd,
                        goto Grow_continue_command_exit;
                }
 
-               sysfs_init(content, fd2, mdstat->devnm);
+               if (sysfs_init(content, fd2, mdstat->devnm)) {
+                       pr_err("Unable to initialize sysfs for %s, Grow cannot continue",
+                              mdstat->devnm);
+                       ret_val = 1;
+                       close(fd2);
+                       goto Grow_continue_command_exit;
+               }
 
                close(fd2);