CC'd Markus for QAPI generator input.

On Thu, Oct 29, 2026 at 17:45:21 +0100, Kevin Wolf wrote:
> The host_device block driver refuses to open a block device read-write
> if the BLKROGET ioctl tells it that it's actually read-only. For such
> devices it's possible to open a read-write file descriptor, but any
> writes to the device would fail.
> 
> There are valid use cases for which this check gets in the way, as
> explained in the bug report:
> 
>     However, this behavior prevents a legitimate enterprise use case:
>     running VMs against storage replication target LUNs in a disaster
>     recovery configuration. Enterprise storage arrays (Dell Powermax,
>     Pure Storage) set the SCSI Write Protect bit on replication target
>     LUNs, causing the Linux kernel to mark them read-only via BLKROGET.
>     The VMs on the passive DR site need to start with these LUNs
>     attached - writes are expected to fail (the application middleware
>     knows it's on the passive side), and after a DR role swap the LUN
>     becomes writable and writes should succeed immediately without any
>     VM restart.
> 
> In order to allow such use cases in which a currently read-only device
> is deliberately opened read-write, add a new option to the host_device
> driver that allows the user to skip the check.
> 
> Buglink: https://redhat.atlassian.net/browse/RHEL-186136
> Signed-off-by: Kevin Wolf <[email protected]>
> Reviewed-by: Eric Blake <[email protected]>
> Reviewed-by: Stefan Hajnoczi <[email protected]>
> ---
>  qapi/block-core.json | 19 ++++++++++++++++++-
>  block/file-posix.c   | 23 ++++++++++++++++++++---
>  2 files changed, 38 insertions(+), 4 deletions(-)
> 
> diff --git a/qapi/block-core.json b/qapi/block-core.json
> index 741c8165c06..80272b878c5 100644
> --- a/qapi/block-core.json
> +++ b/qapi/block-core.json
> @@ -3390,6 +3390,23 @@
>    'features': [ { 'name': 'dynamic-auto-read-only',
>                    'if': 'CONFIG_POSIX' } ] }
>  
> +##
> +# @BlockdevOptionsHostDevice:
> +#     Driver specific block device options for the host_device
> +#     backend.
> +#
> +# @accept-read-only-device: allow opening a read-only device as
> +#     read-write.  If this is false, opening a host device read-write
> +#     requires on Linux that the BLKROGET ioctl considers the device
> +#     writable.  If it is true, this check is skipped.  (since: 11.2,
> +#     default: false)
> +#
> +# Since: 11.2
> +##
> +{ 'struct': 'BlockdevOptionsHostDevice',
> +  'base': 'BlockdevOptionsFile',
> +  'data': { '*accept-read-only-device': 'bool' } }
> +
>  ##
>  # @BlockdevOptionsNull:
>  #     Driver specific block device options for the null backend.
> @@ -4777,7 +4794,7 @@
>        'ftps':       'BlockdevOptionsCurlFtps',
>        'host_cdrom':  { 'type': 'BlockdevOptionsFile',
>                         'if': 'HAVE_HOST_BLOCK_DEVICE' },
> -      'host_device': { 'type': 'BlockdevOptionsFile',
> +      'host_device': { 'type': 'BlockdevOptionsHostDevice',
>                         'if': 'HAVE_HOST_BLOCK_DEVICE' },
>        'http':       'BlockdevOptionsCurlHttp',
>        'https':      'BlockdevOptionsCurlHttps',

After the two hunks above the 'host_device' type in the resulting QMP
schema will no longer have the 'dynamic-auto-read-only' feature which it
had when it used 'BlockdevOptionsFile' directly rather than the
'BlockdevOptionsHostDevice' type which 'inherits' from
'BlockdevOptionsFile'.

Markus, after chatting with Kevin, we're not sure if it's intention that
features are not inherited in the above case, and thus the
'dynamic-auto-read-only' feature would need to be propagated also to
'BlockdevOptionsHostDevice' or it's a mistake in the generator.

Note that I've noticed this when checking what changed between two qemu
versions by using the 'qemu-replies-tool.py --dump-all' script from the
libvirt repo which converts the QMP schema into all possible query
strings the "language" libvirt uses to describe capabilities in qemu to
probe for, so it turned up in a 'diff' of the two.

It's not a problem at all for libvirt because the use of
'dynamic-auto-read-only' feature was now removed when libvirt removed
support for the pre-blockdev -drive code.


Reply via email to