]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: process: Extract pre-start checks into a function
authorPeter Krempa <pkrempa@redhat.com>
Thu, 4 Feb 2016 14:25:29 +0000 (15:25 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 8 Feb 2016 08:19:48 +0000 (09:19 +0100)
When starting a qemu process there are certain checks done to ensure
that the configuration makes sense. Extract them into a separate
function so that they can be reused in the test code.

src/qemu/qemu_migration.c
src/qemu/qemu_process.c
src/qemu/qemu_process.h

index 1443d969df5fc71038e92737263fd95a56027d17..793e412070a3d0ed3a7e4298171ec2aa2d97f4a5 100644 (file)
@@ -3462,7 +3462,7 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
         goto stopjob;
     }
 
-    if (qemuProcessInit(driver, vm, true) < 0)
+    if (qemuProcessInit(driver, vm, true, false) < 0)
         goto stopjob;
     stopProcess = true;
 
index 13974ab4657510bffcdf7033dce468da4ea4aa58..fded697bcd97845d74650e086cfbf88d55834764 100644 (file)
@@ -4401,6 +4401,32 @@ qemuProcessMakeDir(virQEMUDriverPtr driver,
 }
 
 
+/**
+ * qemuProcessStartValidate:
+ * @vm: domain object
+ * @qemuCaps: emulator capabilities
+ * @migration: restoration of existing state
+ *
+ * This function aggregates checks independent from host state done prior to
+ * start of a VM.
+ */
+int
+qemuProcessStartValidate(virDomainDefPtr def,
+                         virQEMUCapsPtr qemuCaps,
+                         bool migration,
+                         bool snapshot)
+{
+    if (qemuValidateCpuCount(def, qemuCaps) < 0)
+        return -1;
+
+    if (!migration && !snapshot &&
+        virDomainDefCheckDuplicateDiskInfo(def) < 0)
+        return -1;
+
+    return 0;
+}
+
+
 /**
  * qemuProcessInit:
  *
@@ -4412,7 +4438,8 @@ qemuProcessMakeDir(virQEMUDriverPtr driver,
 int
 qemuProcessInit(virQEMUDriverPtr driver,
                 virDomainObjPtr vm,
-                bool migration)
+                bool migration,
+                bool snap)
 {
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
     virCapsPtr caps = NULL;
@@ -4441,6 +4468,9 @@ qemuProcessInit(virQEMUDriverPtr driver,
                                                       vm->def->os.machine)))
         goto cleanup;
 
+    if (qemuProcessStartValidate(vm->def, priv->qemuCaps, migration, snap) < 0)
+        goto cleanup;
+
     /* Some things, paths, ... are generated here and we want them to persist.
      * Fill them in prior to setting the domain def as transient. */
     VIR_DEBUG("Generating paths");
@@ -4641,9 +4671,6 @@ qemuProcessLaunch(virConnectPtr conn,
         }
     }
 
-    if (qemuValidateCpuCount(vm->def, priv->qemuCaps) < 0)
-        goto cleanup;
-
     if (qemuAssignDeviceAliases(vm->def, priv->qemuCaps) < 0)
         goto cleanup;
 
@@ -4667,10 +4694,6 @@ qemuProcessLaunch(virConnectPtr conn,
             goto cleanup;
     }
 
-    if (!incoming && !snapshot &&
-        virDomainDefCheckDuplicateDiskInfo(vm->def) < 0)
-        goto cleanup;
-
     /* "volume" type disk's source must be translated before
      * cgroup and security setting.
      */
@@ -5113,7 +5136,7 @@ qemuProcessStart(virConnectPtr conn,
                       VIR_QEMU_PROCESS_START_PAUSED |
                       VIR_QEMU_PROCESS_START_AUTODESTROY, cleanup);
 
-    if (qemuProcessInit(driver, vm, !!migrateFrom) < 0)
+    if (qemuProcessInit(driver, vm, !!migrateFrom, !!snapshot) < 0)
         goto cleanup;
 
     if (migrateFrom) {
index cb5cee1626711d729ae7dd7a5e8f4a26caa182a5..907a58df3b150ee8872a1789553ef5d2fd76b631 100644 (file)
@@ -81,9 +81,16 @@ int qemuProcessStart(virConnectPtr conn,
                      virNetDevVPortProfileOp vmop,
                      unsigned int flags);
 
+
+int qemuProcessStartValidate(virDomainDefPtr def,
+                             virQEMUCapsPtr qemuCaps,
+                             bool migration,
+                             bool snap);
+
 int qemuProcessInit(virQEMUDriverPtr driver,
                     virDomainObjPtr vm,
-                    bool migration);
+                    bool migration,
+                    bool snap);
 
 int qemuProcessLaunch(virConnectPtr conn,
                       virQEMUDriverPtr driver,