From 8ea73bbfba8c53cdaf41f2abf47bec389d1fa8ba Mon Sep 17 00:00:00 2001 From: Michael Vrable Date: Tue, 24 Aug 2010 16:53:00 -0700 Subject: [PATCH] Update logic for flushing data to cloud. Do not force a commit of the most recent data, and instead just write out whatever was last written to the journal. This could be a win or a loss: - We do not need to force a sync of all data to the journal when we upload data to the cloud. - But, we may end up writing out old data, which we'll then need to overwrite a short time later. --- bluesky/cache.c | 4 ++-- bluesky/cloudlog.c | 2 +- bluesky/inode.c | 12 +++++++----- bluesky/serialize.c | 4 +--- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/bluesky/cache.c b/bluesky/cache.c index a9fda5b..d94c18e 100644 --- a/bluesky/cache.c +++ b/bluesky/cache.c @@ -132,14 +132,14 @@ static void flushd_cloud(BlueSkyFS *fs) g_mutex_unlock(fs->lock); g_mutex_lock(inode->lock); - flushd_dirty_inode(inode); + g_assert(inode->change_cloud == inode->change_commit); g_mutex_lock(fs->lock); bluesky_list_unlink(&fs->dirty_list, inode->dirty_list); inode->dirty_list = NULL; g_mutex_unlock(fs->lock); BlueSkyCloudLog *log = inode->committed_item; - bluesky_cloudlog_ref(log); + inode->committed_item = NULL; g_mutex_unlock(inode->lock); if (log != NULL) diff --git a/bluesky/cloudlog.c b/bluesky/cloudlog.c index a47f5b0..0356c7d 100644 --- a/bluesky/cloudlog.c +++ b/bluesky/cloudlog.c @@ -231,7 +231,7 @@ BlueSkyCloudPointer bluesky_cloudlog_serialize(BlueSkyCloudLog *log, { BlueSkyCloudLogState *state = fs->log_state; - if (log->location_flags & CLOUDLOG_CLOUD) { + if ((log->location_flags | log->pending_write) & CLOUDLOG_CLOUD) { return log->location; } diff --git a/bluesky/inode.c b/bluesky/inode.c index d284479..8748164 100644 --- a/bluesky/inode.c +++ b/bluesky/inode.c @@ -50,14 +50,9 @@ void bluesky_inode_update_ctime(BlueSkyInode *inode, gboolean update_mtime) g_mutex_lock(inode->fs->lock); bluesky_list_unlink(&inode->fs->unlogged_list, inode->unlogged_list); inode->unlogged_list = bluesky_list_prepend(&inode->fs->unlogged_list, inode); - bluesky_list_unlink(&inode->fs->dirty_list, inode->dirty_list); - inode->dirty_list = bluesky_list_prepend(&inode->fs->dirty_list, inode); bluesky_list_unlink(&inode->fs->accessed_list, inode->accessed_list); inode->accessed_list = bluesky_list_prepend(&inode->fs->accessed_list, inode); g_mutex_unlock(inode->fs->lock); - - bluesky_cloudlog_unref(inode->committed_item); - inode->committed_item = NULL; } /* Unfortunately a glib hash table is only guaranteed to be able to store @@ -320,6 +315,13 @@ void bluesky_inode_start_sync(BlueSkyInode *inode) g_mutex_lock(inode->fs->lock); bluesky_list_unlink(&inode->fs->unlogged_list, inode->unlogged_list); inode->unlogged_list = NULL; + + /* Since a new version of the inode has been written to the log, also + * schedule a future flush of the new data to cloud storage. */ + bluesky_list_unlink(&inode->fs->dirty_list, inode->dirty_list); + inode->dirty_list = bluesky_list_prepend(&inode->fs->dirty_list, inode); + inode->change_cloud = inode->change_count; + g_mutex_unlock(inode->fs->lock); } diff --git a/bluesky/serialize.c b/bluesky/serialize.c index 6eef425..bee9122 100644 --- a/bluesky/serialize.c +++ b/bluesky/serialize.c @@ -99,9 +99,7 @@ BlueSkyCloudLog *bluesky_serialize_inode(BlueSkyInode *inode) g_string_append_len(out, (gchar *)&size, sizeof(uint64_t)); for (int i = 0; i < inode->blocks->len; i++) { BlueSkyBlock *b = &g_array_index(inode->blocks, BlueSkyBlock, i); - BlueSkyCloudLog *ref = NULL; - if (b->type == BLUESKY_BLOCK_REF) - ref = b->ref; + BlueSkyCloudLog *ref = (b->type == BLUESKY_BLOCK_REF ? b->ref : NULL); bluesky_cloudlog_ref(ref); g_array_append_val(cloudlog->links, ref); } -- 2.20.1