Commit 8ff86d85 authored by Jens Axboe's avatar Jens Axboe

io_uring: convert net related opcodes to use io_cmd_type

This converts accept, connect, send/recv, sendmsg/recvmsg, shutdown, and
socket to use io_cmd_type.
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent bd8587e4
...@@ -979,13 +979,10 @@ struct io_kiocb { ...@@ -979,13 +979,10 @@ struct io_kiocb {
*/ */
struct file *file; struct file *file;
struct io_cmd_data cmd; struct io_cmd_data cmd;
struct io_accept accept;
struct io_sync sync; struct io_sync sync;
struct io_cancel cancel; struct io_cancel cancel;
struct io_timeout timeout; struct io_timeout timeout;
struct io_timeout_rem timeout_rem; struct io_timeout_rem timeout_rem;
struct io_connect connect;
struct io_sr_msg sr_msg;
struct io_open open; struct io_open open;
struct io_close close; struct io_close close;
struct io_rsrc_update rsrc_update; struct io_rsrc_update rsrc_update;
...@@ -995,7 +992,6 @@ struct io_kiocb { ...@@ -995,7 +992,6 @@ struct io_kiocb {
struct io_splice splice; struct io_splice splice;
struct io_provide_buf pbuf; struct io_provide_buf pbuf;
struct io_statx statx; struct io_statx statx;
struct io_shutdown shutdown;
struct io_rename rename; struct io_rename rename;
struct io_unlink unlink; struct io_unlink unlink;
struct io_mkdir mkdir; struct io_mkdir mkdir;
...@@ -1003,7 +999,6 @@ struct io_kiocb { ...@@ -1003,7 +999,6 @@ struct io_kiocb {
struct io_hardlink hardlink; struct io_hardlink hardlink;
struct io_msg msg; struct io_msg msg;
struct io_xattr xattr; struct io_xattr xattr;
struct io_socket sock;
struct io_uring_cmd uring_cmd; struct io_uring_cmd uring_cmd;
}; };
...@@ -5824,16 +5819,19 @@ static int io_sync_file_range(struct io_kiocb *req, unsigned int issue_flags) ...@@ -5824,16 +5819,19 @@ static int io_sync_file_range(struct io_kiocb *req, unsigned int issue_flags)
static int io_shutdown_prep(struct io_kiocb *req, static int io_shutdown_prep(struct io_kiocb *req,
const struct io_uring_sqe *sqe) const struct io_uring_sqe *sqe)
{ {
struct io_shutdown *shutdown = io_kiocb_to_cmd(req);
if (unlikely(sqe->off || sqe->addr || sqe->rw_flags || if (unlikely(sqe->off || sqe->addr || sqe->rw_flags ||
sqe->buf_index || sqe->splice_fd_in)) sqe->buf_index || sqe->splice_fd_in))
return -EINVAL; return -EINVAL;
req->shutdown.how = READ_ONCE(sqe->len); shutdown->how = READ_ONCE(sqe->len);
return 0; return 0;
} }
static int io_shutdown(struct io_kiocb *req, unsigned int issue_flags) static int io_shutdown(struct io_kiocb *req, unsigned int issue_flags)
{ {
struct io_shutdown *shutdown = io_kiocb_to_cmd(req);
struct socket *sock; struct socket *sock;
int ret; int ret;
...@@ -5844,7 +5842,7 @@ static int io_shutdown(struct io_kiocb *req, unsigned int issue_flags) ...@@ -5844,7 +5842,7 @@ static int io_shutdown(struct io_kiocb *req, unsigned int issue_flags)
if (unlikely(!sock)) if (unlikely(!sock))
return -ENOTSOCK; return -ENOTSOCK;
ret = __sys_shutdown_sock(sock, req->shutdown.how); ret = __sys_shutdown_sock(sock, shutdown->how);
io_req_complete(req, ret); io_req_complete(req, ret);
return 0; return 0;
} }
...@@ -5881,10 +5879,12 @@ static int io_setup_async_msg(struct io_kiocb *req, ...@@ -5881,10 +5879,12 @@ static int io_setup_async_msg(struct io_kiocb *req,
static int io_sendmsg_copy_hdr(struct io_kiocb *req, static int io_sendmsg_copy_hdr(struct io_kiocb *req,
struct io_async_msghdr *iomsg) struct io_async_msghdr *iomsg)
{ {
struct io_sr_msg *sr = io_kiocb_to_cmd(req);
iomsg->msg.msg_name = &iomsg->addr; iomsg->msg.msg_name = &iomsg->addr;
iomsg->free_iov = iomsg->fast_iov; iomsg->free_iov = iomsg->fast_iov;
return sendmsg_copy_msghdr(&iomsg->msg, req->sr_msg.umsg, return sendmsg_copy_msghdr(&iomsg->msg, sr->umsg, sr->msg_flags,
req->sr_msg.msg_flags, &iomsg->free_iov); &iomsg->free_iov);
} }
static int io_sendmsg_prep_async(struct io_kiocb *req) static int io_sendmsg_prep_async(struct io_kiocb *req)
...@@ -5899,7 +5899,7 @@ static int io_sendmsg_prep_async(struct io_kiocb *req) ...@@ -5899,7 +5899,7 @@ static int io_sendmsg_prep_async(struct io_kiocb *req)
static int io_sendmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) static int io_sendmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
{ {
struct io_sr_msg *sr = &req->sr_msg; struct io_sr_msg *sr = io_kiocb_to_cmd(req);
if (unlikely(sqe->file_index || sqe->addr2)) if (unlikely(sqe->file_index || sqe->addr2))
return -EINVAL; return -EINVAL;
...@@ -5923,8 +5923,8 @@ static int io_sendmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) ...@@ -5923,8 +5923,8 @@ static int io_sendmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
static int io_sendmsg(struct io_kiocb *req, unsigned int issue_flags) static int io_sendmsg(struct io_kiocb *req, unsigned int issue_flags)
{ {
struct io_sr_msg *sr = io_kiocb_to_cmd(req);
struct io_async_msghdr iomsg, *kmsg; struct io_async_msghdr iomsg, *kmsg;
struct io_sr_msg *sr = &req->sr_msg;
struct socket *sock; struct socket *sock;
unsigned flags; unsigned flags;
int min_ret = 0; int min_ret = 0;
...@@ -5981,7 +5981,7 @@ static int io_sendmsg(struct io_kiocb *req, unsigned int issue_flags) ...@@ -5981,7 +5981,7 @@ static int io_sendmsg(struct io_kiocb *req, unsigned int issue_flags)
static int io_send(struct io_kiocb *req, unsigned int issue_flags) static int io_send(struct io_kiocb *req, unsigned int issue_flags)
{ {
struct io_sr_msg *sr = &req->sr_msg; struct io_sr_msg *sr = io_kiocb_to_cmd(req);
struct msghdr msg; struct msghdr msg;
struct iovec iov; struct iovec iov;
struct socket *sock; struct socket *sock;
...@@ -6039,7 +6039,7 @@ static int io_send(struct io_kiocb *req, unsigned int issue_flags) ...@@ -6039,7 +6039,7 @@ static int io_send(struct io_kiocb *req, unsigned int issue_flags)
static int __io_recvmsg_copy_hdr(struct io_kiocb *req, static int __io_recvmsg_copy_hdr(struct io_kiocb *req,
struct io_async_msghdr *iomsg) struct io_async_msghdr *iomsg)
{ {
struct io_sr_msg *sr = &req->sr_msg; struct io_sr_msg *sr = io_kiocb_to_cmd(req);
struct iovec __user *uiov; struct iovec __user *uiov;
size_t iov_len; size_t iov_len;
int ret; int ret;
...@@ -6072,7 +6072,7 @@ static int __io_recvmsg_copy_hdr(struct io_kiocb *req, ...@@ -6072,7 +6072,7 @@ static int __io_recvmsg_copy_hdr(struct io_kiocb *req,
static int __io_compat_recvmsg_copy_hdr(struct io_kiocb *req, static int __io_compat_recvmsg_copy_hdr(struct io_kiocb *req,
struct io_async_msghdr *iomsg) struct io_async_msghdr *iomsg)
{ {
struct io_sr_msg *sr = &req->sr_msg; struct io_sr_msg *sr = io_kiocb_to_cmd(req);
struct compat_iovec __user *uiov; struct compat_iovec __user *uiov;
compat_uptr_t ptr; compat_uptr_t ptr;
compat_size_t len; compat_size_t len;
...@@ -6135,7 +6135,7 @@ static int io_recvmsg_prep_async(struct io_kiocb *req) ...@@ -6135,7 +6135,7 @@ static int io_recvmsg_prep_async(struct io_kiocb *req)
static int io_recvmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) static int io_recvmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
{ {
struct io_sr_msg *sr = &req->sr_msg; struct io_sr_msg *sr = io_kiocb_to_cmd(req);
if (unlikely(sqe->file_index || sqe->addr2)) if (unlikely(sqe->file_index || sqe->addr2))
return -EINVAL; return -EINVAL;
...@@ -6161,8 +6161,8 @@ static int io_recvmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) ...@@ -6161,8 +6161,8 @@ static int io_recvmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
static int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags) static int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags)
{ {
struct io_sr_msg *sr = io_kiocb_to_cmd(req);
struct io_async_msghdr iomsg, *kmsg; struct io_async_msghdr iomsg, *kmsg;
struct io_sr_msg *sr = &req->sr_msg;
struct socket *sock; struct socket *sock;
unsigned int cflags; unsigned int cflags;
unsigned flags; unsigned flags;
...@@ -6238,7 +6238,7 @@ static int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags) ...@@ -6238,7 +6238,7 @@ static int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags)
static int io_recv(struct io_kiocb *req, unsigned int issue_flags) static int io_recv(struct io_kiocb *req, unsigned int issue_flags)
{ {
struct io_sr_msg *sr = &req->sr_msg; struct io_sr_msg *sr = io_kiocb_to_cmd(req);
struct msghdr msg; struct msghdr msg;
struct socket *sock; struct socket *sock;
struct iovec iov; struct iovec iov;
...@@ -6314,7 +6314,7 @@ static int io_recv(struct io_kiocb *req, unsigned int issue_flags) ...@@ -6314,7 +6314,7 @@ static int io_recv(struct io_kiocb *req, unsigned int issue_flags)
static int io_accept_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) static int io_accept_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
{ {
struct io_accept *accept = &req->accept; struct io_accept *accept = io_kiocb_to_cmd(req);
unsigned flags; unsigned flags;
if (sqe->len || sqe->buf_index) if (sqe->len || sqe->buf_index)
...@@ -6348,7 +6348,7 @@ static int io_accept_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) ...@@ -6348,7 +6348,7 @@ static int io_accept_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
static int io_accept(struct io_kiocb *req, unsigned int issue_flags) static int io_accept(struct io_kiocb *req, unsigned int issue_flags)
{ {
struct io_ring_ctx *ctx = req->ctx; struct io_ring_ctx *ctx = req->ctx;
struct io_accept *accept = &req->accept; struct io_accept *accept = io_kiocb_to_cmd(req);
bool force_nonblock = issue_flags & IO_URING_F_NONBLOCK; bool force_nonblock = issue_flags & IO_URING_F_NONBLOCK;
unsigned int file_flags = force_nonblock ? O_NONBLOCK : 0; unsigned int file_flags = force_nonblock ? O_NONBLOCK : 0;
bool fixed = !!accept->file_slot; bool fixed = !!accept->file_slot;
...@@ -6413,7 +6413,7 @@ static int io_accept(struct io_kiocb *req, unsigned int issue_flags) ...@@ -6413,7 +6413,7 @@ static int io_accept(struct io_kiocb *req, unsigned int issue_flags)
static int io_socket_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) static int io_socket_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
{ {
struct io_socket *sock = &req->sock; struct io_socket *sock = io_kiocb_to_cmd(req);
if (sqe->addr || sqe->rw_flags || sqe->buf_index) if (sqe->addr || sqe->rw_flags || sqe->buf_index)
return -EINVAL; return -EINVAL;
...@@ -6434,7 +6434,7 @@ static int io_socket_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) ...@@ -6434,7 +6434,7 @@ static int io_socket_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
static int io_socket(struct io_kiocb *req, unsigned int issue_flags) static int io_socket(struct io_kiocb *req, unsigned int issue_flags)
{ {
struct io_socket *sock = &req->sock; struct io_socket *sock = io_kiocb_to_cmd(req);
bool fixed = !!sock->file_slot; bool fixed = !!sock->file_slot;
struct file *file; struct file *file;
int ret, fd; int ret, fd;
...@@ -6468,14 +6468,14 @@ static int io_socket(struct io_kiocb *req, unsigned int issue_flags) ...@@ -6468,14 +6468,14 @@ static int io_socket(struct io_kiocb *req, unsigned int issue_flags)
static int io_connect_prep_async(struct io_kiocb *req) static int io_connect_prep_async(struct io_kiocb *req)
{ {
struct io_async_connect *io = req->async_data; struct io_async_connect *io = req->async_data;
struct io_connect *conn = &req->connect; struct io_connect *conn = io_kiocb_to_cmd(req);
return move_addr_to_kernel(conn->addr, conn->addr_len, &io->address); return move_addr_to_kernel(conn->addr, conn->addr_len, &io->address);
} }
static int io_connect_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) static int io_connect_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
{ {
struct io_connect *conn = &req->connect; struct io_connect *conn = io_kiocb_to_cmd(req);
if (sqe->len || sqe->buf_index || sqe->rw_flags || sqe->splice_fd_in) if (sqe->len || sqe->buf_index || sqe->rw_flags || sqe->splice_fd_in)
return -EINVAL; return -EINVAL;
...@@ -6487,6 +6487,7 @@ static int io_connect_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) ...@@ -6487,6 +6487,7 @@ static int io_connect_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
static int io_connect(struct io_kiocb *req, unsigned int issue_flags) static int io_connect(struct io_kiocb *req, unsigned int issue_flags)
{ {
struct io_connect *connect = io_kiocb_to_cmd(req);
struct io_async_connect __io, *io; struct io_async_connect __io, *io;
unsigned file_flags; unsigned file_flags;
int ret; int ret;
...@@ -6495,8 +6496,8 @@ static int io_connect(struct io_kiocb *req, unsigned int issue_flags) ...@@ -6495,8 +6496,8 @@ static int io_connect(struct io_kiocb *req, unsigned int issue_flags)
if (req_has_async_data(req)) { if (req_has_async_data(req)) {
io = req->async_data; io = req->async_data;
} else { } else {
ret = move_addr_to_kernel(req->connect.addr, ret = move_addr_to_kernel(connect->addr,
req->connect.addr_len, connect->addr_len,
&__io.address); &__io.address);
if (ret) if (ret)
goto out; goto out;
...@@ -6506,7 +6507,7 @@ static int io_connect(struct io_kiocb *req, unsigned int issue_flags) ...@@ -6506,7 +6507,7 @@ static int io_connect(struct io_kiocb *req, unsigned int issue_flags)
file_flags = force_nonblock ? O_NONBLOCK : 0; file_flags = force_nonblock ? O_NONBLOCK : 0;
ret = __sys_connect_file(req->file, &io->address, ret = __sys_connect_file(req->file, &io->address,
req->connect.addr_len, file_flags); connect->addr_len, file_flags);
if ((ret == -EAGAIN || ret == -EINPROGRESS) && force_nonblock) { if ((ret == -EAGAIN || ret == -EINPROGRESS) && force_nonblock) {
if (req_has_async_data(req)) if (req_has_async_data(req))
return -EAGAIN; return -EAGAIN;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment