qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org
Subject: [PULL 28/30] block: Activate recursively even for already active nodes
Date: Thu, 19 Dec 2019 18:24:39 +0100	[thread overview]
Message-ID: <20191219172441.7289-29-kwolf@redhat.com> (raw)
In-Reply-To: <20191219172441.7289-1-kwolf@redhat.com>

bdrv_invalidate_cache_all() assumes that all nodes in a given subtree
are either active or inactive when it starts. Therefore, as soon as it
arrives at an already active node, it stops.

However, this assumption is wrong. For example, it's possible to take a
snapshot of an inactive node, which results in an active overlay over an
inactive backing file. The active overlay is probably also the root node
of an inactive BlockBackend (blk->disable_perm == true).

In this case, bdrv_invalidate_cache_all() does not need to do anything
to activate the overlay node, but it still needs to recurse into the
children and the parents to make sure that after returning success,
really everything is activated.

Cc: qemu-stable@nongnu.org
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
---
 block.c | 50 ++++++++++++++++++++++++--------------------------
 1 file changed, 24 insertions(+), 26 deletions(-)

diff --git a/block.c b/block.c
index 73029fad64..1b6f7c86e8 100644
--- a/block.c
+++ b/block.c
@@ -5335,10 +5335,6 @@ static void coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs,
         return;
     }
 
