[Spice-devel] [PATCH spice-server v2 2/6] stream-device: Disable guest device on errors
Frediano Ziglio
fziglio at redhat.com
Wed Feb 28 08:30:29 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 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
More information about the Spice-devel
mailing list