break;
}
- /*if (block->type != BLUESKY_BLOCK_CACHED
- && block->type != BLUESKY_BLOCK_DIRTY)
- g_atomic_int_add(&inode->fs->cache_total, 1); //FIXME */
if (block->type != BLUESKY_BLOCK_DIRTY)
g_atomic_int_add(&inode->fs->cache_dirty, 1);
g_array_set_size(inode->blocks, blocks);
} else if (blocks < inode->blocks->len) {
/* Delete blocks from a file. Must reclaim memory. */
- for (guint i = inode->blocks->len; i < blocks; i++) {
+ for (guint i = blocks; i < inode->blocks->len; i++) {
BlueSkyBlock *b = &g_array_index(inode->blocks, BlueSkyBlock, i);
- /* if (b->type == BLUESKY_BLOCK_CACHED
- || b->type == BLUESKY_BLOCK_DIRTY)
- g_atomic_int_add(&inode->fs->cache_total, -1); FIXME */
if (b->type == BLUESKY_BLOCK_DIRTY)
g_atomic_int_add(&inode->fs->cache_dirty, -1);
bluesky_string_unref(b->dirty);
}
#endif
+ uint64_t start_block, end_block;
+ start_block = offset / BLUESKY_BLOCK_SIZE;
+ end_block = (offset + len - 1) / BLUESKY_BLOCK_SIZE;
+ for (uint64_t i = start_block; i <= end_block; i++) {
+ BlueSkyBlock *b = &g_array_index(inode->blocks, BlueSkyBlock,
+ i);
+ if (b->type == BLUESKY_BLOCK_REF)
+ bluesky_cloudlog_prefetch(b->ref);
+ }
+
while (len > 0) {
uint64_t block_num = offset / BLUESKY_BLOCK_SIZE;
gint block_offset = offset % BLUESKY_BLOCK_SIZE;
bluesky_cloudlog_fetch(block->ref);
g_mutex_unlock(block->ref->lock);
block->type = BLUESKY_BLOCK_REF;
- g_atomic_int_add(&inode->fs->cache_total, 1); //FIXME
}
/* Write the given block to cloud-backed storage and mark it clean. */
g_assert(block->ref == NULL);
- BlueSkyCloudLog *cloudlog = bluesky_cloudlog_new(fs);
+ BlueSkyCloudLog *cloudlog = bluesky_cloudlog_new(fs, NULL);
cloudlog->type = LOGTYPE_DATA;
cloudlog->inum = inode->inum;
cloudlog->data = block->dirty; // String ownership is transferred
+ bluesky_cloudlog_stats_update(cloudlog, 1);
bluesky_cloudlog_sync(cloudlog);
bluesky_cloudlog_ref(cloudlog); // Reference for log_items list
*log_items = g_list_prepend(*log_items, cloudlog);
&& g_atomic_int_get(&b->ref->data_lock_count) == 0
&& (b->ref->location_flags != 0))
{
+ bluesky_cloudlog_stats_update(b->ref, -1);
bluesky_string_unref(b->ref->data);
b->ref->data = NULL;
+ bluesky_cloudlog_stats_update(b->ref, 1);
}
g_mutex_unlock(b->ref->lock);
- g_atomic_int_add(&inode->fs->cache_total, -1);
}
}
}