}
}
-#if 0
-/* Read the given block from cloud-backed storage if the data is not already
- * cached. */
-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);
-
- 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;
-}
-#endif
-
void bluesky_block_fetch(BlueSkyInode *inode, BlueSkyBlock *block,
BlueSkyStoreAsync *barrier)
{
- // TODO: Implement this
-
-#if 0
- BlueSkyFS *fs = inode->fs;
-
if (block->type != BLUESKY_BLOCK_REF)
return;
- 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);
-
- if (barrier != NULL)
- bluesky_store_add_barrier(barrier, async);
- else
- bluesky_store_async_wait(async);
-
- bluesky_store_async_unref(async);
- g_atomic_int_add(&fs->cache_total, 1);
-#endif
+ g_mutex_lock(block->cloudref->lock);
+ bluesky_cloudlog_fetch(block->cloudref);
+ block->data = block->cloudref->data;
+ bluesky_string_ref(block->data);
+ g_mutex_unlock(block->cloudref->lock);
+ block->type = BLUESKY_BLOCK_CACHED;
}
/* Write the given block to cloud-backed storage and mark it clean. */
/* Drop clean data blocks for a file from cache. */
void bluesky_file_drop_cached(BlueSkyInode *inode)
{
-#if 0
g_return_if_fail(inode->type == BLUESKY_REGULAR);
for (int i = 0; i < inode->blocks->len; i++) {
b->data = NULL;
b->type = BLUESKY_BLOCK_REF;
g_atomic_int_add(&inode->fs->cache_total, -1);
+ g_mutex_lock(b->cloudref->lock);
+ bluesky_string_unref(b->cloudref->data);
+ b->cloudref->data = NULL;
+ g_mutex_unlock(b->cloudref->lock);
}
}
-#endif
}