[libvirt] [PATCH 0/2] qemu: Properly report port numbers in spice events

Peter Krempa (2): qemu: event: Properly handle spice events qemu: event: Clean up VNC monitor handling src/qemu/qemu_monitor_json.c | 110 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 87 insertions(+), 23 deletions(-) -- 2.4.1

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. --- 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 d3e98d4..ba1e4f9 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -617,7 +617,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; @@ -690,37 +693,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 = virJSONValueObjectGetObject(data, "client")) || + !(server = virJSONValueObjectGetObject(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 graphics event"); + auth = ""; + } + + if (!(lfamily = virJSONValueObjectGetString(server, "family"))) { + VIR_WARN("missing local address family in graphics event"); + return; + } + if (!(lhost = virJSONValueObjectGetString(server, "host"))) { + VIR_WARN("missing local hostname in graphics event"); + return; + } + if (!(lport = virJSONValueObjectGetString(server, "port"))) { + VIR_WARN("missing local port in graphics event"); + return; + } + + if (!(rfamily = virJSONValueObjectGetString(client, "family"))) { + VIR_WARN("missing remote address family in graphics event"); + return; + } + if (!(rhost = virJSONValueObjectGetString(client, "host"))) { + VIR_WARN("missing remote hostname in graphics event"); + return; + } + if (!(rport = virJSONValueObjectGetString(client, "port"))) { + VIR_WARN("missing remote service in graphics 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.4.1

On Mon, Jun 29, 2015 at 17:13:58 +0200, Peter Krempa wrote:
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. --- 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 d3e98d4..ba1e4f9 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c ... +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 = virJSONValueObjectGetObject(data, "client")) || + !(server = virJSONValueObjectGetObject(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 graphics event"); + auth = ""; + } + + if (!(lfamily = virJSONValueObjectGetString(server, "family"))) { + VIR_WARN("missing local address family in graphics event"); + return; + } + if (!(lhost = virJSONValueObjectGetString(server, "host"))) { + VIR_WARN("missing local hostname in graphics event"); + return; + } + if (!(lport = virJSONValueObjectGetString(server, "port"))) { + VIR_WARN("missing local port in graphics event"); + return; + } + + if (!(rfamily = virJSONValueObjectGetString(client, "family"))) { + VIR_WARN("missing remote address family in graphics event"); + return; + } + if (!(rhost = virJSONValueObjectGetString(client, "host"))) { + VIR_WARN("missing remote hostname in graphics event"); + return; + } + if (!(rport = virJSONValueObjectGetString(client, "port"))) { + VIR_WARN("missing remote service in graphics 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); }
I think it would make sense to s/graphics event/SPICE event/ ACK Jirka

Get rid of spice specific stuff from the handler func and save a few lines by reflowing the conditions. --- src/qemu/qemu_monitor_json.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index ba1e4f9..e9af1e1 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -638,40 +638,37 @@ qemuMonitorJSONHandleGraphicsVNC(qemuMonitorPtr mon, return; } - authScheme = virJSONValueObjectGetString(server, "auth"); - if (!authScheme) { + if (!(authScheme = virJSONValueObjectGetString(server, "auth"))) { /* not all events are required to contain auth scheme */ VIR_DEBUG("missing auth scheme in graphics event"); authScheme = ""; } - localFamily = virJSONValueObjectGetString(server, "family"); - if (!localFamily) { + if (!(localFamily = virJSONValueObjectGetString(server, "family"))) { VIR_WARN("missing local address family in graphics event"); return; } - localNode = virJSONValueObjectGetString(server, "host"); - if (!localNode) { + if (!(localNode = virJSONValueObjectGetString(server, "host"))) { VIR_WARN("missing local hostname in graphics event"); return; } - localService = virJSONValueObjectGetString(server, "service"); - if (!localService) - localService = ""; /* Spice has multiple ports, so this isn't provided */ + if (!(localService = virJSONValueObjectGetString(server, "service"))) { + VIR_WARN("missing local service in graphics event"); + return; + } - remoteFamily = virJSONValueObjectGetString(client, "family"); - if (!remoteFamily) { + if (!(remoteFamily = virJSONValueObjectGetString(client, "family"))) { VIR_WARN("missing remote address family in graphics event"); return; } - remoteNode = virJSONValueObjectGetString(client, "host"); - if (!remoteNode) { + if (!(remoteNode = virJSONValueObjectGetString(client, "host"))) { VIR_WARN("missing remote hostname in graphics event"); return; } - remoteService = virJSONValueObjectGetString(client, "service"); - if (!remoteService) - remoteService = ""; /* Spice has multiple ports, so this isn't provided */ + if (!(remoteService = virJSONValueObjectGetString(client, "service"))) { + VIR_WARN("missing remote service in graphics event"); + return; + } saslUsername = virJSONValueObjectGetString(client, "sasl_username"); x509dname = virJSONValueObjectGetString(client, "x509_dname"); -- 2.4.1

On Mon, Jun 29, 2015 at 17:13:59 +0200, Peter Krempa wrote:
Get rid of spice specific stuff from the handler func and save a few lines by reflowing the conditions. --- src/qemu/qemu_monitor_json.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-)
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index ba1e4f9..e9af1e1 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -638,40 +638,37 @@ qemuMonitorJSONHandleGraphicsVNC(qemuMonitorPtr mon, return; }
- authScheme = virJSONValueObjectGetString(server, "auth"); - if (!authScheme) { + if (!(authScheme = virJSONValueObjectGetString(server, "auth"))) { /* not all events are required to contain auth scheme */ VIR_DEBUG("missing auth scheme in graphics event"); authScheme = ""; }
- localFamily = virJSONValueObjectGetString(server, "family"); - if (!localFamily) { + if (!(localFamily = virJSONValueObjectGetString(server, "family"))) { VIR_WARN("missing local address family in graphics event"); return; } - localNode = virJSONValueObjectGetString(server, "host"); - if (!localNode) { + if (!(localNode = virJSONValueObjectGetString(server, "host"))) { VIR_WARN("missing local hostname in graphics event"); return; } - localService = virJSONValueObjectGetString(server, "service"); - if (!localService) - localService = ""; /* Spice has multiple ports, so this isn't provided */ + if (!(localService = virJSONValueObjectGetString(server, "service"))) { + VIR_WARN("missing local service in graphics event"); + return; + }
- remoteFamily = virJSONValueObjectGetString(client, "family"); - if (!remoteFamily) { + if (!(remoteFamily = virJSONValueObjectGetString(client, "family"))) { VIR_WARN("missing remote address family in graphics event"); return; } - remoteNode = virJSONValueObjectGetString(client, "host"); - if (!remoteNode) { + if (!(remoteNode = virJSONValueObjectGetString(client, "host"))) { VIR_WARN("missing remote hostname in graphics event"); return; } - remoteService = virJSONValueObjectGetString(client, "service"); - if (!remoteService) - remoteService = ""; /* Spice has multiple ports, so this isn't provided */ + if (!(remoteService = virJSONValueObjectGetString(client, "service"))) { + VIR_WARN("missing remote service in graphics event"); + return; + }
saslUsername = virJSONValueObjectGetString(client, "sasl_username"); x509dname = virJSONValueObjectGetString(client, "x509_dname");
It might be worth doing s/graphics event/VNC event/ ACK Jirka

On Tue, Jun 30, 2015 at 11:08:34 +0200, Jiri Denemark wrote:
On Mon, Jun 29, 2015 at 17:13:59 +0200, Peter Krempa wrote:
Get rid of spice specific stuff from the handler func and save a few lines by reflowing the conditions. --- src/qemu/qemu_monitor_json.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-)
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index ba1e4f9..e9af1e1 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c
...
It might be worth doing s/graphics event/VNC event/
I've ran your regexes on the appropriate functions and added a bugzilla reference to the first patch and pushed this series. Thanks. Peter
participants (2)
-
Jiri Denemark
-
Peter Krempa