Allow batched log writes when writing dirty inodes.
[bluesky.git] / bluesky / bluesky-private.h
index 35616d7..039e253 100644 (file)
 extern "C" {
 #endif
 
+extern int bluesky_verbose;
+
+/* Target cache size levels. */
+extern int bluesky_watermark_low_dirty;
+extern int bluesky_watermark_medium_dirty;
+extern int bluesky_watermark_high_dirty;
+
+extern int bluesky_watermark_low_total;
+extern int bluesky_watermark_medium_total;
+extern int bluesky_watermark_high_total;
+
+/* TODO: Make this go away entirely. */
 BlueSkyFS *bluesky_new_fs(gchar *name);
 
+/* Linked list update functions for LRU lists. */
+void bluesky_list_unlink(GList *head, GList *item);
+GList *bluesky_list_prepend(GList *head, BlueSkyInode *inode);
+GList *bluesky_list_append(GList *head, BlueSkyInode *inode);
+BlueSkyInode *bluesky_list_head(GList *head);
+BlueSkyInode *bluesky_list_tail(GList *head);
+
+/* Serialization and deserialization of filesystem data for storing to
+ * persistent storage. */
+void bluesky_serialize_superblock(GString *out, BlueSkyFS *fs);
+BlueSkyFS *bluesky_deserialize_superblock(const gchar *buf);
+void bluesky_serialize_inode(GString *out, BlueSkyInode *inode);
+gboolean bluesky_deserialize_inode(BlueSkyInode *inode, const gchar *buf);
+
+/* Storage layer.  Requests can be performed asynchronously, so these objects
+ * help keep track of operations in progress. */
+typedef enum {
+    STORE_OP_NONE,
+    STORE_OP_GET,
+    STORE_OP_PUT,
+    STORE_OP_DELETE,
+    STORE_OP_BARRIER,       // Waits for other selected operations to complete
+} BlueSkyStoreOp;
+
+typedef enum {
+    ASYNC_NEW,              // Operation not yet submitted to storage layer
+    ASYNC_PENDING,          // Submitted to storage layer
+    ASYNC_RUNNING,          // Operation is in progress
+    ASYNC_COMPLETE,         // Operation finished, results available
+} BlueSkyAsyncStatus;
+
+struct BlueSkyNotifierList;
+typedef struct _BlueSkyStoreAsync BlueSkyStoreAsync;
+struct _BlueSkyStoreAsync {
+    BlueSkyStore *store;
+
+    GMutex *lock;
+    GCond *completion_cond;     /* Used to wait for operation to complete. */
+
+    gint refcount;              /* Reference count for destruction. */
+
+    BlueSkyAsyncStatus status;
+
+    BlueSkyStoreOp op;
+    gchar *key;                 /* Key to read/write */
+    BlueSkyRCStr *data;         /* Data read/to write */
+
+    int result;                 /* Result code; 0 for success. */
+    struct BlueSkyNotifierList *notifiers;
+    gint notifier_count;
+
+    /* The barrier waiting on this operation.  Support for more than one
+     * barrier for a single async is not well-supported and should be avoided
+     * if possible. */
+    BlueSkyStoreAsync *barrier;
+
+    bluesky_time_hires start_time;  /* Time operation was submitted. */
+    bluesky_time_hires exec_time;   /* Time processing started on operation. */
+
+    gpointer store_private;     /* For use by the storage implementation */
+};
+
+/* Support for notification lists.  These are lists of one-shot functions which
+ * can be called when certain events--primarily, competed storage
+ * events--occur.  Multiple notifiers can be added, but no particular order is
+ * guaranteed for the notification functions to be called. */
+struct BlueSkyNotifierList {
+    struct BlueSkyNotifierList *next;
+    GFunc func;
+    BlueSkyStoreAsync *async;
+    gpointer user_data;     // Passed to the function when called
+};
+
+/* The abstraction layer for storage, allowing multiple implementations. */
+typedef struct {
+    /* Create a new store instance and return a handle to it. */
+    gpointer (*create)(const gchar *path);
+
+    /* Clean up any resources used by this store. */
+    void (*destroy)(gpointer store);
+
+    /* Submit an operation (get/put/delete) to the storage layer to be
+     * performed asynchronously. */
+    void (*submit)(gpointer store, BlueSkyStoreAsync *async);
+
+    /* Clean up any implementation-private data in a BlueSkyStoreAsync. */
+    void (*cleanup)(gpointer store, BlueSkyStoreAsync *async);
+} BlueSkyStoreImplementation;
+
+void bluesky_store_register(const BlueSkyStoreImplementation *impl,
+                            const gchar *name);
+
+BlueSkyStoreAsync *bluesky_store_async_new(BlueSkyStore *store);
+gpointer bluesky_store_async_get_handle(BlueSkyStoreAsync *async);
+void bluesky_store_async_ref(BlueSkyStoreAsync *async);
+void bluesky_store_async_unref(BlueSkyStoreAsync *async);
+void bluesky_store_async_wait(BlueSkyStoreAsync *async);
+void bluesky_store_async_add_notifier(BlueSkyStoreAsync *async,
+                                      GFunc func, gpointer user_data);
+void bluesky_store_async_mark_complete(BlueSkyStoreAsync *async);
+void bluesky_store_async_submit(BlueSkyStoreAsync *async);
+void bluesky_store_sync(BlueSkyStore *store);
+
+void bluesky_store_add_barrier(BlueSkyStoreAsync *barrier,
+                               BlueSkyStoreAsync *async);
+
+void bluesky_inode_start_sync(BlueSkyInode *inode, BlueSkyStoreAsync *barrier);
+
+void bluesky_block_touch(BlueSkyInode *inode, uint64_t i);
+void bluesky_block_fetch(BlueSkyFS *fs, BlueSkyBlock *block,
+                         BlueSkyStoreAsync *barrier);
+void bluesky_block_flush(BlueSkyFS *fs, BlueSkyBlock *block,
+                         BlueSkyStoreAsync *barrier, GList **log_items);
+void bluesky_file_flush(BlueSkyInode *inode, BlueSkyStoreAsync *barrier,
+                        GList **log_items);
+void bluesky_file_drop_cached(BlueSkyInode *inode);
+
+/* Logging infrastructure for ensuring operations are persistently recorded to
+ * disk. */
+struct _BlueSkyLog {
+    char *log_directory;
+    GAsyncQueue *queue;
+    int fd;
+    int seq_num;
+};
+
+typedef struct {
+    gboolean committed;
+    GMutex *lock;
+    GCond *cond;
+    char *key;
+    BlueSkyRCStr *data;
+} BlueSkyLogItem;
+
+BlueSkyLog *bluesky_log_new(const char *log_directory);
+BlueSkyLogItem *bluesky_log_item_new();
+void bluesky_log_item_submit(BlueSkyLogItem *item, BlueSkyLog *log);
+void bluesky_log_item_finish(BlueSkyLogItem *item);
+
 #ifdef __cplusplus
 }
 #endif