Skip to contentSkip to conversation

NFSv42: Copy offload should update the file size when appropriate

PATCH In review [email protected] 3 participants 7 messages Apr 14, 2021

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH 1/2 NFSv42: Copy offload should update the file size when appropriate

From: Trond Myklebust <[email protected]>

If the result of a copy offload or clone operation is to grow the destination file size, then we should update it. The reason is that when a client holds a delegation, it is authoritative for the file size.

---
 fs/nfs/nfs42proc.c | 41 ++++++++++++++++++++++++++++++++---------
 1 file changed, 32 insertions(+), 9 deletions(-)
fs/nfs/nfs42proc.c +32 -9
index 8d64eb953347..3875120ef3ef 100644
@@ -269,6 +269,33 @@ static int process_copy_commit(struct file *dst, loff_t pos_dst,
 	return status;
 }
 
+/**
+ * nfs42_copy_dest_done - perform inode cache updates after clone/copy offload
+ * @inode: pointer to destination inode
+ * @pos: destination offset
+ * @len: copy length
+ *
+ * Punch a hole in the inode page cache, so that the NFS client will
+ * know to retrieve new data.
+ * Update the file size if necessary, and then mark the inode as having
+ * invalid cached values for change attribute, ctime, mtime and space used.
+ */
+static void nfs42_copy_dest_done(struct inode *inode, loff_t pos, loff_t len)
+{
+	loff_t newsize = pos + len;
+	loff_t end = newsize - 1;
+
+	truncate_pagecache_range(inode, pos, end);
+	spin_lock(&inode->i_lock);
+	if (newsize > i_size_read(inode))
+		i_size_write(inode, newsize);
+	nfs_set_cache_invalid(inode, NFS_INO_INVALID_CHANGE |
+					     NFS_INO_INVALID_CTIME |
+					     NFS_INO_INVALID_MTIME |
+					     NFS_INO_INVALID_BLOCKS);
+	spin_unlock(&inode->i_lock);
+}
+
 static ssize_t _nfs42_proc_copy(struct file *src,
 				struct nfs_lock_context *src_lock,
 				struct file *dst,
@@ -362,14 +389,8 @@ static ssize_t _nfs42_proc_copy(struct file *src,
 			goto out;
 	}
 
-	truncate_pagecache_range(dst_inode, pos_dst,
-				 pos_dst + res->write_res.count);
-	spin_lock(&dst_inode->i_lock);
-	nfs_set_cache_invalid(
-		dst_inode, NFS_INO_REVAL_PAGECACHE | NFS_INO_REVAL_FORCED |
-				   NFS_INO_INVALID_SIZE | NFS_INO_INVALID_ATTR |
-				   NFS_INO_INVALID_DATA);
-	spin_unlock(&dst_inode->i_lock);
+	nfs42_copy_dest_done(dst_inode, pos_dst, res->write_res.count);
+
 	spin_lock(&src_inode->i_lock);
 	nfs_set_cache_invalid(src_inode, NFS_INO_REVAL_PAGECACHE |
 						 NFS_INO_REVAL_FORCED |
@@ -1055,8 +1076,10 @@ static int _nfs42_proc_clone(struct rpc_message *msg, struct file *src_f,
 
 	status = nfs4_call_sync(server->client, server, msg,
 				&args.seq_args, &res.seq_res, 0);
-	if (status == 0)
+	if (status == 0) {
+		nfs42_copy_dest_done(dst_inode, dst_offset, count);
 		status = nfs_post_op_update_inode(dst_inode, res.dst_fattr);
+	}
 
 	kfree(res.dst_fattr);
 	return status;
Signature · 1 line
2.30.2
author maintainer
#1 lore raw

PATCH 2/2 NFSv42: Don't force attribute revalidation of the copy offload source

From: Trond Myklebust <[email protected]>

When a copy offload is performed, we do not expect the source file to change other than perhaps to see the atime be updated.

---
 fs/nfs/nfs42proc.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
fs/nfs/nfs42proc.c +1 -6
index 3875120ef3ef..a24349512ffe 100644
@@ -390,12 +390,7 @@ static ssize_t _nfs42_proc_copy(struct file *src,
 	}
 
 	nfs42_copy_dest_done(dst_inode, pos_dst, res->write_res.count);
-
-	spin_lock(&src_inode->i_lock);
-	nfs_set_cache_invalid(src_inode, NFS_INO_REVAL_PAGECACHE |
-						 NFS_INO_REVAL_FORCED |
-						 NFS_INO_INVALID_ATIME);
-	spin_unlock(&src_inode->i_lock);
+	nfs_invalidate_atime(src_inode);
 	status = res->write_res.count;
 out:
 	if (args->sync)
Signature · 1 line
2.30.2
#2 lore raw

Re: [PATCH 2/2] NFSv42: Don't force attribute revalidation of the copy offload source

Thanks! Testing....

--b.

Quoted 30 lines · On Wed, Apr 14, 2021 at 10:31:38AM -0400, [email protected] wrote:

From: Trond Myklebust <[email protected]>

When a copy offload is performed, we do not expect the source file to change other than perhaps to see the atime be updated.

---
 fs/nfs/nfs42proc.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
fs/nfs/nfs42proc.c +1 -6
index 3875120ef3ef..a24349512ffe 100644
@@ -390,12 +390,7 @@ static ssize_t _nfs42_proc_copy(struct file *src,
 	}
 
 	nfs42_copy_dest_done(dst_inode, pos_dst, res->write_res.count);
-
-	spin_lock(&src_inode->i_lock);
-	nfs_set_cache_invalid(src_inode, NFS_INO_REVAL_PAGECACHE |
-						 NFS_INO_REVAL_FORCED |
-						 NFS_INO_INVALID_ATIME);
-	spin_unlock(&src_inode->i_lock);
+	nfs_invalidate_atime(src_inode);
 	status = res->write_res.count;
 out:
 	if (args->sync)
Signature · 1 line
2.30.2
#3 lore raw

Re: [PATCH 2/2] NFSv42: Don't force attribute revalidation of the copy offload source

Quoted 1 line · bfields

Thanks! Testing....

... and, test results back with these two patches applied, looks good!

--b.

Quoted 34 lines

--b.

Quoted 30 lines · On Wed, Apr 14, 2021 at 10:31:38AM -0400, [email protected] wrote:

From: Trond Myklebust <[email protected]>

When a copy offload is performed, we do not expect the source file to change other than perhaps to see the atime be updated.

---
 fs/nfs/nfs42proc.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
fs/nfs/nfs42proc.c +1 -6
index 3875120ef3ef..a24349512ffe 100644
@@ -390,12 +390,7 @@ static ssize_t _nfs42_proc_copy(struct file *src,
 	}
 
 	nfs42_copy_dest_done(dst_inode, pos_dst, res->write_res.count);
-
-	spin_lock(&src_inode->i_lock);
-	nfs_set_cache_invalid(src_inode, NFS_INO_REVAL_PAGECACHE |
-						 NFS_INO_REVAL_FORCED |
-						 NFS_INO_INVALID_ATIME);
-	spin_unlock(&src_inode->i_lock);
+	nfs_invalidate_atime(src_inode);
 	status = res->write_res.count;
 out:
 	if (args->sync)
Signature · 1 line
2.30.2
#4 lore raw

Re: [PATCH 2/2] NFSv42: Don't force attribute revalidation of the copy offload source

Quoted 5 lines · J. Bruce Fields
Quoted 1 line · bfields

Thanks!  Testing....

... and, test results back with these two patches applied, looks good!

So, just out of curiosity. With which backing filesystem were you testing? If it was XFS, then note that you may have been testing the CLONE functionality instead of copy offload. As you saw, I added the same fix for both clone and copy offload because they have the same requirements for how the page and attribute caches are handled, so the end result should be the same. However the unpatched code is very different for the two methods, and clone may have been missing more functionality than the actual copy-offload was.

Quoted 43 lines

--b.

Quoted 40 lines

--b.

Quoted 36 lines · On Wed, Apr 14, 2021 at 10:31:38AM -0400, [email protected] wrote:

From: Trond Myklebust <[email protected]>

When a copy offload is performed, we do not expect the source file to
change other than perhaps to see the atime be updated.

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

 1 file changed, 1 insertion(+), 6 deletions(-)
fs/nfs/nfs42proc.c +0 -0
index 3875120ef3ef..a24349512ffe 100644
@@ -390,12 +390,7 @@ static ssize_t _nfs42_proc_copy(struct file
 *src,
         }


        nfs42_copy_dest_done(dst_inode, pos_dst, res-

Quoted 1 line

write_res.count);

-
-       spin_lock(&src_inode->i_lock);
-       nfs_set_cache_invalid(src_inode, NFS_INO_REVAL_PAGECACHE |
-
NFS_INO_REVAL_FORCED |
-
NFS_INO_INVALID_ATIME);
-       spin_unlock(&src_inode->i_lock);
+       nfs_invalidate_atime(src_inode);
        status = res->write_res.count;
 out:
        if (args->sync)

Signature · 1 line
2.30.2
Signature · 3 lines
Trond Myklebust
Linux NFS client maintainer, Hammerspace
[email protected]
#5 lore raw

Re: [PATCH 2/2] NFSv42: Don't force attribute revalidation of the copy offload source

Quoted 7 lines · Trond Myklebust
Quoted 5 lines · J. Bruce Fields
Quoted 1 line · bfields

Thanks!  Testing....

... and, test results back with these two patches applied, looks good!

Quoted 8 lines

So, just out of curiosity. With which backing filesystem were you testing? If it was XFS, then note that you may have been testing the CLONE functionality instead of copy offload. As you saw, I added the same fix for both clone and copy offload because they have the same requirements for how the page and attribute caches are handled, so the end result should be the same. However the unpatched code is very different for the two methods, and clone may have been missing more functionality than the actual copy-offload was.

I think it was actually xfs, but I did look at a trace and my memory is it was trying a CLONE and falling back on COPY. I'll double check....

--b.

Quoted 51 lines
Quoted 44 lines

--b.

Quoted 40 lines

--b.

Quoted 36 lines · On Wed, Apr 14, 2021 at 10:31:38AM -0400, [email protected] wrote:

From: Trond Myklebust <[email protected]>

When a copy offload is performed, we do not expect the source file to
change other than perhaps to see the atime be updated.

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

 1 file changed, 1 insertion(+), 6 deletions(-)
fs/nfs/nfs42proc.c +0 -0
index 3875120ef3ef..a24349512ffe 100644
@@ -390,12 +390,7 @@ static ssize_t _nfs42_proc_copy(struct file
 *src,
         }


        nfs42_copy_dest_done(dst_inode, pos_dst, res-

Quoted 1 line

write_res.count);

-
-       spin_lock(&src_inode->i_lock);
-       nfs_set_cache_invalid(src_inode, NFS_INO_REVAL_PAGECACHE |
-
NFS_INO_REVAL_FORCED |
-
NFS_INO_INVALID_ATIME);
-       spin_unlock(&src_inode->i_lock);
+       nfs_invalidate_atime(src_inode);
        status = res->write_res.count;
 out:
        if (args->sync)

Signature · 1 line
2.30.2
Signature · 3 lines
Trond Myklebust
Linux NFS client maintainer, Hammerspace
[email protected]
#6 lore raw

Re: [PATCH 2/2] NFSv42: Don't force attribute revalidation of the copy offload source

Quoted 17 lines · On Wed, Apr 14, 2021 at 01:28:25PM -0400, [email protected] wrote:
Quoted 7 lines · Trond Myklebust
Quoted 5 lines · J. Bruce Fields
Quoted 1 line · bfields

Thanks!  Testing....

... and, test results back with these two patches applied, looks good!

Quoted 8 lines

So, just out of curiosity. With which backing filesystem were you testing? If it was XFS, then note that you may have been testing the CLONE functionality instead of copy offload. As you saw, I added the same fix for both clone and copy offload because they have the same requirements for how the page and attribute caches are handled, so the end result should be the same. However the unpatched code is very different for the two methods, and clone may have been missing more functionality than the actual copy-offload was.

Quoted 2 lines

I think it was actually xfs, but I did look at a trace and my memory is it was trying a CLONE and falling back on COPY. I'll double check....

Yes, confirmed. At least on my test server's distro (Fedora 28) xfs doesn't seem to be enabling it by default. I recreated the filesystems with "mkfs.xfs -f -mreflink=1 /dev/vdf" and generic/430 is still passing with your patches.

--b.

Quoted 54 lines

--b.

Quoted 51 lines
Quoted 44 lines

--b.

Quoted 40 lines

--b.

Quoted 36 lines · On Wed, Apr 14, 2021 at 10:31:38AM -0400, [email protected] wrote:

From: Trond Myklebust <[email protected]>

When a copy offload is performed, we do not expect the source file to
change other than perhaps to see the atime be updated.

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

 1 file changed, 1 insertion(+), 6 deletions(-)
fs/nfs/nfs42proc.c +0 -0
index 3875120ef3ef..a24349512ffe 100644
@@ -390,12 +390,7 @@ static ssize_t _nfs42_proc_copy(struct file
 *src,
         }


        nfs42_copy_dest_done(dst_inode, pos_dst, res-

Quoted 1 line

write_res.count);

-
-       spin_lock(&src_inode->i_lock);
-       nfs_set_cache_invalid(src_inode, NFS_INO_REVAL_PAGECACHE |
-
NFS_INO_REVAL_FORCED |
-
NFS_INO_INVALID_ATIME);
-       spin_unlock(&src_inode->i_lock);
+       nfs_invalidate_atime(src_inode);
        status = res->write_res.count;
 out:
        if (args->sync)

Signature · 1 line
2.30.2
Signature · 3 lines
Trond Myklebust
Linux NFS client maintainer, Hammerspace
[email protected]