mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-08 20:51:26 +00:00
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:
parent
6b6c4ab8a6
commit
0c4474df4e
@ -4453,31 +4453,19 @@ processSerialChangedEvent(virQEMUDriverPtr driver,
|
|||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
processBlockJobEvent(virQEMUDriverPtr driver,
|
qemuBlockJobEventProcess(virQEMUDriverPtr driver,
|
||||||
virDomainObjPtr vm,
|
virDomainObjPtr vm,
|
||||||
char *diskAlias,
|
virDomainDiskDefPtr disk,
|
||||||
int type,
|
int type,
|
||||||
int status)
|
int status)
|
||||||
{
|
{
|
||||||
virObjectEventPtr event = NULL;
|
virObjectEventPtr event = NULL;
|
||||||
virObjectEventPtr event2 = NULL;
|
virObjectEventPtr event2 = NULL;
|
||||||
const char *path;
|
const char *path;
|
||||||
virDomainDiskDefPtr disk;
|
|
||||||
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
||||||
virDomainDiskDefPtr persistDisk = NULL;
|
virDomainDiskDefPtr persistDisk = NULL;
|
||||||
bool save = false;
|
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
|
/* Have to generate two variants of the event for old vs. new
|
||||||
* client callbacks */
|
* client callbacks */
|
||||||
if (type == VIR_DOMAIN_BLOCK_JOB_TYPE_COMMIT &&
|
if (type == VIR_DOMAIN_BLOCK_JOB_TYPE_COMMIT &&
|
||||||
@ -4485,8 +4473,7 @@ processBlockJobEvent(virQEMUDriverPtr driver,
|
|||||||
type = disk->mirrorJob;
|
type = disk->mirrorJob;
|
||||||
path = virDomainDiskGetSource(disk);
|
path = virDomainDiskGetSource(disk);
|
||||||
event = virDomainEventBlockJobNewFromObj(vm, path, type, status);
|
event = virDomainEventBlockJobNewFromObj(vm, path, type, status);
|
||||||
event2 = virDomainEventBlockJob2NewFromObj(vm, disk->dst, type,
|
event2 = virDomainEventBlockJob2NewFromObj(vm, disk->dst, type, status);
|
||||||
status);
|
|
||||||
|
|
||||||
/* If we completed a block pull or commit, then update the XML
|
/* If we completed a block pull or commit, then update the XML
|
||||||
* to match. */
|
* to match. */
|
||||||
@ -4494,8 +4481,7 @@ processBlockJobEvent(virQEMUDriverPtr driver,
|
|||||||
case VIR_DOMAIN_BLOCK_JOB_COMPLETED:
|
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) {
|
||||||
int indx = virDomainDiskIndexByName(vm->newDef, disk->dst,
|
int indx = virDomainDiskIndexByName(vm->newDef, disk->dst, false);
|
||||||
false);
|
|
||||||
virStorageSourcePtr copy = NULL;
|
virStorageSourcePtr copy = NULL;
|
||||||
|
|
||||||
if (indx >= 0) {
|
if (indx >= 0) {
|
||||||
@ -4563,7 +4549,6 @@ processBlockJobEvent(virQEMUDriverPtr driver,
|
|||||||
case VIR_DOMAIN_BLOCK_JOB_LAST:
|
case VIR_DOMAIN_BLOCK_JOB_LAST:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (save) {
|
if (save) {
|
||||||
if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0)
|
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 "
|
VIR_WARN("Unable to update persistent definition on vm %s "
|
||||||
"after block job", vm->def->name);
|
"after block job", vm->def->name);
|
||||||
}
|
}
|
||||||
virObjectUnref(cfg);
|
|
||||||
|
|
||||||
if (event)
|
if (event)
|
||||||
qemuDomainEventQueue(driver, event);
|
qemuDomainEventQueue(driver, event);
|
||||||
if (event2)
|
if (event2)
|
||||||
qemuDomainEventQueue(driver, 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:
|
endjob:
|
||||||
qemuDomainObjEndJob(driver, vm);
|
qemuDomainObjEndJob(driver, vm);
|
||||||
cleanup:
|
cleanup:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user