Skip to content

Commit 6371c03

Browse files
axboeopsiff
authored andcommitted
io_uring/rw: mark readv/writev as vectored in the opcode definition
This is cleaner than gating on the opcode type, particularly as more read/write type opcodes may be added. Then we can use that for the data import, and for __io_read() on whether or not we need to copy state. Reviewed-by: Gabriel Krisman Bertazi <krisman@suse.de> Signed-off-by: Jens Axboe <axboe@kernel.dk> Conflicts: io_uring/rw.c [because of ("io_uring: add io_file_can_poll() helper") merged before] (cherry picked from commit d2d778f) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
1 parent 62d549e commit 6371c03

3 files changed

Lines changed: 10 additions & 4 deletions

File tree

io_uring/opdef.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ const struct io_issue_def io_issue_defs[] = {
6363
.ioprio = 1,
6464
.iopoll = 1,
6565
.iopoll_queue = 1,
66+
.vectored = 1,
6667
.prep = io_prep_rw,
6768
.issue = io_read,
6869
},
@@ -76,6 +77,7 @@ const struct io_issue_def io_issue_defs[] = {
7677
.ioprio = 1,
7778
.iopoll = 1,
7879
.iopoll_queue = 1,
80+
.vectored = 1,
7981
.prep = io_prep_rw,
8082
.issue = io_write,
8183
},

io_uring/opdef.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ struct io_issue_def {
2929
unsigned iopoll_queue : 1;
3030
/* opcode specific path will handle ->async_data allocation if needed */
3131
unsigned manual_alloc : 1;
32+
/* vectored opcode, set if 1) vectored, and 2) handler needs to know */
33+
unsigned vectored : 1;
3234

3335
int (*issue)(struct io_kiocb *, unsigned int);
3436
int (*prep)(struct io_kiocb *, const struct io_uring_sqe *);

io_uring/rw.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,7 @@ static struct iovec *__io_import_iovec(int ddir, struct io_kiocb *req,
392392
buf = u64_to_user_ptr(rw->addr);
393393
sqe_len = rw->len;
394394

395-
if (opcode == IORING_OP_READ || opcode == IORING_OP_WRITE ||
396-
(req->flags & REQ_F_BUFFER_SELECT)) {
395+
if (!io_issue_defs[opcode].vectored || req->flags & REQ_F_BUFFER_SELECT) {
397396
if (io_do_buffer_select(req)) {
398397
buf = io_buffer_select(req, &sqe_len, issue_flags);
399398
if (!buf)
@@ -792,8 +791,11 @@ static int __io_read(struct io_kiocb *req, unsigned int issue_flags)
792791

793792
if (ret == -EAGAIN || (req->flags & REQ_F_REISSUE)) {
794793
req->flags &= ~REQ_F_REISSUE;
795-
/* if we can poll, just do that */
796-
if (req->opcode == IORING_OP_READ && io_file_can_poll(req))
794+
/*
795+
* If we can poll, just do that. For a vectored read, we'll
796+
* need to copy state first.
797+
*/
798+
if (io_file_can_poll(req) && !io_issue_defs[req->opcode].vectored)
797799
return -EAGAIN;
798800
/* IOPOLL retry should happen for io-wq threads */
799801
if (!force_nonblock && !(req->ctx->flags & IORING_SETUP_IOPOLL))

0 commit comments

Comments
 (0)