Skip to content

Commit 8452fd0

Browse files
committed
io_uring: cleanup io_import_iovec() of pre-mapped request
io_rw_prep_async() goes through a dance of clearing req->io, calling the iovec import, then re-setting req->io. Provide an internal helper that does the right thing without needing state tweaked to get there. This enables further cleanups in io_read, io_write, and io_resubmit_prep(), but that's left for another time. Signed-off-by: Jens Axboe <[email protected]>
1 parent 3b2a443 commit 8452fd0

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

fs/io_uring.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2819,22 +2819,15 @@ static ssize_t io_iov_buffer_select(struct io_kiocb *req, struct iovec *iov,
28192819
return __io_iov_buffer_select(req, iov, needs_lock);
28202820
}
28212821

2822-
static ssize_t io_import_iovec(int rw, struct io_kiocb *req,
2823-
struct iovec **iovec, struct iov_iter *iter,
2824-
bool needs_lock)
2822+
static ssize_t __io_import_iovec(int rw, struct io_kiocb *req,
2823+
struct iovec **iovec, struct iov_iter *iter,
2824+
bool needs_lock)
28252825
{
28262826
void __user *buf = u64_to_user_ptr(req->rw.addr);
28272827
size_t sqe_len = req->rw.len;
28282828
ssize_t ret;
28292829
u8 opcode;
28302830

2831-
if (req->io) {
2832-
struct io_async_rw *iorw = &req->io->rw;
2833-
2834-
*iovec = NULL;
2835-
return iov_iter_count(&iorw->iter);
2836-
}
2837-
28382831
opcode = req->opcode;
28392832
if (opcode == IORING_OP_READ_FIXED || opcode == IORING_OP_WRITE_FIXED) {
28402833
*iovec = NULL;
@@ -2879,6 +2872,16 @@ static ssize_t io_import_iovec(int rw, struct io_kiocb *req,
28792872
return import_iovec(rw, buf, sqe_len, UIO_FASTIOV, iovec, iter);
28802873
}
28812874

2875+
static ssize_t io_import_iovec(int rw, struct io_kiocb *req,
2876+
struct iovec **iovec, struct iov_iter *iter,
2877+
bool needs_lock)
2878+
{
2879+
if (!req->io)
2880+
return __io_import_iovec(rw, req, iovec, iter, needs_lock);
2881+
*iovec = NULL;
2882+
return iov_iter_count(&req->io->rw.iter);
2883+
}
2884+
28822885
/*
28832886
* For files that don't have ->read_iter() and ->write_iter(), handle them
28842887
* by looping over ->read() or ->write() manually.
@@ -3001,11 +3004,8 @@ static inline int io_rw_prep_async(struct io_kiocb *req, int rw,
30013004
ssize_t ret;
30023005

30033006
iorw->iter.iov = iorw->fast_iov;
3004-
/* reset ->io around the iovec import, we don't want to use it */
3005-
req->io = NULL;
3006-
ret = io_import_iovec(rw, req, (struct iovec **) &iorw->iter.iov,
3007+
ret = __io_import_iovec(rw, req, (struct iovec **) &iorw->iter.iov,
30073008
&iorw->iter, !force_nonblock);
3008-
req->io = container_of(iorw, struct io_async_ctx, rw);
30093009
if (unlikely(ret < 0))
30103010
return ret;
30113011

0 commit comments

Comments
 (0)