mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-03 07:43:54 -06:00
qemu-option: qemu_opts_create(): use error_set()
This commit converts qemu_opts_create() from qerror_report() to error_set(). Currently, most calls to qemu_opts_create() can't fail, so most callers don't need any changes. The two cases where code checks for qemu_opts_create() erros are: 1. Initialization code in vl.c. All of them print their own error messages directly to stderr, no need to pass the Error object 2. The functions opts_parse(), qemu_opts_from_qdict() and qemu_chr_parse_compat() make use of the error information and they can be called from HMP or QMP. In this case, to allow for incremental conversion, we propagate the error up using qerror_report_err(), which keeps the QError semantics Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Reviewed-By: Laszlo Ersek <lersek@redhat.com>
This commit is contained in:
parent
783e9b4826
commit
8be7e7e4c7
9 changed files with 59 additions and 32 deletions
|
@ -30,6 +30,7 @@
|
|||
#include "qemu-error.h"
|
||||
#include "qemu-objects.h"
|
||||
#include "qemu-option.h"
|
||||
#include "error.h"
|
||||
#include "qerror.h"
|
||||
|
||||
/*
|
||||
|
@ -729,20 +730,21 @@ static int id_wellformed(const char *id)
|
|||
return 1;
|
||||
}
|
||||
|
||||
QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id, int fail_if_exists)
|
||||
QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id,
|
||||
int fail_if_exists, Error **errp)
|
||||
{
|
||||
QemuOpts *opts = NULL;
|
||||
|
||||
if (id) {
|
||||
if (!id_wellformed(id)) {
|
||||
qerror_report(QERR_INVALID_PARAMETER_VALUE, "id", "an identifier");
|
||||
error_set(errp,QERR_INVALID_PARAMETER_VALUE, "id", "an identifier");
|
||||
error_printf_unless_qmp("Identifiers consist of letters, digits, '-', '.', '_', starting with a letter.\n");
|
||||
return NULL;
|
||||
}
|
||||
opts = qemu_opts_find(list, id);
|
||||
if (opts != NULL) {
|
||||
if (fail_if_exists && !list->merge_lists) {
|
||||
qerror_report(QERR_DUPLICATE_ID, id, list->name);
|
||||
error_set(errp, QERR_DUPLICATE_ID, id, list->name);
|
||||
return NULL;
|
||||
} else {
|
||||
return opts;
|
||||
|
@ -783,9 +785,12 @@ int qemu_opts_set(QemuOptsList *list, const char *id,
|
|||
const char *name, const char *value)
|
||||
{
|
||||
QemuOpts *opts;
|
||||
Error *local_err = NULL;
|
||||
|
||||
opts = qemu_opts_create(list, id, 1);
|
||||
if (opts == NULL) {
|
||||
opts = qemu_opts_create(list, id, 1, &local_err);
|
||||
if (error_is_set(&local_err)) {
|
||||
qerror_report_err(local_err);
|
||||
error_free(local_err);
|
||||
return -1;
|
||||
}
|
||||
return qemu_opt_set(opts, name, value);
|
||||
|
@ -883,6 +888,7 @@ static QemuOpts *opts_parse(QemuOptsList *list, const char *params,
|
|||
char value[1024], *id = NULL;
|
||||
const char *p;
|
||||
QemuOpts *opts;
|
||||
Error *local_err = NULL;
|
||||
|
||||
assert(!permit_abbrev || list->implied_opt_name);
|
||||
firstname = permit_abbrev ? list->implied_opt_name : NULL;
|
||||
|
@ -898,13 +904,18 @@ static QemuOpts *opts_parse(QemuOptsList *list, const char *params,
|
|||
if (!id && !QTAILQ_EMPTY(&list->head)) {
|
||||
opts = qemu_opts_find(list, NULL);
|
||||
} else {
|
||||
opts = qemu_opts_create(list, id, 0);
|
||||
opts = qemu_opts_create(list, id, 0, &local_err);
|
||||
}
|
||||
} else {
|
||||
opts = qemu_opts_create(list, id, 1);
|
||||
opts = qemu_opts_create(list, id, 1, &local_err);
|
||||
}
|
||||
if (opts == NULL)
|
||||
if (opts == NULL) {
|
||||
if (error_is_set(&local_err)) {
|
||||
qerror_report_err(local_err);
|
||||
error_free(local_err);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (opts_do_parse(opts, params, firstname, defaults) != 0) {
|
||||
qemu_opts_del(opts);
|
||||
|
@ -975,11 +986,17 @@ static void qemu_opts_from_qdict_1(const char *key, QObject *obj, void *opaque)
|
|||
QemuOpts *qemu_opts_from_qdict(QemuOptsList *list, const QDict *qdict)
|
||||
{
|
||||
QemuOpts *opts;
|
||||
Error *local_err = NULL;
|
||||
|
||||
opts = qemu_opts_create(list, qdict_get_try_str(qdict, "id"), 1);
|
||||
if (opts == NULL)
|
||||
opts = qemu_opts_create(list, qdict_get_try_str(qdict, "id"), 1,
|
||||
&local_err);
|
||||
if (error_is_set(&local_err)) {
|
||||
qerror_report_err(local_err);
|
||||
error_free(local_err);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
assert(opts != NULL);
|
||||
qdict_iter(qdict, qemu_opts_from_qdict_1, opts);
|
||||
return opts;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue