Add microbenchmarks to build system.
[bluesky.git] / nfs3 / rpc.c
index cda1330..a01408f 100644 (file)
@@ -18,6 +18,7 @@
 #include <stdlib.h>
 #include <rpc/pmap_clnt.h>
 #include <string.h>
+#include <signal.h>
 #include <memory.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -209,6 +210,7 @@ async_rpc_send_failure(RPCRequest *req, enum accept_stat stat)
         if (!req->xdr_args_free(&xdr, req->args)) {
             fprintf(stderr, "unable to free arguments");
         }
+        g_free(req->args);
     }
 
     if (req->raw_args != NULL)
@@ -270,6 +272,7 @@ async_rpc_send_reply(RPCRequest *req, void *result)
         if (!req->xdr_args_free(&xdr, req->args)) {
             fprintf(stderr, "unable to free arguments");
         }
+        g_free(req->args);
     }
 
     if (req->raw_args != NULL)
@@ -516,8 +519,22 @@ static GMainLoop *main_loop;
 
 static GThreadPool *rpc_thread_pool;
 
+static volatile int fs_dump_requested = 0;
+
+static void sig_handler(int sig)
+{
+    if (sig == SIGUSR1) {
+        fs_dump_requested = 1;
+    }
+}
+
 static gboolean async_flushd(gpointer data)
 {
+    if (fs_dump_requested) {
+        bluesky_debug_dump(fs);
+        fs_dump_requested = 0;
+    }
+
     bluesky_flushd_invoke(fs);
     return TRUE;
 }
@@ -539,6 +556,15 @@ static async_rpc_init()
     g_source_set_callback(source, async_flushd, NULL, NULL);
     g_source_attach(source, main_context);
     g_source_unref(source);
+
+    /* Signal USR1 is used to request a debugging dump of filesyste info */
+    struct sigaction sa;
+    sa.sa_handler = sig_handler;
+    sigemptyset(&sa.sa_mask);
+    sa.sa_flags = SA_RESTART;
+    if (sigaction(SIGUSR1, &sa, NULL) < 0) {
+        perror("sigaction");
+    }
 }
 
 struct rpc_call_header {
@@ -620,7 +646,11 @@ static gboolean async_rpc_dispatch(RPCConnection *rpc)
     req->req_proc = ntohl(header->proc);
     rpc->msgbuf = g_string_new("");
 
-    g_thread_pool_push(rpc_thread_pool, req, NULL);
+    if (bluesky_options.sync_frontends) {
+        nfs_program_3(req);
+    } else {
+        g_thread_pool_push(rpc_thread_pool, req, NULL);
+    }
 
     return TRUE;
 }