qemu: blockjob: Update 'mirror' of a copy job before removing images

When concluding a job with a 'mirror' we first unplugged the appropriate
no-longer used images from qemu and then updated the definition.

Normally this wouldn't be a problem because for any other thread this is
done under the VM lock thus atomic. Unfortunately though, the AppArmor
security backend is using a VM XML to pass data to the helper process
and the state of the definition at that point was unsuitable to format a
valid XML thus making 'virt-aa-helper' report parsing failure.

Since we're removing the images the proper state of the VM definition
indeed should not include the mirror element any more at the point when
the images are removed.

Closes: https://gitlab.com/libvirt/libvirt/-/issues/601
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
Peter Krempa 2024-09-27 08:57:08 +02:00
parent fc4d0e7461
commit b85b60d140

View File

@ -1218,6 +1218,8 @@ qemuBlockJobProcessEventConcludedCopyPivot(virQEMUDriver *driver,
virDomainAsyncJob asyncJob)
{
qemuDomainObjPrivate *priv = vm->privateData;
g_autoptr(virStorageSource) src = NULL;
VIR_DEBUG("copy job '%s' on VM '%s' pivoted", job->name, vm->def->name);
/* mirror may be NULL for copy job corresponding to migration */
@ -1241,9 +1243,11 @@ qemuBlockJobProcessEventConcludedCopyPivot(virQEMUDriver *driver,
qemuBlockJobRewriteConfigDiskSource(vm, job->disk, job->disk->mirror);
qemuBlockJobEventProcessConcludedRemoveChain(driver, vm, asyncJob, job->disk->src);
virObjectUnref(job->disk->src);
src = g_steal_pointer(&job->disk->src);
job->disk->src = g_steal_pointer(&job->disk->mirror);
qemuBlockJobEventProcessConcludedRemoveChain(driver, vm, asyncJob, src);
}
@ -1254,6 +1258,7 @@ qemuBlockJobProcessEventConcludedCopyAbort(virQEMUDriver *driver,
virDomainAsyncJob asyncJob)
{
qemuDomainObjPrivate *priv = vm->privateData;
g_autoptr(virStorageSource) mirror = NULL;
VIR_DEBUG("copy job '%s' on VM '%s' aborted", job->name, vm->def->name);
@ -1277,9 +1282,10 @@ qemuBlockJobProcessEventConcludedCopyAbort(virQEMUDriver *driver,
g_clear_pointer(&job->disk->mirror->backingStore, virObjectUnref);
}
mirror = g_steal_pointer(&job->disk->mirror);
/* activeWrite bitmap is removed automatically here */
qemuBlockJobEventProcessConcludedRemoveChain(driver, vm, asyncJob, job->disk->mirror);
g_clear_pointer(&job->disk->mirror, virObjectUnref);
qemuBlockJobEventProcessConcludedRemoveChain(driver, vm, asyncJob, mirror);
}