aboutsummaryrefslogtreecommitdiff
path: root/hmp.c
diff options
context:
space:
mode:
authorAlberto Garcia <berto@igalia.com>2018-03-09 16:11:07 +0200
committerKevin Wolf <kwolf@redhat.com>2018-05-15 16:11:41 +0200
commit83592184d8692c818e083c3ce43f63ca2533fa85 (patch)
treec660338722cad399b44d9fd77132517a0c097d19 /hmp.c
parente18a58b4e3aa355a9b6eef1f39a980a4f18f1294 (diff)
hmp: Allow using a qdev id in block_set_io_throttle
The QMP version of this command can take a qdev ID since 7a9877a02635, but the HMP version is still using the deprecated block device name so there's no way to refer to a block device added like this: -blockdev node-name=disk0,driver=qcow2,file.driver=file,file.filename=hd.qcow2 -device virtio-blk-pci,id=virtio-blk-pci0,drive=disk0 This patch works around this problem by using the specified name as a qdev ID if the block device name is not found. Signed-off-by: Alberto Garcia <berto@igalia.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'hmp.c')
-rw-r--r--hmp.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/hmp.c b/hmp.c
index 898e25f3e1..bdb340605c 100644
--- a/hmp.c
+++ b/hmp.c
@@ -1789,9 +1789,8 @@ void hmp_change(Monitor *mon, const QDict *qdict)
void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
{
Error *err = NULL;
+ char *device = (char *) qdict_get_str(qdict, "device");
BlockIOThrottle throttle = {
- .has_device = true,
- .device = (char *) qdict_get_str(qdict, "device"),
.bps = qdict_get_int(qdict, "bps"),
.bps_rd = qdict_get_int(qdict, "bps_rd"),
.bps_wr = qdict_get_int(qdict, "bps_wr"),
@@ -1800,6 +1799,17 @@ void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
.iops_wr = qdict_get_int(qdict, "iops_wr"),
};
+ /* qmp_block_set_io_throttle has separate parameters for the
+ * (deprecated) block device name and the qdev ID but the HMP
+ * version has only one, so we must decide which one to pass. */
+ if (blk_by_name(device)) {
+ throttle.has_device = true;
+ throttle.device = device;
+ } else {
+ throttle.has_id = true;
+ throttle.id = device;
+ }
+
qmp_block_set_io_throttle(&throttle, &err);
hmp_handle_error(mon, &err);
}