From patchwork Wed Nov 14 13:09:07 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alon Levy X-Patchwork-Id: 198902 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B67342C00AE for ; Thu, 15 Nov 2012 00:09:28 +1100 (EST) Received: from localhost ([::1]:48920 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TYcia-0000JO-Os for incoming@patchwork.ozlabs.org; Wed, 14 Nov 2012 08:09:24 -0500 Received: from eggs.gnu.org ([208.118.235.92]:41823) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TYciR-0000J8-3m for qemu-devel@nongnu.org; Wed, 14 Nov 2012 08:09:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TYciO-0001Z3-26 for qemu-devel@nongnu.org; Wed, 14 Nov 2012 08:09:15 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41455) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TYciN-0001Yw-QW for qemu-devel@nongnu.org; Wed, 14 Nov 2012 08:09:11 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qAED9AKI023711 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 14 Nov 2012 08:09:10 -0500 Received: from garlic.redhat.com (vpn-11-242.rdu.redhat.com [10.11.11.242]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id qAED98Ql024342; Wed, 14 Nov 2012 08:09:08 -0500 From: Alon Levy To: qemu-devel@nongnu.org Date: Wed, 14 Nov 2012 15:09:07 +0200 Message-Id: <1352898547-22694-1-git-send-email-alevy@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: amit.shah@redhat.com, pbonzini@redhat.com, alexl@redhat.com Subject: [Qemu-devel] [PATCH] hw/virtio-serial-bus: post_load send_event when vm is running 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 Add a new timer based on vm_clock for 1 ns in the future from post_load to do the event send in case host_connected differs between migration source and target. RHBZ: 867366 Signed-off-by: Alon Levy Acked-by: Paolo Bonzini --- hw/virtio-serial-bus.c | 54 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 10 deletions(-) diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c index d20bd8b..efa8a81 100644 --- a/hw/virtio-serial-bus.c +++ b/hw/virtio-serial-bus.c @@ -53,6 +53,15 @@ struct VirtIOSerial { uint32_t *ports_map; struct virtio_console_config config; + + struct { + QEMUTimer *timer; + int nr_active_ports; + struct { + VirtIOSerialPort *port; + uint8_t host_connected; + } *connected; + } post_load; }; static VirtIOSerialPort *find_port_by_id(VirtIOSerial *vser, uint32_t id) @@ -626,6 +635,29 @@ static void virtio_serial_save(QEMUFile *f, void *opaque) } } +static void virtio_serial_post_load_timer_cb(void *opaque) +{ + int i; + VirtIOSerial *s = opaque; + VirtIOSerialPort *port; + uint8_t host_connected; + + for (i = 0 ; i < s->post_load.nr_active_ports; ++i) { + port = s->post_load.connected[i].port; + host_connected = s->post_load.connected[i].host_connected; + if (host_connected != port->host_connected) { + /* + * We have to let the guest know of the host connection + * status change + */ + send_control_event(port, VIRTIO_CONSOLE_PORT_OPEN, + port->host_connected); + } + } + g_free(s->post_load.connected); + s->post_load.connected = NULL; +} + static int virtio_serial_load(QEMUFile *f, void *opaque, int version_id) { VirtIOSerial *s = opaque; @@ -673,10 +705,13 @@ static int virtio_serial_load(QEMUFile *f, void *opaque, int version_id) qemu_get_be32s(f, &nr_active_ports); + s->post_load.nr_active_ports = nr_active_ports; + s->post_load.connected = + g_malloc0(sizeof(*s->post_load.connected) * nr_active_ports); + /* Items in struct VirtIOSerialPort */ for (i = 0; i < nr_active_ports; i++) { uint32_t id; - bool host_connected; id = qemu_get_be32(f); port = find_port_by_id(s, id); @@ -685,15 +720,8 @@ static int virtio_serial_load(QEMUFile *f, void *opaque, int version_id) } port->guest_connected = qemu_get_byte(f); - host_connected = qemu_get_byte(f); - if (host_connected != port->host_connected) { - /* - * We have to let the guest know of the host connection - * status change - */ - send_control_event(port, VIRTIO_CONSOLE_PORT_OPEN, - port->host_connected); - } + s->post_load.connected[i].port = port; + s->post_load.connected[i].host_connected = qemu_get_byte(f); if (version_id > 2) { uint32_t elem_popped; @@ -718,6 +746,7 @@ static int virtio_serial_load(QEMUFile *f, void *opaque, int version_id) } } } + qemu_mod_timer(s->post_load.timer, 1); return 0; } @@ -967,6 +996,9 @@ VirtIODevice *virtio_serial_init(DeviceState *dev, virtio_serial_conf *conf) register_savevm(dev, "virtio-console", -1, 3, virtio_serial_save, virtio_serial_load, vser); + vser->post_load.timer = qemu_new_timer_ns(vm_clock, + virtio_serial_post_load_timer_cb, vser); + return vdev; } @@ -979,6 +1011,8 @@ void virtio_serial_exit(VirtIODevice *vdev) g_free(vser->ivqs); g_free(vser->ovqs); g_free(vser->ports_map); + g_free(vser->post_load.connected); + qemu_free_timer(vser->post_load.timer); virtio_cleanup(vdev); }