[PATCH v3 11/16] util: Introduce virObjectLookupHashFind

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

 



This API will use the virHashLookup in order to find the object in
the requested hash table (via @useUUID) by the specified @key. It is
up to the caller to know which table (UUID or Name) to find the data
by @key and handle the error or NULL return.

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

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index de986e5..68961e7 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2287,6 +2287,7 @@ virObjectListFreeCount;
 virObjectLock;
 virObjectLockableNew;
 virObjectLookupHashAdd;
+virObjectLookupHashFind;
 virObjectLookupHashGetName;
 virObjectLookupHashGetUUID;
 virObjectLookupHashNew;
diff --git a/src/util/virobject.c b/src/util/virobject.c
index 9443dda..01922b3 100644
--- a/src/util/virobject.c
+++ b/src/util/virobject.c
@@ -853,6 +853,31 @@ virObjectLookupHashGetUUID(void *anyobj)
 
 
 /**
+ * virObjectLookupHashFind:
+ * @tableobj: poolable hash table pointer find data
+ * @useUUID: boolean to use objsUUID
+ * @key: Key to use for lookup
+ *
+ * Returns a pointer to the entry or NULL on failure
+ */
+virObjectLookupKeysPtr
+virObjectLookupHashFind(void *tableobj,
+                        bool useUUID,
+                        const char *key)
+{
+    virObjectLookupHashPtr hashObj = virObjectGetLookupHashObj(tableobj);
+
+    if (!hashObj) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       ("tableobj=%p is not a lookup hash object"), tableobj);
+        return NULL;
+    }
+
+    return virHashLookup(useUUID ? hashObj->objsUUID : hashObj->objsName, key);
+}
+
+
+/**
  * virObjectLookupHashGetName
  * @anyobj: Pointer to a LookupHash object
  *
diff --git a/src/util/virobject.h b/src/util/virobject.h
index 422c81e..ed99540 100644
--- a/src/util/virobject.h
+++ b/src/util/virobject.h
@@ -187,6 +187,11 @@ void
 virObjectLookupHashRemove(void *tableobj,
                           virObjectLookupKeysPtr obj);
 
+virObjectLookupKeysPtr
+virObjectLookupHashFind(void *tableobj,
+                        bool useUUID,
+                        const char *key);
+
 virHashTablePtr
 virObjectLookupHashGetUUID(void *anyobj);
 
-- 
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