X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=bluesky.h;h=856dd75a6244bce3b1bf22ba65a6f4cb01373abf;hb=d32328c00f54c2f6f4e6eeb8993d33d062e9477c;hp=068173f8c2c2874b06b90487e7102336168224ea;hpb=a6d16121ebce069728e454b9bd4c5716d59c8809;p=bluesky.git diff --git a/bluesky.h b/bluesky.h index 068173f..856dd75 100644 --- a/bluesky.h +++ b/bluesky.h @@ -12,10 +12,28 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + +struct S3Store; + +/* Reference-counted blocks of memory, used for passing data in and out of + * storage backends and in other places. */ +typedef struct { + gint refcount; + gchar *data; + gsize len; +} BlueSkyRCStr; + +BlueSkyRCStr *bluesky_string_new(gpointer data, gsize len); +void bluesky_string_ref(BlueSkyRCStr *string); +void bluesky_string_unref(BlueSkyRCStr *string); +BlueSkyRCStr *bluesky_string_dup(BlueSkyRCStr *string); + /* File types. The numeric values are chosen to match with those used in * NFSv3. */ -enum BlueSkyFileType { - BLUESKY_INVALID = 0, +typedef enum { BLUESKY_REGULAR = 1, BLUESKY_DIRECTORY = 2, BLUESKY_BLOCK = 3, @@ -23,7 +41,7 @@ enum BlueSkyFileType { BLUESKY_SYMLINK = 5, BLUESKY_SOCKET = 6, BLUESKY_FIFO = 7, -}; +} BlueSkyFileType; /* Filesystem state. Each filesystem which is exported is represented by a * single bluesky_fs structure in memory. */ @@ -33,8 +51,13 @@ typedef struct { gchar *name; /* Descriptive name for the filesystem */ GHashTable *inodes; /* Cached inodes */ uint64_t next_inum; /* Next available inode for allocation */ + + struct S3Store *store; } BlueSkyFS; +/* Inode number of the root directory. */ +#define BLUESKY_ROOT_INUM 1 + /* Timestamp, measured in microseconds since the Unix epoch. */ typedef int64_t bluesky_time; @@ -45,7 +68,9 @@ typedef struct { gint refcnt; /* May be accessed atomically without lock */ GMutex *lock; - int type; + BlueSkyFS *fs; + + BlueSkyFileType type; uint32_t mode; uint32_t uid, gid; uint32_t nlink; @@ -63,24 +88,52 @@ typedef struct { /* File-specific fields */ uint64_t size; + GArray *blocks; /* Directory-specific fields */ - GSequence *dirents; + GSequence *dirents; /* List of entries for READDIR */ + GHashTable *dirhash; /* Hash table by name for LOOKUP */ + uint64_t parent_inum; /* inode for ".."; 0 if the root directory */ } BlueSkyInode; /* A directory entry. The name is UTF-8 and is a freshly-allocated string. - * The name is hashed to a 64-bit value, and the directory entries are sorted - * by hash value (the hash value can then be used as a cookie for resuming a - * READDIR call). */ + * Each directory entry is listed in two indices: dirents is indexed by cookie + * and dirhash by name. The cookie is a randomly-assigned 32-bit value, unique + * within the directory, that remains unchanged until the entry is deleted. It + * is used to provide a stable key for restarting a READDIR call. */ typedef struct { gchar *name; - uint64_t hash; + uint32_t cookie; uint64_t inum; -} BlueSkyDirent ; +} BlueSkyDirent; + +/* File data is divided into fixed-size blocks (except the last block which may + * be short?). These blocks are backed by storage in a key/value store, but + * may also be dirty if modifications have been made in-memory that have not + * been committed. */ +#define BLUESKY_BLOCK_SIZE 32768ULL +#define BLUESKY_MAX_FILE_SIZE (BLUESKY_BLOCK_SIZE << 24) +typedef enum { + BLUESKY_BLOCK_ZERO = 0, /* Data is all zeroes, not explicitly stored */ + BLUESKY_BLOCK_REF = 1, /* Reference to key/value store, not cached */ + BLUESKY_BLOCK_CACHED = 2, /* Data is cached in memory, clean */ + BLUESKY_BLOCK_DIRTY = 3, /* Data needs to be committed to store */ +} BlueSkyBlockType; + +typedef struct { + BlueSkyBlockType type; + gchar *ref; /* Name of data block in the backing store */ + BlueSkyRCStr *data; /* Pointer to data in memory if cached */ +} BlueSkyBlock; +BlueSkyFS *bluesky_new_fs(gchar *name); int64_t bluesky_get_current_time(); +void bluesky_inode_update_ctime(BlueSkyInode *inode, gboolean update_mtime); uint64_t bluesky_fs_alloc_inode(BlueSkyFS *fs); -BlueSkyInode *bluesky_new_inode(uint64_t inum); +BlueSkyInode *bluesky_new_inode(uint64_t inum, BlueSkyFS *fs, BlueSkyFileType type); + +BlueSkyInode *bluesky_get_inode(BlueSkyFS *fs, uint64_t inum); +void bluesky_insert_inode(BlueSkyFS *fs, BlueSkyInode *inode); void bluesky_dirent_destroy(gpointer dirent); uint64_t bluesky_directory_hash(gchar *name); @@ -89,4 +142,21 @@ gboolean bluesky_directory_insert(BlueSkyInode *dir, gchar *name, uint64_t inum); void bluesky_directory_dump(BlueSkyInode *dir); +void bluesky_block_touch(BlueSkyInode *inode, uint64_t i); +void bluesky_block_fetch(BlueSkyFS *fs, BlueSkyBlock *block); +void bluesky_block_flush(BlueSkyFS *fs, BlueSkyBlock *block); +void bluesky_file_truncate(BlueSkyInode *inode, uint64_t size); +void bluesky_file_write(BlueSkyInode *inode, uint64_t offset, + const char *data, gint len); +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); + +#ifdef __cplusplus +} +#endif + #endif