qemu: Add qemuDomainObjRestoreAsyncJob

The code for setting up a previously active backup job in
qemuProcessRecoverJob is generalized into a dedicated function so that
it can be later reused in other places.

Signed-off-by: Jiri Denemark <jdenemar@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 d6d1c4980d
commit 6637880b3c
3 changed files with 50 additions and 22 deletions

View File

@ -249,6 +249,41 @@ qemuDomainObjPreserveJob(virDomainObj *obj,
return 0;
}
void
qemuDomainObjRestoreAsyncJob(virDomainObj *vm,
virDomainAsyncJob asyncJob,
int phase,
virDomainJobOperation operation,
qemuDomainJobStatsType statsType,
virDomainJobStatus status,
unsigned long long allowedJobs)
{
qemuDomainObjPrivate *priv = vm->privateData;
qemuDomainJobObj *job = &priv->job;
unsigned long long now;
VIR_DEBUG("Restoring %s async job for domain %s",
virDomainAsyncJobTypeToString(asyncJob), vm->def->name);
ignore_value(virTimeMillisNow(&now));
job->jobsQueued++;
job->asyncJob = asyncJob;
job->phase = phase;
job->asyncOwnerAPI = g_strdup(virThreadJobGet());
job->asyncStarted = now;
qemuDomainObjSetAsyncJobMask(vm, allowedJobs);
job->current = virDomainJobDataInit(&qemuJobDataPrivateDataCallbacks);
qemuDomainJobSetStatsType(priv->job.current, statsType);
job->current->operation = operation;
job->current->status = status;
job->current->started = now;
}
void
qemuDomainObjClearJob(qemuDomainJobObj *job)
{

View File

@ -160,6 +160,14 @@ void qemuDomainObjSetAsyncJobMask(virDomainObj *obj,
unsigned long long allowedJobs);
int qemuDomainObjPreserveJob(virDomainObj *obj,
qemuDomainJobObj *job);
void
qemuDomainObjRestoreAsyncJob(virDomainObj *vm,
virDomainAsyncJob asyncJob,
int phase,
virDomainJobOperation operation,
qemuDomainJobStatsType statsType,
virDomainJobStatus status,
unsigned long long allowedJobs);
void qemuDomainObjDiscardAsyncJob(virDomainObj *obj);
void qemuDomainObjReleaseAsyncJob(virDomainObj *obj);

View File

@ -3557,7 +3557,6 @@ qemuProcessRecoverJob(virQEMUDriver *driver,
qemuDomainObjPrivate *priv = vm->privateData;
virDomainState state;
int reason;
unsigned long long now;
state = virDomainObjGetState(vm, &reason);
@ -3614,28 +3613,14 @@ qemuProcessRecoverJob(virQEMUDriver *driver,
break;
case VIR_ASYNC_JOB_BACKUP:
ignore_value(virTimeMillisNow(&now));
/* Restore the config of the async job which is not persisted */
priv->job.jobsQueued++;
priv->job.asyncJob = VIR_ASYNC_JOB_BACKUP;
priv->job.asyncOwnerAPI = g_strdup(virThreadJobGet());
priv->job.asyncStarted = now;
qemuDomainObjSetAsyncJobMask(vm, (VIR_JOB_DEFAULT_MASK |
qemuDomainObjRestoreAsyncJob(vm, VIR_ASYNC_JOB_BACKUP, 0,
VIR_DOMAIN_JOB_OPERATION_BACKUP,
QEMU_DOMAIN_JOB_STATS_TYPE_BACKUP,
VIR_DOMAIN_JOB_STATUS_ACTIVE,
(VIR_JOB_DEFAULT_MASK |
JOB_MASK(VIR_JOB_SUSPEND) |
JOB_MASK(VIR_JOB_MODIFY)));
/* We reset the job parameters for backup so that the job will look
* active. This is possible because we are able to recover the state
* of blockjobs and also the backup job allows all sub-job types */
priv->job.current = virDomainJobDataInit(&qemuJobDataPrivateDataCallbacks);
qemuDomainJobSetStatsType(priv->job.current,
QEMU_DOMAIN_JOB_STATS_TYPE_BACKUP);
priv->job.current->operation = VIR_DOMAIN_JOB_OPERATION_BACKUP;
priv->job.current->status = VIR_DOMAIN_JOB_STATUS_ACTIVE;
priv->job.current->started = now;
break;
case VIR_ASYNC_JOB_NONE: