A new type to track USB addresses. The buses in virDomainUSBAddressSet correspond to USB controllers. They are represented by the virDomainUSBAddressHub type, having nports USB ports. These can contain nested hubs (nports != 0), or they can be occupied by other USB devices (with nports = 0). --- src/conf/domain_addr.c | 41 +++++++++++++++++++++++++++++++++++++++++ src/conf/domain_addr.h | 17 +++++++++++++++++ src/libvirt_private.syms | 2 ++ 3 files changed, 60 insertions(+) diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c index a5d142d..3962357 100644 --- a/src/conf/domain_addr.c +++ b/src/conf/domain_addr.c @@ -1198,3 +1198,44 @@ virDomainUSBAddressGetPortString(unsigned int *port) return NULL; return virBufferContentAndReset(&buf); } + + +virDomainUSBAddressSetPtr +virDomainUSBAddressSetCreate(void) +{ + virDomainUSBAddressSetPtr addrs; + + if (VIR_ALLOC(addrs) < 0) + return NULL; + + return addrs; +} + + +static void +virDomainUSBAddressHubFree(virDomainUSBAddressHubPtr hub) +{ + size_t i; + + for (i = 0; i < hub->nports; i++) { + if (hub->ports[i]) + virDomainUSBAddressHubFree(hub->ports[i]); + } + VIR_FREE(hub->ports); + VIR_FREE(hub); +} + +void virDomainUSBAddressSetFree(virDomainUSBAddressSetPtr addrs) +{ + size_t i; + + if (!addrs) + return; + + for (i = 0; i < addrs->nbuses; i++) { + if (addrs->buses[i]) + virDomainUSBAddressHubFree(addrs->buses[i]); + } + VIR_FREE(addrs->buses); + VIR_FREE(addrs); +} diff --git a/src/conf/domain_addr.h b/src/conf/domain_addr.h index c6d8da7..dcf86d4 100644 --- a/src/conf/domain_addr.h +++ b/src/conf/domain_addr.h @@ -248,4 +248,21 @@ char * virDomainUSBAddressGetPortString(unsigned int *port) ATTRIBUTE_NONNULL(1); +typedef struct _virDomainUSBAddressHub virDomainUSBAddressHub; +typedef virDomainUSBAddressHub *virDomainUSBAddressHubPtr; +struct _virDomainUSBAddressHub { + virDomainUSBAddressHubPtr *ports; + size_t nports; +}; + +struct _virDomainUSBAddressSet { + virDomainUSBAddressHubPtr *buses; + size_t nbuses; +}; +typedef struct _virDomainUSBAddressSet virDomainUSBAddressSet; +typedef virDomainUSBAddressSet *virDomainUSBAddressSetPtr; + +virDomainUSBAddressSetPtr virDomainUSBAddressSetCreate(void); +void virDomainUSBAddressSetFree(virDomainUSBAddressSetPtr addrs); + #endif /* __DOMAIN_ADDR_H__ */ diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 5168230..a628d00 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -108,6 +108,8 @@ virDomainPCIAddressSlotInUse; virDomainPCIAddressValidate; virDomainUSBAddressGetPortBuf; virDomainUSBAddressGetPortString; +virDomainUSBAddressSetCreate; +virDomainUSBAddressSetFree; virDomainVirtioSerialAddrAssign; virDomainVirtioSerialAddrAutoAssign; virDomainVirtioSerialAddrIsComplete; -- 2.4.6 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list