[PATCH 005/103] qemuBuildInputDevStr: Don't mix generators for -object and -device

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

 



Input devices of VIR_DOMAIN_INPUT_TYPE_EVDEV type are instantiated via
an '-object' rather than a '-device'. Mixing them in one function is a
bad idea as the caller then needs to use the string correctly which is
not the case in 'qemuDomainAttachInputDevice'.

Generate a JSON object for '-object' explicitly.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/qemu/qemu_command.c | 43 ++++++++++++++++++++++-------------------
 1 file changed, 23 insertions(+), 20 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index dcd6a6e75d..a4d439a0ec 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3887,12 +3887,10 @@ qemuBuildUSBInputDevStr(const virDomainDef *def,
 }


-static char *
-qemuBuildObjectInputDevStr(virDomainInputDef *dev,
-                           virQEMUCaps *qemuCaps)
+static virJSONValue *
+qemuBuildInputEvdevProps(virDomainInputDef *dev)
 {
     g_autoptr(virJSONValue) props = NULL;
-    g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;

     if (qemuMonitorCreateObjectProps(&props, "input-linux", dev->info.alias,
                                      "s:evdev", dev->source.evdev,
@@ -3908,10 +3906,7 @@ qemuBuildObjectInputDevStr(virDomainInputDef *dev,
                               virDomainInputSourceGrabToggleTypeToString(dev->source.grabToggle),
                               NULL);

-    if (qemuBuildObjectCommandlineFromJSON(&buf, props, qemuCaps) < 0)
-        return NULL;
-
-    return virBufferContentAndReset(&buf);
+    return g_steal_pointer(&props);
 }


@@ -3931,10 +3926,6 @@ qemuBuildInputDevStr(char **devstr,
         if (!(*devstr = qemuBuildVirtioInputDevStr(def, input, qemuCaps)))
             return -1;
         break;
-    case VIR_DOMAIN_INPUT_BUS_NONE:
-        if (!(*devstr = qemuBuildObjectInputDevStr(input, qemuCaps)))
-            return -1;
-        break;
     }
     return 0;
 }
@@ -3949,20 +3940,32 @@ qemuBuildInputCommandLine(virCommand *cmd,

     for (i = 0; i < def->ninputs; i++) {
         virDomainInputDef *input = def->inputs[i];
-        g_autofree char *devstr = NULL;

         if (qemuCommandAddExtDevice(cmd, &input->info) < 0)
             return -1;

-        if (qemuBuildInputDevStr(&devstr, def, input, qemuCaps) < 0)
-            return -1;
+        if (input->type == VIR_DOMAIN_INPUT_TYPE_EVDEV) {
+            g_autoptr(virJSONValue) props = NULL;
+            g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;

-        if (devstr) {
-            if (input->type == VIR_DOMAIN_INPUT_TYPE_EVDEV)
-                virCommandAddArg(cmd, "-object");
-            else
+            if (!(props = qemuBuildInputEvdevProps(input)))
+                return -1;
+
+            if (qemuBuildObjectCommandlineFromJSON(&buf, props, qemuCaps) < 0)
+                return -1;
+
+            virCommandAddArg(cmd, "-object");
+            virCommandAddArgBuffer(cmd, &buf);
+        } else {
+            g_autofree char *devstr = NULL;
+
+            if (qemuBuildInputDevStr(&devstr, def, input, qemuCaps) < 0)
+                return -1;
+
+            if (devstr) {
                 virCommandAddArg(cmd, "-device");
-            virCommandAddArg(cmd, devstr);
+                virCommandAddArg(cmd, devstr);
+            }
         }
     }

-- 
2.31.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux