Re: [libvirt] [PATCH 7/8] qemu: monitor: Drop calls to text monitor impl where possible

2018-05-22 Thread Ján Tomko

On Tue, May 22, 2018 at 02:35:47PM +0200, Peter Krempa wrote:

Drop all conditional calls which have JSON variants, now that we
guarantee JSON monitor.

Signed-off-by: Peter Krempa 
---
src/qemu/qemu_monitor.c | 297 +++-
1 file changed, 69 insertions(+), 228 deletions(-)



Reviewed-by: Ján Tomko 

Jano


signature.asc
Description: Digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH 7/8] qemu: monitor: Drop calls to text monitor impl where possible

2018-05-22 Thread Peter Krempa
Drop all conditional calls which have JSON variants, now that we
guarantee JSON monitor.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_monitor.c | 297 +++-
 1 file changed, 69 insertions(+), 228 deletions(-)

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index e07d578fa8..ac1fbddb91 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -430,15 +430,9 @@ qemuMonitorIOProcess(qemuMonitorPtr mon)
 PROBE_QUIET(QEMU_MONITOR_IO_PROCESS, "mon=%p buf=%s len=%zu",
 mon, mon->buffer, mon->bufferOffset);

-if (mon->json)
-len = qemuMonitorJSONIOProcess(mon,
-   mon->buffer, mon->bufferOffset,
-   msg);
-else
-len = qemuMonitorTextIOProcess(mon,
-   mon->buffer, mon->bufferOffset,
-   msg);
-
+len = qemuMonitorJSONIOProcess(mon,
+   mon->buffer, mon->bufferOffset,
+   msg);
 if (len < 0)
 return -1;

@@ -1264,19 +1258,15 @@ qemuMonitorHMPCommandWithFd(qemuMonitorPtr mon,

 QEMU_CHECK_MONITOR(mon);

-if (mon->json) {
-/* 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 = qemuMonitorJSONHumanCommandWithFd(mon, json_cmd, scm_fd, reply);
-} else {
-ret = qemuMonitorTextCommandWithFd(mon, cmd, scm_fd, reply);
+/* 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 = qemuMonitorJSONHumanCommandWithFd(mon, json_cmd, scm_fd, reply);

  cleanup:
 VIR_FREE(json_cmd);
@@ -1683,10 +1673,7 @@ qemuMonitorStartCPUs(qemuMonitorPtr mon)
 {
 QEMU_CHECK_MONITOR(mon);

-if (mon->json)
-return qemuMonitorJSONStartCPUs(mon);
-else
-return qemuMonitorTextStartCPUs(mon);
+return qemuMonitorJSONStartCPUs(mon);
 }


@@ -1695,10 +1682,7 @@ qemuMonitorStopCPUs(qemuMonitorPtr mon)
 {
 QEMU_CHECK_MONITOR(mon);

-if (mon->json)
-return qemuMonitorJSONStopCPUs(mon);
-else
-return qemuMonitorTextStopCPUs(mon);
+return qemuMonitorJSONStopCPUs(mon);
 }


@@ -1719,10 +1703,7 @@ qemuMonitorGetStatus(qemuMonitorPtr mon,

 QEMU_CHECK_MONITOR(mon);

-if (mon->json)
-return qemuMonitorJSONGetStatus(mon, running, reason);
-else
-return qemuMonitorTextGetStatus(mon, running, reason);
+return qemuMonitorJSONGetStatus(mon, running, reason);
 }


@@ -1731,10 +1712,7 @@ qemuMonitorSystemPowerdown(qemuMonitorPtr mon)
 {
 QEMU_CHECK_MONITOR(mon);

-if (mon->json)
-return qemuMonitorJSONSystemPowerdown(mon);
-else
-return qemuMonitorTextSystemPowerdown(mon);
+return qemuMonitorJSONSystemPowerdown(mon);
 }


@@ -1743,10 +1721,7 @@ qemuMonitorSystemReset(qemuMonitorPtr mon)
 {
 QEMU_CHECK_MONITOR(mon);

-if (mon->json)
-return qemuMonitorJSONSystemReset(mon);
-else
-return qemuMonitorTextSystemReset(mon);
+return qemuMonitorJSONSystemReset(mon);
 }


@@ -2011,11 +1986,8 @@ qemuMonitorGetCPUInfo(qemuMonitorPtr mon,
 (qemuMonitorJSONGetHotpluggableCPUs(mon, &hotplugcpus, &nhotplugcpus)) 
< 0)
 goto cleanup;

-if (mon->json)
-rc = qemuMonitorJSONQueryCPUs(mon, &cpuentries, &ncpuentries, hotplug,
-  fast);
-else
-rc = qemuMonitorTextQueryCPUs(mon, &cpuentries, &ncpuentries);
+rc = qemuMonitorJSONQueryCPUs(mon, &cpuentries, &ncpuentries, hotplug,
+  fast);

 if (rc < 0) {
 if (!hotplug && rc == -2) {
@@ -2066,11 +2038,8 @@ qemuMonitorGetCpuHalted(qemuMonitorPtr mon,

 QEMU_CHECK_MONITOR_NULL(mon);

-if (mon->json)
-rc = qemuMonitorJSONQueryCPUs(mon, &cpuentries, &ncpuentries, false,
-  fast);
-else
-rc = qemuMonitorTextQueryCPUs(mon, &cpuentries, &ncpuentries);
+rc = qemuMonitorJSONQueryCPUs(mon, &cpuentries, &ncpuentries, false,
+  fast);

 if (rc < 0)
 goto cleanup;
@@ -2098,10 +2067,7 @@ qemuMonitorSetLink(qemuMonitorPtr mon,

 QEMU_CHECK_MONITOR(mon);

-if (mon->json)
-return qemuMonitorJSONSetLink(mon, name, state);
-else
-return qemuMonitorTextSetLink(mon, name, state);