]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: Rework virDomainObjListFindByUUID to allow more concurrent APIs
authorMartin Kletzander <mkletzan@redhat.com>
Tue, 2 Dec 2014 07:33:33 +0000 (08:33 +0100)
committerMartin Kletzander <mkletzan@redhat.com>
Tue, 16 Dec 2014 14:50:49 +0000 (15:50 +0100)
Currently, when there is an API that's blocking with locked domain and
second API that's waiting in virDomainObjListFindByUUID() for the domain
lock (with the domain list locked) no other API can be executed on any
domain on the whole hypervisor because all would wait for the domain
list to be locked.  This patch adds new optional approach to this in
which the domain is only ref'd (reference counter is incremented)
instead of being locked and is locked *after* the list itself is
unlocked.  We might consider only ref'ing the domain in the future and
leaving locking on particular APIs, but that's no tonight's fairy tale.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
src/conf/domain_conf.c
src/conf/domain_conf.h
src/libvirt_private.syms

index ba33e62b1b344b78578dc7c08617bcfce255e70c..aafc05e50602727f888d1b8bf35d50967fd26ba6 100644 (file)
@@ -1074,8 +1074,10 @@ virDomainObjPtr virDomainObjListFindByID(virDomainObjListPtr doms,
 }
 
 
-virDomainObjPtr virDomainObjListFindByUUID(virDomainObjListPtr doms,
-                                           const unsigned char *uuid)
+static virDomainObjPtr
+virDomainObjListFindByUUIDInternal(virDomainObjListPtr doms,
+                                   const unsigned char *uuid,
+                                   bool ref)
 {
     char uuidstr[VIR_UUID_STRING_BUFLEN];
     virDomainObjPtr obj;
@@ -1084,17 +1086,38 @@ virDomainObjPtr virDomainObjListFindByUUID(virDomainObjListPtr doms,
     virUUIDFormat(uuid, uuidstr);
 
     obj = virHashLookup(doms->objs, uuidstr);
+    if (ref) {
+        virObjectRef(obj);
+        virObjectUnlock(doms);
+    }
     if (obj) {
         virObjectLock(obj);
         if (obj->removing) {
+            if (ref)
+                virObjectUnref(obj);
             virObjectUnlock(obj);
             obj = NULL;
         }
     }
-    virObjectUnlock(doms);
+    if (!ref)
+        virObjectUnlock(doms);
     return obj;
 }
 
+virDomainObjPtr
+virDomainObjListFindByUUID(virDomainObjListPtr doms,
+                           const unsigned char *uuid)
+{
+    return virDomainObjListFindByUUIDInternal(doms, uuid, false);
+}
+
+virDomainObjPtr
+virDomainObjListFindByUUIDRef(virDomainObjListPtr doms,
+                              const unsigned char *uuid)
+{
+    return virDomainObjListFindByUUIDInternal(doms, uuid, true);
+}
+
 static int virDomainObjListSearchName(const void *payload,
                                       const void *name ATTRIBUTE_UNUSED,
                                       const void *data)
index 75e3d2a28355bbe54e77d48e720273b23a487805..57297cdbab26cfe15242dc9e2ff989138c355e36 100644 (file)
@@ -2287,6 +2287,8 @@ virDomainObjPtr virDomainObjListFindByID(virDomainObjListPtr doms,
                                          int id);
 virDomainObjPtr virDomainObjListFindByUUID(virDomainObjListPtr doms,
                                            const unsigned char *uuid);
+virDomainObjPtr virDomainObjListFindByUUIDRef(virDomainObjListPtr doms,
+                                              const unsigned char *uuid);
 virDomainObjPtr virDomainObjListFindByName(virDomainObjListPtr doms,
                                            const char *name);
 
index 363d847c7d8cadf3989a90c21bead54115923fd7..46d9495452695d5f0fe2886ca7dbb9c5ad9b06fc 100644 (file)
@@ -353,6 +353,7 @@ virDomainObjListExport;
 virDomainObjListFindByID;
 virDomainObjListFindByName;
 virDomainObjListFindByUUID;
+virDomainObjListFindByUUIDRef;
 virDomainObjListForEach;
 virDomainObjListGetActiveIDs;
 virDomainObjListGetInactiveNames;