Allow batched log writes when writing dirty inodes.
[bluesky.git] / bluesky / file.c
index 311afc3..b107a40 100644 (file)
@@ -258,7 +258,8 @@ void bluesky_block_fetch(BlueSkyFS *fs, BlueSkyBlock *block,
 
 /* Write the given block to cloud-backed storage and mark it clean. */
 void bluesky_block_flush(BlueSkyFS *fs, BlueSkyBlock *block,
-                         BlueSkyStoreAsync *barrier)
+                         BlueSkyStoreAsync *barrier,
+                         GList **log_items)
 {
     if (block->type != BLUESKY_BLOCK_DIRTY)
         return;
@@ -269,6 +270,14 @@ void bluesky_block_flush(BlueSkyFS *fs, BlueSkyBlock *block,
     g_checksum_update(csum, (const guchar *)data->data, data->len);
     gchar *name = g_strdup(g_checksum_get_string(csum));
 
+    /* Start commit to the local log. */
+    BlueSkyLogItem *log_item = bluesky_log_item_new();
+    log_item->key = g_strdup(name);
+    log_item->data = data;
+    bluesky_string_ref(data);
+    bluesky_log_item_submit(log_item, fs->log);
+    *log_items = g_list_prepend(*log_items, log_item);
+
     /* Store the file data asynchronously, and don't bother waiting for a
      * response. */
     BlueSkyStoreAsync *async = bluesky_store_async_new(fs->store);
@@ -291,13 +300,14 @@ void bluesky_block_flush(BlueSkyFS *fs, BlueSkyBlock *block,
 }
 
 /* Flush all blocks in a file to stable storage. */
-void bluesky_file_flush(BlueSkyInode *inode, BlueSkyStoreAsync *barrier)
+void bluesky_file_flush(BlueSkyInode *inode, BlueSkyStoreAsync *barrier,
+                        GList **log_items)
 {
     g_return_if_fail(inode->type == BLUESKY_REGULAR);
 
     for (int i = 0; i < inode->blocks->len; i++) {
         BlueSkyBlock *b = &g_array_index(inode->blocks, BlueSkyBlock, i);
-        bluesky_block_flush(inode->fs, b, barrier);
+        bluesky_block_flush(inode->fs, b, barrier, log_items);
     }
 }