qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 1/2] virtio-serial: report frontend connection state


From: Laszlo Ersek
Subject: [Qemu-devel] [PATCH 1/2] virtio-serial: report frontend connection state via monitor
Date: Thu, 29 May 2014 21:36:40 +0200

Libvirt wants to know about the guest-side connection state of some
virtio-serial ports (in particular the one(s) assigned to guest agent(s)).
Introduce a new property that allows libvirt to request connection state
reporting, and report the state via new monitor events.

RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=1080376
Signed-off-by: Laszlo Ersek <address@hidden>
---
 include/monitor/monitor.h |  2 ++
 hw/char/virtio-console.c  | 20 +++++++++++++++++---
 monitor.c                 |  2 ++
 docs/qmp/qmp-events.txt   | 34 ++++++++++++++++++++++++++++++++++
 4 files changed, 55 insertions(+), 3 deletions(-)

diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
index 1c1f56f..4fcb5b4 100644
--- a/include/monitor/monitor.h
+++ b/include/monitor/monitor.h
@@ -51,6 +51,8 @@ typedef enum MonitorEvent {
     QEVENT_BLOCK_IMAGE_CORRUPTED,
     QEVENT_QUORUM_FAILURE,
     QEVENT_QUORUM_REPORT_BAD,
+    QEVENT_VSERPORT_CONNECTED,
+    QEVENT_VSERPORT_DISCONNECTED,
 
     /* Add to 'monitor_event_names' array in monitor.c when
      * defining new events here */
diff --git a/hw/char/virtio-console.c b/hw/char/virtio-console.c
index 6c8be0f..acca3d9 100644
--- a/hw/char/virtio-console.c
+++ b/hw/char/virtio-console.c
@@ -14,6 +14,8 @@
 #include "qemu/error-report.h"
 #include "trace.h"
 #include "hw/virtio/virtio-serial.h"
+#include "monitor/monitor.h"
+#include "qapi/qmp/qjson.h"
 
 #define TYPE_VIRTIO_CONSOLE_SERIAL_PORT "virtserialport"
 #define VIRTIO_CONSOLE(obj) \
@@ -24,6 +26,7 @@ typedef struct VirtConsole {
 
     CharDriverState *chr;
     guint watch;
+    bool report_connstate;
 } VirtConsole;
 
 /*
@@ -81,11 +84,21 @@ static ssize_t flush_buf(VirtIOSerialPort *port,
 static void set_guest_connected(VirtIOSerialPort *port, int guest_connected)
 {
     VirtConsole *vcon = VIRTIO_CONSOLE(port);
+    DeviceState *dev = DEVICE(port);
 
-    if (!vcon->chr) {
-        return;
+    if (vcon->chr) {
+        qemu_chr_fe_set_open(vcon->chr, guest_connected);
+    }
+
+    if (vcon->report_connstate && dev->id) {
+        QObject *data;
+
+        data = qobject_from_jsonf("{ 'id': %s }", dev->id);
+        monitor_protocol_event(guest_connected ? QEVENT_VSERPORT_CONNECTED :
+                                                 QEVENT_VSERPORT_DISCONNECTED,
+                               data);
+        qobject_decref(data);
     }
-    qemu_chr_fe_set_open(vcon->chr, guest_connected);
 }
 
 /* Readiness of the guest to accept data on a port */
@@ -169,6 +182,7 @@ static const TypeInfo virtconsole_info = {
 
 static Property virtserialport_properties[] = {
     DEFINE_PROP_CHR("chardev", VirtConsole, chr),
+    DEFINE_PROP_BOOL("report_connstate", VirtConsole, report_connstate, false),
     DEFINE_PROP_END_OF_LIST(),
 };
 
diff --git a/monitor.c b/monitor.c
index 593679a..be83399 100644
--- a/monitor.c
+++ b/monitor.c
@@ -485,6 +485,8 @@ static const char *monitor_event_names[] = {
     [QEVENT_BLOCK_IMAGE_CORRUPTED] = "BLOCK_IMAGE_CORRUPTED",
     [QEVENT_QUORUM_FAILURE] = "QUORUM_FAILURE",
     [QEVENT_QUORUM_REPORT_BAD] = "QUORUM_REPORT_BAD",
+    [QEVENT_VSERPORT_CONNECTED] = "VSERPORT_CONNECTED",
+    [QEVENT_VSERPORT_DISCONNECTED] = "VSERPORT_DISCONNECTED",
 };
 QEMU_BUILD_BUG_ON(ARRAY_SIZE(monitor_event_names) != QEVENT_MAX)
 
diff --git a/docs/qmp/qmp-events.txt b/docs/qmp/qmp-events.txt
index 145402e..9a17716 100644
--- a/docs/qmp/qmp-events.txt
+++ b/docs/qmp/qmp-events.txt
@@ -509,6 +509,40 @@ Example:
                     "host": "127.0.0.1", "sasl_username": "luiz" } },
         "timestamp": { "seconds": 1263475302, "microseconds": 150772 } }
 
+VSERPORT_CONNECTED
+------------------
+
+Emitted when the guest opens a virtio-serial port for which connection state
+reporting has been requested with the "virtserialport.report_connstate"
+property.
+
+Data:
+
+- "id": device identifier of the virtio-serial port (json-string)
+
+Example:
+
+{ "event": "VSERPORT_CONNECTED",
+    "data": { "id": "channel0" },
+    "timestamp": { "seconds": 1401385853, "microseconds": 601928 } }
+
+VSERPORT_DISCONNECTED
+---------------------
+
+Emitted when the guest closes a virtio-serial port for which connection state
+reporting has been requested with the "virtserialport.report_connstate"
+property.
+
+Data:
+
+- "id": device identifier of the virtio-serial port (json-string)
+
+Example:
+
+{ "event": "VSERPORT_DISCONNECTED",
+    "data": { "id": "channel0" },
+    "timestamp": { "seconds": 1401385907, "microseconds": 422329 } }
+
 WAKEUP
 ------
 
-- 
1.8.3.1





reply via email to

[Prev in Thread] Current Thread [Next in Thread]