File libvirt-qemu-event-Properly-handle-spice-events.patch of Package libvirt
From cddde29321ee58476a41f202230c4e5a523ddc18 Mon Sep 17 00:00:00 2001
Message-Id: <cddde29321ee58476a41f202230c4e5a523ddc18@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Thu, 30 Jul 2015 10:47:19 +0200
Subject: [PATCH] qemu: event: Properly handle spice events
https://bugzilla.redhat.com/show_bug.cgi?id=1236581
Spice events have mostly similar information present in the event JSON
but they differ in the name of the element containing the port.
The JSON event also provides connection ID which might be useful in the
future.
This patch splits up the event parser code into two functions and the
SPICE reimplements the event parsing with correct names and drops the
VNC only stuff.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1236585
(cherry picked from commit 8df888a532db0994519bbe0d9900f622ef3e3922)
conflicts:
src/qemu/qemu_monitor_json.c: virJSONValueObjectGet was not
yet renamed to virJSONValueObjectGetObject
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
src/qemu/qemu_monitor_json.c | 81 ++++++++++++++++++++++++++++++++++++++++----
1 file changed, 74 insertions(+), 7 deletions(-)
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 23d9c9a..ee39c36 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -683,7 +683,10 @@ VIR_ENUM_IMPL(qemuMonitorGraphicsAddressFamily,
VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_LAST,
"ipv4", "ipv6", "unix");
-static void qemuMonitorJSONHandleGraphics(qemuMonitorPtr mon, virJSONValuePtr data, int phase)
+static void
+qemuMonitorJSONHandleGraphicsVNC(qemuMonitorPtr mon,
+ virJSONValuePtr data,
+ int phase)
{
const char *localNode, *localService, *localFamily;
const char *remoteNode, *remoteService, *remoteFamily;
@@ -756,37 +759,101 @@ static void qemuMonitorJSONHandleGraphics(qemuMonitorPtr mon, virJSONValuePtr da
static void qemuMonitorJSONHandleVNCConnect(qemuMonitorPtr mon, virJSONValuePtr data)
{
- qemuMonitorJSONHandleGraphics(mon, data, VIR_DOMAIN_EVENT_GRAPHICS_CONNECT);
+ qemuMonitorJSONHandleGraphicsVNC(mon, data, VIR_DOMAIN_EVENT_GRAPHICS_CONNECT);
}
static void qemuMonitorJSONHandleVNCInitialize(qemuMonitorPtr mon, virJSONValuePtr data)
{
- qemuMonitorJSONHandleGraphics(mon, data, VIR_DOMAIN_EVENT_GRAPHICS_INITIALIZE);
+ qemuMonitorJSONHandleGraphicsVNC(mon, data, VIR_DOMAIN_EVENT_GRAPHICS_INITIALIZE);
}
static void qemuMonitorJSONHandleVNCDisconnect(qemuMonitorPtr mon, virJSONValuePtr data)
{
- qemuMonitorJSONHandleGraphics(mon, data, VIR_DOMAIN_EVENT_GRAPHICS_DISCONNECT);
+ qemuMonitorJSONHandleGraphicsVNC(mon, data, VIR_DOMAIN_EVENT_GRAPHICS_DISCONNECT);
+}
+
+
+static void
+qemuMonitorJSONHandleGraphicsSPICE(qemuMonitorPtr mon,
+ virJSONValuePtr data,
+ int phase)
+{
+ const char *lhost, *lport, *lfamily;
+ const char *rhost, *rport, *rfamily;
+ const char *auth = "";
+ int lfamilyID, rfamilyID;
+ virJSONValuePtr client;
+ virJSONValuePtr server;
+
+ if (!(client = virJSONValueObjectGet(data, "client")) ||
+ !(server = virJSONValueObjectGet(data, "server"))) {
+ VIR_WARN("missing server or client info in SPICE event");
+ return;
+ }
+
+ if (phase == VIR_DOMAIN_EVENT_GRAPHICS_INITIALIZE &&
+ !(auth = virJSONValueObjectGetString(server, "auth"))) {
+ VIR_DEBUG("missing auth scheme in SPICE event");
+ auth = "";
+ }
+
+ if (!(lfamily = virJSONValueObjectGetString(server, "family"))) {
+ VIR_WARN("missing local address family in SPICE event");
+ return;
+ }
+ if (!(lhost = virJSONValueObjectGetString(server, "host"))) {
+ VIR_WARN("missing local hostname in SPICE event");
+ return;
+ }
+ if (!(lport = virJSONValueObjectGetString(server, "port"))) {
+ VIR_WARN("missing local port in SPICE event");
+ return;
+ }
+
+ if (!(rfamily = virJSONValueObjectGetString(client, "family"))) {
+ VIR_WARN("missing remote address family in SPICE event");
+ return;
+ }
+ if (!(rhost = virJSONValueObjectGetString(client, "host"))) {
+ VIR_WARN("missing remote hostname in SPICE event");
+ return;
+ }
+ if (!(rport = virJSONValueObjectGetString(client, "port"))) {
+ VIR_WARN("missing remote service in SPICE event");
+ return;
+ }
+
+ if ((lfamilyID = qemuMonitorGraphicsAddressFamilyTypeFromString(lfamily)) < 0) {
+ VIR_WARN("unknown address family '%s'", lfamily);
+ lfamilyID = VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV4;
+ }
+ if ((rfamilyID = qemuMonitorGraphicsAddressFamilyTypeFromString(rfamily)) < 0) {
+ VIR_WARN("unknown address family '%s'", rfamily);
+ rfamilyID = VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV4;
+ }
+
+ qemuMonitorEmitGraphics(mon, phase, lfamilyID, lhost, lport, rfamilyID,
+ rhost, rport, auth, NULL, NULL);
}
static void qemuMonitorJSONHandleSPICEConnect(qemuMonitorPtr mon, virJSONValuePtr data)
{
- qemuMonitorJSONHandleGraphics(mon, data, VIR_DOMAIN_EVENT_GRAPHICS_CONNECT);
+ qemuMonitorJSONHandleGraphicsSPICE(mon, data, VIR_DOMAIN_EVENT_GRAPHICS_CONNECT);
}
static void qemuMonitorJSONHandleSPICEInitialize(qemuMonitorPtr mon, virJSONValuePtr data)
{
- qemuMonitorJSONHandleGraphics(mon, data, VIR_DOMAIN_EVENT_GRAPHICS_INITIALIZE);
+ qemuMonitorJSONHandleGraphicsSPICE(mon, data, VIR_DOMAIN_EVENT_GRAPHICS_INITIALIZE);
}
static void qemuMonitorJSONHandleSPICEDisconnect(qemuMonitorPtr mon, virJSONValuePtr data)
{
- qemuMonitorJSONHandleGraphics(mon, data, VIR_DOMAIN_EVENT_GRAPHICS_DISCONNECT);
+ qemuMonitorJSONHandleGraphicsSPICE(mon, data, VIR_DOMAIN_EVENT_GRAPHICS_DISCONNECT);
}
static void
--
2.6.2