render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
404507
From 0d9354fe1bef822c515713a3ceb5b619f7eac00c Mon Sep 17 00:00:00 2001
404507
Message-Id: <0d9354fe1bef822c515713a3ceb5b619f7eac00c@dist-git>
404507
From: Andrea Bolognani <abologna@redhat.com>
404507
Date: Wed, 29 Nov 2017 16:23:11 +0100
404507
Subject: [PATCH] qemu: Remove redundancy in qemuBuildSerialChrDeviceStr()
404507
404507
Instead duplicating the capability check for each possible target
404507
model, introduce a small helper that matches the target model with
404507
the corresponding capability and collapse all existing checks into
404507
a single one.
404507
404507
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
404507
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
404507
(cherry picked from commit fa96d3524296e7119acf5ad7b02653f4c062d030)
404507
404507
https://bugzilla.redhat.com/show_bug.cgi?id=1449265
404507
https://bugzilla.redhat.com/show_bug.cgi?id=1511421
404507
https://bugzilla.redhat.com/show_bug.cgi?id=1512929
404507
https://bugzilla.redhat.com/show_bug.cgi?id=1512934
404507
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
404507
---
404507
 src/qemu/qemu_command.c | 40 +++++++++++++++++++++++++++++-----------
404507
 1 file changed, 29 insertions(+), 11 deletions(-)
404507
404507
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
404507
index 7fd2afb1e0..f8d5d317cd 100644
404507
--- a/src/qemu/qemu_command.c
404507
+++ b/src/qemu/qemu_command.c
404507
@@ -9218,6 +9218,25 @@ qemuBuildShmemCommandLine(virLogManagerPtr logManager,
404507
     return 0;
404507
 }
404507
 
404507
+
404507
+static virQEMUCapsFlags
404507
+qemuChrSerialTargetModelToCaps(virDomainChrSerialTargetModel targetModel)
404507
+{
404507
+    switch (targetModel) {
404507
+    case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_USB_SERIAL:
404507
+        return QEMU_CAPS_DEVICE_USB_SERIAL;
404507
+    case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_PCI_SERIAL:
404507
+        return QEMU_CAPS_DEVICE_PCI_SERIAL;
404507
+    case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_ISA_SERIAL:
404507
+    case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_NONE:
404507
+    case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_LAST:
404507
+        break;
404507
+    }
404507
+
404507
+    return 0;
404507
+}
404507
+
404507
+
404507
 static int
404507
 qemuBuildChrDeviceCommandLine(virCommandPtr cmd,
404507
                               const virDomainDef *def,
404507
@@ -10322,6 +10341,7 @@ qemuBuildCommandLine(virQEMUDriverPtr driver,
404507
     return NULL;
404507
 }
404507
 
404507
+
404507
 /* This function generates the correct '-device' string for character
404507
  * devices of each architecture.
404507
  */
404507
@@ -10332,6 +10352,7 @@ qemuBuildSerialChrDeviceStr(char **deviceStr,
404507
                             virQEMUCapsPtr qemuCaps)
404507
 {
404507
     virBuffer cmd = VIR_BUFFER_INITIALIZER;
404507
+    virQEMUCapsFlags caps;
404507
 
404507
     if (qemuDomainIsPSeries(def)) {
404507
         if (serial->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL &&
404507
@@ -10348,9 +10369,14 @@ qemuBuildSerialChrDeviceStr(char **deviceStr,
404507
     } else {
404507
         switch ((virDomainChrSerialTargetModel) serial->targetModel) {
404507
         case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_USB_SERIAL:
404507
-            if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_USB_SERIAL)) {
404507
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
404507
-                               _("usb-serial is not supported in this QEMU binary"));
404507
+        case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_PCI_SERIAL:
404507
+
404507
+            caps = qemuChrSerialTargetModelToCaps(serial->targetModel);
404507
+
404507
+            if (caps && !virQEMUCapsGet(qemuCaps, caps)) {
404507
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
404507
+                               _("'%s' is not supported in this QEMU binary"),
404507
+                               virDomainChrSerialTargetModelTypeToString(serial->targetModel));
404507
                 goto error;
404507
             }
404507
             break;
404507
@@ -10358,14 +10384,6 @@ qemuBuildSerialChrDeviceStr(char **deviceStr,
404507
         case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_ISA_SERIAL:
404507
             break;
404507
 
404507
-        case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_PCI_SERIAL:
404507
-            if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_PCI_SERIAL)) {
404507
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
404507
-                               _("pci-serial is not supported with this QEMU binary"));
404507
-                goto error;
404507
-            }
404507
-            break;
404507
-
404507
         case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_NONE:
404507
         case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_LAST:
404507
             /* Except from _LAST, which is just a guard value and will never
404507
-- 
404507
2.15.1
404507