qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "David S. Ahern" <daahern@cisco.com>
To: Shahar Havivi <shaharh@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v2] Release usb devices on shutdown and usb_del command
Date: Wed, 19 May 2010 12:43:27 -0600	[thread overview]
Message-ID: <4BF4314F.6000904@cisco.com> (raw)
In-Reply-To: <20100519181031.GA19410@redhat.com>



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 <shaharh@redhat.com>
> ---
>  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


>      qdev_free(&dev->qdev);
>      return 0;
>  }
> diff --git a/hw/usb.h b/hw/usb.h
> index 00d2802..08c48d2 100644
> --- a/hw/usb.h
> +++ b/hw/usb.h
> @@ -258,6 +258,8 @@ void usb_send_msg(USBDevice *dev, int msg);
>  USBDevice *usb_host_device_open(const char *devname);
>  int usb_host_device_close(const char *devname);
>  void usb_host_info(Monitor *mon);
> +int usb_host_device_release(USBDevice *dev);
> +void usb_cleanup(void);
>  
>  /* usb-hid.c */
>  void usb_hid_datain_cb(USBDevice *dev, void *opaque, void (*datain)(void *));
> diff --git a/usb-bsd.c b/usb-bsd.c
> index 48567a3..fc9ea80 100644
> --- a/usb-bsd.c
> +++ b/usb-bsd.c
> @@ -634,3 +634,13 @@ int usb_host_device_close(const char *devname)
>  {
>      return 0;
>  }
> +
> +int usb_host_device_release(USBDevice *dev)
> +{
> +    return 0;
> +}
> +
> +void usb_cleanup(void)
> +{
> +    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/usb-stub.c b/usb-stub.c
> index 9c3fcea..4432c2e 100644
> --- a/usb-stub.c
> +++ b/usb-stub.c
> @@ -50,3 +50,13 @@ int usb_host_device_close(const char *devname)
>  {
>      return 0;
>  }
> +
> +int usb_host_device_release(USBDevice *dev)
> +{
> +    return 0;
> +}
> +
> +void usb_cleanup(void)
> +{
> +    return 0;
> +}
> 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;
>  }

  reply	other threads:[~2010-05-19 18:44 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-19 18:10 [Qemu-devel] [PATCH v2] Release usb devices on shutdown and usb_del command Shahar Havivi
2010-05-19 18:43 ` David S. Ahern [this message]
2010-05-21  6:33   ` Markus Armbruster
2010-05-21  6:51     ` Gerd Hoffmann
2010-05-21 17:55       ` [Qemu-devel] Re: [PATCH] " Shahar Havivi
2010-05-25  8:58         ` Gerd Hoffmann
2010-05-26  8:48           ` Shahar Havivi
  -- strict thread matches above, loose matches on Subject: below --
2010-05-21 18:45 [Qemu-devel] [PATCH v2] " David S. Ahern
2010-05-21 19:40 ` Markus Armbruster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4BF4314F.6000904@cisco.com \
    --to=daahern@cisco.com \
    --cc=qemu-devel@nongnu.org \
    --cc=shaharh@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).