diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index b483928a49..b2aa7771a0 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -768,6 +768,72 @@ virNodeDevCapDRMParseXML(xmlXPathContextPtr ctxt, } +static int +virNodeDevCapMdevTypesParseXML(xmlXPathContextPtr ctxt, + virMediatedDeviceTypePtr **mdev_types, + size_t *nmdev_types) +{ + int ret = -1; + xmlNodePtr orignode = NULL; + xmlNodePtr *nodes = NULL; + int ntypes = -1; + virMediatedDeviceTypePtr type = NULL; + size_t i; + + if ((ntypes = virXPathNodeSet("./type", ctxt, &nodes)) < 0) + goto cleanup; + + if (nmdev_types == 0) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("missing element in element")); + goto cleanup; + } + + orignode = ctxt->node; + for (i = 0; i < ntypes; i++) { + ctxt->node = nodes[i]; + + type = g_new0(virMediatedDeviceType, 1); + + if (!(type->id = virXPathString("string(./@id[1])", ctxt))) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("missing 'id' attribute for mediated device's " + " element")); + goto cleanup; + } + + if (!(type->device_api = virXPathString("string(./deviceAPI[1])", ctxt))) { + virReportError(VIR_ERR_XML_ERROR, + _("missing device API for mediated device type '%s'"), + type->id); + goto cleanup; + } + + if (virXPathUInt("number(./availableInstances)", ctxt, + &type->available_instances) < 0) { + virReportError(VIR_ERR_XML_ERROR, + _("missing number of available instances for " + "mediated device type '%s'"), + type->id); + goto cleanup; + } + + type->name = virXPathString("string(./name)", ctxt); + + if (VIR_APPEND_ELEMENT(*mdev_types, + *nmdev_types, type) < 0) + goto cleanup; + } + + ret = 0; + cleanup: + VIR_FREE(nodes); + virMediatedDeviceTypeFree(type); + ctxt->node = orignode; + return ret; +} + + static int virNodeDevCapCCWParseXML(xmlXPathContextPtr ctxt, virNodeDeviceDefPtr def, @@ -1532,72 +1598,6 @@ virNodeDevPCICapSRIOVVirtualParseXML(xmlXPathContextPtr ctxt, } -static int -virNodeDevPCICapMdevTypesParseXML(xmlXPathContextPtr ctxt, - virNodeDevCapPCIDevPtr pci_dev) -{ - int ret = -1; - xmlNodePtr orignode = NULL; - xmlNodePtr *nodes = NULL; - int nmdev_types = -1; - virMediatedDeviceTypePtr type = NULL; - size_t i; - - if ((nmdev_types = virXPathNodeSet("./type", ctxt, &nodes)) < 0) - goto cleanup; - - if (nmdev_types == 0) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("missing element in element")); - goto cleanup; - } - - orignode = ctxt->node; - for (i = 0; i < nmdev_types; i++) { - ctxt->node = nodes[i]; - - type = g_new0(virMediatedDeviceType, 1); - - if (!(type->id = virXPathString("string(./@id[1])", ctxt))) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("missing 'id' attribute for mediated device's " - " element")); - goto cleanup; - } - - if (!(type->device_api = virXPathString("string(./deviceAPI[1])", ctxt))) { - virReportError(VIR_ERR_XML_ERROR, - _("missing device API for mediated device type '%s'"), - type->id); - goto cleanup; - } - - if (virXPathUInt("number(./availableInstances)", ctxt, - &type->available_instances) < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("missing number of available instances for " - "mediated device type '%s'"), - type->id); - goto cleanup; - } - - type->name = virXPathString("string(./name)", ctxt); - - if (VIR_APPEND_ELEMENT(pci_dev->mdev_types, - pci_dev->nmdev_types, type) < 0) - goto cleanup; - } - - pci_dev->flags |= VIR_NODE_DEV_CAP_FLAG_PCI_MDEV; - ret = 0; - cleanup: - VIR_FREE(nodes); - virMediatedDeviceTypeFree(type); - ctxt->node = orignode; - return ret; -} - - static int virNodeDevPCICapabilityParseXML(xmlXPathContextPtr ctxt, xmlNodePtr node, @@ -1620,9 +1620,12 @@ virNodeDevPCICapabilityParseXML(xmlXPathContextPtr ctxt, } else if (STREQ(type, "virt_functions") && virNodeDevPCICapSRIOVVirtualParseXML(ctxt, pci_dev) < 0) { goto cleanup; - } else if (STREQ(type, "mdev_types") && - virNodeDevPCICapMdevTypesParseXML(ctxt, pci_dev) < 0) { - goto cleanup; + } else if (STREQ(type, "mdev_types")) { + if (virNodeDevCapMdevTypesParseXML(ctxt, + &pci_dev->mdev_types, + &pci_dev->nmdev_types) < 0) + goto cleanup; + pci_dev->flags |= VIR_NODE_DEV_CAP_FLAG_PCI_MDEV; } else { int hdrType = virPCIHeaderTypeFromString(type);