qemu: Refactor qemuDomainObjSetJobPhase

We will want to update migration phase without affecting job ownership.
Either in the thread that already owns the job or from an event handler
which only changes the phase (of a job no-one owns) without assuming it.

Let's move the ownership change to a new qemuDomainObjStartJobPhase
helper and let qemuDomainObjSetJobPhase set the phase without touching
ownership.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
Jiri Denemark 2022-05-10 15:20:25 +02:00
parent 69d9f54c66
commit 2b163ca301
3 changed files with 46 additions and 7 deletions

View File

@ -717,6 +717,10 @@ qemuDomainJobDataToParams(virDomainJobData *jobData,
}
/*
* Sets the job phase without changing the job owner. The owner is supposed to
* be 0 or the current thread, a warning is issued otherwise.
*/
void
qemuDomainObjSetJobPhase(virDomainObj *obj,
int phase)
@ -731,19 +735,51 @@ qemuDomainObjSetJobPhase(virDomainObj *obj,
virDomainAsyncJobTypeToString(priv->job.asyncJob),
qemuDomainAsyncJobPhaseToString(priv->job.asyncJob, phase));
if (priv->job.asyncOwner == 0) {
priv->job.asyncOwnerAPI = g_strdup(virThreadJobGet());
} else if (me != priv->job.asyncOwner) {
VIR_WARN("'%s' async job is owned by thread %llu",
if (priv->job.asyncOwner != 0 &&
priv->job.asyncOwner != me) {
VIR_WARN("'%s' async job is owned by thread %llu, API '%s'",
virDomainAsyncJobTypeToString(priv->job.asyncJob),
priv->job.asyncOwner);
priv->job.asyncOwner,
NULLSTR(priv->job.asyncOwnerAPI));
}
priv->job.phase = phase;
priv->job.asyncOwner = me;
qemuDomainSaveStatus(obj);
}
/*
* Changes the job owner and sets the job phase. The current owner is supposed
* to be 0 or the current thread, a warning is issued otherwise.
*/
void
qemuDomainObjStartJobPhase(virDomainObj *obj,
int phase)
{
qemuDomainObjPrivate *priv = obj->privateData;
unsigned long long me = virThreadSelfID();
if (!priv->job.asyncJob)
return;
VIR_DEBUG("Starting phase '%s' of '%s' job",
qemuDomainAsyncJobPhaseToString(priv->job.asyncJob, phase),
virDomainAsyncJobTypeToString(priv->job.asyncJob));
if (priv->job.asyncOwner == 0) {
priv->job.asyncOwnerAPI = g_strdup(virThreadJobGet());
} else if (me != priv->job.asyncOwner) {
VIR_WARN("'%s' async job is owned by thread %llu, API '%s'",
virDomainAsyncJobTypeToString(priv->job.asyncJob),
priv->job.asyncOwner,
NULLSTR(priv->job.asyncOwnerAPI));
}
priv->job.asyncOwner = me;
qemuDomainObjSetJobPhase(obj, phase);
}
void
qemuDomainObjSetAsyncJobMask(virDomainObj *obj,
unsigned long long allowedJobs)

View File

@ -156,6 +156,9 @@ void qemuDomainObjEndAsyncJob(virDomainObj *obj);
void qemuDomainObjAbortAsyncJob(virDomainObj *obj);
void qemuDomainObjSetJobPhase(virDomainObj *obj,
int phase);
void
qemuDomainObjStartJobPhase(virDomainObj *obj,
int phase);
void qemuDomainObjSetAsyncJobMask(virDomainObj *obj,
unsigned long long allowedJobs);
int qemuDomainObjPreserveJob(virDomainObj *obj,

View File

@ -165,7 +165,7 @@ qemuMigrationJobSetPhase(virDomainObj *vm,
if (qemuMigrationCheckPhase(vm, phase) < 0)
return -1;
qemuDomainObjSetJobPhase(vm, phase);
qemuDomainObjStartJobPhase(vm, phase);
return 0;
}