mirror of https://gitee.com/openkylin/libvirt.git
qemu: blockjob: Record job type when starting the job
We can properly track the job type when starting the job so that we don't have to infer it later. This patch also adds an enum of block job types specific to qemu (qemuBlockjobType) which mirrors the public block job types (virDomainBlockJobType) but allows for other types to be added later which will not be public. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
f877ec1020
commit
79b73251fb
|
@ -96,12 +96,16 @@ qemuBlockJobDataReset(qemuBlockJobDataPtr job)
|
|||
* Returns 0 on success and -1 on failure.
|
||||
*/
|
||||
qemuBlockJobDataPtr
|
||||
qemuBlockJobDiskNew(virDomainDiskDefPtr disk)
|
||||
qemuBlockJobDiskNew(virDomainDiskDefPtr disk,
|
||||
qemuBlockJobType type)
|
||||
{
|
||||
qemuBlockJobDataPtr job = QEMU_DOMAIN_DISK_PRIVATE(disk)->blockjob;
|
||||
job->disk = disk;
|
||||
|
||||
qemuBlockJobDataReset(job);
|
||||
|
||||
job->type = type;
|
||||
|
||||
return virObjectRef(job);
|
||||
}
|
||||
|
||||
|
@ -279,10 +283,6 @@ qemuBlockJobEventProcessLegacy(virQEMUDriverPtr driver,
|
|||
type,
|
||||
status);
|
||||
|
||||
if (type == VIR_DOMAIN_BLOCK_JOB_TYPE_COMMIT &&
|
||||
disk->mirrorJob == VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT)
|
||||
type = disk->mirrorJob;
|
||||
|
||||
qemuBlockJobEmitEvents(driver, vm, disk, type, status);
|
||||
|
||||
/* If we completed a block pull or commit, then update the XML
|
||||
|
|
|
@ -25,6 +25,21 @@
|
|||
# include "internal.h"
|
||||
# include "qemu_conf.h"
|
||||
|
||||
/**
|
||||
* This enum has to map all known block job types from enum virDomainBlockJobType
|
||||
* to the same values. All internal blockjobs can be mapped after and don't
|
||||
* need to have stable values.
|
||||
*/
|
||||
typedef enum {
|
||||
QEMU_BLOCKJOB_TYPE_NONE = VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN,
|
||||
QEMU_BLOCKJOB_TYPE_PULL = VIR_DOMAIN_BLOCK_JOB_TYPE_PULL,
|
||||
QEMU_BLOCKJOB_TYPE_COPY = VIR_DOMAIN_BLOCK_JOB_TYPE_COPY,
|
||||
QEMU_BLOCKJOB_TYPE_COMMIT = VIR_DOMAIN_BLOCK_JOB_TYPE_COMMIT,
|
||||
QEMU_BLOCKJOB_TYPE_ACTIVE_COMMIT = VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT,
|
||||
QEMU_BLOCKJOB_TYPE_INTERNAL,
|
||||
QEMU_BLOCKJOB_TYPE_LAST
|
||||
} qemuBlockJobType;
|
||||
verify((int)QEMU_BLOCKJOB_TYPE_INTERNAL == VIR_DOMAIN_BLOCK_JOB_TYPE_LAST);
|
||||
|
||||
typedef struct _qemuBlockJobData qemuBlockJobData;
|
||||
typedef qemuBlockJobData *qemuBlockJobDataPtr;
|
||||
|
@ -35,7 +50,7 @@ struct _qemuBlockJobData {
|
|||
virDomainDiskDefPtr disk; /* may be NULL, if blockjob does not correspond to any disk */
|
||||
|
||||
bool started;
|
||||
int type;
|
||||
int type; /* qemuBlockJobType */
|
||||
char *errmsg;
|
||||
bool synchronous; /* API call is waiting for this job */
|
||||
|
||||
|
@ -45,7 +60,8 @@ struct _qemuBlockJobData {
|
|||
qemuBlockJobDataPtr qemuBlockJobDataNew(void);
|
||||
|
||||
qemuBlockJobDataPtr
|
||||
qemuBlockJobDiskNew(virDomainDiskDefPtr disk)
|
||||
qemuBlockJobDiskNew(virDomainDiskDefPtr disk,
|
||||
qemuBlockJobType type)
|
||||
ATTRIBUTE_NONNULL(1);
|
||||
|
||||
qemuBlockJobDataPtr
|
||||
|
|
|
@ -4733,12 +4733,11 @@ processBlockJobEvent(virQEMUDriverPtr driver,
|
|||
}
|
||||
|
||||
if (!(job = qemuBlockJobDiskGetJob(disk))) {
|
||||
if (!(job = qemuBlockJobDiskNew(disk)))
|
||||
if (!(job = qemuBlockJobDiskNew(disk, type)))
|
||||
goto endjob;
|
||||
qemuBlockJobStarted(job);
|
||||
}
|
||||
|
||||
job->type = type;
|
||||
job->newstate = status;
|
||||
|
||||
qemuBlockJobUpdateDisk(vm, QEMU_ASYNC_JOB_NONE, disk, NULL);
|
||||
|
@ -17317,7 +17316,7 @@ qemuDomainBlockPullCommon(virQEMUDriverPtr driver,
|
|||
speed <<= 20;
|
||||
}
|
||||
|
||||
if (!(job = qemuBlockJobDiskNew(disk)))
|
||||
if (!(job = qemuBlockJobDiskNew(disk, QEMU_BLOCKJOB_TYPE_PULL)))
|
||||
goto endjob;
|
||||
|
||||
qemuDomainObjEnterMonitor(driver, vm);
|
||||
|
@ -17845,7 +17844,7 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
|
|||
goto endjob;
|
||||
}
|
||||
|
||||
if (!(job = qemuBlockJobDiskNew(disk)))
|
||||
if (!(job = qemuBlockJobDiskNew(disk, QEMU_BLOCKJOB_TYPE_COPY)))
|
||||
goto endjob;
|
||||
|
||||
/* Actually start the mirroring */
|
||||
|
@ -18096,6 +18095,7 @@ qemuDomainBlockCommit(virDomainPtr dom,
|
|||
virStorageSourcePtr mirror = NULL;
|
||||
unsigned long long speed = bandwidth;
|
||||
qemuBlockJobDataPtr job = NULL;
|
||||
qemuBlockJobType jobtype = QEMU_BLOCKJOB_TYPE_COMMIT;
|
||||
|
||||
/* XXX Add support for COMMIT_DELETE */
|
||||
virCheckFlags(VIR_DOMAIN_BLOCK_COMMIT_SHALLOW |
|
||||
|
@ -18255,9 +18255,10 @@ qemuDomainBlockCommit(virDomainPtr dom,
|
|||
disk->mirrorState = VIR_DOMAIN_DISK_MIRROR_STATE_NONE;
|
||||
disk->mirror = mirror;
|
||||
disk->mirrorJob = VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT;
|
||||
jobtype = QEMU_BLOCKJOB_TYPE_ACTIVE_COMMIT;
|
||||
}
|
||||
|
||||
if (!(job = qemuBlockJobDiskNew(disk)))
|
||||
if (!(job = qemuBlockJobDiskNew(disk, jobtype)))
|
||||
goto endjob;
|
||||
|
||||
qemuDomainObjEnterMonitor(driver, vm);
|
||||
|
|
|
@ -908,7 +908,7 @@ qemuMigrationSrcNBDStorageCopyOne(virQEMUDriverPtr driver,
|
|||
if (!(diskAlias = qemuAliasDiskDriveFromDisk(disk)))
|
||||
goto cleanup;
|
||||
|
||||
if (!(job = qemuBlockJobDiskNew(disk)))
|
||||
if (!(job = qemuBlockJobDiskNew(disk, QEMU_BLOCKJOB_TYPE_COPY)))
|
||||
goto cleanup;
|
||||
|
||||
qemuBlockJobSyncBeginDisk(disk);
|
||||
|
|
|
@ -942,7 +942,6 @@ qemuProcessHandleBlockJob(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
|
|||
|
||||
if (job && job->synchronous) {
|
||||
/* We have a SYNC API waiting for this event, dispatch it back */
|
||||
job->type = type;
|
||||
job->newstate = status;
|
||||
VIR_FREE(job->errmsg);
|
||||
ignore_value(VIR_STRDUP_QUIET(job->errmsg, error));
|
||||
|
@ -7829,13 +7828,18 @@ qemuProcessRefreshLegacyBlockjob(void *payload,
|
|||
qemuMonitorBlockJobInfoPtr info = payload;
|
||||
virDomainDiskDefPtr disk;
|
||||
qemuBlockJobDataPtr job;
|
||||
qemuBlockJobType jobtype = info->type;
|
||||
|
||||
if (!(disk = qemuProcessFindDomainDiskByAliasOrQOM(vm, jobname, jobname))) {
|
||||
VIR_DEBUG("could not find disk for block job '%s'", jobname);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(job = qemuBlockJobDiskNew(disk)))
|
||||
if (jobtype == VIR_DOMAIN_BLOCK_JOB_TYPE_COMMIT &&
|
||||
disk->mirrorJob == VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT)
|
||||
jobtype = disk->mirrorJob;
|
||||
|
||||
if (!(job = qemuBlockJobDiskNew(disk, jobtype)))
|
||||
return -1;
|
||||
|
||||
qemuBlockJobStarted(job);
|
||||
|
|
Loading…
Reference in New Issue