qemuValidateDomainDeviceDefDiskFrontend: Refactor validation of <disk type='lun'>

Use a switch statement for checks based on the disk bus.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2024-06-11 16:35:21 +02:00
parent acb26f22a1
commit 126f95c1fe

View File

@ -2901,23 +2901,37 @@ qemuValidateDomainDeviceDefDiskFrontend(const virDomainDiskDef *disk,
} }
if (disk->device == VIR_DOMAIN_DISK_DEVICE_LUN) { if (disk->device == VIR_DOMAIN_DISK_DEVICE_LUN) {
/* make sure that both the bus supports type='lun' (SG_IO). */
if (disk->bus != VIR_DOMAIN_DISK_BUS_VIRTIO && switch (disk->bus) {
disk->bus != VIR_DOMAIN_DISK_BUS_SCSI) { case VIR_DOMAIN_DISK_BUS_SCSI:
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_SCSI_BLOCK)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("This QEMU doesn't support scsi-block for lun passthrough"));
return -1;
}
break;
case VIR_DOMAIN_DISK_BUS_VIRTIO:
break;
case VIR_DOMAIN_DISK_BUS_NONE:
case VIR_DOMAIN_DISK_BUS_IDE:
case VIR_DOMAIN_DISK_BUS_FDC:
case VIR_DOMAIN_DISK_BUS_XEN:
case VIR_DOMAIN_DISK_BUS_USB:
case VIR_DOMAIN_DISK_BUS_UML:
case VIR_DOMAIN_DISK_BUS_SATA:
case VIR_DOMAIN_DISK_BUS_SD:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("disk device='lun' is not supported for bus='%1$s'"), _("disk device='lun' is not supported for bus='%1$s'"),
virDomainDiskBusTypeToString(disk->bus)); virDomainDiskBusTypeToString(disk->bus));
return -1; return -1;
}
if (disk->bus == VIR_DOMAIN_DISK_BUS_SCSI && case VIR_DOMAIN_DISK_BUS_LAST:
!virQEMUCapsGet(qemuCaps, QEMU_CAPS_SCSI_BLOCK)) { virReportEnumRangeError(virDomainDiskBus, disk->bus);
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("This QEMU doesn't support scsi-block for lun passthrough"));
return -1; return -1;
} }
if (disk->copy_on_read == VIR_TRISTATE_SWITCH_ON) { if (disk->copy_on_read == VIR_TRISTATE_SWITCH_ON) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("copy_on_read is not compatible with 'lun' disk '%1$s'"), _("copy_on_read is not compatible with 'lun' disk '%1$s'"),