mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton@redhat.com>
To: Miklos Szeredi <miklos@szeredi.hu>
Cc: "J. Bruce Fields" <bfields@fieldses.org>,
	Malahal Naineni <malahal@us.ibm.com>,
	Steve Dickson <SteveD@redhat.com>,
	linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org,
	linux-kernel@vger.kernel.org, viro@zeniv.linux.org.uk,
	hch@infradead.org, michael.brantley@deshaw.com,
	sven.breuner@itwm.fraunhofer.de, chuck.lever@oracle.com,
	pstaubach@exagrid.com, trond.myklebust@fys.uio.no,
	rees@umich.edu
Subject: Re: [PATCH RFC v3] vfs: make fstatat retry once on ESTALE errors from getattr call
Date: Mon, 23 Apr 2012 14:59:35 -0400	[thread overview]
Message-ID: <20120423145935.141cfe0b@tlielax.poochiereds.net> (raw)
In-Reply-To: <87zka2qxgs.fsf@tucsk.pomaz.szeredi.hu>

On Mon, 23 Apr 2012 17:28:19 +0200
Miklos Szeredi <miklos@szeredi.hu> wrote:

> Jeff Layton <jlayton@redhat.com> writes:
> 
> >
> > Ok, but again, that only applies to the lookup. It has no bearing on
> > the subsequent operation. For instance, if we're doing:
> >
> >      rename("/foo", "/bar");
> >
> > ...and another client is simultaneously doing:
> >
> >      creat("/bar/baz", 0600);
> >
> > ...and we get back ESTALE from the server on the create because the
> > "old" /bar got replaced after the lookup of it. Then it seems like
> > returning -ENOENT would not be correct since there was never a time
> > where /bar didn't exist...
> 
> It may not be "correct" according to some standard.  But it's what Linux
> does since day one on *all* filesystems.  And probably other OS's that
> have remotely scalable lookup routines.
> 
> Thanks,
> Miklos

The race window with local filesystems is very small though. I'm not
sure I've ever heard of anyone hitting this on one in practice. For NFS
OTOH, it's quite large and it's easy to hit an ESTALE without even
trying very hard.

On a related note, here's a first pass at making the getattr codepaths
handle ERETRYLOOKUP. It assumes that we don't need to fix the devtmpfs
callers or block/loop.c.

The really ugly part is that we have to deal with other callers that
don't have the ability to retry. So we have to convert ERETRYLOOKUP
back to ESTALE in those callers.

Dealing with vfs_getattr is actually fairly trivial. A tougher one would
be the inode_permission codepaths. Those go all over the place and it
would be tough to ensure that we don't leak this new error code to
userspace.

Personally, I think this approach is just too ugly to live in these
other codepaths, but it seems like a reasonable approach to allow us to
retry indefinitely on an ESTALE from a lookup.

-------------------------------------------------------------------------------
vfs-add-an-retry_lookup-functi
-------------------------------------------------------------------------------
vfs: add an retry_lookup function to handle retries on ERETRYLOOKUP

From: Jeff Layton <jlayton@redhat.com>

Signed-off-by: Jeff Layton <jlayton@redhat.com>
---

 fs/namei.c         |   23 +++++++++++++++++++++++
 include/linux/fs.h |    2 ++
 2 files changed, 25 insertions(+), 0 deletions(-)


diff --git a/fs/namei.c b/fs/namei.c
index fef6a0d..a781b0e 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -116,6 +116,29 @@
  * POSIX.1 2.4: an empty pathname is invalid (ENOENT).
  * PATH_MAX includes the nul terminator --RR.
  */
