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