]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: blockjob: Update 'mirror' of a copy job before removing images
authorPeter Krempa <pkrempa@redhat.com>
Fri, 27 Sep 2024 06:57:08 +0000 (08:57 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 1 Oct 2024 10:54:40 +0000 (12:54 +0200)
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>
src/qemu/qemu_blockjob.c

index 42856df6d41f10770ffcc4b5ba94895831180f43..9c56d5cb9549116f090cf092f7f69df6174789fa 100644 (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);
 }