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>
This commit is contained in:
Markus Armbruster 2015-03-13 11:07:24 +01:00
parent 8122928a52
commit a4c7367f7d
10 changed files with 44 additions and 37 deletions

View file

@ -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;

View file

@ -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);
}

View file

@ -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);

View file

@ -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;
}

View file

@ -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;
}

3
numa.c
View file

@ -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);
}

3
tpm.c
View file

@ -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;
}

View file

@ -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);
}
}

View file

@ -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)

35
vl.c
View file

@ -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);