]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Grow.c
DDF: ddf_activate_spare: only activate good drives
[thirdparty/mdadm.git] / Grow.c
diff --git a/Grow.c b/Grow.c
index 8ca57e84ee6b460ff3af67a1a01c5ff25128fadf..c1ae6e839312d31a8213fc12ea2e7dde35a5cc0d 100644 (file)
--- a/Grow.c
+++ b/Grow.c
@@ -3086,9 +3086,11 @@ static int reshape_array(char *container, int fd, char *devname,
                        map_fork();
                        break;
                }
+               close(fd);
                wait_reshape(sra);
-               impose_level(fd, info->new_level, devname, verbose);
-
+               fd = open_dev(sra->sys_name);
+               if (fd >= 0)
+                       impose_level(fd, info->new_level, devname, verbose);
                return 0;
        case 1: /* Couldn't set data_offset, try the old way */
                if (data_offset != INVALID_SECTORS) {
@@ -3228,7 +3230,7 @@ started:
        do {
                struct mdstat_ent *mds, *m;
                delayed = 0;
-               mds = mdstat_read(0, 0);
+               mds = mdstat_read(1, 0);
                for (m = mds; m; m = m->next)
                        if (strcmp(m->devnm, sra->sys_name) == 0) {
                                if (m->resync &&
@@ -3248,9 +3250,9 @@ started:
                        delayed = 0;
                }
                if (delayed)
-                       sleep(30 - (delayed-1) * 25);
+                       mdstat_wait(30 - (delayed-1) * 25);
        } while (delayed);
-
+       mdstat_close();
        close(fd);
        if (check_env("MDADM_GROW_VERIFY"))
                fd = open(devname, O_RDONLY | O_DIRECT);
@@ -3475,7 +3477,7 @@ int reshape_container(char *container, char *devname,
                        flush_mdmon(container);
 
                rv = reshape_array(container, fd, adev, st,
-                                  content, force, NULL, 0ULL,
+                                  content, force, NULL, INVALID_SECTORS,
                                   backup_file, verbose, 1, restart,
                                   freeze_reshape);
                close(fd);
@@ -3526,7 +3528,7 @@ int progress_reshape(struct mdinfo *info, struct reshape *reshape,
                     unsigned long long backup_point,
                     unsigned long long wait_point,
                     unsigned long long *suspend_point,
-                    unsigned long long *reshape_completed)
+                    unsigned long long *reshape_completed, int *frozen)
 {
        /* This function is called repeatedly by the reshape manager.
         * It determines how much progress can safely be made and allows
@@ -3743,7 +3745,8 @@ int progress_reshape(struct mdinfo *info, struct reshape *reshape,
                wait_point = info->component_size - wait_point;
        }
 
-       sysfs_set_num(info, NULL, "sync_max", max_progress);
+       if (!*frozen)
+               sysfs_set_num(info, NULL, "sync_max", max_progress);
 
        /* Now wait.  If we have already reached the point that we were
         * asked to wait to, don't wait at all, else wait for any change.
@@ -3825,6 +3828,7 @@ check_progress:
                 */
                int wait = 10000;
                int rv = -2;
+               unsigned long long new_sync_max;
                while (fd >= 0 && rv < 0 && wait > 0) {
                        if (sysfs_wait(fd, &wait) != 1)
                                break;
@@ -3832,6 +3836,11 @@ check_progress:
                        case 0:
                                /* all good again */
                                rv = 1;
+                               /* If "sync_max" is no longer max_progress
+                                * we need to freeze things
+                                */
+                               sysfs_get_ll(info, NULL, "sync_max", &new_sync_max);
+                               *frozen = (new_sync_max != max_progress);
                                break;
                        case -2: /* read error - abort */
                                wait = 0;
@@ -4126,6 +4135,7 @@ int child_monitor(int afd, struct mdinfo *sra, struct reshape *reshape,
        struct mdinfo *sd;
        unsigned long stripes;
        int uuid[4];
+       int frozen = 0;
 
        /* set up the backup-super-block.  This requires the
         * uuid from the array.
@@ -4203,9 +4213,11 @@ int child_monitor(int afd, struct mdinfo *sra, struct reshape *reshape,
                                wait_point = __le64_to_cpu(bsb.arraystart2);
                }
 
+               reshape_completed = sra->reshape_progress;
                rv = progress_reshape(sra, reshape,
                                      backup_point, wait_point,
-                                     &suspend_point, &reshape_completed);
+                                     &suspend_point, &reshape_completed,
+                                     &frozen);
                /* external metadata would need to ping_monitor here */
                sra->reshape_progress = reshape_completed;
 
@@ -4836,7 +4848,8 @@ int Grow_continue(int mdfd, struct supertype *st, struct mdinfo *info,
                                            freeze_reshape);
        } else
                ret_val = reshape_array(NULL, mdfd, "array", st, info, 1,
-                                       NULL, 0ULL, backup_file, 0, 0,
+                                       NULL, INVALID_SECTORS,
+                                       backup_file, 0, 0,
                                        1 | info->reshape_active,
                                        freeze_reshape);