[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 08/22] block: use Error in do_check_io_limits()
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 08/22] block: use Error in do_check_io_limits() |
Date: |
Fri, 22 Feb 2013 22:23:37 +0100 |
From: Stefan Hajnoczi <address@hidden>
The do_check_io_limits() function returns false when I/O limits are
invalid but it doesn't set an Error to indicate why. The two
do_check_io_limits() callers duplicate error reporting. Solve this by
passing an Error pointer into do_check_io_limits().
Note that the two callers report slightly different errors: drive_init()
prints a custom error message while qmp_block_set_io_throttle() does
error_set(errp, QERR_INVALID_PARAMETER_COMBINATION).
QERR_INVALID_PARAMETER_COMBINATION is a generic error, see
include/qapi/qmp/qerror.h:
#define QERR_INVALID_PARAMETER_COMBINATION \
ERROR_CLASS_GENERIC_ERROR, "Invalid parameter combination"
Since it is generic we are not obliged to keep this error. Switch to
the custom error message which contains more information.
This patch prepares for adding additional checks with their own error
messages to do_check_io_limits(). The next patch adds a new check.
Reviewed-by: Kevin Wolf <address@hidden>
Signed-off-by: Stefan Hajnoczi <address@hidden>
---
blockdev.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/blockdev.c b/blockdev.c
index 63e6f1e..9b03513 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -255,7 +255,7 @@ static int parse_block_error_action(const char *buf, bool
is_read)
}
}
-static bool do_check_io_limits(BlockIOLimit *io_limits)
+static bool do_check_io_limits(BlockIOLimit *io_limits, Error **errp)
{
bool bps_flag;
bool iops_flag;
@@ -269,6 +269,8 @@ static bool do_check_io_limits(BlockIOLimit *io_limits)
&& ((io_limits->iops[BLOCK_IO_LIMIT_READ] != 0)
|| (io_limits->iops[BLOCK_IO_LIMIT_WRITE] != 0));
if (bps_flag || iops_flag) {
+ error_setg(errp, "bps(iops) and bps_rd/bps_wr(iops_rd/iops_wr) "
+ "cannot be used at the same time");
return false;
}
@@ -297,6 +299,7 @@ DriveInfo *drive_init(QemuOpts *opts, BlockInterfaceType
block_default_type)
int snapshot = 0;
bool copy_on_read;
int ret;
+ Error *error = NULL;
translation = BIOS_ATA_TRANSLATION_AUTO;
media = MEDIA_DISK;
@@ -427,9 +430,9 @@ DriveInfo *drive_init(QemuOpts *opts, BlockInterfaceType
block_default_type)
io_limits.iops[BLOCK_IO_LIMIT_WRITE] =
qemu_opt_get_number(opts, "iops_wr", 0);
- if (!do_check_io_limits(&io_limits)) {
- error_report("bps(iops) and bps_rd/bps_wr(iops_rd/iops_wr) "
- "cannot be used at the same time");
+ if (!do_check_io_limits(&io_limits, &error)) {
+ error_report("%s", error_get_pretty(error));
+ error_free(error);
return NULL;
}
@@ -975,8 +978,7 @@ void qmp_block_set_io_throttle(const char *device, int64_t
bps, int64_t bps_rd,
io_limits.iops[BLOCK_IO_LIMIT_READ] = iops_rd;
io_limits.iops[BLOCK_IO_LIMIT_WRITE]= iops_wr;
- if (!do_check_io_limits(&io_limits)) {
- error_set(errp, QERR_INVALID_PARAMETER_COMBINATION);
+ if (!do_check_io_limits(&io_limits, errp)) {
return;
}
--
1.8.1.2
- [Qemu-devel] [PULL 00/22] Block patches, Kevin Wolf, 2013/02/22
- [Qemu-devel] [PATCH 02/22] qemu-img: add json output option to the check command, Kevin Wolf, 2013/02/22
- [Qemu-devel] [PATCH 01/22] qemu-img: find the image end offset during check, Kevin Wolf, 2013/02/22
- [Qemu-devel] [PATCH 03/22] qcow2: introduce check_refcounts_l1/l2() flags, Kevin Wolf, 2013/02/22
- [Qemu-devel] [PATCH 04/22] qcow2: record fragmentation statistics during check, Kevin Wolf, 2013/02/22
- [Qemu-devel] [PATCH 10/22] block: Add synchronous wrapper for bdrv_co_is_allocated_above, Kevin Wolf, 2013/02/22
- [Qemu-devel] [PATCH 07/22] qcow2: support compressed clusters in BlockFragInfo, Kevin Wolf, 2013/02/22
- [Qemu-devel] [PATCH 09/22] block: refuse negative iops and bps values, Kevin Wolf, 2013/02/22
- [Qemu-devel] [PATCH 08/22] block: use Error in do_check_io_limits(),
Kevin Wolf <=
- [Qemu-devel] [PATCH 06/22] qemu-img: add compressed clusters to BlockFragInfo, Kevin Wolf, 2013/02/22
- [Qemu-devel] [PATCH 05/22] qemu-img: fix missing space in qemu-img check output, Kevin Wolf, 2013/02/22
- [Qemu-devel] [PATCH 12/22] qemu-img: Add compare subcommand, Kevin Wolf, 2013/02/22
- [Qemu-devel] [PATCH 11/22] qemu-img: Add "Quiet mode" option, Kevin Wolf, 2013/02/22
- [Qemu-devel] [PATCH 15/22] coroutine: move pooling to common code, Kevin Wolf, 2013/02/22
- [Qemu-devel] [PATCH 13/22] qemu-iotests: Add qemu-img compare test, Kevin Wolf, 2013/02/22
- [Qemu-devel] [PATCH 16/22] coroutine: trim down nesting level in perf_nesting test, Kevin Wolf, 2013/02/22
- [Qemu-devel] [PATCH 17/22] block: complete all IOs before .bdrv_truncate, Kevin Wolf, 2013/02/22
- [Qemu-devel] [PATCH 19/22] blockdev: add discard suboption to -drive, Kevin Wolf, 2013/02/22
- [Qemu-devel] [PATCH 18/22] block: implement BDRV_O_UNMAP, Kevin Wolf, 2013/02/22