Skip to contentSkip to conversation

usb-redir: Add flow control support v2 + one more fix

Qemu-devel New Hans de Goede 2 participants 4 messages Mar 19, 2013

lore
Share & tools
lore
#0 lore raw

Here is v2 of the "usb-redir: Add flow control support" patch with the checkpatch issue fixed + one other usb-redir bugfix.

Regards,

Hans

#1 lore raw

PATCH 1/2 usb-redir: Add flow control support

---
 hw/usb/redirect.c | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)
hw/usb/redirect.c +32 -1
index c519b9b..0b2a5e6 100644
@@ -104,6 +104,8 @@ struct USBRedirDevice {
     /* Data passed from chardev the fd_read cb to the usbredirparser read cb */
     const uint8_t *read_buf;
     int read_buf_size;
+    /* Active chardev-watch-tag */
+    guint watch;
     /* For async handling of close */
     QEMUBH *chardev_close_bh;
     /* To delay the usb attach in case of quick chardev close + open */
@@ -254,9 +256,21 @@ static int usbredir_read(void *priv, uint8_t *data, int count)
     return count;
 }
 
+static gboolean usbredir_write_unblocked(GIOChannel *chan, GIOCondition cond,
+                                         void *opaque)
+{
+    USBRedirDevice *dev = opaque;
+
+    dev->watch = 0;
+    usbredirparser_do_write(dev->parser);
+
+    return FALSE;
+}
+
 static int usbredir_write(void *priv, uint8_t *data, int count)
 {
     USBRedirDevice *dev = priv;
+    int r;
 
     if (!dev->cs->opened) {
         return 0;
@@ -267,7 +281,17 @@ static int usbredir_write(void *priv, uint8_t *data, int count)
         return 0;
     }
 
-    return qemu_chr_fe_write(dev->cs, data, count);
+    r = qemu_chr_fe_write(dev->cs, data, count);
+    if (r < count) {
+        if (!dev->watch) {
+            dev->watch = qemu_chr_fe_add_watch(dev->cs, G_IO_OUT,
+                                               usbredir_write_unblocked, dev);
+        }
+        if (r < 0) {
+            r = 0;
+        }
+    }
+    return r;
 }
 
 /*
@@ -1085,6 +1109,10 @@ static void usbredir_chardev_close_bh(void *opaque)
         usbredirparser_destroy(dev->parser);
         dev->parser = NULL;
     }
+    if (dev->watch) {
+        g_source_remove(dev->watch);
+        dev->watch = 0;
+    }
 }
 
 static void usbredir_create_parser(USBRedirDevice *dev)
@@ -1319,6 +1347,9 @@ static void usbredir_handle_destroy(USBDevice *udev)
     if (dev->parser) {
         usbredirparser_destroy(dev->parser);
     }
+    if (dev->watch) {
+        g_source_remove(dev->watch);
+    }
 
     free(dev->filter_rules);
 }
Signature · 1 line
1.8.1.4
#2 lore raw

PATCH 2/2 usb-redir: Fix crash on migration with no client connected

In reply to Hans de Goede

If no client is connected on the src side, then we won't receive a parser during migrate, in this case usbredir_post_load() should be a nop, rather then to try to derefefence the NULL dev->parser pointer.

---
 hw/usb/redirect.c | 4 ++++
 1 file changed, 4 insertions(+)
hw/usb/redirect.c +4 -0
index 0b2a5e6..e0df74b 100644
@@ -2006,6 +2006,10 @@ static int usbredir_post_load(void *priv, int version_id)
 {
     USBRedirDevice *dev = priv;
 
+    if (dev->parser == NULL) {
+        return 0;
+    }
+
     switch (dev->device_info.speed) {
     case usb_redir_speed_low:
         dev->dev.speed = USB_SPEED_LOW;
Signature · 1 line
1.8.1.4
#3 lore raw
In reply to Hans de Goede
Quoted 2 lines · Hans de Goede

Here is v2 of the "usb-redir: Add flow control support" patch with the checkpatch issue fixed + one other usb-redir bugfix.

Added #1, #2 is already in the usb queue (yes, I should flush it ...).

cheers,
Gerd