The qemu driver uses connection close callbacks in more places requiring more changes than other drivers, but luckily the changes are very straightforward. The migration code was written in a way ensuring that there's just one callback present so this can be preserved directly. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/qemu/qemu_conf.c | 17 +++++++++----- src/qemu/qemu_conf.h | 3 --- src/qemu/qemu_driver.c | 8 +------ src/qemu/qemu_migration.c | 47 +++++++++++++-------------------------- src/qemu/qemu_process.c | 35 ++++------------------------- src/qemu/qemu_process.h | 11 ++------- 6 files changed, 34 insertions(+), 87 deletions(-) diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index ae5bbcd138..0f10c5bf93 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1311,17 +1311,22 @@ virQEMUDriverCreateXMLConf(virQEMUDriver *driver, const char *defsecmodel) { g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver); + virDomainXMLOption *ret = NULL; virQEMUDriverDomainDefParserConfig.priv = driver; virQEMUDriverDomainDefParserConfig.defSecModel = defsecmodel; virQEMUDriverDomainJobConfig.maxQueuedJobs = cfg->maxQueuedJobs; - return virDomainXMLOptionNew(&virQEMUDriverDomainDefParserConfig, - &virQEMUDriverPrivateDataCallbacks, - &virQEMUDriverDomainXMLNamespace, - &virQEMUDriverDomainABIStability, - &virQEMUDriverDomainSaveCookie, - &virQEMUDriverDomainJobConfig); + ret = virDomainXMLOptionNew(&virQEMUDriverDomainDefParserConfig, + &virQEMUDriverPrivateDataCallbacks, + &virQEMUDriverDomainXMLNamespace, + &virQEMUDriverDomainABIStability, + &virQEMUDriverDomainSaveCookie, + &virQEMUDriverDomainJobConfig); + + virDomainXMLOptionSetCloseCallbackAlloc(ret, virCloseCallbacksDomainAlloc); + + return ret; } diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 8cf2dd2ec5..b7ed00ca41 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -314,9 +314,6 @@ struct _virQEMUDriver { /* Immutable pointer. lockless access */ virLockManagerPlugin *lockManager; - /* Immutable pointer, self-clocking APIs */ - virCloseCallbacks *closeCallbacks; - /* Immutable pointer, self-locking APIs */ virHashAtomic *migrationErrors; }; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 1b3da86c81..bd8c907567 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -846,9 +846,6 @@ qemuStateInitialize(bool privileged, 0, S_IXGRP | S_IXOTH) < 0) goto error; - if (!(qemu_driver->closeCallbacks = virCloseCallbacksNew())) - goto error; - /* Get all the running persistent or transient configs first */ if (virDomainObjListLoadAllConfigs(qemu_driver->domains, cfg->stateDir, @@ -1053,7 +1050,6 @@ qemuStateCleanup(void) return -1; virObjectUnref(qemu_driver->migrationErrors); - virObjectUnref(qemu_driver->closeCallbacks); virLockManagerPluginUnref(qemu_driver->lockManager); virSysinfoDefFree(qemu_driver->hostsysinfo); virPortAllocatorRangeFree(qemu_driver->migrationPorts); @@ -1146,9 +1142,7 @@ static int qemuConnectClose(virConnectPtr conn) { virQEMUDriver *driver = conn->privateData; - /* Get rid of callbacks registered for this conn */ - virCloseCallbacksRun(driver->closeCallbacks, conn, driver->domains); - + virCloseCallbacksDomainRunForConn(driver->domains, conn); conn->privateData = NULL; return 0; diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index f4441d61ae..61a2bc39c4 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -1371,7 +1371,7 @@ qemuDomainGetMigrationBlockers(virDomainObj *vm, * false otherwise. */ bool -qemuMigrationSrcIsAllowed(virQEMUDriver *driver, +qemuMigrationSrcIsAllowed(virQEMUDriver *driver G_GNUC_UNUSED, virDomainObj *vm, bool remote, int asyncJob, @@ -1437,7 +1437,7 @@ qemuMigrationSrcIsAllowed(virQEMUDriver *driver, return false; } - if (qemuProcessAutoDestroyActive(driver, vm)) { + if (virCloseCallbacksDomainIsRegistered(vm, NULL, qemuProcessAutoDestroy)) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("domain is marked for auto destroy")); return false; @@ -2735,7 +2735,7 @@ qemuMigrationSrcBeginResume(virDomainObj *vm, static char * qemuMigrationSrcBeginResumePhase(virConnectPtr conn, - virQEMUDriver *driver, + virQEMUDriver *driver G_GNUC_UNUSED, virDomainObj *vm, const char *xmlin, char **cookieout, @@ -2753,15 +2753,12 @@ qemuMigrationSrcBeginResumePhase(virConnectPtr conn, if (qemuMigrationJobStartPhase(vm, QEMU_MIGRATION_PHASE_BEGIN_RESUME) < 0) return NULL; - virCloseCallbacksUnset(driver->closeCallbacks, vm, - qemuMigrationAnyConnectionClosed); + virCloseCallbacksDomainRemove(vm, NULL, qemuMigrationAnyConnectionClosed); qemuDomainCleanupRemove(vm, qemuProcessCleanupMigrationJob); xml = qemuMigrationSrcBeginResume(vm, xmlin, cookieout, cookieoutlen, flags); - if (virCloseCallbacksSet(driver->closeCallbacks, vm, conn, - qemuMigrationAnyConnectionClosed) < 0) - g_clear_pointer(&xml, g_free); + virCloseCallbacksDomainAdd(vm, conn, qemuMigrationAnyConnectionClosed); if (!xml) ignore_value(qemuMigrationJobSetPhase(vm, QEMU_MIGRATION_PHASE_POSTCOPY_FAILED)); @@ -2837,9 +2834,7 @@ qemuMigrationSrcBegin(virConnectPtr conn, * This prevents any other APIs being invoked while migration is taking * place. */ - if (virCloseCallbacksSet(driver->closeCallbacks, vm, conn, - qemuMigrationAnyConnectionClosed) < 0) - goto endjob; + virCloseCallbacksDomainAdd(vm, conn, qemuMigrationAnyConnectionClosed); } ret = g_steal_pointer(&xml); @@ -3490,8 +3485,7 @@ qemuMigrationDstPrepareResume(virQEMUDriver *driver, QEMU_MIGRATION_COOKIE_CAPS) < 0) VIR_WARN("Unable to encode migration cookie"); - virCloseCallbacksSet(driver->closeCallbacks, vm, conn, - qemuMigrationAnyConnectionClosed); + virCloseCallbacksDomainAdd(vm, conn, qemuMigrationAnyConnectionClosed); if (autoPort) priv->migrationPort = port; @@ -4031,8 +4025,7 @@ qemuMigrationSrcConfirm(virQEMUDriver *driver, if (qemuMigrationJobStartPhase(vm, phase) < 0) goto cleanup; - virCloseCallbacksUnset(driver->closeCallbacks, vm, - qemuMigrationAnyConnectionClosed); + virCloseCallbacksDomainRemove(vm, NULL, qemuMigrationAnyConnectionClosed); qemuDomainCleanupRemove(vm, qemuProcessCleanupMigrationJob); ret = qemuMigrationSrcConfirmPhase(driver, vm, @@ -5285,8 +5278,7 @@ qemuMigrationSrcPerformResume(virQEMUDriver *driver, if (qemuMigrationJobStartPhase(vm, QEMU_MIGRATION_PHASE_PERFORM_RESUME) < 0) return -1; - virCloseCallbacksUnset(driver->closeCallbacks, vm, - qemuMigrationAnyConnectionClosed); + virCloseCallbacksDomainRemove(vm, NULL, qemuMigrationAnyConnectionClosed); qemuDomainCleanupRemove(vm, qemuProcessCleanupMigrationJob); ret = qemuMigrationSrcPerformNative(driver, vm, NULL, uri, @@ -5294,9 +5286,7 @@ qemuMigrationSrcPerformResume(virQEMUDriver *driver, cookieout, cookieoutlen, flags, 0, NULL, NULL, 0, NULL, migParams, NULL); - if (virCloseCallbacksSet(driver->closeCallbacks, vm, conn, - qemuMigrationAnyConnectionClosed) < 0) - ret = -1; + virCloseCallbacksDomainAdd(vm, conn, qemuMigrationAnyConnectionClosed); if (ret < 0) ignore_value(qemuMigrationJobSetPhase(vm, QEMU_MIGRATION_PHASE_POSTCOPY_FAILED)); @@ -6034,8 +6024,7 @@ qemuMigrationSrcPerformJob(virQEMUDriver *driver, if (qemuMigrationJobStartPhase(vm, QEMU_MIGRATION_PHASE_BEGIN_RESUME) < 0) goto cleanup; - virCloseCallbacksUnset(driver->closeCallbacks, vm, - qemuMigrationAnyConnectionClosed); + virCloseCallbacksDomainRemove(vm, NULL, qemuMigrationAnyConnectionClosed); qemuDomainCleanupRemove(vm, qemuProcessCleanupMigrationJob); } else { if (qemuMigrationJobStart(vm, VIR_ASYNC_JOB_MIGRATION_OUT, @@ -6167,8 +6156,7 @@ qemuMigrationSrcPerformPhase(virQEMUDriver *driver, if (qemuMigrationJobStartPhase(vm, QEMU_MIGRATION_PHASE_PERFORM3) < 0) goto cleanup; - virCloseCallbacksUnset(driver->closeCallbacks, vm, - qemuMigrationAnyConnectionClosed); + virCloseCallbacksDomainRemove(vm, NULL, qemuMigrationAnyConnectionClosed); if (qemuMigrationSrcPerformNative(driver, vm, persist_xml, uri, cookiein, cookieinlen, cookieout, cookieoutlen, @@ -6176,9 +6164,7 @@ qemuMigrationSrcPerformPhase(virQEMUDriver *driver, nmigrate_disks, migrate_disks, migParams, nbdURI) < 0) goto cleanup; - if (virCloseCallbacksSet(driver->closeCallbacks, vm, conn, - qemuMigrationAnyConnectionClosed) < 0) - goto cleanup; + virCloseCallbacksDomainAdd(vm, conn, qemuMigrationAnyConnectionClosed); ignore_value(qemuMigrationJobSetPhase(vm, QEMU_MIGRATION_PHASE_PERFORM3_DONE)); ret = 0; @@ -6434,7 +6420,7 @@ qemuMigrationDstComplete(virQEMUDriver *driver, * nothing to remove when we are resuming post-copy migration. */ if (job->phase < QEMU_MIGRATION_PHASE_POSTCOPY_FAILED) - qemuProcessAutoDestroyRemove(driver, vm); + virCloseCallbacksDomainRemove(vm, NULL, qemuProcessAutoDestroy); /* Remove completed stats for post-copy, everything but timing fields * is obsolete anyway. @@ -6727,7 +6713,7 @@ qemuMigrationDstFinishActive(virQEMUDriver *driver, if (virDomainObjIsFailedPostcopy(vm)) { ignore_value(qemuMigrationJobSetPhase(vm, QEMU_MIGRATION_PHASE_POSTCOPY_FAILED)); - qemuProcessAutoDestroyRemove(driver, vm); + virCloseCallbacksDomainRemove(vm, NULL, qemuProcessAutoDestroy); *finishJob = false; } else { qemuMigrationParamsReset(vm, VIR_ASYNC_JOB_MIGRATION_IN, @@ -6787,8 +6773,7 @@ qemuMigrationDstFinish(virQEMUDriver *driver, goto cleanup; if (flags & VIR_MIGRATE_POSTCOPY_RESUME) { - virCloseCallbacksUnset(driver->closeCallbacks, vm, - qemuMigrationAnyConnectionClosed); + virCloseCallbacksDomainRemove(vm, NULL, qemuMigrationAnyConnectionClosed); qemuDomainCleanupRemove(vm, qemuProcessCleanupMigrationJob); } else { qemuDomainCleanupRemove(vm, qemuMigrationDstPrepareCleanup); diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index b6adcf2f2a..fc4e58f95b 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -7901,9 +7901,8 @@ qemuProcessLaunch(virConnectPtr conn, qemuProcessRefreshBalloonState(vm, asyncJob) < 0) goto cleanup; - if (flags & VIR_QEMU_PROCESS_START_AUTODESTROY && - qemuProcessAutoDestroyAdd(driver, vm, conn) < 0) - goto cleanup; + if (flags & VIR_QEMU_PROCESS_START_AUTODESTROY) + virCloseCallbacksDomainAdd(vm, conn, qemuProcessAutoDestroy); if (!incoming && !snapshot) { VIR_DEBUG("Setting up transient disk"); @@ -8381,7 +8380,7 @@ void qemuProcessStop(virQEMUDriver *driver, virFileDeleteTree(priv->channelTargetDir); /* Stop autodestroy in case guest is restarted */ - qemuProcessAutoDestroyRemove(driver, vm); + virCloseCallbacksDomainRemove(vm, NULL, qemuProcessAutoDestroy); /* now that we know it's stopped call the hook if present */ if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) { @@ -8601,7 +8600,7 @@ void qemuProcessStop(virQEMUDriver *driver, } -static void +void qemuProcessAutoDestroy(virDomainObj *dom, virConnectPtr conn) { @@ -8641,32 +8640,6 @@ qemuProcessAutoDestroy(virDomainObj *dom, virObjectEventStateQueue(driver->domainEventState, event); } -int qemuProcessAutoDestroyAdd(virQEMUDriver *driver, - virDomainObj *vm, - virConnectPtr conn) -{ - VIR_DEBUG("vm=%s, conn=%p", vm->def->name, conn); - return virCloseCallbacksSet(driver->closeCallbacks, vm, conn, - qemuProcessAutoDestroy); -} - -int qemuProcessAutoDestroyRemove(virQEMUDriver *driver, - virDomainObj *vm) -{ - VIR_DEBUG("vm=%s", vm->def->name); - return virCloseCallbacksUnset(driver->closeCallbacks, vm, - qemuProcessAutoDestroy); -} - -bool qemuProcessAutoDestroyActive(virQEMUDriver *driver, - virDomainObj *vm) -{ - virCloseCallback cb; - VIR_DEBUG("vm=%s", vm->def->name); - cb = virCloseCallbacksGet(driver->closeCallbacks, vm, NULL); - return cb == qemuProcessAutoDestroy; -} - int qemuProcessRefreshDisks(virDomainObj *vm, diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h index 9a24745f15..b171f0464c 100644 --- a/src/qemu/qemu_process.h +++ b/src/qemu/qemu_process.h @@ -168,15 +168,8 @@ int qemuProcessKill(virDomainObj *vm, unsigned int flags); void qemuProcessShutdownOrReboot(virDomainObj *vm); -int qemuProcessAutoDestroyInit(virQEMUDriver *driver); -void qemuProcessAutoDestroyShutdown(virQEMUDriver *driver); -int qemuProcessAutoDestroyAdd(virQEMUDriver *driver, - virDomainObj *vm, - virConnectPtr conn); -int qemuProcessAutoDestroyRemove(virQEMUDriver *driver, - virDomainObj *vm); -bool qemuProcessAutoDestroyActive(virQEMUDriver *driver, - virDomainObj *vm); +void qemuProcessAutoDestroy(virDomainObj *dom, + virConnectPtr conn); int qemuProcessSetSchedParams(int id, pid_t pid, size_t nsp, virDomainThreadSchedParam *sp); -- 2.38.1