linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] md: fix sync_action show
@ 2025-08-12  2:17 Zheng Qixing
  2025-08-12  2:17 ` [PATCH v2 1/2] md: add helper rdev_needs_recovery() Zheng Qixing
  2025-08-12  2:17 ` [PATCH v2 2/2] md: fix sync_action incorrect display during resync Zheng Qixing
  0 siblings, 2 replies; 8+ messages in thread
From: Zheng Qixing @ 2025-08-12  2:17 UTC (permalink / raw)
  To: song, yukuai3, linan122
  Cc: linux-raid, linux-kernel, yi.zhang, yangerkun, houtao1,
	zhengqixing

From: Zheng Qixing <zhengqixing@huawei.com>

Fix incorrect display of sync_action when raid is in resync.

Zheng Qixing (2):
  md: add helper rdev_needs_recovery()
  md: fix sync_action incorrect display during resync

 drivers/md/md.c | 58 ++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 48 insertions(+), 10 deletions(-)

-- 
2.39.2


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 1/2] md: add helper rdev_needs_recovery()
  2025-08-12  2:17 [PATCH v2 0/2] md: fix sync_action show Zheng Qixing
@ 2025-08-12  2:17 ` Zheng Qixing
  2025-08-12  7:38   ` Paul Menzel
  2025-08-14  0:52   ` Yu Kuai
  2025-08-12  2:17 ` [PATCH v2 2/2] md: fix sync_action incorrect display during resync Zheng Qixing
  1 sibling, 2 replies; 8+ messages in thread
From: Zheng Qixing @ 2025-08-12  2:17 UTC (permalink / raw)
  To: song, yukuai3, linan122
  Cc: linux-raid, linux-kernel, yi.zhang, yangerkun, houtao1,
	zhengqixing

From: Zheng Qixing <zhengqixing@huawei.com>

Add a helper for checking if an rdev needs recovery.

Signed-off-by: Zheng Qixing <zhengqixing@huawei.com>
---
 drivers/md/md.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/drivers/md/md.c b/drivers/md/md.c
index ac85ec73a409..4ea956a80343 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -4835,6 +4835,16 @@ metadata_store(struct mddev *mddev, const char *buf, size_t len)
 static struct md_sysfs_entry md_metadata =
 __ATTR_PREALLOC(metadata_version, S_IRUGO|S_IWUSR, metadata_show, metadata_store);
 
+static bool rdev_needs_recovery(struct md_rdev *rdev, sector_t sectors)
+{
+	if (!test_bit(Journal, &rdev->flags) &&
+	    !test_bit(Faulty, &rdev->flags) &&
+	    !test_bit(In_sync, &rdev->flags) &&
+	    rdev->recovery_offset < sectors)
+		return true;
+	return false;
+}
+
 enum sync_action md_sync_action(struct mddev *mddev)
 {
 	unsigned long recovery = mddev->recovery;
@@ -8969,10 +8979,7 @@ static sector_t md_sync_position(struct mddev *mddev, enum sync_action action)
 		rcu_read_lock();
 		rdev_for_each_rcu(rdev, mddev)
 			if (rdev->raid_disk >= 0 &&
-			    !test_bit(Journal, &rdev->flags) &&
-			    !test_bit(Faulty, &rdev->flags) &&
-			    !test_bit(In_sync, &rdev->flags) &&
-			    rdev->recovery_offset < start)
+			    rdev_needs_recovery(rdev, start))
 				start = rdev->recovery_offset;
 		rcu_read_unlock();
 
