diff mbox series

[02/14] block: Add bdrv_reopen_set_read_only()

Message ID 23f88429b3135b18abdc8643fb5cc35a6dd5d912.1537367701.git.berto@igalia.com
State New
Headers show
Series Don't pass flags to bdrv_reopen_queue() | expand

Commit Message

Alberto Garcia Sept. 19, 2018, 2:47 p.m. UTC
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>
---
 block.c               | 17 +++++++++++++++++
 include/block/block.h |  2 ++
 2 files changed, 19 insertions(+)

Comments

Max Reitz Oct. 8, 2018, 12:55 a.m. UTC | #1
On 19.09.18 16:47, Alberto Garcia wrote:
> 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>
> ---
>  block.c               | 17 +++++++++++++++++
>  include/block/block.h |  2 ++
>  2 files changed, 19 insertions(+)

Reviewed-by: Max Reitz <mreitz@redhat.com>
diff mbox series

Patch

diff --git a/block.c b/block.c
index d79b6cdc73..e023945c8e 100644
--- a/block.c
+++ b/block.c
@@ -3106,6 +3106,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)
 {
diff --git a/include/block/block.h b/include/block/block.h
index a49a027c54..47ee32512f 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -302,6 +302,8 @@  BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue,
                                     QDict *options, int flags);
 int bdrv_reopen_multiple(AioContext *ctx, BlockReopenQueue *bs_queue, Error **errp);
 int bdrv_reopen(BlockDriverState *bs, int bdrv_flags, Error **errp);
+int bdrv_reopen_set_read_only(BlockDriverState *bs, bool read_only,
+                              Error **errp);
 int bdrv_reopen_prepare(BDRVReopenState *reopen_state,
                         BlockReopenQueue *queue, Error **errp);
 void bdrv_reopen_commit(BDRVReopenState *reopen_state);