From: Mikulas Patocka <mpatocka@redhat.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: Li Nan <linan666@huaweicloud.com>,
Zdenek Kabelac <zkabelac@redhat.com>,
Christoph Hellwig <hch@infradead.org>,
Chaitanya Kulkarni <chaitanyak@nvidia.com>,
linux-block@vger.kernel.org, dm-devel@redhat.com
Subject: [PATCH v3 1/4] brd: use a switch statement in brd_submit_bio
Date: Thu, 10 Aug 2023 12:08:39 +0200 (CEST) [thread overview]
Message-ID: <ee59ce87-9e5-c725-8040-80c5e0fd48f@redhat.com> (raw)
In-Reply-To: <2dacc73-854-e71c-1746-99b017401c9a@redhat.com>
Use a switch statement in brd_submit_bio, so that the code will look
better when we add support for more bio operations.
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
---
drivers/block/brd.c | 43 ++++++++++++++++++++++++++-----------------
1 file changed, 26 insertions(+), 17 deletions(-)
Index: linux-2.6/drivers/block/brd.c
===================================================================
--- linux-2.6.orig/drivers/block/brd.c
+++ linux-2.6/drivers/block/brd.c
@@ -243,29 +243,38 @@ out:
static void brd_submit_bio(struct bio *bio)
{
struct brd_device *brd = bio->bi_bdev->bd_disk->private_data;
- sector_t sector = bio->bi_iter.bi_sector;
+ sector_t sector;
struct bio_vec bvec;
struct bvec_iter iter;
- bio_for_each_segment(bvec, bio, iter) {
- unsigned int len = bvec.bv_len;
- int err;
+ switch (bio_op(bio)) {
+ case REQ_OP_READ:
+ case REQ_OP_WRITE:
+ sector = bio->bi_iter.bi_sector;
+ bio_for_each_segment(bvec, bio, iter) {
+ unsigned int len = bvec.bv_len;
+ int err;
- /* Don't support un-aligned buffer */
- WARN_ON_ONCE((bvec.bv_offset & (SECTOR_SIZE - 1)) ||
- (len & (SECTOR_SIZE - 1)));
+ /* Don't support un-aligned buffer */
+ WARN_ON_ONCE((bvec.bv_offset & (SECTOR_SIZE - 1)) ||
+ (len & (SECTOR_SIZE - 1)));
- err = brd_do_bvec(brd, bvec.bv_page, len, bvec.bv_offset,
- bio->bi_opf, sector);
- if (err) {
- if (err == -ENOMEM && bio->bi_opf & REQ_NOWAIT) {
- bio_wouldblock_error(bio);
- return;
+ err = brd_do_bvec(brd, bvec.bv_page, len, bvec.bv_offset,
+ bio->bi_opf, sector);
+ if (err) {
+ if (err == -ENOMEM && bio->bi_opf & REQ_NOWAIT) {
+ bio_wouldblock_error(bio);
+ return;
+ }
+ bio_io_error(bio);
+ return;
+ }
+ sector += len >> SECTOR_SHIFT;
}
- bio_io_error(bio);
- return;
- }
- sector += len >> SECTOR_SHIFT;
+ break;
+ default:
+ bio->bi_status = BLK_STS_NOTSUPP;
+ break;
}
bio_endio(bio);
next prev parent reply other threads:[~2023-08-10 10:09 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-10 10:07 [PATCH v3 0/4] brd discard patches Mikulas Patocka
2023-08-10 10:08 ` Mikulas Patocka [this message]
2023-08-10 10:09 ` [PATCH v3 2/4] brd: extend the rcu regions to cover read and write Mikulas Patocka
2023-08-10 10:09 ` [PATCH v3 3/4] brd: enable discard Mikulas Patocka
2023-08-10 10:10 ` [PATCH v3 4/4] brd: implement write zeroes Mikulas Patocka
2023-11-10 1:22 ` [PATCH v3 0/4] brd discard patches Li Nan
2023-11-14 13:59 ` Mikulas Patocka
2024-01-19 8:41 ` Ming Lei
2024-01-22 16:30 ` Mikulas Patocka
2024-01-23 2:49 ` Ming Lei
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=ee59ce87-9e5-c725-8040-80c5e0fd48f@redhat.com \
--to=mpatocka@redhat.com \
--cc=axboe@kernel.dk \
--cc=chaitanyak@nvidia.com \
--cc=dm-devel@redhat.com \
--cc=hch@infradead.org \
--cc=linan666@huaweicloud.com \
--cc=linux-block@vger.kernel.org \
--cc=zkabelac@redhat.com \
/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