diff options
author | Kevin Wolf <kwolf@redhat.com> | 2017-09-22 14:50:12 +0200 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2017-09-26 14:46:23 +0200 |
commit | f3adefb2cea1c63b7b198acaef5e40eb4b2d2d39 (patch) | |
tree | 38b95ac286ddedae55d3b540c0a52db6c1b6984f /qemu-io-cmds.c | |
parent | 7a6ab45e19b615b9285b9cfa2bbc1fee012bc8d7 (diff) |
qemu-io: Drop write permissions before read-only reopen
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 <kwolf@redhat.com>
Reviewed-by: Fam Zheng <famz@redhat.com>
Diffstat (limited to 'qemu-io-cmds.c')
-rw-r--r-- | qemu-io-cmds.c | 12 |
1 files changed, 12 insertions, 0 deletions
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); |