[Qemu-devel] [PATCH v3 9/9] block: Make auto-read-only=on default for -drive

Kevin Wolf posted 9 patches 7 years ago
There is a newer version of this series
[Qemu-devel] [PATCH v3 9/9] block: Make auto-read-only=on default for -drive
Posted by Kevin Wolf 7 years ago
While we want machine interfaces like -blockdev and QMP blockdev-add to
add as little auto-detection as possible so that management tools are
explicit about their needs, -drive is a convenience option for human
users. Enabling auto-read-only=on by default there enables users to use
read-only images for read-only guest devices without having to specify
read-only=on explicitly. If they try to attach the image to a read-write
device, they will still get an error message.

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

diff --git a/blockdev.c b/blockdev.c
index a8755bd908..ab57a8a53a 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -590,6 +590,7 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,
         qdict_set_default_str(bs_opts, BDRV_OPT_CACHE_NO_FLUSH, "off");
         qdict_set_default_str(bs_opts, BDRV_OPT_READ_ONLY,
                               read_only ? "on" : "off");
+        qdict_set_default_str(bs_opts, BDRV_OPT_AUTO_READ_ONLY, "on");
         assert((bdrv_flags & BDRV_O_CACHE_MASK) == 0);
 
         if (runstate_check(RUN_STATE_INMIGRATE)) {
-- 
2.19.1


Re: [Qemu-devel] [PATCH v3 9/9] block: Make auto-read-only=on default for -drive
Posted by Eric Blake 7 years ago
On 10/17/18 11:42 AM, Kevin Wolf wrote:
> While we want machine interfaces like -blockdev and QMP blockdev-add to
> add as little auto-detection as possible so that management tools are
> explicit about their needs, -drive is a convenience option for human
> users. Enabling auto-read-only=on by default there enables users to use
> read-only images for read-only guest devices without having to specify
> read-only=on explicitly. If they try to attach the image to a read-write
> device, they will still get an error message.
> 
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
>   blockdev.c | 1 +
>   1 file changed, 1 insertion(+)
> 

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

However, the obligatory: "iotests coverage?"

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org