From patchwork Thu Aug 24 08:46:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 805341 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 3xdHzv26mNz9s8P for ; Thu, 24 Aug 2017 18:50:03 +1000 (AEST) Received: from localhost ([::1]:47282 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dknpx-0005bT-2d for incoming@patchwork.ozlabs.org; Thu, 24 Aug 2017 04:50:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37234) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dknmR-0003QU-Ny for qemu-devel@nongnu.org; Thu, 24 Aug 2017 04:46:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dknmQ-0000S5-Tb for qemu-devel@nongnu.org; Thu, 24 Aug 2017 04:46:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56374) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dknmL-0000Mr-Oh; Thu, 24 Aug 2017 04:46:17 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AB9BE85540; Thu, 24 Aug 2017 08:46:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com AB9BE85540 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=armbru@redhat.com Received: from blackfin.pond.sub.org (ovpn-116-60.ams2.redhat.com [10.36.116.60]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 72FD71797E; Thu, 24 Aug 2017 08:46:16 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id B325A11386CA; Thu, 24 Aug 2017 10:46:11 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 24 Aug 2017 10:46:02 +0200 Message-Id: <1503564371-26090-8-git-send-email-armbru@redhat.com> In-Reply-To: <1503564371-26090-1-git-send-email-armbru@redhat.com> References: <1503564371-26090-1-git-send-email-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 24 Aug 2017 08:46:16 +0000 (UTC) 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 07/16] 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 , marcandre.lureau@redhat.com, mdroth@linux.vnet.ibm.com, qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Marc-André 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=FILENAME rather than into that file. Signed-off-by: Marc-André 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 --- block/blkdebug.c | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/block/blkdebug.c b/block/blkdebug.c index c19ab28..f1bbee9 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" typedef struct BDRVBlkdebugState { @@ -149,20 +150,6 @@ static QemuOptsList *config_groups[] = { NULL }; -static int get_event_by_name(const char *name, BlkdebugEvent *event) -{ - int i; - - for (i = 0; i < BLKDBG__MAX; i++) { - if (!strcmp(BlkdebugEvent_lookup[i], name)) { - *event = 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 = opaque; BDRVBlkdebugState *s = d->s; const char* event_name; - BlkdebugEvent event; + int event; struct BlkdebugRule *rule; int64_t sector; @@ -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 = qapi_enum_parse(BlkdebugEvent_lookup, event_name, -1, errp); + if (event < 0) { return -1; } @@ -743,13 +731,13 @@ static int blkdebug_debug_breakpoint(BlockDriverState *bs, const char *event, { BDRVBlkdebugState *s = bs->opaque; struct BlkdebugRule *rule; - BlkdebugEvent blkdebug_event; + int blkdebug_event; - if (get_event_by_name(event, &blkdebug_event) < 0) { + blkdebug_event = qapi_enum_parse(BlkdebugEvent_lookup, event, -1, NULL); + if (blkdebug_event < 0) { return -ENOENT; } - rule = g_malloc(sizeof(*rule)); *rule = (struct BlkdebugRule) { .event = blkdebug_event,