This patch detects a misconfiguration between the disk bus type and disk
address type for controller based disk buses (SATA, SCSI, FDC and
IDE). The addresses of these bus types are all managed in common code so
it's possible to decide in common code whether the disk address and bus
type are compatible or not.
Signed-off-by: Marc Hartmayer <mhartmay(a)linux.vnet.ibm.com>
Reviewed-by: Bjoern Walk <bwalk(a)linux.vnet.ibm.com>
---
src/conf/domain_conf.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 56 insertions(+)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 5d2bc8d..0481499 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -4672,6 +4672,48 @@ virDomainDefPostParse(virDomainDefPtr def,
}
+/**
+ * virDomainDiskAddressDiskBusCompatibility:
+ * @bus: disk bus type
+ * @addressType: disk address type
+ *
+ * Check if the specified disk address type @addressType is compatible
+ * with the specified disk bus type @bus. This function checks
+ * compatibility with the bus types SATA, SCSI, FDC, and IDE only,
+ * because only these are handled in common code.
+ *
+ * Returns true if compatible or can't be decided in common code,
+ * false if known to be not compatible.
+ */
+static bool
+virDomainDiskAddressDiskBusCompatibility(virDomainDiskBus bus,
+ virDomainDeviceAddressType addressType)
+{
+ if (addressType == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE)
+ return true;
+
+ switch (bus) {
+ case VIR_DOMAIN_DISK_BUS_IDE:
+ case VIR_DOMAIN_DISK_BUS_FDC:
+ case VIR_DOMAIN_DISK_BUS_SCSI:
+ case VIR_DOMAIN_DISK_BUS_SATA:
+ return addressType == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE;
+ case VIR_DOMAIN_DISK_BUS_VIRTIO:
+ case VIR_DOMAIN_DISK_BUS_XEN:
+ case VIR_DOMAIN_DISK_BUS_USB:
+ case VIR_DOMAIN_DISK_BUS_UML:
+ case VIR_DOMAIN_DISK_BUS_SD:
+ case VIR_DOMAIN_DISK_BUS_LAST:
+ return true;
+ }
+
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("unexpected bus type '%d'"),
+ bus);
+ return true;
+}
+
+
static int
virDomainDiskDefValidate(const virDomainDiskDef *disk)
{
@@ -4689,6 +4731,20 @@ virDomainDiskDefValidate(const virDomainDiskDef *disk)
}
}
+ /* Reject disks with a bus type that is not compatible with the
+ * given address type. The function considers only buses that are
+ * handled in common code. For other bus types it's not possible
+ * to decide compatibility in common code.
+ */
+ if (!virDomainDiskAddressDiskBusCompatibility(disk->bus, disk->info.type)) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("Invalid address type '%s' for the disk
'%s' with the bus type '%s'"),
+ virDomainDeviceAddressTypeToString(disk->info.type),
+ disk->dst,
+ virDomainDiskBusTypeToString(disk->bus));
+ return -1;
+ }
+
return 0;
}
--
2.5.5