[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v2] Release usb devices on shutdown and usb_del
From: |
Markus Armbruster |
Subject: |
Re: [Qemu-devel] [PATCH v2] Release usb devices on shutdown and usb_del command |
Date: |
Fri, 21 May 2010 08:33:46 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) |
"David S. Ahern" <address@hidden> writes:
> On 05/19/2010 12:10 PM, Shahar Havivi wrote:
>> When closig Vm or removing usb on guest via usb_del monitor command,
>> qemu does not return the control to the host, the user have to
>> unplug and plug the device in order to use it on the host.
>>
>> v2:
>> added empty methods to usb-bsd and usb-stub.
>> release usb devices when main is out.
>>
>> Signed-off-by: Shahar Havivi <address@hidden>
>> ---
>> hw/usb-bus.c | 4 ++++
>> hw/usb.h | 2 ++
>> usb-bsd.c | 10 ++++++++++
>> usb-linux.c | 21 +++++++++++++++++++++
>> usb-stub.c | 10 ++++++++++
>> vl.c | 1 +
>> 6 files changed, 48 insertions(+), 0 deletions(-)
>>
>> diff --git a/hw/usb-bus.c b/hw/usb-bus.c
>> index b692503..75dc819 100644
>> --- a/hw/usb-bus.c
>> +++ b/hw/usb-bus.c
>> @@ -207,6 +207,10 @@ int usb_device_delete_addr(int busnr, int addr)
>> return -1;
>> dev = port->dev;
>>
>> + if (!strcmp(dev->info->usbdevice_name, "host")) {
>> + usb_host_device_release(dev);
>> + }
>> +
>
> Shouldn't this be done through a callback -- say usbdevice_release
> similar to usbdevice_init -- instead of embedding host specifics here?
> You wouldn't need the bsd and stub stubs then.
>
> David
What about the existing callbacks? Could handle_destroy do?
Note: usbdevice_init() is not for general initialization, just for
dealing with the legacy -usbdevice command line.
>> qdev_free(&dev->qdev);
>> return 0;
>> }
[...]
>> diff --git a/usb-linux.c b/usb-linux.c
>> index 88273ff..cea5b84 100644
>> --- a/usb-linux.c
>> +++ b/usb-linux.c
>> @@ -286,6 +286,27 @@ static void async_cancel(USBPacket *unused, void
>> *opaque)
>> }
>> }
>>
>> +void usb_cleanup(void)
>> +{
>> + struct USBHostDevice *s;
>> +
>> + QTAILQ_FOREACH(s, &hostdevs, next) {
>> + if (s->fd != -1) {
>> + usb_host_device_release((USBDevice*)s);
>> + }
>> + }
>> +}
>> +
>> +int usb_host_device_release(USBDevice *dev)
>> +{
>> + int ret;
>> +
>> + USBHostDevice *s = DO_UPCAST(USBHostDevice, dev, dev);
>> + ret = ioctl(s->fd, USBDEVFS_RESET);
>> +
>> + return ret;
>> +}
>> +
>> static int usb_host_claim_interfaces(USBHostDevice *dev, int configuration)
>> {
>> int dev_descr_len, config_descr_len;
[...]
>> diff --git a/vl.c b/vl.c
>> index d77b47c..e3f4dc9 100644
>> --- a/vl.c
>> +++ b/vl.c
>> @@ -3914,6 +3914,7 @@ int main(int argc, char **argv, char **envp)
>> main_loop();
>> quit_timers();
>> net_cleanup();
>> + usb_cleanup();
>>
>> return 0;
>> }
Figure we'd have to clean up the qdev tree on exit. Gerd?