md: use md_free_cloned_bio() in md_end_clone_io()
PATCH v2 1/1 md: use md_free_cloned_bio() in md_end_clone_io()
md_end_clone_io() and md_free_cloned_bio() share identical teardown logic. Use md_free_cloned_bio() in md_end_clone_io() for cleanup and call bio_endio() afterwards.
---
Changes in v2:
- Reuse md_free_cloned_bio() instead of introducing a new helper
- Link to v1: https://lore.kernel.org/linux-raid/[email protected]
--- drivers/md/md.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-)
drivers/md/md.c +1 -12
@@ -9212,20 +9212,9 @@ static void md_end_clone_io(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); +md_free_cloned_bio (bio);bio_endio (orig_bio); -percpu_ref_put (&mddev->active_io); }static void md_clone_bio (struct mddev *mddev,struct bio **bio)
Signature · 1 line
2.43.0
Quoted 25 lines · Abd-Alrhman Masalkhi
md_end_clone_io()andmd_free_cloned_bio()share identical teardown logic. Usemd_free_cloned_bio()inmd_end_clone_io()for cleanup and callbio_endio()afterwards.Signed-off-by Abd-Alrhman Masalkhi <[email protected]>---
Changes in v2:
- Reusemd_free_cloned_bio()instead of introducing a new helper
- Link to v1: https://lore.kernel.org/linux-raid/[email protected]--- drivers/md/md.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-)drivers/md/md.c +0
-4@@ -9212,20 +9212,9 @@ static void md_end_clone_io(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);
drivers/md/md.c static void md_end_clone_io(struct bio *bio) · line 9217
Quoted 10 lines
drivers/md/md.c +1
-7- -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); +md_free_cloned_bio (bio);bio_endio (orig_bio);
Is it safe to end orig_bio after putting active_io?
Quoted 4 lines
drivers/md/md.c +0
-1-percpu_ref_put (&mddev->active_io); }static void md_clone_bio (struct mddev *mddev,struct bio **bio)
Signature · 2 lines
Thanks, Nan
Hi Nan,
thank you for the feedback.
Quoted 33 lines · Li Nan
Quoted 32 lines · Abd-Alrhman Masalkhi
md_end_clone_io()andmd_free_cloned_bio()share identical teardown logic. Usemd_free_cloned_bio()inmd_end_clone_io()for cleanup and callbio_endio()afterwards.Signed-off-by Abd-Alrhman Masalkhi <[email protected]>---
Changes in v2:
- Reusemd_free_cloned_bio()instead of introducing a new helper
- Link to v1: https://lore.kernel.org/linux-raid/[email protected]--- drivers/md/md.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-)drivers/md/md.c +0
-10@@ -9212,20 +9212,9 @@ static void md_end_clone_io(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);
Quoted 5 lines
drivers/md/md.c static void md_end_clone_io(struct bio *bio) · line 9217
Quoted 3 lines
drivers/md/md.c +1
-1-bio_put (bio); +md_free_cloned_bio (bio);bio_endio (orig_bio);Is it safe to end
orig_bioafter puttingactive_io?
As I understand it, active_io is primarily used to account for in-flight bios, allowing the array to be safely suspended once no bios are outstanding.
I have made a diagram, while i am reviewing the md driver:
mddev->active_io
md driver:md_handle_request()
mddev->active_io +1
pers->make_request()
md_account_bio() +1
if (err)
md_free_cloned_bio -1
mddev->active_io -1lower driver:bio_endio()
md_end_clone_io -1
As shown, it incremented in two places, the first is before passing orig_bio to pers->make_request(), and decremented after it returns (regardless of what make_request() does with it). and the second is when cloning the original bio, and it should be decremented after the cloned bio is released.
In this context, it should not matter whether bio_endio(orig_bio) is called before or after decrementing active_io, as long as the cloned bio teardown is completed correctly.
Am I missing anything that would make this unsafe?
Quoted 10 lines
Quoted 5 lines
drivers/md/md.c +0
-1-percpu_ref_put (&mddev->active_io); }static void md_clone_bio (struct mddev *mddev,struct bio **bio)Signature · 2 lines
Thanks, Nan
Signature · 2 lines
Best Regards, Abd-Alrhman
Li Nan
Reviewed-byQuoted 71 lines · Abd-Alrhman Masalkhi
Hi Nan,
thank you for the feedback.
Quoted 33 lines · Li Nan
Quoted 32 lines · Abd-Alrhman Masalkhi
md_end_clone_io()andmd_free_cloned_bio()share identical teardown logic. Usemd_free_cloned_bio()inmd_end_clone_io()for cleanup and callbio_endio()afterwards.Signed-off-by Abd-Alrhman Masalkhi <[email protected]>---
Changes in v2:
- Reusemd_free_cloned_bio()instead of introducing a new helper
- Link to v1: https://lore.kernel.org/linux-raid/[email protected]--- drivers/md/md.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-)drivers/md/md.c +0
-10@@ -9212,20 +9212,9 @@ static void md_end_clone_io(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);Quoted 5 lines
drivers/md/md.c static void md_end_clone_io(struct bio *bio) · line 9217
Quoted 3 lines
drivers/md/md.c +1
-1-bio_put (bio); +md_free_cloned_bio (bio);bio_endio (orig_bio);Is it safe to end
orig_bioafter puttingactive_io?As I understand it,
active_iois primarily used to account for in-flight bios, allowing the array to be safely suspended once no bios are outstanding.I have made a diagram, while i am reviewing the md driver:
mddev->active_iomd driver:
md_handle_request()mddev->active_io +1 pers->make_request() md_account_bio() +1 if (err) md_free_cloned_bio -1 mddev->active_io -1lower driver:
bio_endio()md_end_clone_io -1As shown, it incremented in two places, the first is before passing
orig_biotopers->make_request(), and decremented after it returns (regardless of whatmake_request()does with it). and the second is when cloning the original bio, and it should be decremented after the cloned bio is released.
Quoted 6 lines
In this context, it should not matter whether
bio_endio(orig_bio)is called before or after decrementingactive_io, as long as the cloned bio teardown is completed correctly.Am I missing anything that would make this unsafe?
Thanks for your reply, LGTM.
Signature · 2 lines
Thanks, Nan
Hi,
Quoted 29 lines · Abd-Alrhman Masalkhi
md_end_clone_io()andmd_free_cloned_bio()share identical teardown logic. Usemd_free_cloned_bio()inmd_end_clone_io()for cleanup and callbio_endio()afterwards.Signed-off-by Abd-Alrhman Masalkhi <[email protected]>---
Changes in v2:
- Reusemd_free_cloned_bio()instead of introducing a new helper
- Link to v1: https://lore.kernel.org/linux-raid/[email protected]--- drivers/md/md.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-)drivers/md/md.c +0
-8@@ -9212,20 +9212,9 @@ static void md_end_clone_io(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; -
drivers/md/md.c static void md_end_clone_io(struct bio *bio) · line 9220
Quoted 10 lines
drivers/md/md.c +1
-4-if (md_io_clone->start_time) -bio_end_io_acct (orig_bio, md_io_clone->start_time); -bio_put (bio); +md_free_cloned_bio (bio);bio_endio (orig_bio); -percpu_ref_put (&mddev->active_io); }static void md_clone_bio (struct mddev *mddev,struct bio **bio)
Same as I replied to v1,
This patch is no longer needed after following patch:
https://lore.kernel.org/r/[email protected]
Signature · 2 lines
Thansk, Kuai
Hi Kuai,
Quoted 41 lines · Yu Kuai
Hi,
Quoted 38 lines · Abd-Alrhman Masalkhi
md_end_clone_io()andmd_free_cloned_bio()share identical teardown logic. Usemd_free_cloned_bio()inmd_end_clone_io()for cleanup and callbio_endio()afterwards.Signed-off-by Abd-Alrhman Masalkhi <[email protected]>---
Changes in v2:
- Reusemd_free_cloned_bio()instead of introducing a new helper
- Link to v1: https://lore.kernel.org/linux-raid/[email protected]--- drivers/md/md.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-)drivers/md/md.c +1
-12@@ -9212,20 +9212,9 @@ static void md_end_clone_io(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); +md_free_cloned_bio (bio);bio_endio (orig_bio); -percpu_ref_put (&mddev->active_io); }
Quoted 5 lines
drivers/md/md.c static void md_end_clone_io(struct bio *bio) · line 9220
Quoted 1 line
drivers/md/md.c +0
-0static void md_clone_bio (struct mddev *mddev,struct bio **bio)Same as I replied to v1,
This patch is no longer needed after following patch:
https://lore.kernel.org/r/[email protected]
Thanks, I'll drop this patch.
Quoted 4 lines
Signature · 3 lines
-- Thansk, Kuai
Signature · 2 lines
Best Regards, Abd-Alrhman