QemuOpts: Wean off qerror_report_err()
qerror_report_err() is a transitional interface to help with
converting existing monitor commands to QMP. It should not be used
elsewhere.
The only remaining user in qemu-option.c is qemu_opts_parse(). Is it
used in QMP context? If not, we can simply replace
qerror_report_err() by error_report_err().
The uses in qemu-img.c, qemu-io.c, qemu-nbd.c and under tests/ are
clearly not in QMP context.
The uses in vl.c aren't either, because the only QMP command handlers
there are qmp_query_status() and qmp_query_machines(), and they don't
call it.
Remaining uses:
* drive_def(): Command line -drive and such, HMP drive_add and pci_add
* hmp_chardev_add(): HMP chardev-add
* monitor_parse_command(): HMP core
* tmp_config_parse(): Command line -tpmdev
* net_host_device_add(): HMP host_net_add
* net_client_parse(): Command line -net and -netdev
* qemu_global_option(): Command line -global
* vnc_parse_func(): Command line -display, -vnc, default display, HMP
change, QMP change. Bummer.
* qemu_pci_hot_add_nic(): HMP pci_add
* usb_net_init(): Command line -usbdevice, HMP usb_add
Propagate errors through qemu_opts_parse(). Create a convenience
function qemu_opts_parse_noisily() that passes errors to
error_report_err(). Switch all non-QMP users outside tests to it.
That leaves vnc_parse_func(). Propagate errors through it. Since I'm
touching it anyway, rename it to vnc_parse().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Luiz Capitulino <lcapitulino@redhat.com>
diff --git a/vl.c b/vl.c
index fd6a5c2..34bf0fb 100644
--- a/vl.c
+++ b/vl.c
@@ -2046,6 +2046,7 @@
static DisplayType select_display(const char *p)
{
+ Error *err = NULL;
const char *opts;
DisplayType display = DT_DEFAULT;
@@ -2114,7 +2115,8 @@
} 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 @@
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 @@
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 @@
}
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
}
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 @@
exit(1);
#endif
break;
+ }
case QEMU_OPTION_no_acpi:
acpi_enabled = 0;
break;
@@ -3720,7 +3738,8 @@
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 @@
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 @@
"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 @@
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 @@
}
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 @@
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 @@
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 @@
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 @@
#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 @@
#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;