]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commitdiff
md: be cautious about using ->curr_resync_completed for ->recovery_offset
authorNeilBrown <neilb@suse.com>
Tue, 17 Oct 2017 05:18:36 +0000 (16:18 +1100)
committerShaohua Li <shli@fb.com>
Thu, 9 Nov 2017 15:29:40 +0000 (07:29 -0800)
The ->recovery_offset shows how much of a non-InSync device is actually
in sync - how much has been recoveryed.

When performing a recovery, ->curr_resync and ->curr_resync_completed
follow the device address being recovered and so can be used to update
->recovery_offset.

When performing a reshape, ->curr_resync* might follow the device
addresses (raid5) or might follow array addresses (raid10), so cannot
in general be used to set ->recovery_offset.  When reshaping backwards,
->curre_resync* measures from the *end* of the array-or-device, so is
particularly unhelpful.

So change the common code in md.c to only use ->curr_resync_complete
for the simple recovery case, and add code to raid5.c to update
->recovery_offset during a forwards reshape.

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

index 2bf4cc41b4f81756ac6243fc4e2e5b4c58f44944..15e4668f594cf64843dd2f4ce5cf946f97d1459f 100644 (file)
@@ -2454,10 +2454,18 @@ repeat:
                }
        }
 
-       /* First make sure individual recovery_offsets are correct */
+       /*
+        * First make sure individual recovery_offsets are correct
+        * curr_resync_completed can only be used during recovery.
+        * During reshape/resync it might use array-addresses rather
+        * that device addresses.
+        */
        rdev_for_each(rdev, mddev) {
                if (rdev->raid_disk >= 0 &&
                    mddev->delta_disks >= 0 &&
+                   test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) &&
+                   test_bit(MD_RECOVERY_RECOVER, &mddev->recovery) &&
+                   !test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery) &&
                    !test_bit(Journal, &rdev->flags) &&
                    !test_bit(In_sync, &rdev->flags) &&
                    mddev->curr_resync_completed > rdev->recovery_offset)
@@ -8491,16 +8499,19 @@ void md_do_sync(struct md_thread *thread)
                } else {
                        if (!test_bit(MD_RECOVERY_INTR, &mddev->recovery))
                                mddev->curr_resync = MaxSector;
-                       rcu_read_lock();
-                       rdev_for_each_rcu(rdev, mddev)
-                               if (rdev->raid_disk >= 0 &&
-                                   mddev->delta_disks >= 0 &&
-                                   !test_bit(Journal, &rdev->flags) &&
-                                   !test_bit(Faulty, &rdev->flags) &&
-                                   !test_bit(In_sync, &rdev->flags) &&
-                                   rdev->recovery_offset < mddev->curr_resync)
-                                       rdev->recovery_offset = mddev->curr_resync;
-                       rcu_read_unlock();
+                       if (!test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery) &&
+                           test_bit(MD_RECOVERY_RECOVER, &mddev->recovery)) {
+                               rcu_read_lock();
+                               rdev_for_each_rcu(rdev, mddev)
+                                       if (rdev->raid_disk >= 0 &&
+                                           mddev->delta_disks >= 0 &&
+                                           !test_bit(Journal, &rdev->flags) &&
+                                           !test_bit(Faulty, &rdev->flags) &&
+                                           !test_bit(In_sync, &rdev->flags) &&
+                                           rdev->recovery_offset < mddev->curr_resync)
+                                               rdev->recovery_offset = mddev->curr_resync;
+                               rcu_read_unlock();
+                       }
                }
        }
  skip:
index 2a4b34941d86edb13304e201505cc86ee42870f4..1649e82faae2975e8126ca3e02a2b39a0fbf6222 100644 (file)
@@ -5738,6 +5738,7 @@ static sector_t reshape_request(struct mddev *mddev, sector_t sector_nr, int *sk
         */
        struct r5conf *conf = mddev->private;
        struct stripe_head *sh;
+       struct md_rdev *rdev;
        sector_t first_sector, last_sector;
        int raid_disks = conf->previous_raid_disks;
        int data_disks = raid_disks - conf->max_degraded;
@@ -5860,6 +5861,15 @@ static sector_t reshape_request(struct mddev *mddev, sector_t sector_nr, int *sk
                        return 0;
                mddev->reshape_position = conf->reshape_progress;
                mddev->curr_resync_completed = sector_nr;
+               if (!mddev->reshape_backwards)
+                       /* Can update recovery_offset */
+                       rdev_for_each(rdev, mddev)
+                               if (rdev->raid_disk >= 0 &&
+                                   !test_bit(Journal, &rdev->flags) &&
+                                   !test_bit(In_sync, &rdev->flags) &&
+                                   rdev->recovery_offset < sector_nr)
+                                       rdev->recovery_offset = sector_nr;
+
                conf->reshape_checkpoint = jiffies;
                set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags);
                md_wakeup_thread(mddev->thread);
@@ -5958,6 +5968,14 @@ finish:
                        goto ret;
                mddev->reshape_position = conf->reshape_progress;
                mddev->curr_resync_completed = sector_nr;
+               if (!mddev->reshape_backwards)
+                       /* Can update recovery_offset */
+                       rdev_for_each(rdev, mddev)
+                               if (rdev->raid_disk >= 0 &&
+                                   !test_bit(Journal, &rdev->flags) &&
+                                   !test_bit(In_sync, &rdev->flags) &&
+                                   rdev->recovery_offset < sector_nr)
+                                       rdev->recovery_offset = sector_nr;
                conf->reshape_checkpoint = jiffies;
                set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags);
                md_wakeup_thread(mddev->thread);
@@ -7945,6 +7963,7 @@ static void end_reshape(struct r5conf *conf)
 {
 
        if (!test_bit(MD_RECOVERY_INTR, &conf->mddev->recovery)) {
+               struct md_rdev *rdev;
 
                spin_lock_irq(&conf->device_lock);
                conf->previous_raid_disks = conf->raid_disks;
@@ -7952,6 +7971,11 @@ static void end_reshape(struct r5conf *conf)
                smp_wmb();
                conf->reshape_progress = MaxSector;
                conf->mddev->reshape_position = MaxSector;
+               rdev_for_each(rdev, conf->mddev)
+                       if (rdev->raid_disk >= 0 &&
+                           !test_bit(Journal, &rdev->flags) &&
+                           !test_bit(In_sync, &rdev->flags))
+                               rdev->recovery_offset = MaxSector;
                spin_unlock_irq(&conf->device_lock);
                wake_up(&conf->wait_for_overlap);