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>
9 /* Declarations internal to the BlueSky library. This header file should not
10 * be included by any users of the library (such as any filesystem
11 * proxy)--external users should only include bluesky.h. */
13 #ifndef _BLUESKY_PRIVATE_H
14 #define _BLUESKY_PRIVATE_H
22 /* Target cache size levels. */
23 extern int bluesky_watermark_low_dirty;
24 extern int bluesky_watermark_medium_dirty;
25 extern int bluesky_watermark_high_dirty;
27 /* TODO: Make this go away entirely. */
28 BlueSkyFS *bluesky_new_fs(gchar *name);
30 /* Linked list update functions for LRU lists. */
31 void bluesky_list_unlink(GList *head, GList *item);
32 GList *bluesky_list_prepend(GList *head, BlueSkyInode *inode);
33 GList *bluesky_list_append(GList *head, BlueSkyInode *inode);
34 BlueSkyInode *bluesky_list_head(GList *head);
35 BlueSkyInode *bluesky_list_tail(GList *head);
37 /* Serialization and deserialization of filesystem data for storing to
38 * persistent storage. */
39 void bluesky_serialize_superblock(GString *out, BlueSkyFS *fs);
40 BlueSkyFS *bluesky_deserialize_superblock(const gchar *buf);
41 void bluesky_serialize_inode(GString *out, BlueSkyInode *inode);
42 gboolean bluesky_deserialize_inode(BlueSkyInode *inode, const gchar *buf);
44 /* Storage layer. Requests can be performed asynchronously, so these objects
45 * help keep track of operations in progress. */
51 STORE_OP_BARRIER, // Waits for other selected operations to complete
55 ASYNC_NEW, // Operation not yet submitted to storage layer
56 ASYNC_PENDING, // Submitted to storage layer
57 ASYNC_RUNNING, // Operation is in progress
58 ASYNC_COMPLETE, // Operation finished, results available
61 struct BlueSkyNotifierList;
62 typedef struct _BlueSkyStoreAsync BlueSkyStoreAsync;
63 struct _BlueSkyStoreAsync {
67 GCond *completion_cond; /* Used to wait for operation to complete. */
69 gint refcount; /* Reference count for destruction. */
71 BlueSkyAsyncStatus status;
74 gchar *key; /* Key to read/write */
75 BlueSkyRCStr *data; /* Data read/to write */
77 int result; /* Result code; 0 for success. */
78 struct BlueSkyNotifierList *notifiers;
81 /* The barrier waiting on this operation. Support for more than one
82 * barrier for a single async is not well-supported and should be avoided
84 BlueSkyStoreAsync *barrier;
86 bluesky_time_hires start_time; /* Time operation was submitted. */
87 bluesky_time_hires exec_time; /* Time processing started on operation. */
89 gpointer store_private; /* For use by the storage implementation */
92 /* Support for notification lists. These are lists of one-shot functions which
93 * can be called when certain events--primarily, competed storage
94 * events--occur. Multiple notifiers can be added, but no particular order is
95 * guaranteed for the notification functions to be called. */
96 struct BlueSkyNotifierList {
97 struct BlueSkyNotifierList *next;
99 BlueSkyStoreAsync *async;
100 gpointer user_data; // Passed to the function when called
103 /* The abstraction layer for storage, allowing multiple implementations. */
105 /* Create a new store instance and return a handle to it. */
106 gpointer (*create)(const gchar *path);
108 /* Clean up any resources used by this store. */
109 void (*destroy)(gpointer store);
111 /* Submit an operation (get/put/delete) to the storage layer to be
112 * performed asynchronously. */
113 void (*submit)(gpointer store, BlueSkyStoreAsync *async);
115 /* Clean up any implementation-private data in a BlueSkyStoreAsync. */
116 void (*cleanup)(gpointer store, BlueSkyStoreAsync *async);
117 } BlueSkyStoreImplementation;
119 void bluesky_store_register(const BlueSkyStoreImplementation *impl,
122 BlueSkyStoreAsync *bluesky_store_async_new(BlueSkyStore *store);
123 gpointer bluesky_store_async_get_handle(BlueSkyStoreAsync *async);
124 void bluesky_store_async_ref(BlueSkyStoreAsync *async);
125 void bluesky_store_async_unref(BlueSkyStoreAsync *async);
126 void bluesky_store_async_wait(BlueSkyStoreAsync *async);
127 void bluesky_store_async_add_notifier(BlueSkyStoreAsync *async,
128 GFunc func, gpointer user_data);
129 void bluesky_store_async_mark_complete(BlueSkyStoreAsync *async);
130 void bluesky_store_async_submit(BlueSkyStoreAsync *async);
131 void bluesky_store_sync(BlueSkyStore *store);
133 void bluesky_store_add_barrier(BlueSkyStoreAsync *barrier,
134 BlueSkyStoreAsync *async);
136 void bluesky_inode_start_sync(BlueSkyInode *inode, BlueSkyStoreAsync *barrier);
138 void bluesky_block_touch(BlueSkyInode *inode, uint64_t i);
139 void bluesky_block_fetch(BlueSkyFS *fs, BlueSkyBlock *block,
140 BlueSkyStoreAsync *barrier);
141 void bluesky_block_flush(BlueSkyFS *fs, BlueSkyBlock *block,
142 BlueSkyStoreAsync *barrier);
143 void bluesky_file_flush(BlueSkyInode *inode, BlueSkyStoreAsync *barrier);
144 void bluesky_file_drop_cached(BlueSkyInode *inode);