Linux NFS development
 help / color / mirror / Atom feed
From: Steve Dickson <SteveD@redhat.com>
To: Trond Myklebust <trond.myklebust@fys.uio.no>
Cc: nfs@lists.sourceforge.net
Subject: Re: [PATCH]  Reinstantiating stale inodes
Date: Fri, 23 Apr 2004 15:14:03 -0400	[thread overview]
Message-ID: <40896AFB.8040407@RedHat.com> (raw)
In-Reply-To: <1082742547.2617.86.camel@lade.trondhjem.org>

[-- Attachment #1: Type: text/plain, Size: 531 bytes --]

Trond Myklebust wrote:

>You can if and only if
>
>  - The dentry is unhashed, and you are holding the semaphore dir->i_sem
>on the parent directory.
>OR
>  - You are holding the spin lock dcache_lock.
>  
>
I decide to hold the dir->i_sem semaphore since d_drop() needs the
dcache_lock to do the unhashing...

>Note: on 2.6.x, the second condition needs to be modified a bit: you
>probably need to hold dentry->d_lock too since the 2.6.x version of
>d_lookup() is by and large lockless...
>  
>
I'll take a look asaic...

SteveD.

[-- Attachment #2: linux-2.4.21-nfs-estale.patch --]
[-- Type: text/plain, Size: 1834 bytes --]

--- linux-2.4.21/fs/nfs/inode.c.org	2004-04-17 18:26:32.000000000 -0400
+++ linux-2.4.21/fs/nfs/inode.c	2004-04-23 14:44:59.000000000 -0400
@@ -953,13 +953,74 @@ nfs_wait_on_inode(struct inode *inode, i
 }
 
 /*
+ * Reinstantiate an inode that has gone stale
+ */
+static int
+nfs_reinstantiate(
+	struct inode *dir, 
+	struct dentry *dentry, 
+	struct nfs_fattr *fattr)
+{
+	int error;
+	struct nfs_fh fhandle;
+	struct inode *inode;
+
+	/*
+	 * We can only reinstantiate the inode if we are the
+	 * only ones accessing it.
+	 */
+	if (atomic_read(&dentry->d_count) > 1)
+		return EACCES;
+
+	error = NFS_PROTO(dir)->lookup(dir, &dentry->d_name, &fhandle, &fattr);
+	if (!error) {
+		error = -ENOMEM;
+		inode = nfs_fhget(dentry, &fhandle, &fattr);
+		if (inode) {
+			/*
+			 * Check again this time holding the i_sem semaphore
+			 * to make sure we are the only ones accessing this
+			 * dentry
+			 */
+			down(&dir->i_sem);
+			if (atomic_read(&dentry->d_count) < 2) {
+				d_drop(dentry);
+				dput(dentry);
+				d_instantiate(dentry, inode);
+				dentry->d_time = jiffies;
+				error = 0;
+			} else
+				iput(inode);
+			up(&dir->i_sem);
+		}
+	}
+	return error;
+}
+
+/*
  * Externally visible revalidation function
  */
 int
 nfs_revalidate(struct dentry *dentry)
 {
 	struct inode *inode = dentry->d_inode;
-	return nfs_revalidate_inode(NFS_SERVER(inode), inode);
+	struct inode *pinode;
+	struct nfs_fattr fattr;
+	int error;
+
+	error = nfs_revalidate_inode(NFS_SERVER(inode), inode);
+	if (!error || error != -ESTALE)
+		return error;
+	/*
+	 * We have a stale fh so ask the server for another one
+	 */
+	pinode = dentry->d_parent->d_inode;	
+	if (nfs_reinstantiate(pinode, dentry, &fattr) == 0) {
+		inode = dentry->d_inode;
+		if (nfs_refresh_inode(inode, &fattr) == 0)
+			error = 0;
+	}
+	return error;
 }
 
 /*

  reply	other threads:[~2004-04-23 19:14 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-04-23 14:15 [PATCH] Reinstantiating stale inodes Steve Dickson
2004-04-23 14:33 ` Olaf Kirch
2004-04-23 15:50   ` Steve Dickson
2004-04-23 17:55     ` Olaf Kirch
2004-04-23 18:43       ` Steve Dickson
2004-04-23 18:50         ` Olaf Kirch
2004-04-23 20:07           ` Steve Dickson
2004-04-23 14:36 ` Trond Myklebust
2004-04-23 16:01   ` Steve Dickson
2004-04-23 16:21     ` Trond Myklebust
2004-04-23 17:21       ` Steve Dickson
2004-04-23 17:49         ` Trond Myklebust
2004-04-23 19:14           ` Steve Dickson [this message]
     [not found] ` <40892DC0.1010001@redhat.com>
2004-04-23 16:04   ` Steve Dickson
2004-05-01 16:13 ` Steve Dickson
2004-05-01 19:25   ` Trond Myklebust
2004-05-01 23:57     ` Steve Dickson
2004-05-02  0:22       ` Trond Myklebust
2004-05-02  3:19         ` Steve Dickson
2004-05-02  3:28           ` Trond Myklebust
2004-05-03 19:50             ` Steve Dickson
2004-05-03 20:15               ` Trond Myklebust
2004-05-03 20:33                 ` Steve Dickson
2004-05-03 21:27                   ` Trond Myklebust
2004-05-04 19:05                     ` Steve Dickson
2004-05-06 17:39 ` Steve Dickson
  -- strict thread matches above, loose matches on Subject: below --
2004-04-23 14:48 Lever, Charles
2004-04-23 15:00 ` Trond Myklebust
2004-04-23 16:16   ` Steve Dickson
2004-04-23 15:08 ` Olaf Kirch
2004-04-23 15:17 Lever, Charles
2004-04-23 16:16 Lever, Charles
2004-04-23 16:27 ` Steve Dickson

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=40896AFB.8040407@RedHat.com \
    --to=steved@redhat.com \
    --cc=nfs@lists.sourceforge.net \
    --cc=trond.myklebust@fys.uio.no \
    /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