Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

io_uring: move msg_ring into its own file

Signed-off-by: Jens Axboe <axboe@kernel.dk>

+71 -55
+1 -1
io_uring/Makefile
··· 5 5 obj-$(CONFIG_IO_URING) += io_uring.o xattr.o nop.o fs.o splice.o \ 6 6 sync.o advise.o filetable.o \ 7 7 openclose.o uring_cmd.o epoll.o \ 8 - statx.o net.o 8 + statx.o net.o msg_ring.o 9 9 obj-$(CONFIG_IO_WQ) += io-wq.o
+1 -54
io_uring/io_uring.c
··· 103 103 #include "epoll.h" 104 104 #include "statx.h" 105 105 #include "net.h" 106 + #include "msg_ring.h" 106 107 107 108 #define IORING_MAX_ENTRIES 32768 108 109 #define IORING_MAX_CQ_ENTRIES (2 * IORING_MAX_ENTRIES) ··· 345 344 __u32 bgid; 346 345 __u16 nbufs; 347 346 __u16 bid; 348 - }; 349 - 350 - struct io_msg { 351 - struct file *file; 352 - u64 user_data; 353 - u32 len; 354 347 }; 355 348 356 349 struct io_rw_state { ··· 3606 3611 if (iovec) 3607 3612 kfree(iovec); 3608 3613 return ret; 3609 - } 3610 - 3611 - static int io_msg_ring_prep(struct io_kiocb *req, 3612 - const struct io_uring_sqe *sqe) 3613 - { 3614 - struct io_msg *msg = io_kiocb_to_cmd(req); 3615 - 3616 - if (unlikely(sqe->addr || sqe->rw_flags || sqe->splice_fd_in || 3617 - sqe->buf_index || sqe->personality)) 3618 - return -EINVAL; 3619 - 3620 - msg->user_data = READ_ONCE(sqe->off); 3621 - msg->len = READ_ONCE(sqe->len); 3622 - return 0; 3623 - } 3624 - 3625 - static int io_msg_ring(struct io_kiocb *req, unsigned int issue_flags) 3626 - { 3627 - struct io_msg *msg = io_kiocb_to_cmd(req); 3628 - struct io_ring_ctx *target_ctx; 3629 - bool filled; 3630 - int ret; 3631 - 3632 - ret = -EBADFD; 3633 - if (req->file->f_op != &io_uring_fops) 3634 - goto done; 3635 - 3636 - ret = -EOVERFLOW; 3637 - target_ctx = req->file->private_data; 3638 - 3639 - spin_lock(&target_ctx->completion_lock); 3640 - filled = io_fill_cqe_aux(target_ctx, msg->user_data, msg->len, 0); 3641 - io_commit_cqring(target_ctx); 3642 - spin_unlock(&target_ctx->completion_lock); 3643 - 3644 - if (filled) { 3645 - io_cqring_ev_posted(target_ctx); 3646 - ret = 0; 3647 - } 3648 - 3649 - done: 3650 - if (ret < 0) 3651 - req_set_fail(req); 3652 - io_req_set_res(req, ret, 0); 3653 - /* put file to avoid an attempt to IOPOLL the req */ 3654 - io_put_file(req->file); 3655 - req->file = NULL; 3656 - return IOU_OK; 3657 3614 } 3658 3615 3659 3616 /*
+65
io_uring/msg_ring.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + #include <linux/kernel.h> 3 + #include <linux/errno.h> 4 + #include <linux/file.h> 5 + #include <linux/slab.h> 6 + #include <linux/io_uring.h> 7 + 8 + #include <uapi/linux/io_uring.h> 9 + 10 + #include "io_uring_types.h" 11 + #include "io_uring.h" 12 + #include "msg_ring.h" 13 + 14 + struct io_msg { 15 + struct file *file; 16 + u64 user_data; 17 + u32 len; 18 + }; 19 + 20 + int io_msg_ring_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) 21 + { 22 + struct io_msg *msg = io_kiocb_to_cmd(req); 23 + 24 + if (unlikely(sqe->addr || sqe->rw_flags || sqe->splice_fd_in || 25 + sqe->buf_index || sqe->personality)) 26 + return -EINVAL; 27 + 28 + msg->user_data = READ_ONCE(sqe->off); 29 + msg->len = READ_ONCE(sqe->len); 30 + return 0; 31 + } 32 + 33 + int io_msg_ring(struct io_kiocb *req, unsigned int issue_flags) 34 + { 35 + struct io_msg *msg = io_kiocb_to_cmd(req); 36 + struct io_ring_ctx *target_ctx; 37 + bool filled; 38 + int ret; 39 + 40 + ret = -EBADFD; 41 + if (!io_is_uring_fops(req->file)) 42 + goto done; 43 + 44 + ret = -EOVERFLOW; 45 + target_ctx = req->file->private_data; 46 + 47 + spin_lock(&target_ctx->completion_lock); 48 + filled = io_fill_cqe_aux(target_ctx, msg->user_data, msg->len, 0); 49 + io_commit_cqring(target_ctx); 50 + spin_unlock(&target_ctx->completion_lock); 51 + 52 + if (filled) { 53 + io_cqring_ev_posted(target_ctx); 54 + ret = 0; 55 + } 56 + 57 + done: 58 + if (ret < 0) 59 + req_set_fail(req); 60 + io_req_set_res(req, ret, 0); 61 + /* put file to avoid an attempt to IOPOLL the req */ 62 + io_put_file(req->file); 63 + req->file = NULL; 64 + return IOU_OK; 65 + }
+4
io_uring/msg_ring.h
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + 3 + int io_msg_ring_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe); 4 + int io_msg_ring(struct io_kiocb *req, unsigned int issue_flags);