qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Chen Gang <gang.chen.5i5j@gmail.com>
To: Kevin Wolf <kwolf@redhat.com>,
	stefanha@redhat.com, Michael Tokarev <mjt@tls.msk.ru>,
	mreitz@redhat.com, eblake@redhat.com, famz@redhat.com
Cc: qemu-trivial@nongnu.org, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH trivial v2] block.c: Add return value for bdrv_append_temp_snapshot() to avoid incorrect failure processing issue
Date: Mon, 23 Jun 2014 23:28:23 +0800	[thread overview]
Message-ID: <53A84797.9040304@gmail.com> (raw)

When failure occurs, 'ret' need be set, or may return 0 to indicate success.
And error_propagate() also need be called only one time within a function.

It is abnormal to prevent bdrv_append_temp_snapshot() return value but still
set errp when error occurs -- although it contents return value internally.

So let bdrv_append_temp_snapshot() internal return value outside, and let
all things normal, then fix the issue too.


Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
---
 block.c               | 7 ++++---
 include/block/block.h | 2 +-
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/block.c b/block.c
index 74af8d7..5e4fb60 100644
--- a/block.c
+++ b/block.c
@@ -1240,7 +1240,7 @@ done:
     return ret;
 }
 
-void bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp)
+int bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp)
 {
     /* TODO: extra byte is a hack to ensure MAX_PATH space on Windows. */
     char *tmp_filename = g_malloc0(PATH_MAX + 1);
@@ -1258,6 +1258,7 @@ void bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp)
     /* Get the required size from the image */
     total_size = bdrv_getlength(bs);
     if (total_size < 0) {
+        ret = total_size;
         error_setg_errno(errp, -total_size, "Could not get image size");
         goto out;
     }
@@ -1304,6 +1305,7 @@ void bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp)
 
 out:
     g_free(tmp_filename);
+    return ret;
 }
 
 static QDict *parse_json_filename(const char *filename, Error **errp)
@@ -1495,9 +1497,8 @@ int bdrv_open(BlockDriverState **pbs, const char *filename,
     /* For snapshot=on, create a temporary qcow2 overlay. bs points to the
      * temporary snapshot afterwards. */
     if (snapshot_flags) {
-        bdrv_append_temp_snapshot(bs, snapshot_flags, &local_err);
+        ret = bdrv_append_temp_snapshot(bs, snapshot_flags, &local_err);
         if (local_err) {
-            error_propagate(errp, local_err);
             goto close_and_fail;
         }
     }
diff --git a/include/block/block.h b/include/block/block.h
index f15b99b..7b3381c 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -217,7 +217,7 @@ int bdrv_open_image(BlockDriverState **pbs, const char *filename,
                     bool allow_none, Error **errp);
 void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd);
 int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp);
-void bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp);
+int bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp);
 int bdrv_open(BlockDriverState **pbs, const char *filename,
               const char *reference, QDict *options, int flags,
               BlockDriver *drv, Error **errp);
-- 
1.7.11.7

             reply	other threads:[~2014-06-23 15:28 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-23 15:28 Chen Gang [this message]
2014-06-24  2:25 ` [Qemu-devel] [PATCH trivial v2] block.c: Add return value for bdrv_append_temp_snapshot() to avoid incorrect failure processing issue Fam Zheng
2014-06-24  2:32   ` Chen Gang
2014-06-24 10:46 ` Kevin Wolf
2014-06-24 11:01   ` Markus Armbruster
2014-06-24 16:00     ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
2014-06-25 22:13       ` Chen Gang
2014-06-27 11:50     ` [Qemu-devel] " Stefan Hajnoczi
2014-06-27 17:21 ` Kevin Wolf

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=53A84797.9040304@gmail.com \
    --to=gang.chen.5i5j@gmail.com \
    --cc=eblake@redhat.com \
    --cc=famz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mjt@tls.msk.ru \
    --cc=mreitz@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@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).