Instead of waiting until we get to command line generation, we can
validate the target for a char device much earlier.
Move all the checks out of qemuBuildSerialChrDeviceStr() and into
the new fuction. This will later allow us to validate the target
for platform devices.
Signed-off-by: Andrea Bolognani <abologna(a)redhat.com>
---
src/qemu/qemu_command.c | 20 ---------------
src/qemu/qemu_domain.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 65 insertions(+), 20 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index d534bc8ad..86521d498 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -10289,22 +10289,9 @@ qemuBuildSerialChrDeviceStr(char **deviceStr,
_("usb-serial is not supported in this QEMU
binary"));
goto error;
}
-
- if (serial->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
- serial->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
- _("usb-serial requires address of usb type"));
- goto error;
- }
break;
case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA:
- if (serial->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
- serial->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_ISA) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
- _("isa-serial requires address of isa type"));
- goto error;
- }
break;
case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_PCI:
@@ -10313,13 +10300,6 @@ qemuBuildSerialChrDeviceStr(char **deviceStr,
_("pci-serial is not supported with this QEMU
binary"));
goto error;
}
-
- if (serial->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
- serial->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
- _("pci-serial requires address of pci type"));
- goto error;
- }
break;
case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_NONE:
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index b60c374d9..12b2a0bf6 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -3490,6 +3490,68 @@ qemuDomainChrSourceDefValidate(const virDomainChrSourceDef *def)
}
+static int
+qemuDomainChrTargetDefValidate(const virDomainDef *def,
+ const virDomainChrDef *chr)
+{
+ switch ((virDomainChrDeviceType) chr->deviceType) {
+ case VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL:
+
+ /* Validate target type */
+ switch ((virDomainChrSerialTargetType) chr->targetType) {
+ case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA:
+ /* Hack required until we have a proper type for pSeries
+ * serial consoles */
+ if (qemuDomainIsPSeries(def))
+ return 0;
+
+ if (chr->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
+ chr->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_ISA) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("Target type 'isa-serial' requires address
"
+ "of type 'isa'"));
+ return -1;
+ }
+ break;
+
+ case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_USB:
+ if (chr->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
+ chr->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("Target type 'usb-serial' requires address
"
+ "of type 'usb'"));
+ return -1;
+ }
+ 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",
+ _("Target type 'pci-serial' requires address
"
+ "of type 'pci'"));
+ return -1;
+ }
+ break;
+
+ case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_NONE:
+ case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_LAST:
+ break;
+ }
+ break;
+
+ case VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE:
+ case VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL:
+ case VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL:
+ case VIR_DOMAIN_CHR_DEVICE_TYPE_LAST:
+ /* Nothing to do */
+ break;
+ }
+
+ return 0;
+}
+
+
static int
qemuDomainChrDefValidate(const virDomainChrDef *dev,
const virDomainDef *def)
@@ -3497,6 +3559,9 @@ qemuDomainChrDefValidate(const virDomainChrDef *dev,
if (qemuDomainChrSourceDefValidate(dev->source) < 0)
return -1;
+ if (qemuDomainChrTargetDefValidate(def, dev) < 0)
+ return -1;
+
if (dev->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL &&
(ARCH_IS_S390(def->os.arch) || qemuDomainIsPSeries(def))) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
--
2.14.3