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 02/13] QemuOpts: Convert qemu_opt_set_number() to Error, fix its use
Date: Mon, 16 Feb 2015 15:44:14 +0100	[thread overview]
Message-ID: <1424097865-3973-3-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1424097865-3973-1-git-send-email-armbru@redhat.com>

Return the Error object instead of reporting it with
qerror_report_err().

Change callers that assume the function can't fail to pass
&error_abort, so that should the assumption ever break, it'll break
noisily.

Turns out all callers outside its unit test assume that.  We could
drop the Error ** argument, but that would make the interface less
regular, so don't.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 block.c                |  6 +++---
 block/nbd.c            |  3 ++-
 block/qcow2.c          |  2 +-
 block/vvfat.c          |  3 ++-
 include/qemu/option.h  |  3 ++-
 qemu-img.c             |  3 ++-
 tests/test-qemu-opts.c | 16 ++++++++--------
 util/qemu-option.c     |  9 ++++-----
 vl.c                   |  2 +-
 9 files changed, 25 insertions(+), 22 deletions(-)

diff --git a/block.c b/block.c
index 210fd5f..be28845 100644
--- a/block.c
+++ b/block.c
@@ -1364,7 +1364,7 @@ int bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp)
 
     opts = qemu_opts_create(bdrv_qcow2.create_opts, NULL, 0,
                             &error_abort);
-    qemu_opt_set_number(opts, BLOCK_OPT_SIZE, total_size);
+    qemu_opt_set_number(opts, BLOCK_OPT_SIZE, total_size, &error_abort);
     ret = bdrv_create(&bdrv_qcow2, tmp_filename, opts, &local_err);
     qemu_opts_del(opts);
     if (ret < 0) {
@@ -5646,7 +5646,7 @@ void bdrv_img_create(const char *filename, const char *fmt,
 
     /* Create parameter list with default values */
     opts = qemu_opts_create(create_opts, NULL, 0, &error_abort);
-    qemu_opt_set_number(opts, BLOCK_OPT_SIZE, img_size);
+    qemu_opt_set_number(opts, BLOCK_OPT_SIZE, img_size, &error_abort);
 
     /* Parse -o options */
     if (options) {
@@ -5728,7 +5728,7 @@ void bdrv_img_create(const char *filename, const char *fmt,
                 goto out;
             }
 
-            qemu_opt_set_number(opts, BLOCK_OPT_SIZE, size);
+            qemu_opt_set_number(opts, BLOCK_OPT_SIZE, size, &error_abort);
 
             bdrv_unref(bs);
         } else {
diff --git a/block/nbd.c b/block/nbd.c
index b05d1d0..13a4bae 100644
--- a/block/nbd.c
+++ b/block/nbd.c
@@ -215,7 +215,8 @@ static void nbd_config(BDRVNBDState *s, QDict *options, char **export,
     }
 
     if (!qemu_opt_get(s->socket_opts, "port")) {
-        qemu_opt_set_number(s->socket_opts, "port", NBD_DEFAULT_PORT);
+        qemu_opt_set_number(s->socket_opts, "port", NBD_DEFAULT_PORT,
+                            &error_abort);
     }
 
     *export = g_strdup(qdict_get_try_str(options, "export"));
diff --git a/block/qcow2.c b/block/qcow2.c
index 7e614d7..c83e0ff 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1858,7 +1858,7 @@ static int qcow2_create2(const char *filename, int64_t total_size,
         meta_size += nreftablee * sizeof(uint64_t);
 
         qemu_opt_set_number(opts, BLOCK_OPT_SIZE,
-                            aligned_total_size + meta_size);
+                            aligned_total_size + meta_size, &error_abort);
         qemu_opt_set(opts, BLOCK_OPT_PREALLOC, PreallocMode_lookup[prealloc]);
     }
 
diff --git a/block/vvfat.c b/block/vvfat.c
index a1a44f0..5e32d77 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -2924,7 +2924,8 @@ static int enable_write_target(BDRVVVFATState *s, Error **errp)
     }
 
     opts = qemu_opts_create(bdrv_qcow->create_opts, NULL, 0, &error_abort);
-    qemu_opt_set_number(opts, BLOCK_OPT_SIZE, s->sector_count * 512);
+    qemu_opt_set_number(opts, BLOCK_OPT_SIZE, s->sector_count * 512,
+                        &error_abort);
     qemu_opt_set(opts, BLOCK_OPT_BACKING_FILE, "fat:");
 
     ret = bdrv_create(bdrv_qcow, s->qcow_filename, opts, errp);
diff --git a/include/qemu/option.h b/include/qemu/option.h
index 3206874..7422cc2 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -99,7 +99,8 @@ void qemu_opt_set_err(QemuOpts *opts, const char *name, const char *value,
                       Error **errp);
 void qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val,
                        Error **errp);
-int qemu_opt_set_number(QemuOpts *opts, const char *name, int64_t val);
+void qemu_opt_set_number(QemuOpts *opts, const char *name, int64_t val,
+                         Error **errp);
 typedef int (*qemu_opt_loopfunc)(const char *name, const char *value, void *opaque);
 int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque,
                      int abort_on_failure);
diff --git a/qemu-img.c b/qemu-img.c
index 25b1369..7eea84a 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -1554,7 +1554,8 @@ static int img_convert(int argc, char **argv)
         goto out;
     }
 
-    qemu_opt_set_number(opts, BLOCK_OPT_SIZE, total_sectors * 512);
+    qemu_opt_set_number(opts, BLOCK_OPT_SIZE, total_sectors * 512,
+                        &error_abort);
     ret = add_old_style_options(out_fmt, opts, out_baseimg, NULL);
     if (ret < 0) {
         goto out;
diff --git a/tests/test-qemu-opts.c b/tests/test-qemu-opts.c
index 6b0ae33..3fea96a 100644
--- a/tests/test-qemu-opts.c
+++ b/tests/test-qemu-opts.c
@@ -215,10 +215,10 @@ static void test_qemu_opt_get_bool(void)
 
 static void test_qemu_opt_get_number(void)
 {
+    Error *err = NULL;
     QemuOptsList *list;
     QemuOpts *opts;
     uint64_t opt;
-    int ret;
 
     list = qemu_find_opts("opts_list_01");
     g_assert(list != NULL);
@@ -238,16 +238,16 @@ static void test_qemu_opt_get_number(void)
     opt = qemu_opt_get_number(opts, "number1", 5);
     g_assert(opt == 5);
 
-    ret = qemu_opt_set_number(opts, "number1", 10);
-    g_assert(ret == 0);
+    qemu_opt_set_number(opts, "number1", 10, &err);
+    g_assert(!err);
 
     /* now we have set number1, should know about it */
     opt = qemu_opt_get_number(opts, "number1", 5);
     g_assert(opt == 10);
 
     /* having reset it, the returned should be the reset one not defval */
-    ret = qemu_opt_set_number(opts, "number1", 15);
-    g_assert(ret == 0);
+    qemu_opt_set_number(opts, "number1", 15, &err);
+    g_assert(!err);
 
     opt = qemu_opt_get_number(opts, "number1", 5);
     g_assert(opt == 15);
@@ -349,10 +349,10 @@ static void test_qemu_opt_unset(void)
 
 static void test_qemu_opts_reset(void)
 {
+    Error *err = NULL;
     QemuOptsList *list;
     QemuOpts *opts;
     uint64_t opt;
-    int ret;
 
     list = qemu_find_opts("opts_list_01");
     g_assert(list != NULL);
@@ -372,8 +372,8 @@ static void test_qemu_opts_reset(void)
     opt = qemu_opt_get_number(opts, "number1", 5);
     g_assert(opt == 5);
 
-    ret = qemu_opt_set_number(opts, "number1", 10);
-    g_assert(ret == 0);
+    qemu_opt_set_number(opts, "number1", 10, &err);
+    g_assert(!err);
 
     /* now we have set number1, should know about it */
     opt = qemu_opt_get_number(opts, "number1", 5);
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 4de8326..c873b6c 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -589,7 +589,8 @@ void qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val,
     QTAILQ_INSERT_TAIL(&opts->head, opt, next);
 }
 
-int qemu_opt_set_number(QemuOpts *opts, const char *name, int64_t val)
+void qemu_opt_set_number(QemuOpts *opts, const char *name, int64_t val,
+                         Error **errp)
 {
     QemuOpt *opt;
     const QemuOptDesc *desc = opts->list->desc;
@@ -597,9 +598,9 @@ int qemu_opt_set_number(QemuOpts *opts, const char *name, int64_t val)
     opt = g_malloc0(sizeof(*opt));
     opt->desc = find_desc_by_name(desc, name);
     if (!opt->desc && !opts_accepts_any(opts)) {
-        qerror_report(QERR_INVALID_PARAMETER, name);
+        error_set(errp, QERR_INVALID_PARAMETER, name);
         g_free(opt);
-        return -1;
+        return;
     }
 
     opt->name = g_strdup(name);
@@ -607,8 +608,6 @@ int qemu_opt_set_number(QemuOpts *opts, const char *name, int64_t val)
     opt->value.uint = val;
     opt->str = g_strdup_printf("%" PRId64, val);
     QTAILQ_INSERT_TAIL(&opts->head, opt, next);
-
-    return 0;
 }
 
 int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque,
diff --git a/vl.c b/vl.c
index d557d11..395793e 100644
--- a/vl.c
+++ b/vl.c
@@ -2684,7 +2684,7 @@ static void set_memory_options(uint64_t *ram_slots, ram_addr_t *maxram_size)
     }
 
     /* store value for the future use */
-    qemu_opt_set_number(opts, "size", ram_size);
+    qemu_opt_set_number(opts, "size", ram_size, &error_abort);
     *maxram_size = ram_size;
 
     maxmem_str = qemu_opt_get(opts, "maxmem");
-- 
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 ` Markus Armbruster [this message]
2015-02-16 20:26   ` [Qemu-devel] [PATCH 02/13] QemuOpts: Convert qemu_opt_set_number() " 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 ` [Qemu-devel] [PATCH 09/13] qemu-img: Suppress unhelpful extra errors in convert, amend Markus Armbruster
2015-02-16 23:38   ` 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-3-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).