]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Move default Input bus logic to PostParse handling
authorK Shiva <shiva_kr@riseup.net>
Sat, 22 Apr 2023 17:55:30 +0000 (23:25 +0530)
committerMartin Kletzander <mkletzan@redhat.com>
Mon, 24 Apr 2023 13:23:50 +0000 (15:23 +0200)
A new enum type "Default" has been added for Input bus.
The logic that handled default input bus types in
virDomainInputParseXML() has been moved to a new function
virDomainInputDefPostParse() in domain_postparse.c
Link to Issue: https://gitlab.com/libvirt/libvirt/-/issues/8

Signed-off-by: K Shiva <shiva_kr@riseup.net>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
src/conf/domain_conf.c
src/conf/domain_conf.h
src/conf/domain_postparse.c
src/qemu/qemu_command.c
src/qemu/qemu_domain_address.c
src/qemu/qemu_hotplug.c

index cda50e56d045db40183482b17c926db85df636a7..222dd989f54f41d4c8c8913c79d6f1116d6b30d3 100644 (file)
@@ -905,6 +905,7 @@ VIR_ENUM_IMPL(virDomainInput,
 
 VIR_ENUM_IMPL(virDomainInputBus,
               VIR_DOMAIN_INPUT_BUS_LAST,
+              "default",
               "ps2",
               "usb",
               "xen",
@@ -10693,7 +10694,6 @@ virDomainPanicDefParseXML(virDomainXMLOption *xmlopt,
 /* Parse the XML definition for an input device */
 static virDomainInputDef *
 virDomainInputDefParseXML(virDomainXMLOption *xmlopt,
-                          const virDomainDef *dom,
                           xmlNodePtr node,
                           xmlXPathContextPtr ctxt,
                           unsigned int flags)
@@ -10733,35 +10733,12 @@ virDomainInputDefParseXML(virDomainXMLOption *xmlopt,
         goto error;
     }
 
-    if (bus) {
-        if ((def->bus = virDomainInputBusTypeFromString(bus)) < 0) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("unknown input bus type '%1$s'"), bus);
-            goto error;
-        }
-
-    } else {
-        if (dom->os.type == VIR_DOMAIN_OSTYPE_HVM) {
-            if ((def->type == VIR_DOMAIN_INPUT_TYPE_MOUSE ||
-                def->type == VIR_DOMAIN_INPUT_TYPE_KBD) &&
-                (ARCH_IS_X86(dom->os.arch) || dom->os.arch == VIR_ARCH_NONE)) {
-                def->bus = VIR_DOMAIN_INPUT_BUS_PS2;
-            } else if (ARCH_IS_S390(dom->os.arch) ||
-                       def->type == VIR_DOMAIN_INPUT_TYPE_PASSTHROUGH) {
-                def->bus = VIR_DOMAIN_INPUT_BUS_VIRTIO;
-            } else if (def->type == VIR_DOMAIN_INPUT_TYPE_EVDEV) {
-                def->bus = VIR_DOMAIN_INPUT_BUS_NONE;
-            } else {
-                def->bus = VIR_DOMAIN_INPUT_BUS_USB;
-            }
-        } else if (dom->os.type == VIR_DOMAIN_OSTYPE_XEN ||
-                   dom->os.type == VIR_DOMAIN_OSTYPE_XENPVH) {
-            def->bus = VIR_DOMAIN_INPUT_BUS_XEN;
-        } else {
-            if ((dom->virtType == VIR_DOMAIN_VIRT_VZ ||
-                 dom->virtType == VIR_DOMAIN_VIRT_PARALLELS))
-                def->bus = VIR_DOMAIN_INPUT_BUS_PARALLELS;
-        }
+    if (bus &&
+        ((def->bus = virDomainInputBusTypeFromString(bus)) < 0 ||
+         def->bus == VIR_DOMAIN_INPUT_BUS_DEFAULT)) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("unknown input bus type '%1$s'"), bus);
+        goto error;
     }
 
     if (virDomainDeviceInfoParseXML(xmlopt, node, ctxt, &def->info, flags) < 0)
