qemu: blockjob: Split out handling of completed jobs

qemuBlockJobEventProcessLegacy was getting too big. Remove handling of
completed jobs in a separate function.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2018-10-17 14:51:56 +02:00
parent 246303dc5b
commit 232ab2f200

View File

@ -81,46 +81,15 @@ qemuBlockJobEmitEvents(virQEMUDriverPtr driver,
} }
/**
* qemuBlockJobEventProcessLegacy:
* @driver: qemu driver
* @vm: domain
* @disk: domain disk
* @type: block job type
* @status: block job status
*
* Update disk's mirror state in response to a block job event
* from QEMU. For mirror state's that must survive libvirt
* restart, also update the domain's status XML.
*/
static void static void
qemuBlockJobEventProcessLegacy(virQEMUDriverPtr driver, qemuBlockJobEventProcessLegacyCompleted(virQEMUDriverPtr driver,
virDomainObjPtr vm, virDomainObjPtr vm,
virDomainDiskDefPtr disk, virDomainDiskDefPtr disk,
int asyncJob, int asyncJob)
int type,
int status)
{ {
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
virDomainDiskDefPtr persistDisk = NULL;
qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk); qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
virDomainDiskDefPtr persistDisk = NULL;
VIR_DEBUG("disk=%s, mirrorState=%s, type=%d, status=%d",
disk->dst,
NULLSTR(virDomainDiskMirrorStateTypeToString(disk->mirrorState)),
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
* to match. */
switch ((virConnectDomainEventBlockJobStatus) status) {
case VIR_DOMAIN_BLOCK_JOB_COMPLETED:
if (disk->mirrorState == VIR_DOMAIN_DISK_MIRROR_STATE_PIVOT) { if (disk->mirrorState == VIR_DOMAIN_DISK_MIRROR_STATE_PIVOT) {
if (vm->newDef) { if (vm->newDef) {
virStorageSourcePtr copy = NULL; virStorageSourcePtr copy = NULL;
@ -173,6 +142,49 @@ qemuBlockJobEventProcessLegacy(virQEMUDriverPtr driver,
ignore_value(qemuDomainDetermineDiskChain(driver, vm, disk, true)); ignore_value(qemuDomainDetermineDiskChain(driver, vm, disk, true));
ignore_value(qemuBlockNodeNamesDetect(driver, vm, asyncJob)); ignore_value(qemuBlockNodeNamesDetect(driver, vm, asyncJob));
diskPriv->blockjob->started = false; diskPriv->blockjob->started = false;
}
/**
* qemuBlockJobEventProcessLegacy:
* @driver: qemu driver
* @vm: domain
* @disk: domain disk
* @type: block job type
* @status: block job status
*
* Update disk's mirror state in response to a block job event
* from QEMU. For mirror state's that must survive libvirt
* restart, also update the domain's status XML.
*/
static void
qemuBlockJobEventProcessLegacy(virQEMUDriverPtr driver,
virDomainObjPtr vm,
virDomainDiskDefPtr disk,
int asyncJob,
int type,
int status)
{
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
VIR_DEBUG("disk=%s, mirrorState=%s, type=%d, status=%d",
disk->dst,
NULLSTR(virDomainDiskMirrorStateTypeToString(disk->mirrorState)),
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
* to match. */
switch ((virConnectDomainEventBlockJobStatus) status) {
case VIR_DOMAIN_BLOCK_JOB_COMPLETED:
qemuBlockJobEventProcessLegacyCompleted(driver, vm, disk, asyncJob);
break; break;
case VIR_DOMAIN_BLOCK_JOB_READY: case VIR_DOMAIN_BLOCK_JOB_READY: