[PATCH 09/11] qemu: process: Extract pre-start checks into a function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 |  2 +-
 src/qemu/qemu_process.c   | 41 ++++++++++++++++++++++++++++++++---------
 src/qemu/qemu_process.h   |  9 ++++++++-
 3 files changed, 41 insertions(+), 11 deletions(-)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 51e7125..c13e1b5 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -3552,7 +3552,7 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
         goto stopjob;
     }

-    if (qemuProcessInit(driver, vm, true) < 0)
+    if (qemuProcessInit(driver, vm, true, false) < 0)
         goto stopjob;
     stopProcess = true;

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 0f617da..ea1e103 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -4401,6 +4401,32 @@ qemuProcessMakeDir(virQEMUDriverPtr driver,


 /**
+ * qemuProcessStartValidate:
+ * @vm: domain object
+ * @qemuCaps: emulator capabilities
+ * @migration: restoration of eixting state
+ *
+ * This function agregates 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:
  *
  * Prepares the domain up to the point when priv->qemuCaps is initialized. The
@@ -4411,7 +4437,8 @@ qemuProcessMakeDir(virQEMUDriverPtr driver,
 int
 qemuProcessInit(virQEMUDriverPtr driver,
                 virDomainObjPtr vm,
-                bool migration)
+                bool migration,
+                bool snap)
 {
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
     virCapsPtr caps = NULL;
@@ -4440,6 +4467,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");
@@ -4640,9 +4670,6 @@ qemuProcessLaunch(virConnectPtr conn,
         }
     }

-    if (qemuValidateCpuCount(vm->def, priv->qemuCaps) < 0)
-        goto cleanup;
-
     if (qemuAssignDeviceAliases(vm->def, priv->qemuCaps) < 0)
         goto cleanup;

@@ -4666,10 +4693,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.
      */
@@ -5112,7 +5135,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) {
diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h
index cb5cee1..907a58d 100644
--- a/src/qemu/qemu_process.h
+++ b/src/qemu/qemu_process.h
@@ -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,
-- 
2.6.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]