[libvirt] [RFC PATCH 03/12] conf: Move index number checking to drivers

Andrea Bolognani abologna at redhat.com
Tue Feb 28 16:12:35 UTC 2017


pSeries guests will soon be allowed to have multiple
PHBs (pci-root controllers), which of course means that
all but one of them will have a non-zero index; hence,
we'll need to relax the current check.

However, right now the check is performed in the conf
module, which is generic rather than tied to the QEMU
driver, and where we don't have information such as the
guest machine type available.

To make this change of behavior possible down the line,
we need to move the check from the XML parser to the
driver. Unfortunately, this means duplicating code :(
---
 src/bhyve/bhyve_domain.c   | 15 +++++++++++++++
 src/conf/domain_conf.c     |  6 ------
 src/libxl/libxl_domain.c   | 14 ++++++++++++++
 src/lxc/lxc_domain.c       | 14 ++++++++++++++
 src/openvz/openvz_driver.c | 14 ++++++++++++++
 src/qemu/qemu_domain.c     | 10 ++++++++++
 src/uml/uml_driver.c       | 14 ++++++++++++++
 src/vz/vz_driver.c         | 14 ++++++++++++++
 src/xen/xen_driver.c       | 14 ++++++++++++++
 9 files changed, 109 insertions(+), 6 deletions(-)

diff --git a/src/bhyve/bhyve_domain.c b/src/bhyve/bhyve_domain.c
index 76b4fac..05c1508 100644
--- a/src/bhyve/bhyve_domain.c
+++ b/src/bhyve/bhyve_domain.c
@@ -122,6 +122,21 @@ bhyveDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
             bhyveDomainDiskDefAssignAddress(driver, disk, def) < 0)
             return -1;
     }
+
+    if (dev->type == VIR_DOMAIN_DEVICE_CONTROLLER) {
+        virDomainControllerDefPtr cont = dev->data.controller;
+
+        if (cont->type == VIR_DOMAIN_CONTROLLER_TYPE_PCI &&
+            (cont->model == VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT ||
+             cont->model == VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT) &&
+            cont->idx != 0) {
+            virReportError(VIR_ERR_XML_ERROR, "%s",
+                           _("pci-root and pcie-root controllers "
+                             "should have index 0"));
+            return -1;
+        }
+    }
+
     return 0;
 }
 
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 97d42fe..fb33e9c 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -8844,12 +8844,6 @@ virDomainControllerDefParseXML(xmlNodePtr node,
                                  "have an address"));
                 goto error;
             }
-            if (def->idx > 0) {
-                virReportError(VIR_ERR_XML_ERROR, "%s",
-                               _("pci-root and pcie-root controllers "
-                                 "should have index 0"));
-                goto error;
-            }
             if ((rc = virDomainParseScaledValue("./pcihole64", NULL,
                                                 ctxt, &bytes, 1024,
                                                 1024ULL * ULONG_MAX, false)) < 0)
diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index ea28c93..844295f 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -379,6 +379,20 @@ libxlDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
             virDomainDiskSetFormat(disk, VIR_STORAGE_FILE_RAW);
     }
 
+    if (dev->type == VIR_DOMAIN_DEVICE_CONTROLLER) {
+        virDomainControllerDefPtr cont = dev->data.controller;
+
+        if (cont->type == VIR_DOMAIN_CONTROLLER_TYPE_PCI &&
+            (cont->model == VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT ||
+             cont->model == VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT) &&
+            cont->idx != 0) {
+            virReportError(VIR_ERR_XML_ERROR, "%s",
+                           _("pci-root and pcie-root controllers "
+                             "should have index 0"));
+            return -1;
+        }
+    }
+
     return 0;
 }
 
diff --git a/src/lxc/lxc_domain.c b/src/lxc/lxc_domain.c
index 3a7404f..a50f6fe 100644
--- a/src/lxc/lxc_domain.c
+++ b/src/lxc/lxc_domain.c
@@ -389,6 +389,20 @@ virLXCDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
         dev->data.chr->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_NONE)
         dev->data.chr->targetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_LXC;
 
+    if (dev->type == VIR_DOMAIN_DEVICE_CONTROLLER) {
+        virDomainControllerDefPtr cont = dev->data.controller;
+
+        if (cont->type == VIR_DOMAIN_CONTROLLER_TYPE_PCI &&
+            (cont->model == VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT ||
+             cont->model == VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT) &&
+            cont->idx != 0) {
+            virReportError(VIR_ERR_XML_ERROR, "%s",
+                           _("pci-root and pcie-root controllers "
+                             "should have index 0"));
+            return -1;
+        }
+    }
+
     return 0;
 }
 
diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index eaa9ef6..62732f3 100644
--- a/src/openvz/openvz_driver.c
+++ b/src/openvz/openvz_driver.c
@@ -128,6 +128,20 @@ openvzDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
         return -1;
     }
 
+    if (dev->type == VIR_DOMAIN_DEVICE_CONTROLLER) {
+        virDomainControllerDefPtr cont = dev->data.controller;
+
+        if (cont->type == VIR_DOMAIN_CONTROLLER_TYPE_PCI &&
+            (cont->model == VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT ||
+             cont->model == VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT) &&
+            cont->idx != 0) {
+            virReportError(VIR_ERR_XML_ERROR, "%s",
+                           _("pci-root and pcie-root controllers "
+                             "should have index 0"));
+            return -1;
+        }
+    }
+
     return 0;
 }
 
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index c187214..3cc827e 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -3207,6 +3207,16 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
                                virDomainNumaGetNodeCount(def->numa));
                 goto cleanup;
             }
+
+            if (cont->type == VIR_DOMAIN_CONTROLLER_TYPE_PCI &&
+                (cont->model == VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT ||
+                 cont->model == VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT) &&
+                cont->idx != 0) {
+                virReportError(VIR_ERR_XML_ERROR, "%s",
+                               _("pci-root and pcie-root controllers "
+                                 "should have index 0"));
+                goto cleanup;
+            }
         } else if (cont->type == VIR_DOMAIN_CONTROLLER_TYPE_USB &&
                    cont->model == -1) {
             /* Pick a suitable default model for the USB controller if none
diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c
index f0c0ad3..0d4b937 100644
--- a/src/uml/uml_driver.c
+++ b/src/uml/uml_driver.c
@@ -427,6 +427,20 @@ umlDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
         return -1;
     }
 
+    if (dev->type == VIR_DOMAIN_DEVICE_CONTROLLER) {
+        virDomainControllerDefPtr cont = dev->data.controller;
+
+        if (cont->type == VIR_DOMAIN_CONTROLLER_TYPE_PCI &&
+            (cont->model == VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT ||
+             cont->model == VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT) &&
+            cont->idx != 0) {
+            virReportError(VIR_ERR_XML_ERROR, "%s",
+                           _("pci-root and pcie-root controllers "
+                             "should have index 0"));
+            return -1;
+        }
+    }
+
     return 0;
 }
 
diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c
index 1ca9fd7..35c63b4 100644
--- a/src/vz/vz_driver.c
+++ b/src/vz/vz_driver.c
@@ -295,6 +295,20 @@ vzDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
         VIR_STRDUP(dev->data.net->model, "e1000") < 0)
         return -1;
 
+    if (dev->type == VIR_DOMAIN_DEVICE_CONTROLLER) {
+        virDomainControllerDefPtr cont = dev->data.controller;
+
+        if (cont->type == VIR_DOMAIN_CONTROLLER_TYPE_PCI &&
+            (cont->model == VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT ||
+             cont->model == VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT) &&
+            cont->idx != 0) {
+            virReportError(VIR_ERR_XML_ERROR, "%s",
+                           _("pci-root and pcie-root controllers "
+                             "should have index 0"));
+            return -1;
+        }
+    }
+
     return 0;
 }
 
diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
index 3f9bfa7..10d8f5a 100644
--- a/src/xen/xen_driver.c
+++ b/src/xen/xen_driver.c
@@ -363,6 +363,20 @@ xenDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
         }
     }
 
+    if (dev->type == VIR_DOMAIN_DEVICE_CONTROLLER) {
+        virDomainControllerDefPtr cont = dev->data.controller;
+
+        if (cont->type == VIR_DOMAIN_CONTROLLER_TYPE_PCI &&
+            (cont->model == VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT ||
+             cont->model == VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT) &&
+            cont->idx != 0) {
+            virReportError(VIR_ERR_XML_ERROR, "%s",
+                           _("pci-root and pcie-root controllers "
+                             "should have index 0"));
+            return -1;
+        }
+    }
+
     return 0;
 }
 
-- 
2.7.4




More information about the libvir-list mailing list