X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=bluesky%2Ffile.c;h=f7e8fcac894ffdc125a8400243ad055b17f79062;hb=a4e456f91da9819e5a1517d4e505816bb4aa1007;hp=ccb45e4eb47d378ae344527a3924b7e041b264a1;hpb=f6697c903221f4f95972b7618f84cf86ff1e6bc0;p=bluesky.git diff --git a/bluesky/file.c b/bluesky/file.c index ccb45e4..f7e8fca 100644 --- a/bluesky/file.c +++ b/bluesky/file.c @@ -182,6 +182,11 @@ void bluesky_block_fetch(BlueSkyFS *fs, BlueSkyBlock *block) block->type = BLUESKY_BLOCK_CACHED; } +static void finished(gpointer a, gpointer b) +{ + g_print("Barrier completed!\n"); +} + /* Write the given block to cloud-backed storage and mark it clean. */ void bluesky_block_flush(BlueSkyFS *fs, BlueSkyBlock *block) { @@ -194,10 +199,26 @@ void bluesky_block_flush(BlueSkyFS *fs, BlueSkyBlock *block) g_checksum_update(csum, data->data, data->len); gchar *name = g_strdup(g_checksum_get_string(csum)); - bluesky_store_put(fs->store, name, data); + /* Store the file data asynchronously, and don't bother waiting for a + * response. */ + BlueSkyStoreAsync *async = bluesky_store_async_new(fs->store); + async->op = STORE_OP_PUT; + async->key = g_strdup(name); + bluesky_string_ref(data); + async->data = data; + bluesky_store_async_submit(async); + bluesky_store_async_unref(async); + g_free(block->ref); block->ref = name; + BlueSkyStoreAsync *barrier = bluesky_store_async_new(fs->store); + barrier->op = STORE_OP_BARRIER; + bluesky_store_add_barrier(barrier, async); + bluesky_store_async_add_notifier(barrier, finished, NULL); + bluesky_store_async_submit(barrier); + bluesky_store_async_unref(barrier); + /* block->type = BLUESKY_BLOCK_CACHED; */ bluesky_string_unref(block->data); block->data = NULL; @@ -206,3 +227,14 @@ void bluesky_block_flush(BlueSkyFS *fs, BlueSkyBlock *block) g_checksum_free(csum); //bluesky_string_unref(data); } + +/* Flush all blocks in a file to stable storage. */ +void bluesky_file_flush(BlueSkyInode *inode) +{ + 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); + } +}