From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43578) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZQGAf-0006zd-Ux for qemu-devel@nongnu.org; Fri, 14 Aug 2015 10:41:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZQGAe-00053b-4V for qemu-devel@nongnu.org; Fri, 14 Aug 2015 10:41:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59298) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZQGAd-00053W-Ub for qemu-devel@nongnu.org; Fri, 14 Aug 2015 10:41:24 -0400 From: Stefan Hajnoczi Date: Fri, 14 Aug 2015 15:41:17 +0100 Message-Id: <1439563278-11873-2-git-send-email-stefanha@redhat.com> In-Reply-To: <1439563278-11873-1-git-send-email-stefanha@redhat.com> References: <1439563278-11873-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [PULL 1/2] throttle: refuse bps_max/iops_max without bps/iops List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , Stefan Hajnoczi The bps_max/iops_max values are meaningless without corresponding bps/iops values. Reported an error if bps_max/iops_max is given without bps/iops. Signed-off-by: Stefan Hajnoczi Reviewed-by: Alberto Garcia Message-id: 1438683733-21111-2-git-send-email-stefanha@redhat.com --- blockdev.c | 6 ++++++ include/qemu/throttle.h | 2 ++ util/throttle.c | 15 +++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/blockdev.c b/blockdev.c index 62a4586..4125ff6 100644 --- a/blockdev.c +++ b/blockdev.c @@ -337,6 +337,12 @@ static bool check_throttle_config(ThrottleConfig *cfg, Error **errp) return false; } + if (throttle_max_is_missing_limit(cfg)) { + error_setg(errp, "bps_max/iops_max require corresponding" + " bps/iops values"); + return false; + } + return true; } diff --git a/include/qemu/throttle.h b/include/qemu/throttle.h index 995b2d5..12faaad 100644 --- a/include/qemu/throttle.h +++ b/include/qemu/throttle.h @@ -114,6 +114,8 @@ bool throttle_conflicting(ThrottleConfig *cfg); bool throttle_is_valid(ThrottleConfig *cfg); +bool throttle_max_is_missing_limit(ThrottleConfig *cfg); + void throttle_config(ThrottleState *ts, ThrottleTimers *tt, ThrottleConfig *cfg); diff --git a/util/throttle.c b/util/throttle.c index 706c131..1113671 100644 --- a/util/throttle.c +++ b/util/throttle.c @@ -300,6 +300,21 @@ bool throttle_is_valid(ThrottleConfig *cfg) return !invalid; } +/* check if bps_max/iops_max is used without bps/iops + * @cfg: the throttling configuration to inspect + */ +bool throttle_max_is_missing_limit(ThrottleConfig *cfg) +{ + int i; + + for (i = 0; i < BUCKETS_COUNT; i++) { + if (cfg->buckets[i].max && !cfg->buckets[i].avg) { + return true; + } + } + return false; +} + /* fix bucket parameters */ static void throttle_fix_bucket(LeakyBucket *bkt) { -- 2.4.3