From patchwork Wed May 10 08:41:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pradeep Jagadeesh X-Patchwork-Id: 760480 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 3wN8s10V3dz9s3T for ; Wed, 10 May 2017 18:43:15 +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="AxKFchlL"; dkim-atps=neutral Received: from localhost ([::1]:41141 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8NDF-0005gL-3B for incoming@patchwork.ozlabs.org; Wed, 10 May 2017 04:43:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46220) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8NCa-0005c4-JB for qemu-devel@nongnu.org; Wed, 10 May 2017 04:42:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d8NCZ-0007Dh-78 for qemu-devel@nongnu.org; Wed, 10 May 2017 04:42:32 -0400 Received: from mail-wr0-x242.google.com ([2a00:1450:400c:c0c::242]:36465) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d8NCY-0007DS-Tr for qemu-devel@nongnu.org; Wed, 10 May 2017 04:42:31 -0400 Received: by mail-wr0-x242.google.com with SMTP id v42so6323461wrc.3 for ; Wed, 10 May 2017 01:42:30 -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=+00665U+zG4JyAYtaIBEC+w1kOkoaX6Iyxn+NABcG2Q=; b=AxKFchlL3jVXG6SVFuwKz9DIGA2Tq55Mn9MqT6yc4qef0rWVSsNXfi5cklA2SHw+xt ZTGSFuhLyW23/SH3s3M5JcHrOeRTJiJa/YBxlG/01REaLsDnQgtP19feWklB8zPTnnuM mp4Ygd5BmGMLKyyZhKJtuRFzBkCy0aiVxcNWcth73fTbGLMOZ6cLWs3qU09+xpKB1G0q 7HjelUQoJSXALuEs+ocXYGnHzF5GsNxT119JZwCs5rCd3FGCSLOovdhqVNppARqSD9Wj 2Vhzjk6baCQQCUJ73eNJB8d8TCdmOz7zhv7nl2PN/ABfIuCDBWN5LpjVX8L/BpopSjiC rcZQ== 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=+00665U+zG4JyAYtaIBEC+w1kOkoaX6Iyxn+NABcG2Q=; b=ors/2b1jl0Kv2iPYmcYW6rL9HX/GvoNVfDF3qUfPhWDwI+lH/W0wYZsEYp37IDEkvG xeiA62Y1YeNmfacrOnuGCX8f0tqg7U6JEnU+uoKsOgliezcte9lQeSiMOmqno7Pt2R0m FhguAqQfvLK+rLqxNKZdJisKk5qYjF36gR8ifd8roOfAKpNpE6xJdLiEs7jE19bIQfc4 18GjqRrkkni2rI+LBpL41Rdwy6imDa7dXFrA7WfuQpr1/esnJuGNffX1tNuCsMSdYY1F SgroQiTbokfoQIER/0pxWDUm5WmyGaB3K0m9NLOgM8/oku78CM/WKuYh8oABnRm5qtB4 b8Bw== X-Gm-Message-State: AODbwcDJceJuLuPjOFTPU/aY/TVU0i3VcD8ZGHAXkXqjSTygSGVg94aM r1Di+/5svzh9OA== X-Received: by 10.28.207.207 with SMTP id f198mr221310wmg.85.1494405749920; Wed, 10 May 2017 01:42:29 -0700 (PDT) Received: from centos-minion-1.localdomain ([217.110.131.66]) by smtp.gmail.com with ESMTPSA id y63sm4300148wme.31.2017.05.10.01.42.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 May 2017 01:42:29 -0700 (PDT) From: Pradeep Jagadeesh X-Google-Original-From: Pradeep Jagadeesh To: "eric blake" , "greg kurz" Date: Wed, 10 May 2017 04:41:22 -0400 Message-Id: <1494405683-20877-4-git-send-email-pradeep.jagadeesh@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1494405683-20877-1-git-send-email-pradeep.jagadeesh@huawei.com> References: <1494405683-20877-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 v4 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+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 | 2 ++ util/throttle-options.c | 54 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 74 insertions(+), 56 deletions(-) diff --git a/blockdev.c b/blockdev.c index a0eb2ed..a55f6be 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); + qmp_set_io_throttle(&cfg, iothrottle); if (!throttle_is_valid(&cfg, errp)) { goto out; diff --git a/hmp.c b/hmp.c index ab407d6..9660373 100644 --- a/hmp.c +++ b/hmp.c @@ -1552,20 +1552,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 9b68eb8..ccf10cc 100644 --- a/include/qemu/throttle-options.h +++ b/include/qemu/throttle-options.h @@ -94,4 +94,6 @@ void parse_io_throttle_options(ThrottleConfig *, QemuOpts *); +void qmp_set_io_throttle(ThrottleConfig *, IOThrottle *); + #endif diff --git a/util/throttle-options.c b/util/throttle-options.c index 02b26b8..ded57bc 100644 --- a/util/throttle-options.c +++ b/util/throttle-options.c @@ -49,3 +49,57 @@ void parse_io_throttle_options(ThrottleConfig *throttle_cfg, QemuOpts *opts) qemu_opt_get_number(opts, "throttling.iops-size", 0); } + +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; + } +}