Skip to contentSkip to conversation

nfsd update mtime/ctime on CLONE/COPY with delegated attritutes

PATCH Superseded Olga Kornievskaia 3 participants 7 messages Apr 8 – Apr 9

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Olga Kornievskaia

author reviewer
#0 lore raw

v2 cover nfsd update mtime/ctime on CLONE/COPY with delegated attritutes

generic/407 is failing in presence of delegated attributes and this patch series explores the solution where the CLONE compound returns updated mtime/ctime in the GETATTR op in the compound.

It's broken into several pieces as I consider asynchronous copy update the trickest because the copy thread currently have no dentry to call notify_change() on. And if we are going to keep a copy of it while the copy is running we probably need to take a reference on it (which I attempt to do).

-- Changes
v2:
patch1: added ATTR_DELEG and doing update if status is successful
patch2: doing update if we copied positive number of bytes copied
patch3: dput on error is done based on non-null d_dst, update is done before callback call and if positive number of bytes copied

Olga Kornievskaia (3):
nfsd: update mtime/ctime on CLONE in presense of delegated attributes
nfsd: update mtime/ctime on synchronous COPY with delegated attributes
nfsd: update mtime/ctime on asynchronous COPY with delegated
attributes

 fs/nfsd/nfs4proc.c | 41 +++++++++++++++++++++++++++++++++++++++--
 fs/nfsd/xdr4.h     |  1 +
 2 files changed, 40 insertions(+), 2 deletions(-)
Signature · 1 line
2.52.0
author reviewer
#1 lore raw

PATCH v2 1/3 nfsd: update mtime/ctime on CLONE in presense of delegated attributes

When delegated attributes are given on open, the file is opened with NOCMTIME and modifying operations do not update mtime/ctime as to not get out-of-sync with the client's delegated view. However, for CLONE operation, the server should update its view of mtime/ctime and reflect that in any GETATTR queries.

Fixes e5e9b24ab8fa ("nfsd: freeze c/mtime updates with outstanding WRITE_ATTRS delegation")
---
 fs/nfsd/nfs4proc.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
fs/nfsd/nfs4proc.c +14 -0
index 99b44b6ec056..1272f2eb5ff4 100644
@@ -1396,6 +1396,17 @@ nfsd4_verify_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 	goto out;
 }
 
+static void nfsd_update_cmtime_attr(struct dentry *dentry)
+{
+	struct iattr attr = {
+		.ia_valid = ATTR_CTIME | ATTR_MTIME | ATTR_DELEG,
+	};
+
+	inode_lock(d_inode(dentry));
+	notify_change(&nop_mnt_idmap, dentry, &attr, NULL);
+	inode_unlock(d_inode(dentry));
+}
+
 static __be32
 nfsd4_clone(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 		union nfsd4_op_u *u)
@@ -1413,6 +1424,9 @@ nfsd4_clone(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 			dst, clone->cl_dst_pos, clone->cl_count,
 			EX_ISSYNC(cstate->current_fh.fh_export));
 
+	if ((READ_ONCE(dst->nf_file->f_mode) & FMODE_NOCMTIME) != 0 && !status)
+		nfsd_update_cmtime_attr(cstate->current_fh.fh_dentry);
+
 	nfsd_file_put(dst);
 	nfsd_file_put(src);
 out:
Signature · 1 line
2.52.0
maintainer
#2 lore raw

Re: [PATCH v2 1/3] nfsd: update mtime/ctime on CLONE in presense of delegated attributes

Quoted 9 lines · Olga Kornievskaia

When delegated attributes are given on open, the file is opened with NOCMTIME and modifying operations do not update mtime/ctime as to not get out-of-sync with the client's delegated view. However, for CLONE operation, the server should update its view of mtime/ctime and reflect that in any GETATTR queries.

