Skip to content

Commit f67eef8

Browse files
jtlaytonchucklever
authored andcommitted
nfsd: drop inode parameter from nfsd4_change_attribute()
The inode that nfs4_open_delegation() passes to this function is wrong, which throws off the result. The inode will end up getting a directory-style change attr instead of a regular-file-style one. Fix up nfs4_delegation_stat() to fetch STATX_MODE, and then drop the inode parameter from nfsd4_change_attribute(), since it's no longer needed. Fixes: c596772 ("NFSD: handle GETATTR conflict with write delegation") Signed-off-by: Jeff Layton <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent ac15933 commit f67eef8

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

fs/nfsd/nfs4state.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5957,7 +5957,7 @@ nfs4_delegation_stat(struct nfs4_delegation *dp, struct svc_fh *currentfh,
59575957
path.dentry = file_dentry(nf->nf_file);
59585958

59595959
rc = vfs_getattr(&path, stat,
5960-
(STATX_SIZE | STATX_CTIME | STATX_CHANGE_COOKIE),
5960+
(STATX_MODE | STATX_SIZE | STATX_CTIME | STATX_CHANGE_COOKIE),
59615961
AT_STATX_SYNC_AS_STAT);
59625962

59635963
nfsd_file_put(nf);
@@ -6041,8 +6041,7 @@ nfs4_open_delegation(struct nfsd4_open *open, struct nfs4_ol_stateid *stp,
60416041
}
60426042
open->op_delegate_type = NFS4_OPEN_DELEGATE_WRITE;
60436043
dp->dl_cb_fattr.ncf_cur_fsize = stat.size;
6044-
dp->dl_cb_fattr.ncf_initial_cinfo =
6045-
nfsd4_change_attribute(&stat, d_inode(currentfh->fh_dentry));
6044+
dp->dl_cb_fattr.ncf_initial_cinfo = nfsd4_change_attribute(&stat);
60466045
trace_nfsd_deleg_write(&dp->dl_stid.sc_stateid);
60476046
} else {
60486047
open->op_delegate_type = NFS4_OPEN_DELEGATE_READ;

fs/nfsd/nfs4xdr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3040,7 +3040,7 @@ static __be32 nfsd4_encode_fattr4_change(struct xdr_stream *xdr,
30403040
return nfs_ok;
30413041
}
30423042

3043-
c = nfsd4_change_attribute(&args->stat, d_inode(args->dentry));
3043+
c = nfsd4_change_attribute(&args->stat);
30443044
return nfsd4_encode_changeid4(xdr, c);
30453045
}
30463046

fs/nfsd/nfsfh.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -667,20 +667,18 @@ fh_update(struct svc_fh *fhp)
667667
__be32 __must_check fh_fill_pre_attrs(struct svc_fh *fhp)
668668
{
669669
bool v4 = (fhp->fh_maxsize == NFS4_FHSIZE);
670-
struct inode *inode;
671670
struct kstat stat;
672671
__be32 err;
673672

674673
if (fhp->fh_no_wcc || fhp->fh_pre_saved)
675674
return nfs_ok;
676675

677-
inode = d_inode(fhp->fh_dentry);
678676
err = fh_getattr(fhp, &stat);
679677
if (err)
680678
return err;
681679

682680
if (v4)
683-
fhp->fh_pre_change = nfsd4_change_attribute(&stat, inode);
681+
fhp->fh_pre_change = nfsd4_change_attribute(&stat);
684682

685683
fhp->fh_pre_mtime = stat.mtime;
686684
fhp->fh_pre_ctime = stat.ctime;
@@ -697,7 +695,6 @@ __be32 __must_check fh_fill_pre_attrs(struct svc_fh *fhp)
697695
__be32 fh_fill_post_attrs(struct svc_fh *fhp)
698696
{
699697
bool v4 = (fhp->fh_maxsize == NFS4_FHSIZE);
700-
struct inode *inode = d_inode(fhp->fh_dentry);
701698
__be32 err;
702699

703700
if (fhp->fh_no_wcc)
@@ -713,7 +710,7 @@ __be32 fh_fill_post_attrs(struct svc_fh *fhp)
713710
fhp->fh_post_saved = true;
714711
if (v4)
715712
fhp->fh_post_change =
716-
nfsd4_change_attribute(&fhp->fh_post_attr, inode);
713+
nfsd4_change_attribute(&fhp->fh_post_attr);
717714
return nfs_ok;
718715
}
719716

@@ -804,7 +801,14 @@ enum fsid_source fsid_source(const struct svc_fh *fhp)
804801
return FSIDSOURCE_DEV;
805802
}
806803

807-
/*
804+
/**
805+
* nfsd4_change_attribute - Generate an NFSv4 change_attribute value
806+
* @stat: inode attributes
807+
*
808+
* Caller must fill in @stat before calling, typically by invoking
809+
* vfs_getattr() with STATX_MODE, STATX_CTIME, and STATX_CHANGE_COOKIE.
810+
* Returns an unsigned 64-bit changeid4 value (RFC 8881 Section 3.2).
811+
*
808812
* We could use i_version alone as the change attribute. However, i_version
809813
* can go backwards on a regular file after an unclean shutdown. On its own
810814
* that doesn't necessarily cause a problem, but if i_version goes backwards
@@ -821,13 +825,13 @@ enum fsid_source fsid_source(const struct svc_fh *fhp)
821825
* assume that the new change attr is always logged to stable storage in some
822826
* fashion before the results can be seen.
823827
*/
824-
u64 nfsd4_change_attribute(const struct kstat *stat, const struct inode *inode)
828+
u64 nfsd4_change_attribute(const struct kstat *stat)
825829
{
826830
u64 chattr;
827831

828832
if (stat->result_mask & STATX_CHANGE_COOKIE) {
829833
chattr = stat->change_cookie;
830-
if (S_ISREG(inode->i_mode) &&
834+
if (S_ISREG(stat->mode) &&
831835
!(stat->attributes & STATX_ATTR_CHANGE_MONOTONIC)) {
832836
chattr += (u64)stat->ctime.tv_sec << 30;
833837
chattr += stat->ctime.tv_nsec;

fs/nfsd/nfsfh.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,7 @@ static inline void fh_clear_pre_post_attrs(struct svc_fh *fhp)
297297
fhp->fh_pre_saved = false;
298298
}
299299

300-
u64 nfsd4_change_attribute(const struct kstat *stat,
301-
const struct inode *inode);
300+
u64 nfsd4_change_attribute(const struct kstat *stat);
302301
__be32 __must_check fh_fill_pre_attrs(struct svc_fh *fhp);
303302
__be32 fh_fill_post_attrs(struct svc_fh *fhp);
304303
__be32 __must_check fh_fill_both_attrs(struct svc_fh *fhp);

0 commit comments

Comments
 (0)