|
|
3e5111 |
From 309e27ed960e7ac34177aa1fcac34cc6faf149fb Mon Sep 17 00:00:00 2001
|
|
|
3e5111 |
Message-Id: <309e27ed960e7ac34177aa1fcac34cc6faf149fb@dist-git>
|
|
|
3e5111 |
From: Erik Skultety <eskultet@redhat.com>
|
|
|
3e5111 |
Date: Thu, 18 May 2017 14:02:51 +0200
|
|
|
3e5111 |
Subject: [PATCH] nodedev: conf: Split PCI sub-capability parsing to separate
|
|
|
3e5111 |
methods
|
|
|
3e5111 |
|
|
|
3e5111 |
Since there's at least SRIOV and MDEV sub-capabilities to be parsed,
|
|
|
3e5111 |
let's make the code more readable by splitting it to several logical
|
|
|
3e5111 |
blocks.
|
|
|
3e5111 |
|
|
|
3e5111 |
https://bugzilla.redhat.com/show_bug.cgi?id=1452072
|
|
|
3e5111 |
|
|
|
3e5111 |
Signed-off-by: Erik Skultety <eskultet@redhat.com>
|
|
|
3e5111 |
(cherry picked from commit a5c1f3b7e028193e8cb9f9a420ac2fdd5f4a66fe)
|
|
|
3e5111 |
Signed-off-by: Erik Skultety <eskultet@redhat.com>
|
|
|
3e5111 |
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
3e5111 |
---
|
|
|
3e5111 |
src/conf/node_device_conf.c | 142 ++++++++++++++++++++++++++------------------
|
|
|
3e5111 |
1 file changed, 83 insertions(+), 59 deletions(-)
|
|
|
3e5111 |
|
|
|
3e5111 |
diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
|
|
|
3e5111 |
index 02215f32d..56a26b578 100644
|
|
|
3e5111 |
--- a/src/conf/node_device_conf.c
|
|
|
3e5111 |
+++ b/src/conf/node_device_conf.c
|
|
|
3e5111 |
@@ -1286,76 +1286,102 @@ virPCIEDeviceInfoParseXML(xmlXPathContextPtr ctxt,
|
|
|
3e5111 |
|
|
|
3e5111 |
|
|
|
3e5111 |
static int
|
|
|
3e5111 |
+virNodeDevPCICapSRIOVPhysicalParseXML(xmlXPathContextPtr ctxt,
|
|
|
3e5111 |
+ virNodeDevCapPCIDevPtr pci_dev)
|
|
|
3e5111 |
+{
|
|
|
3e5111 |
+ xmlNodePtr address = virXPathNode("./address[1]", ctxt);
|
|
|
3e5111 |
+
|
|
|
3e5111 |
+ if (VIR_ALLOC(pci_dev->physical_function) < 0)
|
|
|
3e5111 |
+ return -1;
|
|
|
3e5111 |
+
|
|
|
3e5111 |
+ if (!address) {
|
|
|
3e5111 |
+ virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
3e5111 |
+ _("Missing address in 'phys_function' capability"));
|
|
|
3e5111 |
+ return -1;
|
|
|
3e5111 |
+ }
|
|
|
3e5111 |
+
|
|
|
3e5111 |
+ if (virPCIDeviceAddressParseXML(address,
|
|
|
3e5111 |
+ pci_dev->physical_function) < 0)
|
|
|
3e5111 |
+ return -1;
|
|
|
3e5111 |
+
|
|
|
3e5111 |
+ pci_dev->flags |= VIR_NODE_DEV_CAP_FLAG_PCI_PHYSICAL_FUNCTION;
|
|
|
3e5111 |
+
|
|
|
3e5111 |
+ return 0;
|
|
|
3e5111 |
+}
|
|
|
3e5111 |
+
|
|
|
3e5111 |
+
|
|
|
3e5111 |
+static int
|
|
|
3e5111 |
+virNodeDevPCICapSRIOVVirtualParseXML(xmlXPathContextPtr ctxt,
|
|
|
3e5111 |
+ virNodeDevCapPCIDevPtr pci_dev)
|
|
|
3e5111 |
+{
|
|
|
3e5111 |
+ int ret = -1;
|
|
|
3e5111 |
+ xmlNodePtr *addresses = NULL;
|
|
|
3e5111 |
+ int naddresses = virXPathNodeSet("./address", ctxt, &addresses);
|
|
|
3e5111 |
+ char *maxFuncsStr = virXPathString("string(./@maxCount)", ctxt);
|
|
|
3e5111 |
+ size_t i;
|
|
|
3e5111 |
+
|
|
|
3e5111 |
+ if (naddresses < 0)
|
|
|
3e5111 |
+ goto cleanup;
|
|
|
3e5111 |
+
|
|
|
3e5111 |
+ if (maxFuncsStr &&
|
|
|
3e5111 |
+ virStrToLong_uip(maxFuncsStr, NULL, 10,
|
|
|
3e5111 |
+ &pci_dev->max_virtual_functions) < 0) {
|
|
|
3e5111 |
+ virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
3e5111 |
+ _("Malformed 'maxCount' parameter"));
|
|
|
3e5111 |
+ goto cleanup;
|
|
|
3e5111 |
+ }
|
|
|
3e5111 |
+
|
|
|
3e5111 |
+ if (VIR_ALLOC_N(pci_dev->virtual_functions, naddresses) < 0)
|
|
|
3e5111 |
+ goto cleanup;
|
|
|
3e5111 |
+
|
|
|
3e5111 |
+ for (i = 0; i < naddresses; i++) {
|
|
|
3e5111 |
+ virPCIDeviceAddressPtr addr = NULL;
|
|
|
3e5111 |
+
|
|
|
3e5111 |
+ if (VIR_ALLOC(addr) < 0)
|
|
|
3e5111 |
+ goto cleanup;
|
|
|
3e5111 |
+
|
|
|
3e5111 |
+ if (virPCIDeviceAddressParseXML(addresses[i], addr) < 0) {
|
|
|
3e5111 |
+ VIR_FREE(addr);
|
|
|
3e5111 |
+ goto cleanup;
|
|
|
3e5111 |
+ }
|
|
|
3e5111 |
+
|
|
|
3e5111 |
+ if (VIR_APPEND_ELEMENT(pci_dev->virtual_functions,
|
|
|
3e5111 |
+ pci_dev->num_virtual_functions,
|
|
|
3e5111 |
+ addr) < 0)
|
|
|
3e5111 |
+ goto cleanup;
|
|
|
3e5111 |
+ }
|
|
|
3e5111 |
+
|
|
|
3e5111 |
+ pci_dev->flags |= VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTION;
|
|
|
3e5111 |
+ ret = 0;
|
|
|
3e5111 |
+ cleanup:
|
|
|
3e5111 |
+ VIR_FREE(addresses);
|
|
|
3e5111 |
+ VIR_FREE(maxFuncsStr);
|
|
|
3e5111 |
+ return ret;
|
|
|
3e5111 |
+}
|
|
|
3e5111 |
+
|
|
|
3e5111 |
+
|
|
|
3e5111 |
+static int
|
|
|
3e5111 |
virNodeDevPCICapabilityParseXML(xmlXPathContextPtr ctxt,
|
|
|
3e5111 |
xmlNodePtr node,
|
|
|
3e5111 |
virNodeDevCapPCIDevPtr pci_dev)
|
|
|
3e5111 |
{
|
|
|
3e5111 |
- char *maxFuncsStr = virXMLPropString(node, "maxCount");
|
|
|
3e5111 |
char *type = virXMLPropString(node, "type");
|
|
|
3e5111 |
- xmlNodePtr *addresses = NULL;
|
|
|
3e5111 |
xmlNodePtr orignode = ctxt->node;
|
|
|
3e5111 |
int ret = -1;
|
|
|
3e5111 |
- size_t i = 0;
|
|
|
3e5111 |
|
|
|
3e5111 |
ctxt->node = node;
|
|
|
3e5111 |
|
|
|
3e5111 |
if (!type) {
|
|
|
3e5111 |
virReportError(VIR_ERR_XML_ERROR, "%s", _("Missing capability type"));
|
|
|
3e5111 |
- goto out;
|
|
|
3e5111 |
+ goto cleanup;
|
|
|
3e5111 |
}
|
|
|
3e5111 |
|
|
|
3e5111 |
- if (STREQ(type, "phys_function")) {
|
|
|
3e5111 |
- xmlNodePtr address = virXPathNode("./address[1]", ctxt);
|
|
|
3e5111 |
-
|
|
|
3e5111 |
- if (VIR_ALLOC(pci_dev->physical_function) < 0)
|
|
|
3e5111 |
- goto out;
|
|
|
3e5111 |
-
|
|
|
3e5111 |
- if (!address) {
|
|
|
3e5111 |
- virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
3e5111 |
- _("Missing address in 'phys_function' capability"));
|
|
|
3e5111 |
- goto out;
|
|
|
3e5111 |
- }
|
|
|
3e5111 |
-
|
|
|
3e5111 |
- if (virPCIDeviceAddressParseXML(address,
|
|
|
3e5111 |
- pci_dev->physical_function) < 0)
|
|
|
3e5111 |
- goto out;
|
|
|
3e5111 |
-
|
|
|
3e5111 |
- pci_dev->flags |= VIR_NODE_DEV_CAP_FLAG_PCI_PHYSICAL_FUNCTION;
|
|
|
3e5111 |
- } else if (STREQ(type, "virt_functions")) {
|
|
|
3e5111 |
- int naddresses;
|
|
|
3e5111 |
-
|
|
|
3e5111 |
- if ((naddresses = virXPathNodeSet("./address", ctxt, &addresses)) < 0)
|
|
|
3e5111 |
- goto out;
|
|
|
3e5111 |
-
|
|
|
3e5111 |
- if (maxFuncsStr &&
|
|
|
3e5111 |
- virStrToLong_uip(maxFuncsStr, NULL, 10,
|
|
|
3e5111 |
- &pci_dev->max_virtual_functions) < 0) {
|
|
|
3e5111 |
- virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
3e5111 |
- _("Malformed 'maxCount' parameter"));
|
|
|
3e5111 |
- goto out;
|
|
|
3e5111 |
- }
|
|
|
3e5111 |
-
|
|
|
3e5111 |
- if (VIR_ALLOC_N(pci_dev->virtual_functions, naddresses) < 0)
|
|
|
3e5111 |
- goto out;
|
|
|
3e5111 |
-
|
|
|
3e5111 |
- for (i = 0; i < naddresses; i++) {
|
|
|
3e5111 |
- virPCIDeviceAddressPtr addr = NULL;
|
|
|
3e5111 |
-
|
|
|
3e5111 |
- if (VIR_ALLOC(addr) < 0)
|
|
|
3e5111 |
- goto out;
|
|
|
3e5111 |
-
|
|
|
3e5111 |
- if (virPCIDeviceAddressParseXML(addresses[i], addr) < 0) {
|
|
|
3e5111 |
- VIR_FREE(addr);
|
|
|
3e5111 |
- goto out;
|
|
|
3e5111 |
- }
|
|
|
3e5111 |
-
|
|
|
3e5111 |
- if (VIR_APPEND_ELEMENT(pci_dev->virtual_functions,
|
|
|
3e5111 |
- pci_dev->num_virtual_functions,
|
|
|
3e5111 |
- addr) < 0)
|
|
|
3e5111 |
- goto out;
|
|
|
3e5111 |
- }
|
|
|
3e5111 |
-
|
|
|
3e5111 |
- pci_dev->flags |= VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTION;
|
|
|
3e5111 |
+ if (STREQ(type, "phys_function") &&
|
|
|
3e5111 |
+ virNodeDevPCICapSRIOVPhysicalParseXML(ctxt, pci_dev) < 0) {
|
|
|
3e5111 |
+ goto cleanup;
|
|
|
3e5111 |
+ } else if (STREQ(type, "virt_functions") &&
|
|
|
3e5111 |
+ virNodeDevPCICapSRIOVVirtualParseXML(ctxt, pci_dev) < 0) {
|
|
|
3e5111 |
+ goto cleanup;
|
|
|
3e5111 |
} else {
|
|
|
3e5111 |
int hdrType = virPCIHeaderTypeFromString(type);
|
|
|
3e5111 |
|
|
|
3e5111 |
@@ -1364,9 +1390,7 @@ virNodeDevPCICapabilityParseXML(xmlXPathContextPtr ctxt,
|
|
|
3e5111 |
}
|
|
|
3e5111 |
|
|
|
3e5111 |
ret = 0;
|
|
|
3e5111 |
- out:
|
|
|
3e5111 |
- VIR_FREE(addresses);
|
|
|
3e5111 |
- VIR_FREE(maxFuncsStr);
|
|
|
3e5111 |
+ cleanup:
|
|
|
3e5111 |
VIR_FREE(type);
|
|
|
3e5111 |
ctxt->node = orignode;
|
|
|
3e5111 |
return ret;
|
|
|
3e5111 |
--
|
|
|
3e5111 |
2.13.0
|
|
|
3e5111 |
|