qemu: Make sure qemuProcessStart is run within a job

qemuProcessStart expects to be run with a job already set and every
caller except for qemuMigrationPrepareAny use it correctly. This bug can
be observed in libvirtd logs during incoming migration as

    warning : qemuDomainObjEnterMonitorInternal:979 : This thread seems
    to be the async job owner; entering monitor without asking for a
    nested job is dangerous
This commit is contained in:
Jiri Denemark 2013-02-28 12:48:01 +01:00
parent 438a3850db
commit e4e28220b5
3 changed files with 35 additions and 15 deletions

View File

@ -881,6 +881,29 @@ int qemuDomainObjBeginAsyncJob(virQEMUDriverPtr driver,
asyncJob); asyncJob);
} }
int
qemuDomainObjBeginNestedJob(virQEMUDriverPtr driver,
virDomainObjPtr obj,
enum qemuDomainAsyncJob asyncJob)
{
qemuDomainObjPrivatePtr priv = obj->privateData;
if (asyncJob != priv->job.asyncJob) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected async job %d"), asyncJob);
return -1;
}
if (priv->job.asyncOwner != virThreadSelfID()) {
VIR_WARN("This thread doesn't seem to be the async job owner: %d",
priv->job.asyncOwner);
}
return qemuDomainObjBeginJobInternal(driver, obj,
QEMU_JOB_ASYNC_NESTED,
QEMU_ASYNC_JOB_NONE);
}
/* /*
* obj must be locked before calling * obj must be locked before calling
@ -955,17 +978,7 @@ qemuDomainObjEnterMonitorInternal(virQEMUDriverPtr driver,
qemuDomainObjPrivatePtr priv = obj->privateData; qemuDomainObjPrivatePtr priv = obj->privateData;
if (asyncJob != QEMU_ASYNC_JOB_NONE) { if (asyncJob != QEMU_ASYNC_JOB_NONE) {
if (asyncJob != priv->job.asyncJob) { if (qemuDomainObjBeginNestedJob(driver, obj, asyncJob) < 0)
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected async job %d"), asyncJob);
return -1;
}
if (priv->job.asyncOwner != virThreadSelfID())
VIR_WARN("This thread doesn't seem to be the async job owner: %d",
priv->job.asyncOwner);
if (qemuDomainObjBeginJobInternal(driver, obj,
QEMU_JOB_ASYNC_NESTED,
QEMU_ASYNC_JOB_NONE) < 0)
return -1; return -1;
if (!virDomainObjIsActive(obj)) { if (!virDomainObjIsActive(obj)) {
virReportError(VIR_ERR_OPERATION_FAILED, "%s", virReportError(VIR_ERR_OPERATION_FAILED, "%s",

View File

@ -192,6 +192,10 @@ int qemuDomainObjBeginAsyncJob(virQEMUDriverPtr driver,
virDomainObjPtr obj, virDomainObjPtr obj,
enum qemuDomainAsyncJob asyncJob) enum qemuDomainAsyncJob asyncJob)
ATTRIBUTE_RETURN_CHECK; ATTRIBUTE_RETURN_CHECK;
int qemuDomainObjBeginNestedJob(virQEMUDriverPtr driver,
virDomainObjPtr obj,
enum qemuDomainAsyncJob asyncJob)
ATTRIBUTE_RETURN_CHECK;
bool qemuDomainObjEndJob(virQEMUDriverPtr driver, bool qemuDomainObjEndJob(virQEMUDriverPtr driver,
virDomainObjPtr obj) virDomainObjPtr obj)

View File

@ -2118,6 +2118,10 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
goto endjob; goto endjob;
} }
if (qemuDomainObjBeginNestedJob(driver, vm,
QEMU_ASYNC_JOB_MIGRATION_IN) < 0)
goto endjob;
/* Start the QEMU daemon, with the same command-line arguments plus /* Start the QEMU daemon, with the same command-line arguments plus
* -incoming $migrateFrom * -incoming $migrateFrom
*/ */
@ -2126,9 +2130,8 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
VIR_QEMU_PROCESS_START_PAUSED | VIR_QEMU_PROCESS_START_PAUSED |
VIR_QEMU_PROCESS_START_AUTODESTROY) < 0) { VIR_QEMU_PROCESS_START_AUTODESTROY) < 0) {
virDomainAuditStart(vm, "migrated", false); virDomainAuditStart(vm, "migrated", false);
/* Note that we don't set an error here because qemuProcessStart if (qemuDomainObjEndJob(driver, vm) < 0)
* should have already done that. vm = NULL;
*/
goto endjob; goto endjob;
} }
@ -2235,7 +2238,7 @@ stop:
qemuProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_FAILED, 0); qemuProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_FAILED, 0);
endjob: endjob:
if (!qemuMigrationJobFinish(driver, vm)) { if (vm && !qemuMigrationJobFinish(driver, vm)) {
vm = NULL; vm = NULL;
} }
goto cleanup; goto cleanup;