[libvirt] [PATCH v2 00/15] test driver refactors

Version 2 has a few more fixes as suggested by Michal. Peter Krempa (15): test: Rename testConn to testDriver test: Drop useless forward declaration test: turn 'defaultConn' into a pointer test: Extract code to free testDriver into testDriverFree test: Extract common parts of test driver data allocation test: Drop unused attribute @path from testDriver struct test: Annotate few fields of testDriver structure test: Use atomic access to @nextDomID in struct virTestDriver test: Refactor test driver event sending test: Finalize removal of locking from driver->eventState test: Drop locked access to testDriver->domains test: Refactor test driver domain object retrieval test: Refactor testDomainSetVcpusFlags test: Refactor vcpu pinning and vcpu info retrieval test: Refactor testNodeGetCPUMap src/test/test_driver.c | 1305 +++++++++++++++--------------------------------- 1 file changed, 401 insertions(+), 904 deletions(-) -- 2.4.1

--- src/test/test_driver.c | 308 ++++++++++++++++++++++++------------------------- 1 file changed, 154 insertions(+), 154 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 6613ed7..b1dca29 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -92,7 +92,7 @@ struct _testAuth { typedef struct _testAuth testAuth; typedef struct _testAuth *testAuthPtr; -struct _testConn { +struct _testDriver { virMutex lock; char *path; @@ -114,10 +114,10 @@ struct _testConn { virObjectEventStatePtr eventState; }; -typedef struct _testConn testConn; -typedef testConn *testConnPtr; +typedef struct _testDriver testDriver; +typedef testDriver *testDriverPtr; -static testConn defaultConn; +static testDriver defaultConn; static int defaultConnections; static virMutex defaultLock = VIR_MUTEX_INITIALIZER; @@ -137,15 +137,15 @@ static const virNodeInfo defaultNodeInfo = { static int testConnectClose(virConnectPtr conn); -static void testObjectEventQueue(testConnPtr driver, +static void testObjectEventQueue(testDriverPtr driver, virObjectEventPtr event); -static void testDriverLock(testConnPtr driver) +static void testDriverLock(testDriverPtr driver) { virMutexLock(&driver->lock); } -static void testDriverUnlock(testConnPtr driver) +static void testDriverUnlock(testDriverPtr driver) { virMutexUnlock(&driver->lock); } @@ -311,7 +311,7 @@ testBuildXMLConfig(void) static virCapsPtr testBuildCapabilities(virConnectPtr conn) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; virCapsPtr caps; virCapsGuestPtr guest; int guest_types[] = { VIR_DOMAIN_OSTYPE_HVM, @@ -480,7 +480,7 @@ static virDomainObjPtr testDomObjFromDomain(virDomainPtr domain) { virDomainObjPtr vm; - testConnPtr driver = domain->conn->privateData; + testDriverPtr driver = domain->conn->privateData; char uuidstr[VIR_UUID_STRING_BUFLEN]; testDriverLock(driver); @@ -601,7 +601,7 @@ testDomainUpdateVCPU(virDomainObjPtr dom, * @clear_all: If true, rebuild info for ALL vcpus, not just newly added vcpus */ static int -testDomainUpdateVCPUs(testConnPtr privconn, +testDomainUpdateVCPUs(testDriverPtr privconn, virDomainObjPtr dom, int nvcpus, unsigned int clear_all) @@ -658,7 +658,7 @@ testDomainShutdownState(virDomainPtr domain, /* Set up domain runtime state */ static int -testDomainStartState(testConnPtr privconn, +testDomainStartState(testDriverPtr privconn, virDomainObjPtr dom, virDomainRunningReason reason) { @@ -692,7 +692,7 @@ static int testOpenDefault(virConnectPtr conn) { int u; - testConnPtr privconn = &defaultConn; + testDriverPtr privconn = &defaultConn; virDomainDefPtr domdef = NULL; virDomainObjPtr domobj = NULL; virNetworkDefPtr netdef = NULL; @@ -1002,7 +1002,7 @@ testParseNodeInfo(virNodeInfoPtr nodeInfo, xmlXPathContextPtr ctxt) } static int -testParseDomainSnapshots(testConnPtr privconn, +testParseDomainSnapshots(testDriverPtr privconn, virDomainObjPtr domobj, const char *file, xmlXPathContextPtr ctxt) @@ -1058,7 +1058,7 @@ testParseDomainSnapshots(testConnPtr privconn, } static int -testParseDomains(testConnPtr privconn, +testParseDomains(testDriverPtr privconn, const char *file, xmlXPathContextPtr ctxt) { @@ -1123,7 +1123,7 @@ testParseDomains(testConnPtr privconn, } static int -testParseNetworks(testConnPtr privconn, +testParseNetworks(testDriverPtr privconn, const char *file, xmlXPathContextPtr ctxt) { @@ -1162,7 +1162,7 @@ testParseNetworks(testConnPtr privconn, } static int -testParseInterfaces(testConnPtr privconn, +testParseInterfaces(testDriverPtr privconn, const char *file, xmlXPathContextPtr ctxt) { @@ -1258,7 +1258,7 @@ testOpenVolumesForPool(const char *file, } static int -testParseStorage(testConnPtr privconn, +testParseStorage(testDriverPtr privconn, const char *file, xmlXPathContextPtr ctxt) { @@ -1310,7 +1310,7 @@ testParseStorage(testConnPtr privconn, } static int -testParseNodedevs(testConnPtr privconn, +testParseNodedevs(testDriverPtr privconn, const char *file, xmlXPathContextPtr ctxt) { @@ -1349,7 +1349,7 @@ testParseNodedevs(testConnPtr privconn, } static int -testParseAuthUsers(testConnPtr privconn, +testParseAuthUsers(testDriverPtr privconn, xmlXPathContextPtr ctxt) { int num, ret = -1; @@ -1395,7 +1395,7 @@ testOpenFromFile(virConnectPtr conn, const char *file) { xmlDocPtr doc = NULL; xmlXPathContextPtr ctxt = NULL; - testConnPtr privconn; + testDriverPtr privconn; if (VIR_ALLOC(privconn) < 0) return VIR_DRV_OPEN_ERROR; @@ -1477,7 +1477,7 @@ static int testConnectAuthenticate(virConnectPtr conn, virConnectAuthPtr auth) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; int ret = -1; ssize_t i; char *username = NULL, *password = NULL; @@ -1573,7 +1573,7 @@ static virDrvOpenStatus testConnectOpen(virConnectPtr conn, static int testConnectClose(virConnectPtr conn) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; if (privconn == &defaultConn) { virMutexLock(&defaultLock); @@ -1657,7 +1657,7 @@ testConnectBaselineCPU(virConnectPtr conn ATTRIBUTE_UNUSED, static int testNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; testDriverLock(privconn); memcpy(info, &privconn->nodeInfo, sizeof(virNodeInfo)); testDriverUnlock(privconn); @@ -1666,7 +1666,7 @@ static int testNodeGetInfo(virConnectPtr conn, static char *testConnectGetCapabilities(virConnectPtr conn) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; char *xml; testDriverLock(privconn); xml = virCapabilitiesFormatXML(privconn->caps); @@ -1676,7 +1676,7 @@ static char *testConnectGetCapabilities(virConnectPtr conn) static int testConnectNumOfDomains(virConnectPtr conn) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; int count; testDriverLock(privconn); @@ -1688,7 +1688,7 @@ static int testConnectNumOfDomains(virConnectPtr conn) static int testDomainIsActive(virDomainPtr dom) { - testConnPtr privconn = dom->conn->privateData; + testDriverPtr privconn = dom->conn->privateData; virDomainObjPtr obj; int ret = -1; @@ -1709,7 +1709,7 @@ static int testDomainIsActive(virDomainPtr dom) static int testDomainIsPersistent(virDomainPtr dom) { - testConnPtr privconn = dom->conn->privateData; + testDriverPtr privconn = dom->conn->privateData; virDomainObjPtr obj; int ret = -1; @@ -1737,7 +1737,7 @@ static virDomainPtr testDomainCreateXML(virConnectPtr conn, const char *xml, unsigned int flags) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; virDomainPtr ret = NULL; virDomainDefPtr def; virDomainObjPtr dom = NULL; @@ -1789,7 +1789,7 @@ testDomainCreateXML(virConnectPtr conn, const char *xml, static virDomainPtr testDomainLookupByID(virConnectPtr conn, int id) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; virDomainPtr ret = NULL; virDomainObjPtr dom; @@ -1815,7 +1815,7 @@ static virDomainPtr testDomainLookupByID(virConnectPtr conn, static virDomainPtr testDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; virDomainPtr ret = NULL; virDomainObjPtr dom; @@ -1841,7 +1841,7 @@ static virDomainPtr testDomainLookupByUUID(virConnectPtr conn, static virDomainPtr testDomainLookupByName(virConnectPtr conn, const char *name) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; virDomainPtr ret = NULL; virDomainObjPtr dom; @@ -1867,7 +1867,7 @@ static int testConnectListDomains(virConnectPtr conn, int *ids, int maxids) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; int n; testDriverLock(privconn); @@ -1879,7 +1879,7 @@ static int testConnectListDomains(virConnectPtr conn, static int testDomainDestroy(virDomainPtr domain) { - testConnPtr privconn = domain->conn->privateData; + testDriverPtr privconn = domain->conn->privateData; virDomainObjPtr privdom; virObjectEventPtr event = NULL; int ret = -1; @@ -1912,7 +1912,7 @@ static int testDomainDestroy(virDomainPtr domain) static int testDomainResume(virDomainPtr domain) { - testConnPtr privconn = domain->conn->privateData; + testDriverPtr privconn = domain->conn->privateData; virDomainObjPtr privdom; virObjectEventPtr event = NULL; int ret = -1; @@ -1952,7 +1952,7 @@ static int testDomainResume(virDomainPtr domain) static int testDomainSuspend(virDomainPtr domain) { - testConnPtr privconn = domain->conn->privateData; + testDriverPtr privconn = domain->conn->privateData; virDomainObjPtr privdom; virObjectEventPtr event = NULL; int ret = -1; @@ -1995,7 +1995,7 @@ static int testDomainSuspend(virDomainPtr domain) static int testDomainShutdownFlags(virDomainPtr domain, unsigned int flags) { - testConnPtr privconn = domain->conn->privateData; + testDriverPtr privconn = domain->conn->privateData; virDomainObjPtr privdom; virObjectEventPtr event = NULL; int ret = -1; @@ -2043,7 +2043,7 @@ static int testDomainShutdown(virDomainPtr domain) static int testDomainReboot(virDomainPtr domain, unsigned int action ATTRIBUTE_UNUSED) { - testConnPtr privconn = domain->conn->privateData; + testDriverPtr privconn = domain->conn->privateData; virDomainObjPtr privdom; virObjectEventPtr event = NULL; int ret = -1; @@ -2109,7 +2109,7 @@ static int testDomainReboot(virDomainPtr domain, static int testDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) { - testConnPtr privconn = domain->conn->privateData; + testDriverPtr privconn = domain->conn->privateData; struct timeval tv; virDomainObjPtr privdom; int ret = -1; @@ -2148,7 +2148,7 @@ testDomainGetState(virDomainPtr domain, int *reason, unsigned int flags) { - testConnPtr privconn = domain->conn->privateData; + testDriverPtr privconn = domain->conn->privateData; virDomainObjPtr privdom; int ret = -1; @@ -2178,7 +2178,7 @@ static int testDomainSaveFlags(virDomainPtr domain, const char *path, const char *dxml, unsigned int flags) { - testConnPtr privconn = domain->conn->privateData; + testDriverPtr privconn = domain->conn->privateData; char *xml = NULL; int fd = -1; int len; @@ -2285,7 +2285,7 @@ testDomainRestoreFlags(virConnectPtr conn, const char *dxml, unsigned int flags) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; char *xml = NULL; char magic[15]; int fd = -1; @@ -2389,7 +2389,7 @@ static int testDomainCoreDumpWithFormat(virDomainPtr domain, unsigned int dumpformat, unsigned int flags) { - testConnPtr privconn = domain->conn->privateData; + testDriverPtr privconn = domain->conn->privateData; int fd = -1; virDomainObjPtr privdom; virObjectEventPtr event = NULL; @@ -2475,7 +2475,7 @@ testDomainGetOSType(virDomainPtr dom ATTRIBUTE_UNUSED) static unsigned long long testDomainGetMaxMemory(virDomainPtr domain) { - testConnPtr privconn = domain->conn->privateData; + testDriverPtr privconn = domain->conn->privateData; virDomainObjPtr privdom; unsigned long long ret = 0; @@ -2499,7 +2499,7 @@ testDomainGetMaxMemory(virDomainPtr domain) static int testDomainSetMaxMemory(virDomainPtr domain, unsigned long memory) { - testConnPtr privconn = domain->conn->privateData; + testDriverPtr privconn = domain->conn->privateData; virDomainObjPtr privdom; int ret = -1; @@ -2525,7 +2525,7 @@ static int testDomainSetMaxMemory(virDomainPtr domain, static int testDomainSetMemory(virDomainPtr domain, unsigned long memory) { - testConnPtr privconn = domain->conn->privateData; + testDriverPtr privconn = domain->conn->privateData; virDomainObjPtr privdom; int ret = -1; @@ -2555,7 +2555,7 @@ static int testDomainSetMemory(virDomainPtr domain, static int testDomainGetVcpusFlags(virDomainPtr domain, unsigned int flags) { - testConnPtr privconn = domain->conn->privateData; + testDriverPtr privconn = domain->conn->privateData; virDomainObjPtr vm; virDomainDefPtr def; int ret = -1; @@ -2598,7 +2598,7 @@ static int testDomainSetVcpusFlags(virDomainPtr domain, unsigned int nrCpus, unsigned int flags) { - testConnPtr privconn = domain->conn->privateData; + testDriverPtr privconn = domain->conn->privateData; virDomainObjPtr privdom = NULL; virDomainDefPtr persistentDef; int ret = -1, maxvcpus; @@ -2697,7 +2697,7 @@ static int testDomainGetVcpus(virDomainPtr domain, unsigned char *cpumaps, int maplen) { - testConnPtr privconn = domain->conn->privateData; + testDriverPtr privconn = domain->conn->privateData; testDomainObjPrivatePtr privdomdata; virDomainObjPtr privdom; size_t i; @@ -2783,7 +2783,7 @@ static int testDomainPinVcpu(virDomainPtr domain, unsigned char *cpumap, int maplen) { - testConnPtr privconn = domain->conn->privateData; + testDriverPtr privconn = domain->conn->privateData; testDomainObjPrivatePtr privdomdata; virDomainObjPtr privdom; unsigned char *privcpumap; @@ -2836,7 +2836,7 @@ static int testDomainPinVcpu(virDomainPtr domain, static char *testDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) { - testConnPtr privconn = domain->conn->privateData; + testDriverPtr privconn = domain->conn->privateData; virDomainDefPtr def; virDomainObjPtr privdom; char *ret = NULL; @@ -2866,7 +2866,7 @@ static char *testDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) static int testConnectNumOfDefinedDomains(virConnectPtr conn) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; int count; testDriverLock(privconn); @@ -2881,7 +2881,7 @@ static int testConnectListDefinedDomains(virConnectPtr conn, int maxnames) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; int n; testDriverLock(privconn); @@ -2897,7 +2897,7 @@ static virDomainPtr testDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; virDomainPtr ret = NULL; virDomainDefPtr def; virDomainObjPtr dom = NULL; @@ -2958,7 +2958,7 @@ static char *testDomainGetMetadata(virDomainPtr dom, const char *uri, unsigned int flags) { - testConnPtr privconn = dom->conn->privateData; + testDriverPtr privconn = dom->conn->privateData; virDomainObjPtr privdom; char *ret = NULL; @@ -2990,7 +2990,7 @@ static int testDomainSetMetadata(virDomainPtr dom, const char *uri, unsigned int flags) { - testConnPtr privconn = dom->conn->privateData; + testDriverPtr privconn = dom->conn->privateData; virDomainObjPtr privdom; int ret = -1; @@ -3021,7 +3021,7 @@ static int testNodeGetCellsFreeMemory(virConnectPtr conn, unsigned long long *freemems, int startCell, int maxCells) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; int cell; size_t i; int ret = -1; @@ -3048,7 +3048,7 @@ static int testNodeGetCellsFreeMemory(virConnectPtr conn, static int testDomainCreateWithFlags(virDomainPtr domain, unsigned int flags) { - testConnPtr privconn = domain->conn->privateData; + testDriverPtr privconn = domain->conn->privateData; virDomainObjPtr privdom; virObjectEventPtr event = NULL; int ret = -1; @@ -3096,7 +3096,7 @@ static int testDomainCreate(virDomainPtr domain) static int testDomainUndefineFlags(virDomainPtr domain, unsigned int flags) { - testConnPtr privconn = domain->conn->privateData; + testDriverPtr privconn = domain->conn->privateData; virDomainObjPtr privdom; virObjectEventPtr event = NULL; int nsnapshots; @@ -3168,7 +3168,7 @@ static int testDomainUndefine(virDomainPtr domain) static int testDomainGetAutostart(virDomainPtr domain, int *autostart) { - testConnPtr privconn = domain->conn->privateData; + testDriverPtr privconn = domain->conn->privateData; virDomainObjPtr privdom; int ret = -1; @@ -3194,7 +3194,7 @@ static int testDomainGetAutostart(virDomainPtr domain, static int testDomainSetAutostart(virDomainPtr domain, int autostart) { - testConnPtr privconn = domain->conn->privateData; + testDriverPtr privconn = domain->conn->privateData; virDomainObjPtr privdom; int ret = -1; @@ -3235,7 +3235,7 @@ testDomainGetSchedulerParametersFlags(virDomainPtr domain, int *nparams, unsigned int flags) { - testConnPtr privconn = domain->conn->privateData; + testDriverPtr privconn = domain->conn->privateData; virDomainObjPtr privdom; int ret = -1; @@ -3279,7 +3279,7 @@ testDomainSetSchedulerParametersFlags(virDomainPtr domain, int nparams, unsigned int flags) { - testConnPtr privconn = domain->conn->privateData; + testDriverPtr privconn = domain->conn->privateData; virDomainObjPtr privdom; int ret = -1; size_t i; @@ -3327,7 +3327,7 @@ static int testDomainBlockStats(virDomainPtr domain, const char *path, virDomainBlockStatsPtr stats) { - testConnPtr privconn = domain->conn->privateData; + testDriverPtr privconn = domain->conn->privateData; virDomainObjPtr privdom; struct timeval tv; unsigned long long statbase; @@ -3379,7 +3379,7 @@ static int testDomainInterfaceStats(virDomainPtr domain, const char *path, virDomainInterfaceStatsPtr stats) { - testConnPtr privconn = domain->conn->privateData; + testDriverPtr privconn = domain->conn->privateData; virDomainObjPtr privdom; struct timeval tv; unsigned long long statbase; @@ -3437,7 +3437,7 @@ static int testDomainInterfaceStats(virDomainPtr domain, static virNetworkPtr testNetworkLookupByUUID(virConnectPtr conn, const unsigned char *uuid) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; virNetworkObjPtr net; virNetworkPtr ret = NULL; @@ -3457,7 +3457,7 @@ static virNetworkPtr testNetworkLookupByUUID(virConnectPtr conn, static virNetworkPtr testNetworkLookupByName(virConnectPtr conn, const char *name) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; virNetworkObjPtr net; virNetworkPtr ret = NULL; @@ -3477,7 +3477,7 @@ static virNetworkPtr testNetworkLookupByName(virConnectPtr conn, static int testConnectNumOfNetworks(virConnectPtr conn) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; int numActive; numActive = virNetworkObjListNumOfNetworks(privconn->networks, @@ -3486,7 +3486,7 @@ static int testConnectNumOfNetworks(virConnectPtr conn) } static int testConnectListNetworks(virConnectPtr conn, char **const names, int nnames) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; int n; n = virNetworkObjListGetNames(privconn->networks, @@ -3496,7 +3496,7 @@ static int testConnectListNetworks(virConnectPtr conn, char **const names, int n static int testConnectNumOfDefinedNetworks(virConnectPtr conn) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; int numInactive; numInactive = virNetworkObjListNumOfNetworks(privconn->networks, @@ -3505,7 +3505,7 @@ static int testConnectNumOfDefinedNetworks(virConnectPtr conn) } static int testConnectListDefinedNetworks(virConnectPtr conn, char **const names, int nnames) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; int n; n = virNetworkObjListGetNames(privconn->networks, @@ -3518,7 +3518,7 @@ testConnectListAllNetworks(virConnectPtr conn, virNetworkPtr **nets, unsigned int flags) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; virCheckFlags(VIR_CONNECT_LIST_NETWORKS_FILTERS_ALL, -1); @@ -3527,7 +3527,7 @@ testConnectListAllNetworks(virConnectPtr conn, static int testNetworkIsActive(virNetworkPtr net) { - testConnPtr privconn = net->conn->privateData; + testDriverPtr privconn = net->conn->privateData; virNetworkObjPtr obj; int ret = -1; @@ -3545,7 +3545,7 @@ static int testNetworkIsActive(virNetworkPtr net) static int testNetworkIsPersistent(virNetworkPtr net) { - testConnPtr privconn = net->conn->privateData; + testDriverPtr privconn = net->conn->privateData; virNetworkObjPtr obj; int ret = -1; @@ -3564,7 +3564,7 @@ static int testNetworkIsPersistent(virNetworkPtr net) static virNetworkPtr testNetworkCreateXML(virConnectPtr conn, const char *xml) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; virNetworkDefPtr def; virNetworkObjPtr net = NULL; virNetworkPtr ret = NULL; @@ -3597,7 +3597,7 @@ static virNetworkPtr testNetworkCreateXML(virConnectPtr conn, const char *xml) static virNetworkPtr testNetworkDefineXML(virConnectPtr conn, const char *xml) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; virNetworkDefPtr def; virNetworkObjPtr net = NULL; virNetworkPtr ret = NULL; @@ -3626,7 +3626,7 @@ virNetworkPtr testNetworkDefineXML(virConnectPtr conn, const char *xml) static int testNetworkUndefine(virNetworkPtr network) { - testConnPtr privconn = network->conn->privateData; + testDriverPtr privconn = network->conn->privateData; virNetworkObjPtr privnet; int ret = -1; virObjectEventPtr event = NULL; @@ -3666,7 +3666,7 @@ testNetworkUpdate(virNetworkPtr net, const char *xml, unsigned int flags) { - testConnPtr privconn = net->conn->privateData; + testDriverPtr privconn = net->conn->privateData; virNetworkObjPtr network = NULL; int isActive, ret = -1; @@ -3706,7 +3706,7 @@ testNetworkUpdate(virNetworkPtr net, static int testNetworkCreate(virNetworkPtr network) { - testConnPtr privconn = network->conn->privateData; + testDriverPtr privconn = network->conn->privateData; virNetworkObjPtr privnet; int ret = -1; virObjectEventPtr event = NULL; @@ -3738,7 +3738,7 @@ static int testNetworkCreate(virNetworkPtr network) static int testNetworkDestroy(virNetworkPtr network) { - testConnPtr privconn = network->conn->privateData; + testDriverPtr privconn = network->conn->privateData; virNetworkObjPtr privnet; int ret = -1; virObjectEventPtr event = NULL; @@ -3768,7 +3768,7 @@ static int testNetworkDestroy(virNetworkPtr network) static char *testNetworkGetXMLDesc(virNetworkPtr network, unsigned int flags) { - testConnPtr privconn = network->conn->privateData; + testDriverPtr privconn = network->conn->privateData; virNetworkObjPtr privnet; char *ret = NULL; @@ -3788,7 +3788,7 @@ static char *testNetworkGetXMLDesc(virNetworkPtr network, } static char *testNetworkGetBridgeName(virNetworkPtr network) { - testConnPtr privconn = network->conn->privateData; + testDriverPtr privconn = network->conn->privateData; char *bridge = NULL; virNetworkObjPtr privnet; @@ -3815,7 +3815,7 @@ static char *testNetworkGetBridgeName(virNetworkPtr network) { static int testNetworkGetAutostart(virNetworkPtr network, int *autostart) { - testConnPtr privconn = network->conn->privateData; + testDriverPtr privconn = network->conn->privateData; virNetworkObjPtr privnet; int ret = -1; @@ -3836,7 +3836,7 @@ static int testNetworkGetAutostart(virNetworkPtr network, static int testNetworkSetAutostart(virNetworkPtr network, int autostart) { - testConnPtr privconn = network->conn->privateData; + testDriverPtr privconn = network->conn->privateData; virNetworkObjPtr privnet; int ret = -1; @@ -3862,7 +3862,7 @@ static int testNetworkSetAutostart(virNetworkPtr network, static int testConnectNumOfInterfaces(virConnectPtr conn) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; size_t i; int count = 0; @@ -3879,7 +3879,7 @@ static int testConnectNumOfInterfaces(virConnectPtr conn) static int testConnectListInterfaces(virConnectPtr conn, char **const names, int nnames) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; int n = 0; size_t i; @@ -3908,7 +3908,7 @@ static int testConnectListInterfaces(virConnectPtr conn, char **const names, int static int testConnectNumOfDefinedInterfaces(virConnectPtr conn) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; size_t i; int count = 0; @@ -3925,7 +3925,7 @@ static int testConnectNumOfDefinedInterfaces(virConnectPtr conn) static int testConnectListDefinedInterfaces(virConnectPtr conn, char **const names, int nnames) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; int n = 0; size_t i; @@ -3955,7 +3955,7 @@ static int testConnectListDefinedInterfaces(virConnectPtr conn, char **const nam static virInterfacePtr testInterfaceLookupByName(virConnectPtr conn, const char *name) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; virInterfaceObjPtr iface; virInterfacePtr ret = NULL; @@ -3979,7 +3979,7 @@ static virInterfacePtr testInterfaceLookupByName(virConnectPtr conn, static virInterfacePtr testInterfaceLookupByMACString(virConnectPtr conn, const char *mac) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; virInterfaceObjPtr iface; int ifacect; virInterfacePtr ret = NULL; @@ -4008,7 +4008,7 @@ static virInterfacePtr testInterfaceLookupByMACString(virConnectPtr conn, static int testInterfaceIsActive(virInterfacePtr iface) { - testConnPtr privconn = iface->conn->privateData; + testDriverPtr privconn = iface->conn->privateData; virInterfaceObjPtr obj; int ret = -1; @@ -4030,7 +4030,7 @@ static int testInterfaceIsActive(virInterfacePtr iface) static int testInterfaceChangeBegin(virConnectPtr conn, unsigned int flags) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; int ret = -1; virCheckFlags(0, -1); @@ -4057,7 +4057,7 @@ static int testInterfaceChangeBegin(virConnectPtr conn, static int testInterfaceChangeCommit(virConnectPtr conn, unsigned int flags) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; int ret = -1; virCheckFlags(0, -1); @@ -4085,7 +4085,7 @@ static int testInterfaceChangeCommit(virConnectPtr conn, static int testInterfaceChangeRollback(virConnectPtr conn, unsigned int flags) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; int ret = -1; virCheckFlags(0, -1); @@ -4117,7 +4117,7 @@ static int testInterfaceChangeRollback(virConnectPtr conn, static char *testInterfaceGetXMLDesc(virInterfacePtr iface, unsigned int flags) { - testConnPtr privconn = iface->conn->privateData; + testDriverPtr privconn = iface->conn->privateData; virInterfaceObjPtr privinterface; char *ret = NULL; @@ -4145,7 +4145,7 @@ static char *testInterfaceGetXMLDesc(virInterfacePtr iface, static virInterfacePtr testInterfaceDefineXML(virConnectPtr conn, const char *xmlStr, unsigned int flags) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; virInterfaceDefPtr def; virInterfaceObjPtr iface = NULL; virInterfacePtr ret = NULL; @@ -4172,7 +4172,7 @@ static virInterfacePtr testInterfaceDefineXML(virConnectPtr conn, const char *xm static int testInterfaceUndefine(virInterfacePtr iface) { - testConnPtr privconn = iface->conn->privateData; + testDriverPtr privconn = iface->conn->privateData; virInterfaceObjPtr privinterface; int ret = -1; @@ -4197,7 +4197,7 @@ static int testInterfaceUndefine(virInterfacePtr iface) static int testInterfaceCreate(virInterfacePtr iface, unsigned int flags) { - testConnPtr privconn = iface->conn->privateData; + testDriverPtr privconn = iface->conn->privateData; virInterfaceObjPtr privinterface; int ret = -1; @@ -4230,7 +4230,7 @@ static int testInterfaceCreate(virInterfacePtr iface, static int testInterfaceDestroy(virInterfacePtr iface, unsigned int flags) { - testConnPtr privconn = iface->conn->privateData; + testDriverPtr privconn = iface->conn->privateData; virInterfaceObjPtr privinterface; int ret = -1; @@ -4282,7 +4282,7 @@ static virStoragePoolPtr testStoragePoolLookupByUUID(virConnectPtr conn, const unsigned char *uuid) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; virStoragePoolObjPtr pool; virStoragePoolPtr ret = NULL; @@ -4308,7 +4308,7 @@ static virStoragePoolPtr testStoragePoolLookupByName(virConnectPtr conn, const char *name) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; virStoragePoolObjPtr pool; virStoragePoolPtr ret = NULL; @@ -4339,7 +4339,7 @@ testStoragePoolLookupByVolume(virStorageVolPtr vol) static int testConnectNumOfStoragePools(virConnectPtr conn) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; int numActive = 0; size_t i; @@ -4357,7 +4357,7 @@ testConnectListStoragePools(virConnectPtr conn, char **const names, int nnames) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; int n = 0; size_t i; @@ -4386,7 +4386,7 @@ testConnectListStoragePools(virConnectPtr conn, static int testConnectNumOfDefinedStoragePools(virConnectPtr conn) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; int numInactive = 0; size_t i; @@ -4407,7 +4407,7 @@ testConnectListDefinedStoragePools(virConnectPtr conn, char **const names, int nnames) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; int n = 0; size_t i; @@ -4438,7 +4438,7 @@ testConnectListAllStoragePools(virConnectPtr conn, virStoragePoolPtr **pools, unsigned int flags) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; int ret = -1; virCheckFlags(VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_ALL, -1); @@ -4453,7 +4453,7 @@ testConnectListAllStoragePools(virConnectPtr conn, static int testStoragePoolIsActive(virStoragePoolPtr pool) { - testConnPtr privconn = pool->conn->privateData; + testDriverPtr privconn = pool->conn->privateData; virStoragePoolObjPtr obj; int ret = -1; @@ -4474,7 +4474,7 @@ static int testStoragePoolIsActive(virStoragePoolPtr pool) static int testStoragePoolIsPersistent(virStoragePoolPtr pool) { - testConnPtr privconn = pool->conn->privateData; + testDriverPtr privconn = pool->conn->privateData; virStoragePoolObjPtr obj; int ret = -1; @@ -4499,7 +4499,7 @@ static int testStoragePoolCreate(virStoragePoolPtr pool, unsigned int flags) { - testConnPtr privconn = pool->conn->privateData; + testDriverPtr privconn = pool->conn->privateData; virStoragePoolObjPtr privpool; int ret = -1; @@ -4588,7 +4588,7 @@ testStoragePoolCreateXML(virConnectPtr conn, const char *xml, unsigned int flags) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; virStoragePoolDefPtr def; virStoragePoolObjPtr pool = NULL; virStoragePoolPtr ret = NULL; @@ -4635,7 +4635,7 @@ testStoragePoolDefineXML(virConnectPtr conn, const char *xml, unsigned int flags) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; virStoragePoolDefPtr def; virStoragePoolObjPtr pool = NULL; virStoragePoolPtr ret = NULL; @@ -4674,7 +4674,7 @@ testStoragePoolDefineXML(virConnectPtr conn, static int testStoragePoolUndefine(virStoragePoolPtr pool) { - testConnPtr privconn = pool->conn->privateData; + testDriverPtr privconn = pool->conn->privateData; virStoragePoolObjPtr privpool; int ret = -1; @@ -4707,7 +4707,7 @@ static int testStoragePoolBuild(virStoragePoolPtr pool, unsigned int flags) { - testConnPtr privconn = pool->conn->privateData; + testDriverPtr privconn = pool->conn->privateData; virStoragePoolObjPtr privpool; int ret = -1; @@ -4740,7 +4740,7 @@ testStoragePoolBuild(virStoragePoolPtr pool, static int testStoragePoolDestroy(virStoragePoolPtr pool) { - testConnPtr privconn = pool->conn->privateData; + testDriverPtr privconn = pool->conn->privateData; virStoragePoolObjPtr privpool; int ret = -1; @@ -4779,7 +4779,7 @@ static int testStoragePoolDelete(virStoragePoolPtr pool, unsigned int flags) { - testConnPtr privconn = pool->conn->privateData; + testDriverPtr privconn = pool->conn->privateData; virStoragePoolObjPtr privpool; int ret = -1; @@ -4814,7 +4814,7 @@ static int testStoragePoolRefresh(virStoragePoolPtr pool, unsigned int flags) { - testConnPtr privconn = pool->conn->privateData; + testDriverPtr privconn = pool->conn->privateData; virStoragePoolObjPtr privpool; int ret = -1; @@ -4848,7 +4848,7 @@ static int testStoragePoolGetInfo(virStoragePoolPtr pool, virStoragePoolInfoPtr info) { - testConnPtr privconn = pool->conn->privateData; + testDriverPtr privconn = pool->conn->privateData; virStoragePoolObjPtr privpool; int ret = -1; @@ -4882,7 +4882,7 @@ static char * testStoragePoolGetXMLDesc(virStoragePoolPtr pool, unsigned int flags) { - testConnPtr privconn = pool->conn->privateData; + testDriverPtr privconn = pool->conn->privateData; virStoragePoolObjPtr privpool; char *ret = NULL; @@ -4910,7 +4910,7 @@ static int testStoragePoolGetAutostart(virStoragePoolPtr pool, int *autostart) { - testConnPtr privconn = pool->conn->privateData; + testDriverPtr privconn = pool->conn->privateData; virStoragePoolObjPtr privpool; int ret = -1; @@ -4941,7 +4941,7 @@ static int testStoragePoolSetAutostart(virStoragePoolPtr pool, int autostart) { - testConnPtr privconn = pool->conn->privateData; + testDriverPtr privconn = pool->conn->privateData; virStoragePoolObjPtr privpool; int ret = -1; @@ -4975,7 +4975,7 @@ testStoragePoolSetAutostart(virStoragePoolPtr pool, static int testStoragePoolNumOfVolumes(virStoragePoolPtr pool) { - testConnPtr privconn = pool->conn->privateData; + testDriverPtr privconn = pool->conn->privateData; virStoragePoolObjPtr privpool; int ret = -1; @@ -5008,7 +5008,7 @@ testStoragePoolListVolumes(virStoragePoolPtr pool, char **const names, int maxnames) { - testConnPtr privconn = pool->conn->privateData; + testDriverPtr privconn = pool->conn->privateData; virStoragePoolObjPtr privpool; size_t i = 0; int n = 0; @@ -5055,7 +5055,7 @@ testStoragePoolListAllVolumes(virStoragePoolPtr obj, virStorageVolPtr **vols, unsigned int flags) { - testConnPtr privconn = obj->conn->privateData; + testDriverPtr privconn = obj->conn->privateData; virStoragePoolObjPtr pool; size_t i; virStorageVolPtr *tmp_vols = NULL; @@ -5122,7 +5122,7 @@ static virStorageVolPtr testStorageVolLookupByName(virStoragePoolPtr pool, const char *name ATTRIBUTE_UNUSED) { - testConnPtr privconn = pool->conn->privateData; + testDriverPtr privconn = pool->conn->privateData; virStoragePoolObjPtr privpool; virStorageVolDefPtr privvol; virStorageVolPtr ret = NULL; @@ -5167,7 +5167,7 @@ static virStorageVolPtr testStorageVolLookupByKey(virConnectPtr conn, const char *key) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; size_t i; virStorageVolPtr ret = NULL; @@ -5203,7 +5203,7 @@ static virStorageVolPtr testStorageVolLookupByPath(virConnectPtr conn, const char *path) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; size_t i; virStorageVolPtr ret = NULL; @@ -5240,7 +5240,7 @@ testStorageVolCreateXML(virStoragePoolPtr pool, const char *xmldesc, unsigned int flags) { - testConnPtr privconn = pool->conn->privateData; + testDriverPtr privconn = pool->conn->privateData; virStoragePoolObjPtr privpool; virStorageVolDefPtr privvol = NULL; virStorageVolPtr ret = NULL; @@ -5314,7 +5314,7 @@ testStorageVolCreateXMLFrom(virStoragePoolPtr pool, virStorageVolPtr clonevol, unsigned int flags) { - testConnPtr privconn = pool->conn->privateData; + testDriverPtr privconn = pool->conn->privateData; virStoragePoolObjPtr privpool; virStorageVolDefPtr privvol = NULL, origvol = NULL; virStorageVolPtr ret = NULL; @@ -5396,7 +5396,7 @@ static int testStorageVolDelete(virStorageVolPtr vol, unsigned int flags) { - testConnPtr privconn = vol->conn->privateData; + testDriverPtr privconn = vol->conn->privateData; virStoragePoolObjPtr privpool; virStorageVolDefPtr privvol; size_t i; @@ -5469,7 +5469,7 @@ static int testStorageVolGetInfo(virStorageVolPtr vol, virStorageVolInfoPtr info) { - testConnPtr privconn = vol->conn->privateData; + testDriverPtr privconn = vol->conn->privateData; virStoragePoolObjPtr privpool; virStorageVolDefPtr privvol; int ret = -1; @@ -5515,7 +5515,7 @@ static char * testStorageVolGetXMLDesc(virStorageVolPtr vol, unsigned int flags) { - testConnPtr privconn = vol->conn->privateData; + testDriverPtr privconn = vol->conn->privateData; virStoragePoolObjPtr privpool; virStorageVolDefPtr privvol; char *ret = NULL; @@ -5558,7 +5558,7 @@ testStorageVolGetXMLDesc(virStorageVolPtr vol, static char * testStorageVolGetPath(virStorageVolPtr vol) { - testConnPtr privconn = vol->conn->privateData; + testDriverPtr privconn = vol->conn->privateData; virStoragePoolObjPtr privpool; virStorageVolDefPtr privvol; char *ret = NULL; @@ -5604,7 +5604,7 @@ testNodeNumOfDevices(virConnectPtr conn, const char *cap, unsigned int flags) { - testConnPtr driver = conn->privateData; + testDriverPtr driver = conn->privateData; int ndevs = 0; size_t i; @@ -5627,7 +5627,7 @@ testNodeListDevices(virConnectPtr conn, int maxnames, unsigned int flags) { - testConnPtr driver = conn->privateData; + testDriverPtr driver = conn->privateData; int ndevs = 0; size_t i; @@ -5660,7 +5660,7 @@ testNodeListDevices(virConnectPtr conn, static virNodeDevicePtr testNodeDeviceLookupByName(virConnectPtr conn, const char *name) { - testConnPtr driver = conn->privateData; + testDriverPtr driver = conn->privateData; virNodeDeviceObjPtr obj; virNodeDevicePtr ret = NULL; @@ -5687,7 +5687,7 @@ static char * testNodeDeviceGetXMLDesc(virNodeDevicePtr dev, unsigned int flags) { - testConnPtr driver = dev->conn->privateData; + testDriverPtr driver = dev->conn->privateData; virNodeDeviceObjPtr obj; char *ret = NULL; @@ -5715,7 +5715,7 @@ testNodeDeviceGetXMLDesc(virNodeDevicePtr dev, static char * testNodeDeviceGetParent(virNodeDevicePtr dev) { - testConnPtr driver = dev->conn->privateData; + testDriverPtr driver = dev->conn->privateData; virNodeDeviceObjPtr obj; char *ret = NULL; @@ -5747,7 +5747,7 @@ testNodeDeviceGetParent(virNodeDevicePtr dev) static int testNodeDeviceNumOfCaps(virNodeDevicePtr dev) { - testConnPtr driver = dev->conn->privateData; + testDriverPtr driver = dev->conn->privateData; virNodeDeviceObjPtr obj; virNodeDevCapsDefPtr caps; int ncaps = 0; @@ -5778,7 +5778,7 @@ testNodeDeviceNumOfCaps(virNodeDevicePtr dev) static int testNodeDeviceListCaps(virNodeDevicePtr dev, char **const names, int maxnames) { - testConnPtr driver = dev->conn->privateData; + testDriverPtr driver = dev->conn->privateData; virNodeDeviceObjPtr obj; virNodeDevCapsDefPtr caps; int ncaps = 0; @@ -5817,7 +5817,7 @@ testNodeDeviceCreateXML(virConnectPtr conn, const char *xmlDesc, unsigned int flags) { - testConnPtr driver = conn->privateData; + testDriverPtr driver = conn->privateData; virNodeDeviceDefPtr def = NULL; virNodeDeviceObjPtr obj = NULL; char *wwnn = NULL, *wwpn = NULL; @@ -5881,7 +5881,7 @@ static int testNodeDeviceDestroy(virNodeDevicePtr dev) { int ret = 0; - testConnPtr driver = dev->conn->privateData; + testDriverPtr driver = dev->conn->privateData; virNodeDeviceObjPtr obj = NULL; char *parent_name = NULL, *wwnn = NULL, *wwpn = NULL; int parent_host = -1; @@ -5938,7 +5938,7 @@ testConnectDomainEventRegister(virConnectPtr conn, void *opaque, virFreeCallback freecb) { - testConnPtr driver = conn->privateData; + testDriverPtr driver = conn->privateData; int ret = 0; testDriverLock(driver); @@ -5955,7 +5955,7 @@ static int testConnectDomainEventDeregister(virConnectPtr conn, virConnectDomainEventCallback callback) { - testConnPtr driver = conn->privateData; + testDriverPtr driver = conn->privateData; int ret = 0; testDriverLock(driver); @@ -5976,7 +5976,7 @@ testConnectDomainEventRegisterAny(virConnectPtr conn, void *opaque, virFreeCallback freecb) { - testConnPtr driver = conn->privateData; + testDriverPtr driver = conn->privateData; int ret; testDriverLock(driver); @@ -5993,7 +5993,7 @@ static int testConnectDomainEventDeregisterAny(virConnectPtr conn, int callbackID) { - testConnPtr driver = conn->privateData; + testDriverPtr driver = conn->privateData; int ret = 0; testDriverLock(driver); @@ -6014,7 +6014,7 @@ testConnectNetworkEventRegisterAny(virConnectPtr conn, void *opaque, virFreeCallback freecb) { - testConnPtr driver = conn->privateData; + testDriverPtr driver = conn->privateData; int ret; testDriverLock(driver); @@ -6031,7 +6031,7 @@ static int testConnectNetworkEventDeregisterAny(virConnectPtr conn, int callbackID) { - testConnPtr driver = conn->privateData; + testDriverPtr driver = conn->privateData; int ret = 0; testDriverLock(driver); @@ -6045,7 +6045,7 @@ testConnectNetworkEventDeregisterAny(virConnectPtr conn, /* driver must be locked before calling */ -static void testObjectEventQueue(testConnPtr driver, +static void testObjectEventQueue(testDriverPtr driver, virObjectEventPtr event) { virObjectEventStateQueue(driver->eventState, event); @@ -6056,7 +6056,7 @@ static int testConnectListAllDomains(virConnectPtr conn, virDomainPtr **domains, unsigned int flags) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; int ret; virCheckFlags(VIR_CONNECT_LIST_DOMAINS_FILTERS_ALL, -1); @@ -6075,7 +6075,7 @@ testNodeGetCPUMap(virConnectPtr conn, unsigned int *online, unsigned int flags) { - testConnPtr privconn = conn->privateData; + testDriverPtr privconn = conn->privateData; int ret = -1; virCheckFlags(0, -1); @@ -6129,7 +6129,7 @@ testConnectGetCPUModelNames(virConnectPtr conn ATTRIBUTE_UNUSED, static int testDomainManagedSave(virDomainPtr dom, unsigned int flags) { - testConnPtr privconn = dom->conn->privateData; + testDriverPtr privconn = dom->conn->privateData; virDomainObjPtr vm = NULL; virObjectEventPtr event = NULL; int ret = -1; @@ -6181,7 +6181,7 @@ testDomainManagedSave(virDomainPtr dom, unsigned int flags) static int testDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags) { - testConnPtr privconn = dom->conn->privateData; + testDriverPtr privconn = dom->conn->privateData; virDomainObjPtr vm; int ret = -1; @@ -6205,7 +6205,7 @@ testDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags) static int testDomainManagedSaveRemove(virDomainPtr dom, unsigned int flags) { - testConnPtr privconn = dom->conn->privateData; + testDriverPtr privconn = dom->conn->privateData; virDomainObjPtr vm; int ret = -1; @@ -6597,7 +6597,7 @@ testDomainSnapshotCreateXML(virDomainPtr domain, const char *xmlDesc, unsigned int flags) { - testConnPtr privconn = domain->conn->privateData; + testDriverPtr privconn = domain->conn->privateData; virDomainObjPtr vm = NULL; virDomainSnapshotDefPtr def = NULL; virDomainSnapshotObjPtr snap = NULL; @@ -6844,7 +6844,7 @@ static int testDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, unsigned int flags) { - testConnPtr privconn = snapshot->domain->conn->privateData; + testDriverPtr privconn = snapshot->domain->conn->privateData; virDomainObjPtr vm = NULL; virDomainSnapshotObjPtr snap = NULL; virObjectEventPtr event = NULL; -- 2.4.1

--- src/test/test_driver.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index b1dca29..8d2bb5b 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -136,7 +136,6 @@ static const virNodeInfo defaultNodeInfo = { }; -static int testConnectClose(virConnectPtr conn); static void testObjectEventQueue(testDriverPtr driver, virObjectEventPtr event); -- 2.4.1

--- src/test/test_driver.c | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 8d2bb5b..ff383c6 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -117,7 +117,7 @@ struct _testDriver { typedef struct _testDriver testDriver; typedef testDriver *testDriverPtr; -static testDriver defaultConn; +static testDriverPtr defaultConn; static int defaultConnections; static virMutex defaultLock = VIR_MUTEX_INITIALIZER; @@ -691,7 +691,7 @@ static int testOpenDefault(virConnectPtr conn) { int u; - testDriverPtr privconn = &defaultConn; + testDriverPtr privconn = NULL; virDomainDefPtr domdef = NULL; virDomainObjPtr domobj = NULL; virNetworkDefPtr netdef = NULL; @@ -705,17 +705,18 @@ testOpenDefault(virConnectPtr conn) virMutexLock(&defaultLock); if (defaultConnections++) { - conn->privateData = &defaultConn; + conn->privateData = defaultConn; virMutexUnlock(&defaultLock); return VIR_DRV_OPEN_SUCCESS; } + if (VIR_ALLOC(privconn) < 0) + goto error; + if (virMutexInit(&privconn->lock) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot initialize mutex")); - defaultConnections--; - virMutexUnlock(&defaultLock); - return VIR_DRV_OPEN_ERROR; + goto error; } conn->privateData = privconn; @@ -822,19 +823,23 @@ testOpenDefault(virConnectPtr conn) } virNodeDeviceObjUnlock(nodeobj); + defaultConn = privconn; + virMutexUnlock(&defaultLock); return VIR_DRV_OPEN_SUCCESS; error: - virObjectUnref(privconn->domains); - virObjectUnref(privconn->networks); - virInterfaceObjListFree(&privconn->ifaces); - virStoragePoolObjListFree(&privconn->pools); - virNodeDeviceObjListFree(&privconn->devs); - virObjectUnref(privconn->caps); - virObjectEventStateFree(privconn->eventState); - virMutexDestroy(&privconn->lock); + if (privconn) { + virObjectUnref(privconn->domains); + virObjectUnref(privconn->networks); + virInterfaceObjListFree(&privconn->ifaces); + virStoragePoolObjListFree(&privconn->pools); + virNodeDeviceObjListFree(&privconn->devs); + virObjectUnref(privconn->caps); + virObjectEventStateFree(privconn->eventState); + virMutexDestroy(&privconn->lock); + } conn->privateData = NULL; virDomainDefFree(domdef); defaultConnections--; @@ -1573,8 +1578,10 @@ static virDrvOpenStatus testConnectOpen(virConnectPtr conn, static int testConnectClose(virConnectPtr conn) { testDriverPtr privconn = conn->privateData; + bool dflt = false; - if (privconn == &defaultConn) { + if (privconn == defaultConn) { + dflt = true; virMutexLock(&defaultLock); if (--defaultConnections) { virMutexUnlock(&defaultLock); @@ -1596,10 +1603,13 @@ static int testConnectClose(virConnectPtr conn) testDriverUnlock(privconn); virMutexDestroy(&privconn->lock); - if (privconn == &defaultConn) + VIR_FREE(privconn); + + if (dflt) { + defaultConn = NULL; virMutexUnlock(&defaultLock); - else - VIR_FREE(privconn); + } + conn->privateData = NULL; return 0; } -- 2.4.1

On Wed, Jun 24, 2015 at 04:11:45PM +0200, Peter Krempa wrote:
--- src/test/test_driver.c | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 8d2bb5b..ff383c6 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -117,7 +117,7 @@ struct _testDriver { typedef struct _testDriver testDriver; typedef testDriver *testDriverPtr;
-static testDriver defaultConn; +static testDriverPtr defaultConn;
The variable could be also renamed to defaultDrv.
static int defaultConnections; static virMutex defaultLock = VIR_MUTEX_INITIALIZER;
@@ -691,7 +691,7 @@ static int testOpenDefault(virConnectPtr conn) { int u; - testDriverPtr privconn = &defaultConn; + testDriverPtr privconn = NULL;
Same here, this could be privdrv.
virDomainDefPtr domdef = NULL; virDomainObjPtr domobj = NULL; virNetworkDefPtr netdef = NULL; @@ -705,17 +705,18 @@ testOpenDefault(virConnectPtr conn)
virMutexLock(&defaultLock); if (defaultConnections++) { - conn->privateData = &defaultConn; + conn->privateData = defaultConn; virMutexUnlock(&defaultLock); return VIR_DRV_OPEN_SUCCESS; }
+ if (VIR_ALLOC(privconn) < 0) + goto error; + if (virMutexInit(&privconn->lock) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot initialize mutex")); - defaultConnections--; - virMutexUnlock(&defaultLock); - return VIR_DRV_OPEN_ERROR; + goto error; }
conn->privateData = privconn; @@ -822,19 +823,23 @@ testOpenDefault(virConnectPtr conn) } virNodeDeviceObjUnlock(nodeobj);
+ defaultConn = privconn; + virMutexUnlock(&defaultLock);
return VIR_DRV_OPEN_SUCCESS;
error: - virObjectUnref(privconn->domains); - virObjectUnref(privconn->networks); - virInterfaceObjListFree(&privconn->ifaces); - virStoragePoolObjListFree(&privconn->pools); - virNodeDeviceObjListFree(&privconn->devs); - virObjectUnref(privconn->caps); - virObjectEventStateFree(privconn->eventState); - virMutexDestroy(&privconn->lock); + if (privconn) { + virObjectUnref(privconn->domains); + virObjectUnref(privconn->networks); + virInterfaceObjListFree(&privconn->ifaces); + virStoragePoolObjListFree(&privconn->pools); + virNodeDeviceObjListFree(&privconn->devs); + virObjectUnref(privconn->caps); + virObjectEventStateFree(privconn->eventState); + virMutexDestroy(&privconn->lock); + } conn->privateData = NULL; virDomainDefFree(domdef); defaultConnections--; @@ -1573,8 +1578,10 @@ static virDrvOpenStatus testConnectOpen(virConnectPtr conn, static int testConnectClose(virConnectPtr conn) { testDriverPtr privconn = conn->privateData; + bool dflt = false;
- if (privconn == &defaultConn) { + if (privconn == defaultConn) { + dflt = true; virMutexLock(&defaultLock); if (--defaultConnections) { virMutexUnlock(&defaultLock); @@ -1596,10 +1603,13 @@ static int testConnectClose(virConnectPtr conn) testDriverUnlock(privconn); virMutexDestroy(&privconn->lock);
- if (privconn == &defaultConn) + VIR_FREE(privconn); + + if (dflt) { + defaultConn = NULL; virMutexUnlock(&defaultLock); - else - VIR_FREE(privconn); + } + conn->privateData = NULL; return 0; } -- 2.4.1
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

On Wed, Jun 24, 2015 at 16:33:37 +0200, Pavel Hrdina wrote:
On Wed, Jun 24, 2015 at 04:11:45PM +0200, Peter Krempa wrote:
--- src/test/test_driver.c | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 8d2bb5b..ff383c6 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -117,7 +117,7 @@ struct _testDriver { typedef struct _testDriver testDriver; typedef testDriver *testDriverPtr;
-static testDriver defaultConn; +static testDriverPtr defaultConn;
The variable could be also renamed to defaultDrv.
Patches are welcome ;) Peter

Avoid reimplementing it 3 times. --- src/test/test_driver.c | 55 +++++++++++++++++++++----------------------------- 1 file changed, 23 insertions(+), 32 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index ff383c6..732dde9 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -135,6 +135,26 @@ static const virNodeInfo defaultNodeInfo = { 2, }; +static void +testDriverFree(testDriverPtr driver) +{ + if (!driver) + return; + + virObjectUnref(driver->caps); + virObjectUnref(driver->xmlopt); + virObjectUnref(driver->domains); + virNodeDeviceObjListFree(&driver->devs); + virObjectUnref(driver->networks); + virInterfaceObjListFree(&driver->ifaces); + virStoragePoolObjListFree(&driver->pools); + virObjectEventStateFree(driver->eventState); + VIR_FREE(driver->path); + virMutexUnlock(&driver->lock); + virMutexDestroy(&driver->lock); + + VIR_FREE(driver); +} static void testObjectEventQueue(testDriverPtr driver, virObjectEventPtr event); @@ -830,16 +850,7 @@ testOpenDefault(virConnectPtr conn) return VIR_DRV_OPEN_SUCCESS; error: - if (privconn) { - virObjectUnref(privconn->domains); - virObjectUnref(privconn->networks); - virInterfaceObjListFree(&privconn->ifaces); - virStoragePoolObjListFree(&privconn->pools); - virNodeDeviceObjListFree(&privconn->devs); - virObjectUnref(privconn->caps); - virObjectEventStateFree(privconn->eventState); - virMutexDestroy(&privconn->lock); - } + testDriverFree(privconn); conn->privateData = NULL; virDomainDefFree(domdef); defaultConnections--; @@ -1465,14 +1476,7 @@ testOpenFromFile(virConnectPtr conn, const char *file) error: xmlXPathFreeContext(ctxt); xmlFreeDoc(doc); - virObjectUnref(privconn->domains); - virObjectUnref(privconn->networks); - virInterfaceObjListFree(&privconn->ifaces); - virStoragePoolObjListFree(&privconn->pools); - VIR_FREE(privconn->path); - virObjectEventStateFree(privconn->eventState); - testDriverUnlock(privconn); - VIR_FREE(privconn); + testDriverFree(privconn); conn->privateData = NULL; return VIR_DRV_OPEN_ERROR; } @@ -1590,20 +1594,7 @@ static int testConnectClose(virConnectPtr conn) } testDriverLock(privconn); - virObjectUnref(privconn->caps); - virObjectUnref(privconn->xmlopt); - virObjectUnref(privconn->domains); - virNodeDeviceObjListFree(&privconn->devs); - virObjectUnref(privconn->networks); - virInterfaceObjListFree(&privconn->ifaces); - virStoragePoolObjListFree(&privconn->pools); - virObjectEventStateFree(privconn->eventState); - VIR_FREE(privconn->path); - - testDriverUnlock(privconn); - virMutexDestroy(&privconn->lock); - - VIR_FREE(privconn); + testDriverFree(privconn); if (dflt) { defaultConn = NULL; -- 2.4.1

--- src/test/test_driver.c | 96 +++++++++++++++++++++----------------------------- 1 file changed, 41 insertions(+), 55 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 732dde9..c68b3d6 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -309,24 +309,6 @@ testDomainDefNamespaceParse(xmlDocPtr xml ATTRIBUTE_UNUSED, return -1; } -static virDomainXMLOptionPtr -testBuildXMLConfig(void) -{ - virDomainXMLPrivateDataCallbacks priv = { - .alloc = testDomainObjPrivateAlloc, - .free = testDomainObjPrivateFree - }; - - /* All our XML extensions are input only, so we only need to parse */ - virDomainXMLNamespace ns = { - .parse = testDomainDefNamespaceParse, - .free = testDomainDefNamespaceFree, - }; - - return virDomainXMLOptionNew(NULL, &priv, &ns); -} - - static virCapsPtr testBuildCapabilities(virConnectPtr conn) { @@ -402,6 +384,45 @@ testBuildCapabilities(virConnectPtr conn) } +static testDriverPtr +testDriverNew(void) +{ + virDomainXMLPrivateDataCallbacks priv = { + .alloc = testDomainObjPrivateAlloc, + .free = testDomainObjPrivateFree + }; + + virDomainXMLNamespace ns = { + .parse = testDomainDefNamespaceParse, + .free = testDomainDefNamespaceFree, + }; + testDriverPtr ret; + + if (VIR_ALLOC(ret) < 0) + return NULL; + + if (virMutexInit(&ret->lock) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("cannot initialize mutex")); + goto error; + } + + if (!(ret->xmlopt = virDomainXMLOptionNew(NULL, &priv, &ns)) || + !(ret->eventState = virObjectEventStateNew()) || + !(ret->domains = virDomainObjListNew()) || + !(ret->networks = virNetworkObjListNew())) + goto error; + + ret->nextDomID = 1; + + return ret; + + error: + testDriverFree(ret); + return NULL; +} + + static const char *defaultDomainXML = "<domain type='test'>" " <name>test</name>" @@ -730,24 +751,11 @@ testOpenDefault(virConnectPtr conn) return VIR_DRV_OPEN_SUCCESS; } - if (VIR_ALLOC(privconn) < 0) - goto error; - - if (virMutexInit(&privconn->lock) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("cannot initialize mutex")); + if (!(privconn = testDriverNew())) goto error; - } conn->privateData = privconn; - if (!(privconn->eventState = virObjectEventStateNew())) - goto error; - - if (!(privconn->domains = virDomainObjListNew()) || - !(privconn->networks = virNetworkObjListNew())) - goto error; - memmove(&privconn->nodeInfo, &defaultNodeInfo, sizeof(defaultNodeInfo)); /* Numa setup */ @@ -770,11 +778,6 @@ testOpenDefault(virConnectPtr conn) if (!(privconn->caps = testBuildCapabilities(conn))) goto error; - if (!(privconn->xmlopt = testBuildXMLConfig())) - goto error; - - privconn->nextDomID = 1; - if (!(domdef = virDomainDefParseString(defaultDomainXML, privconn->caps, privconn->xmlopt, @@ -1412,31 +1415,15 @@ testOpenFromFile(virConnectPtr conn, const char *file) xmlXPathContextPtr ctxt = NULL; testDriverPtr privconn; - if (VIR_ALLOC(privconn) < 0) - return VIR_DRV_OPEN_ERROR; - if (virMutexInit(&privconn->lock) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("cannot initialize mutex")); - VIR_FREE(privconn); + if (!(privconn = testDriverNew())) return VIR_DRV_OPEN_ERROR; - } testDriverLock(privconn); conn->privateData = privconn; - if (!(privconn->domains = virDomainObjListNew()) || - !(privconn->networks = virNetworkObjListNew())) - goto error; - if (!(privconn->caps = testBuildCapabilities(conn))) goto error; - if (!(privconn->xmlopt = testBuildXMLConfig())) - goto error; - - if (!(privconn->eventState = virObjectEventStateNew())) - goto error; - if (!(doc = virXMLParseFileCtxt(file, &ctxt))) goto error; @@ -1446,7 +1433,6 @@ testOpenFromFile(virConnectPtr conn, const char *file) goto error; } - privconn->nextDomID = 1; privconn->numCells = 0; if (VIR_STRDUP(privconn->path, file) < 0) goto error; -- 2.4.1

It's filled and then freed, but not used anywhere else. --- src/test/test_driver.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index c68b3d6..f105055 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -95,7 +95,6 @@ typedef struct _testAuth *testAuthPtr; struct _testDriver { virMutex lock; - char *path; int nextDomID; virCapsPtr caps; virDomainXMLOptionPtr xmlopt; @@ -149,7 +148,6 @@ testDriverFree(testDriverPtr driver) virInterfaceObjListFree(&driver->ifaces); virStoragePoolObjListFree(&driver->pools); virObjectEventStateFree(driver->eventState); - VIR_FREE(driver->path); virMutexUnlock(&driver->lock); virMutexDestroy(&driver->lock); @@ -1434,8 +1432,6 @@ testOpenFromFile(virConnectPtr conn, const char *file) } privconn->numCells = 0; - if (VIR_STRDUP(privconn->path, file) < 0) - goto error; memmove(&privconn->nodeInfo, &defaultNodeInfo, sizeof(defaultNodeInfo)); if (testParseNodeInfo(&privconn->nodeInfo, ctxt) < 0) -- 2.4.1

Some of the fields are either immutable or self locking, so make a note of that for future reference. --- src/test/test_driver.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index f105055..0cd8e6a 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -96,11 +96,7 @@ struct _testDriver { virMutex lock; int nextDomID; - virCapsPtr caps; - virDomainXMLOptionPtr xmlopt; virNodeInfo nodeInfo; - virDomainObjListPtr domains; - virNetworkObjListPtr networks; virInterfaceObjList ifaces; bool transaction_running; virInterfaceObjList backupIfaces; @@ -111,6 +107,16 @@ struct _testDriver { size_t numAuths; testAuthPtr auths; + /* immutable pointer, immutable object after being initialized with + * testBuildCapabilities */ + virCapsPtr caps; + + /* immutable pointer, immutable object */ + virDomainXMLOptionPtr xmlopt; + + /* immutable pointer, self-locking APIs */ + virDomainObjListPtr domains; + virNetworkObjListPtr networks; virObjectEventStatePtr eventState; }; typedef struct _testDriver testDriver; -- 2.4.1

--- src/test/test_driver.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 0cd8e6a..1d54639 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -59,6 +59,7 @@ #include "virstring.h" #include "cpu/cpu.h" #include "virauth.h" +#include "viratomic.h" #define VIR_FROM_THIS VIR_FROM_TEST @@ -95,7 +96,6 @@ typedef struct _testAuth *testAuthPtr; struct _testDriver { virMutex lock; - int nextDomID; virNodeInfo nodeInfo; virInterfaceObjList ifaces; bool transaction_running; @@ -107,6 +107,9 @@ struct _testDriver { size_t numAuths; testAuthPtr auths; + /* virAtomic access only */ + volatile int nextDomID; + /* immutable pointer, immutable object after being initialized with * testBuildCapabilities */ virCapsPtr caps; @@ -417,7 +420,7 @@ testDriverNew(void) !(ret->networks = virNetworkObjListNew())) goto error; - ret->nextDomID = 1; + virAtomicIntSet(&ret->nextDomID, 1); return ret; @@ -712,7 +715,7 @@ testDomainStartState(testDriverPtr privconn, goto cleanup; virDomainObjSetState(dom, VIR_DOMAIN_RUNNING, reason); - dom->def->id = privconn->nextDomID++; + dom->def->id = virAtomicIntAdd(&privconn->nextDomID, 1); if (virDomainObjSetDefTransient(privconn->caps, privconn->xmlopt, -- 2.4.1

Make testObjectEventQueue tolerant to NULL @event and move it so that it does not require a prototype. Additionally we are now able to remove locking when accessing driver->eventState, since it's using self-locking APIs and the pointer is immutable. --- src/test/test_driver.c | 99 ++++++++++++++++---------------------------------- 1 file changed, 31 insertions(+), 68 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 1d54639..2ab0402 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -163,8 +163,6 @@ testDriverFree(testDriverPtr driver) VIR_FREE(driver); } -static void testObjectEventQueue(testDriverPtr driver, - virObjectEventPtr event); static void testDriverLock(testDriverPtr driver) { @@ -176,6 +174,15 @@ static void testDriverUnlock(testDriverPtr driver) virMutexUnlock(&driver->lock); } +static void testObjectEventQueue(testDriverPtr driver, + virObjectEventPtr event) +{ + if (!event) + return; + + virObjectEventStateQueue(driver->eventState, event); +} + static void *testDomainObjPrivateAlloc(void) { testDomainObjPrivatePtr priv; @@ -1769,8 +1776,7 @@ testDomainCreateXML(virConnectPtr conn, const char *xml, cleanup: if (dom) virObjectUnlock(dom); - if (event) - testObjectEventQueue(privconn, event); + testObjectEventQueue(privconn, event); virDomainDefFree(def); testDriverUnlock(privconn); return ret; @@ -1895,8 +1901,7 @@ static int testDomainDestroy(virDomainPtr domain) ret = 0; cleanup: virDomainObjEndAPI(&privdom); - if (event) - testObjectEventQueue(privconn, event); + testObjectEventQueue(privconn, event); testDriverUnlock(privconn); return ret; } @@ -1933,11 +1938,7 @@ static int testDomainResume(virDomainPtr domain) cleanup: virDomainObjEndAPI(&privdom); - if (event) { - testDriverLock(privconn); - testObjectEventQueue(privconn, event); - testDriverUnlock(privconn); - } + testObjectEventQueue(privconn, event); return ret; } @@ -1974,12 +1975,7 @@ static int testDomainSuspend(virDomainPtr domain) cleanup: virDomainObjEndAPI(&privdom); - - if (event) { - testDriverLock(privconn); - testObjectEventQueue(privconn, event); - testDriverUnlock(privconn); - } + testObjectEventQueue(privconn, event); return ret; } @@ -2019,8 +2015,7 @@ static int testDomainShutdownFlags(virDomainPtr domain, ret = 0; cleanup: virDomainObjEndAPI(&privdom); - if (event) - testObjectEventQueue(privconn, event); + testObjectEventQueue(privconn, event); testDriverUnlock(privconn); return ret; } @@ -2091,8 +2086,7 @@ static int testDomainReboot(virDomainPtr domain, ret = 0; cleanup: virDomainObjEndAPI(&privdom); - if (event) - testObjectEventQueue(privconn, event); + testObjectEventQueue(privconn, event); testDriverUnlock(privconn); return ret; } @@ -2257,8 +2251,7 @@ testDomainSaveFlags(virDomainPtr domain, const char *path, unlink(path); } virDomainObjEndAPI(&privdom); - if (event) - testObjectEventQueue(privconn, event); + testObjectEventQueue(privconn, event); testDriverUnlock(privconn); return ret; } @@ -2362,8 +2355,7 @@ testDomainRestoreFlags(virConnectPtr conn, VIR_FORCE_CLOSE(fd); if (dom) virObjectUnlock(dom); - if (event) - testObjectEventQueue(privconn, event); + testObjectEventQueue(privconn, event); testDriverUnlock(privconn); return ret; } @@ -2436,8 +2428,7 @@ static int testDomainCoreDumpWithFormat(virDomainPtr domain, cleanup: VIR_FORCE_CLOSE(fd); virDomainObjEndAPI(&privdom); - if (event) - testObjectEventQueue(privconn, event); + testObjectEventQueue(privconn, event); testDriverUnlock(privconn); return ret; } @@ -2932,8 +2923,7 @@ static virDomainPtr testDomainDefineXMLFlags(virConnectPtr conn, virDomainDefFree(oldDef); if (dom) virObjectUnlock(dom); - if (event) - testObjectEventQueue(privconn, event); + testObjectEventQueue(privconn, event); testDriverUnlock(privconn); return ret; } @@ -3073,8 +3063,7 @@ static int testDomainCreateWithFlags(virDomainPtr domain, unsigned int flags) cleanup: virDomainObjEndAPI(&privdom); - if (event) - testObjectEventQueue(privconn, event); + testObjectEventQueue(privconn, event); testDriverUnlock(privconn); return ret; } @@ -3145,8 +3134,7 @@ static int testDomainUndefineFlags(virDomainPtr domain, cleanup: virDomainObjEndAPI(&privdom); - if (event) - testObjectEventQueue(privconn, event); + testObjectEventQueue(privconn, event); testDriverUnlock(privconn); return ret; } @@ -3579,8 +3567,7 @@ static virNetworkPtr testNetworkCreateXML(virConnectPtr conn, const char *xml) cleanup: virNetworkDefFree(def); - if (event) - testObjectEventQueue(privconn, event); + testObjectEventQueue(privconn, event); virNetworkObjEndAPI(&net); return ret; } @@ -3609,8 +3596,7 @@ virNetworkPtr testNetworkDefineXML(virConnectPtr conn, const char *xml) cleanup: virNetworkDefFree(def); - if (event) - testObjectEventQueue(privconn, event); + testObjectEventQueue(privconn, event); virNetworkObjEndAPI(&net); return ret; } @@ -3643,8 +3629,7 @@ static int testNetworkUndefine(virNetworkPtr network) ret = 0; cleanup: - if (event) - testObjectEventQueue(privconn, event); + testObjectEventQueue(privconn, event); virNetworkObjEndAPI(&privnet); return ret; } @@ -3721,8 +3706,7 @@ static int testNetworkCreate(virNetworkPtr network) ret = 0; cleanup: - if (event) - testObjectEventQueue(privconn, event); + testObjectEventQueue(privconn, event); virNetworkObjEndAPI(&privnet); return ret; } @@ -3750,8 +3734,7 @@ static int testNetworkDestroy(virNetworkPtr network) ret = 0; cleanup: - if (event) - testObjectEventQueue(privconn, event); + testObjectEventQueue(privconn, event); virNetworkObjEndAPI(&privnet); return ret; } @@ -6034,15 +6017,6 @@ testConnectNetworkEventDeregisterAny(virConnectPtr conn, return ret; } - -/* driver must be locked before calling */ -static void testObjectEventQueue(testDriverPtr driver, - virObjectEventPtr event) -{ - virObjectEventStateQueue(driver->eventState, event); -} - - static int testConnectListAllDomains(virConnectPtr conn, virDomainPtr **domains, unsigned int flags) @@ -6159,11 +6133,7 @@ testDomainManagedSave(virDomainPtr dom, unsigned int flags) ret = 0; cleanup: virDomainObjEndAPI(&vm); - if (event) { - testDriverLock(privconn); - testObjectEventQueue(privconn, event); - testDriverUnlock(privconn); - } + testObjectEventQueue(privconn, event); return ret; } @@ -6692,11 +6662,7 @@ testDomainSnapshotCreateXML(virDomainPtr domain, } virDomainObjEndAPI(&vm); } - if (event) { - testDriverLock(privconn); - testObjectEventQueue(privconn, event); - testDriverUnlock(privconn); - } + testObjectEventQueue(privconn, event); virDomainSnapshotDefFree(def); return snapshot; } @@ -6936,8 +6902,7 @@ testDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, event = virDomainEventLifecycleNewFromObj(vm, VIR_DOMAIN_EVENT_STOPPED, VIR_DOMAIN_EVENT_STOPPED_FROM_SNAPSHOT); - if (event) - testObjectEventQueue(privconn, event); + testObjectEventQueue(privconn, event); goto load; } @@ -7016,8 +6981,7 @@ testDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, /* Flush first event, now do transition 2 or 3 */ bool paused = (flags & VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED) != 0; - if (event) - testObjectEventQueue(privconn, event); + testObjectEventQueue(privconn, event); event = virDomainEventLifecycleNewFromObj(vm, VIR_DOMAIN_EVENT_STARTED, VIR_DOMAIN_EVENT_STARTED_FROM_SNAPSHOT); @@ -7034,8 +6998,7 @@ testDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, cleanup: if (event) { testObjectEventQueue(privconn, event); - if (event2) - testObjectEventQueue(privconn, event2); + testObjectEventQueue(privconn, event2); } else { virObjectUnref(event2); } -- 2.4.1

Don't lock the driver when registering event callbacks. --- src/test/test_driver.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 2ab0402..b08c1e5 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -5915,11 +5915,9 @@ testConnectDomainEventRegister(virConnectPtr conn, testDriverPtr driver = conn->privateData; int ret = 0; - testDriverLock(driver); if (virDomainEventStateRegister(conn, driver->eventState, callback, opaque, freecb) < 0) ret = -1; - testDriverUnlock(driver); return ret; } @@ -5932,11 +5930,9 @@ testConnectDomainEventDeregister(virConnectPtr conn, testDriverPtr driver = conn->privateData; int ret = 0; - testDriverLock(driver); if (virDomainEventStateDeregister(conn, driver->eventState, callback) < 0) ret = -1; - testDriverUnlock(driver); return ret; } @@ -5953,12 +5949,10 @@ testConnectDomainEventRegisterAny(virConnectPtr conn, testDriverPtr driver = conn->privateData; int ret; - testDriverLock(driver); if (virDomainEventStateRegisterID(conn, driver->eventState, dom, eventID, callback, opaque, freecb, &ret) < 0) ret = -1; - testDriverUnlock(driver); return ret; } @@ -5970,11 +5964,9 @@ testConnectDomainEventDeregisterAny(virConnectPtr conn, testDriverPtr driver = conn->privateData; int ret = 0; - testDriverLock(driver); if (virObjectEventStateDeregisterID(conn, driver->eventState, callbackID) < 0) ret = -1; - testDriverUnlock(driver); return ret; } @@ -5991,12 +5983,10 @@ testConnectNetworkEventRegisterAny(virConnectPtr conn, testDriverPtr driver = conn->privateData; int ret; - testDriverLock(driver); if (virNetworkEventStateRegisterID(conn, driver->eventState, net, eventID, callback, opaque, freecb, &ret) < 0) ret = -1; - testDriverUnlock(driver); return ret; } @@ -6008,11 +5998,9 @@ testConnectNetworkEventDeregisterAny(virConnectPtr conn, testDriverPtr driver = conn->privateData; int ret = 0; - testDriverLock(driver); if (virObjectEventStateDeregisterID(conn, driver->eventState, callbackID) < 0) ret = -1; - testDriverUnlock(driver); return ret; } -- 2.4.1

On 06/24/2015 10:11 AM, Peter Krempa wrote:
Don't lock the driver when registering event callbacks. --- src/test/test_driver.c | 12 ------------ 1 file changed, 12 deletions(-)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 2ab0402..b08c1e5 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -5915,11 +5915,9 @@ testConnectDomainEventRegister(virConnectPtr conn, testDriverPtr driver = conn->privateData; int ret = 0;
- testDriverLock(driver); if (virDomainEventStateRegister(conn, driver->eventState, callback, opaque, freecb) < 0) ret = -1; - testDriverUnlock(driver);
return ret; } @@ -5932,11 +5930,9 @@ testConnectDomainEventDeregister(virConnectPtr conn, testDriverPtr driver = conn->privateData; int ret = 0;
- testDriverLock(driver); if (virDomainEventStateDeregister(conn, driver->eventState, callback) < 0) ret = -1; - testDriverUnlock(driver);
return ret; } @@ -5953,12 +5949,10 @@ testConnectDomainEventRegisterAny(virConnectPtr conn, testDriverPtr driver = conn->privateData; int ret;
int ret = 0;
- testDriverLock(driver); if (virDomainEventStateRegisterID(conn, driver->eventState, dom, eventID, callback, opaque, freecb, &ret) < 0) ret = -1; - testDriverUnlock(driver);
return ret; } @@ -5970,11 +5964,9 @@ testConnectDomainEventDeregisterAny(virConnectPtr conn, testDriverPtr driver = conn->privateData; int ret = 0;
- testDriverLock(driver); if (virObjectEventStateDeregisterID(conn, driver->eventState, callbackID) < 0) ret = -1; - testDriverUnlock(driver);
return ret; } @@ -5991,12 +5983,10 @@ testConnectNetworkEventRegisterAny(virConnectPtr conn, testDriverPtr driver = conn->privateData; int ret;
int ret = 0; I know, existing... but for consistency of other places... not required, but suggested ;-) John
- testDriverLock(driver); if (virNetworkEventStateRegisterID(conn, driver->eventState, net, eventID, callback, opaque, freecb, &ret) < 0) ret = -1; - testDriverUnlock(driver);
return ret; } @@ -6008,11 +5998,9 @@ testConnectNetworkEventDeregisterAny(virConnectPtr conn, testDriverPtr driver = conn->privateData; int ret = 0;
- testDriverLock(driver); if (virObjectEventStateDeregisterID(conn, driver->eventState, callbackID) < 0) ret = -1; - testDriverUnlock(driver);
return ret; }

On Wed, Jun 24, 2015 at 14:04:06 -0400, John Ferlan wrote:
On 06/24/2015 10:11 AM, Peter Krempa wrote:
Don't lock the driver when registering event callbacks. --- src/test/test_driver.c | 12 ------------ 1 file changed, 12 deletions(-)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 2ab0402..b08c1e5 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -5915,11 +5915,9 @@ testConnectDomainEventRegister(virConnectPtr conn, testDriverPtr driver = conn->privateData; int ret = 0;
- testDriverLock(driver); if (virDomainEventStateRegister(conn, driver->eventState, callback, opaque, freecb) < 0) ret = -1; - testDriverUnlock(driver);
return ret; } @@ -5932,11 +5930,9 @@ testConnectDomainEventDeregister(virConnectPtr conn, testDriverPtr driver = conn->privateData; int ret = 0;
- testDriverLock(driver); if (virDomainEventStateDeregister(conn, driver->eventState, callback) < 0) ret = -1; - testDriverUnlock(driver);
return ret; } @@ -5953,12 +5949,10 @@ testConnectDomainEventRegisterAny(virConnectPtr conn, testDriverPtr driver = conn->privateData; int ret;
int ret = 0;
Well this certainly isn't material for this patch. Peter

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. --- src/test/test_driver.c | 73 +++++++------------------------------------------- 1 file changed, 10 insertions(+), 63 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index b08c1e5..c36e0f8 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -537,7 +537,6 @@ testDomObjFromDomain(virDomainPtr domain) testDriverPtr driver = domain->conn->privateData; char uuidstr[VIR_UUID_STRING_BUFLEN]; - testDriverLock(driver); vm = virDomainObjListFindByUUIDRef(driver->domains, domain->uuid); if (!vm) { virUUIDFormat(domain->uuid, uuidstr); @@ -546,7 +545,6 @@ testDomObjFromDomain(virDomainPtr domain) uuidstr, domain->name); } - testDriverUnlock(driver); return vm; } @@ -1790,11 +1788,7 @@ static virDomainPtr testDomainLookupByID(virConnectPtr conn, virDomainPtr ret = NULL; virDomainObjPtr dom; - testDriverLock(privconn); - dom = virDomainObjListFindByID(privconn->domains, id); - testDriverUnlock(privconn); - - if (dom == NULL) { + if (!(dom = virDomainObjListFindByID(privconn->domains, id))) { virReportError(VIR_ERR_NO_DOMAIN, NULL); goto cleanup; } @@ -1816,11 +1810,7 @@ static virDomainPtr testDomainLookupByUUID(virConnectPtr conn, virDomainPtr ret = NULL; virDomainObjPtr dom; - testDriverLock(privconn); - dom = virDomainObjListFindByUUID(privconn->domains, uuid); - testDriverUnlock(privconn); - - if (dom == NULL) { + if (!(dom = virDomainObjListFindByUUID(privconn->domains, uuid))) { virReportError(VIR_ERR_NO_DOMAIN, NULL); goto cleanup; } @@ -1842,11 +1832,7 @@ static virDomainPtr testDomainLookupByName(virConnectPtr conn, virDomainPtr ret = NULL; virDomainObjPtr dom; - testDriverLock(privconn); - dom = virDomainObjListFindByName(privconn->domains, name); - testDriverUnlock(privconn); - - if (dom == NULL) { + if (!(dom = virDomainObjListFindByName(privconn->domains, name))) { virReportError(VIR_ERR_NO_DOMAIN, NULL); goto cleanup; } @@ -1865,13 +1851,9 @@ static int testConnectListDomains(virConnectPtr conn, int maxids) { testDriverPtr privconn = conn->privateData; - int n; - - testDriverLock(privconn); - n = virDomainObjListGetActiveIDs(privconn->domains, ids, maxids, NULL, NULL); - testDriverUnlock(privconn); - return n; + return virDomainObjListGetActiveIDs(privconn->domains, ids, maxids, + NULL, NULL); } static int testDomainDestroy(virDomainPtr domain) @@ -1881,7 +1863,6 @@ static int testDomainDestroy(virDomainPtr domain) virObjectEventPtr event = NULL; int ret = -1; - testDriverLock(privconn); privdom = virDomainObjListFindByName(privconn->domains, domain->name); @@ -1902,7 +1883,6 @@ static int testDomainDestroy(virDomainPtr domain) cleanup: virDomainObjEndAPI(&privdom); testObjectEventQueue(privconn, event); - testDriverUnlock(privconn); return ret; } @@ -1989,7 +1969,6 @@ static int testDomainShutdownFlags(virDomainPtr domain, virCheckFlags(0, -1); - testDriverLock(privconn); privdom = virDomainObjListFindByName(privconn->domains, domain->name); @@ -2016,7 +1995,6 @@ static int testDomainShutdownFlags(virDomainPtr domain, cleanup: virDomainObjEndAPI(&privdom); testObjectEventQueue(privconn, event); - testDriverUnlock(privconn); return ret; } @@ -2034,7 +2012,6 @@ static int testDomainReboot(virDomainPtr domain, virObjectEventPtr event = NULL; int ret = -1; - testDriverLock(privconn); privdom = virDomainObjListFindByName(privconn->domains, domain->name); @@ -2087,7 +2064,6 @@ static int testDomainReboot(virDomainPtr domain, cleanup: virDomainObjEndAPI(&privdom); testObjectEventQueue(privconn, event); - testDriverUnlock(privconn); return ret; } @@ -2178,7 +2154,6 @@ testDomainSaveFlags(virDomainPtr domain, const char *path, return -1; } - testDriverLock(privconn); privdom = virDomainObjListFindByName(privconn->domains, domain->name); @@ -2252,7 +2227,6 @@ testDomainSaveFlags(virDomainPtr domain, const char *path, } virDomainObjEndAPI(&privdom); testObjectEventQueue(privconn, event); - testDriverUnlock(privconn); return ret; } @@ -2286,8 +2260,6 @@ testDomainRestoreFlags(virConnectPtr conn, return -1; } - testDriverLock(privconn); - if ((fd = open(path, O_RDONLY)) < 0) { virReportSystemError(errno, _("cannot read domain image '%s'"), @@ -2356,7 +2328,6 @@ testDomainRestoreFlags(virConnectPtr conn, if (dom) virObjectUnlock(dom); testObjectEventQueue(privconn, event); - testDriverUnlock(privconn); return ret; } @@ -2380,7 +2351,6 @@ static int testDomainCoreDumpWithFormat(virDomainPtr domain, virCheckFlags(VIR_DUMP_CRASH, -1); - testDriverLock(privconn); privdom = virDomainObjListFindByName(privconn->domains, domain->name); @@ -2429,7 +2399,6 @@ static int testDomainCoreDumpWithFormat(virDomainPtr domain, VIR_FORCE_CLOSE(fd); virDomainObjEndAPI(&privdom); testObjectEventQueue(privconn, event); - testDriverUnlock(privconn); return ret; } @@ -2849,13 +2818,8 @@ static char *testDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) static int testConnectNumOfDefinedDomains(virConnectPtr conn) { testDriverPtr privconn = conn->privateData; - int count; - - testDriverLock(privconn); - count = virDomainObjListNumOfDomains(privconn->domains, false, NULL, NULL); - testDriverUnlock(privconn); - return count; + return virDomainObjListNumOfDomains(privconn->domains, false, NULL, NULL); } static int testConnectListDefinedDomains(virConnectPtr conn, @@ -2864,15 +2828,10 @@ static int testConnectListDefinedDomains(virConnectPtr conn, { testDriverPtr privconn = conn->privateData; - int n; - testDriverLock(privconn); memset(names, 0, sizeof(*names)*maxnames); - n = virDomainObjListGetInactiveNames(privconn->domains, names, maxnames, - NULL, NULL); - testDriverUnlock(privconn); - - return n; + return virDomainObjListGetInactiveNames(privconn->domains, names, maxnames, + NULL, NULL); } static virDomainPtr testDomainDefineXMLFlags(virConnectPtr conn, @@ -2892,7 +2851,6 @@ static virDomainPtr testDomainDefineXMLFlags(virConnectPtr conn, if (flags & VIR_DOMAIN_DEFINE_VALIDATE) parse_flags |= VIR_DOMAIN_DEF_PARSE_VALIDATE; - testDriverLock(privconn); if ((def = virDomainDefParseString(xml, privconn->caps, privconn->xmlopt, parse_flags)) == NULL) goto cleanup; @@ -2924,7 +2882,6 @@ static virDomainPtr testDomainDefineXMLFlags(virConnectPtr conn, if (dom) virObjectUnlock(dom); testObjectEventQueue(privconn, event); - testDriverUnlock(privconn); return ret; } @@ -3085,7 +3042,6 @@ static int testDomainUndefineFlags(virDomainPtr domain, virCheckFlags(VIR_DOMAIN_UNDEFINE_MANAGED_SAVE | VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA, -1); - testDriverLock(privconn); privdom = virDomainObjListFindByName(privconn->domains, domain->name); @@ -3135,7 +3091,6 @@ static int testDomainUndefineFlags(virDomainPtr domain, cleanup: virDomainObjEndAPI(&privdom); testObjectEventQueue(privconn, event); - testDriverUnlock(privconn); return ret; } @@ -6010,16 +5965,11 @@ static int testConnectListAllDomains(virConnectPtr conn, unsigned int flags) { testDriverPtr privconn = conn->privateData; - int ret; virCheckFlags(VIR_CONNECT_LIST_DOMAINS_FILTERS_ALL, -1); - testDriverLock(privconn); - ret = virDomainObjListExport(privconn->domains, conn, domains, - NULL, flags); - testDriverUnlock(privconn); - - return ret; + return virDomainObjListExport(privconn->domains, conn, domains, + NULL, flags); } static int @@ -6821,8 +6771,6 @@ testDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, if (!(snap = testSnapObjFromSnapshot(vm, snapshot))) goto cleanup; - testDriverLock(privconn); - if (!vm->persistent && snap->def->state != VIR_DOMAIN_RUNNING && snap->def->state != VIR_DOMAIN_PAUSED && @@ -6991,7 +6939,6 @@ testDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, virObjectUnref(event2); } virDomainObjEndAPI(&vm); - testDriverUnlock(privconn); return ret; } -- 2.4.1

Reuse testDomObjFromDomain testDomObjFromDomain to retrieve domain objects in the rest of the test driver instead of open-coding it in every API. Now that testDomObjFromDomain does not lock the driver it can be reused also in places where the driver is already locked. --- src/test/test_driver.c | 390 ++++++++++--------------------------------------- 1 file changed, 77 insertions(+), 313 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index c36e0f8..2c2f009 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1684,43 +1684,28 @@ static int testConnectNumOfDomains(virConnectPtr conn) static int testDomainIsActive(virDomainPtr dom) { - testDriverPtr privconn = dom->conn->privateData; virDomainObjPtr obj; - int ret = -1; + int ret; - testDriverLock(privconn); - obj = virDomainObjListFindByUUID(privconn->domains, dom->uuid); - testDriverUnlock(privconn); - if (!obj) { - virReportError(VIR_ERR_NO_DOMAIN, NULL); - goto cleanup; - } - ret = virDomainObjIsActive(obj); + if (!(obj = testDomObjFromDomain(dom))) + return -1; - cleanup: - if (obj) - virObjectUnlock(obj); + ret = virDomainObjIsActive(obj); + virDomainObjEndAPI(&obj); return ret; } static int testDomainIsPersistent(virDomainPtr dom) { - testDriverPtr privconn = dom->conn->privateData; virDomainObjPtr obj; - int ret = -1; + int ret; + + if (!(obj = testDomObjFromDomain(dom))) + return -1; - testDriverLock(privconn); - obj = virDomainObjListFindByUUID(privconn->domains, dom->uuid); - testDriverUnlock(privconn); - if (!obj) { - virReportError(VIR_ERR_NO_DOMAIN, NULL); - goto cleanup; - } ret = obj->persistent; - cleanup: - if (obj) - virObjectUnlock(obj); + virDomainObjEndAPI(&obj); return ret; } @@ -1863,13 +1848,9 @@ static int testDomainDestroy(virDomainPtr domain) virObjectEventPtr event = NULL; int ret = -1; - privdom = virDomainObjListFindByName(privconn->domains, - domain->name); - if (privdom == NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); + if (!(privdom = testDomObjFromDomain(domain))) goto cleanup; - } testDomainShutdownState(domain, privdom, VIR_DOMAIN_SHUTOFF_DESTROYED); event = virDomainEventLifecycleNewFromObj(privdom, @@ -1893,15 +1874,8 @@ static int testDomainResume(virDomainPtr domain) virObjectEventPtr event = NULL; int ret = -1; - testDriverLock(privconn); - privdom = virDomainObjListFindByName(privconn->domains, - domain->name); - testDriverUnlock(privconn); - - if (privdom == NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); - goto cleanup; - } + if (!(privdom = testDomObjFromDomain(domain))) + return -1; if (virDomainObjGetState(privdom, NULL) != VIR_DOMAIN_PAUSED) { virReportError(VIR_ERR_INTERNAL_ERROR, _("domain '%s' not paused"), @@ -1930,15 +1904,8 @@ static int testDomainSuspend(virDomainPtr domain) int ret = -1; int state; - testDriverLock(privconn); - privdom = virDomainObjListFindByName(privconn->domains, - domain->name); - testDriverUnlock(privconn); - - if (privdom == NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); - goto cleanup; - } + if (!(privdom = testDomObjFromDomain(domain))) + return -1; state = virDomainObjGetState(privdom, NULL); if (state == VIR_DOMAIN_SHUTOFF || state == VIR_DOMAIN_PAUSED) { @@ -1969,13 +1936,9 @@ static int testDomainShutdownFlags(virDomainPtr domain, virCheckFlags(0, -1); - privdom = virDomainObjListFindByName(privconn->domains, - domain->name); - if (privdom == NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); + if (!(privdom = testDomObjFromDomain(domain))) goto cleanup; - } if (virDomainObjGetState(privdom, NULL) == VIR_DOMAIN_SHUTOFF) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -2012,13 +1975,9 @@ static int testDomainReboot(virDomainPtr domain, virObjectEventPtr event = NULL; int ret = -1; - privdom = virDomainObjListFindByName(privconn->domains, - domain->name); - if (privdom == NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); + if (!(privdom = testDomObjFromDomain(domain))) goto cleanup; - } virDomainObjSetState(privdom, VIR_DOMAIN_SHUTDOWN, VIR_DOMAIN_SHUTDOWN_USER); @@ -2070,20 +2029,12 @@ static int testDomainReboot(virDomainPtr domain, static int testDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) { - testDriverPtr privconn = domain->conn->privateData; struct timeval tv; virDomainObjPtr privdom; int ret = -1; - testDriverLock(privconn); - privdom = virDomainObjListFindByName(privconn->domains, - domain->name); - testDriverUnlock(privconn); - - if (privdom == NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); - goto cleanup; - } + if (!(privdom = testDomObjFromDomain(domain))) + return -1; if (gettimeofday(&tv, NULL) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -2109,28 +2060,18 @@ testDomainGetState(virDomainPtr domain, int *reason, unsigned int flags) { - testDriverPtr privconn = domain->conn->privateData; virDomainObjPtr privdom; - int ret = -1; virCheckFlags(0, -1); - testDriverLock(privconn); - privdom = virDomainObjListFindByName(privconn->domains, - domain->name); - testDriverUnlock(privconn); - - if (privdom == NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); - goto cleanup; - } + if (!(privdom = testDomObjFromDomain(domain))) + return -1; *state = virDomainObjGetState(privdom, reason); - ret = 0; - cleanup: virDomainObjEndAPI(&privdom); - return ret; + + return 0; } #define TEST_SAVE_MAGIC "TestGuestMagic" @@ -2154,13 +2095,9 @@ testDomainSaveFlags(virDomainPtr domain, const char *path, return -1; } - privdom = virDomainObjListFindByName(privconn->domains, - domain->name); - if (privdom == NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); + if (!(privdom = testDomObjFromDomain(domain))) goto cleanup; - } xml = virDomainDefFormat(privdom->def, VIR_DOMAIN_DEF_FORMAT_SECURE); @@ -2351,13 +2288,9 @@ static int testDomainCoreDumpWithFormat(virDomainPtr domain, virCheckFlags(VIR_DUMP_CRASH, -1); - privdom = virDomainObjListFindByName(privconn->domains, - domain->name); - if (privdom == NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); + if (!(privdom = testDomObjFromDomain(domain))) goto cleanup; - } if ((fd = open(to, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR)) < 0) { virReportSystemError(errno, @@ -2426,23 +2359,14 @@ testDomainGetOSType(virDomainPtr dom ATTRIBUTE_UNUSED) static unsigned long long testDomainGetMaxMemory(virDomainPtr domain) { - testDriverPtr privconn = domain->conn->privateData; virDomainObjPtr privdom; unsigned long long ret = 0; - testDriverLock(privconn); - privdom = virDomainObjListFindByName(privconn->domains, - domain->name); - testDriverUnlock(privconn); - - if (privdom == NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); - goto cleanup; - } + if (!(privdom = testDomObjFromDomain(domain))) + return 0; ret = virDomainDefGetMemoryActual(privdom->def); - cleanup: virDomainObjEndAPI(&privdom); return ret; } @@ -2450,45 +2374,26 @@ testDomainGetMaxMemory(virDomainPtr domain) static int testDomainSetMaxMemory(virDomainPtr domain, unsigned long memory) { - testDriverPtr privconn = domain->conn->privateData; virDomainObjPtr privdom; - int ret = -1; - - testDriverLock(privconn); - privdom = virDomainObjListFindByName(privconn->domains, - domain->name); - testDriverUnlock(privconn); - if (privdom == NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); - goto cleanup; - } + if (!(privdom = testDomObjFromDomain(domain))) + return -1; /* XXX validate not over host memory wrt to other domains */ virDomainDefSetMemoryInitial(privdom->def, memory); - ret = 0; - cleanup: virDomainObjEndAPI(&privdom); - return ret; + return 0; } static int testDomainSetMemory(virDomainPtr domain, unsigned long memory) { - testDriverPtr privconn = domain->conn->privateData; virDomainObjPtr privdom; int ret = -1; - testDriverLock(privconn); - privdom = virDomainObjListFindByName(privconn->domains, - domain->name); - testDriverUnlock(privconn); - - if (privdom == NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); - goto cleanup; - } + if (!(privdom = testDomObjFromDomain(domain))) + return -1; if (memory > virDomainDefGetMemoryActual(privdom->def)) { virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); @@ -2506,7 +2411,6 @@ static int testDomainSetMemory(virDomainPtr domain, static int testDomainGetVcpusFlags(virDomainPtr domain, unsigned int flags) { - testDriverPtr privconn = domain->conn->privateData; virDomainObjPtr vm; virDomainDefPtr def; int ret = -1; @@ -2515,17 +2419,8 @@ testDomainGetVcpusFlags(virDomainPtr domain, unsigned int flags) VIR_DOMAIN_AFFECT_CONFIG | VIR_DOMAIN_VCPU_MAXIMUM, -1); - testDriverLock(privconn); - vm = virDomainObjListFindByUUID(privconn->domains, domain->uuid); - testDriverUnlock(privconn); - - if (!vm) { - char uuidstr[VIR_UUID_STRING_BUFLEN]; - virUUIDFormat(domain->uuid, uuidstr); - virReportError(VIR_ERR_NO_DOMAIN, - _("no domain with matching uuid '%s'"), uuidstr); - goto cleanup; - } + if (!(vm = testDomObjFromDomain(domain))) + return -1; if (!(def = virDomainObjGetOneDef(vm, flags))) goto cleanup; @@ -2533,8 +2428,7 @@ testDomainGetVcpusFlags(virDomainPtr domain, unsigned int flags) ret = (flags & VIR_DOMAIN_VCPU_MAXIMUM) ? def->maxvcpus : def->vcpus; cleanup: - if (vm) - virObjectUnlock(vm); + virDomainObjEndAPI(&vm); return ret; } @@ -2573,14 +2467,8 @@ testDomainSetVcpusFlags(virDomainPtr domain, unsigned int nrCpus, return -1; } - testDriverLock(privconn); - privdom = virDomainObjListFindByUUID(privconn->domains, domain->uuid); - testDriverUnlock(privconn); - - if (privdom == NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); - goto cleanup; - } + if (!(privdom = testDomObjFromDomain(domain))) + return -1; if (!virDomainObjIsActive(privdom) && (flags & VIR_DOMAIN_AFFECT_LIVE)) { virReportError(VIR_ERR_OPERATION_INVALID, @@ -2631,8 +2519,7 @@ testDomainSetVcpusFlags(virDomainPtr domain, unsigned int nrCpus, } cleanup: - if (privdom) - virObjectUnlock(privdom); + virDomainObjEndAPI(&privdom); return ret; } @@ -2657,14 +2544,8 @@ static int testDomainGetVcpus(virDomainPtr domain, struct timeval tv; unsigned long long statbase; - testDriverLock(privconn); - privdom = virDomainObjListFindByName(privconn->domains, domain->name); - testDriverUnlock(privconn); - - if (privdom == NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); - goto cleanup; - } + if (!(privdom = testDomObjFromDomain(domain))) + return -1; if (!virDomainObjIsActive(privdom)) { virReportError(VIR_ERR_OPERATION_INVALID, @@ -2742,14 +2623,8 @@ static int testDomainPinVcpu(virDomainPtr domain, int maxcpu, hostcpus, privmaplen; int ret = -1; - testDriverLock(privconn); - privdom = virDomainObjListFindByName(privconn->domains, domain->name); - testDriverUnlock(privconn); - - if (privdom == NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); - goto cleanup; - } + if (!(privdom = testDomObjFromDomain(domain))) + return -1; if (!virDomainObjIsActive(privdom)) { virReportError(VIR_ERR_OPERATION_INVALID, @@ -2787,30 +2662,20 @@ static int testDomainPinVcpu(virDomainPtr domain, static char *testDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) { - testDriverPtr privconn = domain->conn->privateData; virDomainDefPtr def; virDomainObjPtr privdom; char *ret = NULL; /* Flags checked by virDomainDefFormat */ - testDriverLock(privconn); - privdom = virDomainObjListFindByName(privconn->domains, - domain->name); - testDriverUnlock(privconn); - - if (privdom == NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); - goto cleanup; - } + if (!(privdom = testDomObjFromDomain(domain))) + return NULL; def = (flags & VIR_DOMAIN_XML_INACTIVE) && privdom->newDef ? privdom->newDef : privdom->def; - ret = virDomainDefFormat(def, - virDomainDefFormatConvertXMLFlags(flags)); + ret = virDomainDefFormat(def, virDomainDefFormatConvertXMLFlags(flags)); - cleanup: virDomainObjEndAPI(&privdom); return ret; } @@ -2898,25 +2763,17 @@ static char *testDomainGetMetadata(virDomainPtr dom, { testDriverPtr privconn = dom->conn->privateData; virDomainObjPtr privdom; - char *ret = NULL; + char *ret; virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, NULL); - testDriverLock(privconn); - privdom = virDomainObjListFindByName(privconn->domains, - dom->name); - testDriverUnlock(privconn); - - if (privdom == NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); - goto cleanup; - } + if (!(privdom = testDomObjFromDomain(dom))) + return NULL; ret = virDomainObjGetMetadata(privdom, type, uri, privconn->caps, privconn->xmlopt, flags); - cleanup: virDomainObjEndAPI(&privdom); return ret; } @@ -2930,26 +2787,18 @@ static int testDomainSetMetadata(virDomainPtr dom, { testDriverPtr privconn = dom->conn->privateData; virDomainObjPtr privdom; - int ret = -1; + int ret; virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1); - testDriverLock(privconn); - privdom = virDomainObjListFindByName(privconn->domains, - dom->name); - testDriverUnlock(privconn); - - if (privdom == NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); - goto cleanup; - } + if (!(privdom = testDomObjFromDomain(dom))) + return -1; ret = virDomainObjSetMetadata(privdom, type, metadata, key, uri, privconn->caps, privconn->xmlopt, NULL, NULL, flags); - cleanup: virDomainObjEndAPI(&privdom); return ret; } @@ -2994,13 +2843,9 @@ static int testDomainCreateWithFlags(virDomainPtr domain, unsigned int flags) virCheckFlags(0, -1); testDriverLock(privconn); - privdom = virDomainObjListFindByName(privconn->domains, - domain->name); - if (privdom == NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); + if (!(privdom = testDomObjFromDomain(domain))) goto cleanup; - } if (virDomainObjGetState(privdom, NULL) != VIR_DOMAIN_SHUTOFF) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -3042,13 +2887,9 @@ static int testDomainUndefineFlags(virDomainPtr domain, virCheckFlags(VIR_DOMAIN_UNDEFINE_MANAGED_SAVE | VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA, -1); - privdom = virDomainObjListFindByName(privconn->domains, - domain->name); - if (privdom == NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); + if (!(privdom = testDomObjFromDomain(domain))) goto cleanup; - } if (privdom->hasManagedSave && !(flags & VIR_DOMAIN_UNDEFINE_MANAGED_SAVE)) { @@ -3102,52 +2943,30 @@ static int testDomainUndefine(virDomainPtr domain) static int testDomainGetAutostart(virDomainPtr domain, int *autostart) { - testDriverPtr privconn = domain->conn->privateData; virDomainObjPtr privdom; - int ret = -1; - testDriverLock(privconn); - privdom = virDomainObjListFindByName(privconn->domains, - domain->name); - testDriverUnlock(privconn); - - if (privdom == NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); - goto cleanup; - } + if (!(privdom = testDomObjFromDomain(domain))) + return -1; *autostart = privdom->autostart; - ret = 0; - cleanup: virDomainObjEndAPI(&privdom); - return ret; + return 0; } static int testDomainSetAutostart(virDomainPtr domain, int autostart) { - testDriverPtr privconn = domain->conn->privateData; virDomainObjPtr privdom; - int ret = -1; - - testDriverLock(privconn); - privdom = virDomainObjListFindByName(privconn->domains, - domain->name); - testDriverUnlock(privconn); - if (privdom == NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); - goto cleanup; - } + if (!(privdom = testDomObjFromDomain(domain))) + return -1; privdom->autostart = autostart ? 1 : 0; - ret = 0; - cleanup: virDomainObjEndAPI(&privdom); - return ret; + return 0; } static char *testDomainGetSchedulerType(virDomainPtr domain ATTRIBUTE_UNUSED, @@ -3169,21 +2988,13 @@ testDomainGetSchedulerParametersFlags(virDomainPtr domain, int *nparams, unsigned int flags) { - testDriverPtr privconn = domain->conn->privateData; virDomainObjPtr privdom; int ret = -1; virCheckFlags(0, -1); - testDriverLock(privconn); - privdom = virDomainObjListFindByName(privconn->domains, - domain->name); - testDriverUnlock(privconn); - - if (privdom == NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); - goto cleanup; - } + if (!(privdom = testDomObjFromDomain(domain))) + return -1; if (virTypedParameterAssign(params, VIR_DOMAIN_SCHEDULER_WEIGHT, VIR_TYPED_PARAM_UINT, 50) < 0) @@ -3213,7 +3024,6 @@ testDomainSetSchedulerParametersFlags(virDomainPtr domain, int nparams, unsigned int flags) { - testDriverPtr privconn = domain->conn->privateData; virDomainObjPtr privdom; int ret = -1; size_t i; @@ -3225,15 +3035,8 @@ testDomainSetSchedulerParametersFlags(virDomainPtr domain, NULL) < 0) return -1; - testDriverLock(privconn); - privdom = virDomainObjListFindByName(privconn->domains, - domain->name); - testDriverUnlock(privconn); - - if (privdom == NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); - goto cleanup; - } + if (!(privdom = testDomObjFromDomain(domain))) + return -1; for (i = 0; i < nparams; i++) { if (STREQ(params[i].field, VIR_DOMAIN_SCHEDULER_WEIGHT)) { @@ -3244,7 +3047,6 @@ testDomainSetSchedulerParametersFlags(virDomainPtr domain, ret = 0; - cleanup: virDomainObjEndAPI(&privdom); return ret; } @@ -3261,7 +3063,6 @@ static int testDomainBlockStats(virDomainPtr domain, const char *path, virDomainBlockStatsPtr stats) { - testDriverPtr privconn = domain->conn->privateData; virDomainObjPtr privdom; struct timeval tv; unsigned long long statbase; @@ -3273,15 +3074,8 @@ static int testDomainBlockStats(virDomainPtr domain, return ret; } - testDriverLock(privconn); - privdom = virDomainObjListFindByName(privconn->domains, - domain->name); - testDriverUnlock(privconn); - - if (privdom == NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); - goto error; - } + if (!(privdom = testDomObjFromDomain(domain))) + return ret; if (virDomainDiskIndexByName(privdom->def, path, false) < 0) { virReportError(VIR_ERR_INVALID_ARG, @@ -3313,22 +3107,14 @@ static int testDomainInterfaceStats(virDomainPtr domain, const char *path, virDomainInterfaceStatsPtr stats) { - testDriverPtr privconn = domain->conn->privateData; virDomainObjPtr privdom; struct timeval tv; unsigned long long statbase; size_t i; int found = 0, ret = -1; - testDriverLock(privconn); - privdom = virDomainObjListFindByName(privconn->domains, - domain->name); - testDriverUnlock(privconn); - - if (privdom == NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); - goto error; - } + if (!(privdom = testDomObjFromDomain(domain))) + return -1; for (i = 0; i < privdom->def->nnets; i++) { if (privdom->def->nets[i]->ifname && @@ -6041,14 +5827,8 @@ testDomainManagedSave(virDomainPtr dom, unsigned int flags) VIR_DOMAIN_SAVE_RUNNING | VIR_DOMAIN_SAVE_PAUSED, -1); - testDriverLock(privconn); - vm = virDomainObjListFindByName(privconn->domains, dom->name); - testDriverUnlock(privconn); - - if (vm == NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); - goto cleanup; - } + if (!(vm = testDomObjFromDomain(dom))) + return -1; if (!virDomainObjIsActive(vm)) { virReportError(VIR_ERR_OPERATION_INVALID, @@ -6080,50 +5860,34 @@ testDomainManagedSave(virDomainPtr dom, unsigned int flags) static int testDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags) { - testDriverPtr privconn = dom->conn->privateData; virDomainObjPtr vm; - int ret = -1; + int ret; virCheckFlags(0, -1); - testDriverLock(privconn); - - vm = virDomainObjListFindByName(privconn->domains, dom->name); - if (vm == NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); - goto cleanup; - } + if (!(vm = testDomObjFromDomain(dom))) + return -1; ret = vm->hasManagedSave; - cleanup: + virDomainObjEndAPI(&vm); - testDriverUnlock(privconn); return ret; } static int testDomainManagedSaveRemove(virDomainPtr dom, unsigned int flags) { - testDriverPtr privconn = dom->conn->privateData; virDomainObjPtr vm; - int ret = -1; virCheckFlags(0, -1); - testDriverLock(privconn); - - vm = virDomainObjListFindByName(privconn->domains, dom->name); - if (vm == NULL) { - virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__); - goto cleanup; - } + if (!(vm = testDomObjFromDomain(dom))) + return -1; vm->hasManagedSave = false; - ret = 0; - cleanup: + virDomainObjEndAPI(&vm); - testDriverUnlock(privconn); - return ret; + return 0; } -- 2.4.1

On Wed, Jun 24, 2015 at 04:11:54PM +0200, Peter Krempa wrote:
Reuse testDomObjFromDomain testDomObjFromDomain to retrieve domain objects in the rest of the test driver instead of open-coding it in every API.
Now that testDomObjFromDomain does not lock the driver it can be reused also in places where the driver is already locked.
The commit message is confusing, please fix it. Pavel
--- src/test/test_driver.c | 390 ++++++++++--------------------------------------- 1 file changed, 77 insertions(+), 313 deletions(-)

Remove the bogous flag check and refactor the code by using virDomainObjGetDefs instead of virDomainObjGetPersistentDef. --- src/test/test_driver.c | 68 +++++++++++++++++--------------------------------- 1 file changed, 23 insertions(+), 45 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 2c2f009..ae332ef 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -2445,6 +2445,7 @@ testDomainSetVcpusFlags(virDomainPtr domain, unsigned int nrCpus, { testDriverPtr privconn = domain->conn->privateData; virDomainObjPtr privdom = NULL; + virDomainDefPtr def; virDomainDefPtr persistentDef; int ret = -1, maxvcpus; @@ -2452,72 +2453,49 @@ testDomainSetVcpusFlags(virDomainPtr domain, unsigned int nrCpus, VIR_DOMAIN_AFFECT_CONFIG | VIR_DOMAIN_VCPU_MAXIMUM, -1); - /* At least one of LIVE or CONFIG must be set. MAXIMUM cannot be - * mixed with LIVE. */ - if ((flags & (VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG)) == 0 || - (flags & (VIR_DOMAIN_VCPU_MAXIMUM | VIR_DOMAIN_AFFECT_LIVE)) == - (VIR_DOMAIN_VCPU_MAXIMUM | VIR_DOMAIN_AFFECT_LIVE)) { - virReportError(VIR_ERR_INVALID_ARG, - _("invalid flag combination: (0x%x)"), flags); + if ((maxvcpus = testConnectGetMaxVcpus(domain->conn, NULL)) == -1) return -1; - } - if (!nrCpus || (maxvcpus = testConnectGetMaxVcpus(domain->conn, NULL)) < nrCpus) { + + if (nrCpus > maxvcpus) { virReportError(VIR_ERR_INVALID_ARG, - _("argument out of range: %d"), nrCpus); + _("requested cpu amount exceeds maximum supported amount " + "(%d > %d)"), nrCpus, maxvcpus); return -1; } if (!(privdom = testDomObjFromDomain(domain))) return -1; - if (!virDomainObjIsActive(privdom) && (flags & VIR_DOMAIN_AFFECT_LIVE)) { - virReportError(VIR_ERR_OPERATION_INVALID, - "%s", _("cannot hotplug vcpus for an inactive domain")); + if (virDomainObjGetDefs(privdom, flags, &def, &persistentDef) < 0) goto cleanup; - } - - /* We allow more cpus in guest than host, but not more than the - * domain's starting limit. */ - if (!(flags & (VIR_DOMAIN_VCPU_MAXIMUM)) && - privdom->def->maxvcpus < maxvcpus) - maxvcpus = privdom->def->maxvcpus; - if (nrCpus > maxvcpus) { + if ((def && + def->maxvcpus < nrCpus) || + (persistentDef && + !(flags & VIR_DOMAIN_VCPU_MAXIMUM) && + persistentDef->maxvcpus < nrCpus)) { virReportError(VIR_ERR_INVALID_ARG, _("requested cpu amount exceeds maximum (%d > %d)"), nrCpus, maxvcpus); goto cleanup; } - if (!(persistentDef = virDomainObjGetPersistentDef(privconn->caps, - privconn->xmlopt, - privdom))) + if (def && + testDomainUpdateVCPUs(privconn, privdom, nrCpus, 0) < 0) goto cleanup; - switch (flags) { - case VIR_DOMAIN_VCPU_MAXIMUM | VIR_DOMAIN_AFFECT_CONFIG: - persistentDef->maxvcpus = nrCpus; - if (nrCpus < persistentDef->vcpus) - persistentDef->vcpus = nrCpus; - ret = 0; - break; - - case VIR_DOMAIN_AFFECT_CONFIG: - persistentDef->vcpus = nrCpus; - ret = 0; - break; - - case VIR_DOMAIN_AFFECT_LIVE: - ret = testDomainUpdateVCPUs(privconn, privdom, nrCpus, 0); - break; - - case VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG: - ret = testDomainUpdateVCPUs(privconn, privdom, nrCpus, 0); - if (ret == 0) + if (persistentDef) { + if (flags & VIR_DOMAIN_VCPU_MAXIMUM) { + persistentDef->maxvcpus = nrCpus; + if (nrCpus < persistentDef->vcpus) + persistentDef->vcpus = nrCpus; + } else { persistentDef->vcpus = nrCpus; - break; + } } + ret = 0; + cleanup: virDomainObjEndAPI(&privdom); return ret; -- 2.4.1

On Wed, Jun 24, 2015 at 04:11:55PM +0200, Peter Krempa wrote:
Remove the bogous flag check and refactor the code by using
s/bogous/bogus/
virDomainObjGetDefs instead of virDomainObjGetPersistentDef. --- src/test/test_driver.c | 68 +++++++++++++++++--------------------------------- 1 file changed, 23 insertions(+), 45 deletions(-)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 2c2f009..ae332ef 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -2445,6 +2445,7 @@ testDomainSetVcpusFlags(virDomainPtr domain, unsigned int nrCpus, { testDriverPtr privconn = domain->conn->privateData; virDomainObjPtr privdom = NULL; + virDomainDefPtr def; virDomainDefPtr persistentDef; int ret = -1, maxvcpus;
@@ -2452,72 +2453,49 @@ testDomainSetVcpusFlags(virDomainPtr domain, unsigned int nrCpus, VIR_DOMAIN_AFFECT_CONFIG | VIR_DOMAIN_VCPU_MAXIMUM, -1);
- /* At least one of LIVE or CONFIG must be set. MAXIMUM cannot be - * mixed with LIVE. */ - if ((flags & (VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG)) == 0 || - (flags & (VIR_DOMAIN_VCPU_MAXIMUM | VIR_DOMAIN_AFFECT_LIVE)) == - (VIR_DOMAIN_VCPU_MAXIMUM | VIR_DOMAIN_AFFECT_LIVE)) { - virReportError(VIR_ERR_INVALID_ARG, - _("invalid flag combination: (0x%x)"), flags); + if ((maxvcpus = testConnectGetMaxVcpus(domain->conn, NULL)) == -1) return -1; - } - if (!nrCpus || (maxvcpus = testConnectGetMaxVcpus(domain->conn, NULL)) < nrCpus) { + + if (nrCpus > maxvcpus) { virReportError(VIR_ERR_INVALID_ARG, - _("argument out of range: %d"), nrCpus); + _("requested cpu amount exceeds maximum supported amount " + "(%d > %d)"), nrCpus, maxvcpus); return -1; }
if (!(privdom = testDomObjFromDomain(domain))) return -1;
- if (!virDomainObjIsActive(privdom) && (flags & VIR_DOMAIN_AFFECT_LIVE)) { - virReportError(VIR_ERR_OPERATION_INVALID, - "%s", _("cannot hotplug vcpus for an inactive domain")); + if (virDomainObjGetDefs(privdom, flags, &def, &persistentDef) < 0) goto cleanup; - } - - /* We allow more cpus in guest than host, but not more than the - * domain's starting limit. */ - if (!(flags & (VIR_DOMAIN_VCPU_MAXIMUM)) && - privdom->def->maxvcpus < maxvcpus) - maxvcpus = privdom->def->maxvcpus;
- if (nrCpus > maxvcpus) { + if ((def && + def->maxvcpus < nrCpus) || + (persistentDef && + !(flags & VIR_DOMAIN_VCPU_MAXIMUM) && + persistentDef->maxvcpus < nrCpus)) { virReportError(VIR_ERR_INVALID_ARG, _("requested cpu amount exceeds maximum (%d > %d)"), nrCpus, maxvcpus);
As pointed in the previous review, you need to use (def|persistentDef)->maxvcpus in the error message.
goto cleanup; }
- if (!(persistentDef = virDomainObjGetPersistentDef(privconn->caps, - privconn->xmlopt, - privdom))) + if (def && + testDomainUpdateVCPUs(privconn, privdom, nrCpus, 0) < 0) goto cleanup;
- switch (flags) { - case VIR_DOMAIN_VCPU_MAXIMUM | VIR_DOMAIN_AFFECT_CONFIG: - persistentDef->maxvcpus = nrCpus; - if (nrCpus < persistentDef->vcpus) - persistentDef->vcpus = nrCpus; - ret = 0; - break; - - case VIR_DOMAIN_AFFECT_CONFIG: - persistentDef->vcpus = nrCpus; - ret = 0; - break; - - case VIR_DOMAIN_AFFECT_LIVE: - ret = testDomainUpdateVCPUs(privconn, privdom, nrCpus, 0); - break; - - case VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG: - ret = testDomainUpdateVCPUs(privconn, privdom, nrCpus, 0); - if (ret == 0) + if (persistentDef) { + if (flags & VIR_DOMAIN_VCPU_MAXIMUM) { + persistentDef->maxvcpus = nrCpus; + if (nrCpus < persistentDef->vcpus) + persistentDef->vcpus = nrCpus; + } else { persistentDef->vcpus = nrCpus; - break; + } }
+ ret = 0; + cleanup: virDomainObjEndAPI(&privdom); return ret; -- 2.4.1
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

Drop internal data structures and use the proper fields in virDomainDef. This allows to greatly simplify the code and allows to remove the private data structure that was holding just redundant data. This patch also fixes the bogous output where we'd report that a fresh VM without vCPU pinning would not run on all vcpus. --- src/test/test_driver.c | 224 +++++++++++-------------------------------------- 1 file changed, 49 insertions(+), 175 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index ae332ef..ed67dca 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -65,14 +65,6 @@ VIR_LOG_INIT("test.test_driver"); -/* Driver specific info to carry with a domain */ -struct _testDomainObjPrivate { - virVcpuInfoPtr vcpu_infos; - - unsigned char *cpumaps; -}; -typedef struct _testDomainObjPrivate testDomainObjPrivate; -typedef struct _testDomainObjPrivate *testDomainObjPrivatePtr; #define MAX_CPUS 128 @@ -183,25 +175,6 @@ static void testObjectEventQueue(testDriverPtr driver, virObjectEventStateQueue(driver->eventState, event); } -static void *testDomainObjPrivateAlloc(void) -{ - testDomainObjPrivatePtr priv; - - if (VIR_ALLOC(priv) < 0) - return NULL; - - return priv; -} - -static void testDomainObjPrivateFree(void *data) -{ - testDomainObjPrivatePtr priv = data; - - VIR_FREE(priv->vcpu_infos); - VIR_FREE(priv->cpumaps); - VIR_FREE(priv); -} - #define TEST_NAMESPACE_HREF "http://libvirt.org/schemas/domain/test/1.0" typedef struct _testDomainNamespaceDef testDomainNamespaceDef; @@ -401,11 +374,6 @@ testBuildCapabilities(virConnectPtr conn) static testDriverPtr testDriverNew(void) { - virDomainXMLPrivateDataCallbacks priv = { - .alloc = testDomainObjPrivateAlloc, - .free = testDomainObjPrivateFree - }; - virDomainXMLNamespace ns = { .parse = testDomainDefNamespaceParse, .free = testDomainDefNamespaceFree, @@ -421,7 +389,7 @@ testDriverNew(void) goto error; } - if (!(ret->xmlopt = virDomainXMLOptionNew(NULL, &priv, &ns)) || + if (!(ret->xmlopt = virDomainXMLOptionNew(NULL, NULL, &ns)) || !(ret->eventState = virObjectEventStateNew()) || !(ret->domains = virDomainObjListNew()) || !(ret->networks = virNetworkObjListNew())) @@ -601,95 +569,6 @@ testDomainGenerateIfnames(virDomainDefPtr domdef) return 0; } -/* Helper to update info for a single VCPU */ -static int -testDomainUpdateVCPU(virDomainObjPtr dom, - int vcpu, - int maplen, - int maxcpu) -{ - testDomainObjPrivatePtr privdata = dom->privateData; - virVcpuInfoPtr info = &privdata->vcpu_infos[vcpu]; - unsigned char *cpumap = VIR_GET_CPUMAP(privdata->cpumaps, maplen, vcpu); - size_t j; - bool cpu; - - memset(info, 0, sizeof(virVcpuInfo)); - memset(cpumap, 0, maplen); - - info->number = vcpu; - info->state = VIR_VCPU_RUNNING; - info->cpuTime = 5000000; - info->cpu = 0; - - if (dom->def->cpumask) { - for (j = 0; j < maxcpu && j < VIR_DOMAIN_CPUMASK_LEN; ++j) { - if (virBitmapGetBit(dom->def->cpumask, j, &cpu) < 0) - return -1; - if (cpu) { - VIR_USE_CPU(cpumap, j); - info->cpu = j; - } - } - } else { - for (j = 0; j < maxcpu; ++j) { - if ((j % 3) == 0) { - /* Mark of every third CPU as usable */ - VIR_USE_CPU(cpumap, j); - info->cpu = j; - } - } - } - - return 0; -} - -/* - * Update domain VCPU amount and info - * - * @conn: virConnectPtr - * @dom : domain needing updates - * @nvcpus: New amount of vcpus for the domain - * @clear_all: If true, rebuild info for ALL vcpus, not just newly added vcpus - */ -static int -testDomainUpdateVCPUs(testDriverPtr privconn, - virDomainObjPtr dom, - int nvcpus, - unsigned int clear_all) -{ - testDomainObjPrivatePtr privdata = dom->privateData; - size_t i; - int ret = -1; - int cpumaplen, maxcpu; - - maxcpu = VIR_NODEINFO_MAXCPUS(privconn->nodeInfo); - cpumaplen = VIR_CPU_MAPLEN(maxcpu); - - if (VIR_REALLOC_N(privdata->vcpu_infos, nvcpus) < 0) - goto cleanup; - - if (VIR_REALLOC_N(privdata->cpumaps, nvcpus * cpumaplen) < 0) - goto cleanup; - - /* Set running VCPU and cpumap state */ - if (clear_all) { - for (i = 0; i < nvcpus; ++i) - if (testDomainUpdateVCPU(dom, i, cpumaplen, maxcpu) < 0) - goto cleanup; - - } else if (nvcpus > dom->def->vcpus) { - /* VCPU amount has grown, populate info for the new vcpus */ - for (i = dom->def->vcpus; i < nvcpus; ++i) - if (testDomainUpdateVCPU(dom, i, cpumaplen, maxcpu) < 0) - goto cleanup; - } - - dom->def->vcpus = nvcpus; - ret = 0; - cleanup: - return ret; -} static void testDomainShutdownState(virDomainPtr domain, @@ -716,9 +595,6 @@ testDomainStartState(testDriverPtr privconn, { int ret = -1; - if (testDomainUpdateVCPUs(privconn, dom, dom->def->vcpus, 1) < 0) - goto cleanup; - virDomainObjSetState(dom, VIR_DOMAIN_RUNNING, reason); dom->def->id = virAtomicIntAdd(&privconn->nextDomID, 1); @@ -2443,7 +2319,6 @@ static int testDomainSetVcpusFlags(virDomainPtr domain, unsigned int nrCpus, unsigned int flags) { - testDriverPtr privconn = domain->conn->privateData; virDomainObjPtr privdom = NULL; virDomainDefPtr def; virDomainDefPtr persistentDef; @@ -2480,9 +2355,8 @@ testDomainSetVcpusFlags(virDomainPtr domain, unsigned int nrCpus, goto cleanup; } - if (def && - testDomainUpdateVCPUs(privconn, privdom, nrCpus, 0) < 0) - goto cleanup; + if (def) + def->vcpus = nrCpus; if (persistentDef) { if (flags & VIR_DOMAIN_VCPU_MAXIMUM) { @@ -2514,13 +2388,14 @@ static int testDomainGetVcpus(virDomainPtr domain, int maplen) { testDriverPtr privconn = domain->conn->privateData; - testDomainObjPrivatePtr privdomdata; virDomainObjPtr privdom; + virDomainDefPtr def; size_t i; - int v, maxcpu, hostcpus; + int maxcpu, hostcpus; int ret = -1; struct timeval tv; unsigned long long statbase; + virBitmapPtr allcpumap; if (!(privdom = testDomObjFromDomain(domain))) return -1; @@ -2531,7 +2406,7 @@ static int testDomainGetVcpus(virDomainPtr domain, goto cleanup; } - privdomdata = privdom->privateData; + def = privdom->def; if (gettimeofday(&tv, NULL) < 0) { virReportSystemError(errno, @@ -2541,45 +2416,47 @@ static int testDomainGetVcpus(virDomainPtr domain, statbase = (tv.tv_sec * 1000UL * 1000UL) + tv.tv_usec; - hostcpus = VIR_NODEINFO_MAXCPUS(privconn->nodeInfo); maxcpu = maplen * 8; if (maxcpu > hostcpus) maxcpu = hostcpus; + if (!(allcpumap = virBitmapNew(hostcpus))) + goto cleanup; + + virBitmapSetAll(allcpumap); + /* Clamp to actual number of vcpus */ if (maxinfo > privdom->def->vcpus) maxinfo = privdom->def->vcpus; - /* Populate virVcpuInfo structures */ - if (info != NULL) { - memset(info, 0, sizeof(*info) * maxinfo); + memset(info, 0, sizeof(*info) * maxinfo); + memset(cpumaps, 0, maxinfo * maplen); - for (i = 0; i < maxinfo; i++) { - virVcpuInfo privinfo = privdomdata->vcpu_infos[i]; + for (i = 0; i < maxinfo; i++) { + virDomainPinDefPtr pininfo; + virBitmapPtr bitmap = NULL; - info[i].number = privinfo.number; - info[i].state = privinfo.state; - info[i].cpu = privinfo.cpu; + pininfo = virDomainPinFind(def->cputune.vcpupin, + def->cputune.nvcpupin, + i); - /* Fake an increasing cpu time value */ - info[i].cpuTime = statbase / 10; - } - } + if (pininfo && pininfo->cpumask) + bitmap = pininfo->cpumask; + else if (def->cpumask) + bitmap = def->cpumask; + else + bitmap = allcpumap; - /* Populate cpumaps */ - if (cpumaps != NULL) { - int privmaplen = VIR_CPU_MAPLEN(hostcpus); - memset(cpumaps, 0, maplen * maxinfo); + if (cpumaps) + virBitmapToDataBuf(bitmap, VIR_GET_CPUMAP(cpumaps, maplen, i), maplen); - for (v = 0; v < maxinfo; v++) { - unsigned char *cpumap = VIR_GET_CPUMAP(cpumaps, maplen, v); + info[i].number = i; + info[i].state = VIR_VCPU_RUNNING; + info[i].cpu = virBitmapLastSetBit(bitmap); - for (i = 0; i < maxcpu; i++) { - if (VIR_CPU_USABLE(privdomdata->cpumaps, privmaplen, v, i)) - VIR_USE_CPU(cpumap, i); - } - } + /* Fake an increasing cpu time value */ + info[i].cpuTime = statbase / 10; } ret = maxinfo; @@ -2593,17 +2470,15 @@ static int testDomainPinVcpu(virDomainPtr domain, unsigned char *cpumap, int maplen) { - testDriverPtr privconn = domain->conn->privateData; - testDomainObjPrivatePtr privdomdata; virDomainObjPtr privdom; - unsigned char *privcpumap; - size_t i; - int maxcpu, hostcpus, privmaplen; + virDomainDefPtr def; int ret = -1; if (!(privdom = testDomObjFromDomain(domain))) return -1; + def = privdom->def; + if (!virDomainObjIsActive(privdom)) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("cannot pin vcpus on an inactive domain")); @@ -2616,20 +2491,19 @@ static int testDomainPinVcpu(virDomainPtr domain, goto cleanup; } - privdomdata = privdom->privateData; - hostcpus = VIR_NODEINFO_MAXCPUS(privconn->nodeInfo); - privmaplen = VIR_CPU_MAPLEN(hostcpus); - - maxcpu = maplen * 8; - if (maxcpu > hostcpus) - maxcpu = hostcpus; - - privcpumap = VIR_GET_CPUMAP(privdomdata->cpumaps, privmaplen, vcpu); - memset(privcpumap, 0, privmaplen); - - for (i = 0; i < maxcpu; i++) { - if (VIR_CPU_USABLE(cpumap, maplen, 0, i)) - VIR_USE_CPU(privcpumap, i); + if (!def->cputune.vcpupin) { + if (VIR_ALLOC(def->cputune.vcpupin) < 0) + goto cleanup; + def->cputune.nvcpupin = 0; + } + if (virDomainPinAdd(&def->cputune.vcpupin, + &def->cputune.nvcpupin, + cpumap, + maplen, + vcpu) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("failed to update or add vcpupin")); + goto cleanup; } ret = 0; -- 2.4.1

On 06/24/2015 10:11 AM, Peter Krempa wrote:
Drop internal data structures and use the proper fields in virDomainDef.
This allows to greatly simplify the code and allows to remove the private data structure that was holding just redundant data.
This patch also fixes the bogous output where we'd report that a fresh
Another bogus typo
VM without vCPU pinning would not run on all vcpus. --- src/test/test_driver.c | 224 +++++++++++-------------------------------------- 1 file changed, 49 insertions(+), 175 deletions(-)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c index ae332ef..ed67dca 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c
...
@@ -2541,45 +2416,47 @@ static int testDomainGetVcpus(virDomainPtr domain,
statbase = (tv.tv_sec * 1000UL * 1000UL) + tv.tv_usec;
- hostcpus = VIR_NODEINFO_MAXCPUS(privconn->nodeInfo); maxcpu = maplen * 8; if (maxcpu > hostcpus) maxcpu = hostcpus;
+ if (!(allcpumap = virBitmapNew(hostcpus))) + goto cleanup; + + virBitmapSetAll(allcpumap); + /* Clamp to actual number of vcpus */ if (maxinfo > privdom->def->vcpus) maxinfo = privdom->def->vcpus;
- /* Populate virVcpuInfo structures */ - if (info != NULL) { - memset(info, 0, sizeof(*info) * maxinfo); + memset(info, 0, sizeof(*info) * maxinfo); + memset(cpumaps, 0, maxinfo * maplen);
- for (i = 0; i < maxinfo; i++) { - virVcpuInfo privinfo = privdomdata->vcpu_infos[i]; + for (i = 0; i < maxinfo; i++) { + virDomainPinDefPtr pininfo; + virBitmapPtr bitmap = NULL;
- info[i].number = privinfo.number; - info[i].state = privinfo.state; - info[i].cpu = privinfo.cpu; + pininfo = virDomainPinFind(def->cputune.vcpupin, + def->cputune.nvcpupin, + i);
- /* Fake an increasing cpu time value */ - info[i].cpuTime = statbase / 10; - } - } + if (pininfo && pininfo->cpumask) + bitmap = pininfo->cpumask; + else if (def->cpumask) + bitmap = def->cpumask; + else + bitmap = allcpumap;
- /* Populate cpumaps */ - if (cpumaps != NULL) { - int privmaplen = VIR_CPU_MAPLEN(hostcpus); - memset(cpumaps, 0, maplen * maxinfo); + if (cpumaps) + virBitmapToDataBuf(bitmap, VIR_GET_CPUMAP(cpumaps, maplen, i), maplen);
- for (v = 0; v < maxinfo; v++) { - unsigned char *cpumap = VIR_GET_CPUMAP(cpumaps, maplen, v); + info[i].number = i; + info[i].state = VIR_VCPU_RUNNING; + info[i].cpu = virBitmapLastSetBit(bitmap);
- for (i = 0; i < maxcpu; i++) { - if (VIR_CPU_USABLE(privdomdata->cpumaps, privmaplen, v, i)) - VIR_USE_CPU(cpumap, i); - } - } + /* Fake an increasing cpu time value */ + info[i].cpuTime = statbase / 10; }
ret = maxinfo;
... Coverity determines that there's a need for virBitmapFree(allcpumap); John

Drop locking of the driver since it is not accessed and simplify the code flow. --- src/test/test_driver.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index ed67dca..25de641 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -5611,31 +5611,23 @@ static int testConnectListAllDomains(virConnectPtr conn, } static int -testNodeGetCPUMap(virConnectPtr conn, +testNodeGetCPUMap(virConnectPtr conn ATTRIBUTE_UNUSED, unsigned char **cpumap, unsigned int *online, unsigned int flags) { - testDriverPtr privconn = conn->privateData; - int ret = -1; - virCheckFlags(0, -1); - testDriverLock(privconn); if (cpumap) { if (VIR_ALLOC_N(*cpumap, 1) < 0) - goto cleanup; + return -1; *cpumap[0] = 0x15; } if (online) *online = 3; - ret = 8; - - cleanup: - testDriverUnlock(privconn); - return ret; + return 8; } static char * -- 2.4.1

On Wed, Jun 24, 2015 at 04:11:57PM +0200, Peter Krempa wrote:
Drop locking of the driver since it is not accessed and simplify the code flow. --- src/test/test_driver.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c index ed67dca..25de641 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -5611,31 +5611,23 @@ static int testConnectListAllDomains(virConnectPtr conn, }
static int -testNodeGetCPUMap(virConnectPtr conn, +testNodeGetCPUMap(virConnectPtr conn ATTRIBUTE_UNUSED, unsigned char **cpumap, unsigned int *online, unsigned int flags) { - testDriverPtr privconn = conn->privateData; - int ret = -1; - virCheckFlags(0, -1);
- testDriverLock(privconn); if (cpumap) { if (VIR_ALLOC_N(*cpumap, 1) < 0) - goto cleanup; + return -1; *cpumap[0] = 0x15; }
if (online) *online = 3;
- ret = 8; - - cleanup: - testDriverUnlock(privconn); - return ret; + return 8;
It would be nice to have a #define for that value instead of a magic number, but if you decide to leave it here, remove the extra space. Pavel
}
static char * -- 2.4.1
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

On Thu, Jun 25, 2015 at 10:57:18 +0200, Pavel Hrdina wrote:
On Wed, Jun 24, 2015 at 04:11:57PM +0200, Peter Krempa wrote:
Drop locking of the driver since it is not accessed and simplify the code flow. --- src/test/test_driver.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c index ed67dca..25de641 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -5611,31 +5611,23 @@ static int testConnectListAllDomains(virConnectPtr conn, }
static int -testNodeGetCPUMap(virConnectPtr conn, +testNodeGetCPUMap(virConnectPtr conn ATTRIBUTE_UNUSED, unsigned char **cpumap, unsigned int *online, unsigned int flags) { - testDriverPtr privconn = conn->privateData; - int ret = -1; - virCheckFlags(0, -1);
- testDriverLock(privconn); if (cpumap) { if (VIR_ALLOC_N(*cpumap, 1) < 0) - goto cleanup; + return -1; *cpumap[0] = 0x15; }
if (online) *online = 3;
- ret = 8; - - cleanup: - testDriverUnlock(privconn); - return ret; + return 8;
It would be nice to have a #define for that value instead of a magic number, but if you decide to leave it here, remove the extra space.
Well there's probably just this one usage place, so I don't think it's worth. Peter

On 06/24/2015 10:11 AM, Peter Krempa wrote:
Version 2 has a few more fixes as suggested by Michal.
Peter Krempa (15): test: Rename testConn to testDriver test: Drop useless forward declaration test: turn 'defaultConn' into a pointer test: Extract code to free testDriver into testDriverFree test: Extract common parts of test driver data allocation test: Drop unused attribute @path from testDriver struct test: Annotate few fields of testDriver structure test: Use atomic access to @nextDomID in struct virTestDriver test: Refactor test driver event sending test: Finalize removal of locking from driver->eventState test: Drop locked access to testDriver->domains test: Refactor test driver domain object retrieval test: Refactor testDomainSetVcpusFlags test: Refactor vcpu pinning and vcpu info retrieval test: Refactor testNodeGetCPUMap
src/test/test_driver.c | 1305 +++++++++++++++--------------------------------- 1 file changed, 401 insertions(+), 904 deletions(-)
Other than a couple of things pointed out things seem reasonable to me ACK John
participants (3)
-
John Ferlan
-
Pavel Hrdina
-
Peter Krempa