Fixes e5e9b24ab8fa ("nfsd: freeze c/mtime updates with outstanding

WRITE_ATTRS delegation")

b/fs/nfsd/nfs4proc.c

Quoted 8 lines

index 99b44b6ec056..1272f2eb5ff4 100644

fs/nfsd/nfs4proc.c +0 -0
@@ -1396,6 +1396,17 @@ nfsd4_verify_copy(struct svc_rqst *rqstp, struct 
 nfsd4_compound_state *cstate,
 	goto out;
 }
 

fs/nfsd/nfs4proc.c nfsd4_verify_copy(struct svc_rqst *rqstp, struct · line 1409

Quoted 10 lines
fs/nfsd/nfs4proc.c +10 -0
+static void nfsd_update_cmtime_attr(struct dentry *dentry)
+{
+	struct iattr attr = {
+		.ia_valid = ATTR_CTIME | ATTR_MTIME | ATTR_DELEG,
+	};
+
+	inode_lock(d_inode(dentry));
+	notify_change(&nop_mnt_idmap, dentry, &attr, NULL);
+	inode_unlock(d_inode(dentry));
+}

nfsd4_finalize_deleg_timestamps() invokes the same call and logs failures. notify_change() can fail through security_inode_setattr() or the filesystem's ->setattr method. Is it worth logging the failure (or adding a trace point)? (I don't really know, just asking here).

Signature · 1 line
Chuck Lever
#3 lore raw

Re: [PATCH v2 1/3] nfsd: update mtime/ctime on CLONE in presense of delegated attributes

Quoted 22 lines · Chuck Lever
Quoted 9 lines · Olga Kornievskaia

When delegated attributes are given on open, the file is opened with NOCMTIME and modifying operations do not update mtime/ctime as to not get out-of-sync with the client's delegated view. However, for CLONE operation, the server should update its view of mtime/ctime and reflect that in any GETATTR queries.

Fixes e5e9b24ab8fa ("nfsd: freeze c/mtime updates with outstanding

WRITE_ATTRS delegation")

b/fs/nfsd/nfs4proc.c

Quoted 8 lines

index 99b44b6ec056..1272f2eb5ff4 100644

fs/nfsd/nfs4proc.c +0 -0
@@ -1396,6 +1396,17 @@ nfsd4_verify_copy(struct svc_rqst *rqstp, struct
 nfsd4_compound_state *cstate,
      goto out;
 }
 
Quoted 16 lines

fs/nfsd/nfs4proc.c nfsd4_verify_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · line 1408

Quoted 10 lines
fs/nfsd/nfs4proc.c +10 -0
+static void nfsd_update_cmtime_attr(struct dentry *dentry)
+{
+     struct iattr attr = {
+             .ia_valid = ATTR_CTIME | ATTR_MTIME | ATTR_DELEG,
+     };
+
+     inode_lock(d_inode(dentry));
+     notify_change(&nop_mnt_idmap, dentry, &attr, NULL);
+     inode_unlock(d_inode(dentry));
+}

nfsd4_finalize_deleg_timestamps() invokes the same call and logs failures. notify_change() can fail through security_inode_setattr() or the filesystem's ->setattr method. Is it worth logging the failure (or adding a trace point)? (I don't really know, just asking here).

Well, I'm now thinking of stripping out that piece that calls notify_change() in nfsd4_finalize_deleg_timestamps() into its own function and call it from both places?

Now that I see that nfsd4_finalize_deleg_timestamps() gets a dentry from file->fh_path.dentry, I'm thinking I don't need to save a dentry in the copy case and get it from copy->nf_dst->nf_file->fh_path.dentry? I'm assuming then I no longer need to dget/dput then?

Quoted 6 lines

--
Chuck Lever

author reviewer
#4 lore raw

PATCH v2 2/3 nfsd: update mtime/ctime on synchronous COPY with delegated attributes

In reply to Olga Kornievskaia

COPY should update destination file's mtime/ctime upon completion.

Fixes e5e9b24ab8fa ("nfsd: freeze c/mtime updates with outstanding WRITE_ATTRS delegation")
---
 fs/nfsd/nfs4proc.c | 4 ++++
 1 file changed, 4 insertions(+)
fs/nfsd/nfs4proc.c +4 -0
index 1272f2eb5ff4..ac47cddef384 100644
@@ -2211,6 +2211,10 @@ nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 	} else {
 		status = nfsd4_do_copy(copy, copy->nf_src->nf_file,
 				       copy->nf_dst->nf_file, true);
+		if ((READ_ONCE(copy->nf_dst->nf_file->f_mode) &
+			       FMODE_NOCMTIME) != 0 &&
+				copy->cp_res.wr_bytes_written > 0)
+			nfsd_update_cmtime_attr(cstate->current_fh.fh_dentry);
 	}
 out:
 	trace_nfsd_copy_done(copy, status);
Signature · 1 line
2.52.0
author reviewer
#5 lore raw

PATCH v2 3/3 nfsd: update mtime/ctime on asynchronous COPY with delegated attributes

In reply to Olga Kornievskaia

Asynchronous COPY should update destination file's mtime/ctime upon completion of copy work (not COPY compound processing).

Fixes e5e9b24ab8fa ("nfsd: freeze c/mtime updates with outstanding WRITE_ATTRS delegation")
---
 fs/nfsd/nfs4proc.c | 23 +++++++++++++++++++++--
 fs/nfsd/xdr4.h     |  1 +
 2 files changed, 22 insertions(+), 2 deletions(-)
fs/nfsd/nfs4proc.c +21 -2
index ac47cddef384..b6490167e78b 100644
@@ -2132,8 +2132,19 @@ static int nfsd4_do_async_copy(void *data)
 
 	set_bit(NFSD4_COPY_F_COMPLETED, &copy->cp_flags);
 	trace_nfsd_copy_async_done(copy);
