From patchwork Fri Feb 22 21:23:37 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 222689 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 5D3EA2C04CE for ; Sat, 23 Feb 2013 09:42:17 +1100 (EST) Received: from localhost ([::1]:42317 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U907k-0004P9-1P for incoming@patchwork.ozlabs.org; Fri, 22 Feb 2013 16:25:44 -0500 Received: from eggs.gnu.org ([208.118.235.92]:35779) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U906N-0002A9-MF for qemu-devel@nongnu.org; Fri, 22 Feb 2013 16:24:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U906G-0003jU-F8 for qemu-devel@nongnu.org; Fri, 22 Feb 2013 16:24:19 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49427) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U906G-0003jG-3u for qemu-devel@nongnu.org; Fri, 22 Feb 2013 16:24:12 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r1MLOAWx009801 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 22 Feb 2013 16:24:10 -0500 Received: from dhcp-200-207.str.redhat.com (ovpn-116-66.ams2.redhat.com [10.36.116.66]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r1MLNuFX010868; Fri, 22 Feb 2013 16:24:09 -0500 From: Kevin Wolf To: anthony@codemonkey.ws Date: Fri, 22 Feb 2013 22:23:37 +0100 Message-Id: <1361568231-18198-9-git-send-email-kwolf@redhat.com> In-Reply-To: <1361568231-18198-1-git-send-email-kwolf@redhat.com> References: <1361568231-18198-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 08/22] block: use Error in do_check_io_limits() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stefan Hajnoczi 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 Signed-off-by: Stefan Hajnoczi --- 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; }