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/splice: open code 2nd direct file assignment

In preparation for not pinning the whole registered file table, open
code the second potential direct file assignment. This will be handled
by appropriate helpers in the future, for now just do it manually.

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

+39 -8
+2
io_uring/opdef.c
··· 641 641 }, 642 642 [IORING_OP_SPLICE] = { 643 643 .name = "SPLICE", 644 + .cleanup = io_splice_cleanup, 644 645 }, 645 646 [IORING_OP_PROVIDE_BUFFERS] = { 646 647 .name = "PROVIDE_BUFFERS", ··· 651 650 }, 652 651 [IORING_OP_TEE] = { 653 652 .name = "TEE", 653 + .cleanup = io_splice_cleanup, 654 654 }, 655 655 [IORING_OP_SHUTDOWN] = { 656 656 .name = "SHUTDOWN",
+36 -8
io_uring/splice.c
··· 21 21 u64 len; 22 22 int splice_fd_in; 23 23 unsigned int flags; 24 + struct io_rsrc_node *rsrc_node; 24 25 }; 25 26 26 27 static int __io_splice_prep(struct io_kiocb *req, ··· 35 34 if (unlikely(sp->flags & ~valid_flags)) 36 35 return -EINVAL; 37 36 sp->splice_fd_in = READ_ONCE(sqe->splice_fd_in); 37 + sp->rsrc_node = NULL; 38 38 req->flags |= REQ_F_FORCE_ASYNC; 39 39 return 0; 40 40 } ··· 45 43 if (READ_ONCE(sqe->splice_off_in) || READ_ONCE(sqe->off)) 46 44 return -EINVAL; 47 45 return __io_splice_prep(req, sqe); 46 + } 47 + 48 + void io_splice_cleanup(struct io_kiocb *req) 49 + { 50 + struct io_splice *sp = io_kiocb_to_cmd(req, struct io_splice); 51 + 52 + io_put_rsrc_node(req->ctx, sp->rsrc_node); 53 + } 54 + 55 + static struct file *io_splice_get_file(struct io_kiocb *req, 56 + unsigned int issue_flags) 57 + { 58 + struct io_splice *sp = io_kiocb_to_cmd(req, struct io_splice); 59 + struct io_ring_ctx *ctx = req->ctx; 60 + struct io_fixed_file *slot; 61 + struct file *file = NULL; 62 + 63 + if (!(sp->flags & SPLICE_F_FD_IN_FIXED)) 64 + return io_file_get_normal(req, sp->splice_fd_in); 65 + 66 + io_ring_submit_lock(ctx, issue_flags); 67 + if (unlikely(sp->splice_fd_in >= ctx->nr_user_files)) 68 + goto out; 69 + sp->splice_fd_in = array_index_nospec(sp->splice_fd_in, ctx->nr_user_files); 70 + slot = &ctx->file_table.files[sp->splice_fd_in]; 71 + if (!req->rsrc_node) 72 + __io_req_set_rsrc_node(req, ctx); 73 + file = io_slot_file(slot); 74 + req->flags |= REQ_F_NEED_CLEANUP; 75 + out: 76 + io_ring_submit_unlock(ctx, issue_flags); 77 + return file; 48 78 } 49 79 50 80 int io_tee(struct io_kiocb *req, unsigned int issue_flags) ··· 89 55 90 56 WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK); 91 57 92 - if (sp->flags & SPLICE_F_FD_IN_FIXED) 93 - in = io_file_get_fixed(req, sp->splice_fd_in, issue_flags); 94 - else 95 - in = io_file_get_normal(req, sp->splice_fd_in); 58 + in = io_splice_get_file(req, issue_flags); 96 59 if (!in) { 97 60 ret = -EBADF; 98 61 goto done; ··· 127 96 128 97 WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK); 129 98 130 - if (sp->flags & SPLICE_F_FD_IN_FIXED) 131 - in = io_file_get_fixed(req, sp->splice_fd_in, issue_flags); 132 - else 133 - in = io_file_get_normal(req, sp->splice_fd_in); 99 + in = io_splice_get_file(req, issue_flags); 134 100 if (!in) { 135 101 ret = -EBADF; 136 102 goto done;
+1
io_uring/splice.h
··· 3 3 int io_tee_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe); 4 4 int io_tee(struct io_kiocb *req, unsigned int issue_flags); 5 5 6 + void io_splice_cleanup(struct io_kiocb *req); 6 7 int io_splice_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe); 7 8 int io_splice(struct io_kiocb *req, unsigned int issue_flags);