Initial work on proper writeback caching.
[bluesky.git] / bluesky / cache.c
1 /* Blue Sky: File Systems in the Cloud
2  *
3  * Copyright (C) 2009  The Regents of the University of California
4  * Written by Michael Vrable <mvrable@cs.ucsd.edu>
5  *
6  * TODO: Licensing
7  */
8
9 #include <stdint.h>
10 #include <glib.h>
11 #include <string.h>
12 #include <inttypes.h>
13
14 #include "bluesky-private.h"
15
16 /* Filesystem caching and cache coherency. */
17
18 static void flushd_inode(gpointer key, gpointer value, gpointer user_data)
19 {
20     BlueSkyFS *fs = (BlueSkyFS *)user_data;
21
22     BlueSkyInode *inode = (BlueSkyInode *)value;
23
24     if (inode->change_count == inode->change_commit)
25         return;
26
27     g_log("bluesky/flushd", G_LOG_LEVEL_DEBUG,
28           "Starting flush of inode %"PRIu64, inode->inum);
29
30     if (inode->type == BLUESKY_REGULAR)
31         bluesky_file_flush(inode);
32     bluesky_inode_flush(fs, inode);
33 }
34
35 /* Scan through the cache for dirty data and start flushing it to stable
36  * storage.  This does not guarantee that data is committed when it returns.
37  * Instead, this can be called occasionally to ensure that dirty data is
38  * gradually flushed. */
39 void bluesky_flushd_invoke(BlueSkyFS *fs)
40 {
41     g_log("bluesky/flushd", G_LOG_LEVEL_DEBUG,
42           "Writeout process invoked");
43
44     g_mutex_lock(fs->lock);
45     g_hash_table_foreach(fs->inodes, flushd_inode, fs);
46     g_mutex_unlock(fs->lock);
47 }