Skip to contentSkip to conversation

NFSv4.2: fix COPY attrs in presence of delegated timestamps

PATCH Superseded Olga Kornievskaia 4 participants 5 messages Mar 27 – Apr 13

Subsystems (2)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Olga Kornievskaia

author reviewer
#0 lore raw

PATCH 1/1 NFSv4.2: fix COPY attrs in presence of delegated timestamps

A similar to generic/407 test can be done with a COPY operation instead of CLONE (reflink). And it leads to same problem that ctime and mtime saved before doing a "cp" operation are the same as after.

---
 fs/nfs/nfs42proc.c | 6 ++++++
 1 file changed, 6 insertions(+)
fs/nfs/nfs42proc.c +6 -0
index f77372a78be7..ea420dc94875 100644
@@ -502,6 +502,12 @@ static ssize_t _nfs42_proc_copy(struct file *src,
 
 	nfs42_copy_dest_done(dst, pos_dst, res->write_res.count, oldsize_dst);
 	nfs_invalidate_atime(src_inode);
+	if (nfs_have_delegated_attributes(dst_inode)) {
+		nfs_update_delegated_mtime(dst_inode);
+		spin_lock(&dst_inode->i_lock);
+		nfs_set_cache_invalid(dst_inode, NFS_INO_INVALID_BLOCKS);
+		spin_unlock(&dst_inode->i_lock);
+	}
 	status = res->write_res.count;
 out:
 	if (args->sync)
Signature · 1 line
2.52.0
#1 lore raw
Quoted 4 lines · Olga Kornievskaia

A similar to generic/407 test can be done with a COPY operation instead of CLONE (reflink). And it leads to same problem that ctime and mtime saved before doing a "cp" operation are the same as after.

Some extra comments here.

Currently the COPY compound does not add a GETATTR after the COPY. Jeff's solution to REMOVEXATTR not updating ctime was to add GETATTR to the compound and then call update attributes. This could be the alternative solution here instead. I'm not sure such an approach would be preferred. But then there is a question of whether or not the server does update its attributes on COPY.

Quoted 26 lines
---
 fs/nfs/nfs42proc.c | 6 ++++++
 1 file changed, 6 insertions(+)
fs/nfs/nfs42proc.c +6 -1
index f77372a78be7..ea420dc94875 100644
@@ -502,6 +502,12 @@ static ssize_t _nfs42_proc_copy(struct file *src,
 
        nfs42_copy_dest_done(dst, pos_dst, res->write_res.count, oldsize_dst);
        nfs_invalidate_atime(src_inode);
+       if (nfs_have_delegated_attributes(dst_inode)) {
+               nfs_update_delegated_mtime(dst_inode);
+               spin_lock(&dst_inode->i_lock);
+               nfs_set_cache_invalid(dst_inode, NFS_INO_INVALID_BLOCKS);
+               spin_unlock(&dst_inode->i_lock);
+       }
        status = res->write_res.count;
 out:
        if (args->sync)
--

2.52.0

maintainer
#2 lore raw
Quoted 6 lines · Olga Kornievskaia
Quoted 4 lines · Olga Kornievskaia

A similar to generic/407 test can be done with a COPY operation instead of CLONE (reflink). And it leads to same problem that ctime and mtime saved before doing a "cp" operation are the same as after.

Quoted 9 lines

Some extra comments here.

Currently the COPY compound does not add a GETATTR after the COPY. Jeff's solution to REMOVEXATTR not updating ctime was to add GETATTR to the compound and then call update attributes. This could be the alternative solution here instead. I'm not sure such an approach would be preferred. But then there is a question of whether or not the server does update its attributes on COPY.

I think that'd ultimately be more efficient, and I think the server should be updating the c/mtime on COPY, even if there is an outstanding timestamp delegation. The server is doing the COPY. The client isn't really involved so why should it be trying to stamp the file?

A GETATTR is cheap and in this case, the inode will even likely be in cache on the server. We might as well update the attributes without forcing another round trip in this case, since we pretty much know that they will have changed.

If the server isn't updating its attrs on COPY in this case, then it's probably because we're using the open file description in the destination stateid and it has FMODE_NOCMTIME set. We can probably fix this by just turning that flag off while the copy is running, and then reenabling it before returning.

Quoted 26 lines
Quoted 26 lines
---
 fs/nfs/nfs42proc.c | 6 ++++++
 1 file changed, 6 insertions(+)
fs/nfs/nfs42proc.c +6 -1
index f77372a78be7..ea420dc94875 100644
@@ -502,6 +502,12 @@ static ssize_t _nfs42_proc_copy(struct file *src,
 
        nfs42_copy_dest_done(dst, pos_dst, res->write_res.count, oldsize_dst);
        nfs_invalidate_atime(src_inode);
+       if (nfs_have_delegated_attributes(dst_inode)) {
+               nfs_update_delegated_mtime(dst_inode);
+               spin_lock(&dst_inode->i_lock);
+               nfs_set_cache_invalid(dst_inode, NFS_INO_INVALID_BLOCKS);
+               spin_unlock(&dst_inode->i_lock);
+       }
        status = res->write_res.count;
 out:
        if (args->sync)
--

2.52.0

Signature · 1 line
Jeff Layton <[email protected]>
#3 lore raw
In reply to Olga Kornievskaia
Quoted 6 lines · Olga Kornievskaia

A similar to generic/407 test can be done with a COPY operation instead of CLONE (reflink). And it leads to same problem that ctime and mtime saved before doing a "cp" operation are the same as after.

This patch isn't needed if the server updates mtime/ctime after doing a COPY.

In the process of all the work, I have also created a patch that adds a GETATTR to the COPY compound. I'm not sure if it's needed or not but I can post it.

Quoted 25 lines
---
 fs/nfs/nfs42proc.c | 6 ++++++
 1 file changed, 6 insertions(+)
fs/nfs/nfs42proc.c +6 -1
index f77372a78be7..ea420dc94875 100644
@@ -502,6 +502,12 @@ static ssize_t _nfs42_proc_copy(struct file *src,
 
        nfs42_copy_dest_done(dst, pos_dst, res->write_res.count, oldsize_dst);
        nfs_invalidate_atime(src_inode);
+       if (nfs_have_delegated_attributes(dst_inode)) {
+               nfs_update_delegated_mtime(dst_inode);
+               spin_lock(&dst_inode->i_lock);
+               nfs_set_cache_invalid(dst_inode, NFS_INO_INVALID_BLOCKS);
+               spin_unlock(&dst_inode->i_lock);
+       }
        status = res->write_res.count;
 out:
        if (args->sync)
--

2.52.0

maintainer
#4 lore raw
In reply to Olga Kornievskaia
Quoted 24 lines · Olga Kornievskaia

A similar to generic/407 test can be done with a COPY operation instead of CLONE (reflink). And it leads to same problem that ctime and mtime saved before doing a "cp" operation are the same as after.

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

 1 file changed, 6 insertions(+)
fs/nfs/nfs42proc.c +0 -0
index f77372a78be7..ea420dc94875 100644
@@ -502,6 +502,12 @@ static ssize_t _nfs42_proc_copy(struct file
 *src,


  nfs42_copy_dest_done(dst, pos_dst, res->write_res.count, oldsize_dst);
  nfs_invalidate_atime(src_inode);

fs/nfs/nfs42proc.c +4 -0
+	if (nfs_have_delegated_attributes(dst_inode)) {
+		nfs_update_delegated_mtime(dst_inode);
+		spin_lock(&dst_inode->i_lock);
+		nfs_set_cache_invalid(dst_inode,

NFS_INO_INVALID_BLOCKS);

fs/nfs/nfs42proc.c static ssize_t _nfs42_proc_copy(struct file *src, · line 509

Quoted 1 line
fs/nfs/nfs42proc.c +1 -0
+		spin_unlock(&dst_inode->i_lock);

Isn't NFS_INO_INVALID_BLOCKS already set it nfs42_copy_dest_done()?

Quoted 4 lines
fs/nfs/nfs42proc.c +1 -0
+	}

  status = res->write_res.count;
 out:
  if (args->sync)

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