From da353cc1db4b13c50c3d79d5053d47a389a86148 Mon Sep 17 00:00:00 2001 Message-Id: From: =?UTF-8?q?J=C3=A1n=20Tomko?= Date: Thu, 21 Jul 2016 15:57:50 +0200 Subject: [PATCH] Introduce virDomainUSBAddressSet MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A new type to track USB addresses. Every is represented by an object of type virDomainUSBAddressHub located at buses[i]. Each of these hubs has up to 'nports' ports. If a port is occupied, it has the corresponding bit set in the 'ports' bitmap, e.g. port 1 would have the 0th bit set. If there is a hub on this port, then hubs[i] will point to this hub. (cherry picked from commit 82c142b321a10c62aa0a10e3ae9ba603b2d7d155) Signed-off-by: Ján Tomko https://bugzilla.redhat.com/show_bug.cgi?id=1215968 --- src/conf/domain_addr.c | 42 ++++++++++++++++++++++++++++++++++++++++++ src/conf/domain_addr.h | 22 ++++++++++++++++++++++ src/libvirt_private.syms | 2 ++ 3 files changed, 66 insertions(+) diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c index 741d045..658aad5 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 cfc74d5..168d3ed 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 44b78e0..49f8d6c 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -110,6 +110,8 @@ virDomainPCIControllerModelToConnectType; virDomainUSBAddressPortFormat; virDomainUSBAddressPortFormatBuf; virDomainUSBAddressPortIsValid; +virDomainUSBAddressSetCreate; +virDomainUSBAddressSetFree; virDomainVirtioSerialAddrAssign; virDomainVirtioSerialAddrAutoAssign; virDomainVirtioSerialAddrIsComplete; -- 2.9.2