+
+/**
+ * retry_lookup - determine whether the caller should retry a lookup and op
+ *
+ * @error: the error we'll be returning
+ * @retry: what retry attempt we're on
+ *
+ */
+bool
+retry_lookup(const long error, const unsigned int retry)
+{
+	long timeout;
+
+	if (likely(error != -ERETRYLOOKUP))
+		return false;
+
+	/* arbitrarily cap backoff delay at 1s */
+	timeout = retry * 2;
+	timeout = timeout > HZ ? HZ : timeout;
+
+	return !schedule_timeout_killable(timeout);
+}
+
 static int do_getname(const char __user *filename, char *page)
 {
 	int retval;
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 8de6755..5cc03c3 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2026,6 +2026,8 @@ extern struct file * dentry_open(struct dentry *, struct vfsmount *, int,
 extern int filp_close(struct file *, fl_owner_t id);
 extern char * getname(const char __user *);
 
+extern bool retry_lookup(const long error, const unsigned int retry);
+
 /* fs/ioctl.c */
 
 extern int ioctl_preallocate(struct file *filp, void __user *argp);
-------------------------------------------------------------------------------
vfs-make-fstatat-retry-on-esta
-------------------------------------------------------------------------------
vfs: make fstatat retry on ESTALE errors from getattr call

From: Jeff Layton <jlayton@redhat.com>

Have NFS return ERETRYLOOKUP to the vfs when it gets an ESTALE back on a
GETATTR call. The VFS will then retry the lookup and call when it sees
that error.

Unfortunately, we do need to deal with the potential for "leakage" of
this error when we can't retry, so we must check for it in *all* callers
of vfs_getattr and swap -ESTALE for it when it occurs.

Signed-off-by: Jeff Layton <jlayton@redhat.com>
---

 fs/ecryptfs/inode.c |    2 +-
 fs/nfs/inode.c      |    2 +-
 fs/nfsd/nfsproc.c   |    1 +
 fs/stat.c           |   20 ++++++++++++--------
 4 files changed, 15 insertions(+), 10 deletions(-)


diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
index ab35b11..d4b5f15 100644
--- a/fs/ecryptfs/inode.c
+++ b/fs/ecryptfs/inode.c
@@ -1068,7 +1068,7 @@ int ecryptfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
 		generic_fillattr(dentry->d_inode, stat);
 		stat->blocks = lower_stat.blocks;
 	}
-	return rc;
+	return rc == -ERETRYLOOKUP ? -ESTALE : rc;
 }
 
 int
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index e8bbfa5..2916e87 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -541,7 +541,7 @@ int nfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
 		stat->ino = nfs_compat_user_ino64(NFS_FILEID(inode));
 	}
 out:
-	return err;
+	return err == -ESTALE ? -ERETRYLOOKUP : err;
 }
 
 static void nfs_init_lock_context(struct nfs_lock_context *l_ctx)
diff --git a/fs/nfsd/nfsproc.c b/fs/nfsd/nfsproc.c
index e15dc45..5dee967 100644
--- a/fs/nfsd/nfsproc.c
+++ b/fs/nfsd/nfsproc.c
@@ -742,6 +742,7 @@ nfserrno (int errno)
 		{ nfserr_notsupp, -EOPNOTSUPP },
 		{ nfserr_toosmall, -ETOOSMALL },
 		{ nfserr_serverfault, -ESERVERFAULT },
+		{ nfserr_stale, -ERETRYLOOKUP },
 	};
 	int	i;
 
diff --git a/fs/stat.c b/fs/stat.c
index c733dc5..fb4cf29 100644
--- a/fs/stat.c
+++ b/fs/stat.c
@@ -64,7 +64,7 @@ int vfs_fstat(unsigned int fd, struct kstat *stat)
 		error = vfs_getattr(f->f_path.mnt, f->f_path.dentry, stat);
 		fput(f);
 	}
-	return error;
+	return error == -ERETRYLOOKUP ? -ESTALE : error;
 }
 EXPORT_SYMBOL(vfs_fstat);
 
@@ -73,7 +73,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)
@@ -84,12 +85,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;
-
-	error = vfs_getattr(path.mnt, path.dentry, stat);
-	path_put(&path);
+	do {
+		error = user_path_at(dfd, filename, lookup_flags, &path);
+		if (!error) {
+			error = vfs_getattr(path.mnt, path.dentry, stat);
+			path_put(&path);
+			break;
+		}
+		lookup_flags |= LOOKUP_REVAL;
+	} while (retry_lookup(error, try++));
 out:
 	return error;
 }


  reply	other threads:[~2012-04-23 19:00 UTC|newest]

