mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 14:15:28 +00:00
qemu: blockjob: Register new and running blockjobs in the global table
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@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
acff582915
commit
5ff46aaa7f
@ -94,8 +94,16 @@ qemuBlockJobDataNew(qemuBlockJobType type,
|
||||
|
||||
static int
|
||||
qemuBlockJobRegister(qemuBlockJobDataPtr job,
|
||||
virDomainObjPtr vm,
|
||||
virDomainDiskDefPtr disk)
|
||||
{
|
||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||
|
||||
if (virHashAddEntry(priv->blockjobs, job->name, virObjectRef(job)) < 0) {
|
||||
virObjectUnref(job);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (disk) {
|
||||
job->disk = disk;
|
||||
QEMU_DOMAIN_DISK_PRIVATE(disk)->blockjob = virObjectRef(job);
|
||||
@ -106,8 +114,10 @@ qemuBlockJobRegister(qemuBlockJobDataPtr job,
|
||||
|
||||
|
||||
static void
|
||||
qemuBlockJobUnregister(qemuBlockJobDataPtr job)
|
||||
qemuBlockJobUnregister(qemuBlockJobDataPtr job,
|
||||
virDomainObjPtr vm)
|
||||
{
|
||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||
qemuDomainDiskPrivatePtr diskPriv;
|
||||
|
||||
if (job->disk) {
|
||||
@ -120,6 +130,9 @@ qemuBlockJobUnregister(qemuBlockJobDataPtr job)
|
||||
|
||||
job->disk = NULL;
|
||||
}
|
||||
|
||||
/* this may remove the last reference of 'job' */
|
||||
virHashRemoveEntry(priv->blockjobs, job->name);
|
||||
}
|
||||
|
||||
|
||||
@ -132,7 +145,8 @@ qemuBlockJobUnregister(qemuBlockJobDataPtr job)
|
||||
* Returns 0 on success and -1 on failure.
|
||||
*/
|
||||
qemuBlockJobDataPtr
|
||||
qemuBlockJobDiskNew(virDomainDiskDefPtr disk,
|
||||
qemuBlockJobDiskNew(virDomainObjPtr vm,
|
||||
virDomainDiskDefPtr disk,
|
||||
qemuBlockJobType type,
|
||||
const char *jobname)
|
||||
{
|
||||
@ -141,7 +155,7 @@ qemuBlockJobDiskNew(virDomainDiskDefPtr disk,
|
||||
if (!(job = qemuBlockJobDataNew(type, jobname)))
|
||||
return NULL;
|
||||
|
||||
if (qemuBlockJobRegister(job, disk) < 0)
|
||||
if (qemuBlockJobRegister(job, vm, disk) < 0)
|
||||
return NULL;
|
||||
|
||||
VIR_RETURN_PTR(job);
|
||||
@ -189,13 +203,14 @@ qemuBlockJobStarted(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)
|
||||
qemuBlockJobUnregister(job);
|
||||
qemuBlockJobUnregister(job, vm);
|
||||
|
||||
virObjectUnref(job);
|
||||
}
|
||||
@ -314,7 +329,7 @@ qemuBlockJobEventProcessLegacyCompleted(virQEMUDriverPtr driver,
|
||||
virStorageSourceBackingStoreClear(disk->src);
|
||||
ignore_value(qemuDomainDetermineDiskChain(driver, vm, disk, NULL, true));
|
||||
ignore_value(qemuBlockNodeNamesDetect(driver, vm, asyncJob));
|
||||
qemuBlockJobUnregister(job);
|
||||
qemuBlockJobUnregister(job, vm);
|
||||
qemuDomainSaveConfig(vm);
|
||||
}
|
||||
|
||||
@ -373,7 +388,7 @@ qemuBlockJobEventProcessLegacy(virQEMUDriverPtr driver,
|
||||
}
|
||||
disk->mirrorState = VIR_DOMAIN_DISK_MIRROR_STATE_NONE;
|
||||
disk->mirrorJob = VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN;
|
||||
qemuBlockJobUnregister(job);
|
||||
qemuBlockJobUnregister(job, vm);
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_BLOCK_JOB_LAST:
|
||||
|
@ -80,7 +80,8 @@ struct _qemuBlockJobData {
|
||||
|
||||
|
||||
qemuBlockJobDataPtr
|
||||
qemuBlockJobDiskNew(virDomainDiskDefPtr disk,
|
||||
qemuBlockJobDiskNew(virDomainObjPtr vm,
|
||||
virDomainDiskDefPtr disk,
|
||||
qemuBlockJobType type,
|
||||
const char *jobname)
|
||||
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3);
|
||||
@ -98,7 +99,8 @@ qemuBlockJobIsRunning(qemuBlockJobDataPtr job)
|
||||
ATTRIBUTE_NONNULL(1);
|
||||
|
||||
void
|
||||
qemuBlockJobStartupFinalize(qemuBlockJobDataPtr job);
|
||||
qemuBlockJobStartupFinalize(virDomainObjPtr vm,
|
||||
qemuBlockJobDataPtr job);
|
||||
|
||||
int qemuBlockJobUpdate(virDomainObjPtr vm,
|
||||
qemuBlockJobDataPtr job,
|
||||
|
@ -4702,7 +4702,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);
|
||||
}
|
||||
@ -4712,7 +4712,7 @@ processBlockJobEvent(virQEMUDriverPtr driver,
|
||||
qemuBlockJobUpdate(vm, job, QEMU_ASYNC_JOB_NONE);
|
||||
|
||||
endjob:
|
||||
qemuBlockJobStartupFinalize(job);
|
||||
qemuBlockJobStartupFinalize(vm, job);
|
||||
qemuDomainObjEndJob(driver, vm);
|
||||
}
|
||||
|
||||
@ -17084,7 +17084,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);
|
||||
@ -17110,7 +17110,7 @@ qemuDomainBlockPullCommon(virQEMUDriverPtr driver,
|
||||
qemuDomainObjEndJob(driver, vm);
|
||||
|
||||
cleanup:
|
||||
qemuBlockJobStartupFinalize(job);
|
||||
qemuBlockJobStartupFinalize(vm, job);
|
||||
virDomainObjEndAPI(&vm);
|
||||
return ret;
|
||||
}
|
||||
@ -17655,7 +17655,7 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
|
||||
if (qemuDomainStorageSourceChainAccessAllow(driver, vm, mirror) < 0)
|
||||
goto endjob;
|
||||
|
||||
if (!(job = qemuBlockJobDiskNew(disk, QEMU_BLOCKJOB_TYPE_COPY, device)))
|
||||
if (!(job = qemuBlockJobDiskNew(vm, disk, QEMU_BLOCKJOB_TYPE_COPY, device)))
|
||||
goto endjob;
|
||||
|
||||
disk->mirrorState = VIR_DOMAIN_DISK_MIRROR_STATE_NONE;
|
||||
@ -17691,7 +17691,7 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
|
||||
VIR_WARN("%s", _("unable to remove just-created copy target"));
|
||||
virStorageFileDeinit(mirror);
|
||||
qemuDomainObjEndJob(driver, vm);
|
||||
qemuBlockJobStartupFinalize(job);
|
||||
qemuBlockJobStartupFinalize(vm, job);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -18042,7 +18042,7 @@ qemuDomainBlockCommit(virDomainPtr dom,
|
||||
qemuDomainStorageSourceAccessAllow(driver, vm, top_parent, false, false) < 0))
|
||||
goto endjob;
|
||||
|
||||
if (!(job = qemuBlockJobDiskNew(disk, jobtype, device)))
|
||||
if (!(job = qemuBlockJobDiskNew(vm, disk, jobtype, device)))
|
||||
goto endjob;
|
||||
|
||||
disk->mirrorState = VIR_DOMAIN_DISK_MIRROR_STATE_NONE;
|
||||
@ -18089,7 +18089,7 @@ qemuDomainBlockCommit(virDomainPtr dom,
|
||||
virFreeError(orig_err);
|
||||
}
|
||||
}
|
||||
qemuBlockJobStartupFinalize(job);
|
||||
qemuBlockJobStartupFinalize(vm, job);
|
||||
qemuDomainObjEndJob(driver, vm);
|
||||
|
||||
cleanup:
|
||||
|
@ -923,7 +923,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);
|
||||
@ -951,7 +951,7 @@ qemuMigrationSrcNBDStorageCopyOne(virQEMUDriverPtr driver,
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
qemuBlockJobStartupFinalize(job);
|
||||
qemuBlockJobStartupFinalize(vm, job);
|
||||
VIR_FREE(diskAlias);
|
||||
return ret;
|
||||
}
|
||||
|
@ -976,7 +976,7 @@ qemuProcessHandleBlockJob(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
|
||||
}
|
||||
|
||||
cleanup:
|
||||
qemuBlockJobStartupFinalize(job);
|
||||
qemuBlockJobStartupFinalize(vm, job);
|
||||
qemuProcessEventFree(processEvent);
|
||||
virObjectUnlock(vm);
|
||||
return 0;
|
||||
@ -7816,7 +7816,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);
|
||||
@ -7850,7 +7850,7 @@ qemuProcessRefreshLegacyBlockjob(void *payload,
|
||||
}
|
||||
|
||||
cleanup:
|
||||
qemuBlockJobStartupFinalize(job);
|
||||
qemuBlockJobStartupFinalize(vm, job);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user