Implement handling of unstable data in WRITE/COMMIT nfs procedures.
[bluesky.git] / nfs3 / rpc.c
index 2342b79..f753bd1 100644 (file)
@@ -28,6 +28,7 @@
 extern BlueSkyFS *fs;
 
 static int outstanding_rpcs = 0;
+static struct bluesky_stats *rpc_recv_stats, *rpc_send_stats;
 
 /* TCP port number to use for NFS protocol.  (Should be 2049.) */
 #define NFS_SERVICE_PORT 2051
@@ -172,6 +173,7 @@ async_rpc_send_failure(RPCRequest *req, enum accept_stat stat)
         /* For UDP, a connection only exists for the duration of a single
          * message. */
         g_mutex_free(req->connection->send_lock);
+        g_string_free(req->connection->msgbuf, TRUE);
         g_string_free(req->connection->sendbuf, TRUE);
         g_free(req->connection);
     }
@@ -194,6 +196,7 @@ async_rpc_send_reply(RPCRequest *req, void *result)
     }
 
     g_atomic_int_add(&outstanding_rpcs, -1);
+    bluesky_stats_add(rpc_send_stats, str->len);
 
     struct rpc_reply header;
     header.xid = htonl(req->xid);
@@ -248,6 +251,7 @@ async_rpc_send_reply(RPCRequest *req, void *result)
         /* For UDP, a connection only exists for the duration of a single
          * message. */
         g_mutex_free(req->connection->send_lock);
+        g_string_free(req->connection->msgbuf, TRUE);
         g_string_free(req->connection->sendbuf, TRUE);
         g_free(req->connection);
     }
@@ -508,6 +512,7 @@ static gboolean async_flushd(gpointer data)
 
     if (fs_dump_requested) {
         bluesky_debug_dump(fs);
+        bluesky_stats_dump_all();
         fs_dump_requested = 0;
     }
 
@@ -568,6 +573,8 @@ static gboolean async_rpc_dispatch(RPCConnection *rpc)
     GString *msg = rpc->msgbuf;
     const char *buf = msg->str;
 
+    bluesky_stats_add(rpc_recv_stats, msg->len);
+
     if (msg->len < sizeof(struct rpc_call_header)) {
         fprintf(stderr, "Short RPC message: only %zd bytes!\n", msg->len);
         return FALSE;
@@ -860,6 +867,9 @@ void register_rpc()
 {
     SVCXPRT *transp;
 
+    rpc_recv_stats = bluesky_stats_new("NFS RPC Messages In");
+    rpc_send_stats = bluesky_stats_new("NFS RPC Messages Out");
+
     async_rpc_init();
 
     /* MOUNT protocol */