Skip to contentSkip to conversation

throttle: refuse bps_max/iops_max without bps/iops

PATCH Applied Stefan Hajnoczi 2 participants 6 messages Aug 4, 2015 – Aug 5, 2015

lore
Share & tools
lore
#0 lore raw

cover throttle: refuse bps_max/iops_max without bps/iops

A bps_max/iops_max value without a corresponding bps/iops does nothing. Avoid confusing the user by refusing invalid inputs instead of silently ignoring them.

Stefan Hajnoczi (2):
throttle: refuse bps_max/iops_max without bps/iops
throttle: add throttle_max_is_missing_limit() test

 blockdev.c              |  6 ++++++
 include/qemu/throttle.h |  2 ++
 tests/test-throttle.c   | 21 +++++++++++++++++++++
 util/throttle.c         | 15 +++++++++++++++
 4 files changed, 44 insertions(+)
Signature · 1 line
2.4.3
#1 lore raw

PATCH 1/2 throttle: refuse bps_max/iops_max without bps/iops

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.

---
 blockdev.c              |  6 ++++++
 include/qemu/throttle.h |  2 ++
 util/throttle.c         | 15 +++++++++++++++
 3 files changed, 23 insertions(+)
blockdev.c +6 -0
index 62a4586..4125ff6 100644
@@ -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;
 }
 
include/qemu/throttle.h +2 -0
index 995b2d5..12faaad 100644
@@ -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);
util/throttle.c +15 -0
index 706c131..1113671 100644
@@ -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)
 {
Signature · 1 line
2.4.3
#3 lore raw

PATCH 2/2 throttle: add throttle_max_is_missing_limit() test

In reply to Stefan Hajnoczi
---
 tests/test-throttle.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
tests/test-throttle.c +21 -0
index 0168445..85c9b6c 100644
@@ -329,6 +329,26 @@ static void test_is_valid(void)
     test_is_valid_for_value(1, true);
 }
 
+static void test_max_is_missing_limit(void)
+{
+    int i;
+
+    for (i = 0; i < BUCKETS_COUNT; i++) {
+        memset(&cfg, 0, sizeof(cfg));
+        cfg.buckets[i].max = 100;
+        cfg.buckets[i].avg = 0;
+        g_assert(throttle_max_is_missing_limit(&cfg));
+
+        cfg.buckets[i].max = 0;
+        cfg.buckets[i].avg = 0;
+        g_assert(!throttle_max_is_missing_limit(&cfg));
+
+        cfg.buckets[i].max = 0;
+        cfg.buckets[i].avg = 100;
+        g_assert(!throttle_max_is_missing_limit(&cfg));
+    }
+}
+
 static void test_have_timer(void)
 {
     /* zero structures */
@@ -591,6 +611,7 @@ int main(int argc, char **argv)
     g_test_add_func("/throttle/config/enabled",     test_enabled);
     g_test_add_func("/throttle/config/conflicting", test_conflicting_config);
     g_test_add_func("/throttle/config/is_valid",    test_is_valid);
+    g_test_add_func("/throttle/config/max",         test_max_is_missing_limit);
     g_test_add_func("/throttle/config_functions",   test_config_functions);
     g_test_add_func("/throttle/accounting",         test_accounting);
     g_test_add_func("/throttle/groups",             test_groups);
Signature · 1 line
2.4.3
author Applied
#5 lore raw
In reply to Stefan Hajnoczi
Quoted 8 lines · Stefan Hajnoczi

A bps_max/iops_max value without a corresponding bps/iops does nothing. Avoid confusing the user by refusing invalid inputs instead of silently ignoring them.

Stefan Hajnoczi (2):
throttle: refuse bps_max/iops_max without bps/iops
throttle: add throttle_max_is_missing_limit() test

Quoted 9 lines
 blockdev.c              |  6 ++++++
 include/qemu/throttle.h |  2 ++
 tests/test-throttle.c   | 21 +++++++++++++++++++++
 util/throttle.c         | 15 +++++++++++++++
 4 files changed, 44 insertions(+)
Signature · 1 line
2.4.3

Thanks, applied to my block-next tree:
https://github.com/stefanha/qemu/commits/block-next

Stefan