1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-01-20 18:03:50 +03:00

test: introduce testDriverCloseInternal

Refactor testConnectClose as it's then obvious that conn->privateData
is set to NULL in all cases. In addition, 'testConnectCloseInternal'
can be better reused.

Signed-off-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
Marc Hartmayer 2018-03-08 13:20:34 +01:00 committed by John Ferlan
parent 55130c0b63
commit bc0f82adf8

View File

@ -1419,10 +1419,36 @@ testConnectAuthenticate(virConnectPtr conn,
return ret;
}
static virDrvOpenStatus testConnectOpen(virConnectPtr conn,
virConnectAuthPtr auth,
virConfPtr conf ATTRIBUTE_UNUSED,
unsigned int flags)
static void
testDriverCloseInternal(testDriverPtr driver)
{
bool dflt = false;
if (driver == defaultPrivconn) {
dflt = true;
virMutexLock(&defaultLock);
if (--defaultConnections) {
virMutexUnlock(&defaultLock);
return;
}
}
testDriverLock(driver);
testDriverFree(driver);
if (dflt) {
defaultPrivconn = NULL;
virMutexUnlock(&defaultLock);
}
}
static virDrvOpenStatus
testConnectOpen(virConnectPtr conn,
virConnectAuthPtr auth,
virConfPtr conf ATTRIBUTE_UNUSED,
unsigned int flags)
{
int ret;
@ -1463,33 +1489,16 @@ static virDrvOpenStatus testConnectOpen(virConnectPtr conn,
return VIR_DRV_OPEN_SUCCESS;
}
static int testConnectClose(virConnectPtr conn)
static int
testConnectClose(virConnectPtr conn)
{
testDriverPtr privconn = conn->privateData;
bool dflt = false;
if (privconn == defaultPrivconn) {
dflt = true;
virMutexLock(&defaultLock);
if (--defaultConnections) {
conn->privateData = NULL;
virMutexUnlock(&defaultLock);
return 0;
}
}
testDriverLock(privconn);
testDriverFree(privconn);
if (dflt) {
defaultPrivconn = NULL;
virMutexUnlock(&defaultLock);
}
testDriverCloseInternal(conn->privateData);
conn->privateData = NULL;
return 0;
}
static int testConnectGetVersion(virConnectPtr conn ATTRIBUTE_UNUSED,
unsigned long *hvVer)
{