mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
qemu: Introduce and use qemuDomainRemoveInactiveJob
At some places we either already have synchronous job or we just released it. Also, some APIs might want to use this code without having to release their job. Anyway, the job acquire code is moved out to qemuDomainRemoveInactiveJob so that qemuDomainRemoveInactive does just what it promises. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
parent
265d0bed0b
commit
9115dcd83e
@ -5330,14 +5330,16 @@ qemuDomainSnapshotDiscardAllMetadata(virQEMUDriverPtr driver,
|
||||
return rem.err;
|
||||
}
|
||||
|
||||
/*
|
||||
* The caller must hold a lock the vm.
|
||||
|
||||
/**
|
||||
* qemuDomainRemoveInactive:
|
||||
*
|
||||
* The caller must hold a lock to the vm.
|
||||
*/
|
||||
void
|
||||
qemuDomainRemoveInactive(virQEMUDriverPtr driver,
|
||||
virDomainObjPtr vm)
|
||||
{
|
||||
bool haveJob = true;
|
||||
char *snapDir;
|
||||
virQEMUDriverConfigPtr cfg;
|
||||
|
||||
@ -5348,9 +5350,6 @@ qemuDomainRemoveInactive(virQEMUDriverPtr driver,
|
||||
|
||||
cfg = virQEMUDriverGetConfig(driver);
|
||||
|
||||
if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
|
||||
haveJob = false;
|
||||
|
||||
/* Remove any snapshot metadata prior to removing the domain */
|
||||
if (qemuDomainSnapshotDiscardAllMetadata(driver, vm) < 0) {
|
||||
VIR_WARN("unable to remove all snapshots for domain %s",
|
||||
@ -5383,13 +5382,33 @@ qemuDomainRemoveInactive(virQEMUDriverPtr driver,
|
||||
*/
|
||||
virObjectLock(vm);
|
||||
virObjectUnref(cfg);
|
||||
virObjectUnref(vm);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* qemuDomainRemoveInactiveJob:
|
||||
*
|
||||
* Just like qemuDomainRemoveInactive but it tries to grab a
|
||||
* QEMU_JOB_MODIFY first. Even though it doesn't succeed in
|
||||
* grabbing the job the control carries with
|
||||
* qemuDomainRemoveInactive call.
|
||||
*/
|
||||
void
|
||||
qemuDomainRemoveInactiveJob(virQEMUDriverPtr driver,
|
||||
virDomainObjPtr vm)
|
||||
{
|
||||
bool haveJob;
|
||||
|
||||
haveJob = qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) >= 0;
|
||||
|
||||
qemuDomainRemoveInactive(driver, vm);
|
||||
|
||||
if (haveJob)
|
||||
qemuDomainObjEndJob(driver, vm);
|
||||
|
||||
virObjectUnref(vm);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
qemuDomainSetFakeReboot(virQEMUDriverPtr driver,
|
||||
virDomainObjPtr vm,
|
||||
|
@ -611,6 +611,9 @@ int qemuDomainSnapshotDiscardAllMetadata(virQEMUDriverPtr driver,
|
||||
void qemuDomainRemoveInactive(virQEMUDriverPtr driver,
|
||||
virDomainObjPtr vm);
|
||||
|
||||
void qemuDomainRemoveInactiveJob(virQEMUDriverPtr driver,
|
||||
virDomainObjPtr vm);
|
||||
|
||||
void qemuDomainSetFakeReboot(virQEMUDriverPtr driver,
|
||||
virDomainObjPtr vm,
|
||||
bool value);
|
||||
|
@ -1779,7 +1779,7 @@ static virDomainPtr qemuDomainCreateXML(virConnectPtr conn,
|
||||
def = NULL;
|
||||
|
||||
if (qemuProcessBeginJob(driver, vm, VIR_DOMAIN_JOB_OPERATION_START) < 0) {
|
||||
qemuDomainRemoveInactive(driver, vm);
|
||||
qemuDomainRemoveInactiveJob(driver, vm);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
@ -1788,8 +1788,8 @@ static virDomainPtr qemuDomainCreateXML(virConnectPtr conn,
|
||||
VIR_NETDEV_VPORT_PROFILE_OP_CREATE,
|
||||
start_flags) < 0) {
|
||||
virDomainAuditStart(vm, "booted", false);
|
||||
qemuProcessEndJob(driver, vm);
|
||||
qemuDomainRemoveInactive(driver, vm);
|
||||
qemuProcessEndJob(driver, vm);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
@ -2259,9 +2259,9 @@ qemuDomainDestroyFlags(virDomainPtr dom,
|
||||
|
||||
ret = 0;
|
||||
endjob:
|
||||
qemuDomainObjEndJob(driver, vm);
|
||||
if (ret == 0)
|
||||
qemuDomainRemoveInactive(driver, vm);
|
||||
qemuDomainObjEndJob(driver, vm);
|
||||
|
||||
cleanup:
|
||||
virDomainObjEndAPI(&vm);
|
||||
@ -3396,7 +3396,7 @@ qemuDomainSaveInternal(virQEMUDriverPtr driver, virDomainPtr dom,
|
||||
}
|
||||
qemuDomainObjEndAsyncJob(driver, vm);
|
||||
if (ret == 0)
|
||||
qemuDomainRemoveInactive(driver, vm);
|
||||
qemuDomainRemoveInactiveJob(driver, vm);
|
||||
|
||||
cleanup:
|
||||
virObjectUnref(cookie);
|
||||
@ -3916,7 +3916,7 @@ qemuDomainCoreDumpWithFormat(virDomainPtr dom,
|
||||
|
||||
qemuDomainObjEndAsyncJob(driver, vm);
|
||||
if (ret == 0 && flags & VIR_DUMP_CRASH)
|
||||
qemuDomainRemoveInactive(driver, vm);
|
||||
qemuDomainRemoveInactiveJob(driver, vm);
|
||||
|
||||
cleanup:
|
||||
virDomainObjEndAPI(&vm);
|
||||
@ -4227,7 +4227,7 @@ processGuestPanicEvent(virQEMUDriverPtr driver,
|
||||
endjob:
|
||||
qemuDomainObjEndAsyncJob(driver, vm);
|
||||
if (removeInactive)
|
||||
qemuDomainRemoveInactive(driver, vm);
|
||||
qemuDomainRemoveInactiveJob(driver, vm);
|
||||
|
||||
cleanup:
|
||||
virObjectUnref(cfg);
|
||||
@ -4729,8 +4729,8 @@ processMonitorEOFEvent(virQEMUDriverPtr driver,
|
||||
qemuDomainEventQueue(driver, event);
|
||||
|
||||
endjob:
|
||||
qemuDomainObjEndJob(driver, vm);
|
||||
qemuDomainRemoveInactive(driver, vm);
|
||||
qemuDomainObjEndJob(driver, vm);
|
||||
}
|
||||
|
||||
|
||||
@ -6680,7 +6680,7 @@ qemuDomainRestoreFlags(virConnectPtr conn,
|
||||
VIR_FREE(xmlout);
|
||||
virFileWrapperFdFree(wrapperFd);
|
||||
if (vm && ret < 0)
|
||||
qemuDomainRemoveInactive(driver, vm);
|
||||
qemuDomainRemoveInactiveJob(driver, vm);
|
||||
virDomainObjEndAPI(&vm);
|
||||
virNWFilterUnlockFilterUpdates();
|
||||
return ret;
|
||||
@ -7263,7 +7263,7 @@ qemuDomainDefineXMLFlags(virConnectPtr conn,
|
||||
/* Brand new domain. Remove it */
|
||||
VIR_INFO("Deleting domain '%s'", vm->def->name);
|
||||
vm->persistent = 0;
|
||||
qemuDomainRemoveInactive(driver, vm);
|
||||
qemuDomainRemoveInactiveJob(driver, vm);
|
||||
}
|
||||
goto cleanup;
|
||||
}
|
||||
@ -7396,7 +7396,7 @@ qemuDomainUndefineFlags(virDomainPtr dom,
|
||||
*/
|
||||
vm->persistent = 0;
|
||||
if (!virDomainObjIsActive(vm))
|
||||
qemuDomainRemoveInactive(driver, vm);
|
||||
qemuDomainRemoveInactiveJob(driver, vm);
|
||||
|
||||
ret = 0;
|
||||
|
||||
@ -15646,8 +15646,8 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
|
||||
}
|
||||
|
||||
if (qemuDomainSnapshotRevertInactive(driver, vm, snap) < 0) {
|
||||
qemuProcessEndJob(driver, vm);
|
||||
qemuDomainRemoveInactive(driver, vm);
|
||||
qemuProcessEndJob(driver, vm);
|
||||
goto cleanup;
|
||||
}
|
||||
if (config)
|
||||
@ -15668,8 +15668,8 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
|
||||
start_flags);
|
||||
virDomainAuditStart(vm, "from-snapshot", rc >= 0);
|
||||
if (rc < 0) {
|
||||
qemuProcessEndJob(driver, vm);
|
||||
qemuDomainRemoveInactive(driver, vm);
|
||||
qemuProcessEndJob(driver, vm);
|
||||
goto cleanup;
|
||||
}
|
||||
detail = VIR_DOMAIN_EVENT_STARTED_FROM_SNAPSHOT;
|
||||
@ -16012,8 +16012,8 @@ static virDomainPtr qemuDomainQemuAttach(virConnectPtr conn,
|
||||
if (qemuProcessAttach(conn, driver, vm, pid,
|
||||
pidfile, monConfig, monJSON) < 0) {
|
||||
monConfig = NULL;
|
||||
qemuDomainObjEndJob(driver, vm);
|
||||
qemuDomainRemoveInactive(driver, vm);
|
||||
qemuDomainObjEndJob(driver, vm);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
@ -2850,7 +2850,7 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
|
||||
virPortAllocatorRelease(driver->migrationPorts, priv->nbdPort);
|
||||
priv->nbdPort = 0;
|
||||
virDomainObjRemoveTransientDef(vm);
|
||||
qemuDomainRemoveInactive(driver, vm);
|
||||
qemuDomainRemoveInactiveJob(driver, vm);
|
||||
}
|
||||
qemuMigrationParamsClear(&migParams);
|
||||
virDomainObjEndAPI(&vm);
|
||||
@ -3291,7 +3291,7 @@ qemuMigrationConfirm(virConnectPtr conn,
|
||||
virDomainDeleteConfig(cfg->configDir, cfg->autostartDir, vm);
|
||||
vm->persistent = 0;
|
||||
}
|
||||
qemuDomainRemoveInactive(driver, vm);
|
||||
qemuDomainRemoveInactiveJob(driver, vm);
|
||||
}
|
||||
|
||||
cleanup:
|
||||
@ -4867,7 +4867,7 @@ qemuMigrationPerformJob(virQEMUDriverPtr driver,
|
||||
virDomainDeleteConfig(cfg->configDir, cfg->autostartDir, vm);
|
||||
vm->persistent = 0;
|
||||
}
|
||||
qemuDomainRemoveInactive(driver, vm);
|
||||
qemuDomainRemoveInactiveJob(driver, vm);
|
||||
}
|
||||
|
||||
if (orig_err) {
|
||||
@ -4947,7 +4947,7 @@ qemuMigrationPerformPhase(virQEMUDriverPtr driver,
|
||||
}
|
||||
|
||||
if (!virDomainObjIsActive(vm))
|
||||
qemuDomainRemoveInactive(driver, vm);
|
||||
qemuDomainRemoveInactiveJob(driver, vm);
|
||||
|
||||
cleanup:
|
||||
virDomainObjEndAPI(&vm);
|
||||
@ -5388,7 +5388,7 @@ qemuMigrationFinish(virQEMUDriverPtr driver,
|
||||
|
||||
qemuMigrationJobFinish(driver, vm);
|
||||
if (!virDomainObjIsActive(vm))
|
||||
qemuDomainRemoveInactive(driver, vm);
|
||||
qemuDomainRemoveInactiveJob(driver, vm);
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(jobInfo);
|
||||
|
@ -6661,10 +6661,10 @@ qemuProcessAutoDestroy(virDomainObjPtr dom,
|
||||
VIR_DOMAIN_EVENT_STOPPED,
|
||||
VIR_DOMAIN_EVENT_STOPPED_DESTROYED);
|
||||
|
||||
qemuDomainObjEndJob(driver, dom);
|
||||
|
||||
qemuDomainRemoveInactive(driver, dom);
|
||||
|
||||
qemuDomainObjEndJob(driver, dom);
|
||||
|
||||
qemuDomainEventQueue(driver, event);
|
||||
|
||||
cleanup:
|
||||
@ -6996,10 +6996,14 @@ qemuProcessReconnect(void *opaque)
|
||||
driver->inhibitCallback(true, driver->inhibitOpaque);
|
||||
|
||||
cleanup:
|
||||
if (jobStarted)
|
||||
if (jobStarted) {
|
||||
if (!virDomainObjIsActive(obj))
|
||||
qemuDomainRemoveInactive(driver, obj);
|
||||
qemuDomainObjEndJob(driver, obj);
|
||||
if (!virDomainObjIsActive(obj))
|
||||
qemuDomainRemoveInactive(driver, obj);
|
||||
} else {
|
||||
if (!virDomainObjIsActive(obj))
|
||||
qemuDomainRemoveInactiveJob(driver, obj);
|
||||
}
|
||||
virDomainObjEndAPI(&obj);
|
||||
virObjectUnref(conn);
|
||||
virObjectUnref(cfg);
|
||||
@ -7074,7 +7078,7 @@ qemuProcessReconnectHelper(virDomainObjPtr obj,
|
||||
*/
|
||||
qemuProcessStop(src->driver, obj, VIR_DOMAIN_SHUTOFF_FAILED,
|
||||
QEMU_ASYNC_JOB_NONE, 0);
|
||||
qemuDomainRemoveInactive(src->driver, obj);
|
||||
qemuDomainRemoveInactiveJob(src->driver, obj);
|
||||
|
||||
virDomainObjEndAPI(&obj);
|
||||
virNWFilterUnlockFilterUpdates();
|
||||
|
Loading…
Reference in New Issue
Block a user