nfsd: minor nfsd_setattr cleanup
authorChristoph Hellwig <hch@lst.de>
Mon, 20 Feb 2017 22:04:42 +0000 (17:04 -0500)
committerBen Hutchings <ben@decadent.org.uk>
Mon, 5 Jun 2017 20:13:50 +0000 (21:13 +0100)
commit 758e99fefe1d9230111296956335cd35995c0eaf upstream.

Simplify exit paths, size_change use.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
[bwh: Backported to 3.2: adjust context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
fs/nfsd/vfs.c

index babe7f9..56bdccc 100644 (file)
@@ -409,7 +409,7 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, struct iattr *iap,
        __be32          err;
        int             host_err;
        bool            get_write_count;
        __be32          err;
        int             host_err;
        bool            get_write_count;
-       int             size_change = 0;
+       bool            size_change = (iap->ia_valid & ATTR_SIZE);
 
        if (iap->ia_valid & (ATTR_ATIME | ATTR_MTIME | ATTR_SIZE))
                accmode |= NFSD_MAY_WRITE|NFSD_MAY_OWNER_OVERRIDE;
 
        if (iap->ia_valid & (ATTR_ATIME | ATTR_MTIME | ATTR_SIZE))
                accmode |= NFSD_MAY_WRITE|NFSD_MAY_OWNER_OVERRIDE;
@@ -422,11 +422,11 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, struct iattr *iap,
        /* Get inode */
        err = fh_verify(rqstp, fhp, ftype, accmode);
        if (err)
        /* Get inode */
        err = fh_verify(rqstp, fhp, ftype, accmode);
        if (err)
-               goto out;
+               return err;
        if (get_write_count) {
                host_err = fh_want_write(fhp);
                if (host_err)
        if (get_write_count) {
                host_err = fh_want_write(fhp);
                if (host_err)
-                       return nfserrno(host_err);
+                       goto out;
        }
 
        dentry = fhp->fh_dentry;
        }
 
        dentry = fhp->fh_dentry;
@@ -437,19 +437,21 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, struct iattr *iap,
                iap->ia_valid &= ~ATTR_MODE;
 
        if (!iap->ia_valid)
                iap->ia_valid &= ~ATTR_MODE;
 
        if (!iap->ia_valid)
-               goto out;
+               return 0;
 
        nfsd_sanitize_attrs(dentry, iap);
 
 
        nfsd_sanitize_attrs(dentry, iap);
 
+       if (check_guard && guardtime != inode->i_ctime.tv_sec)
+               return nfserr_notsync;
+
        /*
         * The size case is special, it changes the file in addition to the
         * attributes.
         */
        /*
         * The size case is special, it changes the file in addition to the
         * attributes.
         */
-       if (iap->ia_valid & ATTR_SIZE) {
+       if (size_change) {
                err = nfsd_get_write_access(rqstp, fhp, iap);
                if (err)
                err = nfsd_get_write_access(rqstp, fhp, iap);
                if (err)
-                       goto out;
-               size_change = 1;
+                       return err;
 
                /*
                 * RFC5661, Section 18.30.4:
 
                /*
                 * RFC5661, Section 18.30.4:
@@ -464,11 +466,6 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, struct iattr *iap,
 
        iap->ia_valid |= ATTR_CTIME;
 
 
        iap->ia_valid |= ATTR_CTIME;
 
-       if (check_guard && guardtime != inode->i_ctime.tv_sec) {
-               err = nfserr_notsync;
-               goto out_put_write_access;
-       }
-
        host_err = nfsd_break_lease(inode);
        if (host_err)
                goto out_put_write_access_nfserror;
        host_err = nfsd_break_lease(inode);
        if (host_err)
                goto out_put_write_access_nfserror;
@@ -478,14 +475,12 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, struct iattr *iap,
        fh_unlock(fhp);
 
 out_put_write_access_nfserror:
        fh_unlock(fhp);
 
 out_put_write_access_nfserror:
-       err = nfserrno(host_err);
-out_put_write_access:
        if (size_change)
                put_write_access(inode);
        if (size_change)
                put_write_access(inode);
-       if (!err)
-               commit_metadata(fhp);
 out:
 out:
-       return err;
+       if (!host_err)
+               commit_metadata(fhp);
+       return nfserrno(host_err);
 }
 
 #if defined(CONFIG_NFSD_V2_ACL) || \
 }
 
 #if defined(CONFIG_NFSD_V2_ACL) || \