]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Grow.c
Create.c: fix uclibc build
[thirdparty/mdadm.git] / Grow.c
diff --git a/Grow.c b/Grow.c
index 8f5cf07d10d9a22f1545ab85be4cbba76ca508e3..074f19956e17a4568a254a23b2f6d615068c8727 100644 (file)
--- a/Grow.c
+++ b/Grow.c
@@ -309,7 +309,7 @@ int Grow_addbitmap(char *devname, int fd, struct context *c, struct shape *s)
                return 1;
        }
        if (bmf.pathname[0]) {
-               if (strcmp(s->bitmap_file,"none") == 0) {
+               if (str_is_none(s->bitmap_file) == true) {
                        if (ioctl(fd, SET_BITMAP_FILE, -1) != 0) {
                                pr_err("failed to remove bitmap %s\n",
                                        bmf.pathname);
@@ -325,7 +325,7 @@ int Grow_addbitmap(char *devname, int fd, struct context *c, struct shape *s)
                return 1;
        }
        if (array.state & (1 << MD_SB_BITMAP_PRESENT)) {
-               if (strcmp(s->bitmap_file, "none")==0) {
+               if (str_is_none(s->bitmap_file) == true) {
                        array.state &= ~(1 << MD_SB_BITMAP_PRESENT);
                        if (md_set_array_info(fd, &array) != 0) {
                                if (array.state & (1 << MD_SB_CLUSTERED))
@@ -340,7 +340,7 @@ int Grow_addbitmap(char *devname, int fd, struct context *c, struct shape *s)
                return 1;
        }
 
-       if (strcmp(s->bitmap_file, "none") == 0) {
+       if (str_is_none(s->bitmap_file) == true) {
                pr_err("no bitmap found on %s\n", devname);
                return 1;
        }
@@ -429,7 +429,7 @@ int Grow_addbitmap(char *devname, int fd, struct context *c, struct shape *s)
                        dv = map_dev(disk.major, disk.minor, 1);
                        if (!dv)
                                continue;
-                       if (((disk.state & (1 << MD_DISK_WRITEMOSTLY)) == 0) &&
+                       if ((disk.state & (1 << MD_DISK_WRITEMOSTLY)) &&
                           (strcmp(s->bitmap_file, "clustered") == 0)) {
                                pr_err("%s disks marked write-mostly are not supported with clustered bitmap\n",devname);
                                free(mdi);
@@ -545,7 +545,7 @@ int Grow_consistency_policy(char *devname, int fd, struct context *c, struct sha
        char *subarray = NULL;
        int ret = 0;
        char container_dev[PATH_MAX];
-       char buf[20];
+       char buf[SYSFS_MAX_BUF_SIZE];
 
        if (s->consistency_policy != CONSISTENCY_POLICY_RESYNC &&
            s->consistency_policy != CONSISTENCY_POLICY_PPL) {
@@ -594,7 +594,7 @@ int Grow_consistency_policy(char *devname, int fd, struct context *c, struct sha
        }
 
        if (s->consistency_policy == CONSISTENCY_POLICY_PPL) {
-               if (sysfs_get_str(sra, NULL, "sync_action", buf, 20) <= 0) {
+               if (sysfs_get_str(sra, NULL, "sync_action", buf, sizeof(buf)) <= 0) {
                        ret = 1;
                        goto free_info;
                } else if (strcmp(buf, "reshape\n") == 0) {
@@ -817,12 +817,12 @@ static int freeze(struct supertype *st)
        else {
                struct mdinfo *sra = sysfs_read(-1, st->devnm, GET_VERSION);
                int err;
-               char buf[20];
+               char buf[SYSFS_MAX_BUF_SIZE];
 
                if (!sra)
                        return -1;
                /* Need to clear any 'read-auto' status */
-               if (sysfs_get_str(sra, NULL, "array_state", buf, 20) > 0 &&
+               if (sysfs_get_str(sra, NULL, "array_state", buf, sizeof(buf)) > 0 &&
                    strncmp(buf, "read-auto", 9) == 0)
                        sysfs_set_str(sra, NULL, "array_state", "clean");
 
@@ -838,10 +838,10 @@ static void unfreeze(struct supertype *st)
                return unfreeze_container(st);
        else {
                struct mdinfo *sra = sysfs_read(-1, st->devnm, GET_VERSION);
-               char buf[20];
+               char buf[SYSFS_MAX_BUF_SIZE];
 
                if (sra &&
-                   sysfs_get_str(sra, NULL, "sync_action", buf, 20) > 0 &&
+                   sysfs_get_str(sra, NULL, "sync_action", buf, sizeof(buf)) > 0 &&
                    strcmp(buf, "frozen\n") == 0)
                        sysfs_set_str(sra, NULL, "sync_action", "idle");
                sysfs_free(sra);
@@ -851,12 +851,12 @@ static void unfreeze(struct supertype *st)
 static void wait_reshape(struct mdinfo *sra)
 {
        int fd = sysfs_get_fd(sra, NULL, "sync_action");
-       char action[20];
+       char action[SYSFS_MAX_BUF_SIZE];
 
        if (fd < 0)
                return;
 
-       while (sysfs_fd_get_str(fd, action, 20) > 0 &&
+       while (sysfs_fd_get_str(fd, action, sizeof(action)) > 0 &&
               strncmp(action, "reshape", 7) == 0)
                sysfs_wait(fd, NULL);
        close(fd);
@@ -902,7 +902,7 @@ static int subarray_set_num(char *container, struct mdinfo *sra, char *name, int
         * to close a race with the array_state going clean before the
         * next write to raid_disks / stripe_cache_size
         */
-       char safe[50];
+       char safe[SYSFS_MAX_BUF_SIZE];
        int rc;
 
        /* only 'raid_disks' and 'stripe_cache_size' trigger md_allow_write */
@@ -1067,7 +1067,7 @@ int remove_disks_for_takeover(struct supertype *st,
                remaining = sd->next;
 
                sysfs_set_str(sra, sd, "state", "faulty");
-               sysfs_set_str(sra, sd, "slot", "none");
+               sysfs_set_str(sra, sd, "slot", STR_COMMON_NONE);
                /* for external metadata disks should be removed in mdmon */
                if (!st->ss->external)
                        sysfs_set_str(sra, sd, "state", "remove");
@@ -1708,14 +1708,6 @@ char *analyse_change(char *devname, struct mdinfo *info, struct reshape *re)
                return NULL;
        }
 
-       if (re->after.data_disks == re->before.data_disks &&
-           get_linux_version() < 2006032)
-               return "in-place reshape is not safe before 2.6.32 - sorry.";
-
-       if (re->after.data_disks < re->before.data_disks &&
-           get_linux_version() < 2006030)
-               return "reshape to fewer devices is not supported before 2.6.30 - sorry.";
-
        re->backup_blocks = compute_backup_blocks(
                info->new_chunk, info->array.chunk_size,
                re->after.data_disks, re->before.data_disks);
@@ -1895,14 +1887,6 @@ int Grow_reshape(char *devname, int fd,
                return 1;
        }
 
-       if (s->raiddisks && s->raiddisks < array.raid_disks &&
-           array.level > 1 && get_linux_version() < 2006032 &&
-           !check_env("MDADM_FORCE_FEWER")) {
-               pr_err("reducing the number of devices is not safe before Linux 2.6.32\n"
-                       "       Please use a newer kernel\n");
-               return 1;
-       }
-
        if (array.level > 1 && s->size > 1 &&
            (unsigned long long) (array.chunk_size / 1024) > s->size) {
                pr_err("component size must be larger than chunk size.\n");
@@ -2101,9 +2085,10 @@ int Grow_reshape(char *devname, int fd,
                        if (!mdmon_running(st->container_devnm))
                                start_mdmon(st->container_devnm);
                        ping_monitor(container);
-                       if (mdmon_running(st->container_devnm) &&
-                                       st->update_tail == NULL)
-                               st->update_tail = &st->updates;
+                       if (mdmon_running(st->container_devnm) == false) {
+                               pr_err("No mdmon found. Grow cannot continue.\n");
+                               goto release;
+                       }
                }
 
                if (s->size == MAX_SIZE)
@@ -2113,11 +2098,7 @@ int Grow_reshape(char *devname, int fd,
                        /* got truncated to 32bit, write to
                         * component_size instead
                         */
-                       if (sra)
-                               rv = sysfs_set_num(sra, NULL,
-                                                  "component_size", s->size);
-                       else
-                               rv = -1;
+                       rv = sysfs_set_num(sra, NULL, "component_size", s->size);
                } else {
                        rv = md_set_array_info(fd, &array);
 
@@ -2161,8 +2142,7 @@ size_change_error:
                         * a backport has been arranged.
                         */
                        if (sra == NULL ||
-                           sysfs_set_str(sra, NULL, "resync_start",
-                                         "none") < 0)
+                           sysfs_set_str(sra, NULL, "resync_start", STR_COMMON_NONE) < 0)
                                pr_err("--assume-clean not supported with --grow on this kernel\n");
                }
                md_get_array_info(fd, &array);
@@ -2412,11 +2392,11 @@ release:
 static int verify_reshape_position(struct mdinfo *info, int level)
 {
        int ret_val = 0;
-       char buf[40];
+       char buf[SYSFS_MAX_BUF_SIZE];
        int rv;
 
        /* read sync_max, failure can mean raid0 array */
-       rv = sysfs_get_str(info, NULL, "sync_max", buf, 40);
+       rv = sysfs_get_str(info, NULL, "sync_max", buf, sizeof(buf));
 
        if (rv > 0) {
                char *ep;
@@ -3056,7 +3036,7 @@ static int reshape_array(char *container, int fd, char *devname,
        unsigned long long array_size;
        int done;
        struct mdinfo *sra = NULL;
-       char buf[20];
+       char buf[SYSFS_MAX_BUF_SIZE];
 
        /* when reshaping a RAID0, the component_size might be zero.
         * So try to fix that up.
@@ -3065,6 +3045,8 @@ static int reshape_array(char *container, int fd, char *devname,
                dprintf("Cannot get array information.\n");
                goto release;
        }
+       if (st->update_tail == NULL)
+               st->update_tail = &st->updates;
        if (array.level == 0 && info->component_size == 0) {
                get_dev_size(fd, NULL, &array_size);
                info->component_size = array_size / array.raid_disks;
@@ -3516,7 +3498,7 @@ started:
 
        if (!forked)
                if (continue_via_systemd(container ?: sra->sys_name,
-                                        GROW_SERVICE)) {
+                                        GROW_SERVICE, NULL)) {
                        free(fdlist);
                        free(offsets);
                        sysfs_free(sra);
@@ -3714,7 +3696,7 @@ int reshape_container(char *container, char *devname,
        ping_monitor(container);
 
        if (!forked && !freeze_reshape)
-               if (continue_via_systemd(container, GROW_SERVICE))
+               if (continue_via_systemd(container, GROW_SERVICE, NULL))
                        return 0;
 
        switch (forked ? 0 : fork()) {
@@ -3932,7 +3914,7 @@ int progress_reshape(struct mdinfo *info, struct reshape *reshape,
        unsigned long long array_size = (info->component_size
                                         * reshape->before.data_disks);
        int fd;
-       char buf[20];
+       char buf[SYSFS_MAX_BUF_SIZE];
 
        /* First, we unsuspend any region that is now known to be safe.
         * If suspend_point is on the 'wrong' side of reshape_progress, then
@@ -4110,8 +4092,8 @@ int progress_reshape(struct mdinfo *info, struct reshape *reshape,
                /* Check that sync_action is still 'reshape' to avoid
                 * waiting forever on a dead array
                 */
-               char action[20];
-               if (sysfs_get_str(info, NULL, "sync_action", action, 20) <= 0 ||
+               char action[SYSFS_MAX_BUF_SIZE];
+               if (sysfs_get_str(info, NULL, "sync_action", action, sizeof(action)) <= 0 ||
                    strncmp(action, "reshape", 7) != 0)
                        break;
                /* Some kernels reset 'sync_completed' to zero
@@ -4137,8 +4119,8 @@ int progress_reshape(struct mdinfo *info, struct reshape *reshape,
         */
        if (completed == 0) {
                unsigned long long reshapep;
-               char action[20];
-               if (sysfs_get_str(info, NULL, "sync_action", action, 20) > 0 &&
+               char action[SYSFS_MAX_BUF_SIZE];
+               if (sysfs_get_str(info, NULL, "sync_action", action, sizeof(action)) > 0 &&
                    strncmp(action, "idle", 4) == 0 &&
                    sysfs_get_ll(info, NULL,
                                 "reshape_position", &reshapep) == 0)
@@ -4175,8 +4157,8 @@ check_progress:
         * it was just a device failure that leaves us degraded but
         * functioning.
         */
-       if (sysfs_get_str(info, NULL, "reshape_position", buf,
-                         sizeof(buf)) < 0 || strncmp(buf, "none", 4) != 0) {
+       if (sysfs_get_str(info, NULL, "reshape_position", buf, sizeof(buf)) < 0 ||
+           str_is_none(buf) == false) {
                /* The abort might only be temporary.  Wait up to 10
                 * seconds for fd to contain a valid number again.
                 */
@@ -4256,7 +4238,7 @@ static int grow_backup(struct mdinfo *sra,
                        if (sd->disk.state & (1<<MD_DISK_FAULTY))
                                continue;
                        if (sd->disk.state & (1<<MD_DISK_SYNC)) {
-                               char sbuf[100];
+                               char sbuf[SYSFS_MAX_BUF_SIZE];
 
                                if (sysfs_get_str(sra, sd, "state",
                                                  sbuf, sizeof(sbuf)) < 0 ||
@@ -4431,19 +4413,8 @@ static void validate(int afd, int bfd, unsigned long long offset)
                lseek64(afd, __le64_to_cpu(bsb2.arraystart)*512, 0);
                if ((unsigned long long)read(afd, abuf, len) != len)
                        fail("read first from array failed");
-               if (memcmp(bbuf, abuf, len) != 0) {
-#if 0
-                       int i;
-                       printf("offset=%llu len=%llu\n",
-                              (unsigned long long)__le64_to_cpu(bsb2.arraystart)*512, len);
-                       for (i=0; i<len; i++)
-                               if (bbuf[i] != abuf[i]) {
-                                       printf("first diff byte %d\n", i);
-                                       break;
-                               }
-#endif
+               if (memcmp(bbuf, abuf, len) != 0)
                        fail("data1 compare failed");
-               }
        }
        if (bsb2.length2) {
                unsigned long long len = __le64_to_cpu(bsb2.length2)*512;
@@ -5169,9 +5140,7 @@ int Grow_continue_command(char *devname, int fd,
                        start_mdmon(container);
                ping_monitor(container);
 
-               if (mdmon_running(container))
-                       st->update_tail = &st->updates;
-               else {
+               if (mdmon_running(container) == false) {
                        pr_err("No mdmon found. Grow cannot continue.\n");
                        ret_val = 1;
                        goto Grow_continue_command_exit;