Skip to content

Commit 0e984ec

Browse files
committed
io_uring/rw: add separate prep handler for readv/writev
Rather than sprinkle opcode checks in the generic read/write prep handler, have a separate prep handler for the vectored readv/writev operation. Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent f8f9ab2 commit 0e984ec

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

io_uring/opdef.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const struct io_issue_def io_issue_defs[] = {
6666
.iopoll = 1,
6767
.iopoll_queue = 1,
6868
.vectored = 1,
69-
.prep = io_prep_rw,
69+
.prep = io_prep_rwv,
7070
.issue = io_read,
7171
},
7272
[IORING_OP_WRITEV] = {
@@ -80,7 +80,7 @@ const struct io_issue_def io_issue_defs[] = {
8080
.iopoll = 1,
8181
.iopoll_queue = 1,
8282
.vectored = 1,
83-
.prep = io_prep_rw,
83+
.prep = io_prep_rwv,
8484
.issue = io_write,
8585
},
8686
[IORING_OP_FSYNC] = {

io_uring/rw.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,23 @@ int io_prep_rw(struct io_kiocb *req, const struct io_uring_sqe *sqe)
110110
rw->addr = READ_ONCE(sqe->addr);
111111
rw->len = READ_ONCE(sqe->len);
112112
rw->flags = READ_ONCE(sqe->rw_flags);
113+
return 0;
114+
}
113115

114-
/* Have to do this validation here, as this is in io_read() rw->len might
115-
* have chanaged due to buffer selection
116+
int io_prep_rwv(struct io_kiocb *req, const struct io_uring_sqe *sqe)
117+
{
118+
int ret;
119+
120+
ret = io_prep_rw(req, sqe);
121+
if (unlikely(ret))
122+
return ret;
123+
124+
/*
125+
* Have to do this validation here, as this is in io_read() rw->len
126+
* might have chanaged due to buffer selection
116127
*/
117-
if (req->opcode == IORING_OP_READV && req->flags & REQ_F_BUFFER_SELECT) {
118-
ret = io_iov_buffer_select_prep(req);
119-
if (ret)
120-
return ret;
121-
}
128+
if (req->flags & REQ_F_BUFFER_SELECT)
129+
return io_iov_buffer_select_prep(req);
122130

123131
return 0;
124132
}

io_uring/rw.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ struct io_async_rw {
1616
};
1717

1818
int io_prep_rw(struct io_kiocb *req, const struct io_uring_sqe *sqe);
19+
int io_prep_rwv(struct io_kiocb *req, const struct io_uring_sqe *sqe);
1920
int io_read(struct io_kiocb *req, unsigned int issue_flags);
2021
int io_readv_prep_async(struct io_kiocb *req);
2122
int io_write(struct io_kiocb *req, unsigned int issue_flags);

0 commit comments

Comments
 (0)