From: Ming Lei <ming.lei@redhat.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org,
ZiyangZhang <ZiyangZhang@linux.alibaba.com>,
Ming Lei <ming.lei@redhat.com>
Subject: [PATCH 5/7] ublk: support to copy any part of request pages
Date: Thu, 20 Apr 2023 23:40:30 +0800 [thread overview]
Message-ID: <20230420154032.1272836-6-ming.lei@redhat.com> (raw)
In-Reply-To: <20230420154032.1272836-1-ming.lei@redhat.com>
Add 'offset' to 'struct ublk_map_data', so that ublk_copy_user_pages()
can be used to copy any sub-buffer(linear mapped) of the request.
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
drivers/block/ublk_drv.c | 31 ++++++++++++++++++++++++-------
1 file changed, 24 insertions(+), 7 deletions(-)
diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
index 11ce55f0c395..7d21ee22e503 100644
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -504,19 +504,36 @@ static void ublk_copy_io_pages(struct ublk_io_iter *data,
}
}
+static bool ublk_advance_io_iter(const struct request *req,
+ struct ublk_io_iter *iter, unsigned int offset)
+{
+ struct bio *bio = req->bio;
+
+ for_each_bio(bio) {
+ if (bio->bi_iter.bi_size > offset) {
+ iter->bio = bio;
+ iter->iter = bio->bi_iter;
+ bio_advance_iter(iter->bio, &iter->iter, offset);
+ return true;
+ }
+ offset -= bio->bi_iter.bi_size;
+ }
+ return false;
+}
+
/*
* Copy data between request pages and io_iter, and 'offset'
* is the start point of linear offset of request.
*/
static size_t ublk_copy_user_pages(const struct request *req,
- struct iov_iter *uiter, int dir)
+ unsigned offset, struct iov_iter *uiter, int dir)
{
- struct ublk_io_iter iter = {
- .bio = req->bio,
- .iter = req->bio->bi_iter,
- };
+ struct ublk_io_iter iter;
size_t done = 0;
+ if (!ublk_advance_io_iter(req, &iter, offset))
+ return 0;
+
while (iov_iter_count(uiter) && iter.bio) {
unsigned nr_pages;
size_t len, off;
@@ -569,7 +586,7 @@ static int ublk_map_io(const struct ublk_queue *ubq, const struct request *req,
import_single_range(dir, u64_to_user_ptr(io->addr), rq_bytes,
&iov, &iter);
- return ublk_copy_user_pages(req, &iter, dir);
+ return ublk_copy_user_pages(req, 0, &iter, dir);
}
return rq_bytes;
}
@@ -589,7 +606,7 @@ static int ublk_unmap_io(const struct ublk_queue *ubq,
import_single_range(dir, u64_to_user_ptr(io->addr), io->res,
&iov, &iter);
- return ublk_copy_user_pages(req, &iter, dir);
+ return ublk_copy_user_pages(req, 0, &iter, dir);
}
return rq_bytes;
}
--
2.39.2
next prev parent reply other threads:[~2023-04-20 15:42 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-20 15:40 [PATCH 0/7] ublk: cleanup and support user copy Ming Lei
2023-04-20 15:40 ` [PATCH 1/7] ublk: kill queuing request by task_work_add Ming Lei
2023-04-20 15:40 ` [PATCH 2/7] ublk: cleanup io cmd code path by adding ublk_fill_io() Ming Lei
2023-04-20 15:40 ` [PATCH 3/7] ublk: cleanup ublk_copy_user_pages Ming Lei
2023-04-20 15:40 ` [PATCH 4/7] ublk: grab request reference when the request is handled by userspace Ming Lei
2023-04-20 15:40 ` Ming Lei [this message]
2023-04-20 15:40 ` [PATCH 6/7] ublk: add read()/write() support for ublk char device Ming Lei
2023-04-20 15:40 ` [PATCH 7/7] ublk: support user copy Ming Lei
2023-04-20 15:46 ` [PATCH 0/7] ublk: cleanup and " 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=20230420154032.1272836-6-ming.lei@redhat.com \
--to=ming.lei@redhat.com \
--cc=ZiyangZhang@linux.alibaba.com \
--cc=axboe@kernel.dk \
--cc=linux-block@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;
as well as URLs for NNTP newsgroup(s).