[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 12/24] qemu-io: Drop write permissions before read-on
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 12/24] qemu-io: Drop write permissions before read-only reopen |
Date: |
Tue, 26 Sep 2017 16:21:21 +0200 |
qemu-io provides a 'reopen' command that allows switching from writable
to read-only access. We need to make sure that we don't try to keep
write permissions to a BlockBackend that becomes read-only, otherwise
things are going to fail.
This requires a bdrv_drain() call because otherwise in-flight AIO
write requests could issue new internal requests while the permission
has already gone away, which would cause assertion failures. Draining
the queue doesn't break AIO requests in any new way, bdrv_reopen() would
drain it anyway only a few lines later.
Signed-off-by: Kevin Wolf <address@hidden>
Reviewed-by: Fam Zheng <address@hidden>
---
qemu-io-cmds.c | 12 ++++++++++++
tests/qemu-iotests/187.out | 2 +-
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
index 2811a89099..3727fb43f3 100644
--- a/qemu-io-cmds.c
+++ b/qemu-io-cmds.c
@@ -2010,6 +2010,18 @@ static int reopen_f(BlockBackend *blk, int argc, char
**argv)
return 0;
}
+ if (!(flags & BDRV_O_RDWR)) {
+ uint64_t orig_perm, orig_shared_perm;
+
+ bdrv_drain(bs);
+
+ blk_get_perm(blk, &orig_perm, &orig_shared_perm);
+ blk_set_perm(blk,
+ orig_perm & ~(BLK_PERM_WRITE | BLK_PERM_WRITE_UNCHANGED),
+ orig_shared_perm,
+ &error_abort);
+ }
+
qopts = qemu_opts_find(&reopen_opts, NULL);
opts = qopts ? qemu_opts_to_qdict(qopts, NULL) : NULL;
qemu_opts_reset(&reopen_opts);
diff --git a/tests/qemu-iotests/187.out b/tests/qemu-iotests/187.out
index 68fb944cd5..30b987f71f 100644
--- a/tests/qemu-iotests/187.out
+++ b/tests/qemu-iotests/187.out
@@ -12,7 +12,7 @@ Start from read-write
wrote 65536/65536 bytes at offset 0
64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
-write failed: Operation not permitted
+Block node is read-only
wrote 65536/65536 bytes at offset 0
64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
*** done
--
2.13.5
- [Qemu-devel] [PULL 00/24] Block layer patches, Kevin Wolf, 2017/09/26
- [Qemu-devel] [PULL 01/24] qemu-iotests: Add missing -machine accel=qtest, Kevin Wolf, 2017/09/26
- [Qemu-devel] [PULL 02/24] qemu-img: Clarify about relative backing file options, Kevin Wolf, 2017/09/26
- [Qemu-devel] [PULL 06/24] iotests: use -ccw on s390x for 051, Kevin Wolf, 2017/09/26
- [Qemu-devel] [PULL 08/24] iotests: Print full path of bad output if mismatch, Kevin Wolf, 2017/09/26
- [Qemu-devel] [PULL 05/24] iotests: use -ccw on s390x for 040, 139, and 182, Kevin Wolf, 2017/09/26
- [Qemu-devel] [PULL 03/24] file-posix: Clear out first sector in hdev_create, Kevin Wolf, 2017/09/26
- [Qemu-devel] [PULL 10/24] block/throttle-groups.c: allocate RestartData on the heap, Kevin Wolf, 2017/09/26
- [Qemu-devel] [PULL 13/24] block: Add reopen_queue to bdrv_child_perm(), Kevin Wolf, 2017/09/26
- [Qemu-devel] [PULL 12/24] qemu-io: Drop write permissions before read-only reopen,
Kevin Wolf <=
- [Qemu-devel] [PULL 09/24] throttle: Assert that bkt->max is valid in throttle_compute_wait(), Kevin Wolf, 2017/09/26
- [Qemu-devel] [PULL 07/24] iotests: use virtio aliases for 067, Kevin Wolf, 2017/09/26
- [Qemu-devel] [PULL 17/24] block: Fix permissions after bdrv_reopen(), Kevin Wolf, 2017/09/26
- [Qemu-devel] [PULL 18/24] qemu-iotests: Test change-backing-file command, Kevin Wolf, 2017/09/26
- [Qemu-devel] [PULL 04/24] docs: add qemu-block-drivers(7) man page, Kevin Wolf, 2017/09/26
- [Qemu-devel] [PULL 15/24] block: Base permissions on rw state after reopen, Kevin Wolf, 2017/09/26
- [Qemu-devel] [PULL 11/24] block: Clean up some bad code in the vvfat driver, Kevin Wolf, 2017/09/26
- [Qemu-devel] [PULL 14/24] block: Add reopen queue to bdrv_check_perm(), Kevin Wolf, 2017/09/26
- [Qemu-devel] [PULL 16/24] block: reopen: Queue children after their parents, Kevin Wolf, 2017/09/26
- [Qemu-devel] [PULL 19/24] iotests: fix 181: enable postcopy-ram capability on target, Kevin Wolf, 2017/09/26