cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-block-Activate-recursively-even-for-already-active-n.patch

22c213
From 0ef6691ce8964bb2bbd677756c4e594793ca3ad8 Mon Sep 17 00:00:00 2001
22c213
From: Kevin Wolf <kwolf@redhat.com>
22c213
Date: Fri, 7 Feb 2020 11:24:01 +0000
22c213
Subject: [PATCH 04/18] block: Activate recursively even for already active
22c213
 nodes
22c213
22c213
RH-Author: Kevin Wolf <kwolf@redhat.com>
22c213
Message-id: <20200207112404.25198-4-kwolf@redhat.com>
22c213
Patchwork-id: 93749
22c213
O-Subject: [RHEL-AV-8.2.0 qemu-kvm PATCH v2 3/6] block: Activate recursively even for already active nodes
22c213
Bugzilla: 1781637
22c213
RH-Acked-by: Sergio Lopez Pascual <slp@redhat.com>
22c213
RH-Acked-by: Max Reitz <mreitz@redhat.com>
22c213
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
22c213
22c213
bdrv_invalidate_cache_all() assumes that all nodes in a given subtree
22c213
are either active or inactive when it starts. Therefore, as soon as it
22c213
arrives at an already active node, it stops.
22c213
22c213
However, this assumption is wrong. For example, it's possible to take a
22c213
snapshot of an inactive node, which results in an active overlay over an
22c213
inactive backing file. The active overlay is probably also the root node
22c213
of an inactive BlockBackend (blk->disable_perm == true).
22c213
22c213
In this case, bdrv_invalidate_cache_all() does not need to do anything
22c213
to activate the overlay node, but it still needs to recurse into the
22c213
children and the parents to make sure that after returning success,
22c213
really everything is activated.
22c213
22c213
Cc: qemu-stable@nongnu.org
22c213
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
22c213
Reviewed-by: Max Reitz <mreitz@redhat.com>
22c213
(cherry picked from commit 7bb4941ace471fc7dd6ded4749b95b9622baa6ed)
22c213
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
22c213
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
22c213
---
22c213
 block.c | 50 ++++++++++++++++++++++++--------------------------
22c213
 1 file changed, 24 insertions(+), 26 deletions(-)
22c213
22c213
diff --git a/block.c b/block.c
22c213
index 473eb6e..2e5e8b6 100644
22c213
--- a/block.c
22c213
+++ b/block.c
22c213
@@ -5335,10 +5335,6 @@ static void coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs,
22c213
         return;
22c213
     }
22c213
 
22c213
-    if (!(bs->open_flags & BDRV_O_INACTIVE)) {
22c213
-        return;
22c213
-    }
22c213
-
22c213
     QLIST_FOREACH(child, &bs->children, next) {
22c213
         bdrv_co_invalidate_cache(child->bs, &local_err);
22c213
         if (local_err) {
22c213
@@ -5360,34 +5356,36 @@ static void coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs,
22c213
      * just keep the extended permissions for the next time that an activation
22c213
      * of the image is tried.
22c213
      */
22c213
-    bs->open_flags &= ~BDRV_O_INACTIVE;
22c213
-    bdrv_get_cumulative_perm(bs, &perm, &shared_perm);
22c213
-    ret = bdrv_check_perm(bs, NULL, perm, shared_perm, NULL, NULL, &local_err);
22c213
-    if (ret < 0) {
22c213
-        bs->open_flags |= BDRV_O_INACTIVE;
22c213
-        error_propagate(errp, local_err);
22c213
-        return;
22c213
-    }
22c213
-    bdrv_set_perm(bs, perm, shared_perm);
22c213
-
22c213
-    if (bs->drv->bdrv_co_invalidate_cache) {
22c213
-        bs->drv->bdrv_co_invalidate_cache(bs, &local_err);
22c213
-        if (local_err) {
22c213
+    if (bs->open_flags & BDRV_O_INACTIVE) {
22c213
+        bs->open_flags &= ~BDRV_O_INACTIVE;
22c213
+        bdrv_get_cumulative_perm(bs, &perm, &shared_perm);
22c213
+        ret = bdrv_check_perm(bs, NULL, perm, shared_perm, NULL, NULL, &local_err);
22c213
+        if (ret < 0) {
22c213
             bs->open_flags |= BDRV_O_INACTIVE;
22c213
             error_propagate(errp, local_err);
22c213
             return;
22c213
         }
22c213
-    }
22c213
+        bdrv_set_perm(bs, perm, shared_perm);
22c213
 
22c213
-    FOR_EACH_DIRTY_BITMAP(bs, bm) {
22c213
-        bdrv_dirty_bitmap_skip_store(bm, false);
22c213
-    }
22c213
+        if (bs->drv->bdrv_co_invalidate_cache) {
22c213
+            bs->drv->bdrv_co_invalidate_cache(bs, &local_err);
22c213
+            if (local_err) {
22c213
+                bs->open_flags |= BDRV_O_INACTIVE;
22c213
+                error_propagate(errp, local_err);
22c213
+                return;
22c213
+            }
22c213
+        }
22c213
 
22c213
-    ret = refresh_total_sectors(bs, bs->total_sectors);
22c213
-    if (ret < 0) {
22c213
-        bs->open_flags |= BDRV_O_INACTIVE;
22c213
-        error_setg_errno(errp, -ret, "Could not refresh total sector count");
22c213
-        return;
22c213
+        FOR_EACH_DIRTY_BITMAP(bs, bm) {
22c213
+            bdrv_dirty_bitmap_skip_store(bm, false);
22c213
+        }
22c213
+
22c213
+        ret = refresh_total_sectors(bs, bs->total_sectors);
22c213
+        if (ret < 0) {
22c213
+            bs->open_flags |= BDRV_O_INACTIVE;
22c213
+            error_setg_errno(errp, -ret, "Could not refresh total sector count");
22c213
+            return;
22c213
+        }
22c213
     }
22c213
 
22c213
     QLIST_FOREACH(parent, &bs->parents, next_parent) {
22c213
-- 
22c213
1.8.3.1
22c213