Thread overview: 80+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-13 11:25 [PATCH RFC] vfs: make fstatat retry " Jeff Layton
2012-04-13 12:02 ` Jim Rees
2012-04-13 12:09   ` Jeff Layton
     [not found] ` <20120413150518.GA1987@us.ibm.com>
2012-04-13 15:42   ` Jeff Layton
2012-04-13 16:07     ` Steve Dickson
2012-04-13 17:10       ` Jeff Layton
2012-04-13 17:34       ` Peter Staubach
2012-04-13 23:00         ` Jeff Layton
2012-04-14  0:57         ` Trond Myklebust
2012-04-15 19:03     ` Bernd Schubert
2012-04-15 19:27       ` J. Bruce Fields
2012-04-16 14:23         ` Bernd Schubert
2012-04-15 19:57       ` Chuck Lever
2012-04-16 11:23         ` Jeff Layton
2012-04-17 11:53         ` Steve Dickson
2012-04-16 11:36       ` Jeff Layton
2012-04-16 12:54         ` Peter Staubach
2012-04-16 16:04           ` Jeff Layton
2012-04-16 14:44         ` Bernd Schubert
2012-04-16 17:46           ` Jeff Layton
2012-04-16 19:33             ` Myklebust, Trond
2012-04-16 19:43               ` Jeff Layton
2012-04-16 20:25                 ` Myklebust, Trond
2012-04-16 23:05                   ` Jeff Layton
2012-04-17 11:46                     ` Steve Dickson
2012-04-17 13:36                       ` Jeff Layton
2012-04-17 14:14                         ` Steve Dickson
2012-04-17 14:27                           ` Miklos Szeredi
2012-04-17 15:02                             ` Jeff Layton
2012-04-17 15:50                               ` Miklos Szeredi
2012-04-17 16:03                                 ` Jeff Layton
2012-04-17 15:59                               ` Steve Dickson
2012-04-17 13:12                     ` Miklos Szeredi
2012-04-17 13:32                       ` Jeff Layton
2012-04-17 14:03                         ` Miklos Szeredi
2012-04-17 14:22                           ` Jeff Layton
2012-04-17 14:04                         ` Myklebust, Trond
2012-04-17 14:20                           ` Jeff Layton
2012-04-17 15:45                             ` J. Bruce Fields
2012-04-17 16:02                               ` Miklos Szeredi
2012-04-17 13:39                     ` Peter Staubach
2012-04-17 14:08                       ` Myklebust, Trond
2012-04-17 14:48                         ` Peter Staubach
2012-04-18 15:16                           ` Jeff Layton
2012-04-16 19:43             ` Scott Lovenberg
2012-04-16 16:55 ` [PATCH RFC v2] " Jeff Layton
2012-04-18 11:52 ` [PATCH RFC v3] vfs: make fstatat retry once " Jeff Layton
2012-04-20 14:40   ` Jeff Layton
2012-04-20 20:18     ` Steve Dickson
2012-04-20 20:37       ` Malahal Naineni
2012-04-20 21:13         ` Jeff Layton
2012-04-22  5:40           ` Miklos Szeredi
2012-04-23 12:00             ` Jeff Layton
2012-04-23 13:00               ` J. Bruce Fields
2012-04-23 13:12                 ` Jeff Layton
2012-04-23 13:34                   ` J. Bruce Fields
2012-04-23 13:50                     ` Jeff Layton
2012-04-23 13:54                       ` J. Bruce Fields
2012-04-23 14:51                         ` Miklos Szeredi
2012-04-23 15:02                           ` Chuck Lever
2012-04-23 15:23                             ` Miklos Szeredi
2012-04-23 17:45                               ` Peter Staubach
2012-04-23 15:16                           ` Jeff Layton
2012-04-23 15:28                             ` Miklos Szeredi
2012-04-23 18:59                               ` Jeff Layton [this message]
2012-04-20 21:13       ` Jeff Layton
2012-04-23 14:55         ` Steve Dickson
2012-04-23 15:32           ` Jeff Layton
2012-04-23 18:06             ` Steve Dickson
2012-04-23 18:33               ` Jeff Layton
2012-04-23 20:38               ` Peter Staubach
2012-04-24 14:50                 ` Jeff Layton
2012-04-24 15:54                   ` Miklos Szeredi
2012-04-24 16:34                     ` Jeff Layton
2012-04-25  9:41                       ` Miklos Szeredi
2012-04-25 12:04                         ` Jeff Layton
2012-04-23 17:43           ` Peter Staubach
2012-04-23 19:06           ` Malahal Naineni
2012-04-22  4:16     ` Ric Wheeler
2012-04-23 11:20       ` Jeff Layton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120423145935.141cfe0b@tlielax.poochiereds.net \
    --to=jlayton@redhat.com \
    --cc=SteveD@redhat.com \
    --cc=bfields@fieldses.org \
    --cc=chuck.lever@oracle.com \
    --cc=hch@infradead.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=malahal@us.ibm.com \
    --cc=michael.brantley@deshaw.com \
    --cc=miklos@szeredi.hu \
    --cc=pstaubach@exagrid.com \
    --cc=rees@umich.edu \
    --cc=sven.breuner@itwm.fraunhofer.de \
    --cc=trond.myklebust@fys.uio.no \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®