From patchwork Thu Mar 30 12:10:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pradeep X-Patchwork-Id: 9654007 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 2DD7B6034C for ; Thu, 30 Mar 2017 12:11:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1AA342815E for ; Thu, 30 Mar 2017 12:11:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0C54028334; Thu, 30 Mar 2017 12:11:59 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 0B3B52858C for ; Thu, 30 Mar 2017 12:11:58 +0000 (UTC) Received: from localhost ([::1]:35314 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ctYvl-0006AC-3k for patchwork-qemu-devel@patchwork.kernel.org; Thu, 30 Mar 2017 08:11:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42099) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ctYup-00067i-3x for qemu-devel@nongnu.org; Thu, 30 Mar 2017 08:11:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ctYun-0007LE-Cq for qemu-devel@nongnu.org; Thu, 30 Mar 2017 08:10:59 -0400 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]:32808) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ctYun-0007Jv-1A for qemu-devel@nongnu.org; Thu, 30 Mar 2017 08:10:57 -0400 Received: by mail-wr0-x241.google.com with SMTP id u18so11549642wrc.0 for ; Thu, 30 Mar 2017 05:10:57 -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=kNoRJCsQKM4fp7OlsYZN1kBtNCHR8njsCXznNm6GtyU=; b=R6EJ0L+PLcwQxomvG1Zrxh4em7XOs1GOBoS3mvoOgaO/YjSIBjVMF+AmGsbo08uD3i YEux7rqUJhuwPkPloNh+frEm/DAoMS53Pd+RicZ+oXQ6d7fidqYUs5ndp647TrRoMBVv rjl3tzDCsaqHEw6Wg2IN8fX4PITWlEYaX33Pp6+gCCpuipbVsnHAFWzza/vKpPlrlSHV 9xSulp4OK248AXA8LAIE8mzb3VurPdypcFyhEqwKbZwrelI7WQbupSdT/L14PWa7fYnD uXEaYoDx3ouJtg19tR344n1GBuY6qps9XjPe5ZpJ1wuE4iN1A6eG+IPtVnpsyJ/jYSuq PTrg== 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=kNoRJCsQKM4fp7OlsYZN1kBtNCHR8njsCXznNm6GtyU=; b=F6FInwePqU06jHQh4Pg6pWqgOOynvmOryFAa3zzhafr2A4Ap0sfF5n6Qb9A0jdr8uG hfkggbrM/okZNZw6k7fI0+8ygjO/zzW2+r6ayyD+884Jsm3CznMZoFUDE3Kh7QvP+sC8 UQ6q1BNCNh+MlqBo+1eY3gp2jo4wni5zpMWSwRP2dPE+LoaxXauLln7MpCPAE2p0OvTU Q5muCERcSrScHIdG8tNJYdQ7kq7gqji1VftDkhQkWV4NsjgDhnwfmFiKOoJlaaglnJdu LMIuG3h6pH4xZTX6/f3bf91vpMyOY0SJEIJNBJz05smbgJVnqmXBChiSQic9PDNFpOre eLOQ== X-Gm-Message-State: AFeK/H02Sop/5Gt6bxlwUlNK2u5R4aEKdCYxxpiRkpzBpAO7y4cDjF68laEv+hNL04p8uA== X-Received: by 10.223.150.168 with SMTP id u37mr5617045wrb.184.1490875856069; Thu, 30 Mar 2017 05:10:56 -0700 (PDT) Received: from localhost.localdomain.localdomain ([217.110.131.66]) by smtp.gmail.com with ESMTPSA id k139sm12122910wmg.11.2017.03.30.05.10.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Mar 2017 05:10:55 -0700 (PDT) From: Pradeep Jagadeesh X-Google-Original-From: Pradeep Jagadeesh To: "eric blake" , "greg kurz" Date: Thu, 30 Mar 2017 08:10:12 -0400 Message-Id: <1490875813-35588-4-git-send-email-pradeep.jagadeesh@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1490875813-35588-1-git-send-email-pradeep.jagadeesh@huawei.com> References: <1490875813-35588-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::241 Subject: [Qemu-devel] [PATCH v2 3/4] 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This patchset 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 +++---------------------------------- fsdev/qemu-fsdev-throttle.c | 51 +----------------------------------- fsdev/qemu-fsdev.c | 1 - hmp.c | 34 ++++++++++++------------ include/qemu/throttle-options.h | 5 ++++ util/Makefile.objs | 1 + util/throttle-options.c | 58 +++++++++++++++++++++++++++++++++++++++++ 7 files changed, 85 insertions(+), 118 deletions(-) create mode 100644 util/throttle-options.c diff --git a/blockdev.c b/blockdev.c index c5b2c2c..3114dc5 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2635,6 +2635,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, @@ -2652,56 +2653,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); + qmp_set_io_throttle(&cfg, iothrottle); if (!throttle_is_valid(&cfg, errp)) { goto out; diff --git a/fsdev/qemu-fsdev-throttle.c b/fsdev/qemu-fsdev-throttle.c index 43dbcd8..cd653af 100644 --- a/fsdev/qemu-fsdev-throttle.c +++ b/fsdev/qemu-fsdev-throttle.c @@ -33,56 +33,7 @@ void fsdev_set_io_throttle(IOThrottle *arg, FsThrottle *fst, Error **errp) { ThrottleConfig cfg; - 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; - } + qmp_set_io_throttle(&cfg, arg); if (throttle_is_valid(&cfg, errp)) { fst->cfg = cfg; diff --git a/fsdev/qemu-fsdev.c b/fsdev/qemu-fsdev.c index a99e299..8c078b1 100644 --- a/fsdev/qemu-fsdev.c +++ b/fsdev/qemu-fsdev.c @@ -102,7 +102,6 @@ FsDriverEntry *get_fsdev_fsentry(char *id) void qmp_fsdev_set_io_throttle(IOThrottle *arg, Error **errp) { - FsDriverEntry *fse; fse = get_fsdev_fsentry(arg->has_id ? arg->id : NULL); diff --git a/hmp.c b/hmp.c index 493f48b..cafe595 100644 --- a/hmp.c +++ b/hmp.c @@ -1554,20 +1554,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); } @@ -1577,17 +1586,8 @@ void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict) void hmp_fsdev_set_io_throttle(Monitor *mon, const QDict *qdict) { Error *err = NULL; - IOThrottle throttle = { - .has_id = true, - .id = (char *) qdict_get_str(qdict, "id"), - .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 throttle; + hmp_initialize_io_throttle(&throttle, qdict); qmp_fsdev_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 3133d1c..ca0fd7d 100644 --- a/include/qemu/throttle-options.h +++ b/include/qemu/throttle-options.h @@ -10,6 +10,9 @@ #ifndef THROTTLE_OPTIONS_H #define THROTTLE_OPTIONS_H +#include "qemu/throttle.h" +#include "qmp-commands.h" + #define THROTTLE_OPTS \ { \ .name = "throttling.iops-total",\ @@ -89,4 +92,6 @@ .help = "when limiting by iops max size of an I/O in bytes",\ } +void qmp_set_io_throttle(ThrottleConfig *, IOThrottle *); + #endif diff --git a/util/Makefile.objs b/util/Makefile.objs index c6205eb..7119ce0 100644 --- a/util/Makefile.objs +++ b/util/Makefile.objs @@ -43,3 +43,4 @@ util-obj-y += qdist.o util-obj-y += qht.o util-obj-y += range.o util-obj-y += systemd.o +util-obj-y += throttle-options.o diff --git a/util/throttle-options.c b/util/throttle-options.c new file mode 100644 index 0000000..47cffed --- /dev/null +++ b/util/throttle-options.c @@ -0,0 +1,58 @@ +#include "qemu/osdep.h" +#include "qemu/error-report.h" +#include "qemu/throttle-options.h" +#include "qemu/iov.h" + +void qmp_set_io_throttle(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; + } +}