block: Use qemu_enum_parse() in blkdebug_debug_breakpoint()
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 <marcandre.lureau@redhat.com> Message-Id: <20170822132255.23945-11-marcandre.lureau@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> [Rebased, commit message rewritten] Cc: Kevin Wolf <kwolf@redhat.com> Cc: Max Reitz <mreitz@redhat.com> Cc: qemu-block@nongnu.org Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-Id: <1503564371-26090-8-git-send-email-armbru@redhat.com>
This commit is contained in:
parent
262517b7e0
commit
f9509d1517
|
@ -32,6 +32,7 @@
|
||||||
#include "qapi/qmp/qbool.h"
|
#include "qapi/qmp/qbool.h"
|
||||||
#include "qapi/qmp/qdict.h"
|
#include "qapi/qmp/qdict.h"
|
||||||
#include "qapi/qmp/qstring.h"
|
#include "qapi/qmp/qstring.h"
|
||||||
|
#include "qapi/util.h"
|
||||||
#include "sysemu/qtest.h"
|
#include "sysemu/qtest.h"
|
||||||
|
|
||||||
typedef struct BDRVBlkdebugState {
|
typedef struct BDRVBlkdebugState {
|
||||||
|
@ -149,20 +150,6 @@ static QemuOptsList *config_groups[] = {
|
||||||
NULL
|
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 {
|
struct add_rule_data {
|
||||||
BDRVBlkdebugState *s;
|
BDRVBlkdebugState *s;
|
||||||
int action;
|
int action;
|
||||||
|
@ -173,7 +160,7 @@ static int add_rule(void *opaque, QemuOpts *opts, Error **errp)
|
||||||
struct add_rule_data *d = opaque;
|
struct add_rule_data *d = opaque;
|
||||||
BDRVBlkdebugState *s = d->s;
|
BDRVBlkdebugState *s = d->s;
|
||||||
const char* event_name;
|
const char* event_name;
|
||||||
BlkdebugEvent event;
|
int event;
|
||||||
struct BlkdebugRule *rule;
|
struct BlkdebugRule *rule;
|
||||||
int64_t sector;
|
int64_t sector;
|
||||||
|
|
||||||
|
@ -182,8 +169,9 @@ static int add_rule(void *opaque, QemuOpts *opts, Error **errp)
|
||||||
if (!event_name) {
|
if (!event_name) {
|
||||||
error_setg(errp, "Missing event name for rule");
|
error_setg(errp, "Missing event name for rule");
|
||||||
return -1;
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -743,13 +731,13 @@ static int blkdebug_debug_breakpoint(BlockDriverState *bs, const char *event,
|
||||||
{
|
{
|
||||||
BDRVBlkdebugState *s = bs->opaque;
|
BDRVBlkdebugState *s = bs->opaque;
|
||||||
struct BlkdebugRule *rule;
|
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;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
rule = g_malloc(sizeof(*rule));
|
rule = g_malloc(sizeof(*rule));
|
||||||
*rule = (struct BlkdebugRule) {
|
*rule = (struct BlkdebugRule) {
|
||||||
.event = blkdebug_event,
|
.event = blkdebug_event,
|
||||||
|
|
Loading…
Reference in New Issue