nwfilter_driver: Split up nwfilterStateCleanup

This allows nwfilterStateCleanupLocked to be used in
nwfilterStateInitialize in a later patch.

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Tim Wiederhake 2022-03-08 10:49:09 +01:00
parent 8c86168868
commit 68523b2605

View File

@ -53,8 +53,6 @@ VIR_LOG_INIT("nwfilter.nwfilter_driver");
static virNWFilterDriverState *driver;
static int nwfilterStateCleanup(void);
static int nwfilterStateReload(void);
static virMutex driverMutex = VIR_MUTEX_INITIALIZER;
@ -150,6 +148,51 @@ virNWFilterTriggerRebuildImpl(void *opaque)
}
static int
nwfilterStateCleanupLocked(void)
{
if (!driver)
return -1;
if (driver->privileged) {
virNWFilterConfLayerShutdown();
virNWFilterDHCPSnoopShutdown();
virNWFilterLearnShutdown();
virNWFilterIPAddrMapShutdown();
virNWFilterTechDriversShutdown();
nwfilterDriverRemoveDBusMatches();
if (driver->lockFD != -1)
virPidFileRelease(driver->stateDir, "driver", driver->lockFD);
g_free(driver->stateDir);
g_free(driver->configDir);
g_free(driver->bindingDir);
}
virObjectUnref(driver->bindings);
/* free inactive nwfilters */
virNWFilterObjListFree(driver->nwfilters);
g_clear_pointer(&driver, g_free);
return 0;
}
/**
* nwfilterStateCleanup:
*
* Shutdown the nwfilter driver, it will stop all active nwfilters
*/
static int
nwfilterStateCleanup(void)
{
VIR_LOCK_GUARD lock = virLockGuardLock(&driverMutex);
return nwfilterStateCleanupLocked();
}
/**
* nwfilterStateInitialize:
*
@ -307,48 +350,6 @@ nwfilterStateReload(void)
}
/**
* nwfilterStateCleanup:
*
* Shutdown the nwfilter driver, it will stop all active nwfilters
*/
static int
nwfilterStateCleanup(void)
{
if (!driver)
return -1;
if (driver->privileged) {
virNWFilterConfLayerShutdown();
virNWFilterDHCPSnoopShutdown();
virNWFilterLearnShutdown();
virNWFilterIPAddrMapShutdown();
virNWFilterTechDriversShutdown();
nwfilterDriverLock();
nwfilterDriverRemoveDBusMatches();
if (driver->lockFD != -1)
virPidFileRelease(driver->stateDir, "driver", driver->lockFD);
g_free(driver->stateDir);
g_free(driver->configDir);
g_free(driver->bindingDir);
nwfilterDriverUnlock();
}
virObjectUnref(driver->bindings);
/* free inactive nwfilters */
virNWFilterObjListFree(driver->nwfilters);
g_clear_pointer(&driver, g_free);
return 0;
}
static virDrvOpenStatus
nwfilterConnectOpen(virConnectPtr conn,
virConnectAuthPtr auth G_GNUC_UNUSED,