qemu: validate: Allow <transient/> disks

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@jp.fujitsu.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Tested-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Tested-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Masayoshi Mizuma 2020-09-17 09:30:43 -04:00 committed by Peter Krempa
parent 1c9227de5d
commit 596c659b4e
2 changed files with 53 additions and 8 deletions

View File

@ -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 supported 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

View File

@ -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,