More work on synchronous/asynchronous operations.
[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     gint refcount;              /* Reference count for destruction. */
55
56     BlueSkyAsyncStatus status;
57
58     BlueSkyStoreOp op;
59     gchar *key;                 /* Key to read/write */
60     BlueSkyRCStr *data;         /* Data read/to write */
61
62     int result;                 /* Result code; 0 for success. */
63
64     gpointer store_private;     /* For use by the storage implementation */
65 } BlueSkyStoreAsync;
66
67 /* The abstraction layer for storage, allowing multiple implementations. */
68 typedef struct {
69     /* Create a new store instance and return a handle to it. */
70     gpointer (*create)();
71
72     /* Clean up any resources used by this store. */
73     void (*destroy)(gpointer store);
74
75     /* Submit an operation (get/put/delete) to the storage layer to be
76      * performed asynchronously. */
77     void (*submit)(gpointer store, BlueSkyStoreAsync *async);
78
79     /* Clean up any implementation-private data in a BlueSkyStoreAsync. */
80     void (*cleanup)(gpointer store, BlueSkyStoreAsync *async);
81 } BlueSkyStoreImplementation;
82
83 void bluesky_store_register(const BlueSkyStoreImplementation *impl,
84                             const gchar *name);
85
86 BlueSkyStoreAsync *bluesky_store_async_new(BlueSkyStore *store);
87 void bluesky_store_async_ref(BlueSkyStoreAsync *async);
88 void bluesky_store_async_unref(BlueSkyStoreAsync *async);
89 void bluesky_store_async_wait(BlueSkyStoreAsync *async);
90 void bluesky_store_async_mark_complete(BlueSkyStoreAsync *async);
91 void bluesky_store_async_submit(BlueSkyStoreAsync *async);
92 void bluesky_store_sync(BlueSkyStore *store);
93
94 #ifdef __cplusplus
95 }
96 #endif
97
98 #endif