From: Christoph Hellwig <hch@lst.de>
To: Jens Axboe <axboe@kernel.dk>, Yu Kuai <yukuai1@huaweicloud.com>
Cc: linux-block@vger.kernel.org, Yu Kuai <yukuai3@huawei.com>,
Hannes Reinecke <hare@suse.de>
Subject: [PATCH 1/5] brd: pass a bvec pointer to brd_do_bvec
Date: Mon, 28 Apr 2025 07:09:47 -0700 [thread overview]
Message-ID: <20250428141014.2360063-2-hch@lst.de> (raw)
In-Reply-To: <20250428141014.2360063-1-hch@lst.de>
Pass the bvec to brd_do_bvec instead of marshalling the information into
individual arguments.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Yu Kuai <yukuai3@huawei.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
---
drivers/block/brd.c | 35 +++++++++++++----------------------
1 file changed, 13 insertions(+), 22 deletions(-)
diff --git a/drivers/block/brd.c b/drivers/block/brd.c
index 292f127cae0a..c8974bc545fb 100644
--- a/drivers/block/brd.c
+++ b/drivers/block/brd.c
@@ -189,12 +189,10 @@ static void copy_from_brd(void *dst, struct brd_device *brd,
/*
* Process a single bvec of a bio.
*/
-static int brd_do_bvec(struct brd_device *brd, struct page *page,
- unsigned int len, unsigned int off, blk_opf_t opf,
- sector_t sector)
+static int brd_rw_bvec(struct brd_device *brd, struct bio_vec *bv,
+ blk_opf_t opf, sector_t sector)
{
void *mem;
- int err = 0;
if (op_is_write(opf)) {
/*
@@ -202,24 +200,23 @@ static int brd_do_bvec(struct brd_device *brd, struct page *page,
* block or filesystem layers from page reclaim.
*/
gfp_t gfp = opf & REQ_NOWAIT ? GFP_NOWAIT : GFP_NOIO;
+ int err;
- err = copy_to_brd_setup(brd, sector, len, gfp);
+ err = copy_to_brd_setup(brd, sector, bv->bv_len, gfp);
if (err)
- goto out;
+ return err;
}
- mem = kmap_atomic(page);
+ mem = kmap_atomic(bv->bv_page);
if (!op_is_write(opf)) {
- copy_from_brd(mem + off, brd, sector, len);
- flush_dcache_page(page);
+ copy_from_brd(mem + bv->bv_offset, brd, sector, bv->bv_len);
+ flush_dcache_page(bv->bv_page);
} else {
- flush_dcache_page(page);
- copy_to_brd(brd, mem + off, sector, len);
+ flush_dcache_page(bv->bv_page);
+ copy_to_brd(brd, mem + bv->bv_offset, sector, bv->bv_len);
}
kunmap_atomic(mem);
-
-out:
- return err;
+ return 0;
}
static void brd_do_discard(struct brd_device *brd, sector_t sector, u32 size)
@@ -255,15 +252,9 @@ static void brd_submit_bio(struct bio *bio)
}
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)));
-
- err = brd_do_bvec(brd, bvec.bv_page, len, bvec.bv_offset,
- bio->bi_opf, sector);
+ err = brd_rw_bvec(brd, &bvec, bio->bi_opf, sector);
if (err) {
if (err == -ENOMEM && bio->bi_opf & REQ_NOWAIT) {
bio_wouldblock_error(bio);
@@ -272,7 +263,7 @@ static void brd_submit_bio(struct bio *bio)
bio_io_error(bio);
return;
}
- sector += len >> SECTOR_SHIFT;
+ sector += bvec.bv_len >> SECTOR_SHIFT;
}
bio_endio(bio);
--
2.47.2
next prev parent reply other threads:[~2025-04-28 14:10 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-28 14:09 brd cleanups v2 Christoph Hellwig
2025-04-28 14:09 ` Christoph Hellwig [this message]
2025-04-28 14:09 ` [PATCH 2/5] brd: remove the sector variable in brd_submit_bio Christoph Hellwig
2025-04-28 14:09 ` [PATCH 3/5] brd: use bvec_kmap_local in brd_do_bvec Christoph Hellwig
2025-04-28 14:09 ` [PATCH 4/5] brd: split I/O at page boundaries Christoph Hellwig
2025-04-28 18:07 ` Keith Busch
2025-04-29 1:38 ` Yu Kuai
2025-04-29 12:15 ` Christoph Hellwig
2025-04-29 21:17 ` Keith Busch
2025-04-28 14:09 ` [PATCH 5/5] brd: use memcpy_{to,from]_page in brd_rw_bvec Christoph Hellwig
2025-04-28 15:30 ` brd cleanups v2 Johannes Thumshirn
2025-04-28 17:46 ` Jens Axboe
-- strict thread matches above, loose matches on Subject: below --
2025-04-21 7:26 brd cleanups Christoph Hellwig
2025-04-21 7:26 ` [PATCH 1/5] brd; pass a bvec pointer to brd_do_bvec Christoph Hellwig
2025-04-22 6:36 ` Yu Kuai
2025-04-22 9:24 ` Hannes Reinecke
2025-04-28 9:21 ` Johannes Thumshirn
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=20250428141014.2360063-2-hch@lst.de \
--to=hch@lst.de \
--cc=axboe@kernel.dk \
--cc=hare@suse.de \
--cc=linux-block@vger.kernel.org \
--cc=yukuai1@huaweicloud.com \
--cc=yukuai3@huawei.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