+ while (1) {
+ BlueSkyInode *inode;
+ if (fs->unlogged_list.prev == NULL)
+ break;
+ inode = fs->unlogged_list.prev->data;
+
+ if (bluesky_verbose) {
+ g_log("bluesky/flushd", G_LOG_LEVEL_DEBUG,
+ "Considering flushing inode %"PRIu64, inode->inum);
+ }
+
+ /* Stop processing dirty inodes if we both have enough memory available
+ * and the oldest inode is sufficiently new that it need not be flushed
+ * out. */
+ uint64_t elapsed = bluesky_get_current_time() - inode->change_time;
+ if (g_atomic_int_get(&fs->cache_dirty) < bluesky_watermark_low_dirty
+ && elapsed < WRITEBACK_DELAY)
+ break;
+ if (inode->change_time > start_time)
+ break;
+
+ bluesky_inode_ref(inode);
+
+ g_mutex_unlock(fs->lock);
+
+ g_mutex_lock(inode->lock);
+ flushd_dirty_inode(inode);
+ g_mutex_unlock(inode->lock);
+ bluesky_inode_unref(inode);
+
+ g_mutex_lock(fs->lock);
+ flushd_check_wakeup(fs);
+ }
+
+ g_cond_broadcast(fs->flushd_cond);
+
+ g_mutex_unlock(fs->lock);
+}
+
+/* Try to flush dirty data to the cloud.
+ * TODO: Rewrite this to work on cloud log items rather than inodes, so we can
+ * better track which logs are fully synchronized to the cloud and can be
+ * garbage collected if needed? */
+static void flushd_cloud(BlueSkyFS *fs)
+{
+ int64_t start_time = bluesky_get_current_time();
+ g_mutex_lock(fs->lock);
+