Skip to content

Commit 3fbb51c

Browse files
committed
io_uring: move all prep state for IORING_OP_CONNECT to prep handler
Add struct io_connect in our io_kiocb per-command union, and ensure that io_connect_prep() has grabbed what it needs from the SQE. Signed-off-by: Jens Axboe <[email protected]>
1 parent 9adbd45 commit 3fbb51c

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

fs/io_uring.c

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,12 @@ struct io_rw {
339339
u64 len;
340340
};
341341

342+
struct io_connect {
343+
struct file *file;
344+
struct sockaddr __user *addr;
345+
int addr_len;
346+
};
347+
342348
struct io_async_connect {
343349
struct sockaddr_storage address;
344350
};
@@ -382,6 +388,7 @@ struct io_kiocb {
382388
struct io_sync sync;
383389
struct io_cancel cancel;
384390
struct io_timeout timeout;
391+
struct io_connect connect;
385392
};
386393

387394
const struct io_uring_sqe *sqe;
@@ -2406,33 +2413,28 @@ static int io_connect_prep(struct io_kiocb *req, struct io_async_ctx *io)
24062413
{
24072414
#if defined(CONFIG_NET)
24082415
const struct io_uring_sqe *sqe = req->sqe;
2409-
struct sockaddr __user *addr;
2410-
int addr_len;
24112416

2412-
addr = u64_to_user_ptr(READ_ONCE(sqe->addr));
2413-
addr_len = READ_ONCE(sqe->addr2);
2414-
return move_addr_to_kernel(addr, addr_len, &io->connect.address);
2417+
if (unlikely(req->ctx->flags & (IORING_SETUP_IOPOLL|IORING_SETUP_SQPOLL)))
2418+
return -EINVAL;
2419+
if (sqe->ioprio || sqe->len || sqe->buf_index || sqe->rw_flags)
2420+
return -EINVAL;
2421+
2422+
req->connect.addr = u64_to_user_ptr(READ_ONCE(sqe->addr));
2423+
req->connect.addr_len = READ_ONCE(sqe->addr2);
2424+
return move_addr_to_kernel(req->connect.addr, req->connect.addr_len,
2425+
&io->connect.address);
24152426
#else
2416-
return 0;
2427+
return -EOPNOTSUPP;
24172428
#endif
24182429
}
24192430

24202431
static int io_connect(struct io_kiocb *req, struct io_kiocb **nxt,
24212432
bool force_nonblock)
24222433
{
24232434
#if defined(CONFIG_NET)
2424-
const struct io_uring_sqe *sqe = req->sqe;
24252435
struct io_async_ctx __io, *io;
24262436
unsigned file_flags;
2427-
int addr_len, ret;
2428-
2429-
if (unlikely(req->ctx->flags & (IORING_SETUP_IOPOLL|IORING_SETUP_SQPOLL)))
2430-
return -EINVAL;
2431-
if (sqe->ioprio || sqe->len || sqe->buf_index || sqe->rw_flags)
2432-
return -EINVAL;
2433-
2434-
addr_len = READ_ONCE(sqe->addr2);
2435-
file_flags = force_nonblock ? O_NONBLOCK : 0;
2437+
int ret;
24362438

24372439
if (req->io) {
24382440
io = req->io;
@@ -2443,8 +2445,10 @@ static int io_connect(struct io_kiocb *req, struct io_kiocb **nxt,
24432445
io = &__io;
24442446
}
24452447

2446-
ret = __sys_connect_file(req->file, &io->connect.address, addr_len,
2447-
file_flags);
2448+
file_flags = force_nonblock ? O_NONBLOCK : 0;
2449+
2450+
ret = __sys_connect_file(req->file, &io->connect.address,
2451+
req->connect.addr_len, file_flags);
24482452
if ((ret == -EAGAIN || ret == -EINPROGRESS) && force_nonblock) {
24492453
if (req->io)
24502454
return -EAGAIN;

0 commit comments

Comments
 (0)