Blame SOURCES/kvm-qemu-io-Drop-write-permissions-before-read-only-reop.patch

4a2fec
From 1c4c0df8838e32c524c86ae7ab0fcdc56cb0cad0 Mon Sep 17 00:00:00 2001
4a2fec
From: Kevin Wolf <kwolf@redhat.com>
4a2fec
Date: Mon, 4 Dec 2017 12:10:00 +0100
4a2fec
Subject: [PATCH 29/36] qemu-io: Drop write permissions before read-only reopen
4a2fec
4a2fec
RH-Author: Kevin Wolf <kwolf@redhat.com>
4a2fec
Message-id: <20171204121007.12964-2-kwolf@redhat.com>
4a2fec
Patchwork-id: 78106
4a2fec
O-Subject: [RHV-7.5 qemu-kvm-rhev PATCH v2 1/8] qemu-io: Drop write permissions before read-only reopen
4a2fec
Bugzilla: 1492178
4a2fec
RH-Acked-by: Fam Zheng <famz@redhat.com>
4a2fec
RH-Acked-by: Max Reitz <mreitz@redhat.com>
4a2fec
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
4a2fec
4a2fec
qemu-io provides a 'reopen' command that allows switching from writable
4a2fec
to read-only access. We need to make sure that we don't try to keep
4a2fec
write permissions to a BlockBackend that becomes read-only, otherwise
4a2fec
things are going to fail.
4a2fec
4a2fec
This requires a bdrv_drain() call because otherwise in-flight AIO
4a2fec
write requests could issue new internal requests while the permission
4a2fec
has already gone away, which would cause assertion failures. Draining
4a2fec
the queue doesn't break AIO requests in any new way, bdrv_reopen() would
4a2fec
drain it anyway only a few lines later.
4a2fec
4a2fec
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
4a2fec
Reviewed-by: Fam Zheng <famz@redhat.com>
4a2fec
(cherry picked from commit f3adefb2cea1c63b7b198acaef5e40eb4b2d2d39)
4a2fec
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
4a2fec
---
4a2fec
 qemu-io-cmds.c             | 12 ++++++++++++
4a2fec
 tests/qemu-iotests/187.out |  2 +-
4a2fec
 2 files changed, 13 insertions(+), 1 deletion(-)
4a2fec
4a2fec
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
4a2fec
index 2811a89..3727fb4 100644
4a2fec
--- a/qemu-io-cmds.c
4a2fec
+++ b/qemu-io-cmds.c
4a2fec
@@ -2010,6 +2010,18 @@ static int reopen_f(BlockBackend *blk, int argc, char **argv)
4a2fec
         return 0;
4a2fec
     }
4a2fec
 
4a2fec
+    if (!(flags & BDRV_O_RDWR)) {
4a2fec
+        uint64_t orig_perm, orig_shared_perm;
4a2fec
+
4a2fec
+        bdrv_drain(bs);
4a2fec
+
4a2fec
+        blk_get_perm(blk, &orig_perm, &orig_shared_perm);
4a2fec
+        blk_set_perm(blk,
4a2fec
+                     orig_perm & ~(BLK_PERM_WRITE | BLK_PERM_WRITE_UNCHANGED),
4a2fec
+                     orig_shared_perm,
4a2fec
+                     &error_abort);
4a2fec
+    }
4a2fec
+
4a2fec
     qopts = qemu_opts_find(&reopen_opts, NULL);
4a2fec
     opts = qopts ? qemu_opts_to_qdict(qopts, NULL) : NULL;
4a2fec
     qemu_opts_reset(&reopen_opts);
4a2fec
diff --git a/tests/qemu-iotests/187.out b/tests/qemu-iotests/187.out
4a2fec
index 68fb944..30b987f 100644
4a2fec
--- a/tests/qemu-iotests/187.out
4a2fec
+++ b/tests/qemu-iotests/187.out
4a2fec
@@ -12,7 +12,7 @@ Start from read-write
4a2fec
 
4a2fec
 wrote 65536/65536 bytes at offset 0
4a2fec
 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
4a2fec
-write failed: Operation not permitted
4a2fec
+Block node is read-only
4a2fec
 wrote 65536/65536 bytes at offset 0
4a2fec
 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
4a2fec
 *** done
4a2fec
-- 
4a2fec
1.8.3.1
4a2fec