From patchwork Thu Jan 15 18:05:31 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 2510 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n0FI1RX9008148 for ; Thu, 15 Jan 2009 10:01:27 -0800 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756814AbZAOSFg (ORCPT ); Thu, 15 Jan 2009 13:05:36 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1757117AbZAOSFg (ORCPT ); Thu, 15 Jan 2009 13:05:36 -0500 Received: from g4t0015.houston.hp.com ([15.201.24.18]:43554 "EHLO g4t0015.houston.hp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754450AbZAOSFf (ORCPT ); Thu, 15 Jan 2009 13:05:35 -0500 Received: from g4t0009.houston.hp.com (g4t0009.houston.hp.com [16.234.32.26]) by g4t0015.houston.hp.com (Postfix) with ESMTP id EE7108008; Thu, 15 Jan 2009 18:05:34 +0000 (UTC) Received: from ldl.fc.hp.com (ldl.fc.hp.com [15.11.146.30]) by g4t0009.houston.hp.com (Postfix) with ESMTP id C6459C0A3; Thu, 15 Jan 2009 18:05:34 +0000 (UTC) Received: from localhost (ldl.fc.hp.com [127.0.0.1]) by ldl.fc.hp.com (Postfix) with ESMTP id 77B4B39C00B; Thu, 15 Jan 2009 11:05:34 -0700 (MST) X-Virus-Scanned: Debian amavisd-new at ldl.fc.hp.com Received: from ldl.fc.hp.com ([127.0.0.1]) by localhost (ldl.fc.hp.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id vvK5C0klsHOq; Thu, 15 Jan 2009 11:05:33 -0700 (MST) Received: from [192.168.1.60] (squirrel.fc.hp.com [15.11.146.57]) by ldl.fc.hp.com (Postfix) with ESMTP id 9BAC139C009; Thu, 15 Jan 2009 11:05:32 -0700 (MST) Subject: [PATCH] virtio-net: Fix save/load From: Alex Williamson To: Avi Kivity Cc: kvm-devel Organization: HP OSLO R&D Date: Thu, 15 Jan 2009 11:05:31 -0700 Message-Id: <1232042731.20605.9.camel@bling> Mime-Version: 1.0 X-Mailer: Evolution 2.24.2 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org We can't rely on build switches to tell us if a save image includes a given field. We also need to save status since it's visible to the guest. Draw another line in the sand for broken save versions. The version number should always be updated when new values are saved and load should make an attempt to set reasonable defaults for lower version save images. Signed-off-by: Alex Williamson --- qemu/hw/virtio-net.c | 19 +++++++++++++++++-- 1 files changed, 17 insertions(+), 2 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/qemu/hw/virtio-net.c b/qemu/hw/virtio-net.c index 358c382..6ce2ff5 100644 --- a/qemu/hw/virtio-net.c +++ b/qemu/hw/virtio-net.c @@ -21,6 +21,8 @@ #define TAP_VNET_HDR +#define VIRTIO_NET_VM_VERSION 3 + typedef struct VirtIONet { VirtIODevice vdev; @@ -368,6 +370,11 @@ static void virtio_net_tx_timer(void *opaque) virtio_net_flush_tx(n, n->tx_vq); } +/* + * Anything added here should cause a bump in VIRTIO_NET_VM_VERSION + * and appropriate conditionalized load with sane defaults for older + * images should be added to virtio_net_load(). + */ static void virtio_net_save(QEMUFile *f, void *opaque) { VirtIONet *n = opaque; @@ -380,14 +387,18 @@ static void virtio_net_save(QEMUFile *f, void *opaque) #ifdef TAP_VNET_HDR qemu_put_be32(f, tap_has_vnet_hdr(n->vc->vlan->first_client)); +#else + qemu_put_be32(f, 0); #endif + + qemu_put_be16(f, n->status); } static int virtio_net_load(QEMUFile *f, void *opaque, int version_id) { VirtIONet *n = opaque; - if (version_id != 2) + if (version_id < 3 || version_id > VIRTIO_NET_VM_VERSION) return -EINVAL; virtio_load(&n->vdev, f); @@ -399,8 +410,12 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id) #ifdef TAP_VNET_HDR if (qemu_get_be32(f)) tap_using_vnet_hdr(n->vc->vlan->first_client, 1); +#else + qemu_get_be32(f); #endif + n->status = qemu_get_be16(f); + if (n->tx_timer_active) { qemu_mod_timer(n->tx_timer, qemu_get_clock(vm_clock) + TX_TIMER_INTERVAL); @@ -439,7 +454,7 @@ PCIDevice *virtio_net_init(PCIBus *bus, NICInfo *nd, int devfn) n->tx_timer_active = 0; n->mergeable_rx_bufs = 0; - register_savevm("virtio-net", virtio_net_id++, 2, + register_savevm("virtio-net", virtio_net_id++, VIRTIO_NET_VM_VERSION, virtio_net_save, virtio_net_load, n); return (PCIDevice *)n;