A function that builds the -device string for input devices.
---
src/qemu/qemu_command.c | 42 +++++++++++++++++++++++++++++-------------
src/qemu/qemu_command.h | 7 +++++++
2 files changed, 36 insertions(+), 13 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 138bbdf1a..7bdff85fc 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -4303,6 +4303,27 @@ qemuBuildUSBInputDevStr(const virDomainDef *def,
}
+int
+qemuBuildInputDevStr(char **devstr,
+ const virDomainDef *def,
+ virDomainInputDefPtr input,
+ virQEMUCapsPtr qemuCaps)
+{
+ switch (input->bus) {
+ case VIR_DOMAIN_INPUT_BUS_USB:
+ if (!(*devstr = qemuBuildUSBInputDevStr(def, input, qemuCaps)))
+ return -1;
+ break;
+
+ case VIR_DOMAIN_INPUT_BUS_VIRTIO:
+ if (!(*devstr = qemuBuildVirtioInputDevStr(def, input, qemuCaps)))
+ return -1;
+ break;
+ }
+ return 0;
+}
+
+
static int
qemuBuildInputCommandLine(virCommandPtr cmd,
const virDomainDef *def,
@@ -4312,22 +4333,17 @@ qemuBuildInputCommandLine(virCommandPtr cmd,
for (i = 0; i < def->ninputs; i++) {
virDomainInputDefPtr input = def->inputs[i];
+ char *devstr = NULL;
- if (input->bus == VIR_DOMAIN_INPUT_BUS_USB) {
- char *optstr;
- virCommandAddArg(cmd, "-device");
- if (!(optstr = qemuBuildUSBInputDevStr(def, input, qemuCaps)))
- return -1;
- virCommandAddArg(cmd, optstr);
- VIR_FREE(optstr);
- } else if (input->bus == VIR_DOMAIN_INPUT_BUS_VIRTIO) {
- char *optstr;
+ if (qemuBuildInputDevStr(&devstr, def, input, qemuCaps) < 0)
+ return -1;
+
+ if (devstr) {
virCommandAddArg(cmd, "-device");
- if (!(optstr = qemuBuildVirtioInputDevStr(def, input, qemuCaps)))
- return -1;
- virCommandAddArg(cmd, optstr);
- VIR_FREE(optstr);
+ virCommandAddArg(cmd, devstr);
}
+
+ VIR_FREE(devstr);
}
return 0;
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h
index 1254ad4df..0961ec8cb 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -204,4 +204,11 @@ char *qemuBuildWatchdogDevStr(const virDomainDef *def,
virDomainWatchdogDefPtr dev,
virQEMUCapsPtr qemuCaps);
+int qemuBuildInputDevStr(char **devstr,
+ const virDomainDef *def,
+ virDomainInputDefPtr input,
+ virQEMUCapsPtr qemuCaps)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
+ ATTRIBUTE_NONNULL(4);
+
#endif /* __QEMU_COMMAND_H__*/
--
2.13.0