mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 06:05:27 +00:00
qemu: Improve qemuDomainChrTargetDefValidate()
Instead of validating each target type / address type combination separately, create a small helper to perform the matching and collapse all existing checks into a single one. Signed-off-by: Andrea Bolognani <abologna@redhat.com> Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
parent
81e14caf60
commit
9ae116eadf
@ -3460,43 +3460,53 @@ qemuDomainChrSourceDefValidate(const virDomainChrSourceDef *def)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
qemuDomainChrSerialTargetTypeToAddressType(int targetType)
|
||||||
|
{
|
||||||
|
switch ((virDomainChrSerialTargetType) targetType) {
|
||||||
|
case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA:
|
||||||
|
return VIR_DOMAIN_DEVICE_ADDRESS_TYPE_ISA;
|
||||||
|
case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_USB:
|
||||||
|
return VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB;
|
||||||
|
case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_PCI:
|
||||||
|
return VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI;
|
||||||
|
case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_LAST:
|
||||||
|
case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_NONE:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemuDomainChrTargetDefValidate(const virDomainDef *def,
|
qemuDomainChrTargetDefValidate(const virDomainDef *def,
|
||||||
const virDomainChrDef *chr)
|
const virDomainChrDef *chr)
|
||||||
{
|
{
|
||||||
|
int expected;
|
||||||
|
|
||||||
switch ((virDomainChrDeviceType) chr->deviceType) {
|
switch ((virDomainChrDeviceType) chr->deviceType) {
|
||||||
case VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL:
|
case VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL:
|
||||||
|
|
||||||
/* Validate target type */
|
/* Validate target type */
|
||||||
switch ((virDomainChrSerialTargetType) chr->targetType) {
|
switch ((virDomainChrSerialTargetType) chr->targetType) {
|
||||||
case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA:
|
case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA:
|
||||||
|
case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_USB:
|
||||||
|
case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_PCI:
|
||||||
|
|
||||||
/* Hack required until we have a proper type for pSeries
|
/* Hack required until we have a proper type for pSeries
|
||||||
* serial consoles */
|
* serial consoles */
|
||||||
if (qemuDomainIsPSeries(def))
|
if (qemuDomainIsPSeries(def))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (chr->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
|
expected = qemuDomainChrSerialTargetTypeToAddressType(chr->targetType);
|
||||||
chr->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_ISA) {
|
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
||||||
_("isa-serial requires address of isa type"));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_USB:
|
|
||||||
if (chr->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
|
if (chr->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
|
||||||
chr->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB) {
|
chr->info.type != expected) {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
_("usb-serial requires address of usb type"));
|
_("Target type '%s' requires address type '%s'"),
|
||||||
return -1;
|
virDomainChrSerialTargetTypeToString(chr->targetType),
|
||||||
}
|
virDomainDeviceAddressTypeToString(expected));
|
||||||
break;
|
|
||||||
|
|
||||||
case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_PCI:
|
|
||||||
if (chr->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
|
|
||||||
chr->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
|
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
||||||
_("pci-serial requires address of pci type"));
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user