qemu: migration: don't open storage driver too early

If storage migration is requested, and the destination storage does
not exist on the remote host, qemu's migration support will call
into the libvirt storage driver to precreate the destination storage.

The storage driver virConnectPtr is opened too early though, adding
an unnecessary dependency on the storage driver for several cases
that don't require it. This currently requires kubevirt to install
the storage driver even though they aren't actually using it.

Push the virGetConnectStorage calls to right before the cases they are
actually needed.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
Cole Robinson 2020-10-07 15:20:30 -04:00
parent 6ad23525e4
commit accdc0e773
1 changed files with 16 additions and 8 deletions

View File

@ -169,7 +169,7 @@ qemuMigrationSrcRestoreDomainState(virQEMUDriverPtr driver, virDomainObjPtr vm)
static int
qemuMigrationDstPrecreateDisk(virConnectPtr conn,
qemuMigrationDstPrecreateDisk(virConnectPtr *conn,
virDomainDiskDefPtr disk,
unsigned long long capacity)
{
@ -204,7 +204,12 @@ qemuMigrationDstPrecreateDisk(virConnectPtr conn,
*volName = '\0';
volName++;
if (!(pool = virStoragePoolLookupByTargetPath(conn, basePath)))
if (!*conn) {
if (!(*conn = virGetConnectStorage()))
goto cleanup;
}
if (!(pool = virStoragePoolLookupByTargetPath(*conn, basePath)))
goto cleanup;
format = virStorageFileFormatTypeToString(disk->src->format);
if (disk->src->format == VIR_STORAGE_FILE_QCOW2)
@ -212,7 +217,12 @@ qemuMigrationDstPrecreateDisk(virConnectPtr conn,
break;
case VIR_STORAGE_TYPE_VOLUME:
if (!(pool = virStoragePoolLookupByName(conn, disk->src->srcpool->pool)))
if (!*conn) {
if (!(*conn = virGetConnectStorage()))
goto cleanup;
}
if (!(pool = virStoragePoolLookupByName(*conn, disk->src->srcpool->pool)))
goto cleanup;
format = virStorageFileFormatTypeToString(disk->src->format);
volName = disk->src->srcpool->volume;
@ -304,14 +314,11 @@ qemuMigrationDstPrecreateStorage(virDomainObjPtr vm,
{
int ret = -1;
size_t i = 0;
virConnectPtr conn;
virConnectPtr conn = NULL;
if (!nbd || !nbd->ndisks)
return 0;
if (!(conn = virGetConnectStorage()))
return -1;
for (i = 0; i < nbd->ndisks; i++) {
virDomainDiskDefPtr disk;
const char *diskSrcPath;
@ -349,7 +356,8 @@ qemuMigrationDstPrecreateStorage(virDomainObjPtr vm,
VIR_DEBUG("Proceeding with disk source %s", NULLSTR(diskSrcPath));
if (qemuMigrationDstPrecreateDisk(conn, disk, nbd->disks[i].capacity) < 0)
if (qemuMigrationDstPrecreateDisk(&conn,
disk, nbd->disks[i].capacity) < 0)
goto cleanup;
}