[Spice-devel] [PATCH] Revert "usbredir: Disconnect USB device asynchronously"

Christophe Fergeau cfergeau at redhat.com
Tue May 15 10:17:03 UTC 2018


If I remember correctly, this asynchronous disconnection was needed
because in some case, during normal usage, the disconnection was
blocking for seconds (on Windows with usbdk), and if it's not async, it
would block the main loop, and thus the whole GUI (all of this should
have been in the commit log :(
This seems a bit trickier to achieve, but I'd try to block the exit
process until the disconnection thread has finished its job.

Christophe


On Mon, May 07, 2018 at 05:02:47PM +0800, Qiu Wenbo wrote:
> This reverts commit 9fbf679453d8dbfe797a738cb536136599d7adab.
> 
> In some cases, remote-viewer will exit before the async function run in
> another thread finish and USB devices redirected to the VM will not "pop up" to
> operation system. For example, a USB disk should be auto mounted
> when remote-viewer exit.
> 
> Signed-off-by: Qiu Wenbo <qiuwenbo at kylinos.com.cn>
> ---
>  src/channel-usbredir.c | 48 ++++++------------------------------------
>  1 file changed, 7 insertions(+), 41 deletions(-)
> 
> diff --git a/src/channel-usbredir.c b/src/channel-usbredir.c
> index 0cc5630..34c4679 100644
> --- a/src/channel-usbredir.c
> +++ b/src/channel-usbredir.c
> @@ -121,54 +121,20 @@ static void spice_usbredir_channel_init(SpiceUsbredirChannel *channel)
>  }
>  
>  #ifdef USE_USBREDIR
> -
> -static void _channel_reset_finish(SpiceUsbredirChannel *channel)
> -{
> -    SpiceUsbredirChannelPrivate *priv = channel->priv;
> -
> -    spice_usbredir_channel_lock(channel);
> -
> -    usbredirhost_close(priv->host);
> -    priv->host = NULL;
> -
> -    /* Call set_context to re-create the host */
> -    spice_usbredir_channel_set_context(channel, priv->context);
> -
> -    spice_usbredir_channel_unlock(channel);
> -}
> -
> -static void _channel_reset_cb(GObject *gobject,
> -                              GAsyncResult *result,
> -                              gpointer user_data)
> -{
> -    SpiceChannel *spice_channel =  SPICE_CHANNEL(gobject);
> -    SpiceUsbredirChannel *channel = SPICE_USBREDIR_CHANNEL(spice_channel);
> -    gboolean migrating = GPOINTER_TO_UINT(user_data);
> -    GError *err = NULL;
> -
> -    _channel_reset_finish(channel);
> -
> -    SPICE_CHANNEL_CLASS(spice_usbredir_channel_parent_class)->channel_reset(spice_channel, migrating);
> -
> -    spice_usbredir_channel_disconnect_device_finish(channel, result, &err);
> -    g_object_unref(result);
> -}
> -
>  static void spice_usbredir_channel_reset(SpiceChannel *c, gboolean migrating)
>  {
>      SpiceUsbredirChannel *channel = SPICE_USBREDIR_CHANNEL(c);
>      SpiceUsbredirChannelPrivate *priv = channel->priv;
>  
>      if (priv->host) {
> -        if (priv->state == STATE_CONNECTED) {
> -            spice_usbredir_channel_disconnect_device_async(channel, NULL,
> -                _channel_reset_cb, GUINT_TO_POINTER(migrating));
> -        } else {
> -            _channel_reset_finish(channel);
> -        }
> -    } else {
> -        SPICE_CHANNEL_CLASS(spice_usbredir_channel_parent_class)->channel_reset(c, migrating);
> +        if (priv->state == STATE_CONNECTED)
> +            spice_usbredir_channel_disconnect_device(channel);
> +        usbredirhost_close(priv->host);
> +        priv->host = NULL;
> +        /* Call set_context to re-create the host */
> +        spice_usbredir_channel_set_context(channel, priv->context);
>      }
> +    SPICE_CHANNEL_CLASS(spice_usbredir_channel_parent_class)->channel_reset(c, migrating);
>  }
>  #endif
>  
> -- 
> 2.17.0
> 
> 
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/spice-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20180515/1fd00b25/attachment.sig>


More information about the Spice-devel mailing list