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 extern int bluesky_verbose;
24 /* Target cache size levels. */
25 extern int bluesky_watermark_low_dirty;
26 extern int bluesky_watermark_medium_dirty;
27 extern int bluesky_watermark_high_dirty;
29 extern int bluesky_watermark_low_total;
30 extern int bluesky_watermark_medium_total;
31 extern int bluesky_watermark_high_total;
33 /* TODO: Make this go away entirely. */
34 BlueSkyFS *bluesky_new_fs(gchar *name);
36 /* Linked list update functions for LRU lists. */
37 void bluesky_list_unlink(GList *head, GList *item);
38 GList *bluesky_list_prepend(GList *head, BlueSkyInode *inode);
39 GList *bluesky_list_append(GList *head, BlueSkyInode *inode);
40 BlueSkyInode *bluesky_list_head(GList *head);
41 BlueSkyInode *bluesky_list_tail(GList *head);
43 /* Serialization and deserialization of filesystem data for storing to
44 * persistent storage. */
45 void bluesky_serialize_superblock(GString *out, BlueSkyFS *fs);
46 BlueSkyFS *bluesky_deserialize_superblock(const gchar *buf);
47 BlueSkyCloudLog *bluesky_serialize_inode(BlueSkyInode *inode);
48 gboolean bluesky_deserialize_inode(BlueSkyInode *inode, const gchar *buf);
50 /* Storage layer. Requests can be performed asynchronously, so these objects
51 * help keep track of operations in progress. */
57 STORE_OP_BARRIER, // Waits for other selected operations to complete
61 ASYNC_NEW, // Operation not yet submitted to storage layer
62 ASYNC_PENDING, // Submitted to storage layer
63 ASYNC_RUNNING, // Operation is in progress
64 ASYNC_COMPLETE, // Operation finished, results available
67 struct BlueSkyNotifierList;
68 typedef struct _BlueSkyStoreAsync BlueSkyStoreAsync;
69 struct _BlueSkyStoreAsync {
73 GCond *completion_cond; /* Used to wait for operation to complete. */
75 gint refcount; /* Reference count for destruction. */
77 BlueSkyAsyncStatus status;
80 gchar *key; /* Key to read/write */
81 BlueSkyRCStr *data; /* Data read/to write */
83 int result; /* Result code; 0 for success. */
84 struct BlueSkyNotifierList *notifiers;
87 /* The barrier waiting on this operation. Support for more than one
88 * barrier for a single async is not well-supported and should be avoided
90 BlueSkyStoreAsync *barrier;
92 bluesky_time_hires start_time; /* Time operation was submitted. */
93 bluesky_time_hires exec_time; /* Time processing started on operation. */
95 gpointer store_private; /* For use by the storage implementation */
98 /* Support for notification lists. These are lists of one-shot functions which
99 * can be called when certain events--primarily, competed storage
100 * events--occur. Multiple notifiers can be added, but no particular order is
101 * guaranteed for the notification functions to be called. */
102 struct BlueSkyNotifierList {
103 struct BlueSkyNotifierList *next;
105 BlueSkyStoreAsync *async;
106 gpointer user_data; // Passed to the function when called
109 /* The abstraction layer for storage, allowing multiple implementations. */
111 /* Create a new store instance and return a handle to it. */
112 gpointer (*create)(const gchar *path);
114 /* Clean up any resources used by this store. */
115 void (*destroy)(gpointer store);
117 /* Submit an operation (get/put/delete) to the storage layer to be
118 * performed asynchronously. */
119 void (*submit)(gpointer store, BlueSkyStoreAsync *async);
121 /* Clean up any implementation-private data in a BlueSkyStoreAsync. */
122 void (*cleanup)(gpointer store, BlueSkyStoreAsync *async);
123 } BlueSkyStoreImplementation;
125 void bluesky_store_register(const BlueSkyStoreImplementation *impl,
128 BlueSkyStoreAsync *bluesky_store_async_new(BlueSkyStore *store);
129 gpointer bluesky_store_async_get_handle(BlueSkyStoreAsync *async);
130 void bluesky_store_async_ref(BlueSkyStoreAsync *async);
131 void bluesky_store_async_unref(BlueSkyStoreAsync *async);
132 void bluesky_store_async_wait(BlueSkyStoreAsync *async);
133 void bluesky_store_async_add_notifier(BlueSkyStoreAsync *async,
134 GFunc func, gpointer user_data);
135 void bluesky_store_async_mark_complete(BlueSkyStoreAsync *async);
136 void bluesky_store_async_submit(BlueSkyStoreAsync *async);
137 void bluesky_store_sync(BlueSkyStore *store);
139 void bluesky_store_add_barrier(BlueSkyStoreAsync *barrier,
140 BlueSkyStoreAsync *async);
142 void bluesky_inode_start_sync(BlueSkyInode *inode);
144 void bluesky_block_touch(BlueSkyInode *inode, uint64_t i);
145 void bluesky_block_fetch(BlueSkyInode *inode, BlueSkyBlock *block,
146 BlueSkyStoreAsync *barrier);
147 void bluesky_block_flush(BlueSkyInode *inode, BlueSkyBlock *block,
149 void bluesky_file_flush(BlueSkyInode *inode, GList **log_items);
150 void bluesky_file_drop_cached(BlueSkyInode *inode);
152 /* Writing of data to the cloud in log segments and tracking the location of
153 * various pieces of data (both where in the cloud and where cached locally).
165 } BlueSkyCloudPointer;
168 LOGTYPE_INVALID = -1,
172 LOGTYPE_INODE_MAP = 3,
173 LOGTYPE_CHECKPOINT = 4,
174 LOGTYPE_CHECKPOINT_PTR = 5,
175 } BlueSkyCloudLogType;
177 /* A record which tracks an object which has been written to a local log,
178 * cached, locally, and/or written to the cloud. */
179 #define CLOUDLOG_JOURNAL 0x01
180 #define CLOUDLOG_CLOUD 0x02
181 #define CLOUDLOG_CACHE 0x04
182 struct _BlueSkyCloudLog {
189 BlueSkyCloudLogType type;
191 // Bitmask of CLOUDLOG_* flags indicating where the object exists.
193 int pending_read, pending_write;
195 // A stable identifier for the object (only changes when authenticated data
196 // is written out, but stays the same when the in-cloud cleaner relocates
200 // The inode which owns this data, if any, and an offset.
204 // The location of the object in the cloud, if available.
205 BlueSkyCloudPointer location;
207 // TODO: Location in journal/cache
208 int log_seq, log_offset, log_size;
210 // Pointers to other objects. Each link counts towards the reference count
211 // of the pointed-to object. To avoid memory leaks there should be no
212 // cycles in the reference graph.
215 // Serialized data, if available in memory (otherwise NULL), and a lock
216 // count which tracks if there are users that require the data to be kept
222 /* Serialize objects into a log segment to be written to the cloud. */
223 struct _BlueSkyCloudLogState {
225 BlueSkyCloudPointer location;
229 gboolean bluesky_cloudlog_equal(gconstpointer a, gconstpointer b);
230 guint bluesky_cloudlog_hash(gconstpointer a);
231 BlueSkyCloudLog *bluesky_cloudlog_new(BlueSkyFS *fs);
232 gchar *bluesky_cloudlog_id_to_string(BlueSkyCloudID id);
233 BlueSkyCloudID bluesky_cloudlog_id_from_string(const gchar *idstr);
234 void bluesky_cloudlog_ref(BlueSkyCloudLog *log);
235 void bluesky_cloudlog_unref(BlueSkyCloudLog *log);
236 void bluesky_cloudlog_stats_update(BlueSkyCloudLog *log, int type);
237 void bluesky_cloudlog_sync(BlueSkyCloudLog *log);
238 void bluesky_cloudlog_insert(BlueSkyCloudLog *log);
239 void bluesky_cloudlog_fetch(BlueSkyCloudLog *log);
240 BlueSkyCloudPointer bluesky_cloudlog_serialize(BlueSkyCloudLog *log,
242 void bluesky_cloudlog_flush(BlueSkyFS *fs);
244 /* Logging infrastructure for ensuring operations are persistently recorded to
246 #define BLUESKY_CRC32C_SEED (~(uint32_t)0)
247 uint32_t crc32c(uint32_t crc, const char *buf, unsigned int length);
248 uint32_t crc32c_finalize(uint32_t crc);
257 /* Cache of log segments which have been memory-mapped. */
259 GHashTable *mmap_cache;
262 /* Reference-counted blocks of memory, used for passing data in and out of
263 * storage backends and in other places. This may also refer to read-only
265 struct _BlueSkyMmap {
273 BlueSkyLog *bluesky_log_new(const char *log_directory);
274 void bluesky_log_item_submit(BlueSkyCloudLog *item, BlueSkyLog *log);
275 void bluesky_log_finish_all(GList *log_items);
276 BlueSkyRCStr *bluesky_log_map_object(BlueSkyLog *log, int log_seq,
277 int log_offset, int log_size);
278 void bluesky_mmap_unref(BlueSkyMmap *mmap);