summaryrefslogtreecommitdiffstats
path: root/block.c
diff options
context:
space:
mode:
authorAlberto Garcia2018-11-12 15:00:33 +0100
committerKevin Wolf2018-12-14 11:55:01 +0100
commit6e1000a863f9dcdb4a6f51cd7cd0782f23120ba5 (patch)
tree55e2e61726db55960febfee3d3d85de06831fbae /block.c
parentfile-posix: Avoid aio_worker() for QEMU_AIO_IOCTL (diff)
downloadqemu-6e1000a863f9dcdb4a6f51cd7cd0782f23120ba5.tar.gz
qemu-6e1000a863f9dcdb4a6f51cd7cd0782f23120ba5.tar.xz
qemu-6e1000a863f9dcdb4a6f51cd7cd0782f23120ba5.zip
block: Add bdrv_reopen_set_read_only()
Most callers of bdrv_reopen() only use it to switch a BlockDriverState between read-only and read-write, so this patch adds a new function that does just that. We also want to get rid of the flags parameter in the bdrv_reopen() API, so this function sets the "read-only" option and passes the original flags (which will then be updated in bdrv_reopen_prepare()). Signed-off-by: Alberto Garcia <berto@igalia.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block.c')
-rw-r--r--block.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/block.c b/block.c
index 811239ca23..7178872560 100644
--- a/block.c
+++ b/block.c
@@ -3146,6 +3146,23 @@ int bdrv_reopen(BlockDriverState *bs, int bdrv_flags, Error **errp)
return ret;
}
+int bdrv_reopen_set_read_only(BlockDriverState *bs, bool read_only,
+ Error **errp)
+{
+ int ret;
+ BlockReopenQueue *queue;
+ QDict *opts = qdict_new();
+
+ qdict_put_bool(opts, BDRV_OPT_READ_ONLY, read_only);
+
+ bdrv_subtree_drained_begin(bs);
+ queue = bdrv_reopen_queue(NULL, bs, opts, bdrv_get_flags(bs));
+ ret = bdrv_reopen_multiple(bdrv_get_aio_context(bs), queue, errp);
+ bdrv_subtree_drained_end(bs);
+
+ return ret;
+}
+
static BlockReopenQueueEntry *find_parent_in_reopen_queue(BlockReopenQueue *q,
BdrvChild *c)
{