public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] md: factor out cloned bio cleanup into md_free_bio()
@ 2026-04-14 10:38 Abd-Alrhman Masalkhi
  2026-04-15  2:27 ` Li Nan
  0 siblings, 1 reply; 3+ messages in thread
From: Abd-Alrhman Masalkhi @ 2026-04-14 10:38 UTC (permalink / raw)
  To: song, yukuai; +Cc: linux-raid, linux-kernel, Abd-Alrhman Masalkhi

Refactor duplicated cloned bio completion and cleanup logic into
a new helper, md_free_bio().

md_end_clone_io() and md_free_cloned_bio() previously shared nearly
identical teardown code, differing only in whether the original
bio’s endio callback was invoked. Introduce a boolean parameter
orig_endio to control this behavior and consolidate the logic.

Signed-off-by: Abd-Alrhman Masalkhi <abd.masalkhi@gmail.com>
---
 drivers/md/md.c | 26 +++++++++-----------------
 1 file changed, 9 insertions(+), 17 deletions(-)

diff --git a/drivers/md/md.c b/drivers/md/md.c
index ac71640ff3a8..707d605fee61 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -9208,7 +9208,7 @@ static void md_bitmap_end(struct mddev *mddev, struct md_io_clone *md_io_clone)
 	fn(mddev, md_io_clone->offset, md_io_clone->sectors);
 }
 
-static void md_end_clone_io(struct bio *bio)
+static void md_free_bio(struct bio *bio, bool orig_endio)
 {
 	struct md_io_clone *md_io_clone = bio->bi_private;
 	struct bio *orig_bio = md_io_clone->orig_bio;
@@ -9224,10 +9224,16 @@ static void md_end_clone_io(struct bio *bio)
 		bio_end_io_acct(orig_bio, md_io_clone->start_time);
 
 	bio_put(bio);
-	bio_endio(orig_bio);
+	if (orig_endio)
+		bio_endio(orig_bio);
 	percpu_ref_put(&mddev->active_io);
 }
 
+static void md_end_clone_io(struct bio *bio)
+{
+	md_free_bio(bio, true);
+}
+
 static void md_clone_bio(struct mddev *mddev, struct bio **bio)
 {
 	struct block_device *bdev = (*bio)->bi_bdev;
@@ -9262,21 +9268,7 @@ EXPORT_SYMBOL_GPL(md_account_bio);
 
 void md_free_cloned_bio(struct bio *bio)
 {
-	struct md_io_clone *md_io_clone = bio->bi_private;
-	struct bio *orig_bio = md_io_clone->orig_bio;
-	struct mddev *mddev = md_io_clone->mddev;
-
-	if (bio_data_dir(orig_bio) == WRITE && md_bitmap_enabled(mddev, false))
-		md_bitmap_end(mddev, md_io_clone);
-
-	if (bio->bi_status && !orig_bio->bi_status)
-		orig_bio->bi_status = bio->bi_status;
-
-	if (md_io_clone->start_time)
-		bio_end_io_acct(orig_bio, md_io_clone->start_time);
-
-	bio_put(bio);
-	percpu_ref_put(&mddev->active_io);
+	md_free_bio(bio, false);
 }
 EXPORT_SYMBOL_GPL(md_free_cloned_bio);
 
-- 
2.43.0


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

* Re: [PATCH] md: factor out cloned bio cleanup into md_free_bio()
  2026-04-14 10:38 [PATCH] md: factor out cloned bio cleanup into md_free_bio() Abd-Alrhman Masalkhi
@ 2026-04-15  2:27 ` Li Nan
  2026-04-15  7:48   ` Abd-Alrhman Masalkhi
  0 siblings, 1 reply; 3+ messages in thread
From: Li Nan @ 2026-04-15  2:27 UTC (permalink / raw)
  To: Abd-Alrhman Masalkhi, song, yukuai
  Cc: linux-raid, linux-kernel, yangerkun@huawei.com



在 2026/4/14 18:38, Abd-Alrhman Masalkhi 写道:
> Refactor duplicated cloned bio completion and cleanup logic into
> a new helper, md_free_bio().
> 
> md_end_clone_io() and md_free_cloned_bio() previously shared nearly
> identical teardown code, differing only in whether the original
> bio’s endio callback was invoked. Introduce a boolean parameter
> orig_endio to control this behavior and consolidate the logic.
> 
> Signed-off-by: Abd-Alrhman Masalkhi <abd.masalkhi@gmail.com>
> ---
>   drivers/md/md.c | 26 +++++++++-----------------
>   1 file changed, 9 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index ac71640ff3a8..707d605fee61 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -9208,7 +9208,7 @@ static void md_bitmap_end(struct mddev *mddev, struct md_io_clone *md_io_clone)
>   	fn(mddev, md_io_clone->offset, md_io_clone->sectors);
>   }
>   
> -static void md_end_clone_io(struct bio *bio)
> +static void md_free_bio(struct bio *bio, bool orig_endio)
>   {
>   	struct md_io_clone *md_io_clone = bio->bi_private;
>   	struct bio *orig_bio = md_io_clone->orig_bio;
> @@ -9224,10 +9224,16 @@ static void md_end_clone_io(struct bio *bio)
>   		bio_end_io_acct(orig_bio, md_io_clone->start_time);
>   
>   	bio_put(bio);
> -	bio_endio(orig_bio);
> +	if (orig_endio)
> +		bio_endio(orig_bio);
>   	percpu_ref_put(&mddev->active_io);
>   }
>   
> +static void md_end_clone_io(struct bio *bio)
> +{
> +	md_free_bio(bio, true);
> +}
> +
>   static void md_clone_bio(struct mddev *mddev, struct bio **bio)
>   {
>   	struct block_device *bdev = (*bio)->bi_bdev;
> @@ -9262,21 +9268,7 @@ EXPORT_SYMBOL_GPL(md_account_bio);
>   
>   void md_free_cloned_bio(struct bio *bio)
>   {
> -	struct md_io_clone *md_io_clone = bio->bi_private;
> -	struct bio *orig_bio = md_io_clone->orig_bio;
> -	struct mddev *mddev = md_io_clone->mddev;
> -
> -	if (bio_data_dir(orig_bio) == WRITE && md_bitmap_enabled(mddev, false))
> -		md_bitmap_end(mddev, md_io_clone);
> -
> -	if (bio->bi_status && !orig_bio->bi_status)
> -		orig_bio->bi_status = bio->bi_status;
> -
> -	if (md_io_clone->start_time)
> -		bio_end_io_acct(orig_bio, md_io_clone->start_time);
> -
> -	bio_put(bio);
> -	percpu_ref_put(&mddev->active_io);
> +	md_free_bio(bio, false);
>   }
>   EXPORT_SYMBOL_GPL(md_free_cloned_bio);
>   

md_free_bio() is redundant. Can md_end_clone_io() directly call
md_free_cloned_bio()?

We do not need to consider the compatibility of the EXPORT_SYMBOL in
mainline.

-- 
Thanks,
Nan


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

* Re: [PATCH] md: factor out cloned bio cleanup into md_free_bio()
  2026-04-15  2:27 ` Li Nan
