ublk: split out ublk_user_copy() helper

ublk_ch_read_iter() and ublk_ch_write_iter() are nearly identical except
for the iter direction. Split out a helper function ublk_user_copy() to
reduce the code duplication as these functions are about to get larger.

Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
Caleb Sander Mateos 2026-01-08 02:19:34 -07:00 committed by Jens Axboe
parent fc652d415c
commit 5bfbbc9938

View File

@ -2709,38 +2709,32 @@ static struct request *ublk_check_and_get_req(struct kiocb *iocb,
return ERR_PTR(-EACCES);
}
static ssize_t ublk_ch_read_iter(struct kiocb *iocb, struct iov_iter *to)
static ssize_t
ublk_user_copy(struct kiocb *iocb, struct iov_iter *iter, int dir)
{
struct request *req;
struct ublk_io *io;
size_t buf_off;
size_t ret;
req = ublk_check_and_get_req(iocb, to, &buf_off, ITER_DEST, &io);
req = ublk_check_and_get_req(iocb, iter, &buf_off, dir, &io);
if (IS_ERR(req))
return PTR_ERR(req);
ret = ublk_copy_user_pages(req, buf_off, to, ITER_DEST);
ret = ublk_copy_user_pages(req, buf_off, iter, dir);
ublk_put_req_ref(io, req);
return ret;
}
static ssize_t ublk_ch_read_iter(struct kiocb *iocb, struct iov_iter *to)
{
return ublk_user_copy(iocb, to, ITER_DEST);
}
static ssize_t ublk_ch_write_iter(struct kiocb *iocb, struct iov_iter *from)
{
struct request *req;
struct ublk_io *io;
size_t buf_off;
size_t ret;
req = ublk_check_and_get_req(iocb, from, &buf_off, ITER_SOURCE, &io);
if (IS_ERR(req))
return PTR_ERR(req);
ret = ublk_copy_user_pages(req, buf_off, from, ITER_SOURCE);
ublk_put_req_ref(io, req);
return ret;
return ublk_user_copy(iocb, from, ITER_SOURCE);
}
static const struct file_operations ublk_ch_fops = {