Blame SOURCES/kvm-virtio-serial-report-frontend-connection-state-via-m.patch

958e1b
From b9295fa6535d7092f9234e63ed6b5670bd862d0c Mon Sep 17 00:00:00 2001
958e1b
From: Laszlo Ersek <lersek@redhat.com>
958e1b
Date: Tue, 22 Jul 2014 18:31:22 +0200
958e1b
Subject: [PATCH 02/11] virtio-serial: report frontend connection state via monitor
958e1b
958e1b
Message-id: <1406053883-21237-2-git-send-email-lersek@redhat.com>
958e1b
Patchwork-id: 60229
958e1b
O-Subject: [RHEL-7.1 qemu-kvm PATCH 1/2] virtio-serial: report frontend connection state via monitor
958e1b
Bugzilla: 1122151
958e1b
RH-Acked-by: Luiz Capitulino <lcapitulino@redhat.com>
958e1b
RH-Acked-by: Amit Shah <amit.shah@redhat.com>
958e1b
RH-Acked-by: Eric Blake <eblake@redhat.com>
958e1b
958e1b
Libvirt wants to know about the guest-side connection state of some
958e1b
virtio-serial ports (in particular the one(s) assigned to guest agent(s)).
958e1b
Report such states with a new monitor event.
958e1b
958e1b
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=1080376
958e1b
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
958e1b
Reviewed-by: Eric Blake <eblake@redhat.com>
958e1b
Reviewed-by: Amit Shah <amit.shah@redhat.com>
958e1b
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
958e1b
958e1b
RHEL-7 notes: manual reimplementation of upstream commit
958e1b
e2ae6159de2482ee5e22532301eb7f2795828d07, because we don't have Wenchao
958e1b
Xia's qapi-event series.
958e1b
958e1b
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
958e1b
---
958e1b
 include/monitor/monitor.h |  1 +
958e1b
 hw/char/virtio-console.c  | 17 ++++++++++++++---
958e1b
 monitor.c                 |  2 ++
958e1b
 QMP/qmp-events.txt        | 16 ++++++++++++++++
958e1b
 4 files changed, 33 insertions(+), 3 deletions(-)
958e1b
958e1b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
958e1b
---
958e1b
 QMP/qmp-events.txt        |   16 ++++++++++++++++
958e1b
 hw/char/virtio-console.c  |   17 ++++++++++++++---
958e1b
 include/monitor/monitor.h |    1 +
958e1b
 monitor.c                 |    2 ++
958e1b
 4 files changed, 33 insertions(+), 3 deletions(-)
958e1b
958e1b
diff --git a/QMP/qmp-events.txt b/QMP/qmp-events.txt
958e1b
index fc4b7db..ec4e4b9 100644
958e1b
--- a/QMP/qmp-events.txt
958e1b
+++ b/QMP/qmp-events.txt
958e1b
@@ -485,6 +485,22 @@ Example:
958e1b
                     "host": "127.0.0.1", "sasl_username": "luiz" } },
958e1b
         "timestamp": { "seconds": 1263475302, "microseconds": 150772 } }
958e1b
 
958e1b
+VSERPORT_CHANGE
958e1b
+---------------
958e1b
+
958e1b
+Emitted when the guest opens or closes a virtio-serial port.
958e1b
+
958e1b
+Data:
958e1b
+
958e1b
+- "id": device identifier of the virtio-serial port (json-string)
958e1b
+- "open": true if the guest has opened the virtio-serial port (json-bool)
958e1b
+
958e1b
+Example:
958e1b
+
958e1b
+{ "event": "VSERPORT_CHANGE",
958e1b
+    "data": { "id": "channel0",  "open": true },
958e1b
+    "timestamp": { "seconds": 1401385907, "microseconds": 422329 } }
958e1b
+
958e1b
 WAKEUP
958e1b
 ------
958e1b
 
958e1b
diff --git a/hw/char/virtio-console.c b/hw/char/virtio-console.c
958e1b
index 2e00ad2..1b01dcd 100644
958e1b
--- a/hw/char/virtio-console.c
958e1b
+++ b/hw/char/virtio-console.c
958e1b
@@ -14,6 +14,8 @@
958e1b
 #include "qemu/error-report.h"
958e1b
 #include "trace.h"
958e1b
 #include "hw/virtio/virtio-serial.h"
958e1b
+#include "monitor/monitor.h"
958e1b
+#include "qapi/qmp/qjson.h"
958e1b
 
958e1b
 typedef struct VirtConsole {
958e1b
     VirtIOSerialPort port;
958e1b
@@ -76,11 +78,20 @@ static ssize_t flush_buf(VirtIOSerialPort *port,
958e1b
 static void set_guest_connected(VirtIOSerialPort *port, int guest_connected)
958e1b
 {
958e1b
     VirtConsole *vcon = DO_UPCAST(VirtConsole, port, port);
958e1b
+    DeviceState *dev = DEVICE(port);
958e1b
 
958e1b
-    if (!vcon->chr) {
958e1b
-        return;
958e1b
+    if (vcon->chr) {
958e1b
+        qemu_chr_fe_set_open(vcon->chr, guest_connected);
958e1b
     }
958e1b
-    qemu_chr_fe_set_open(vcon->chr, guest_connected);
958e1b
+
958e1b
+    if (dev->id) {
958e1b
+        QObject *data;
958e1b
+
958e1b
+        data = qobject_from_jsonf("{ 'id': %s, 'open': %i }",
958e1b
+                                  dev->id, guest_connected);
958e1b
+        monitor_protocol_event(QEVENT_VSERPORT_CHANGE, data);
958e1b
+        qobject_decref(data);
958e1b
+     }
958e1b
 }
958e1b
 
958e1b
 /* Readiness of the guest to accept data on a port */
958e1b
diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
958e1b
index dcce609..6c128e9 100644
958e1b
--- a/include/monitor/monitor.h
958e1b
+++ b/include/monitor/monitor.h
958e1b
@@ -52,6 +52,7 @@ typedef enum MonitorEvent {
958e1b
     QEVENT_SPICE_MIGRATE_COMPLETED,
958e1b
     QEVENT_GUEST_PANICKED,
958e1b
     QEVENT_BLOCK_IMAGE_CORRUPTED,
958e1b
+    QEVENT_VSERPORT_CHANGE,
958e1b
 
958e1b
     /* Add to 'monitor_event_names' array in monitor.c when
958e1b
      * defining new events here */
958e1b
diff --git a/monitor.c b/monitor.c
958e1b
index a6abfb5..798885d 100644
958e1b
--- a/monitor.c
958e1b
+++ b/monitor.c
958e1b
@@ -506,6 +506,7 @@ static const char *monitor_event_names[] = {
958e1b
     [QEVENT_SPICE_MIGRATE_COMPLETED] = "SPICE_MIGRATE_COMPLETED",
958e1b
     [QEVENT_GUEST_PANICKED] = "GUEST_PANICKED",
958e1b
     [QEVENT_BLOCK_IMAGE_CORRUPTED] = "BLOCK_IMAGE_CORRUPTED",
958e1b
+    [QEVENT_VSERPORT_CHANGE] = "VSERPORT_CHANGE",
958e1b
 };
958e1b
 QEMU_BUILD_BUG_ON(ARRAY_SIZE(monitor_event_names) != QEVENT_MAX)
958e1b
 
958e1b
@@ -642,6 +643,7 @@ static void monitor_protocol_event_init(void)
958e1b
     monitor_protocol_event_throttle(QEVENT_RTC_CHANGE, 1000);
958e1b
     monitor_protocol_event_throttle(QEVENT_BALLOON_CHANGE, 1000);
958e1b
     monitor_protocol_event_throttle(QEVENT_WATCHDOG, 1000);
958e1b
+    monitor_protocol_event_throttle(QEVENT_VSERPORT_CHANGE, 1000);
958e1b
 }
958e1b
 
958e1b
 /**
958e1b
-- 
958e1b
1.7.1
958e1b