X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=nfs3%2Frpc.c;h=3c6da98764de453236a79734889a5e889852f32d;hb=8ff0fd08d6e1cc97cdb7e94b7cd97dc28c29e674;hp=dbe0a64b67b20f992b14bdb5a8666b9857a1d186;hpb=348aaaad42163d6829112c9b18026c16b09e1914;p=bluesky.git diff --git a/nfs3/rpc.c b/nfs3/rpc.c index dbe0a64..3c6da98 100644 --- a/nfs3/rpc.c +++ b/nfs3/rpc.c @@ -3,7 +3,29 @@ * Copyright (C) 2009 The Regents of the University of California * Written by Michael Vrable * - * TODO: Licensing + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. */ /* RPC handling: registration, marshalling and unmarshalling of messages. For @@ -28,6 +50,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 @@ -148,6 +171,8 @@ async_rpc_send_failure(RPCRequest *req, enum accept_stat stat) async_rpc_flush(req->connection); g_mutex_unlock(req->connection->send_lock); + bluesky_profile_free(req->profile); + if (req->args != NULL) { char buf[4]; XDR xdr; @@ -172,6 +197,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); } @@ -184,6 +210,9 @@ async_rpc_send_reply(RPCRequest *req, void *result) { bluesky_time_hires time_end; + bluesky_profile_add_event(req->profile, + g_strdup("Start encoding NFS response")); + GString *str = g_string_new(""); XDR xdr_out; xdr_string_create(&xdr_out, str, XDR_ENCODE); @@ -194,6 +223,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); @@ -221,7 +251,12 @@ async_rpc_send_reply(RPCRequest *req, void *result) req->xid, time_end - req->time_start); #endif + bluesky_profile_add_event(req->profile, + g_strdup("NFS reply sent")); + bluesky_profile_print(req->profile); + /* Clean up. */ + bluesky_profile_free(req->profile); g_string_free(str, TRUE); if (req->args != NULL) { @@ -248,6 +283,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); } @@ -315,14 +351,15 @@ nfs_program_3(RPCRequest *req) xdrproc_t _xdr_argument, _xdr_result; char *(*local)(char *, RPCRequest *); -#if 0 + bluesky_profile_set(req->profile); + 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); + bluesky_profile_add_event( + req->profile, + g_strdup_printf("Dispatching NFS %s request", + nfs_proc_names[req->req_proc]) + ); } -#endif switch (req->req_proc) { case NFSPROC3_NULL: @@ -569,6 +606,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; @@ -590,7 +629,8 @@ static gboolean async_rpc_dispatch(RPCConnection *rpc) RPCRequest *req = g_new0(RPCRequest, 1); req->connection = rpc; - req->time_start = time_start; + req->profile = bluesky_profile_new(); + bluesky_profile_add_event(req->profile, g_strdup("Receive NFS request")); req->xid = xid; if (ntohl(header->prog) != NFS_PROGRAM) { @@ -861,6 +901,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 */