io_uring: add mkdir and [sym]linkat support
Subsystems (3)
v6 cover io_uring: add mkdir and [sym]linkat support
This started out as an attempt to add mkdirat support to io_uring which is heavily based on renameat() / unlinkat() support.
During the review process more operations were added (linkat, symlinkat, mknodat) mainly to keep things uniform internally (in namei.c), and with things changed in namei.c adding support for these operations to io_uring is trivial, so that was done too (except for mknodat). See
https://lore.kernel.org/io-uring/20210514145259.wtl4xcsp52woi6ab@wittgenstein/
The first patch is preparation with no functional changes, makes do_mkdirat accept struct filename pointer rather than the user string.
The second one leverages that to implement mkdirat in io_uring.
3-6 just convert other similar do_* functions in namei.c to accept struct filename, for uniformity with do_mkdirat, do_renameat and do_unlinkat. No functional changes there.
7 changes do_* helpers in namei.c to return ints rather than some of them returning ints and some longs.
8-9 add symlinkat and linkat support to io_uring correspondingly.
Based on for-5.14/io_uring.
v6:
- rebase
- add safety checks for IOPOLL mode
- add safety checks for unused sqe parts
- drop mknodat support from io_uring as requested by Jens
- add Christian's Acked-by
v5:
- rebase
- add symlinkat, linkat and mknodat support to io_uring
v4:
- update do_mknodat, do_symlinkat and do_linkat to accept struct filename for uniformity with do_mkdirat, do_renameat and do_unlinkat;
v3:
- rebase;
v2:
- do not mess with struct filename's refcount in do_mkdirat, instead add and use __filename_create() that does not drop the name on success;
Dmitry Kadashev (9):
fs: make do_mkdirat() take struct filename
io_uring: add support for IORING_OP_MKDIRAT
fs: make do_mknodat() take struct filename
fs: make do_symlinkat() take struct filename
namei: add getname_uflags()
fs: make do_linkat() take struct filename
fs: update do_*() helpers to return ints
io_uring: add support for IORING_OP_SYMLINKAT
io_uring: add support for IORING_OP_LINKAT
fs/exec.c | 8 +- fs/internal.h | 8 +- fs/io_uring.c | 196 ++++++++++++++++++++++++++++++++++ fs/namei.c | 137 ++++++++++++++++-------- include/linux/fs.h | 1 + include/uapi/linux/io_uring.h | 4 + 6 files changed, 301 insertions(+), 53 deletions(-)
Signature · 1 line
2.30.2
PATCH v6 1/9 fs: make do_mkdirat() take struct filename
Pass in the struct filename pointers instead of the user string, and update the three callers to do the same. This is heavily based on commit dbea8d345177 ("fs: make do_renameat2() take struct filename").
This behaves like do_unlinkat() and do_renameat2().
--- fs/internal.h | 1 + fs/namei.c | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-)
fs/internal.h +1 -0
@@ -77,6 +77,7 @@ long do_unlinkat(int dfd, struct filename *name);int may_linkat (struct user_namespace *mnt_userns,struct path *link);int do_renameat2 (int olddfd,struct filename *oldname,int newdfd,struct filename *newname,unsigned int flags); +long do_mkdirat (int dfd,struct filename *name,umode_t mode);/* * namespace.c
fs/namei.c +16 -6
@@ -3556,7 +3556,7 @@ struct file *do_file_open_root(struct dentry *dentry, struct vfsmount *mnt,return file; } -static struct dentry *filename_create (int dfd,struct filename *name, +static struct dentry *__filename_create (int dfd,struct filename *name,struct path *path,unsigned int lookup_flags) {struct dentry *dentry =ERR_PTR (-EEXIST );
@@ -3612,7 +3612,6 @@ static struct dentry *filename_create(int dfd, struct filename *name, error = err2; goto fail; } -putname (name);return dentry; fail:dput (dentry);
@@ -3627,6 +3626,16 @@ static struct dentry *filename_create(int dfd, struct filename *name,return dentry; } +static inline struct dentry *filename_create (int dfd,struct filename *name, +struct path *path,unsigned int lookup_flags) +{ +struct dentry *res =__filename_create (dfd, name, path, lookup_flags); + +if (!IS_ERR (res)) +putname (name); +return res; +} +struct dentry *kern_path_create (int dfd,const char *pathname,struct path *path,unsigned int lookup_flags) {
@@ -3817,7 +3826,7 @@ int vfs_mkdir(struct user_namespace *mnt_userns, struct inode *dir, }EXPORT_SYMBOL (vfs_mkdir); -static long do_mkdirat (int dfd,const char __user *pathname,umode_t mode) +long do_mkdirat (int dfd,struct filename *name,umode_t mode) {struct dentry *dentry;struct path path;
@@ -3825,7 +3834,7 @@ static long do_mkdirat(int dfd, const char __user *pathname, umode_t mode)unsigned int lookup_flags =LOOKUP_DIRECTORY ; retry: - dentry =user_path_create (dfd, pathname, &path, lookup_flags); + dentry =__filename_create (dfd, name, &path, lookup_flags);if (IS_ERR (dentry))return PTR_ERR (dentry);
@@ -3843,17 +3852,18 @@ static long do_mkdirat(int dfd, const char __user *pathname, umode_t mode) lookup_flags |=LOOKUP_REVAL ; goto retry; } +putname (name);return error; } SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode) { -return do_mkdirat (dfd, pathname, mode); +return do_mkdirat (dfd,getname (pathname), mode); } SYSCALL_DEFINE2(mkdir, const char __user *, pathname, umode_t, mode) { -return do_mkdirat (AT_FDCWD , pathname, mode); +return do_mkdirat (AT_FDCWD ,getname (pathname), mode); }/**
Signature · 1 line
2.30.2
PATCH v6 2/9 io_uring: add support for IORING_OP_MKDIRAT
In reply to Dmitry KadashevIORING_OP_MKDIRAT behaves like mkdirat(2) and takes the same flags and arguments.
--- fs/io_uring.c | 59 +++++++++++++++++++++++++++++++++++ include/uapi/linux/io_uring.h | 1 + 2 files changed, 60 insertions(+)
fs/io_uring.c +59 -0
@@ -673,6 +673,13 @@ struct io_unlink {struct filename *filename; }; +struct io_mkdir { +struct file *file; +int dfd; +umode_t mode; +struct filename *filename; +}; +struct io_completion {struct file *file;struct list_head list;
@@ -825,6 +832,7 @@ struct io_kiocb {struct io_shutdown shutdown;struct io_rename rename;struct io_unlink unlink; +struct io_mkdir mkdir;/* use only after cleaning per-op data, see io_clean_op() */ struct io_completion compl; };
@@ -1039,6 +1047,7 @@ static const struct io_op_def io_op_defs[] = { }, [IORING_OP_RENAMEAT] = {}, [IORING_OP_UNLINKAT] = {}, + [IORING_OP_MKDIRAT] = {}, };static bool io_disarm_next (struct io_kiocb *req);
@@ -3548,6 +3557,48 @@ static int io_unlinkat(struct io_kiocb *req, unsigned int issue_flags)return 0 ; } +static int io_mkdirat_prep (struct io_kiocb *req, +const struct io_uring_sqe *sqe) +{ +struct io_mkdir *mkd = &req->mkdir; +const char __user *fname; + +if (unlikely (req->ctx->flags &IORING_SETUP_IOPOLL )) +return -EINVAL ; +if (sqe->ioprio || sqe->off || sqe->rw_flags || sqe->buf_index) +return -EINVAL ; +if (unlikely (req->flags &REQ_F_FIXED_FILE )) +return -EBADF ; + + mkd->dfd =READ_ONCE (sqe->fd); + mkd->mode =READ_ONCE (sqe->len); + + fname =u64_to_user_ptr (READ_ONCE (sqe->addr)); + mkd->filename =getname (fname); +if (IS_ERR (mkd->filename)) +return PTR_ERR (mkd->filename); + + req->flags |=REQ_F_NEED_CLEANUP ; +return 0 ; +} + +static int io_mkdirat (struct io_kiocb *req,int issue_flags) +{ +struct io_mkdir *mkd = &req->mkdir; +int ret; + +if (issue_flags &IO_URING_F_NONBLOCK ) +return -EAGAIN ; + + ret =do_mkdirat (mkd->dfd, mkd->filename, mkd->mode); + + req->flags &= ~REQ_F_NEED_CLEANUP ; +if (ret <0 ) +req_set_fail (req); +io_req_complete (req, ret); +return 0 ; +} +static int io_shutdown_prep (struct io_kiocb *req,const struct io_uring_sqe *sqe) {
@@ -5956,6 +6007,8 @@ static int io_req_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)return io_renameat_prep (req, sqe);case IORING_OP_UNLINKAT :return io_unlinkat_prep (req, sqe); +case IORING_OP_MKDIRAT : +return io_mkdirat_prep (req, sqe); } printk_once(KERN_WARNING "io_uring: unhandled opcode %d\n",
@@ -6117,6 +6170,9 @@ static void io_clean_op(struct io_kiocb *req)case IORING_OP_UNLINKAT :putname (req->unlink.filename);break ; +case IORING_OP_MKDIRAT : +putname (req->mkdir.filename); +break ; } }if ((req->flags &REQ_F_POLLED ) && req->apoll) {
@@ -6245,6 +6301,9 @@ static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags)case IORING_OP_UNLINKAT : ret =io_unlinkat (req, issue_flags);break ; +case IORING_OP_MKDIRAT : + ret =io_mkdirat (req, issue_flags); +break ;default : ret = -EINVAL ;break ;
include/uapi/linux/io_uring.h +1 -0
@@ -137,6 +137,7 @@ enum {IORING_OP_SHUTDOWN ,IORING_OP_RENAMEAT ,IORING_OP_UNLINKAT , +IORING_OP_MKDIRAT ,/* this goes last, obviously */ IORING_OP_LAST,
Signature · 1 line
2.30.2
PATCH v6 3/9 fs: make do_mknodat() take struct filename
In reply to Dmitry KadashevPass in the struct filename pointers instead of the user string, for uniformity with the recently converted do_unlinkat(), do_renameat(), do_mkdirat().
--- fs/namei.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
fs/namei.c +10 -7
@@ -3724,7 +3724,7 @@ static int may_mknod(umode_t mode) } } -static long do_mknodat (int dfd,const char __user *filename,umode_t mode, +static long do_mknodat (int dfd,struct filename *name,umode_t mode,unsigned int dev) {struct user_namespace *mnt_userns;
@@ -3735,9 +3735,9 @@ static long do_mknodat(int dfd, const char __user *filename, umode_t mode, error =may_mknod (mode);if (error) -return error; + goto out1; retry: - dentry =user_path_create (dfd, filename, &path, lookup_flags); + dentry =__filename_create (dfd, name, &path, lookup_flags);if (IS_ERR (dentry))return PTR_ERR (dentry);
@@ -3745,7 +3745,7 @@ static long do_mknodat(int dfd, const char __user *filename, umode_t mode, mode &= ~current_umask (); error =security_path_mknod (&path, dentry, mode, dev);if (error) - goto out; + goto out2; mnt_userns =mnt_user_ns (path.mnt);switch (mode &S_IFMT ) {
@@ -3764,24 +3764,27 @@ static long do_mknodat(int dfd, const char __user *filename, umode_t mode, dentry, mode, 0);break ; } -out: +out2:done_path_create (&path, dentry);if (retry_estale (error, lookup_flags)) { lookup_flags |=LOOKUP_REVAL ; goto retry; } +out1: +if (!IS_ERR (name)) +putname (name);return error; } SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode, unsigned int, dev) { -return do_mknodat (dfd, filename, mode, dev); +return do_mknodat (dfd,getname (filename), mode, dev); } SYSCALL_DEFINE3(mknod, const char __user *, filename, umode_t, mode, unsigned, dev) { -return do_mknodat (AT_FDCWD , filename, mode, dev); +return do_mknodat (AT_FDCWD ,getname (filename), mode, dev); }/**
Signature · 1 line
2.30.2
PATCH v6 4/9 fs: make do_symlinkat() take struct filename
In reply to Dmitry KadashevPass in the struct filename pointers instead of the user string, for uniformity with the recently converted do_mkdnodat(), do_unlinkat(), do_renameat(), do_mkdirat().
--- fs/namei.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-)
fs/namei.c +16 -12
@@ -4189,23 +4189,23 @@ int vfs_symlink(struct user_namespace *mnt_userns, struct inode *dir, }EXPORT_SYMBOL (vfs_symlink); -static long do_symlinkat (const char __user *oldname,int newdfd, -const char __user *newname) +static long do_symlinkat (struct filename *from,int newdfd, +struct filename *to) {int error; -struct filename *from;struct dentry *dentry;struct path path;unsigned int lookup_flags =0 ; - from =getname (oldname); -if (IS_ERR (from)) -return PTR_ERR (from); +if (IS_ERR (from)) { + error =PTR_ERR (from); + goto out_putboth; + } retry: - dentry =user_path_create (newdfd, newname, &path, lookup_flags); + dentry =__filename_create (newdfd, to, &path, lookup_flags); error =PTR_ERR (dentry);if (IS_ERR (dentry)) - goto out_putname; + goto out_putfrom; error =security_path_symlink (&path, dentry, from->name);if (!error) {
@@ -4220,20 +4220,24 @@ static long do_symlinkat(const char __user *oldname, int newdfd, lookup_flags |=LOOKUP_REVAL ; goto retry; } -out_putname: -putname (from); +out_putboth: +if (!IS_ERR (to)) +putname (to); +out_putfrom: +if (!IS_ERR (from)) +putname (from);return error; } SYSCALL_DEFINE3(symlinkat, const char __user *, oldname, int, newdfd, const char __user *, newname) { -return do_symlinkat (oldname, newdfd, newname); +return do_symlinkat (getname (oldname), newdfd,getname (newname)); } SYSCALL_DEFINE2(symlink, const char __user *, oldname, const char __user *, newname) { -return do_symlinkat (oldname,AT_FDCWD , newname); +return do_symlinkat (getname (oldname),AT_FDCWD ,getname (newname)); }/**
Signature · 1 line
2.30.2
PATCH v6 5/9 namei: add getname_uflags()
In reply to Dmitry KadashevThere are a couple of places where we already open-code the (flags & AT_EMPTY_PATH) check and io_uring will likely add another one in the future. Let's just add a simple helper getname_uflags() that handles this directly and use it.
--- fs/exec.c | 8 ++------ fs/namei.c | 8 ++++++++ include/linux/fs.h | 1 + 3 files changed, 11 insertions(+), 6 deletions(-)
fs/exec.c +2 -6
@@ -2069,10 +2069,8 @@ SYSCALL_DEFINE5(execveat, const char __user *const __user *, envp, int, flags) { - int lookup_flags = (flags & AT_EMPTY_PATH) ? LOOKUP_EMPTY : 0; - return do_execveat(fd, -getname_flags (filename, lookup_flags,NULL ), +getname_uflags (filename ,flags ),argv ,envp ,flags ); }
@@ -2090,10 +2088,8 @@ COMPAT_SYSCALL_DEFINE5(execveat, int, fd, const compat_uptr_t __user *, envp, int, flags) { - int lookup_flags = (flags & AT_EMPTY_PATH) ? LOOKUP_EMPTY : 0; - return compat_do_execveat(fd, -getname_flags (filename, lookup_flags,NULL ), +getname_uflags (filename ,flags ),argv ,envp ,flags ); }#endif
fs/namei.c +8 -0
@@ -203,6 +203,14 @@ getname_flags(const char __user *filename, int flags, int *empty)return result; } +struct filename * +getname_uflags (const char __user *filename,int uflags) +{ +int flags = (uflags &AT_EMPTY_PATH ) ?LOOKUP_EMPTY :0 ; + +return getname_flags (filename, flags,NULL ); +} +struct filename *getname (const char __user * filename) {
include/linux/fs.h +1 -0
@@ -2781,6 +2781,7 @@ static inline struct file *file_clone_open(struct file *file)extern int filp_close (struct file *,fl_owner_t id);extern struct filename *getname_flags (const char __user *,int ,int *); +extern struct filename *getname_uflags (const char __user *,int );extern struct filename *getname (const char __user *);extern struct filename *getname_kernel (const char *);extern void putname (struct filename *name);
Signature · 1 line
2.30.2
PATCH v6 6/9 fs: make do_linkat() take struct filename
In reply to Dmitry KadashevPass in the struct filename pointers instead of the user string, for uniformity with do_renameat2, do_unlinkat, do_mknodat, etc.
--- fs/namei.c | 59 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 18 deletions(-)
fs/namei.c +41 -18
@@ -2447,7 +2447,7 @@ static int path_lookupat(struct nameidata *nd, unsigned flags, struct path *pathreturn err; } -int filename_lookup (int dfd,struct filename *name,unsigned flags, +static int __filename_lookup (int dfd,struct filename *name,unsigned flags,struct path *path,struct path *root) {int retval;
@@ -2469,7 +2469,18 @@ int filename_lookup(int dfd, struct filename *name, unsigned flags,audit_inode (name, path->dentry, flags &LOOKUP_MOUNTPOINT ?AUDIT_INODE_NOEVAL :0 );restore_nameidata (); -putname (name); +if (retval) +putname (name); +return retval; +} + +int filename_lookup (int dfd,struct filename *name,unsigned flags, +struct path *path,struct path *root) +{ +int retval =__filename_lookup (dfd, name, flags, path, root); + +if (!retval) +putname (name);return retval; }
@@ -4346,8 +4357,8 @@ EXPORT_SYMBOL(vfs_link);* with linux 2.0, and to avoid hard-linking to directories * and other special files. --ADM */ -static int do_linkat (int olddfd,const char __user *oldname,int newdfd, -const char __user *newname,int flags) +static int do_linkat (int olddfd,struct filename *old,int newdfd, +struct filename *new,int flags) {struct user_namespace *mnt_userns;struct dentry *new_dentry;
@@ -4356,31 +4367,36 @@ static int do_linkat(int olddfd, const char __user *oldname, int newdfd,int how =0 ;int error; -if ((flags & ~(AT_SYMLINK_FOLLOW |AT_EMPTY_PATH )) !=0 ) -return -EINVAL ; +if ((flags & ~(AT_SYMLINK_FOLLOW |AT_EMPTY_PATH )) !=0 ) { + error = -EINVAL ; + goto out_putnames; + }/* * To use null names we require CAP_DAC_READ_SEARCH * This ensures that not everyone will be able to create * handlink using the passed filedescriptor. */ -if (flags &AT_EMPTY_PATH ) { -if (!capable (CAP_DAC_READ_SEARCH )) -return -ENOENT ; - how =LOOKUP_EMPTY ; +if (flags &AT_EMPTY_PATH && !capable (CAP_DAC_READ_SEARCH )) { + error = -ENOENT ; + goto out_putnames; }if (flags &AT_SYMLINK_FOLLOW ) how |=LOOKUP_FOLLOW ; retry: - error =user_path_at (olddfd, oldname, how, &old_path); + error =__filename_lookup (olddfd, old, how, &old_path,NULL );if (error) -return error; + goto out_putnew; - new_dentry =user_path_create (newdfd, newname, &new_path, + new_dentry =__filename_create (newdfd, new, &new_path, (how &LOOKUP_REVAL )); error =PTR_ERR (new_dentry); -if (IS_ERR (new_dentry)) - goto out; +if (IS_ERR (new_dentry)) { +// On error `new` is freed by __filename_create, prevent extra freeing +// below + new =ERR_PTR (error); + goto out_putpath; + } error = -EXDEV ;if (old_path.mnt != new_path.mnt)
@@ -4408,8 +4424,14 @@ static int do_linkat(int olddfd, const char __user *oldname, int newdfd, how |=LOOKUP_REVAL ; goto retry; } -out: +out_putpath:path_put (&old_path); +out_putnames: +if (!IS_ERR (old)) +putname (old); +out_putnew: +if (!IS_ERR (new)) +putname (new);return error; }
@@ -4417,12 +4439,13 @@ static int do_linkat(int olddfd, const char __user *oldname, int newdfd, SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname, int, newdfd, const char __user *, newname, int, flags) { -return do_linkat (olddfd, oldname, newdfd, newname, flags); +return do_linkat (olddfd,getname_uflags (oldname, flags), + newdfd,getname (newname), flags); } SYSCALL_DEFINE2(link, const char __user *, oldname, const char __user *, newname) { -return do_linkat (AT_FDCWD , oldname,AT_FDCWD , newname,0 ); +return do_linkat (AT_FDCWD ,getname (oldname),AT_FDCWD ,getname (newname),0 ); }/**
Signature · 1 line
2.30.2
PATCH v6 7/9 fs: update do_*() helpers to return ints
In reply to Dmitry KadashevUpdate the following to return int rather than long, for uniformity with the rest of the do_* helpers in namei.c:
* do_rmdir()
* do_unlinkat()
* do_mkdirat()
* do_mknodat()
* do_symlinkat()
--- fs/internal.h | 6 +++--- fs/namei.c | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-)
fs/internal.h +3 -3
@@ -72,12 +72,12 @@ extern int filename_lookup(int dfd, struct filename *name, unsigned flags, struct path *path, struct path *root);extern int vfs_path_lookup (struct dentry *,struct vfsmount *,const char *,unsigned int ,struct path *); -long do_rmdir (int dfd,struct filename *name); -long do_unlinkat (int dfd,struct filename *name); +int do_rmdir (int dfd,struct filename *name); +int do_unlinkat (int dfd,struct filename *name);int may_linkat (struct user_namespace *mnt_userns,struct path *link);int do_renameat2 (int olddfd,struct filename *oldname,int newdfd,struct filename *newname,unsigned int flags); -long do_mkdirat (int dfd,struct filename *name,umode_t mode); +int do_mkdirat (int dfd,struct filename *name,umode_t mode);/* * namespace.c
fs/namei.c +5 -5
@@ -3743,7 +3743,7 @@ static int may_mknod(umode_t mode) } } -static long do_mknodat (int dfd,struct filename *name,umode_t mode, +static int do_mknodat (int dfd,struct filename *name,umode_t mode,unsigned int dev) {struct user_namespace *mnt_userns;
@@ -3848,7 +3848,7 @@ int vfs_mkdir(struct user_namespace *mnt_userns, struct inode *dir, }EXPORT_SYMBOL (vfs_mkdir); -long do_mkdirat (int dfd,struct filename *name,umode_t mode) +int do_mkdirat (int dfd,struct filename *name,umode_t mode) {struct dentry *dentry;struct path path;
@@ -3943,7 +3943,7 @@ int vfs_rmdir(struct user_namespace *mnt_userns, struct inode *dir, }EXPORT_SYMBOL (vfs_rmdir); -long do_rmdir (int dfd,struct filename *name) +int do_rmdir (int dfd,struct filename *name) {struct user_namespace *mnt_userns;int error =0 ;
@@ -4081,7 +4081,7 @@ EXPORT_SYMBOL(vfs_unlink);* writeout happening, and we don't want to prevent access to the directory * while waiting on the I/O. */ -long do_unlinkat (int dfd,struct filename *name) +int do_unlinkat (int dfd,struct filename *name) {int error;struct dentry *dentry;
@@ -4208,7 +4208,7 @@ int vfs_symlink(struct user_namespace *mnt_userns, struct inode *dir, }EXPORT_SYMBOL (vfs_symlink); -static long do_symlinkat (struct filename *from,int newdfd, +static int do_symlinkat (struct filename *from,int newdfd,struct filename *to) {int error;
Signature · 1 line
2.30.2
PATCH v6 8/9 io_uring: add support for IORING_OP_SYMLINKAT
In reply to Dmitry KadashevIORING_OP_SYMLINKAT behaves like symlinkat(2) and takes the same flags and arguments.
--- fs/internal.h | 1 + fs/io_uring.c | 66 +++++++++++++++++++++++++++++++++++ fs/namei.c | 3 +- include/uapi/linux/io_uring.h | 1 + 4 files changed, 69 insertions(+), 2 deletions(-)
fs/internal.h +1 -0
@@ -78,6 +78,7 @@ int may_linkat(struct user_namespace *mnt_userns, struct path *link);int do_renameat2 (int olddfd,struct filename *oldname,int newdfd,struct filename *newname,unsigned int flags);int do_mkdirat (int dfd,struct filename *name,umode_t mode); +int do_symlinkat (struct filename *from,int newdfd,struct filename *to);/* * namespace.c
fs/io_uring.c +66 -0
108 lines not on this page · raw message
fs/namei.c +1 -2
@@ -4208,8 +4208,7 @@ int vfs_symlink(struct user_namespace *mnt_userns, struct inode *dir, }EXPORT_SYMBOL (vfs_symlink); -static int do_symlinkat (struct filename *from,int newdfd, -struct filename *to) +int do_symlinkat (struct filename *from,int newdfd,struct filename *to) {int error;struct dentry *dentry;
include/uapi/linux/io_uring.h +1 -0
@@ -138,6 +138,7 @@ enum {IORING_OP_RENAMEAT ,IORING_OP_UNLINKAT ,IORING_OP_MKDIRAT , +IORING_OP_SYMLINKAT ,/* this goes last, obviously */ IORING_OP_LAST,
Signature · 1 line
2.30.2
PATCH v6 9/9 io_uring: add support for IORING_OP_LINKAT
In reply to Dmitry KadashevIORING_OP_LINKAT behaves like linkat(2) and takes the same flags and arguments.
In some internal places 'hardlink' is used instead of 'link' to avoid confusion with the SQE links. Name 'link' conflicts with the existing 'link' member of io_kiocb.
--- fs/internal.h | 2 + fs/io_uring.c | 71 +++++++++++++++++++++++++++++++++++ fs/namei.c | 2 +- include/uapi/linux/io_uring.h | 2 + 4 files changed, 76 insertions(+), 1 deletion(-)
fs/internal.h +2 -0
@@ -79,6 +79,8 @@ int do_renameat2(int olddfd, struct filename *oldname, int newdfd, struct filename *newname, unsigned int flags);int do_mkdirat (int dfd,struct filename *name,umode_t mode);int do_symlinkat (struct filename *from,int newdfd,struct filename *to); +int do_linkat (int olddfd,struct filename *old,int newdfd, +struct filename *new,int flags);/* * namespace.c
fs/io_uring.c +71 -0
113 lines not on this page · raw message
fs/namei.c +1 -1
@@ -4356,7 +4356,7 @@ EXPORT_SYMBOL(vfs_link);* with linux 2.0, and to avoid hard-linking to directories * and other special files. --ADM */ -static int do_linkat (int olddfd,struct filename *old,int newdfd, +int do_linkat (int olddfd,struct filename *old,int newdfd,struct filename *new,int flags) {struct user_namespace *mnt_userns;
include/uapi/linux/io_uring.h +2 -0
@@ -44,6 +44,7 @@ struct io_uring_sqe {__u32 splice_flags;__u32 rename_flags;__u32 unlink_flags; +__u32 hardlink_flags; };__u64 user_data;/* data to be passed back at completion time */ union {
@@ -139,6 +140,7 @@ enum {IORING_OP_UNLINKAT ,IORING_OP_MKDIRAT ,IORING_OP_SYMLINKAT , +IORING_OP_LINKAT ,/* this goes last, obviously */ IORING_OP_LAST,
Signature · 1 line
2.30.2
Re: [PATCH v6 2/9] io_uring: add support for IORING_OP_MKDIRAT
In reply to Dmitry KadashevQuoted 2 lines · Dmitry Kadashev
IORING_OP_MKDIRATbehaves like mkdirat(2) and takes the same flags and arguments.
io_uring part looks good, great finally see it taken.
Quoted 133 lines
Signed-off-by Dmitry Kadashev <[email protected]>--- fs/io_uring.c | 59 +++++++++++++++++++++++++++++++++++ include/uapi/linux/io_uring.h | 1 + 2 files changed, 60 insertions(+)fs/io_uring.c +59
-0@@ -673,6 +673,13 @@ struct io_unlink {struct filename *filename; }; +struct io_mkdir { +struct file *file; +int dfd; +umode_t mode; +struct filename *filename; +}; +struct io_completion {struct file *file;struct list_head list;@@ -825,6 +832,7 @@ struct io_kiocb {struct io_shutdown shutdown;struct io_rename rename;struct io_unlink unlink; +struct io_mkdir mkdir;/* use only after cleaning per-op data, see io_clean_op() */ struct io_completion compl; };@@ -1039,6 +1047,7 @@ static const struct io_op_def io_op_defs[] = { }, [IORING_OP_RENAMEAT] = {}, [IORING_OP_UNLINKAT] = {}, + [IORING_OP_MKDIRAT] = {}, };static bool io_disarm_next (struct io_kiocb *req);@@ -3548,6 +3557,48 @@ static int io_unlinkat(struct io_kiocb *req, unsigned int issue_flags)return 0 ; } +static int io_mkdirat_prep (struct io_kiocb *req, +const struct io_uring_sqe *sqe) +{ +struct io_mkdir *mkd = &req->mkdir; +const char __user *fname; + +if (unlikely (req->ctx->flags &IORING_SETUP_IOPOLL )) +return -EINVAL ; +if (sqe->ioprio || sqe->off || sqe->rw_flags || sqe->buf_index) +return -EINVAL ; +if (unlikely (req->flags &REQ_F_FIXED_FILE )) +return -EBADF ; + + mkd->dfd =READ_ONCE (sqe->fd); + mkd->mode =READ_ONCE (sqe->len); + + fname =u64_to_user_ptr (READ_ONCE (sqe->addr)); + mkd->filename =getname (fname); +if (IS_ERR (mkd->filename)) +return PTR_ERR (mkd->filename); + + req->flags |=REQ_F_NEED_CLEANUP ; +return 0 ; +} + +static int io_mkdirat (struct io_kiocb *req,int issue_flags) +{ +struct io_mkdir *mkd = &req->mkdir; +int ret; + +if (issue_flags &IO_URING_F_NONBLOCK ) +return -EAGAIN ; + + ret =do_mkdirat (mkd->dfd, mkd->filename, mkd->mode); + + req->flags &= ~REQ_F_NEED_CLEANUP ; +if (ret <0 ) +req_set_fail (req); +io_req_complete (req, ret); +return 0 ; +} +static int io_shutdown_prep (struct io_kiocb *req,const struct io_uring_sqe *sqe) {@@ -5956,6 +6007,8 @@ static int io_req_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)return io_renameat_prep (req, sqe);case IORING_OP_UNLINKAT :return io_unlinkat_prep (req, sqe); +case IORING_OP_MKDIRAT : +return io_mkdirat_prep (req, sqe); } printk_once(KERN_WARNING "io_uring: unhandled opcode %d\n",@@ -6117,6 +6170,9 @@ static void io_clean_op(struct io_kiocb *req)case IORING_OP_UNLINKAT :putname (req->unlink.filename);break ; +case IORING_OP_MKDIRAT : +putname (req->mkdir.filename); +break ; } }if ((req->flags &REQ_F_POLLED ) && req->apoll) {@@ -6245,6 +6301,9 @@ static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags)case IORING_OP_UNLINKAT : ret =io_unlinkat (req, issue_flags);break ; +case IORING_OP_MKDIRAT : + ret =io_mkdirat (req, issue_flags); +break ;default : ret = -EINVAL ;break ;include/uapi/linux/io_uring.h +1
-0@@ -137,6 +137,7 @@ enum {IORING_OP_SHUTDOWN ,IORING_OP_RENAMEAT ,IORING_OP_UNLINKAT , +IORING_OP_MKDIRAT ,/* this goes last, obviously */ IORING_OP_LAST,
Signature · 1 line
Pavel Begunkov
Re: [PATCH v6 8/9] io_uring: add support for IORING_OP_SYMLINKAT
In reply to Dmitry KadashevQuoted 2 lines · Dmitry Kadashev
IORING_OP_SYMLINKATbehaves like symlinkat(2) and takes the same flags and arguments.
Quoted 170 lines
Suggested-by Christian Brauner <[email protected]>Signed-off-by Dmitry Kadashev <[email protected]>--- fs/internal.h | 1 + fs/io_uring.c | 66 +++++++++++++++++++++++++++++++++++ fs/namei.c | 3 +- include/uapi/linux/io_uring.h | 1 + 4 files changed, 69 insertions(+), 2 deletions(-)fs/internal.h +1
-0@@ -78,6 +78,7 @@ int may_linkat(struct user_namespace *mnt_userns, struct path *link);int do_renameat2 (int olddfd,struct filename *oldname,int newdfd,struct filename *newname,unsigned int flags);int do_mkdirat (int dfd,struct filename *name,umode_t mode); +int do_symlinkat (struct filename *from,int newdfd,struct filename *to);/* * namespace.c fs/io_uring.c +66
-0@@ -680,6 +680,13 @@ struct io_mkdir {struct filename *filename; }; +struct io_symlink { +struct file *file; +int new_dfd; +struct filename *oldpath; +struct filename *newpath; +}; +struct io_completion {struct file *file;struct list_head list;@@ -833,6 +840,7 @@ struct io_kiocb {struct io_rename rename;struct io_unlink unlink;struct io_mkdir mkdir; +struct io_symlink symlink;/* use only after cleaning per-op data, see io_clean_op() */ struct io_completion compl; };@@ -1048,6 +1056,7 @@ static const struct io_op_def io_op_defs[] = { [IORING_OP_RENAMEAT] = {}, [IORING_OP_UNLINKAT] = {}, [IORING_OP_MKDIRAT] = {}, + [IORING_OP_SYMLINKAT] = {}, };static bool io_disarm_next (struct io_kiocb *req);@@ -3599,6 +3608,54 @@ static int io_mkdirat(struct io_kiocb *req, int issue_flags)return 0 ; } +static int io_symlinkat_prep (struct io_kiocb *req, +const struct io_uring_sqe *sqe) +{ +struct io_symlink *sl = &req->symlink; +const char __user *oldpath, *newpath; + +if (unlikely (req->ctx->flags &IORING_SETUP_IOPOLL )) +return -EINVAL ; +if (sqe->ioprio || sqe->len || sqe->rw_flags || sqe->buf_index) +return -EINVAL ; +if (unlikely (req->flags &REQ_F_FIXED_FILE )) +return -EBADF ; + + sl->new_dfd =READ_ONCE (sqe->fd); + oldpath =u64_to_user_ptr (READ_ONCE (sqe->addr)); + newpath =u64_to_user_ptr (READ_ONCE (sqe->addr2)); + + sl->oldpath =getname (oldpath); +if (IS_ERR (sl->oldpath)) +return PTR_ERR (sl->oldpath); + + sl->newpath =getname (newpath); +if (IS_ERR (sl->newpath)) { +putname (sl->oldpath); +return PTR_ERR (sl->newpath); + } + + req->flags |=REQ_F_NEED_CLEANUP ; +return 0 ; +} + +static int io_symlinkat (struct io_kiocb *req,int issue_flags) +{ +struct io_symlink *sl = &req->symlink; +int ret; + +if (issue_flags &IO_URING_F_NONBLOCK ) +return -EAGAIN ; + + ret =do_symlinkat (sl->oldpath, sl->new_dfd, sl->newpath); + + req->flags &= ~REQ_F_NEED_CLEANUP ; +if (ret <0 ) +req_set_fail (req); +io_req_complete (req, ret); +return 0 ; +} +static int io_shutdown_prep (struct io_kiocb *req,const struct io_uring_sqe *sqe) {@@ -6009,6 +6066,8 @@ static int io_req_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)return io_unlinkat_prep (req, sqe);case IORING_OP_MKDIRAT :return io_mkdirat_prep (req, sqe); +case IORING_OP_SYMLINKAT : +return io_symlinkat_prep (req, sqe); } printk_once(KERN_WARNING "io_uring: unhandled opcode %d\n",@@ -6173,6 +6232,10 @@ static void io_clean_op(struct io_kiocb *req)case IORING_OP_MKDIRAT :putname (req->mkdir.filename);break ; +case IORING_OP_SYMLINKAT : +putname (req->symlink.oldpath); +putname (req->symlink.newpath); +break ; } }if ((req->flags &REQ_F_POLLED ) && req->apoll) {@@ -6304,6 +6367,9 @@ static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags)case IORING_OP_MKDIRAT : ret =io_mkdirat (req, issue_flags);break ; +case IORING_OP_SYMLINKAT : + ret =io_symlinkat (req, issue_flags); +break ;default : ret = -EINVAL ;break ;fs/namei.c +1
-2@@ -4208,8 +4208,7 @@ int vfs_symlink(struct user_namespace *mnt_userns, struct inode *dir, }EXPORT_SYMBOL (vfs_symlink); -static int do_symlinkat (struct filename *from,int newdfd, -struct filename *to) +int do_symlinkat (struct filename *from,int newdfd,struct filename *to) {int error;struct dentry *dentry;include/uapi/linux/io_uring.h +1
-0@@ -138,6 +138,7 @@ enum {IORING_OP_RENAMEAT ,IORING_OP_UNLINKAT ,IORING_OP_MKDIRAT , +IORING_OP_SYMLINKAT ,/* this goes last, obviously */ IORING_OP_LAST,
Signature · 1 line
Pavel Begunkov
Re: [PATCH v6 9/9] io_uring: add support for IORING_OP_LINKAT
In reply to Dmitry KadashevQuoted 6 lines · Dmitry Kadashev
IORING_OP_LINKATbehaves like linkat(2) and takes the same flags and arguments.In some internal places 'hardlink' is used instead of 'link' to avoid confusion with the SQE links. Name 'link' conflicts with the existing 'link' member of
io_kiocb.
Quoted 183 lines
Suggested-by Christian Brauner <[email protected]>Signed-off-by Dmitry Kadashev <[email protected]>--- fs/internal.h | 2 + fs/io_uring.c | 71 +++++++++++++++++++++++++++++++++++ fs/namei.c | 2 +- include/uapi/linux/io_uring.h | 2 + 4 files changed, 76 insertions(+), 1 deletion(-)fs/internal.h +2
-0@@ -79,6 +79,8 @@ int do_renameat2(int olddfd, struct filename *oldname, int newdfd, struct filename *newname, unsigned int flags);int do_mkdirat (int dfd,struct filename *name,umode_t mode);int do_symlinkat (struct filename *from,int newdfd,struct filename *to); +int do_linkat (int olddfd,struct filename *old,int newdfd, +struct filename *new,int flags);/* * namespace.c fs/io_uring.c +71
-0@@ -687,6 +687,15 @@ struct io_symlink {struct filename *newpath; }; +struct io_hardlink { +struct file *file; +int old_dfd; +int new_dfd; +struct filename *oldpath; +struct filename *newpath; +int flags; +}; +struct io_completion {struct file *file;struct list_head list;@@ -841,6 +850,7 @@ struct io_kiocb {struct io_unlink unlink;struct io_mkdir mkdir;struct io_symlink symlink; +struct io_hardlink hardlink;/* use only after cleaning per-op data, see io_clean_op() */ struct io_completion compl; };@@ -1057,6 +1067,7 @@ static const struct io_op_def io_op_defs[] = { [IORING_OP_UNLINKAT] = {}, [IORING_OP_MKDIRAT] = {}, [IORING_OP_SYMLINKAT] = {}, + [IORING_OP_LINKAT] = {}, };static bool io_disarm_next (struct io_kiocb *req);@@ -3656,6 +3667,57 @@ static int io_symlinkat(struct io_kiocb *req, int issue_flags)return 0 ; } +static int io_linkat_prep (struct io_kiocb *req, +const struct io_uring_sqe *sqe) +{ +struct io_hardlink *lnk = &req->hardlink; +const char __user *oldf, *newf; + +if (unlikely (req->ctx->flags &IORING_SETUP_IOPOLL )) +return -EINVAL ; +if (sqe->ioprio || sqe->rw_flags || sqe->buf_index) +return -EINVAL ; +if (unlikely (req->flags &REQ_F_FIXED_FILE )) +return -EBADF ; + + lnk->old_dfd =READ_ONCE (sqe->fd); + lnk->new_dfd =READ_ONCE (sqe->len); + oldf =u64_to_user_ptr (READ_ONCE (sqe->addr)); + newf =u64_to_user_ptr (READ_ONCE (sqe->addr2)); + lnk->flags =READ_ONCE (sqe->hardlink_flags); + + lnk->oldpath =getname (oldf); +if (IS_ERR (lnk->oldpath)) +return PTR_ERR (lnk->oldpath); + + lnk->newpath =getname (newf); +if (IS_ERR (lnk->newpath)) { +putname (lnk->oldpath); +return PTR_ERR (lnk->newpath); + } + + req->flags |=REQ_F_NEED_CLEANUP ; +return 0 ; +} + +static int io_linkat (struct io_kiocb *req,int issue_flags) +{ +struct io_hardlink *lnk = &req->hardlink; +int ret; + +if (issue_flags &IO_URING_F_NONBLOCK ) +return -EAGAIN ; + + ret =do_linkat (lnk->old_dfd, lnk->oldpath, lnk->new_dfd, + lnk->newpath, lnk->flags); + + req->flags &= ~REQ_F_NEED_CLEANUP ; +if (ret <0 ) +req_set_fail (req); +io_req_complete (req, ret); +return 0 ; +} +static int io_shutdown_prep (struct io_kiocb *req,const struct io_uring_sqe *sqe) {@@ -6068,6 +6130,8 @@ static int io_req_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)return io_mkdirat_prep (req, sqe);case IORING_OP_SYMLINKAT :return io_symlinkat_prep (req, sqe); +case IORING_OP_LINKAT : +return io_linkat_prep (req, sqe); } printk_once(KERN_WARNING "io_uring: unhandled opcode %d\n",@@ -6236,6 +6300,10 @@ static void io_clean_op(struct io_kiocb *req)putname (req->symlink.oldpath);putname (req->symlink.newpath);break ; +case IORING_OP_LINKAT : +putname (req->hardlink.oldpath); +putname (req->hardlink.newpath); +break ; } }if ((req->flags &REQ_F_POLLED ) && req->apoll) {@@ -6370,6 +6438,9 @@ static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags)case IORING_OP_SYMLINKAT : ret =io_symlinkat (req, issue_flags);break ; +case IORING_OP_LINKAT : + ret =io_linkat (req, issue_flags); +break ;default : ret = -EINVAL ;break ;fs/namei.c +1
-1@@ -4356,7 +4356,7 @@ EXPORT_SYMBOL(vfs_link);* with linux 2.0, and to avoid hard-linking to directories * and other special files. --ADM */ -static int do_linkat (int olddfd,struct filename *old,int newdfd, +int do_linkat (int olddfd,struct filename *old,int newdfd,struct filename *new,int flags) {struct user_namespace *mnt_userns;include/uapi/linux/io_uring.h +2
-0@@ -44,6 +44,7 @@ struct io_uring_sqe {__u32 splice_flags;__u32 rename_flags;__u32 unlink_flags; +__u32 hardlink_flags; };__u64 user_data;/* data to be passed back at completion time */ union {@@ -139,6 +140,7 @@ enum {IORING_OP_UNLINKAT ,IORING_OP_MKDIRAT ,IORING_OP_SYMLINKAT , +IORING_OP_LINKAT ,/* this goes last, obviously */ IORING_OP_LAST,
Signature · 1 line
Pavel Begunkov
Jens Axboe
maintainerQuoted 18 lines · Dmitry Kadashev
This started out as an attempt to add mkdirat support to
io_uringwhich is heavily based onrenameat()/unlinkat()support.During the review process more operations were added (linkat, symlinkat, mknodat) mainly to keep things uniform internally (in
namei.c), and with things changed innamei.cadding support for these operations toio_uringis trivial, so that was done too (except for mknodat). See
https://lore.kernel.org/io-uring/20210514145259.wtl4xcsp52woi6ab@wittgenstein/The first patch is preparation with no functional changes, makes
do_mkdirataccept struct filename pointer rather than the user string.The second one leverages that to implement mkdirat in
io_uring.3-6 just convert other similar do_* functions in
namei.cto accept struct filename, for uniformity withdo_mkdirat,do_renameatanddo_unlinkat. No functional changes there.
Quoted 6 lines
7 changes do_* helpers in
namei.cto return ints rather than some of them returning ints and some longs.8-9 add symlinkat and linkat support to
io_uringcorrespondingly.Based on for-5.14/io_uring.
Thanks for respinning it! I've applied it, thanks.
Signature · 1 line
Jens Axboe