Move default Input bus logic to PostParse handling

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>
This commit is contained in:
K Shiva 2023-04-22 23:25:30 +05:30 committed by Martin Kletzander
parent fb1bfad7ad
commit c4bc4d3b82
6 changed files with 43 additions and 32 deletions

View 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);

View 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,

View 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:

View 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:

View 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:

View 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: