Re: [PATCHv3 04/10] Introduce virDomainUSBAddressSet

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 23/06/16 09:45, Ján Tomko wrote:
> A new type to track USB addresses.
> 
> Every <controller type='usb' index='i'/> is represented by
> as a virDomainUSBAddressHub at buses[i].
> 

"represented by as..", I'd say something like "is represented by an
object of type virDomainUSBAddressHub where each of such objects can be
located at buses[i]" or something similar...

> 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.
> ---
>  src/conf/domain_addr.c   | 46 ++++++++++++++++++++++++++++++++++++++++++++++
>  src/conf/domain_addr.h   | 22 ++++++++++++++++++++++
>  src/libvirt_private.syms |  2 ++
>  3 files changed, 70 insertions(+)
> 
> diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c
> index 1f5193c..a43657b 100644
> --- a/src/conf/domain_addr.c
> +++ b/src/conf/domain_addr.c
> @@ -1277,3 +1277,49 @@ 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++) {
> +        if (hub->hubs[i])
> +            virDomainUSBAddressHubFree(hub->hubs[i]);
> +    }
> +    virBitmapFree(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 8efd512..51bbb61 100644
> --- a/src/conf/domain_addr.h
> +++ b/src/conf/domain_addr.h
> @@ -245,4 +245,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 ports;
> +    size_t nports;
> +    virDomainUSBAddressHubPtr *hubs;
> +};
> +
> +struct _virDomainUSBAddressSet {
> +    /* every <controller type='usb' index='i'> is represented
> +     * as a hub at buses[i] */
> +    virDomainUSBAddressHubPtr *buses;
> +    size_t nbuses;
> +};

At first, I wasn't really convinced by the data type name
"virDomainUSBAddressSet", but unfortunately I couldn't come up with
anything more descriptive, so I guess I'm okay with it.

> +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 414d990..9e1bad7 100644
> --- a/src/libvirt_private.syms
> +++ b/src/libvirt_private.syms
> @@ -111,6 +111,8 @@ virDomainPCIAddressValidate;
>  virDomainPCIControllerModelToConnectType;
>  virDomainUSBAddressPortFormat;
>  virDomainUSBAddressPortFormatBuf;
> +virDomainUSBAddressSetCreate;
> +virDomainUSBAddressSetFree;
>  virDomainVirtioSerialAddrAssign;
>  virDomainVirtioSerialAddrAutoAssign;
>  virDomainVirtioSerialAddrIsComplete;
> 

ACK

Erik

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]