vfs: add the ability to retry on ESTALE to several syscalls
Subsystems (10)
v6 cover vfs: add the ability to retry on ESTALE to several syscalls
This patchset is a respin of the one I sent on August 8th. The main reason is to respin this series on top of my getname/putname overhaul, which simplifies the set greatly and doesn't require so many getname callers.
This series depends on the "getname" series that I sent earlier today.
This set (and the prerequiste patches) are also available via the "estale" branch of my git tree:
git://git.samba.org/jlayton/linux.git estale
I'd like to see this go in for 3.7 if at all possible.
The original cover letter text follows:
ESTALE errors are a source of pain for many users, primarily those who are doing work on NFS. When userspace provides a path to a syscall, then there's really little excuse for returning ESTALE. If userspace gave us a path that we had to lookup in order to do the call, then it's not particularly helpful to return ESTALE just because that path went stale before we could do the actual operation.
We can and should do better here. The kernel should instead catch that error and retry the lookup and call, while forcing a revalidation of all dentries involved.
Unfortunately fixing this requires touching the syscalls themselves, or at least their immediate helper functions. Not all syscalls can be retried -- only those that take a pathname as an argument.
With this patchset, I've decided to take the relatively less controversial approach of just having the kernel retry once when it gets an ESTALE error. I still think that it's not as strong as it should be, but it should improve the situation in many common cases.
I've also tried to engineer this in such a way that if we do decide that we need to retry more than once, then it should be easy to change that later. This should cover all of the syscalls in fs/stat.c and fs/namei.c, and most of fs/open.c.
Once these are merged, I'll look at adding similar handling to other path-based syscalls in a later set. A quick look shows that we have about 50-odd path-based syscalls that will need similar handling, so this is just a start.
Jeff Layton (20):
vfs: add a retry_estale helper function to handle retries on ESTALE
vfs: make fstatat retry on ESTALE errors from getattr call
vfs: fix readlinkat to retry on ESTALE
vfs: add new "reval" argument to kern_path_create and
user_path_create
vfs: fix mknodat to retry on ESTALE errors
vfs: fix mkdir to retry on ESTALE errors
vfs: fix symlinkat to retry on ESTALE errors
vfs: fix linkat to retry on ESTALE errors
vfs: add a reval argument to user_path_parent
vfs: make rmdir retry on ESTALE errors
vfs: make do_unlinkat retry on ESTALE errors
vfs: fix renameat to retry on ESTALE errors
vfs: have do_sys_truncate retry once on an ESTALE error
vfs: have faccessat retry once on an ESTALE error
vfs: have chdir retry lookup and call once on ESTALE error
vfs: make chroot retry once on ESTALE error
vfs: make fchmodat retry once on ESTALE errors
vfs: make fchownat retry once on ESTALE errors
vfs: convert do_filp_open to use retry_estale helper
vfs: convert do_file_open_root to use retry_estale helper
arch/powerpc/platforms/cell/spufs/syscalls.c | 2 +- drivers/base/devtmpfs.c | 7 +- fs/namei.c | 265 ++++++++++++++++----------- fs/ocfs2/refcounttree.c | 3 +- fs/open.c | 252 +++++++++++++------------ fs/stat.c | 32 +++- include/linux/fs.h | 21 +++ include/linux/namei.h | 4 +- net/unix/af_unix.c | 2 +- 9 files changed, 352 insertions(+), 236 deletions(-)
Signature · 1 line
1.7.11.4
PATCH v6 1/20 vfs: add a retry_estale helper function to handle retries on ESTALE
This function is expected to be called from path-based syscalls to help them decide whether to try the lookup and call again in the event that they got an -ESTALE return back on an earier try.
Currently, we only retry the call once on an ESTALE error, but in the event that we decide that that's not enough in the future, we should be able to change the logic in this helper without too much effort.
--- include/linux/fs.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
include/linux/fs.h +21 -0
@@ -2221,6 +2221,27 @@ extern int finish_open(struct file *file, struct dentry *dentry, int *opened);extern int finish_no_open (struct file *file,struct dentry *dentry); +/** +* retry_estale - determine whether the caller should retry an operation +* +* @error: the error we'll be returning +* @try: number of retries already performed +* +* Check to see if the error code was -ESTALE, and then determine whether +* to retry the call based on the number of retries so far. Currently, we only +* retry the call once. +* +* Returns true if the caller should try again. +*/ +static inline bool +retry_estale (const long error,const unsigned int try) +{ +if (likely (error != -ESTALE )) +return false; + +return !try; +} +/* fs/ioctl.c */ extern int ioctl_preallocate (struct file *filp,void __user *argp);
Signature · 1 line
1.7.11.4
PATCH v6 2/20 vfs: make fstatat retry on ESTALE errors from getattr call
In reply to Jeff Layton--- fs/stat.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
fs/stat.c +10 -6
@@ -74,7 +74,8 @@ int vfs_fstatat(int dfd, const char __user *filename, struct kstat *stat, {struct path path;int error = -EINVAL ; -int lookup_flags =0 ; +unsigned int try =0 ; +unsigned int lookup_flags =0 ;if ((flag & ~(AT_SYMLINK_NOFOLLOW |AT_NO_AUTOMOUNT |AT_EMPTY_PATH )) !=0 )
@@ -85,12 +86,15 @@ int vfs_fstatat(int dfd, const char __user *filename, struct kstat *stat,if (flag &AT_EMPTY_PATH ) lookup_flags |=LOOKUP_EMPTY ; - error =user_path_at (dfd, filename, lookup_flags, &path); -if (error) - goto out; +do { + error =user_path_at (dfd, filename, lookup_flags, &path); +if (error) +break ; - error =vfs_getattr (path.mnt, path.dentry, stat); -path_put (&path); + error =vfs_getattr (path.mnt, path.dentry, stat); +path_put (&path); + lookup_flags |=LOOKUP_REVAL ; + }while (retry_estale (error, try++)); out:return error; }
Signature · 1 line
1.7.11.4
PATCH v6 3/20 vfs: fix readlinkat to retry on ESTALE
In reply to Jeff Layton--- fs/stat.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
fs/stat.c +12 -4
@@ -300,14 +300,21 @@ SYSCALL_DEFINE4(readlinkat, int, dfd, const char __user *, pathname,struct path path;int error;int empty =0 ; +unsigned int try =0 ; +unsigned int lookup_flags =LOOKUP_EMPTY ;if (bufsiz <=0 )return -EINVAL ; - error =user_path_at_empty (dfd, pathname,LOOKUP_EMPTY , &path, &empty); -if (!error) { -struct inode *inode = path.dentry->d_inode; + do { + struct inode *inode; + + error = user_path_at_empty(dfd, pathname, lookup_flags, + &path, &empty); + if (error) + break; + inode = path.dentry->d_inode; error = empty ? -ENOENT : -EINVAL; if (inode->i_op->readlink) { error = security_inode_readlink(path.dentry);
@@ -318,7 +325,8 @@ SYSCALL_DEFINE4(readlinkat, int, dfd, const char __user *, pathname, } }path_put (&path); - } + lookup_flags |=LOOKUP_REVAL ; + }while (retry_estale (error, try++));return error; }
Signature · 1 line
1.7.11.4
PATCH v6 4/20 vfs: add new "reval" argument to kern_path_create and user_path_create
In reply to Jeff Layton...for now, all of the callers pass in "false". Eventually, we'll set that to "true" when we retry the lookup after getting back an ESTALE on a call.
While we're at it, change the is_dir arg to a bool since that's how it's used currently.
--- arch/powerpc/platforms/cell/spufs/syscalls.c | 2 +- drivers/base/devtmpfs.c | 7 ++++--- fs/namei.c | 23 +++++++++++++++-------- fs/ocfs2/refcounttree.c | 3 ++- include/linux/namei.h | 4 ++-- net/unix/af_unix.c | 2 +- 6 files changed, 25 insertions(+), 16 deletions(-)
arch/powerpc/platforms/cell/spufs/syscalls.c +1 -1
@@ -66,7 +66,7 @@ static long do_spu_create(const char __user *pathname, unsigned int flags,struct dentry *dentry;int ret; - dentry =user_path_create (AT_FDCWD , pathname, &path,1 ); + dentry =user_path_create (AT_FDCWD , pathname, &path, true, false); ret =PTR_ERR (dentry);if (!IS_ERR (dentry)) { ret =spufs_create (&path, dentry, flags, mode, neighbor);
drivers/base/devtmpfs.c +4 -3
@@ -148,7 +148,7 @@ static int dev_mkdir(const char *name, umode_t mode)struct path path;int err; - dentry =kern_path_create (AT_FDCWD , name, &path,1 ); + dentry =kern_path_create (AT_FDCWD , name, &path, true, false);if (IS_ERR (dentry))return PTR_ERR (dentry);
@@ -193,10 +193,11 @@ static int handle_create(const char *nodename, umode_t mode, struct device *dev)struct path path;int err; - dentry =kern_path_create (AT_FDCWD , nodename, &path,0 ); + dentry =kern_path_create (AT_FDCWD , nodename, &path, false, false);if (dentry ==ERR_PTR (-ENOENT )) {create_path (nodename); - dentry =kern_path_create (AT_FDCWD , nodename, &path,0 ); + dentry =kern_path_create (AT_FDCWD , nodename, &path, + false, false); }if (IS_ERR (dentry))return PTR_ERR (dentry);
fs/namei.c +15 -8
@@ -3038,12 +3038,18 @@ struct file *do_file_open_root(struct dentry *dentry, struct vfsmount *mnt,return file; } -struct dentry *kern_path_create (int dfd,const char *pathname,struct path *path,int is_dir) +struct dentry *kern_path_create (int dfd,const char *pathname,struct path *path,bool is_dir,bool reval) {struct dentry *dentry =ERR_PTR (-EEXIST );struct nameidata nd;int err2; -int error =do_path_lookup (dfd, pathname,LOOKUP_PARENT , &nd); +int error; +unsigned int lookup_flags =LOOKUP_PARENT ; + +if (reval) + lookup_flags |=LOOKUP_REVAL ; + + error =do_path_lookup (dfd, pathname, lookup_flags, &nd);if (error)return ERR_PTR (error);
@@ -3107,13 +3113,14 @@ void done_path_create(struct path *path, struct dentry *dentry) }EXPORT_SYMBOL (done_path_create); -struct dentry *user_path_create (int dfd,const char __user *pathname,struct path *path,int is_dir) +struct dentry *user_path_create (int dfd,const char __user *pathname, +struct path *path,bool is_dir,bool reval) {struct getname_info *tmp =getname (pathname);struct dentry *res;if (IS_ERR (tmp))return ERR_CAST (tmp); - res =kern_path_create (dfd, tmp->name, path, is_dir); + res =kern_path_create (dfd, tmp->name, path, is_dir, reval);putname (tmp);return res; }
@@ -3174,7 +3181,7 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,if (error)return error; - dentry =user_path_create (dfd, filename, &path,0 ); + dentry =user_path_create (dfd, filename, &path, false, false);if (IS_ERR (dentry))return PTR_ERR (dentry);
@@ -3236,7 +3243,7 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)struct path path;int error; - dentry =user_path_create (dfd, pathname, &path,1 ); + dentry =user_path_create (dfd, pathname, &path, true, false);if (IS_ERR (dentry))return PTR_ERR (dentry);
@@ -3512,7 +3519,7 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,if (IS_ERR (from))return PTR_ERR (from); - dentry =user_path_create (newdfd, newname, &path,0 ); + dentry =user_path_create (newdfd, newname, &path, false, false); error =PTR_ERR (dentry);if (IS_ERR (dentry)) goto out_putname;
@@ -3612,7 +3619,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,if (error)return error; - new_dentry =user_path_create (newdfd, newname, &new_path,0 ); + new_dentry =user_path_create (newdfd, newname, &new_path, false, false); error =PTR_ERR (new_dentry);if (IS_ERR (new_dentry)) goto out;
fs/ocfs2/refcounttree.c +2 -1
@@ -4453,7 +4453,8 @@ int ocfs2_reflink_ioctl(struct inode *inode,return error; } - new_dentry =user_path_create (AT_FDCWD , newname, &new_path,0 ); + new_dentry =user_path_create (AT_FDCWD , newname, &new_path, + false, false); error =PTR_ERR (new_dentry);if (IS_ERR (new_dentry)) {mlog_errno (error);
include/linux/namei.h +2 -2
@@ -65,8 +65,8 @@ extern int user_path_at_empty(int, const char __user *, unsigned, struct path *,extern int kern_path (const char *,unsigned ,struct path *); -extern struct dentry *kern_path_create (int ,const char *,struct path *,int ); -extern struct dentry *user_path_create (int ,const char __user *,struct path *,int ); +extern struct dentry *kern_path_create (int ,const char *,struct path *,bool ,bool ); +extern struct dentry *user_path_create (int ,const char __user *,struct path *,bool ,bool );extern void done_path_create (struct path *,struct dentry *);extern struct dentry *kern_path_locked (const char *,struct path *); extern int vfs_path_lookup(struct dentry *, struct vfsmount *,
net/unix/af_unix.c +1 -1
@@ -832,7 +832,7 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)* Get the parent directory, calculate the hash for last * component. */ - dentry =kern_path_create (AT_FDCWD , sun_path, &path,0 ); + dentry =kern_path_create (AT_FDCWD , sun_path, &path, false, false); err =PTR_ERR (dentry);if (IS_ERR (dentry))return err;
Signature · 1 line
1.7.11.4
PATCH v6 5/20 vfs: fix mknodat to retry on ESTALE errors
In reply to Jeff Layton--- fs/namei.c | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-)
fs/namei.c +25 -18
@@ -3176,34 +3176,41 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,struct dentry *dentry;struct path path;int error; +unsigned int try =0 ; error =may_mknod (mode);if (error)return error; - dentry =user_path_create (dfd, filename, &path, false, false); -if (IS_ERR (dentry)) -return PTR_ERR (dentry); +do { + dentry =user_path_create (dfd, filename, &path, false, try); +if (IS_ERR (dentry)) +return PTR_ERR (dentry); -if (!IS_POSIXACL (path.dentry->d_inode)) - mode &= ~current_umask (); - error =security_path_mknod (&path, dentry, mode, dev); -if (error) - goto out; -switch (mode &S_IFMT ) { -case 0 :case S_IFREG : - error =vfs_create (path.dentry->d_inode,dentry,mode,true); +if (!IS_POSIXACL (path.dentry->d_inode)) + mode &= ~current_umask (); + error =security_path_mknod (&path, dentry, mode, dev); +if (error) + goto out; +switch (mode &S_IFMT ) { +case 0 : +case S_IFREG : + error =vfs_create (path.dentry->d_inode, dentry, + mode, true);break ; -case S_IFCHR :case S_IFBLK : - error =vfs_mknod (path.dentry->d_inode,dentry,mode, +case S_IFCHR : +case S_IFBLK : + error =vfs_mknod (path.dentry->d_inode, dentry, mode,new_decode_dev (dev));break ; -case S_IFIFO :case S_IFSOCK : - error =vfs_mknod (path.dentry->d_inode,dentry,mode,0 ); -break ; - } +case S_IFIFO : +case S_IFSOCK : + error =vfs_mknod (path.dentry->d_inode, dentry, + mode,0 ); + } out: -done_path_create (&path, dentry); +done_path_create (&path, dentry); + }while (retry_estale (error, try++));return error; }
Signature · 1 line
1.7.11.4
PATCH v6 6/20 vfs: fix mkdir to retry on ESTALE errors
In reply to Jeff Layton--- fs/namei.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)
fs/namei.c +12 -9
@@ -3249,17 +3249,20 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)struct dentry *dentry;struct path path;int error; +unsigned int try =0 ; - dentry =user_path_create (dfd, pathname, &path, true, false); -if (IS_ERR (dentry)) -return PTR_ERR (dentry); +do { + dentry =user_path_create (dfd, pathname, &path, true, false); +if (IS_ERR (dentry)) +return PTR_ERR (dentry); -if (!IS_POSIXACL (path.dentry->d_inode)) - mode &= ~current_umask (); - error =security_path_mkdir (&path, dentry, mode); -if (!error) - error =vfs_mkdir (path.dentry->d_inode, dentry, mode); -done_path_create (&path, dentry); +if (!IS_POSIXACL (path.dentry->d_inode)) + mode &= ~current_umask (); + error =security_path_mkdir (&path, dentry, mode); +if (!error) + error =vfs_mkdir (path.dentry->d_inode, dentry, mode); +done_path_create (&path, dentry); + }while (retry_estale (error, try++));return error; }
Signature · 1 line
1.7.11.4
PATCH v6 7/20 vfs: fix symlinkat to retry on ESTALE errors
In reply to Jeff Layton--- fs/namei.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-)
fs/namei.c +13 -9
@@ -3524,21 +3524,25 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,struct getname_info *from;struct dentry *dentry;struct path path; +unsigned int try =0 ; from =getname (oldname);if (IS_ERR (from))return PTR_ERR (from); - dentry =user_path_create (newdfd, newname, &path, false, false); - error =PTR_ERR (dentry); -if (IS_ERR (dentry)) - goto out_putname; +do { + dentry =user_path_create (newdfd, newname, &path, false, false); +if (IS_ERR (dentry)) { + error =PTR_ERR (dentry); +break ; + } - error =security_path_symlink (&path, dentry, from->name); -if (!error) - error =vfs_symlink (path.dentry->d_inode, dentry, from->name); -done_path_create (&path, dentry); -out_putname: + error =security_path_symlink (&path, dentry, from->name); +if (!error) + error =vfs_symlink (path.dentry->d_inode, dentry, + from->name); +done_path_create (&path, dentry); + }while (retry_estale (error, try++));putname (from);return error; }
Signature · 1 line
1.7.11.4
PATCH v6 8/20 vfs: fix linkat to retry on ESTALE errors
In reply to Jeff Layton--- fs/namei.c | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-)
fs/namei.c +26 -20
@@ -3612,6 +3612,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,struct path old_path, new_path;int how =0 ;int error; +unsigned int try =0 ;if ((flags & ~(AT_SYMLINK_FOLLOW |AT_EMPTY_PATH )) !=0 )return -EINVAL ;
@@ -3629,30 +3630,35 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,if (flags &AT_SYMLINK_FOLLOW ) how |=LOOKUP_FOLLOW ; - error =user_path_at (olddfd, oldname, how, &old_path); -if (error) -return error; +do { + error =user_path_at (olddfd, oldname, how, &old_path); +if (error) +break ; - new_dentry =user_path_create (newdfd, newname, &new_path, false, false); - error =PTR_ERR (new_dentry); -if (IS_ERR (new_dentry)) - goto out; + new_dentry =user_path_create (newdfd, newname, &new_path, + false, false); + error =PTR_ERR (new_dentry); +if (IS_ERR (new_dentry)) + goto out; - error = -EXDEV ; -if (old_path.mnt != new_path.mnt) - goto out_dput; - error =may_linkat (&old_path); -if (unlikely (error)) - goto out_dput; - error =security_path_link (old_path.dentry, &new_path, new_dentry); -if (error) - goto out_dput; - error =vfs_link (old_path.dentry, new_path.dentry->d_inode, new_dentry); + error = -EXDEV ; +if (old_path.mnt != new_path.mnt) + goto out_dput; + error =may_linkat (&old_path); +if (unlikely (error)) + goto out_dput; + error =security_path_link (old_path.dentry, &new_path, + new_dentry); +if (error) + goto out_dput; + error =vfs_link (old_path.dentry, new_path.dentry->d_inode, + new_dentry); out_dput: -done_path_create (&new_path, new_dentry); +done_path_create (&new_path, new_dentry); out: -path_put (&old_path); - +path_put (&old_path); + how |=LOOKUP_REVAL ; + }while (retry_estale (error, try++));return error; }
Signature · 1 line
1.7.11.4
PATCH v6 9/20 vfs: add a reval argument to user_path_parent
In reply to Jeff Layton...so we can tell it when to set LOOKUP_REVAL.
--- fs/namei.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
fs/namei.c +11 -6
@@ -2183,15 +2183,20 @@ int user_path_at(int dfd, const char __user *name, unsigned flags,* path-walking is complete. */ static struct getname_info * -user_path_parent (int dfd,const char __user *path,struct nameidata *nd) +user_path_parent (int dfd,const char __user *path,struct nameidata *nd, +unsigned int reval) {struct getname_info *s =getname (path);int error; +unsigned int flags =LOOKUP_PARENT ; + +if (reval) + flags |=LOOKUP_REVAL ;if (IS_ERR (s))return s; - error =ginfo_lookup (dfd, s,LOOKUP_PARENT , nd); + error =ginfo_lookup (dfd, s, flags, nd);if (error) {putname (s);return ERR_PTR (error);
@@ -3339,7 +3344,7 @@ static long do_rmdir(int dfd, const char __user *pathname)struct dentry *dentry;struct nameidata nd; - name =user_path_parent (dfd, pathname, &nd); + name =user_path_parent (dfd, pathname, &nd,0 );if (IS_ERR (name))return PTR_ERR (name);
@@ -3435,7 +3440,7 @@ static long do_unlinkat(int dfd, const char __user *pathname)struct nameidata nd;struct inode *inode =NULL ; - name =user_path_parent (dfd, pathname, &nd); + name =user_path_parent (dfd, pathname, &nd,0 );if (IS_ERR (name))return PTR_ERR (name);
@@ -3830,13 +3835,13 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,struct getname_info *to;int error; - from =user_path_parent (olddfd, oldname, &oldnd); + from =user_path_parent (olddfd, oldname, &oldnd,0 );if (IS_ERR (from)) { error =PTR_ERR (from); goto exit; } - to =user_path_parent (newdfd, newname, &newnd); + to =user_path_parent (newdfd, newname, &newnd,0 );if (IS_ERR (to)) { error =PTR_ERR (to); goto exit1;
Signature · 6 lines
1.7.11.4 -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v6 10/20 vfs: make rmdir retry on ESTALE errors
In reply to Jeff Layton--- fs/namei.c | 81 ++++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 44 insertions(+), 37 deletions(-)
fs/namei.c +44 -37
@@ -3343,49 +3343,56 @@ static long do_rmdir(int dfd, const char __user *pathname)struct getname_info *name;struct dentry *dentry;struct nameidata nd; +unsigned int try =0 ; +unsigned int lookup_flags =LOOKUP_PARENT ; - name =user_path_parent (dfd, pathname, &nd,0 ); -if (IS_ERR (name)) -return PTR_ERR (name); - -switch (nd.last_type) { -case LAST_DOTDOT : - error = -ENOTEMPTY ; - goto exit1; -case LAST_DOT : - error = -EINVAL ; - goto exit1; -case LAST_ROOT : - error = -EBUSY ; - goto exit1; - } +do { + name =user_path_parent (dfd, pathname, &nd, try); +if (IS_ERR (name)) +return PTR_ERR (name); + +switch (nd.last_type) { +case LAST_DOTDOT : + error = -ENOTEMPTY ; + goto exit1; +case LAST_DOT : + error = -EINVAL ; + goto exit1; +case LAST_ROOT : + error = -EBUSY ; + goto exit1; + } - nd.flags &= ~LOOKUP_PARENT ; - error =mnt_want_write (nd.path.mnt); -if (error) - goto exit1; + nd.flags &= ~LOOKUP_PARENT ; + error =mnt_want_write (nd.path.mnt); +if (error) + goto exit1; -mutex_lock_nested (&nd.path.dentry->d_inode->i_mutex,I_MUTEX_PARENT ); - dentry =lookup_hash (&nd); - error =PTR_ERR (dentry); -if (IS_ERR (dentry)) - goto exit2; -if (!dentry->d_inode) { - error = -ENOENT ; - goto exit3; - } - error =security_path_rmdir (&nd.path, dentry); -if (error) - goto exit3; - error =vfs_rmdir (nd.path.dentry->d_inode, dentry); +mutex_lock_nested (&nd.path.dentry->d_inode->i_mutex, +I_MUTEX_PARENT ); + dentry =lookup_hash (&nd); +if (IS_ERR (dentry)) { + error =PTR_ERR (dentry); + goto exit2; + } +if (!dentry->d_inode) { + error = -ENOENT ; + goto exit3; + } + error =security_path_rmdir (&nd.path, dentry); +if (error) + goto exit3; + error =vfs_rmdir (nd.path.dentry->d_inode, dentry); exit3: -dput (dentry); +dput (dentry); exit2: -mutex_unlock (&nd.path.dentry->d_inode->i_mutex); -mnt_drop_write (nd.path.mnt); +mutex_unlock (&nd.path.dentry->d_inode->i_mutex); +mnt_drop_write (nd.path.mnt); exit1: -path_put (&nd.path); -putname (name); +path_put (&nd.path); + lookup_flags |=LOOKUP_REVAL ; +putname (name); + }while (retry_estale (error, try++));return error; }
Signature · 1 line
1.7.11.4
PATCH v6 11/20 vfs: make do_unlinkat retry on ESTALE errors
In reply to Jeff Layton--- fs/namei.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
fs/namei.c +8 -1
@@ -3446,8 +3446,11 @@ static long do_unlinkat(int dfd, const char __user *pathname)struct dentry *dentry;struct nameidata nd;struct inode *inode =NULL ; +unsigned int try =0 ; +unsigned int lookup_flags =LOOKUP_PARENT ; - name =user_path_parent (dfd, pathname, &nd,0 ); +retry: + name =user_path_parent (dfd, pathname, &nd, try);if (IS_ERR (name))return PTR_ERR (name);
@@ -3485,6 +3488,10 @@ exit2: exit1:path_put (&nd.path);putname (name); +if (retry_estale (error, try++)) { + lookup_flags |=LOOKUP_REVAL ; + goto retry; + }return error; slashes:
Signature · 1 line
1.7.11.4
PATCH v6 12/20 vfs: fix renameat to retry on ESTALE errors
In reply to Jeff Layton...as always, rename is the messiest of the bunch. We have to track whether to retry or not via a separate flag since the error handling is already quite complex.
--- fs/namei.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
fs/namei.c +11 -2
@@ -3847,15 +3847,18 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,struct nameidata oldnd, newnd;struct getname_info *from;struct getname_info *to; +unsigned int try =0 ; +bool should_retry = false;int error; - from =user_path_parent (olddfd, oldname, &oldnd,0 ); +retry: + from =user_path_parent (olddfd, oldname, &oldnd, try);if (IS_ERR (from)) { error =PTR_ERR (from); goto exit; } - to =user_path_parent (newdfd, newname, &newnd,0 ); + to =user_path_parent (newdfd, newname, &newnd, try);if (IS_ERR (to)) { error =PTR_ERR (to); goto exit1;
@@ -3927,11 +3930,17 @@ exit3:unlock_rename (new_dir, old_dir);mnt_drop_write (oldnd.path.mnt); exit2: +if (retry_estale (error, try++)) + should_retry = true;path_put (&newnd.path);putname (to); exit1:path_put (&oldnd.path);putname (from); +if (should_retry) { + should_retry = false; + goto retry; + } exit:return error; }
Signature · 1 line
1.7.11.4
PATCH v6 13/20 vfs: have do_sys_truncate retry once on an ESTALE error
In reply to Jeff Layton--- fs/open.c | 86 +++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 45 insertions(+), 41 deletions(-)
fs/open.c +45 -41
@@ -66,62 +66,66 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)struct path path;struct inode *inode;int error; +unsigned int lookup_flags =LOOKUP_FOLLOW ; +unsigned int try =0 ; - error = -EINVAL ;if (length <0 )/* sorry, but loff_t says... */ - goto out; +return -EINVAL ; - error =user_path (pathname, &path); -if (error) - goto out; - inode = path.dentry->d_inode; +do { + error =user_path_at (AT_FDCWD , pathname, lookup_flags, &path); +if (error) +break ; + inode = path.dentry->d_inode; -/* For directories it's -EISDIR, for other non-regulars - -EINVAL */ - error = -EISDIR ; -if (S_ISDIR (inode->i_mode)) - goto dput_and_out; +/* For dirs, -EISDIR. For other non-regulars, -EINVAL */ + error = -EISDIR ; +if (S_ISDIR (inode->i_mode)) + goto dput_and_out; - error = -EINVAL ; -if (!S_ISREG (inode->i_mode)) - goto dput_and_out; + error = -EINVAL ; +if (!S_ISREG (inode->i_mode)) + goto dput_and_out; - error =mnt_want_write (path.mnt); -if (error) - goto dput_and_out; + error =mnt_want_write (path.mnt); +if (error) + goto dput_and_out; - error =inode_permission (inode,MAY_WRITE ); -if (error) - goto mnt_drop_write_and_out; + error =inode_permission (inode,MAY_WRITE ); +if (error) + goto mnt_drop_write_and_out; - error = -EPERM ; -if (IS_APPEND (inode)) - goto mnt_drop_write_and_out; + error = -EPERM ; +if (IS_APPEND (inode)) + goto mnt_drop_write_and_out; - error =get_write_access (inode); -if (error) - goto mnt_drop_write_and_out; + error =get_write_access (inode); +if (error) + goto mnt_drop_write_and_out; -/* -* Make sure that there are no leases. get_write_access() protects -* against the truncate racing with a lease-granting setlease(). -*/ - error =break_lease (inode,O_WRONLY ); -if (error) - goto put_write_and_out; +/* +* Make sure that there are no leases. get_write_access() +* protects against the truncate racing with a lease-granting +* setlease(). +*/ + error =break_lease (inode,O_WRONLY ); +if (error) + goto put_write_and_out; - error =locks_verify_truncate (inode,NULL , length); -if (!error) - error =security_path_truncate (&path); -if (!error) - error =do_truncate (path.dentry, length,0 ,NULL ); + error =locks_verify_truncate (inode,NULL , length); +if (!error) + error =security_path_truncate (&path); +if (!error) + error =do_truncate (path.dentry, length,0 ,NULL ); put_write_and_out: -put_write_access (inode); +put_write_access (inode); mnt_drop_write_and_out: -mnt_drop_write (path.mnt); +mnt_drop_write (path.mnt); dput_and_out: -path_put (&path); -out: +path_put (&path); + lookup_flags |=LOOKUP_REVAL ; + }while (retry_estale (error, try++));return error; }
Signature · 6 lines
1.7.11.4 -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v6 14/20 vfs: have faccessat retry once on an ESTALE error
In reply to Jeff Layton--- fs/open.c | 64 +++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 34 insertions(+), 30 deletions(-)
fs/open.c +34 -30
@@ -312,6 +312,8 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)struct path path;struct inode *inode;int res; +unsigned int lookup_flags =LOOKUP_FOLLOW ; +unsigned int try =0 ;if (mode & ~S_IRWXO )/* where's F_OK, X_OK, W_OK, R_OK? */ return -EINVAL ;
@@ -335,42 +337,44 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode) old_cred =override_creds (override_cred); - res =user_path_at (dfd, filename,LOOKUP_FOLLOW , &path); -if (res) - goto out; +do { + res =user_path_at (dfd, filename, lookup_flags, &path); +if (res) +break ; - inode = path.dentry->d_inode; + inode = path.dentry->d_inode; + +if ((mode &MAY_EXEC ) &&S_ISREG (inode->i_mode)) { +/* +* MAY_EXEC on regular files is denied if the fs is +* mounted with the "noexec" flag. +*/ + res = -EACCES ; +if (path.mnt->mnt_flags &MNT_NOEXEC ) + goto out_path_release; + } -if ((mode &MAY_EXEC ) &&S_ISREG (inode->i_mode)) { + res =inode_permission (inode, mode |MAY_ACCESS ); +/* SuS v2 requires we report a read only fs too */ +if (res || !(mode &S_IWOTH ) ||special_file (inode->i_mode)) + goto out_path_release;/* -* MAY_EXEC on regular files is denied if the fs is mounted -* with the "noexec" flag. +* This is a rare case where using __mnt_is_readonly() +* is OK without a mnt_want/drop_write() pair. Since +* no actual write to the fs is performed here, we do +* not need to telegraph to that to anyone. +* +* By doing this, we accept that this access is +* inherently racy and know that the fs may change +* state before we even see this result. */ - res = -EACCES ; -if (path.mnt->mnt_flags &MNT_NOEXEC ) - goto out_path_release; - } - - res =inode_permission (inode, mode |MAY_ACCESS ); -/* SuS v2 requires we report a read only fs too */ -if (res || !(mode &S_IWOTH ) ||special_file (inode->i_mode)) - goto out_path_release; -/* -* This is a rare case where using __mnt_is_readonly() -* is OK without a mnt_want/drop_write() pair. Since -* no actual write to the fs is performed here, we do -* not need to telegraph to that to anyone. -* -* By doing this, we accept that this access is -* inherently racy and know that the fs may change -* state before we even see this result. -*/ -if (__mnt_is_readonly (path.mnt)) - res = -EROFS ; +if (__mnt_is_readonly (path.mnt)) + res = -EROFS ; out_path_release: -path_put (&path); -out: +path_put (&path); + lookup_flags |=LOOKUP_REVAL ; + }while (retry_estale (res, try++));revert_creds (old_cred);put_cred (override_cred);return res;
Signature · 1 line
1.7.11.4
PATCH v6 15/20 vfs: have chdir retry lookup and call once on ESTALE error
In reply to Jeff Layton--- fs/open.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-)
fs/open.c +13 -12
@@ -389,20 +389,21 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename) {struct path path;int error; +int lookup_flags =LOOKUP_FOLLOW |LOOKUP_DIRECTORY ; +unsigned int try =0 ; - error =user_path_dir (filename, &path); -if (error) - goto out; - - error =inode_permission (path.dentry->d_inode,MAY_EXEC |MAY_CHDIR ); -if (error) - goto dput_and_out; - -set_fs_pwd (current->fs, &path); +do { + error =user_path_at (AT_FDCWD , filename, lookup_flags, &path); +if (error) +break ; -dput_and_out: -path_put (&path); -out: + error =inode_permission (path.dentry->d_inode, +MAY_EXEC |MAY_CHDIR ); +if (!error) +set_fs_pwd (current->fs, &path); +path_put (&path); + lookup_flags |=LOOKUP_REVAL ; + }while (retry_estale (error, try++));return error; }
Signature · 1 line
1.7.11.4
PATCH v6 16/20 vfs: make chroot retry once on ESTALE error
In reply to Jeff Layton--- fs/open.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-)
fs/open.c +21 -16
@@ -437,27 +437,32 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename) {struct path path;int error; +int lookup_flags =LOOKUP_FOLLOW |LOOKUP_DIRECTORY ; +unsigned int try =0 ; - error =user_path_dir (filename, &path); -if (error) - goto out; +do { + error =user_path_at (AT_FDCWD , filename, lookup_flags, &path); +if (error) +break ; - error =inode_permission (path.dentry->d_inode,MAY_EXEC |MAY_CHDIR ); -if (error) - goto dput_and_out; + error =inode_permission (path.dentry->d_inode, +MAY_EXEC |MAY_CHDIR ); +if (error) + goto dput_and_out; - error = -EPERM ; -if (!capable (CAP_SYS_CHROOT )) - goto dput_and_out; - error =security_path_chroot (&path); -if (error) - goto dput_and_out; + error = -EPERM ; +if (!capable (CAP_SYS_CHROOT )) + goto dput_and_out; + error =security_path_chroot (&path); +if (error) + goto dput_and_out; -set_fs_root (current->fs, &path); - error =0 ; +set_fs_root (current->fs, &path); + error =0 ; dput_and_out: -path_put (&path); -out: +path_put (&path); + lookup_flags |=LOOKUP_REVAL ; + }while (retry_estale (error, try++));return error; }
Signature · 1 line
1.7.11.4
PATCH v6 17/20 vfs: make fchmodat retry once on ESTALE errors
In reply to Jeff Layton--- fs/open.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
fs/open.c +8 -3
@@ -506,12 +506,17 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, const char __user *, filename, umode_t, mode {struct path path;int error; +unsigned int try =0 ; +int lookup_flags =LOOKUP_FOLLOW ; - error =user_path_at (dfd, filename,LOOKUP_FOLLOW , &path); -if (!error) { +do { + error =user_path_at (dfd, filename, lookup_flags, &path); +if (error) +break ; error =chmod_common (&path, mode);path_put (&path); - } + lookup_flags |=LOOKUP_REVAL ; + }while (retry_estale (error, try++));return error; }
Signature · 6 lines
1.7.11.4 -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v6 18/20 vfs: make fchownat retry once on ESTALE errors
In reply to Jeff Layton--- fs/open.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-)
fs/open.c +17 -12
@@ -567,24 +567,29 @@ SYSCALL_DEFINE5(fchownat, int, dfd, const char __user *, filename, uid_t, user,struct path path;int error = -EINVAL ;int lookup_flags; +unsigned int try =0 ;if ((flag & ~(AT_SYMLINK_NOFOLLOW |AT_EMPTY_PATH )) !=0 ) - goto out; +return error; lookup_flags = (flag &AT_SYMLINK_NOFOLLOW ) ?0 :LOOKUP_FOLLOW ;if (flag &AT_EMPTY_PATH ) lookup_flags |=LOOKUP_EMPTY ; - error =user_path_at (dfd, filename, lookup_flags, &path); -if (error) - goto out; - error =mnt_want_write (path.mnt); -if (error) - goto out_release; - error =chown_common (&path, user, group); -mnt_drop_write (path.mnt); -out_release: -path_put (&path); -out: + +do { + error =user_path_at (dfd, filename, lookup_flags, &path); +if (error) +break ; + + error =mnt_want_write (path.mnt); +if (!error) { + error =chown_common (&path, user, group); +mnt_drop_write (path.mnt); + } + +path_put (&path); + lookup_flags |=LOOKUP_REVAL ; + }while (retry_estale (error, try++));return error; }
Signature · 6 lines
1.7.11.4 -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v6 19/20 vfs: convert do_filp_open to use retry_estale helper
In reply to Jeff Layton--- fs/namei.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/namei.c +2 -1
@@ -3011,11 +3011,12 @@ struct file *do_filp_open(int dfd, struct getname_info *ginfo, {struct nameidata nd;struct file *filp; +unsigned int try =0 ; filp =path_openat (dfd, ginfo, &nd, op, flags |LOOKUP_RCU );if (unlikely (filp ==ERR_PTR (-ECHILD ))) filp =path_openat (dfd, ginfo, &nd, op, flags); -if (unlikely (filp ==ERR_PTR (-ESTALE ))) +while (retry_estale (PTR_ERR (filp), try++)) filp =path_openat (dfd, ginfo, &nd, op, flags |LOOKUP_REVAL );return filp; }
Signature · 1 line
1.7.11.4
PATCH v6 20/20 vfs: convert do_file_open_root to use retry_estale helper
In reply to Jeff Layton--- fs/namei.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/namei.c +2 -1
@@ -3027,6 +3027,7 @@ struct file *do_file_open_root(struct dentry *dentry, struct vfsmount *mnt,struct nameidata nd;struct file *file;struct getname_info ginfo = { .name = name }; +unsigned int try =0 ; nd.root.mnt = mnt; nd.root.dentry = dentry;
@@ -3039,7 +3040,7 @@ struct file *do_file_open_root(struct dentry *dentry, struct vfsmount *mnt, file =path_openat (-1 , &ginfo, &nd, op, flags |LOOKUP_RCU );if (unlikely (file ==ERR_PTR (-ECHILD ))) file =path_openat (-1 , &ginfo, &nd, op, flags); -if (unlikely (file ==ERR_PTR (-ESTALE ))) +while (retry_estale (PTR_ERR (file), try++)) file =path_openat (-1 , &ginfo, &nd, op, flags |LOOKUP_REVAL );return file; }
Signature · 1 line
1.7.11.4