mirror of
https://github.com/xemu-project/xemu.git
synced 2024-11-23 11:39:53 +00:00
qemu-img: Suppress unhelpful extra errors in convert, amend
img_convert() and img_amend() use qemu_opts_do_parse(), which reports errors with qerror_report_err(). Its error messages aren't helpful here, the caller reports one that actually makes sense. Reproducer: $ qemu-img convert -o backing_format=raw in.img out.img qemu-img: Invalid parameter 'backing_format' qemu-img: Invalid options for file format 'raw' To fix, propagate errors through qemu_opts_do_parse(). This lifts the error reporting into callers. Drop it from img_convert() and img_amend(), keep it in qemu_chr_parse_compat(), bdrv_img_create(). Since I'm touching qemu_opts_do_parse() anyway, write a function comment for it. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
4f81273dd9
commit
dc523cd348
5
block.c
5
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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
10
qemu-char.c
10
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) ||
|
||||
|
25
qemu-img.c
25
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() */
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user