diff --git a/block.c b/block.c index ebbb51544d..28ea19aafb 100644 --- a/block.c +++ b/block.c @@ -5653,7 +5653,10 @@ void bdrv_img_create(const char *filename, const char *fmt, /* Parse -o options */ if (options) { - if (qemu_opts_do_parse(opts, options, NULL) != 0) { + qemu_opts_do_parse(opts, options, NULL, &local_err); + if (local_err) { + error_report_err(local_err); + local_err = NULL; error_setg(errp, "Invalid options for file format '%s'", fmt); goto out; } diff --git a/include/qemu/option.h b/include/qemu/option.h index a41ee92508..f88b545dfc 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -115,7 +115,8 @@ const char *qemu_opts_id(QemuOpts *opts); void qemu_opts_set_id(QemuOpts *opts, char *id); void qemu_opts_del(QemuOpts *opts); void qemu_opts_validate(QemuOpts *opts, const QemuOptDesc *desc, Error **errp); -int qemu_opts_do_parse(QemuOpts *opts, const char *params, const char *firstname); +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); void qemu_opts_set_defaults(QemuOptsList *list, const char *params, int permit_abbrev); diff --git a/qemu-char.c b/qemu-char.c index 3ed46ee36d..a405d76c31 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -3379,8 +3379,11 @@ QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename) qemu_opt_set(opts, "host", host, &error_abort); qemu_opt_set(opts, "port", port, &error_abort); if (p[pos] == ',') { - if (qemu_opts_do_parse(opts, p+pos+1, NULL) != 0) + qemu_opts_do_parse(opts, p+pos+1, NULL, &local_err); + if (local_err) { + error_report_err(local_err); goto fail; + } } if (strstart(filename, "telnet:", &p)) qemu_opt_set(opts, "telnet", "on", &error_abort); @@ -3411,8 +3414,11 @@ QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename) } if (strstart(filename, "unix:", &p)) { qemu_opt_set(opts, "backend", "socket", &error_abort); - if (qemu_opts_do_parse(opts, p, "path") != 0) + qemu_opts_do_parse(opts, p, "path", &local_err); + if (local_err) { + error_report_err(local_err); goto fail; + } return opts; } if (strstart(filename, "/dev/parport", NULL) || diff --git a/qemu-img.c b/qemu-img.c index 54e34bd3e3..7ac7f56c5d 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1550,10 +1550,14 @@ static int img_convert(int argc, char **argv) create_opts = qemu_opts_append(create_opts, proto_drv->create_opts); opts = qemu_opts_create(create_opts, NULL, 0, &error_abort); - if (options && qemu_opts_do_parse(opts, options, NULL)) { - error_report("Invalid options for file format '%s'", out_fmt); - ret = -1; - goto out; + if (options) { + qemu_opts_do_parse(opts, options, NULL, &local_err); + if (local_err) { + error_report("Invalid options for file format '%s'", out_fmt); + error_free(local_err); + ret = -1; + goto out; + } } qemu_opt_set_number(opts, BLOCK_OPT_SIZE, total_sectors * 512, @@ -2887,6 +2891,7 @@ static void amend_status_cb(BlockDriverState *bs, static int img_amend(int argc, char **argv) { + Error *err = NULL; int c, ret = 0; char *options = NULL; QemuOptsList *create_opts = NULL; @@ -2992,10 +2997,14 @@ static int img_amend(int argc, char **argv) create_opts = qemu_opts_append(create_opts, bs->drv->create_opts); opts = qemu_opts_create(create_opts, NULL, 0, &error_abort); - if (options && qemu_opts_do_parse(opts, options, NULL)) { - error_report("Invalid options for file format '%s'", fmt); - ret = -1; - goto out; + if (options) { + qemu_opts_do_parse(opts, options, NULL, &err); + if (err) { + error_report("Invalid options for file format '%s'", fmt); + error_free(err); + ret = -1; + goto out; + } } /* In case the driver does not call amend_status_cb() */ diff --git a/util/qemu-option.c b/util/qemu-option.c index 95f242ea0e..fda4e5fcbf 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -799,17 +799,16 @@ static void opts_do_parse(QemuOpts *opts, const char *params, } } -int qemu_opts_do_parse(QemuOpts *opts, const char *params, const char *firstname) +/** + * Store options parsed from @params into @opts. + * If @firstname is non-null, the first key=value in @params may omit + * key=, and is treated as if key was @firstname. + * On error, store an error object through @errp if non-null. + */ +void qemu_opts_do_parse(QemuOpts *opts, const char *params, + const char *firstname, Error **errp) { - Error *err = NULL; - - opts_do_parse(opts, params, firstname, false, &err); - if (err) { - qerror_report_err(err); - error_free(err); - return -1; - } - return 0; + opts_do_parse(opts, params, firstname, false, errp); } static QemuOpts *opts_parse(QemuOptsList *list, const char *params,