Commit 24772c1edabb8bef3e74cd12da5c28c273d51153
1 parent
64838171
husb: remove disconnect detection timer (Max Krasnyansky)
On top of my previous USB patchset. Async completion handler can detect device disconnects without polling. We do not need the timer anymore. Signed-off-by: Max Krasnyansky <maxk@kernel.org> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5052 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
1 changed file
with
6 additions
and
31 deletions
usb-linux.c
... | ... | @@ -82,11 +82,10 @@ typedef struct USBHostDevice { |
82 | 82 | uint8_t descr[1024]; |
83 | 83 | int descr_len; |
84 | 84 | int configuration; |
85 | + int closing; | |
85 | 86 | |
86 | 87 | struct endp_data endp_table[MAX_ENDPOINTS]; |
87 | 88 | |
88 | - QEMUTimer *timer; | |
89 | - | |
90 | 89 | /* Host side address */ |
91 | 90 | int bus_num; |
92 | 91 | int addr; |
... | ... | @@ -186,7 +185,7 @@ static void async_complete(void *opaque) |
186 | 185 | if (errno == EAGAIN) |
187 | 186 | return; |
188 | 187 | |
189 | - if (errno == ENODEV) { | |
188 | + if (errno == ENODEV && !s->closing) { | |
190 | 189 | printf("husb: device %d.%d disconnected\n", s->bus_num, s->addr); |
191 | 190 | usb_device_del_addr(0, s->dev.addr); |
192 | 191 | return; |
... | ... | @@ -328,7 +327,8 @@ static void usb_host_handle_destroy(USBDevice *dev) |
328 | 327 | { |
329 | 328 | USBHostDevice *s = (USBHostDevice *)dev; |
330 | 329 | |
331 | - qemu_del_timer(s->timer); | |
330 | + s->closing = 1; | |
331 | + | |
332 | 332 | qemu_set_fd_handler(s->fd, NULL, NULL, NULL); |
333 | 333 | |
334 | 334 | hostdev_unlink(s); |
... | ... | @@ -582,22 +582,6 @@ static int usb_linux_update_endp_table(USBHostDevice *s) |
582 | 582 | return 0; |
583 | 583 | } |
584 | 584 | |
585 | -static void usb_host_device_check(void *priv) | |
586 | -{ | |
587 | - USBHostDevice *s = priv; | |
588 | - struct usbdevfs_connectinfo ci; | |
589 | - int err; | |
590 | - | |
591 | - err = ioctl(s->fd, USBDEVFS_CONNECTINFO, &ci); | |
592 | - if (err < 0) { | |
593 | - printf("husb: device %d.%d disconnected\n", s->bus_num, s->addr); | |
594 | - usb_device_del_addr(0, s->dev.addr); | |
595 | - return; | |
596 | - } | |
597 | - | |
598 | - qemu_mod_timer(s->timer, qemu_get_clock(rt_clock) + 1000); | |
599 | -} | |
600 | - | |
601 | 585 | static USBDevice *usb_host_device_open_addr(int bus_num, int addr, const char *prod_name) |
602 | 586 | { |
603 | 587 | int fd = -1, ret; |
... | ... | @@ -612,10 +596,6 @@ static USBDevice *usb_host_device_open_addr(int bus_num, int addr, const char *p |
612 | 596 | dev->bus_num = bus_num; |
613 | 597 | dev->addr = addr; |
614 | 598 | |
615 | - dev->timer = qemu_new_timer(rt_clock, usb_host_device_check, (void *) dev); | |
616 | - if (!dev->timer) | |
617 | - goto fail; | |
618 | - | |
619 | 599 | printf("husb: open device %d.%d\n", bus_num, addr); |
620 | 600 | |
621 | 601 | snprintf(buf, sizeof(buf), USBDEVFS_PATH "/%03d/%03d", |
... | ... | @@ -683,19 +663,14 @@ static USBDevice *usb_host_device_open_addr(int bus_num, int addr, const char *p |
683 | 663 | /* USB devio uses 'write' flag to check for async completions */ |
684 | 664 | qemu_set_fd_handler(dev->fd, NULL, async_complete, dev); |
685 | 665 | |
686 | - /* Start the timer to detect disconnect */ | |
687 | - qemu_mod_timer(dev->timer, qemu_get_clock(rt_clock) + 1000); | |
688 | - | |
689 | 666 | hostdev_link(dev); |
690 | 667 | |
691 | 668 | return (USBDevice *) dev; |
692 | 669 | |
693 | 670 | fail: |
694 | - if (dev) { | |
695 | - if (dev->timer) | |
696 | - qemu_del_timer(dev->timer); | |
671 | + if (dev) | |
697 | 672 | qemu_free(dev); |
698 | - } | |
673 | + | |
699 | 674 | close(fd); |
700 | 675 | return NULL; |
701 | 676 | } | ... | ... |