c1c534
From 04e24e8cb39c0a3b3d3203985fa0ec824195d1ab Mon Sep 17 00:00:00 2001
c1c534
Message-Id: <04e24e8cb39c0a3b3d3203985fa0ec824195d1ab@dist-git>
c1c534
From: Andrea Bolognani <abologna@redhat.com>
c1c534
Date: Wed, 29 Nov 2017 16:23:06 +0100
c1c534
Subject: [PATCH] qemu: Improve qemuDomainChrTargetDefValidate()
c1c534
c1c534
Instead of validating each target type / address type combination
c1c534
separately, create a small helper to perform the matching and
c1c534
collapse all existing checks into a single one.
c1c534
c1c534
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
c1c534
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
c1c534
(cherry picked from commit 9ae116eadf7578282d284635fa23a4265b8db734)
c1c534
c1c534
https://bugzilla.redhat.com/show_bug.cgi?id=1449265
c1c534
https://bugzilla.redhat.com/show_bug.cgi?id=1511421
c1c534
https://bugzilla.redhat.com/show_bug.cgi?id=1512929
c1c534
https://bugzilla.redhat.com/show_bug.cgi?id=1512934
c1c534
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c1c534
---
c1c534
 src/qemu/qemu_domain.c | 50 ++++++++++++++++++++++++++++++--------------------
c1c534
 1 file changed, 30 insertions(+), 20 deletions(-)
c1c534
c1c534
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
c1c534
index 35eb19ca32..bb25255b94 100644
c1c534
--- a/src/qemu/qemu_domain.c
c1c534
+++ b/src/qemu/qemu_domain.c
c1c534
@@ -3456,43 +3456,53 @@ qemuDomainChrSourceDefValidate(const virDomainChrSourceDef *def)
c1c534
 }
c1c534
 
c1c534
 
c1c534
+static int
c1c534
+qemuDomainChrSerialTargetTypeToAddressType(int targetType)
c1c534
+{
c1c534
+    switch ((virDomainChrSerialTargetType) targetType) {
c1c534
+    case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA:
c1c534
+        return VIR_DOMAIN_DEVICE_ADDRESS_TYPE_ISA;
c1c534
+    case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_USB:
c1c534
+        return VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB;
c1c534
+    case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_PCI:
c1c534
+        return VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI;
c1c534
+    case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_LAST:
c1c534
+    case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_NONE:
c1c534
+        break;
c1c534
+    }
c1c534
+
c1c534
+    return VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE;
c1c534
+}
c1c534
+
c1c534
+
c1c534
 static int
c1c534
 qemuDomainChrTargetDefValidate(const virDomainDef *def,
c1c534
                                const virDomainChrDef *chr)
c1c534
 {
c1c534
+    int expected;
c1c534
+
c1c534
     switch ((virDomainChrDeviceType) chr->deviceType) {
c1c534
     case VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL:
c1c534
 
c1c534
         /* Validate target type */
c1c534
         switch ((virDomainChrSerialTargetType) chr->targetType) {
c1c534
         case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA:
c1c534
+        case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_USB:
c1c534
+        case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_PCI:
c1c534
+
c1c534
             /* Hack required until we have a proper type for pSeries
c1c534
              * serial consoles */
c1c534
             if (qemuDomainIsPSeries(def))
c1c534
                 return 0;
c1c534
 
c1c534
-            if (chr->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
c1c534
-                chr->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_ISA) {
c1c534
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
c1c534
-                               _("isa-serial requires address of isa type"));
c1c534
-                return -1;
c1c534
-            }
c1c534
-            break;
c1c534
+            expected = qemuDomainChrSerialTargetTypeToAddressType(chr->targetType);
c1c534
 
c1c534
-        case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_USB:
c1c534
             if (chr->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
c1c534
-                chr->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB) {
c1c534
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
c1c534
-                               _("usb-serial requires address of usb type"));
c1c534
-                return -1;
c1c534
-            }
c1c534
-            break;
c1c534
-
c1c534
-        case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_PCI:
c1c534
-            if (chr->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
c1c534
-                chr->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
c1c534
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
c1c534
-                               _("pci-serial requires address of pci type"));
c1c534
+                chr->info.type != expected) {
c1c534
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
c1c534
+                               _("Target type '%s' requires address type '%s'"),
c1c534
+                               virDomainChrSerialTargetTypeToString(chr->targetType),
c1c534
+                               virDomainDeviceAddressTypeToString(expected));
c1c534
                 return -1;
c1c534
             }
c1c534
             break;
c1c534
-- 
c1c534
2.15.1
c1c534