From 092b21aa7edf7962248e731cddaf5350d268e333 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Fri, 13 Mar 2015 12:59:43 +0100 Subject: vl: Report failure to sandbox at most once It's reported once per -sandbox on. Stop on the first failure, like we do for other options. Not fixed: "-sandbox on -sandbox off" should leave the sandbox off. It doesn't. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- vl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'vl.c') diff --git a/vl.c b/vl.c index 66ccd06..dd56a82 100644 --- a/vl.c +++ b/vl.c @@ -3797,7 +3797,7 @@ int main(int argc, char **argv, char **envp) exit(1); } - if (qemu_opts_foreach(qemu_find_opts("sandbox"), parse_sandbox, NULL, 0)) { + if (qemu_opts_foreach(qemu_find_opts("sandbox"), parse_sandbox, NULL, 1)) { exit(1); } -- cgit v1.1 From 8416abb3b0f42132fc6346c439ec543635075135 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Fri, 13 Mar 2015 13:02:03 +0100 Subject: vl: Print -device help at most once We print it once for each -device help. Not helpful. Stop after the first one. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- vl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'vl.c') diff --git a/vl.c b/vl.c index dd56a82..680f4d8 100644 --- a/vl.c +++ b/vl.c @@ -4049,7 +4049,7 @@ int main(int argc, char **argv, char **envp) exit(1); } - if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func, NULL, 0) + if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func, NULL, 1) != 0) { exit(0); } -- cgit v1.1 From 8122928a52248e28513c79d9b9929c6d20c866ea Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Fri, 13 Mar 2015 13:08:36 +0100 Subject: vl: Fail right after first bad -object Failure to create an object with -object is a fatal error. However, we delay the actual exit until all -object are processed. On the one hand, this permits detection of genuine additional errors. On the other hand, it can muddy the waters with uninteresting additional errors, e.g. when a later -object tries to reference a prior one that failed. We generally stop right on the first bad option, so do that for -object as well. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- vl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'vl.c') diff --git a/vl.c b/vl.c index 680f4d8..c9c3f33 100644 --- a/vl.c +++ b/vl.c @@ -4055,7 +4055,7 @@ int main(int argc, char **argv, char **envp) } if (qemu_opts_foreach(qemu_find_opts("object"), - object_create, NULL, 0) != 0) { + object_create, NULL, 1) != 0) { exit(1); } -- cgit v1.1 From a4c7367f7dd9348f94dc4298571ed515b8160a27 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Fri, 13 Mar 2015 11:07:24 +0100 Subject: 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 Reviewed-by: Eric Blake Acked-by: Kevin Wolf --- vl.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'vl.c') diff --git a/vl.c b/vl.c index c9c3f33..f360e11 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); -- cgit v1.1 From 28d0de7a4fb721b06de72970bd163f5183c2188b Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Fri, 13 Mar 2015 13:35:14 +0100 Subject: QemuOpts: Convert qemu_opts_foreach() to Error Retain the function value for now, to permit selective conversion of its callers. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Acked-by: Kevin Wolf --- vl.c | 72 +++++++++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 43 insertions(+), 29 deletions(-) (limited to 'vl.c') diff --git a/vl.c b/vl.c index f360e11..b3c1722 100644 --- a/vl.c +++ b/vl.c @@ -515,7 +515,7 @@ static void res_free(void) } } -static int default_driver_check(QemuOpts *opts, void *opaque) +static int default_driver_check(void *opaque, QemuOpts *opts, Error **errp) { const char *driver = qemu_opt_get(opts, "driver"); int i; @@ -961,7 +961,7 @@ static int bt_parse(const char *opt) return 1; } -static int parse_sandbox(QemuOpts *opts, void *opaque) +static int parse_sandbox(void *opaque, QemuOpts *opts, Error **errp) { /* FIXME: change this to true for 1.3 */ if (qemu_opt_get_bool(opts, "enable", false)) { @@ -981,7 +981,7 @@ static int parse_sandbox(QemuOpts *opts, void *opaque) return 0; } -static int parse_name(QemuOpts *opts, void *opaque) +static int parse_name(void *opaque, QemuOpts *opts, Error **errp) { const char *proc_name; @@ -1009,7 +1009,7 @@ bool usb_enabled(void) } #ifndef _WIN32 -static int parse_add_fd(QemuOpts *opts, void *opaque) +static int parse_add_fd(void *opaque, QemuOpts *opts, Error **errp) { int fd, dupfd, flags; int64_t fdset_id; @@ -1071,7 +1071,7 @@ static int parse_add_fd(QemuOpts *opts, void *opaque) return 0; } -static int cleanup_add_fd(QemuOpts *opts, void *opaque) +static int cleanup_add_fd(void *opaque, QemuOpts *opts, Error **errp) { int fd; @@ -1092,14 +1092,14 @@ static int cleanup_add_fd(QemuOpts *opts, void *opaque) #define MTD_OPTS "" #define SD_OPTS "" -static int drive_init_func(QemuOpts *opts, void *opaque) +static int drive_init_func(void *opaque, QemuOpts *opts, Error **errp) { BlockInterfaceType *block_default_type = opaque; return drive_new(opts, *block_default_type) == NULL; } -static int drive_enable_snapshot(QemuOpts *opts, void *opaque) +static int drive_enable_snapshot(void *opaque, QemuOpts *opts, Error **errp) { if (qemu_opt_get(opts, "snapshot") == NULL) { qemu_opt_set(opts, "snapshot", "on", &error_abort); @@ -1119,7 +1119,7 @@ static void default_drive(int enable, int snapshot, BlockInterfaceType type, opts = drive_add(type, index, NULL, optstr); if (snapshot) { - drive_enable_snapshot(opts, NULL); + drive_enable_snapshot(NULL, opts, NULL); } dinfo = drive_new(opts, type); @@ -2127,12 +2127,12 @@ char *qemu_find_file(int type, const char *name) return NULL; } -static int device_help_func(QemuOpts *opts, void *opaque) +static int device_help_func(void *opaque, QemuOpts *opts, Error **errp) { return qdev_device_help(opts); } -static int device_init_func(QemuOpts *opts, void *opaque) +static int device_init_func(void *opaque, QemuOpts *opts, Error **errp) { DeviceState *dev; @@ -2143,7 +2143,7 @@ static int device_init_func(QemuOpts *opts, void *opaque) return 0; } -static int chardev_init_func(QemuOpts *opts, void *opaque) +static int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp) { Error *local_err = NULL; @@ -2156,7 +2156,7 @@ static int chardev_init_func(QemuOpts *opts, void *opaque) } #ifdef CONFIG_VIRTFS -static int fsdev_init_func(QemuOpts *opts, void *opaque) +static int fsdev_init_func(void *opaque, QemuOpts *opts, Error **errp) { int ret; ret = qemu_fsdev_add(opts); @@ -2165,7 +2165,7 @@ static int fsdev_init_func(QemuOpts *opts, void *opaque) } #endif -static int mon_init_func(QemuOpts *opts, void *opaque) +static int mon_init_func(void *opaque, QemuOpts *opts, Error **errp) { CharDriverState *chr; const char *chardev; @@ -2606,7 +2606,7 @@ static int machine_set_property(const char *name, const char *value, return 0; } -static int object_create(QemuOpts *opts, void *opaque) +static int object_create(void *opaque, QemuOpts *opts, Error **errp) { Error *err = NULL; char *type = NULL; @@ -3797,20 +3797,24 @@ int main(int argc, char **argv, char **envp) exit(1); } - if (qemu_opts_foreach(qemu_find_opts("sandbox"), parse_sandbox, NULL)) { + if (qemu_opts_foreach(qemu_find_opts("sandbox"), + parse_sandbox, NULL, NULL)) { exit(1); } - if (qemu_opts_foreach(qemu_find_opts("name"), parse_name, NULL)) { + if (qemu_opts_foreach(qemu_find_opts("name"), + parse_name, NULL, NULL)) { exit(1); } #ifndef _WIN32 - if (qemu_opts_foreach(qemu_find_opts("add-fd"), parse_add_fd, NULL)) { + if (qemu_opts_foreach(qemu_find_opts("add-fd"), + parse_add_fd, NULL, NULL)) { exit(1); } - if (qemu_opts_foreach(qemu_find_opts("add-fd"), cleanup_add_fd, NULL)) { + if (qemu_opts_foreach(qemu_find_opts("add-fd"), + cleanup_add_fd, NULL, NULL)) { exit(1); } #endif @@ -3897,8 +3901,10 @@ 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); - qemu_opts_foreach(qemu_find_opts("global"), default_driver_check, NULL); + qemu_opts_foreach(qemu_find_opts("device"), + default_driver_check, NULL, NULL); + qemu_opts_foreach(qemu_find_opts("global"), + default_driver_check, NULL, NULL); if (!vga_model && !default_vga) { vga_interface_type = VGA_DEVICE; @@ -4036,12 +4042,14 @@ int main(int argc, char **argv, char **envp) socket_init(); - if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func, NULL)) { + if (qemu_opts_foreach(qemu_find_opts("chardev"), + chardev_init_func, NULL, NULL)) { exit(1); } #ifdef CONFIG_VIRTFS - if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func, NULL)) { + if (qemu_opts_foreach(qemu_find_opts("fsdev"), + fsdev_init_func, NULL, NULL)) { exit(1); } #endif @@ -4051,11 +4059,13 @@ int main(int argc, char **argv, char **envp) exit(1); } - if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func, NULL)) { + if (qemu_opts_foreach(qemu_find_opts("device"), + device_help_func, NULL, NULL)) { exit(0); } - if (qemu_opts_foreach(qemu_find_opts("object"), object_create, NULL)) { + if (qemu_opts_foreach(qemu_find_opts("object"), + object_create, NULL, NULL)) { exit(1); } @@ -4189,9 +4199,10 @@ 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); + qemu_opts_foreach(qemu_find_opts("drive"), + drive_enable_snapshot, NULL, NULL); if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func, - &machine_class->block_default_type)) { + &machine_class->block_default_type, NULL)) { exit(1); } @@ -4202,7 +4213,8 @@ 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)) { + if (qemu_opts_foreach(qemu_find_opts("mon"), + mon_init_func, NULL, NULL)) { exit(1); } @@ -4268,7 +4280,8 @@ int main(int argc, char **argv, char **envp) } /* init generic devices */ - if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL)) { + if (qemu_opts_foreach(qemu_find_opts("device"), + device_init_func, NULL, NULL)) { exit(1); } @@ -4322,7 +4335,8 @@ 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); + qemu_opts_foreach(qemu_find_opts("vnc"), + vnc_init_func, NULL, NULL); if (show_vnc_port) { char *ret = vnc_display_local_addr("default"); printf("VNC server running on `%s'\n", ret); -- cgit v1.1 From 1640b200d53e3d981f12a192fe84b7bb7958c065 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 12 Mar 2015 07:45:10 +0100 Subject: QemuOpts: Drop qemu_opt_foreach() parameter abort_on_failure 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 Reviewed-by: Eric Blake --- vl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'vl.c') 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); } -- cgit v1.1 From 71df1d833776647fc12f5bbcd6d6fe4c5e931094 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 12 Mar 2015 08:40:25 +0100 Subject: QemuOpts: Convert qemu_opt_foreach() to Error Retain the function value for now, to permit selective conversion of its callers. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- vl.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'vl.c') diff --git a/vl.c b/vl.c index b12e6ff..d4b2d03 100644 --- a/vl.c +++ b/vl.c @@ -2576,8 +2576,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; @@ -4070,8 +4071,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); } -- cgit v1.1