Some initial work on logging gathering data into cloud log segments.
[bluesky.git] / bluesky / inode.c
index a0b3c6a..2780253 100644 (file)
@@ -42,8 +42,10 @@ void bluesky_inode_update_ctime(BlueSkyInode *inode, gboolean update_mtime)
     if (inode->change_time == 0)
         inode->change_time = now;
 
+#if 0
     if (bluesky_options.writethrough_cache)
         bluesky_file_flush(inode, NULL);
+#endif
 
     g_mutex_lock(inode->fs->lock);
     bluesky_list_unlink(&inode->fs->dirty_list, inode->dirty_list);
@@ -84,6 +86,8 @@ BlueSkyFS *bluesky_new_fs(gchar *name)
     fs->next_inum = BLUESKY_ROOT_INUM + 1;
     fs->store = bluesky_store_new("file");
     fs->flushd_lock = g_mutex_new();
+    fs->locations = g_hash_table_new(bluesky_cloudlog_hash,
+                                     bluesky_cloudlog_equal);
 
     return fs;
 }
@@ -95,6 +99,7 @@ BlueSkyFS *bluesky_init_fs(gchar *name, BlueSkyStore *store)
         BlueSkyFS *fs = bluesky_deserialize_superblock(data->data);
         if (fs != NULL) {
             fs->store = store;
+            fs->log = bluesky_log_new("journal");
             g_print("Loaded filesystem superblock\n");
             g_free(fs->name);
             fs->name = g_strdup(name);
@@ -297,10 +302,11 @@ void bluesky_inode_flush(BlueSkyFS *fs, BlueSkyInode *inode)
 /* Start writeback of an inode and all associated data. */
 void bluesky_inode_start_sync(BlueSkyInode *inode, BlueSkyStoreAsync *barrier)
 {
+    GList *log_items = NULL;
     BlueSkyFS *fs = inode->fs;
 
     if (inode->type == BLUESKY_REGULAR)
-        bluesky_file_flush(inode, barrier);
+        bluesky_file_flush(inode, barrier, &log_items);
 
     GString *buf = g_string_new("");
     bluesky_serialize_inode(buf, inode);
@@ -309,12 +315,34 @@ void bluesky_inode_start_sync(BlueSkyInode *inode, BlueSkyStoreAsync *barrier)
     char key[64];
     sprintf(key, "inode-%016"PRIx64, inode->inum);
 
-    BlueSkyLogItem *log_item = bluesky_log_item_new();
-    log_item->key = g_strdup(key);
-    log_item->data = data;
+    BlueSkyCloudLog *cloudlog = bluesky_cloudlog_new(fs);
+    cloudlog->type = LOGTYPE_INODE;
+    cloudlog->inum = inode->inum;
+    cloudlog->data = data;
     bluesky_string_ref(data);
-    bluesky_log_item_submit(log_item, fs->log);
-    bluesky_log_item_finish(log_item);
+
+    if (inode->type == BLUESKY_REGULAR) {
+        for (int i = 0; i < inode->blocks->len; i++) {
+            BlueSkyBlock *b = &g_array_index(inode->blocks, BlueSkyBlock, i);
+            if (b->type == BLUESKY_BLOCK_CACHED
+                || b->type == BLUESKY_BLOCK_REF)
+            {
+                BlueSkyCloudID id = bluesky_cloudlog_id_from_string(b->ref);
+                g_array_append_val(cloudlog->pointers, id);
+            }
+        }
+    }
+
+    log_items = g_list_prepend(log_items, bluesky_cloudlog_sync(cloudlog));
+
+    bluesky_cloudlog_insert(cloudlog);
+
+    /* Wait for all log items to be committed to disk. */
+    while (log_items != NULL) {
+        BlueSkyLogItem *log_item = (BlueSkyLogItem *)log_items->data;
+        bluesky_log_item_finish(log_item);
+        log_items = g_list_delete_link(log_items, log_items);
+    }
 
     BlueSkyStoreAsync *async = bluesky_store_async_new(fs->store);
     async->op = STORE_OP_PUT;