From patchwork Tue Jul 19 11:39:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 9236843 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5A4D060574 for ; Tue, 19 Jul 2016 11:49:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 42DC820265 for ; Tue, 19 Jul 2016 11:49:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3450A26A4D; Tue, 19 Jul 2016 11:49:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2670B20265 for ; Tue, 19 Jul 2016 11:49:04 +0000 (UTC) Received: from localhost ([::1]:54864 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPTWJ-0004X7-6I for patchwork-qemu-devel@patchwork.kernel.org; Tue, 19 Jul 2016 07:49:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50945) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPTNM-0001ZO-1l for qemu-devel@nongnu.org; Tue, 19 Jul 2016 07:39:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bPTNI-0001vd-KQ for qemu-devel@nongnu.org; Tue, 19 Jul 2016 07:39:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35499) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPTNI-0001vQ-BZ for qemu-devel@nongnu.org; Tue, 19 Jul 2016 07:39:44 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E3F92600D for ; Tue, 19 Jul 2016 11:39:43 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-35.ams2.redhat.com [10.36.116.35]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u6JBdfnT020631 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 19 Jul 2016 07:39:42 -0400 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 1F01911AD298; Tue, 19 Jul 2016 13:39:38 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Tue, 19 Jul 2016 13:39:34 +0200 Message-Id: <1468928377-20384-13-git-send-email-armbru@redhat.com> In-Reply-To: <1468928377-20384-1-git-send-email-armbru@redhat.com> References: <1468928377-20384-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 19 Jul 2016 11:39:43 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL for-2.7 12/15] block: Simplify block_set_io_throttle X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Eric Blake Now that we can support boxed commands, use it to greatly reduce the number of parameters (and likelihood of getting out of sync) when adjusting throttle parameters. Signed-off-by: Eric Blake Reviewed-by: Alberto Garcia Message-Id: <1468468228-27827-11-git-send-email-eblake@redhat.com> Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- blockdev.c | 111 +++++++++++++++++++-------------------------------- hmp.c | 45 +++++---------------- qapi/block-core.json | 20 ++++++++-- 3 files changed, 66 insertions(+), 110 deletions(-) diff --git a/blockdev.c b/blockdev.c index 384ad3b..c5443c1 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2634,49 +2634,17 @@ fail: } /* throttling disk I/O limits */ -void qmp_block_set_io_throttle(const char *device, int64_t bps, int64_t bps_rd, - int64_t bps_wr, - int64_t iops, - int64_t iops_rd, - int64_t iops_wr, - bool has_bps_max, - int64_t bps_max, - bool has_bps_rd_max, - int64_t bps_rd_max, - bool has_bps_wr_max, - int64_t bps_wr_max, - bool has_iops_max, - int64_t iops_max, - bool has_iops_rd_max, - int64_t iops_rd_max, - bool has_iops_wr_max, - int64_t iops_wr_max, - bool has_bps_max_length, - int64_t bps_max_length, - bool has_bps_rd_max_length, - int64_t bps_rd_max_length, - bool has_bps_wr_max_length, - int64_t bps_wr_max_length, - bool has_iops_max_length, - int64_t iops_max_length, - bool has_iops_rd_max_length, - int64_t iops_rd_max_length, - bool has_iops_wr_max_length, - int64_t iops_wr_max_length, - bool has_iops_size, - int64_t iops_size, - bool has_group, - const char *group, Error **errp) +void qmp_block_set_io_throttle(BlockIOThrottle *arg, Error **errp) { ThrottleConfig cfg; BlockDriverState *bs; BlockBackend *blk; AioContext *aio_context; - blk = blk_by_name(device); + blk = blk_by_name(arg->device); if (!blk) { error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, - "Device '%s' not found", device); + "Device '%s' not found", arg->device); return; } @@ -2685,59 +2653,59 @@ void qmp_block_set_io_throttle(const char *device, int64_t bps, int64_t bps_rd, bs = blk_bs(blk); if (!bs) { - error_setg(errp, "Device '%s' has no medium", device); + error_setg(errp, "Device '%s' has no medium", arg->device); goto out; } throttle_config_init(&cfg); - cfg.buckets[THROTTLE_BPS_TOTAL].avg = bps; - cfg.buckets[THROTTLE_BPS_READ].avg = bps_rd; - cfg.buckets[THROTTLE_BPS_WRITE].avg = bps_wr; + cfg.buckets[THROTTLE_BPS_TOTAL].avg = arg->bps; + cfg.buckets[THROTTLE_BPS_READ].avg = arg->bps_rd; + cfg.buckets[THROTTLE_BPS_WRITE].avg = arg->bps_wr; - cfg.buckets[THROTTLE_OPS_TOTAL].avg = iops; - cfg.buckets[THROTTLE_OPS_READ].avg = iops_rd; - cfg.buckets[THROTTLE_OPS_WRITE].avg = iops_wr; + cfg.buckets[THROTTLE_OPS_TOTAL].avg = arg->iops; + cfg.buckets[THROTTLE_OPS_READ].avg = arg->iops_rd; + cfg.buckets[THROTTLE_OPS_WRITE].avg = arg->iops_wr; - if (has_bps_max) { - cfg.buckets[THROTTLE_BPS_TOTAL].max = bps_max; + if (arg->has_bps_max) { + cfg.buckets[THROTTLE_BPS_TOTAL].max = arg->bps_max; } - if (has_bps_rd_max) { - cfg.buckets[THROTTLE_BPS_READ].max = bps_rd_max; + if (arg->has_bps_rd_max) { + cfg.buckets[THROTTLE_BPS_READ].max = arg->bps_rd_max; } - if (has_bps_wr_max) { - cfg.buckets[THROTTLE_BPS_WRITE].max = bps_wr_max; + if (arg->has_bps_wr_max) { + cfg.buckets[THROTTLE_BPS_WRITE].max = arg->bps_wr_max; } - if (has_iops_max) { - cfg.buckets[THROTTLE_OPS_TOTAL].max = iops_max; + if (arg->has_iops_max) { + cfg.buckets[THROTTLE_OPS_TOTAL].max = arg->iops_max; } - if (has_iops_rd_max) { - cfg.buckets[THROTTLE_OPS_READ].max = iops_rd_max; + if (arg->has_iops_rd_max) { + cfg.buckets[THROTTLE_OPS_READ].max = arg->iops_rd_max; } - if (has_iops_wr_max) { - cfg.buckets[THROTTLE_OPS_WRITE].max = iops_wr_max; + if (arg->has_iops_wr_max) { + cfg.buckets[THROTTLE_OPS_WRITE].max = arg->iops_wr_max; } - if (has_bps_max_length) { - cfg.buckets[THROTTLE_BPS_TOTAL].burst_length = bps_max_length; + if (arg->has_bps_max_length) { + cfg.buckets[THROTTLE_BPS_TOTAL].burst_length = arg->bps_max_length; } - if (has_bps_rd_max_length) { - cfg.buckets[THROTTLE_BPS_READ].burst_length = bps_rd_max_length; + if (arg->has_bps_rd_max_length) { + cfg.buckets[THROTTLE_BPS_READ].burst_length = arg->bps_rd_max_length; } - if (has_bps_wr_max_length) { - cfg.buckets[THROTTLE_BPS_WRITE].burst_length = bps_wr_max_length; + if (arg->has_bps_wr_max_length) { + cfg.buckets[THROTTLE_BPS_WRITE].burst_length = arg->bps_wr_max_length; } - if (has_iops_max_length) { - cfg.buckets[THROTTLE_OPS_TOTAL].burst_length = iops_max_length; + if (arg->has_iops_max_length) { + cfg.buckets[THROTTLE_OPS_TOTAL].burst_length = arg->iops_max_length; } - if (has_iops_rd_max_length) { - cfg.buckets[THROTTLE_OPS_READ].burst_length = iops_rd_max_length; + if (arg->has_iops_rd_max_length) { + cfg.buckets[THROTTLE_OPS_READ].burst_length = arg->iops_rd_max_length; } - if (has_iops_wr_max_length) { - cfg.buckets[THROTTLE_OPS_WRITE].burst_length = iops_wr_max_length; + if (arg->has_iops_wr_max_length) { + cfg.buckets[THROTTLE_OPS_WRITE].burst_length = arg->iops_wr_max_length; } - if (has_iops_size) { - cfg.op_size = iops_size; + if (arg->has_iops_size) { + cfg.op_size = arg->iops_size; } if (!throttle_is_valid(&cfg, errp)) { @@ -2748,9 +2716,10 @@ void qmp_block_set_io_throttle(const char *device, int64_t bps, int64_t bps_rd, /* Enable I/O limits if they're not enabled yet, otherwise * just update the throttling group. */ if (!blk_get_public(blk)->throttle_state) { - blk_io_limits_enable(blk, has_group ? group : device); - } else if (has_group) { - blk_io_limits_update_group(blk, group); + blk_io_limits_enable(blk, + arg->has_group ? arg->group : arg->device); + } else if (arg->has_group) { + blk_io_limits_update_group(blk, arg->group); } /* Set the new throttling configuration */ blk_set_io_limits(blk, &cfg); diff --git a/hmp.c b/hmp.c index 3ca79c3..ea17d49 100644 --- a/hmp.c +++ b/hmp.c @@ -1439,42 +1439,17 @@ void hmp_change(Monitor *mon, const QDict *qdict) void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict) { Error *err = NULL; + BlockIOThrottle throttle = { + .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"), + .iops = qdict_get_int(qdict, "iops"), + .iops_rd = qdict_get_int(qdict, "iops_rd"), + .iops_wr = qdict_get_int(qdict, "iops_wr"), + }; - qmp_block_set_io_throttle(qdict_get_str(qdict, "device"), - 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"), - false, /* no burst max via HMP */ - 0, - false, - 0, - false, - 0, - false, - 0, - false, - 0, - false, - 0, - false, /* no burst length via HMP */ - 0, - false, - 0, - false, - 0, - false, - 0, - false, - 0, - false, - 0, - false, /* No default I/O size */ - 0, - false, - NULL, &err); + qmp_block_set_io_throttle(&throttle, &err); hmp_handle_error(mon, &err); } diff --git a/qapi/block-core.json b/qapi/block-core.json index 3444a9b..3d4b071 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -1330,6 +1330,21 @@ # the device will be removed from its group and the rest of its # members will not be affected. The 'group' parameter is ignored. # +# See BlockIOThrottle for parameter descriptions. +# +# Returns: Nothing on success +# If @device is not a valid block device, DeviceNotFound +# +# Since: 1.1 +## +{ 'command': 'block_set_io_throttle', 'boxed': true, + 'data': 'BlockIOThrottle' } + +## +# BlockIOThrottle +# +# A set of parameters describing block throttling. +# # @device: The name of the device # # @bps: total throughput limit in bytes per second @@ -1396,12 +1411,9 @@ # # @group: #optional throttle group name (Since 2.4) # -# Returns: Nothing on success -# If @device is not a valid block device, DeviceNotFound -# # Since: 1.1 ## -{ 'command': 'block_set_io_throttle', +{ 'struct': 'BlockIOThrottle', 'data': { 'device': 'str', 'bps': 'int', 'bps_rd': 'int', 'bps_wr': 'int', 'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int', '*bps_max': 'int', '*bps_rd_max': 'int',