提交 ad9f1273 编写于 作者: J John Ferlan

qemu: Alter qemuMonitorJSONSetBlockIoThrottle command logic

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.
上级 c84ad82a
...@@ -4568,45 +4568,55 @@ int qemuMonitorJSONSetBlockIoThrottle(qemuMonitorPtr mon, ...@@ -4568,45 +4568,55 @@ int qemuMonitorJSONSetBlockIoThrottle(qemuMonitorPtr mon,
int ret = -1; int ret = -1;
virJSONValuePtr cmd = NULL; virJSONValuePtr cmd = NULL;
virJSONValuePtr result = NULL; virJSONValuePtr result = NULL;
virJSONValuePtr args = NULL;
/* The qemu capability check has already been made in if (!(cmd = qemuMonitorJSONMakeCommand("block_set_io_throttle", NULL)))
* 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)
return -1; 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) if (qemuMonitorJSONCommand(mon, cmd, &result) < 0)
goto cleanup; goto cleanup;
...@@ -4631,6 +4641,7 @@ int qemuMonitorJSONSetBlockIoThrottle(qemuMonitorPtr mon, ...@@ -4631,6 +4641,7 @@ int qemuMonitorJSONSetBlockIoThrottle(qemuMonitorPtr mon,
cleanup: cleanup:
virJSONValueFree(cmd); virJSONValueFree(cmd);
virJSONValueFree(result); virJSONValueFree(result);
virJSONValueFree(args);
return ret; return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册