The appropriate time to ensure the required capabilities are
present is validate rather than command line generation: add
a new qemuDomainDeviceDefValidateInput() function and move
all existing checks there.
Signed-off-by: Andrea Bolognani <abologna(a)redhat.com>
---
src/qemu/qemu_command.c | 26 ------------------
src/qemu/qemu_domain.c | 59 ++++++++++++++++++++++++++++++++++++++++-
2 files changed, 58 insertions(+), 27 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index e5743fad9d..db7c3ad698 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -4057,41 +4057,15 @@ qemuBuildVirtioInputDevStr(const virDomainDef *def,
switch ((virDomainInputType)dev->type) {
case VIR_DOMAIN_INPUT_TYPE_MOUSE:
- if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_MOUSE) ||
- (dev->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"));
- goto error;
- }
virBufferAsprintf(&buf, "virtio-mouse%s", suffix);
break;
case VIR_DOMAIN_INPUT_TYPE_TABLET:
- if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_TABLET) ||
- (dev->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"));
- goto error;
- }
virBufferAsprintf(&buf, "virtio-tablet%s", suffix);
break;
case VIR_DOMAIN_INPUT_TYPE_KBD:
- if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_KEYBOARD) ||
- (dev->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"));
- goto error;
- }
virBufferAsprintf(&buf, "virtio-keyboard%s", suffix);
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"));
- goto error;
- }
virBufferAsprintf(&buf, "virtio-input-host%s", suffix);
break;
case VIR_DOMAIN_INPUT_TYPE_LAST:
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index f161cf6c84..05e90c3615 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -5727,6 +5727,60 @@ qemuDomainDeviceDefValidateGraphics(const virDomainGraphicsDef
*graphics,
}
+static int
+qemuDomainDeviceDefValidateInput(const virDomainInputDef *input,
+ const virDomainDef *def ATTRIBUTE_UNUSED,
+ virQEMUCapsPtr qemuCaps)
+{
+ 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;
+ }
+ 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;
+ }
+ 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;
+ }
+ 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;
+ }
+ break;
+ case VIR_DOMAIN_INPUT_TYPE_LAST:
+ default:
+ virReportEnumRangeError(virDomainInputType,
+ input->type);
+ return -1;
+ }
+
+ return 0;
+}
+
+
static int
qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
const virDomainDef *def,
@@ -5796,9 +5850,12 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
qemuCaps);
break;
+ case VIR_DOMAIN_DEVICE_INPUT:
+ ret = qemuDomainDeviceDefValidateInput(dev->data.input, def, qemuCaps);
+ break;
+
case VIR_DOMAIN_DEVICE_LEASE:
case VIR_DOMAIN_DEVICE_FS:
- case VIR_DOMAIN_DEVICE_INPUT:
case VIR_DOMAIN_DEVICE_SOUND:
case VIR_DOMAIN_DEVICE_HUB:
case VIR_DOMAIN_DEVICE_MEMBALLOON:
--
2.17.1