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