diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c index 1565d43fe6..cbdfbf6ef4 100644 --- a/src/conf/device_conf.c +++ b/src/conf/device_conf.c @@ -330,6 +330,273 @@ virDomainDeviceCCWAddressIsValid(virDomainDeviceCCWAddressPtr addr) addr->devno <= VIR_DOMAIN_DEVICE_CCW_MAX_DEVNO; } +int +virDomainDeviceCCWAddressParseXML(xmlNodePtr node, + virDomainDeviceCCWAddressPtr addr) +{ + int ret = -1; + char *cssid; + char *ssid; + char *devno; + + memset(addr, 0, sizeof(*addr)); + + cssid = virXMLPropString(node, "cssid"); + ssid = virXMLPropString(node, "ssid"); + devno = virXMLPropString(node, "devno"); + + if (cssid && ssid && devno) { + if (cssid && + virStrToLong_uip(cssid, NULL, 0, &addr->cssid) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot parse
'cssid' attribute")); + goto cleanup; + } + if (ssid && + virStrToLong_uip(ssid, NULL, 0, &addr->ssid) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot parse 'ssid' attribute")); + goto cleanup; + } + if (devno && + virStrToLong_uip(devno, NULL, 0, &addr->devno) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot parse 'devno' attribute")); + goto cleanup; + } + if (!virDomainDeviceCCWAddressIsValid(addr)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Invalid specification for virtio ccw" + " address: cssid='%s' ssid='%s' devno='%s'"), + cssid, ssid, devno); + goto cleanup; + } + addr->assigned = true; + } else if (cssid || ssid || devno) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Invalid partial specification for virtio ccw" + " address")); + goto cleanup; + } + + ret = 0; + + cleanup: + VIR_FREE(cssid); + VIR_FREE(ssid); + VIR_FREE(devno); + return ret; +} + +int +virDomainDeviceDriveAddressParseXML(xmlNodePtr node, + virDomainDeviceDriveAddressPtr addr) +{ + char *bus, *unit, *controller, *target; + int ret = -1; + + memset(addr, 0, sizeof(*addr)); + + controller = virXMLPropString(node, "controller"); + bus = virXMLPropString(node, "bus"); + target = virXMLPropString(node, "target"); + unit = virXMLPropString(node, "unit"); + + if (controller && + virStrToLong_uip(controller, NULL, 10, &addr->controller) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot parse 'controller' attribute")); + goto cleanup; + } + + if (bus && + virStrToLong_uip(bus, NULL, 10, &addr->bus) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot parse 'bus' attribute")); + goto cleanup; + } + + if (target && + virStrToLong_uip(target, NULL, 10, &addr->target) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot parse 'target' attribute")); + goto cleanup; + } + + if (unit && + virStrToLong_uip(unit, NULL, 10, &addr->unit) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot parse 'unit' attribute")); + goto cleanup; + } + + ret = 0; + + cleanup: + VIR_FREE(controller); + VIR_FREE(bus); + VIR_FREE(target); + VIR_FREE(unit); + return ret; +} + +int +virDomainDeviceVirtioSerialAddressParseXML(xmlNodePtr node, + virDomainDeviceVirtioSerialAddressPtr addr) +{ + char *controller, *bus, *port; + int ret = -1; + + memset(addr, 0, sizeof(*addr)); + + controller = virXMLPropString(node, "controller"); + bus = virXMLPropString(node, "bus"); + port = virXMLPropString(node, "port"); + + if (controller && + virStrToLong_uip(controller, NULL, 10, &addr->controller) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot parse 'controller' attribute")); + goto cleanup; + } + + if (bus && + virStrToLong_uip(bus, NULL, 10, &addr->bus) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot parse 'bus' attribute")); + goto cleanup; + } + + if (port && + virStrToLong_uip(port, NULL, 10, &addr->port) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot parse 'port' attribute")); + goto cleanup; + } + + ret = 0; + + cleanup: + VIR_FREE(controller); + VIR_FREE(bus); + VIR_FREE(port); + return ret; +} + +int +virDomainDeviceCcidAddressParseXML(xmlNodePtr node, + virDomainDeviceCcidAddressPtr addr) +{ + char *controller, *slot; + int ret = -1; + + memset(addr, 0, sizeof(*addr)); + + controller = virXMLPropString(node, "controller"); + slot = virXMLPropString(node, "slot"); + + if (controller && + virStrToLong_uip(controller, NULL, 10, &addr->controller) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot parse 'controller' attribute")); + goto cleanup; + } + + if (slot && + virStrToLong_uip(slot, NULL, 10, &addr->slot) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot parse 'slot' attribute")); + goto cleanup; + } + + ret = 0; + + cleanup: + VIR_FREE(controller); + VIR_FREE(slot); + return ret; +} + +static int +virDomainDeviceUSBAddressParsePort(virDomainDeviceUSBAddressPtr addr, + char *port) +{ + char *tmp = port; + size_t i; + + for (i = 0; i < VIR_DOMAIN_DEVICE_USB_MAX_PORT_DEPTH; i++) { + if (virStrToLong_uip(tmp, &tmp, 10, &addr->port[i]) < 0) + break; + + if (*tmp == '\0') + return 0; + + if (*tmp == '.') + tmp++; + } + + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot parse 'port' attribute")); + return -1; +} + +int +virDomainDeviceUSBAddressParseXML(xmlNodePtr node, + virDomainDeviceUSBAddressPtr addr) +{ + char *port, *bus; + int ret = -1; + + memset(addr, 0, sizeof(*addr)); + + port = virXMLPropString(node, "port"); + bus = virXMLPropString(node, "bus"); + + if (port && virDomainDeviceUSBAddressParsePort(addr, port) < 0) + goto cleanup; + + if (bus && + virStrToLong_uip(bus, NULL, 10, &addr->bus) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot parse 'bus' attribute")); + goto cleanup; + } + + ret = 0; + + cleanup: + VIR_FREE(bus); + VIR_FREE(port); + return ret; +} + +int +virDomainDeviceSpaprVioAddressParseXML(xmlNodePtr node, + virDomainDeviceSpaprVioAddressPtr addr) +{ + char *reg; + int ret; + + memset(addr, 0, sizeof(*addr)); + + reg = virXMLPropString(node, "reg"); + if (reg) { + if (virStrToLong_ull(reg, NULL, 16, &addr->reg) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot parse 'reg' attribute")); + ret = -1; + goto cleanup; + } + + addr->has_reg = true; + } + + ret = 0; + cleanup: + VIR_FREE(reg); + return ret; +} + bool virDomainDeviceAddressIsValid(virDomainDeviceInfoPtr info, int type) diff --git a/src/conf/device_conf.h b/src/conf/device_conf.h index b09d6bcecb..9f51118e29 100644 --- a/src/conf/device_conf.h +++ b/src/conf/device_conf.h @@ -209,6 +209,23 @@ bool virPCIDeviceAddressEqual(virPCIDeviceAddress *addr1, virPCIDeviceAddress *addr2); bool virDomainDeviceCCWAddressIsValid(virDomainDeviceCCWAddressPtr addr); +int virDomainDeviceCCWAddressParseXML(xmlNodePtr node, + virDomainDeviceCCWAddressPtr addr); + +int virDomainDeviceDriveAddressParseXML(xmlNodePtr node, + virDomainDeviceDriveAddressPtr addr); + +int virDomainDeviceVirtioSerialAddressParseXML(xmlNodePtr node, + virDomainDeviceVirtioSerialAddressPtr addr); + +int virDomainDeviceCcidAddressParseXML(xmlNodePtr node, + virDomainDeviceCcidAddressPtr addr); + +int virDomainDeviceUSBAddressParseXML(xmlNodePtr node, + virDomainDeviceUSBAddressPtr addr); + +int virDomainDeviceSpaprVioAddressParseXML(xmlNodePtr node, + virDomainDeviceSpaprVioAddressPtr addr); int virInterfaceLinkParseXML(xmlNodePtr node, virNetDevIfLinkPtr lnk); diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index fcb4103ad9..86199623cc 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -6538,276 +6538,6 @@ virDomainDeviceInfoFormat(virBufferPtr buf, virBufferAddLit(buf, "/>\n"); } -static int -virDomainDeviceDriveAddressParseXML(xmlNodePtr node, - virDomainDeviceDriveAddressPtr addr) -{ - char *bus, *unit, *controller, *target; - int ret = -1; - - memset(addr, 0, sizeof(*addr)); - - controller = virXMLPropString(node, "controller"); - bus = virXMLPropString(node, "bus"); - target = virXMLPropString(node, "target"); - unit = virXMLPropString(node, "unit"); - - if (controller && - virStrToLong_uip(controller, NULL, 10, &addr->controller) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot parse 'controller' attribute")); - goto cleanup; - } - - if (bus && - virStrToLong_uip(bus, NULL, 10, &addr->bus) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot parse 'bus' attribute")); - goto cleanup; - } - - if (target && - virStrToLong_uip(target, NULL, 10, &addr->target) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot parse 'target' attribute")); - goto cleanup; - } - - if (unit && - virStrToLong_uip(unit, NULL, 10, &addr->unit) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot parse 'unit' attribute")); - goto cleanup; - } - - ret = 0; - - cleanup: - VIR_FREE(controller); - VIR_FREE(bus); - VIR_FREE(target); - VIR_FREE(unit); - return ret; -} - - -static int -virDomainDeviceVirtioSerialAddressParseXML( - xmlNodePtr node, - virDomainDeviceVirtioSerialAddressPtr addr -) -{ - char *controller, *bus, *port; - int ret = -1; - - memset(addr, 0, sizeof(*addr)); - - controller = virXMLPropString(node, "controller"); - bus = virXMLPropString(node, "bus"); - port = virXMLPropString(node, "port"); - - if (controller && - virStrToLong_uip(controller, NULL, 10, &addr->controller) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot parse 'controller' attribute")); - goto cleanup; - } - - if (bus && - virStrToLong_uip(bus, NULL, 10, &addr->bus) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot parse 'bus' attribute")); - goto cleanup; - } - - if (port && - virStrToLong_uip(port, NULL, 10, &addr->port) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot parse 'port' attribute")); - goto cleanup; - } - - ret = 0; - - cleanup: - VIR_FREE(controller); - VIR_FREE(bus); - VIR_FREE(port); - return ret; -} - -static int -virDomainDeviceCCWAddressParseXML(xmlNodePtr node, - virDomainDeviceCCWAddressPtr addr) -{ - int ret = -1; - char *cssid; - char *ssid; - char *devno; - - memset(addr, 0, sizeof(*addr)); - - cssid = virXMLPropString(node, "cssid"); - ssid = virXMLPropString(node, "ssid"); - devno = virXMLPropString(node, "devno"); - - if (cssid && ssid && devno) { - if (cssid && - virStrToLong_uip(cssid, NULL, 0, &addr->cssid) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot parse 'cssid' attribute")); - goto cleanup; - } - if (ssid && - virStrToLong_uip(ssid, NULL, 0, &addr->ssid) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot parse 'ssid' attribute")); - goto cleanup; - } - if (devno && - virStrToLong_uip(devno, NULL, 0, &addr->devno) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot parse 'devno' attribute")); - goto cleanup; - } - if (!virDomainDeviceCCWAddressIsValid(addr)) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Invalid specification for virtio ccw" - " address: cssid='%s' ssid='%s' devno='%s'"), - cssid, ssid, devno); - goto cleanup; - } - addr->assigned = true; - } else if (cssid || ssid || devno) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Invalid partial specification for virtio ccw" - " address")); - goto cleanup; - } - - ret = 0; - - cleanup: - VIR_FREE(cssid); - VIR_FREE(ssid); - VIR_FREE(devno); - return ret; -} - -static int -virDomainDeviceCcidAddressParseXML(xmlNodePtr node, - virDomainDeviceCcidAddressPtr addr) -{ - char *controller, *slot; - int ret = -1; - - memset(addr, 0, sizeof(*addr)); - - controller = virXMLPropString(node, "controller"); - slot = virXMLPropString(node, "slot"); - - if (controller && - virStrToLong_uip(controller, NULL, 10, &addr->controller) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot parse 'controller' attribute")); - goto cleanup; - } - - if (slot && - virStrToLong_uip(slot, NULL, 10, &addr->slot) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot parse 'slot' attribute")); - goto cleanup; - } - - ret = 0; - - cleanup: - VIR_FREE(controller); - VIR_FREE(slot); - return ret; -} - -static int -virDomainDeviceUSBAddressParsePort(virDomainDeviceUSBAddressPtr addr, - char *port) -{ - char *tmp = port; - size_t i; - - for (i = 0; i < VIR_DOMAIN_DEVICE_USB_MAX_PORT_DEPTH; i++) { - if (virStrToLong_uip(tmp, &tmp, 10, &addr->port[i]) < 0) - break; - - if (*tmp == '\0') - return 0; - - if (*tmp == '.') - tmp++; - } - - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot parse 'port' attribute")); - return -1; -} - -static int -virDomainDeviceUSBAddressParseXML(xmlNodePtr node, - virDomainDeviceUSBAddressPtr addr) -{ - char *port, *bus; - int ret = -1; - - memset(addr, 0, sizeof(*addr)); - - port = virXMLPropString(node, "port"); - bus = virXMLPropString(node, "bus"); - - if (port && virDomainDeviceUSBAddressParsePort(addr, port) < 0) - goto cleanup; - - if (bus && - virStrToLong_uip(bus, NULL, 10, &addr->bus) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot parse 'bus' attribute")); - goto cleanup; - } - - ret = 0; - - cleanup: - VIR_FREE(bus); - VIR_FREE(port); - return ret; -} - -static int -virDomainDeviceSpaprVioAddressParseXML(xmlNodePtr node, - virDomainDeviceSpaprVioAddressPtr addr) -{ - char *reg; - int ret; - - memset(addr, 0, sizeof(*addr)); - - reg = virXMLPropString(node, "reg"); - if (reg) { - if (virStrToLong_ull(reg, NULL, 16, &addr->reg) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot parse 'reg' attribute")); - ret = -1; - goto cleanup; - } - - addr->has_reg = true; - } - - ret = 0; - cleanup: - VIR_FREE(reg); - return ret; -} - static int virDomainDeviceUSBMasterParseXML(xmlNodePtr node, virDomainDeviceUSBMasterPtr master) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 96520958df..e2340d23a6 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -97,9 +97,15 @@ virDeviceInfoPCIAddressIsPresent; virDeviceInfoPCIAddressIsWanted; virDomainDeviceAddressIsValid; virDomainDeviceAddressTypeToString; +virDomainDeviceCcidAddressParseXML; virDomainDeviceCCWAddressIsValid; +virDomainDeviceCCWAddressParseXML; +virDomainDeviceDriveAddressParseXML; virDomainDeviceInfoAddressIsEqual; virDomainDeviceInfoCopy; +virDomainDeviceSpaprVioAddressParseXML; +virDomainDeviceUSBAddressParseXML; +virDomainDeviceVirtioSerialAddressParseXML; virInterfaceLinkFormat; virInterfaceLinkParseXML; virPCIDeviceAddressEqual;