io_uring: add mkdir and [sym]linkat support
Subsystems (3)
v9 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 makes putname() ignore IS_ERR_OR_NULL names and converts a couple of places where the check was already implemented in the callers. No functional changes.
The second one splits filename_lookup() that used to consume the passed struct filename * on error but not on the success (returning it) into
two: filename_lookup(), that always consumes the name and __filename_lookup() that never does. This is a preparation change to enable the subsequent changes to filename_create and filename_lookup. No functional changes.
The third patch is preparation with no functional changes, makes do_mkdirat accept struct filename pointer rather than the user string.
4-7 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.
8 changes do_* helpers in namei.c to return ints rather than some of them returning ints and some longs.
9-11 leverages the previous changes to add mkdirat, symlinkat and linkat support to io_uring correspondingly
Based on for-5.14/io_uring.
v9:
- reorder commits to keep io_uring ones nicely grouped at the end
- change 'fs:' to 'namei:' in related commit subjects, since this is what seems to be usually used in such cases
v8:
- update filename_parentat() calling conventions to be uniform with the ones followed by (changed in subsequent patches) filename_create() and filename_lookup()
v7:
- rebase
- make putname() ignore IS_ERR_OR_NULL names, remove conditional calls to it from the callers
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 (11):
namei: ignore ERR/NULL names in putname()
namei: change filename_parentat() calling conventions
namei: make do_mkdirat() take struct filename
namei: make do_mknodat() take struct filename
namei: make do_symlinkat() take struct filename
namei: add getname_uflags()
namei: make do_linkat() take struct filename
namei: update do_*() helpers to return ints
io_uring: add support for IORING_OP_MKDIRAT
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 | 239 +++++++++++++++++++--------------- include/linux/fs.h | 1 + include/uapi/linux/io_uring.h | 4 + 6 files changed, 346 insertions(+), 110 deletions(-)
Signature · 1 line
2.30.2
PATCH v9 1/11 namei: ignore ERR/NULL names in putname()
Supporting ERR/NULL names in putname() makes callers code cleaner, and is what some other path walking functions already support for the same reason.
This also removes a few existing IS_ERR checks before putname().
--- fs/namei.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
fs/namei.c +5 -4
@@ -247,6 +247,9 @@ getname_kernel(const char * filename)void putname (struct filename *name) { +if (IS_ERR_OR_NULL (name)) +return ; +BUG_ON (name->refcnt <=0 );if (--name->refcnt >0 )
@@ -4718,11 +4721,9 @@ int do_renameat2(int olddfd, struct filename *from, int newdfd, goto retry; } put_both: -if (!IS_ERR (from)) -putname (from); +putname (from); put_new: -if (!IS_ERR (to)) -putname (to); +putname (to);return error; }
Signature · 1 line
2.30.2
PATCH v9 2/11 namei: change filename_parentat() calling conventions
In reply to Dmitry KadashevSince commit 5c31b6cedb675 ("namei: saner calling conventions for filename_parentat()") filename_parentat() had the following behavior WRT the passed in struct filename *:
* On error the name is consumed (putname() is called on it);
* On success the name is returned back as the return value;
Now there is a need for filename_create() and filename_lookup() variants that do not consume the passed filename, and following the same "consume the name only on error" semantics is proven to be hard to reason about and result in confusing code.
Hence this preparation change splits filename_parentat() into two: one that always consumes the name and another that never consumes the name. This will allow to implement two filename_create() variants in the same way, and is a consistent and hopefully easier to reason about approach.
--- fs/namei.c | 108 ++++++++++++++++++++++++++--------------------------- 1 file changed, 53 insertions(+), 55 deletions(-)
fs/namei.c +53 -55
@@ -2485,7 +2485,7 @@ static int path_parentat(struct nameidata *nd, unsigned flags,return err; } -static struct filename *filename_parentat (int dfd,struct filename *name, +static int __filename_parentat (int dfd,struct filename *name,unsigned int flags,struct path *parent,struct qstr *last,int *type) {
@@ -2493,7 +2493,7 @@ static struct filename *filename_parentat(int dfd, struct filename *name,struct nameidata nd;if (IS_ERR (name)) -return name; +return PTR_ERR (name);set_nameidata (&nd, dfd, name); retval =path_parentat (&nd, flags |LOOKUP_RCU , parent);if (unlikely (retval == -ECHILD ))
@@ -2504,29 +2504,34 @@ static struct filename *filename_parentat(int dfd, struct filename *name, *last = nd.last; *type = nd.last_type;audit_inode (name, parent->dentry,AUDIT_INODE_PARENT ); - }else { -putname (name); - name =ERR_PTR (retval); }restore_nameidata (); -return name; +return retval; +} + +static int filename_parentat (int dfd,struct filename *name, +unsigned int flags,struct path *parent, +struct qstr *last,int *type) +{ +int retval =__filename_parentat (dfd, name, flags, parent, last, type); + +putname (name); +return retval; }/* does lookup, returns the object with parent locked */ struct dentry *kern_path_locked (const char *name,struct path *path) { -struct filename *filename;struct dentry *d;struct qstr last; -int type; +int type, error; - filename =filename_parentat (AT_FDCWD ,getname_kernel (name),0 , path, + error =filename_parentat (AT_FDCWD ,getname_kernel (name),0 , path, &last, &type); -if (IS_ERR (filename)) -return ERR_CAST (filename); +if (error) +return ERR_PTR (error);if (unlikely (type !=LAST_NORM )) {path_put (path); -putname (filename);return ERR_PTR (-EINVAL ); }inode_lock_nested (path->dentry->d_inode,I_MUTEX_PARENT );
@@ -2535,7 +2540,6 @@ struct dentry *kern_path_locked(const char *name, struct path *path)inode_unlock (path->dentry->d_inode);path_put (path); } -putname (filename);return d; }
@@ -3575,9 +3579,9 @@ static struct dentry *filename_create(int dfd, struct filename *name,*/ lookup_flags &=LOOKUP_REVAL ; - name =filename_parentat (dfd, name, lookup_flags, path, &last, &type); -if (IS_ERR (name)) -return ERR_CAST (name); + error =filename_parentat (dfd, name, lookup_flags, path, &last, &type); +if (error) +return ERR_PTR (error);/* * Yucky last component or no last component at all?
@@ -3615,7 +3619,6 @@ static struct dentry *filename_create(int dfd, struct filename *name, error = err2; goto fail; } -putname (name);return dentry; fail:dput (dentry);
@@ -3626,7 +3629,6 @@ static struct dentry *filename_create(int dfd, struct filename *name,mnt_drop_write (path->mnt); out:path_put (path); -putname (name);return dentry; }
@@ -3917,59 +3919,59 @@ EXPORT_SYMBOL(vfs_rmdir);long do_rmdir (int dfd,struct filename *name) {struct user_namespace *mnt_userns; -int error =0 ; +int error;struct dentry *dentry;struct path path;struct qstr last;int type;unsigned int lookup_flags =0 ; retry: - name =filename_parentat (dfd, name, lookup_flags, - &path, &last, &type); -if (IS_ERR (name)) -return PTR_ERR (name); + error =__filename_parentat (dfd, name, lookup_flags, &path, &last, &type); +if (error) + goto exit1;switch (type) {case LAST_DOTDOT : error = -ENOTEMPTY ; - goto exit1; + goto exit2;case LAST_DOT : error = -EINVAL ; - goto exit1; + goto exit2;case LAST_ROOT : error = -EBUSY ; - goto exit1; + goto exit2; } error =mnt_want_write (path.mnt);if (error) - goto exit1; + goto exit2;inode_lock_nested (path.dentry->d_inode,I_MUTEX_PARENT ); dentry =__lookup_hash (&last, path.dentry, lookup_flags); error =PTR_ERR (dentry);if (IS_ERR (dentry)) - goto exit2; + goto exit3;if (!dentry->d_inode) { error = -ENOENT ; - goto exit3; + goto exit4; } error =security_path_rmdir (&path, dentry);if (error) - goto exit3; + goto exit4; mnt_userns =mnt_user_ns (path.mnt); error =vfs_rmdir (mnt_userns, path.dentry->d_inode, dentry); -exit3: +exit4:dput (dentry); -exit2: +exit3:inode_unlock (path.dentry->d_inode);mnt_drop_write (path.mnt); -exit1: +exit2:path_put (&path);if (retry_estale (error, lookup_flags)) { lookup_flags |=LOOKUP_REVAL ; goto retry; } +exit1:putname (name);return error; }
@@ -4063,17 +4065,17 @@ long do_unlinkat(int dfd, struct filename *name)struct inode *delegated_inode =NULL ;unsigned int lookup_flags =0 ; retry: - name =filename_parentat (dfd, name, lookup_flags, &path, &last, &type); -if (IS_ERR (name)) -return PTR_ERR (name); + error =__filename_parentat (dfd, name, lookup_flags, &path, &last, &type); +if (error) + goto exit1; error = -EISDIR ;if (type !=LAST_NORM ) - goto exit1; + goto exit2; error =mnt_want_write (path.mnt);if (error) - goto exit1; + goto exit2; retry_deleg:inode_lock_nested (path.dentry->d_inode,I_MUTEX_PARENT ); dentry =__lookup_hash (&last, path.dentry, lookup_flags);
@@ -4090,11 +4092,11 @@ long do_unlinkat(int dfd, struct filename *name)ihold (inode); error =security_path_unlink (&path, dentry);if (error) - goto exit2; + goto exit3; mnt_userns =mnt_user_ns (path.mnt); error =vfs_unlink (mnt_userns, path.dentry->d_inode, dentry, &delegated_inode); -exit2: +exit3:dput (dentry); }inode_unlock (path.dentry->d_inode);
@@ -4107,13 +4109,14 @@ long do_unlinkat(int dfd, struct filename *name) goto retry_deleg; }mnt_drop_write (path.mnt); -exit1: +exit2:path_put (&path);if (retry_estale (error, lookup_flags)) { lookup_flags |=LOOKUP_REVAL ; inode =NULL ; goto retry; } +exit1:putname (name);return error;
@@ -4124,7 +4127,7 @@ long do_unlinkat(int dfd, struct filename *name) error = -EISDIR ; else error = -ENOTDIR ; - goto exit2; + goto exit3; } SYSCALL_DEFINE3(unlinkat, int, dfd, const char __user *, pathname, int, flag)
@@ -4595,29 +4598,25 @@ int do_renameat2(int olddfd, struct filename *from, int newdfd,int error = -EINVAL ;if (flags & ~(RENAME_NOREPLACE |RENAME_EXCHANGE |RENAME_WHITEOUT )) - goto put_both; + goto put_names;if ((flags & (RENAME_NOREPLACE |RENAME_WHITEOUT )) && (flags &RENAME_EXCHANGE )) - goto put_both; + goto put_names;if (flags &RENAME_EXCHANGE ) target_flags =0 ; retry: - from =filename_parentat (olddfd, from, lookup_flags, &old_path, + error =__filename_parentat (olddfd, from, lookup_flags, &old_path, &old_last, &old_type); -if (IS_ERR (from)) { - error =PTR_ERR (from); - goto put_new; - } +if (error) + goto put_names; - to =filename_parentat (newdfd, to, lookup_flags, &new_path, &new_last, + error =__filename_parentat (newdfd, to, lookup_flags, &new_path, &new_last, &new_type); -if (IS_ERR (to)) { - error =PTR_ERR (to); +if (error) goto exit1; - } error = -EXDEV ;if (old_path.mnt != new_path.mnt)
@@ -4720,9 +4719,8 @@ int do_renameat2(int olddfd, struct filename *from, int newdfd, lookup_flags |=LOOKUP_REVAL ; goto retry; } -put_both: +put_names:putname (from); -put_new:putname (to);return error; }
Signature · 1 line
2.30.2
PATCH v9 3/11 namei: make do_mkdirat() take struct filename
In reply to Dmitry KadashevPass 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 | 26 +++++++++++++++++++------- 2 files changed, 20 insertions(+), 7 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 +19 -7
@@ -3563,7 +3563,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 );
@@ -3579,7 +3579,7 @@ static struct dentry *filename_create(int dfd, struct filename *name,*/ lookup_flags &=LOOKUP_REVAL ; - error =filename_parentat (dfd, name, lookup_flags, path, &last, &type); + error =__filename_parentat (dfd, name, lookup_flags, path, &last, &type);if (error)return ERR_PTR (error);
@@ -3632,6 +3632,15 @@ 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); + +putname (name); +return res; +} +struct dentry *kern_path_create (int dfd,const char *pathname,struct path *path,unsigned int lookup_flags) {
@@ -3822,7 +3831,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;
@@ -3830,9 +3839,10 @@ 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); + error =PTR_ERR (dentry);if (IS_ERR (dentry)) -return PTR_ERR (dentry); + goto out_putname;if (!IS_POSIXACL (path.dentry->d_inode)) mode &= ~current_umask ();
@@ -3848,17 +3858,19 @@ static long do_mkdirat(int dfd, const char __user *pathname, umode_t mode) lookup_flags |=LOOKUP_REVAL ; goto retry; } +out_putname: +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 v9 4/11 namei: 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 | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-)
fs/namei.c +11 -8
@@ -3729,7 +3729,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;
@@ -3740,17 +3740,18 @@ 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); + error =PTR_ERR (dentry);if (IS_ERR (dentry)) -return PTR_ERR (dentry); + goto out1;if (!IS_POSIXACL (path.dentry->d_inode)) 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 ) {
@@ -3769,24 +3770,26 @@ 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: +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 v9 5/11 namei: 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 | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-)
fs/namei.c +12 -11
@@ -4197,23 +4197,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_putnames; + } 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_putnames; error =security_path_symlink (&path, dentry, from->name);if (!error) {
@@ -4228,7 +4228,8 @@ static long do_symlinkat(const char __user *oldname, int newdfd, lookup_flags |=LOOKUP_REVAL ; goto retry; } -out_putname: +out_putnames: +putname (to);putname (from);return error; }
@@ -4236,12 +4237,12 @@ static long do_symlinkat(const char __user *oldname, int newdfd, 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 v9 6/11 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 v9 7/11 namei: 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 | 45 +++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-)
fs/namei.c +29 -16
@@ -2450,7 +2450,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;
@@ -2472,6 +2472,14 @@ int filename_lookup(int dfd, struct filename *name, unsigned flags,audit_inode (name, path->dentry, flags &LOOKUP_MOUNTPOINT ?AUDIT_INODE_NOEVAL :0 );restore_nameidata (); +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); +putname (name);return retval; }
@@ -4351,8 +4359,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;
@@ -4361,31 +4369,32 @@ 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_putnames; - 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; + goto out_putpath; error = -EXDEV ;if (old_path.mnt != new_path.mnt)
@@ -4413,8 +4422,11 @@ 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: +putname (old); +putname (new);return error; }
@@ -4422,12 +4434,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 v9 8/11 namei: 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
@@ -3745,7 +3745,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;
@@ -3850,7 +3850,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;
@@ -3947,7 +3947,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;
@@ -4085,7 +4085,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;
@@ -4213,7 +4213,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 v9 9/11 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
@@ -674,6 +674,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;
@@ -831,6 +838,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; };
@@ -1042,6 +1050,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);
@@ -3545,6 +3554,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) {
@@ -5953,6 +6004,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",
@@ -6114,6 +6167,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) {
@@ -6242,6 +6298,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
@@ -133,6 +133,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 v9 10/11 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
@@ -4213,8 +4213,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
@@ -134,6 +134,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 v9 11/11 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
@@ -4358,7 +4358,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 */ /* pack this to avoid bogus arm OABI complaints */
@@ -135,6 +136,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
Quoted 5 lines · Dmitry Kadashev
v9:
- reorder commits to keepio_uringones nicely grouped at the end
- change 'fs:' to 'namei:' in related commit subjects, since this is what seems to be usually used in such cases
Ok, ack from me on this series, and as far as I'm concerned it can go through the io_uring branch.
Al, please holler if you have any concerns.
I do see a few cleanups - the ones I've already mentioned to try to remove some of the goto spaghetti, and I think we end up with just two users of filename_create(), and we might just make those convert to the new world order, and get rid of the __filename_create() vs filename_creat() distinction.
But those cleanups might as well be left for later, so I don't think that needs to hold the series up.
Al - one last chance to speak up..
Linus
Jens Axboe
maintainerQuoted 9 lines · Linus Torvalds
Quoted 5 lines · Dmitry Kadashev
v9:
- reorder commits to keepio_uringones nicely grouped at the end
- change 'fs:' to 'namei:' in related commit subjects, since this is what seems to be usually used in such casesOk, ack from me on this series, and as far as I'm concerned it can go through the
io_uringbranch.
I'll queue it up in a separate branch. I'm assuming we're talking 5.15 at this point.
Quoted 1 line
Al, please holler if you have any concerns.
Indeed.
Signature · 1 line
Jens Axboe
Quoted 9 lines · Jens Axboe
Quoted 7 lines · Linus Torvalds
Quoted 5 lines · Dmitry Kadashev
v9:
- reorder commits to keepio_uringones nicely grouped at the end
- change 'fs:' to 'namei:' in related commit subjects, since this is what seems to be usually used in such cases
Quoted 5 lines
Quoted 2 lines
Ok, ack from me on this series, and as far as I'm concerned it can go through the
io_uringbranch.I'll queue it up in a separate branch. I'm assuming we're talking 5.15 at this point.
Is this going to be merged into 5.15? I'm still working on the follow-up patch (well, right at this moment I'm actually on vacation, but will be working on it when I'm back), but hopefully it does not have to be merged in the same merge window / version? Especially given the fact that Al prefers it to be a bigger refactoring of the ESTALE retries rather than just moving bits and pieces to helper functions to simplify the flow, see here:
https://lore.kernel.org/io-uring/[email protected]/
Signature · 1 line
Dmitry Kadashev
Jens Axboe
maintainerQuoted 24 lines · Dmitry Kadashev
Quoted 9 lines · Jens Axboe
Quoted 7 lines · Linus Torvalds
Quoted 5 lines · Dmitry Kadashev
v9:
- reorder commits to keepio_uringones nicely grouped at the end
- change 'fs:' to 'namei:' in related commit subjects, since this is what seems to be usually used in such casesQuoted 5 lines
Quoted 2 lines
Ok, ack from me on this series, and as far as I'm concerned it can go through the
io_uringbranch.I'll queue it up in a separate branch. I'm assuming we're talking 5.15 at this point.
Is this going to be merged into 5.15? I'm still working on the follow-up patch (well, right at this moment I'm actually on vacation, but will be working on it when I'm back), but hopefully it does not have to be merged in the same merge window / version? Especially given the fact that Al prefers it to be a bigger refactoring of the ESTALE retries rather than just moving bits and pieces to helper functions to simplify the flow, see here:
Quoted 1 line
I added this to the for-5.15/io_uring-vfs branch:
https://git.kernel.dk/cgit/linux-block/log/?h=for-5.15/io_uring-vfs
had one namei.c conflict, set_nameidata() taking one more parameter, and just a trivial conflict in each io_uring patch at the end. Can you double check them?
Signature · 1 line
Jens Axboe
Quoted 28 lines · Jens Axboe
Quoted 24 lines · Dmitry Kadashev
Quoted 9 lines · Jens Axboe
Quoted 7 lines · Linus Torvalds
Quoted 5 lines · Dmitry Kadashev
v9:
- reorder commits to keepio_uringones nicely grouped at the end
- change 'fs:' to 'namei:' in related commit subjects, since this is what seems to be usually used in such casesQuoted 5 lines
Quoted 2 lines
Ok, ack from me on this series, and as far as I'm concerned it can go through the
io_uringbranch.I'll queue it up in a separate branch. I'm assuming we're talking 5.15 at this point.
Is this going to be merged into 5.15? I'm still working on the follow-up patch (well, right at this moment I'm actually on vacation, but will be working on it when I'm back), but hopefully it does not have to be merged in the same merge window / version? Especially given the fact that Al prefers it to be a bigger refactoring of the ESTALE retries rather than just moving bits and pieces to helper functions to simplify the flow, see here:
Quoted 1 line
Quoted 7 lines
I added this to the for-5.15/io_uring-vfs branch:
https://git.kernel.dk/cgit/linux-block/log/?h=for-5.15/io_uring-vfs
had one
namei.cconflict,set_nameidata()taking one more parameter, and just a trivial conflict in eachio_uringpatch at the end. Can you double check them?
Looks good to me, thanks!
Signature · 1 line
Dmitry Kadashev