qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL v2 7/9] QemuOpts: Drop qemu_opt_foreach() parameter abort_on_failure
Date: Tue,  9 Jun 2015 07:47:54 +0200	[thread overview]
Message-ID: <1433828876-10892-8-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1433828876-10892-1-git-send-email-armbru@redhat.com>

When the argument is non-zero, qemu_opt_foreach() stops on callback
returning non-zero, and returns that value.

When the argument is zero, it doesn't stop, and returns the callback's
value from the last iteration.

The two callers that pass zero could just as well pass one:

* qemu_spice_init()'s callback add_channel() either returns zero or
  exit()s.

* config_write_opts()'s callback config_write_opt() always returns
  zero.

Drop the parameter, and always stop.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
 include/qemu/option.h |  3 +--
 net/vhost-user.c      |  2 +-
 qdev-monitor.c        |  2 +-
 ui/spice-core.c       |  2 +-
 util/qemu-config.c    |  2 +-
 util/qemu-option.c    | 17 +++++++++++------
 vl.c                  |  4 ++--
 7 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/include/qemu/option.h b/include/qemu/option.h
index a3850b2..a3cf4c1 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -101,8 +101,7 @@ void qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val,
 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,
-                     int abort_on_failure);
+int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque);
 
 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 cce168a..167082e 100644
--- a/net/vhost-user.c
+++ b/net/vhost-user.c
@@ -189,7 +189,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, true) != 0) {
+    if (qemu_opt_foreach(chr->opts, net_vhost_chardev_opts, &props)) {
         return NULL;
     }
 
diff --git a/qdev-monitor.c b/qdev-monitor.c
index 9f17c81..b7a2150 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -564,7 +564,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)
     }
 
     /* set properties */
-    if (qemu_opt_foreach(opts, set_property, dev, 1) != 0) {
+    if (qemu_opt_foreach(opts, set_property, dev)) {
         object_unparent(OBJECT(dev));
         object_unref(OBJECT(dev));
         return NULL;
diff --git a/ui/spice-core.c b/ui/spice-core.c
index 2e8384e..60818d9 100644
--- a/ui/spice-core.c
+++ b/ui/spice-core.c
@@ -782,7 +782,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, 0);
+    qemu_opt_foreach(opts, add_channel, &tls_port);
 
     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 a88461f..aff4cb3 100644
--- a/util/qemu-config.c
+++ b/util/qemu-config.c
@@ -353,7 +353,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, 0);
+    qemu_opt_foreach(opts, config_write_opt, data);
     fprintf(data->fp, "\n");
     return 0;
 }
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 07b03e3..296e2b3 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -596,18 +596,23 @@ void qemu_opt_set_number(QemuOpts *opts, const char *name, int64_t val,
     QTAILQ_INSERT_TAIL(&opts->head, opt, next);
 }
 
-int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque,
-                     int abort_on_failure)
+/**
+ * For each member of @opts, call @func(name, value, @opaque).
+ * 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)
 {
     QemuOpt *opt;
-    int rc = 0;
+    int rc;
 
     QTAILQ_FOREACH(opt, &opts->head, next) {
         rc = func(opt->name, opt->str, opaque);
-        if (abort_on_failure  &&  rc != 0)
-            break;
+        if (rc) {
+            return rc;
+        }
     }
-    return rc;
+    return 0;
 }
 
 QemuOpts *qemu_opts_find(QemuOptsList *list, const char *id)
diff --git a/vl.c b/vl.c
index b3c1722..b12e6ff 100644
--- a/vl.c
+++ b/vl.c
@@ -4070,8 +4070,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,
-                         1) < 0) {
+    if (qemu_opt_foreach(machine_opts, machine_set_property,
+                         current_machine)) {
         object_unref(OBJECT(current_machine));
         exit(1);
     }
-- 
1.9.3

  parent reply	other threads:[~2015-06-09  5:48 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-09  5:47 [Qemu-devel] [PULL v2 0/9] Error reporting patches Markus Armbruster
2015-06-09  5:47 ` [Qemu-devel] [PULL v2 1/9] vl: Report failure to sandbox at most once Markus Armbruster
2015-06-09  5:47 ` [Qemu-devel] [PULL v2 2/9] vl: Print -device help " Markus Armbruster
2015-06-09  5:47 ` [Qemu-devel] [PULL v2 3/9] vl: Fail right after first bad -object Markus Armbruster
2015-06-09  5:47 ` [Qemu-devel] [PULL v2 4/9] QemuOpts: Drop qemu_opts_foreach() parameter abort_on_failure Markus Armbruster
2015-06-09  5:47 ` [Qemu-devel] [PULL v2 5/9] QemuOpts: Convert qemu_opts_foreach() to Error Markus Armbruster
2015-06-09  5:47 ` [Qemu-devel] [PULL v2 6/9] blkdebug: Simplify passing of Error through qemu_opts_foreach() Markus Armbruster
2015-06-09  5:47 ` Markus Armbruster [this message]
2015-06-09  5:47 ` [Qemu-devel] [PULL v2 8/9] QemuOpts: Convert qemu_opt_foreach() to Error Markus Armbruster
2015-06-09  5:47 ` [Qemu-devel] [PULL v2 9/9] vhost-user: Improve -netdev/netdev_add/-net/... error reporting Markus Armbruster
2015-06-09 10:07 ` [Qemu-devel] [PULL v2 0/9] Error reporting patches Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1433828876-10892-8-git-send-email-armbru@redhat.com \
    --to=armbru@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).