From patchwork Thu May 29 19:36:40 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laszlo Ersek X-Patchwork-Id: 353829 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id AD378140094 for ; Fri, 30 May 2014 05:37:32 +1000 (EST) Received: from localhost ([::1]:49903 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wq68o-0002TM-CG for incoming@patchwork.ozlabs.org; Thu, 29 May 2014 15:37:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32879) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wq68I-0001Sw-GN for qemu-devel@nongnu.org; Thu, 29 May 2014 15:37:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wq687-0006Ek-T4 for qemu-devel@nongnu.org; Thu, 29 May 2014 15:36:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32912) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wq687-0006ER-KT for qemu-devel@nongnu.org; Thu, 29 May 2014 15:36:47 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s4TJakGv005012 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 29 May 2014 15:36:47 -0400 Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-31.ams2.redhat.com [10.36.116.31]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s4TJahF2023275; Thu, 29 May 2014 15:36:45 -0400 From: Laszlo Ersek To: qemu-devel@nongnu.org, mprivozn@redhat.com, kraxel@redhat.com, amit.shah@redhat.com Date: Thu, 29 May 2014 21:36:40 +0200 Message-Id: <1401392201-29988-2-git-send-email-lersek@redhat.com> In-Reply-To: <1401392201-29988-1-git-send-email-lersek@redhat.com> References: <1401392201-29988-1-git-send-email-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 1/2] virtio-serial: report frontend connection state via monitor X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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 ------