diff mbox series

[v2,1/8] block: Update flags in bdrv_set_read_only()

Message ID 20181012115532.12645-2-kwolf@redhat.com
State New
Headers show
Series block: Add auto-read-only option | expand

Commit Message

Kevin Wolf Oct. 12, 2018, 11:55 a.m. UTC
To fully change the read-only state of a node, we must not only change
bs->read_only, but also update bs->open_flags.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block.c | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Eric Blake Oct. 12, 2018, 4:19 p.m. UTC | #1
On 10/12/18 6:55 AM, Kevin Wolf wrote:
> To fully change the read-only state of a node, we must not only change
> bs->read_only, but also update bs->open_flags.
> 
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
>   block.c | 7 +++++++
>   1 file changed, 7 insertions(+)

Reviewed-by: Eric Blake <eblake@redhat.com>

> 
> diff --git a/block.c b/block.c
> index 0d6e5f1a76..d7bd6d29b4 100644
> --- a/block.c
> +++ b/block.c
> @@ -281,6 +281,13 @@ int bdrv_set_read_only(BlockDriverState *bs, bool read_only, Error **errp)
>       }
>   
>       bs->read_only = read_only;
> +
> +    if (read_only) {
> +        bs->open_flags &= ~BDRV_O_RDWR;
> +    } else {
> +        bs->open_flags |= BDRV_O_RDWR;
> +    }
> +
>       return 0;
>   }
>   
>
Alberto Garcia Oct. 17, 2018, 9:02 a.m. UTC | #2
On Fri 12 Oct 2018 01:55:25 PM CEST, Kevin Wolf wrote:
> To fully change the read-only state of a node, we must not only change
> bs->read_only, but also update bs->open_flags.
>
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>

Reviewed-by: Alberto Garcia <berto@igalia.com>

Berto
diff mbox series

Patch

diff --git a/block.c b/block.c
index 0d6e5f1a76..d7bd6d29b4 100644
--- a/block.c
+++ b/block.c
@@ -281,6 +281,13 @@  int bdrv_set_read_only(BlockDriverState *bs, bool read_only, Error **errp)
     }
 
     bs->read_only = read_only;
+
+    if (read_only) {
+        bs->open_flags &= ~BDRV_O_RDWR;
+    } else {
+        bs->open_flags |= BDRV_O_RDWR;
+    }
+
     return 0;
 }