1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-23 21:34:54 +03:00

qemu: migration: Split out setup of the migration target

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>
This commit is contained in:
Peter Krempa 2019-12-06 17:47:46 +01:00
parent 0d0b490a32
commit 69abc80f5e

View File

@ -776,6 +776,43 @@ qemuMigrationSrcNBDCopyCancel(virQEMUDriverPtr driver,
}
static virStorageSourcePtr
qemuMigrationSrcNBDStorageCopyBlockdevPrepareSource(virDomainDiskDefPtr disk,
const char *host,
int port,
const char *tlsAlias)
{
g_autoptr(virStorageSource) copysrc = NULL;
if (!(copysrc = virStorageSourceNew()))
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 NULL;
if (!(copysrc->path = qemuAliasDiskDriveFromDisk(disk)))
return NULL;
copysrc->hosts = g_new0(virStorageNetHostDef, 1);
copysrc->nhosts = 1;
copysrc->hosts->transport = VIR_STORAGE_NET_HOST_TRANS_TCP;
copysrc->hosts->port = port;
copysrc->hosts->name = g_strdup(host);
copysrc->tlsAlias = g_strdup(tlsAlias);
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,
@ -794,31 +831,9 @@ qemuMigrationSrcNBDStorageCopyBlockdev(virQEMUDriverPtr driver,
VIR_DEBUG("starting blockdev mirror for disk=%s to host=%s", diskAlias, host);
if (!(copysrc = virStorageSourceNew()))
if (!(copysrc = qemuMigrationSrcNBDStorageCopyBlockdevPrepareSource(disk, host, port, tlsAlias)))
return -1;
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;
copysrc->path = g_strdup(diskAlias);
if (VIR_ALLOC_N(copysrc->hosts, 1) < 0)
return -1;
copysrc->nhosts = 1;
copysrc->hosts->transport = VIR_STORAGE_NET_HOST_TRANS_TCP;
copysrc->hosts->port = port;
copysrc->hosts->name = g_strdup(host);
copysrc->tlsAlias = g_strdup(tlsAlias);
copysrc->nodestorage = g_strdup_printf("migration-%s-storage", disk->dst);
copysrc->nodeformat = g_strdup_printf("migration-%s-format", disk->dst);
/* Migration via blockdev-mirror was supported sooner than the auto-read-only
* feature was added to qemu */
if (!(data = qemuBlockStorageSourceAttachPrepareBlockdev(copysrc,