[PATCH 07/12] qemu_process: move checks to qemuProcessStartValidate

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

 



Move all code that checks host and domain.  Do not check host if we use
VIR_QEMU_PROCESS_START_PRETEND flag.

Signed-off-by: Pavel Hrdina <phrdina@xxxxxxxxxx>
---
 src/qemu/qemu_driver.c    |   4 +-
 src/qemu/qemu_migration.c |   2 +-
 src/qemu/qemu_process.c   | 168 ++++++++++++++++++++++++----------------------
 src/qemu/qemu_process.h   |   9 ++-
 tests/qemuxml2argvtest.c  |   5 +-
 5 files changed, 103 insertions(+), 85 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 24fa3ec..1862c60 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -6985,7 +6985,9 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn,
                                             VIR_DOMAIN_DEF_PARSE_ABI_UPDATE)))
         goto cleanup;
 
-    if (qemuProcessStartValidate(driver, vm, qemuCaps, false, false) < 0)
+    if (qemuProcessStartValidate(driver, vm, qemuCaps, false, false,
+                                 VIR_QEMU_PROCESS_START_COLD |
+                                 VIR_QEMU_PROCESS_START_PRETEND) < 0)
         goto cleanup;
 
     /* Generate per-domain paths because we don't have the domain object */
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index f204855..8c7fd5c 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -3465,7 +3465,7 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
     }
 
     if (qemuProcessInit(driver, vm, QEMU_ASYNC_JOB_MIGRATION_IN,
-                        true, false) < 0)
+                        true, false, VIR_QEMU_PROCESS_START_AUTODESTROY) < 0)
         goto stopjob;
     stopProcess = true;
 
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 32efafb..6265cf5 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -4327,18 +4327,97 @@ qemuProcessMakeDir(virQEMUDriverPtr driver,
  * start of a VM.
  */
 int
-qemuProcessStartValidate(virDomainDefPtr def,
+qemuProcessStartValidate(virQEMUDriverPtr driver,
+                         virDomainObjPtr vm,
                          virQEMUCapsPtr qemuCaps,
                          bool migration,
-                         bool snapshot)
+                         bool snapshot,
+                         unsigned int flags)
 {
-    if (qemuValidateCpuCount(def, qemuCaps) < 0)
+    bool check_shmem = false;
+    size_t i;
+
+    if (!(flags & VIR_QEMU_PROCESS_START_PRETEND)) {
+        if (vm->def->virtType == VIR_DOMAIN_VIRT_KVM) {
+            VIR_DEBUG("Checking for KVM availability");
+            if (!virFileExists("/dev/kvm")) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                               _("Domain requires KVM, but it is not available. "
+                                 "Check that virtualization is enabled in the "
+                                 "host BIOS, and host configuration is setup to "
+                                 "load the kvm modules."));
+                return -1;
+            }
+        }
+
+        if (qemuDomainCheckDiskPresence(driver, vm,
+                                        flags & VIR_QEMU_PROCESS_START_COLD) < 0)
+            return -1;
+
+        VIR_DEBUG("Checking domain and device security labels");
+        if (virSecurityManagerCheckAllLabel(driver->securityManager, vm->def) < 0)
+            return -1;
+
+    }
+
+    if (qemuValidateCpuCount(vm->def, qemuCaps) < 0)
         return -1;
 
     if (!migration && !snapshot &&
-        virDomainDefCheckDuplicateDiskInfo(def) < 0)
+        virDomainDefCheckDuplicateDiskInfo(vm->def) < 0)
         return -1;
 