@@ -9333,10 +9340,7 @@ void md_do_sync(struct md_thread *thread)
 				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_needs_recovery(rdev, mddev->curr_resync))
 						rdev->recovery_offset = mddev->curr_resync;
 				rcu_read_unlock();
 			}
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 2/2] md: fix sync_action incorrect display during resync
  2025-08-12  2:17 [PATCH v2 0/2] md: fix sync_action show Zheng Qixing
  2025-08-12  2:17 ` [PATCH v2 1/2] md: add helper rdev_needs_recovery() Zheng Qixing
@ 2025-08-12  2:17 ` Zheng Qixing
  2025-08-12  9:22   ` Paul Menzel
  1 sibling, 1 reply; 8+ messages in thread
From: Zheng Qixing @ 2025-08-12  2:17 UTC (permalink / raw)
  To: song, yukuai3, linan122
  Cc: linux-raid, linux-kernel, yi.zhang, yangerkun, houtao1,
	zhengqixing

From: Zheng Qixing <zhengqixing@huawei.com>

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 happended
  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: 4b10a3bc67c1 ("md: ensure resync is prioritized over recovery")
Signed-off-by: Zheng Qixing <zhengqixing@huawei.com>
---
 drivers/md/md.c | 38 ++++++++++++++++++++++++++++++++++++--
 1 file changed, 36 insertions(+), 2 deletions(-)

diff --git a/drivers/md/md.c b/drivers/md/md.c
index 4ea956a80343..798428d0870b 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -4845,9 +4845,34 @@ static bool rdev_needs_recovery(struct md_rdev *rdev, sector_t sectors)
 	return false;
 }
 
+static enum sync_action md_get_active_sync_action(struct mddev *mddev)
+{
+	struct md_rdev *rdev;
+	bool is_recover = false;
+
+	if (mddev->resync_offset < MaxSector)
+		return ACTION_RESYNC;
+
+	if (mddev->reshape_position != MaxSector)
+		return ACTION_RESHAPE;
+
+	rcu_read_lock();
+	rdev_for_each_rcu(rdev, mddev) {
+		if (rdev->raid_disk >= 0 &&
+		    rdev_needs_recovery(rdev, MaxSector)) {
+			is_recover = true;
+			break;
+		}
+	}
+	rcu_read_unlock();
+
+	return is_recover ? ACTION_RECOVER : ACTION_IDLE;
+}
+
 enum sync_action md_sync_action(struct mddev *mddev)
 {
 	unsigned long recovery = mddev->recovery;
+	enum sync_action active_action;
 
 	/*
 	 * frozen has the highest priority, means running sync_thread will be
@@ -4871,8 +4896,17 @@ enum sync_action md_sync_action(struct mddev *mddev)
 	    !test_bit(MD_RECOVERY_NEEDED, &recovery))
 		return ACTION_IDLE;
 
-	if (test_bit(MD_RECOVERY_RESHAPE, &recovery) ||
-	    mddev->reshape_position != MaxSector)
+	/*
+	 * Check if any sync operation (resync/recover/reshape) is
+	 * currently active. This ensures that only one sync operation
+	 * can run at a time. Returns the type of active operation, or
+	 * ACTION_IDLE if none are active.
+	 */
+	active_action = md_get_active_sync_action(mddev);
+	if (active_action != ACTION_IDLE)
+		return active_action;
+
+	if (test_bit(MD_RECOVERY_RESHAPE, &recovery))
 		return ACTION_RESHAPE;
 
 	if (test_bit(MD_RECOVERY_RECOVER, &recovery))
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 1/2] md: add helper rdev_needs_recovery()
  2025-08-12  2:17 ` [PATCH v2 1/2] md: add helper rdev_needs_recovery() Zheng Qixing
@ 2025-08-12  7:38   ` Paul Menzel
  2025-08-14  0:52   ` Yu Kuai
  1 sibling, 0 replies; 8+ messages in thread
From: Paul Menzel @ 2025-08-12  7:38 UTC (permalink / raw)
  To: Zheng Qixing
  Cc: song, yukuai3, linan122, linux-raid, linux-kernel, yi.zhang,
	yangerkun, houtao1, zhengqixing

Dear Zheng,


Thank you for your patch.

Am 12.08.25 um 04:17 schrieb Zheng Qixing:
> From: Zheng Qixing <zhengqixing@huawei.com>
> 
> Add a helper for checking if an rdev needs recovery.
> 
> Signed-off-by: Zheng Qixing <zhengqixing@huawei.com>
> ---
>   drivers/md/md.c | 20 ++++++++++++--------
>   1 file changed, 12 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index ac85ec73a409..4ea956a80343 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -4835,6 +4835,16 @@ metadata_store(struct mddev *mddev, const char *buf, size_t len)
>   static struct md_sysfs_entry md_metadata =
>   __ATTR_PREALLOC(metadata_version, S_IRUGO|S_IWUSR, metadata_show, metadata_store);
>   
> +static bool rdev_needs_recovery(struct md_rdev *rdev, sector_t sectors)
> +{
> +	if (!test_bit(Journal, &rdev->flags) &&
> +	    !test_bit(Faulty, &rdev->flags) &&
> +	    !test_bit(In_sync, &rdev->flags) &&
> +	    rdev->recovery_offset < sectors)
> +		return true;
> +	return false;
> +}
> +
>   enum sync_action md_sync_action(struct mddev *mddev)
>   {
>   	unsigned long recovery = mddev->recovery;
> @@ -8969,10 +8979,7 @@ static sector_t md_sync_position(struct mddev *mddev, enum sync_action action)
>   		rcu_read_lock();
>   		rdev_for_each_rcu(rdev, mddev)
>   			if (rdev->raid_disk >= 0 &&
> -			    !test_bit(Journal, &rdev->flags) &&
> -			    !test_bit(Faulty, &rdev->flags) &&
> -			    !test_bit(In_sync, &rdev->flags) &&
> -			    rdev->recovery_offset < start)
> +			    rdev_needs_recovery(rdev, start))
>   				start = rdev->recovery_offset;
>   		rcu_read_unlock();
>   
> @@ -9333,10 +9340,7 @@ void md_do_sync(struct md_thread *thread)
>   				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_needs_recovery(rdev, mddev->curr_resync))
>   						rdev->recovery_offset = mddev->curr_resync;
>   				rcu_read_unlock();
>   			}

Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de>


Kind regards,

Paul

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 2/2] md: fix sync_action incorrect display during resync
  2025-08-12  2:17 ` [PATCH v2 2/2] md: fix sync_action incorrect display during resync Zheng Qixing
@ 2025-08-12  9:22   ` Paul Menzel
  2025-08-12 11:03     ` Zheng Qixing
  0 siblings, 1 reply; 8+ messages in thread
From: Paul Menzel @ 2025-08-12  9:22 UTC (permalink / raw)
  To: Zheng Qixing
  Cc: song, yukuai3, linan122, linux-raid, linux-kernel, yi.zhang,
	yangerkun, houtao1, zhengqixing

Dear Zheng,


Thank you for your patch.

Am 12.08.25 um 04:17 schrieb Zheng Qixing:
> From: Zheng Qixing <zhengqixing@huawei.com>
> 
> 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 happended
>    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: 4b10a3bc67c1 ("md: ensure resync is prioritized over recovery")
> Signed-off-by: Zheng Qixing <zhengqixing@huawei.com>
> ---
>   drivers/md/md.c | 38 ++++++++++++++++++++++++++++++++++++--
>   1 file changed, 36 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index 4ea956a80343..798428d0870b 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -4845,9 +4845,34 @@ static bool rdev_needs_recovery(struct md_rdev *rdev, sector_t sectors)
>   	return false;
>   }
>   
> +static enum sync_action md_get_active_sync_action(struct mddev *mddev)
> +{
> +	struct md_rdev *rdev;
> +	bool is_recover = false;

`is_recover` sounds strange to me, but I am not an expert with the code. 
Maybe `needs_recovery`?

> +
> +	if (mddev->resync_offset < MaxSector)
> +		return ACTION_RESYNC;
> +
> +	if (mddev->reshape_position != MaxSector)
> +		return ACTION_RESHAPE;
> +
> +	rcu_read_lock();
> +	rdev_for_each_rcu(rdev, mddev) {
> +		if (rdev->raid_disk >= 0 &&
> +		    rdev_needs_recovery(rdev, MaxSector)) {
> +			is_recover = true;
> +			break;
> +		}
> +	}
> +	rcu_read_unlock();
> +
> +	return is_recover ? ACTION_RECOVER : ACTION_IDLE;
> +}
> +
>   enum sync_action md_sync_action(struct mddev *mddev)
>   {
>   	unsigned long recovery = mddev->recovery;
> +	enum sync_action active_action;
>   
>   	/*
>   	 * frozen has the highest priority, means running sync_thread will be
> @@ -4871,8 +4896,17 @@ enum sync_action md_sync_action(struct mddev *mddev)
>   	    !test_bit(MD_RECOVERY_NEEDED, &recovery))
>   		return ACTION_IDLE;
>   
> -	if (test_bit(MD_RECOVERY_RESHAPE, &recovery) ||
> -	    mddev->reshape_position != MaxSector)
> +	/*
> +	 * Check if any sync operation (resync/recover/reshape) is
> +	 * currently active. This ensures that only one sync operation
> +	 * can run at a time. Returns the type of active operation, or
> +	 * ACTION_IDLE if none are active.
> +	 */
> +	active_action = md_get_active_sync_action(mddev);
> +	if (active_action != ACTION_IDLE)
> +		return active_action;
> +
> +	if (test_bit(MD_RECOVERY_RESHAPE, &recovery))
>   		return ACTION_RESHAPE;
>   
>   	if (test_bit(MD_RECOVERY_RECOVER, &recovery))

Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de>


Kind regards,

Paul

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 2/2] md: fix sync_action incorrect display during resync
  2025-08-12  9:22   ` Paul Menzel
