nfsd: update mtime/ctime on CLONE and COPY in presence of delegated attributes
Subsystems (2)
Olga Kornievskaia
reviewerPATCH 1/1 nfsd: update mtime/ctime on CLONE and COPY in presence 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 operations CLONE/COPY server should update its view of mtime/ctime and reflect that in any GETATTR queries.
--- fs/nfsd/nfs4proc.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-)
fs/nfsd/nfs4proc.c +26 -1
@@ -1396,6 +1396,24 @@ nfsd4_verify_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, goto out; } +static bool nfsd4_clear_nocmtime (struct file *f) +{ +if ((READ_ONCE (f->f_mode) &FMODE_NOCMTIME ) !=0 ) { +spin_lock (&f->f_lock); + f->f_mode &= ~FMODE_NOCMTIME ; +spin_unlock (&f->f_lock); +return true; + } +return false; +} + +static void nfsd4_restore_nocmtime (struct file *f) +{ +spin_lock (&f->f_lock); + f->f_mode |=FMODE_NOCMTIME ; +spin_unlock (&f->f_lock); +} +static __be32 nfsd4_clone (struct svc_rqst *rqstp,struct nfsd4_compound_state *cstate,union nfsd4_op_u *u)
@@ -1403,16 +1421,19 @@ nfsd4_clone(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,struct nfsd4_clone *clone = &u->clone;struct nfsd_file *src, *dst;__be32 status; +bool restore_nocmtime = false; status =nfsd4_verify_copy (rqstp, cstate, &clone->cl_src_stateid, &src, &clone->cl_dst_stateid, &dst);if (status) goto out; + restore_nocmtime =nfsd4_clear_nocmtime (dst->nf_file); status =nfsd4_clone_file_range (rqstp, src, clone->cl_src_pos, dst, clone->cl_dst_pos, clone->cl_count,EX_ISSYNC (cstate->current_fh.fh_export)); - +if (restore_nocmtime) +nfsd4_restore_nocmtime (dst->nf_file);nfsd_file_put (dst);nfsd_file_put (src); out:
@@ -2132,6 +2153,7 @@ nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,struct nfsd4_copy *copy = &u->copy;struct nfsd42_write_res *result;__be32 status; +bool restore_nocmtime = false; result = ©->cp_res;nfsd_copy_write_verifier ((__be32 *)&result->wr_verifier.data, nn);
@@ -2157,6 +2179,7 @@ nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, } } + restore_nocmtime =nfsd4_clear_nocmtime (copy->nf_dst->nf_file);memcpy (©->fh, &cstate->current_fh.fh_handle,sizeof (struct knfsd_fh ));if (nfsd4_copy_is_async (copy)) {
@@ -2199,6 +2222,8 @@ nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, copy->nf_dst->nf_file, true); } out: +if (restore_nocmtime) +nfsd4_restore_nocmtime (copy->nf_dst->nf_file);trace_nfsd_copy_done (copy, status);release_copy_files (copy);return status;
Signature · 1 line
2.52.0
Jeff Layton
maintainerQuoted 78 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 operations CLONE/COPY 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")Signed-off-by Olga Kornievskaia <[email protected]>--- fs/nfsd/nfs4proc.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-)fs/nfsd/nfs4proc.c +24
-1@@ -1396,6 +1396,24 @@ nfsd4_verify_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, goto out; } +static bool nfsd4_clear_nocmtime (struct file *f) +{ +if ((READ_ONCE (f->f_mode) &FMODE_NOCMTIME ) !=0 ) { +spin_lock (&f->f_lock); + f->f_mode &= ~FMODE_NOCMTIME ; +spin_unlock (&f->f_lock); +return true; + } +return false; +} + +static void nfsd4_restore_nocmtime (struct file *f) +{ +spin_lock (&f->f_lock); + f->f_mode |=FMODE_NOCMTIME ; +spin_unlock (&f->f_lock); +} +static __be32 nfsd4_clone (struct svc_rqst *rqstp,struct nfsd4_compound_state *cstate,union nfsd4_op_u *u)@@ -1403,16 +1421,19 @@ nfsd4_clone(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,struct nfsd4_clone *clone = &u->clone;struct nfsd_file *src, *dst;__be32 status; +bool restore_nocmtime = false; status =nfsd4_verify_copy (rqstp, cstate, &clone->cl_src_stateid, &src, &clone->cl_dst_stateid, &dst);if (status) goto out; + restore_nocmtime =nfsd4_clear_nocmtime (dst->nf_file); status =nfsd4_clone_file_range (rqstp, src, clone->cl_src_pos, dst, clone->cl_dst_pos, clone->cl_count,EX_ISSYNC (cstate->current_fh.fh_export)); - +if (restore_nocmtime) +nfsd4_restore_nocmtime (dst->nf_file);nfsd_file_put (dst);nfsd_file_put (src); out:@@ -2132,6 +2153,7 @@ nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,struct nfsd4_copy *copy = &u->copy;struct nfsd42_write_res *result;__be32 status; +bool restore_nocmtime = false; result = ©->cp_res;nfsd_copy_write_verifier ((__be32 *)&result->wr_verifier.data, nn);@@ -2157,6 +2179,7 @@ nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, } } + restore_nocmtime =nfsd4_clear_nocmtime (copy->nf_dst->nf_file);memcpy (©->fh, &cstate->current_fh.fh_handle,sizeof (struct knfsd_fh ));if (nfsd4_copy_is_async (copy)) {
fs/nfsd/nfs4proc.c nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · line 2229
Quoted 8 lines
fs/nfsd/nfs4proc.c +2
-0@@ -2199,6 +2222,8 @@ nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, copy->nf_dst->nf_file, true); } out: +if (restore_nocmtime) +nfsd4_restore_nocmtime (copy->nf_dst->nf_file);trace_nfsd_copy_done (copy, status);release_copy_files (copy);return status;
This seems simple enough, but there is some raciness involved if other calls are running concurrently with the COPY/CLONE. You might end up reenabling FMODE_NOCMTIME before a second COPY/CLONE finishes.
A simpler idea might be to just do a notify_change() for ATTR_MTIME after each COPY or CLONE operation done on a file with FMODE_NOCMTIME set.
That should set the timestamp to something pretty close to whatever the last write() would have set it to, but without having to monkey with the fmode.
Signature · 1 line
Jeff Layton <[email protected]>
Quoted 93 lines · Jeff Layton
Quoted 78 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 operations CLONE/COPY 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")Signed-off-by Olga Kornievskaia <[email protected]>--- fs/nfsd/nfs4proc.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-)fs/nfsd/nfs4proc.c +24
-1@@ -1396,6 +1396,24 @@ nfsd4_verify_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, goto out; } +static bool nfsd4_clear_nocmtime (struct file *f) +{ +if ((READ_ONCE (f->f_mode) &FMODE_NOCMTIME ) !=0 ) { +spin_lock (&f->f_lock); + f->f_mode &= ~FMODE_NOCMTIME ; +spin_unlock (&f->f_lock); +return true; + } +return false; +} + +static void nfsd4_restore_nocmtime (struct file *f) +{ +spin_lock (&f->f_lock); + f->f_mode |=FMODE_NOCMTIME ; +spin_unlock (&f->f_lock); +} +static __be32 nfsd4_clone (struct svc_rqst *rqstp,struct nfsd4_compound_state *cstate,union nfsd4_op_u *u)@@ -1403,16 +1421,19 @@ nfsd4_clone(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,struct nfsd4_clone *clone = &u->clone;struct nfsd_file *src, *dst;__be32 status; +bool restore_nocmtime = false; status =nfsd4_verify_copy (rqstp, cstate, &clone->cl_src_stateid, &src, &clone->cl_dst_stateid, &dst);if (status) goto out; + restore_nocmtime =nfsd4_clear_nocmtime (dst->nf_file); status =nfsd4_clone_file_range (rqstp, src, clone->cl_src_pos, dst, clone->cl_dst_pos, clone->cl_count,EX_ISSYNC (cstate->current_fh.fh_export)); - +if (restore_nocmtime) +nfsd4_restore_nocmtime (dst->nf_file);nfsd_file_put (dst);nfsd_file_put (src); out:@@ -2132,6 +2153,7 @@ nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,struct nfsd4_copy *copy = &u->copy;struct nfsd42_write_res *result;__be32 status; +bool restore_nocmtime = false; result = ©->cp_res;nfsd_copy_write_verifier ((__be32 *)&result->wr_verifier.data, nn);@@ -2157,6 +2179,7 @@ nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, } } + restore_nocmtime =nfsd4_clear_nocmtime (copy->nf_dst->nf_file);memcpy (©->fh, &cstate->current_fh.fh_handle,sizeof (struct knfsd_fh ));if (nfsd4_copy_is_async (copy)) {fs/nfsd/nfs4proc.c nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · line 2229
Quoted 8 lines
fs/nfsd/nfs4proc.c +2
-0@@ -2199,6 +2222,8 @@ nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, copy->nf_dst->nf_file, true); } out: +if (restore_nocmtime) +nfsd4_restore_nocmtime (copy->nf_dst->nf_file);trace_nfsd_copy_done (copy, status);release_copy_files (copy);return status;This seems simple enough, but there is some raciness involved if other calls are running concurrently with the COPY/CLONE. You might end up reenabling
FMODE_NOCMTIMEbefore a second COPY/CLONE finishes.
Quoted 7 lines
A simpler idea might be to just do a
notify_change()forATTR_MTIMEafter each COPY or CLONE operation done on a file withFMODE_NOCMTIMEset.That should set the timestamp to something pretty close to whatever the last
write()would have set it to, but without having to monkey with the fmode.
Thanks Jeff and Chuck. I've changed the code to use the notify_change() but before I send out I have a question regarding where you think this notify_change () should take place in case of a copy (specifically thinking about async copy vs sync copy). The easiest option is to do it (regardless of sync or async) upon completion of the COPY compound (ie not at the end of when async copy completes). Or for the async copy should it happen upon (successful) copy completion?
Quoted 3 lines
--
Jeff Layton <[email protected]>
Jeff Layton
maintainerQuoted 102 lines · Olga Kornievskaia
Quoted 93 lines · Jeff Layton
Quoted 78 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 operations CLONE/COPY 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")Signed-off-by Olga Kornievskaia <[email protected]>--- fs/nfsd/nfs4proc.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-)fs/nfsd/nfs4proc.c +24
-1@@ -1396,6 +1396,24 @@ nfsd4_verify_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, goto out; } +static bool nfsd4_clear_nocmtime (struct file *f) +{ +if ((READ_ONCE (f->f_mode) &FMODE_NOCMTIME ) !=0 ) { +spin_lock (&f->f_lock); + f->f_mode &= ~FMODE_NOCMTIME ; +spin_unlock (&f->f_lock); +return true; + } +return false; +} + +static void nfsd4_restore_nocmtime (struct file *f) +{ +spin_lock (&f->f_lock); + f->f_mode |=FMODE_NOCMTIME ; +spin_unlock (&f->f_lock); +} +static __be32 nfsd4_clone (struct svc_rqst *rqstp,struct nfsd4_compound_state *cstate,union nfsd4_op_u *u)@@ -1403,16 +1421,19 @@ nfsd4_clone(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,struct nfsd4_clone *clone = &u->clone;struct nfsd_file *src, *dst;__be32 status; +bool restore_nocmtime = false; status =nfsd4_verify_copy (rqstp, cstate, &clone->cl_src_stateid, &src, &clone->cl_dst_stateid, &dst);if (status) goto out; + restore_nocmtime =nfsd4_clear_nocmtime (dst->nf_file); status =nfsd4_clone_file_range (rqstp, src, clone->cl_src_pos, dst, clone->cl_dst_pos, clone->cl_count,EX_ISSYNC (cstate->current_fh.fh_export)); - +if (restore_nocmtime) +nfsd4_restore_nocmtime (dst->nf_file);nfsd_file_put (dst);nfsd_file_put (src); out:@@ -2132,6 +2153,7 @@ nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,struct nfsd4_copy *copy = &u->copy;struct nfsd42_write_res *result;__be32 status; +bool restore_nocmtime = false; result = ©->cp_res;nfsd_copy_write_verifier ((__be32 *)&result->wr_verifier.data, nn);@@ -2157,6 +2179,7 @@ nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, } } + restore_nocmtime =nfsd4_clear_nocmtime (copy->nf_dst->nf_file);memcpy (©->fh, &cstate->current_fh.fh_handle,sizeof (struct knfsd_fh ));if (nfsd4_copy_is_async (copy)) {fs/nfsd/nfs4proc.c nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · line 2229
Quoted 8 lines
fs/nfsd/nfs4proc.c +2
-0@@ -2199,6 +2222,8 @@ nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, copy->nf_dst->nf_file, true); } out: +if (restore_nocmtime) +nfsd4_restore_nocmtime (copy->nf_dst->nf_file);trace_nfsd_copy_done (copy, status);release_copy_files (copy);return status;This seems simple enough, but there is some raciness involved if other calls are running concurrently with the COPY/CLONE. You might end up reenabling
FMODE_NOCMTIMEbefore a second COPY/CLONE finishes.Quoted 7 lines
A simpler idea might be to just do a
notify_change()forATTR_MTIMEafter each COPY or CLONE operation done on a file withFMODE_NOCMTIMEset.That should set the timestamp to something pretty close to whatever the last
write()would have set it to, but without having to monkey with the fmode.
Quoted 10 lines
Thanks Jeff and Chuck. I've changed the code to use the
notify_change()but before I send out I have a question regarding where you think thisnotify_change() should take place in case of a copy (specifically thinking about async copy vs sync copy). The easiest option is to do it (regardless of sync or async) upon completion of the COPY compound (ie not at the end of when async copy completes). Or for the async copy should it happen upon (successful) copy completion?
I think you want to do it when the copy completes. If that's sync copy then you'd stamp it before you send the COPY reply. For async copy, I think you'd want to do it before sending a CB_OFFLOAD.
Signature · 1 line
Jeff Layton <[email protected]>
Chuck Lever
maintainerQuoted 35 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 operations CLONE/COPY 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_ATTRSdelegation")Signed-off-by Olga Kornievskaia <[email protected]>--- fs/nfsd/nfs4proc.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-)fs/nfsd/nfs4proc.c +1
-0@@ -2157,6 +2179,7 @@ nfsd4_copy(struct svc_rqst *rqstp, structnfsd4_compound_state *cstate, } } + restore_nocmtime =nfsd4_clear_nocmtime (copy->nf_dst->nf_file);memcpy (©->fh, &cstate->current_fh.fh_handle,sizeof (struct knfsd_fh ));fs/nfsd/nfs4proc.c +2
-0if (nfsd4_copy_is_async (copy)) {@@ -2199,6 +2222,8 @@ nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, copy->nf_dst->nf_file, true); } out: +if (restore_nocmtime) +nfsd4_restore_nocmtime (copy->nf_dst->nf_file);trace_nfsd_copy_done (copy, status);release_copy_files (copy);
Quoted 3 lines
return status;
Signature · 1 line
2.52.0
For async copies, does this restore FMODE_NOCMTIME before the kthread performs the actual data transfer?
The async path creates a kthread then falls through to the out: label. The restore runs here, before the kthread calls nfsd4_do_copy(). By the time the kthread runs nfsd4_do_async_copy() -> nfsd4_do_copy() -> _nfsd_copy_file_range(), FMODE_NOCMTIME has already been restored, and the timestamp update that this patch intends to enable will not take effect for async copies.
This is probably a variant of the race that Jeff already called out.
Signature · 1 line
Chuck Lever