From patchwork Wed Jun 3 09:17:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 479818 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 64382140280 for ; Wed, 3 Jun 2015 19:18:55 +1000 (AEST) Received: from localhost ([::1]:34135 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z04p3-000119-9K for incoming@patchwork.ozlabs.org; Wed, 03 Jun 2015 05:18:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48879) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z04oJ-00082H-0V for qemu-devel@nongnu.org; Wed, 03 Jun 2015 05:18:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z04oD-0007P9-Vz for qemu-devel@nongnu.org; Wed, 03 Jun 2015 05:18:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59149) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z04oD-0007Os-Os for qemu-devel@nongnu.org; Wed, 03 Jun 2015 05:18:01 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 791988F27A for ; Wed, 3 Jun 2015 09:18:01 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-58.ams2.redhat.com [10.36.116.58]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t539HxCn014368 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 3 Jun 2015 05:18:00 -0400 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 20E09304602D; Wed, 3 Jun 2015 11:17:57 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Wed, 3 Jun 2015 11:17:55 +0200 Message-Id: <1433323076-9264-9-git-send-email-armbru@redhat.com> In-Reply-To: <1433323076-9264-1-git-send-email-armbru@redhat.com> References: <1433323076-9264-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, pbonzini@redhat.com Subject: [Qemu-devel] [PATCH v2 8/9] QemuOpts: Convert qemu_opt_foreach() to Error X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Retain the function value for now, to permit selective conversion of its callers. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- include/qemu/option.h | 7 +++++-- net/vhost-user.c | 7 ++++--- qdev-monitor.c | 5 +++-- ui/spice-core.c | 5 +++-- util/qemu-config.c | 5 +++-- util/qemu-option.c | 9 ++++++--- vl.c | 9 +++++---- 7 files changed, 29 insertions(+), 18 deletions(-) diff --git a/include/qemu/option.h b/include/qemu/option.h index a3cf4c1..ac0e43b 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -100,8 +100,11 @@ void qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val, Error **errp); void qemu_opt_set_number(QemuOpts *opts, const char *name, int64_t val, Error **errp); -typedef int (*qemu_opt_loopfunc)(const char *name, const char *value, void *opaque); -int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque); +typedef int (*qemu_opt_loopfunc)(void *opaque, + const char *name, const char *value, + Error **errp); +int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque, + Error **errp); QemuOpts *qemu_opts_find(QemuOptsList *list, const char *id); QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id, diff --git a/net/vhost-user.c b/net/vhost-user.c index 167082e..7e8a9ec 100644 --- a/net/vhost-user.c +++ b/net/vhost-user.c @@ -157,8 +157,9 @@ static int net_vhost_user_init(NetClientState *peer, const char *device, return 0; } -static int net_vhost_chardev_opts(const char *name, const char *value, - void *opaque) +static int net_vhost_chardev_opts(void *opaque, + const char *name, const char *value, + Error **errp) { VhostUserChardevProps *props = opaque; @@ -189,7 +190,7 @@ static CharDriverState *net_vhost_parse_chardev(const NetdevVhostUserOptions *op /* inspect chardev opts */ memset(&props, 0, sizeof(props)); - if (qemu_opt_foreach(chr->opts, net_vhost_chardev_opts, &props)) { + if (qemu_opt_foreach(chr->opts, net_vhost_chardev_opts, &props, NULL)) { return NULL; } diff --git a/qdev-monitor.c b/qdev-monitor.c index da2cbc9..dc56082 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -143,7 +143,8 @@ static void qdev_print_devinfos(bool show_no_user) g_slist_free(list); } -static int set_property(const char *name, const char *value, void *opaque) +static int set_property(void *opaque, const char *name, const char *value, + Error **errp) { Object *obj = opaque; Error *err = NULL; @@ -564,7 +565,7 @@ DeviceState *qdev_device_add(QemuOpts *opts) } /* set properties */ - if (qemu_opt_foreach(opts, set_property, dev)) { + if (qemu_opt_foreach(opts, set_property, dev, NULL)) { object_unparent(OBJECT(dev)); object_unref(OBJECT(dev)); return NULL; diff --git a/ui/spice-core.c b/ui/spice-core.c index 60818d9..a30da3c 100644 --- a/ui/spice-core.c +++ b/ui/spice-core.c @@ -583,7 +583,8 @@ int qemu_spice_migrate_info(const char *hostname, int port, int tls_port, return ret; } -static int add_channel(const char *name, const char *value, void *opaque) +static int add_channel(void *opaque, const char *name, const char *value, + Error **errp) { int security = 0; int rc; @@ -782,7 +783,7 @@ void qemu_spice_init(void) spice_server_set_playback_compression (spice_server, qemu_opt_get_bool(opts, "playback-compression", 1)); - qemu_opt_foreach(opts, add_channel, &tls_port); + qemu_opt_foreach(opts, add_channel, &tls_port, NULL); spice_server_set_name(spice_server, qemu_name); spice_server_set_uuid(spice_server, qemu_uuid); diff --git a/util/qemu-config.c b/util/qemu-config.c index aff4cb3..35adfda 100644 --- a/util/qemu-config.c +++ b/util/qemu-config.c @@ -335,7 +335,8 @@ struct ConfigWriteData { FILE *fp; }; -static int config_write_opt(const char *name, const char *value, void *opaque) +static int config_write_opt(void *opaque, const char *name, const char *value, + Error **errp) { struct ConfigWriteData *data = opaque; @@ -353,7 +354,7 @@ static int config_write_opts(void *opaque, QemuOpts *opts, Error **errp) } else { fprintf(data->fp, "[%s]\n", data->list->name); } - qemu_opt_foreach(opts, config_write_opt, data); + qemu_opt_foreach(opts, config_write_opt, data, NULL); fprintf(data->fp, "\n"); return 0; } diff --git a/util/qemu-option.c b/util/qemu-option.c index 296e2b3..840f5f7 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -597,20 +597,23 @@ void qemu_opt_set_number(QemuOpts *opts, const char *name, int64_t val, } /** - * For each member of @opts, call @func(name, value, @opaque). + * For each member of @opts, call @func(@opaque, name, value, @errp). + * @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_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque) +int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque, + Error **errp) { QemuOpt *opt; int rc; QTAILQ_FOREACH(opt, &opts->head, next) { - rc = func(opt->name, opt->str, opaque); + rc = func(opaque, opt->name, opt->str, errp); if (rc) { return rc; } + assert(!errp || !*errp); } return 0; } diff --git a/vl.c b/vl.c index 2495f0e..5e37602 100644 --- a/vl.c +++ b/vl.c @@ -2565,8 +2565,9 @@ static void free_and_trace(gpointer mem) free(mem); } -static int machine_set_property(const char *name, const char *value, - void *opaque) +static int machine_set_property(void *opaque, + const char *name, const char *value, + Error **errp) { Object *obj = OBJECT(opaque); Error *local_err = NULL; @@ -4059,8 +4060,8 @@ int main(int argc, char **argv, char **envp) } machine_opts = qemu_get_machine_opts(); - if (qemu_opt_foreach(machine_opts, machine_set_property, - current_machine)) { + if (qemu_opt_foreach(machine_opts, machine_set_property, current_machine, + NULL)) { object_unref(OBJECT(current_machine)); exit(1); }