[PATCH RFC 01/39] qemu: monitor: Reuse qemuMonitorJSONQueryBlock in qemuMonitorJSONBlockIoThrottleInfo

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

 



The wrapper executes the command and does error detection so there's no
need to open-code all of those things.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/qemu/qemu_monitor_json.c | 37 +++++--------------------------------
 1 file changed, 5 insertions(+), 32 deletions(-)

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 75d0738b5d..abbcede097 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -4833,21 +4833,14 @@ int qemuMonitorJSONOpenGraphics(qemuMonitorPtr mon,
         goto cleanup; \
     }
 static int
-qemuMonitorJSONBlockIoThrottleInfo(virJSONValuePtr result,
+qemuMonitorJSONBlockIoThrottleInfo(virJSONValuePtr io_throttle,
                                    const char *device,
                                    virDomainBlockIoTuneInfoPtr reply)
 {
-    virJSONValuePtr io_throttle;
     int ret = -1;
     size_t i;
     bool found = false;

-    if (!(io_throttle = virJSONValueObjectGetArray(result, "return"))) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _(" block_io_throttle reply was missing device list"));
-        goto cleanup;
-    }
-
     for (i = 0; i < virJSONValueArraySize(io_throttle); i++) {
         virJSONValuePtr temp_dev = virJSONValueArrayGet(io_throttle, i);
         virJSONValuePtr inserted;
@@ -5017,33 +5010,13 @@ int qemuMonitorJSONGetBlockIoThrottle(qemuMonitorPtr mon,
                                       virDomainBlockIoTuneInfoPtr reply)
 {
     int ret = -1;
-    virJSONValuePtr cmd = NULL;
-    virJSONValuePtr result = NULL;
+    virJSONValuePtr devices = NULL;

-    cmd = qemuMonitorJSONMakeCommand("query-block", NULL);
-    if (!cmd)
+    if (!(devices = qemuMonitorJSONQueryBlock(mon)))
         return -1;

-    if (qemuMonitorJSONCommand(mon, cmd, &result) < 0)
-        goto cleanup;
-
-    if (virJSONValueObjectHasKey(result, "error")) {
-        if (qemuMonitorJSONHasError(result, "DeviceNotActive"))
-            virReportError(VIR_ERR_OPERATION_INVALID,
-                           _("No active operation on device: %s"), device);
-        else if (qemuMonitorJSONHasError(result, "NotSupported"))
-            virReportError(VIR_ERR_OPERATION_INVALID,
-                           _("Operation is not supported for device: %s"), device);
-        else
-            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                           _("Unexpected error"));
-        goto cleanup;
-    }
-
-    ret = qemuMonitorJSONBlockIoThrottleInfo(result, device, reply);
- cleanup:
-    virJSONValueFree(cmd);
-    virJSONValueFree(result);
+    ret = qemuMonitorJSONBlockIoThrottleInfo(devices, device, reply);
+    virJSONValueFree(devices);
     return ret;
 }

-- 
2.16.2

--
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