On Thu, Sep 24, 2020 at 01:43:56PM +0200, Peter Krempa wrote:
From: Masayoshi Mizuma <m.mizuma(a)jp.fujitsu.com>
Extract the validation of transient disk option. We support transient
disks in qemu under the following conditions:
- -blockdev is used
- the disk source is a local file
- the disk type is 'disk'
- the disk is not readonly
Signed-off-by: Masayoshi Mizuma <m.mizuma(a)jp.fujitsu.com>
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
docs/formatdomain.rst | 5 ++--
src/qemu/qemu_validate.c | 56 +++++++++++++++++++++++++++++++++++-----
2 files changed, 53 insertions(+), 8 deletions(-)
diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst
index 888db5ea29..cc1467c0e6 100644
--- a/docs/formatdomain.rst
+++ b/docs/formatdomain.rst
@@ -2974,8 +2974,9 @@ paravirtualized driver is specified via the ``disk`` element.
``transient``
If present, this indicates that changes to the device contents should be
reverted automatically when the guest exits. With some hypervisors, marking a
- disk transient prevents the domain from participating in migration or
- snapshots. Only suppported in vmx hypervisor. :since:`Since 0.9.5`
+ disk transient prevents the domain from participating in migration,
+ snapshots, or blockjobs. Only suppported in vmx hypervisor
+ (:since:`Since 0.9.5`) and ``qemu`` hypervisor (:since:`Since 6.9.0`).
``serial``
If present, this specify serial number of virtual hard drive. For example, it
may look like ``<serial>WD-WMAP9A966149</serial>``. Not supported for
diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index 3ed4039cdf..3196814aca 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -2186,12 +2186,6 @@ qemuValidateDomainDeviceDefDiskFrontend(const virDomainDiskDef
*disk,
}
}
- if (disk->transient) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
- _("transient disks not supported yet"));
- return -1;
- }
-
if (disk->iomode == VIR_DOMAIN_DISK_IO_NATIVE &&
disk->cachemode != VIR_DOMAIN_DISK_CACHE_DIRECTSYNC &&
disk->cachemode != VIR_DOMAIN_DISK_CACHE_DISABLE) {
@@ -2340,6 +2334,53 @@ qemuValidateDomainDeviceDefDiskBlkdeviotune(const virDomainDiskDef
*disk,
}
+static int
+qemuValidateDomainDeviceDefDiskTransient(const virDomainDiskDef *disk,
+ virQEMUCapsPtr qemuCaps)
+
+{
+ virStorageType actualType = virStorageSourceGetActualType(disk->src);
+
+ if (!disk->transient)
+ return 0;
+
+ if (virStorageSourceIsEmpty(disk->src)) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("transient disk '%s' must not be empty"),
disk->dst);
+ return -1;
+ }
+
+ if (disk->src->readonly) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("transient disk '%s' must not be read-only"),
disk->dst);
+ return -1;
+ }
+
+ if (actualType != VIR_STORAGE_TYPE_FILE) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("transient disk supported only with 'file' type
(%s)"),
+ disk->dst);
+ return -1;
+ }
+
+ if (disk->device != VIR_DOMAIN_DISK_DEVICE_DISK) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("transient disk supported only with 'disk' device
(%s)"),
+ disk->dst);
+ return -1;
+ }
+
+ if (qemuCaps && !virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV)) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("transient disk not supported by this qemu binary
(%s)"),
+ disk->dst);
+ return -1;
+ }
+
+ return 0;
+}
+
+
int
qemuValidateDomainDeviceDefDisk(const virDomainDiskDef *disk,
const virDomainDef *def,
@@ -2357,6 +2398,9 @@ qemuValidateDomainDeviceDefDisk(const virDomainDiskDef *disk,
if (qemuValidateDomainDeviceDefDiskBlkdeviotune(disk, def, qemuCaps) < 0)
return -1;
+ if (qemuValidateDomainDeviceDefDiskTransient(disk, qemuCaps) < 0)
+ return -1;
+
if (disk->src->shared && !disk->src->readonly &&
!qemuBlockStorageSourceSupportsConcurrentAccess(disk->src)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
--
Tested-by: Masayoshi Mizuma <m.mizuma(a)jp.fujitsu.com>
Thanks a lot!
Masa