[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL for-2.10 07/15] throttle: Make burst_length 64bit and
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-devel] [PULL for-2.10 07/15] throttle: Make burst_length 64bit and add range checks |
Date: |
Thu, 31 Aug 2017 09:22:02 +0100 |
From: Alberto Garcia <address@hidden>
LeakyBucket.burst_length is defined as an unsigned integer but the
code never checks for overflows and it only makes sure that the value
is not 0.
In practice this means that the user can set something like
throttling.iops-total-max-length=4294967300 despite being larger than
UINT_MAX and the final value after casting to unsigned int will be 4.
This patch changes the data type to uint64_t. This does not increase
the storage size of LeakyBucket, and allows us to assign the value
directly from qemu_opt_get_number() or BlockIOThrottle and then do the
checks directly in throttle_is_valid().
The value of burst_length does not have a specific upper limit,
but since the bucket size is defined by max * burst_length we have
to prevent overflows. Instead of going for UINT64_MAX or something
similar this patch reuses THROTTLE_VALUE_MAX, which allows I/O bursts
of 1 GiB/s for 10 days in a row.
Signed-off-by: Alberto Garcia <address@hidden>
Message-id: address@hidden
Signed-off-by: Stefan Hajnoczi <address@hidden>
---
include/qemu/throttle.h | 2 +-
util/throttle.c | 5 +++++
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/include/qemu/throttle.h b/include/qemu/throttle.h
index 6e31155fd4..8e01885d29 100644
--- a/include/qemu/throttle.h
+++ b/include/qemu/throttle.h
@@ -81,7 +81,7 @@ typedef struct LeakyBucket {
uint64_t max; /* leaky bucket max burst in units */
double level; /* bucket level in units */
double burst_level; /* bucket level in units (for computing bursts)
*/
- unsigned burst_length; /* max length of the burst period, in seconds */
+ uint64_t burst_length; /* max length of the burst period, in seconds */
} LeakyBucket;
/* The following structure is used to configure a ThrottleState
diff --git a/util/throttle.c b/util/throttle.c
index 80660ffd2c..b8c524336c 100644
--- a/util/throttle.c
+++ b/util/throttle.c
@@ -354,6 +354,11 @@ bool throttle_is_valid(ThrottleConfig *cfg, Error **errp)
return false;
}
+ if (bkt->max && bkt->burst_length > THROTTLE_VALUE_MAX / bkt->max) {
+ error_setg(errp, "burst length too high for this burst rate");
+ return false;
+ }
+
if (bkt->max && !bkt->avg) {
error_setg(errp, "bps_max/iops_max require corresponding"
" bps/iops values");
--
2.13.5
- [Qemu-devel] [PULL for-2.10 00/15] Block patches, Stefan Hajnoczi, 2017/08/31
- [Qemu-devel] [PULL for-2.10 01/15] nvme: Fix get/set number of queues feature, again, Stefan Hajnoczi, 2017/08/31
- [Qemu-devel] [PULL for-2.10 02/15] throttle: Fix wrong variable name in the header documentation, Stefan Hajnoczi, 2017/08/31
- [Qemu-devel] [PULL for-2.10 03/15] throttle: Update the throttle_fix_bucket() documentation, Stefan Hajnoczi, 2017/08/31
- [Qemu-devel] [PULL for-2.10 04/15] throttle: Make throttle_is_valid() a bit less verbose, Stefan Hajnoczi, 2017/08/31
- [Qemu-devel] [PULL for-2.10 05/15] throttle: Remove throttle_fix_bucket() / throttle_unfix_bucket(), Stefan Hajnoczi, 2017/08/31
- [Qemu-devel] [PULL for-2.10 06/15] throttle: Make LeakyBucket.avg and LeakyBucket.max integer types, Stefan Hajnoczi, 2017/08/31
- [Qemu-devel] [PULL for-2.10 07/15] throttle: Make burst_length 64bit and add range checks,
Stefan Hajnoczi <=
- [Qemu-devel] [PULL for-2.10 08/15] throttle: Test the valid range of config values, Stefan Hajnoczi, 2017/08/31
- [Qemu-devel] [PULL for-2.10 09/15] oslib-posix: Print errors before aborting on qemu_alloc_stack(), Stefan Hajnoczi, 2017/08/31
- [Qemu-devel] [PULL for-2.10 10/15] misc: Remove unused Error variables, Stefan Hajnoczi, 2017/08/31
- [Qemu-devel] [PULL for-2.10 12/15] docker.py: Python 2.6 argparse compatibility, Stefan Hajnoczi, 2017/08/31
- [Qemu-devel] [PULL for-2.10 13/15] tests: migration/guestperf Python 2.6 argparse compatibility, Stefan Hajnoczi, 2017/08/31
- [Qemu-devel] [PULL for-2.10 14/15] qemu-doc: Add UUID support in initiator name, Stefan Hajnoczi, 2017/08/31
- [Qemu-devel] [PULL for-2.10 11/15] scripts: add argparse module for Python 2.6 compatibility, Stefan Hajnoczi, 2017/08/31
- [Qemu-devel] [PULL for-2.10 15/15] qcow2: allocate cluster_cache/cluster_data on demand, Stefan Hajnoczi, 2017/08/31
- Re: [Qemu-devel] [PULL for-2.10 00/15] Block patches, no-reply, 2017/08/31
- Re: [Qemu-devel] [PULL for-2.10 00/15] Block patches, Eric Blake, 2017/08/31