From: Andreas Gruenbacher <agruenba@redhat.com>
To: Christoph Hellwig <hch@infradead.org>,
Jens Axboe <axboe@kernel.dk>, Chris Mason <clm@fb.com>,
David Sterba <dsterba@suse.com>
Cc: Andreas Gruenbacher <agruenba@redhat.com>,
linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org,
linux-raid@vger.kernel.org, dm-devel@lists.linux.dev,
linux-kernel@vger.kernel.org
Subject: [RFC 06/12] bio: don't check target->bi_status on error
Date: Mon, 8 Dec 2025 12:10:13 +0000 [thread overview]
Message-ID: <20251208121020.1780402-7-agruenba@redhat.com> (raw)
In-Reply-To: <20251208121020.1780402-1-agruenba@redhat.com>
In a few places, target->bi_status is set to source->bi_status only if
source->bi_status is not 0 and target->bi_status is (still) 0. Here,
checking the value of target->bi_status before setting it is an
unnecessary micro optimization because we are already on an error path.
In addition, we can be racing with other execution contexts in the case
of chained bios, so there is no guarantee that target->bi_status won't
be set concurrently. We don't require atomic test-and-set semantics
here.
Created with Coccinelle using the following semantic patch:
@@
struct bio *source;
struct bio *target;
@@
- if (source->bi_status && !target->bi_status)
- target->bi_status = source->bi_status;
+ bio_set_status(target, source->bi_status);
@@
struct bio *source;
struct bio target;
@@
- if (source->bi_status && !target.bi_status)
- target.bi_status = source->bi_status;
+ bio_set_status(&target, source->bi_status);
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
---
block/bio.c | 3 +--
block/fops.c | 3 +--
drivers/md/md.c | 6 ++----
3 files changed, 4 insertions(+), 8 deletions(-)
diff --git a/block/bio.c b/block/bio.c
index 3f408e1ba13f..5389321872f0 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -314,8 +314,7 @@ static struct bio *__bio_chain_endio(struct bio *bio)
{
struct bio *parent = bio->bi_private;
- if (bio->bi_status && !parent->bi_status)
- parent->bi_status = bio->bi_status;
+ bio_set_status(parent, bio->bi_status);
bio_put(bio);
return parent;
}
diff --git a/block/fops.c b/block/fops.c
index b4f911273289..a4a6972cbfbf 100644
--- a/block/fops.c
+++ b/block/fops.c
@@ -135,8 +135,7 @@ static void blkdev_bio_end_io(struct bio *bio)
bool should_dirty = dio->flags & DIO_SHOULD_DIRTY;
bool is_sync = dio->flags & DIO_IS_SYNC;
- if (bio->bi_status && !dio->bio.bi_status)
- dio->bio.bi_status = bio->bi_status;
+ bio_set_status(&dio->bio, bio->bi_status);
if (bio_integrity(bio))
bio_integrity_unmap_user(bio);
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 41c476b40c7a..f6f1aab18a8b 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -9084,8 +9084,7 @@ static void md_end_clone_io(struct bio *bio)
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;
+ bio_set_status(orig_bio, bio->bi_status);
if (md_io_clone->start_time)
bio_end_io_acct(orig_bio, md_io_clone->start_time);
@@ -9136,8 +9135,7 @@ void md_free_cloned_bio(struct bio *bio)
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;
+ bio_set_status(orig_bio, bio->bi_status);
if (md_io_clone->start_time)
bio_end_io_acct(orig_bio, md_io_clone->start_time);
--
2.51.0
next prev parent reply other threads:[~2025-12-08 12:10 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-08 12:10 [RFC 00/12] bio cleanups Andreas Gruenbacher
2025-12-08 12:10 ` [RFC 01/12] bio: rename bio_chain arguments Andreas Gruenbacher
2025-12-16 7:57 ` Christoph Hellwig
2025-12-08 12:10 ` [RFC 02/12] bio: use bio_io_error more often Andreas Gruenbacher
2025-12-16 7:57 ` Christoph Hellwig
2025-12-08 12:10 ` [RFC 03/12] bio: add bio_set_errno Andreas Gruenbacher
2025-12-16 7:58 ` Christoph Hellwig
2025-12-08 12:10 ` [RFC 04/12] bio: use bio_set_errno in more places Andreas Gruenbacher
2025-12-08 12:10 ` [RFC 05/12] bio: add bio_set_status Andreas Gruenbacher
2025-12-16 7:59 ` Christoph Hellwig
2025-12-08 12:10 ` Andreas Gruenbacher [this message]
2025-12-16 7:59 ` [RFC 06/12] bio: don't check target->bi_status on error Christoph Hellwig
2025-12-16 8:41 ` Andreas Gruenbacher
2025-12-16 10:44 ` Christoph Hellwig
2025-12-16 11:20 ` Andreas Gruenbacher
2025-12-18 8:47 ` Christoph Hellwig
2025-12-19 20:14 ` Andreas Gruenbacher
2025-12-08 12:10 ` [RFC 07/12] bio: use bio_set_status for BLK_STS_* status codes Andreas Gruenbacher
2025-12-08 12:10 ` [RFC 08/12] bio: use bio_set_status in some more places Andreas Gruenbacher
2025-12-08 12:10 ` [RFC 09/12] bio: switch to bio_set_status in submit_bio_noacct Andreas Gruenbacher
2025-12-08 12:10 ` [RFC 10/12] bio: never set bi_status to BLK_STS_OK during completion Andreas Gruenbacher
2025-12-08 12:10 ` [RFC 11/12] bio: add bio_endio_errno Andreas Gruenbacher
2025-12-16 8:00 ` Christoph Hellwig
2025-12-08 12:10 ` [RFC 12/12] bio: add bio_endio_status Andreas Gruenbacher
2025-12-16 8:01 ` Christoph Hellwig
2025-12-08 19:37 ` [RFC 00/12] bio cleanups David Sterba
2025-12-08 21:16 ` Andreas Gruenbacher
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251208121020.1780402-7-agruenba@redhat.com \
--to=agruenba@redhat.com \
--cc=axboe@kernel.dk \
--cc=clm@fb.com \
--cc=dm-devel@lists.linux.dev \
--cc=dsterba@suse.com \
--cc=hch@infradead.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-raid@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®