[PATCH 4/8] qemu: monitor: Don't escape HMP commands just to unescape them right away

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

 



Historically HMP commands needed to be escaped to work properly.

The backdoor for calling HMP commands via QMP must unescape them so that
arguments aren't messed up.

Since we now only support the QMP passthrough the escape->unescape dance
is pointless.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/qemu/qemu_monitor.c      | 17 +----------------
 src/qemu/qemu_monitor_text.c | 28 +++++-----------------------
 2 files changed, 6 insertions(+), 39 deletions(-)

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 6a09ba91ed..c15b194bb5 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -1258,24 +1258,9 @@ qemuMonitorHMPCommand(qemuMonitorPtr mon,
                       const char *cmd,
                       char **reply)
 {
-    char *json_cmd = NULL;
-    int ret = -1;
-
     QEMU_CHECK_MONITOR(mon);

-    /* hack to avoid complicating each call to text monitor functions */
-    json_cmd = qemuMonitorUnescapeArg(cmd);
-    if (!json_cmd) {
-        VIR_DEBUG("Could not unescape command: %s", cmd);
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("Unable to unescape command"));
-        goto cleanup;
-    }
-    ret = qemuMonitorJSONHumanCommand(mon, json_cmd, reply);
-
- cleanup:
-    VIR_FREE(json_cmd);
-    return ret;
+    return qemuMonitorJSONHumanCommand(mon, cmd, reply);
 }


diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c
index a15c3df76e..7bc28e54c0 100644
--- a/src/qemu/qemu_monitor_text.c
+++ b/src/qemu/qemu_monitor_text.c
@@ -38,15 +38,10 @@ int qemuMonitorTextAddDrive(qemuMonitorPtr mon,
     char *cmd = NULL;
     char *reply = NULL;
     int ret = -1;
-    char *safe_str;
-
-    safe_str = qemuMonitorEscapeArg(drivestr);
-    if (!safe_str)
-        return -1;

     /* 'dummy' here is just a placeholder since there is no PCI
      * address required when attaching drives to a controller */
-    if (virAsprintf(&cmd, "drive_add dummy %s", safe_str) < 0)
+    if (virAsprintf(&cmd, "drive_add dummy %s", drivestr) < 0)
         goto cleanup;

     if (qemuMonitorHMPCommand(mon, cmd, &reply) < 0)
@@ -85,7 +80,6 @@ int qemuMonitorTextAddDrive(qemuMonitorPtr mon,
  cleanup:
     VIR_FREE(cmd);
     VIR_FREE(reply);
-    VIR_FREE(safe_str);
     return ret;
 }

@@ -95,13 +89,9 @@ int qemuMonitorTextDriveDel(qemuMonitorPtr mon,
 {
     char *cmd = NULL;
     char *reply = NULL;
-    char *safedev;
     int ret = -1;

-    if (!(safedev = qemuMonitorEscapeArg(drivestr)))
-        goto cleanup;
-
-    if (virAsprintf(&cmd, "drive_del %s", safedev) < 0)
+    if (virAsprintf(&cmd, "drive_del %s", drivestr) < 0)
         goto cleanup;

     if (qemuMonitorHMPCommand(mon, cmd, &reply) < 0)
@@ -129,7 +119,6 @@ int qemuMonitorTextDriveDel(qemuMonitorPtr mon,
  cleanup:
     VIR_FREE(cmd);
     VIR_FREE(reply);
-    VIR_FREE(safedev);
     return ret;
 }

@@ -140,10 +129,8 @@ qemuMonitorTextCreateSnapshot(qemuMonitorPtr mon,
     char *cmd = NULL;
     char *reply = NULL;
     int ret = -1;
-    char *safename;

-    if (!(safename = qemuMonitorEscapeArg(name)) ||
-        virAsprintf(&cmd, "savevm \"%s\"", safename) < 0)
+    if (virAsprintf(&cmd, "savevm \"%s\"", name) < 0)
         goto cleanup;

     if (qemuMonitorHMPCommand(mon, cmd, &reply))
@@ -166,7 +153,6 @@ qemuMonitorTextCreateSnapshot(qemuMonitorPtr mon,
     ret = 0;

  cleanup:
-    VIR_FREE(safename);
     VIR_FREE(cmd);
     VIR_FREE(reply);
     return ret;
@@ -179,8 +165,7 @@ int qemuMonitorTextLoadSnapshot(qemuMonitorPtr mon, const char *name)
     int ret = -1;
     char *safename;

-    if (!(safename = qemuMonitorEscapeArg(name)) ||
-        virAsprintf(&cmd, "loadvm \"%s\"", safename) < 0)
+    if (virAsprintf(&cmd, "loadvm \"%s\"", name) < 0)
         goto cleanup;

     if (qemuMonitorHMPCommand(mon, cmd, &reply))
@@ -223,10 +208,8 @@ int qemuMonitorTextDeleteSnapshot(qemuMonitorPtr mon, const char *name)
     char *cmd = NULL;
     char *reply = NULL;
     int ret = -1;
-    char *safename;

-    if (!(safename = qemuMonitorEscapeArg(name)) ||
-        virAsprintf(&cmd, "delvm \"%s\"", safename) < 0)
+    if (virAsprintf(&cmd, "delvm \"%s\"", name) < 0)
         goto cleanup;
     if (qemuMonitorHMPCommand(mon, cmd, &reply))
         goto cleanup;
@@ -249,7 +232,6 @@ int qemuMonitorTextDeleteSnapshot(qemuMonitorPtr mon, const char *name)
     ret = 0;

  cleanup:
-    VIR_FREE(safename);
     VIR_FREE(cmd);
     VIR_FREE(reply);
     return ret;
-- 
2.21.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[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