提交 a9254a2d 编写于 作者: A Andrea Bolognani

qemu: Validate target model for serial devices

Target model and target type must agree for the configuration
to make sense, so check that's actually the case and error out
otherwise.
Signed-off-by: NAndrea Bolognani <abologna@redhat.com>
Reviewed-by: NPavel Hrdina <phrdina@redhat.com>
上级 72bf21f2
...@@ -209,6 +209,8 @@ virDomainChrGetDomainPtrs; ...@@ -209,6 +209,8 @@ virDomainChrGetDomainPtrs;
virDomainChrInsertPreAlloced; virDomainChrInsertPreAlloced;
virDomainChrPreAlloc; virDomainChrPreAlloc;
virDomainChrRemove; virDomainChrRemove;
virDomainChrSerialTargetModelTypeFromString;
virDomainChrSerialTargetModelTypeToString;
virDomainChrSerialTargetTypeFromString; virDomainChrSerialTargetTypeFromString;
virDomainChrSerialTargetTypeToString; virDomainChrSerialTargetTypeToString;
virDomainChrSourceDefClear; virDomainChrSourceDefClear;
......
...@@ -3479,6 +3479,25 @@ qemuDomainChrSerialTargetTypeToAddressType(int targetType) ...@@ -3479,6 +3479,25 @@ qemuDomainChrSerialTargetTypeToAddressType(int targetType)
} }
static int
qemuDomainChrSerialTargetModelToTargetType(int targetModel)
{
switch ((virDomainChrSerialTargetModel) targetModel) {
case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_ISA_SERIAL:
return VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA;
case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_USB_SERIAL:
return VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_USB;
case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_PCI_SERIAL:
return VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_PCI;
case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_NONE:
case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_LAST:
break;
}
return VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_NONE;
}
static int static int
qemuDomainChrTargetDefValidate(const virDomainDef *def, qemuDomainChrTargetDefValidate(const virDomainDef *def,
const virDomainChrDef *chr) const virDomainChrDef *chr)
...@@ -3515,6 +3534,28 @@ qemuDomainChrTargetDefValidate(const virDomainDef *def, ...@@ -3515,6 +3534,28 @@ qemuDomainChrTargetDefValidate(const virDomainDef *def,
case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_LAST: case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_LAST:
break; break;
} }
/* Validate target model */
switch ((virDomainChrSerialTargetModel) chr->targetModel) {
case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_ISA_SERIAL:
case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_USB_SERIAL:
case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_PCI_SERIAL:
expected = qemuDomainChrSerialTargetModelToTargetType(chr->targetModel);
if (chr->targetType != expected) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Target model '%s' requires target type '%s'"),
virDomainChrSerialTargetModelTypeToString(chr->targetModel),
virDomainChrSerialTargetTypeToString(expected));
return -1;
}
break;
case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_NONE:
case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_LAST:
break;
}
break; break;
case VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE: case VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册