Rework the storage interface so that operations are asynchronous.
[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 BlueSkyInode *bluesky_deserialize_inode(BlueSkyFS *fs, 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 } BlueSkyStoreOp;
40
41 typedef enum {
42     ASYNC_NEW,              // Operation not yet submitted to storage layer
43     ASYNC_PENDING,          // Submitted to storage layer
44     ASYNC_RUNNING,          // Operation is in progress
45     ASYNC_COMPLETE,         // Operation finished, results available
46 } BlueSkyAsyncStatus;
47
48 typedef struct {
49     BlueSkyStore *store;
50
51     GMutex *lock;
52     GCond *completion_cond;     /* Used to wait for operation to complete. */
53
54     BlueSkyAsyncStatus status;
55
56     BlueSkyStoreOp op;
57     gchar *key;                 /* Key to read/write */
58     BlueSkyRCStr *data;         /* Data read/to write */
59
60     int result;                 /* Result code; 0 for success. */
61
62     gpointer store_private;     /* For use by the storage implementation */
63 } BlueSkyStoreAsync;
64
65 /* The abstraction layer for storage, allowing multiple implementations. */
66 typedef struct {
67     /* Create a new store instance and return a handle to it. */
68     gpointer (*create)();
69
70     /* Clean up any resources used by this store. */
71     void (*destroy)(gpointer store);
72
73     /* Submit an operation (get/put/delete) to the storage layer to be
74      * performed asynchronously. */
75     void (*submit)(gpointer store, BlueSkyStoreAsync *async);
76
77     /* Clean up any implementation-private data in a BlueSkyStoreAsync. */
78     void (*cleanup)(gpointer store, BlueSkyStoreAsync *async);
79 } BlueSkyStoreImplementation;
80
81 void bluesky_store_register(const BlueSkyStoreImplementation *impl,
82                             const gchar *name);
83
84 BlueSkyStoreAsync *bluesky_store_async_new(BlueSkyStore *store);
85 void bluesky_store_async_wait(BlueSkyStoreAsync *async);
86 void bluesky_store_async_mark_complete(BlueSkyStoreAsync *async);
87
88 #ifdef __cplusplus
89 }
90 #endif
91
92 #endif