mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
test: Drop locked access to testDriver->domains
Only self-locking APIs are used and the pointer is immutable so there's no need to lock the driver to access the domain list. This patch removes locking partially for everything that will not be converted to testDomObjFromDomain in the next patch.
This commit is contained in:
parent
caf5aef4c5
commit
21be8e8ecc
@ -537,7 +537,6 @@ testDomObjFromDomain(virDomainPtr domain)
|
|||||||
testDriverPtr driver = domain->conn->privateData;
|
testDriverPtr driver = domain->conn->privateData;
|
||||||
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
||||||
|
|
||||||
testDriverLock(driver);
|
|
||||||
vm = virDomainObjListFindByUUIDRef(driver->domains, domain->uuid);
|
vm = virDomainObjListFindByUUIDRef(driver->domains, domain->uuid);
|
||||||
if (!vm) {
|
if (!vm) {
|
||||||
virUUIDFormat(domain->uuid, uuidstr);
|
virUUIDFormat(domain->uuid, uuidstr);
|
||||||
@ -546,7 +545,6 @@ testDomObjFromDomain(virDomainPtr domain)
|
|||||||
uuidstr, domain->name);
|
uuidstr, domain->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
testDriverUnlock(driver);
|
|
||||||
return vm;
|
return vm;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1790,11 +1788,7 @@ static virDomainPtr testDomainLookupByID(virConnectPtr conn,
|
|||||||
virDomainPtr ret = NULL;
|
virDomainPtr ret = NULL;
|
||||||
virDomainObjPtr dom;
|
virDomainObjPtr dom;
|
||||||
|
|
||||||
testDriverLock(privconn);
|
if (!(dom = virDomainObjListFindByID(privconn->domains, id))) {
|
||||||
dom = virDomainObjListFindByID(privconn->domains, id);
|
|
||||||
testDriverUnlock(privconn);
|
|
||||||
|
|
||||||
if (dom == NULL) {
|
|
||||||
virReportError(VIR_ERR_NO_DOMAIN, NULL);
|
virReportError(VIR_ERR_NO_DOMAIN, NULL);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -1816,11 +1810,7 @@ static virDomainPtr testDomainLookupByUUID(virConnectPtr conn,
|
|||||||
virDomainPtr ret = NULL;
|
virDomainPtr ret = NULL;
|
||||||
virDomainObjPtr dom;
|
virDomainObjPtr dom;
|
||||||
|
|
||||||
testDriverLock(privconn);
|
if (!(dom = virDomainObjListFindByUUID(privconn->domains, uuid))) {
|
||||||
dom = virDomainObjListFindByUUID(privconn->domains, uuid);
|
|
||||||
testDriverUnlock(privconn);
|
|
||||||
|
|
||||||
if (dom == NULL) {
|
|
||||||
virReportError(VIR_ERR_NO_DOMAIN, NULL);
|
virReportError(VIR_ERR_NO_DOMAIN, NULL);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -1842,11 +1832,7 @@ static virDomainPtr testDomainLookupByName(virConnectPtr conn,
|
|||||||
virDomainPtr ret = NULL;
|
virDomainPtr ret = NULL;
|
||||||
virDomainObjPtr dom;
|
virDomainObjPtr dom;
|
||||||
|
|
||||||
testDriverLock(privconn);
|
if (!(dom = virDomainObjListFindByName(privconn->domains, name))) {
|
||||||
dom = virDomainObjListFindByName(privconn->domains, name);
|
|
||||||
testDriverUnlock(privconn);
|
|
||||||
|
|
||||||
if (dom == NULL) {
|
|
||||||
virReportError(VIR_ERR_NO_DOMAIN, NULL);
|
virReportError(VIR_ERR_NO_DOMAIN, NULL);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -1865,13 +1851,9 @@ static int testConnectListDomains(virConnectPtr conn,
|
|||||||
int maxids)
|
int maxids)
|
||||||
{
|
{
|
||||||
testDriverPtr privconn = conn->privateData;
|
testDriverPtr privconn = conn->privateData;
|
||||||
int n;
|
|
||||||
|
|
||||||
testDriverLock(privconn);
|
return virDomainObjListGetActiveIDs(privconn->domains, ids, maxids,
|
||||||
n = virDomainObjListGetActiveIDs(privconn->domains, ids, maxids, NULL, NULL);
|
NULL, NULL);
|
||||||
testDriverUnlock(privconn);
|
|
||||||
|
|
||||||
return n;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int testDomainDestroy(virDomainPtr domain)
|
static int testDomainDestroy(virDomainPtr domain)
|
||||||
@ -1881,7 +1863,6 @@ static int testDomainDestroy(virDomainPtr domain)
|
|||||||
virObjectEventPtr event = NULL;
|
virObjectEventPtr event = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
testDriverLock(privconn);
|
|
||||||
privdom = virDomainObjListFindByName(privconn->domains,
|
privdom = virDomainObjListFindByName(privconn->domains,
|
||||||
domain->name);
|
domain->name);
|
||||||
|
|
||||||
@ -1902,7 +1883,6 @@ static int testDomainDestroy(virDomainPtr domain)
|
|||||||
cleanup:
|
cleanup:
|
||||||
virDomainObjEndAPI(&privdom);
|
virDomainObjEndAPI(&privdom);
|
||||||
testObjectEventQueue(privconn, event);
|
testObjectEventQueue(privconn, event);
|
||||||
testDriverUnlock(privconn);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1989,7 +1969,6 @@ static int testDomainShutdownFlags(virDomainPtr domain,
|
|||||||
|
|
||||||
virCheckFlags(0, -1);
|
virCheckFlags(0, -1);
|
||||||
|
|
||||||
testDriverLock(privconn);
|
|
||||||
privdom = virDomainObjListFindByName(privconn->domains,
|
privdom = virDomainObjListFindByName(privconn->domains,
|
||||||
domain->name);
|
domain->name);
|
||||||
|
|
||||||
@ -2016,7 +1995,6 @@ static int testDomainShutdownFlags(virDomainPtr domain,
|
|||||||
cleanup:
|
cleanup:
|
||||||
virDomainObjEndAPI(&privdom);
|
virDomainObjEndAPI(&privdom);
|
||||||
testObjectEventQueue(privconn, event);
|
testObjectEventQueue(privconn, event);
|
||||||
testDriverUnlock(privconn);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2034,7 +2012,6 @@ static int testDomainReboot(virDomainPtr domain,
|
|||||||
virObjectEventPtr event = NULL;
|
virObjectEventPtr event = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
testDriverLock(privconn);
|
|
||||||
privdom = virDomainObjListFindByName(privconn->domains,
|
privdom = virDomainObjListFindByName(privconn->domains,
|
||||||
domain->name);
|
domain->name);
|
||||||
|
|
||||||
@ -2087,7 +2064,6 @@ static int testDomainReboot(virDomainPtr domain,
|
|||||||
cleanup:
|
cleanup:
|
||||||
virDomainObjEndAPI(&privdom);
|
virDomainObjEndAPI(&privdom);
|
||||||
testObjectEventQueue(privconn, event);
|
testObjectEventQueue(privconn, event);
|
||||||
testDriverUnlock(privconn);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2178,7 +2154,6 @@ testDomainSaveFlags(virDomainPtr domain, const char *path,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
testDriverLock(privconn);
|
|
||||||
privdom = virDomainObjListFindByName(privconn->domains,
|
privdom = virDomainObjListFindByName(privconn->domains,
|
||||||
domain->name);
|
domain->name);
|
||||||
|
|
||||||
@ -2252,7 +2227,6 @@ testDomainSaveFlags(virDomainPtr domain, const char *path,
|
|||||||
}
|
}
|
||||||
virDomainObjEndAPI(&privdom);
|
virDomainObjEndAPI(&privdom);
|
||||||
testObjectEventQueue(privconn, event);
|
testObjectEventQueue(privconn, event);
|
||||||
testDriverUnlock(privconn);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2286,8 +2260,6 @@ testDomainRestoreFlags(virConnectPtr conn,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
testDriverLock(privconn);
|
|
||||||
|
|
||||||
if ((fd = open(path, O_RDONLY)) < 0) {
|
if ((fd = open(path, O_RDONLY)) < 0) {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("cannot read domain image '%s'"),
|
_("cannot read domain image '%s'"),
|
||||||
@ -2356,7 +2328,6 @@ testDomainRestoreFlags(virConnectPtr conn,
|
|||||||
if (dom)
|
if (dom)
|
||||||
virObjectUnlock(dom);
|
virObjectUnlock(dom);
|
||||||
testObjectEventQueue(privconn, event);
|
testObjectEventQueue(privconn, event);
|
||||||
testDriverUnlock(privconn);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2380,7 +2351,6 @@ static int testDomainCoreDumpWithFormat(virDomainPtr domain,
|
|||||||
|
|
||||||
virCheckFlags(VIR_DUMP_CRASH, -1);
|
virCheckFlags(VIR_DUMP_CRASH, -1);
|
||||||
|
|
||||||
testDriverLock(privconn);
|
|
||||||
privdom = virDomainObjListFindByName(privconn->domains,
|
privdom = virDomainObjListFindByName(privconn->domains,
|
||||||
domain->name);
|
domain->name);
|
||||||
|
|
||||||
@ -2429,7 +2399,6 @@ static int testDomainCoreDumpWithFormat(virDomainPtr domain,
|
|||||||
VIR_FORCE_CLOSE(fd);
|
VIR_FORCE_CLOSE(fd);
|
||||||
virDomainObjEndAPI(&privdom);
|
virDomainObjEndAPI(&privdom);
|
||||||
testObjectEventQueue(privconn, event);
|
testObjectEventQueue(privconn, event);
|
||||||
testDriverUnlock(privconn);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2849,13 +2818,8 @@ static char *testDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)
|
|||||||
static int testConnectNumOfDefinedDomains(virConnectPtr conn)
|
static int testConnectNumOfDefinedDomains(virConnectPtr conn)
|
||||||
{
|
{
|
||||||
testDriverPtr privconn = conn->privateData;
|
testDriverPtr privconn = conn->privateData;
|
||||||
int count;
|
|
||||||
|
|
||||||
testDriverLock(privconn);
|
return virDomainObjListNumOfDomains(privconn->domains, false, NULL, NULL);
|
||||||
count = virDomainObjListNumOfDomains(privconn->domains, false, NULL, NULL);
|
|
||||||
testDriverUnlock(privconn);
|
|
||||||
|
|
||||||
return count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int testConnectListDefinedDomains(virConnectPtr conn,
|
static int testConnectListDefinedDomains(virConnectPtr conn,
|
||||||
@ -2864,15 +2828,10 @@ static int testConnectListDefinedDomains(virConnectPtr conn,
|
|||||||
{
|
{
|
||||||
|
|
||||||
testDriverPtr privconn = conn->privateData;
|
testDriverPtr privconn = conn->privateData;
|
||||||
int n;
|
|
||||||
|
|
||||||
testDriverLock(privconn);
|
|
||||||
memset(names, 0, sizeof(*names)*maxnames);
|
memset(names, 0, sizeof(*names)*maxnames);
|
||||||
n = virDomainObjListGetInactiveNames(privconn->domains, names, maxnames,
|
return virDomainObjListGetInactiveNames(privconn->domains, names, maxnames,
|
||||||
NULL, NULL);
|
NULL, NULL);
|
||||||
testDriverUnlock(privconn);
|
|
||||||
|
|
||||||
return n;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static virDomainPtr testDomainDefineXMLFlags(virConnectPtr conn,
|
static virDomainPtr testDomainDefineXMLFlags(virConnectPtr conn,
|
||||||
@ -2892,7 +2851,6 @@ static virDomainPtr testDomainDefineXMLFlags(virConnectPtr conn,
|
|||||||
if (flags & VIR_DOMAIN_DEFINE_VALIDATE)
|
if (flags & VIR_DOMAIN_DEFINE_VALIDATE)
|
||||||
parse_flags |= VIR_DOMAIN_DEF_PARSE_VALIDATE;
|
parse_flags |= VIR_DOMAIN_DEF_PARSE_VALIDATE;
|
||||||
|
|
||||||
testDriverLock(privconn);
|
|
||||||
if ((def = virDomainDefParseString(xml, privconn->caps, privconn->xmlopt,
|
if ((def = virDomainDefParseString(xml, privconn->caps, privconn->xmlopt,
|
||||||
parse_flags)) == NULL)
|
parse_flags)) == NULL)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -2924,7 +2882,6 @@ static virDomainPtr testDomainDefineXMLFlags(virConnectPtr conn,
|
|||||||
if (dom)
|
if (dom)
|
||||||
virObjectUnlock(dom);
|
virObjectUnlock(dom);
|
||||||
testObjectEventQueue(privconn, event);
|
testObjectEventQueue(privconn, event);
|
||||||
testDriverUnlock(privconn);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3085,7 +3042,6 @@ static int testDomainUndefineFlags(virDomainPtr domain,
|
|||||||
virCheckFlags(VIR_DOMAIN_UNDEFINE_MANAGED_SAVE |
|
virCheckFlags(VIR_DOMAIN_UNDEFINE_MANAGED_SAVE |
|
||||||
VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA, -1);
|
VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA, -1);
|
||||||
|
|
||||||
testDriverLock(privconn);
|
|
||||||
privdom = virDomainObjListFindByName(privconn->domains,
|
privdom = virDomainObjListFindByName(privconn->domains,
|
||||||
domain->name);
|
domain->name);
|
||||||
|
|
||||||
@ -3135,7 +3091,6 @@ static int testDomainUndefineFlags(virDomainPtr domain,
|
|||||||
cleanup:
|
cleanup:
|
||||||
virDomainObjEndAPI(&privdom);
|
virDomainObjEndAPI(&privdom);
|
||||||
testObjectEventQueue(privconn, event);
|
testObjectEventQueue(privconn, event);
|
||||||
testDriverUnlock(privconn);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -6010,16 +5965,11 @@ static int testConnectListAllDomains(virConnectPtr conn,
|
|||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
testDriverPtr privconn = conn->privateData;
|
testDriverPtr privconn = conn->privateData;
|
||||||
int ret;
|
|
||||||
|
|
||||||
virCheckFlags(VIR_CONNECT_LIST_DOMAINS_FILTERS_ALL, -1);
|
virCheckFlags(VIR_CONNECT_LIST_DOMAINS_FILTERS_ALL, -1);
|
||||||
|
|
||||||
testDriverLock(privconn);
|
return virDomainObjListExport(privconn->domains, conn, domains,
|
||||||
ret = virDomainObjListExport(privconn->domains, conn, domains,
|
NULL, flags);
|
||||||
NULL, flags);
|
|
||||||
testDriverUnlock(privconn);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -6821,8 +6771,6 @@ testDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
|
|||||||
if (!(snap = testSnapObjFromSnapshot(vm, snapshot)))
|
if (!(snap = testSnapObjFromSnapshot(vm, snapshot)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
testDriverLock(privconn);
|
|
||||||
|
|
||||||
if (!vm->persistent &&
|
if (!vm->persistent &&
|
||||||
snap->def->state != VIR_DOMAIN_RUNNING &&
|
snap->def->state != VIR_DOMAIN_RUNNING &&
|
||||||
snap->def->state != VIR_DOMAIN_PAUSED &&
|
snap->def->state != VIR_DOMAIN_PAUSED &&
|
||||||
@ -6991,7 +6939,6 @@ testDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
|
|||||||
virObjectUnref(event2);
|
virObjectUnref(event2);
|
||||||
}
|
}
|
||||||
virDomainObjEndAPI(&vm);
|
virDomainObjEndAPI(&vm);
|
||||||
testDriverUnlock(privconn);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user