Skip to contentSkip to conversation

Check for link count change when refreshing inode

PATCH Trond Myklebust 1 participant 1 message Mar 9, 2004 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive

På må , 08/03/2004 klokka 21:28, skreiv Shantanu Goel:

Quoted 8 lines

Hi,

The attached patch adds a check for change in link count when refreshing an inode. Otherwise, the following sequence of calls produces an incorrect link count. Such a sequence is used by "gnucash" to lock its data files.

Quoted 6 lines

1. create file "foo" and don't close the descriptor.
2. link("foo", "bar")
3. stat("foo") to retrieve the link count. The stock NFS client returns 1 instead of 2.

The patch is on top of linux-2.6.4-NFS4_ALL.dif.

Hmm... The problem is that nfs_refresh_inode() is only called iff the RPC call returns post_op attributes, whereas you are pointing to a more general problem: that of seeing our own updates as soon as they happen.

Post-op attributes should really only be used for catching updates to the inode that we didn't cause ourselves.

How about the following change instead? It includes your change for catching updates that have been made by third parties, but also ensures that we always see our own updates immediately...

Cheers,
Trond

 inode.c |   19 +++++++++++--------
 write.c |    4 ----
 2 files changed, 11 insertions(+), 12 deletions(-)
fs/nfs/inode.c +11 -8
diff -u --recursive --new-file --show-c-function linux-2.6.4-01-attr.old/fs/nfs/inode.c linux-2.6.4-01-attr/fs/nfs/inode.c
@@ -1053,14 +1053,13 @@ void nfs_end_data_update(struct inode *i
 {
 	struct nfs_inode *nfsi = NFS_I(inode);
 
-	if (atomic_dec_and_test(&nfsi->data_updates)) {
-		nfsi->cache_change_attribute ++;
-		/* Mark the attribute cache for revalidation */
-		nfsi->flags |= NFS_INO_INVALID_ATTR;
-		/* Directories and symlinks: invalidate page cache too */
-		if (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode))
-			nfsi->flags |= NFS_INO_INVALID_DATA;
-	}
+	/* Mark the attribute cache for revalidation */
+	nfsi->flags |= NFS_INO_INVALID_ATTR;
+	/* Directories and symlinks: invalidate page cache too */
+	if (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode))
+		nfsi->flags |= NFS_INO_INVALID_DATA;
+	nfsi->cache_change_attribute ++;
+	atomic_dec(&nfsi->data_updates);
 }
 
 /**
@@ -1122,6 +1121,10 @@ int nfs_refresh_inode(struct inode *inod
 			|| inode->i_gid != fattr->gid)
 		nfsi->flags |= NFS_INO_INVALID_ATTR;
 
+	/* Has the link count changed? */
+	if (inode->i_nlink != fattr->nlink)
+		nfsi->flags |= NFS_INO_INVALID_ATTR;
+
 	if (!timespec_equal(&inode->i_atime, &fattr->atime))
 		nfsi->flags |= NFS_INO_INVALID_ATIME;
 
fs/nfs/write.c +0 -4
diff -u --recursive --new-file --show-c-function linux-2.6.4-01-attr.old/fs/nfs/write.c linux-2.6.4-01-attr/fs/nfs/write.c
@@ -205,7 +205,6 @@ static int nfs_writepage_async(struct fi
 	loff_t		end;
 	int		status;
 
-	nfs_begin_data_update(inode);
 	req = nfs_update_request(file, inode, page, offset, count);
 	status = (IS_ERR(req)) ? PTR_ERR(req) : 0;
 	if (status < 0)
@@ -216,7 +215,6 @@ static int nfs_writepage_async(struct fi
 	if (i_size_read(inode) < end)
 		i_size_write(inode, end);
  out:
-	nfs_end_data_update(inode);
 	return status;
 }
 
@@ -701,7 +699,6 @@ nfs_updatepage(struct file *file, struct
 		return status;
 	}
 
-	nfs_begin_data_update(inode);
 	/*
 	 * Try to find an NFS request corresponding to this page
 	 * and update it.
@@ -735,7 +732,6 @@ nfs_updatepage(struct file *file, struct
 	} else
 		nfs_unlock_request(req);
 done:
-	nfs_end_data_update(inode);
         dprintk("NFS:      nfs_updatepage returns %d (isize %Ld)\n",
 			status, (long long)i_size_read(inode));
 	if (status < 0)