[PATCH 04/10] nfsd: remove subtlety from nfsd4_create_file()
NeilBrown <[email protected]>
| Newsgroups | gmane.linux.nfs |
|---|---|
| Message-ID | <[email protected]> |
From: NeilBrown <neil-+NVA1uvv1dVBDLzU/[email protected]> nfsd4_create_file() has a switch with cases for NFS4_CREATE_EXCLUSIVE and NFS4_CREATE_EXCLUSIVE4_1 which are identical except for one line which is marked "subtle" in both cases. The difference boils down to a "goto". For the EXCLUSIVE case the target is "out:" which is after a setattr call. For EXCLUSIVE4_1 the target is "set_attr:" which is the start of that setattr call. We already have a function is_create_with_attrs() which determines if the setattr is needed, and differentiates between these two cases. So if we guard the setattr with "is_create_with_attrs()", then we can "goto setattr" for both cases and so unify the two cases in the switch. This, I think, makes the code clearer and less subtle. Signed-off-by: NeilBrown <neil-+NVA1uvv1dVBDLzU/[email protected]> --- fs/nfsd/nfs4proc.c | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index c63c8fe64079..5b7f0314776f 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -363,22 +363,15 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, status = nfserr_exist; break; case NFS4_CREATE_EXCLUSIVE: - if (inode_get_mtime_sec(d_inode(child)) == v_mtime && - inode_get_atime_sec(d_inode(child)) == v_atime && - d_inode(child)->i_size == 0) { - open->op_created = true; - break; /* subtle */ - } - status = nfserr_exist; - break; case NFS4_CREATE_EXCLUSIVE4_1: if (inode_get_mtime_sec(d_inode(child)) == v_mtime && inode_get_atime_sec(d_inode(child)) == v_atime && d_inode(child)->i_size == 0) { open->op_created = true; - goto set_attr; /* subtle */ + goto set_attr; } status = nfserr_exist; + break; } goto out; } @@ -398,16 +391,18 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, iap->ia_valid &= ~ATTR_SIZE; set_attr: - status = nfsd_create_setattr(rqstp, fhp, resfhp, &attrs); - - if (attrs.na_labelerr) - open->op_bmval[2] &= ~FATTR4_WORD2_SECURITY_LABEL; - if (attrs.na_paclerr || attrs.na_dpaclerr) - open->op_bmval[0] &= ~FATTR4_WORD0_ACL; - if (attrs.na_dpaclerr) - open->op_bmval[2] &= ~FATTR4_WORD2_POSIX_DEFAULT_ACL; - if (attrs.na_paclerr) - open->op_bmval[2] &= ~FATTR4_WORD2_POSIX_ACCESS_ACL; + if (is_create_with_attrs(open)) { + status = nfsd_create_setattr(rqstp, fhp, resfhp, &attrs); + + if (attrs.na_labelerr) + open->op_bmval[2] &= ~FATTR4_WORD2_SECURITY_LABEL; + if (attrs.na_paclerr || attrs.na_dpaclerr) + open->op_bmval[0] &= ~FATTR4_WORD0_ACL; + if (attrs.na_dpaclerr) + open->op_bmval[2] &= ~FATTR4_WORD2_POSIX_DEFAULT_ACL; + if (attrs.na_paclerr) + open->op_bmval[2] &= ~FATTR4_WORD2_POSIX_ACCESS_ACL; + } out: end_creating(child); fh_drop_write(fhp); -- 2.50.0.107.gf914562f5916.dirty