[PATCH v4 17/30] qemu: Remove redundancy in qemuBuildSerialChrDeviceStr()

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

 



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@xxxxxxxxxx>
Reviewed-by: Pavel Hrdina <phrdina@xxxxxxxxxx>
---
 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 718dfb15f..8249c6237 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -9222,6 +9222,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,
@@ -10351,6 +10370,7 @@ qemuBuildCommandLine(virQEMUDriverPtr driver,
     return NULL;
 }
 
+
 /* This function generates the correct '-device' string for character
  * devices of each architecture.
  */
@@ -10361,6 +10381,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 &&
@@ -10377,9 +10398,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;
@@ -10387,14 +10413,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.14.3

--
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]
  Powered by Linux