qemu: blockjob: Extract emitting of libvirt events

Put the emitting of VIR_DOMAIN_EVENT_ID_BLOCK_JOB and
VIR_DOMAIN_EVENT_ID_BLOCK_JOB_2 into 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-09-12 17:13:16 +02:00
parent 926cb125a4
commit 56557b4898

View File

@ -42,6 +42,31 @@
VIR_LOG_INIT("qemu.qemu_blockjob");
/**
* qemuBlockJobEmitEvents:
*
* Emits the VIR_DOMAIN_EVENT_ID_BLOCK_JOB and VIR_DOMAIN_EVENT_ID_BLOCK_JOB_2
* for a block job.
*/
static void
qemuBlockJobEmitEvents(virQEMUDriverPtr driver,
virDomainObjPtr vm,
virDomainDiskDefPtr disk,
virDomainBlockJobType type,
virConnectDomainEventBlockJobStatus status)
{
virObjectEventPtr event = NULL;
virObjectEventPtr event2 = NULL;
event = virDomainEventBlockJobNewFromObj(vm, virDomainDiskGetSource(disk),
type, status);
virObjectEventStateQueue(driver->domainEventState, event);
event2 = virDomainEventBlockJob2NewFromObj(vm, disk->dst, type, status);
virObjectEventStateQueue(driver->domainEventState, event2);
}
/**
* qemuBlockJobUpdate:
* @vm: domain
@ -101,9 +126,6 @@ qemuBlockJobEventProcess(virQEMUDriverPtr driver,
int type,
int status)
{
virObjectEventPtr event = NULL;
virObjectEventPtr event2 = NULL;
const char *path;
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
virDomainDiskDefPtr persistDisk = NULL;
qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
@ -114,14 +136,11 @@ qemuBlockJobEventProcess(virQEMUDriverPtr driver,
type,
status);
/* Have to generate two variants of the event for old vs. new
* client callbacks */
if (type == VIR_DOMAIN_BLOCK_JOB_TYPE_COMMIT &&
disk->mirrorJob == VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT)
type = disk->mirrorJob;
path = virDomainDiskGetSource(disk);
event = virDomainEventBlockJobNewFromObj(vm, path, type, status);
event2 = virDomainEventBlockJob2NewFromObj(vm, disk->dst, type, status);
qemuBlockJobEmitEvents(driver, vm, disk, type, status);
/* If we completed a block pull or commit, then update the XML
* to match. */
@ -210,9 +229,6 @@ qemuBlockJobEventProcess(virQEMUDriverPtr driver,
"after block job", vm->def->name);
}
virObjectEventStateQueue(driver->domainEventState, event);
virObjectEventStateQueue(driver->domainEventState, event2);
virObjectUnref(cfg);
}