[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH REPOST 7/8] qemu: Introduce qemuBuildInputCommandLine



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 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 258fac4..defc3e9 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3433,7 +3433,7 @@ qemuBuildNVRAMDevStr(virDomainNVRAMDefPtr dev)
 }
 
 static char *
-qemuBuildVirtioInputDevStr(virDomainDefPtr def,
+qemuBuildVirtioInputDevStr(const virDomainDef *def,
                            virDomainInputDefPtr dev,
                            virQEMUCapsPtr qemuCaps)
 {
@@ -3502,8 +3502,8 @@ qemuBuildVirtioInputDevStr(virDomainDefPtr def,
     return NULL;
 }
 
-char *
-qemuBuildUSBInputDevStr(virDomainDefPtr def,
+static char *
+qemuBuildUSBInputDevStr(const virDomainDef *def,
                         virDomainInputDefPtr dev,
                         virQEMUCapsPtr qemuCaps)
 {
@@ -3537,6 +3537,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,
@@ -8531,39 +8577,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 0316f43..d3e676b 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -138,10 +138,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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]