Initial work on proper writeback caching.
authorMichael Vrable <mvrable@cs.ucsd.edu>
Sun, 6 Dec 2009 18:02:13 +0000 (10:02 -0800)
committerMichael Vrable <mvrable@cs.ucsd.edu>
Sun, 6 Dec 2009 18:02:13 +0000 (10:02 -0800)
bluesky/CMakeLists.txt
bluesky/bluesky.h
bluesky/cache.c [new file with mode: 0644]
bluesky/inode.c
bluesky/store.c

index aa5b5c5..b1e7343 100644 (file)
@@ -2,11 +2,11 @@ include_directories("${LIBS3_BUILD_DIR}/include")
 link_directories("${LIBS3_BUILD_DIR}/lib")
 
 add_library(bluesky SHARED
-            crypto.c dir.c file.c init.c inode.c serialize.c store.c s3store.c
-            util.c)
+            cache.c crypto.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 "-std=gnu99 ${CMAKE_C_FLAGS}")
+set(CMAKE_C_FLAGS "-Wall -std=gnu99 ${CMAKE_C_FLAGS}")
 set(INSTALL_RPATH_USE_LINK_PATH 1)
 
 include_directories(${GLIB_INCLUDE_DIRS})
index 7f237d3..17a9540 100644 (file)
@@ -228,6 +228,8 @@ void bluesky_inode_fetch(BlueSkyFS *fs, uint64_t inum);
 gint bluesky_dirent_compare(gconstpointer a, gconstpointer b,
                             gpointer unused);
 
+void bluesky_flushd_invoke(BlueSkyFS *fs);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/bluesky/cache.c b/bluesky/cache.c
new file mode 100644 (file)
index 0000000..f953a64
--- /dev/null
@@ -0,0 +1,47 @@
+/* Blue Sky: File Systems in the Cloud
+ *
+ * Copyright (C) 2009  The Regents of the University of California
+ * Written by Michael Vrable <mvrable@cs.ucsd.edu>
+ *
+ * TODO: Licensing
+ */
+
+#include <stdint.h>
+#include <glib.h>
+#include <string.h>
+#include <inttypes.h>
+
+#include "bluesky-private.h"
+
+/* Filesystem caching and cache coherency. */
+
+static void flushd_inode(gpointer key, gpointer value, gpointer user_data)
+{
+    BlueSkyFS *fs = (BlueSkyFS *)user_data;
+
+    BlueSkyInode *inode = (BlueSkyInode *)value;
+
+    if (inode->change_count == inode->change_commit)
+        return;
+
+    g_log("bluesky/flushd", G_LOG_LEVEL_DEBUG,
+          "Starting flush of inode %"PRIu64, inode->inum);
+
+    if (inode->type == BLUESKY_REGULAR)
+        bluesky_file_flush(inode);
+    bluesky_inode_flush(fs, inode);
+}
+
+/* Scan through the cache for dirty data and start flushing it to stable
+ * storage.  This does not guarantee that data is committed when it returns.
+ * Instead, this can be called occasionally to ensure that dirty data is
+ * gradually flushed. */
+void bluesky_flushd_invoke(BlueSkyFS *fs)
+{
+    g_log("bluesky/flushd", G_LOG_LEVEL_DEBUG,
+          "Writeout process invoked");
+
+    g_mutex_lock(fs->lock);
+    g_hash_table_foreach(fs->inodes, flushd_inode, fs);
+    g_mutex_unlock(fs->lock);
+}
index a264f35..438e59f 100644 (file)
@@ -200,7 +200,7 @@ void bluesky_insert_inode(BlueSkyFS *fs, BlueSkyInode *inode)
     g_hash_table_insert(fs->inodes, &inode->inum, inode);
 }
 
-/* Synchronize an inode to stable storage. */
+/* Deprecated: Synchronize an inode to stable storage. */
 void bluesky_inode_flush(BlueSkyFS *fs, BlueSkyInode *inode)
 {
     GString *buf = g_string_new("");
@@ -218,6 +218,24 @@ void bluesky_inode_flush(BlueSkyFS *fs, BlueSkyInode *inode)
     bluesky_store_async_unref(async);
 }
 
+/* Start writeback of an inode and all associated data. */
+void bluesky_inode_start_sync(BlueSkyInode *inode)
+{
+    GString *buf = g_string_new("");
+    bluesky_serialize_inode(buf, inode);
+    BlueSkyRCStr *data = bluesky_string_new_from_gstring(buf);
+
+    char key[64];
+    sprintf(key, "inode-%016"PRIx64, inode->inum);
+
+    BlueSkyStoreAsync *async = bluesky_store_async_new(fs->store);
+    async->op = STORE_OP_PUT;
+    async->key = g_strdup(key);
+    async->data = data;
+    bluesky_store_async_submit(async);
+    bluesky_store_async_unref(async);
+}
+
 /* Fetch an inode from stable storage. */
 void bluesky_inode_fetch(BlueSkyFS *fs, uint64_t inum)
 {
index 7ca0402..022deeb 100644 (file)
@@ -205,7 +205,6 @@ void bluesky_store_async_submit(BlueSkyStoreAsync *async)
 
 static void op_complete(gpointer a, gpointer b)
 {
-    BlueSkyStoreAsync *async = (BlueSkyStoreAsync *)a;
     BlueSkyStoreAsync *barrier = (BlueSkyStoreAsync *)b;
 
     g_mutex_lock(barrier->lock);