aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--block/blkdebug.c4
-rw-r--r--hw/core/qdev-properties-system.c2
-rw-r--r--include/qemu/option.h4
-rw-r--r--net/net.c5
-rw-r--r--net/vhost-user.c2
-rw-r--r--numa.c3
-rw-r--r--tpm.c3
-rw-r--r--util/qemu-config.c2
-rw-r--r--util/qemu-option.c21
-rw-r--r--vl.c35
10 files changed, 44 insertions, 37 deletions
diff --git a/block/blkdebug.c b/block/blkdebug.c
index 3c30edba73..58f5105cc8 100644
--- a/block/blkdebug.c
+++ b/block/blkdebug.c
@@ -320,7 +320,7 @@ static int read_config(BDRVBlkdebugState *s, const char *filename,
d.s = s;
d.action = ACTION_INJECT_ERROR;
d.errp = &local_err;
- qemu_opts_foreach(&inject_error_opts, add_rule, &d, 1);
+ qemu_opts_foreach(&inject_error_opts, add_rule, &d);
if (local_err) {
error_propagate(errp, local_err);
ret = -EINVAL;
@@ -328,7 +328,7 @@ static int read_config(BDRVBlkdebugState *s, const char *filename,
}
d.action = ACTION_SET_STATE;
- qemu_opts_foreach(&set_state_opts, add_rule, &d, 1);
+ qemu_opts_foreach(&set_state_opts, add_rule, &d);
if (local_err) {
error_propagate(errp, local_err);
ret = -EINVAL;
diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c
index c413226a97..93daeb07c2 100644
--- a/hw/core/qdev-properties-system.c
+++ b/hw/core/qdev-properties-system.c
@@ -404,5 +404,5 @@ static int qdev_add_one_global(QemuOpts *opts, void *opaque)
void qemu_add_globals(void)
{
- qemu_opts_foreach(qemu_find_opts("global"), qdev_add_one_global, NULL, 0);
+ qemu_opts_foreach(qemu_find_opts("global"), qdev_add_one_global, NULL);
}
diff --git a/include/qemu/option.h b/include/qemu/option.h
index f88b545dfc..2edf58f61f 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -126,9 +126,9 @@ QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict *qdict);
void qemu_opts_absorb_qdict(QemuOpts *opts, QDict *qdict, Error **errp);
typedef int (*qemu_opts_loopfunc)(QemuOpts *opts, void *opaque);
+int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func,
+ void *opaque);
void qemu_opts_print(QemuOpts *opts, const char *sep);
-int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque,
- int abort_on_failure);
void qemu_opts_print_help(QemuOptsList *list);
void qemu_opts_free(QemuOptsList *list);
QemuOptsList *qemu_opts_append(QemuOptsList *dst, QemuOptsList *list);
diff --git a/net/net.c b/net/net.c
index db6be12a1e..011de593e9 100644
--- a/net/net.c
+++ b/net/net.c
@@ -1373,10 +1373,11 @@ int net_init_clients(void)
QTAILQ_INIT(&net_clients);
- if (qemu_opts_foreach(qemu_find_opts("netdev"), net_init_netdev, NULL, 1) == -1)
+ if (qemu_opts_foreach(qemu_find_opts("netdev"), net_init_netdev, NULL)) {
return -1;
+ }
- if (qemu_opts_foreach(net, net_init_client, NULL, 1) == -1) {
+ if (qemu_opts_foreach(net, net_init_client, NULL)) {
return -1;
}
diff --git a/net/vhost-user.c b/net/vhost-user.c
index 8d2672846f..f1a15ceb61 100644
--- a/net/vhost-user.c
+++ b/net/vhost-user.c
@@ -245,7 +245,7 @@ int net_init_vhost_user(const NetClientOptions *opts, const char *name,
/* verify net frontend */
if (qemu_opts_foreach(qemu_find_opts("device"), net_vhost_check_net,
- (char *)name, true) == -1) {
+ (char *)name)) {
return -1;
}
diff --git a/numa.c b/numa.c
index c975fb2682..360a595621 100644
--- a/numa.c
+++ b/numa.c
@@ -216,8 +216,7 @@ void parse_numa_opts(MachineClass *mc)
{
int i;
- if (qemu_opts_foreach(qemu_find_opts("numa"), parse_numa,
- NULL, 1) != 0) {
+ if (qemu_opts_foreach(qemu_find_opts("numa"), parse_numa, NULL)) {
exit(1);
}
diff --git a/tpm.c b/tpm.c
index 963b7ee0d8..bca3b3a98f 100644
--- a/tpm.c
+++ b/tpm.c
@@ -207,8 +207,7 @@ void tpm_cleanup(void)
*/
int tpm_init(void)
{
- if (qemu_opts_foreach(qemu_find_opts("tpmdev"),
- tpm_init_tpmdev, NULL, 1) != 0) {
+ if (qemu_opts_foreach(qemu_find_opts("tpmdev"), tpm_init_tpmdev, NULL)) {
return -1;
}
diff --git a/util/qemu-config.c b/util/qemu-config.c
index 30d6dcf526..b38927a88d 100644
--- a/util/qemu-config.c
+++ b/util/qemu-config.c
@@ -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, 0);
+ qemu_opts_foreach(data.list, config_write_opts, &data);
}
}
diff --git a/util/qemu-option.c b/util/qemu-option.c
index fda4e5fcbf..7672aae897 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -1046,22 +1046,29 @@ void qemu_opts_validate(QemuOpts *opts, const QemuOptDesc *desc, Error **errp)
}
}
-int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque,
- int abort_on_failure)
+/**
+ * For each member of @list, call @func(member, @opaque).
+ * Call it with the current location temporarily set to the member's.
+ * 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)
{
Location loc;
QemuOpts *opts;
- int rc = 0;
+ int rc;
loc_push_none(&loc);
QTAILQ_FOREACH(opts, &list->head, next) {
loc_restore(&opts->loc);
- rc |= func(opts, opaque);
- if (abort_on_failure && rc != 0)
- break;
+ rc = func(opts, opaque);
+ if (rc) {
+ return rc;
+ }
}
loc_pop(&loc);
- return rc;
+ return 0;
}
static size_t count_opts_list(QemuOptsList *list)
diff --git a/vl.c b/vl.c
index c9c3f33ce7..f360e11e93 100644
--- a/vl.c
+++ b/vl.c
@@ -3797,20 +3797,20 @@ int main(int argc, char **argv, char **envp)
exit(1);
}
- if (qemu_opts_foreach(qemu_find_opts("sandbox"), parse_sandbox, NULL, 1)) {
+ if (qemu_opts_foreach(qemu_find_opts("sandbox"), parse_sandbox, NULL)) {
exit(1);
}
- if (qemu_opts_foreach(qemu_find_opts("name"), parse_name, NULL, 1)) {
+ if (qemu_opts_foreach(qemu_find_opts("name"), parse_name, NULL)) {
exit(1);
}
#ifndef _WIN32
- if (qemu_opts_foreach(qemu_find_opts("add-fd"), parse_add_fd, NULL, 1)) {
+ if (qemu_opts_foreach(qemu_find_opts("add-fd"), parse_add_fd, NULL)) {
exit(1);
}
- if (qemu_opts_foreach(qemu_find_opts("add-fd"), cleanup_add_fd, NULL, 1)) {
+ if (qemu_opts_foreach(qemu_find_opts("add-fd"), cleanup_add_fd, NULL)) {
exit(1);
}
#endif
@@ -3897,8 +3897,8 @@ int main(int argc, char **argv, char **envp)
machine_class->default_machine_opts, 0);
}
- qemu_opts_foreach(qemu_find_opts("device"), default_driver_check, NULL, 0);
- qemu_opts_foreach(qemu_find_opts("global"), default_driver_check, NULL, 0);
+ qemu_opts_foreach(qemu_find_opts("device"), default_driver_check, NULL);
+ qemu_opts_foreach(qemu_find_opts("global"), default_driver_check, NULL);
if (!vga_model && !default_vga) {
vga_interface_type = VGA_DEVICE;
@@ -4036,10 +4036,12 @@ int main(int argc, char **argv, char **envp)
socket_init();
- if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func, NULL, 1) != 0)
+ if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func, NULL)) {
exit(1);
+ }
+
#ifdef CONFIG_VIRTFS
- if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func, NULL, 1) != 0) {
+ if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func, NULL)) {
exit(1);
}
#endif
@@ -4049,13 +4051,11 @@ int main(int argc, char **argv, char **envp)
exit(1);
}
- if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func, NULL, 1)
- != 0) {
+ if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func, NULL)) {
exit(0);
}
- if (qemu_opts_foreach(qemu_find_opts("object"),
- object_create, NULL, 1) != 0) {
+ if (qemu_opts_foreach(qemu_find_opts("object"), object_create, NULL)) {
exit(1);
}
@@ -4189,9 +4189,9 @@ int main(int argc, char **argv, char **envp)
/* open the virtual block devices */
if (snapshot)
- qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot, NULL, 0);
+ qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot, NULL);
if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func,
- &machine_class->block_default_type, 1) != 0) {
+ &machine_class->block_default_type)) {
exit(1);
}
@@ -4202,7 +4202,7 @@ int main(int argc, char **argv, char **envp)
parse_numa_opts(machine_class);
- if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func, NULL, 1) != 0) {
+ if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func, NULL)) {
exit(1);
}
@@ -4268,8 +4268,9 @@ int main(int argc, char **argv, char **envp)
}
/* init generic devices */
- if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, 1) != 0)
+ if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL)) {
exit(1);
+ }
/* Did we create any drives that we failed to create a device for? */
drive_check_orphaned();
@@ -4321,7 +4322,7 @@ int main(int argc, char **argv, char **envp)
#ifdef CONFIG_VNC
/* init remote displays */
- qemu_opts_foreach(qemu_find_opts("vnc"), vnc_init_func, NULL, 0);
+ qemu_opts_foreach(qemu_find_opts("vnc"), vnc_init_func, NULL);
if (show_vnc_port) {
char *ret = vnc_display_local_addr("default");
printf("VNC server running on `%s'\n", ret);