X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=nfs3%2Frpc.c;h=2c640d7bf68b3dd6b5329aa8d178a9cfcb11eb92;hb=79fd07ce3738aceebc08fd363c14795ae9353057;hp=7b73840c62349c046ab77d67cee02f65651353c4;hpb=3c5c5e9b5a8650e0549712e20e007ba2399656bf;p=bluesky.git diff --git a/nfs3/rpc.c b/nfs3/rpc.c index 7b73840..2c640d7 100644 --- a/nfs3/rpc.c +++ b/nfs3/rpc.c @@ -195,10 +195,12 @@ async_rpc_send_failure(RPCRequest *req, enum accept_stat stat) header.verf_len = 0; header.accept_stat = htonl(stat); + g_mutex_lock(req->connection->send_lock); uint32_t fragment = htonl(sizeof(header) | 0x80000000); async_rpc_write(req->connection, (const char *)&fragment, sizeof(fragment)); async_rpc_write(req->connection, (const char *)&header, sizeof(header)); g_io_channel_flush(req->connection->channel, NULL); + g_mutex_unlock(req->connection->send_lock); if (req->args != NULL) { char buf[4]; @@ -207,6 +209,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) @@ -244,12 +247,14 @@ async_rpc_send_reply(RPCRequest *req, void *result) header.verf_len = 0; header.accept_stat = 0; + g_mutex_lock(req->connection->send_lock); gsize msg_size = str->len; uint32_t fragment = htonl((msg_size + sizeof(header)) | 0x80000000); async_rpc_write(req->connection, (const char *)&fragment, sizeof(fragment)); async_rpc_write(req->connection, (const char *)&header, sizeof(header)); async_rpc_write(req->connection, str->str, str->len); g_io_channel_flush(req->connection->channel, NULL); + g_mutex_unlock(req->connection->send_lock); time_end = bluesky_now_hires(); @@ -266,6 +271,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) @@ -281,6 +287,31 @@ async_rpc_send_reply(RPCRequest *req, void *result) g_free(req); } +static const char *nfs_proc_names[] = { + [NFSPROC3_NULL] = "NULL", + [NFSPROC3_GETATTR] = "GETATTR", + [NFSPROC3_SETATTR] = "SETATTR", + [NFSPROC3_LOOKUP] = "LOOKUP", + [NFSPROC3_ACCESS] = "ACCESS", + [NFSPROC3_READLINK] = "READLINK", + [NFSPROC3_READ] = "READ", + [NFSPROC3_WRITE] = "WRITE", + [NFSPROC3_CREATE] = "CREATE", + [NFSPROC3_MKDIR] = "MKDIR", + [NFSPROC3_SYMLINK] = "SYMLINK", + [NFSPROC3_MKNOD] = "MKNOD", + [NFSPROC3_REMOVE] = "REMOVE", + [NFSPROC3_RMDIR] = "RMDIR", + [NFSPROC3_RENAME] = "RENAME", + [NFSPROC3_LINK] = "LINK", + [NFSPROC3_READDIR] = "READDIR", + [NFSPROC3_READDIRPLUS] = "READDIRPLUS", + [NFSPROC3_FSSTAT] = "FSSTAT", + [NFSPROC3_FSINFO] = "FSINFO", + [NFSPROC3_PATHCONF] = "PATHCONF", + [NFSPROC3_COMMIT] = "COMMIT", +}; + static void nfs_program_3(RPCRequest *req) { @@ -316,7 +347,12 @@ nfs_program_3(RPCRequest *req) xdrproc_t _xdr_argument, _xdr_result; char *(*local)(char *, RPCRequest *); - printf("Dispatched NFS RPC message type %d\n", req->req_proc); + if (req->req_proc < sizeof(nfs_proc_names) / sizeof(const char *)) { + printf("Dispatched NFS RPC message type %s\n", + nfs_proc_names[req->req_proc]); + } else { + printf("Dispatched unknown NFS RPC message type %d\n", req->req_proc); + } switch (req->req_proc) { case NFSPROC3_NULL: @@ -471,9 +507,6 @@ nfs_program_3(RPCRequest *req) req->xdr_result = _xdr_result; result = (*local)((char *)req->args, req); - bluesky_flushd_invoke(fs); - bluesky_debug_dump(fs); - return; } @@ -483,10 +516,31 @@ nfs_program_3(RPCRequest *req) static GMainContext *main_context; static GMainLoop *main_loop; +static GThreadPool *rpc_thread_pool; + +static gboolean async_flushd(gpointer data) +{ + bluesky_flushd_invoke(fs); + return TRUE; +} + +static void async_rpc_task(gpointer data, gpointer user_data) +{ + nfs_program_3((RPCRequest *)data); +} + static async_rpc_init() { main_context = g_main_context_new(); main_loop = g_main_loop_new(main_context, FALSE); + + rpc_thread_pool = g_thread_pool_new(async_rpc_task, NULL, -1, FALSE, NULL); + + /* Arrange to have the cache writeback code run every five seconds. */ + GSource *source = g_timeout_source_new_seconds(5); + g_source_set_callback(source, async_flushd, NULL, NULL); + g_source_attach(source, main_context); + g_source_unref(source); } struct rpc_call_header { @@ -568,7 +622,7 @@ static gboolean async_rpc_dispatch(RPCConnection *rpc) req->req_proc = ntohl(header->proc); rpc->msgbuf = g_string_new(""); - nfs_program_3(req); + g_thread_pool_push(rpc_thread_pool, req, NULL); return TRUE; } @@ -640,6 +694,7 @@ static gboolean async_rpc_do_read(GIOChannel *channel, fprintf(stderr, "Unexpected error or end of file on RPC stream %d!\n", g_io_channel_unix_get_fd(rpc->channel)); g_io_channel_shutdown(rpc->channel, TRUE, NULL); + /* TODO: Clean up connection object. */ return FALSE; } @@ -698,6 +753,7 @@ static gboolean async_rpc_do_accept(GIOChannel *channel, rpc->channel = g_io_channel_unix_new(nfd); rpc->msgbuf = g_string_new(""); g_io_channel_set_encoding(rpc->channel, NULL, NULL); + rpc->send_lock = g_mutex_new(); GSource *source = g_io_create_watch(rpc->channel, G_IO_IN); g_source_set_callback(source, (GSourceFunc)async_rpc_do_read, rpc, NULL);