conf: validate: Move qemu-specific LUN disk validation to global validation

LUN disks are supported only by VMX and QEMU drivers and the VMX
implementation is a subset of qemu's implementation, thus we can move
the qemu-specific validator to the global validation code providing that
we allow the format to be 'none' (qemu driver always sets 'raw' if it's
not set) and allow disk type 'volume' as a source (qemu always
translates the source, and VMX doesn't implement 'volume' at all).

Moving the code to the global validation allows us to stop calling it
from the qemu specific validation and also deduplicates the checks.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Peter Krempa 2021-09-07 14:01:26 +02:00
parent 5ccb39616f
commit 7dee442677
7 changed files with 56 additions and 64 deletions

View File

@ -540,6 +540,57 @@ virDomainDiskDefValidateSource(const virStorageSource *src)
#define VENDOR_LEN 8 #define VENDOR_LEN 8
#define PRODUCT_LEN 16 #define PRODUCT_LEN 16
/**
* virDomainDiskDefSourceLUNValidate:
* @src: disk source struct
*
* Validate whether the disk source is valid for disk device='lun'.
*
* Returns 0 if the configuration is valid -1 and a libvirt error if the source
* is invalid.
*/
int
virDomainDiskDefSourceLUNValidate(const virStorageSource *src)
{
if (virStorageSourceGetActualType(src) == VIR_STORAGE_TYPE_NETWORK) {
if (src->protocol != VIR_STORAGE_NET_PROTOCOL_ISCSI) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("disk device='lun' is not supported for protocol='%s'"),
virStorageNetProtocolTypeToString(src->protocol));
return -1;
}
} else if (!virStorageSourceIsBlockLocal(src) &&
src->type != VIR_STORAGE_TYPE_VOLUME) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("disk device='lun' is only valid for block type disk source"));
return -1;
}
if (src->format != VIR_STORAGE_FILE_RAW &&
src->format != VIR_STORAGE_FILE_NONE) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("disk device 'lun' must use 'raw' format"));
return -1;
}
if (src->sliceStorage) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("disk device 'lun' doesn't support storage slice"));
return -1;
}
if (src->encryption &&
src->encryption->format != VIR_STORAGE_ENCRYPTION_FORMAT_DEFAULT) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("disk device 'lun' doesn't support encryption"));
return -1;
}
return 0;
}
static int static int
virDomainDiskDefValidate(const virDomainDef *def, virDomainDiskDefValidate(const virDomainDef *def,
const virDomainDiskDef *disk) const virDomainDiskDef *disk)
@ -551,16 +602,8 @@ virDomainDiskDefValidate(const virDomainDef *def,
/* Validate LUN configuration */ /* Validate LUN configuration */
if (disk->device == VIR_DOMAIN_DISK_DEVICE_LUN) { if (disk->device == VIR_DOMAIN_DISK_DEVICE_LUN) {
/* volumes haven't been translated at this point, so accept them */ if (virDomainDiskDefSourceLUNValidate(disk->src) < 0)
if (!(disk->src->type == VIR_STORAGE_TYPE_BLOCK ||
disk->src->type == VIR_STORAGE_TYPE_VOLUME ||
(disk->src->type == VIR_STORAGE_TYPE_NETWORK &&
disk->src->protocol == VIR_STORAGE_NET_PROTOCOL_ISCSI))) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("disk '%s' improperly configured for a "
"device='lun'"), disk->dst);
return -1; return -1;
}
} else { } else {
if (disk->src->pr) { if (disk->src->pr) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",

View File

@ -40,3 +40,5 @@ int virDomainDeviceDefValidate(const virDomainDeviceDef *dev,
void *parseOpaque); void *parseOpaque);
int virDomainDiskDefValidateSource(const virStorageSource *src); int virDomainDiskDefValidateSource(const virStorageSource *src);
int virDomainDiskDefSourceLUNValidate(const virStorageSource *src);

View File

@ -767,6 +767,7 @@ virDomainConfVMNWFilterTeardown;
virDomainActualNetDefValidate; virDomainActualNetDefValidate;
virDomainDefValidate; virDomainDefValidate;
virDomainDeviceValidateAliasForHotplug; virDomainDeviceValidateAliasForHotplug;
virDomainDiskDefSourceLUNValidate;
# conf/interface_conf.h # conf/interface_conf.h

View File

@ -9825,54 +9825,6 @@ qemuDomainDiskByName(virDomainDef *def,
} }
/**
* qemuDomainDefValidateDiskLunSource:
* @src: disk source struct
*
* Validate whether the disk source is valid for disk device='lun'.
*
* Returns 0 if the configuration is valid -1 and a libvirt error if the source
* is invalid.
*/
int
qemuDomainDefValidateDiskLunSource(const virStorageSource *src)
{
if (virStorageSourceGetActualType(src) == VIR_STORAGE_TYPE_NETWORK) {
if (src->protocol != VIR_STORAGE_NET_PROTOCOL_ISCSI) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("disk device='lun' is not supported for protocol='%s'"),
virStorageNetProtocolTypeToString(src->protocol));
return -1;
}
} else if (!virStorageSourceIsBlockLocal(src)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("disk device='lun' is only valid for block type disk source"));
return -1;
}
if (src->format != VIR_STORAGE_FILE_RAW) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("disk device 'lun' must use 'raw' format"));
return -1;
}
if (src->sliceStorage) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("disk device 'lun' doesn't support storage slice"));
return -1;
}
if (src->encryption &&
src->encryption->format != VIR_STORAGE_ENCRYPTION_FORMAT_DEFAULT) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("disk device 'lun' doesn't support encryption"));
return -1;
}
return 0;
}
int int
qemuDomainPrepareChannel(virDomainChrDef *channel, qemuDomainPrepareChannel(virDomainChrDef *channel,
const char *domainChannelTargetDir) const char *domainChannelTargetDir)

View File

@ -893,9 +893,6 @@ int qemuDomainSecretPrepare(virQEMUDriver *driver,
virDomainObj *vm) virDomainObj *vm)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
int qemuDomainDefValidateDiskLunSource(const virStorageSource *src)
ATTRIBUTE_NONNULL(1);
int qemuDomainDeviceDefValidateDisk(const virDomainDiskDef *disk, int qemuDomainDeviceDefValidateDisk(const virDomainDiskDef *disk,
virQEMUCaps *qemuCaps); virQEMUCaps *qemuCaps);

View File

@ -14856,7 +14856,7 @@ qemuDomainBlockCopyCommon(virDomainObj *vm,
goto endjob; goto endjob;
if (disk->device == VIR_DOMAIN_DISK_DEVICE_LUN && if (disk->device == VIR_DOMAIN_DISK_DEVICE_LUN &&
qemuDomainDefValidateDiskLunSource(mirror) < 0) virDomainDiskDefSourceLUNValidate(mirror) < 0)
goto endjob; goto endjob;
if (!(flags & VIR_DOMAIN_BLOCK_COPY_TRANSIENT_JOB) && if (!(flags & VIR_DOMAIN_BLOCK_COPY_TRANSIENT_JOB) &&

View File

@ -2663,9 +2663,6 @@ qemuValidateDomainDeviceDefDiskFrontend(const virDomainDiskDef *disk,
return -1; return -1;
} }
if (qemuDomainDefValidateDiskLunSource(disk->src) < 0)
return -1;
if (disk->wwn) { if (disk->wwn) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Setting wwn is not supported for lun device")); _("Setting wwn is not supported for lun device"));