Skip to content

Commit 2e86337

Browse files
committed
md: fix sync_action incorrect display during resync
JIRA: https://issues.redhat.com/browse/RHEL-94433 commit b7ee30f Author: Zheng Qixing <zhengqixing@huawei.com> Date: Sat Aug 16 08:25:34 2025 +0800 md: fix sync_action incorrect display during resync During raid resync, if a disk becomes faulty, the operation is briefly interrupted. The MD_RECOVERY_RECOVER flag triggered by the disk failure causes sync_action to incorrectly show "recover" instead of "resync". The same issue affects reshape operations. Reproduction steps: mdadm -Cv /dev/md1 -l1 -n4 -e1.2 /dev/sd{a..d} // -> resync happened mdadm -f /dev/md1 /dev/sda // -> resync interrupted cat sync_action -> recover Add progress checks in md_sync_action() for resync/recover/reshape to ensure the interface correctly reports the actual operation type. Fixes: 4b10a3b ("md: ensure resync is prioritized over recovery") Signed-off-by: Zheng Qixing <zhengqixing@huawei.com> Link: https://lore.kernel.org/linux-raid/20250816002534.1754356-3-zhengqixing@huaweicloud.com Signed-off-by: Yu Kuai <yukuai3@huawei.com> Signed-off-by: Nigel Croxon <ncroxon@redhat.com>
1 parent 4a3aa02 commit 2e86337

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

drivers/md/md.c

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4874,9 +4874,33 @@ static bool rdev_needs_recovery(struct md_rdev *rdev, sector_t sectors)
48744874
rdev->recovery_offset < sectors;
48754875
}
48764876

4877+
static enum sync_action md_get_active_sync_action(struct mddev *mddev)
4878+
{
4879+
struct md_rdev *rdev;
4880+
bool is_recover = false;
4881+
4882+
if (mddev->resync_offset < MaxSector)
4883+
return ACTION_RESYNC;
4884+
4885+
if (mddev->reshape_position != MaxSector)
4886+
return ACTION_RESHAPE;
4887+
4888+
rcu_read_lock();
4889+
rdev_for_each_rcu(rdev, mddev) {
4890+
if (rdev_needs_recovery(rdev, MaxSector)) {
4891+
is_recover = true;
4892+
break;
4893+
}
4894+
}
4895+
rcu_read_unlock();
4896+
4897+
return is_recover ? ACTION_RECOVER : ACTION_IDLE;
4898+
}
4899+
48774900
enum sync_action md_sync_action(struct mddev *mddev)
48784901
{
48794902
unsigned long recovery = mddev->recovery;
4903+
enum sync_action active_action;
48804904

48814905
/*
48824906
* frozen has the highest priority, means running sync_thread will be
@@ -4900,8 +4924,17 @@ enum sync_action md_sync_action(struct mddev *mddev)
49004924
!test_bit(MD_RECOVERY_NEEDED, &recovery))
49014925
return ACTION_IDLE;
49024926

4903-
if (test_bit(MD_RECOVERY_RESHAPE, &recovery) ||
4904-
mddev->reshape_position != MaxSector)
4927+
/*
4928+
* Check if any sync operation (resync/recover/reshape) is
4929+
* currently active. This ensures that only one sync operation
4930+
* can run at a time. Returns the type of active operation, or
4931+
* ACTION_IDLE if none are active.
4932+
*/
4933+
active_action = md_get_active_sync_action(mddev);
4934+
if (active_action != ACTION_IDLE)
4935+
return active_action;
4936+
4937+
if (test_bit(MD_RECOVERY_RESHAPE, &recovery))
49054938
return ACTION_RESHAPE;
49064939

49074940
if (test_bit(MD_RECOVERY_RECOVER, &recovery))

0 commit comments

Comments
 (0)