diff mbox

[5/8] kvm tools: use correct vnet header size for mergable rx buffers

Message ID 1367612957-6719-5-git-send-email-sasha.levin@oracle.com (mailing list archive)
State New, archived
Headers show

Commit Message

Sasha Levin May 3, 2013, 8:29 p.m. UTC
vnet header size depends on whether we use mergable rx buffers.

Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
---
 tools/kvm/virtio/net.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/tools/kvm/virtio/net.c b/tools/kvm/virtio/net.c
index 2dbca09..15dbde3 100644
--- a/tools/kvm/virtio/net.c
+++ b/tools/kvm/virtio/net.c
@@ -243,7 +243,9 @@  static bool virtio_net__tap_init(struct net_dev *ndev)
 		goto fail;
 	}
 
-	hdr_len = sizeof(struct virtio_net_hdr);
+	hdr_len = (ndev->features & (1 << VIRTIO_NET_F_MRG_RXBUF)) ?
+			sizeof(struct virtio_net_hdr_mrg_rxbuf) :
+			sizeof(struct virtio_net_hdr);
 	if (ioctl(ndev->tap_fd, TUNSETVNETHDRSZ, &hdr_len) < 0)
 		pr_warning("Config tap device TUNSETVNETHDRSZ error");
 
@@ -679,7 +681,6 @@  static int virtio_net__init_one(struct virtio_net_params *params)
 		ndev->info.guest_ip		= ntohl(inet_addr(params->guest_ip));
 		ndev->info.guest_netmask	= ntohl(inet_addr("255.255.255.0"));
 		ndev->info.buf_nr		= 20,
-		ndev->info.vnet_hdr_len		= sizeof(struct virtio_net_hdr);
 		ndev->ops = &uip_ops;
 	}
 
@@ -710,6 +711,9 @@  static void notify_status(struct kvm *kvm, void *dev, u8 status)
 		if (!virtio_net__tap_init(ndev))
 			die_perror("You have requested a TAP device, but creation of one has failed because");
 	} else {
+		ndev->info.vnet_hdr_len = (ndev->features & (1 << VIRTIO_NET_F_MRG_RXBUF)) ?
+						sizeof(struct virtio_net_hdr_mrg_rxbuf) :
+						sizeof(struct virtio_net_hdr);
 		uip_init(&ndev->info);
 	}
 }