hmp: Use qapi_enum_parse() in hmp_migrate_set_capability()

The error message on invalid capability name changes from

    Invalid parameter "NAME"

to

    invalid parameter value: NAME

No worse than before.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20170822132255.23945-9-marcandre.lureau@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
[Rebased, commit message rewritten]
Cc: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <1503564371-26090-6-git-send-email-armbru@redhat.com>
This commit is contained in:
Marc-André Lureau 2017-08-24 10:46:00 +02:00 committed by Markus Armbruster
parent 00bbf50a50
commit 8e615e34f9

23
hmp.c
View File

@ -1527,23 +1527,20 @@ void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
bool state = qdict_get_bool(qdict, "state");
Error *err = NULL;
MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
int i;
int val;
for (i = 0; i < MIGRATION_CAPABILITY__MAX; i++) {
if (strcmp(cap, MigrationCapability_lookup[i]) == 0) {
caps->value = g_malloc0(sizeof(*caps->value));
caps->value->capability = i;
caps->value->state = state;
caps->next = NULL;
qmp_migrate_set_capabilities(caps, &err);
break;
}
val = qapi_enum_parse(MigrationCapability_lookup, cap, -1, &err);
if (val < 0) {
goto end;
}
if (i == MIGRATION_CAPABILITY__MAX) {
error_setg(&err, QERR_INVALID_PARAMETER, cap);
}
caps->value = g_malloc0(sizeof(*caps->value));
caps->value->capability = val;
caps->value->state = state;
caps->next = NULL;
qmp_migrate_set_capabilities(caps, &err);
end:
qapi_free_MigrationCapabilityStatusList(caps);
if (err) {