[PATCH v4 15/17] util: Introduce virObjectLookupHashPrune

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



A convenience API that will utilize the virHashForEach API for the
LookupHash in order to remove elements from the hash table(s) that
match some requirement from the callback.

NB: Once elements are removed from objsKey1 - if something goes wrong
in objsKey2, the best that can be done is to issue a warning and hope
for the best.

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/libvirt_private.syms |  1 +
 src/util/virobject.c     | 36 ++++++++++++++++++++++++++++++++++++
 src/util/virobject.h     |  5 +++++
 3 files changed, 42 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index c7c9762..47393c6 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2337,6 +2337,7 @@ virObjectLookupHashFind;
 virObjectLookupHashFindLocked;
 virObjectLookupHashForEach;
 virObjectLookupHashNew;
+virObjectLookupHashPrune;
 virObjectLookupHashRemove;
 virObjectLookupHashSearch;
 virObjectLookupHashSearchLocked;
diff --git a/src/util/virobject.c b/src/util/virobject.c
index 0a4195d..47787f7 100644
--- a/src/util/virobject.c
+++ b/src/util/virobject.c
@@ -1246,3 +1246,39 @@ virObjectLookupHashClone(void *srcAnyobj,
 
     return 0;
 }
+
+
+/**
+ * virObjectLookupHashPrune
+ * @anyobj: LookupHash object
+ * @callback: callback function to handle the object specific checks
+ * @opaque: callback data
+ *
+ * Call the callback function from virHashRemoveSet in order to determine
+ * if the incoming opaque data should be removed from the hash table(s)
+ * for the LookupHash. If a second hash table exists and we fail to remove
+ * data from it
+ */
+void
+virObjectLookupHashPrune(void *anyobj,
+                         virHashSearcher callback,
+                         void *opaque)
+{
+    virObjectLookupHashPtr hashObj = virObjectGetLookupHashObj(anyobj);
+    ssize_t cntKey1;
+    ssize_t cntKey2;
+
+    if (!hashObj)
+        return;
+
+    virObjectRWLockWrite(hashObj);
+    cntKey1 = virHashRemoveSet(hashObj->objsKey1, callback, opaque);
+    if (cntKey1 > 0 && hashObj->objsKey2) {
+        cntKey2 = virHashRemoveSet(hashObj->objsKey2, callback, opaque);
+
+        if (cntKey2 != cntKey1)
+            VIR_ERROR(_("removed %zd elems from objsKey1 and %zd elems "
+                        "from objsKey2"), cntKey1, cntKey2);
+    }
+    virObjectRWUnlock(hashObj);
+}
diff --git a/src/util/virobject.h b/src/util/virobject.h
index b9e6311..54eff81 100644
--- a/src/util/virobject.h
+++ b/src/util/virobject.h
@@ -260,5 +260,10 @@ virObjectLookupHashClone(void *srcAnyobj,
                          virObjectLookupHashCloneCallback cb)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
 
+void
+virObjectLookupHashPrune(void *anyobj,
+                         virHashSearcher callback,
+                         void *opaque)
+    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
 
 #endif /* __VIR_OBJECT_H */
-- 
2.9.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux