Re: [libvirt] [PATCH v2 3/3] qemu: search usb device accurately to improve usb device hotplug

2012-05-03 Thread Guannan Ren

On 05/03/2012 02:06 AM, Osier Yang wrote:

On 2012年05月01日 16:16, Guannan Ren wrote:

One usb device could be allowed to hotplug in at a time. If user
give a xml as follows.


s/give/gives/

Probably there are two usb devices avaiable

s/avaiable/available/


but with different value of "bus, device"

we give a error to let user use  to specify the desired one.







---

-hostdev->source.subsys.u.usb.bus = usbDeviceGetBus(usb);
-hostdev->source.subsys.u.usb.device = usbDeviceGetDevno(usb);
+if (usbDeviceListAdd(list, usb)<  0) {
+usbFreeDevice(usb);
+goto cleanup;
+}

-usbFreeDevice(usb);
-}
+if (qemuPrepareHostdevUSBDevices(driver, vm->def->name, 
list)<  0)

+goto cleanup;


Do we really need a list here? there is only found usb device is , I 
guess

the only purpose is to take use of the new helper function
qemuPrepareHostdevUSBDevices, I.e. to use the new helper function,
it create a new list, and the only one usb device is inserted to
and removed from the list. IMO it's a waste.



  qemuPrepareHostUSBDevices probably have multiple devices to add 
to qemu driver

  Usb hotplug shares the function for the job, that's it.

  Guannan Ren


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

Re: [libvirt] [PATCH v2 3/3] qemu: search usb device accurately to improve usb device hotplug

2012-05-03 Thread Guannan Ren

On 05/03/2012 01:31 AM, Eric Blake wrote:

On 05/01/2012 02:16 AM, Guannan Ren wrote:

One usb device could be allowed to hotplug in at a time. If user
give a xml as follows. Probably there are two usb devices avaiable

s/avaiable/available/


but with different value of "bus, device"

we give a error to let user use  to specify the desired one.


   
 
 
   

