summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2022-05-25 06:42:08 -0600
committerJens Axboe <axboe@kernel.dk>2022-07-24 18:39:12 -0600
commit36404b09aa609e00f8f0108356830c22b99b3cbf (patch)
tree9ec7d25af7015e16c3e26962c8a135eea5d290c4
parentf9ead18c10589a351f395ac5aa107360f2f6ce53 (diff)
downloadlinux-stable-36404b09aa609e00f8f0108356830c22b99b3cbf.tar.gz
linux-stable-36404b09aa609e00f8f0108356830c22b99b3cbf.tar.bz2
linux-stable-36404b09aa609e00f8f0108356830c22b99b3cbf.zip
io_uring: move msg_ring into its own file
Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--io_uring/Makefile2
-rw-r--r--io_uring/io_uring.c55
-rw-r--r--io_uring/msg_ring.c65
-rw-r--r--io_uring/msg_ring.h4
4 files changed, 71 insertions, 55 deletions
diff --git a/io_uring/Makefile b/io_uring/Makefile
index c9ec1bbabfbd..d7cf992c841a 100644
--- a/io_uring/Makefile
+++ b/io_uring/Makefile
@@ -5,5 +5,5 @@
obj-$(CONFIG_IO_URING) += io_uring.o xattr.o nop.o fs.o splice.o \
sync.o advise.o filetable.o \
openclose.o uring_cmd.o epoll.o \
- statx.o net.o
+ statx.o net.o msg_ring.o
obj-$(CONFIG_IO_WQ) += io-wq.o
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index cbc20985cd6f..a0173ab5178c 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -103,6 +103,7 @@
#include "epoll.h"
#include "statx.h"
#include "net.h"
+#include "msg_ring.h"
#define IORING_MAX_ENTRIES 32768
#define IORING_MAX_CQ_ENTRIES (2 * IORING_MAX_ENTRIES)
@@ -346,12 +347,6 @@ struct io_provide_buf {
__u16 bid;
};
-struct io_msg {
- struct file *file;
- u64 user_data;
- u32 len;
-};
-
struct io_rw_state {
struct iov_iter iter;
struct iov_iter_state iter_state;
@@ -3613,54 +3608,6 @@ out_free:
return ret;
}
-static int io_msg_ring_prep(struct io_kiocb *req,
- const struct io_uring_sqe *sqe)
-{
- struct io_msg *msg = io_kiocb_to_cmd(req);
-
- if (unlikely(sqe->addr || sqe->rw_flags || sqe->splice_fd_in ||
- sqe->buf_index || sqe->personality))
- return -EINVAL;
-
- msg->user_data = READ_ONCE(sqe->off);
- msg->len = READ_ONCE(sqe->len);
- return 0;
-}
-
-static int io_msg_ring(struct io_kiocb *req, unsigned int issue_flags)
-{
- struct io_msg *msg = io_kiocb_to_cmd(req);
- struct io_ring_ctx *target_ctx;
- bool filled;
- int ret;
-
- ret = -EBADFD;
- if (req->file->f_op != &io_uring_fops)
- goto done;
-
- ret = -EOVERFLOW;
- target_ctx = req->file->private_data;
-
- spin_lock(&target_ctx->completion_lock);
- filled = io_fill_cqe_aux(target_ctx, msg->user_data, msg->len, 0);
- io_commit_cqring(target_ctx);
- spin_unlock(&target_ctx->completion_lock);
-
- if (filled) {
- io_cqring_ev_posted(target_ctx);
- ret = 0;
- }
-
-done:
- if (ret < 0)
- req_set_fail(req);
- io_req_set_res(req, ret, 0);
- /* put file to avoid an attempt to IOPOLL the req */
- io_put_file(req->file);
- req->file = NULL;
- return IOU_OK;
-}
-
/*
* Note when io_fixed_fd_install() returns error value, it will ensure
* fput() is called correspondingly.
diff --git a/io_uring/msg_ring.c b/io_uring/msg_ring.c
new file mode 100644
index 000000000000..3b89f9a0a0b4
--- /dev/null
+++ b/io_uring/msg_ring.c
@@ -0,0 +1,65 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/file.h>
+#include <linux/slab.h>
+#include <linux/io_uring.h>
+
+#include <uapi/linux/io_uring.h>
+
+#include "io_uring_types.h"
+#include "io_uring.h"
+#include "msg_ring.h"
+
+struct io_msg {
+ struct file *file;
+ u64 user_data;
+ u32 len;
+};
+
+int io_msg_ring_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
+{
+ struct io_msg *msg = io_kiocb_to_cmd(req);
+
+ if (unlikely(sqe->addr || sqe->rw_flags || sqe->splice_fd_in ||
+ sqe->buf_index || sqe->personality))
+ return -EINVAL;
+
+ msg->user_data = READ_ONCE(sqe->off);
+ msg->len = READ_ONCE(sqe->len);
+ return 0;
+}
+
+int io_msg_ring(struct io_kiocb *req, unsigned int issue_flags)
+{
+ struct io_msg *msg = io_kiocb_to_cmd(req);
+ struct io_ring_ctx *target_ctx;
+ bool filled;
+ int ret;
+
+ ret = -EBADFD;
+ if (!io_is_uring_fops(req->file))
+ goto done;
+
+ ret = -EOVERFLOW;
+ target_ctx = req->file->private_data;
+
+ spin_lock(&target_ctx->completion_lock);
+ filled = io_fill_cqe_aux(target_ctx, msg->user_data, msg->len, 0);
+ io_commit_cqring(target_ctx);
+ spin_unlock(&target_ctx->completion_lock);
+
+ if (filled) {
+ io_cqring_ev_posted(target_ctx);
+ ret = 0;
+ }
+
+done:
+ if (ret < 0)
+ req_set_fail(req);
+ io_req_set_res(req, ret, 0);
+ /* put file to avoid an attempt to IOPOLL the req */
+ io_put_file(req->file);
+ req->file = NULL;
+ return IOU_OK;
+}
diff --git a/io_uring/msg_ring.h b/io_uring/msg_ring.h
new file mode 100644
index 000000000000..fb9601f202d0
--- /dev/null
+++ b/io_uring/msg_ring.h
@@ -0,0 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0
+
+int io_msg_ring_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe);
+int io_msg_ring(struct io_kiocb *req, unsigned int issue_flags);