@ 2025-08-12 11:03     ` Zheng Qixing
  0 siblings, 0 replies; 8+ messages in thread
From: Zheng Qixing @ 2025-08-12 11:03 UTC (permalink / raw)
  To: Paul Menzel
  Cc: song, yukuai3, linan122, linux-raid, linux-kernel, yi.zhang,
	yangerkun, houtao1, zhengqixing

Hi,


在 2025/8/12 17:22, Paul Menzel 写道:
> Dear Zheng,
>
>
> Thank you for your patch.
>
> Am 12.08.25 um 04:17 schrieb Zheng Qixing:
>> From: Zheng Qixing <zhengqixing@huawei.com>
>>
>> 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 happended
>>    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: 4b10a3bc67c1 ("md: ensure resync is prioritized over recovery")
>> Signed-off-by: Zheng Qixing <zhengqixing@huawei.com>
>> ---
>>   drivers/md/md.c | 38 ++++++++++++++++++++++++++++++++++++--
>>   1 file changed, 36 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/md/md.c b/drivers/md/md.c
>> index 4ea956a80343..798428d0870b 100644
>> --- a/drivers/md/md.c
>> +++ b/drivers/md/md.c
>> @@ -4845,9 +4845,34 @@ static bool rdev_needs_recovery(struct md_rdev 
>> *rdev, sector_t sectors)
>>       return false;
>>   }
>>   +static enum sync_action md_get_active_sync_action(struct mddev 
>> *mddev)
>> +{
>> +    struct md_rdev *rdev;
>> +    bool is_recover = false;
>
> `is_recover` sounds strange to me, but I am not an expert with the 
> code. Maybe `needs_recovery`?


is_recover is used here to distinguish whether the current sync_action 
is a recover, rather than a resync or reshape.

But it's not a big deal, no need to focus on it :)


>
>> +
>> +    if (mddev->resync_offset < MaxSector)
>> +        return ACTION_RESYNC;
>> +
>> +    if (mddev->reshape_position != MaxSector)
>> +        return ACTION_RESHAPE;
>> +
>> +    rcu_read_lock();
>> +    rdev_for_each_rcu(rdev, mddev) {
>> +        if (rdev->raid_disk >= 0 &&
>> +            rdev_needs_recovery(rdev, MaxSector)) {
>> +            is_recover = true;
>> +            break;
>> +        }
>> +    }
>> +    rcu_read_unlock();
>> +
>> +    return is_recover ? ACTION_RECOVER : ACTION_IDLE;
>> +}
>> +
>>   enum sync_action md_sync_action(struct mddev *mddev)
>>   {
>>       unsigned long recovery = mddev->recovery;
>> +    enum sync_action active_action;
>>         /*
>>        * frozen has the highest priority, means running sync_thread 
>> will be
>> @@ -4871,8 +4896,17 @@ enum sync_action md_sync_action(struct mddev 
>> *mddev)
>>           !test_bit(MD_RECOVERY_NEEDED, &recovery))
>>           return ACTION_IDLE;
>>   -    if (test_bit(MD_RECOVERY_RESHAPE, &recovery) ||
>> -        mddev->reshape_position != MaxSector)
>> +    /*
>> +     * Check if any sync operation (resync/recover/reshape) is
>> +     * currently active. This ensures that only one sync operation
>> +     * can run at a time. Returns the type of active operation, or
>> +     * ACTION_IDLE if none are active.
>> +     */
>> +    active_action = md_get_active_sync_action(mddev);
>> +    if (active_action != ACTION_IDLE)
>> +        return active_action;
>> +
>> +    if (test_bit(MD_RECOVERY_RESHAPE, &recovery))
>>           return ACTION_RESHAPE;
>>         if (test_bit(MD_RECOVERY_RECOVER, &recovery))
>
> Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de>
>
>
> Kind regards,
>
> Paul


Thanks,

Qixing



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 1/2] md: add helper rdev_needs_recovery()
  2025-08-12  2:17 ` [PATCH v2 1/2] md: add helper rdev_needs_recovery() Zheng Qixing
  2025-08-12  7:38   ` Paul Menzel
@ 2025-08-14  0:52   ` Yu Kuai
  2025-08-14  1:24     ` Zheng Qixing
  1 sibling, 1 reply; 8+ messages in thread
From: Yu Kuai @ 2025-08-14  0:52 UTC (permalink / raw)
  To: Zheng Qixing, song, linan122
  Cc: linux-raid, linux-kernel, yi.zhang, yangerkun, houtao1,
	zhengqixing, yukuai (C)

Hi,

在 2025/08/12 10:17, Zheng Qixing 写道:
> From: Zheng Qixing <zhengqixing@huawei.com>
> 
> Add a helper for checking if an rdev needs recovery.
> 
> Signed-off-by: Zheng Qixing <zhengqixing@huawei.com>
> ---
>   drivers/md/md.c | 20 ++++++++++++--------
>   1 file changed, 12 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index ac85ec73a409..4ea956a80343 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -4835,6 +4835,16 @@ metadata_store(struct mddev *mddev, const char *buf, size_t len)
>   static struct md_sysfs_entry md_metadata =
>   __ATTR_PREALLOC(metadata_version, S_IRUGO|S_IWUSR, metadata_show, metadata_store);
>   
> +static bool rdev_needs_recovery(struct md_rdev *rdev, sector_t sectors)
> +{
> +	if (!test_bit(Journal, &rdev->flags) &&
> +	    !test_bit(Faulty, &rdev->flags) &&
> +	    !test_bit(In_sync, &rdev->flags) &&
> +	    rdev->recovery_offset < sectors)
> +		return true;
> +	return false;
return directly:

return !test_bit(Journal, &rdev->flags) &&
	!test_bit(Faulty, &rdev->flags) &&
	!test_bit(In_sync, &rdev->flags) &&
	rdev->recovery_offset < sectors);

Otherwise, feel free to add
Reviewed-by: Yu Kuai <yukuai3@huawei.com>

Kuai

> +}
> +
>   enum sync_action md_sync_action(struct mddev *mddev)
>   {
>   	unsigned long recovery = mddev->recovery;
> @@ -8969,10 +8979,7 @@ static sector_t md_sync_position(struct mddev *mddev, enum sync_action action)
>   		rcu_read_lock();
>   		rdev_for_each_rcu(rdev, mddev)
>   			if (rdev->raid_disk >= 0 &&
> -			    !test_bit(Journal, &rdev->flags) &&
> -			    !test_bit(Faulty, &rdev->flags) &&
> -			    !test_bit(In_sync, &rdev->flags) &&
> -			    rdev->recovery_offset < start)
> +			    rdev_needs_recovery(rdev, start))
>   				start = rdev->recovery_offset;
>   		rcu_read_unlock();
>   
> @@ -9333,10 +9340,7 @@ void md_do_sync(struct md_thread *thread)
>   				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_needs_recovery(rdev, mddev->curr_resync))
>   						rdev->recovery_offset = mddev->curr_resync;
>   				rcu_read_unlock();
>   			}
> 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 1/2] md: add helper rdev_needs_recovery()
  2025-08-14  0:52   ` Yu Kuai
