Rather than storing the presence of the blockjob in a flag we can bind together the lifecycle of the job with the lifecycle of the object which is tracking the data for it. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/qemu/qemu_blockjob.c | 76 +++++++++++++++++++++++++++++----------- src/qemu/qemu_blockjob.h | 1 - src/qemu/qemu_domain.c | 5 --- 3 files changed, 55 insertions(+), 27 deletions(-) diff --git a/src/qemu/qemu_blockjob.c b/src/qemu/qemu_blockjob.c index c1826baa3c..87dc520f2c 100644 --- a/src/qemu/qemu_blockjob.c +++ b/src/qemu/qemu_blockjob.c @@ -66,23 +66,22 @@ qemuBlockJobDataOnceInit(void) VIR_ONCE_GLOBAL_INIT(qemuBlockJobData) -qemuBlockJobDataPtr -qemuBlockJobDataNew(void) +static qemuBlockJobDataPtr +qemuBlockJobDataNew(qemuBlockjobType type) { + qemuBlockJobDataPtr job = NULL; + if (qemuBlockJobDataInitialize() < 0) return NULL; - return virObjectNew(qemuBlockJobDataClass); -} - + if (!(job = virObjectNew(qemuBlockJobDataClass))) + return NULL; -static void -qemuBlockJobDataReset(qemuBlockJobDataPtr job) -{ - job->type = -1; + job->state = QEMU_BLOCKJOB_STATE_NEW; job->newstate = -1; - VIR_FREE(job->errmsg); - job->synchronous = false; + job->type = type; + + return job; } @@ -98,15 +97,16 @@ qemuBlockJobDataPtr qemuBlockJobDiskNew(virDomainDiskDefPtr disk, qemuBlockjobType type) { - qemuBlockJobDataPtr job = QEMU_DOMAIN_DISK_PRIVATE(disk)->blockjob; - job->disk = disk; + qemuBlockJobDataPtr job = NULL; - qemuBlockJobDataReset(job); + if (!(job = qemuBlockJobDataNew(type))) + return NULL; - job->state = QEMU_BLOCKJOB_STATE_NEW; - job->type = type; + job->disk = disk; + if (disk) + QEMU_DOMAIN_DISK_PRIVATE(disk)->blockjob = virObjectRef(job); - return virObjectRef(job); + return job; } @@ -141,6 +141,22 @@ qemuBlockJobStarted(qemuBlockJobDataPtr job) } +static void +qemuBlockJobTerminate(qemuBlockJobDataPtr job) +{ + qemuDomainDiskPrivatePtr diskPriv; + + if (job->disk) { + diskPriv = QEMU_DOMAIN_DISK_PRIVATE(job->disk); + + if (job == diskPriv->blockjob) { + virObjectUnref(diskPriv->blockjob); + diskPriv->blockjob = NULL; + } + } +} + + /** * qemuBlockJobStartupFinalize: * @job: job being started @@ -156,7 +172,7 @@ qemuBlockJobStartupFinalize(qemuBlockJobDataPtr job) return; if (job->state == QEMU_BLOCKJOB_STATE_NEW) - qemuBlockJobDataReset(job); + qemuBlockJobTerminate(job); virObjectUnref(job); } @@ -200,11 +216,15 @@ qemuBlockJobEmitEvents(virQEMUDriverPtr driver, static void qemuBlockJobEventProcessLegacyCompleted(virQEMUDriverPtr driver, virDomainObjPtr vm, - virDomainDiskDefPtr disk, + qemuBlockJobDataPtr job, int asyncJob) { + virDomainDiskDefPtr disk = job->disk; virDomainDiskDefPtr persistDisk = NULL; + if (!disk) + return; + if (disk->mirrorState == VIR_DOMAIN_DISK_MIRROR_STATE_PIVOT) { if (vm->newDef) { virStorageSourcePtr copy = NULL; @@ -256,6 +276,7 @@ qemuBlockJobEventProcessLegacyCompleted(virQEMUDriverPtr driver, virStorageSourceBackingStoreClear(disk->src); ignore_value(qemuDomainDetermineDiskChain(driver, vm, disk, true)); ignore_value(qemuBlockNodeNamesDetect(driver, vm, asyncJob)); + qemuBlockJobTerminate(job); } @@ -294,7 +315,7 @@ qemuBlockJobEventProcessLegacy(virQEMUDriverPtr driver, * to match. */ switch ((virConnectDomainEventBlockJobStatus) job->newstate) { case VIR_DOMAIN_BLOCK_JOB_COMPLETED: - qemuBlockJobEventProcessLegacyCompleted(driver, vm, disk, asyncJob); + qemuBlockJobEventProcessLegacyCompleted(driver, vm, job, asyncJob); break; case VIR_DOMAIN_BLOCK_JOB_READY: @@ -310,6 +331,7 @@ qemuBlockJobEventProcessLegacy(virQEMUDriverPtr driver, } disk->mirrorState = VIR_DOMAIN_DISK_MIRROR_STATE_NONE; disk->mirrorJob = VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN; + qemuBlockJobTerminate(job); break; case VIR_DOMAIN_BLOCK_JOB_LAST: @@ -333,7 +355,7 @@ qemuBlockJobEventProcessLegacy(virQEMUDriverPtr driver, /** - * qemuBlockJobUpdate: + * qemuBlockJobUpdateDisk: * @vm: domain * @disk: domain disk * @error: error (output parameter) @@ -410,3 +432,15 @@ qemuBlockJobSyncEndDisk(virDomainObjPtr vm, qemuBlockJobUpdate(vm, job, asyncJob); job->synchronous = false; } + + +qemuBlockJobDataPtr +qemuBlockJobGetByDisk(virDomainDiskDefPtr disk) +{ + qemuBlockJobDataPtr job = QEMU_DOMAIN_DISK_PRIVATE(disk)->blockjob; + + if (!job) + return NULL; + + return virObjectRef(job); +} diff --git a/src/qemu/qemu_blockjob.h b/src/qemu/qemu_blockjob.h index 9dad47f732..8c567ec886 100644 --- a/src/qemu/qemu_blockjob.h +++ b/src/qemu/qemu_blockjob.h @@ -73,7 +73,6 @@ struct _qemuBlockJobData { int newstate; /* virConnectDomainEventBlockJobStatus - new state to be processed */ }; -qemuBlockJobDataPtr qemuBlockJobDataNew(void); qemuBlockJobDataPtr qemuBlockJobDiskNew(virDomainDiskDefPtr disk, diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 01b4c97a91..9961ba67d8 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -1062,11 +1062,6 @@ qemuDomainDiskPrivateNew(void) if (!(priv = virObjectNew(qemuDomainDiskPrivateClass))) return NULL; - if (!(priv->blockjob = qemuBlockJobDataNew())) { - virObjectUnref(priv); - priv = NULL; - } - return (virObjectPtr) priv; } -- 2.19.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list