提交 6750e795 编写于 作者: M Markus Armbruster

qemu-img: Suppress unhelpful extra errors in convert, resize

add_old_style_options() for img_convert() and img_resize() use
qemu_opt_set(), 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 -B raw in.img out.img
    qemu-img: Invalid parameter 'backing_file'
    qemu-img: Backing file not supported for file format 'raw'

Switch to qemu_opt_set_err() to get rid of the unwanted messages.
Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
Reviewed-by: NEric Blake <eblake@redhat.com>
上级 79087c78
...@@ -332,17 +332,23 @@ static int add_old_style_options(const char *fmt, QemuOpts *opts, ...@@ -332,17 +332,23 @@ static int add_old_style_options(const char *fmt, QemuOpts *opts,
const char *base_filename, const char *base_filename,
const char *base_fmt) const char *base_fmt)
{ {
Error *err = NULL;
if (base_filename) { if (base_filename) {
if (qemu_opt_set(opts, BLOCK_OPT_BACKING_FILE, base_filename)) { qemu_opt_set_err(opts, BLOCK_OPT_BACKING_FILE, base_filename, &err);
if (err) {
error_report("Backing file not supported for file format '%s'", error_report("Backing file not supported for file format '%s'",
fmt); fmt);
error_free(err);
return -1; return -1;
} }
} }
if (base_fmt) { if (base_fmt) {
if (qemu_opt_set(opts, BLOCK_OPT_BACKING_FMT, base_fmt)) { qemu_opt_set_err(opts, BLOCK_OPT_BACKING_FMT, base_fmt, &err);
if (err) {
error_report("Backing file format not supported for file " error_report("Backing file format not supported for file "
"format '%s'", fmt); "format '%s'", fmt);
error_free(err);
return -1; return -1;
} }
} }
...@@ -2750,6 +2756,7 @@ out: ...@@ -2750,6 +2756,7 @@ out:
static int img_resize(int argc, char **argv) static int img_resize(int argc, char **argv)
{ {
Error *err = NULL;
int c, ret, relative; int c, ret, relative;
const char *filename, *fmt, *size; const char *filename, *fmt, *size;
int64_t n, total_size; int64_t n, total_size;
...@@ -2821,8 +2828,9 @@ static int img_resize(int argc, char **argv) ...@@ -2821,8 +2828,9 @@ static int img_resize(int argc, char **argv)
/* Parse size */ /* Parse size */
param = qemu_opts_create(&resize_options, NULL, 0, &error_abort); param = qemu_opts_create(&resize_options, NULL, 0, &error_abort);
if (qemu_opt_set(param, BLOCK_OPT_SIZE, size)) { qemu_opt_set_err(param, BLOCK_OPT_SIZE, size, &err);
/* Error message already printed when size parsing fails */ if (err) {
error_report_err(err);
ret = -1; ret = -1;
qemu_opts_del(param); qemu_opts_del(param);
goto out; goto out;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册