+    if (vm->def->mem.min_guarantee) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("Parameter 'min_guarantee' "
+                         "not supported by QEMU."));
+        return -1;
+    }
+
+    VIR_DEBUG("Checking for any possible (non-fatal) issues");
+
+    /*
+     * For vhost-user to work, the domain has to have some type of
+     * shared memory configured.  We're not the proper ones to judge
+     * whether shared hugepages or shm are enough and will be in the
+     * future, so we'll just warn in case neither is configured.
+     * Moreover failing would give the false illusion that libvirt is
+     * really checking that everything works before running the domain
+     * and not only we are unable to do that, but it's also not our
+     * aim to do so.
+     */
+    for (i = 0; i < vm->def->nnets; i++) {
+        if (virDomainNetGetActualType(vm->def->nets[i]) ==
+                                      VIR_DOMAIN_NET_TYPE_VHOSTUSER) {
+            check_shmem = true;
+            break;
+        }
+    }
+
+    if (check_shmem) {
+        bool shmem = vm->def->nshmems;
+
+        /*
+         * This check is by no means complete.  We merely check
+         * whether there are *some* hugepages enabled and *some* NUMA
+         * nodes with shared memory access.
+         */
+        if (!shmem && vm->def->mem.nhugepages) {
+            for (i = 0; i < virDomainNumaGetNodeCount(vm->def->numa); i++) {
+                if (virDomainNumaGetNodeMemoryAccessMode(vm->def->numa, i) ==
+                    VIR_NUMA_MEM_ACCESS_SHARED) {
+                    shmem = true;
+                    break;
+                }
+            }
+        }
+
+        if (!shmem) {
+            VIR_WARN("Detected vhost-user interface without any shared memory, "
+                     "the interface might not be operational");
+        }
+    }
+
     return 0;
 }
 
@@ -4356,7 +4435,8 @@ qemuProcessInit(virQEMUDriverPtr driver,
                 virDomainObjPtr vm,
                 qemuDomainAsyncJob asyncJob,
                 bool migration,
-                bool snap)
+                bool snap,
+                unsigned int flags)
 {
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
     virCapsPtr caps = NULL;
@@ -4385,7 +4465,8 @@ qemuProcessInit(virQEMUDriverPtr driver,
                                                       vm->def->os.machine)))
         goto cleanup;
 
