Blame SOURCES/kvm-block-Always-abort-reopen-after-prepare-succeeded.patch

7711c0
From 168f27ca545f530ac694ed596bdafc8fa3c26860 Mon Sep 17 00:00:00 2001
7711c0
From: Kevin Wolf <kwolf@redhat.com>
7711c0
Date: Fri, 15 Mar 2019 18:10:00 +0100
7711c0
Subject: [PATCH 004/163] block: Always abort reopen after prepare succeeded
7711c0
7711c0
RH-Author: Kevin Wolf <kwolf@redhat.com>
7711c0
Message-id: <20190315181010.14964-5-kwolf@redhat.com>
7711c0
Patchwork-id: 84881
7711c0
O-Subject: [RHEL-7.7 qemu-kvm-rhev PATCH 04/14] block: Always abort reopen after prepare succeeded
7711c0
Bugzilla: 1685989
7711c0
RH-Acked-by: John Snow <jsnow@redhat.com>
7711c0
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
7711c0
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
7711c0
7711c0
From: Max Reitz <mreitz@redhat.com>
7711c0
7711c0
bdrv_reopen_multiple() does not invoke bdrv_reopen_abort() for the
7711c0
element of the reopen queue for which bdrv_reopen_prepare() failed,
7711c0
because it assumes that the prepare function will have rolled back all
7711c0
changes already.
7711c0
7711c0
However, bdrv_reopen_prepare() does not do this in every case: It may
7711c0
notice an error after BlockDriver.bdrv_reopen_prepare() succeeded, and
7711c0
it will not invoke BlockDriver.bdrv_reopen_abort() then; and neither
7711c0
will bdrv_reopen_multiple(), as explained above.
7711c0
7711c0
This is wrong because we must always call .bdrv_reopen_commit() or
7711c0
.bdrv_reopen_abort() after .bdrv_reopen_prepare() has succeeded.
7711c0
Otherwise, the block driver has no chance to undo what it has done in
7711c0
its implementation of .bdrv_reopen_prepare().
7711c0
7711c0
To fix this, bdrv_reopen_prepare() has to call .bdrv_reopen_abort() if
7711c0
it wants to return an error after .bdrv_reopen_prepare() has succeeded.
7711c0
7711c0
Signed-off-by: Max Reitz <mreitz@redhat.com>
7711c0
Reviewed-by: Alberto Garcia <berto@igalia.com>
7711c0
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
7711c0
(cherry picked from commit 9ad08c44566bf4466c6263c71d43e9f7a354d4ba)
7711c0
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
7711c0
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
7711c0
---
7711c0
 block.c | 12 ++++++++++++
7711c0
 1 file changed, 12 insertions(+)
7711c0
7711c0
diff --git a/block.c b/block.c
7711c0
index c3148cc..2f1b4d1 100644
7711c0
--- a/block.c
7711c0
+++ b/block.c
7711c0
@@ -3191,6 +3191,7 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue,
7711c0
     QemuOpts *opts;
7711c0
     const char *value;
7711c0
     bool read_only;
7711c0
+    bool drv_prepared = false;
7711c0
 
7711c0
     assert(reopen_state != NULL);
7711c0
     assert(reopen_state->bs->drv != NULL);
7711c0
@@ -3260,6 +3261,8 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue,
7711c0
         goto error;
7711c0
     }
7711c0
 
7711c0
+    drv_prepared = true;
7711c0
+
7711c0
     /* Options that are not handled are only okay if they are unchanged
7711c0
      * compared to the old state. It is expected that some options are only
7711c0
      * used for the initial open, but not reopen (e.g. filename) */
7711c0
@@ -3303,6 +3306,15 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue,
7711c0
     ret = 0;
7711c0
 
7711c0
 error:
7711c0
+    if (ret < 0 && drv_prepared) {
7711c0
+        /* drv->bdrv_reopen_prepare() has succeeded, so we need to
7711c0
+         * call drv->bdrv_reopen_abort() before signaling an error
7711c0
+         * (bdrv_reopen_multiple() will not call bdrv_reopen_abort()
7711c0
+         * when the respective bdrv_reopen_prepare() has failed) */
7711c0
+        if (drv->bdrv_reopen_abort) {
7711c0
+            drv->bdrv_reopen_abort(reopen_state);
7711c0
+        }
7711c0
+    }
7711c0
     qemu_opts_del(opts);
7711c0
     return ret;
7711c0
 }
7711c0
-- 
7711c0
1.8.3.1
7711c0