Skip to content

Commit d2d778f

Browse files
committed
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 <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent a08d195 commit d2d778f

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

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
@@ -388,8 +388,7 @@ static struct iovec *__io_import_iovec(int ddir, struct io_kiocb *req,
388388
buf = u64_to_user_ptr(rw->addr);
389389
sqe_len = rw->len;
390390

391-
if (opcode == IORING_OP_READ || opcode == IORING_OP_WRITE ||
392-
(req->flags & REQ_F_BUFFER_SELECT)) {
391+
if (!io_issue_defs[opcode].vectored || req->flags & REQ_F_BUFFER_SELECT) {
393392
if (io_do_buffer_select(req)) {
394393
buf = io_buffer_select(req, &sqe_len, issue_flags);
395394
if (!buf)
@@ -776,8 +775,11 @@ static int __io_read(struct io_kiocb *req, unsigned int issue_flags)
776775

777776
if (ret == -EAGAIN || (req->flags & REQ_F_REISSUE)) {
778777
req->flags &= ~REQ_F_REISSUE;
779-
/* if we can poll, just do that */
780-
if (req->opcode == IORING_OP_READ && file_can_poll(req->file))
778+
/*
779+
* If we can poll, just do that. For a vectored read, we'll
780+
* need to copy state first.
781+
*/
782+
if (file_can_poll(req->file) && !io_issue_defs[req->opcode].vectored)
781783
return -EAGAIN;
782784
/* IOPOLL retry should happen for io-wq threads */
783785
if (!force_nonblock && !(req->ctx->flags & IORING_SETUP_IOPOLL))

0 commit comments

Comments
 (0)