Do not hold references to all inode data in inode map.
[bluesky.git] / bluesky / imap.c
index cc8f1ba..5d5be8a 100644 (file)
@@ -156,6 +156,7 @@ static void bluesky_inode_map_serialize_section(BlueSkyFS *fs,
 
 BlueSkyCloudLog *bluesky_inode_map_serialize(BlueSkyFS *fs)
 {
+    gboolean updated = FALSE;
     GString *buf = g_string_new("");
     BlueSkyCloudLog *log = bluesky_cloudlog_new(fs, NULL);
     log->type = LOGTYPE_CHECKPOINT;
@@ -169,15 +170,23 @@ BlueSkyCloudLog *bluesky_inode_map_serialize(BlueSkyFS *fs)
         inum = GUINT64_TO_LE(range->end);
         g_string_append_len(buf, (const char *)&inum, sizeof(inum));
 
-        if (range->serialized == NULL)
+        if (range->serialized == NULL) {
             bluesky_inode_map_serialize_section(fs, range);
+            updated = TRUE;
+        }
         bluesky_cloudlog_ref(range->serialized);
         g_array_append_val(log->links, range->serialized);
         i = g_sequence_iter_next(i);
     }
 
     log->data = bluesky_string_new_from_gstring(buf);
-    return log;
+
+    if (updated) {
+        return log;
+    } else {
+        bluesky_cloudlog_unref(log);
+        return NULL;
+    }
 }
 
 /* Reconstruct the inode map from data stored in the cloud. */