qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Markus Armbruster <armbru@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Josh Durgin <josh.durgin@inktank.com>
Subject: [Qemu-devel] [PULL 18/33] block/rbd: Propagate errors to open and create methods
Date: Fri, 23 May 2014 17:41:50 +0200	[thread overview]
Message-ID: <1400859725-31879-19-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1400859725-31879-1-git-send-email-stefanha@redhat.com>

From: Markus Armbruster <armbru@redhat.com>

Completes the conversion to Error started in commit 015a103^..d5124c0.

Cc: Josh Durgin <josh.durgin@inktank.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 block/rbd.c | 71 +++++++++++++++++++++++++++++++++----------------------------
 1 file changed, 39 insertions(+), 32 deletions(-)

diff --git a/block/rbd.c b/block/rbd.c
index dbc79f4..09af484 100644
--- a/block/rbd.c
+++ b/block/rbd.c
@@ -105,7 +105,7 @@ typedef struct BDRVRBDState {
 static int qemu_rbd_next_tok(char *dst, int dst_len,
                              char *src, char delim,
                              const char *name,
-                             char **p)
+                             char **p, Error **errp)
 {
     int l;
     char *end;
@@ -128,10 +128,10 @@ static int qemu_rbd_next_tok(char *dst, int dst_len,
     }
     l = strlen(src);
     if (l >= dst_len) {
-        error_report("%s too long", name);
+        error_setg(errp, "%s too long", name);
         return -EINVAL;
     } else if (l == 0) {
-        error_report("%s too short", name);
+        error_setg(errp, "%s too short", name);
         return -EINVAL;
     }
 
@@ -157,13 +157,15 @@ static int qemu_rbd_parsename(const char *filename,
                               char *pool, int pool_len,
                               char *snap, int snap_len,
                               char *name, int name_len,
-                              char *conf, int conf_len)
+                              char *conf, int conf_len,
+                              Error **errp)
 {
     const char *start;
     char *p, *buf;
     int ret;
 
     if (!strstart(filename, "rbd:", &start)) {
+        error_setg(errp, "File name must start with 'rbd:'");
         return -EINVAL;
     }
 
@@ -172,7 +174,8 @@ static int qemu_rbd_parsename(const char *filename,
     *snap = '\0';
     *conf = '\0';
 
-    ret = qemu_rbd_next_tok(pool, pool_len, p, '/', "pool name", &p);
+    ret = qemu_rbd_next_tok(pool, pool_len, p,
+                            '/', "pool name", &p, errp);
     if (ret < 0 || !p) {
         ret = -EINVAL;
         goto done;
@@ -180,21 +183,25 @@ static int qemu_rbd_parsename(const char *filename,
     qemu_rbd_unescape(pool);
 
     if (strchr(p, '@')) {
-        ret = qemu_rbd_next_tok(name, name_len, p, '@', "object name", &p);
+        ret = qemu_rbd_next_tok(name, name_len, p,
+                                '@', "object name", &p, errp);
         if (ret < 0) {
             goto done;
         }
-        ret = qemu_rbd_next_tok(snap, snap_len, p, ':', "snap name", &p);
+        ret = qemu_rbd_next_tok(snap, snap_len, p,
+                                ':', "snap name", &p, errp);
         qemu_rbd_unescape(snap);
     } else {
-        ret = qemu_rbd_next_tok(name, name_len, p, ':', "object name", &p);
+        ret = qemu_rbd_next_tok(name, name_len, p,
+                                ':', "object name", &p, errp);
     }
     qemu_rbd_unescape(name);
     if (ret < 0 || !p) {
         goto done;
     }
 
-    ret = qemu_rbd_next_tok(conf, conf_len, p, '\0', "configuration", &p);
+    ret = qemu_rbd_next_tok(conf, conf_len, p,
+                            '\0', "configuration", &p, errp);
 
 done:
     g_free(buf);
@@ -229,7 +236,7 @@ static char *qemu_rbd_parse_clientname(const char *conf, char *clientname)
     return NULL;
 }
 
-static int qemu_rbd_set_conf(rados_t cluster, const char *conf)
+static int qemu_rbd_set_conf(rados_t cluster, const char *conf, Error **errp)
 {
     char *p, *buf;
     char name[RBD_MAX_CONF_NAME_SIZE];
@@ -241,20 +248,20 @@ static int qemu_rbd_set_conf(rados_t cluster, const char *conf)
 
     while (p) {
         ret = qemu_rbd_next_tok(name, sizeof(name), p,
-                                '=', "conf option name", &p);
+                                '=', "conf option name", &p, errp);
         if (ret < 0) {
             break;
         }
         qemu_rbd_unescape(name);
 
         if (!p) {
-            error_report("conf option %s has no value", name);
+            error_setg(errp, "conf option %s has no value", name);
             ret = -EINVAL;
             break;
         }
 
         ret = qemu_rbd_next_tok(value, sizeof(value), p,
-                                ':', "conf option value", &p);
+                                ':', "conf option value", &p, errp);
         if (ret < 0) {
             break;
         }
@@ -263,7 +270,7 @@ static int qemu_rbd_set_conf(rados_t cluster, const char *conf)
         if (strcmp(name, "conf") == 0) {
             ret = rados_conf_read_file(cluster, value);
             if (ret < 0) {
-                error_report("error reading conf file %s", value);
+                error_setg(errp, "error reading conf file %s", value);
                 break;
             }
         } else if (strcmp(name, "id") == 0) {
@@ -271,7 +278,7 @@ static int qemu_rbd_set_conf(rados_t cluster, const char *conf)
         } else {
             ret = rados_conf_set(cluster, name, value);
             if (ret < 0) {
-                error_report("invalid conf option %s", name);
+                error_setg(errp, "invalid conf option %s", name);
                 ret = -EINVAL;
                 break;
             }
@@ -285,6 +292,7 @@ static int qemu_rbd_set_conf(rados_t cluster, const char *conf)
 static int qemu_rbd_create(const char *filename, QEMUOptionParameter *options,
                            Error **errp)
 {
+    Error *local_err = NULL;
     int64_t bytes = 0;
     int64_t objsize;
     int obj_order = 0;
@@ -301,7 +309,8 @@ static int qemu_rbd_create(const char *filename, QEMUOptionParameter *options,
     if (qemu_rbd_parsename(filename, pool, sizeof(pool),
                            snap_buf, sizeof(snap_buf),
                            name, sizeof(name),
-                           conf, sizeof(conf)) < 0) {
+                           conf, sizeof(conf), &local_err) < 0) {
+        error_propagate(errp, local_err);
         return -EINVAL;
     }
 
@@ -313,11 +322,11 @@ static int qemu_rbd_create(const char *filename, QEMUOptionParameter *options,
             if (options->value.n) {
                 objsize = options->value.n;
                 if ((objsize - 1) & objsize) {    /* not a power of 2? */
-                    error_report("obj size needs to be power of 2");
+                    error_setg(errp, "obj size needs to be power of 2");
                     return -EINVAL;
                 }
                 if (objsize < 4096) {
-                    error_report("obj size too small");
+                    error_setg(errp, "obj size too small");
                     return -EINVAL;
                 }
                 obj_order = ffs(objsize) - 1;
@@ -328,7 +337,7 @@ static int qemu_rbd_create(const char *filename, QEMUOptionParameter *options,
 
     clientname = qemu_rbd_parse_clientname(conf, clientname_buf);
     if (rados_create(&cluster, clientname) < 0) {
-        error_report("error initializing");
+        error_setg(errp, "error initializing");
         return -EIO;
     }
 
@@ -338,20 +347,20 @@ static int qemu_rbd_create(const char *filename, QEMUOptionParameter *options,
     }
 
     if (conf[0] != '\0' &&
-        qemu_rbd_set_conf(cluster, conf) < 0) {
-        error_report("error setting config options");
+        qemu_rbd_set_conf(cluster, conf, &local_err) < 0) {
         rados_shutdown(cluster);
+        error_propagate(errp, local_err);
         return -EIO;
     }
 
     if (rados_connect(cluster) < 0) {
-        error_report("error connecting");
+        error_setg(errp, "error connecting");
         rados_shutdown(cluster);
         return -EIO;
     }
 
     if (rados_ioctx_create(cluster, pool, &io_ctx) < 0) {
-        error_report("error opening pool %s", pool);
+        error_setg(errp, "error opening pool %s", pool);
         rados_shutdown(cluster);
         return -EIO;
     }
@@ -441,8 +450,7 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags,
     opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
     qemu_opts_absorb_qdict(opts, options, &local_err);
     if (local_err) {
-        qerror_report_err(local_err);
-        error_free(local_err);
+        error_propagate(errp, local_err);
         qemu_opts_del(opts);
         return -EINVAL;
     }
@@ -452,7 +460,7 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags,
     if (qemu_rbd_parsename(filename, pool, sizeof(pool),
                            snap_buf, sizeof(snap_buf),
                            s->name, sizeof(s->name),
-                           conf, sizeof(conf)) < 0) {
+                           conf, sizeof(conf), errp) < 0) {
         r = -EINVAL;
         goto failed_opts;
     }
@@ -460,7 +468,7 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags,
     clientname = qemu_rbd_parse_clientname(conf, clientname_buf);
     r = rados_create(&s->cluster, clientname);
     if (r < 0) {
-        error_report("error initializing");
+        error_setg(&local_err, "error initializing");
         goto failed_opts;
     }
 
@@ -488,28 +496,27 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags,
     }
 
     if (conf[0] != '\0') {
-        r = qemu_rbd_set_conf(s->cluster, conf);
+        r = qemu_rbd_set_conf(s->cluster, conf, errp);
         if (r < 0) {
-            error_report("error setting config options");
             goto failed_shutdown;
         }
     }
 
     r = rados_connect(s->cluster);
     if (r < 0) {
-        error_report("error connecting");
+        error_setg(&local_err, "error connecting");
         goto failed_shutdown;
     }
 
     r = rados_ioctx_create(s->cluster, pool, &s->io_ctx);
     if (r < 0) {
-        error_report("error opening pool %s", pool);
+        error_setg(&local_err, "error opening pool %s", pool);
         goto failed_shutdown;
     }
 
     r = rbd_open(s->io_ctx, s->name, &s->image, s->snap);
     if (r < 0) {
-        error_report("error reading header from %s", s->name);
+        error_setg(&local_err, "error reading header from %s", s->name);
         goto failed_open;
     }
 
-- 
1.9.0

  parent reply	other threads:[~2014-05-23 15:43 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-23 15:41 [Qemu-devel] [PULL 00/33] Block patches Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 01/33] qemu-iotests: Handle cache mode option in 091 Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 02/33] QemuOpt: add unit tests Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 03/33] qcow2: Fix memory leak in COW error path Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 04/33] aio: Fix use-after-free in cancellation path Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 05/33] iotests: Use _img_info in test 089 Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 06/33] block: Add BlockOpType enum Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 07/33] block: Introduce op_blockers to BlockDriverState Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 08/33] block: Replace in_use with operation blocker Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 09/33] block: Move op_blocker check from block_job_create to its caller Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 10/33] block: Add bdrv_set_backing_hd() Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 11/33] block: Use bdrv_set_backing_hd everywhere Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 12/33] block: Add backing_blocker in BlockDriverState Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 13/33] block: Drop redundant bdrv_refresh_limits Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 14/33] docs: Define refcount_bits value Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 15/33] blockdev: Don't use qerror_report_err() in drive_init() Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 16/33] blockdev: Don't use qerror_report() in do_drive_del() Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 17/33] qemu-nbd: Don't use qerror_report() Stefan Hajnoczi
2014-05-23 15:41 ` Stefan Hajnoczi [this message]
2014-05-23 15:41 ` [Qemu-devel] [PULL 19/33] block/ssh: Drop superfluous libssh2_session_last_errno() calls Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 20/33] block/ssh: Propagate errors through check_host_key() Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 21/33] block/ssh: Propagate errors through authenticate() Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 22/33] block/ssh: Propagate errors through connect_to_ssh() Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 23/33] block/ssh: Propagate errors to open and create methods Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 24/33] block/vvfat: Propagate errors through enable_write_target() Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 25/33] block/vvfat: Propagate errors through init_directories() Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 26/33] block/sheepdog: Propagate errors through connect_to_sdog() Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 27/33] block/sheepdog: Propagate errors through get_sheep_fd() Stefan Hajnoczi
2014-05-23 15:42 ` [Qemu-devel] [PULL 28/33] block/sheepdog: Propagate errors through sd_prealloc() Stefan Hajnoczi
2014-05-23 15:42 ` [Qemu-devel] [PULL 29/33] block/sheepdog: Propagate errors through do_sd_create() Stefan Hajnoczi
2014-05-23 15:42 ` [Qemu-devel] [PULL 30/33] block/sheepdog: Propagate errors through find_vdi_name() Stefan Hajnoczi
2014-05-23 15:42 ` [Qemu-devel] [PULL 31/33] block/sheepdog: Propagate errors to open and create methods Stefan Hajnoczi
2014-05-23 15:42 ` [Qemu-devel] [PULL 32/33] block/sheepdog: Fix silent sd_open(), sd_create() failures Stefan Hajnoczi
2014-05-23 15:42 ` [Qemu-devel] [PULL 33/33] block/sheepdog: Don't use qerror_report() Stefan Hajnoczi

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=1400859725-31879-19-git-send-email-stefanha@redhat.com \
    --to=stefanha@redhat.com \
    --cc=armbru@redhat.com \
    --cc=josh.durgin@inktank.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /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).