[PATCH 03/10] qemu: Make basic upfront checks before creating command

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

 



Create qemuBuildPreCheck to make some basic upfront checks before
trying to build the command.

Unfortunately the 'spice' count was used later on, so yuck, handle that.

This will move some logic from much later to much earlier - we shouldn't
be adjusting any data so that shouldn't matter.

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/qemu/qemu_command.c | 169 +++++++++++++++++++++++++++---------------------
 1 file changed, 97 insertions(+), 72 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index ab27619..36fe110 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -6593,6 +6593,99 @@ qemuBuildTPMCommandLine(virDomainDefPtr def,
 }
 
 
+/*
+ * qemuBuildPreCheck:
+ *
+ * Perform some basic configuration checks before taking the plunge.
+ */
+static int
+qemuBuildPreCheck(virQEMUDriverPtr driver,
+                  const virDomainDef  *def,
+                  int *spicecnt)
+{
+    size_t i;
+    int sdl = 0;
+    int vnc = 0;
+    int spice = 0;
+
+    if (!virQEMUDriverIsPrivileged(driver)) {
+        /* If we have no cgroups then we can have no tunings that
+         * require them */
+
+        if (virMemoryLimitIsSet(def->mem.hard_limit) ||
+            virMemoryLimitIsSet(def->mem.soft_limit) ||
+            def->mem.min_guarantee ||
+            virMemoryLimitIsSet(def->mem.swap_hard_limit)) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("Memory tuning is not available in session mode"));
+            goto error;
+        }
+
+        if (def->blkio.weight) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("Block I/O tuning is not available in session mode"));
+            goto error;
+        }
+
+        if (def->cputune.sharesSpecified || def->cputune.period ||
+            def->cputune.quota || def->cputune.emulator_period ||
+            def->cputune.emulator_quota) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("CPU tuning is not available in session mode"));
+            goto error;
+        }
+    }
+
+    for (i = 0; i < def->ngraphics; ++i) {
+        switch (def->graphics[i]->type) {
+        case VIR_DOMAIN_GRAPHICS_TYPE_SDL:
+            ++sdl;
+            break;
+        case VIR_DOMAIN_GRAPHICS_TYPE_VNC:
+            ++vnc;
+            break;
+        case VIR_DOMAIN_GRAPHICS_TYPE_SPICE:
+            ++spice;
+            break;
+        }
+    }
+
+    if (sdl > 1 || vnc > 1 || spice > 1) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("only 1 graphics device of each type "
+                         "(sdl, vnc, spice) is supported"));
+        goto error;
+    }
+    *spicecnt = spice;
+
+    if (def->virtType == VIR_DOMAIN_VIRT_XEN ||
+        def->os.type == VIR_DOMAIN_OSTYPE_XEN ||
+        def->os.type == VIR_DOMAIN_OSTYPE_LINUX) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("qemu emulator '%s' does not support xen"),
+                       def->emulator);
+        goto error;
+    }
+
+    for (i = 0; i < def->ndisks; i++) {
+        virDomainDiskDefPtr disk = def->disks[i];
+
+        if (disk->src->driverName != NULL &&
+            STRNEQ(disk->src->driverName, "qemu")) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("unsupported driver name '%s' for disk '%s'"),
+                           disk->src->driverName, disk->src->path);
+            goto error;
+        }
+    }
+
+    return 0;
+
+ error:
+    return -1;
+}
+
+
 qemuBuildCommandLineCallbacks buildCommandLineCallbacks = {
     .qemuGetSCSIDeviceSgName = virSCSIDeviceGetSgName,
 };
