]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemuMigrationDstPrecreateStorage: Fix and clarify logic
authorPeter Krempa <pkrempa@redhat.com>
Wed, 6 Dec 2023 13:47:01 +0000 (14:47 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 13 Dec 2023 19:15:49 +0000 (20:15 +0100)
While it's intended that qemuMigrationDstPrecreateDisk is called with
any kind of the disk, the logic in qemuMigrationDstPrecreateStorage
which checks the existence of the image wouldn't properly handle e.g.
network backed disks, where it would attempt to use virFileExists() on
the disk's 'src->path'.

Fix the logic by first skipping disks not meant for migration, then do
the existence check only when 'disk->src' is local storage.

Since qemuMigrationDstPrecreateDisk has a debug statement there's no
need to have an extra one right before calling into it.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_migration.c

index 356b7c382b5f84a6c8e93d1f6a1e4f904d6e6cd4..f4e99087d898b52f70457b4f139610388d2fd002 100644 (file)
@@ -448,7 +448,7 @@ qemuMigrationDstPrecreateStorage(virDomainObj *vm,
 
     for (i = 0; i < nbd->ndisks; i++) {
         virDomainDiskDef *disk;
-        const char *diskSrcPath;
+        const char *diskSrcPath = NULL;
         g_autofree char *nvmePath = NULL;
 
         VIR_DEBUG("Looking up disk target '%s' (capacity=%llu)",
@@ -461,19 +461,28 @@ qemuMigrationDstPrecreateStorage(virDomainObj *vm,
             return -1;
         }
 
+        /* Skip disks we don't want to migrate. */
+        if (!qemuMigrationAnyCopyDisk(disk, nmigrate_disks, migrate_disks))
+            continue;
+
         if (disk->src->type == VIR_STORAGE_TYPE_NVME) {
             virPCIDeviceAddressGetSysfsFile(&disk->src->nvme->pciAddr, &nvmePath);
             diskSrcPath = nvmePath;
-        } else {
+        } else if (virStorageSourceIsLocalStorage(disk->src)) {
             diskSrcPath = virDomainDiskGetSource(disk);
         }
 
-        /* Skip disks we don't want to migrate and already existing disks. */
-        if (!qemuMigrationAnyCopyDisk(disk, nmigrate_disks, migrate_disks) ||
-            (diskSrcPath && virFileExists(diskSrcPath))) {
-            continue;
+        if (diskSrcPath) {
+
+            /* don't pre-create existing disks */
+            if (virFileExists(diskSrcPath)) {
+                VIR_DEBUG("Skipping pre-create of existing source for disk '%s'", disk->dst);
+                continue;
+            }
         }
 
+        /* create the storage - if supported */
+
         if (incremental) {
             virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
                            _("pre-creation of storage target '%1$s' for incremental storage migration of disk '%2$s' is not supported"),
@@ -481,8 +490,6 @@ qemuMigrationDstPrecreateStorage(virDomainObj *vm,
             return -1;
         }
 
-        VIR_DEBUG("Proceeding with disk source %s", NULLSTR(diskSrcPath));
-
         if (qemuMigrationDstPrecreateDisk(&conn, disk, nbd->disks[i].capacity) < 0)
             return -1;
     }