From patchwork Thu Mar 30 12:10:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pradeep Jagadeesh X-Patchwork-Id: 745212 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 3vv3VH3DP9z9s1y for ; Thu, 30 Mar 2017 23:15:03 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="T8VOYoi3"; dkim-atps=neutral Received: from localhost ([::1]:35324 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ctYyi-0008Di-US for incoming@patchwork.ozlabs.org; Thu, 30 Mar 2017 08:15:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42117) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ctYuq-000683-Px for qemu-devel@nongnu.org; Thu, 30 Mar 2017 08:11:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ctYup-0007Ok-4c for qemu-devel@nongnu.org; Thu, 30 Mar 2017 08:11:00 -0400 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]:35333) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ctYuo-0007Mn-RK for qemu-devel@nongnu.org; Thu, 30 Mar 2017 08:10:59 -0400 Received: by mail-wr0-x243.google.com with SMTP id p52so11557787wrc.2 for ; Thu, 30 Mar 2017 05:10:58 -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=2aPTFtpWmJcTPLWhMLB/SQ6bpFKTo4VcybGQr+Dl/os=; b=T8VOYoi3mJ21KLyftk3Jq/2JieVmONZiD4QEO48yvj5IckNmZoAedeBsqBN5md2fPr or/Yvq4kHfH49b94z8AXvxLPvUSQO2TdundnSeesEiBQHytlEXU9WfCity2SdJjNW7GB MC/cCZkF55OIQE6Jp5UG4WtD2ngUS8bg1rdx8GZJYguL6Yk+hTqO2TfPjY//XU59sSx7 eq6bpe6e/nwpR24Q8Qt0oge7Ccd/WtBnhg3lX5pBQdrvcUIOR/50VkO3vKizPnF4nHGF 2z0W1T2pXp3I+83ng16mJ4Dnrx+EvZ+J62aRfsL7+6fnlQ2i8C5FjPOeM/HVHVrEMkI2 6nCQ== 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=2aPTFtpWmJcTPLWhMLB/SQ6bpFKTo4VcybGQr+Dl/os=; b=C0ouAwD9jtYYppJA7eXCVcIhE1ZRJC423kFpFug2tptSV5mQU0VsJ8ZA5EqpW2MAKe FBblbt6yLZOqXIbcHtcGJyMXopQ0h4t4FkNvap7Om7UGZbT+fB6wQsPSctjqSw72xCQg XI78TwnTWZkOsPFxucOtekhG1bljKeeLLUInQoLG8/6xXShmjesWRDFiWeotwk7nmOWw l0PRYrUHBqJ7y9jCXzf2FRAU5LdE3w3RldsVrPEVG865cjNJO4a5aZHGsf7fFhLZoOzl iyaTdyva2F+X/SHK2hEy8knnE7SEC1iY8dQPozPAzKCA4x7GBOU5a368DnNYBKb2cwv+ FOgA== X-Gm-Message-State: AFeK/H1tzyGY/S8eN53vzg2ZGdABUBJ0nirVc9TJVu0YGV4wkopDY4OgmerYTODM/GDEWg== X-Received: by 10.28.30.197 with SMTP id e188mr2962692wme.99.1490875857824; Thu, 30 Mar 2017 05:10:57 -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.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Mar 2017 05:10:57 -0700 (PDT) From: Pradeep Jagadeesh X-Google-Original-From: Pradeep Jagadeesh To: "eric blake" , "greg kurz" Date: Thu, 30 Mar 2017 08:10:13 -0400 Message-Id: <1490875813-35588-5-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::243 Subject: [Qemu-devel] [PATCH v2 4/4] throttle: factor out 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 patchset factor out the duplicate throttle code that was present in block and fsdev devices. Signed-off-by: Pradeep Jagadeesh --- blockdev.c | 44 +------------------------------------- fsdev/qemu-fsdev-throttle.c | 43 +------------------------------------ include/qemu/throttle-options.h | 2 ++ util/throttle-options.c | 47 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 85 deletions(-) diff --git a/blockdev.c b/blockdev.c index 3114dc5..775d7e8 100644 --- a/blockdev.c +++ b/blockdev.c @@ -386,49 +386,7 @@ static void extract_common_blockdev_options(QemuOpts *opts, int *bdrv_flags, } if (throttle_cfg) { - throttle_config_init(throttle_cfg); - throttle_cfg->buckets[THROTTLE_BPS_TOTAL].avg = - qemu_opt_get_number(opts, "throttling.bps-total", 0); - throttle_cfg->buckets[THROTTLE_BPS_READ].avg = - qemu_opt_get_number(opts, "throttling.bps-read", 0); - throttle_cfg->buckets[THROTTLE_BPS_WRITE].avg = - qemu_opt_get_number(opts, "throttling.bps-write", 0); - throttle_cfg->buckets[THROTTLE_OPS_TOTAL].avg = - qemu_opt_get_number(opts, "throttling.iops-total", 0); - throttle_cfg->buckets[THROTTLE_OPS_READ].avg = - qemu_opt_get_number(opts, "throttling.iops-read", 0); - throttle_cfg->buckets[THROTTLE_OPS_WRITE].avg = - qemu_opt_get_number(opts, "throttling.iops-write", 0); - - throttle_cfg->buckets[THROTTLE_BPS_TOTAL].max = - qemu_opt_get_number(opts, "throttling.bps-total-max", 0); - throttle_cfg->buckets[THROTTLE_BPS_READ].max = - qemu_opt_get_number(opts, "throttling.bps-read-max", 0); - throttle_cfg->buckets[THROTTLE_BPS_WRITE].max = - qemu_opt_get_number(opts, "throttling.bps-write-max", 0); - throttle_cfg->buckets[THROTTLE_OPS_TOTAL].max = - qemu_opt_get_number(opts, "throttling.iops-total-max", 0); - throttle_cfg->buckets[THROTTLE_OPS_READ].max = - qemu_opt_get_number(opts, "throttling.iops-read-max", 0); - throttle_cfg->buckets[THROTTLE_OPS_WRITE].max = - qemu_opt_get_number(opts, "throttling.iops-write-max", 0); - - throttle_cfg->buckets[THROTTLE_BPS_TOTAL].burst_length = - qemu_opt_get_number(opts, "throttling.bps-total-max-length", 1); - throttle_cfg->buckets[THROTTLE_BPS_READ].burst_length = - qemu_opt_get_number(opts, "throttling.bps-read-max-length", 1); - throttle_cfg->buckets[THROTTLE_BPS_WRITE].burst_length = - qemu_opt_get_number(opts, "throttling.bps-write-max-length", 1); - throttle_cfg->buckets[THROTTLE_OPS_TOTAL].burst_length = - qemu_opt_get_number(opts, "throttling.iops-total-max-length", 1); - throttle_cfg->buckets[THROTTLE_OPS_READ].burst_length = - qemu_opt_get_number(opts, "throttling.iops-read-max-length", 1); - throttle_cfg->buckets[THROTTLE_OPS_WRITE].burst_length = - qemu_opt_get_number(opts, "throttling.iops-write-max-length", 1); - - throttle_cfg->op_size = - qemu_opt_get_number(opts, "throttling.iops-size", 0); - + parse_io_throttle_options(throttle_cfg, opts); if (!throttle_is_valid(throttle_cfg, errp)) { return; } diff --git a/fsdev/qemu-fsdev-throttle.c b/fsdev/qemu-fsdev-throttle.c index cd653af..3cbf887 100644 --- a/fsdev/qemu-fsdev-throttle.c +++ b/fsdev/qemu-fsdev-throttle.c @@ -78,48 +78,7 @@ void fsdev_get_io_throttle(FsThrottle *fst, IOThrottle **fs9pcfg, void fsdev_throttle_parse_opts(QemuOpts *opts, FsThrottle *fst, Error **errp) { - throttle_config_init(&fst->cfg); - fst->cfg.buckets[THROTTLE_BPS_TOTAL].avg = - qemu_opt_get_number(opts, "throttling.bps-total", 0); - fst->cfg.buckets[THROTTLE_BPS_READ].avg = - qemu_opt_get_number(opts, "throttling.bps-read", 0); - fst->cfg.buckets[THROTTLE_BPS_WRITE].avg = - qemu_opt_get_number(opts, "throttling.bps-write", 0); - fst->cfg.buckets[THROTTLE_OPS_TOTAL].avg = - qemu_opt_get_number(opts, "throttling.iops-total", 0); - fst->cfg.buckets[THROTTLE_OPS_READ].avg = - qemu_opt_get_number(opts, "throttling.iops-read", 0); - fst->cfg.buckets[THROTTLE_OPS_WRITE].avg = - qemu_opt_get_number(opts, "throttling.iops-write", 0); - - fst->cfg.buckets[THROTTLE_BPS_TOTAL].max = - qemu_opt_get_number(opts, "throttling.bps-total-max", 0); - fst->cfg.buckets[THROTTLE_BPS_READ].max = - qemu_opt_get_number(opts, "throttling.bps-read-max", 0); - fst->cfg.buckets[THROTTLE_BPS_WRITE].max = - qemu_opt_get_number(opts, "throttling.bps-write-max", 0); - fst->cfg.buckets[THROTTLE_OPS_TOTAL].max = - qemu_opt_get_number(opts, "throttling.iops-total-max", 0); - fst->cfg.buckets[THROTTLE_OPS_READ].max = - qemu_opt_get_number(opts, "throttling.iops-read-max", 0); - fst->cfg.buckets[THROTTLE_OPS_WRITE].max = - qemu_opt_get_number(opts, "throttling.iops-write-max", 0); - - fst->cfg.buckets[THROTTLE_BPS_TOTAL].burst_length = - qemu_opt_get_number(opts, "throttling.bps-total-max-length", 1); - fst->cfg.buckets[THROTTLE_BPS_READ].burst_length = - qemu_opt_get_number(opts, "throttling.bps-read-max-length", 1); - fst->cfg.buckets[THROTTLE_BPS_WRITE].burst_length = - qemu_opt_get_number(opts, "throttling.bps-write-max-length", 1); - fst->cfg.buckets[THROTTLE_OPS_TOTAL].burst_length = - qemu_opt_get_number(opts, "throttling.iops-total-max-length", 1); - fst->cfg.buckets[THROTTLE_OPS_READ].burst_length = - qemu_opt_get_number(opts, "throttling.iops-read-max-length", 1); - fst->cfg.buckets[THROTTLE_OPS_WRITE].burst_length = - qemu_opt_get_number(opts, "throttling.iops-write-max-length", 1); - fst->cfg.op_size = - qemu_opt_get_number(opts, "throttling.iops-size", 0); - + parse_io_throttle_options(&fst->cfg, opts); throttle_is_valid(&fst->cfg, errp); } diff --git a/include/qemu/throttle-options.h b/include/qemu/throttle-options.h index ca0fd7d..bcfd185 100644 --- a/include/qemu/throttle-options.h +++ b/include/qemu/throttle-options.h @@ -94,4 +94,6 @@ void qmp_set_io_throttle(ThrottleConfig *, IOThrottle *); +void parse_io_throttle_options(ThrottleConfig *, QemuOpts *); + #endif diff --git a/util/throttle-options.c b/util/throttle-options.c index 47cffed..e92c8c8 100644 --- a/util/throttle-options.c +++ b/util/throttle-options.c @@ -56,3 +56,50 @@ void qmp_set_io_throttle(ThrottleConfig *cfg, IOThrottle *arg) cfg->op_size = arg->iops_size; } } + +void parse_io_throttle_options(ThrottleConfig *throttle_cfg, QemuOpts *opts) +{ + throttle_config_init(throttle_cfg); + throttle_cfg->buckets[THROTTLE_BPS_TOTAL].avg = + qemu_opt_get_number(opts, "throttling.bps-total", 0); + throttle_cfg->buckets[THROTTLE_BPS_READ].avg = + qemu_opt_get_number(opts, "throttling.bps-read", 0); + throttle_cfg->buckets[THROTTLE_BPS_WRITE].avg = + qemu_opt_get_number(opts, "throttling.bps-write", 0); + throttle_cfg->buckets[THROTTLE_OPS_TOTAL].avg = + qemu_opt_get_number(opts, "throttling.iops-total", 0); + throttle_cfg->buckets[THROTTLE_OPS_READ].avg = + qemu_opt_get_number(opts, "throttling.iops-read", 0); + throttle_cfg->buckets[THROTTLE_OPS_WRITE].avg = + qemu_opt_get_number(opts, "throttling.iops-write", 0); + + throttle_cfg->buckets[THROTTLE_BPS_TOTAL].max = + qemu_opt_get_number(opts, "throttling.bps-total-max", 0); + throttle_cfg->buckets[THROTTLE_BPS_READ].max = + qemu_opt_get_number(opts, "throttling.bps-read-max", 0); + throttle_cfg->buckets[THROTTLE_BPS_WRITE].max = + qemu_opt_get_number(opts, "throttling.bps-write-max", 0); + throttle_cfg->buckets[THROTTLE_OPS_TOTAL].max = + qemu_opt_get_number(opts, "throttling.iops-total-max", 0); + throttle_cfg->buckets[THROTTLE_OPS_READ].max = + qemu_opt_get_number(opts, "throttling.iops-read-max", 0); + throttle_cfg->buckets[THROTTLE_OPS_WRITE].max = + qemu_opt_get_number(opts, "throttling.iops-write-max", 0); + + throttle_cfg->buckets[THROTTLE_BPS_TOTAL].burst_length = + qemu_opt_get_number(opts, "throttling.bps-total-max-length", 1); + throttle_cfg->buckets[THROTTLE_BPS_READ].burst_length = + qemu_opt_get_number(opts, "throttling.bps-read-max-length", 1); + throttle_cfg->buckets[THROTTLE_BPS_WRITE].burst_length = + qemu_opt_get_number(opts, "throttling.bps-write-max-length", 1); + throttle_cfg->buckets[THROTTLE_OPS_TOTAL].burst_length = + qemu_opt_get_number(opts, "throttling.iops-total-max-length", 1); + throttle_cfg->buckets[THROTTLE_OPS_READ].burst_length = + qemu_opt_get_number(opts, "throttling.iops-read-max-length", 1); + throttle_cfg->buckets[THROTTLE_OPS_WRITE].burst_length = + qemu_opt_get_number(opts, "throttling.iops-write-max-length", 1); + + throttle_cfg->op_size = + qemu_opt_get_number(opts, "throttling.iops-size", 0); + +}