diff mbox series

block: Apply auto-read-only for ro-whitelist drivers

Message ID 20190122121926.25554-1-kwolf@redhat.com
State New
Headers show
Series block: Apply auto-read-only for ro-whitelist drivers | expand

Commit Message

Kevin Wolf Jan. 22, 2019, 12:19 p.m. UTC
If QEMU was configured with a driver in --block-drv-ro-whitelist, trying
to use that driver read-write resulted in an error message even if
auto-read-only=on was set.

Consider auto-read-only=on for the whitelist checking and use it to
automatically degrade to read-only for block drivers on the read-only
whitelist.

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

Comments

Eric Blake Jan. 22, 2019, 9:58 p.m. UTC | #1
On 1/22/19 6:19 AM, Kevin Wolf wrote:
> If QEMU was configured with a driver in --block-drv-ro-whitelist, trying
> to use that driver read-write resulted in an error message even if
> auto-read-only=on was set.
> 
> Consider auto-read-only=on for the whitelist checking and use it to
> automatically degrade to read-only for block drivers on the read-only
> whitelist.
> 
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
>  block.c | 20 +++++++++++++-------
>  1 file changed, 13 insertions(+), 7 deletions(-)
> 

Reviewed-by: Eric Blake <eblake@redhat.com>
Stefan Hajnoczi Jan. 24, 2019, 10:07 a.m. UTC | #2
On Tue, Jan 22, 2019 at 01:19:26PM +0100, Kevin Wolf wrote:
> If QEMU was configured with a driver in --block-drv-ro-whitelist, trying
> to use that driver read-write resulted in an error message even if
> auto-read-only=on was set.
> 
> Consider auto-read-only=on for the whitelist checking and use it to
> automatically degrade to read-only for block drivers on the read-only
> whitelist.
> 
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
>  block.c | 20 +++++++++++++-------
>  1 file changed, 13 insertions(+), 7 deletions(-)

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
diff mbox series

Patch

diff --git a/block.c b/block.c
index 92a3b45a78..0eba8ebe5c 100644
--- a/block.c
+++ b/block.c
@@ -1438,13 +1438,19 @@  static int bdrv_open_common(BlockDriverState *bs, BlockBackend *file,
     bs->read_only = !(bs->open_flags & BDRV_O_RDWR);
 
     if (use_bdrv_whitelist && !bdrv_is_whitelisted(drv, bs->read_only)) {
-        error_setg(errp,
-                   !bs->read_only && bdrv_is_whitelisted(drv, true)
-                        ? "Driver '%s' can only be used for read-only devices"
-                        : "Driver '%s' is not whitelisted",
-                   drv->format_name);
-        ret = -ENOTSUP;
-        goto fail_opts;
+        if (!bs->read_only && bdrv_is_whitelisted(drv, true)) {
+            ret = bdrv_apply_auto_read_only(bs, NULL, NULL);
+        } else {
+            ret = -ENOTSUP;
+        }
+        if (ret < 0) {
+            error_setg(errp,
+                       !bs->read_only && bdrv_is_whitelisted(drv, true)
+                       ? "Driver '%s' can only be used for read-only devices"
+                       : "Driver '%s' is not whitelisted",
+                       drv->format_name);
+            goto fail_opts;
+        }
     }
 
     /* bdrv_new() and bdrv_close() make it so */