提交 a5c1f3b7 编写于 作者: E Erik Skultety

nodedev: conf: Split PCI sub-capability parsing to separate methods

Since there's at least SRIOV and MDEV sub-capabilities to be parsed,
let's make the code more readable by splitting it to several logical
blocks.
Signed-off-by: NErik Skultety <eskultet@redhat.com>
上级 3a2a2a74
...@@ -1286,76 +1286,102 @@ virPCIEDeviceInfoParseXML(xmlXPathContextPtr ctxt, ...@@ -1286,76 +1286,102 @@ virPCIEDeviceInfoParseXML(xmlXPathContextPtr ctxt,
static int static int
virNodeDevPCICapabilityParseXML(xmlXPathContextPtr ctxt, virNodeDevPCICapSRIOVPhysicalParseXML(xmlXPathContextPtr ctxt,
xmlNodePtr node, virNodeDevCapPCIDevPtr pci_dev)
virNodeDevCapPCIDevPtr pci_dev)
{ {
char *maxFuncsStr = virXMLPropString(node, "maxCount"); xmlNodePtr address = virXPathNode("./address[1]", ctxt);
char *type = virXMLPropString(node, "type");
xmlNodePtr *addresses = NULL;
xmlNodePtr orignode = ctxt->node;
int ret = -1;
size_t i = 0;
ctxt->node = node; if (VIR_ALLOC(pci_dev->physical_function) < 0)
return -1;
if (!type) { if (!address) {
virReportError(VIR_ERR_XML_ERROR, "%s", _("Missing capability type")); virReportError(VIR_ERR_XML_ERROR, "%s",
goto out; _("Missing address in 'phys_function' capability"));
return -1;
} }
if (STREQ(type, "phys_function")) { if (virPCIDeviceAddressParseXML(address,
xmlNodePtr address = virXPathNode("./address[1]", ctxt); pci_dev->physical_function) < 0)
return -1;
if (VIR_ALLOC(pci_dev->physical_function) < 0) pci_dev->flags |= VIR_NODE_DEV_CAP_FLAG_PCI_PHYSICAL_FUNCTION;
goto out;
if (!address) { return 0;
virReportError(VIR_ERR_XML_ERROR, "%s", }
_("Missing address in 'phys_function' capability"));
goto out;
}
if (virPCIDeviceAddressParseXML(address,
pci_dev->physical_function) < 0)
goto out;
pci_dev->flags |= VIR_NODE_DEV_CAP_FLAG_PCI_PHYSICAL_FUNCTION; static int
} else if (STREQ(type, "virt_functions")) { virNodeDevPCICapSRIOVVirtualParseXML(xmlXPathContextPtr ctxt,
int naddresses; virNodeDevCapPCIDevPtr pci_dev)
{
int ret = -1;
xmlNodePtr *addresses = NULL;
int naddresses = virXPathNodeSet("./address", ctxt, &addresses);
char *maxFuncsStr = virXPathString("string(./@maxCount)", ctxt);
size_t i;
if ((naddresses = virXPathNodeSet("./address", ctxt, &addresses)) < 0) if (naddresses < 0)
goto out; goto cleanup;
if (maxFuncsStr && if (maxFuncsStr &&
virStrToLong_uip(maxFuncsStr, NULL, 10, virStrToLong_uip(maxFuncsStr, NULL, 10,
&pci_dev->max_virtual_functions) < 0) { &pci_dev->max_virtual_functions) < 0) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("Malformed 'maxCount' parameter")); _("Malformed 'maxCount' parameter"));
goto out; goto cleanup;
}
if (VIR_ALLOC_N(pci_dev->virtual_functions, naddresses) < 0)
goto cleanup;
for (i = 0; i < naddresses; i++) {
virPCIDeviceAddressPtr addr = NULL;
if (VIR_ALLOC(addr) < 0)
goto cleanup;
if (virPCIDeviceAddressParseXML(addresses[i], addr) < 0) {
VIR_FREE(addr);
goto cleanup;
} }
if (VIR_ALLOC_N(pci_dev->virtual_functions, naddresses) < 0) if (VIR_APPEND_ELEMENT(pci_dev->virtual_functions,
goto out; pci_dev->num_virtual_functions,
addr) < 0)
goto cleanup;
}
for (i = 0; i < naddresses; i++) { pci_dev->flags |= VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTION;
virPCIDeviceAddressPtr addr = NULL; ret = 0;
cleanup:
VIR_FREE(addresses);
VIR_FREE(maxFuncsStr);
return ret;
}
if (VIR_ALLOC(addr) < 0)
goto out;
if (virPCIDeviceAddressParseXML(addresses[i], addr) < 0) { static int
VIR_FREE(addr); virNodeDevPCICapabilityParseXML(xmlXPathContextPtr ctxt,
goto out; xmlNodePtr node,
} virNodeDevCapPCIDevPtr pci_dev)
{
char *type = virXMLPropString(node, "type");
xmlNodePtr orignode = ctxt->node;
int ret = -1;
if (VIR_APPEND_ELEMENT(pci_dev->virtual_functions, ctxt->node = node;
pci_dev->num_virtual_functions,
addr) < 0) if (!type) {
goto out; virReportError(VIR_ERR_XML_ERROR, "%s", _("Missing capability type"));
} goto cleanup;
}
pci_dev->flags |= VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTION; if (STREQ(type, "phys_function") &&
virNodeDevPCICapSRIOVPhysicalParseXML(ctxt, pci_dev) < 0) {
goto cleanup;
} else if (STREQ(type, "virt_functions") &&
virNodeDevPCICapSRIOVVirtualParseXML(ctxt, pci_dev) < 0) {
goto cleanup;
} else { } else {
int hdrType = virPCIHeaderTypeFromString(type); int hdrType = virPCIHeaderTypeFromString(type);
...@@ -1364,9 +1390,7 @@ virNodeDevPCICapabilityParseXML(xmlXPathContextPtr ctxt, ...@@ -1364,9 +1390,7 @@ virNodeDevPCICapabilityParseXML(xmlXPathContextPtr ctxt,
} }
ret = 0; ret = 0;
out: cleanup:
VIR_FREE(addresses);
VIR_FREE(maxFuncsStr);
VIR_FREE(type); VIR_FREE(type);
ctxt->node = orignode; ctxt->node = orignode;
return ret; return ret;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册