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 xattr related opcodes to its own file

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

+277 -247
+1 -1
io_uring/Makefile
··· 2 2 # 3 3 # Makefile for io_uring 4 4 5 - obj-$(CONFIG_IO_URING) += io_uring.o 5 + obj-$(CONFIG_IO_URING) += io_uring.o xattr.o 6 6 obj-$(CONFIG_IO_WQ) += io-wq.o
+2 -246
io_uring/io_uring.c
··· 80 80 #include <linux/io_uring.h> 81 81 #include <linux/audit.h> 82 82 #include <linux/security.h> 83 - #include <linux/xattr.h> 84 83 85 84 #define CREATE_TRACE_POINTS 86 85 #include <trace/events/io_uring.h> ··· 91 92 92 93 #include "io_uring_types.h" 93 94 #include "io_uring.h" 95 + 96 + #include "xattr.h" 94 97 95 98 #define IORING_MAX_ENTRIES 32768 96 99 #define IORING_MAX_CQ_ENTRIES (2 * IORING_MAX_ENTRIES) ··· 528 527 const struct iovec *free_iovec; 529 528 size_t bytes_done; 530 529 struct wait_page_queue wpq; 531 - }; 532 - 533 - struct io_xattr { 534 - struct file *file; 535 - struct xattr_ctx ctx; 536 - struct filename *filename; 537 530 }; 538 531 539 532 struct async_poll { ··· 3897 3902 3898 3903 putname(ren->oldpath); 3899 3904 putname(ren->newpath); 3900 - } 3901 - 3902 - static inline void io_xattr_cleanup(struct io_kiocb *req) 3903 - { 3904 - struct io_xattr *ix = io_kiocb_to_cmd(req); 3905 - 3906 - if (ix->filename) 3907 - putname(ix->filename); 3908 - 3909 - kfree(ix->ctx.kname); 3910 - kvfree(ix->ctx.kvalue); 3911 - } 3912 - 3913 - static void io_xattr_finish(struct io_kiocb *req, int ret) 3914 - { 3915 - req->flags &= ~REQ_F_NEED_CLEANUP; 3916 - 3917 - io_xattr_cleanup(req); 3918 - io_req_set_res(req, ret, 0); 3919 - } 3920 - 3921 - static int __io_getxattr_prep(struct io_kiocb *req, 3922 - const struct io_uring_sqe *sqe) 3923 - { 3924 - struct io_xattr *ix = io_kiocb_to_cmd(req); 3925 - const char __user *name; 3926 - int ret; 3927 - 3928 - if (unlikely(req->flags & REQ_F_FIXED_FILE)) 3929 - return -EBADF; 3930 - 3931 - ix->filename = NULL; 3932 - ix->ctx.kvalue = NULL; 3933 - name = u64_to_user_ptr(READ_ONCE(sqe->addr)); 3934 - ix->ctx.cvalue = u64_to_user_ptr(READ_ONCE(sqe->addr2)); 3935 - ix->ctx.size = READ_ONCE(sqe->len); 3936 - ix->ctx.flags = READ_ONCE(sqe->xattr_flags); 3937 - 3938 - if (ix->ctx.flags) 3939 - return -EINVAL; 3940 - 3941 - ix->ctx.kname = kmalloc(sizeof(*ix->ctx.kname), GFP_KERNEL); 3942 - if (!ix->ctx.kname) 3943 - return -ENOMEM; 3944 - 3945 - ret = strncpy_from_user(ix->ctx.kname->name, name, 3946 - sizeof(ix->ctx.kname->name)); 3947 - if (!ret || ret == sizeof(ix->ctx.kname->name)) 3948 - ret = -ERANGE; 3949 - if (ret < 0) { 3950 - kfree(ix->ctx.kname); 3951 - return ret; 3952 - } 3953 - 3954 - req->flags |= REQ_F_NEED_CLEANUP; 3955 - return 0; 3956 - } 3957 - 3958 - static int io_fgetxattr_prep(struct io_kiocb *req, 3959 - const struct io_uring_sqe *sqe) 3960 - { 3961 - return __io_getxattr_prep(req, sqe); 3962 - } 3963 - 3964 - static int io_getxattr_prep(struct io_kiocb *req, 3965 - const struct io_uring_sqe *sqe) 3966 - { 3967 - struct io_xattr *ix = io_kiocb_to_cmd(req); 3968 - const char __user *path; 3969 - int ret; 3970 - 3971 - ret = __io_getxattr_prep(req, sqe); 3972 - if (ret) 3973 - return ret; 3974 - 3975 - path = u64_to_user_ptr(READ_ONCE(sqe->addr3)); 3976 - 3977 - ix->filename = getname_flags(path, LOOKUP_FOLLOW, NULL); 3978 - if (IS_ERR(ix->filename)) { 3979 - ret = PTR_ERR(ix->filename); 3980 - ix->filename = NULL; 3981 - } 3982 - 3983 - return ret; 3984 - } 3985 - 3986 - static int io_fgetxattr(struct io_kiocb *req, unsigned int issue_flags) 3987 - { 3988 - struct io_xattr *ix = io_kiocb_to_cmd(req); 3989 - int ret; 3990 - 3991 - if (issue_flags & IO_URING_F_NONBLOCK) 3992 - return -EAGAIN; 3993 - 3994 - ret = do_getxattr(mnt_user_ns(req->file->f_path.mnt), 3995 - req->file->f_path.dentry, 3996 - &ix->ctx); 3997 - 3998 - io_xattr_finish(req, ret); 3999 - return IOU_OK; 4000 - } 4001 - 4002 - static int io_getxattr(struct io_kiocb *req, unsigned int issue_flags) 4003 - { 4004 - struct io_xattr *ix = io_kiocb_to_cmd(req); 4005 - unsigned int lookup_flags = LOOKUP_FOLLOW; 4006 - struct path path; 4007 - int ret; 4008 - 4009 - if (issue_flags & IO_URING_F_NONBLOCK) 4010 - return -EAGAIN; 4011 - 4012 - retry: 4013 - ret = filename_lookup(AT_FDCWD, ix->filename, lookup_flags, &path, NULL); 4014 - if (!ret) { 4015 - ret = do_getxattr(mnt_user_ns(path.mnt), 4016 - path.dentry, 4017 - &ix->ctx); 4018 - 4019 - path_put(&path); 4020 - if (retry_estale(ret, lookup_flags)) { 4021 - lookup_flags |= LOOKUP_REVAL; 4022 - goto retry; 4023 - } 4024 - } 4025 - 4026 - io_xattr_finish(req, ret); 4027 - return IOU_OK; 4028 - } 4029 - 4030 - static int __io_setxattr_prep(struct io_kiocb *req, 4031 - const struct io_uring_sqe *sqe) 4032 - { 4033 - struct io_xattr *ix = io_kiocb_to_cmd(req); 4034 - const char __user *name; 4035 - int ret; 4036 - 4037 - if (unlikely(req->flags & REQ_F_FIXED_FILE)) 4038 - return -EBADF; 4039 - 4040 - ix->filename = NULL; 4041 - name = u64_to_user_ptr(READ_ONCE(sqe->addr)); 4042 - ix->ctx.cvalue = u64_to_user_ptr(READ_ONCE(sqe->addr2)); 4043 - ix->ctx.kvalue = NULL; 4044 - ix->ctx.size = READ_ONCE(sqe->len); 4045 - ix->ctx.flags = READ_ONCE(sqe->xattr_flags); 4046 - 4047 - ix->ctx.kname = kmalloc(sizeof(*ix->ctx.kname), GFP_KERNEL); 4048 - if (!ix->ctx.kname) 4049 - return -ENOMEM; 4050 - 4051 - ret = setxattr_copy(name, &ix->ctx); 4052 - if (ret) { 4053 - kfree(ix->ctx.kname); 4054 - return ret; 4055 - } 4056 - 4057 - req->flags |= REQ_F_NEED_CLEANUP; 4058 - return 0; 4059 - } 4060 - 4061 - static int io_setxattr_prep(struct io_kiocb *req, 4062 - const struct io_uring_sqe *sqe) 4063 - { 4064 - struct io_xattr *ix = io_kiocb_to_cmd(req); 4065 - const char __user *path; 4066 - int ret; 4067 - 4068 - ret = __io_setxattr_prep(req, sqe); 4069 - if (ret) 4070 - return ret; 4071 - 4072 - path = u64_to_user_ptr(READ_ONCE(sqe->addr3)); 4073 - 4074 - ix->filename = getname_flags(path, LOOKUP_FOLLOW, NULL); 4075 - if (IS_ERR(ix->filename)) { 4076 - ret = PTR_ERR(ix->filename); 4077 - ix->filename = NULL; 4078 - } 4079 - 4080 - return ret; 4081 - } 4082 - 4083 - static int io_fsetxattr_prep(struct io_kiocb *req, 4084 - const struct io_uring_sqe *sqe) 4085 - { 4086 - return __io_setxattr_prep(req, sqe); 4087 - } 4088 - 4089 - static int __io_setxattr(struct io_kiocb *req, unsigned int issue_flags, 4090 - struct path *path) 4091 - { 4092 - struct io_xattr *ix = io_kiocb_to_cmd(req); 4093 - int ret; 4094 - 4095 - ret = mnt_want_write(path->mnt); 4096 - if (!ret) { 4097 - ret = do_setxattr(mnt_user_ns(path->mnt), path->dentry, &ix->ctx); 4098 - mnt_drop_write(path->mnt); 4099 - } 4100 - 4101 - return ret; 4102 - } 4103 - 4104 - static int io_fsetxattr(struct io_kiocb *req, unsigned int issue_flags) 4105 - { 4106 - int ret; 4107 - 4108 - if (issue_flags & IO_URING_F_NONBLOCK) 4109 - return -EAGAIN; 4110 - 4111 - ret = __io_setxattr(req, issue_flags, &req->file->f_path); 4112 - io_xattr_finish(req, ret); 4113 - return IOU_OK; 4114 - } 4115 - 4116 - static int io_setxattr(struct io_kiocb *req, unsigned int issue_flags) 4117 - { 4118 - struct io_xattr *ix = io_kiocb_to_cmd(req); 4119 - unsigned int lookup_flags = LOOKUP_FOLLOW; 4120 - struct path path; 4121 - int ret; 4122 - 4123 - if (issue_flags & IO_URING_F_NONBLOCK) 4124 - return -EAGAIN; 4125 - 4126 - retry: 4127 - ret = filename_lookup(AT_FDCWD, ix->filename, lookup_flags, &path, NULL); 4128 - if (!ret) { 4129 - ret = __io_setxattr(req, issue_flags, &path); 4130 - path_put(&path); 4131 - if (retry_estale(ret, lookup_flags)) { 4132 - lookup_flags |= LOOKUP_REVAL; 4133 - goto retry; 4134 - } 4135 - } 4136 - 4137 - io_xattr_finish(req, ret); 4138 - return IOU_OK; 4139 3905 } 4140 3906 4141 3907 static int io_unlinkat_prep(struct io_kiocb *req,
+259
io_uring/xattr.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + #include <linux/kernel.h> 3 + #include <linux/errno.h> 4 + #include <linux/fs.h> 5 + #include <linux/file.h> 6 + #include <linux/mm.h> 7 + #include <linux/slab.h> 8 + #include <linux/namei.h> 9 + #include <linux/io_uring.h> 10 + #include <linux/xattr.h> 11 + 12 + #include <uapi/linux/io_uring.h> 13 + 14 + #include "../fs/internal.h" 15 + 16 + #include "io_uring_types.h" 17 + #include "io_uring.h" 18 + #include "xattr.h" 19 + 20 + struct io_xattr { 21 + struct file *file; 22 + struct xattr_ctx ctx; 23 + struct filename *filename; 24 + }; 25 + 26 + void io_xattr_cleanup(struct io_kiocb *req) 27 + { 28 + struct io_xattr *ix = io_kiocb_to_cmd(req); 29 + 30 + if (ix->filename) 31 + putname(ix->filename); 32 + 33 + kfree(ix->ctx.kname); 34 + kvfree(ix->ctx.kvalue); 35 + } 36 + 37 + static void io_xattr_finish(struct io_kiocb *req, int ret) 38 + { 39 + req->flags &= ~REQ_F_NEED_CLEANUP; 40 + 41 + io_xattr_cleanup(req); 42 + io_req_set_res(req, ret, 0); 43 + } 44 + 45 + static int __io_getxattr_prep(struct io_kiocb *req, 46 + const struct io_uring_sqe *sqe) 47 + { 48 + struct io_xattr *ix = io_kiocb_to_cmd(req); 49 + const char __user *name; 50 + int ret; 51 + 52 + if (unlikely(req->flags & REQ_F_FIXED_FILE)) 53 + return -EBADF; 54 + 55 + ix->filename = NULL; 56 + ix->ctx.kvalue = NULL; 57 + name = u64_to_user_ptr(READ_ONCE(sqe->addr)); 58 + ix->ctx.cvalue = u64_to_user_ptr(READ_ONCE(sqe->addr2)); 59 + ix->ctx.size = READ_ONCE(sqe->len); 60 + ix->ctx.flags = READ_ONCE(sqe->xattr_flags); 61 + 62 + if (ix->ctx.flags) 63 + return -EINVAL; 64 + 65 + ix->ctx.kname = kmalloc(sizeof(*ix->ctx.kname), GFP_KERNEL); 66 + if (!ix->ctx.kname) 67 + return -ENOMEM; 68 + 69 + ret = strncpy_from_user(ix->ctx.kname->name, name, 70 + sizeof(ix->ctx.kname->name)); 71 + if (!ret || ret == sizeof(ix->ctx.kname->name)) 72 + ret = -ERANGE; 73 + if (ret < 0) { 74 + kfree(ix->ctx.kname); 75 + return ret; 76 + } 77 + 78 + req->flags |= REQ_F_NEED_CLEANUP; 79 + return 0; 80 + } 81 + 82 + int io_fgetxattr_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) 83 + { 84 + return __io_getxattr_prep(req, sqe); 85 + } 86 + 87 + int io_getxattr_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) 88 + { 89 + struct io_xattr *ix = io_kiocb_to_cmd(req); 90 + const char __user *path; 91 + int ret; 92 + 93 + ret = __io_getxattr_prep(req, sqe); 94 + if (ret) 95 + return ret; 96 + 97 + path = u64_to_user_ptr(READ_ONCE(sqe->addr3)); 98 + 99 + ix->filename = getname_flags(path, LOOKUP_FOLLOW, NULL); 100 + if (IS_ERR(ix->filename)) { 101 + ret = PTR_ERR(ix->filename); 102 + ix->filename = NULL; 103 + } 104 + 105 + return ret; 106 + } 107 + 108 + int io_fgetxattr(struct io_kiocb *req, unsigned int issue_flags) 109 + { 110 + struct io_xattr *ix = io_kiocb_to_cmd(req); 111 + int ret; 112 + 113 + if (issue_flags & IO_URING_F_NONBLOCK) 114 + return -EAGAIN; 115 + 116 + ret = do_getxattr(mnt_user_ns(req->file->f_path.mnt), 117 + req->file->f_path.dentry, 118 + &ix->ctx); 119 + 120 + io_xattr_finish(req, ret); 121 + return IOU_OK; 122 + } 123 + 124 + int io_getxattr(struct io_kiocb *req, unsigned int issue_flags) 125 + { 126 + struct io_xattr *ix = io_kiocb_to_cmd(req); 127 + unsigned int lookup_flags = LOOKUP_FOLLOW; 128 + struct path path; 129 + int ret; 130 + 131 + if (issue_flags & IO_URING_F_NONBLOCK) 132 + return -EAGAIN; 133 + 134 + retry: 135 + ret = filename_lookup(AT_FDCWD, ix->filename, lookup_flags, &path, NULL); 136 + if (!ret) { 137 + ret = do_getxattr(mnt_user_ns(path.mnt), 138 + path.dentry, 139 + &ix->ctx); 140 + 141 + path_put(&path); 142 + if (retry_estale(ret, lookup_flags)) { 143 + lookup_flags |= LOOKUP_REVAL; 144 + goto retry; 145 + } 146 + } 147 + 148 + io_xattr_finish(req, ret); 149 + return IOU_OK; 150 + } 151 + 152 + static int __io_setxattr_prep(struct io_kiocb *req, 153 + const struct io_uring_sqe *sqe) 154 + { 155 + struct io_xattr *ix = io_kiocb_to_cmd(req); 156 + const char __user *name; 157 + int ret; 158 + 159 + if (unlikely(req->flags & REQ_F_FIXED_FILE)) 160 + return -EBADF; 161 + 162 + ix->filename = NULL; 163 + name = u64_to_user_ptr(READ_ONCE(sqe->addr)); 164 + ix->ctx.cvalue = u64_to_user_ptr(READ_ONCE(sqe->addr2)); 165 + ix->ctx.kvalue = NULL; 166 + ix->ctx.size = READ_ONCE(sqe->len); 167 + ix->ctx.flags = READ_ONCE(sqe->xattr_flags); 168 + 169 + ix->ctx.kname = kmalloc(sizeof(*ix->ctx.kname), GFP_KERNEL); 170 + if (!ix->ctx.kname) 171 + return -ENOMEM; 172 + 173 + ret = setxattr_copy(name, &ix->ctx); 174 + if (ret) { 175 + kfree(ix->ctx.kname); 176 + return ret; 177 + } 178 + 179 + req->flags |= REQ_F_NEED_CLEANUP; 180 + return 0; 181 + } 182 + 183 + int io_setxattr_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) 184 + { 185 + struct io_xattr *ix = io_kiocb_to_cmd(req); 186 + const char __user *path; 187 + int ret; 188 + 189 + ret = __io_setxattr_prep(req, sqe); 190 + if (ret) 191 + return ret; 192 + 193 + path = u64_to_user_ptr(READ_ONCE(sqe->addr3)); 194 + 195 + ix->filename = getname_flags(path, LOOKUP_FOLLOW, NULL); 196 + if (IS_ERR(ix->filename)) { 197 + ret = PTR_ERR(ix->filename); 198 + ix->filename = NULL; 199 + } 200 + 201 + return ret; 202 + } 203 + 204 + int io_fsetxattr_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) 205 + { 206 + return __io_setxattr_prep(req, sqe); 207 + } 208 + 209 + static int __io_setxattr(struct io_kiocb *req, unsigned int issue_flags, 210 + struct path *path) 211 + { 212 + struct io_xattr *ix = io_kiocb_to_cmd(req); 213 + int ret; 214 + 215 + ret = mnt_want_write(path->mnt); 216 + if (!ret) { 217 + ret = do_setxattr(mnt_user_ns(path->mnt), path->dentry, &ix->ctx); 218 + mnt_drop_write(path->mnt); 219 + } 220 + 221 + return ret; 222 + } 223 + 224 + int io_fsetxattr(struct io_kiocb *req, unsigned int issue_flags) 225 + { 226 + int ret; 227 + 228 + if (issue_flags & IO_URING_F_NONBLOCK) 229 + return -EAGAIN; 230 + 231 + ret = __io_setxattr(req, issue_flags, &req->file->f_path); 232 + io_xattr_finish(req, ret); 233 + return IOU_OK; 234 + } 235 + 236 + int io_setxattr(struct io_kiocb *req, unsigned int issue_flags) 237 + { 238 + struct io_xattr *ix = io_kiocb_to_cmd(req); 239 + unsigned int lookup_flags = LOOKUP_FOLLOW; 240 + struct path path; 241 + int ret; 242 + 243 + if (issue_flags & IO_URING_F_NONBLOCK) 244 + return -EAGAIN; 245 + 246 + retry: 247 + ret = filename_lookup(AT_FDCWD, ix->filename, lookup_flags, &path, NULL); 248 + if (!ret) { 249 + ret = __io_setxattr(req, issue_flags, &path); 250 + path_put(&path); 251 + if (retry_estale(ret, lookup_flags)) { 252 + lookup_flags |= LOOKUP_REVAL; 253 + goto retry; 254 + } 255 + } 256 + 257 + io_xattr_finish(req, ret); 258 + return IOU_OK; 259 + }
+15
io_uring/xattr.h
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + 3 + void io_xattr_cleanup(struct io_kiocb *req); 4 + 5 + int io_fsetxattr_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe); 6 + int io_fsetxattr(struct io_kiocb *req, unsigned int issue_flags); 7 + 8 + int io_setxattr_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe); 9 + int io_setxattr(struct io_kiocb *req, unsigned int issue_flags); 10 + 11 + int io_fgetxattr_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe); 12 + int io_fgetxattr(struct io_kiocb *req, unsigned int issue_flags); 13 + 14 + int io_getxattr_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe); 15 + int io_getxattr(struct io_kiocb *req, unsigned int issue_flags);