X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=bluesky%2Ffile.c;h=b107a40e32337c1f0f3eb5b46a586d1099432a5c;hb=810fdc7bdf0cd13aaa7c88d3c5af5aae24e77254;hp=35ed1dc72b5cfb3a92f0ffd4908c8efa13b46063;hpb=966a43ffed492d387e0d75e56c3984d9001c15b1;p=bluesky.git diff --git a/bluesky/file.c b/bluesky/file.c index 35ed1dc..b107a40 100644 --- a/bluesky/file.c +++ b/bluesky/file.c @@ -225,6 +225,13 @@ static void block_fetch_completion(BlueSkyStoreAsync *async, gpointer data) bluesky_string_unref(block->data); block->data = async->data; bluesky_string_ref(block->data); + + if (block->data == NULL) { + g_warning("Failed to fetch data block from store!\n"); + block->data = bluesky_string_new(g_malloc0(BLUESKY_BLOCK_SIZE), + BLUESKY_BLOCK_SIZE); + } + block->type = BLUESKY_BLOCK_CACHED; } @@ -251,7 +258,8 @@ void bluesky_block_fetch(BlueSkyFS *fs, BlueSkyBlock *block, /* Write the given block to cloud-backed storage and mark it clean. */ void bluesky_block_flush(BlueSkyFS *fs, BlueSkyBlock *block, - BlueSkyStoreAsync *barrier) + BlueSkyStoreAsync *barrier, + GList **log_items) { if (block->type != BLUESKY_BLOCK_DIRTY) return; @@ -262,6 +270,14 @@ void bluesky_block_flush(BlueSkyFS *fs, BlueSkyBlock *block, g_checksum_update(csum, (const guchar *)data->data, data->len); gchar *name = g_strdup(g_checksum_get_string(csum)); + /* Start commit to the local log. */ + BlueSkyLogItem *log_item = bluesky_log_item_new(); + log_item->key = g_strdup(name); + log_item->data = data; + bluesky_string_ref(data); + bluesky_log_item_submit(log_item, fs->log); + *log_items = g_list_prepend(*log_items, log_item); + /* Store the file data asynchronously, and don't bother waiting for a * response. */ BlueSkyStoreAsync *async = bluesky_store_async_new(fs->store); @@ -284,13 +300,14 @@ void bluesky_block_flush(BlueSkyFS *fs, BlueSkyBlock *block, } /* Flush all blocks in a file to stable storage. */ -void bluesky_file_flush(BlueSkyInode *inode, BlueSkyStoreAsync *barrier) +void bluesky_file_flush(BlueSkyInode *inode, BlueSkyStoreAsync *barrier, + GList **log_items) { g_return_if_fail(inode->type == BLUESKY_REGULAR); for (int i = 0; i < inode->blocks->len; i++) { BlueSkyBlock *b = &g_array_index(inode->blocks, BlueSkyBlock, i); - bluesky_block_flush(inode->fs, b, barrier); + bluesky_block_flush(inode->fs, b, barrier, log_items); } }