diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c index 741d04552b6230a4814d5c77a2aae6291644ab4e..658aad5b216716834e453502013e77b833a638e4 100644 --- a/src/conf/domain_addr.c +++ b/src/conf/domain_addr.c @@ -1284,3 +1284,45 @@ virDomainUSBAddressPortFormat(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; + + if (!hub) + return; + + for (i = 0; i < hub->nports; i++) + virDomainUSBAddressHubFree(hub->ports[i]); + virBitmapFree(hub->portmap); + VIR_FREE(hub); +} + + +void +virDomainUSBAddressSetFree(virDomainUSBAddressSetPtr addrs) +{ + size_t i; + + if (!addrs) + return; + + for (i = 0; i < addrs->nbuses; 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 cfc74d5f65a7afb7576c53d81db0e0ecd260b6c1..168d3ed6f14196b42a8faf7605e174b518a952db 100644 --- a/src/conf/domain_addr.h +++ b/src/conf/domain_addr.h @@ -249,4 +249,26 @@ char * virDomainUSBAddressPortFormat(unsigned int *port) ATTRIBUTE_NONNULL(1); +typedef struct _virDomainUSBAddressHub virDomainUSBAddressHub; +typedef virDomainUSBAddressHub *virDomainUSBAddressHubPtr; +struct _virDomainUSBAddressHub { + /* indexes are shifted by one: + * ports[0] represents port 1, because ports are numbered from 1 */ + virBitmapPtr portmap; + size_t nports; + virDomainUSBAddressHubPtr *ports; +}; + +struct _virDomainUSBAddressSet { + /* every is represented + * as a hub at buses[i] */ + 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 cd3cc64e42270f56ade8ee6bdeeeb3acde00b228..c0bcff82436deb18bd7eca98758df4bf001bdadb 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -110,6 +110,8 @@ virDomainPCIControllerModelToConnectType; virDomainUSBAddressPortFormat; virDomainUSBAddressPortFormatBuf; virDomainUSBAddressPortIsValid; +virDomainUSBAddressSetCreate; +virDomainUSBAddressSetFree; virDomainVirtioSerialAddrAssign; virDomainVirtioSerialAddrAutoAssign; virDomainVirtioSerialAddrIsComplete;