]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: migration: Extract validation of disk target list
authorPeter Krempa <pkrempa@redhat.com>
Mon, 30 Sep 2024 08:38:58 +0000 (10:38 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 1 Oct 2024 10:57:02 +0000 (12:57 +0200)
The migration code is checking the disk list provided via
VIR_MIGRATE_PARAM_MIGRATE_DISKS against existing disks. Extract it to a
helper function as we'll be passing another list of disk targets soon.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
src/qemu/qemu_migration.c

index bb466bf1eedced80e7b0ac5abfc112887c2bbbdb..a4efd8bfa7faec96d57a4db3830bbc27e57151ec 100644 (file)
@@ -2576,6 +2576,37 @@ qemuMigrationSrcBeginXML(virDomainObj *vm,
 }
 
 
+/**
+ * qemuMigrationSrcBeginPhaseValidateDiskTargetList:
+ * @vm: domain object
+ * @disks: NULL-terminated list of disk 'dst' strings to validate
+ *
+ * Validates that all members of the @disk list are valid disk targets.
+ */
+static int
+qemuMigrationSrcBeginPhaseValidateDiskTargetList(virDomainObj *vm,
+                                                 const char **disks)
+{
+    size_t i;
+    const char **d;
+
+    for (d = disks; *d; d++) {
+        for (i = 0; i < vm->def->ndisks; i++) {
+            if (STREQ(vm->def->disks[i]->dst, *d))
+                break;
+        }
+
+        if (i == vm->def->ndisks) {
+            virReportError(VIR_ERR_INVALID_ARG,
+                           _("disk target %1$s not found"), *d);
+            return -1;
+        }
+    }
+
+    return 0;
+}
+
+
 /* The caller is supposed to lock the vm and start a migration job. */
 static char *
 qemuMigrationSrcBeginPhase(virQEMUDriver *driver,
@@ -2660,24 +2691,9 @@ qemuMigrationSrcBeginPhase(virQEMUDriver *driver,
             return NULL;
         }
 
-        if (migrate_disks) {
-            size_t j;
-            const char **d;
-
-            /* Check user requested only known disk targets. */
-            for (d = migrate_disks; *d; d++) {
-                for (j = 0; j < vm->def->ndisks; j++) {
-                    if (STREQ(vm->def->disks[j]->dst, *d))
-                        break;
-                }
-
-                if (j == vm->def->ndisks) {
-                    virReportError(VIR_ERR_INVALID_ARG,
-                                   _("disk target %1$s not found"), *d);
-                    return NULL;
-                }
-            }
-        }
+        if (migrate_disks &&
+            qemuMigrationSrcBeginPhaseValidateDiskTargetList(vm, migrate_disks) < 0)
+            return NULL;
 
         priv->nbdPort = 0;