lxc: Use new connection close callbacks API

The rewrite is straightforward as LXC registers only the
'lxcProcessAutoDestroy' callback which by design doesn't need any
special handling (there's just one caller which can start the VM thus
implicitly there's only one possible registration for that function).

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
Peter Krempa 2022-08-29 16:13:58 +02:00
parent cb195c19b7
commit e74bb402e4
4 changed files with 16 additions and 18 deletions

View File

@ -184,12 +184,19 @@ virCaps *virLXCDriverGetCapabilities(virLXCDriver *driver,
virDomainXMLOption *
lxcDomainXMLConfInit(virLXCDriver *driver, const char *defsecmodel)
{
virDomainXMLOption *ret = NULL;
virLXCDriverDomainDefParserConfig.priv = driver;
virLXCDriverDomainDefParserConfig.defSecModel = defsecmodel;
return virDomainXMLOptionNew(&virLXCDriverDomainDefParserConfig,
&virLXCDriverPrivateDataCallbacks,
&virLXCDriverDomainXMLNamespace,
NULL, NULL, NULL);
ret = virDomainXMLOptionNew(&virLXCDriverDomainDefParserConfig,
&virLXCDriverPrivateDataCallbacks,
&virLXCDriverDomainXMLNamespace,
NULL, NULL, NULL);
virDomainXMLOptionSetCloseCallbackAlloc(ret, virCloseCallbacksDomainAlloc);
return ret;
}

View File

@ -93,9 +93,6 @@ struct _virLXCDriver {
/* Immutable pointer. self-locking APIs */
virSecurityManager *securityManager;
/* Immutable pointer, self-locking APIs */
virCloseCallbacks *closeCallbacks;
};
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virLXCDriverConfig, virObjectUnref);

View File

@ -161,7 +161,8 @@ static int lxcConnectClose(virConnectPtr conn)
{
virLXCDriver *driver = conn->privateData;
virCloseCallbacksRun(driver->closeCallbacks, conn, driver->domains);
virCloseCallbacksDomainRunForConn(driver->domains, conn);
conn->privateData = NULL;
return 0;
}
@ -1496,9 +1497,6 @@ static int lxcStateInitialize(bool privileged,
if (!(lxc_driver->xmlopt = lxcDomainXMLConfInit(lxc_driver, defsecmodel)))
goto cleanup;
if (!(lxc_driver->closeCallbacks = virCloseCallbacksNew()))
goto cleanup;
if (g_mkdir_with_parents(cfg->stateDir, 0777) < 0) {
virReportSystemError(errno,
_("Failed to mkdir %s"),
@ -1586,8 +1584,6 @@ static int lxcStateCleanup(void)
virObjectUnref(lxc_driver->domains);
virObjectUnref(lxc_driver->domainEventState);
virObjectUnref(lxc_driver->closeCallbacks);
virSysinfoDefFree(lxc_driver->hostsysinfo);
virObjectUnref(lxc_driver->hostdevMgr);

View File

@ -188,7 +188,7 @@ static void virLXCProcessCleanup(virLXCDriver *driver,
/* Stop autodestroy in case guest is restarted */
if (flags & VIR_LXC_PROCESS_CLEANUP_AUTODESTROY) {
virCloseCallbacksUnset(driver->closeCallbacks, vm, lxcProcessAutoDestroy);
virCloseCallbacksDomainRemove(vm, NULL, lxcProcessAutoDestroy);
}
if (priv->monitor) {
@ -1504,10 +1504,8 @@ int virLXCProcessStart(virLXCDriver * driver,
goto cleanup;
}
if (autoDestroyConn &&
virCloseCallbacksSet(driver->closeCallbacks, vm,
autoDestroyConn, lxcProcessAutoDestroy) < 0)
goto cleanup;
if (autoDestroyConn)
virCloseCallbacksDomainAdd(vm, autoDestroyConn, lxcProcessAutoDestroy);
/* We don't need the temporary NIC names anymore, clear them */
virLXCProcessCleanInterfaces(vm->def);