]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: migration: Split out setup of the migration target
authorPeter Krempa <pkrempa@redhat.com>
Fri, 6 Dec 2019 16:47:46 +0000 (17:47 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 9 Dec 2019 06:11:24 +0000 (07:11 +0100)
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@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
src/qemu/qemu_migration.c

index 9062be38ab824ee349cf9a3789aa84d55c80295a..8bf23e9f308d1ca6aa35f00b674c06e311a79cce 100644 (file)
@@ -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(&copysrc);
+}
+
+
+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,