- GString *buf = g_string_new("");
- bluesky_serialize_inode(buf, inode);
- BlueSkyRCStr *data = bluesky_string_new_from_gstring(buf);
-
- char key[64];
- sprintf(key, "inode-%016"PRIx64, inode->inum);
-
- BlueSkyStoreAsync *async = bluesky_store_async_new(fs->store);
- async->op = STORE_OP_PUT;
- async->key = g_strdup(key);
- async->data = data;
- bluesky_store_async_submit(async);
- bluesky_store_async_unref(async);
+ GList *log_items = NULL;
+
+ if (inode->type == BLUESKY_REGULAR)
+ bluesky_file_flush(inode, &log_items);
+
+ BlueSkyCloudLog *cloudlog = bluesky_serialize_inode(inode);
+
+ bluesky_cloudlog_unref(inode->committed_item);
+ inode->committed_item = cloudlog;
+
+ bluesky_cloudlog_sync(cloudlog);
+ bluesky_cloudlog_ref(cloudlog);
+ log_items = g_list_prepend(log_items, cloudlog);
+
+ /* Wait for all log items to be committed to disk. */
+ bluesky_log_finish_all(log_items);
+
+ /* Mark the inode as clean */
+ inode->change_commit = inode->change_count;
+ inode->change_time = 0;
+ 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);