summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirill Moizik <kmoizik@redhat.com>2016-03-08 16:05:52 +0200
committerJonathon Jongsma <jjongsma@redhat.com>2016-03-24 11:00:01 -0500
commit7fec6cd96176290ffe475612535d139936d31c0b (patch)
tree214c8a5c85f23cfc74a1980b807def94ec36b12b
parentb4b4187813cdd6c137915bf3967bfaeac0f14a36 (diff)
usbredir: Protect data accessed by asynchronous redirection flows
This commit adds locking to ensure thread safety required after start/stop redirection flows moved to separate threads. This is done in preparation to following commits that will introduce actual multithreaded access to corresponding routines. Signed-off-by: Kirill Moizik <kmoizik@redhat.com> Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com> Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
-rw-r--r--src/channel-usbredir.c9
-rw-r--r--src/usb-device-manager.c12
2 files changed, 18 insertions, 3 deletions
diff --git a/src/channel-usbredir.c b/src/channel-usbredir.c
index ff238e5..a2a9343 100644
--- a/src/channel-usbredir.c
+++ b/src/channel-usbredir.c
@@ -656,6 +656,8 @@ static void usbredir_handle_msg(SpiceChannel *c, SpiceMsgIn *in)
priv->read_buf = buf;
priv->read_buf_size = size;
+ spice_usbredir_channel_lock(channel);
+
r = usbredirhost_read_guest_data(priv->host);
if (r != 0) {
SpiceUsbDevice *spice_device = priv->spice_device;
@@ -663,7 +665,10 @@ static void usbredir_handle_msg(SpiceChannel *c, SpiceMsgIn *in)
gchar *desc;
GError *err;
- g_return_if_fail(spice_device != NULL);
+ if (spice_device == NULL) {
+ spice_usbredir_channel_unlock(channel);
+ return;
+ }
desc = spice_usb_device_get_description(spice_device, NULL);
switch (r) {
@@ -700,6 +705,8 @@ static void usbredir_handle_msg(SpiceChannel *c, SpiceMsgIn *in)
g_error_free(err);
}
+
+ spice_usbredir_channel_unlock(channel);
}
#endif /* USE_USBREDIR */
diff --git a/src/usb-device-manager.c b/src/usb-device-manager.c
index be8b517..3872bb6 100644
--- a/src/usb-device-manager.c
+++ b/src/usb-device-manager.c
@@ -1353,9 +1353,13 @@ static SpiceUsbredirChannel *spice_usb_device_manager_get_channel_for_dev(
for (i = 0; i < priv->channels->len; i++) {
SpiceUsbredirChannel *channel = g_ptr_array_index(priv->channels, i);
+ spice_usbredir_channel_lock(channel);
libusb_device *libdev = spice_usbredir_channel_get_device(channel);
- if (spice_usb_manager_device_equal_libdev(manager, device, libdev))
+ if (spice_usb_manager_device_equal_libdev(manager, device, libdev)) {
+ spice_usbredir_channel_unlock(channel);
return channel;
+ }
+ spice_usbredir_channel_unlock(channel);
}
#endif
return NULL;
@@ -1749,9 +1753,13 @@ spice_usb_device_manager_can_redirect_device(SpiceUsbDeviceManager *self,
/* Check if there are free channels */
for (i = 0; i < priv->channels->len; i++) {
SpiceUsbredirChannel *channel = g_ptr_array_index(priv->channels, i);
+ spice_usbredir_channel_lock(channel);
- if (!spice_usbredir_channel_get_device(channel))
+ if (!spice_usbredir_channel_get_device(channel)){
+ spice_usbredir_channel_unlock(channel);
break;
+ }
+ spice_usbredir_channel_unlock(channel);
}
if (i == priv->channels->len) {
g_set_error_literal(err, SPICE_CLIENT_ERROR, SPICE_CLIENT_ERROR_FAILED,