From patchwork Tue Aug 9 04:17:52 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhi Yong Wu X-Patchwork-Id: 1047482 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p794Lkde030244 for ; Tue, 9 Aug 2011 04:21:46 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751123Ab1HIEVo (ORCPT ); Tue, 9 Aug 2011 00:21:44 -0400 Received: from e8.ny.us.ibm.com ([32.97.182.138]:54290 "EHLO e8.ny.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750916Ab1HIEVn (ORCPT ); Tue, 9 Aug 2011 00:21:43 -0400 Received: from d01relay01.pok.ibm.com (d01relay01.pok.ibm.com [9.56.227.233]) by e8.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id p7948UcP019357 for ; Tue, 9 Aug 2011 00:08:30 -0400 Received: from d01av04.pok.ibm.com (d01av04.pok.ibm.com [9.56.224.64]) by d01relay01.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p794LgTO234648 for ; Tue, 9 Aug 2011 00:21:42 -0400 Received: from d01av04.pok.ibm.com (loopback [127.0.0.1]) by d01av04.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p794Lfqm001711 for ; Tue, 9 Aug 2011 00:21:42 -0400 Received: from us.ibm.com (wks563189wss.cn.ibm.com [9.123.136.155] (may be forged)) by d01av04.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with SMTP id p794LabE001635; Tue, 9 Aug 2011 00:21:36 -0400 Received: by us.ibm.com (sSMTP sendmail emulation); Tue, 9 Aug 2011 12:18:27 +0800 From: Zhi Yong Wu To: qemu-devel@nongnu.org Cc: kvm@vger.kernel.org, stefanha@linux.vnet.ibm.com, mtosatti@redhat.com, anthony@codemonkey.ws, ryanh@us.ibm.com, zwu.kernel@gmail.com, kwolf@redhat.com, pair@us.ibm.com, luowenj@cn.ibm.com, Zhi Yong Wu Subject: [PATCH v5 4/4] qmp/hmp: add block_set_io_throttle Date: Tue, 9 Aug 2011 12:17:52 +0800 Message-Id: <1312863472-6901-5-git-send-email-wuzhy@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <1312863472-6901-1-git-send-email-wuzhy@linux.vnet.ibm.com> References: <1312863472-6901-1-git-send-email-wuzhy@linux.vnet.ibm.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Tue, 09 Aug 2011 04:21:46 +0000 (UTC) The patch introduce one new command block_set_io_throttle; For its usage syntax, if you have better idea, pls let me know. Signed-off-by: Zhi Yong Wu --- blockdev.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ blockdev.h | 2 + hmp-commands.hx | 15 ++++++++++++ qerror.c | 4 +++ qerror.h | 3 ++ qmp-commands.hx | 52 ++++++++++++++++++++++++++++++++++++++++- 6 files changed, 144 insertions(+), 1 deletions(-) diff --git a/blockdev.c b/blockdev.c index 9c78548..ddf7af9 100644 --- a/blockdev.c +++ b/blockdev.c @@ -782,6 +782,75 @@ int do_change_block(Monitor *mon, const char *device, return monitor_read_bdrv_key_start(mon, bs, NULL, NULL); } +/* throttling disk I/O limits */ +int do_block_set_io_throttle(Monitor *mon, + const QDict *qdict, QObject **ret_data) +{ + const char *devname = qdict_get_str(qdict, "device"); + uint64_t bps = qdict_get_try_int(qdict, "bps", -1); + uint64_t bps_rd = qdict_get_try_int(qdict, "bps_rd", -1); + uint64_t bps_wr = qdict_get_try_int(qdict, "bps_wr", -1); + uint64_t iops = qdict_get_try_int(qdict, "iops", -1); + uint64_t iops_rd = qdict_get_try_int(qdict, "iops_rd", -1); + uint64_t iops_wr = qdict_get_try_int(qdict, "iops_wr", -1); + BlockDriverState *bs; + + bs = bdrv_find(devname); + if (!bs) { + qerror_report(QERR_DEVICE_NOT_FOUND, devname); + return -1; + } + + if ((bps == -1) && (bps_rd == -1) && (bps_wr == -1) + && (iops == -1) && (iops_rd == -1) && (iops_wr == -1)) { + qerror_report(QERR_MISSING_PARAMETER, + "bps/bps_rd/bps_wr/iops/iops_rd/iops_wr"); + return -1; + } + + if (((bps != -1) && ((bps_rd != -1) || (bps_wr != -1))) + || ((iops != -1) && ((iops_rd != -1) || (iops_wr != -1)))) { + qerror_report(QERR_INVALID_PARAMETER_COMBINATION); + return -1; + } + + if (bps != -1) { + bs->io_limits.bps[BLOCK_IO_LIMIT_TOTAL] = bps; + bs->io_limits.bps[BLOCK_IO_LIMIT_READ] = 0; + bs->io_limits.bps[BLOCK_IO_LIMIT_WRITE] = 0; + } + + if ((bps_rd != -1) || (bps_wr != -1)) { + bs->io_limits.bps[BLOCK_IO_LIMIT_READ] = + (bps_rd == -1) ? bs->io_limits.bps[BLOCK_IO_LIMIT_READ] : bps_rd; + bs->io_limits.bps[BLOCK_IO_LIMIT_WRITE] = + (bps_wr == -1) ? bs->io_limits.bps[BLOCK_IO_LIMIT_WRITE] : bps_wr; + bs->io_limits.bps[BLOCK_IO_LIMIT_TOTAL] = 0; + } + + if (iops != -1) { + bs->io_limits.iops[BLOCK_IO_LIMIT_TOTAL] = iops; + bs->io_limits.iops[BLOCK_IO_LIMIT_READ] = 0; + bs->io_limits.iops[BLOCK_IO_LIMIT_WRITE] = 0; + } + + if ((iops_rd != -1) || (iops_wr != -1)) { + bs->io_limits.iops[BLOCK_IO_LIMIT_READ] = + (iops_rd == -1) ? bs->io_limits.iops[BLOCK_IO_LIMIT_READ] : iops_rd; + bs->io_limits.iops[BLOCK_IO_LIMIT_WRITE] = + (iops_wr == -1) ? bs->io_limits.iops[BLOCK_IO_LIMIT_WRITE] : iops_wr; + bs->io_limits.iops[BLOCK_IO_LIMIT_TOTAL] = 0; + } + + if (!bs->io_limits_enabled && bdrv_io_limits_enabled(bs)) { + bdrv_io_limits_enable(bs); + } else if (bs->io_limits_enabled && !bdrv_io_limits_enabled(bs)) { + bdrv_io_limits_disable(bs); + } + + return 0; +} + int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data) { const char *id = qdict_get_str(qdict, "id"); diff --git a/blockdev.h b/blockdev.h index 0a5144c..d0d0d77 100644 --- a/blockdev.h +++ b/blockdev.h @@ -63,6 +63,8 @@ int do_block_set_passwd(Monitor *mon, const QDict *qdict, QObject **ret_data); int do_change_block(Monitor *mon, const char *device, const char *filename, const char *fmt); int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data); +int do_block_set_io_throttle(Monitor *mon, + const QDict *qdict, QObject **ret_data); int do_snapshot_blkdev(Monitor *mon, const QDict *qdict, QObject **ret_data); int do_block_resize(Monitor *mon, const QDict *qdict, QObject **ret_data); diff --git a/hmp-commands.hx b/hmp-commands.hx index aceba74..3ca496d 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1210,6 +1210,21 @@ ETEXI }, STEXI +@item block_set_io_throttle @var{device} @var{bps} @var{bps_rd} @var{bps_wr} @var{iops} @var{iops_rd} @var{iops_wr} +@findex block_set_io_throttle +Change I/O throttle limits for a block drive to @var{bps} @var{bps_rd} @var{bps_wr} @var{iops} @var{iops_rd} @var{iops_wr} +ETEXI + + { + .name = "block_set_io_throttle", + .args_type = "device:B,bps:i?,bps_rd:i?,bps_wr:i?,iops:i?,iops_rd:i?,iops_wr:i?", + .params = "device [bps] [bps_rd] [bps_wr] [iops] [iops_rd] [iops_wr]", + .help = "change I/O throttle limts for a block drive", + .user_print = monitor_user_noop, + .mhandler.cmd_new = do_block_set_io_throttle, + }, + +STEXI @item block_passwd @var{device} @var{password} @findex block_passwd Set the encrypted device @var{device} password to @var{password} diff --git a/qerror.c b/qerror.c index d7fcd93..3a21560 100644 --- a/qerror.c +++ b/qerror.c @@ -213,6 +213,10 @@ static const QErrorStringTable qerror_table[] = { .error_fmt = QERR_VNC_SERVER_FAILED, .desc = "Could not start VNC server on %(target)", }, + { + .error_fmt = QERR_INVALID_PARAMETER_COMBINATION, + .desc = "Invalid paramter combination", + }, {} }; diff --git a/qerror.h b/qerror.h index 16c830d..81cfe79 100644 --- a/qerror.h +++ b/qerror.h @@ -181,4 +181,7 @@ QError *qobject_to_qerror(const QObject *obj); #define QERR_FEATURE_DISABLED \ "{ 'class': 'FeatureDisabled', 'data': { 'name': %s } }" +#define QERR_INVALID_PARAMETER_COMBINATION \ + "{ 'class': 'InvalidParameterCombination', 'data': {} }" + #endif /* QERROR_H */ diff --git a/qmp-commands.hx b/qmp-commands.hx index 92c5c3a..9b594cd 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -828,6 +828,44 @@ Example: EQMP { + .name = "block_set_io_throttle", + .args_type = "device:B,bps:i?,bps_rd:i?,bps_wr:i?,iops:i?,iops_rd:i?,iops_wr:i?", + .params = "device [bps] [bps_rd] [bps_wr] [iops] [iops_rd] [iops_wr]", + .help = "change I/O throttle limts for a block drive", + .user_print = monitor_user_noop, + .mhandler.cmd_new = do_block_set_io_throttle, + }, + +SQMP +block_set_io_throttle +------------ + +Change I/O throttle limits for a block drive. + +Arguments: + +- "device": device name (json-string) +- "bps": total throughput limit in bytes per second(json-int, optional) +- "bps_rd": read throughput limit in bytes per second(json-int, optional) +- "bps_wr": read throughput limit in bytes per second(json-int, optional) +- "iops": total I/O operations per second(json-int, optional) +- "iops_rd": read I/O operations per second(json-int, optional) +- "iops_wr": write I/O operations per second(json-int, optional) + +Example: + +-> { "execute": "block_set_io_throttle", "arguments": { "device": "virtio0", + "bps": "1000000", + "bps_rd": "0", + "bps_wr": "0", + "iops": "0", + "iops_rd": "0", + "iops_wr": "0" } } +<- { "return": {} } + +EQMP + + { .name = "set_password", .args_type = "protocol:s,password:s,connected:s?", .params = "protocol password action-if-connected", @@ -1082,6 +1120,12 @@ Each json-object contain the following: "tftp", "vdi", "vmdk", "vpc", "vvfat" - "backing_file": backing file name (json-string, optional) - "encrypted": true if encrypted, false otherwise (json-bool) + - "bps": limit total bytes per second (json-int) + - "bps_rd": limit read bytes per second (json-int) + - "bps_wr": limit write bytes per second (json-int) + - "iops": limit total I/O operations per second (json-int) + - "iops_rd": limit read operations per second (json-int) + - "iops_wr": limit write operations per second (json-int) Example: @@ -1096,7 +1140,13 @@ Example: "ro":false, "drv":"qcow2", "encrypted":false, - "file":"disks/test.img" + "file":"disks/test.img", + "bps":1000000, + "bps_rd":0, + "bps_wr":0, + "iops":1000000, + "iops_rd":0, + "iops_wr":0, }, "type":"unknown" },