Add new function to manage adding the input device options to the
command line removing that task from the mainline qemuBuildCommandLine.
Make qemuBuildUSBInputDevStr static since only this module calls it.
Also the change to use const virDomainDef forces other changes.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/qemu/qemu_command.c | 87 +++++++++++++++++++++++++++++--------------------
src/qemu/qemu_command.h | 4 ---
2 files changed, 51 insertions(+), 40 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index d106f61..af09d8c 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3378,7 +3378,7 @@ qemuBuildNVRAMDevStr(virDomainNVRAMDefPtr dev)
}
static char *
-qemuBuildVirtioInputDevStr(virDomainDefPtr def,
+qemuBuildVirtioInputDevStr(const virDomainDef *def,
virDomainInputDefPtr dev,
virQEMUCapsPtr qemuCaps)
{
@@ -3447,8 +3447,8 @@ qemuBuildVirtioInputDevStr(virDomainDefPtr def,
return NULL;
}
-char *
-qemuBuildUSBInputDevStr(virDomainDefPtr def,
+static char *
+qemuBuildUSBInputDevStr(const virDomainDef *def,
virDomainInputDefPtr dev,
virQEMUCapsPtr qemuCaps)
{
@@ -3482,6 +3482,52 @@ qemuBuildUSBInputDevStr(virDomainDefPtr def,
}
+static int
+qemuBuildInputCommandLine(virCommandPtr cmd,
+ const virDomainDef *def,
+ virQEMUCapsPtr qemuCaps)
+{
+ size_t i;
+
+ for (i = 0; i < def->ninputs; i++) {
+ virDomainInputDefPtr input = def->inputs[i];
+
+ if (input->bus == VIR_DOMAIN_INPUT_BUS_USB) {
+ if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE)) {
+ char *optstr;
+ virCommandAddArg(cmd, "-device");
+ if (!(optstr = qemuBuildUSBInputDevStr(def, input, qemuCaps)))
+ return -1;
+ virCommandAddArg(cmd, optstr);
+ VIR_FREE(optstr);
+ } else {
+ switch (input->type) {
+ case VIR_DOMAIN_INPUT_TYPE_MOUSE:
+ virCommandAddArgList(cmd, "-usbdevice",
"mouse", NULL);
+ break;
+ case VIR_DOMAIN_INPUT_TYPE_TABLET:
+ virCommandAddArgList(cmd, "-usbdevice",
"tablet", NULL);
+ break;
+ case VIR_DOMAIN_INPUT_TYPE_KBD:
+ virCommandAddArgList(cmd, "-usbdevice",
"keyboard",
+ NULL);
+ break;
+ }
+ }
+ } else if (input->bus == VIR_DOMAIN_INPUT_BUS_VIRTIO) {
+ char *optstr;
+ virCommandAddArg(cmd, "-device");
+ if (!(optstr = qemuBuildVirtioInputDevStr(def, input, qemuCaps)))
+ return -1;
+ virCommandAddArg(cmd, optstr);
+ VIR_FREE(optstr);
+ }
+ }
+
+ return 0;
+}
+
+
char *
qemuBuildSoundDevStr(virDomainDefPtr def,
virDomainSoundDefPtr sound,
@@ -8387,39 +8433,8 @@ qemuBuildCommandLine(virConnectPtr conn,
if (qemuBuildTPMCommandLine(cmd, def, qemuCaps) < 0)
goto error;
- for (i = 0; i < def->ninputs; i++) {
- virDomainInputDefPtr input = def->inputs[i];
-
- if (input->bus == VIR_DOMAIN_INPUT_BUS_USB) {
- if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE)) {
- char *optstr;
- virCommandAddArg(cmd, "-device");
- if (!(optstr = qemuBuildUSBInputDevStr(def, input, qemuCaps)))
- goto error;
- virCommandAddArg(cmd, optstr);
- VIR_FREE(optstr);
- } else {
- switch (input->type) {
- case VIR_DOMAIN_INPUT_TYPE_MOUSE:
- virCommandAddArgList(cmd, "-usbdevice",
"mouse", NULL);
- break;
- case VIR_DOMAIN_INPUT_TYPE_TABLET:
- virCommandAddArgList(cmd, "-usbdevice",
"tablet", NULL);
- break;
- case VIR_DOMAIN_INPUT_TYPE_KBD:
- virCommandAddArgList(cmd, "-usbdevice",
"keyboard", NULL);
- break;
- }
- }
- } else if (input->bus == VIR_DOMAIN_INPUT_BUS_VIRTIO) {
- char *optstr;
- virCommandAddArg(cmd, "-device");
- if (!(optstr = qemuBuildVirtioInputDevStr(def, input, qemuCaps)))
- goto error;
- virCommandAddArg(cmd, optstr);
- VIR_FREE(optstr);
- }
- }
+ if (qemuBuildInputCommandLine(cmd, def, qemuCaps) < 0)
+ goto error;
for (i = 0; i < def->ngraphics; ++i) {
if (qemuBuildGraphicsCommandLine(cfg, cmd, def, qemuCaps,
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h
index be5a4c4..8a83335 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -133,10 +133,6 @@ char *qemuBuildMemballoonDevStr(virDomainDefPtr domainDef,
virDomainMemballoonDefPtr dev,
virQEMUCapsPtr qemuCaps);
-char *qemuBuildUSBInputDevStr(virDomainDefPtr domainDef,
- virDomainInputDefPtr dev,
- virQEMUCapsPtr qemuCaps);
-
char *qemuBuildSoundDevStr(virDomainDefPtr domainDef,
virDomainSoundDefPtr sound,
virQEMUCapsPtr qemuCaps);
--
2.5.0