All of lore.kernel.org
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: qemu-block@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	Peter Maydell <peter.maydell@linaro.org>,
	qemu-devel@nongnu.org, Max Reitz <mreitz@redhat.com>
Subject: [PULL 16/17] block/backup-top: fix failure path
Date: Thu,  6 Feb 2020 13:51:31 +0100	[thread overview]
Message-ID: <20200206125132.594625-17-mreitz@redhat.com> (raw)
In-Reply-To: <20200206125132.594625-1-mreitz@redhat.com>

From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>

We can't access top after call bdrv_backup_top_drop, as it is already
freed at this time.

Also, no needs to unref target child by hand, it will be unrefed on
bdrv_close() automatically.

So, just do bdrv_backup_top_drop if append succeed and one bdrv_unref
otherwise.

Note, that in !appended case bdrv_unref(top) moved into drained section
on source. It doesn't really matter, but just for code simplicity.

Fixes: 7df7868b96404
Cc: qemu-stable@nongnu.org # v4.2.0
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Message-id: 20200121142802.21467-2-vsementsov@virtuozzo.com
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 block/backup-top.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/block/backup-top.c b/block/backup-top.c
index 9aed2eb4c0..fa78f3256d 100644
--- a/block/backup-top.c
+++ b/block/backup-top.c
@@ -190,6 +190,7 @@ BlockDriverState *bdrv_backup_top_append(BlockDriverState *source,
     BlockDriverState *top = bdrv_new_open_driver(&bdrv_backup_top_filter,
                                                  filter_node_name,
                                                  BDRV_O_RDWR, errp);
+    bool appended = false;
 
     if (!top) {
         return NULL;
@@ -212,8 +213,9 @@ BlockDriverState *bdrv_backup_top_append(BlockDriverState *source,
     bdrv_append(top, source, &local_err);
     if (local_err) {
         error_prepend(&local_err, "Cannot append backup-top filter: ");
-        goto append_failed;
+        goto fail;
     }
+    appended = true;
 
     /*
      * bdrv_append() finished successfully, now we can require permissions
@@ -224,14 +226,14 @@ BlockDriverState *bdrv_backup_top_append(BlockDriverState *source,
     if (local_err) {
         error_prepend(&local_err,
                       "Cannot set permissions for backup-top filter: ");
-        goto failed_after_append;
+        goto fail;
     }
 
     state->bcs = block_copy_state_new(top->backing, state->target,
                                       cluster_size, write_flags, &local_err);
     if (local_err) {
         error_prepend(&local_err, "Cannot create block-copy-state: ");
-        goto failed_after_append;
+        goto fail;
     }
     *bcs = state->bcs;
 
@@ -239,14 +241,15 @@ BlockDriverState *bdrv_backup_top_append(BlockDriverState *source,
 
     return top;
 
-failed_after_append:
-    state->active = false;
-    bdrv_backup_top_drop(top);
+fail:
+    if (appended) {
+        state->active = false;
+        bdrv_backup_top_drop(top);
+    } else {
+        bdrv_unref(top);
+    }
 
-append_failed:
     bdrv_drained_end(source);
-    bdrv_unref_child(top, state->target);
-    bdrv_unref(top);
     error_propagate(errp, local_err);
 
     return NULL;
-- 
2.24.1



  parent reply	other threads:[~2020-02-06 13:01 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-06 12:51 [PULL 00/17] Block patches Max Reitz
2020-02-06 12:51 ` [PULL 01/17] qcow2: Assert that host cluster offsets fit in L2 table entries Max Reitz
2020-02-06 12:51 ` [PULL 02/17] block: Use a GString in bdrv_perm_names() Max Reitz
2020-02-06 12:51 ` [PULL 03/17] block: fix memleaks in bdrv_refresh_filename Max Reitz
2020-02-06 12:51 ` [PULL 04/17] qcow2: Use a GString in report_unsupported_feature() Max Reitz
2020-02-06 12:51 ` [PULL 05/17] iotests: remove 'linux' from default supported platforms Max Reitz
2020-02-06 12:51 ` [PULL 06/17] iotests: Test 041 only works on certain systems Max Reitz
2020-02-06 12:51 ` [PULL 07/17] iotests: Test 183 does not work on macOS and OpenBSD Max Reitz
2020-02-06 12:51 ` [PULL 08/17] iotests: Check for the availability of the required devices in 267 and 127 Max Reitz
2020-02-06 12:51 ` [PULL 09/17] iotests: Skip Python-based tests if QEMU does not support virtio-blk Max Reitz
2020-02-06 12:51 ` [PULL 10/17] iotests: Enable more tests in the 'auto' group to improve test coverage Max Reitz
2020-02-06 12:51 ` [PULL 11/17] qcow2: Don't round the L1 table allocation up to the sector size Max Reitz
2020-02-06 12:51 ` [PULL 12/17] qcow2: Tighten cluster_offset alignment assertions Max Reitz
2020-02-06 12:51 ` [PULL 13/17] qcow2: Use bs->bl.request_alignment when updating an L1 entry Max Reitz
2020-02-06 12:51 ` [PULL 14/17] qcow2: Don't require aligned offsets in qcow2_co_copy_range_from() Max Reitz
2020-02-06 12:51 ` [PULL 15/17] qcow2: Use BDRV_SECTOR_SIZE instead of the hardcoded value Max Reitz
2020-02-06 12:51 ` Max Reitz [this message]
2020-02-06 12:51 ` [PULL 17/17] iotests: add test for backup-top failure on permission activation Max Reitz
2020-02-06 18:58 ` [PULL 00/17] Block patches Peter Maydell

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=20200206125132.594625-17-mreitz@redhat.com \
    --to=mreitz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-block@nongnu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.