404507
From 4f4db541098163a2061cd63ce6bfb83ce2ed38b5 Mon Sep 17 00:00:00 2001
404507
Message-Id: <4f4db541098163a2061cd63ce6bfb83ce2ed38b5@dist-git>
404507
From: Andrea Bolognani <abologna@redhat.com>
404507
Date: Wed, 29 Nov 2017 16:22:58 +0100
404507
Subject: [PATCH] conf: Introduce VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_NONE
404507
404507
This is the first step in getting rid of the assumption that
404507
isa-serial is the default target type for serial devices.
404507
404507
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
404507
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
404507
(cherry picked from commit 6385c8c14233388d929ed62717684e7352543416)
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/conf/domain_conf.c         |  8 +++++---
404507
 src/conf/domain_conf.h         |  3 ++-
404507
 src/qemu/qemu_command.c        | 13 +++++++++++++
404507
 src/qemu/qemu_domain.c         | 21 +++++++++++++++++++++
404507
 src/qemu/qemu_domain_address.c |  1 +
404507
 5 files changed, 42 insertions(+), 4 deletions(-)
404507
404507
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
404507
index 41674a85af..3a5ecd3a9d 100644
404507
--- a/src/conf/domain_conf.c
404507
+++ b/src/conf/domain_conf.c
404507
@@ -441,6 +441,7 @@ VIR_ENUM_IMPL(virDomainChrDeviceState, VIR_DOMAIN_CHR_DEVICE_STATE_LAST,
404507
 
404507
 VIR_ENUM_IMPL(virDomainChrSerialTarget,
404507
               VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_LAST,
404507
+              "none",
404507
               "isa-serial",
404507
               "usb-serial",
404507
               "pci-serial")
404507
@@ -4025,7 +4026,7 @@ virDomainDefAddConsoleCompat(virDomainDefPtr def)
404507
 
404507
             /* modify it to be a serial port */
404507
             def->serials[0]->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL;
404507
-            def->serials[0]->targetType = VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA;
404507
+            def->serials[0]->targetType = VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_NONE;
404507
             def->serials[0]->target.port = 0;
404507
         } else {
404507
             /* if the console source doesn't match */
404507
@@ -4049,7 +4050,8 @@ virDomainDefAddConsoleCompat(virDomainDefPtr def)
404507
                def->serials[0]->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL) {
404507
 
404507
         switch ((virDomainChrSerialTargetType) def->serials[0]->targetType) {
404507
-        case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA: {
404507
+        case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA:
404507
+        case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_NONE: {
404507
 
404507
             /* Create a stub console to match the serial port.
404507
              * console[0] either does not exist
404507
@@ -11485,7 +11487,7 @@ virDomainChrDefaultTargetType(int devtype)
404507
         return VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_NONE;
404507
 
404507
     case VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL:
404507
-        return VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA;
404507
+        return VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_NONE;
404507
 
404507
     case VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL:
404507
     case VIR_DOMAIN_CHR_DEVICE_TYPE_LAST:
404507
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
404507
index 09635763a1..9502573b34 100644
404507
--- a/src/conf/domain_conf.h
404507
+++ b/src/conf/domain_conf.h
404507
@@ -1073,7 +1073,8 @@ typedef enum {
404507
 } virDomainChrDeviceType;
404507
 
404507
 typedef enum {
404507
-    VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA = 0,
404507
+    VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_NONE = 0,
404507
+    VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA,
404507
     VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_USB,
404507
     VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_PCI,
404507
 
404507
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
404507
index 3d970ed9d1..d593e60198 100644
404507
--- a/src/qemu/qemu_command.c
404507
+++ b/src/qemu/qemu_command.c
404507
@@ -9255,6 +9255,14 @@ qemuChrIsPlatformDevice(const virDomainDef *def,
404507
             return true;
404507
     }
404507
 
404507
+    /* If we got all the way here and we're still stuck with the default
404507
+     * target type for a serial device, it means we have no clue what kind of
404507
+     * device we're talking about and we must treat it as a platform device. */
404507
+    if (chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL &&
404507
+        chr->targetType == VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_NONE) {
404507
+        return true;
404507
+    }
404507
+
404507
     return false;
404507
 }
404507
 
404507
@@ -10378,7 +10386,12 @@ qemuBuildSerialChrDeviceStr(char **deviceStr,
404507
             }
404507
             break;
404507
 
404507
+        case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_NONE:
404507
         case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_LAST:
404507
+            /* Except from _LAST, which is just a guard value and will never
404507
+             * be used, all of the above are platform devices, which means
404507
+             * qemuBuildSerialCommandLine() will have taken the appropriate
404507
+             * branch and we will not have ended up here. */
404507
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
404507
                            _("Invalid target type for serial device"));
404507
             goto error;
404507
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
404507
index b15d994774..e43f7496c2 100644
404507
--- a/src/qemu/qemu_domain.c
404507
+++ b/src/qemu/qemu_domain.c
404507
@@ -4095,6 +4095,27 @@ qemuDomainChrDefPostParse(virDomainChrDefPtr chr,
404507
         chr->targetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_VIRTIO;
404507
     }
404507
 
404507
+    /* Historically, isa-serial and the default matched, so in order to
404507
+     * maintain backwards compatibility we map them here. The actual default
404507
+     * will be picked below based on the architecture and machine type. */
404507
+    if (chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL &&
404507
+        chr->targetType == VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA) {
404507
+        chr->targetType = VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_NONE;
404507
+    }
404507
+
404507
+    /* Set the default serial type */
404507
+    if (chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL &&
404507
+        chr->targetType == VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_NONE) {
404507
+        if (ARCH_IS_X86(def->os.arch)) {
404507
+            chr->targetType = VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA;
404507
+        } else if (qemuDomainIsPSeries(def)) {
404507
+            /* Setting TYPE_ISA here is just a temporary hack to reduce test
404507
+             * suite churn. Later on we will have a proper serial type for
404507
+             * pSeries and this line will be updated accordingly. */
404507
+            chr->targetType = VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA;
404507
+        }
404507
+    }
404507
+
404507
     /* clear auto generated unix socket path for inactive definitions */
404507
     if (parseFlags & VIR_DOMAIN_DEF_PARSE_INACTIVE) {
404507
         if (qemuDomainChrDefDropDefaultPath(chr, driver) < 0)
404507
diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
404507
index 7f4ac0f45a..989c0e6c93 100644
404507
--- a/src/qemu/qemu_domain_address.c
404507
+++ b/src/qemu/qemu_domain_address.c
404507
@@ -782,6 +782,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev,
404507
 
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_NONE:
404507
         case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_LAST:
404507
             return 0;
404507
         }
404507
-- 
404507
2.15.1
404507