]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Grow.c
Consistently print program Name and __func__ in debug messages.
[thirdparty/mdadm.git] / Grow.c
diff --git a/Grow.c b/Grow.c
index 2af6c96e764a67b6125bea90775342b462f61a45..f2879768ca70354f6f6707a511af0b1fd7319819 100644 (file)
--- a/Grow.c
+++ b/Grow.c
@@ -940,7 +940,9 @@ int reshape_open_backup_file(char *backup_file,
 
        if (!restart && strncmp(backup_file, MAP_DIR, strlen(MAP_DIR)) != 0) {
                char *bu = make_backup(sys_name);
-               symlink(backup_file, bu);
+               if (symlink(backup_file, bu))
+                       pr_err("Recording backup file in " MAP_DIR "failed: %s\n",
+                              strerror(errno));
                free(bu);
        }
 
@@ -1026,7 +1028,12 @@ char *analyse_change(char *devname, struct mdinfo *info, struct reshape *re)
 
        switch (info->array.level) {
        default:
-               return "Cannot understand this RAID level";
+               return "No reshape is possibly for this RAID level";
+       case LEVEL_LINEAR:
+               if (info->delta_disks != UnSet)
+                       return "Only --add is supported for LINEAR, setting --raid-disks is not needed";
+               else
+                       return "Only --add is supported for LINEAR, other --grow options are not meaningful";
        case 1:
                /* RAID1 can convert to RAID1 with different disks, or
                 * raid5 with 2 disks, or
@@ -1338,7 +1345,6 @@ char *analyse_change(char *devname, struct mdinfo *info, struct reshape *re)
 
                switch (re->level) {
                case 4:
-                       re->before.layout = 0;
                        re->after.layout = 0;
                        break;
                case 5:
@@ -1490,8 +1496,8 @@ static int set_array_size(struct supertype *st, struct mdinfo *sra,
                                ret_val = 0;
                                dprintf("Array size changed");
                        }
-                       dprintf(" from %llu to %llu.\n",
-                               current_size, new_size);
+                       dprintf_cont(" from %llu to %llu.\n",
+                                    current_size, new_size);
                }
                sysfs_free(info);
        } else
@@ -1812,7 +1818,7 @@ int Grow_reshape(char *devname, int fd,
                if (s->size == MAX_SIZE)
                        s->size = 0;
                array.size = s->size;
-               if ((unsigned)array.size != s->size) {
+               if (s->size & ~INT32_MAX) {
                        /* got truncated to 32bit, write to
                         * component_size instead
                         */
@@ -1913,7 +1919,7 @@ size_change_error:
                int err;
                err = remove_disks_for_takeover(st, sra, array.layout);
                if (err) {
-                       dprintf(Name": Array cannot be reshaped\n");
+                       dprintf("Array cannot be reshaped\n");
                        if (cfd > -1)
                                close(cfd);
                        rv = 1;
@@ -2127,7 +2133,7 @@ static int verify_reshape_position(struct mdinfo *info, int level)
                char *ep;
                unsigned long long position = strtoull(buf, &ep, 0);
 
-               dprintf(Name": Read sync_max sysfs entry is: %s\n", buf);
+               dprintf("Read sync_max sysfs entry is: %s\n", buf);
                if (!(ep == buf || (*ep != 0 && *ep != '\n' && *ep != ' '))) {
                        position *= get_data_disks(level,
                                                   info->new_layout,
@@ -2249,7 +2255,9 @@ static int set_new_data_offset(struct mdinfo *sra, struct supertype *st,
                if (info2.space_before == 0 &&
                    info2.space_after == 0) {
                        /* Metadata doesn't support data_offset changes */
-                       return 1;
+                       pr_err("%s: Metadata version doesn't support"
+                              " data_offset changes\n", devname);
+                       goto fallback;
                }
                if (before > info2.space_before)
                        before = info2.space_before;
@@ -2821,6 +2829,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];
 
        /* when reshaping a RAID0, the component_size might be zero.
         * So try to fix that up.
@@ -2868,7 +2877,9 @@ static int reshape_array(char *container, int fd, char *devname,
                goto release;
        }
 
-       if (st->ss->external && restart && (info->reshape_progress == 0)) {
+       if (st->ss->external && restart && (info->reshape_progress == 0) &&
+           !((sysfs_get_str(info, NULL, "sync_action", buf, sizeof(buf)) > 0) &&
+             (strncmp(buf, "reshape", 7) == 0))) {
                /* When reshape is restarted from '0', very begin of array
                 * it is possible that for external metadata reshape and array
                 * configuration doesn't happen.
@@ -3472,7 +3483,7 @@ int reshape_container(char *container, char *devname,
         */
        ping_monitor(container);
 
-       if (!forked && !check_env("MDADM_NO_SYSTEMCTL"))
+       if (!forked && !freeze_reshape && !check_env("MDADM_NO_SYSTEMCTL"))
                if (continue_via_systemd(container))
                        return 0;
 
@@ -3483,8 +3494,8 @@ int reshape_container(char *container, char *devname,
                return 1;
        default: /* parent */
                if (!freeze_reshape)
-                       printf(Name ": multi-array reshape continues"
-                              " in background\n");
+                       printf("%s: multi-array reshape continues"
+                              " in background\n", Name);
                return 0;
        case 0: /* child */
                map_fork();
@@ -3546,8 +3557,7 @@ int reshape_container(char *container, char *devname,
 
                fd = open_dev(mdstat->devnm);
                if (fd < 0) {
-                       printf(Name ": Device %s cannot be opened for reshape.",
-                              adev);
+                       pr_err("Device %s cannot be opened for reshape.\n", adev);
                        break;
                }
 
@@ -3562,8 +3572,8 @@ int reshape_container(char *container, char *devname,
                         * This is possibly interim until the behaviour of
                         * reshape_array is resolved().
                         */
-                       printf(Name ": Multiple reshape execution detected for "
-                              "device  %s.", adev);
+                       printf("%s: Multiple reshape execution detected for "
+                              "device  %s.\n", Name, adev);
                        close(fd);
                        break;
                }
@@ -4600,7 +4610,7 @@ int Grow_restart(struct supertype *st, struct mdinfo *info, int *fdlist, int cnt
                        st->ss->free_super(st);
                        offsets[j] = dinfo.data_offset * 512;
                }
-               printf(Name ": restoring critical section\n");
+               printf("%s: restoring critical section\n", Name);
 
                if (restore_stripes(fdlist, offsets,
                                    info->array.raid_disks,
@@ -4759,7 +4769,7 @@ 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);
+               dprintf_cont("native array (%s)\n", devname);
                if (ioctl(fd, GET_ARRAY_INFO, &array.array) < 0) {
                        pr_err("%s is not an active md array -"
                                " aborting\n", devname);
@@ -4807,14 +4817,14 @@ int Grow_continue_command(char *devname, int fd,
                char *container;
 
                if (subarray) {
-                       dprintf("subarray (%s)\n", subarray);
+                       dprintf_cont("subarray (%s)\n", subarray);
                        container = st->container_devnm;
                        cfd = open_dev_excl(st->container_devnm);
                } else {
                        container = st->devnm;
                        close(fd);
                        cfd = open_dev_excl(st->devnm);
-                       dprintf("container (%s)\n", container);
+                       dprintf_cont("container (%s)\n", container);
                        fd = cfd;
                }
                if (cfd < 0) {
@@ -4950,7 +4960,7 @@ int Grow_continue(int mdfd, struct supertype *st, struct mdinfo *info,
                close(cfd);
                ret_val = reshape_container(st->container_devnm, NULL, mdfd,
                                            st, info, 0, backup_file,
-                                           0, 1,
+                                           0, forked,
                                            1 | info->reshape_active,
                                            freeze_reshape);
        } else