Add the job structure to the table when instantiating a new job and
remove it when it terminates/fails.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/qemu/qemu_blockjob.c | 31 ++++++++++++++++++++++++-------
src/qemu/qemu_blockjob.h | 6 ++++--
src/qemu/qemu_driver.c | 16 ++++++++--------
src/qemu/qemu_migration.c | 4 ++--
src/qemu/qemu_process.c | 6 +++---
5 files changed, 41 insertions(+), 22 deletions(-)
diff --git a/src/qemu/qemu_blockjob.c b/src/qemu/qemu_blockjob.c
index 27e854e2b2..97b9d7e5a6 100644
--- a/src/qemu/qemu_blockjob.c
+++ b/src/qemu/qemu_blockjob.c
@@ -105,20 +105,32 @@ qemuBlockJobDataNew(qemuBlockjobType type,
* Returns 0 on success and -1 on failure.
*/
qemuBlockJobDataPtr
-qemuBlockJobDiskNew(virDomainDiskDefPtr disk,
+qemuBlockJobDiskNew(virDomainObjPtr vm,
+ virDomainDiskDefPtr disk,
qemuBlockjobType type,
const char *jobname)
{
+ qemuDomainObjPrivatePtr priv = vm->privateData;
qemuBlockJobDataPtr job = NULL;
+ qemuBlockJobDataPtr ret = NULL;
if (!(job = qemuBlockJobDataNew(type, jobname)))
return NULL;
+ if (virHashAddEntry(priv->blockjobs, jobname, virObjectRef(job)) < 0) {
+ virObjectUnref(job);
+ goto cleanup;
+ }
+
job->disk = disk;
if (disk)
QEMU_DOMAIN_DISK_PRIVATE(disk)->blockjob = virObjectRef(job);
- return job;
+ VIR_STEAL_PTR(ret, job);
+
+ cleanup:
+ virObjectUnref(job);
+ return ret;
}
@@ -154,10 +166,14 @@ qemuBlockJobStarted(qemuBlockJobDataPtr job)
static void
-qemuBlockJobTerminate(qemuBlockJobDataPtr job)
+qemuBlockJobTerminate(virDomainObjPtr vm,
+ qemuBlockJobDataPtr job)
{
+ qemuDomainObjPrivatePtr priv = vm->privateData;
qemuDomainDiskPrivatePtr diskPriv;
+ virHashRemoveEntry(priv->blockjobs, job->name);
+
if (job->disk) {
diskPriv = QEMU_DOMAIN_DISK_PRIVATE(job->disk);
@@ -178,13 +194,14 @@ qemuBlockJobTerminate(qemuBlockJobDataPtr job)
* to @job if it was started.
*/
void
-qemuBlockJobStartupFinalize(qemuBlockJobDataPtr job)
+qemuBlockJobStartupFinalize(virDomainObjPtr vm,
+ qemuBlockJobDataPtr job)
{
if (!job)
return;
if (job->state == QEMU_BLOCKJOB_STATE_NEW)
- qemuBlockJobTerminate(job);
+ qemuBlockJobTerminate(vm, job);
virObjectUnref(job);
}
@@ -288,7 +305,7 @@ qemuBlockJobEventProcessLegacyCompleted(virQEMUDriverPtr driver,
virStorageSourceBackingStoreClear(disk->src);
ignore_value(qemuDomainDetermineDiskChain(driver, vm, disk, true));
ignore_value(qemuBlockNodeNamesDetect(driver, vm, asyncJob));
- qemuBlockJobTerminate(job);
+ qemuBlockJobTerminate(vm, job);
}
@@ -343,7 +360,7 @@ qemuBlockJobEventProcessLegacy(virQEMUDriverPtr driver,
}
disk->mirrorState = VIR_DOMAIN_DISK_MIRROR_STATE_NONE;
disk->mirrorJob = VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN;
- qemuBlockJobTerminate(job);
+ qemuBlockJobTerminate(vm, job);
break;
case VIR_DOMAIN_BLOCK_JOB_LAST:
diff --git a/src/qemu/qemu_blockjob.h b/src/qemu/qemu_blockjob.h
index f67b0f39be..6f58d323d0 100644
--- a/src/qemu/qemu_blockjob.h
+++ b/src/qemu/qemu_blockjob.h
@@ -77,7 +77,8 @@ struct _qemuBlockJobData {
qemuBlockJobDataPtr
-qemuBlockJobDiskNew(virDomainDiskDefPtr disk,
+qemuBlockJobDiskNew(virDomainObjPtr vm,
+ virDomainDiskDefPtr disk,
qemuBlockjobType type,
const char *jobname)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3);
@@ -95,7 +96,8 @@ qemuBlockJobIsRunning(qemuBlockJobDataPtr job)
ATTRIBUTE_NONNULL(1);
void
-qemuBlockJobStartupFinalize(qemuBlockJobDataPtr job);
+qemuBlockJobStartupFinalize(virDomainObjPtr vm,
+ qemuBlockJobDataPtr job);
int qemuBlockJobUpdate(virDomainObjPtr vm,
qemuBlockJobDataPtr job,
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 5675d2dc87..1b31132807 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4732,7 +4732,7 @@ processBlockJobEvent(virQEMUDriverPtr driver,
}
if (!(job = qemuBlockJobDiskGetJob(disk))) {
- if (!(job = qemuBlockJobDiskNew(disk, type, diskAlias)))
+ if (!(job = qemuBlockJobDiskNew(vm, disk, type, diskAlias)))
goto endjob;
qemuBlockJobStarted(job);
}
@@ -4742,7 +4742,7 @@ processBlockJobEvent(virQEMUDriverPtr driver,
qemuBlockJobUpdate(vm, job, QEMU_ASYNC_JOB_NONE);
endjob:
- qemuBlockJobStartupFinalize(job);
+ qemuBlockJobStartupFinalize(vm, job);
qemuDomainObjEndJob(driver, vm);
}
@@ -17268,7 +17268,7 @@ qemuDomainBlockPullCommon(virQEMUDriverPtr driver,
speed <<= 20;
}
- if (!(job = qemuBlockJobDiskNew(disk, QEMU_BLOCKJOB_TYPE_PULL, device)))
+ if (!(job = qemuBlockJobDiskNew(vm, disk, QEMU_BLOCKJOB_TYPE_PULL, device)))
goto endjob;
qemuDomainObjEnterMonitor(driver, vm);
@@ -17294,7 +17294,7 @@ qemuDomainBlockPullCommon(virQEMUDriverPtr driver,
qemuDomainObjEndJob(driver, vm);
cleanup:
- qemuBlockJobStartupFinalize(job);
+ qemuBlockJobStartupFinalize(vm, job);
virObjectUnref(cfg);
VIR_FREE(basePath);
VIR_FREE(backingPath);
@@ -17803,7 +17803,7 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
goto endjob;
}
- if (!(job = qemuBlockJobDiskNew(disk, QEMU_BLOCKJOB_TYPE_COPY, device)))
+ if (!(job = qemuBlockJobDiskNew(vm, disk, QEMU_BLOCKJOB_TYPE_COPY, device)))
goto endjob;
/* Actually start the mirroring */
@@ -17842,7 +17842,7 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
virSetError(monitor_error);
virFreeError(monitor_error);
}
- qemuBlockJobStartupFinalize(job);
+ qemuBlockJobStartupFinalize(vm, job);
cleanup:
VIR_FREE(device);
@@ -18217,7 +18217,7 @@ qemuDomainBlockCommit(virDomainPtr dom,
jobtype = QEMU_BLOCKJOB_TYPE_ACTIVE_COMMIT;
}
- if (!(job = qemuBlockJobDiskNew(disk, jobtype, device)))
+ if (!(job = qemuBlockJobDiskNew(vm, disk, jobtype, device)))
goto endjob;
qemuDomainObjEnterMonitor(driver, vm);
@@ -18260,7 +18260,7 @@ qemuDomainBlockCommit(virDomainPtr dom,
}
}
virStorageSourceFree(mirror);
- qemuBlockJobStartupFinalize(job);
+ qemuBlockJobStartupFinalize(vm, job);
qemuDomainObjEndJob(driver, vm);
cleanup:
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 4ce3141465..87eeec3d84 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -914,7 +914,7 @@ qemuMigrationSrcNBDStorageCopyOne(virQEMUDriverPtr driver,
if (!(diskAlias = qemuAliasDiskDriveFromDisk(disk)))
goto cleanup;
- if (!(job = qemuBlockJobDiskNew(disk, QEMU_BLOCKJOB_TYPE_COPY, diskAlias)))
+ if (!(job = qemuBlockJobDiskNew(vm, disk, QEMU_BLOCKJOB_TYPE_COPY, diskAlias)))
goto cleanup;
qemuBlockJobSyncBegin(job);
@@ -943,7 +943,7 @@ qemuMigrationSrcNBDStorageCopyOne(virQEMUDriverPtr driver,
ret = 0;
cleanup:
- qemuBlockJobStartupFinalize(job);
+ qemuBlockJobStartupFinalize(vm, job);
VIR_FREE(diskAlias);
return ret;
}
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 3f1dd662e9..4b57411856 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -967,7 +967,7 @@ qemuProcessHandleBlockJob(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
}
cleanup:
- qemuBlockJobStartupFinalize(job);
+ qemuBlockJobStartupFinalize(vm, job);
qemuProcessEventFree(processEvent);
virObjectUnlock(vm);
return 0;
@@ -7776,7 +7776,7 @@ qemuProcessRefreshLegacyBlockjob(void *payload,
disk->mirrorJob == VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT)
jobtype = disk->mirrorJob;
- if (!(job = qemuBlockJobDiskNew(disk, jobtype, jobname)))
+ if (!(job = qemuBlockJobDiskNew(vm, disk, jobtype, jobname)))
return -1;
qemuBlockJobStarted(job);
@@ -7789,7 +7789,7 @@ qemuProcessRefreshLegacyBlockjob(void *payload,
}
}
- qemuBlockJobStartupFinalize(job);
+ qemuBlockJobStartupFinalize(vm, job);
return 0;
}
--
2.19.2