qemu & conf: move BeginAsyncJob & EndAsyncJob into src/conf

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Kristina Hanicova 2022-09-05 15:57:14 +02:00 committed by Ján Tomko
parent 421f1e749f
commit 4435c026b7
12 changed files with 63 additions and 60 deletions

View File

@ -141,7 +141,7 @@ To acquire the agent job condition
To acquire the asynchronous job condition
``qemuDomainObjBeginAsyncJob()``
``virDomainObjBeginAsyncJob()``
- Waits until no async job is running
- Waits for ``job.cond`` condition ``job.active != 0`` using ``virDomainObj``
mutex
@ -149,7 +149,7 @@ To acquire the asynchronous job condition
and repeats waiting in that case
- Sets ``job.asyncJob`` to the asynchronous job type
``qemuDomainObjEndAsyncJob()``
``virDomainObjEndAsyncJob()``
- Sets ``job.asyncJob`` to 0
- Broadcasts on ``job.asyncCond`` condition
@ -277,7 +277,7 @@ Design patterns
obj = qemuDomObjFromDomain(dom);
qemuDomainObjBeginAsyncJob(obj, VIR_ASYNC_JOB_TYPE);
virDomainObjBeginAsyncJob(obj, VIR_ASYNC_JOB_TYPE);
qemuDomainObjSetAsyncJobMask(obj, allowedJobs);
...do prep work...
@ -306,7 +306,7 @@ Design patterns
...do final work...
qemuDomainObjEndAsyncJob(obj);
virDomainObjEndAsyncJob(obj);
virDomainObjEndAPI(&obj);
@ -317,7 +317,7 @@ Design patterns
obj = qemuDomObjFromDomain(dom);
qemuDomainObjBeginAsyncJob(obj, VIR_ASYNC_JOB_TYPE);
virDomainObjBeginAsyncJob(obj, VIR_ASYNC_JOB_TYPE);
...do prep work...
@ -334,5 +334,5 @@ Design patterns
...do final work...
qemuDomainObjEndAsyncJob(obj);
virDomainObjEndAsyncJob(obj);
virDomainObjEndAPI(&obj);

View File

@ -544,6 +544,21 @@ virDomainObjBeginAgentJob(virDomainObj *obj,
VIR_ASYNC_JOB_NONE, false);
}
int virDomainObjBeginAsyncJob(virDomainObj *obj,
virDomainAsyncJob asyncJob,
virDomainJobOperation operation,
unsigned long apiFlags)
{
if (virDomainObjBeginJobInternal(obj, obj->job, VIR_JOB_ASYNC,
VIR_AGENT_JOB_NONE,
asyncJob, false) < 0)
return -1;
obj->job->current->operation = operation;
obj->job->apiFlags = apiFlags;
return 0;
}
/*
* obj must be locked and have a reference before calling
*
@ -589,3 +604,18 @@ virDomainObjEndAgentJob(virDomainObj *obj)
* grabbing a job requires checking more variables. */
virCondBroadcast(&obj->job->cond);
}
void
virDomainObjEndAsyncJob(virDomainObj *obj)
{
obj->job->jobsQueued--;
VIR_DEBUG("Stopping async job: %s (vm=%p name=%s)",
virDomainAsyncJobTypeToString(obj->job->asyncJob),
obj, obj->def->name);
virDomainObjResetAsyncJob(obj->job);
if (obj->job->cb->saveStatusPrivate)
obj->job->cb->saveStatusPrivate(obj);
virCondBroadcast(&obj->job->asyncCond);
}

View File

