qemu: drop needless acquiring job removing domain

Acquiring job introduced in commit [1] to fix a race described in the
commit. Actually it does not help because we get domain in create API
before acuiring job. Then [2] fixed the race but [1] was not reverted even
it is does not required by [2] to work properly.

[1] commit b629c64e5e
Author: Martin Kletzander <mkletzan@redhat.com>
Date:   Thu Oct 30 14:38:35 2014 +0100

    qemu: avoid rare race when undefining domain

[2] commit c7d1c139ca
Author: Martin Kletzander <mkletzan@redhat.com>
Date:   Thu Dec 11 11:14:08 2014 +0100

    qemu: avoid rare race when undefining domain

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@openvz.org>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
Nikolay Shirokovskiy 2022-04-12 15:34:09 +03:00
parent b66a36e719
commit e55302596b
5 changed files with 20 additions and 69 deletions

View File

@ -7343,7 +7343,7 @@ qemuDomainRemoveInactive(virQEMUDriver *driver,
* lock on driver->domains in order to call the remove obj * lock on driver->domains in order to call the remove obj
* from locked list method. * from locked list method.
*/ */
static void void
qemuDomainRemoveInactiveLocked(virQEMUDriver *driver, qemuDomainRemoveInactiveLocked(virQEMUDriver *driver,
virDomainObj *vm) virDomainObj *vm)
{ {
@ -7357,49 +7357,6 @@ qemuDomainRemoveInactiveLocked(virQEMUDriver *driver,
virDomainObjListRemoveLocked(driver->domains, vm); virDomainObjListRemoveLocked(driver->domains, vm);
} }
/**
* qemuDomainRemoveInactiveJob:
*
* Just like qemuDomainRemoveInactive but it tries to grab a
* VIR_JOB_MODIFY first. Even though it doesn't succeed in
* grabbing the job the control carries with
* qemuDomainRemoveInactive call.
*/
void
qemuDomainRemoveInactiveJob(virQEMUDriver *driver,
virDomainObj *vm)
{
bool haveJob;
haveJob = qemuDomainObjBeginJob(driver, vm, VIR_JOB_MODIFY) >= 0;
qemuDomainRemoveInactive(driver, vm);
if (haveJob)
qemuDomainObjEndJob(vm);
}
/**
* qemuDomainRemoveInactiveJobLocked:
*
* Similar to qemuDomainRemoveInactiveJob, except that the caller must
* also hold the lock @driver->domains
*/
void
qemuDomainRemoveInactiveJobLocked(virQEMUDriver *driver,
virDomainObj *vm)
{
bool haveJob;
haveJob = qemuDomainObjBeginJob(driver, vm, VIR_JOB_MODIFY) >= 0;
qemuDomainRemoveInactiveLocked(driver, vm);
if (haveJob)
qemuDomainObjEndJob(vm);
}
void void
qemuDomainSetFakeReboot(virDomainObj *vm, qemuDomainSetFakeReboot(virDomainObj *vm,

View File

@ -672,6 +672,10 @@ int qemuDomainSnapshotDiscardAllMetadata(virQEMUDriver *driver,
void qemuDomainRemoveInactive(virQEMUDriver *driver, void qemuDomainRemoveInactive(virQEMUDriver *driver,
virDomainObj *vm); virDomainObj *vm);
void
qemuDomainRemoveInactiveLocked(virQEMUDriver *driver,
virDomainObj *vm);
void qemuDomainSetFakeReboot(virDomainObj *vm, void qemuDomainSetFakeReboot(virDomainObj *vm,
bool value); bool value);
@ -1036,12 +1040,6 @@ int
qemuDomainDefNumaCPUsRectify(virDomainDef *def, qemuDomainDefNumaCPUsRectify(virDomainDef *def,
virQEMUCaps *qemuCaps); virQEMUCaps *qemuCaps);
void qemuDomainRemoveInactiveJob(virQEMUDriver *driver,
virDomainObj *vm);
void qemuDomainRemoveInactiveJobLocked(virQEMUDriver *driver,
virDomainObj *vm);
int virQEMUFileOpenAs(uid_t fallback_uid, int virQEMUFileOpenAs(uid_t fallback_uid,
gid_t fallback_gid, gid_t fallback_gid,
bool dynamicOwnership, bool dynamicOwnership,

View File

@ -1625,7 +1625,7 @@ static virDomainPtr qemuDomainCreateXML(virConnectPtr conn,
if (qemuProcessBeginJob(driver, vm, VIR_DOMAIN_JOB_OPERATION_START, if (qemuProcessBeginJob(driver, vm, VIR_DOMAIN_JOB_OPERATION_START,
flags) < 0) { flags) < 0) {
qemuDomainRemoveInactiveJob(driver, vm); qemuDomainRemoveInactive(driver, vm);
goto cleanup; goto cleanup;
} }
@ -2751,7 +2751,7 @@ qemuDomainSaveInternal(virQEMUDriver *driver,
} }
qemuDomainObjEndAsyncJob(vm); qemuDomainObjEndAsyncJob(vm);
if (ret == 0) if (ret == 0)
qemuDomainRemoveInactiveJob(driver, vm); qemuDomainRemoveInactive(driver, vm);
cleanup: cleanup:
virQEMUSaveDataFree(data); virQEMUSaveDataFree(data);
@ -3228,7 +3228,7 @@ qemuDomainCoreDumpWithFormat(virDomainPtr dom,
qemuDomainObjEndAsyncJob(vm); qemuDomainObjEndAsyncJob(vm);
if (ret == 0 && flags & VIR_DUMP_CRASH) if (ret == 0 && flags & VIR_DUMP_CRASH)
qemuDomainRemoveInactiveJob(driver, vm); qemuDomainRemoveInactive(driver, vm);
cleanup: cleanup:
virDomainObjEndAPI(&vm); virDomainObjEndAPI(&vm);
@ -3536,7 +3536,7 @@ processGuestPanicEvent(virQEMUDriver *driver,
endjob: endjob:
qemuDomainObjEndAsyncJob(vm); qemuDomainObjEndAsyncJob(vm);
if (removeInactive) if (removeInactive)
qemuDomainRemoveInactiveJob(driver, vm); qemuDomainRemoveInactive(driver, vm);
} }
@ -5851,7 +5851,7 @@ qemuDomainRestoreFlags(virConnectPtr conn,
virFileWrapperFdFree(wrapperFd); virFileWrapperFdFree(wrapperFd);
virQEMUSaveDataFree(data); virQEMUSaveDataFree(data);
if (vm && ret < 0) if (vm && ret < 0)
qemuDomainRemoveInactiveJob(driver, vm); qemuDomainRemoveInactive(driver, vm);
virDomainObjEndAPI(&vm); virDomainObjEndAPI(&vm);
return ret; return ret;
} }
@ -6510,7 +6510,7 @@ qemuDomainDefineXMLFlags(virConnectPtr conn,
} else { } else {
/* Brand new domain. Remove it */ /* Brand new domain. Remove it */
VIR_INFO("Deleting domain '%s'", vm->def->name); VIR_INFO("Deleting domain '%s'", vm->def->name);
qemuDomainRemoveInactiveJob(driver, vm); qemuDomainRemoveInactive(driver, vm);
} }
} }

View File

@ -3100,7 +3100,7 @@ qemuMigrationDstPrepareAny(virQEMUDriver *driver,
virPortAllocatorRelease(priv->nbdPort); virPortAllocatorRelease(priv->nbdPort);
priv->nbdPort = 0; priv->nbdPort = 0;
virDomainObjRemoveTransientDef(vm); virDomainObjRemoveTransientDef(vm);
qemuDomainRemoveInactiveJob(driver, vm); qemuDomainRemoveInactive(driver, vm);
} }
virDomainObjEndAPI(&vm); virDomainObjEndAPI(&vm);
virObjectEventStateQueue(driver->domainEventState, event); virObjectEventStateQueue(driver->domainEventState, event);
@ -3517,7 +3517,7 @@ qemuMigrationSrcConfirm(virQEMUDriver *driver,
virDomainDeleteConfig(cfg->configDir, cfg->autostartDir, vm); virDomainDeleteConfig(cfg->configDir, cfg->autostartDir, vm);
vm->persistent = 0; vm->persistent = 0;
} }
qemuDomainRemoveInactiveJob(driver, vm); qemuDomainRemoveInactive(driver, vm);
} }
cleanup: cleanup:
@ -5342,7 +5342,7 @@ qemuMigrationSrcPerformJob(virQEMUDriver *driver,
virDomainDeleteConfig(cfg->configDir, cfg->autostartDir, vm); virDomainDeleteConfig(cfg->configDir, cfg->autostartDir, vm);
vm->persistent = 0; vm->persistent = 0;
} }
qemuDomainRemoveInactiveJob(driver, vm); qemuDomainRemoveInactive(driver, vm);
} }
virErrorRestore(&orig_err); virErrorRestore(&orig_err);
@ -5416,7 +5416,7 @@ qemuMigrationSrcPerformPhase(virQEMUDriver *driver,
} }
if (!virDomainObjIsActive(vm)) if (!virDomainObjIsActive(vm))
qemuDomainRemoveInactiveJob(driver, vm); qemuDomainRemoveInactive(driver, vm);
return ret; return ret;
} }
@ -5877,7 +5877,7 @@ qemuMigrationDstFinish(virQEMUDriver *driver,
qemuMigrationJobFinish(vm); qemuMigrationJobFinish(vm);
if (!virDomainObjIsActive(vm)) if (!virDomainObjIsActive(vm))
qemuDomainRemoveInactiveJob(driver, vm); qemuDomainRemoveInactive(driver, vm);
cleanup: cleanup:
g_clear_pointer(&jobData, virDomainJobDataFree); g_clear_pointer(&jobData, virDomainJobDataFree);

View File

@ -8973,14 +8973,10 @@ qemuProcessReconnect(void *opaque)
driver->inhibitCallback(true, driver->inhibitOpaque); driver->inhibitCallback(true, driver->inhibitOpaque);
cleanup: cleanup:
if (jobStarted) { if (jobStarted)
if (!virDomainObjIsActive(obj))
qemuDomainRemoveInactive(driver, obj);
qemuDomainObjEndJob(obj); qemuDomainObjEndJob(obj);
} else { if (!virDomainObjIsActive(obj))
if (!virDomainObjIsActive(obj)) qemuDomainRemoveInactive(driver, obj);
qemuDomainRemoveInactiveJob(driver, obj);
}
virDomainObjEndAPI(&obj); virDomainObjEndAPI(&obj);
virIdentitySetCurrent(NULL); virIdentitySetCurrent(NULL);
return; return;
@ -9052,7 +9048,7 @@ qemuProcessReconnectHelper(virDomainObj *obj,
*/ */
qemuProcessStop(src->driver, obj, VIR_DOMAIN_SHUTOFF_FAILED, qemuProcessStop(src->driver, obj, VIR_DOMAIN_SHUTOFF_FAILED,
VIR_ASYNC_JOB_NONE, 0); VIR_ASYNC_JOB_NONE, 0);
qemuDomainRemoveInactiveJobLocked(src->driver, obj); qemuDomainRemoveInactiveLocked(src->driver, obj);
virDomainObjEndAPI(&obj); virDomainObjEndAPI(&obj);
g_clear_object(&data->identity); g_clear_object(&data->identity);