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