From nobody Tue Nov 4 13:09:05 2025 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 1504272121365557.4143815341606; Fri, 1 Sep 2017 06:22:01 -0700 (PDT) Received: from localhost ([::1]:40013 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dnltY-00073l-A2 for importer@patchew.org; Fri, 01 Sep 2017 09:22:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54330) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dnlV4-0000fa-1w for qemu-devel@nongnu.org; Fri, 01 Sep 2017 08:56:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dnlV3-0007Wf-4N for qemu-devel@nongnu.org; Fri, 01 Sep 2017 08:56:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35746) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dnlUl-0007ON-0o; Fri, 01 Sep 2017 08:56:23 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F351CC9D2F; Fri, 1 Sep 2017 12:56:21 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-75.ams2.redhat.com [10.36.116.75]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2637CA63AA; Fri, 1 Sep 2017 12:56:21 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id B21A41132F47; Fri, 1 Sep 2017 14:56:12 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com F351CC9D2F Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=armbru@redhat.com From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 1 Sep 2017 14:56:02 +0200 Message-Id: <20170901125611.29295-39-armbru@redhat.com> In-Reply-To: <20170901125611.29295-1-armbru@redhat.com> References: <20170901125611.29295-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 01 Sep 2017 12:56:22 +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] [PULL 38/47] 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?= , qemu-block@nongnu.org, 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" From: Marc-Andr=C3=A9 Lureau The error message on invalid blkdebug events changes from qemu-system-x86_64: LOCATION: Invalid event name "VALUE" to qemu-system-x86_64: LOCATION: invalid parameter value: VALUE Slight degradation, but the message is sub-par even before the patch. When complaining about a parameter value, both parameter name and value should be mentioned, as the value may well not be unique. Left for another day. Also left is the error message's unhelpful location: it points to the config=3DFILENAME rather than into that file. Signed-off-by: Marc-Andr=C3=A9 Lureau Message-Id: <20170822132255.23945-11-marcandre.lureau@redhat.com> Reviewed-by: Markus Armbruster [Rebased, commit message rewritten] Cc: Kevin Wolf Cc: Max Reitz Cc: qemu-block@nongnu.org Signed-off-by: Markus Armbruster Message-Id: <1503564371-26090-8-git-send-email-armbru@redhat.com> --- block/blkdebug.c | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/block/blkdebug.c b/block/blkdebug.c index c19ab28f07..f1bbee9497 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, -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, -1, NU= LL); + if (blkdebug_event < 0) { return -ENOENT; } =20 - rule =3D g_malloc(sizeof(*rule)); *rule =3D (struct BlkdebugRule) { .event =3D blkdebug_event, --=20 2.13.5