/* A stale reference to a journal file which doesn't exist any longer
* because it was reclaimed. Return NULL. */
} else if (map == NULL) {
- g_print("Adding cache file %s\n", logname);
+ if (bluesky_verbose)
+ g_print("Adding cache file %s\n", logname);
map = g_new0(BlueSkyCacheFile, 1);
map->fs = fs;
g_mutex_lock(map->lock);
map->cond = g_cond_new();
map->filename = g_strdup(logname);
+ map->log_dir = clouddir;
map->log_seq = log_seq;
map->log = log;
g_atomic_int_set(&map->mapcount, 0);
async->key = g_strdup(cachefile->filename);
async->start = offset;
async->len = length;
+ async->profile = bluesky_profile_get();
bluesky_store_async_add_notifier(async,
(GFunc)cloudlog_partial_fetch_complete,
cachefile);
static void cloudlog_partial_fetch_complete(BlueSkyStoreAsync *async,
BlueSkyCacheFile *cachefile)
{
- g_print("Partial fetch of %s from cloud complete, status = %d\n",
+ g_print("Fetch of %s from cloud complete, status = %d\n",
async->key, async->result);
g_mutex_lock(cachefile->lock);
if (async->result >= 0) {
+ if (async->len == 0) {
+ g_print("Complete object was fetched.\n");
+ cachefile->complete = TRUE;
+ }
+
/* Descrypt items fetched and write valid items out to the local log,
* but only if they do not overlap existing objects. This will protect
* against an attack by the cloud provider where one valid object is
BlueSkyRangeset *items = bluesky_rangeset_new();
int fd = openat(cachefile->log->dirfd, cachefile->filename, O_WRONLY);
if (fd >= 0) {
+ gboolean allow_unauth;
async->data = bluesky_string_dup(async->data);
+ allow_unauth = cachefile->log_dir == BLUESKY_CLOUD_DIR_CLEANER;
bluesky_cloudlog_decrypt(async->data->data, async->data->len,
- cachefile->fs->keys, items);
+ cachefile->fs->keys, items, allow_unauth);
uint64_t item_offset = 0;
while (TRUE) {
const BlueSkyRangesetItem *item;
item = bluesky_rangeset_lookup_next(items, item_offset);
if (item == NULL)
break;
- g_print(" item offset from range request: %d\n",
- (int)(item->start + async->start));
+ if (bluesky_verbose) {
+ g_print(" item offset from range request: %d\n",
+ (int)(item->start + async->start));
+ }
if (bluesky_rangeset_insert(cachefile->items,
async->start + item->start,
item->length, item->data))
BlueSkyStoreAsync *async = bluesky_store_async_new(cachefile->fs->store);
async->op = STORE_OP_GET;
async->key = g_strdup(cachefile->filename);
+ async->profile = bluesky_profile_get();
bluesky_store_async_add_notifier(async,
(GFunc)cloudlog_partial_fetch_complete,
cachefile);
goto exit2;
}
if (rangeitem == NULL) {
- g_print("Item at offset 0x%zx not available, need to fetch.\n",
- file_offset);
- if (range_request)
- cloudlog_partial_fetch_start(map, file_offset, file_size);
+ if (bluesky_verbose) {
+ g_print("Item at offset 0x%zx not available, need to fetch.\n",
+ file_offset);
+ }
+ if (range_request) {
+ uint64_t start = 0, length = 0, end;
+ if (map->prefetches != NULL)
+ bluesky_rangeset_get_extents(map->prefetches,
+ &start, &length);
+ start = MIN(start, file_offset);
+ end = MAX(start + length, file_offset + file_size);
+ length = end - start;
+ cloudlog_partial_fetch_start(map, start, length);
+ if (map->prefetches != NULL) {
+ bluesky_rangeset_free(map->prefetches);
+ map->prefetches = NULL;
+ }
+ }
g_cond_wait(map->cond, map->lock);
} else if (rangeitem->start == file_offset
&& rangeitem->length == file_size) {
- g_print("Item now available.\n");
+ if (bluesky_verbose)
+ g_print("Item now available.\n");
break;
}
}
if (g_atomic_int_dec_and_test(&mmap->mapcount)) {
g_mutex_lock(mmap->lock);
if (g_atomic_int_get(&mmap->mapcount) == 0) {
- g_print("Unmapped log segment %d...\n", mmap->log_seq);
+ if (bluesky_verbose)
+ g_print("Unmapped log segment %d...\n", mmap->log_seq);
munmap((void *)mmap->addr, mmap->len);
mmap->addr = NULL;
g_atomic_int_add(&mmap->refcount, -1);