From: Michael Vrable Date: Fri, 12 Nov 2010 03:12:47 +0000 (-0800) Subject: Add a prefetch method. At the moment it is a no-op. X-Git-Url: https://git.vrable.net/?a=commitdiff_plain;h=7f47ef48ce38ab71fc414bee592a9078ed1c0a7a;p=bluesky.git Add a prefetch method. At the moment it is a no-op. --- diff --git a/bluesky/bluesky-private.h b/bluesky/bluesky-private.h index 7735a91..dcd7c48 100644 --- a/bluesky/bluesky-private.h +++ b/bluesky/bluesky-private.h @@ -332,6 +332,7 @@ void bluesky_cloudlog_sync(BlueSkyCloudLog *log); void bluesky_cloudlog_insert(BlueSkyCloudLog *log); void bluesky_cloudlog_insert_locked(BlueSkyCloudLog *log); BlueSkyCloudLog *bluesky_cloudlog_get(BlueSkyFS *fs, BlueSkyCloudID id); +void bluesky_cloudlog_prefetch(BlueSkyCloudLog *log); void bluesky_cloudlog_fetch(BlueSkyCloudLog *log); BlueSkyCloudPointer bluesky_cloudlog_serialize(BlueSkyCloudLog *log, BlueSkyFS *fs); diff --git a/bluesky/cloudlog.c b/bluesky/cloudlog.c index a37776a..7730d0e 100644 --- a/bluesky/cloudlog.c +++ b/bluesky/cloudlog.c @@ -268,6 +268,16 @@ BlueSkyCloudLog *bluesky_cloudlog_get(BlueSkyFS *fs, BlueSkyCloudID id) return item; } +/* Attempt to prefetch a cloud log item. This does not guarantee that it will + * be made available, but does make it more likely that a future call to + * bluesky_cloudlog_fetch will complete quickly. */ +void bluesky_cloudlog_prefetch(BlueSkyCloudLog *log) +{ + gchar *id = bluesky_cloudlog_id_to_string(log->id); + g_print("Prefetch for %s\n", id); + g_free(id); +} + /* Ensure that a cloud log item is loaded in memory, and if not read it in. * TODO: Make asynchronous, and make this also fetch from the cloud. Right now * we only read from the log. Log item must be locked. */ diff --git a/bluesky/file.c b/bluesky/file.c index 7b11e70..a4a8108 100644 --- a/bluesky/file.c +++ b/bluesky/file.c @@ -192,6 +192,16 @@ void bluesky_file_read(BlueSkyInode *inode, uint64_t offset, } #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;