mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-20 07:59:00 +00:00
virDomainInputDefParseXML: Move validation into validator
There is some code that validates whether parsed @bus <input/> 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 <mprivozn@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
ddb2384f0c
commit
3de95c3d51
@ -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 ||
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user