From patchwork Fri Oct 28 10:02:23 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: 122378 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E45A3B6F70 for ; Fri, 28 Oct 2011 21:05:12 +1100 (EST) Received: from localhost ([::1]:38007 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RJjJA-0004ZC-1t for incoming@patchwork.ozlabs.org; Fri, 28 Oct 2011 06:05:04 -0400 Received: from eggs.gnu.org ([140.186.70.92]:46058) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RJjJ0-0004Yt-PF for qemu-devel@nongnu.org; Fri, 28 Oct 2011 06:04:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RJjIz-0007Yi-6S for qemu-devel@nongnu.org; Fri, 28 Oct 2011 06:04:54 -0400 Received: from e1.ny.us.ibm.com ([32.97.182.141]:58856) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RJjIz-0007Yb-1R for qemu-devel@nongnu.org; Fri, 28 Oct 2011 06:04:53 -0400 Received: from /spool/local by e1.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 28 Oct 2011 06:03:53 -0400 Received: from d01relay06.pok.ibm.com ([9.56.227.116]) by e1.ny.us.ibm.com ([192.168.1.101]) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 28 Oct 2011 06:03:46 -0400 Received: from d01av03.pok.ibm.com (d01av03.pok.ibm.com [9.56.224.217]) by d01relay06.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p9SA3f4M2396320 for ; Fri, 28 Oct 2011 06:03:41 -0400 Received: from d01av03.pok.ibm.com (loopback [127.0.0.1]) by d01av03.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p9SA3f4h024776 for ; Fri, 28 Oct 2011 08:03:41 -0200 Received: from us.ibm.com ([9.115.118.38]) by d01av03.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with SMTP id p9SA3cBM023509; Fri, 28 Oct 2011 08:03:39 -0200 Received: by us.ibm.com (sSMTP sendmail emulation); Fri, 28 Oct 2011 18:03:24 +0800 From: Zhi Yong Wu To: kwolf@redhat.com Date: Fri, 28 Oct 2011 18:02:23 +0800 Message-Id: <1319796143-9061-5-git-send-email-wuzhy@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.6 In-Reply-To: <1319796143-9061-1-git-send-email-wuzhy@linux.vnet.ibm.com> References: <1319796143-9061-1-git-send-email-wuzhy@linux.vnet.ibm.com> x-cbid: 11102810-6078-0000-0000-000002512DB1 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 32.97.182.141 Cc: wuzhy@linux.vnet.ibm.com, qemu-devel@nongnu.org, stefanha@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH v9 4/4] qmp/hmp: add block_set_io_throttle X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Zhi Yong Wu --- block.c | 27 ++++++++++++++++++++++++--- blockdev.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ blockdev.h | 2 ++ hmp-commands.hx | 15 +++++++++++++++ qerror.c | 4 ++++ qerror.h | 3 +++ qmp-commands.hx | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 7 files changed, 151 insertions(+), 4 deletions(-) diff --git a/block.c b/block.c index 2d85b64..395bbd7 100644 --- a/block.c +++ b/block.c @@ -2164,6 +2164,16 @@ static void bdrv_print_dict(QObject *obj, void *opaque) qdict_get_bool(qdict, "ro"), qdict_get_str(qdict, "drv"), qdict_get_bool(qdict, "encrypted")); + + monitor_printf(mon, " bps=%" PRId64 " bps_rd=%" PRId64 + " bps_wr=%" PRId64 " iops=%" PRId64 + " iops_rd=%" PRId64 " iops_wr=%" PRId64, + qdict_get_int(qdict, "bps"), + qdict_get_int(qdict, "bps_rd"), + qdict_get_int(qdict, "bps_wr"), + qdict_get_int(qdict, "iops"), + qdict_get_int(qdict, "iops_rd"), + qdict_get_int(qdict, "iops_wr")); } else { monitor_printf(mon, " [not inserted]"); } @@ -2214,10 +2224,22 @@ void bdrv_info(Monitor *mon, QObject **ret_data) QObject *obj; obj = qobject_from_jsonf("{ 'file': %s, 'ro': %i, 'drv': %s, " - "'encrypted': %i }", + "'encrypted': %i, " + "'bps': %" PRId64 "," + "'bps_rd': %" PRId64 "," + "'bps_wr': %" PRId64 "," + "'iops': %" PRId64 "," + "'iops_rd': %" PRId64 "," + "'iops_wr': %" PRId64 "}", bs->filename, bs->read_only, bs->drv->format_name, - bdrv_is_encrypted(bs)); + bdrv_is_encrypted(bs), + bs->io_limits.bps[BLOCK_IO_LIMIT_TOTAL], + bs->io_limits.bps[BLOCK_IO_LIMIT_READ], + bs->io_limits.bps[BLOCK_IO_LIMIT_WRITE], + bs->io_limits.iops[BLOCK_IO_LIMIT_TOTAL], + bs->io_limits.iops[BLOCK_IO_LIMIT_READ], + bs->io_limits.iops[BLOCK_IO_LIMIT_WRITE]); if (bs->backing_file[0] != '\0') { QDict *qdict = qobject_to_qdict(obj); qdict_put(qdict, "backing_file", @@ -2405,7 +2427,6 @@ void bdrv_debug_event(BlockDriverState *bs, BlkDebugEvent event) } return drv->bdrv_debug_event(bs, event); - } /**************************************************************/ diff --git a/blockdev.c b/blockdev.c index faf8c56..9eed973 100644 --- a/blockdev.c +++ b/blockdev.c @@ -745,6 +745,57 @@ 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"); + int64_t bps = qdict_get_try_int(qdict, "bps", -1); + int64_t bps_rd = qdict_get_try_int(qdict, "bps_rd", -1); + int64_t bps_wr = qdict_get_try_int(qdict, "bps_wr", -1); + int64_t iops = qdict_get_try_int(qdict, "iops", -1); + int64_t iops_rd = qdict_get_try_int(qdict, "iops_rd", -1); + int64_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 != 0 && (bps_rd != 0 || bps_wr != 0)) + || (iops != 0 && (iops_rd != 0 || iops_wr != 0))) { + qerror_report(QERR_INVALID_PARAMETER_COMBINATION); + return -1; + } + + bs->io_limits.bps[BLOCK_IO_LIMIT_TOTAL] = bps; + bs->io_limits.bps[BLOCK_IO_LIMIT_READ] = bps_rd; + bs->io_limits.bps[BLOCK_IO_LIMIT_WRITE] = bps_wr; + bs->io_limits.iops[BLOCK_IO_LIMIT_TOTAL] = iops; + bs->io_limits.iops[BLOCK_IO_LIMIT_READ] = iops_rd; + bs->io_limits.iops[BLOCK_IO_LIMIT_WRITE] = iops_wr; + bs->slice_time = BLOCK_IO_SLICE_TIME; + + 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); + } else { + qemu_mod_timer(bs->block_timer, qemu_get_clock_ns(vm_clock)); + } + + 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 3587786..1b48a75 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 ab08d58..a2fdf68 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1207,6 +1207,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 limits 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 68998d4..6fe53b6 100644 --- a/qerror.c +++ b/qerror.c @@ -234,6 +234,10 @@ static const QErrorStringTable qerror_table[] = { .error_fmt = QERR_QGA_COMMAND_FAILED, .desc = "Guest agent command failed, error was '%(message)'", }, + { + .error_fmt = QERR_INVALID_PARAMETER_COMBINATION, + .desc = "Invalid paramter combination", + }, {} }; diff --git a/qerror.h b/qerror.h index d4bfcfd..777a36a 100644 --- a/qerror.h +++ b/qerror.h @@ -198,4 +198,7 @@ QError *qobject_to_qerror(const QObject *obj); #define QERR_QGA_COMMAND_FAILED \ "{ 'class': 'QgaCommandFailed', 'data': { 'message': %s } }" +#define QERR_INVALID_PARAMETER_COMBINATION \ + "{ 'class': 'InvalidParameterCombination', 'data': {} }" + #endif /* QERROR_H */ diff --git a/qmp-commands.hx b/qmp-commands.hx index 4328e8b..6aa90b7 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -853,6 +853,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 limits 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", @@ -1154,6 +1192,13 @@ 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) + - "io-status": I/O operation status, only present if the device supports it and the VM is configured to stop on errors. It's always reset to "ok" when the "cont" command is issued (json_string, optional) @@ -1173,7 +1218,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" },