From e534d19b5d0b5decf53733d7f3ff6d439f9a2a9d Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Tue, 14 Nov 2023 17:07:44 +0100 Subject: [PATCH] qemuMigrationSrcNBDCopyCancel: Use qemuBlockStorageSourceAttachRollback to detach migration NBD blockdevs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rewrite the code to use the common tooling for removing blockdevs instead of the ad-hoc qemuBlockStorageSourceDetachOneBlockdev helper. Use of the common infrastructure will properly handle cases when the raw driver is ommited from the block graph. Since the TLS data object is shared for all migration QMP commands and objects we need to strip its alias from the definition of the storage source before attempting to detach it. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- src/qemu/qemu_migration.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index ac58aa1a8c..0f4c6dbe98 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -938,12 +938,26 @@ qemuMigrationSrcNBDCopyCancel(virDomainObj *vm, for (i = 0; i < vm->def->ndisks; i++) { virDomainDiskDef *disk = vm->def->disks[i]; qemuDomainDiskPrivate *diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk); + g_autoptr(qemuBlockStorageSourceAttachData) data = NULL; if (!diskPriv->migrSource) continue; - qemuBlockStorageSourceDetachOneBlockdev(vm, asyncJob, - diskPriv->migrSource); + /* remove the alias of the TLS object when we're about to detach the + * migration NBD blockdev as the TLS object is shared for the migration + * and we don't want to detach it. The alias is not needed after + * the JSON object of the blockdev props is formatted */ + g_clear_pointer(&diskPriv->migrSource->tlsAlias, g_free); + + data = qemuBlockStorageSourceDetachPrepare(diskPriv->migrSource); + + if (qemuDomainObjEnterMonitorAsync(vm, asyncJob) < 0) + goto cleanup; + + qemuBlockStorageSourceAttachRollback(qemuDomainGetMonitor(vm), data); + + qemuDomainObjExitMonitor(vm); + g_clear_pointer(&diskPriv->migrSource, virObjectUnref); }