From: Fam Zheng <famz@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
Markus Armbruster <armbru@redhat.com>,
qemu-block@nongnu.org
Subject: [Qemu-devel] [PATCH 1/2] blockdev: Error out on negative throttling option values
Date: Mon, 11 Jan 2016 13:42:38 +0800 [thread overview]
Message-ID: <1452490959-10387-2-git-send-email-famz@redhat.com> (raw)
In-Reply-To: <1452490959-10387-1-git-send-email-famz@redhat.com>
The implicit casting from unsigned int to double changes negative values
into large positive numbers, whereas explicitly casting to signed
integer first will let us catch the invalid value and report error
correctly:
$ qemu-system-x86_64 -drive file=null-co://,iops=-1
qemu-system-x86_64: -drive file=null-co://,iops=-1: bps/iops/maxs
values must be 0 or greater
Signed-off-by: Fam Zheng <famz@redhat.com>
---
blockdev.c | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/blockdev.c b/blockdev.c
index 2df0c6d..8b6b398 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -407,33 +407,33 @@ static void extract_common_blockdev_options(QemuOpts *opts, int *bdrv_flags,
if (throttle_cfg) {
memset(throttle_cfg, 0, sizeof(*throttle_cfg));
throttle_cfg->buckets[THROTTLE_BPS_TOTAL].avg =
- qemu_opt_get_number(opts, "throttling.bps-total", 0);
+ (int64_t)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);
+ (int64_t)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);
+ (int64_t)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);
+ (int64_t)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);
+ (int64_t)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);
+ (int64_t)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);
+ (int64_t)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);
+ (int64_t)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);
+ (int64_t)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);
+ (int64_t)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);
+ (int64_t)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);
+ (int64_t)qemu_opt_get_number(opts, "throttling.iops-write-max", 0);
throttle_cfg->op_size =
- qemu_opt_get_number(opts, "throttling.iops-size", 0);
+ (int64_t)qemu_opt_get_number(opts, "throttling.iops-size", 0);
if (!check_throttle_config(throttle_cfg, errp)) {
return;
--
2.4.3
next prev parent reply other threads:[~2016-01-11 5:43 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-11 5:42 [Qemu-devel] [PATCH 0/2] block: Reject negative values for throttling options Fam Zheng
2016-01-11 5:42 ` Fam Zheng [this message]
2016-01-12 15:00 ` [Qemu-devel] [Qemu-block] [PATCH 1/2] blockdev: Error out on negative throttling option values Alberto Garcia
2016-01-13 0:29 ` Fam Zheng
2016-01-11 5:42 ` [Qemu-devel] [PATCH 2/2] iotests: Test that negative throttle values are rejected Fam Zheng
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1452490959-10387-2-git-send-email-famz@redhat.com \
--to=famz@redhat.com \
--cc=armbru@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).