提交 feb1a4d7 编写于 作者: M Martin Kletzander

conf: Rework virDomainObjListFindByUUID to allow more concurrent APIs

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: NMartin Kletzander <mkletzan@redhat.com>
上级 d2632d60
......@@ -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)
......
......@@ -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);
......
......@@ -353,6 +353,7 @@ virDomainObjListExport;
virDomainObjListFindByID;
virDomainObjListFindByName;
virDomainObjListFindByUUID;
virDomainObjListFindByUUIDRef;
virDomainObjListForEach;
virDomainObjListGetActiveIDs;
virDomainObjListGetInactiveNames;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册