qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, kraxel@redhat.com, stefanha@redhat.com
Subject: [Qemu-devel] [PATCH 09/13] qemu-img: Suppress unhelpful extra errors in convert, amend
Date: Mon, 16 Feb 2015 15:44:21 +0100	[thread overview]
Message-ID: <1424097865-3973-10-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1424097865-3973-1-git-send-email-armbru@redhat.com>

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>
---
 block.c               |  5 ++++-
 include/qemu/option.h |  3 ++-
 qemu-char.c           | 10 ++++++++--
 qemu-img.c            | 25 +++++++++++++++++--------
 util/qemu-option.c    | 19 +++++++++----------
 5 files changed, 40 insertions(+), 22 deletions(-)

diff --git a/block.c b/block.c
index 71d3bcc..e596330 100644
--- a/block.c
+++ b/block.c
@@ -5650,7 +5650,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 a41ee92..f88b545 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 3ed46ee..a405d76 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 cb99cc2..eadebd7 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -1554,10 +1554,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,
@@ -2897,6 +2901,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;
@@ -3002,10 +3007,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 95f242e..ea49140 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 into @opts options parsed from @params.
+ * 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,
-- 
1.9.3

  parent reply	other threads:[~2015-02-16 14:44 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-16 14:44 [Qemu-devel] [PATCH 00/13] QemuOpts: Convert various setters to Error Markus Armbruster
2015-02-16 14:44 ` [Qemu-devel] [PATCH 01/13] QemuOpts: Convert qemu_opt_set_bool() to Error, fix its use Markus Armbruster
2015-02-16 20:24   ` Eric Blake
2015-02-16 14:44 ` [Qemu-devel] [PATCH 02/13] QemuOpts: Convert qemu_opt_set_number() " Markus Armbruster
2015-02-16 20:26   ` Eric Blake
2015-02-16 14:44 ` [Qemu-devel] [PATCH 03/13] QemuOpts: Convert qemu_opts_set() " Markus Armbruster
2015-02-16 21:06   ` Eric Blake
2015-02-16 14:44 ` [Qemu-devel] [PATCH 04/13] qemu-img: Suppress unhelpful extra errors in convert, resize Markus Armbruster
2015-02-16 20:19   ` John Snow
2015-02-17  8:18     ` Markus Armbruster
2015-02-17 15:28   ` Eric Blake
2015-02-16 14:44 ` [Qemu-devel] [PATCH 05/13] block: Suppress unhelpful extra errors in bdrv_img_create() Markus Armbruster
2015-02-16 22:26   ` Eric Blake
2015-02-16 14:44 ` [Qemu-devel] [PATCH 06/13] QemuOpts: Drop qemu_opt_set(), rename qemu_opt_set_err(), fix use Markus Armbruster
2015-02-16 22:53   ` Eric Blake
2015-02-17  8:21     ` Markus Armbruster
2015-02-16 14:44 ` [Qemu-devel] [PATCH 07/13] QemuOpts: Propagate errors through opts_do_parse() Markus Armbruster
2015-02-16 22:54   ` Eric Blake
2015-02-16 14:44 ` [Qemu-devel] [PATCH 08/13] QemuOpts: Propagate errors through opts_parse() Markus Armbruster
2015-02-16 23:15   ` Eric Blake
2015-02-16 14:44 ` Markus Armbruster [this message]
2015-02-16 23:38   ` [Qemu-devel] [PATCH 09/13] qemu-img: Suppress unhelpful extra errors in convert, amend Eric Blake
2015-02-17  8:25     ` Markus Armbruster
2015-02-16 14:44 ` [Qemu-devel] [PATCH 10/13] block: Simplify setting numeric options Markus Armbruster
2015-02-17 16:42   ` Eric Blake
2015-02-16 14:44 ` [Qemu-devel] [PATCH 11/13] qemu-sockets: Simplify setting numeric and boolean options Markus Armbruster
2015-02-17 16:45   ` Eric Blake
2015-02-16 14:44 ` [Qemu-devel] [PATCH 12/13] pc: Use qemu_opt_set() instead of qemu_opts_parse() Markus Armbruster
2015-02-17 16:46   ` Eric Blake
2015-02-16 14:44 ` [Qemu-devel] [PATCH 13/13] qtest: " Markus Armbruster
2015-02-17 16:47   ` Eric Blake
2015-02-17  8:16 ` [Qemu-devel] [PATCH 00/13] QemuOpts: Convert various setters to Error Markus Armbruster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1424097865-3973-10-git-send-email-armbru@redhat.com \
    --to=armbru@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).