[libvirt] [PATCH 0/6] conf: Move a bunch of stuff to device_conf

These are the times where I wish we were using a language with support for proper classes and modules like, I dunno, PHP or something. Andrea Bolognani (6): conf: Move virDomainDeviceAddressType to device_conf conf: Move virDomainDeviceAddressIsValid() to device_conf conf: Change return type of *AddressIsValid() to bool conf: Move virDomainPCIAddressAsString() to device_conf conf: Rename virDomainPCIAddressAsString() conf: Move *AddressParseXML() to device_conf src/conf/device_conf.c | 348 ++++++++++++++++++++++++++++++++- src/conf/device_conf.h | 31 ++- src/conf/domain_addr.c | 20 +- src/conf/domain_addr.h | 3 - src/conf/domain_conf.c | 320 ------------------------------ src/conf/domain_conf.h | 3 - src/libvirt_private.syms | 13 +- src/qemu/qemu_command.c | 2 +- src/qemu/qemu_domain_address.c | 6 +- 9 files changed, 386 insertions(+), 360 deletions(-) -- 2.17.1

It's used in virDomainDeviceInfo, which makes domain_conf the wrong place to declare it. Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- src/conf/device_conf.c | 15 +++++++++++++++ src/conf/device_conf.h | 2 ++ src/conf/domain_conf.c | 14 -------------- src/conf/domain_conf.h | 1 - src/libvirt_private.syms | 2 +- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c index 7a8f84e036..dd381f303e 100644 --- a/src/conf/device_conf.c +++ b/src/conf/device_conf.c @@ -32,6 +32,21 @@ #define VIR_FROM_THIS VIR_FROM_DEVICE +VIR_ENUM_IMPL(virDomainDeviceAddress, VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST, + "none", + "pci", + "drive", + "virtio-serial", + "ccid", + "usb", + "spapr-vio", + "virtio-s390", + "ccw", + "virtio-mmio", + "isa", + "dimm", +); + int virDomainDeviceInfoCopy(virDomainDeviceInfoPtr dst, virDomainDeviceInfoPtr src) diff --git a/src/conf/device_conf.h b/src/conf/device_conf.h index ff7d6c9d5f..66a999760c 100644 --- a/src/conf/device_conf.h +++ b/src/conf/device_conf.h @@ -51,6 +51,8 @@ typedef enum { VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST } virDomainDeviceAddressType; +VIR_ENUM_DECL(virDomainDeviceAddress); + typedef struct _virDomainDeviceDriveAddress virDomainDeviceDriveAddress; typedef virDomainDeviceDriveAddress *virDomainDeviceDriveAddressPtr; struct _virDomainDeviceDriveAddress { diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 38cac07913..2a22978855 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -263,20 +263,6 @@ VIR_ENUM_IMPL(virDomainDevice, VIR_DOMAIN_DEVICE_LAST, "iommu", "vsock") -VIR_ENUM_IMPL(virDomainDeviceAddress, VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST, - "none", - "pci", - "drive", - "virtio-serial", - "ccid", - "usb", - "spapr-vio", - "virtio-s390", - "ccw", - "virtio-mmio", - "isa", - "dimm") - VIR_ENUM_IMPL(virDomainDiskDevice, VIR_DOMAIN_DISK_DEVICE_LAST, "disk", "cdrom", diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 8a3673361a..2a827a093f 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3380,7 +3380,6 @@ VIR_ENUM_DECL(virDomainCapsFeature) VIR_ENUM_DECL(virDomainLifecycle) VIR_ENUM_DECL(virDomainLifecycleAction) VIR_ENUM_DECL(virDomainDevice) -VIR_ENUM_DECL(virDomainDeviceAddress) VIR_ENUM_DECL(virDomainDiskDevice) VIR_ENUM_DECL(virDomainDiskGeometryTrans) VIR_ENUM_DECL(virDomainDiskBus) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 954ab4b66c..ae0c26ba99 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -95,6 +95,7 @@ virCPUModeTypeToString; # conf/device_conf.h virDeviceInfoPCIAddressIsPresent; virDeviceInfoPCIAddressIsWanted; +virDomainDeviceAddressTypeToString; virDomainDeviceInfoAddressIsEqual; virDomainDeviceInfoCopy; virInterfaceLinkFormat; @@ -291,7 +292,6 @@ virDomainDefValidate; virDomainDefVcpuOrderClear; virDomainDeleteConfig; virDomainDeviceAddressIsValid; -virDomainDeviceAddressTypeToString; virDomainDeviceAliasIsUserAlias; virDomainDeviceDefCopy; virDomainDeviceDefFree; -- 2.17.1

