From patchwork Tue Apr 17 19:36:05 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 153295 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 6565CB705E for ; Wed, 18 Apr 2012 05:36:42 +1000 (EST) Received: from localhost ([::1]:58301 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SKECe-0004ow-5G for incoming@patchwork.ozlabs.org; Tue, 17 Apr 2012 15:36:40 -0400 Received: from eggs.gnu.org ([208.118.235.92]:37300) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SKECO-0004fg-Fx for qemu-devel@nongnu.org; Tue, 17 Apr 2012 15:36:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SKECL-0008Mp-0R for qemu-devel@nongnu.org; Tue, 17 Apr 2012 15:36:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60179) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SKECK-0008Mc-OP for qemu-devel@nongnu.org; Tue, 17 Apr 2012 15:36:20 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q3HJaHIW006606 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 17 Apr 2012 15:36:17 -0400 Received: from localhost (ovpn-113-173.phx2.redhat.com [10.3.113.173]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q3HJaG82032530; Tue, 17 Apr 2012 15:36:17 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Tue, 17 Apr 2012 16:36:05 -0300 Message-Id: <1334691381-7666-3-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1334691381-7666-1-git-send-email-lcapitulino@redhat.com> References: <1334691381-7666-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: pbonzini@redhat.com, aliguori@us.ibm.com, mdroth@linux.vnet.ibm.com, armbru@redhat.com Subject: [Qemu-devel] [PATCH 02/18] qemu-option: parse_option_number(): use error_set() 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 Note that qemu_opt_parse() callers still expect automatic error reporting with QError, so qemu_opts_parse() calls qerror_report_err() to keep the same semantics. Signed-off-by: Luiz Capitulino --- qemu-option.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/qemu-option.c b/qemu-option.c index 9f531c8..72dcb56 100644 --- a/qemu-option.c +++ b/qemu-option.c @@ -186,7 +186,8 @@ static int parse_option_bool(const char *name, const char *value, bool *ret) return 0; } -static int parse_option_number(const char *name, const char *value, uint64_t *ret) +static void parse_option_number(const char *name, const char *value, + uint64_t *ret, Error **errp) { char *postfix; uint64_t number; @@ -194,15 +195,13 @@ static int parse_option_number(const char *name, const char *value, uint64_t *re if (value != NULL) { number = strtoull(value, &postfix, 0); if (*postfix != '\0') { - qerror_report(QERR_INVALID_PARAMETER_VALUE, name, "a number"); - return -1; + error_set(errp, QERR_INVALID_PARAMETER_VALUE, name, "a number"); + return; } *ret = number; } else { - qerror_report(QERR_INVALID_PARAMETER_VALUE, name, "a number"); - return -1; + error_set(errp, QERR_INVALID_PARAMETER_VALUE, name, "a number"); } - return 0; } static int parse_option_size(const char *name, const char *value, uint64_t *ret) @@ -579,8 +578,11 @@ uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval) static int qemu_opt_parse(QemuOpt *opt) { + Error *local_err = NULL; + if (opt->desc == NULL) return 0; + switch (opt->desc->type) { case QEMU_OPT_STRING: /* nothing */ @@ -588,12 +590,22 @@ static int qemu_opt_parse(QemuOpt *opt) case QEMU_OPT_BOOL: return parse_option_bool(opt->name, opt->str, &opt->value.boolean); case QEMU_OPT_NUMBER: - return parse_option_number(opt->name, opt->str, &opt->value.uint); + parse_option_number(opt->name, opt->str, &opt->value.uint, + &local_err); + break; case QEMU_OPT_SIZE: return parse_option_size(opt->name, opt->str, &opt->value.uint); default: abort(); } + + if (error_is_set(&local_err)) { + qerror_report_err(local_err); + error_free(local_err); + return -1; + } + + return 0; } static void qemu_opt_del(QemuOpt *opt)