]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Alter qemuMonitorJSONSetBlockIoThrottle command logic
authorJohn Ferlan <jferlan@redhat.com>
Mon, 7 Nov 2016 19:46:09 +0000 (14:46 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Mon, 5 Dec 2016 23:12:08 +0000 (18:12 -0500)
Currently we build the JSON object for the "block_set_io_throttle"
command using the knowledge that a NULL for a support*Options boolean
would essentially ignore the rest of the arguments.

This may not work properly if some capability was backported, plus it just
looks rather ugly. So instead, build the "base" arguments and then if
the support*Option bool capability is set, add in the arguments on the fly.

Then append those arguments to the basic command and send to qemu.

src/qemu/qemu_monitor_json.c

index 81e86412d45ae3a1c20e07c31358f01c49272dc0..8a51624f230d9e96aebd2c6bfb355b15a9ec809c 100644 (file)
@@ -4568,45 +4568,55 @@ int qemuMonitorJSONSetBlockIoThrottle(qemuMonitorPtr mon,
     int ret = -1;
     virJSONValuePtr cmd = NULL;
     virJSONValuePtr result = NULL;
+    virJSONValuePtr args = NULL;
 
-    /* The qemu capability check has already been made in
-     * qemuDomainSetBlockIoTune. NB, once a NULL is found in
-     * the sequence, qemuMonitorJSONMakeCommand will stop. So
-     * let's make use of that when !supportMaxOptions and
-     * similarly when !supportMaxLengthOptions */
-   cmd = qemuMonitorJSONMakeCommand("block_set_io_throttle",
-                                    "s:device", device,
-                                    "U:bps", info->total_bytes_sec,
-                                    "U:bps_rd", info->read_bytes_sec,
-                                    "U:bps_wr", info->write_bytes_sec,
-                                    "U:iops", info->total_iops_sec,
-                                    "U:iops_rd", info->read_iops_sec,
-                                    "U:iops_wr", info->write_iops_sec,
-                                    !supportMaxOptions ? NULL :
-                                    "U:bps_max", info->total_bytes_sec_max,
-                                    "U:bps_rd_max", info->read_bytes_sec_max,
-                                    "U:bps_wr_max", info->write_bytes_sec_max,
-                                    "U:iops_max", info->total_iops_sec_max,
-                                    "U:iops_rd_max", info->read_iops_sec_max,
-                                    "U:iops_wr_max", info->write_iops_sec_max,
-                                    "U:iops_size", info->size_iops_sec,
-                                    !supportMaxLengthOptions ? NULL :
-                                    "P:bps_max_length",
-                                    info->total_bytes_sec_max_length,
-                                    "P:bps_rd_max_length",
-                                    info->read_bytes_sec_max_length,
-                                    "P:bps_wr_max_length",
-                                    info->write_bytes_sec_max_length,
-                                    "P:iops_max_length",
-                                    info->total_iops_sec_max_length,
-                                    "P:iops_rd_max_length",
-                                    info->read_iops_sec_max_length,
-                                    "P:iops_wr_max_length",
-                                    info->write_iops_sec_max_length,
-                                    NULL);
-    if (!cmd)
+    if (!(cmd = qemuMonitorJSONMakeCommand("block_set_io_throttle", NULL)))
         return -1;
 
+    if (virJSONValueObjectCreate(&args,
+                                 "s:device", device,
+                                 "U:bps", info->total_bytes_sec,
+                                 "U:bps_rd", info->read_bytes_sec,
+                                 "U:bps_wr", info->write_bytes_sec,
+                                 "U:iops", info->total_iops_sec,
+                                 "U:iops_rd", info->read_iops_sec,
+                                 "U:iops_wr", info->write_iops_sec,
+                                 NULL) < 0)
+        goto cleanup;
+
+    if (supportMaxOptions &&
+        virJSONValueObjectAdd(args,
+                              "U:bps_max", info->total_bytes_sec_max,
+                              "U:bps_rd_max", info->read_bytes_sec_max,
+                              "U:bps_wr_max", info->write_bytes_sec_max,
+                              "U:iops_max", info->total_iops_sec_max,
+                              "U:iops_rd_max", info->read_iops_sec_max,
+                              "U:iops_wr_max", info->write_iops_sec_max,
+                              "U:iops_size", info->size_iops_sec,
+                              NULL) < 0)
+        goto cleanup;
+
+    if (supportMaxLengthOptions &&
+        virJSONValueObjectAdd(args,
+                              "P:bps_max_length",
+                              info->total_bytes_sec_max_length,
+                              "P:bps_rd_max_length",
+                              info->read_bytes_sec_max_length,
+                              "P:bps_wr_max_length",
+                              info->write_bytes_sec_max_length,
+                              "P:iops_max_length",
+                              info->total_iops_sec_max_length,
+                              "P:iops_rd_max_length",
+                              info->read_iops_sec_max_length,
+                              "P:iops_wr_max_length",
+                              info->write_iops_sec_max_length,
+                              NULL) < 0)
+        goto cleanup;
+
+    if (virJSONValueObjectAppend(cmd, "arguments", args) < 0)
+        goto cleanup;
+    args = NULL; /* obj owns reference to args now */
+
     if (qemuMonitorJSONCommand(mon, cmd, &result) < 0)
         goto cleanup;
 
@@ -4631,6 +4641,7 @@ int qemuMonitorJSONSetBlockIoThrottle(qemuMonitorPtr mon,
  cleanup:
     virJSONValueFree(cmd);
     virJSONValueFree(result);
+    virJSONValueFree(args);
     return ret;
 }