Skip to content

Commit

Permalink
nfsd: minor nfsd_setattr cleanup
Browse files Browse the repository at this point in the history
Simplify exit paths, size_change use.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Cc: stable@kernel.org
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
  • Loading branch information
Christoph Hellwig authored and J. Bruce Fields committed Feb 20, 2017
1 parent 60709c0 commit 758e99f
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions fs/nfsd/vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, struct iattr *iap,
__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;
Expand All @@ -390,11 +390,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)
goto out;
return err;
if (get_write_count) {
host_err = fh_want_write(fhp);
if (host_err)
return nfserrno(host_err);
goto out;
}

dentry = fhp->fh_dentry;
Expand All @@ -405,19 +405,21 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, struct iattr *iap,
iap->ia_valid &= ~ATTR_MODE;

if (!iap->ia_valid)
goto out;
return 0;

nfsd_sanitize_attrs(inode, 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.
*/
if (iap->ia_valid & ATTR_SIZE) {
if (size_change) {
err = nfsd_get_write_access(rqstp, fhp, iap);
if (err)
goto out;
size_change = 1;
return err;

/*
* RFC5661, Section 18.30.4:
Expand All @@ -432,23 +434,16 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, struct iattr *iap,

iap->ia_valid |= ATTR_CTIME;

if (check_guard && guardtime != inode->i_ctime.tv_sec) {
err = nfserr_notsync;
goto out_put_write_access;
}

fh_lock(fhp);
host_err = notify_change(dentry, iap, NULL);
fh_unlock(fhp);
err = nfserrno(host_err);

out_put_write_access:
if (size_change)
put_write_access(inode);
if (!err)
err = nfserrno(commit_metadata(fhp));
out:
return err;
if (!host_err)
host_err = commit_metadata(fhp);
return nfserrno(host_err);
}

#if defined(CONFIG_NFSD_V4)
Expand Down

0 comments on commit 758e99f

Please sign in to comment.