qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Vasilis Liaskovitis <vasilis.liaskovitis@profitbricks.com>
To: qemu-devel@nongnu.org
Cc: aliguori@us.ibm.com, armbru@redhat.com, lcapitulino@redhat.com,
	Vasilis Liaskovitis <vasilis.liaskovitis@profitbricks.com>,
	snaiksat@cisco.com
Subject: [Qemu-devel] [RFC PATCH 2/2] virtio-net: re-initialize tap device for new netdev
Date: Wed,  2 May 2012 18:06:42 +0200	[thread overview]
Message-ID: <1335974802-12984-3-git-send-email-vasilis.liaskovitis@profitbricks.com> (raw)
In-Reply-To: <1335974802-12984-1-git-send-email-vasilis.liaskovitis@profitbricks.com>

When a nic's backend netdev device is changed, the tap device needs to be
re-initialized for vnet_hdr and offload features. Also, vhost will have to
be re-initialized. This is currently implemented in the virtio set_status
callback function.

Signed-off-by: Vasilis Liaskovitis <vasilis.liaskovitis@profitbricks.com>
---
 hw/virtio-net.c |   30 ++++++++++++++++++++++++++++++
 1 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index bc5e3a8..858434a 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -63,6 +63,7 @@ typedef struct VirtIONet
     } mac_table;
     uint32_t *vlans;
     DeviceState *qdev;
+    VLANClientState *old_peer;
 } VirtIONet;
 
 /* TODO
@@ -137,10 +138,38 @@ static void virtio_net_vhost_status(VirtIONet *n, uint8_t status)
     }
 }
 
+static int peer_has_vnet_hdr(VirtIONet *n);
+
 static void virtio_net_set_status(struct VirtIODevice *vdev, uint8_t status)
 {
     VirtIONet *n = to_virtio_net(vdev);
+    uint32_t features;
+
+    /* re-initialize backend netdev if it is has been changed */
+    if (n->old_peer != n->nic->nc.peer) {
+        features = vdev->guest_features;
+
+        if (peer_has_vnet_hdr(n))
+            tap_using_vnet_hdr(n->nic->nc.peer, 1);
+
+        if (n->has_vnet_hdr) {
+            tap_set_offload(n->nic->nc.peer,
+                    (features >> VIRTIO_NET_F_GUEST_CSUM) & 1,
+                    (features >> VIRTIO_NET_F_GUEST_TSO4) & 1,
+                    (features >> VIRTIO_NET_F_GUEST_TSO6) & 1,
+                    (features >> VIRTIO_NET_F_GUEST_ECN)  & 1,
+                    (features >> VIRTIO_NET_F_GUEST_UFO)  & 1);
+        }
+        if ((n->nic->nc.peer->info->type == NET_CLIENT_TYPE_TAP) &&
+                tap_get_vhost_net(n->nic->nc.peer)) {
+            vhost_net_ack_features(tap_get_vhost_net(n->nic->nc.peer), features);
+        }
+        /* vhost will have to be restarted */
+        if (n->vhost_started)
+            n->vhost_started = 0;
 
+        n->old_peer = n->nic->nc.peer;
+    }     
     virtio_net_vhost_status(n, status);
 
     if (!n->tx_waiting) {
@@ -1044,6 +1073,7 @@ VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf,
     n->vlans = g_malloc0(MAX_VLAN >> 3);
 
     n->qdev = dev;
+    n->old_peer = conf->peer;
     register_savevm(dev, "virtio-net", -1, VIRTIO_NET_VM_VERSION,
                     virtio_net_save, virtio_net_load, n);
 
-- 
1.7.9

      parent reply	other threads:[~2012-05-02 16:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-02 16:06 [Qemu-devel] [RFC PATCH 0/2] Decouple netdev from nic Vasilis Liaskovitis
2012-05-02 16:06 ` [Qemu-devel] [RFC PATCH 1/2] Implement netdev_set command Vasilis Liaskovitis
2012-05-02 16:06 ` Vasilis Liaskovitis [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1335974802-12984-3-git-send-email-vasilis.liaskovitis@profitbricks.com \
    --to=vasilis.liaskovitis@profitbricks.com \
    --cc=aliguori@us.ibm.com \
    --cc=armbru@redhat.com \
    --cc=lcapitulino@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=snaiksat@cisco.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).