Signed-off-by: Andrea Bolognani <abologna(a)redhat.com>
---
src/qemu/qemu_domain.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 54 insertions(+), 2 deletions(-)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 9dc3d5597..e4e67c585 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -4243,9 +4243,61 @@ qemuDomainDeviceDefValidateControllerSCSI(const
virDomainControllerDef *controll
static int
-qemuDomainDeviceDefValidateControllerPCI(const virDomainControllerDef *controller
ATTRIBUTE_UNUSED,
- const virDomainDef *def ATTRIBUTE_UNUSED)
+qemuDomainDeviceDefValidateControllerPCI(const virDomainControllerDef *controller,
+ const virDomainDef *def)
{
+ const virDomainPCIControllerOpts *pciopts = &controller->opts.pciopts;
+ const char *model = virDomainControllerModelPCITypeToString(controller->model);
+ const char *modelName =
virDomainControllerPCIModelNameTypeToString(pciopts->modelName);
+
+ if (!model) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unknown virDomainControllerModelPCI value: %d"),
+ controller->model);
+ return -1;
+ }
+ if (!modelName) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unknown virDomainControllerPCIModelName value: %d"),
+ pciopts->modelName);
+ return -1;
+ }
+
+ /* index */
+ switch ((virDomainControllerModelPCI) controller->model) {
+ case VIR_DOMAIN_CONTROLLER_MODEL_PCI_BRIDGE:
+ case VIR_DOMAIN_CONTROLLER_MODEL_DMI_TO_PCI_BRIDGE:
+ case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT_PORT:
+ case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_SWITCH_UPSTREAM_PORT:
+ case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_SWITCH_DOWNSTREAM_PORT:
+ case VIR_DOMAIN_CONTROLLER_MODEL_PCI_EXPANDER_BUS:
+ case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_EXPANDER_BUS:
+ if (controller->idx == 0) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("Index for '%s' controller must be >
0"),
+ model);
+ return -1;
+ }
+ break;
+
+ case VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT:
+ case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT:
+ /* pci-root controllers for pSeries guests can have any index, but
+ * all other pci-root and pcie-root controller must have index 0 */
+ if (controller->idx != 0 &&
+ !(qemuDomainIsPSeries(def) &&
+ controller->model == VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT)) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("Index for '%s' controller must be 0"),
+ model);
+ return -1;
+ }
+ break;
+
+ case VIR_DOMAIN_CONTROLLER_MODEL_PCI_LAST:
+ break;
+ }
+
return 0;
}
--
2.14.3