Skip to contentSkip to conversation

NFS: Optimise away the close-to-open getattr if there is no cached data

PATCH In review Trond Myklebust 2 participants 3 messages Sep 4, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 NFS: Optimise away the close-to-open getattr if there is no cached data

If there is no cached data, then there is no need to track the file change attribute on close.

---
 fs/nfs/inode.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
fs/nfs/inode.c +10 -3
index 99a68bd9c178..6307d8de103d 100644
@@ -761,11 +761,13 @@ EXPORT_SYMBOL_GPL(nfs_put_lock_context);
  * @ctx: pointer to context
  * @is_sync: is this a synchronous close
  *
- * always ensure that the attributes are up to date if we're mounted
- * with close-to-open semantics
+ * Ensure that the attributes are up to date if we're mounted
+ * with close-to-open semantics and we have cached data that will
+ * need to be revalidated on open.
  */
 void nfs_close_context(struct nfs_open_context *ctx, int is_sync)
 {
+	struct nfs_inode *nfsi;
 	struct inode *inode;
 	struct nfs_server *server;
 
@@ -774,7 +776,12 @@ void nfs_close_context(struct nfs_open_context *ctx, int is_sync)
 	if (!is_sync)
 		return;
 	inode = d_inode(ctx->dentry);
-	if (!list_empty(&NFS_I(inode)->open_files))
+	nfsi = NFS_I(inode);
+	if (inode->i_mapping->nrpages == 0)
+		return;
+	if (nfsi->cache_validity & NFS_INO_INVALID_DATA)
+		return;
+	if (!list_empty(&nfsi->open_files))
 		return;
 	server = NFS_SERVER(inode);
 	if (server->flags & NFS_MOUNT_NOCTO)
Signature · 1 line
2.4.3
#1 lore raw

PATCH v2 2/2 Revert "NFS: Make close(2) asynchronous when closing NFS O_DIRECT files"

This reverts commit f895c53f8ace3c3e49ebf9def90e63fc6d46d2bf.

This commit causes a NFSv4 regression in that close()+unlink() can end up failing. The reason is that we no longer have a guarantee that the CLOSE has completed on the server, meaning that the subsequent call to REMOVE may fail with NFS4ERR_FILE_OPEN if the server implements Windows unlink() semantics.

Reported-by <Olga Kornievskaia <[email protected]>
Cc Chuck Lever <[email protected]>
---
 fs/nfs/inode.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
fs/nfs/inode.c +6 -1
index 6307d8de103d..326d9e10d833 100644
@@ -853,6 +853,11 @@ void put_nfs_open_context(struct nfs_open_context *ctx)
 }
 EXPORT_SYMBOL_GPL(put_nfs_open_context);
 
+static void put_nfs_open_context_sync(struct nfs_open_context *ctx)
+{
+	__put_nfs_open_context(ctx, 1);
+}
+
 /*
  * Ensure that mmap has a recent RPC credential for use when writing out
  * shared pages
@@ -908,7 +913,7 @@ void nfs_file_clear_open_context(struct file *filp)
 		spin_lock(&inode->i_lock);
 		list_move_tail(&ctx->list, &NFS_I(inode)->open_files);
 		spin_unlock(&inode->i_lock);
-		__put_nfs_open_context(ctx, filp->f_flags & O_DIRECT ? 0 : 1);
+		put_nfs_open_context_sync(ctx);
 	}
 }
 
Signature · 1 line
2.4.3
Reviewed-by on v2 2/2
#2 lore raw

Re: [PATCH v2 2/2] Revert "NFS: Make close(2) asynchronous when closing NFS O_DIRECT files"

Quoted 10 lines · Trond Myklebust

This reverts commit f895c53f8ace3c3e49ebf9def90e63fc6d46d2bf.

This commit causes a NFSv4 regression in that close()+unlink() can end up failing. The reason is that we no longer have a guarantee that the CLOSE has completed on the server, meaning that the subsequent call to REMOVE may fail with NFS4ERR_FILE_OPEN if the server implements Windows unlink() semantics.

Reported-by <Olga Kornievskaia <[email protected]>
Cc Chuck Lever <[email protected]>

I'm fine with this as long as the current NFSv3 behavior stays the same. I haven't tested, but I believe 1/2 will guarantee that NFSv3 close(2) behavior does not change.

Quoted 33 lines

---
fs/nfs/inode.c | 7 ++++++-

1 file changed, 6 insertions(+), 1 deletion(-)
fs/nfs/inode.c +6 -1
index 6307d8de103d..326d9e10d833 100644
@@ -853,6 +853,11 @@ void put_nfs_open_context(struct nfs_open_context *ctx)
 }
 EXPORT_SYMBOL_GPL(put_nfs_open_context);
 
+static void put_nfs_open_context_sync(struct nfs_open_context *ctx)
+{
+	__put_nfs_open_context(ctx, 1);
+}
+
 /*
 * Ensure that mmap has a recent RPC credential for use when writing out
 * shared pages
@@ -908,7 +913,7 @@ void nfs_file_clear_open_context(struct file *filp)
 		spin_lock(&inode->i_lock);
 		list_move_tail(&ctx->list, &NFS_I(inode)->open_files);
 		spin_unlock(&inode->i_lock);
-		__put_nfs_open_context(ctx, filp->f_flags & O_DIRECT ? 0 : 1);
+		put_nfs_open_context_sync(ctx);
 	}
 }
 
Signature · 1 line
2.4.3

--
Chuck Lever