Patchwork [32/41] virtio-net: split virtio_net_post_load

login
register
mail settings
Submitter Juan Quintela
Date Dec. 2, 2009, 12:04 p.m.
Message ID <a31b2270f84ce3c5dad39e25fae770c0158e1c4c.1259754427.git.quintela@redhat.com>
Download mbox | patch
Permalink /patch/40038/
State New
Headers show

Comments

Juan Quintela - Dec. 2, 2009, 12:04 p.m.
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 hw/virtio-net.c |   79 ++++++++++++++++++++++++++++++++-----------------------
 1 files changed, 46 insertions(+), 33 deletions(-)

Patch

diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index 550a814..4434827 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -703,6 +703,51 @@  static void virtio_net_tx_timer(void *opaque)
     virtio_net_flush_tx(n, n->tx_vq);
 }

+static int virtio_net_post_load(void *opaque, int version_id)
+{
+    VirtIONet *n = opaque;
+    int i;
+
+    if (version_id >= 7) {
+        if (n->has_vnet_hdr && !peer_has_vnet_hdr(n)) {
+            qemu_error("virtio-net: saved image requires vnet_hdr=on\n");
+            return -1;
+        }
+
+        if (n->has_vnet_hdr) {
+            tap_using_vnet_hdr(n->vc->peer, 1);
+            tap_set_offload(n->vc->peer,
+                            (n->vdev.features >> VIRTIO_NET_F_GUEST_CSUM) & 1,
+                            (n->vdev.features >> VIRTIO_NET_F_GUEST_TSO4) & 1,
+                            (n->vdev.features >> VIRTIO_NET_F_GUEST_TSO6) & 1,
+                            (n->vdev.features >> VIRTIO_NET_F_GUEST_ECN)  & 1,
+                            (n->vdev.features >> VIRTIO_NET_F_GUEST_UFO)  & 1);
+        }
+    }
+
+    if (version_id >= 11) {
+        if (n->has_ufo && !peer_has_ufo(n)) {
+            qemu_error("virtio-net: saved image requires TUN_F_UFO support\n");
+            return -1;
+        }
+    }
+
+    /* Find the first multicast entry in the saved MAC filter */
+    for (i = 0; i < n->mac_table.in_use; i++) {
+        if (n->mac_table.macs[i * ETH_ALEN] & 1) {
+            break;
+        }
+    }
+    n->mac_table.first_multi = i;
+
+    if (n->tx_timer_active) {
+        qemu_mod_timer(n->tx_timer,
+                       qemu_get_clock(vm_clock) + TX_TIMER_INTERVAL);
+    }
+
+    return 0;
+}
+
 static void virtio_net_save(QEMUFile *f, void *opaque)
 {
     VirtIONet *n = opaque;
@@ -731,7 +776,6 @@  static void virtio_net_save(QEMUFile *f, void *opaque)
 static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
 {
     VirtIONet *n = opaque;
-    int i;

     if (version_id < 2 || version_id > VIRTIO_NET_VM_VERSION)
         return -EINVAL;
@@ -766,20 +810,6 @@  static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)

     if (version_id >= 7) {
         qemu_get_be32s(f, &n->has_vnet_hdr);
-        if (n->has_vnet_hdr && !peer_has_vnet_hdr(n)) {
-            qemu_error("virtio-net: saved image requires vnet_hdr=on\n");
-            return -1;
-        }
-
-        if (n->has_vnet_hdr) {
-            tap_using_vnet_hdr(n->vc->peer, 1);
-            tap_set_offload(n->vc->peer,
-                            (n->vdev.features >> VIRTIO_NET_F_GUEST_CSUM) & 1,
-                            (n->vdev.features >> VIRTIO_NET_F_GUEST_TSO4) & 1,
-                            (n->vdev.features >> VIRTIO_NET_F_GUEST_TSO6) & 1,
-                            (n->vdev.features >> VIRTIO_NET_F_GUEST_ECN)  & 1,
-                            (n->vdev.features >> VIRTIO_NET_F_GUEST_UFO)  & 1);
-        }
     }

     if (version_id >= 9) {
@@ -796,26 +826,9 @@  static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)

     if (version_id >= 11) {
         qemu_get_8s(f, &n->has_ufo);
-        if (n->has_ufo && !peer_has_ufo(n)) {
-            qemu_error("virtio-net: saved image requires TUN_F_UFO support\n");
-            return -1;
-        }
     }

-    /* Find the first multicast entry in the saved MAC filter */
-    for (i = 0; i < n->mac_table.in_use; i++) {
-        if (n->mac_table.macs[i * ETH_ALEN] & 1) {
-            break;
-        }
-    }
-    n->mac_table.first_multi = i;
-
-    if (n->tx_timer_active) {
-        qemu_mod_timer(n->tx_timer,
-                       qemu_get_clock(vm_clock) + TX_TIMER_INTERVAL);
-    }
-
-    return 0;
+    return virtio_net_post_load(n, version_id);
 }

 static void virtio_net_cleanup(VLANClientState *vc)