All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anthony Liguori <anthony@codemonkey.ws>
To: Max Krasnyansky <maxk@kernel.org>
Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org
Subject: Re: [PATCH 1/5] husb: support for USB host device auto disconnect.
Date: Thu, 14 Aug 2008 11:28:30 -0500	[thread overview]
Message-ID: <48A45D2E.5000704@codemonkey.ws> (raw)
In-Reply-To: <75c6e94e6d567896941e879ef7eddb29ecc3f6fa.1218685608.git.maxk@kernel.org>

Max Krasnyansky wrote:
> I got really annoyed by the fact that you have to manually do
> usb_del in the monitor when host device is unplugged and decided
> to fix it :)
>   

Yes, I've felt the same annoyance.

> Basically we now automatically remove guest USB device
> when the actual host device is disconnected.
>
> At first I've extended set_fd_handlerX() stuff to support checking
> for exceptions on fds. But unfortunately usbfs code does not wake up
> user-space process when device is removed, which means we need a
> timer to periodically check if device is still there. So I removed
> fd exception stuff and implemented it with the timer.
>   

I'm surprised there isn't an EOF when the device is disconnected.  There 
has to be some sort of userspace notification that a device has been 
unplugged.  I don't really like the idea of polling but it wouldn't 
surprise me if we had to.

