[PATCH 25/33] qemu: Add qemuDomainDefaultSerialModel()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Factor out the existing code.

Signed-off-by: Andrea Bolognani <abologna@xxxxxxxxxx>
---
 src/qemu/qemu_domain.c | 66 ++++++++++++++++++++++--------------------
 1 file changed, 35 insertions(+), 31 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index b3e63b3648..c9d213dd7b 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -4312,6 +4312,40 @@ qemuDomainDefaultSerialType(const virDomainDef *def)
 }
 
 
+static int
+qemuDomainDefaultSerialModel(const virDomainDef *def,
+                             const virDomainChrDef *chr)
+{
+    switch ((virDomainChrSerialTargetType)chr->targetType) {
+    case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA:
+        return VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_ISA_SERIAL;
+    case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_USB:
+        return VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_USB_SERIAL;
+    case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_PCI:
+        return VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_PCI_SERIAL;
+    case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SPAPR_VIO:
+        return VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_SPAPR_VTY;
+    case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SYSTEM:
+        if (qemuDomainIsARMVirt(def)) {
+            return VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_PL011;
+        } else if (qemuDomainIsRISCVVirt(def)) {
+            return VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_16550A;
+        }
+        break;
+    case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SCLP:
+        return VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_SCLPCONSOLE;
+    case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA_DEBUG:
+        return VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_ISA_DEBUGCON;
+    case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_NONE:
+    case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_LAST:
+        /* Nothing to do */
+        break;
+    }
+
+    return VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_NONE;
+}
+
+
 static int
 qemuDomainDefAddDefaultDevices(virQEMUDriver *driver,
                                virDomainDef *def,
@@ -5898,37 +5932,7 @@ qemuDomainChrDefPostParse(virDomainChrDef *chr,
     /* Set the default target model */
     if (chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL &&
         chr->targetModel == VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_NONE) {
-        switch ((virDomainChrSerialTargetType)chr->targetType) {
-        case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA:
-            chr->targetModel = VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_ISA_SERIAL;
-            break;
-        case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_USB:
-            chr->targetModel = VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_USB_SERIAL;
-            break;
-        case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_PCI:
-            chr->targetModel = VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_PCI_SERIAL;
-            break;
-        case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SPAPR_VIO:
-            chr->targetModel = VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_SPAPR_VTY;
-            break;
-        case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SYSTEM:
-            if (qemuDomainIsARMVirt(def)) {
-                chr->targetModel = VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_PL011;
-            } else if (qemuDomainIsRISCVVirt(def)) {
-                chr->targetModel = VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_16550A;
-            }
-            break;
-        case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SCLP:
-            chr->targetModel = VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_SCLPCONSOLE;
-            break;
-        case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA_DEBUG:
-            chr->targetModel = VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_ISA_DEBUGCON;
-            break;
-        case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_NONE:
-        case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_LAST:
-            /* Nothing to do */
-            break;
-        }
+        chr->targetModel = qemuDomainDefaultSerialModel(def, chr);
     }
 
     /* clear auto generated unix socket path for inactive definitions */
-- 
2.43.0
_______________________________________________
Devel mailing list -- devel@xxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxx




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux