X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=bluesky%2Fbluesky.h;h=7419cd439daa2082fa6db0fca37db09b2fa590ee;hb=03476a3d39444ff2a09174e945ab645508c2224c;hp=856dd75a6244bce3b1bf22ba65a6f4cb01373abf;hpb=70fdd2326239a9a5e02b3c3699d2588d5fee48fa;p=bluesky.git diff --git a/bluesky/bluesky.h b/bluesky/bluesky.h index 856dd75..7419cd4 100644 --- a/bluesky/bluesky.h +++ b/bluesky/bluesky.h @@ -16,7 +16,9 @@ extern "C" { #endif -struct S3Store; +void bluesky_init(void); + +gchar *bluesky_lowercase(const gchar *s); /* Reference-counted blocks of memory, used for passing data in and out of * storage backends and in other places. */ @@ -31,6 +33,44 @@ void bluesky_string_ref(BlueSkyRCStr *string); void bluesky_string_unref(BlueSkyRCStr *string); BlueSkyRCStr *bluesky_string_dup(BlueSkyRCStr *string); +/* Cryptographic operations. */ +#define CRYPTO_BLOCK_SIZE 16 /* 128-bit AES */ +#define CRYPTO_KEY_SIZE 16 + +void bluesky_crypt_init(); +void bluesky_crypt_random_bytes(guchar *buf, gint len); +BlueSkyRCStr *bluesky_crypt_encrypt(BlueSkyRCStr *in, const uint8_t *key); +BlueSkyRCStr *bluesky_crypt_decrypt(BlueSkyRCStr *in, const uint8_t *key); + +/* Storage interface. This presents a key-value store abstraction, and can + * have multiple implementations: in-memory, on-disk, in-cloud. */ +typedef struct { + /* Create a new store instance and return a handle to it. */ + gpointer (*create)(); + + /* Clean up any resources used by this store. */ + void (*destroy)(gpointer store); + + /* Fetch an item with the given name, or return NULL if not found. */ + BlueSkyRCStr * (*get)(gpointer store, const gchar *key); + + /* Store an item to the given key name. */ + void (*put)(gpointer store, const gchar *key, BlueSkyRCStr *val); +} BlueSkyStoreImplementation; + +void bluesky_store_register(const BlueSkyStoreImplementation *impl, + const gchar *name); + +struct _BlueSkyStore; +typedef struct _BlueSkyStore BlueSkyStore; + +void bluesky_store_init(); +BlueSkyStore *bluesky_store_new(const gchar *type); +void bluesky_store_free(BlueSkyStore *store); +BlueSkyRCStr *bluesky_store_get(BlueSkyStore *store, const gchar *key); +void bluesky_store_put(BlueSkyStore *store, + const gchar *key, BlueSkyRCStr *val); + /* File types. The numeric values are chosen to match with those used in * NFSv3. */ typedef enum { @@ -52,7 +92,9 @@ typedef struct { GHashTable *inodes; /* Cached inodes */ uint64_t next_inum; /* Next available inode for allocation */ - struct S3Store *store; + BlueSkyStore *store; + + uint8_t *encryption_key; } BlueSkyFS; /* Inode number of the root directory. */ @@ -63,10 +105,18 @@ typedef int64_t bluesky_time; /* In-memory representation of an inode within a Blue Sky server. This * corresponds roughly with information that is committed to persistent - * storage. */ + * storage. Locking/refcounting rules: + * - To access or modify any data fields, the lock must be held. This + * includes file blocks. + * - One reference is held by the BlueSkyFS inode hash table. If that is the + * only reference (and the inode is unlocked), the inode is subject to + * dropping from the cache. + * - Any pending operations should hold extra references to the inode as + * appropriate to keep it available until the operation completes. + * */ typedef struct { - gint refcnt; /* May be accessed atomically without lock */ GMutex *lock; + gint refcount; BlueSkyFS *fs; @@ -80,7 +130,12 @@ typedef struct { * that we don't exhaust the identifier space. */ uint64_t inum; - uint64_t change_count; /* Incremented each with each change made */ + /* change_count is increased with every operation which modifies the inode, + * and can be used to determine if cached data is still valid. + * change_commit is the value of change_count when the inode was last + * committed to stable storage. */ + uint64_t change_count, change_commit; + int64_t atime; /* Microseconds since the Unix epoch */ int64_t ctime; int64_t mtime; @@ -151,9 +206,13 @@ void bluesky_file_write(BlueSkyInode *inode, uint64_t offset, void bluesky_file_read(BlueSkyInode *inode, uint64_t offset, char *buf, gint len); -struct S3Store *s3store_new(); -BlueSkyRCStr *s3store_get(struct S3Store *store, const gchar *key); -void s3store_put(struct S3Store *store, const gchar *key, BlueSkyRCStr *val); +void bluesky_inode_flush(BlueSkyFS *fs, BlueSkyInode *inode); +void bluesky_inode_fetch(BlueSkyFS *fs, uint64_t inum); +void bluesky_serialize_inode(GString *out, BlueSkyInode *inode); +BlueSkyInode *bluesky_deserialize_inode(BlueSkyFS *fs, const gchar *buf); + +gint bluesky_dirent_compare(gconstpointer a, gconstpointer b, + gpointer unused); #ifdef __cplusplus }