Separate out allocation of the virStorageSource corresponding to the target NBD export of the migration. As part of the splitout we allocate the export name explicitly as that one must not change regardless whether blockdev is used or not to provide compatibility. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/qemu/qemu_migration.c | 55 +++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 9062be38ab..8bf23e9f30 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -776,38 +776,28 @@ qemuMigrationSrcNBDCopyCancel(virQEMUDriverPtr driver, } -static int -qemuMigrationSrcNBDStorageCopyBlockdev(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainDiskDefPtr disk, - const char *diskAlias, - const char *host, - int port, - unsigned long long mirror_speed, - unsigned int mirror_shallow, - const char *tlsAlias) +static virStorageSourcePtr +qemuMigrationSrcNBDStorageCopyBlockdevPrepareSource(virDomainDiskDefPtr disk, + const char *host, + int port, + const char *tlsAlias) { - g_autoptr(qemuBlockStorageSourceAttachData) data = NULL; - qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk); - int mon_ret = 0; g_autoptr(virStorageSource) copysrc = NULL; - VIR_DEBUG("starting blockdev mirror for disk=%s to host=%s", diskAlias, host); - if (!(copysrc = virStorageSourceNew())) - return -1; + return NULL; copysrc->type = VIR_STORAGE_TYPE_NETWORK; copysrc->protocol = VIR_STORAGE_NET_PROTOCOL_NBD; copysrc->format = VIR_STORAGE_FILE_RAW; if (!(copysrc->backingStore = virStorageSourceNew())) - return -1; + return NULL; - copysrc->path = g_strdup(diskAlias); + if (!(copysrc->path = qemuAliasDiskDriveFromDisk(disk))) + return NULL; - if (VIR_ALLOC_N(copysrc->hosts, 1) < 0) - return -1; + copysrc->hosts = g_new0(virStorageNetHostDef, 1); copysrc->nhosts = 1; copysrc->hosts->transport = VIR_STORAGE_NET_HOST_TRANS_TCP; @@ -819,6 +809,31 @@ qemuMigrationSrcNBDStorageCopyBlockdev(virQEMUDriverPtr driver, copysrc->nodestorage = g_strdup_printf("migration-%s-storage", disk->dst); copysrc->nodeformat = g_strdup_printf("migration-%s-format", disk->dst); + return g_steal_pointer(©src); +} + + +static int +qemuMigrationSrcNBDStorageCopyBlockdev(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainDiskDefPtr disk, + const char *diskAlias, + const char *host, + int port, + unsigned long long mirror_speed, + unsigned int mirror_shallow, + const char *tlsAlias) +{ + g_autoptr(qemuBlockStorageSourceAttachData) data = NULL; + qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk); + int mon_ret = 0; + g_autoptr(virStorageSource) copysrc = NULL; + + VIR_DEBUG("starting blockdev mirror for disk=%s to host=%s", diskAlias, host); + + if (!(copysrc = qemuMigrationSrcNBDStorageCopyBlockdevPrepareSource(disk, host, port, tlsAlias))) + return -1; + /* Migration via blockdev-mirror was supported sooner than the auto-read-only * feature was added to qemu */ if (!(data = qemuBlockStorageSourceAttachPrepareBlockdev(copysrc, -- 2.23.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list