From nobody Tue Feb 10 11:12:57 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1503409270400128.00644893159006; Tue, 22 Aug 2017 06:41:10 -0700 (PDT) Received: from localhost ([::1]:46966 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9Qb-0005Zv-5K for importer@patchew.org; Tue, 22 Aug 2017 09:41:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54664) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9HW-0006Oi-Ut for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:31:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9HR-0005mJ-2x for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:31:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55034) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9HJ-0005cS-Ro; Tue, 22 Aug 2017 09:31:34 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3251740430A; Tue, 22 Aug 2017 13:23:51 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id BA6BF61786; Tue, 22 Aug 2017 13:23:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3251740430A Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 22 Aug 2017 15:22:11 +0200 Message-Id: <20170822132255.23945-11-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 22 Aug 2017 13:23:51 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 10/54] block: use qemu_enum_parse() in blkdebug_debug_breakpoint X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "open list:blkdebug" , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This slightly change the error report message from "Invalid event name" to "Invalid parameter". Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Markus Armbruster --- block/blkdebug.c | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/block/blkdebug.c b/block/blkdebug.c index c19ab28f07..50edda2a31 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -32,6 +32,7 @@ #include "qapi/qmp/qbool.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qstring.h" +#include "qapi/util.h" #include "sysemu/qtest.h" =20 typedef struct BDRVBlkdebugState { @@ -149,20 +150,6 @@ static QemuOptsList *config_groups[] =3D { NULL }; =20 -static int get_event_by_name(const char *name, BlkdebugEvent *event) -{ - int i; - - for (i =3D 0; i < BLKDBG__MAX; i++) { - if (!strcmp(BlkdebugEvent_lookup[i], name)) { - *event =3D i; - return 0; - } - } - - return -1; -} - struct add_rule_data { BDRVBlkdebugState *s; int action; @@ -173,7 +160,7 @@ static int add_rule(void *opaque, QemuOpts *opts, Error= **errp) struct add_rule_data *d =3D opaque; BDRVBlkdebugState *s =3D d->s; const char* event_name; - BlkdebugEvent event; + int event; struct BlkdebugRule *rule; int64_t sector; =20 @@ -182,8 +169,9 @@ static int add_rule(void *opaque, QemuOpts *opts, Error= **errp) if (!event_name) { error_setg(errp, "Missing event name for rule"); return -1; - } else if (get_event_by_name(event_name, &event) < 0) { - error_setg(errp, "Invalid event name \"%s\"", event_name); + } + event =3D qapi_enum_parse(BlkdebugEvent_lookup, event_name, BLKDBG__MA= X, -1, errp); + if (event < 0) { return -1; } =20 @@ -743,13 +731,13 @@ static int blkdebug_debug_breakpoint(BlockDriverState= *bs, const char *event, { BDRVBlkdebugState *s =3D bs->opaque; struct BlkdebugRule *rule; - BlkdebugEvent blkdebug_event; + int blkdebug_event; =20 - if (get_event_by_name(event, &blkdebug_event) < 0) { + blkdebug_event =3D qapi_enum_parse(BlkdebugEvent_lookup, event, BLKDBG= __MAX, -1, NULL); + if (blkdebug_event < 0) { return -ENOENT; } =20 - rule =3D g_malloc(sizeof(*rule)); *rule =3D (struct BlkdebugRule) { .event =3D blkdebug_event, --=20 2.14.1.146.gd35faa819