Thursday, 6 September
2018
Thu, 6 Sep
'18
7:22 a.m.
The checks and error messages are mostly the same across
all virtio-input devices, so we can avoid having multiple
copies of the same code.
Signed-off-by: Andrea Bolognani <abologna(a)redhat.com>
---
src/qemu/qemu_domain.c | 51 +++++++++++++++++++++---------------------
1 file changed, 25 insertions(+), 26 deletions(-)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 05e90c3615..cd4e78993f 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -5732,43 +5732,33 @@ qemuDomainDeviceDefValidateInput(const virDomainInputDef *input,
const virDomainDef *def ATTRIBUTE_UNUSED,
virQEMUCapsPtr qemuCaps)
{
+ const char *baseName;
+ int cap;
+ int ccwCap;
+
if (input->bus != VIR_DOMAIN_INPUT_BUS_VIRTIO)
return 0;
switch ((virDomainInputType)input->type) {
case VIR_DOMAIN_INPUT_TYPE_MOUSE:
- if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_MOUSE) ||
- (input->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW &&
- !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VIRTIO_MOUSE_CCW))) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
- _("virtio-mouse is not supported by this QEMU
binary"));
- return -1;
- }
+ baseName = "virtio-mouse";
+ cap = QEMU_CAPS_VIRTIO_MOUSE;
+ ccwCap = QEMU_CAPS_DEVICE_VIRTIO_MOUSE_CCW;
break;
case VIR_DOMAIN_INPUT_TYPE_TABLET:
- if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_TABLET) ||
- (input->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW &&
- !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VIRTIO_TABLET_CCW))) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
- _("virtio-tablet is not supported by this QEMU
binary"));
- return -1;
- }
+ baseName = "virtio-tablet";
+ cap = QEMU_CAPS_VIRTIO_TABLET;
+ ccwCap = QEMU_CAPS_DEVICE_VIRTIO_TABLET_CCW;
break;
case VIR_DOMAIN_INPUT_TYPE_KBD:
- if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_KEYBOARD) ||
- (input->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW &&
- !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VIRTIO_KEYBOARD_CCW))) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
- _("virtio-keyboard is not supported by this QEMU
binary"));
- return -1;
- }
+ baseName = "virtio-keyboard";
+ cap = QEMU_CAPS_VIRTIO_KEYBOARD;
+ ccwCap = QEMU_CAPS_DEVICE_VIRTIO_KEYBOARD_CCW;
break;
case VIR_DOMAIN_INPUT_TYPE_PASSTHROUGH:
- if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_INPUT_HOST)) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
- _("virtio-input-host is not supported by this QEMU
binary"));
- return -1;
- }
+ baseName = "virtio-input-host";
+ cap = QEMU_CAPS_VIRTIO_INPUT_HOST;
+ ccwCap = QEMU_CAPS_VIRTIO_INPUT_HOST;
break;
case VIR_DOMAIN_INPUT_TYPE_LAST:
default:
@@ -5777,6 +5767,15 @@ qemuDomainDeviceDefValidateInput(const virDomainInputDef *input,
return -1;
}
+ if (!virQEMUCapsGet(qemuCaps, cap) ||
+ (input->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW &&
+ !virQEMUCapsGet(qemuCaps, ccwCap))) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("%s is not supported by this QEMU binary"),
+ baseName);
+ return -1;
+ }
+
return 0;
}
--
2.17.1