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: define a request type cleanup handler

This can move request type specific cleanup into a private handler,
removing the need for the core io_uring parts to know what types
they are dealing with.

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

+86 -69
+86 -69
io_uring/io_uring.c
··· 1093 1093 int (*prep)(struct io_kiocb *, const struct io_uring_sqe *); 1094 1094 int (*issue)(struct io_kiocb *, unsigned int); 1095 1095 int (*prep_async)(struct io_kiocb *); 1096 + void (*cleanup)(struct io_kiocb *); 1096 1097 }; 1097 1098 1098 1099 static const struct io_op_def io_op_defs[]; ··· 3434 3433 return 0; 3435 3434 } 3436 3435 3436 + static void io_readv_writev_cleanup(struct io_kiocb *req) 3437 + { 3438 + struct io_async_rw *io = req->async_data; 3439 + 3440 + kfree(io->free_iovec); 3441 + } 3442 + 3437 3443 static inline void io_rw_done(struct kiocb *kiocb, ssize_t ret) 3438 3444 { 3439 3445 switch (ret) { ··· 4399 4391 return 0; 4400 4392 } 4401 4393 4402 - static inline void __io_xattr_finish(struct io_kiocb *req) 4394 + static void io_renameat_cleanup(struct io_kiocb *req) 4395 + { 4396 + struct io_rename *ren = io_kiocb_to_cmd(req); 4397 + 4398 + putname(ren->oldpath); 4399 + putname(ren->newpath); 4400 + } 4401 + 4402 + static inline void io_xattr_cleanup(struct io_kiocb *req) 4403 4403 { 4404 4404 struct io_xattr *ix = io_kiocb_to_cmd(req); 4405 4405 ··· 4422 4406 { 4423 4407 req->flags &= ~REQ_F_NEED_CLEANUP; 4424 4408 4425 - __io_xattr_finish(req); 4409 + io_xattr_cleanup(req); 4426 4410 io_req_complete(req, ret); 4427 4411 } 4428 4412 ··· 4691 4675 return 0; 4692 4676 } 4693 4677 4678 + static void io_unlinkat_cleanup(struct io_kiocb *req) 4679 + { 4680 + struct io_unlink *ul = io_kiocb_to_cmd(req); 4681 + 4682 + putname(ul->filename); 4683 + } 4684 + 4694 4685 static int io_mkdirat_prep(struct io_kiocb *req, 4695 4686 const struct io_uring_sqe *sqe) 4696 4687 { ··· 4734 4711 req->flags &= ~REQ_F_NEED_CLEANUP; 4735 4712 io_req_complete(req, ret); 4736 4713 return 0; 4714 + } 4715 + 4716 + static void io_mkdirat_cleanup(struct io_kiocb *req) 4717 + { 4718 + struct io_mkdir *md = io_kiocb_to_cmd(req); 4719 + 4720 + putname(md->filename); 4737 4721 } 4738 4722 4739 4723 static int io_symlinkat_prep(struct io_kiocb *req, ··· 4832 4802 req->flags &= ~REQ_F_NEED_CLEANUP; 4833 4803 io_req_complete(req, ret); 4834 4804 return 0; 4805 + } 4806 + 4807 + static void io_link_cleanup(struct io_kiocb *req) 4808 + { 4809 + struct io_link *sl = io_kiocb_to_cmd(req); 4810 + 4811 + putname(sl->oldpath); 4812 + putname(sl->newpath); 4835 4813 } 4836 4814 4837 4815 static void io_uring_cmd_work(struct io_kiocb *req, bool *locked) ··· 5352 5314 return io_openat2(req, issue_flags); 5353 5315 } 5354 5316 5317 + static void io_open_cleanup(struct io_kiocb *req) 5318 + { 5319 + struct io_open *open = io_kiocb_to_cmd(req); 5320 + 5321 + if (open->filename) 5322 + putname(open->filename); 5323 + } 5324 + 5355 5325 static int io_remove_buffers_prep(struct io_kiocb *req, 5356 5326 const struct io_uring_sqe *sqe) 5357 5327 { ··· 5771 5725 return 0; 5772 5726 } 5773 5727 5728 + static void io_statx_cleanup(struct io_kiocb *req) 5729 + { 5730 + struct io_statx *sx = io_kiocb_to_cmd(req); 5731 + 5732 + if (sx->filename) 5733 + putname(sx->filename); 5734 + } 5735 + 5774 5736 static int io_close_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) 5775 5737 { 5776 5738 struct io_close *close = io_kiocb_to_cmd(req); ··· 5949 5895 if (!ret) 5950 5896 req->flags |= REQ_F_NEED_CLEANUP; 5951 5897 return ret; 5898 + } 5899 + 5900 + static void io_sendmsg_recvmsg_cleanup(struct io_kiocb *req) 5901 + { 5902 + struct io_async_msghdr *io = req->async_data; 5903 + 5904 + kfree(io->free_iov); 5952 5905 } 5953 5906 5954 5907 static int io_sendmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) ··· 8019 7958 } 8020 7959 8021 7960 if (req->flags & REQ_F_NEED_CLEANUP) { 8022 - switch (req->opcode) { 8023 - case IORING_OP_READV: 8024 - case IORING_OP_READ_FIXED: 8025 - case IORING_OP_READ: 8026 - case IORING_OP_WRITEV: 8027 - case IORING_OP_WRITE_FIXED: 8028 - case IORING_OP_WRITE: { 8029 - struct io_async_rw *io = req->async_data; 7961 + const struct io_op_def *def = &io_op_defs[req->opcode]; 8030 7962 8031 - kfree(io->free_iovec); 8032 - break; 8033 - } 8034 - case IORING_OP_RECVMSG: 8035 - case IORING_OP_SENDMSG: { 8036 - struct io_async_msghdr *io = req->async_data; 8037 - 8038 - kfree(io->free_iov); 8039 - break; 8040 - } 8041 - case IORING_OP_OPENAT: 8042 - case IORING_OP_OPENAT2: { 8043 - struct io_open *open = io_kiocb_to_cmd(req); 8044 - 8045 - if (open->filename) 8046 - putname(open->filename); 8047 - break; 8048 - } 8049 - case IORING_OP_RENAMEAT: { 8050 - struct io_rename *ren = io_kiocb_to_cmd(req); 8051 - 8052 - putname(ren->oldpath); 8053 - putname(ren->newpath); 8054 - break; 8055 - } 8056 - case IORING_OP_UNLINKAT: { 8057 - struct io_unlink *ul = io_kiocb_to_cmd(req); 8058 - 8059 - putname(ul->filename); 8060 - break; 8061 - } 8062 - case IORING_OP_MKDIRAT: { 8063 - struct io_mkdir *md = io_kiocb_to_cmd(req); 8064 - 8065 - putname(md->filename); 8066 - break; 8067 - } 8068 - case IORING_OP_SYMLINKAT: 8069 - case IORING_OP_LINKAT: { 8070 - struct io_link *hl = io_kiocb_to_cmd(req); 8071 - 8072 - putname(hl->oldpath); 8073 - putname(hl->newpath); 8074 - break; 8075 - } 8076 - case IORING_OP_STATX: { 8077 - struct io_statx *sx = io_kiocb_to_cmd(req); 8078 - 8079 - if (sx->filename) 8080 - putname(sx->filename); 8081 - break; 8082 - } 8083 - case IORING_OP_SETXATTR: 8084 - case IORING_OP_FSETXATTR: 8085 - case IORING_OP_GETXATTR: 8086 - case IORING_OP_FGETXATTR: 8087 - __io_xattr_finish(req); 8088 - break; 8089 - } 7963 + if (def->cleanup) 7964 + def->cleanup(req); 8090 7965 } 8091 7966 if ((req->flags & REQ_F_POLLED) && req->apoll) { 8092 7967 kfree(req->apoll->double_poll); ··· 12835 12838 .prep = io_prep_rw, 12836 12839 .issue = io_read, 12837 12840 .prep_async = io_readv_prep_async, 12841 + .cleanup = io_readv_writev_cleanup, 12838 12842 }, 12839 12843 [IORING_OP_WRITEV] = { 12840 12844 .needs_file = 1, ··· 12850 12852 .prep = io_prep_rw, 12851 12853 .issue = io_write, 12852 12854 .prep_async = io_writev_prep_async, 12855 + .cleanup = io_readv_writev_cleanup, 12853 12856 }, 12854 12857 [IORING_OP_FSYNC] = { 12855 12858 .needs_file = 1, ··· 12910 12911 .prep = io_sendmsg_prep, 12911 12912 .issue = io_sendmsg, 12912 12913 .prep_async = io_sendmsg_prep_async, 12914 + #if defined(CONFIG_NET) 12915 + .cleanup = io_sendmsg_recvmsg_cleanup, 12916 + #endif 12913 12917 }, 12914 12918 [IORING_OP_RECVMSG] = { 12915 12919 .needs_file = 1, ··· 12924 12922 .prep = io_recvmsg_prep, 12925 12923 .issue = io_recvmsg, 12926 12924 .prep_async = io_recvmsg_prep_async, 12925 + #if defined(CONFIG_NET) 12926 + .cleanup = io_sendmsg_recvmsg_cleanup, 12927 + #endif 12927 12928 }, 12928 12929 [IORING_OP_TIMEOUT] = { 12929 12930 .audit_skip = 1, ··· 12977 12972 [IORING_OP_OPENAT] = { 12978 12973 .prep = io_openat_prep, 12979 12974 .issue = io_openat, 12975 + .cleanup = io_open_cleanup, 12980 12976 }, 12981 12977 [IORING_OP_CLOSE] = { 12982 12978 .prep = io_close_prep, ··· 12993 12987 .audit_skip = 1, 12994 12988 .prep = io_statx_prep, 12995 12989 .issue = io_statx, 12990 + .cleanup = io_statx_cleanup, 12996 12991 }, 12997 12992 [IORING_OP_READ] = { 12998 12993 .needs_file = 1, ··· 13053 13046 [IORING_OP_OPENAT2] = { 13054 13047 .prep = io_openat2_prep, 13055 13048 .issue = io_openat2, 13049 + .cleanup = io_open_cleanup, 13056 13050 }, 13057 13051 [IORING_OP_EPOLL_CTL] = { 13058 13052 .unbound_nonreg_file = 1, ··· 13097 13089 [IORING_OP_RENAMEAT] = { 13098 13090 .prep = io_renameat_prep, 13099 13091 .issue = io_renameat, 13092 + .cleanup = io_renameat_cleanup, 13100 13093 }, 13101 13094 [IORING_OP_UNLINKAT] = { 13102 13095 .prep = io_unlinkat_prep, 13103 13096 .issue = io_unlinkat, 13097 + .cleanup = io_unlinkat_cleanup, 13104 13098 }, 13105 13099 [IORING_OP_MKDIRAT] = { 13106 13100 .prep = io_mkdirat_prep, 13107 13101 .issue = io_mkdirat, 13102 + .cleanup = io_mkdirat_cleanup, 13108 13103 }, 13109 13104 [IORING_OP_SYMLINKAT] = { 13110 13105 .prep = io_symlinkat_prep, 13111 13106 .issue = io_symlinkat, 13107 + .cleanup = io_link_cleanup, 13112 13108 }, 13113 13109 [IORING_OP_LINKAT] = { 13114 13110 .prep = io_linkat_prep, 13115 13111 .issue = io_linkat, 13112 + .cleanup = io_link_cleanup, 13116 13113 }, 13117 13114 [IORING_OP_MSG_RING] = { 13118 13115 .needs_file = 1, ··· 13129 13116 .needs_file = 1, 13130 13117 .prep = io_fsetxattr_prep, 13131 13118 .issue = io_fsetxattr, 13119 + .cleanup = io_xattr_cleanup, 13132 13120 }, 13133 13121 [IORING_OP_SETXATTR] = { 13134 13122 .prep = io_setxattr_prep, 13135 13123 .issue = io_setxattr, 13124 + .cleanup = io_xattr_cleanup, 13136 13125 }, 13137 13126 [IORING_OP_FGETXATTR] = { 13138 13127 .needs_file = 1, 13139 13128 .prep = io_fgetxattr_prep, 13140 13129 .issue = io_fgetxattr, 13130 + .cleanup = io_xattr_cleanup, 13141 13131 }, 13142 13132 [IORING_OP_GETXATTR] = { 13143 13133 .prep = io_getxattr_prep, 13144 13134 .issue = io_getxattr, 13135 + .cleanup = io_xattr_cleanup, 13145 13136 }, 13146 13137 [IORING_OP_SOCKET] = { 13147 13138 .audit_skip = 1,