X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=bluesky%2Ffile.c;h=822c2c81f8d4c548ee9da49c155afa701646c346;hb=349ac2f2bcc67551a5bb946c73c650501228f056;hp=6ba39e3eff30ac32421d42c2211dd210edda69aa;hpb=4540b5b4a664faa0cdac04b61a2e336dc5cadf94;p=bluesky.git diff --git a/bluesky/file.c b/bluesky/file.c index 6ba39e3..822c2c8 100644 --- a/bluesky/file.c +++ b/bluesky/file.c @@ -35,7 +35,7 @@ void bluesky_block_touch(BlueSkyInode *inode, uint64_t i) block->data = bluesky_string_new(g_malloc0(block_len), block_len); break; case BLUESKY_BLOCK_REF: - bluesky_block_fetch(inode->fs, block); + bluesky_block_fetch(inode->fs, block, NULL); g_assert(block->type == BLUESKY_BLOCK_CACHED); /* Fall through */ case BLUESKY_BLOCK_CACHED: @@ -169,7 +169,7 @@ void bluesky_file_read(BlueSkyInode *inode, uint64_t offset, memset(buf, 0, bytes); break; case BLUESKY_BLOCK_REF: - bluesky_block_fetch(inode->fs, b); + bluesky_block_fetch(inode->fs, b, NULL); /* Fall through */ case BLUESKY_BLOCK_CACHED: case BLUESKY_BLOCK_DIRTY: @@ -185,16 +185,32 @@ void bluesky_file_read(BlueSkyInode *inode, uint64_t offset, /* Read the given block from cloud-backed storage if the data is not already * cached. */ -void bluesky_block_fetch(BlueSkyFS *fs, BlueSkyBlock *block) +static void block_fetch_completion(BlueSkyStoreAsync *async, gpointer data) +{ + BlueSkyBlock *block = (BlueSkyBlock *)data; + + bluesky_string_unref(block->data); + block->data = async->data; + bluesky_string_ref(block->data); + block->type = BLUESKY_BLOCK_CACHED; +} + +void bluesky_block_fetch(BlueSkyFS *fs, BlueSkyBlock *block, + BlueSkyStoreAsync *barrier) { if (block->type != BLUESKY_BLOCK_REF) return; - BlueSkyRCStr *string = bluesky_store_get(fs->store, block->ref); + BlueSkyStoreAsync *async = bluesky_store_async_new(fs->store); + async->op = STORE_OP_GET; + async->key = g_strdup(block->ref); + bluesky_store_async_add_notifier(async, (GFunc)block_fetch_completion, block); + bluesky_store_async_submit(async); - bluesky_string_unref(block->data); - block->data = string; - block->type = BLUESKY_BLOCK_CACHED; + if (barrier != NULL) + bluesky_store_add_barrier(barrier, async); + else + bluesky_store_async_wait(async); } /* Write the given block to cloud-backed storage and mark it clean. */