Commit 38f2dd34 authored by Ming Lei's avatar Ming Lei Committed by Jens Axboe

ublk: support to copy any part of request pages

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: default avatarMing Lei <ming.lei@redhat.com>
Link: https://lore.kernel.org/r/20230519065030.351216-6-ming.lei@redhat.comSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 82840669
......@@ -505,19 +505,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;
......@@ -570,7 +587,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;
}
......@@ -590,7 +607,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;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment