diff --git a/blockdev.c b/blockdev.c index 52aabf7b90..11a3139851 100644 --- a/blockdev.c +++ b/blockdev.c @@ -349,9 +349,7 @@ static bool check_throttle_config(ThrottleConfig *cfg, Error **errp) return false; } - if (!throttle_is_valid(cfg)) { - error_setg(errp, "bps/iops/max values must be within [0, %lld]", - THROTTLE_VALUE_MAX); + if (!throttle_is_valid(cfg, errp)) { return false; } diff --git a/include/qemu/throttle.h b/include/qemu/throttle.h index 03bdec07ea..ecae6212ff 100644 --- a/include/qemu/throttle.h +++ b/include/qemu/throttle.h @@ -108,7 +108,7 @@ bool throttle_enabled(ThrottleConfig *cfg); bool throttle_conflicting(ThrottleConfig *cfg, Error **errp); -bool throttle_is_valid(ThrottleConfig *cfg); +bool throttle_is_valid(ThrottleConfig *cfg, Error **errp); bool throttle_max_is_missing_limit(ThrottleConfig *cfg, Error **errp); diff --git a/tests/test-throttle.c b/tests/test-throttle.c index 49bd3bccaf..0e7c7e0f3f 100644 --- a/tests/test-throttle.c +++ b/tests/test-throttle.c @@ -315,7 +315,7 @@ static void test_is_valid_for_value(int value, bool should_be_valid) for (index = 0; index < BUCKETS_COUNT; index++) { memset(&cfg, 0, sizeof(cfg)); set_cfg_value(is_max, index, value); - g_assert(throttle_is_valid(&cfg) == should_be_valid); + g_assert(throttle_is_valid(&cfg, NULL) == should_be_valid); } } } diff --git a/util/throttle.c b/util/throttle.c index 77010b4a1a..9046dd8e36 100644 --- a/util/throttle.c +++ b/util/throttle.c @@ -287,8 +287,9 @@ bool throttle_conflicting(ThrottleConfig *cfg, Error **errp) /* check if a throttling configuration is valid * @cfg: the throttling configuration to inspect * @ret: true if valid else false + * @errp: error object */ -bool throttle_is_valid(ThrottleConfig *cfg) +bool throttle_is_valid(ThrottleConfig *cfg, Error **errp) { int i; @@ -297,6 +298,8 @@ bool throttle_is_valid(ThrottleConfig *cfg) cfg->buckets[i].max < 0 || cfg->buckets[i].avg > THROTTLE_VALUE_MAX || cfg->buckets[i].max > THROTTLE_VALUE_MAX) { + error_setg(errp, "bps/iops/max values must be within [0, %lld]", + THROTTLE_VALUE_MAX); return false; } }