On Fri, Aug 31, 2018 at 04:00:42PM +0200, Andrea Bolognani wrote:
It's used in virDomainDeviceInfo, which makes domain_conf the wrong place to declare it.
Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- src/conf/device_conf.c | 15 +++++++++++++++ src/conf/device_conf.h | 2 ++ src/conf/domain_conf.c | 14 -------------- src/conf/domain_conf.h | 1 - src/libvirt_private.syms | 2 +- 5 files changed, 18 insertions(+), 16 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

The function is called on a virDomainDeviceInfo, so it should be declared along with it. Moving this function requires moving and making public virDomainDeviceCCWAddressIsValid() as well, but that's perfectly fine since the same reasoning above also applies to it, due to virDomainDeviceCCWAddress being (correctly) declared in device_conf. Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- src/conf/device_conf.c | 36 ++++++++++++++++++++++++++++++++++++ src/conf/device_conf.h | 5 +++++ src/conf/domain_conf.c | 36 ------------------------------------ src/conf/domain_conf.h | 2 -- src/libvirt_private.syms | 3 ++- 5 files changed, 43 insertions(+), 39 deletions(-) diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c index dd381f303e..1db92aba4a 100644 --- a/src/conf/device_conf.c +++ b/src/conf/device_conf.c @@ -321,6 +321,42 @@ virPCIDeviceAddressEqual(virPCIDeviceAddress *addr1, return false; } +int +virDomainDeviceCCWAddressIsValid(virDomainDeviceCCWAddressPtr addr) +{ + return addr->cssid <= VIR_DOMAIN_DEVICE_CCW_MAX_CSSID && + addr->ssid <= VIR_DOMAIN_DEVICE_CCW_MAX_SSID && + addr->devno <= VIR_DOMAIN_DEVICE_CCW_MAX_DEVNO; +} + +int +virDomainDeviceAddressIsValid(virDomainDeviceInfoPtr info, + int type) +{ + if (info->type != type) + return 0; + + switch (info->type) { + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI: + return virPCIDeviceAddressIsValid(&info->addr.pci, false); + + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE: + return 1; + + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390: + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO: + return 1; + + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW: + return virDomainDeviceCCWAddressIsValid(&info->addr.ccw); + + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB: + return 1; + } + + return 0; +} + int virInterfaceLinkParseXML(xmlNodePtr node, virNetDevIfLinkPtr lnk) diff --git a/src/conf/device_conf.h b/src/conf/device_conf.h index 66a999760c..4a50c3183e 100644 --- a/src/conf/device_conf.h +++ b/src/conf/device_conf.h @@ -188,6 +188,9 @@ bool virDomainDeviceInfoAddressIsEqual(const virDomainDeviceInfo *a, const virDomainDeviceInfo *b) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK; +int virDomainDeviceAddressIsValid(virDomainDeviceInfoPtr info, + int type); + int virPCIDeviceAddressIsValid(virPCIDeviceAddressPtr addr, bool report); bool virPCIDeviceAddressIsEmpty(const virPCIDeviceAddress *addr); @@ -205,6 +208,8 @@ int virPCIDeviceAddressFormat(virBufferPtr buf, bool virPCIDeviceAddressEqual(virPCIDeviceAddress *addr1, virPCIDeviceAddress *addr2); +int virDomainDeviceCCWAddressIsValid(virDomainDeviceCCWAddressPtr addr); + int virInterfaceLinkParseXML(xmlNodePtr node, virNetDevIfLinkPtr lnk); diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 2a22978855..3cae6b2aeb 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -3586,42 +3586,6 @@ virDomainObjGetOneDef(virDomainObjPtr vm, return virDomainObjGetOneDefState(vm, flags, NULL); } - -static int -virDomainDeviceCCWAddressIsValid(virDomainDeviceCCWAddressPtr addr) -{ - return addr->cssid <= VIR_DOMAIN_DEVICE_CCW_MAX_CSSID && - addr->ssid <= VIR_DOMAIN_DEVICE_CCW_MAX_SSID && - addr->devno <= VIR_DOMAIN_DEVICE_CCW_MAX_DEVNO; -} - -int virDomainDeviceAddressIsValid(virDomainDeviceInfoPtr info, - int type) -{ - if (info->type != type) - return 0; - - switch (info->type) { - case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI: - return virPCIDeviceAddressIsValid(&info->addr.pci, false); - - case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE: - return 1; - - case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390: - case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO: - return 1; - - case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW: - return virDomainDeviceCCWAddressIsValid(&info->addr.ccw); - - case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB: - return 1; - } - - return 0; -} - virDomainDeviceInfoPtr virDomainDeviceGetInfo(virDomainDeviceDefPtr device) { diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 2a827a093f..3ff6eea117 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2911,8 +2911,6 @@ virDomainDeviceDefPtr virDomainDeviceDefCopy(virDomainDeviceDefPtr src, const virDomainDef *def, virCapsPtr caps, virDomainXMLOptionPtr xmlopt); -int virDomainDeviceAddressIsValid(virDomainDeviceInfoPtr info, - int type); virDomainDeviceInfoPtr virDomainDeviceGetInfo(virDomainDeviceDefPtr device); void virDomainTPMDefFree(virDomainTPMDefPtr def); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index ae0c26ba99..78307885dc 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -95,7 +95,9 @@ virCPUModeTypeToString; # conf/device_conf.h virDeviceInfoPCIAddressIsPresent; virDeviceInfoPCIAddressIsWanted; +virDomainDeviceAddressIsValid; virDomainDeviceAddressTypeToString; +virDomainDeviceCCWAddressIsValid; virDomainDeviceInfoAddressIsEqual; virDomainDeviceInfoCopy; virInterfaceLinkFormat; @@ -291,7 +293,6 @@ virDomainDefSetVcpusMax; virDomainDefValidate; virDomainDefVcpuOrderClear; virDomainDeleteConfig; -virDomainDeviceAddressIsValid; virDomainDeviceAliasIsUserAlias; virDomainDeviceDefCopy; virDomainDeviceDefFree; -- 2.17.1

