md: be careful when testing resync_max against curr_resync_completed.
authorNeilBrown <neilb@suse.com>
Fri, 17 Jul 2015 02:06:02 +0000 (12:06 +1000)
committerNeilBrown <neilb@suse.com>
Mon, 31 Aug 2015 17:37:33 +0000 (19:37 +0200)
While it generally shouldn't happen, it is not impossible for
curr_resync_completed to exceed resync_max.
This can particularly happen when reshaping RAID5 - the current
status isn't copied to curr_resync_completed promptly, so when it
is, it can exceed resync_max.
This happens when the reshape is 'frozen', resync_max is set low,
and reshape is re-enabled.

Taking a difference between two unsigned numbers is always dangerous
anyway, so add a test to behave correctly if
   curr_resync_completed > resync_max

Signed-off-by: NeilBrown <neilb@suse.com>
drivers/md/md.c
drivers/md/raid5.c

index 5b62a3d49e12ed6f8522d6d960b45da5c193e525..b326cd26b0277d534b13013a92c65bd1ee03ef44 100644 (file)
@@ -7834,7 +7834,8 @@ void md_do_sync(struct md_thread *thread)
                      > (max_sectors >> 4)) ||
                     time_after_eq(jiffies, update_time + UPDATE_FREQUENCY) ||
                     (j - mddev->curr_resync_completed)*2
-                    >= mddev->resync_max - mddev->curr_resync_completed
+                    >= mddev->resync_max - mddev->curr_resync_completed ||
+                    mddev->curr_resync_completed > mddev->resync_max
                            )) {
                        /* time to update curr_resync_completed */
                        wait_event(mddev->recovery_wait,
index 19bbdbe1a52f814a64b40c0ac0f0a17ca798ea6f..1c27aa10f89cc07c296f544e892f7841d89ee43e 100644 (file)
@@ -5542,7 +5542,8 @@ static sector_t reshape_request(struct mddev *mddev, sector_t sector_nr, int *sk
        sector_nr += reshape_sectors;
        retn = reshape_sectors;
 finish:
-       if ((sector_nr - mddev->curr_resync_completed) * 2
+       if (mddev->curr_resync_completed > mddev->resync_max ||
+           (sector_nr - mddev->curr_resync_completed) * 2
            >= mddev->resync_max - mddev->curr_resync_completed) {
                /* Cannot proceed until we've updated the superblock... */
                wait_event(conf->wait_for_overlap,