diff options
author | Markus Armbruster <armbru@redhat.com> | 2015-03-13 11:07:24 +0100 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2015-06-08 19:33:20 +0200 |
commit | a4c7367f7dd9348f94dc4298571ed515b8160a27 (patch) | |
tree | c2b07e89034639213052178832ed3b1e24bb4ac7 | |
parent | 8122928a52248e28513c79d9b9929c6d20c866ea (diff) | |
download | qemu-a4c7367f7dd9348f94dc4298571ed515b8160a27.zip qemu-a4c7367f7dd9348f94dc4298571ed515b8160a27.tar.gz qemu-a4c7367f7dd9348f94dc4298571ed515b8160a27.tar.bz2 |
QemuOpts: Drop qemu_opts_foreach() parameter abort_on_failure
When the argument is non-zero, qemu_opts_foreach() stops on callback
returning non-zero, and returns that value.
When the argument is zero, it doesn't stop, and returns the bit-wise
inclusive or of all the return values. Funky :)
The callers that pass zero could just as well pass one, because their
callbacks can't return anything but zero:
* qemu_add_globals()'s callback qdev_add_one_global()
* qemu_config_write()'s callback config_write_opts()
* main()'s callbacks default_driver_check(), drive_enable_snapshot(),
vnc_init_func()
Drop the parameter, and always stop.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Acked-by: Kevin Wolf <kwolf@redhat.com>
-rw-r--r-- | block/blkdebug.c | 4 | ||||
-rw-r--r-- | hw/core/qdev-properties-system.c | 2 | ||||
-rw-r--r-- | include/qemu/option.h | 4 | ||||
-rw-r--r-- | net/net.c | 5 | ||||
-rw-r--r-- | net/vhost-user.c | 2 | ||||
-rw-r--r-- | numa.c | 3 | ||||
-rw-r--r-- | tpm.c | 3 | ||||
-rw-r--r-- | util/qemu-config.c | 2 | ||||
-rw-r--r-- | util/qemu-option.c | 21 | ||||
-rw-r--r-- | vl.c | 35 |
10 files changed, 44 insertions, 37 deletions
diff --git a/block/blkdebug.c b/block/blkdebug.c index 3c30edb..58f5105 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 c413226..93daeb0 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 f88b545..2edf58f 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); @@ -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 8d26728..f1a15ce 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; } @@ -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); } @@ -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 30d6dcf..b38927a 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 fda4e5f..7672aae 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) @@ -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); |