> Signed-off-by: Max Krasnyansky <maxk@kernel.org>
> ---
>  hw/usb.h    |    1 +
>  usb-linux.c |   56 +++++++++++++++++++++++++++++++++++++++++++++++---------
>  vl.c        |   26 ++++++++++++++++++--------
>  3 files changed, 66 insertions(+), 17 deletions(-)
>
> diff --git a/hw/usb.h b/hw/usb.h
> index 8bdc68d..2edb982 100644
> --- a/hw/usb.h
> +++ b/hw/usb.h
> @@ -197,6 +197,7 @@ static inline void usb_cancel_packet(USBPacket * p)
>      p->cancel_cb(p, p->cancel_opaque);
>  }
>  
> +int usb_device_del_addr(int bus_num, int addr);
>  void usb_attach(USBPort *port, USBDevice *dev);
>  int usb_generic_handle_packet(USBDevice *s, USBPacket *p);
>  int set_usb_string(uint8_t *buf, const char *str);
> diff --git a/usb-linux.c b/usb-linux.c
> index d3e4e2e..0023c1d 100644
> --- a/usb-linux.c
> +++ b/usb-linux.c
> @@ -22,6 +22,7 @@
>   * THE SOFTWARE.
>   */
>  #include "qemu-common.h"
> +#include "qemu-timer.h"
>  #include "hw/usb.h"
>  #include "console.h"
>  
> @@ -77,6 +78,7 @@ typedef struct USBHostDevice {
>      uint8_t descr[1024];
>      int descr_len;
>      int urbs_ready;
> +    QEMUTimer *timer;
>  } USBHostDevice;
>  
>  typedef struct PendingURB {
> @@ -165,7 +167,11 @@ static int usb_host_update_interfaces(USBHostDevice *dev, int configuration)
>          }
>          config_descr_len = dev->descr[i];
>  
> -        if (configuration == dev->descr[i + 5])
> +#ifdef DEBUG
> +	printf("config #%d need %d\n", dev->descr[i + 5], configuration); 
> +#endif
> +
> +        if (configuration < 0 || configuration == dev->descr[i + 5])
>              break;
>  
>          i += config_descr_len;
> @@ -230,8 +236,11 @@ static void usb_host_handle_destroy(USBDevice *dev)
>  {
>      USBHostDevice *s = (USBHostDevice *)dev;
>  
> +    qemu_del_timer(s->timer);
> +
>   

qemu_del_timer() only removes a pending timer.  You need 
qemu_free_timer() to actually free the memory associated with it.

>      dev->urbs_ready = 0;
>      return (USBDevice *)dev;
>  fail:
> -    if (dev)
> +    if (dev) {
> +	if (dev->timer)
> +		qemu_del_timer(dev->timer);
>   

Here too.

Regards,

Anthony Liguori

WARNING: multiple messages have this Message-ID (diff)
From: Anthony Liguori <anthony@codemonkey.ws>
To: Max Krasnyansky <maxk@kernel.org>
Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org
Subject: [Qemu-devel] Re: [PATCH 1/5] husb: support for USB host device auto disconnect.
Date: Thu, 14 Aug 2008 11:28:30 -0500	[thread overview]
Message-ID: <48A45D2E.5000704@codemonkey.ws> (raw)
In-Reply-To: <75c6e94e6d567896941e879ef7eddb29ecc3f6fa.1218685608.git.maxk@kernel.org>

Max Krasnyansky wrote:
> I got really annoyed by the fact that you have to manually do
> usb_del in the monitor when host device is unplugged and decided
> to fix it :)
>   

Yes, I've felt the same annoyance.

> Basically we now automatically remove guest USB device
> when the actual host device is disconnected.
>
> At first I've extended set_fd_handlerX() stuff to support checking
> for exceptions on fds. But unfortunately usbfs code does not wake up
> user-space process when device is removed, which means we need a
> timer to periodically check if device is still there. So I removed
> fd exception stuff and implemented it with the timer.
>   

I'm surprised there isn't an EOF when the device is disconnected.  There 
has to be some sort of userspace notification that a device has been 
unplugged.  I don't really like the idea of polling but it wouldn't 
surprise me if we had to.

> Signed-off-by: Max Krasnyansky <maxk@kernel.org>
> ---
>  hw/usb.h    |    1 +
>  usb-linux.c |   56 +++++++++++++++++++++++++++++++++++++++++++++++---------
>  vl.c        |   26 ++++++++++++++++++--------
>  3 files changed, 66 insertions(+), 17 deletions(-)
>
> diff --git a/hw/usb.h b/hw/usb.h
> index 8bdc68d..2edb982 100644
> --- a/hw/usb.h
> +++ b/hw/usb.h
> @@ -197,6 +197,7 @@ static inline void usb_cancel_packet(USBPacket * p)
>      p->cancel_cb(p, p->cancel_opaque);
>  }
>  
> +int usb_device_del_addr(int bus_num, int addr);
>  void usb_attach(USBPort *port, USBDevice *dev);
>  int usb_generic_handle_packet(USBDevice *s, USBPacket *p);
>  int set_usb_string(uint8_t *buf, const char *str);
> diff --git a/usb-linux.c b/usb-linux.c
> index d3e4e2e..0023c1d 100644
> --- a/usb-linux.c
> +++ b/usb-linux.c
> @@ -22,6 +22,7 @@
>   * THE SOFTWARE.
>   */
>  #include "qemu-common.h"
> +#include "qemu-timer.h"
>  #include "hw/usb.h"
>  #include "console.h"
>  
> @@ -77,6 +78,7 @@ typedef struct USBHostDevice {
>      uint8_t descr[1024];
>      int descr_len;
>      int urbs_ready;
> +    QEMUTimer *timer;
>  } USBHostDevice;
>  
>  typedef struct PendingURB {
> @@ -165,7 +167,11 @@ static int usb_host_update_interfaces(USBHostDevice *dev, int configuration)
>          }
>          config_descr_len = dev->descr[i];
>  
> -        if (configuration == dev->descr[i + 5])
> +#ifdef DEBUG
> +	printf("config #%d need %d\n", dev->descr[i + 5], configuration); 
> +#endif
> +
> +        if (configuration < 0 || configuration == dev->descr[i + 5])
>              break;
>  
>          i += config_descr_len;
> @@ -230,8 +236,11 @@ static void usb_host_handle_destroy(USBDevice *dev)
>  {
>      USBHostDevice *s = (USBHostDevice *)dev;
>  
> +    qemu_del_timer(s->timer);
> +
>   

qemu_del_timer() only removes a pending timer.  You need 
qemu_free_timer() to actually free the memory associated with it.

>      dev->urbs_ready = 0;
>      return (USBDevice *)dev;
>  fail:
> -    if (dev)
> +    if (dev) {
> +	if (dev->timer)
> +		qemu_del_timer(dev->timer);
>   

Here too.

Regards,

Anthony Liguori

  reply	other threads:[~2008-08-14 16:29 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-14  4:22 [PATCH 0/5] Various USB fixes and improvements Max Krasnyansky
2008-08-14  4:22 ` [Qemu-devel] " Max Krasnyansky
2008-08-14  4:22 ` [PATCH 1/5] husb: support for USB host device auto disconnect Max Krasnyansky
2008-08-14  4:22   ` [Qemu-devel] " Max Krasnyansky
2008-08-14 16:28   ` Anthony Liguori [this message]
2008-08-14 16:28     ` [Qemu-devel] " Anthony Liguori
2008-08-14 19:26     ` Max Krasnyansky
2008-08-14 19:26       ` [Qemu-devel] " Max Krasnyansky
2008-08-14 21:41     ` Max Krasnyansky
2008-08-14 21:41       ` [Qemu-devel] " Max Krasnyansky
2008-08-14  4:22 ` [PATCH 2/5] husb: support for USB host device auto connect Max Krasnyansky
2008-08-14  4:22   ` [Qemu-devel] " Max Krasnyansky
2008-08-14 16:41   ` Anthony Liguori
2008-08-14 16:41     ` [Qemu-devel] " Anthony Liguori
2008-08-14 19:38     ` Max Krasnyansky
2008-08-14 19:38       ` [Qemu-devel] " Max Krasnyansky
2008-08-14 20:21       ` Anthony Liguori
2008-08-14 20:21         ` [Qemu-devel] " Anthony Liguori
2008-08-14 20:34         ` Max Krasnyansky
2008-08-14 20:34           ` [Qemu-devel] " Max Krasnyansky
2008-08-14 20:41           ` Anthony Liguori
2008-08-14 20:41             ` [Qemu-devel] " Anthony Liguori
2008-08-14 21:14             ` François Revol
2008-08-15  7:46             ` Guido Günther
2008-08-15  7:46               ` Guido Günther
2008-08-15 18:24               ` Max Krasnyansky
2008-08-15 18:31                 ` Javier Guerra
2008-08-18 18:21                   ` Max Krasnyansky
2008-08-18 18:52                     ` Javier Guerra
2008-08-18 18:56                       ` Jamie Lokier
2008-08-18 18:56                         ` Jamie Lokier
2008-08-17  7:52                 ` Avi Kivity
2008-08-18 18:46                   ` Max Krasnyansky
2008-08-18 14:11                 ` Anthony Liguori
2008-08-18 18:16                   ` Max Krasnyansky
2008-08-14  4:22 ` [PATCH 3/5] usb: generic packet handler cleanup and documentation Max Krasnyansky
2008-08-14  4:22   ` [Qemu-devel] " Max Krasnyansky
2008-08-14  4:22 ` [PATCH 4/5] uhci: rewrite UHCI emulator, fully async operation with multiple outstanding transactions Max Krasnyansky
2008-08-14  4:22   ` [Qemu-devel] " Max Krasnyansky
2008-08-14 17:51   ` Anthony Liguori
2008-08-14 17:51     ` [Qemu-devel] " Anthony Liguori
2008-08-14 19:49     ` Max Krasnyansky
2008-08-14 19:49       ` [Qemu-devel] " Max Krasnyansky
2008-10-11 23:54   ` [Qemu-devel] " Juergen Lock
2008-10-15 19:54     ` Max Krasnyansky
2008-10-15 22:05       ` andrzej zaborowski
2008-10-16 21:25         ` Juergen Lock
2008-08-14  4:22 ` [PATCH 5/5] husb: rewrite Linux host USB layer, fully async operation Max Krasnyansky
2008-08-14  4:22   ` [Qemu-devel] " Max Krasnyansky
2008-08-15 14:24   ` Paul Brook
2008-08-15 14:24     ` Paul Brook
2008-08-15 19:04     ` Max Krasnyansky
2008-08-15 19:53       ` Paul Brook
2008-08-15 19:53         ` Paul Brook
2008-08-18 18:40         ` Max Krasnyansky
2008-08-14 17:55 ` [PATCH 0/5] Various USB fixes and improvements Anthony Liguori
2008-08-14 17:55   ` [Qemu-devel] " Anthony Liguori
2008-08-14 19:55   ` Max Krasnyansky
2008-08-14 19:55     ` [Qemu-devel] " Max Krasnyansky

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=48A45D2E.5000704@codemonkey.ws \
    --to=anthony@codemonkey.ws \
    --cc=kvm@vger.kernel.org \
    --cc=maxk@kernel.org \
    --cc=qemu-devel@nongnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.