]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu_process: move checks to qemuProcessStartValidate
authorPavel Hrdina <phrdina@redhat.com>
Thu, 17 Mar 2016 12:51:20 +0000 (13:51 +0100)
committerPavel Hrdina <phrdina@redhat.com>
Tue, 22 Mar 2016 14:15:48 +0000 (15:15 +0100)
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@redhat.com>
src/qemu/qemu_driver.c
src/qemu/qemu_migration.c
src/qemu/qemu_process.c
src/qemu/qemu_process.h
tests/qemuxml2argvtest.c

index dc4ccc2a9fb9dd41e9a1f1a97f729ff7f8c44723..d9c248e640ce4e769248cf4a989e92d8999db14a 100644 (file)
@@ -6984,7 +6984,9 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn,
                                             VIR_DOMAIN_DEF_PARSE_ABI_UPDATE)))
         goto cleanup;
 
-    if (qemuProcessStartValidate(vm->def, 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 */
index 9f420ee1da1c7d41e470c8061b597aee203484b4..8bc76bf1671d198942667f87e54e681fe45babda 100644 (file)
@@ -3580,7 +3580,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;
 
index 7e3d7925232b95268299a9fedc27bb8e6ed0225f..9cdd9d5cbab83c88d8fc2a97d0a9a6edc7ca2e1c 100644 (file)
@@ -4372,22 +4372,104 @@ qemuProcessMakeDir(virQEMUDriverPtr driver,
  * @qemuCaps: emulator capabilities
  * @migration: restoration of existing state
  *
- * This function aggregates checks independent from host state done prior to
- * start of a VM.
+ * This function aggregates checks done prior to start of a VM.
+ *
+ * Flag VIR_QEMU_PROCESS_START_PRETEND tells, that we don't want to actually
+ * start the domain but create a valid qemu command.  If some code shouldn't be
+ * executed in this case, make sure to check this flag.
  */
 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;
 }
 
@@ -4405,7 +4487,8 @@ qemuProcessInit(virQEMUDriverPtr driver,
                 virDomainObjPtr vm,
                 qemuDomainAsyncJob asyncJob,
                 bool migration,
-                bool snap)
+                bool snap,
+                unsigned int flags)
 {
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
     virCapsPtr caps = NULL;
@@ -4434,7 +4517,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
@@ -5025,12 +5109,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 "
@@ -5060,38 +5142,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,
@@ -5100,50 +5156,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),
@@ -5466,7 +5478,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) {
index 049c0972c309c788e5e50d3c506d06c04c94c2df..48200478e98aa718477f31cb89ae5933d1811ab7 100644 (file)
@@ -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,
index f1c304a592def894ce4c35aa7435bfde9a87189d..1000ab7f3b4d59a0727c397c3f6a5d7565a0f620 100644 (file)
@@ -350,7 +350,10 @@ static int testCompareXMLToArgvFiles(const char *xml,
             goto out;
     }
 
-    if (qemuProcessStartValidate(vm->def, 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;