@ 2025-08-14  1:24     ` Zheng Qixing
  0 siblings, 0 replies; 8+ messages in thread
From: Zheng Qixing @ 2025-08-14  1:24 UTC (permalink / raw)
  To: Yu Kuai, song, linan122
  Cc: linux-raid, linux-kernel, yi.zhang, yangerkun, houtao1,
	zhengqixing, yukuai (C)

Hi,


在 2025/8/14 8:52, Yu Kuai 写道:
> Hi,
>
> 在 2025/08/12 10:17, Zheng Qixing 写道:
>> From: Zheng Qixing <zhengqixing@huawei.com>
>>
>> Add a helper for checking if an rdev needs recovery.
>>
>> Signed-off-by: Zheng Qixing <zhengqixing@huawei.com>
>> ---
>>   drivers/md/md.c | 20 ++++++++++++--------
>>   1 file changed, 12 insertions(+), 8 deletions(-)
>>
>> diff --git a/drivers/md/md.c b/drivers/md/md.c
>> index ac85ec73a409..4ea956a80343 100644
>> --- a/drivers/md/md.c
>> +++ b/drivers/md/md.c
>> @@ -4835,6 +4835,16 @@ metadata_store(struct mddev *mddev, const char 
>> *buf, size_t len)
>>   static struct md_sysfs_entry md_metadata =
>>   __ATTR_PREALLOC(metadata_version, S_IRUGO|S_IWUSR, metadata_show, 
>> metadata_store);
>>   +static bool rdev_needs_recovery(struct md_rdev *rdev, sector_t 
>> sectors)
>> +{
>> +    if (!test_bit(Journal, &rdev->flags) &&
>> +        !test_bit(Faulty, &rdev->flags) &&
>> +        !test_bit(In_sync, &rdev->flags) &&
>> +        rdev->recovery_offset < sectors)
>> +        return true;
>> +    return false;
> return directly:
>
> return !test_bit(Journal, &rdev->flags) &&
>     !test_bit(Faulty, &rdev->flags) &&
>     !test_bit(In_sync, &rdev->flags) &&
>     rdev->recovery_offset < sectors);
>
Okay.


Thanks,

Qixing


> Otherwise, feel free to add
> Reviewed-by: Yu Kuai <yukuai3@huawei.com>
>
> Kuai
>
>> +}
>> +
>>   enum sync_action md_sync_action(struct mddev *mddev)
>>   {
>>       unsigned long recovery = mddev->recovery;
>> @@ -8969,10 +8979,7 @@ static sector_t md_sync_position(struct mddev 
>> *mddev, enum sync_action action)
>>           rcu_read_lock();
>>           rdev_for_each_rcu(rdev, mddev)
>>               if (rdev->raid_disk >= 0 &&
>> -                !test_bit(Journal, &rdev->flags) &&
>> -                !test_bit(Faulty, &rdev->flags) &&
>> -                !test_bit(In_sync, &rdev->flags) &&
>> -                rdev->recovery_offset < start)
>> +                rdev_needs_recovery(rdev, start))
>>                   start = rdev->recovery_offset;
>>           rcu_read_unlock();
>>   @@ -9333,10 +9340,7 @@ void md_do_sync(struct md_thread *thread)
>>                   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_needs_recovery(rdev, mddev->curr_resync))
>>                           rdev->recovery_offset = mddev->curr_resync;
>>                   rcu_read_unlock();
>>               }
>>


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-08-14  1:24 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-12  2:17 [PATCH v2 0/2] md: fix sync_action show Zheng Qixing
2025-08-12  2:17 ` [PATCH v2 1/2] md: add helper rdev_needs_recovery() Zheng Qixing
2025-08-12  7:38   ` Paul Menzel
2025-08-14  0:52   ` Yu Kuai
2025-08-14  1:24     ` Zheng Qixing
2025-08-12  2:17 ` [PATCH v2 2/2] md: fix sync_action incorrect display during resync Zheng Qixing
2025-08-12  9:22   ` Paul Menzel
2025-08-12 11:03     ` Zheng Qixing

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).