[Spice-devel] [PATCH spice-server v5 5/8] stream-device: Disable guest device on errors

Frediano Ziglio fziglio at redhat.com
Tue Feb 13 15:54:18 UTC 2018


To communicate the error and avoiding to have to read any data the
guest want to write disable the device.

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 server/stream-device.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/server/stream-device.c b/server/stream-device.c
index a5c39992..b7553c67 100644
--- a/server/stream-device.c
+++ b/server/stream-device.c
@@ -88,6 +88,7 @@ stream_device_partial_read(StreamDevice *dev, SpiceCharDeviceInstance *sin)
         while (sif->read(sin, buf, sizeof(buf)) > 0) {
             continue;
         }
+        sif->state(sin, 0);
         return false;
     }
 
@@ -374,6 +375,19 @@ reset_channels(StreamDevice *dev)
     }
 }
 
+static void
+char_device_enable(RedCharDevice *char_dev)
+{
+    SpiceCharDeviceInstance *sin = NULL;
+    g_object_get(char_dev, "sin", &sin, NULL);
+    spice_assert(sin != NULL);
+
+    SpiceCharDeviceInterface *sif = spice_char_device_get_interface(sin);
+    if (sif->state) {
+        sif->state(sin, 1);
+    }
+}
+
 static void
 stream_device_port_event(RedCharDevice *char_dev, uint8_t event)
 {
@@ -394,6 +408,12 @@ stream_device_port_event(RedCharDevice *char_dev, uint8_t event)
     dev->flow_stopped = false;
     red_char_device_reset(char_dev);
     reset_channels(dev);
+
+    // enable the device again. We try to enable it even on close as
+    // this could prevent a possible race condition where we open the
+    // device from the guest and it take some time to enable causing
+    // temporary writing issues.
+    char_device_enable(char_dev);
 }
 
 static void
-- 
2.14.3



More information about the Spice-devel mailing list