-    if (qemuProcessStartValidate(vm->def, priv->qemuCaps, migration, snap) < 0)
+    if (qemuProcessStartValidate(driver, vm, priv->qemuCaps,
+                                 migration, snap, flags) < 0)
         goto cleanup;
 
     /* Do this upfront, so any part of the startup process can add
@@ -4955,12 +5036,10 @@ qemuProcessLaunch(virConnectPtr conn,
     qemuDomainObjPrivatePtr priv = vm->privateData;
     virCommandPtr cmd = NULL;
     struct qemuProcessHookData hookData;
-    size_t i;
     virQEMUDriverConfigPtr cfg;
     virCapsPtr caps = NULL;
     size_t nnicindexes = 0;
     int *nicindexes = NULL;
-    bool check_shmem = false;
 
     VIR_DEBUG("vm=%p name=%s id=%d asyncJob=%d "
               "incoming.launchURI=%s incoming.deferredURI=%s "
@@ -4990,38 +5069,12 @@ qemuProcessLaunch(virConnectPtr conn,
     if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
         goto cleanup;
 
-    VIR_DEBUG("Checking domain and device security labels");
-    if (virSecurityManagerCheckAllLabel(driver->securityManager, vm->def) < 0)
-        goto cleanup;
-
     VIR_DEBUG("Creating domain log file");
     if (!(logCtxt = qemuDomainLogContextNew(driver, vm,
                                             QEMU_DOMAIN_LOG_CONTEXT_MODE_START)))
         goto cleanup;
     logfile = qemuDomainLogContextGetWriteFD(logCtxt);
 
-    if (vm->def->virtType == VIR_DOMAIN_VIRT_KVM) {
-        VIR_DEBUG("Checking for KVM availability");
-        if (!virFileExists("/dev/kvm")) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("Domain requires KVM, but it is not available. "
-                             "Check that virtualization is enabled in the host BIOS, "
-                             "and host configuration is setup to load the kvm modules."));
-            goto cleanup;
-        }
-    }
-
-    if (qemuDomainCheckDiskPresence(driver, vm,
-                                    flags & VIR_QEMU_PROCESS_START_COLD) < 0)
-        goto cleanup;
-
-    if (vm->def->mem.min_guarantee) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                       _("Parameter 'min_guarantee' "
-                         "not supported by QEMU."));
-        goto cleanup;
-    }
-
     if (qemuDomainSetPrivatePaths(&priv->libDir,
                                   &priv->channelTargetDir,
                                   cfg->libDir,
@@ -5030,50 +5083,6 @@ qemuProcessLaunch(virConnectPtr conn,
                                   vm->def->id) < 0)
         goto cleanup;
 
-    VIR_DEBUG("Checking for any possible (non-fatal) issues");
-
-    /*
-     * For vhost-user to work, the domain has to have some type of
-     * shared memory configured.  We're not the proper ones to judge
-     * whether shared hugepages or shm are enough and will be in the
-     * future, so we'll just warn in case neither is configured.
-     * Moreover failing would give the false illusion that libvirt is
-     * really checking that everything works before running the domain
-     * and not only we are unable to do that, but it's also not our
-     * aim to do so.
-     */
-    for (i = 0; i < vm->def->nnets; i++) {
-        if (virDomainNetGetActualType(vm->def->nets[i]) ==
-                                      VIR_DOMAIN_NET_TYPE_VHOSTUSER) {
-            check_shmem = true;
-            break;
-        }
-    }
-
-    if (check_shmem) {
-        bool shmem = vm->def->nshmems;
-
-        /*
-         * This check is by no means complete.  We merely check
-         * whether there are *some* hugepages enabled and *some* NUMA
-         * nodes with shared memory access.
-         */
-        if (!shmem && vm->def->mem.nhugepages) {
-            for (i = 0; i < virDomainNumaGetNodeCount(vm->def->numa); i++) {
-                if (virDomainNumaGetNodeMemoryAccessMode(vm->def->numa, i) ==
-                    VIR_NUMA_MEM_ACCESS_SHARED) {
-                    shmem = true;
-                    break;
-                }
-            }
-        }
-
-        if (!shmem) {
-            VIR_WARN("Detected vhost-user interface without any shared memory, "
-                     "the interface might not be operational");
-        }
-    }
-
     VIR_DEBUG("Building emulator command line");
     if (!(cmd = qemuBuildCommandLine(conn, driver,
                                      qemuDomainLogContextGetManager(logCtxt),
@@ -5396,7 +5405,8 @@ qemuProcessStart(virConnectPtr conn,
                       VIR_QEMU_PROCESS_START_PAUSED |
                       VIR_QEMU_PROCESS_START_AUTODESTROY, cleanup);
 
-    if (qemuProcessInit(driver, vm, asyncJob, !!migrateFrom, !!snapshot) < 0)
+    if (qemuProcessInit(driver, vm, asyncJob, !!migrateFrom,
+                        !!snapshot, flags) < 0)
         goto cleanup;
 
     if (migrateFrom) {
diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h
index 049c097..4820047 100644
--- a/src/qemu/qemu_process.h
+++ b/src/qemu/qemu_process.h
@@ -82,16 +82,19 @@ int qemuProcessStart(virConnectPtr conn,
                      unsigned int flags);
 
 
-int qemuProcessStartValidate(virDomainDefPtr def,
+int qemuProcessStartValidate(virQEMUDriverPtr driver,
+                             virDomainObjPtr vm,
                              virQEMUCapsPtr qemuCaps,
                              bool migration,
-                             bool snap);
+                             bool snap,
+                             unsigned int flags);
 
 int qemuProcessInit(virQEMUDriverPtr driver,
                     virDomainObjPtr vm,
                     qemuDomainAsyncJob asyncJob,
                     bool migration,
-                    bool snap);
+                    bool snap,
+                    unsigned int flags);
 
 int qemuProcessPrepareDomain(virConnectPtr conn,
                              virQEMUDriverPtr driver,
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 135fbd5..2c9dd1c 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -350,7 +350,10 @@ static int testCompareXMLToArgvFiles(const char *xml,
             goto out;
     }
 
-    if (qemuProcessStartValidate(&driver, vm, extraFlags, !!migrateURI, false) < 0) {
+    if (qemuProcessStartValidate(&driver, vm, extraFlags,
+                                 !!migrateURI, false,
+                                 VIR_QEMU_PROCESS_START_COLD |
+                                 VIR_QEMU_PROCESS_START_PRETEND) < 0) {
         if (flags & FLAG_EXPECT_FAILURE)
             goto ok;
         goto out;
-- 
2.7.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]