]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: Split FindBy{UUID|Name} into locked helpers
authorJohn Ferlan <jferlan@redhat.com>
Fri, 9 Mar 2018 12:09:20 +0000 (07:09 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Thu, 3 May 2018 23:09:03 +0000 (19:09 -0400)
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@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
src/conf/virdomainobjlist.c

index d57ed10a5f0a3a330e414c6f1794e14fba7179b2..2f1702059361280a7e31c9312ab3819035dcf02e 100644 (file)
@@ -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: 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) {
@@ -179,6 +197,28 @@ virDomainObjPtr virDomainObjListFindByName(virDomainObjListPtr doms,
 }
 
 
+/**
+ * @doms: 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