render / rpms / qemu

Forked from rpms/qemu 10 months ago
Clone

Blame 0013-spice-qemu-char-Generate-chardev-open-close-events.patch

Justin M. Forbes 5e10b1
From 5149f056bd4fbeeb0ce3b850febe213a305a348b Mon Sep 17 00:00:00 2001
Justin M. Forbes 5e10b1
From: Hans de Goede <hdegoede@redhat.com>
Justin M. Forbes 5e10b1
Date: Thu, 21 Jul 2011 15:36:40 +0200
Justin M. Forbes 5e10b1
Subject: [PATCH 13/13] spice-qemu-char: Generate chardev open/close events
Justin M. Forbes 5e10b1
Justin M. Forbes 5e10b1
Define a state callback and make that generate chardev open/close events when
Justin M. Forbes 5e10b1
called by the spice-server.
Justin M. Forbes 5e10b1
Justin M. Forbes 5e10b1
Note that for all but the newest spice-server versions (which have a fix for
Justin M. Forbes 5e10b1
this) the code ignores these events for a spicevmc with a subtype of vdagent,
Justin M. Forbes 5e10b1
this subtype specific knowledge is undesirable, but unavoidable for now, see:
Justin M. Forbes 5e10b1
http://lists.freedesktop.org/archives/spice-devel/2011-July/004837.html
Justin M. Forbes 5e10b1
Justin M. Forbes 5e10b1
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Justin M. Forbes 5e10b1
---
Justin M. Forbes 5e10b1
 spice-qemu-char.c |   46 +++++++++++++++++++++++++++++++++++++++++++++-
Justin M. Forbes 5e10b1
 1 files changed, 45 insertions(+), 1 deletions(-)
Justin M. Forbes 5e10b1
Justin M. Forbes 5e10b1
diff --git a/spice-qemu-char.c b/spice-qemu-char.c
Justin M. Forbes 5e10b1
index 2b8aec4..1f4f1ec 100644
Justin M. Forbes 5e10b1
--- a/spice-qemu-char.c
Justin M. Forbes 5e10b1
+++ b/spice-qemu-char.c
Justin M. Forbes 5e10b1
@@ -89,11 +89,50 @@ static int vmc_read(SpiceCharDeviceInstance *sin, uint8_t *buf, int len)
Justin M. Forbes 5e10b1
     return bytes;
Justin M. Forbes 5e10b1
 }
Justin M. Forbes 5e10b1
 
Justin M. Forbes 5e10b1
+static void vmc_state(SpiceCharDeviceInstance *sin, int connected)
Justin M. Forbes 5e10b1
+{
Justin M. Forbes 5e10b1
+    SpiceCharDriver *scd = container_of(sin, SpiceCharDriver, sin);
Justin M. Forbes 5e10b1
+    int event;
Justin M. Forbes 5e10b1
+
Justin M. Forbes 5e10b1
+#if SPICE_SERVER_VERSION < 0x000901
Justin M. Forbes 5e10b1
+    /*
Justin M. Forbes 5e10b1
+     * spice-server calls the state callback for the agent channel when the
Justin M. Forbes 5e10b1
+     * spice client connects / disconnects. Given that not the client but
Justin M. Forbes 5e10b1
+     * the server is doing the parsing of the messages this is wrong as the
Justin M. Forbes 5e10b1
+     * server is still listening. Worse, this causes the parser in the server
Justin M. Forbes 5e10b1
+     * to go out of sync, so we ignore state calls for subtype vdagent
Justin M. Forbes 5e10b1
+     * spicevmc chardevs. For the full story see:
Justin M. Forbes 5e10b1
+     * http://lists.freedesktop.org/archives/spice-devel/2011-July/004837.html
Justin M. Forbes 5e10b1
+     */
Justin M. Forbes 5e10b1
+    if (strcmp(sin->subtype, "vdagent") == 0) {
Justin M. Forbes 5e10b1
+        return;
Justin M. Forbes 5e10b1
+    }
Justin M. Forbes 5e10b1
+#endif
Justin M. Forbes 5e10b1
+
Justin M. Forbes 5e10b1
+    if ((scd->chr->opened && connected) ||
Justin M. Forbes 5e10b1
+        (!scd->chr->opened && !connected)) {
Justin M. Forbes 5e10b1
+        return;
Justin M. Forbes 5e10b1
+    }
Justin M. Forbes 5e10b1
+
Justin M. Forbes 5e10b1
+    if (connected) {
Justin M. Forbes 5e10b1
+        scd->chr->opened = 1;
Justin M. Forbes 5e10b1
+        event = CHR_EVENT_OPENED;
Justin M. Forbes 5e10b1
+    } else {
Justin M. Forbes 5e10b1
+        scd->chr->opened = 0;
Justin M. Forbes 5e10b1
+        event = CHR_EVENT_CLOSED;
Justin M. Forbes 5e10b1
+    }
Justin M. Forbes 5e10b1
+
Justin M. Forbes 5e10b1
+    if (scd->chr->chr_event) {
Justin M. Forbes 5e10b1
+        scd->chr->chr_event(scd->chr->handler_opaque, event);
Justin M. Forbes 5e10b1
+    }
Justin M. Forbes 5e10b1
+}
Justin M. Forbes 5e10b1
+
Justin M. Forbes 5e10b1
 static SpiceCharDeviceInterface vmc_interface = {
Justin M. Forbes 5e10b1
     .base.type          = SPICE_INTERFACE_CHAR_DEVICE,
Justin M. Forbes 5e10b1
     .base.description   = "spice virtual channel char device",
Justin M. Forbes 5e10b1
     .base.major_version = SPICE_INTERFACE_CHAR_DEVICE_MAJOR,
Justin M. Forbes 5e10b1
     .base.minor_version = SPICE_INTERFACE_CHAR_DEVICE_MINOR,
Justin M. Forbes 5e10b1
+    .state              = vmc_state,
Justin M. Forbes 5e10b1
     .write              = vmc_write,
Justin M. Forbes 5e10b1
     .read               = vmc_read,
Justin M. Forbes 5e10b1
 };
Justin M. Forbes 5e10b1
@@ -222,7 +261,12 @@ int qemu_chr_open_spice(QemuOpts *opts, CharDriverState **_chr)
Justin M. Forbes 5e10b1
     chr->chr_guest_close = spice_chr_guest_close;
Justin M. Forbes 5e10b1
     s->unblock_timer = qemu_new_timer_ms(vm_clock, spice_chr_unblock, s);
Justin M. Forbes 5e10b1
 
Justin M. Forbes 5e10b1
-    qemu_chr_generic_open(chr);
Justin M. Forbes 5e10b1
+#if SPICE_SERVER_VERSION < 0x000901
Justin M. Forbes 5e10b1
+    /* See comment in vmc_state() */
Justin M. Forbes 5e10b1
+    if (strcmp(subtype, "vdagent") == 0) {
Justin M. Forbes 5e10b1
+        qemu_chr_generic_open(chr);
Justin M. Forbes 5e10b1
+    }
Justin M. Forbes 5e10b1
+#endif
Justin M. Forbes 5e10b1
 
Justin M. Forbes 5e10b1
     *_chr = chr;
Justin M. Forbes 5e10b1
     return 0;
Justin M. Forbes 5e10b1
-- 
Justin M. Forbes 5e10b1
1.7.5.1
Justin M. Forbes 5e10b1