From: Erik Rull <spamfolder@rdsoftware.de>
To: Gerd Hoffmann <kraxel@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 6/7] usb-host: claim port
Date: Thu, 25 Aug 2011 18:03:34 +0200 [thread overview]
Message-ID: <4E567256.5030401@rdsoftware.de> (raw)
In-Reply-To: <1314284817-9034-7-git-send-email-kraxel@redhat.com>
Hi Gerd,
is this related / the fix to my question regarding the recurring claimed
messages? (See my mail dated 2011-08-21)
Best regards,
Erik
Gerd Hoffmann wrote:
> When configured to pass through a specific host port (using hostbus and
> hostport properties), try to claim the port if supported by the kernel.
> That will avoid any kernel drivers binding to devices plugged into that
> port. It will not stop any userspace apps (such as usb_modeswitch)
> access the device via usbfs though.
>
> Signed-off-by: Gerd Hoffmann<kraxel@redhat.com>
> ---
> trace-events | 1 +
> usb-linux.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 58 insertions(+), 0 deletions(-)
>
> diff --git a/trace-events b/trace-events
> index 1c7a624..6fe8f62 100644
> --- a/trace-events
> +++ b/trace-events
> @@ -260,6 +260,7 @@ usb_host_urb_complete(int bus, int addr, void *aurb, int status, int length, int
> usb_host_ep_op(int bus, int addr, int ep, const char *op) "dev %d:%d, ep %d, %s"
> usb_host_reset(int bus, int addr) "dev %d:%d"
> usb_host_auto_scan(const char *state) "%s"
> +usb_host_claim_port(int bus, int hub, int port) "bus %d, hub addr %d, port %d"
>
> # hw/scsi-bus.c
> disable scsi_req_alloc(int target, int lun, int tag) "target %d lun %d tag %d"
> diff --git a/usb-linux.c b/usb-linux.c
> index 3b0f53f..de6cb70 100644
> --- a/usb-linux.c
> +++ b/usb-linux.c
> @@ -115,6 +115,7 @@ struct USBAutoFilter {
> typedef struct USBHostDevice {
> USBDevice dev;
> int fd;
> + int hub_fd;
>
> uint8_t descr[8192];
> int descr_len;
> @@ -525,6 +526,9 @@ static void usb_host_handle_destroy(USBDevice *dev)
> USBHostDevice *s = (USBHostDevice *)dev;
>
> usb_host_close(s);
> + if (s->hub_fd != -1) {
> + close(s->hub_fd);
> + }
> QTAILQ_REMOVE(&hostdevs, s, next);
> qemu_remove_exit_notifier(&s->exit);
> }
> @@ -1266,10 +1270,63 @@ static int usb_host_initfn(USBDevice *dev)
>
> dev->auto_attach = 0;
> s->fd = -1;
> + s->hub_fd = -1;
> +
> QTAILQ_INSERT_TAIL(&hostdevs, s, next);
> s->exit.notify = usb_host_exit_notifier;
> qemu_add_exit_notifier(&s->exit);
> usb_host_auto_check(NULL);
> +
> +#ifdef USBDEVFS_CLAIM_PORT
> + if (s->match.bus_num != 0&& s->match.port != NULL) {
> + char *h, hub_name[64], line[1024];
> + int hub_addr, portnr, ret;
> +
> + snprintf(hub_name, sizeof(hub_name), "%d-%s",
> + s->match.bus_num, s->match.port);
> +
> + /* try strip off last ".$portnr" to get hub */
> + h = strrchr(hub_name, '.');
> + if (h != NULL) {
> + portnr = atoi(h+1);
> + *h = '\0';
> + } else {
> + /* no dot in there -> it is the root hub */
> + snprintf(hub_name, sizeof(hub_name), "usb%d",
> + s->match.bus_num);
> + portnr = atoi(s->match.port);
> + }
> +
> + if (!usb_host_read_file(line, sizeof(line), "devnum",
> + hub_name)) {
> + goto out;
> + }
> + if (sscanf(line, "%d",&hub_addr) != 1) {
> + goto out;
> + }
> +
> + if (!usb_host_device_path) {
> + goto out;
> + }
> + snprintf(line, sizeof(line), "%s/%03d/%03d",
> + usb_host_device_path, s->match.bus_num, hub_addr);
> + s->hub_fd = open(line, O_RDWR | O_NONBLOCK);
> + if (s->hub_fd< 0) {
> + goto out;
> + }
> +
> + ret = ioctl(s->hub_fd, USBDEVFS_CLAIM_PORT,&portnr);
> + if (ret< 0) {
> + close(s->hub_fd);
> + s->hub_fd = -1;
> + goto out;
> + }
> +
> + trace_usb_host_claim_port(s->match.bus_num, hub_addr, portnr);
> + }
> +out:
> +#endif
> +
> return 0;
> }
>
next prev parent reply other threads:[~2011-08-25 16:03 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-25 15:06 [Qemu-devel] [PATCH 0/7] usb-host: bugfixes Gerd Hoffmann
2011-08-25 15:06 ` [Qemu-devel] [PATCH 1/7] usb-host: start tracing support Gerd Hoffmann
2011-08-25 15:58 ` Stefan Hajnoczi
2011-08-25 15:06 ` [Qemu-devel] [PATCH 2/7] usb-host: reapurb error report fix Gerd Hoffmann
2011-08-25 15:06 ` [Qemu-devel] [PATCH 3/7] usb-host: fix halted endpoints Gerd Hoffmann
2011-08-25 15:06 ` [Qemu-devel] [PATCH 4/7] usb-host: limit open retries Gerd Hoffmann
2011-08-25 15:06 ` [Qemu-devel] [PATCH 5/7] usb-host: fix configuration tracking Gerd Hoffmann
2011-08-25 15:06 ` [Qemu-devel] [PATCH 6/7] usb-host: claim port Gerd Hoffmann
2011-08-25 16:03 ` Erik Rull [this message]
2011-08-25 20:48 ` Gerd Hoffmann
2011-08-25 15:06 ` [Qemu-devel] [PATCH 7/7] usb: fix use after free Gerd Hoffmann
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=4E567256.5030401@rdsoftware.de \
--to=spamfolder@rdsoftware.de \
--cc=kraxel@redhat.com \
--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 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).