]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Grow.c
util: Remove unnecesary NULL pointer checks when calling sysfs_free()
[thirdparty/mdadm.git] / Grow.c
diff --git a/Grow.c b/Grow.c
old mode 100644 (file)
new mode 100755 (executable)
index a1f8e4c..c4f417e
--- a/Grow.c
+++ b/Grow.c
@@ -297,6 +297,9 @@ int Grow_addbitmap(char *devname, int fd, struct context *c, struct shape *s)
                        "  between different architectures.  Consider upgrading the Linux kernel.\n");
        }
 
+       if (s->bitmap_file && strcmp(s->bitmap_file, "clustered") == 0)
+               major = BITMAP_MAJOR_CLUSTERED;
+
        if (ioctl(fd, GET_BITMAP_FILE, &bmf) != 0) {
                if (errno == ENOMEM)
                        pr_err("Memory allocation failure.\n");
@@ -325,12 +328,15 @@ int Grow_addbitmap(char *devname, int fd, struct context *c, struct shape *s)
                if (strcmp(s->bitmap_file, "none")==0) {
                        array.state &= ~(1<<MD_SB_BITMAP_PRESENT);
                        if (ioctl(fd, SET_ARRAY_INFO, &array)!= 0) {
-                               pr_err("failed to remove internal bitmap.\n");
+                               if (array.state & (1<<MD_SB_CLUSTERED))
+                                       pr_err("failed to remove clustered bitmap.\n");
+                               else
+                                       pr_err("failed to remove internal bitmap.\n");
                                return 1;
                        }
                        return 0;
                }
-               pr_err("%s bitmap already present on %s\n", s->bitmap_file, devname);
+               pr_err("bitmap already present on %s\n", devname);
                return 1;
        }
 
@@ -734,6 +740,14 @@ int start_reshape(struct mdinfo *sra, int already_running,
 void abort_reshape(struct mdinfo *sra)
 {
        sysfs_set_str(sra, NULL, "sync_action", "idle");
+       /*
+        * Prior to kernel commit: 23ddff3792f6 ("md: allow suspend_lo and
+        * suspend_hi to decrease as well as increase.")
+        * you could only increase suspend_{lo,hi} unless the region they
+        * covered was empty.  So to reset to 0, you need to push suspend_lo
+        * up past suspend_hi first.  So to maximize the chance of mdadm
+        * working on all kernels, we want to keep doing that.
+        */
        sysfs_set_num(sra, NULL, "suspend_lo", 0x7FFFFFFFFFFFFFFFULL);
        sysfs_set_num(sra, NULL, "suspend_hi", 0);
        sysfs_set_num(sra, NULL, "suspend_lo", 0);
@@ -1584,6 +1598,15 @@ int Grow_reshape(char *devname, int fd,
                pr_err("Cannot increase raid-disks on this array beyond %d\n", st->max_devs);
                return 1;
        }
+       if (s->level == 0 &&
+           (array.state & (1<<MD_SB_BITMAP_PRESENT)) &&
+           !(array.state & (1<<MD_SB_CLUSTERED))) {
+                array.state &= ~(1<<MD_SB_BITMAP_PRESENT);
+                if (ioctl(fd, SET_ARRAY_INFO, &array)!= 0) {
+                        pr_err("failed to remove internal bitmap.\n");
+                        return 1;
+                }
+        }
 
        /* in the external case we need to check that the requested reshape is
         * supported, and perform an initial check that the container holds the
@@ -4500,8 +4523,8 @@ int Grow_restart(struct supertype *st, struct mdinfo *info, int *fdlist, int cnt
                 * sometimes they aren't... So allow considerable flexability in matching, and allow
                 * this test to be overridden by an environment variable.
                 */
-               if (info->array.utime > (int)__le64_to_cpu(bsb.mtime) + 2*60*60 ||
-                   info->array.utime < (int)__le64_to_cpu(bsb.mtime) - 10*60) {
+               if(time_after(info->array.utime, (unsigned int)__le64_to_cpu(bsb.mtime) + 2*60*60) ||
+                  time_before(info->array.utime, (unsigned int)__le64_to_cpu(bsb.mtime) - 10*60)) {
                        if (check_env("MDADM_GROW_ALLOW_OLD")) {
                                pr_err("accepting backup with timestamp %lu for array with timestamp %lu\n",
                                        (unsigned long)__le64_to_cpu(bsb.mtime),
@@ -4870,6 +4893,9 @@ int Grow_continue_command(char *devname, int fd,
 
                sysfs_init(content, fd2, mdstat->devnm);
 
+               close(fd2);
+               fd2 = -1;
+
                /* start mdmon in case it is not running
                 */
                if (!mdmon_running(container))