@ 2026-04-15  7:48   ` Abd-Alrhman Masalkhi
  0 siblings, 0 replies; 3+ messages in thread
From: Abd-Alrhman Masalkhi @ 2026-04-15  7:48 UTC (permalink / raw)
  To: Li Nan, song, yukuai; +Cc: linux-raid, linux-kernel, yangerkun@huawei.com

On Wed, Apr 15, 2026 at 10:27 +0800, Li Nan wrote:
> 在 2026/4/14 18:38, Abd-Alrhman Masalkhi 写道:
>> Refactor duplicated cloned bio completion and cleanup logic into
>> a new helper, md_free_bio().
>> 
>> md_end_clone_io() and md_free_cloned_bio() previously shared nearly
>> identical teardown code, differing only in whether the original
>> bio’s endio callback was invoked. Introduce a boolean parameter
>> orig_endio to control this behavior and consolidate the logic.
>> 
>> Signed-off-by: Abd-Alrhman Masalkhi <abd.masalkhi@gmail.com>
>> ---
>>   drivers/md/md.c | 26 +++++++++-----------------
>>   1 file changed, 9 insertions(+), 17 deletions(-)
>> 
>> diff --git a/drivers/md/md.c b/drivers/md/md.c
>> index ac71640ff3a8..707d605fee61 100644
>> --- a/drivers/md/md.c
>> +++ b/drivers/md/md.c
>> @@ -9208,7 +9208,7 @@ static void md_bitmap_end(struct mddev *mddev, struct md_io_clone *md_io_clone)
>>   	fn(mddev, md_io_clone->offset, md_io_clone->sectors);
>>   }
>>   
>> -static void md_end_clone_io(struct bio *bio)
>> +static void md_free_bio(struct bio *bio, bool orig_endio)
>>   {
>>   	struct md_io_clone *md_io_clone = bio->bi_private;
>>   	struct bio *orig_bio = md_io_clone->orig_bio;
>> @@ -9224,10 +9224,16 @@ static void md_end_clone_io(struct bio *bio)
>>   		bio_end_io_acct(orig_bio, md_io_clone->start_time);
>>   
>>   	bio_put(bio);
>> -	bio_endio(orig_bio);
>> +	if (orig_endio)
>> +		bio_endio(orig_bio);
>>   	percpu_ref_put(&mddev->active_io);
>>   }
>>   
>> +static void md_end_clone_io(struct bio *bio)
>> +{
>> +	md_free_bio(bio, true);
>> +}
>> +
>>   static void md_clone_bio(struct mddev *mddev, struct bio **bio)
>>   {
>>   	struct block_device *bdev = (*bio)->bi_bdev;
>> @@ -9262,21 +9268,7 @@ EXPORT_SYMBOL_GPL(md_account_bio);
>>   
>>   void md_free_cloned_bio(struct bio *bio)
>>   {
>> -	struct md_io_clone *md_io_clone = bio->bi_private;
>> -	struct bio *orig_bio = md_io_clone->orig_bio;
>> -	struct mddev *mddev = md_io_clone->mddev;
>> -
>> -	if (bio_data_dir(orig_bio) == WRITE && md_bitmap_enabled(mddev, false))
>> -		md_bitmap_end(mddev, md_io_clone);
>> -
>> -	if (bio->bi_status && !orig_bio->bi_status)
>> -		orig_bio->bi_status = bio->bi_status;
>> -
>> -	if (md_io_clone->start_time)
>> -		bio_end_io_acct(orig_bio, md_io_clone->start_time);
>> -
>> -	bio_put(bio);
>> -	percpu_ref_put(&mddev->active_io);
>> +	md_free_bio(bio, false);
>>   }
>>   EXPORT_SYMBOL_GPL(md_free_cloned_bio);
>>   
>
> md_free_bio() is redundant. Can md_end_clone_io() directly call
> md_free_cloned_bio()?
>
> We do not need to consider the compatibility of the EXPORT_SYMBOL in
> mainline.
>
Thanks for the feedback!

You're right, this can be simplified. I'll send a v2 shortly.
> -- 
> Thanks,
> Nan
>

-- 
Best Regards,
Abd-Alrhman

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

end of thread, other threads:[~2026-04-15  7:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-14 10:38 [PATCH] md: factor out cloned bio cleanup into md_free_bio() Abd-Alrhman Masalkhi
2026-04-15  2:27 ` Li Nan
2026-04-15  7:48   ` Abd-Alrhman Masalkhi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox