+/* 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);
+}