Skip to content

Commit 4255873

Browse files
scottmayhewgregkh
authored andcommitted
nfsd: fix file change detection in CB_GETATTR
commit 304d81a2fbf2b454def4debcb38ea173911b72cd upstream. RFC 8881, section 10.4.3 doesn't say anything about caching the file size in the delegation record, nor does it say anything about comparing a cached file size with the size reported by the client in the CB_GETATTR reply for the purpose of determining if the client holds modified data for the file. What section 10.4.3 of RFC 8881 does say is that the server should compare the *current* file size with the size reported by the client holding the delegation in the CB_GETATTR reply, and if they differ to treat it as a modification regardless of the change attribute retrieved via the CB_GETATTR. Doing otherwise would cause the server to believe the client holding the delegation has a modified version of the file, even if the client flushed the modifications to the server prior to the CB_GETATTR. This would have the added side effect of subsequent CB_GETATTRs causing updates to the mtime, ctime, and change attribute even if the client holding the delegation makes no further updates to the file. Modify nfsd4_deleg_getattr_conflict() to obtain the current file size via i_size_read(). Retain the ncf_cur_fsize field, since it's a convenient way to return the file size back to nfsd4_encode_fattr4(), but don't use it for the purpose of detecting file changes. Remove the unnecessary initialization of ncf_cur_fsize in nfs4_open_delegation(). Also, if we recall the delegation (because the client didn't respond to the CB_GETATTR), then skip the logic that checks the nfs4_cb_fattr fields. Fixes: c596772 ("NFSD: handle GETATTR conflict with write delegation") Cc: stable@vger.kernel.org Signed-off-by: Scott Mayhew <smayhew@redhat.com> Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent fc6db1e commit 4255873

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

fs/nfsd/nfs4state.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6350,7 +6350,6 @@ nfs4_open_delegation(struct svc_rqst *rqstp, struct nfsd4_open *open,
63506350
}
63516351
open->op_delegate_type = deleg_ts ? OPEN_DELEGATE_WRITE_ATTRS_DELEG :
63526352
OPEN_DELEGATE_WRITE;
6353-
dp->dl_cb_fattr.ncf_cur_fsize = stat.size;
63546353
dp->dl_cb_fattr.ncf_initial_cinfo = nfsd4_change_attribute(&stat);
63556354
dp->dl_atime = stat.atime;
63566355
dp->dl_ctime = stat.ctime;
@@ -9396,11 +9395,15 @@ nfsd4_deleg_getattr_conflict(struct svc_rqst *rqstp, struct dentry *dentry,
93969395
if (status != nfserr_jukebox ||
93979396
!nfsd_wait_for_delegreturn(rqstp, inode))
93989397
goto out_status;
9398+
status = nfs_ok;
9399+
goto out_status;
9400+
}
9401+
if (!ncf->ncf_file_modified) {
9402+
if (ncf->ncf_initial_cinfo != ncf->ncf_cb_change)
9403+
ncf->ncf_file_modified = true;
9404+
else if (i_size_read(inode) != ncf->ncf_cb_fsize)
9405+
ncf->ncf_file_modified = true;
93999406
}
9400-
if (!ncf->ncf_file_modified &&
9401-
(ncf->ncf_initial_cinfo != ncf->ncf_cb_change ||
9402-
ncf->ncf_cur_fsize != ncf->ncf_cb_fsize))
9403-
ncf->ncf_file_modified = true;
94049407
if (ncf->ncf_file_modified) {
94059408
int err;
94069409

0 commit comments

Comments
 (0)