mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-02 01:45:17 +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,116 +4453,101 @@ 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)
|
/* Have to generate two variants of the event for old vs. new
|
||||||
goto cleanup;
|
* 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);
|
||||||
|
|
||||||
if (!virDomainObjIsActive(vm)) {
|
/* If we completed a block pull or commit, then update the XML
|
||||||
VIR_DEBUG("Domain is not running");
|
* to match. */
|
||||||
goto endjob;
|
switch ((virConnectDomainEventBlockJobStatus) status) {
|
||||||
}
|
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);
|
||||||
|
virStorageSourcePtr copy = NULL;
|
||||||
|
|
||||||
disk = qemuProcessFindDomainDiskByAlias(vm, diskAlias);
|
if (indx >= 0) {
|
||||||
|
persistDisk = vm->newDef->disks[indx];
|
||||||
if (disk) {
|
copy = virStorageSourceCopy(disk->mirror, false);
|
||||||
/* Have to generate two variants of the event for old vs. new
|
if (virStorageSourceInitChainElement(copy,
|
||||||
* client callbacks */
|
persistDisk->src,
|
||||||
if (type == VIR_DOMAIN_BLOCK_JOB_TYPE_COMMIT &&
|
true) < 0) {
|
||||||
disk->mirrorJob == VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT)
|
VIR_WARN("Unable to update persistent definition "
|
||||||
type = disk->mirrorJob;
|
"on vm %s after block job",
|
||||||
path = virDomainDiskGetSource(disk);
|
vm->def->name);
|
||||||
event = virDomainEventBlockJobNewFromObj(vm, path, type, status);
|
virStorageSourceFree(copy);
|
||||||
event2 = virDomainEventBlockJob2NewFromObj(vm, disk->dst, type,
|
copy = NULL;
|
||||||
status);
|
persistDisk = NULL;
|
||||||
|
|
||||||
/* 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 (vm->newDef) {
|
|
||||||
int indx = virDomainDiskIndexByName(vm->newDef, disk->dst,
|
|
||||||
false);
|
|
||||||
virStorageSourcePtr copy = NULL;
|
|
||||||
|
|
||||||
if (indx >= 0) {
|
|
||||||
persistDisk = vm->newDef->disks[indx];
|
|
||||||
copy = virStorageSourceCopy(disk->mirror, false);
|
|
||||||
if (virStorageSourceInitChainElement(copy,
|
|
||||||
persistDisk->src,
|
|
||||||
true) < 0) {
|
|
||||||
VIR_WARN("Unable to update persistent definition "
|
|
||||||
"on vm %s after block job",
|
|
||||||
vm->def->name);
|
|
||||||
virStorageSourceFree(copy);
|
|
||||||
copy = NULL;
|
|
||||||
persistDisk = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (copy) {
|
|
||||||
virStorageSourceFree(persistDisk->src);
|
|
||||||
persistDisk->src = copy;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (copy) {
|
||||||
/* XXX We want to revoke security labels and disk
|
virStorageSourceFree(persistDisk->src);
|
||||||
* lease, as well as audit that revocation, before
|
persistDisk->src = copy;
|
||||||
* dropping the original source. But it gets tricky
|
}
|
||||||
* if both source and mirror share common backing
|
|
||||||
* files (we want to only revoke the non-shared
|
|
||||||
* portion of the chain); so for now, we leak the
|
|
||||||
* access to the original. */
|
|
||||||
virStorageSourceFree(disk->src);
|
|
||||||
disk->src = disk->mirror;
|
|
||||||
} else {
|
|
||||||
virStorageSourceFree(disk->mirror);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Recompute the cached backing chain to match our
|
/* XXX We want to revoke security labels and disk
|
||||||
* updates. Better would be storing the chain ourselves
|
* lease, as well as audit that revocation, before
|
||||||
* rather than reprobing, but we haven't quite completed
|
* dropping the original source. But it gets tricky
|
||||||
* that conversion to use our XML tracking. */
|
* if both source and mirror share common backing
|
||||||
disk->mirror = NULL;
|
* files (we want to only revoke the non-shared
|
||||||
save = disk->mirrorState != VIR_DOMAIN_DISK_MIRROR_STATE_NONE;
|
* portion of the chain); so for now, we leak the
|
||||||
disk->mirrorState = VIR_DOMAIN_DISK_MIRROR_STATE_NONE;
|
* access to the original. */
|
||||||
disk->mirrorJob = VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN;
|
virStorageSourceFree(disk->src);
|
||||||
ignore_value(qemuDomainDetermineDiskChain(driver, vm, disk,
|
disk->src = disk->mirror;
|
||||||
true, true));
|
} else {
|
||||||
disk->blockjob = false;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case VIR_DOMAIN_BLOCK_JOB_READY:
|
|
||||||
disk->mirrorState = VIR_DOMAIN_DISK_MIRROR_STATE_READY;
|
|
||||||
save = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case VIR_DOMAIN_BLOCK_JOB_FAILED:
|
|
||||||
case VIR_DOMAIN_BLOCK_JOB_CANCELED:
|
|
||||||
virStorageSourceFree(disk->mirror);
|
virStorageSourceFree(disk->mirror);
|
||||||
disk->mirror = NULL;
|
|
||||||
disk->mirrorState = status == VIR_DOMAIN_BLOCK_JOB_FAILED ?
|
|
||||||
VIR_DOMAIN_DISK_MIRROR_STATE_ABORT : VIR_DOMAIN_DISK_MIRROR_STATE_NONE;
|
|
||||||
disk->mirrorJob = VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN;
|
|
||||||
save = true;
|
|
||||||
disk->blockjob = false;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case VIR_DOMAIN_BLOCK_JOB_LAST:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Recompute the cached backing chain to match our
|
||||||
|
* updates. Better would be storing the chain ourselves
|
||||||
|
* rather than reprobing, but we haven't quite completed
|
||||||
|
* that conversion to use our XML tracking. */
|
||||||
|
disk->mirror = NULL;
|
||||||
|
save = disk->mirrorState != VIR_DOMAIN_DISK_MIRROR_STATE_NONE;
|
||||||
|
disk->mirrorState = VIR_DOMAIN_DISK_MIRROR_STATE_NONE;
|
||||||
|
disk->mirrorJob = VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN;
|
||||||
|
ignore_value(qemuDomainDetermineDiskChain(driver, vm, disk,
|
||||||
|
true, true));
|
||||||
|
disk->blockjob = false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VIR_DOMAIN_BLOCK_JOB_READY:
|
||||||
|
disk->mirrorState = VIR_DOMAIN_DISK_MIRROR_STATE_READY;
|
||||||
|
save = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VIR_DOMAIN_BLOCK_JOB_FAILED:
|
||||||
|
case VIR_DOMAIN_BLOCK_JOB_CANCELED:
|
||||||
|
virStorageSourceFree(disk->mirror);
|
||||||
|
disk->mirror = NULL;
|
||||||
|
disk->mirrorState = status == VIR_DOMAIN_BLOCK_JOB_FAILED ?
|
||||||
|
VIR_DOMAIN_DISK_MIRROR_STATE_ABORT : VIR_DOMAIN_DISK_MIRROR_STATE_NONE;
|
||||||
|
disk->mirrorJob = VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN;
|
||||||
|
save = true;
|
||||||
|
disk->blockjob = false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VIR_DOMAIN_BLOCK_JOB_LAST:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (save) {
|
if (save) {
|
||||||
@ -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