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

[libvirt] [PATCH v3 13/16] util: Introduce virObjectLookupHashSearch



A common object API wrapper to use the virHashSearch API to search the
specified LookupHash for specific data defined in the @opaque parameter.
Once data is found, the search would end and the LookupKeys object that
is represented is returned locked with it's reference count incremented.

It is up to the caller to unlock and lower the refcnt once done with the
object and of course handle a NULL return indicating no object found.

Signed-off-by: John Ferlan <jferlan redhat com>
---
 src/libvirt_private.syms |  1 +
 src/util/virobject.c     | 38 ++++++++++++++++++++++++++++++++++++++
 src/util/virobject.h     |  6 ++++++
 3 files changed, 45 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index f783fec..2c4296a 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2293,6 +2293,7 @@ virObjectLookupHashGetName;
 virObjectLookupHashGetUUID;
 virObjectLookupHashNew;
 virObjectLookupHashRemove;
+virObjectLookupHashSearch;
 virObjectLookupKeysGetName;
 virObjectLookupKeysGetUUID;
 virObjectLookupKeysIsActive;
diff --git a/src/util/virobject.c b/src/util/virobject.c
index 8a994f5..60bc5b5 100644
--- a/src/util/virobject.c
+++ b/src/util/virobject.c
@@ -954,3 +954,41 @@ virObjectLookupHashForEach(void *tableobj,
     }
     return -1;
 }
+
+
+/**
+ * virObjectLookupHashSearchName
+ * @tableobj: poolable hash table pointer to search
+ * @useUUID: boolean to use objsUUID
+ * @callback: callback function to handle the object specific checks
+ * @opaque: callback data
+ *
+ * Search the objsName hash table calling the specified @callback routine
+ * with an object and @opaque data in order to determine whether the searched
+ * object is represented by the @opaque data.
+ *
+ * Returns locked/refcnt incremented object on success, NULL on failure
+ */
+virObjectLookupKeysPtr
+virObjectLookupHashSearch(void *tableobj,
+                          bool useUUID,
+                          virHashSearcher callback,
+                          void *opaque)
+{
+    virObjectLookupHashPtr tableObj = virObjectGetLookupHashObj(tableobj);
+    virObjectLookupKeysPtr obj;
+
+    if (!tableObj)
+        return NULL;
+
+    virObjectLock(tableObj);
+    obj = virHashSearch(useUUID ? tableObj->objsUUID : tableObj->objsName,
+                        callback, opaque);
+    virObjectRef(obj);
+    virObjectUnlock(tableObj);
+
+    if (obj)
+        virObjectLock(obj);
+
+    return obj;
+}
diff --git a/src/util/virobject.h b/src/util/virobject.h
index 926c9d3..7e58e34 100644
--- a/src/util/virobject.h
+++ b/src/util/virobject.h
@@ -218,4 +218,10 @@ virObjectLookupHashForEach(void *tableobj,
                            virHashIterator callback,
                            virObjectLookupHashForEachDataPtr data);
 
+virObjectLookupKeysPtr
+virObjectLookupHashSearch(void *tableobj,
+                          bool useUUID,
+                          virHashSearcher callback,
+                          void *opaque);
+
 #endif /* __VIR_OBJECT_H */
-- 
2.9.4


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