[PATCH 1/6] conf: Split FindBy{UUID|Name} into locked helpers

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

 



Create helpers virDomainObjListFindByUUIDLocked and
virDomainObjListFindByNameLocked to avoid the need
to lock the domain object list leaving that task
for the caller.

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/conf/virdomainobjlist.c | 58 ++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 49 insertions(+), 9 deletions(-)

diff --git a/src/conf/virdomainobjlist.c b/src/conf/virdomainobjlist.c
index d57ed10a5f..9aa2abd8c3 100644
--- a/src/conf/virdomainobjlist.c
+++ b/src/conf/virdomainobjlist.c
@@ -133,19 +133,16 @@ virDomainObjListFindByID(virDomainObjListPtr doms,
 }
 
 
-virDomainObjPtr
-virDomainObjListFindByUUID(virDomainObjListPtr doms,
-                           const unsigned char *uuid)
+static virDomainObjPtr
+virDomainObjListFindByUUIDLocked(virDomainObjListPtr doms,
+                                 const unsigned char *uuid)
 {
     char uuidstr[VIR_UUID_STRING_BUFLEN];
     virDomainObjPtr obj;
 
-    virObjectRWLockRead(doms);
     virUUIDFormat(uuid, uuidstr);
-
     obj = virHashLookup(doms->objs, uuidstr);
     virObjectRef(obj);
-    virObjectRWUnlock(doms);
     if (obj) {
         virObjectLock(obj);
         if (obj->removing) {
@@ -158,15 +155,36 @@ virDomainObjListFindByUUID(virDomainObjListPtr doms,
 }
 
 
-virDomainObjPtr virDomainObjListFindByName(virDomainObjListPtr doms,
-                                           const char *name)
+/**
+ * @doms: Locked domain object list
+ * @uuid: UUID to search the doms->objs table
+ *
+ * Lookup the @uuid in the doms->objs hash table and return a
+ * locked and ref counted domain object if found. Caller is
+ * expected to use the virDomainObjEndAPI when done with the object.
+ */
+virDomainObjPtr
+virDomainObjListFindByUUID(virDomainObjListPtr doms,
+                           const unsigned char *uuid)
 {
     virDomainObjPtr obj;
 
     virObjectRWLockRead(doms);
+    obj = virDomainObjListFindByUUIDLocked(doms, uuid);
+    virObjectRWUnlock(doms);
+
+    return obj;
+}
+
+
+static virDomainObjPtr
+virDomainObjListFindByNameLocked(virDomainObjListPtr doms,
+                                 const char *name)
+{
+    virDomainObjPtr obj;
+
     obj = virHashLookup(doms->objsName, name);
     virObjectRef(obj);
-    virObjectRWUnlock(doms);
     if (obj) {
         virObjectLock(obj);
         if (obj->removing) {
@@ -180,6 +198,28 @@ virDomainObjPtr virDomainObjListFindByName(virDomainObjListPtr doms,
 
 
 /**
+ * @doms: Locked domain object list
+ * @name: Name to search the doms->objsName table
+ *
+ * Lookup the @name in the doms->objsName hash table and return a
+ * locked and ref counted domain object if found. Caller is expected
+ * to use the virDomainObjEndAPI when done with the object.
+ */
+virDomainObjPtr
+virDomainObjListFindByName(virDomainObjListPtr doms,
+                           const char *name)
+{
+    virDomainObjPtr obj;
+
+    virObjectRWLockRead(doms);
+    obj = virDomainObjListFindByNameLocked(doms, name);
+    virObjectRWUnlock(doms);
+
+    return obj;
+}
+
+
+/**
  * @doms: Domain object list pointer
  * @vm: Domain object to be added
  *
-- 
2.13.6

--
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