On Fri, Aug 31, 2018 at 04:00:43PM +0200, Andrea Bolognani wrote:
The function is called on a virDomainDeviceInfo, so it should be declared along with it.
Moving this function requires moving and making public virDomainDeviceCCWAddressIsValid() as well, but that's perfectly fine since the same reasoning above also applies to it, due to virDomainDeviceCCWAddress being (correctly) declared in device_conf.
Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- src/conf/device_conf.c | 36 ++++++++++++++++++++++++++++++++++++ src/conf/device_conf.h | 5 +++++ src/conf/domain_conf.c | 36 ------------------------------------ src/conf/domain_conf.h | 2 -- src/libvirt_private.syms | 3 ++- 5 files changed, 43 insertions(+), 39 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

These are simple predicates, which makes bool a more appropriate return type than int. Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- src/conf/device_conf.c | 31 ++++++++++++++++--------------- src/conf/device_conf.h | 10 +++++----- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c index 1db92aba4a..1565d43fe6 100644 --- a/src/conf/device_conf.c +++ b/src/conf/device_conf.c @@ -160,8 +160,9 @@ virDomainDeviceInfoAddressIsEqual(const virDomainDeviceInfo *a, return true; } -int virPCIDeviceAddressIsValid(virPCIDeviceAddressPtr addr, - bool report) +bool +virPCIDeviceAddressIsValid(virPCIDeviceAddressPtr addr, + bool report) { if (addr->domain > 0xFFFF) { if (report) @@ -169,7 +170,7 @@ int virPCIDeviceAddressIsValid(virPCIDeviceAddressPtr addr, _("Invalid PCI address domain='0x%x', " "must be <= 0xFFFF"), addr->domain); - return 0; + return false; } if (addr->bus > 0xFF) { if (report) @@ -177,7 +178,7 @@ int virPCIDeviceAddressIsValid(virPCIDeviceAddressPtr addr, _("Invalid PCI address bus='0x%x', " "must be <= 0xFF"), addr->bus); - return 0; + return false; } if (addr->slot > 0x1F) { if (report) @@ -185,7 +186,7 @@ int virPCIDeviceAddressIsValid(virPCIDeviceAddressPtr addr, _("Invalid PCI address slot='0x%x', " "must be <= 0x1F"), addr->slot); - return 0; + return false; } if (addr->function > 7) { if (report) @@ -193,16 +194,16 @@ int virPCIDeviceAddressIsValid(virPCIDeviceAddressPtr addr, _("Invalid PCI address function=0x%x, " "must be <= 7"), addr->function); - return 0; + return false; } if (virPCIDeviceAddressIsEmpty(addr)) { if (report) virReportError(VIR_ERR_XML_ERROR, "%s", _("Invalid PCI address 0000:00:00, at least " "one of domain, bus, or slot must be > 0")); - return 0; + return false; } - return 1; + return true; } @@ -321,7 +322,7 @@ virPCIDeviceAddressEqual(virPCIDeviceAddress *addr1, return false; } -int +bool virDomainDeviceCCWAddressIsValid(virDomainDeviceCCWAddressPtr addr) { return addr->cssid <= VIR_DOMAIN_DEVICE_CCW_MAX_CSSID && @@ -329,32 +330,32 @@ virDomainDeviceCCWAddressIsValid(virDomainDeviceCCWAddressPtr addr) addr->devno <= VIR_DOMAIN_DEVICE_CCW_MAX_DEVNO; } -int +bool virDomainDeviceAddressIsValid(virDomainDeviceInfoPtr info, int type) { if (info->type != type) - return 0; + return false; switch (info->type) { case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI: return virPCIDeviceAddressIsValid(&info->addr.pci, false); case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE: - return 1; + return true; case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390: case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO: - return 1; + return true; case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW: return virDomainDeviceCCWAddressIsValid(&info->addr.ccw); case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB: - return 1; + return true; } - return 0; + return false; } int diff --git a/src/conf/device_conf.h b/src/conf/device_conf.h index 4a50c3183e..b09d6bcecb 100644 --- a/src/conf/device_conf.h +++ b/src/conf/device_conf.h @@ -188,11 +188,11 @@ bool virDomainDeviceInfoAddressIsEqual(const virDomainDeviceInfo *a, const virDomainDeviceInfo *b) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK; -int virDomainDeviceAddressIsValid(virDomainDeviceInfoPtr info, - int type); +bool virDomainDeviceAddressIsValid(virDomainDeviceInfoPtr info, + int type); -int virPCIDeviceAddressIsValid(virPCIDeviceAddressPtr addr, - bool report); +bool virPCIDeviceAddressIsValid(virPCIDeviceAddressPtr addr, + bool report); bool virPCIDeviceAddressIsEmpty(const virPCIDeviceAddress *addr); bool virDeviceInfoPCIAddressIsWanted(const virDomainDeviceInfo *info); @@ -208,7 +208,7 @@ int virPCIDeviceAddressFormat(virBufferPtr buf, bool virPCIDeviceAddressEqual(virPCIDeviceAddress *addr1, virPCIDeviceAddress *addr2); -int virDomainDeviceCCWAddressIsValid(virDomainDeviceCCWAddressPtr addr); +bool virDomainDeviceCCWAddressIsValid(virDomainDeviceCCWAddressPtr addr); int virInterfaceLinkParseXML(xmlNodePtr node, virNetDevIfLinkPtr lnk); -- 2.17.1

On Fri, Aug 31, 2018 at 04:00:44PM +0200, Andrea Bolognani wrote:
These are simple predicates, which makes bool a more appropriate return type than int.
Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- src/conf/device_conf.c | 31 ++++++++++++++++--------------- src/conf/device_conf.h | 10 +++++----- 2 files changed, 21 insertions(+), 20 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

It's a better fit than domain_conf. Unfortunately, even after this change functions handling virPCIDeviceAddress are split pretty much evenly between conf/device_conf and utils/virpci: ideally everything would be moved to the former, including the struct declaration itself, and all the names would be changed to be consistent with the rest of the virDomainDevice*Address, but that's a cleanup for another day. Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- src/conf/device_conf.c | 13 +++++++++++++ src/conf/device_conf.h | 3 +++ src/conf/domain_addr.c | 14 -------------- src/conf/domain_addr.h | 3 --- src/libvirt_private.syms | 2 +- 5 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c index 1565d43fe6..afa06c3cda 100644 --- a/src/conf/device_conf.c +++ b/src/conf/device_conf.c @@ -309,6 +309,19 @@ virPCIDeviceAddressFormat(virBufferPtr buf, return 0; } +char * +virDomainPCIAddressAsString(virPCIDeviceAddressPtr addr) +{ + char *str; + + ignore_value(virAsprintf(&str, "%.4x:%.2x:%.2x.%.1x", + addr->domain, + addr->bus, + addr->slot, + addr->function)); + return str; +} + bool virPCIDeviceAddressEqual(virPCIDeviceAddress *addr1, virPCIDeviceAddress *addr2) diff --git a/src/conf/device_conf.h b/src/conf/device_conf.h index b09d6bcecb..846d12543d 100644 --- a/src/conf/device_conf.h +++ b/src/conf/device_conf.h @@ -205,6 +205,9 @@ int virPCIDeviceAddressFormat(virBufferPtr buf, virPCIDeviceAddress addr, bool includeTypeInAddr); +char *virDomainPCIAddressAsString(virPCIDeviceAddressPtr addr) + ATTRIBUTE_NONNULL(1); + bool virPCIDeviceAddressEqual(virPCIDeviceAddress *addr1, virPCIDeviceAddress *addr2); diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c index b62fd53c66..d2e1142462 100644 --- a/src/conf/domain_addr.c +++ b/src/conf/domain_addr.c @@ -573,20 +573,6 @@ virDomainPCIAddressSetGrow(virDomainPCIAddressSetPtr addrs, } -char * -virDomainPCIAddressAsString(virPCIDeviceAddressPtr addr) -{ - char *str; - - ignore_value(virAsprintf(&str, "%.4x:%.2x:%.2x.%.1x", - addr->domain, - addr->bus, - addr->slot, - addr->function)); - return str; -} - - /* * Check if the PCI slot is used by another device. */ diff --git a/src/conf/domain_addr.h b/src/conf/domain_addr.h index 5ad9d8ef3d..2a9af9c00b 100644 --- a/src/conf/domain_addr.h +++ b/src/conf/domain_addr.h @@ -124,9 +124,6 @@ struct _virDomainPCIAddressSet { typedef struct _virDomainPCIAddressSet virDomainPCIAddressSet; typedef virDomainPCIAddressSet *virDomainPCIAddressSetPtr; -char *virDomainPCIAddressAsString(virPCIDeviceAddressPtr addr) - ATTRIBUTE_NONNULL(1); - virDomainPCIAddressSetPtr virDomainPCIAddressSetAlloc(unsigned int nbuses); void virDomainPCIAddressSetFree(virDomainPCIAddressSetPtr addrs); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 78307885dc..77f55b3c40 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -100,6 +100,7 @@ virDomainDeviceAddressTypeToString; virDomainDeviceCCWAddressIsValid; virDomainDeviceInfoAddressIsEqual; virDomainDeviceInfoCopy; +virDomainPCIAddressAsString; virInterfaceLinkFormat; virInterfaceLinkParseXML; virPCIDeviceAddressEqual; @@ -113,7 +114,6 @@ virPCIDeviceAddressParseXML; virDomainCCWAddressAssign; virDomainCCWAddressSetCreateFromDomain; virDomainCCWAddressSetFree; -virDomainPCIAddressAsString; virDomainPCIAddressBusIsFullyReserved; virDomainPCIAddressBusSetModel; virDomainPCIAddressEnsureAddr; -- 2.17.1

On Fri, Aug 31, 2018 at 04:00:45PM +0200, Andrea Bolognani wrote:
It's a better fit than domain_conf.
Unfortunately, even after this change functions handling virPCIDeviceAddress are split pretty much evenly between conf/device_conf and utils/virpci: ideally everything would be moved to the former, including the struct declaration itself, and all the names would be changed to be consistent with the rest of the virDomainDevice*Address, but that's a cleanup for another day.
Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- src/conf/device_conf.c | 13 +++++++++++++ src/conf/device_conf.h | 3 +++ src/conf/domain_addr.c | 14 -------------- src/conf/domain_addr.h | 3 --- src/libvirt_private.syms | 2 +- 5 files changed, 17 insertions(+), 18 deletions(-)
diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c index 1565d43fe6..afa06c3cda 100644 --- a/src/conf/device_conf.c +++ b/src/conf/device_conf.c @@ -309,6 +309,19 @@ virPCIDeviceAddressFormat(virBufferPtr buf, return 0; }
+char * +virDomainPCIAddressAsString(virPCIDeviceAddressPtr addr) +{ + char *str; + + ignore_value(virAsprintf(&str, "%.4x:%.2x:%.2x.%.1x", + addr->domain, + addr->bus, + addr->slot, + addr->function)); + return str; +}
This should really be in src/util/virpci.{c,h}, since that's where the virPCIDeviceAddressPtr struct is declared. There's nothing XML related about this string conversion, so doesn't belong in src/conf at all. Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

On Fri, 2018-08-31 at 15:05 +0100, Daniel P. Berrangé wrote:
On Fri, Aug 31, 2018 at 04:00:45PM +0200, Andrea Bolognani wrote:
Unfortunately, even after this change functions handling virPCIDeviceAddress are split pretty much evenly between conf/device_conf and utils/virpci: ideally everything would be moved to the former, including the struct declaration itself, and all the names would be changed to be consistent with the rest of the virDomainDevice*Address, but that's a cleanup for another day. [...] +char * +virDomainPCIAddressAsString(virPCIDeviceAddressPtr addr) +{ + char *str; + + ignore_value(virAsprintf(&str, "%.4x:%.2x:%.2x.%.1x", + addr->domain, + addr->bus, + addr->slot, + addr->function)); + return str; +}
This should really be in src/util/virpci.{c,h}, since that's where the virPCIDeviceAddressPtr struct is declared. There's nothing XML related about this string conversion, so doesn't belong in src/conf at all.
See the commit message :) I can move this to util/virpci instead of conf/device_conf for the time being if you prefer, but at some point we're going to have to pick a place for *all* functions related to PCI addresses and conf/device_conf is the most sensible option IMHO, seeing as all other address types and related functions are defined there. -- Andrea Bolognani / Red Hat / Virtualization

On Fri, Aug 31, 2018 at 04:25:25PM +0200, Andrea Bolognani wrote:
On Fri, 2018-08-31 at 15:05 +0100, Daniel P. Berrangé wrote:
On Fri, Aug 31, 2018 at 04:00:45PM +0200, Andrea Bolognani wrote:
Unfortunately, even after this change functions handling virPCIDeviceAddress are split pretty much evenly between conf/device_conf and utils/virpci: ideally everything would be moved to the former, including the struct declaration itself, and all the names would be changed to be consistent with the rest of the virDomainDevice*Address, but that's a cleanup for another day. [...] +char * +virDomainPCIAddressAsString(virPCIDeviceAddressPtr addr) +{ + char *str; + + ignore_value(virAsprintf(&str, "%.4x:%.2x:%.2x.%.1x", + addr->domain, + addr->bus, + addr->slot, + addr->function)); + return str; +}
This should really be in src/util/virpci.{c,h}, since that's where the virPCIDeviceAddressPtr struct is declared. There's nothing XML related about this string conversion, so doesn't belong in src/conf at all.
See the commit message :)
I can move this to util/virpci instead of conf/device_conf for the time being if you prefer, but at some point we're going to have to pick a place for *all* functions related to PCI addresses and conf/device_conf is the most sensible option IMHO, seeing as all other address types and related functions are defined there.
The device_conf file is dealing with domain device addresses. The virPCIDeviceAddressPtr struct is independant of domain device addresses. It is used across domain, node device, network and storage drivers. For that matter device_conf should probably be domain_device_conf as a name. Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