-	nfsd4_send_cb_offload(copy);
 	atomic_dec(&copy->cp_nn->pending_async_copies);
+	/*
+	 * choosing to check for existence of set dentry pointer to indicate
+	 * that we need to update the attributes and do a dput because the
+	 * file flag could be cleared by a DELEGRETURN and then we'd lose
+	 * that copy was started with file opened with NOCMTIME and we got
+	 * a reference on the dentry.
+	 */
+	if (copy->d_dst && copy->cp_res.wr_bytes_written > 0) {
+		nfsd_update_cmtime_attr(copy->d_dst);
+		dput(copy->d_dst);
+	}
+	nfsd4_send_cb_offload(copy);
 	return 0;
 }
 
@@ -2193,6 +2204,11 @@ nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 		memcpy(&result->cb_stateid, &copy->cp_stateid.cs_stid,
 			sizeof(result->cb_stateid));
 		dup_copy_fields(copy, async_copy);
+		if ((READ_ONCE(copy->nf_dst->nf_file->f_mode) &
+			       FMODE_NOCMTIME) != 0) {
+			async_copy->d_dst = cstate->current_fh.fh_dentry;
+			dget(cstate->current_fh.fh_dentry);
+		}
 		memcpy(async_copy->cp_cb_offload.co_referring_sessionid.data,
 		       cstate->session->se_sessionid.data,
 		       NFS4_MAX_SESSIONID_LEN);
@@ -2221,8 +2237,11 @@ nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 	release_copy_files(copy);
 	return status;
 out_dec_async_copy_err:
-	if (async_copy)
+	if (async_copy) {
 		atomic_dec(&nn->pending_async_copies);
+		if (async_copy->d_dst)
+			dput(cstate->current_fh.fh_dentry);
+	}
 out_err:
 	if (nfsd4_ssc_is_inter(copy)) {
 		/*
fs/nfsd/xdr4.h +1 -0
index 417e9ad9fbb3..ddd6e005d3cf 100644
@@ -752,6 +752,7 @@ struct nfsd4_copy {
 
 	struct nfsd_file        *nf_src;
 	struct nfsd_file        *nf_dst;
+	struct dentry		*d_dst;
 
 	copy_stateid_t		cp_stateid;
 
Signature · 1 line
2.52.0
maintainer
#6 lore raw

Re: [PATCH v2 3/3] nfsd: update mtime/ctime on asynchronous COPY with delegated attributes

Quoted 21 lines · Olga Kornievskaia

Asynchronous COPY should update destination file's mtime/ctime upon completion of copy work (not COPY compound processing).

Fixes e5e9b24ab8fa ("nfsd: freeze c/mtime updates with outstanding

WRITE_ATTRS delegation")

fs/nfsd/nfs4proc.c +5 -1
index ac47cddef384..b6490167e78b 100644
@@ -2132,8 +2132,19 @@ static int nfsd4_do_async_copy(void *data)
 
 	set_bit(NFSD4_COPY_F_COMPLETED, &copy->cp_flags);
 	trace_nfsd_copy_async_done(copy);
-	nfsd4_send_cb_offload(copy);
 	atomic_dec(&copy->cp_nn->pending_async_copies);
+	/*
+	 * choosing to check for existence of set dentry pointer to indicate
+	 * that we need to update the attributes and do a dput because the
+	 * file flag could be cleared by a DELEGRETURN and then we'd lose
+	 * that copy was started with file opened with NOCMTIME and we got

fs/nfsd/nfs4proc.c static int nfsd4_do_async_copy(void *data) · line 2150

Quoted 10 lines
fs/nfsd/nfs4proc.c +7 -0
+	 * a reference on the dentry.
+	 */
+	if (copy->d_dst && copy->cp_res.wr_bytes_written > 0) {
+		nfsd_update_cmtime_attr(copy->d_dst);
+		dput(copy->d_dst);
+	}
+	nfsd4_send_cb_offload(copy);
 	return 0;
 }
 

There might be another potential dentry reference underflow here.

If the async copy fails before writing any bytes (wr_bytes_written == 0), the dput is skipped but the dget taken in nfsd4_copy() is never released elsewhere.

This might happen when _nfsd_copy_file_range() fails on the first iteration, when nfs42_ssc_open() fails for inter-SSC copies, or when kthread_should_stop() fires before any bytes are copied.

Rearranging the logic a little might avoid the issue:

  if (copy->d_dst) {
      if (copy->cp_res.wr_bytes_written > 0)
          nfsd_update_cmtime_attr(copy->d_dst);
      dput(copy->d_dst);
  }
Signature · 1 line
Chuck Lever