diff options
author | Pavel Begunkov <asml.silence@gmail.com> | 2025-03-08 18:21:15 +0000 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2025-03-10 07:14:27 -0600 |
commit | d291fb65202051e996cd983b29dce3e390421bc6 (patch) | |
tree | b123bfa5630d496b8699cd4e499d7f2f8d67b9fb /io_uring/rsrc.c | |
parent | 5027d02452c982bdc7b36205c66466ebd7e6ee17 (diff) |
io_uring: introduce io_prep_reg_iovec()
iovecs that are turned into registered buffers are imported in a special
way with an offset, so that later we can do an in place translation. Add
a helper function taking care of it.
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/7de2ecb9ed5efc3c5cf320232236966da5ad4ccc.1741457480.git.asml.silence@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'io_uring/rsrc.c')
-rw-r--r-- | io_uring/rsrc.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c index 71fe47facd4c..0e413e910f3d 100644 --- a/io_uring/rsrc.c +++ b/io_uring/rsrc.c @@ -1397,3 +1397,29 @@ int io_import_reg_vec(int ddir, struct iov_iter *iter, return io_vec_fill_bvec(ddir, iter, imu, iov, nr_iovs, vec); } + +int io_prep_reg_iovec(struct io_kiocb *req, struct iou_vec *iv, + const struct iovec __user *uvec, size_t uvec_segs) +{ + struct iovec *iov; + int iovec_off, ret; + void *res; + + if (uvec_segs > iv->nr) { + ret = io_vec_realloc(iv, uvec_segs); + if (ret) + return ret; + req->flags |= REQ_F_NEED_CLEANUP; + } + + /* pad iovec to the right */ + iovec_off = iv->nr - uvec_segs; + iov = iv->iovec + iovec_off; + res = iovec_from_user(uvec, uvec_segs, uvec_segs, iov, + io_is_compat(req->ctx)); + if (IS_ERR(res)) + return PTR_ERR(res); + + req->flags |= REQ_F_IMPORT_BUFFER; + return 0; +} |