render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
c1c534
From 37bf217cd53b115427999d5421dca30eb472616c Mon Sep 17 00:00:00 2001
c1c534
Message-Id: <37bf217cd53b115427999d5421dca30eb472616c@dist-git>
c1c534
From: Andrea Bolognani <abologna@redhat.com>
c1c534
Date: Wed, 29 Nov 2017 16:23:09 +0100
c1c534
Subject: [PATCH] qemu: Validate target model for serial devices
c1c534
c1c534
Target model and target type must agree for the configuration
c1c534
to make sense, so check that's actually the case and error out
c1c534
otherwise.
c1c534
c1c534
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
c1c534
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
c1c534
(cherry picked from commit a9254a2d6e9db1030350ff562b9ea91494143aa9)
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/libvirt_private.syms |  2 ++
c1c534
 src/qemu/qemu_domain.c   | 41 +++++++++++++++++++++++++++++++++++++++++
c1c534
 2 files changed, 43 insertions(+)
c1c534
c1c534
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
c1c534
index 65b1143c9b..ecf7036dff 100644
c1c534
--- a/src/libvirt_private.syms
c1c534
+++ b/src/libvirt_private.syms
c1c534
@@ -209,6 +209,8 @@ virDomainChrGetDomainPtrs;
c1c534
 virDomainChrInsertPreAlloced;
c1c534
 virDomainChrPreAlloc;
c1c534
 virDomainChrRemove;
c1c534
+virDomainChrSerialTargetModelTypeFromString;
c1c534
+virDomainChrSerialTargetModelTypeToString;
c1c534
 virDomainChrSerialTargetTypeFromString;
c1c534
 virDomainChrSerialTargetTypeToString;
c1c534
 virDomainChrSourceDefClear;
c1c534
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
c1c534
index a8a91de2fe..7b5bc97de6 100644
c1c534
--- a/src/qemu/qemu_domain.c
c1c534
+++ b/src/qemu/qemu_domain.c
c1c534
@@ -3475,6 +3475,25 @@ qemuDomainChrSerialTargetTypeToAddressType(int targetType)
c1c534
 }
c1c534
 
c1c534
 
c1c534
+static int
c1c534
+qemuDomainChrSerialTargetModelToTargetType(int targetModel)
c1c534
+{
c1c534
+    switch ((virDomainChrSerialTargetModel) targetModel) {
c1c534
+    case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_ISA_SERIAL:
c1c534
+        return VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA;
c1c534
+    case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_USB_SERIAL:
c1c534
+        return VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_USB;
c1c534
+    case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_PCI_SERIAL:
c1c534
+        return VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_PCI;
c1c534
+    case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_NONE:
c1c534
+    case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_LAST:
c1c534
+        break;
c1c534
+    }
c1c534
+
c1c534
+    return VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_NONE;
c1c534
+}
c1c534
+
c1c534
+
c1c534
 static int
c1c534
 qemuDomainChrTargetDefValidate(const virDomainDef *def,
c1c534
                                const virDomainChrDef *chr)
c1c534
@@ -3511,6 +3530,28 @@ qemuDomainChrTargetDefValidate(const virDomainDef *def,
c1c534
         case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_LAST:
c1c534
             break;
c1c534
         }
c1c534
+
c1c534
+        /* Validate target model */
c1c534
+        switch ((virDomainChrSerialTargetModel) chr->targetModel) {
c1c534
+        case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_ISA_SERIAL:
c1c534
+        case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_USB_SERIAL:
c1c534
+        case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_PCI_SERIAL:
c1c534
+
c1c534
+            expected = qemuDomainChrSerialTargetModelToTargetType(chr->targetModel);
c1c534
+
c1c534
+            if (chr->targetType != expected) {
c1c534
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
c1c534
+                               _("Target model '%s' requires target type '%s'"),
c1c534
+                               virDomainChrSerialTargetModelTypeToString(chr->targetModel),
c1c534
+                               virDomainChrSerialTargetTypeToString(expected));
c1c534
+                return -1;
c1c534
+            }
c1c534
+            break;
c1c534
+
c1c534
+        case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_NONE:
c1c534
+        case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_LAST:
c1c534
+            break;
c1c534
+        }
c1c534
         break;
c1c534
 
c1c534
     case VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE:
c1c534
-- 
c1c534
2.15.1
c1c534