1
0

qemu: Extract internals of processBlockJobEvent into a helper

Later on I'll be adding a condition that will allow to synchronise a
SYNC block job abort. The approach will require this code to be called
from two different places so it has to be extracted into a helper.
This commit is contained in:
Peter Krempa 2015-03-30 11:26:19 +02:00 committed by Daniel Veillard
parent 6b6c4ab8a6
commit 0c4474df4e

View File

@ -4453,31 +4453,19 @@ processSerialChangedEvent(virQEMUDriverPtr driver,
static void
processBlockJobEvent(virQEMUDriverPtr driver,
qemuBlockJobEventProcess(virQEMUDriverPtr driver,
virDomainObjPtr vm,
char *diskAlias,
virDomainDiskDefPtr disk,
int type,
int status)
{
virObjectEventPtr event = NULL;
virObjectEventPtr event2 = NULL;
const char *path;
virDomainDiskDefPtr disk;
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
virDomainDiskDefPtr persistDisk = NULL;
bool save = false;
if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
goto cleanup;
if (!virDomainObjIsActive(vm)) {
VIR_DEBUG("Domain is not running");
goto endjob;
}
disk = qemuProcessFindDomainDiskByAlias(vm, diskAlias);
if (disk) {
/* Have to generate two variants of the event for old vs. new
* client callbacks */
if (type == VIR_DOMAIN_BLOCK_JOB_TYPE_COMMIT &&
@ -4485,8 +4473,7 @@ processBlockJobEvent(virQEMUDriverPtr driver,
type = disk->mirrorJob;
path = virDomainDiskGetSource(disk);
event = virDomainEventBlockJobNewFromObj(vm, path, type, status);
event2 = virDomainEventBlockJob2NewFromObj(vm, disk->dst, type,
status);
event2 = virDomainEventBlockJob2NewFromObj(vm, disk->dst, type, status);
/* If we completed a block pull or commit, then update the XML
* to match. */
@ -4494,8 +4481,7 @@ processBlockJobEvent(virQEMUDriverPtr driver,
case VIR_DOMAIN_BLOCK_JOB_COMPLETED:
if (disk->mirrorState == VIR_DOMAIN_DISK_MIRROR_STATE_PIVOT) {
if (vm->newDef) {
int indx = virDomainDiskIndexByName(vm->newDef, disk->dst,
false);
int indx = virDomainDiskIndexByName(vm->newDef, disk->dst, false);
virStorageSourcePtr copy = NULL;
if (indx >= 0) {
@ -4563,7 +4549,6 @@ processBlockJobEvent(virQEMUDriverPtr driver,
case VIR_DOMAIN_BLOCK_JOB_LAST:
break;
}
}
if (save) {
if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0)
@ -4574,13 +4559,36 @@ processBlockJobEvent(virQEMUDriverPtr driver,
VIR_WARN("Unable to update persistent definition on vm %s "
"after block job", vm->def->name);
}
virObjectUnref(cfg);
if (event)
qemuDomainEventQueue(driver, event);
if (event2)
qemuDomainEventQueue(driver, event2);
virObjectUnref(cfg);
}
static void
processBlockJobEvent(virQEMUDriverPtr driver,
virDomainObjPtr vm,
char *diskAlias,
int type,
int status)
{
virDomainDiskDefPtr disk;
if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
goto cleanup;
if (!virDomainObjIsActive(vm)) {
VIR_DEBUG("Domain is not running");
goto endjob;
}
if ((disk = qemuProcessFindDomainDiskByAlias(vm, diskAlias)))
qemuBlockJobEventProcess(driver, vm, disk, type, status);
endjob:
qemuDomainObjEndJob(driver, vm);
cleanup: