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@xxxxxxxxxx> --- src/conf/domain_conf.c | 27 ++++++++++++++++++++++++--- src/conf/domain_conf.h | 2 ++ src/libvirt_private.syms | 1 + 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 2d81c37..0bb216d 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1068,8 +1068,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; @@ -1078,12 +1080,31 @@ virDomainObjPtr virDomainObjListFindByUUID(virDomainObjListPtr doms, virUUIDFormat(uuid, uuidstr); obj = virHashLookup(doms->objs, uuidstr); + if (ref) { + virObjectRef(obj); + virObjectUnlock(doms); + } if (obj) virObjectLock(obj); - 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) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 439f3c0..3812a16 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2285,6 +2285,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); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 1853a9c..2351b91 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -352,6 +352,7 @@ virDomainObjListExport; virDomainObjListFindByID; virDomainObjListFindByName; virDomainObjListFindByUUID; +virDomainObjListFindByUUIDRef; virDomainObjListForEach; virDomainObjListGetActiveIDs; virDomainObjListGetInactiveNames; -- 2.2.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list