[Spice-devel] [PATCH v2 2/6] WinUsbDev: add redirecting state to GUdevClientPrivate

Kirill Moizik kirill at daynix.com
Mon Jul 6 10:59:02 PDT 2015


wnd_proc callback should not query usb devices in the middle of redirecting flow. Caller may get inconsistent enumeration results due to device resets performed by UsbDk and Windows mechanisms handling those resets.

Signed-off-by: Kirill Moizik <kirill at daynix.com>
---
 src/map-file      |  2 ++
 src/win-usb-dev.c | 15 +++++++++++++++
 src/win-usb-dev.h |  2 ++
 3 files changed, 19 insertions(+)

diff --git a/src/map-file b/src/map-file
index d5a073f..d0c24a4 100644
--- a/src/map-file
+++ b/src/map-file
@@ -117,6 +117,8 @@ spice_uri_to_string;
 spice_usb_device_get_description;
 spice_usb_device_get_libusb_device;
 spice_usb_device_get_type;
+spice_g_udev_set_redirecting;
+spice_g_udev_handle_device_change;
 spice_usb_device_manager_can_redirect_device;
 spice_usb_device_manager_connect_device_async;
 spice_usb_device_manager_connect_device_finish;
diff --git a/src/win-usb-dev.c b/src/win-usb-dev.c
index 1e4b2d6..23bea42 100644
--- a/src/win-usb-dev.c
+++ b/src/win-usb-dev.c
@@ -37,6 +37,7 @@ struct _GUdevClientPrivate {
     gssize udev_list_size;
     GList *udev_list;
     HWND hwnd;
+    gboolean redirecting;
 };
 
 #define G_UDEV_CLIENT_WINCLASS_NAME  TEXT("G_UDEV_CLIENT")
@@ -186,6 +187,7 @@ g_udev_client_initable_init(GInitable *initable, GCancellable *cancellable,
     self = G_UDEV_CLIENT(initable);
     priv = self->priv;
 
+    priv->redirecting = FALSE;
     rc = libusb_init(&priv->ctx);
     if (rc < 0) {
         const char *errstr = spice_usbutil_libusb_strerror(rc);
@@ -334,6 +336,11 @@ static gboolean gudev_devices_are_equal(GUdevDevice *a, GUdevDevice *b)
     return (same_pid && same_vid);
 }
 
+void spice_g_udev_set_redirecting (gboolean val)
+{
+    GUdevClientPrivate *priv = singleton->priv;
+    priv->redirecting = val;
+}
 
 /* Assumes each event stands for a single device change (at most) */
 static void handle_dev_change(GUdevClient *self)
@@ -347,6 +354,9 @@ static void handle_dev_change(GUdevClient *self)
     GList *llist, *slist; /* long-list and short-list*/
     GList *lit, *sit; /* iterators for long-list and short-list */
     GUdevDevice *ldev, *sdev; /* devices on long-list and short-list */
+    if (priv->redirecting == TRUE) {
+        return;
+    }
 
     dev_count = g_udev_client_list_devices(self, &now_devs, &err,
                                            __FUNCTION__);
@@ -409,6 +419,11 @@ leave:
     priv->udev_list_size = dev_count;
 }
 
+void spice_g_udev_handle_device_change(void)
+{
+    handle_dev_change(singleton);
+}
+
 static LRESULT CALLBACK wnd_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
 {
     /* Only DBT_DEVNODES_CHANGED recieved */
diff --git a/src/win-usb-dev.h b/src/win-usb-dev.h
index b5c4fce..080c89f 100644
--- a/src/win-usb-dev.h
+++ b/src/win-usb-dev.h
@@ -86,6 +86,8 @@ GType g_udev_device_get_type(void) G_GNUC_CONST;
 const gchar *g_udev_device_get_property(GUdevDevice *udev, const gchar *property);
 const gchar *g_udev_device_get_sysfs_attr(GUdevDevice *udev, const gchar *attr);
 
+void   spice_g_udev_set_redirecting(gboolean val);
+void   spice_g_udev_handle_device_change(void);
 GQuark g_udev_client_error_quark(void);
 #define G_UDEV_CLIENT_ERROR g_udev_client_error_quark()
 
-- 
2.1.0



More information about the Spice-devel mailing list