@@ -13768,7 +13745,7 @@ virDomainDeviceDefParse(const char *xmlStr,
             return NULL;
         break;
     case VIR_DOMAIN_DEVICE_INPUT:
-        if (!(dev->data.input = virDomainInputDefParseXML(xmlopt, def, node,
+        if (!(dev->data.input = virDomainInputDefParseXML(xmlopt, node,
                                                           ctxt, flags)))
             return NULL;
         break;
@@ -18874,7 +18851,6 @@ virDomainDefParseXML(xmlXPathContextPtr ctxt,
 
     for (i = 0; i < n; i++) {
         virDomainInputDef *input = virDomainInputDefParseXML(xmlopt,
-                                                             def,
                                                              nodes[i],
                                                              ctxt,
                                                              flags);
index 511067a0502a3f8ed4dd2de1ab6fbbf6438e9ec9..2a8fc6f90d4fa23019d97db79d700ee8762f6c3e 100644 (file)
@@ -1510,6 +1510,7 @@ typedef enum {
 } virDomainInputType;
 
 typedef enum {
+    VIR_DOMAIN_INPUT_BUS_DEFAULT,
     VIR_DOMAIN_INPUT_BUS_PS2,
     VIR_DOMAIN_INPUT_BUS_USB,
     VIR_DOMAIN_INPUT_BUS_XEN,
index b756e2cde84a2962c3809212da2eda3c66a2b7f0..7ef478e3e1745c3422f4c42f1207889bd80dbf17 100644 (file)
@@ -649,6 +649,33 @@ virDomainFSDefPostParse(virDomainFSDef *fs)
     return 0;
 }
 
+static void
+virDomainInputDefPostParse(virDomainInputDef *input,
+                           const virDomainDef *def)
+{
+    if (input->bus == VIR_DOMAIN_INPUT_BUS_DEFAULT) {
+        if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
+            if ((input->type == VIR_DOMAIN_INPUT_TYPE_MOUSE ||
+                 input->type == VIR_DOMAIN_INPUT_TYPE_KBD) &&
+                (ARCH_IS_X86(def->os.arch) || def->os.arch == VIR_ARCH_NONE)) {
+            } else if (ARCH_IS_S390(def->os.arch) ||
+                       input->type == VIR_DOMAIN_INPUT_TYPE_PASSTHROUGH) {
+                input->bus = VIR_DOMAIN_INPUT_BUS_VIRTIO;
+            } else if (input->type == VIR_DOMAIN_INPUT_TYPE_EVDEV) {
+                input->bus = VIR_DOMAIN_INPUT_BUS_NONE;
+            } else {
+                input->bus = VIR_DOMAIN_INPUT_BUS_USB;
+            }
+        } else if (def->os.type == VIR_DOMAIN_OSTYPE_XEN ||
+                   def->os.type == VIR_DOMAIN_OSTYPE_XENPVH) {
+            input->bus = VIR_DOMAIN_INPUT_BUS_XEN;
+        } else {
+            if ((def->virtType == VIR_DOMAIN_VIRT_VZ ||
+                 def->virtType == VIR_DOMAIN_VIRT_PARALLELS))
+                input->bus = VIR_DOMAIN_INPUT_BUS_PARALLELS;
+        }
+    }
+}
 
 static int
 virDomainDeviceDefPostParseCommon(virDomainDeviceDef *dev,
@@ -701,6 +728,9 @@ virDomainDeviceDefPostParseCommon(virDomainDeviceDef *dev,
     case VIR_DOMAIN_DEVICE_LEASE:
     case VIR_DOMAIN_DEVICE_NET:
     case VIR_DOMAIN_DEVICE_INPUT:
+        virDomainInputDefPostParse(dev->data.input, def);
+        ret = 0;
+        break;
     case VIR_DOMAIN_DEVICE_SOUND:
     case VIR_DOMAIN_DEVICE_WATCHDOG:
     case VIR_DOMAIN_DEVICE_GRAPHICS:
index 0afb038954cfd55850e82d6f360c52cd3e84f1c8..e0faebf3bb6556a1e522f690065e36326b8bc9c6 100644 (file)
@@ -4345,6 +4345,7 @@ qemuBuildInputCommandLine(virCommand *cmd,
                 if (!(props = qemuBuildInputVirtioDevProps(def, input, qemuCaps)))
                     return -1;
 
+            case VIR_DOMAIN_INPUT_BUS_DEFAULT:
             case VIR_DOMAIN_INPUT_BUS_PS2:
             case VIR_DOMAIN_INPUT_BUS_XEN:
             case VIR_DOMAIN_INPUT_BUS_PARALLELS:
index 7d3d072d5a254a0add72d7599ebb82e46cb4e308..49c5e199fab3aed579c770d6102eba1f7637c89c 100644 (file)
@@ -984,6 +984,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDef *dev,
             }
             return 0;
 
+        case VIR_DOMAIN_INPUT_BUS_DEFAULT:
         case VIR_DOMAIN_INPUT_BUS_PS2:
         case VIR_DOMAIN_INPUT_BUS_USB:
         case VIR_DOMAIN_INPUT_BUS_XEN:
index 52b057b4f3738ec6e8795ede2e0376d2fa1fa46e..7d007abd6e52f823bf765081b158c6ecb701db7c 100644 (file)
@@ -3064,6 +3064,7 @@ qemuDomainAttachInputDevice(virDomainObj *vm,
             goto cleanup;
         break;
 
+    case VIR_DOMAIN_INPUT_BUS_DEFAULT:
     case VIR_DOMAIN_INPUT_BUS_PS2:
     case VIR_DOMAIN_INPUT_BUS_XEN:
     case VIR_DOMAIN_INPUT_BUS_PARALLELS:
@@ -5810,6 +5811,7 @@ qemuDomainDetachPrepInput(virDomainObj *vm,
     *detach = input = vm->def->inputs[idx];
 
     switch ((virDomainInputBus) input->bus) {
+    case VIR_DOMAIN_INPUT_BUS_DEFAULT:
     case VIR_DOMAIN_INPUT_BUS_PS2:
     case VIR_DOMAIN_INPUT_BUS_XEN:
     case VIR_DOMAIN_INPUT_BUS_PARALLELS: