Debugging/refcount cleanups.
authorMichael Vrable <mvrable@cs.ucsd.edu>
Tue, 17 Aug 2010 18:02:56 +0000 (11:02 -0700)
committerMichael Vrable <mvrable@cs.ucsd.edu>
Tue, 17 Aug 2010 18:02:56 +0000 (11:02 -0700)
bluesky/bluesky-private.h
bluesky/debug.c
bluesky/log.c
bluesky/util.c

index 636b664..46a6690 100644 (file)
@@ -269,7 +269,7 @@ struct _BlueSkyCacheFile {
     int log_dir;
     int log_seq;
     char *filename;             // Local filename, relateive to log directory
-    gint refcount;              // References to the mmaped data
+    gint mapcount;              // References to the mmaped data
     const char *addr;           // May be null if data is not mapped in memory
     size_t len;
     BlueSkyFS *fs;
index 43b29be..9d875bd 100644 (file)
@@ -51,10 +51,21 @@ static void cloudlog_dump(gpointer key, gpointer value, gpointer user_data)
             log->location.sequence, log->location.offset);
 }
 
+static void cache_dump(gpointer key, gpointer value, gpointer user_data)
+{
+    BlueSkyCacheFile *cache = (BlueSkyCacheFile *)value;
+
+    g_print("%s addr=%p mapcount=%d",
+            cache->filename, cache->addr, cache->mapcount);
+    if (cache->fetching)
+        g_print(" (fetching)");
+    g_print("\n");
+}
+
 /* 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("\n*** DEBUG DUMP FOR FILESYSTEM %s ***\n", fs->name);
     g_print("Dirty blocks: %d\n", g_atomic_int_get(&fs->cache_dirty));
     g_print("Cached inodes: %u\tNext inode: %"PRIu64"\n",
             g_hash_table_size(fs->inodes), fs->next_inum);
@@ -85,6 +96,9 @@ void bluesky_debug_dump(BlueSkyFS *fs)
 
     g_print("\nLog Objects:\n");
     g_hash_table_foreach(fs->locations, cloudlog_dump, fs);
+
+    g_print("\nJournal/Cache Files:\n");
+    g_hash_table_foreach(fs->log->mmap_cache, cache_dump, fs);
     g_print("\n");
 }
 
index bdf14ff..0918d37 100644 (file)
@@ -331,7 +331,7 @@ BlueSkyCacheFile *bluesky_cachefile_lookup(BlueSkyFS *fs,
         map->filename = logname;
         map->log_seq = log_seq;
         map->log = log;
-        g_atomic_int_set(&map->refcount, 0);
+        g_atomic_int_set(&map->mapcount, 0);
 
         g_hash_table_insert(log->mmap_cache, GINT_TO_POINTER(log_seq), map);
 
@@ -407,9 +407,9 @@ void bluesky_mmap_unref(BlueSkyCacheFile *mmap)
     if (mmap == NULL)
         return;
 
-    if (g_atomic_int_dec_and_test(&mmap->refcount)) {
+    if (g_atomic_int_dec_and_test(&mmap->mapcount)) {
         g_mutex_lock(mmap->lock);
-        if (g_atomic_int_get(&mmap->refcount) > 0) {
+        if (g_atomic_int_get(&mmap->mapcount) > 0) {
             g_print("Unmapped log segment %d...\n", mmap->log_seq);
             munmap((void *)mmap->addr, mmap->len);
             mmap->addr = NULL;
index 427519c..d292634 100644 (file)
@@ -82,7 +82,7 @@ BlueSkyRCStr *bluesky_string_new_from_mmap(BlueSkyCacheFile *mmap,
 
     BlueSkyRCStr *string = g_new(BlueSkyRCStr, 1);
     string->mmap = mmap;
-    g_atomic_int_inc(&mmap->refcount);
+    g_atomic_int_inc(&mmap->mapcount);
     string->data = (char *)mmap->addr + offset;
     string->len = len;
     g_atomic_int_set(&string->refcount, 1);