From 70b9433109ed99217b812f19800de550e2e0ecd5 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Fri, 13 Feb 2015 12:50:26 +0100 Subject: 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 Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi Reviewed-by: Luiz Capitulino --- util/qemu-option.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'util') diff --git a/util/qemu-option.c b/util/qemu-option.c index 69da28c..06c63ed 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; } -- cgit v1.1