Skip to content

Commit

Permalink
QemuOpts: Wean off qerror_report_err()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Markus Armbruster committed Jun 22, 2015
1 parent f006cf7 commit 70b9433
Show file tree
Hide file tree
Showing 18 changed files with 109 additions and 62 deletions.
2 changes: 1 addition & 1 deletion blockdev.c
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion hmp.c
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion hw/usb/dev-network.c
Expand Up @@ -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;
}
Expand Down
5 changes: 4 additions & 1 deletion include/qemu/option.h
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion include/ui/console.h
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion monitor.c
Expand Up @@ -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;
}
Expand Down
5 changes: 3 additions & 2 deletions net/net.c
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion qdev-monitor.c
Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion qemu-img.c
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion qemu-io.c
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion qemu-nbd.c
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion qmp.c
Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion tests/test-opts-visitor.c
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/test-qemu-opts.c
Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion tpm.c
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions ui/vnc.c
Expand Up @@ -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) {
Expand Down
25 changes: 19 additions & 6 deletions util/qemu-option.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 70b9433

Please sign in to comment.