@@ -6626,14 +6719,12 @@ qemuBuildCommandLine(virConnectPtr conn,
     char uuid[VIR_UUID_STRING_BUFLEN];
     char *cpu;
     char *smp;
+    int spicecnt = 0;
     int last_good_net = -1;
     bool hasHwVirt = false;
     virCommandPtr cmd = NULL;
     bool allowReboot = true;
     bool emitBootindex = false;
-    int sdl = 0;
-    int vnc = 0;
-    int spice = 0;
     int usbcontroller = 0;
     int actualSerials = 0;
     bool usblegacy = false;
@@ -6677,47 +6768,8 @@ qemuBuildCommandLine(virConnectPtr conn,
 
     virUUIDFormat(def->uuid, uuid);
 
-    if (!virQEMUDriverIsPrivileged(driver)) {
-        /* If we have no cgroups then we can have no tunings that
-         * require them */
-
-        if (virMemoryLimitIsSet(def->mem.hard_limit) ||
-            virMemoryLimitIsSet(def->mem.soft_limit) ||
-            def->mem.min_guarantee ||
-            virMemoryLimitIsSet(def->mem.swap_hard_limit)) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("Memory tuning is not available in session mode"));
-            goto error;
-        }
-
-        if (def->blkio.weight) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("Block I/O tuning is not available in session mode"));
-            goto error;
-        }
-
-        if (def->cputune.sharesSpecified || def->cputune.period ||
-            def->cputune.quota || def->cputune.emulator_period ||
-            def->cputune.emulator_quota) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("CPU tuning is not available in session mode"));
-            goto error;
-        }
-    }
-
-    for (i = 0; i < def->ngraphics; ++i) {
-        switch (def->graphics[i]->type) {
-        case VIR_DOMAIN_GRAPHICS_TYPE_SDL:
-            ++sdl;
-            break;
-        case VIR_DOMAIN_GRAPHICS_TYPE_VNC:
-            ++vnc;
-            break;
-        case VIR_DOMAIN_GRAPHICS_TYPE_SPICE:
-            ++spice;
-            break;
-        }
-    }
+    if (qemuBuildPrecCheck(driver, def, &spicecnt) < 0)
+        goto error;
 
     /*
      * do not use boot=on for drives when not using KVM since this
@@ -6857,14 +6909,6 @@ qemuBuildCommandLine(virConnectPtr conn,
     }
 
     virCommandAddArgList(cmd, "-uuid", uuid, NULL);
-    if (def->virtType == VIR_DOMAIN_VIRT_XEN ||
-        def->os.type == VIR_DOMAIN_OSTYPE_XEN ||
-        def->os.type == VIR_DOMAIN_OSTYPE_LINUX) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("qemu emulator '%s' does not support xen"),
-                       def->emulator);
-        goto error;
-    }
 
     if ((def->os.smbios_mode != VIR_DOMAIN_SMBIOS_NONE) &&
         (def->os.smbios_mode != VIR_DOMAIN_SMBIOS_EMULATE)) {
@@ -7379,18 +7423,6 @@ qemuBuildCommandLine(virConnectPtr conn,
         }
     }
 
-    for (i = 0; i < def->ndisks; i++) {
-        virDomainDiskDefPtr disk = def->disks[i];
-
-        if (disk->src->driverName != NULL &&
-            STRNEQ(disk->src->driverName, "qemu")) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("unsupported driver name '%s' for disk '%s'"),
-                           disk->src->driverName, disk->src->path);
-            goto error;
-        }
-    }
-
     if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE)) {
         for (j = 0; j < ARRAY_CARDINALITY(contOrder); j++) {
             for (i = 0; i < def->ncontrollers; i++) {
@@ -7803,7 +7835,7 @@ qemuBuildCommandLine(virConnectPtr conn,
         virDomainChrDefPtr serial = def->serials[i];
         char *devstr;
 
-        if (serial->source.type == VIR_DOMAIN_CHR_TYPE_SPICEPORT && !spice)
+        if (serial->source.type == VIR_DOMAIN_CHR_TYPE_SPICEPORT && !spicecnt)
             continue;
 
         /* Use -chardev with -device if they are available */
@@ -8037,13 +8069,6 @@ qemuBuildCommandLine(virConnectPtr conn,
         }
     }
 
-    if (sdl > 1 || vnc > 1 || spice > 1) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                       _("only 1 graphics device of each type "
-                         "(sdl, vnc, spice) is supported"));
-        goto error;
-    }
-
     for (i = 0; i < def->ngraphics; ++i) {
         if (qemuBuildGraphicsCommandLine(cfg, cmd, def, qemuCaps,
                                          def->graphics[i]) < 0)
-- 
2.5.0

--
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]