From 79b73251fb49051339fd1d4102c81971a819b965 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Fri, 23 Nov 2018 12:45:32 +0100 Subject: [PATCH] qemu: blockjob: Record job type when starting the job MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Ján Tomko --- src/qemu/qemu_blockjob.c | 10 +++++----- src/qemu/qemu_blockjob.h | 20 ++++++++++++++++++-- src/qemu/qemu_driver.c | 11 ++++++----- src/qemu/qemu_migration.c | 2 +- src/qemu/qemu_process.c | 8 ++++++-- 5 files changed, 36 insertions(+), 15 deletions(-) diff --git a/src/qemu/qemu_blockjob.c b/src/qemu/qemu_blockjob.c index 1941c0763e..d46b40f762 100644 --- a/src/qemu/qemu_blockjob.c +++ b/src/qemu/qemu_blockjob.c @@ -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 diff --git a/src/qemu/qemu_blockjob.h b/src/qemu/qemu_blockjob.h index 5155d18f88..b45c938aa2 100644 --- a/src/qemu/qemu_blockjob.h +++ b/src/qemu/qemu_blockjob.h @@ -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 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 8ecdd6b6f1..4f46772f5d 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -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); diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 588e61cfce..e44654ecdf 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -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); diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 4bc1218fab..226d2ba5c8 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -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);