From: Peter Krempa <pkrempa@redhat.com> QEMU when instantiating a 'host_device' blockdev backend performs checks to ensure that the device is actually writable (per host's kernel) when the device is to be opened in read-write mode. For configurations where the storage is marked as read-only while waiting for failover which happens at guest OS level this would prevent the start of the failover VM which is waiting for the primary one to fail as it wouldn't be able to open the device in read-write mode and then perform failover later during runtime. QEMU introduced a new property 'accept-read-only-device' for the 'host-device' backend, so libvirt needs to expose it to users. Signed-off-by: Peter Krempa <pipo@pipo.sk> --- docs/formatdomain.rst | 7 +++++++ src/conf/domain_conf.c | 13 +++++++++++++ src/conf/schemas/domaincommon.rng | 5 +++++ src/conf/storage_source_conf.c | 1 + src/conf/storage_source_conf.h | 3 +++ src/qemu/qemu_block.c | 4 ++++ src/qemu/qemu_domain.c | 8 ++++++++ tests/qemuxmlconfdata/disk-misc.x86_64-latest.args | 4 ++++ tests/qemuxmlconfdata/disk-misc.x86_64-latest.xml | 12 ++++++++++++ tests/qemuxmlconfdata/disk-misc.xml | 10 ++++++++++ 10 files changed, 67 insertions(+) diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index 11a4efb8d8..3f219378a7 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -3054,6 +3054,13 @@ paravirtualized driver is specified via the ``disk`` element. ``block`` The ``dev`` attribute specifies the fully-qualified path to the host device to serve as the disk. :since:`Since 0.0.3` + + The optional ``accept-read-only-dev`` :since:`(Since 12.10.0)` attribute + when set to ``yes`` instructs the hypervisor to avoid checks enforcing + that device passed as ``dev`` is writable when the disk is in read-write + mode. This is useful for failover scenarios where the storage may be + considered read-only by the host kernel but at failover the device will + start accepting writes. ``dir`` The ``dir`` attribute specifies the fully-qualified path to the directory to use as the disk. :since:`Since 0.7.5` diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 360287cd8e..ad7bbcd2f4 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7951,9 +7951,17 @@ virDomainStorageSourceParse(xmlNodePtr node, src->path = virXMLPropString(node, "file"); src->fdgroup = virXMLPropString(node, "fdgroup"); break; + case VIR_STORAGE_TYPE_BLOCK: src->path = virXMLPropString(node, "dev"); + + if (virXMLPropTristateBool(node, "accept-read-only-dev", + VIR_XML_PROP_NONE, + &src->block_accept_readonly_dev) < 0) + return -1; + break; + case VIR_STORAGE_TYPE_DIR: src->path = virXMLPropString(node, "dir"); break; @@ -24435,6 +24443,11 @@ virDomainDiskSourceFormat(virBuffer *buf, case VIR_STORAGE_TYPE_BLOCK: virBufferEscapeString(&attrBuf, " dev='%s'", src->path); + + if (src->block_accept_readonly_dev != VIR_TRISTATE_BOOL_ABSENT) + virBufferAsprintf(&attrBuf, " accept-read-only-dev='%s'", + virTristateBoolTypeToString(src->block_accept_readonly_dev)); + break; case VIR_STORAGE_TYPE_DIR: diff --git a/src/conf/schemas/domaincommon.rng b/src/conf/schemas/domaincommon.rng index 377052830e..77e9f0be92 100644 --- a/src/conf/schemas/domaincommon.rng +++ b/src/conf/schemas/domaincommon.rng @@ -2046,6 +2046,11 @@ </choice> </attribute> </optional> + <optional> + <attribute name="accept-read-only-dev"> + <ref name="virYesNo"/> + </attribute> + </optional> <ref name="diskSourceCommon"/> <optional> <ref name="storageStartupPolicy"/> diff --git a/src/conf/storage_source_conf.c b/src/conf/storage_source_conf.c index 010b44ccb0..23081cd140 100644 --- a/src/conf/storage_source_conf.c +++ b/src/conf/storage_source_conf.c @@ -822,6 +822,7 @@ virStorageSourceCopy(const virStorageSource *src, def->timeout = src->timeout; def->reconnectDelay = src->reconnectDelay; def->metadataCacheMaxSize = src->metadataCacheMaxSize; + def->block_accept_readonly_dev = src->block_accept_readonly_dev; /* storage driver metadata are not copied */ def->drv = NULL; diff --git a/src/conf/storage_source_conf.h b/src/conf/storage_source_conf.h index fa71a9ef39..fb955b6bdc 100644 --- a/src/conf/storage_source_conf.h +++ b/src/conf/storage_source_conf.h @@ -284,6 +284,9 @@ struct _virStorageSource { virStorageType type; char *path; char *fdgroup; /* name of group of file descriptors the user wishes to use instead of 'path' */ + virTristateBool block_accept_readonly_dev; /* hypervisor should open device regardless + of if the kernel considers it read-only in + read-write mode */ virStorageNetProtocol protocol; char *snapshot; /* for storage systems supporting internal snapshots */ char *configFile; /* some storage systems use config file as part of diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 324c2635b4..de124c95a4 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -791,6 +791,7 @@ qemuBlockStorageSourceGetFileProps(virStorageSource *src, const char *path = src->path; const char *iomode = NULL; const char *prManagerAlias = NULL; + virTristateBool accept_read_only_device = VIR_TRISTATE_BOOL_ABSENT; virJSONValue *ret = NULL; if (!onlytarget) { @@ -804,12 +805,15 @@ qemuBlockStorageSourceGetFileProps(virStorageSource *src, if (srcpriv && srcpriv->fdpass) path = qemuFDPassGetPath(srcpriv->fdpass); + + accept_read_only_device = src->block_accept_readonly_dev; } ignore_value(virJSONValueObjectAdd(&ret, "s:filename", path, "S:aio", iomode, "S:pr-manager", prManagerAlias, + "T:accept-read-only-device", accept_read_only_device, NULL) < 0); return ret; } diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index a4e5f92840..360c33c078 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -4888,6 +4888,14 @@ qemuDomainValidateStorageSource(virStorageSource *src, } } + if (src->block_accept_readonly_dev != VIR_TRISTATE_BOOL_ABSENT) { + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_HOST_DEVICE_ACCEPT_READ_ONLY)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("'accept-read-only-dev' option is not supported by this QEMU")); + return -1; + } + } + return 0; } diff --git a/tests/qemuxmlconfdata/disk-misc.x86_64-latest.args b/tests/qemuxmlconfdata/disk-misc.x86_64-latest.args index 86a63522a8..5949280289 100644 --- a/tests/qemuxmlconfdata/disk-misc.x86_64-latest.args +++ b/tests/qemuxmlconfdata/disk-misc.x86_64-latest.args @@ -28,6 +28,10 @@ XDG_CONFIG_HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.config \ -boot strict=on \ -device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0x2"}' \ -device '{"driver":"virtio-scsi-pci","id":"scsi0","bus":"pci.0","addr":"0x2"}' \ +-blockdev '{"driver":"host_device","filename":"/dev/failover1","accept-read-only-device":true,"node-name":"libvirt-2-storage","read-only":false}' \ +-device '{"driver":"scsi-hd","bus":"scsi0.0","channel":0,"scsi-id":0,"lun":1,"device_id":"drive-scsi0-0-0-1","drive":"libvirt-2-storage","id":"scsi0-0-0-1","bootindex":1}' \ +-blockdev '{"driver":"host_device","filename":"/dev/failover2","accept-read-only-device":true,"node-name":"libvirt-1-storage","read-only":false}' \ +-device '{"driver":"scsi-block","bus":"scsi0.0","channel":0,"scsi-id":0,"lun":2,"drive":"libvirt-1-storage","id":"scsi0-0-0-2"}' \ -audiodev '{"id":"audio1","driver":"none"}' \ -device '{"driver":"virtio-balloon-pci","id":"balloon0","bus":"pci.0","addr":"0x3"}' \ -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \ diff --git a/tests/qemuxmlconfdata/disk-misc.x86_64-latest.xml b/tests/qemuxmlconfdata/disk-misc.x86_64-latest.xml index 993ab96911..cad5fd1874 100644 --- a/tests/qemuxmlconfdata/disk-misc.x86_64-latest.xml +++ b/tests/qemuxmlconfdata/disk-misc.x86_64-latest.xml @@ -17,6 +17,18 @@ <on_crash>destroy</on_crash> <devices> <emulator>/usr/bin/qemu-system-x86_64</emulator> + <disk type='block' device='disk'> + <driver name='qemu' type='raw'/> + <source dev='/dev/failover1' accept-read-only-dev='yes'/> + <target dev='sda' bus='scsi'/> + <address type='drive' controller='0' bus='0' target='0' unit='1'/> + </disk> + <disk type='block' device='lun'> + <driver name='qemu' type='raw'/> + <source dev='/dev/failover2' accept-read-only-dev='yes'/> + <target dev='sdb' bus='scsi'/> + <address type='drive' controller='0' bus='0' target='0' unit='2'/> + </disk> <controller type='usb' index='0' model='piix3-uhci'> <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> </controller> diff --git a/tests/qemuxmlconfdata/disk-misc.xml b/tests/qemuxmlconfdata/disk-misc.xml index 33583e3d16..ce47921fb6 100644 --- a/tests/qemuxmlconfdata/disk-misc.xml +++ b/tests/qemuxmlconfdata/disk-misc.xml @@ -14,6 +14,16 @@ <on_crash>destroy</on_crash> <devices> <emulator>/usr/bin/qemu-system-x86_64</emulator> + <disk type='block' device='disk'> + <source dev='/dev/failover1' accept-read-only-dev='yes'/> + <target dev='sda' bus='scsi'/> + <address type='drive' controller='0' bus='0' target='0' unit='1'/> + </disk> + <disk type='block' device='lun'> + <source dev='/dev/failover2' accept-read-only-dev='yes'/> + <target dev='sdb' bus='scsi'/> + <address type='drive' controller='0' bus='0' target='0' unit='2'/> + </disk> <controller type='usb' index='0'/> <controller type='scsi' index='0' model='virtio-scsi'/> <memballoon model='virtio'/> -- 2.56.1