Add very rudimentary eviction data blocks from the cache.
[bluesky.git] / bluesky / file.c
index 9b9f916..2df979e 100644 (file)
@@ -244,3 +244,22 @@ void bluesky_file_flush(BlueSkyInode *inode, BlueSkyStoreAsync *barrier)
         bluesky_block_flush(inode->fs, b, barrier);
     }
 }
+
+/* Drop clean data blocks for a file from cache. */
+void bluesky_file_drop_cached(BlueSkyInode *inode)
+{
+    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);
+        if (b->type == BLUESKY_BLOCK_CACHED) {
+            g_log("bluesky/cache", G_LOG_LEVEL_DEBUG,
+                  "Dropping block %d of inode %"PRIu64" from cache",
+                  i, inode->inum);
+
+            bluesky_string_unref(b->data);
+            b->data = NULL;
+            b->type = BLUESKY_BLOCK_REF;
+        }
+    }
+}