Add in some support for journal replay.
[bluesky.git] / bluesky / serialize.c
index e453f49..f90c63a 100644 (file)
@@ -67,10 +67,16 @@ BlueSkyFS *bluesky_deserialize_superblock(const gchar *buf)
     return fs;
 }
 
-void bluesky_serialize_inode(GString *out, BlueSkyInode *inode)
+BlueSkyCloudLog *bluesky_serialize_inode(BlueSkyInode *inode)
 {
+    BlueSkyFS *fs = inode->fs;
+    GString *out = g_string_new("");
     struct serialized_inode buf;
 
+    BlueSkyCloudLog *cloudlog = bluesky_cloudlog_new(fs, NULL);
+    cloudlog->type = LOGTYPE_INODE;
+    cloudlog->inum = inode->inum;
+
     buf.signature = GUINT64_TO_LE(INODE_MAGIC);
     buf.type = GUINT32_TO_LE(inode->type);
     buf.mode = GUINT32_TO_LE(inode->mode);
@@ -93,9 +99,9 @@ void bluesky_serialize_inode(GString *out, 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);
-            if (b->ref != NULL)
-                g_string_append(out, b->ref);
-            g_string_append_c(out, '\0');
+            BlueSkyCloudLog *ref = (b->type == BLUESKY_BLOCK_REF ? b->ref : NULL);
+            bluesky_cloudlog_ref(ref);
+            g_array_append_val(cloudlog->links, ref);
         }
         break;
     }
@@ -136,6 +142,12 @@ void bluesky_serialize_inode(GString *out, BlueSkyInode *inode)
         g_warning("Serialization for inode type %d not implemented!\n",
                   inode->type);
     }
+
+    cloudlog->data = bluesky_string_new_from_gstring(out);
+    bluesky_cloudlog_insert(cloudlog);
+    bluesky_cloudlog_stats_update(cloudlog, 1);
+
+    return cloudlog;
 }
 
 /* Deserialize an inode into an in-memory representation.  Returns a boolean
@@ -178,12 +190,15 @@ gboolean bluesky_deserialize_inode(BlueSkyInode *inode, const gchar *buf)
         g_array_set_size(inode->blocks,
                          (inode->size + BLUESKY_BLOCK_SIZE - 1)
                           / BLUESKY_BLOCK_SIZE);
+        // TODO
+#if 0
         for (int i = 0; i < inode->blocks->len; i++) {
             BlueSkyBlock *b = &g_array_index(inode->blocks, BlueSkyBlock, i);
             b->type = BLUESKY_BLOCK_REF;
             b->ref = g_strdup(buf);
             buf += strlen(b->ref) + 1;
         }
+#endif
         break;
 
     case BLUESKY_DIRECTORY: