From patchwork Wed Aug 13 17:20:17 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Lieven X-Patchwork-Id: 379700 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id EF8F1140087 for ; Thu, 14 Aug 2014 03:22:22 +1000 (EST) Received: from localhost ([::1]:49011 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XHcFg-0001JZ-HP for incoming@patchwork.ozlabs.org; Wed, 13 Aug 2014 13:22:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59419) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XHcF6-0000OT-AY for qemu-devel@nongnu.org; Wed, 13 Aug 2014 13:21:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XHcF1-0007ku-P4 for qemu-devel@nongnu.org; Wed, 13 Aug 2014 13:21:44 -0400 Received: from mx-v6.kamp.de ([2a02:248:0:51::16]:40498 helo=mx01.kamp.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XHcF1-0007ie-Dy for qemu-devel@nongnu.org; Wed, 13 Aug 2014 13:21:39 -0400 Received: (qmail 27472 invoked by uid 89); 13 Aug 2014 17:21:36 -0000 Received: from [82.141.1.145] by client-16-kamp (envelope-from , uid 89) with qmail-scanner-2010/03/19-MF (clamdscan: 0.98.4/19279. hbedv: 8.3.24.6/7.11.166.238. spamassassin: 3.4.0. Clear:RC:1(82.141.1.145):SA:0(-1.2/5.0):. Processed in 1.472788 secs); 13 Aug 2014 17:21:36 -0000 Received: from ns.kamp-intra.net (HELO dns.kamp-intra.net) ([82.141.1.145]) by mx01.kamp.de with SMTP; 13 Aug 2014 17:21:34 -0000 X-GL_Whitelist: yes Received: from lieven-pc.kamp-intra.net (lieven-pc.kamp-intra.net [172.21.12.60]) by dns.kamp-intra.net (Postfix) with ESMTP id 0FF162068F; Wed, 13 Aug 2014 19:20:24 +0200 (CEST) Received: by lieven-pc.kamp-intra.net (Postfix, from userid 1000) id 05B746117B; Wed, 13 Aug 2014 19:20:24 +0200 (CEST) From: Peter Lieven To: qemu-devel@nongnu.org Date: Wed, 13 Aug 2014 19:20:17 +0200 Message-Id: <1407950419-3486-2-git-send-email-pl@kamp.de> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1407950419-3486-1-git-send-email-pl@kamp.de> References: <1407950419-3486-1-git-send-email-pl@kamp.de> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a02:248:0:51::16 Cc: kwolf@redhat.com, hutao@cn.fujitsu.com, Peter Lieven , armbru@redhat.com, mreitz@redhat.com, stefanha@redhat.com, pbonzini@redhat.com Subject: [Qemu-devel] [PATCHv2 1/3] rename parse_enum_option to qapi_enum_parse and make it public 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 relaxing the license to LGPLv2+ is intentional. Suggested-by: Markus Armbruster Signed-off-by: Hu Tao Signed-off-by: Peter Lieven Reviewed-by: Eric Blake Reviewed-by: Benoit Canet --- blockdev.c | 30 ++++++------------------------ include/qapi/util.h | 17 +++++++++++++++++ qapi/Makefile.objs | 2 +- qapi/qapi-util.c | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 25 deletions(-) create mode 100644 include/qapi/util.h create mode 100644 qapi/qapi-util.c diff --git a/blockdev.c b/blockdev.c index 48bd9a3..9b93cf2 100644 --- a/blockdev.c +++ b/blockdev.c @@ -39,6 +39,7 @@ #include "qapi/qmp/types.h" #include "qapi-visit.h" #include "qapi/qmp-output-visitor.h" +#include "qapi/util.h" #include "sysemu/sysemu.h" #include "block/block_int.h" #include "qmp-commands.h" @@ -274,25 +275,6 @@ static int parse_block_error_action(const char *buf, bool is_read, Error **errp) } } -static inline int parse_enum_option(const char *lookup[], const char *buf, - int max, int def, Error **errp) -{ - int i; - - if (!buf) { - return def; - } - - for (i = 0; i < max; i++) { - if (!strcmp(buf, lookup[i])) { - return i; - } - } - - error_setg(errp, "invalid parameter value: %s", buf); - return def; -} - static bool check_throttle_config(ThrottleConfig *cfg, Error **errp) { if (throttle_conflicting(cfg)) { @@ -456,11 +438,11 @@ static DriveInfo *blockdev_init(const char *file, QDict *bs_opts, } detect_zeroes = - parse_enum_option(BlockdevDetectZeroesOptions_lookup, - qemu_opt_get(opts, "detect-zeroes"), - BLOCKDEV_DETECT_ZEROES_OPTIONS_MAX, - BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF, - &error); + qapi_enum_parse(BlockdevDetectZeroesOptions_lookup, + qemu_opt_get(opts, "detect-zeroes"), + BLOCKDEV_DETECT_ZEROES_OPTIONS_MAX, + BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF, + &error); if (error) { error_propagate(errp, error); goto early_err; diff --git a/include/qapi/util.h b/include/qapi/util.h new file mode 100644 index 0000000..de9238b --- /dev/null +++ b/include/qapi/util.h @@ -0,0 +1,17 @@ +/* + * QAPI util functions + * + * Copyright Fujitsu, Inc. 2014 + * + * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. + * See the COPYING.LIB file in the top-level directory. + * + */ + +#ifndef QAPI_UTIL_H +#define QAPI_UTIL_H + +int qapi_enum_parse(const char *lookup[], const char *buf, + int max, int def, Error **errp); + +#endif diff --git a/qapi/Makefile.objs b/qapi/Makefile.objs index d14b769..2278970 100644 --- a/qapi/Makefile.objs +++ b/qapi/Makefile.objs @@ -1,6 +1,6 @@ util-obj-y = qapi-visit-core.o qapi-dealloc-visitor.o qmp-input-visitor.o util-obj-y += qmp-output-visitor.o qmp-registry.o qmp-dispatch.o util-obj-y += string-input-visitor.o string-output-visitor.o - util-obj-y += opts-visitor.o util-obj-y += qmp-event.o +util-obj-y += qapi-util.o diff --git a/qapi/qapi-util.c b/qapi/qapi-util.c new file mode 100644 index 0000000..1d8fb96 --- /dev/null +++ b/qapi/qapi-util.c @@ -0,0 +1,34 @@ +/* + * QAPI util functions + * + * Authors: + * Hu Tao + * Peter Lieven + * + * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. + * See the COPYING.LIB file in the top-level directory. + * + */ + +#include "qemu-common.h" +#include "qapi/error.h" +#include "qapi/util.h" + +int qapi_enum_parse(const char *lookup[], const char *buf, + int max, int def, Error **errp) +{ + int i; + + if (!buf) { + return def; + } + + for (i = 0; i < max; i++) { + if (!strcmp(buf, lookup[i])) { + return i; + } + } + + error_setg(errp, "invalid parameter value: %s", buf); + return def; +}