Do not signal barrier until all notifiers have run.
[bluesky.git] / bluesky / bluesky-private.h
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 /* 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. */
12
13 #ifndef _BLUESKY_PRIVATE_H
14 #define _BLUESKY_PRIVATE_H
15
16 #include "bluesky.h"
17
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21
22 /* TODO: Make this go away entirely. */
23 BlueSkyFS *bluesky_new_fs(gchar *name);
24
25 /* Serialization and deserialization of filesystem data for storing to
26  * persistent storage. */
27 void bluesky_serialize_superblock(GString *out, BlueSkyFS *fs);
28 BlueSkyFS *bluesky_deserialize_superblock(const gchar *buf);
29 void bluesky_serialize_inode(GString *out, BlueSkyInode *inode);
30 gboolean bluesky_deserialize_inode(BlueSkyInode *inode, const gchar *buf);
31
32 /* Storage layer.  Requests can be performed asynchronously, so these objects
33  * help keep track of operations in progress. */
34 typedef enum {
35     STORE_OP_NONE,
36     STORE_OP_GET,
37     STORE_OP_PUT,
38     STORE_OP_DELETE,
39     STORE_OP_BARRIER,       // Waits for other selected operations to complete
40 } BlueSkyStoreOp;
41
42 typedef enum {
43     ASYNC_NEW,              // Operation not yet submitted to storage layer
44     ASYNC_PENDING,          // Submitted to storage layer
45     ASYNC_RUNNING,          // Operation is in progress
46     ASYNC_COMPLETE,         // Operation finished, results available
47 } BlueSkyAsyncStatus;
48
49 struct BlueSkyNotifierList;
50 typedef struct _BlueSkyStoreAsync BlueSkyStoreAsync;
51 struct _BlueSkyStoreAsync {
52     BlueSkyStore *store;
53
54     GMutex *lock;
55     GCond *completion_cond;     /* Used to wait for operation to complete. */
56
57     gint refcount;              /* Reference count for destruction. */
58
59     BlueSkyAsyncStatus status;
60
61     BlueSkyStoreOp op;
62     gchar *key;                 /* Key to read/write */
63     BlueSkyRCStr *data;         /* Data read/to write */
64
65     int result;                 /* Result code; 0 for success. */
66     struct BlueSkyNotifierList *notifiers;
67     gint notifier_count;
68
69     /* The barrier waiting on this operation.  Support for more than one
70      * barrier for a single async is not well-supported and should be avoided
71      * if possible. */
72     BlueSkyStoreAsync *barrier;
73
74     bluesky_time_hires start_time;  /* Time operation was submitted. */
75
76     gpointer store_private;     /* For use by the storage implementation */
77 };
78
79 /* Support for notification lists.  These are lists of one-shot functions which
80  * can be called when certain events--primarily, competed storage
81  * events--occur.  Multiple notifiers can be added, but no particular order is
82  * guaranteed for the notification functions to be called. */
83 struct BlueSkyNotifierList {
84     struct BlueSkyNotifierList *next;
85     GFunc func;
86     BlueSkyStoreAsync *async;
87     gpointer user_data;     // Passed to the function when called
88 };
89
90 /* The abstraction layer for storage, allowing multiple implementations. */
91 typedef struct {
92     /* Create a new store instance and return a handle to it. */
93     gpointer (*create)(const gchar *path);
94
95     /* Clean up any resources used by this store. */
96     void (*destroy)(gpointer store);
97
98     /* Submit an operation (get/put/delete) to the storage layer to be
99      * performed asynchronously. */
100     void (*submit)(gpointer store, BlueSkyStoreAsync *async);
101
102     /* Clean up any implementation-private data in a BlueSkyStoreAsync. */
103     void (*cleanup)(gpointer store, BlueSkyStoreAsync *async);
104 } BlueSkyStoreImplementation;
105
106 void bluesky_store_register(const BlueSkyStoreImplementation *impl,
107                             const gchar *name);
108
109 BlueSkyStoreAsync *bluesky_store_async_new(BlueSkyStore *store);
110 gpointer bluesky_store_async_get_handle(BlueSkyStoreAsync *async);
111 void bluesky_store_async_ref(BlueSkyStoreAsync *async);
112 void bluesky_store_async_unref(BlueSkyStoreAsync *async);
113 void bluesky_store_async_wait(BlueSkyStoreAsync *async);
114 void bluesky_store_async_add_notifier(BlueSkyStoreAsync *async,
115                                       GFunc func, gpointer user_data);
116 void bluesky_store_async_mark_complete(BlueSkyStoreAsync *async);
117 void bluesky_store_async_submit(BlueSkyStoreAsync *async);
118 void bluesky_store_sync(BlueSkyStore *store);
119
120 void bluesky_store_add_barrier(BlueSkyStoreAsync *barrier,
121                                BlueSkyStoreAsync *async);
122
123 void bluesky_inode_start_sync(BlueSkyInode *inode, BlueSkyStoreAsync *barrier);
124
125 void bluesky_block_touch(BlueSkyInode *inode, uint64_t i);
126 void bluesky_block_fetch(BlueSkyFS *fs, BlueSkyBlock *block,
127                          BlueSkyStoreAsync *barrier);
128 void bluesky_block_flush(BlueSkyFS *fs, BlueSkyBlock *block,
129                          BlueSkyStoreAsync *barrier);
130 void bluesky_file_flush(BlueSkyInode *inode, BlueSkyStoreAsync *barrier);
131 void bluesky_file_drop_cached(BlueSkyInode *inode);
132
133 #ifdef __cplusplus
134 }
135 #endif
136
137 #endif