From patchwork Thu Dec 13 10:37:55 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Shah X-Patchwork-Id: 205807 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 AFD792C0098 for ; Thu, 13 Dec 2012 22:23:49 +1100 (EST) Received: from localhost ([::1]:50181 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tj6C0-0002J8-4U for incoming@patchwork.ozlabs.org; Thu, 13 Dec 2012 05:39:04 -0500 Received: from eggs.gnu.org ([208.118.235.92]:57284) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tj6Bc-0001Re-Dm for qemu-devel@nongnu.org; Thu, 13 Dec 2012 05:38:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tj6Ba-0001S2-HV for qemu-devel@nongnu.org; Thu, 13 Dec 2012 05:38:40 -0500 Received: from mx1.redhat.com ([209.132.183.28]:26352) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tj6Ba-0001Rw-8X for qemu-devel@nongnu.org; Thu, 13 Dec 2012 05:38:38 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qBDAcbVS019951 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 13 Dec 2012 05:38:37 -0500 Received: from localhost (ovpn-113-39.phx2.redhat.com [10.3.113.39]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id qBDAcW7A019717; Thu, 13 Dec 2012 05:38:35 -0500 From: Amit Shah To: Alon Levy Date: Thu, 13 Dec 2012 16:07:55 +0530 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Amit Shah , qemu list Subject: [Qemu-devel] [PATCH 3/4] virtio-serial: allocate post_load only at load-time 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 This saves us a few bytes in the VirtIOSerial struct. Not a big savings, but since the entire structure is used only during a short while after migration, it's helpful to keep the struct cleaner and smaller. Signed-off-by: Amit Shah --- hw/virtio-serial-bus.c | 63 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 25 deletions(-) diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c index 2e0fe3d..09d4659 100644 --- a/hw/virtio-serial-bus.c +++ b/hw/virtio-serial-bus.c @@ -36,6 +36,15 @@ struct VirtIOSerialBus { uint32_t max_nr_ports; }; +typedef struct VirtIOSerialPostLoad { + QEMUTimer *timer; + uint32_t nr_active_ports; + struct { + VirtIOSerialPort *port; + uint8_t host_connected; + } *connected; +} VirtIOSerialPostLoad; + struct VirtIOSerial { VirtIODevice vdev; @@ -54,14 +63,7 @@ struct VirtIOSerial { struct virtio_console_config config; - struct { - QEMUTimer *timer; - uint32_t nr_active_ports; - struct { - VirtIOSerialPort *port; - uint8_t host_connected; - } *connected; - } post_load; + struct VirtIOSerialPostLoad *post_load; }; static VirtIOSerialPort *find_port_by_id(VirtIOSerial *vser, uint32_t id) @@ -642,9 +644,12 @@ static void virtio_serial_post_load_timer_cb(void *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 (!s->post_load) { + return; + } + 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 @@ -654,8 +659,10 @@ static void virtio_serial_post_load_timer_cb(void *opaque) port->host_connected); } } - g_free(s->post_load.connected); - s->post_load.connected = NULL; + g_free(s->post_load->connected); + qemu_free_timer(s->post_load->timer); + g_free(s->post_load); + s->post_load = NULL; } static int fetch_active_ports_list(QEMUFile *f, int version_id, @@ -663,9 +670,14 @@ static int fetch_active_ports_list(QEMUFile *f, int version_id, { uint32_t i; - s->post_load.nr_active_ports = nr_active_ports; - s->post_load.connected = - g_malloc0(sizeof(*s->post_load.connected) * nr_active_ports); + s->post_load = g_malloc0(sizeof(*s->post_load)); + s->post_load->nr_active_ports = nr_active_ports; + s->post_load->connected = + g_malloc0(sizeof(*s->post_load->connected) * nr_active_ports); + + s->post_load->timer = qemu_new_timer_ns(vm_clock, + virtio_serial_post_load_timer_cb, + s); /* Items in struct VirtIOSerialPort */ for (i = 0; i < nr_active_ports; i++) { @@ -679,8 +691,8 @@ static int fetch_active_ports_list(QEMUFile *f, int version_id, } port->guest_connected = qemu_get_byte(f); - s->post_load.connected[i].port = port; - s->post_load.connected[i].host_connected = qemu_get_byte(f); + 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; @@ -705,7 +717,7 @@ static int fetch_active_ports_list(QEMUFile *f, int version_id, } } } - qemu_mod_timer(s->post_load.timer, 1); + qemu_mod_timer(s->post_load->timer, 1); return 0; } @@ -1003,6 +1015,8 @@ VirtIODevice *virtio_serial_init(DeviceState *dev, virtio_serial_conf *conf) vser->qdev = dev; + vser->post_load = NULL; + /* * Register for the savevm section with the virtio-console name * to preserve backward compat @@ -1010,9 +1024,6 @@ 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; } @@ -1025,9 +1036,11 @@ 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); - + if (vser->post_load) { + g_free(vser->post_load->connected); + qemu_free_timer(vser->post_load->timer); + g_free(vser->post_load); + } virtio_cleanup(vdev); }