From: Michael Vrable <mvrable@cs.ucsd.edu>
Date: Mon, 27 Sep 2010 17:57:59 +0000 (-0700)
Subject: Implement handling of unstable data in WRITE/COMMIT nfs procedures.
X-Git-Url: http://git.vrable.net/?a=commitdiff_plain;h=7fea6eae8397d399c2557bdcbb969255dd440d72;p=bluesky.git

Implement handling of unstable data in WRITE/COMMIT nfs procedures.

Before all NFS operations were synchronous; now we support asynchronous
commits of file writes which might improve performance.
---

diff --git a/nfs3/nfs3.c b/nfs3/nfs3.c
index 7662a2c..b5dae80 100644
--- a/nfs3/nfs3.c
+++ b/nfs3/nfs3.c
@@ -428,9 +428,15 @@ void nfsproc3_write_3_svc(write3args *argp, RPCRequest *req)
     encode_fattr3(&wcc.after.post_op_attr_u.attributes, inode);
     result.write3res_u.resok.file_wcc = wcc;
     result.write3res_u.resok.count = argp->count;
-    result.write3res_u.resok.committed = FILE_SYNC;
+    result.write3res_u.resok.committed = UNSTABLE;
+    memcpy(result.write3res_u.resok.verf,
+           nfsd_instance_verf_cookie, NFS3_WRITEVERFSIZE);
+
+    if (argp->stable != UNSTABLE) {
+        bluesky_inode_do_sync(inode);
+        result.write3res_u.resok.committed = FILE_SYNC;
+    }
 
-    bluesky_inode_do_sync(inode);
     g_mutex_unlock(inode->lock);
 
     async_rpc_send_reply(req, &result);
@@ -1163,6 +1169,8 @@ void nfsproc3_commit_3_svc(commit3args *argp, RPCRequest *req)
 
     result.commit3res_u.resok.file_wcc.after.present = TRUE;
     encode_fattr3(&result.commit3res_u.resok.file_wcc.after.post_op_attr_u.attributes, inode);
+    memcpy(result.commit3res_u.resok.verf,
+           nfsd_instance_verf_cookie, NFS3_WRITEVERFSIZE);
 
     g_mutex_unlock(inode->lock);
 
diff --git a/nfs3/nfs3_prot.h b/nfs3/nfs3_prot.h
index 1b8352b..ab1125d 100644
--- a/nfs3/nfs3_prot.h
+++ b/nfs3/nfs3_prot.h
@@ -22,6 +22,8 @@ typedef int int32;
 #define NFS3_CREATEVERFSIZE 8
 #define NFS3_WRITEVERFSIZE 8
 
+extern char nfsd_instance_verf_cookie[NFS3_WRITEVERFSIZE];
+
 typedef char *filename3;
 
 typedef char *nfspath3;
diff --git a/nfs3/nfsd.c b/nfs3/nfsd.c
index f9cbd7f..8641a56 100644
--- a/nfs3/nfsd.c
+++ b/nfs3/nfsd.c
@@ -10,6 +10,7 @@
  * filesystem. */
 
 #include "mount_prot.h"
+#include "nfs3_prot.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <rpc/pmap_clnt.h>
@@ -26,6 +27,10 @@ void register_rpc();
 BlueSkyFS *fs;
 BlueSkyStore *store;
 
+/* A cookie value returned for uncommitted writes and verified by commits; this
+ * should be a unique value each time the server is started. */
+char nfsd_instance_verf_cookie[NFS3_WRITEVERFSIZE];
+
 static void shutdown_handler(int num)
 {
     g_print("SIGINT caught, shutting down...\n");
@@ -51,6 +56,9 @@ int main(int argc, char *argv[])
     store = bluesky_store_new(target);
     fs = bluesky_init_fs("export", store);
 
+    bluesky_crypt_random_bytes(nfsd_instance_verf_cookie,
+                               sizeof(nfsd_instance_verf_cookie));
+
     register_rpc();
 
     svc_run();