[virt-tools-list] [PATCH 1/2] details: the bus, device values of USB device is decimal rather than hex

Guannan Ren gren at redhat.com
Fri Apr 26 06:27:19 UTC 2013


On 04/23/2013 09:30 PM, Guannan Ren wrote:
> Although the code in lookup_nodedev() is general to deal with
> hostdev, it has to seperate USB device from PCI device there.
> For PCI device, the domain/bus/slot/function is hex.
> For USB device, the bus/device is decimal.
>
> This fix makes the label use hostdev pretty_name:
>
>   +------------------------------------------------------+
>   | Physical USB Device                                  |
>   |   Device: 006:032 RSA RSA SecureID (R) Authenticator |
> ---
>   virtManager/details.py | 24 +++++++++++++++---------
>   1 file changed, 15 insertions(+), 9 deletions(-)
>
> diff --git a/virtManager/details.py b/virtManager/details.py
> index cd18aa8..f43fefe 100644
> --- a/virtManager/details.py
> +++ b/virtManager/details.py
> @@ -270,19 +270,25 @@ def lookup_nodedev(vmmconn, hostdev):
>               return None
>           return getattr(node, attr)
>   
> -    devtype     = hostdev.type
> -    vendor_id   = hostdev.vendor or -1
> -    product_id  = hostdev.product or -1
> -    device      = intify(hostdev.device, True)
> -    bus         = intify(hostdev.bus, True)
> -    domain      = intify(hostdev.domain, True)
> -    func        = intify(hostdev.function, True)
> -    slot        = intify(hostdev.slot, True)
> +    devtype = hostdev.type
>       found_dev = None
>   
> +    vendor_id = product_id = bus = device = \
> +        domain = slot = function = None
> +
>       # For USB we want a device, not a bus
>       if devtype == 'usb':
> -        devtype = 'usb_device'
> +        devtype    = 'usb_device'
> +        vendor_id  = hostdev.vendor or -1
> +        product_id = hostdev.product or -1
> +        bus        = intify(hostdev.bus)
> +        device     = intify(hostdev.device)
> +
> +    elif devtype == 'pci':
> +        domain     = intify(hostdev.domain, True)
> +        bus        = intify(hostdev.bus, True)
> +        slot       = intify(hostdev.slot, True)
> +        func       = intify(hostdev.function, True)
>   
>       devs = vmmconn.get_nodedevs(devtype, None)
>       for dev in devs:

      About this patch, I think I need to add more informations here.
      For the node device of 'pci' type, for example NIC on my machine:
      virt-manager gets its domain/bus/slot/function via libvirt API:
          nodedev = nodeDeviceLookupByName("pci_0000_00_19_0")
          nodedev.XMLDesc(0)
      In the output of above, the values of DBSF is decimal.
         <device>
           ...
           <domain>0</domain>
           <bus>0</bus>
           <slot>25</slot>
           <function>0</function>
           ...
         </device>
      After the new domain XML is defined, the tick() get the new XML 
definition of the domain.
      The DBSF of the above NIC device in new domain XML is hex.
         <address domain='0x0000' bus='0x00' slot='0x19' function='0x0'/>

      But for host USB device,  the bus/device values is always decimal, 
like:
         <address bus="2" device="19"/>

      So, the issue fixed here is when the value of device attribute in 
<address> element of
      host USB device is greater than 10, it failed to find a node 
device, because it treats it as
      a hex. the no pretty_name is labelled in UI.

      Hope these info can help clarify a little more. :)

      Guannan




More information about the virt-tools-list mailing list