md: don't update recovery_cp when curr_resync is ACTIVE
authorHou Tao <houtao1@huawei.com>
Tue, 31 Jan 2023 07:07:19 +0000 (15:07 +0800)
committerSong Liu <song@kernel.org>
Wed, 1 Feb 2023 16:32:57 +0000 (08:32 -0800)
Don't update recovery_cp when curr_resync is MD_RESYNC_ACTIVE, otherwise
md may skip the resync of the first 3 sectors if the resync procedure is
interrupted before the first calling of ->sync_request() as shown below:

md_do_sync thread          control thread
  // setup resync
  mddev->recovery_cp = 0
  j = 0
  mddev->curr_resync = MD_RESYNC_ACTIVE

                             // e.g., set array as idle
                             set_bit(MD_RECOVERY_INTR, &&mddev_recovery)
  // resync loop
  // check INTR before calling sync_request
  !test_bit(MD_RECOVERY_INTR, &mddev->recovery

  // resync interrupted
  // update recovery_cp from 0 to 3
  // the resync of three 3 sectors will be skipped
  mddev->recovery_cp = 3

Fixes: eac58d08d493 ("md: Use enum for overloaded magic numbers used by mddev->curr_resync")
Cc: stable@vger.kernel.org # 6.0+
Signed-off-by: Hou Tao <houtao1@huawei.com>
Reviewed-by: Logan Gunthorpe <logang@deltatee.com>
Signed-off-by: Song Liu <song@kernel.org>
drivers/md/md.c

index 02b0240e7c715a0a4a7dde9af66835fd55df16dc..272cc5d14906fdce773839b592a38af18d522589 100644 (file)
@@ -9030,7 +9030,7 @@ void md_do_sync(struct md_thread *thread)
        mddev->pers->sync_request(mddev, max_sectors, &skipped);
 
        if (!test_bit(MD_RECOVERY_CHECK, &mddev->recovery) &&
-           mddev->curr_resync >= MD_RESYNC_ACTIVE) {
+           mddev->curr_resync > MD_RESYNC_ACTIVE) {
                if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) {
                        if (test_bit(MD_RECOVERY_INTR, &mddev->recovery)) {
                                if (mddev->curr_resync >= mddev->recovery_cp) {