-    if (!(bs->open_flags & BDRV_O_INACTIVE)) {
-        return;
-    }
-
     QLIST_FOREACH(child, &bs->children, next) {
         bdrv_co_invalidate_cache(child->bs, &local_err);
         if (local_err) {
@@ -5360,34 +5356,36 @@ static void coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs,
      * just keep the extended permissions for the next time that an activation
      * of the image is tried.
      */
-    bs->open_flags &= ~BDRV_O_INACTIVE;
-    bdrv_get_cumulative_perm(bs, &perm, &shared_perm);
-    ret = bdrv_check_perm(bs, NULL, perm, shared_perm, NULL, NULL, &local_err);
-    if (ret < 0) {
-        bs->open_flags |= BDRV_O_INACTIVE;
-        error_propagate(errp, local_err);
-        return;
-    }
-    bdrv_set_perm(bs, perm, shared_perm);
-
-    if (bs->drv->bdrv_co_invalidate_cache) {
-        bs->drv->bdrv_co_invalidate_cache(bs, &local_err);
-        if (local_err) {
+    if (bs->open_flags & BDRV_O_INACTIVE) {
+        bs->open_flags &= ~BDRV_O_INACTIVE;
+        bdrv_get_cumulative_perm(bs, &perm, &shared_perm);
+        ret = bdrv_check_perm(bs, NULL, perm, shared_perm, NULL, NULL, &local_err);
+        if (ret < 0) {
             bs->open_flags |= BDRV_O_INACTIVE;
             error_propagate(errp, local_err);
             return;
         }
-    }
+        bdrv_set_perm(bs, perm, shared_perm);
 
-    FOR_EACH_DIRTY_BITMAP(bs, bm) {
-        bdrv_dirty_bitmap_skip_store(bm, false);
-    }
+        if (bs->drv->bdrv_co_invalidate_cache) {
+            bs->drv->bdrv_co_invalidate_cache(bs, &local_err);
+            if (local_err) {
+                bs->open_flags |= BDRV_O_INACTIVE;
+                error_propagate(errp, local_err);
+                return;
+            }
+        }
 
-    ret = refresh_total_sectors(bs, bs->total_sectors);
-    if (ret < 0) {
-        bs->open_flags |= BDRV_O_INACTIVE;
-        error_setg_errno(errp, -ret, "Could not refresh total sector count");
-        return;
+        FOR_EACH_DIRTY_BITMAP(bs, bm) {
+            bdrv_dirty_bitmap_skip_store(bm, false);
+        }
+
+        ret = refresh_total_sectors(bs, bs->total_sectors);
+        if (ret < 0) {
+            bs->open_flags |= BDRV_O_INACTIVE;
+            error_setg_errno(errp, -ret, "Could not refresh total sector count");
+            return;
+        }
     }
 
     QLIST_FOREACH(parent, &bs->parents, next_parent) {
-- 
2.20.1



  parent reply	other threads:[~2019-12-19 17:46 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-19 17:24 [PULL 00/30] Block layer patches Kevin Wolf
2019-12-19 17:24 ` [PULL 01/30] iotests: Provide a function for checking the creation of huge files Kevin Wolf
2019-12-19 17:24 ` [PULL 02/30] iotests: Skip test 060 if it is not possible to create large files Kevin Wolf
2019-12-19 17:24 ` [PULL 03/30] iotests: Skip test 079 " Kevin Wolf
2019-12-19 17:24 ` [PULL 04/30] qapi: better document NVMe blockdev @device parameter Kevin Wolf
2019-12-19 17:24 ` [PULL 05/30] qemu-img: fix info --backing-chain --image-opts Kevin Wolf
2019-12-19 17:24 ` [PULL 06/30] block: Error out on image creation with conflicting size options Kevin Wolf
2019-12-19 17:24 ` [PULL 07/30] blockjob: Fix error message for negative speed Kevin Wolf
2019-12-19 17:24 ` [PULL 08/30] qcow2: Declare BDRV_REQ_NO_FALLBACK supported Kevin Wolf
2019-12-19 17:24 ` [PULL 09/30] iotests: Add qemu_io_log() Kevin Wolf
2019-12-19 17:24 ` [PULL 10/30] iotests: Fix timeout in run_job() Kevin Wolf
2019-12-19 17:24 ` [PULL 11/30] iotests: Support job-complete " Kevin Wolf
2019-12-19 17:24 ` [PULL 12/30] qcow2: Use offset_into_cluster() Kevin Wolf
2019-12-19 17:24 ` [PULL 13/30] MAINTAINERS: fix qcow2-bitmap.c under Dirty Bitmaps header Kevin Wolf
2019-12-19 17:24 ` [PULL 14/30] iotests: Add more "_require_drivers" checks to the shell-based tests Kevin Wolf
2019-12-19 17:24 ` [PULL 15/30] iotests/273: Filter format-specific information Kevin Wolf
2019-12-19 17:24 ` [PULL 16/30] iotests: Fix IMGOPTSSYNTAX for nbd Kevin Wolf
2019-12-19 17:24 ` [PULL 17/30] qcow2: Move error check of local_err near its assignment Kevin Wolf
2019-12-19 17:24 ` [PULL 18/30] iotests: Create VM.blockdev_create() Kevin Wolf
2019-12-19 17:24 ` [PULL 19/30] iotests: 255: Drop blockdev_create() Kevin Wolf
2019-12-19 17:24 ` [PULL 20/30] iotests: 206: Convert to VM.blockdev_create() Kevin Wolf
2019-12-19 17:24 ` [PULL 21/30] iotests: 210: " Kevin Wolf
2019-12-19 17:24 ` [PULL 22/30] iotests: 212: " Kevin Wolf
2019-12-19 17:24 ` [PULL 23/30] iotests: 213: " Kevin Wolf
2019-12-19 17:24 ` [PULL 24/30] iotests: 237: " Kevin Wolf
2019-12-19 17:24 ` [PULL 25/30] iotests: 266: " Kevin Wolf
2019-12-19 17:24 ` [PULL 26/30] iotests: 207: Remove duplication with VM.blockdev_create() Kevin Wolf
2019-12-19 17:24 ` [PULL 27/30] iotests: 211: " Kevin Wolf
2019-12-19 17:24 ` Kevin Wolf [this message]
2019-12-19 17:24 ` [PULL 29/30] hmp: Allow using qdev ID for qemu-io command Kevin Wolf
2019-12-19 17:24 ` [PULL 30/30] iotests: Test external snapshot with VM state Kevin Wolf
2020-01-03 14:29 ` [PULL 00/30] Block layer 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=20191219172441.7289-29-kwolf@redhat.com \
    --to=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 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).