@ -252,6 +252,12 @@ int virDomainObjBeginJob(virDomainObj *obj,
int virDomainObjBeginAgentJob(virDomainObj *obj,
virDomainAgentJob agentJob)
G_GNUC_WARN_UNUSED_RESULT;
int virDomainObjBeginAsyncJob(virDomainObj *obj,
virDomainAsyncJob asyncJob,
virDomainJobOperation operation,
unsigned long apiFlags)
G_GNUC_WARN_UNUSED_RESULT;
void virDomainObjEndJob(virDomainObj *obj);
void virDomainObjEndAgentJob(virDomainObj *obj);
void virDomainObjEndAsyncJob(virDomainObj *obj);

View File

@ -1188,11 +1188,13 @@ virDomainJobTypeFromString;
virDomainJobTypeToString;
virDomainNestedJobAllowed;
virDomainObjBeginAgentJob;
virDomainObjBeginAsyncJob;
virDomainObjBeginJob;
virDomainObjBeginJobInternal;
virDomainObjCanSetJob;
virDomainObjClearJob;
virDomainObjEndAgentJob;
virDomainObjEndAsyncJob;
virDomainObjEndJob;
virDomainObjInitJob;
virDomainObjPreserveJob;

View File

@ -618,7 +618,7 @@ qemuBackupJobTerminate(virDomainObj *vm,
g_clear_pointer(&priv->backup, virDomainBackupDefFree);
if (vm->job->asyncJob == VIR_ASYNC_JOB_BACKUP)
qemuDomainObjEndAsyncJob(vm);
virDomainObjEndAsyncJob(vm);
}
@ -786,7 +786,7 @@ qemuBackupBegin(virDomainObj *vm,
* infrastructure for async jobs. We'll allow standard modify-type jobs
* as the interlocking of conflicting operations is handled on the block
* job level */
if (qemuDomainObjBeginAsyncJob(vm, VIR_ASYNC_JOB_BACKUP,
if (virDomainObjBeginAsyncJob(vm, VIR_ASYNC_JOB_BACKUP,
VIR_DOMAIN_JOB_OPERATION_BACKUP, flags) < 0)
return -1;
@ -937,7 +937,7 @@ qemuBackupBegin(virDomainObj *vm,
if (ret == 0)
qemuDomainObjReleaseAsyncJob(vm);
else
qemuDomainObjEndAsyncJob(vm);
virDomainObjEndAsyncJob(vm);
return ret;
}

View File

@ -6037,7 +6037,7 @@ void qemuDomainObjEnterMonitor(virDomainObj *obj)
* To be called immediately before any QEMU monitor API call.
* Must have already either called virDomainObjBeginJob()
* and checked that the VM is still active, with asyncJob of
* VIR_ASYNC_JOB_NONE; or already called qemuDomainObjBeginAsyncJob,
* VIR_ASYNC_JOB_NONE; or already called virDomainObjBeginAsyncJob,
* with the same asyncJob.
*
* Returns 0 if job was started, in which case this must be followed with

View File

@ -655,21 +655,6 @@ qemuDomainObjReleaseAsyncJob(virDomainObj *obj)
obj->job->asyncOwner = 0;
}
int qemuDomainObjBeginAsyncJob(virDomainObj *obj,
virDomainAsyncJob asyncJob,
virDomainJobOperation operation,
unsigned long apiFlags)
{
if (virDomainObjBeginJobInternal(obj, obj->job, VIR_JOB_ASYNC,
VIR_AGENT_JOB_NONE,
asyncJob, false) < 0)
return -1;
obj->job->current->operation = operation;
obj->job->apiFlags = apiFlags;
return 0;
}
int
qemuDomainObjBeginNestedJob(virDomainObj *obj,
virDomainAsyncJob asyncJob)
@ -714,20 +699,6 @@ qemuDomainObjBeginJobNowait(virDomainObj *obj,
VIR_ASYNC_JOB_NONE, true);
}
void
qemuDomainObjEndAsyncJob(virDomainObj *obj)
{
obj->job->jobsQueued--;
VIR_DEBUG("Stopping async job: %s (vm=%p name=%s)",
virDomainAsyncJobTypeToString(obj->job->asyncJob),
obj, obj->def->name);
virDomainObjResetAsyncJob(obj->job);
qemuDomainSaveStatus(obj);
virCondBroadcast(&obj->job->asyncCond);
}
void
qemuDomainObjAbortAsyncJob(virDomainObj *obj)
{

View File

@ -69,11 +69,6 @@ int qemuDomainAsyncJobPhaseFromString(virDomainAsyncJob job,
void qemuDomainEventEmitJobCompleted(virQEMUDriver *driver,
virDomainObj *vm);
int qemuDomainObjBeginAsyncJob(virDomainObj *obj,
virDomainAsyncJob asyncJob,
virDomainJobOperation operation,
unsigned long apiFlags)
G_GNUC_WARN_UNUSED_RESULT;
int qemuDomainObjBeginNestedJob(virDomainObj *obj,
virDomainAsyncJob asyncJob)
G_GNUC_WARN_UNUSED_RESULT;
@ -81,7 +76,6 @@ int qemuDomainObjBeginJobNowait(virDomainObj *obj,
virDomainJob job)
G_GNUC_WARN_UNUSED_RESULT;
void qemuDomainObjEndAsyncJob(virDomainObj *obj);
void qemuDomainObjAbortAsyncJob(virDomainObj *obj);
void qemuDomainObjSetJobPhase(virDomainObj *obj,
int phase);

View File

@ -2637,8 +2637,8 @@ qemuDomainSaveInternal(virQEMUDriver *driver,
virQEMUSaveData *data = NULL;
g_autoptr(qemuDomainSaveCookie) cookie = NULL;
if (qemuDomainObjBeginAsyncJob(vm, VIR_ASYNC_JOB_SAVE,
VIR_DOMAIN_JOB_OPERATION_SAVE, flags) < 0)
if (virDomainObjBeginAsyncJob(vm, VIR_ASYNC_JOB_SAVE,
VIR_DOMAIN_JOB_OPERATION_SAVE, flags) < 0)
goto cleanup;
if (!qemuMigrationSrcIsAllowed(driver, vm, false, VIR_ASYNC_JOB_SAVE, 0))
@ -2735,7 +2735,7 @@ qemuDomainSaveInternal(virQEMUDriver *driver,
virErrorRestore(&save_err);
}
}
qemuDomainObjEndAsyncJob(vm);
virDomainObjEndAsyncJob(vm);
if (ret == 0)
qemuDomainRemoveInactive(driver, vm);
@ -3209,7 +3209,7 @@ qemuDomainCoreDumpWithFormat(virDomainPtr dom,
if (virDomainCoreDumpWithFormatEnsureACL(dom->conn, vm->def) < 0)
goto cleanup;
if (qemuDomainObjBeginAsyncJob(vm, VIR_ASYNC_JOB_DUMP,
if (virDomainObjBeginAsyncJob(vm, VIR_ASYNC_JOB_DUMP,
VIR_DOMAIN_JOB_OPERATION_DUMP,
flags) < 0)
goto cleanup;
@ -3275,7 +3275,7 @@ qemuDomainCoreDumpWithFormat(virDomainPtr dom,
}
}
qemuDomainObjEndAsyncJob(vm);
virDomainObjEndAsyncJob(vm);
if (ret == 0 && flags & VIR_DUMP_CRASH)
qemuDomainRemoveInactive(driver, vm);
@ -3447,7 +3447,7 @@ processWatchdogEvent(virQEMUDriver *driver,
switch (action) {
case VIR_DOMAIN_WATCHDOG_ACTION_DUMP:
if (qemuDomainObjBeginAsyncJob(vm, VIR_ASYNC_JOB_DUMP,
if (virDomainObjBeginAsyncJob(vm, VIR_ASYNC_JOB_DUMP,
VIR_DOMAIN_JOB_OPERATION_DUMP,
flags) < 0) {
return;
@ -3475,7 +3475,7 @@ processWatchdogEvent(virQEMUDriver *driver,
}
endjob:
qemuDomainObjEndAsyncJob(vm);
virDomainObjEndAsyncJob(vm);
}
static int
@ -3523,7 +3523,7 @@ processGuestPanicEvent(virQEMUDriver *driver,
bool removeInactive = false;
unsigned long flags = VIR_DUMP_MEMORY_ONLY;
if (qemuDomainObjBeginAsyncJob(vm, VIR_ASYNC_JOB_DUMP,
if (virDomainObjBeginAsyncJob(vm, VIR_ASYNC_JOB_DUMP,
VIR_DOMAIN_JOB_OPERATION_DUMP, flags) < 0)
return;
@ -3587,7 +3587,7 @@ processGuestPanicEvent(virQEMUDriver *driver,
}
endjob:
qemuDomainObjEndAsyncJob(vm);
virDomainObjEndAsyncJob(vm);
if (removeInactive)
qemuDomainRemoveInactive(driver, vm);
}

View File

@ -120,7 +120,7 @@ qemuMigrationJobStart(virDomainObj *vm,
}
mask |= JOB_MASK(VIR_JOB_MODIFY_MIGRATION_SAFE);
if (qemuDomainObjBeginAsyncJob(vm, job, op, apiFlags) < 0)
if (virDomainObjBeginAsyncJob(vm, job, op, apiFlags) < 0)
return -1;
qemuDomainJobSetStatsType(vm->job->current,
@ -203,7 +203,7 @@ qemuMigrationJobIsActive(virDomainObj *vm,
static void ATTRIBUTE_NONNULL(1)
qemuMigrationJobFinish(virDomainObj *vm)
{
qemuDomainObjEndAsyncJob(vm);
virDomainObjEndAsyncJob(vm);
}

View File

@ -4675,7 +4675,7 @@ qemuProcessBeginJob(virDomainObj *vm,
virDomainJobOperation operation,
unsigned long apiFlags)
{
if (qemuDomainObjBeginAsyncJob(vm, VIR_ASYNC_JOB_START,
if (virDomainObjBeginAsyncJob(vm, VIR_ASYNC_JOB_START,
operation, apiFlags) < 0)
return -1;
@ -4687,7 +4687,7 @@ qemuProcessBeginJob(virDomainObj *vm,
void
qemuProcessEndJob(virDomainObj *vm)
{
qemuDomainObjEndAsyncJob(vm);
virDomainObjEndAsyncJob(vm);
}

View File

@ -1794,7 +1794,7 @@ qemuSnapshotCreateXML(virDomainPtr domain,
* a regular job, so we need to set the job mask to disallow query as
* 'savevm' blocks the monitor. External snapshot will then modify the
* job mask appropriately. */
if (qemuDomainObjBeginAsyncJob(vm, VIR_ASYNC_JOB_SNAPSHOT,
if (virDomainObjBeginAsyncJob(vm, VIR_ASYNC_JOB_SNAPSHOT,
VIR_DOMAIN_JOB_OPERATION_SNAPSHOT, flags) < 0)
return NULL;
@ -1806,7 +1806,7 @@ qemuSnapshotCreateXML(virDomainPtr domain,
snapshot = qemuSnapshotCreate(vm, domain, def, driver, cfg, flags);
}
qemuDomainObjEndAsyncJob(vm);
virDomainObjEndAsyncJob(vm);
return snapshot;
}