From: Michal Privoznik Date: Sun, 23 Jan 2022 11:54:27 +0000 (+0100) Subject: virDomainInputDefParseXML: Move validation into validator X-Git-Tag: v8.1.0-rc1~293 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3de95c3d51801cbd65c096a1d9e8135e2c6f5eda;p=thirdparty%2Flibvirt.git virDomainInputDefParseXML: Move validation into validator There is some code that validates whether parsed @bus makes sense (e.g. some hypervisors have their own type of bus). But this code should not live in the parser, but validator rather. That way, we can also validate that the value we compute (if user didn't provide any) is valid. Signed-off-by: Michal Privoznik Reviewed-by: Ján Tomko --- diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index f5b15cff33..87576d4804 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -11857,62 +11857,6 @@ virDomainInputDefParseXML(virDomainXMLOption *xmlopt, goto error; } - if (dom->os.type == VIR_DOMAIN_OSTYPE_HVM) { - if (def->bus == VIR_DOMAIN_INPUT_BUS_PS2 && - def->type != VIR_DOMAIN_INPUT_TYPE_MOUSE && - def->type != VIR_DOMAIN_INPUT_TYPE_KBD) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("ps2 bus does not support %s input device"), - type); - goto error; - } - if (def->bus == VIR_DOMAIN_INPUT_BUS_XEN) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unsupported input bus %s"), - bus); - goto error; - } - } else if (dom->os.type == VIR_DOMAIN_OSTYPE_XEN || - dom->os.type == VIR_DOMAIN_OSTYPE_XENPVH) { - if (def->bus != VIR_DOMAIN_INPUT_BUS_XEN) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unsupported input bus %s"), - bus); - goto error; - } - if (def->type != VIR_DOMAIN_INPUT_TYPE_MOUSE && - def->type != VIR_DOMAIN_INPUT_TYPE_KBD) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("xen bus does not support %s input device"), - type); - goto error; - } - } else { - if (dom->virtType == VIR_DOMAIN_VIRT_VZ || - dom->virtType == VIR_DOMAIN_VIRT_PARALLELS) { - if (def->bus != VIR_DOMAIN_INPUT_BUS_PARALLELS) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("parallels containers don't support " - "input bus %s"), - bus); - goto error; - } - - if (def->type != VIR_DOMAIN_INPUT_TYPE_MOUSE && - def->type != VIR_DOMAIN_INPUT_TYPE_KBD) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("parallels bus does not support " - "%s input device"), - type); - goto error; - } - } else { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Input devices are not supported by this " - "virtualization driver.")); - goto error; - } - } } else { if (dom->os.type == VIR_DOMAIN_OSTYPE_HVM) { if ((def->type == VIR_DOMAIN_INPUT_TYPE_MOUSE || diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index e9baf1d41a..e443a17b0e 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -2112,8 +2112,71 @@ virDomainVsockDefValidate(const virDomainVsockDef *vsock) static int -virDomainInputDefValidate(const virDomainInputDef *input) +virDomainInputDefValidate(const virDomainInputDef *input, + const virDomainDef *def) { + switch (def->os.type) { + case VIR_DOMAIN_OSTYPE_HVM: + if (input->bus == VIR_DOMAIN_INPUT_BUS_PS2 && + input->type != VIR_DOMAIN_INPUT_TYPE_MOUSE && + input->type != VIR_DOMAIN_INPUT_TYPE_KBD) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("ps2 bus does not support %s input device"), + virDomainInputTypeToString(input->type)); + return -1; + } + if (input->bus == VIR_DOMAIN_INPUT_BUS_XEN) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unsupported input bus %s"), + virDomainInputBusTypeToString(input->bus)); + return -1; + } + break; + + case VIR_DOMAIN_OSTYPE_XEN: + case VIR_DOMAIN_OSTYPE_XENPVH: + if (input->bus != VIR_DOMAIN_INPUT_BUS_XEN) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unsupported input bus %s"), + virDomainInputBusTypeToString(input->bus)); + return -1; + } + if (input->type != VIR_DOMAIN_INPUT_TYPE_MOUSE && + input->type != VIR_DOMAIN_INPUT_TYPE_KBD) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("xen bus does not support %s input device"), + virDomainInputTypeToString(input->type)); + return -1; + } + break; + + default: + if (def->virtType == VIR_DOMAIN_VIRT_VZ || + def->virtType == VIR_DOMAIN_VIRT_PARALLELS) { + if (input->bus != VIR_DOMAIN_INPUT_BUS_PARALLELS) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("parallels containers don't support " + "input bus %s"), + virDomainInputBusTypeToString(input->bus)); + return -1; + } + + if (input->type != VIR_DOMAIN_INPUT_TYPE_MOUSE && + input->type != VIR_DOMAIN_INPUT_TYPE_KBD) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("parallels bus does not support " + "%s input device"), + virDomainInputTypeToString(input->type)); + return -1; + } + } else { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Input devices are not supported by this " + "virtualization driver.")); + return -1; + } + } + switch ((virDomainInputType) input->type) { case VIR_DOMAIN_INPUT_TYPE_MOUSE: case VIR_DOMAIN_INPUT_TYPE_TABLET: @@ -2296,7 +2359,7 @@ virDomainDeviceDefValidateInternal(const virDomainDeviceDef *dev, return virDomainVsockDefValidate(dev->data.vsock); case VIR_DOMAIN_DEVICE_INPUT: - return virDomainInputDefValidate(dev->data.input); + return virDomainInputDefValidate(dev->data.input, def); case VIR_DOMAIN_DEVICE_SHMEM: return virDomainShmemDefValidate(dev->data.shmem);