NFSv3 SETATTR operation.
authorMichael Vrable <mvrable@cs.ucsd.edu>
Tue, 1 Sep 2009 21:04:33 +0000 (14:04 -0700)
committerMichael Vrable <mvrable@turin.ucsd.edu>
Tue, 1 Sep 2009 21:04:33 +0000 (14:04 -0700)
nfs3/nfs3.c

index 051d728..a5439f8 100644 (file)
@@ -42,6 +42,13 @@ BlueSkyInode *lookup_fh(nfs_fh3 *fh)
     return inode;
 }
 
+int64_t decode_nfstime3(nfstime3 *time)
+{
+    int64_t result = (int64_t)time->seconds * 1000000;
+    result += time->nseconds / 1000;
+    return result;
+}
+
 /* Copy inode attributes into NFS response.  The BlueSkyInode should be locked
  * by the caller. */
 void encode_fattr3(struct fattr3 *result, BlueSkyInode *inode)
@@ -101,7 +108,73 @@ nfsproc3_setattr_3_svc(setattr3args *argp, struct svc_req *rqstp)
 {
     static wccstat3 result;
 
-    result.status = NFS3ERR_NOTSUPP;
+    result.wccstat3_u.wcc.before.present = FALSE;
+    result.wccstat3_u.wcc.after.present = FALSE;
+    BlueSkyInode *inode = lookup_fh(&argp->object);
+    if (inode == NULL) {
+        result.status = NFS3ERR_STALE;
+        return &result;
+    }
+
+    encode_pre_wcc(&result.wccstat3_u.wcc, inode);
+    if (argp->guard.check) {
+        if (inode->ctime != decode_nfstime3(&argp->guard.sattrguard3_u.ctime)) {
+            result.status = NFS3ERR_NOT_SYNC;
+            result.wccstat3_u.wcc.after.present = TRUE;
+            encode_fattr3(&result.wccstat3_u.wcc.after.post_op_attr_u.attributes, inode);
+            return &result;
+        }
+    }
+
+    if (argp->new_attributes.mode.set) {
+        inode->mode = argp->new_attributes.mode.set_uint32_u.val;
+    }
+
+    if (argp->new_attributes.uid.set) {
+        inode->uid = argp->new_attributes.uid.set_uint32_u.val;
+    }
+
+    if (argp->new_attributes.gid.set) {
+        inode->gid = argp->new_attributes.gid.set_uint32_u.val;
+    }
+
+    int64_t now = bluesky_get_current_time();
+
+    if (argp->new_attributes.size.set) {
+        bluesky_file_truncate(inode,
+                              argp->new_attributes.size.set_uint64_u.val);
+        inode->mtime = now;
+    }
+
+    switch (argp->new_attributes.atime.set) {
+    case DONT_CHANGE:
+        break;
+    case SET_TO_SERVER_TIME:
+        inode->atime = now;
+        break;
+    case SET_TO_CLIENT_TIME:
+        inode->atime = decode_nfstime3(&argp->new_attributes.atime.set_time_u.time);
+        break;
+    }
+
+    switch (argp->new_attributes.mtime.set) {
+    case DONT_CHANGE:
+        break;
+    case SET_TO_SERVER_TIME:
+        inode->mtime = now;
+        break;
+    case SET_TO_CLIENT_TIME:
+        inode->mtime = decode_nfstime3(&argp->new_attributes.mtime.set_time_u.time);
+        break;
+    }
+
+    inode->ctime = now;
+    inode->change_count++;
+
+    result.wccstat3_u.wcc.after.present = TRUE;
+    encode_fattr3(&result.wccstat3_u.wcc.after.post_op_attr_u.attributes,
+                  inode);
+    result.status = NFS3_OK;
 
     return &result;
 }