]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: virfilecache: Introduce virFileCacheClear for usage in tests
authorPeter Krempa <pkrempa@redhat.com>
Thu, 2 Mar 2023 16:32:28 +0000 (17:32 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 6 Mar 2023 19:55:49 +0000 (20:55 +0100)
In tests we need to be able to populate the cache with a deterministic
set of entries. This means we need to drop the contents of the cache
between runs to prevent spillage between test cases.

virFileCacheClear drops all entries from the hash table used for the
cache.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/libvirt_private.syms
src/util/virfilecache.c
src/util/virfilecache.h

index 8792bf7f5486db9ec2584ab759f8af9f3af1cbe9..d5b1b9cb7216c7a9efce52f5d210bc8f671d93b1 100644 (file)
@@ -2354,6 +2354,7 @@ virFindFileInPath;
 
 
 # util/virfilecache.h
+virFileCacheClear;
 virFileCacheGetPriv;
 virFileCacheInsertData;
 virFileCacheLookup;
index bad37c9f004f7755de76dc40b3487e353df1b09e..b9e06545c0203c3d4ae7080d5104a37ae846fd4c 100644 (file)
@@ -407,3 +407,19 @@ virFileCacheInsertData(virFileCache *cache,
 
     return ret;
 }
+
+
+/**
+ * virFileCacheClear:
+ * @cache: existing cache object
+ *
+ * Drops all entries from the cache. This is useful in tests to clean out
+ * previous usage.
+ */
+void
+virFileCacheClear(virFileCache *cache)
+{
+    virObjectLock(cache);
+    virHashRemoveAll(cache->table);
+    virObjectUnlock(cache);
+}
index 81be8feef53686e9cb8c14bd55bfb18ebf9c09ab..c3bc0f529ca17931a5c28a7f973164bb1f45a22b 100644 (file)
@@ -135,3 +135,7 @@ int
 virFileCacheInsertData(virFileCache *cache,
                        const char *name,
                        void *data);
+
+/* for testing usage */
+void
+virFileCacheClear(virFileCache *cache);