From 7bb8900e1209a2abf3d83e7f06e2dfb314cef61e Mon Sep 17 00:00:00 2001 From: Michael Vrable Date: Wed, 20 Jan 2010 15:59:10 -0800 Subject: [PATCH] Add support for dumping filesystem state for debugging purposes. --- bluesky/CMakeLists.txt | 4 ++-- bluesky/bluesky.h | 2 ++ bluesky/debug.c | 46 ++++++++++++++++++++++++++++++++++++++++++ nfs3/rpc.c | 5 +++-- 4 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 bluesky/debug.c diff --git a/bluesky/CMakeLists.txt b/bluesky/CMakeLists.txt index b1e7343..e380312 100644 --- a/bluesky/CMakeLists.txt +++ b/bluesky/CMakeLists.txt @@ -2,8 +2,8 @@ include_directories("${LIBS3_BUILD_DIR}/include") link_directories("${LIBS3_BUILD_DIR}/lib") add_library(bluesky SHARED - cache.c crypto.c dir.c file.c init.c inode.c serialize.c store.c - s3store.c util.c) + cache.c crypto.c debug.c dir.c file.c init.c inode.c serialize.c + store.c s3store.c util.c) add_executable(bluesky-test main.c) set(CMAKE_C_FLAGS "-Wall -std=gnu99 ${CMAKE_C_FLAGS}") diff --git a/bluesky/bluesky.h b/bluesky/bluesky.h index 59814b1..41618b5 100644 --- a/bluesky/bluesky.h +++ b/bluesky/bluesky.h @@ -237,6 +237,8 @@ gint bluesky_dirent_compare(gconstpointer a, gconstpointer b, void bluesky_flushd_invoke(BlueSkyFS *fs); +void bluesky_debug_dump(BlueSkyFS *fs); + #ifdef __cplusplus } #endif diff --git a/bluesky/debug.c b/bluesky/debug.c new file mode 100644 index 0000000..b030b7f --- /dev/null +++ b/bluesky/debug.c @@ -0,0 +1,46 @@ +/* Blue Sky: File Systems in the Cloud + * + * Copyright (C) 2009 The Regents of the University of California + * Written by Michael Vrable + * + * TODO: Licensing + */ + +#include +#include +#include +#include +#include + +#include "bluesky-private.h" + +/* Debugging support for BlueSky. */ + +static void inode_dump(gpointer key, gpointer value, gpointer user_data) +{ + BlueSkyInode *inode = (BlueSkyInode *)value; + + g_print("Inode %"PRIu64":\n", inode->inum); + + gboolean locked = FALSE; + if (g_mutex_trylock(inode->lock)) { + locked = TRUE; + g_mutex_unlock(inode->lock); + } + g_print(" Locked: %c Refcount: %d\n", + locked ? 'T' : 'F', inode->refcount); + + g_print(" Type: %d Mode: %o\n", inode->type, inode->mode); + g_print(" change_count = %"PRIu64", change_commit = %"PRIu64"\n", + inode->change_count, inode->change_commit); +} + +/* Dump a summary of filesystem state as it is cached in memory. */ +void bluesky_debug_dump(BlueSkyFS *fs) +{ + g_print("*** DEBUG DUMP FOR FILESYSTEM %s ***\n", fs->name); + g_print("Cached inodes: %u\tNext inode: %"PRIu64"\n", + g_hash_table_size(fs->inodes), fs->next_inum); + + g_hash_table_foreach(fs->inodes, inode_dump, fs); +} diff --git a/nfs3/rpc.c b/nfs3/rpc.c index 92c17c8..468c58c 100644 --- a/nfs3/rpc.c +++ b/nfs3/rpc.c @@ -295,6 +295,8 @@ 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); + switch (req->req_proc) { case NFSPROC3_NULL: _xdr_argument = (xdrproc_t) xdr_void; @@ -449,6 +451,7 @@ nfs_program_3(RPCRequest *req) result = (*local)((char *)req->args, req); bluesky_flushd_invoke(fs); + bluesky_debug_dump(fs); return; } @@ -632,7 +635,6 @@ static gboolean async_rpc_do_read(GIOChannel *channel, rpc->frag_len = ntohl(rpc->frag_len); g_string_set_size(rpc->msgbuf, rpc->msgbuf->len - 4); rpc->frag_hdr_bytes = 0; - g_print("RPC fragment header: %08x\n", rpc->frag_len); } } else { /* We were reading in the fragment body. */ @@ -641,7 +643,6 @@ static gboolean async_rpc_do_read(GIOChannel *channel, if (rpc->frag_len = 0x80000000) { /* We have a complete message since this was the last fragment and * there are no more bytes in it. Dispatch the message. */ - g_print("Complete RPC message: %zd bytes\n", rpc->msgbuf->len); if (!async_rpc_dispatch(rpc)) { fprintf(stderr, "Invalid RPC message, closing channel\n"); g_io_channel_shutdown(rpc->channel, TRUE, NULL); -- 2.20.1