qemu-option: qemu_opt_parse(): use error_set()

The functions opt_set() and qemu_opts_validate() both call qemu_opt_parse(),
but their callers expect QError semantics. Thus, both functions call
qerro_report_err() to keep the expected semantics.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Reviewed-By: Laszlo Ersek <lersek@redhat.com>
This commit is contained in:
Luiz Capitulino 2012-03-21 15:21:26 -03:00
parent ec7b2ccb4a
commit 6c5194046a
1 changed files with 17 additions and 19 deletions

View File

@ -581,38 +581,27 @@ uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval)
return opt->value.uint; return opt->value.uint;
} }
static int qemu_opt_parse(QemuOpt *opt) static void qemu_opt_parse(QemuOpt *opt, Error **errp)
{ {
Error *local_err = NULL;
if (opt->desc == NULL) if (opt->desc == NULL)
return 0; return;
switch (opt->desc->type) { switch (opt->desc->type) {
case QEMU_OPT_STRING: case QEMU_OPT_STRING:
/* nothing */ /* nothing */
return 0; return;
case QEMU_OPT_BOOL: case QEMU_OPT_BOOL:
parse_option_bool(opt->name, opt->str, &opt->value.boolean, &local_err); parse_option_bool(opt->name, opt->str, &opt->value.boolean, errp);
break; break;
case QEMU_OPT_NUMBER: case QEMU_OPT_NUMBER:
parse_option_number(opt->name, opt->str, &opt->value.uint, parse_option_number(opt->name, opt->str, &opt->value.uint, errp);
&local_err);
break; break;
case QEMU_OPT_SIZE: case QEMU_OPT_SIZE:
parse_option_size(opt->name, opt->str, &opt->value.uint, &local_err); parse_option_size(opt->name, opt->str, &opt->value.uint, errp);
break; break;
default: default:
abort(); abort();
} }
if (error_is_set(&local_err)) {
qerror_report_err(local_err);
error_free(local_err);
return -1;
}
return 0;
} }
static void qemu_opt_del(QemuOpt *opt) static void qemu_opt_del(QemuOpt *opt)
@ -628,6 +617,7 @@ static int opt_set(QemuOpts *opts, const char *name, const char *value,
{ {
QemuOpt *opt; QemuOpt *opt;
const QemuOptDesc *desc = opts->list->desc; const QemuOptDesc *desc = opts->list->desc;
Error *local_err = NULL;
int i; int i;
for (i = 0; desc[i].name != NULL; i++) { for (i = 0; desc[i].name != NULL; i++) {
@ -658,10 +648,14 @@ static int opt_set(QemuOpts *opts, const char *name, const char *value,
if (value) { if (value) {
opt->str = g_strdup(value); opt->str = g_strdup(value);
} }
if (qemu_opt_parse(opt) < 0) { qemu_opt_parse(opt, &local_err);
if (error_is_set(&local_err)) {
qerror_report_err(local_err);
error_free(local_err);
qemu_opt_del(opt); qemu_opt_del(opt);
return -1; return -1;
} }
return 0; return 0;
} }
@ -1050,6 +1044,7 @@ QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict *qdict)
int qemu_opts_validate(QemuOpts *opts, const QemuOptDesc *desc) int qemu_opts_validate(QemuOpts *opts, const QemuOptDesc *desc)
{ {
QemuOpt *opt; QemuOpt *opt;
Error *local_err = NULL;
assert(opts->list->desc[0].name == NULL); assert(opts->list->desc[0].name == NULL);
@ -1068,7 +1063,10 @@ int qemu_opts_validate(QemuOpts *opts, const QemuOptDesc *desc)
opt->desc = &desc[i]; opt->desc = &desc[i];
if (qemu_opt_parse(opt) < 0) { qemu_opt_parse(opt, &local_err);
if (error_is_set(&local_err)) {
qerror_report_err(local_err);
error_free(local_err);
return -1; return -1;
} }
} }