From 28d0de7a4fb721b06de72970bd163f5183c2188b Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Fri, 13 Mar 2015 13:35:14 +0100 Subject: QemuOpts: Convert qemu_opts_foreach() to Error Retain the function value for now, to permit selective conversion of its callers. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Acked-by: Kevin Wolf --- util/qemu-config.c | 4 ++-- util/qemu-option.c | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'util') diff --git a/util/qemu-config.c b/util/qemu-config.c index b38927a..a88461f 100644 --- a/util/qemu-config.c +++ b/util/qemu-config.c @@ -343,7 +343,7 @@ static int config_write_opt(const char *name, const char *value, void *opaque) return 0; } -static int config_write_opts(QemuOpts *opts, void *opaque) +static int config_write_opts(void *opaque, QemuOpts *opts, Error **errp) { struct ConfigWriteData *data = opaque; const char *id = qemu_opts_id(opts); @@ -367,7 +367,7 @@ void qemu_config_write(FILE *fp) fprintf(fp, "# qemu config file\n\n"); for (i = 0; lists[i] != NULL; i++) { data.list = lists[i]; - qemu_opts_foreach(data.list, config_write_opts, &data); + qemu_opts_foreach(data.list, config_write_opts, &data, NULL); } } diff --git a/util/qemu-option.c b/util/qemu-option.c index 7672aae..07b03e3 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -1047,13 +1047,14 @@ void qemu_opts_validate(QemuOpts *opts, const QemuOptDesc *desc, Error **errp) } /** - * For each member of @list, call @func(member, @opaque). + * For each member of @list, call @func(@opaque, member, @errp). * Call it with the current location temporarily set to the member's. + * @func() may store an Error through @errp, but must return non-zero then. * When @func() returns non-zero, break the loop and return that value. * Return zero when the loop completes. */ int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, - void *opaque) + void *opaque, Error **errp) { Location loc; QemuOpts *opts; @@ -1062,10 +1063,11 @@ int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, loc_push_none(&loc); QTAILQ_FOREACH(opts, &list->head, next) { loc_restore(&opts->loc); - rc = func(opts, opaque); + rc = func(opaque, opts, errp); if (rc) { return rc; } + assert(!errp || !*errp); } loc_pop(&loc); return 0; -- cgit v1.1