nfsd: minor nfsd_setattr cleanup
[pandora-kernel.git] / fs / nfsd / vfs.c
index 11e1888..56bdccc 100644 (file)
@@ -301,17 +301,19 @@ commit_metadata(struct svc_fh *fhp)
  * NFS semantics and what Linux expects.
  */
 static void
-nfsd_sanitize_attrs(struct inode *inode, struct iattr *iap)
+nfsd_sanitize_attrs(struct dentry *dentry, struct iattr *iap)
 {
+       struct inode *inode = dentry->d_inode;
+
        /*
         * NFSv2 does not differentiate between "set-[ac]time-to-now"
         * which only requires access, and "set-[ac]time-to-X" which
         * requires ownership.
         * So if it looks like it might be "set both to the same time which
-        * is close to now", and if inode_change_ok fails, then we
+        * is close to now", and if setattr_prepare fails, then we
         * convert to "set to now" instead of "set to explicit time"
         *
-        * We only call inode_change_ok as the last test as technically
+        * We only call setattr_prepare as the last test as technically
         * it is not an interface that we should be using.
         */
 #define BOTH_TIME_SET (ATTR_ATIME_SET | ATTR_MTIME_SET)
@@ -329,7 +331,7 @@ nfsd_sanitize_attrs(struct inode *inode, struct iattr *iap)
                if (delta < 0)
                        delta = -delta;
                if (delta < MAX_TOUCH_TIME_ERROR &&
-                   inode_change_ok(inode, iap) != 0) {
+                   setattr_prepare(dentry, iap) != 0) {
                        /*
                         * Turn off ATTR_[AM]TIME_SET but leave ATTR_[AM]TIME.
                         * This will cause notify_change to set these times
@@ -407,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;
-       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;
@@ -420,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)
-               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;
@@ -435,28 +437,35 @@ 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);
+       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.
         */
-       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:
+                *   Changing the size of a file with SETATTR indirectly
+                *   changes the time_modify and change attributes.
+                *
+                * (and similar for the older RFCs)
+                */
+               if (iap->ia_size != i_size_read(inode))
+                       iap->ia_valid |= ATTR_MTIME;
        }
 
        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;
@@ -466,14 +475,12 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, struct iattr *iap,
        fh_unlock(fhp);
 
 out_put_write_access_nfserror:
-       err = nfserrno(host_err);
-out_put_write_access:
        if (size_change)
                put_write_access(inode);
-       if (!err)
-               commit_metadata(fhp);
 out:
-       return err;
+       if (!host_err)
+               commit_metadata(fhp);
+       return nfserrno(host_err);
 }
 
 #if defined(CONFIG_NFSD_V2_ACL) || \
@@ -508,6 +515,9 @@ set_nfsv4_acl_one(struct dentry *dentry, struct posix_acl *pacl, char *key)
        char *buf = NULL;
        int error = 0;
 
+       if (!pacl)
+               return vfs_setxattr(dentry, key, NULL, 0, 0);
+
        buflen = posix_acl_xattr_size(pacl->a_count);
        buf = kmalloc(buflen, GFP_KERNEL);
        error = -ENOMEM;