diff options
-rw-r--r-- | blockdev.c | 2 | ||||
-rw-r--r-- | hmp.c | 2 | ||||
-rw-r--r-- | hw/usb/dev-network.c | 2 | ||||
-rw-r--r-- | include/qemu/option.h | 5 | ||||
-rw-r--r-- | include/ui/console.h | 2 | ||||
-rw-r--r-- | monitor.c | 2 | ||||
-rw-r--r-- | net/net.c | 5 | ||||
-rw-r--r-- | qdev-monitor.c | 2 | ||||
-rw-r--r-- | qemu-img.c | 3 | ||||
-rw-r--r-- | qemu-io.c | 2 | ||||
-rw-r--r-- | qemu-nbd.c | 3 | ||||
-rw-r--r-- | qmp.c | 2 | ||||
-rw-r--r-- | tests/test-opts-visitor.c | 3 | ||||
-rw-r--r-- | tests/test-qemu-opts.c | 2 | ||||
-rw-r--r-- | tpm.c | 2 | ||||
-rw-r--r-- | ui/vnc.c | 4 | ||||
-rw-r--r-- | util/qemu-option.c | 25 | ||||
-rw-r--r-- | vl.c | 103 |
18 files changed, 109 insertions, 62 deletions
diff --git a/blockdev.c b/blockdev.c index 41d7e0fe54..3950e90edd 100644 --- a/blockdev.c +++ b/blockdev.c @@ -174,7 +174,7 @@ static int drive_index_to_unit_id(BlockInterfaceType type, int index) QemuOpts *drive_def(const char *optstr) { - return qemu_opts_parse(qemu_find_opts("drive"), optstr, 0); + return qemu_opts_parse_noisily(qemu_find_opts("drive"), optstr, false); } QemuOpts *drive_add(BlockInterfaceType type, int index, const char *file, @@ -1839,7 +1839,7 @@ void hmp_chardev_add(Monitor *mon, const QDict *qdict) Error *err = NULL; QemuOpts *opts; - opts = qemu_opts_parse(qemu_find_opts("chardev"), args, 1); + opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true); if (opts == NULL) { error_setg(&err, "Parsing chardev args failed"); } else { diff --git a/hw/usb/dev-network.c b/hw/usb/dev-network.c index 743c231d6b..5eeb4c6b06 100644 --- a/hw/usb/dev-network.c +++ b/hw/usb/dev-network.c @@ -1397,7 +1397,7 @@ static USBDevice *usb_net_init(USBBus *bus, const char *cmdline) QemuOpts *opts; int idx; - opts = qemu_opts_parse(qemu_find_opts("net"), cmdline, 0); + opts = qemu_opts_parse_noisily(qemu_find_opts("net"), cmdline, false); if (!opts) { return NULL; } diff --git a/include/qemu/option.h b/include/qemu/option.h index ac0e43b7e5..57e51c9628 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -119,7 +119,10 @@ void qemu_opts_del(QemuOpts *opts); void qemu_opts_validate(QemuOpts *opts, const QemuOptDesc *desc, Error **errp); void qemu_opts_do_parse(QemuOpts *opts, const char *params, const char *firstname, Error **errp); -QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, int permit_abbrev); +QemuOpts *qemu_opts_parse_noisily(QemuOptsList *list, const char *params, + bool permit_abbrev); +QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, + bool permit_abbrev, Error **errp); void qemu_opts_set_defaults(QemuOptsList *list, const char *params, int permit_abbrev); QemuOpts *qemu_opts_from_qdict(QemuOptsList *list, const QDict *qdict, diff --git a/include/ui/console.h b/include/ui/console.h index de92523bbb..9ad6c17ecc 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -369,7 +369,7 @@ char *vnc_display_local_addr(const char *id); #ifdef CONFIG_VNC int vnc_display_password(const char *id, const char *password); int vnc_display_pw_expire(const char *id, time_t expires); -QemuOpts *vnc_parse_func(const char *str); +QemuOpts *vnc_parse(const char *str, Error **errp); int vnc_init_func(void *opaque, QemuOpts *opts, Error **errp); #else static inline int vnc_display_password(const char *id, const char *password) @@ -3749,7 +3749,7 @@ static QDict *monitor_parse_arguments(Monitor *mon, if (get_str(buf, sizeof(buf), &p) < 0) { goto fail; } - opts = qemu_opts_parse(opts_list, buf, 1); + opts = qemu_opts_parse_noisily(opts_list, buf, true); if (!opts) { goto fail; } @@ -1049,7 +1049,8 @@ void hmp_host_net_add(Monitor *mon, const QDict *qdict) return; } - opts = qemu_opts_parse(qemu_find_opts("net"), opts_str ? opts_str : "", 0); + opts = qemu_opts_parse_noisily(qemu_find_opts("net"), + opts_str ? opts_str : "", false); if (!opts) { return; } @@ -1412,7 +1413,7 @@ int net_client_parse(QemuOptsList *opts_list, const char *optarg) } #endif - if (!qemu_opts_parse(opts_list, optarg, 1)) { + if (!qemu_opts_parse_noisily(opts_list, optarg, true)) { return -1; } diff --git a/qdev-monitor.c b/qdev-monitor.c index f6ceea7ac4..e1223b27f4 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -853,7 +853,7 @@ int qemu_global_option(const char *str) return 0; } - opts = qemu_opts_parse(&qemu_global_opts, str, false); + opts = qemu_opts_parse_noisily(&qemu_global_opts, str, false); if (!opts) { return -1; } diff --git a/qemu-img.c b/qemu-img.c index 60c820d002..ea964fefb8 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1590,7 +1590,8 @@ static int img_convert(int argc, char **argv) break; case 'l': if (strstart(optarg, SNAPSHOT_OPT_BASE, NULL)) { - sn_opts = qemu_opts_parse(&internal_snapshot_opts, optarg, 0); + sn_opts = qemu_opts_parse_noisily(&internal_snapshot_opts, + optarg, false); if (!sn_opts) { error_report("Failed in parsing snapshot param '%s'", optarg); @@ -153,7 +153,7 @@ static int open_f(BlockBackend *blk, int argc, char **argv) readonly = 1; break; case 'o': - if (!qemu_opts_parse(&empty_opts, optarg, 0)) { + if (!qemu_opts_parse_noisily(&empty_opts, optarg, false)) { printf("could not parse option list -- %s\n", optarg); qemu_opts_reset(&empty_opts); return 0; diff --git a/qemu-nbd.c b/qemu-nbd.c index 5af6d11e33..7a4bf1bc56 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -549,7 +549,8 @@ int main(int argc, char **argv) break; case 'l': if (strstart(optarg, SNAPSHOT_OPT_BASE, NULL)) { - sn_opts = qemu_opts_parse(&internal_snapshot_opts, optarg, 0); + sn_opts = qemu_opts_parse_noisily(&internal_snapshot_opts, + optarg, false); if (!sn_opts) { errx(EXIT_FAILURE, "Failed in parsing snapshot param `%s'", optarg); @@ -387,7 +387,7 @@ static void qmp_change_vnc_listen(const char *target, Error **errp) if (opts) { qemu_opts_del(opts); } - opts = vnc_parse_func(target); + opts = vnc_parse(target, errp); if (!opts) { return; } diff --git a/tests/test-opts-visitor.c b/tests/test-opts-visitor.c index ebeee5d589..1c753d9824 100644 --- a/tests/test-opts-visitor.c +++ b/tests/test-opts-visitor.c @@ -39,7 +39,8 @@ setup_fixture(OptsVisitorFixture *f, gconstpointer test_data) QemuOpts *opts; OptsVisitor *ov; - opts = qemu_opts_parse(qemu_find_opts("userdef"), opts_string, 0); + opts = qemu_opts_parse(qemu_find_opts("userdef"), opts_string, false, + NULL); g_assert(opts != NULL); ov = opts_visitor_new(opts); diff --git a/tests/test-qemu-opts.c b/tests/test-qemu-opts.c index da564923d0..0c1136d1b2 100644 --- a/tests/test-qemu-opts.c +++ b/tests/test-qemu-opts.c @@ -323,7 +323,7 @@ static void test_qemu_opt_unset(void) int ret; /* dynamically initialized (parsed) opts */ - opts = qemu_opts_parse(&opts_list_03, "key=value", 0); + opts = qemu_opts_parse(&opts_list_03, "key=value", false, NULL); g_assert(opts != NULL); /* check default/parsed value */ @@ -228,7 +228,7 @@ int tpm_config_parse(QemuOptsList *opts_list, const char *optarg) tpm_display_backend_drivers(); return -1; } - opts = qemu_opts_parse(opts_list, optarg, 1); + opts = qemu_opts_parse_noisily(opts_list, optarg, true); if (!opts) { return -1; } @@ -3749,10 +3749,10 @@ static void vnc_auto_assign_id(QemuOptsList *olist, QemuOpts *opts) qemu_opts_set_id(opts, id); } -QemuOpts *vnc_parse_func(const char *str) +QemuOpts *vnc_parse(const char *str, Error **errp) { QemuOptsList *olist = qemu_find_opts("vnc"); - QemuOpts *opts = qemu_opts_parse(olist, str, 1); + QemuOpts *opts = qemu_opts_parse(olist, str, true, errp); const char *id; if (!opts) { diff --git a/util/qemu-option.c b/util/qemu-option.c index 69da28c7e1..06c63ed619 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -820,7 +820,7 @@ void qemu_opts_do_parse(QemuOpts *opts, const char *params, } static QemuOpts *opts_parse(QemuOptsList *list, const char *params, - int permit_abbrev, bool defaults, Error **errp) + bool permit_abbrev, bool defaults, Error **errp) { const char *firstname; char value[1024], *id = NULL; @@ -867,19 +867,32 @@ static QemuOpts *opts_parse(QemuOptsList *list, const char *params, * Create a QemuOpts in @list and with options parsed from @params. * If @permit_abbrev, the first key=value in @params may omit key=, * and is treated as if key was @list->implied_opt_name. - * Report errors with qerror_report_err(). + * On error, store an error object through @errp if non-null. * Return the new QemuOpts on success, null pointer on error. */ QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, - int permit_abbrev) + bool permit_abbrev, Error **errp) +{ + return opts_parse(list, params, permit_abbrev, false, errp); +} + +/** + * Create a QemuOpts in @list and with options parsed from @params. + * If @permit_abbrev, the first key=value in @params may omit key=, + * and is treated as if key was @list->implied_opt_name. + * Report errors with error_report_err(). This is inappropriate in + * QMP context. Do not use this function there! + * Return the new QemuOpts on success, null pointer on error. + */ +QemuOpts *qemu_opts_parse_noisily(QemuOptsList *list, const char *params, + bool permit_abbrev) { Error *err = NULL; QemuOpts *opts; opts = opts_parse(list, params, permit_abbrev, false, &err); - if (!opts) { - qerror_report_err(err); - error_free(err); + if (err) { + error_report_err(err); } return opts; } @@ -2046,6 +2046,7 @@ static void select_vgahw (const char *p) static DisplayType select_display(const char *p) { + Error *err = NULL; const char *opts; DisplayType display = DT_DEFAULT; @@ -2114,7 +2115,8 @@ static DisplayType select_display(const char *p) } else if (strstart(p, "vnc", &opts)) { #ifdef CONFIG_VNC if (*opts == '=') { - if (vnc_parse_func(opts+1) == NULL) { + if (vnc_parse(opts + 1, &err) == NULL) { + error_report_err(err); exit(1); } } else { @@ -2188,7 +2190,8 @@ static int balloon_parse(const char *arg) if (!strncmp(arg, "virtio", 6)) { if (arg[6] == ',') { /* have params -> parse them */ - opts = qemu_opts_parse(qemu_find_opts("device"), arg+7, 0); + opts = qemu_opts_parse_noisily(qemu_find_opts("device"), arg + 7, + false); if (!opts) return -1; } else { @@ -3067,7 +3070,7 @@ int main(int argc, char **argv, char **envp) switch(popt->index) { case QEMU_OPTION_no_kvm_irqchip: { olist = qemu_find_opts("machine"); - qemu_opts_parse(olist, "kernel_irqchip=off", 0); + qemu_opts_parse_noisily(olist, "kernel_irqchip=off", false); break; } case QEMU_OPTION_cpu: @@ -3184,7 +3187,8 @@ int main(int argc, char **argv, char **envp) } break; case QEMU_OPTION_numa: - opts = qemu_opts_parse(qemu_find_opts("numa"), optarg, 1); + opts = qemu_opts_parse_noisily(qemu_find_opts("numa"), + optarg, true); if (!opts) { exit(1); } @@ -3235,7 +3239,8 @@ int main(int argc, char **argv, char **envp) drive_add(IF_DEFAULT, 2, optarg, CDROM_OPTS); break; case QEMU_OPTION_boot: - opts = qemu_opts_parse(qemu_find_opts("boot-opts"), optarg, 1); + opts = qemu_opts_parse_noisily(qemu_find_opts("boot-opts"), + optarg, true); if (!opts) { exit(1); } @@ -3260,7 +3265,8 @@ int main(int argc, char **argv, char **envp) break; #ifdef CONFIG_LIBISCSI case QEMU_OPTION_iscsi: - opts = qemu_opts_parse(qemu_find_opts("iscsi"), optarg, 0); + opts = qemu_opts_parse_noisily(qemu_find_opts("iscsi"), + optarg, false); if (!opts) { exit(1); } @@ -3296,8 +3302,8 @@ int main(int argc, char **argv, char **envp) exit(0); break; case QEMU_OPTION_m: - opts = qemu_opts_parse(qemu_find_opts("memory"), - optarg, 1); + opts = qemu_opts_parse_noisily(qemu_find_opts("memory"), + optarg, true); if (!opts) { exit(EXIT_FAILURE); } @@ -3409,14 +3415,16 @@ int main(int argc, char **argv, char **envp) default_monitor = 0; break; case QEMU_OPTION_mon: - opts = qemu_opts_parse(qemu_find_opts("mon"), optarg, 1); + opts = qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg, + true); if (!opts) { exit(1); } default_monitor = 0; break; case QEMU_OPTION_chardev: - opts = qemu_opts_parse(qemu_find_opts("chardev"), optarg, 1); + opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), + optarg, true); if (!opts) { exit(1); } @@ -3427,7 +3435,7 @@ int main(int argc, char **argv, char **envp) fprintf(stderr, "fsdev is not supported by this qemu build.\n"); exit(1); } - opts = qemu_opts_parse(olist, optarg, 1); + opts = qemu_opts_parse_noisily(olist, optarg, true); if (!opts) { exit(1); } @@ -3442,7 +3450,7 @@ int main(int argc, char **argv, char **envp) fprintf(stderr, "virtfs is not supported by this qemu build.\n"); exit(1); } - opts = qemu_opts_parse(olist, optarg, 1); + opts = qemu_opts_parse_noisily(olist, optarg, true); if (!opts) { exit(1); } @@ -3602,40 +3610,43 @@ int main(int argc, char **argv, char **envp) break; } case QEMU_OPTION_acpitable: - opts = qemu_opts_parse(qemu_find_opts("acpi"), optarg, 1); + opts = qemu_opts_parse_noisily(qemu_find_opts("acpi"), + optarg, true); if (!opts) { exit(1); } do_acpitable_option(opts); break; case QEMU_OPTION_smbios: - opts = qemu_opts_parse(qemu_find_opts("smbios"), optarg, 0); + opts = qemu_opts_parse_noisily(qemu_find_opts("smbios"), + optarg, false); if (!opts) { exit(1); } do_smbios_option(opts); break; case QEMU_OPTION_fwcfg: - opts = qemu_opts_parse(qemu_find_opts("fw_cfg"), optarg, 1); + opts = qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"), + optarg, true); if (opts == NULL) { exit(1); } break; case QEMU_OPTION_enable_kvm: olist = qemu_find_opts("machine"); - qemu_opts_parse(olist, "accel=kvm", 0); + qemu_opts_parse_noisily(olist, "accel=kvm", false); break; case QEMU_OPTION_M: case QEMU_OPTION_machine: olist = qemu_find_opts("machine"); - opts = qemu_opts_parse(olist, optarg, 1); + opts = qemu_opts_parse_noisily(olist, optarg, true); if (!opts) { exit(1); } break; case QEMU_OPTION_no_kvm: olist = qemu_find_opts("machine"); - qemu_opts_parse(olist, "accel=tcg", 0); + qemu_opts_parse_noisily(olist, "accel=tcg", false); break; case QEMU_OPTION_no_kvm_pit: { fprintf(stderr, "Warning: KVM PIT can no longer be disabled " @@ -3659,26 +3670,32 @@ int main(int argc, char **argv, char **envp) } case QEMU_OPTION_usb: olist = qemu_find_opts("machine"); - qemu_opts_parse(olist, "usb=on", 0); + qemu_opts_parse_noisily(olist, "usb=on", false); break; case QEMU_OPTION_usbdevice: olist = qemu_find_opts("machine"); - qemu_opts_parse(olist, "usb=on", 0); + qemu_opts_parse_noisily(olist, "usb=on", false); add_device_config(DEV_USB, optarg); break; case QEMU_OPTION_device: - if (!qemu_opts_parse(qemu_find_opts("device"), optarg, 1)) { + if (!qemu_opts_parse_noisily(qemu_find_opts("device"), + optarg, true)) { exit(1); } break; case QEMU_OPTION_smp: - if (!qemu_opts_parse(qemu_find_opts("smp-opts"), optarg, 1)) { + if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"), + optarg, true)) { exit(1); } break; case QEMU_OPTION_vnc: + { #ifdef CONFIG_VNC - if (vnc_parse_func(optarg) == NULL) { + Error *local_err = NULL; + + if (vnc_parse(optarg, &local_err) == NULL) { + error_report_err(local_err); exit(1); } #else @@ -3686,6 +3703,7 @@ int main(int argc, char **argv, char **envp) exit(1); #endif break; + } case QEMU_OPTION_no_acpi: acpi_enabled = 0; break; @@ -3720,7 +3738,8 @@ int main(int argc, char **argv, char **envp) fprintf(stderr, "Too many option ROMs\n"); exit(1); } - opts = qemu_opts_parse(qemu_find_opts("option-rom"), optarg, 1); + opts = qemu_opts_parse_noisily(qemu_find_opts("option-rom"), + optarg, true); if (!opts) { exit(1); } @@ -3739,8 +3758,8 @@ int main(int argc, char **argv, char **envp) break; case QEMU_OPTION_semihosting_config: semihosting.enabled = true; - opts = qemu_opts_parse(qemu_find_opts("semihosting-config"), - optarg, 0); + opts = qemu_opts_parse_noisily(qemu_find_opts("semihosting-config"), + optarg, false); if (opts != NULL) { semihosting.enabled = qemu_opt_get_bool(opts, "enable", true); @@ -3775,7 +3794,8 @@ int main(int argc, char **argv, char **envp) "is no longer supported.\n"); break; case QEMU_OPTION_name: - opts = qemu_opts_parse(qemu_find_opts("name"), optarg, 1); + opts = qemu_opts_parse_noisily(qemu_find_opts("name"), + optarg, true); if (!opts) { exit(1); } @@ -3800,7 +3820,8 @@ int main(int argc, char **argv, char **envp) configure_rtc_date_offset(optarg, 1); break; case QEMU_OPTION_rtc: - opts = qemu_opts_parse(qemu_find_opts("rtc"), optarg, 0); + opts = qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg, + false); if (!opts) { exit(1); } @@ -3813,8 +3834,8 @@ int main(int argc, char **argv, char **envp) } break; case QEMU_OPTION_icount: - icount_opts = qemu_opts_parse(qemu_find_opts("icount"), - optarg, 1); + icount_opts = qemu_opts_parse_noisily(qemu_find_opts("icount"), + optarg, true); if (!icount_opts) { exit(1); } @@ -3851,7 +3872,8 @@ int main(int argc, char **argv, char **envp) break; case QEMU_OPTION_trace: { - opts = qemu_opts_parse(qemu_find_opts("trace"), optarg, 0); + opts = qemu_opts_parse_noisily(qemu_find_opts("trace"), + optarg, false); if (!opts) { exit(1); } @@ -3875,7 +3897,7 @@ int main(int argc, char **argv, char **envp) fprintf(stderr, "spice is not supported by this qemu build.\n"); exit(1); } - opts = qemu_opts_parse(olist, optarg, 0); + opts = qemu_opts_parse_noisily(olist, optarg, false); if (!opts) { exit(1); } @@ -3906,14 +3928,16 @@ int main(int argc, char **argv, char **envp) qtest_log = optarg; break; case QEMU_OPTION_sandbox: - opts = qemu_opts_parse(qemu_find_opts("sandbox"), optarg, 1); + opts = qemu_opts_parse_noisily(qemu_find_opts("sandbox"), + optarg, true); if (!opts) { exit(1); } break; case QEMU_OPTION_add_fd: #ifndef _WIN32 - opts = qemu_opts_parse(qemu_find_opts("add-fd"), optarg, 0); + opts = qemu_opts_parse_noisily(qemu_find_opts("add-fd"), + optarg, false); if (!opts) { exit(1); } @@ -3924,20 +3948,23 @@ int main(int argc, char **argv, char **envp) #endif break; case QEMU_OPTION_object: - opts = qemu_opts_parse(qemu_find_opts("object"), optarg, 1); + opts = qemu_opts_parse_noisily(qemu_find_opts("object"), + optarg, true); if (!opts) { exit(1); } break; case QEMU_OPTION_realtime: - opts = qemu_opts_parse(qemu_find_opts("realtime"), optarg, 0); + opts = qemu_opts_parse_noisily(qemu_find_opts("realtime"), + optarg, false); if (!opts) { exit(1); } enable_mlock = qemu_opt_get_bool(opts, "mlock", true); break; case QEMU_OPTION_msg: - opts = qemu_opts_parse(qemu_find_opts("msg"), optarg, 0); + opts = qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg, + false); if (!opts) { exit(1); } @@ -4189,7 +4216,7 @@ int main(int argc, char **argv, char **envp) #elif defined(CONFIG_SDL) || defined(CONFIG_COCOA) display_type = DT_SDL; #elif defined(CONFIG_VNC) - vnc_parse_func("localhost:0,to=99,id=default"); + vnc_parse("localhost:0,to=99,id=default", &error_abort); show_vnc_port = 1; #else display_type = DT_NONE; |