Add per-item encryption/authentication to the cloud log storage.
[bluesky.git] / bluesky / imap.c
index 6318256..9036263 100644 (file)
@@ -110,7 +110,8 @@ InodeMapEntry *bluesky_inode_map_lookup(GSequence *inode_map, uint64_t inum,
         entry->inum = inum;
         g_sequence_insert_sorted(range->map_entries, entry, compare, NULL);
 
-        g_print("Created inode map entry for %"PRIu64"\n", inum);
+        if (bluesky_verbose)
+            g_print("Created inode map entry for %"PRIu64"\n", inum);
     }
 
     if (action != 0) {
@@ -203,6 +204,24 @@ void bluesky_inode_map_minimize(BlueSkyFS *fs)
         if (range->serialized != NULL)
             bluesky_cloudlog_erase(range->serialized);
 
+        GSequenceIter *j;
+        for (j = g_sequence_get_begin_iter(range->map_entries);
+             !g_sequence_iter_is_end(j); j = g_sequence_iter_next(j))
+        {
+            InodeMapEntry *entry = (InodeMapEntry *)g_sequence_get(j);
+            BlueSkyCloudLog *item = entry->item;
+            if (item != NULL) {
+                g_mutex_lock(item->lock);
+                if (g_atomic_int_get(&item->refcount) == 1) {
+                    bluesky_cloudlog_erase(item);
+                }
+                g_mutex_unlock(item->lock);
+            } else {
+                g_warning("Null item for inode map entry %"PRIu64"!",
+                          entry->inum);
+            }
+        }
+
         i = g_sequence_iter_next(i);
     }
 }
@@ -260,6 +279,9 @@ gboolean bluesky_checkpoint_load(BlueSkyFS *fs)
         return FALSE;
     }
 
+    last = bluesky_string_dup(last);
+    bluesky_cloudlog_decrypt(last->data, last->len, fs->keys);
+
     /* Scan through the contents of the last log segment to find a checkpoint
      * record.  We need to do a linear scan since at this point we don't have a
      * direct pointer; once we have the last commit record then all other data
@@ -307,7 +329,7 @@ gboolean bluesky_checkpoint_load(BlueSkyFS *fs)
     g_mutex_unlock(commit->lock);
 
     bluesky_inode_map_deserialize(fs, commit);
-    //bluesky_cloudlog_unref(commit);
+    bluesky_cloudlog_unref(commit);
 
     return TRUE;
 }