1 /* Blue Sky: File Systems in the Cloud
3 * Copyright (C) 2009 The Regents of the University of California
4 * Written by Michael Vrable <mvrable@cs.ucsd.edu>
15 #include "bluesky-private.h"
17 /* Debugging support for BlueSky. */
19 static void inode_dump(gpointer key, gpointer value, gpointer user_data)
21 BlueSkyInode *inode = (BlueSkyInode *)value;
23 g_print("Inode %"PRIu64":\n", inode->inum);
25 gboolean locked = TRUE;
26 if (g_mutex_trylock(inode->lock)) {
28 g_mutex_unlock(inode->lock);
30 g_print(" Locked: %c Refcount: %d\n",
31 locked ? 'T' : 'F', inode->refcount);
33 g_print(" Type: %d Mode: %o\n", inode->type, inode->mode);
34 g_print(" change_count = %"PRIu64", change_commit = %"PRIu64", "
35 "change_cloud = %"PRIu64"\n",
36 inode->change_count, inode->change_commit, inode->change_cloud);
39 static void cloudlog_dump(gpointer key, gpointer value, gpointer user_data)
41 BlueSkyCloudLog *log = (BlueSkyCloudLog *)value;
43 for (int i = 0; i < sizeof(BlueSkyCloudID); i++) {
44 g_print("%02x", (uint8_t)(log->id.bytes[i]));
46 g_print(": refs=%d ty=%d inode=%"PRIu64" locs=%x log@(%d,%d) cloud@(%d,%d,%d)\n",
49 log->location_flags | (log->data != NULL ? 0x100 : 0),
50 log->log_seq, log->log_offset, log->location.directory,
51 log->location.sequence, log->location.offset);
54 static void cache_dump(gpointer key, gpointer value, gpointer user_data)
56 BlueSkyCacheFile *cache = (BlueSkyCacheFile *)value;
58 int64_t age = bluesky_get_current_time() - cache->atime;
59 g_print("%s addr=%p mapcount=%d refcount=%d atime_age=%f",
60 cache->filename, cache->addr, cache->mapcount, cache->refcount,
63 g_print(" (fetching)");
68 void inode_map_dump(GSequence *inode_map)
72 g_print("\nInode map dump:\n");
73 for (i = g_sequence_get_begin_iter(inode_map);
74 !g_sequence_iter_is_end(i); i = g_sequence_iter_next(i))
76 InodeMapRange *range = (InodeMapRange *)g_sequence_get(i);
78 g_print(" Range [%"PRIu64", %"PRIu64"]\n", range->start, range->end);
80 for (j = g_sequence_get_begin_iter(range->map_entries);
81 !g_sequence_iter_is_end(j); j = g_sequence_iter_next(j))
83 InodeMapEntry *entry = (InodeMapEntry *)g_sequence_get(j);
84 char *id = bluesky_cloudlog_id_to_string(entry->id);
85 g_print(" Entry %"PRIu64" id=%s\n", entry->inum, id);
90 /* Dump a summary of filesystem state as it is cached in memory. */
91 void bluesky_debug_dump(BlueSkyFS *fs)
93 g_print("\n*** DEBUG DUMP FOR FILESYSTEM %s ***\n", fs->name);
94 g_print("Dirty blocks: %d\n", g_atomic_int_get(&fs->cache_dirty));
95 g_print("Cached inodes: %u\tNext inode: %"PRIu64"\n",
96 g_hash_table_size(fs->inodes), fs->next_inum);
97 g_print("Cloudlog cache: %d dirty, %d writeback, %d journal, %d cloud\n",
98 g_atomic_int_get(&fs->cache_log_dirty),
99 g_atomic_int_get(&fs->cache_log_writeback),
100 g_atomic_int_get(&fs->cache_log_journal),
101 g_atomic_int_get(&fs->cache_log_cloud));
104 g_print("Unsynced inode list:");
105 for (item = fs->unlogged_list.next; item != NULL; item = item->next) {
106 g_print(" %"PRIu64";", ((BlueSkyInode *)item->data)->inum);
109 g_print("Dirty inode LRU list:");
110 for (item = fs->dirty_list.next; item != NULL; item = item->next) {
111 g_print(" %"PRIu64";", ((BlueSkyInode *)item->data)->inum);
114 g_print("Accessed inode LRU list:");
115 for (item = fs->accessed_list.next; item != NULL; item = item->next) {
116 g_print(" %"PRIu64";", ((BlueSkyInode *)item->data)->inum);
120 g_hash_table_foreach(fs->inodes, inode_dump, fs);
122 g_print("\nLog Objects:\n");
123 g_hash_table_foreach(fs->locations, cloudlog_dump, fs);
125 g_print("\nJournal/Cache Files:\n");
126 g_hash_table_foreach(fs->log->mmap_cache, cache_dump, fs);
129 g_mutex_lock(fs->lock);
130 inode_map_dump(fs->inode_map);
131 g_mutex_unlock(fs->lock);
134 /* Statistics counters: for operation counts, bytes transferred, etc. */
135 static GStaticMutex stats_lock = G_STATIC_MUTEX_INIT;
136 static GList *stats_list = NULL;
138 struct bluesky_stats *bluesky_stats_new(const char *name)
140 struct bluesky_stats *stats = g_new0(struct bluesky_stats, 1);
142 g_static_mutex_lock(&stats_lock);
143 stats_list = g_list_append(stats_list, stats);
144 g_static_mutex_unlock(&stats_lock);
148 void bluesky_stats_add(struct bluesky_stats *stats, int64_t value)
150 __sync_fetch_and_add(&stats->count, (int64_t)1);
151 __sync_fetch_and_add(&stats->sum, value);
154 void bluesky_stats_dump_all()
156 g_static_mutex_lock(&stats_lock);
157 for (GList *item = stats_list; item != NULL; item = item->next) {
158 struct bluesky_stats *stats = (struct bluesky_stats *)item->data;
159 g_print("%s: count=%"PRIi64" sum=%"PRIi64"\n",
160 stats->name, stats->count, stats->sum);
162 g_static_mutex_unlock(&stats_lock);