From patchwork Thu Mar 29 17:26:32 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 149452 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 010E1B6EEC for ; Fri, 30 Mar 2012 04:57:54 +1100 (EST) Received: from localhost ([::1]:40562 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SDJ8H-0000b2-VE for incoming@patchwork.ozlabs.org; Thu, 29 Mar 2012 13:27:33 -0400 Received: from eggs.gnu.org ([208.118.235.92]:41739) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SDJ7a-0007MM-OF for qemu-devel@nongnu.org; Thu, 29 Mar 2012 13:26:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SDJ7U-0003Sc-Gh for qemu-devel@nongnu.org; Thu, 29 Mar 2012 13:26:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60284) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SDJ7U-0003SR-8m for qemu-devel@nongnu.org; Thu, 29 Mar 2012 13:26:44 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q2THQfYZ030363 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 29 Mar 2012 13:26:41 -0400 Received: from localhost (ovpn-113-102.phx2.redhat.com [10.3.113.102]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q2THQeMh023727; Thu, 29 Mar 2012 13:26:40 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Thu, 29 Mar 2012 14:26:32 -0300 Message-Id: <1333042003-15490-3-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1333042003-15490-1-git-send-email-lcapitulino@redhat.com> References: <1333042003-15490-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: mdroth@linux.vnet.ibm.com, aliguori@us.ibm.com, kraxel@redhat.com, stefanha@linux.vnet.ibm.com, armbru@redhat.com Subject: [Qemu-devel] [PATCH 02/13] 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)