[PATCH spice-server v2 2/6] stream-device: Disable guest device on errors

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 server/stream-device.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/server/stream-device.c b/server/stream-device.c
index ca28800c..59ead59d 100644
--- a/server/stream-device.c
+++ b/server/stream-device.c
@@ -94,6 +94,7 @@ stream_device_partial_read(StreamDevice *dev, SpiceCharDeviceInstance *sin)
         while (sif->read(sin, buf, sizeof(buf)) > 0) {
             continue;
         }
+        sif->state(sin, 0);
         return false;
     }
 
@@ -560,6 +561,19 @@ reset_channels(StreamDevice *dev)
     }
 }
 
+static void
+char_device_set_state(RedCharDevice *char_dev, int state)
+{
+    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, state);
+    }
+}
+
 static void
 stream_device_port_event(RedCharDevice *char_dev, uint8_t event)
 {
@@ -580,6 +594,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_set_state(char_dev, 1);
 }
 
 static void
-- 
2.14.3

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]