Blob Blame History Raw
From 0d9354fe1bef822c515713a3ceb5b619f7eac00c Mon Sep 17 00:00:00 2001
Message-Id: <0d9354fe1bef822c515713a3ceb5b619f7eac00c@dist-git>
From: Andrea Bolognani <abologna@redhat.com>
Date: Wed, 29 Nov 2017 16:23:11 +0100
Subject: [PATCH] qemu: Remove redundancy in qemuBuildSerialChrDeviceStr()

Instead duplicating the capability check for each possible target
model, introduce a small helper that matches the target model with
the corresponding capability and collapse all existing checks into
a single one.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
(cherry picked from commit fa96d3524296e7119acf5ad7b02653f4c062d030)

https://bugzilla.redhat.com/show_bug.cgi?id=1449265
https://bugzilla.redhat.com/show_bug.cgi?id=1511421
https://bugzilla.redhat.com/show_bug.cgi?id=1512929
https://bugzilla.redhat.com/show_bug.cgi?id=1512934
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/qemu/qemu_command.c | 40 +++++++++++++++++++++++++++++-----------
 1 file changed, 29 insertions(+), 11 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 7fd2afb1e0..f8d5d317cd 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -9218,6 +9218,25 @@ qemuBuildShmemCommandLine(virLogManagerPtr logManager,
     return 0;
 }
 
+
+static virQEMUCapsFlags
+qemuChrSerialTargetModelToCaps(virDomainChrSerialTargetModel targetModel)
+{
+    switch (targetModel) {
+    case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_USB_SERIAL:
+        return QEMU_CAPS_DEVICE_USB_SERIAL;
+    case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_PCI_SERIAL:
+        return QEMU_CAPS_DEVICE_PCI_SERIAL;
+    case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_ISA_SERIAL:
+    case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_NONE:
+    case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_LAST:
+        break;
+    }
+
+    return 0;
+}
+
+
 static int
 qemuBuildChrDeviceCommandLine(virCommandPtr cmd,
                               const virDomainDef *def,
@@ -10322,6 +10341,7 @@ qemuBuildCommandLine(virQEMUDriverPtr driver,
     return NULL;
 }
 
+
 /* This function generates the correct '-device' string for character
  * devices of each architecture.
  */
@@ -10332,6 +10352,7 @@ qemuBuildSerialChrDeviceStr(char **deviceStr,
                             virQEMUCapsPtr qemuCaps)
 {
     virBuffer cmd = VIR_BUFFER_INITIALIZER;
+    virQEMUCapsFlags caps;
 
     if (qemuDomainIsPSeries(def)) {
         if (serial->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL &&
@@ -10348,9 +10369,14 @@ qemuBuildSerialChrDeviceStr(char **deviceStr,
     } else {
         switch ((virDomainChrSerialTargetModel) serial->targetModel) {
         case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_USB_SERIAL:
-            if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_USB_SERIAL)) {
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                               _("usb-serial is not supported in this QEMU binary"));
+        case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_PCI_SERIAL:
+
+            caps = qemuChrSerialTargetModelToCaps(serial->targetModel);
+
+            if (caps && !virQEMUCapsGet(qemuCaps, caps)) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                               _("'%s' is not supported in this QEMU binary"),
+                               virDomainChrSerialTargetModelTypeToString(serial->targetModel));
                 goto error;
             }
             break;
@@ -10358,14 +10384,6 @@ qemuBuildSerialChrDeviceStr(char **deviceStr,
         case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_ISA_SERIAL:
             break;
 
-        case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_PCI_SERIAL:
-            if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_PCI_SERIAL)) {
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                               _("pci-serial is not supported with this QEMU binary"));
-                goto error;
-            }
-            break;
-
         case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_NONE:
         case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_LAST:
             /* Except from _LAST, which is just a guard value and will never
-- 
2.15.1