From patchwork Mon Jun 19 13:11:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pradeep Jagadeesh X-Patchwork-Id: 777755 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wrs2W4VMHz9s71 for ; Mon, 19 Jun 2017 23:17:07 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Q4/wXmfV"; dkim-atps=neutral Received: from localhost ([::1]:42625 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dMwYD-0006sF-7c for incoming@patchwork.ozlabs.org; Mon, 19 Jun 2017 09:17:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50315) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dMwU3-00036o-Do for qemu-devel@nongnu.org; Mon, 19 Jun 2017 09:12:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dMwU1-0001rT-M3 for qemu-devel@nongnu.org; Mon, 19 Jun 2017 09:12:47 -0400 Received: from mail-wr0-x242.google.com ([2a00:1450:400c:c0c::242]:34884) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dMwU1-0001qf-Ch for qemu-devel@nongnu.org; Mon, 19 Jun 2017 09:12:45 -0400 Received: by mail-wr0-x242.google.com with SMTP id z45so13434600wrb.2 for ; Mon, 19 Jun 2017 06:12:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ALk9mMHmYHjp5vM5gUGfIcNvCjQbx8lFZtjgkfpOvB0=; b=Q4/wXmfVDSCyhUy2VsrtbHLYIYVNnAGMNRr1P9gyPcTo/9Fc8rP+NTocHHpsYxuBXt SPiyzUsBTcz7+8e8S6UOLS2WI4ZyOteTBc9+xRe12gBwqVLv3/TOHmjMSBKgKFqpPc+/ tSCMSSGkb8luYKu10jCVkyen+u5cYrmAnvK1AlP2L4rkW09FlMopjtSz055uKe10qiD1 NA+0APppAN4EwZII9GCPhGBtc1RsIIS6wCQhuW+bFrYUOkqMXOYsLm0g6jzoluW/YXil osZOq+hvmNLVAkAX1ufEpPQE9u1FHXag84jC2T+AsAsqe9GTqV0UzgfneoTYX3yIvYh3 unEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ALk9mMHmYHjp5vM5gUGfIcNvCjQbx8lFZtjgkfpOvB0=; b=qYX6IfeBh1pgRovtgmbPdXj2xGo9XMuIeUasDwrAuD3tMVBUizenYohhv7Qkd9ltk4 yZ4zAbNzjZ81/Emx8iyBcshCN9eDyE6r58bT+T5wE05/KvYKQ5X4NnxtSXUg3XaWbonB TyE+R9+tZvDtxMY2aUqnMnH2jt8ZP1mYqPcXiYJAl9PTTNfFWNeIQMTa/Grt0BXlr6Rm b+qPXB/N3ofNbz48nv0mGcrzpud8bzjyIOS1uxQtWIqnzzP4epcjj6XxpeoUN056yQl3 nPEAHZQdbB3sKbAkaqGC+DCV7y/Jgky8CNhoXJ3V+8EeECIeRrIrh/QzpD9r44elrNE4 HutA== X-Gm-Message-State: AKS2vOyNnAMte08mHx9awMRIuGo91H4xNT4Gs3AyGmbT80+lL6d5d5RB JlLwKgLXJTB6Mw== X-Received: by 10.28.170.193 with SMTP id t184mr15889169wme.124.1497877964351; Mon, 19 Jun 2017 06:12:44 -0700 (PDT) Received: from centos-minion-1.localdomain ([217.110.131.66]) by smtp.gmail.com with ESMTPSA id n71sm13459351wrb.62.2017.06.19.06.12.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Jun 2017 06:12:43 -0700 (PDT) From: Pradeep Jagadeesh X-Google-Original-From: Pradeep Jagadeesh To: "eric blake" , "greg kurz" Date: Mon, 19 Jun 2017 09:11:34 -0400 Message-Id: <1497877896-35700-4-git-send-email-pradeep.jagadeesh@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1497877896-35700-1-git-send-email-pradeep.jagadeesh@huawei.com> References: <1497877896-35700-1-git-send-email-pradeep.jagadeesh@huawei.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::242 Subject: [Qemu-devel] [PATCH v5 3/5] qmp: refactor duplicate code 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: , Cc: jani kokkonen , alberto garcia , Pradeep Jagadeesh , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This patch factor out the duplicate qmp throttle interface code that was present in both block and fsdev device files. Signed-off-by: Pradeep Jagadeesh --- blockdev.c | 53 +++--------------------------------- hmp.c | 21 ++++++++++----- include/qemu/throttle-options.h | 3 +++ util/throttle.c | 60 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 56 deletions(-) diff --git a/blockdev.c b/blockdev.c index 5db9e5c..3d06e9e 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2593,6 +2593,7 @@ void qmp_block_set_io_throttle(BlockIOThrottle *arg, Error **errp) BlockDriverState *bs; BlockBackend *blk; AioContext *aio_context; + IOThrottle *iothrottle; blk = qmp_get_blk(arg->has_device ? arg->device : NULL, arg->has_id ? arg->id : NULL, @@ -2610,56 +2611,8 @@ void qmp_block_set_io_throttle(BlockIOThrottle *arg, Error **errp) goto out; } - throttle_config_init(&cfg); - 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 = arg->iops; - cfg.buckets[THROTTLE_OPS_READ].avg = arg->iops_rd; - cfg.buckets[THROTTLE_OPS_WRITE].avg = arg->iops_wr; - - if (arg->has_bps_max) { - cfg.buckets[THROTTLE_BPS_TOTAL].max = arg->bps_max; - } - if (arg->has_bps_rd_max) { - cfg.buckets[THROTTLE_BPS_READ].max = arg->bps_rd_max; - } - if (arg->has_bps_wr_max) { - cfg.buckets[THROTTLE_BPS_WRITE].max = arg->bps_wr_max; - } - if (arg->has_iops_max) { - cfg.buckets[THROTTLE_OPS_TOTAL].max = arg->iops_max; - } - if (arg->has_iops_rd_max) { - cfg.buckets[THROTTLE_OPS_READ].max = arg->iops_rd_max; - } - if (arg->has_iops_wr_max) { - cfg.buckets[THROTTLE_OPS_WRITE].max = arg->iops_wr_max; - } - - if (arg->has_bps_max_length) { - cfg.buckets[THROTTLE_BPS_TOTAL].burst_length = arg->bps_max_length; - } - if (arg->has_bps_rd_max_length) { - cfg.buckets[THROTTLE_BPS_READ].burst_length = arg->bps_rd_max_length; - } - if (arg->has_bps_wr_max_length) { - cfg.buckets[THROTTLE_BPS_WRITE].burst_length = arg->bps_wr_max_length; - } - if (arg->has_iops_max_length) { - cfg.buckets[THROTTLE_OPS_TOTAL].burst_length = arg->iops_max_length; - } - if (arg->has_iops_rd_max_length) { - cfg.buckets[THROTTLE_OPS_READ].burst_length = arg->iops_rd_max_length; - } - if (arg->has_iops_wr_max_length) { - cfg.buckets[THROTTLE_OPS_WRITE].burst_length = arg->iops_wr_max_length; - } - - if (arg->has_iops_size) { - cfg.op_size = arg->iops_size; - } + iothrottle = qapi_BlockIOThrottle_base(arg); + throttle_set_io_limits(&cfg, iothrottle); if (!throttle_is_valid(&cfg, errp)) { goto out; diff --git a/hmp.c b/hmp.c index 8c72c58..220d301 100644 --- a/hmp.c +++ b/hmp.c @@ -1749,20 +1749,29 @@ void hmp_change(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, &err); } +static void hmp_initialize_io_throttle(IOThrottle *iot, const QDict *qdict) +{ + iot->has_id = true; + iot->id = (char *) qdict_get_str(qdict, "id"); + iot->bps = qdict_get_int(qdict, "bps"); + iot->bps_rd = qdict_get_int(qdict, "bps_rd"); + iot->bps_wr = qdict_get_int(qdict, "bps_wr"); + iot->iops = qdict_get_int(qdict, "iops"); + iot->iops_rd = qdict_get_int(qdict, "iops_rd"); + iot->iops_wr = qdict_get_int(qdict, "iops_wr"); +} + void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict) { Error *err = NULL; + IOThrottle *iothrottle; 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"), - .iops = qdict_get_int(qdict, "iops"), - .iops_rd = qdict_get_int(qdict, "iops_rd"), - .iops_wr = qdict_get_int(qdict, "iops_wr"), }; + iothrottle = qapi_BlockIOThrottle_base(&throttle); + hmp_initialize_io_throttle(iothrottle, qdict); qmp_block_set_io_throttle(&throttle, &err); hmp_handle_error(mon, &err); } diff --git a/include/qemu/throttle-options.h b/include/qemu/throttle-options.h index 565553a..e94ea39 100644 --- a/include/qemu/throttle-options.h +++ b/include/qemu/throttle-options.h @@ -11,6 +11,7 @@ #define THROTTLE_OPTIONS_H #include "qemu/throttle.h" +#include "qmp-commands.h" #define THROTTLE_OPTS \ { \ @@ -93,4 +94,6 @@ void throttle_parse_options(ThrottleConfig *, QemuOpts *); +void throttle_set_io_limits(ThrottleConfig *, IOThrottle *); + #endif diff --git a/util/throttle.c b/util/throttle.c index ebe9dd0..2cf9ec5 100644 --- a/util/throttle.c +++ b/util/throttle.c @@ -27,6 +27,7 @@ #include "qemu/throttle.h" #include "qemu/timer.h" #include "block/aio.h" +#include "qemu/throttle-options.h" /* This function make a bucket leak * @@ -564,3 +565,62 @@ void throttle_parse_options(ThrottleConfig *throttle_cfg, QemuOpts *opts) throttle_cfg->op_size = qemu_opt_get_number(opts, "throttling.iops-size", 0); } + +/* set the throttle limits + * + * @arg: iothrottle limits + * @cfg: throttle configuration + */ +void throttle_set_io_limits(ThrottleConfig *cfg, IOThrottle *arg) +{ + throttle_config_init(cfg); + 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 = arg->iops; + cfg->buckets[THROTTLE_OPS_READ].avg = arg->iops_rd; + cfg->buckets[THROTTLE_OPS_WRITE].avg = arg->iops_wr; + + if (arg->has_bps_max) { + cfg->buckets[THROTTLE_BPS_TOTAL].max = arg->bps_max; + } + if (arg->has_bps_rd_max) { + cfg->buckets[THROTTLE_BPS_READ].max = arg->bps_rd_max; + } + if (arg->has_bps_wr_max) { + cfg->buckets[THROTTLE_BPS_WRITE].max = arg->bps_wr_max; + } + if (arg->has_iops_max) { + cfg->buckets[THROTTLE_OPS_TOTAL].max = arg->iops_max; + } + if (arg->has_iops_rd_max) { + cfg->buckets[THROTTLE_OPS_READ].max = arg->iops_rd_max; + } + if (arg->has_iops_wr_max) { + cfg->buckets[THROTTLE_OPS_WRITE].max = arg->iops_wr_max; + } + + if (arg->has_bps_max_length) { + cfg->buckets[THROTTLE_BPS_TOTAL].burst_length = arg->bps_max_length; + } + if (arg->has_bps_rd_max_length) { + cfg->buckets[THROTTLE_BPS_READ].burst_length = arg->bps_rd_max_length; + } + if (arg->has_bps_wr_max_length) { + cfg->buckets[THROTTLE_BPS_WRITE].burst_length = arg->bps_wr_max_length; + } + if (arg->has_iops_max_length) { + cfg->buckets[THROTTLE_OPS_TOTAL].burst_length = arg->iops_max_length; + } + if (arg->has_iops_rd_max_length) { + cfg->buckets[THROTTLE_OPS_READ].burst_length = arg->iops_rd_max_length; + } + if (arg->has_iops_wr_max_length) { + cfg->buckets[THROTTLE_OPS_WRITE].burst_length = arg->iops_wr_max_length; + } + + if (arg->has_iops_size) { + cfg->op_size = arg->iops_size; + } +}