404507
From 9ec1516a227445872bf5bcb8a535c1a71f644739 Mon Sep 17 00:00:00 2001
404507
Message-Id: <9ec1516a227445872bf5bcb8a535c1a71f644739@dist-git>
404507
From: Andrea Bolognani <abologna@redhat.com>
404507
Date: Wed, 29 Nov 2017 16:23:05 +0100
404507
Subject: [PATCH] qemu: Introduce qemuDomainChrTargetDefValidate()
404507
404507
Instead of waiting until we get to command line generation, we can
404507
validate the target for a char device much earlier.
404507
404507
Move all the checks out of qemuBuildSerialChrDeviceStr() and into
404507
the new fuction. This will later allow us to validate the target
404507
for platform devices.
404507
404507
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
404507
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
404507
(cherry picked from commit 81e14caf60ac28acf9b7147617ef26bb99955757)
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 | 20 ----------------
404507
 src/qemu/qemu_domain.c  | 62 +++++++++++++++++++++++++++++++++++++++++++++++++
404507
 2 files changed, 62 insertions(+), 20 deletions(-)
404507
404507
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
404507
index d593e60198..8142834afd 100644
404507
--- a/src/qemu/qemu_command.c
404507
+++ b/src/qemu/qemu_command.c
404507
@@ -10353,22 +10353,9 @@ qemuBuildSerialChrDeviceStr(char **deviceStr,
404507
                                _("usb-serial is not supported in this QEMU binary"));
404507
                 goto error;
404507
             }
404507
-
404507
-            if (serial->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
404507
-                serial->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB) {
404507
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
404507
-                               _("usb-serial requires address of usb type"));
404507
-                goto error;
404507
-            }
404507
             break;
404507
 
404507
         case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA:
404507
-            if (serial->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
404507
-                serial->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_ISA) {
404507
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
404507
-                               _("isa-serial requires address of isa type"));
404507
-                goto error;
404507
-            }
404507
             break;
404507
 
404507
         case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_PCI:
404507
@@ -10377,13 +10364,6 @@ qemuBuildSerialChrDeviceStr(char **deviceStr,
404507
                                _("pci-serial is not supported with this QEMU binary"));
404507
                 goto error;
404507
             }
404507
-
404507
-            if (serial->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
404507
-                serial->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
404507
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
404507
-                               _("pci-serial requires address of pci type"));
404507
-                goto error;
404507
-            }
404507
             break;
404507
 
404507
         case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_NONE:
404507
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
404507
index e43f7496c2..35eb19ca32 100644
404507
--- a/src/qemu/qemu_domain.c
404507
+++ b/src/qemu/qemu_domain.c
404507
@@ -3456,6 +3456,65 @@ qemuDomainChrSourceDefValidate(const virDomainChrSourceDef *def)
404507
 }
404507
 
404507
 
404507
+static int
404507
+qemuDomainChrTargetDefValidate(const virDomainDef *def,
404507
+                               const virDomainChrDef *chr)
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
+            /* 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
+
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
+                return -1;
404507
+            }
404507
+            break;
404507
+
404507
+        case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_NONE:
404507
+        case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_LAST:
404507
+            break;
404507
+        }
404507
+        break;
404507
+
404507
+    case VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE:
404507
+    case VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL:
404507
+    case VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL:
404507
+    case VIR_DOMAIN_CHR_DEVICE_TYPE_LAST:
404507
+        /* Nothing to do */
404507
+        break;
404507
+    }
404507
+
404507
+    return 0;
404507
+}
404507
+
404507
+
404507
 static int
404507
 qemuDomainChrDefValidate(const virDomainChrDef *dev,
404507
                          const virDomainDef *def)
404507
@@ -3463,6 +3522,9 @@ qemuDomainChrDefValidate(const virDomainChrDef *dev,
404507
     if (qemuDomainChrSourceDefValidate(dev->source) < 0)
404507
         return -1;
404507
 
404507
+    if (qemuDomainChrTargetDefValidate(def, dev) < 0)
404507
+        return -1;
404507
+
404507
     if (dev->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL &&
404507
         (ARCH_IS_S390(def->os.arch) || qemuDomainIsPSeries(def))) {
404507
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
404507
-- 
404507
2.15.1
404507