On Fri, 2018-08-31 at 15:29 +0100, Daniel P. Berrangé wrote:
On Fri, Aug 31, 2018 at 04:25:25PM +0200, Andrea Bolognani wrote:
On Fri, 2018-08-31 at 15:05 +0100, Daniel P. Berrangé wrote:
This should really be in src/util/virpci.{c,h}, since that's where the virPCIDeviceAddressPtr struct is declared. There's nothing XML related about this string conversion, so doesn't belong in src/conf at all.
See the commit message :)
I can move this to util/virpci instead of conf/device_conf for the time being if you prefer, but at some point we're going to have to pick a place for *all* functions related to PCI addresses and conf/device_conf is the most sensible option IMHO, seeing as all other address types and related functions are defined there.
The device_conf file is dealing with domain device addresses. The virPCIDeviceAddressPtr struct is independant of domain device addresses. It is used across domain, node device, network and storage drivers.
Yeah, it's a mess. I'll move it to util/virpci instead, but that won't make the mess go away :) -- Andrea Bolognani / Red Hat / Virtualization

The struct is called virPCIDeviceAddress and the functions operating on it should be named accordingly. Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- src/conf/device_conf.c | 2 +- src/conf/device_conf.h | 2 +- src/conf/domain_addr.c | 6 +++--- src/libvirt_private.syms | 2 +- src/qemu/qemu_command.c | 2 +- src/qemu/qemu_domain_address.c | 6 +++--- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c index afa06c3cda..48788540d3 100644 --- a/src/conf/device_conf.c +++ b/src/conf/device_conf.c @@ -310,7 +310,7 @@ virPCIDeviceAddressFormat(virBufferPtr buf, } char * -virDomainPCIAddressAsString(virPCIDeviceAddressPtr addr) +virPCIDeviceAddressAsString(virPCIDeviceAddressPtr addr) { char *str; diff --git a/src/conf/device_conf.h b/src/conf/device_conf.h index 846d12543d..c23a5918b3 100644 --- a/src/conf/device_conf.h +++ b/src/conf/device_conf.h @@ -205,7 +205,7 @@ int virPCIDeviceAddressFormat(virBufferPtr buf, virPCIDeviceAddress addr, bool includeTypeInAddr); -char *virDomainPCIAddressAsString(virPCIDeviceAddressPtr addr) +char *virPCIDeviceAddressAsString(virPCIDeviceAddressPtr addr) ATTRIBUTE_NONNULL(1); bool virPCIDeviceAddressEqual(virPCIDeviceAddress *addr1, diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c index d2e1142462..442e6aab94 100644 --- a/src/conf/domain_addr.c +++ b/src/conf/domain_addr.c @@ -604,7 +604,7 @@ virDomainPCIAddressReserveAddrInternal(virDomainPCIAddressSetPtr addrs, virErrorNumber errType = (fromConfig ? VIR_ERR_XML_ERROR : VIR_ERR_INTERNAL_ERROR); - if (!(addrStr = virDomainPCIAddressAsString(addr))) + if (!(addrStr = virPCIDeviceAddressAsString(addr))) goto cleanup; /* Add an extra bus if necessary */ @@ -689,7 +689,7 @@ virDomainPCIAddressEnsureAddr(virDomainPCIAddressSetPtr addrs, if (!flags) return 0; - if (!(addrStr = virDomainPCIAddressAsString(&dev->addr.pci))) + if (!(addrStr = virPCIDeviceAddressAsString(&dev->addr.pci))) goto cleanup; if (virDeviceInfoPCIAddressIsPresent(dev)) { @@ -770,7 +770,7 @@ virDomainPCIAddressFindUnusedFunctionOnBus(virDomainPCIAddressBusPtr bus, *found = false; - if (!(addrStr = virDomainPCIAddressAsString(searchAddr))) + if (!(addrStr = virPCIDeviceAddressAsString(searchAddr))) goto cleanup; if (!virDomainPCIAddressFlagsCompatible(searchAddr, addrStr, bus->flags, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 77f55b3c40..44bf54da81 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -100,9 +100,9 @@ virDomainDeviceAddressTypeToString; virDomainDeviceCCWAddressIsValid; virDomainDeviceInfoAddressIsEqual; virDomainDeviceInfoCopy; -virDomainPCIAddressAsString; virInterfaceLinkFormat; virInterfaceLinkParseXML; +virPCIDeviceAddressAsString; virPCIDeviceAddressEqual; virPCIDeviceAddressFormat; virPCIDeviceAddressIsEmpty; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 8aa20496bc..b72506f4e1 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -301,7 +301,7 @@ qemuBuildDeviceAddressStr(virBufferPtr buf, if (info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) { size_t i; - if (!(devStr = virDomainPCIAddressAsString(&info->addr.pci))) + if (!(devStr = virPCIDeviceAddressAsString(&info->addr.pci))) goto cleanup; for (i = 0; i < domainDef->ncontrollers; i++) { virDomainControllerDefPtr cont = domainDef->controllers[i]; diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index dda14adeb3..24fdf12128 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -1306,7 +1306,7 @@ qemuDomainCollectPCIAddress(virDomainDefPtr def ATTRIBUTE_UNUSED, * inappropriate address types. */ if (!info->pciConnectFlags) { - char *addrStr = virDomainPCIAddressAsString(&info->addr.pci); + char *addrStr = virPCIDeviceAddressAsString(&info->addr.pci); VIR_WARN("qemuDomainDeviceCalculatePCIConnectFlags() thinks that the " "device with PCI address %s should not have a PCI address", @@ -1554,7 +1554,7 @@ qemuDomainValidateDevicePCISlotsPIIX3(virDomainDefPtr def, memset(&tmp_addr, 0, sizeof(tmp_addr)); tmp_addr.slot = 2; - if (!(addrStr = virDomainPCIAddressAsString(&tmp_addr))) + if (!(addrStr = virPCIDeviceAddressAsString(&tmp_addr))) goto cleanup; if (!virDomainPCIAddressValidate(addrs, &tmp_addr, addrStr, flags, true)) @@ -1743,7 +1743,7 @@ qemuDomainValidateDevicePCISlotsQ35(virDomainDefPtr def, memset(&tmp_addr, 0, sizeof(tmp_addr)); tmp_addr.slot = 1; - if (!(addrStr = virDomainPCIAddressAsString(&tmp_addr))) + if (!(addrStr = virPCIDeviceAddressAsString(&tmp_addr))) goto cleanup; if (!virDomainPCIAddressValidate(addrs, &tmp_addr, addrStr, flags, true)) -- 2.17.1

The corresponding structs are declared there. Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- src/conf/device_conf.c | 267 ++++++++++++++++++++++++++++++++++++++ src/conf/device_conf.h | 17 +++ src/conf/domain_conf.c | 270 --------------------------------------- src/libvirt_private.syms | 6 + 4 files changed, 290 insertions(+), 270 deletions(-) diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c index 48788540d3..18592bbc1d 100644 --- a/src/conf/device_conf.c +++ b/src/conf/device_conf.c @@ -343,6 +343,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 <address> 'cssid' attribute")); + goto cleanup; + } + if (ssid && + virStrToLong_uip(ssid, NULL, 0, &addr->ssid) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot parse <address> 'ssid' attribute")); + goto cleanup; + } + if (devno && + virStrToLong_uip(devno, NULL, 0, &addr->devno) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot parse <address> '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 <address> 'controller' attribute")); + goto cleanup; + } + + if (bus && + virStrToLong_uip(bus, NULL, 10, &addr->bus) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot parse <address> 'bus' attribute")); + goto cleanup; + } + + if (target && + virStrToLong_uip(target, NULL, 10, &addr->target) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot parse <address> 'target' attribute")); + goto cleanup; + } + + if (unit && + virStrToLong_uip(unit, NULL, 10, &addr->unit) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot parse <address> '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 <address> 'controller' attribute")); + goto cleanup; + } + + if (bus && + virStrToLong_uip(bus, NULL, 10, &addr->bus) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot parse <address> 'bus' attribute")); + goto cleanup; + } + + if (port && + virStrToLong_uip(port, NULL, 10, &addr->port) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot parse <address> '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 <address> 'controller' attribute")); + goto cleanup; + } + + if (slot && + virStrToLong_uip(slot, NULL, 10, &addr->slot) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot parse <address> '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 <address> '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 <address> '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 <address> '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 c23a5918b3..33146f0caa 100644 --- a/src/conf/device_conf.h +++ b/src/conf/device_conf.h @@ -212,6 +212,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 3cae6b2aeb..7a52fc1e81 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 <address> 'controller' attribute")); - goto cleanup; - } - - if (bus && - virStrToLong_uip(bus, NULL, 10, &addr->bus) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot parse <address> 'bus' attribute")); - goto cleanup; - } - - if (target && - virStrToLong_uip(target, NULL, 10, &addr->target) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot parse <address> 'target' attribute")); - goto cleanup; - } - - if (unit && - virStrToLong_uip(unit, NULL, 10, &addr->unit) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot parse <address> '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 <address> 'controller' attribute")); - goto cleanup; - } - - if (bus && - virStrToLong_uip(bus, NULL, 10, &addr->bus) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot parse <address> 'bus' attribute")); - goto cleanup; - } - - if (port && - virStrToLong_uip(port, NULL, 10, &addr->port) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot parse <address> '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 <address> 'cssid' attribute")); - goto cleanup; - } - if (ssid && - virStrToLong_uip(ssid, NULL, 0, &addr->ssid) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot parse <address> 'ssid' attribute")); - goto cleanup; - } - if (devno && - virStrToLong_uip(devno, NULL, 0, &addr->devno) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot parse <address> '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 <address> 'controller' attribute")); - goto cleanup; - } - - if (slot && - virStrToLong_uip(slot, NULL, 10, &addr->slot) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot parse <address> '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 <address> '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 <address> '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 <address> '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 44bf54da81..6711cce02d 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; virPCIDeviceAddressAsString; -- 2.17.1

On Fri, Aug 31, 2018 at 04:00:47PM +0200, Andrea Bolognani wrote:
The corresponding structs are declared there.
Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- src/conf/device_conf.c | 267 ++++++++++++++++++++++++++++++++++++++ src/conf/device_conf.h | 17 +++ src/conf/domain_conf.c | 270 --------------------------------------- src/libvirt_private.syms | 6 + 4 files changed, 290 insertions(+), 270 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano
participants (3)
-
Andrea Bolognani
-
Daniel P. Berrangé
-
Ján Tomko