---
  src/qemu/qemu_hotplug.c |   68 +-
  1 files changed, 54 insertions(+), 14 deletions(-)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 7cf7b90..15693a0 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1121,6 +1121,9 @@ int qemuDomainAttachHostDevice(struct qemud_driver 
*driver,
 virDomainObjPtr vm,
 virDomainHostdevDefPtr hostdev)
  {
+usbDeviceList *list;
+usbDevice * usb = NULL;

Style: no space after *.


+if (!(list = usbDeviceListNew()))
+goto cleanup;

virReportOOMError()


OOM error will be raised in usbDeviceListNew()
we get 'NULL' value in that case.



+
+if (hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB) {
+unsigned vendor = hostdev->source.subsys.u.usb.vendor;
+unsigned product = hostdev->source.subsys.u.usb.product;
+unsigned bus = hostdev->source.subsys.u.usb.bus;
+unsigned device = hostdev->source.subsys.u.usb.device;
+
+if (vendor&&  bus) {

Same question as in 2/3 about valid values for bus.



+if (usbDeviceListCount(devs)>  1) {
+qemuReportError(VIR_ERR_XML_ERROR,
+_("multiple USB deivces %x:%x, "

s/deivces/devices/



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


Re: [libvirt] [PATCH v2 3/3] qemu: search usb device accurately to improve usb device hotplug

2012-05-02 Thread Osier Yang

On 2012年05月01日 16:16, Guannan Ren wrote:

One usb device could be allowed to hotplug in at a time. If user
give a xml as follows.


s/give/gives/

Probably there are two usb devices avaiable

s/avaiable/available/


but with different value of "bus, device"

we give a error to let user use  to specify the desired one.


   
 
 
   

---
  src/qemu/qemu_hotplug.c |   68 +-
  1 files changed, 54 insertions(+), 14 deletions(-)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 7cf7b90..15693a0 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1121,6 +1121,9 @@ int qemuDomainAttachHostDevice(struct qemud_driver 
*driver,
 virDomainObjPtr vm,
 virDomainHostdevDefPtr hostdev)
  {
+usbDeviceList *list;
+usbDevice * usb = NULL;


s/usbDevice * usb/usbDevice *usb/


+
  if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) {
  qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED,
  _("hostdev mode '%s' not supported"),
@@ -1128,29 +1131,62 @@ int qemuDomainAttachHostDevice(struct qemud_driver 
*driver,
  return -1;
  }

-/* Resolve USB product/vendor to bus/device */
-if (hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB&&
-hostdev->source.subsys.u.usb.vendor) {
-if (qemuPrepareHostdevUSBDevices(driver, vm->def->name,&hostdev, 1)<  
0)
-goto error;
+if (!(list = usbDeviceListNew()))


virReportOOMError()


+goto cleanup;
+
+if (hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB) {
+unsigned vendor = hostdev->source.subsys.u.usb.vendor;
+unsigned product = hostdev->source.subsys.u.usb.product;
+unsigned bus = hostdev->source.subsys.u.usb.bus;
+unsigned device = hostdev->source.subsys.u.usb.device;
+
+if (vendor&&  bus) {
+usb = usbFindDevice(vendor, product, bus, device);
+if (!usb)
+goto cleanup;


Should be removed. See [1]


+
+} else if (vendor&&  !bus) {
+usbDeviceList *devs = usbFindDevByVendor(vendor, product);
+if (!devs)
+goto cleanup;
+
+if (usbDeviceListCount(devs)>  1) {
+qemuReportError(VIR_ERR_XML_ERROR,
+_("multiple USB deivces %x:%x, "
+  "use  to specify one"), vendor, 
product);
+usbDeviceListFree(devs);
+goto cleanup;
+}
+usb = usbDeviceListGet(devs, 0);
+usbDeviceListSteal(devs, usb);
+usbDeviceListFree(devs);

-usbDevice *usb
-= usbFindDevice(hostdev->source.subsys.u.usb.vendor,
-hostdev->source.subsys.u.usb.product);
+hostdev->source.subsys.u.usb.bus = usbDeviceGetBus(usb);
+hostdev->source.subsys.u.usb.device = usbDeviceGetDevno(usb);
+
+} else if (!vendor&&  bus) {
+usb = usbFindDevByBus(bus, device);
+if (!usb)
+goto cleanup;


Should be removed. see [1]


+}

  if (!usb)
-return -1;
+goto cleanup;


[1] There is a duplicate check here.



-hostdev->source.subsys.u.usb.bus = usbDeviceGetBus(usb);
-hostdev->source.subsys.u.usb.device = usbDeviceGetDevno(usb);
+if (usbDeviceListAdd(list, usb)<  0) {
+usbFreeDevice(usb);
+goto cleanup;
+}

-usbFreeDevice(usb);
-}
+if (qemuPrepareHostdevUSBDevices(driver, vm->def->name, list)<  0)
+goto cleanup;


Do we really need a list here? there is only found usb device is , I guess
the only purpose is to take use of the new helper function
qemuPrepareHostdevUSBDevices, I.e. to use the new helper function,
it create a new list, and the only one usb device is inserted to
and removed from the list. IMO it's a waste.



+usbDeviceListSteal(list, usb);
+}

  if (virSecurityManagerSetHostdevLabel(driver->securityManager,
vm->def, hostdev)<  0)
-return -1;
+goto cleanup;

  switch (hostdev->source.subsys.type) {
  case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
@@ -1172,6 +1208,7 @@ int qemuDomainAttachHostDevice(struct qemud_driver 
*driver,
  goto error;
  }

+usbDeviceListFree(list);
  return 0;

  error:
@@ -1179,6 +1216,9 @@ error:
vm->def, hostdev)<  0)
  VIR_WARN("Unable to restore host device labelling on hotplug fail");

+cleanup:
+usbDeviceListFree(list);
+usbDeviceListSteal(driver->activeUsbHostdevs, usb);
  return -1;
  }



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

Re: [libvirt] [PATCH v2 3/3] qemu: search usb device accurately to improve usb device hotplug

2012-05-02 Thread Osier Yang

On 2012年05月03日 02:06, Osier Yang wrote:

On 2012年05月01日 16:16, Guannan Ren wrote:

One usb device could be allowed to hotplug in at a time. If user
give a xml as follows.


s/give/gives/

Probably there are two usb devices avaiable

s/avaiable/available/


but with different value of "bus, device"

we give a error to let user use to specify the desired one.







---
src/qemu/qemu_hotplug.c | 68
+-
1 files changed, 54 insertions(+), 14 deletions(-)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 7cf7b90..15693a0 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1121,6 +1121,9 @@ int qemuDomainAttachHostDevice(struct
qemud_driver *driver,
virDomainObjPtr vm,
virDomainHostdevDefPtr hostdev)
{
+ usbDeviceList *list;
+ usbDevice * usb = NULL;


s/usbDevice * usb/usbDevice *usb/


+
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) {
qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("hostdev mode '%s' not supported"),
@@ -1128,29 +1131,62 @@ int qemuDomainAttachHostDevice(struct
qemud_driver *driver,
return -1;
}

- /* Resolve USB product/vendor to bus/device */
- if (hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB&&
- hostdev->source.subsys.u.usb.vendor) {
- if (qemuPrepareHostdevUSBDevices(driver, vm->def->name,&hostdev, 1)< 0)
- goto error;
+ if (!(list = usbDeviceListNew()))


virReportOOMError()


+ goto cleanup;
+
+ if (hostdev->source.subsys.type ==
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB) {
+ unsigned vendor = hostdev->source.subsys.u.usb.vendor;
+ unsigned product = hostdev->source.subsys.u.usb.product;
+ unsigned bus = hostdev->source.subsys.u.usb.bus;
+ unsigned device = hostdev->source.subsys.u.usb.device;
+
+ if (vendor&& bus) {
+ usb = usbFindDevice(vendor, product, bus, device);
+ if (!usb)
+ goto cleanup;


Should be removed. See [1]


+
+ } else if (vendor&& !bus) {
+ usbDeviceList *devs = usbFindDevByVendor(vendor, product);
+ if (!devs)
+ goto cleanup;
+
+ if (usbDeviceListCount(devs)> 1) {
+ qemuReportError(VIR_ERR_XML_ERROR,
+ _("multiple USB deivces %x:%x, "
+ "use to specify one"), vendor, product);
+ usbDeviceListFree(devs);
+ goto cleanup;
+ }
+ usb = usbDeviceListGet(devs, 0);
+ usbDeviceListSteal(devs, usb);
+ usbDeviceListFree(devs);

- usbDevice *usb
- = usbFindDevice(hostdev->source.subsys.u.usb.vendor,
- hostdev->source.subsys.u.usb.product);
+ hostdev->source.subsys.u.usb.bus = usbDeviceGetBus(usb);
+ hostdev->source.subsys.u.usb.device = usbDeviceGetDevno(usb);
+
+ } else if (!vendor&& bus) {
+ usb = usbFindDevByBus(bus, device);
+ if (!usb)
+ goto cleanup;


Should be removed. see [1]


+ }

if (!usb)
- return -1;
+ goto cleanup;


[1] There is a duplicate check here.



- hostdev->source.subsys.u.usb.bus = usbDeviceGetBus(usb);
- hostdev->source.subsys.u.usb.device = usbDeviceGetDevno(usb);
+ if (usbDeviceListAdd(list, usb)< 0) {
+ usbFreeDevice(usb);
+ goto cleanup;
+ }

- usbFreeDevice(usb);
- }
+ if (qemuPrepareHostdevUSBDevices(driver, vm->def->name, list)< 0)
+ goto cleanup;


Do we really need a list here? there is only found usb device is , I guess
the only purpose is to take use of the new helper function
qemuPrepareHostdevUSBDevices, I.e. to use the new helper function,
it create a new list, and the only one usb device is inserted to
and removed from the list. IMO it's a waste.


I.e. Given the name of the new helper function is confused with
"qemuPrepareHostUSBDevices", and it's actually no need to use it
here, IMO the new helper function is no need.





+ usbDeviceListSteal(list, usb);
+ }

if (virSecurityManagerSetHostdevLabel(driver->securityManager,
vm->def, hostdev)< 0)
- return -1;
+ goto cleanup;

switch (hostdev->source.subsys.type) {
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
@@ -1172,6 +1208,7 @@ int qemuDomainAttachHostDevice(struct
qemud_driver *driver,
goto error;
}

+ usbDeviceListFree(list);
return 0;

error:
@@ -1179,6 +1216,9 @@ error:
vm->def, hostdev)< 0)
VIR_WARN("Unable to restore host device labelling on hotplug fail");

+cleanup:
+ usbDeviceListFree(list);
+ usbDeviceListSteal(driver->activeUsbHostdevs, usb);
return -1;
}



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


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

Re: [libvirt] [PATCH v2 3/3] qemu: search usb device accurately to improve usb device hotplug

2012-05-02 Thread Eric Blake
On 05/01/2012 02:16 AM, Guannan Ren wrote:
> One usb device could be allowed to hotplug in at a time. If user
> give a xml as follows. Probably there are two usb devices avaiable

s/avaiable/available/

> but with different value of "bus, device"
> 
> we give a error to let user use  to specify the desired one.
> 
> 
>   
> 
> 
>   
> 
> ---
>  src/qemu/qemu_hotplug.c |   68 +-
>  1 files changed, 54 insertions(+), 14 deletions(-)
> 
> diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
> index 7cf7b90..15693a0 100644
> --- a/src/qemu/qemu_hotplug.c
> +++ b/src/qemu/qemu_hotplug.c
> @@ -1121,6 +1121,9 @@ int qemuDomainAttachHostDevice(struct qemud_driver 
> *driver,
> virDomainObjPtr vm,
> virDomainHostdevDefPtr hostdev)
>  {
> +usbDeviceList *list;
> +usbDevice * usb = NULL;

Style: no space after *.

> +if (!(list = usbDeviceListNew()))
> +goto cleanup;

virReportOOMError()

> +
> +if (hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB) {
> +unsigned vendor = hostdev->source.subsys.u.usb.vendor;
> +unsigned product = hostdev->source.subsys.u.usb.product;
> +unsigned bus = hostdev->source.subsys.u.usb.bus;
> +unsigned device = hostdev->source.subsys.u.usb.device;
> +
> +if (vendor && bus) {

Same question as in 2/3 about valid values for bus.


> +if (usbDeviceListCount(devs) > 1) {
> +qemuReportError(VIR_ERR_XML_ERROR,
> +_("multiple USB deivces %x:%x, "

s/deivces/devices/

-- 
Eric Blake   ebl...@redhat.com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH v2 3/3] qemu: search usb device accurately to improve usb device hotplug

2012-05-02 Thread Martin Kletzander
On 05/01/2012 10:16 AM, Guannan Ren wrote:
> One usb device could be allowed to hotplug in at a time. If user
> give a xml as follows. Probably there are two usb devices avaiable
> but with different value of "bus, device"
> 
> we give a error to let user use  to specify the desired one.
> 
> 
>   
> 
> 
>   
> 
> ---
>  src/qemu/qemu_hotplug.c |   68 +-
>  1 files changed, 54 insertions(+), 14 deletions(-)
> 
> diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
> index 7cf7b90..15693a0 100644
> --- a/src/qemu/qemu_hotplug.c
> +++ b/src/qemu/qemu_hotplug.c
> @@ -1121,6 +1121,9 @@ int qemuDomainAttachHostDevice(struct qemud_driver 
> *driver,
> virDomainObjPtr vm,
> virDomainHostdevDefPtr hostdev)
>  {
> +usbDeviceList *list;
> +usbDevice * usb = NULL;
> +
>  if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) {
>  qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED,
>  _("hostdev mode '%s' not supported"),
> @@ -1128,29 +1131,62 @@ int qemuDomainAttachHostDevice(struct qemud_driver 
> *driver,
>  return -1;
>  }
>  
> -/* Resolve USB product/vendor to bus/device */
> -if (hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB &&
> -hostdev->source.subsys.u.usb.vendor) {
> -if (qemuPrepareHostdevUSBDevices(driver, vm->def->name, &hostdev, 1) 
> < 0)
> -goto error;
> +if (!(list = usbDeviceListNew()))
> +goto cleanup;
> +
> +if (hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB) {
> +unsigned vendor = hostdev->source.subsys.u.usb.vendor;
> +unsigned product = hostdev->source.subsys.u.usb.product;
> +unsigned bus = hostdev->source.subsys.u.usb.bus;
> +unsigned device = hostdev->source.subsys.u.usb.device;
> +
> +if (vendor && bus) {
> +usb = usbFindDevice(vendor, product, bus, device);
> +if (!usb)
> +goto cleanup;
> +
> +} else if (vendor && !bus) {
> +usbDeviceList *devs = usbFindDevByVendor(vendor, product);
> +if (!devs)
> +goto cleanup;
> +
> +if (usbDeviceListCount(devs) > 1) {
> +qemuReportError(VIR_ERR_XML_ERROR,
> +_("multiple USB deivces %x:%x, "
> +  "use  to specify one"), vendor, 
> product);
> +usbDeviceListFree(devs);
> +goto cleanup;
> +}
> +usb = usbDeviceListGet(devs, 0);
> +usbDeviceListSteal(devs, usb);
> +usbDeviceListFree(devs);
>  
> -usbDevice *usb
> -= usbFindDevice(hostdev->source.subsys.u.usb.vendor,
> -hostdev->source.subsys.u.usb.product);
> +hostdev->source.subsys.u.usb.bus = usbDeviceGetBus(usb);
> +hostdev->source.subsys.u.usb.device = usbDeviceGetDevno(usb);
> +
> +} else if (!vendor && bus) {
> +usb = usbFindDevByBus(bus, device);
> +if (!usb)
> +goto cleanup;
> +}
>  
>  if (!usb)
> -return -1;
> +goto cleanup;
>  
> -hostdev->source.subsys.u.usb.bus = usbDeviceGetBus(usb);
> -hostdev->source.subsys.u.usb.device = usbDeviceGetDevno(usb);
> +if (usbDeviceListAdd(list, usb) < 0) {
> +usbFreeDevice(usb);
> +goto cleanup;
> +}
>  
> -usbFreeDevice(usb);
> -}
> +if (qemuPrepareHostdevUSBDevices(driver, vm->def->name, list) < 0)
> +goto cleanup;
>  
> +usbDeviceListSteal(list, usb);
> +}
>  
>  if (virSecurityManagerSetHostdevLabel(driver->securityManager,
>vm->def, hostdev) < 0)
> -return -1;
> +goto cleanup;
>  
>  switch (hostdev->source.subsys.type) {
>  case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
> @@ -1172,6 +1208,7 @@ int qemuDomainAttachHostDevice(struct qemud_driver 
> *driver,
>  goto error;
>  }
>  
> +usbDeviceListFree(list);
>  return 0;
>  
>  error:
> @@ -1179,6 +1216,9 @@ error:
>vm->def, hostdev) < 0)
>  VIR_WARN("Unable to restore host device labelling on hotplug fail");
>  
> +cleanup:
> +usbDeviceListFree(list);
> +usbDeviceListSteal(driver->activeUsbHostdevs, usb);
>  return -1;
>  }
>  

Seems all is well for me, ACK.

Martin

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


[libvirt] [PATCH v2 3/3] qemu: search usb device accurately to improve usb device hotplug

2012-05-01 Thread Guannan Ren
One usb device could be allowed to hotplug in at a time. If user
give a xml as follows. Probably there are two usb devices avaiable
but with different value of "bus, device"

we give a error to let user use  to specify the desired one.


  


  

---
 src/qemu/qemu_hotplug.c |   68 +-
 1 files changed, 54 insertions(+), 14 deletions(-)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 7cf7b90..15693a0 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1121,6 +1121,9 @@ int qemuDomainAttachHostDevice(struct qemud_driver 
*driver,
virDomainObjPtr vm,
virDomainHostdevDefPtr hostdev)
 {
+usbDeviceList *list;
+usbDevice * usb = NULL;
+
 if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) {
 qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED,
 _("hostdev mode '%s' not supported"),
@@ -1128,29 +1131,62 @@ int qemuDomainAttachHostDevice(struct qemud_driver 
*driver,
 return -1;
 }
 
-/* Resolve USB product/vendor to bus/device */
-if (hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB &&
-hostdev->source.subsys.u.usb.vendor) {
-if (qemuPrepareHostdevUSBDevices(driver, vm->def->name, &hostdev, 1) < 
0)
-goto error;
+if (!(list = usbDeviceListNew()))
+goto cleanup;
+
+if (hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB) {
+unsigned vendor = hostdev->source.subsys.u.usb.vendor;
+unsigned product = hostdev->source.subsys.u.usb.product;
+unsigned bus = hostdev->source.subsys.u.usb.bus;
+unsigned device = hostdev->source.subsys.u.usb.device;
+
+if (vendor && bus) {
+usb = usbFindDevice(vendor, product, bus, device);
+if (!usb)
+goto cleanup;
+
+} else if (vendor && !bus) {
+usbDeviceList *devs = usbFindDevByVendor(vendor, product);
+if (!devs)
+goto cleanup;
+
+if (usbDeviceListCount(devs) > 1) {
+qemuReportError(VIR_ERR_XML_ERROR,
+_("multiple USB deivces %x:%x, "
+  "use  to specify one"), vendor, 
product);
+usbDeviceListFree(devs);
+goto cleanup;
+}
+usb = usbDeviceListGet(devs, 0);
+usbDeviceListSteal(devs, usb);
+usbDeviceListFree(devs);
 
-usbDevice *usb
-= usbFindDevice(hostdev->source.subsys.u.usb.vendor,
-hostdev->source.subsys.u.usb.product);
+hostdev->source.subsys.u.usb.bus = usbDeviceGetBus(usb);
+hostdev->source.subsys.u.usb.device = usbDeviceGetDevno(usb);
+
+} else if (!vendor && bus) {
+usb = usbFindDevByBus(bus, device);
+if (!usb)
+goto cleanup;
+}
 
 if (!usb)
-return -1;
+goto cleanup;
 
-hostdev->source.subsys.u.usb.bus = usbDeviceGetBus(usb);
-hostdev->source.subsys.u.usb.device = usbDeviceGetDevno(usb);
+if (usbDeviceListAdd(list, usb) < 0) {
+usbFreeDevice(usb);
+goto cleanup;
+}
 
-usbFreeDevice(usb);
-}
+if (qemuPrepareHostdevUSBDevices(driver, vm->def->name, list) < 0)
+goto cleanup;
 
+usbDeviceListSteal(list, usb);
+}
 
 if (virSecurityManagerSetHostdevLabel(driver->securityManager,
   vm->def, hostdev) < 0)
-return -1;
+goto cleanup;
 
 switch (hostdev->source.subsys.type) {
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
@@ -1172,6 +1208,7 @@ int qemuDomainAttachHostDevice(struct qemud_driver 
*driver,
 goto error;
 }
 
+usbDeviceListFree(list);
 return 0;
 
 error:
@@ -1179,6 +1216,9 @@ error:
   vm->def, hostdev) < 0)
 VIR_WARN("Unable to restore host device labelling on hotplug fail");
 
+cleanup:
+usbDeviceListFree(list);
+usbDeviceListSteal(driver->activeUsbHostdevs, usb);
 return -1;
 }
 
-- 
1.7.7.5

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