From: Mark McLoughlin <markmc@redhat.com>
To: Avi Kivity <avi@qumranet.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH 08/12] kvm: qemu: Don't require all drivers to use virtio_net_hdr
Date: Tue, 12 Aug 2008 18:41:05 +0100 [thread overview]
Message-ID: <1218562865.29159.1.camel@muff> (raw)
In-Reply-To: <1218485535-877-9-git-send-email-markmc@redhat.com>
Hi Avi,
Thanks for catching the build error in this one.
Here's a new (yet uglier) version; the rest remain the same.
Cheers,
Mark.
Subject: [PATCH 08/11] kvm: qemu: Don't require all drivers to use virtio_net_hdr
The virtio-net driver is the only one which wishes to deal
with virtio_net_hdr headers, so add a "using_vnet_hdr" flag
to allow it to indicate this.
Preferably, we'd prefer to only enable IFF_VNET_HDR when
we're using virtio-net, but qemu's various abstractions
would make this very messy.
Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
qemu/hw/virtio-net.c | 1 +
qemu/net.h | 1 +
qemu/vl.c | 87 +++++++++++++++++++++++++++++++++++++++++++------
3 files changed, 78 insertions(+), 11 deletions(-)
diff --git a/qemu/hw/virtio-net.c b/qemu/hw/virtio-net.c
index 9b1298e..2298316 100644
--- a/qemu/hw/virtio-net.c
+++ b/qemu/hw/virtio-net.c
@@ -97,6 +97,7 @@ static uint32_t virtio_net_get_features(VirtIODevice *vdev)
uint32_t features = (1 << VIRTIO_NET_F_MAC);
if (tap_has_vnet_hdr(host)) {
+ tap_using_vnet_hdr(host, 1);
features |= (1 << VIRTIO_NET_F_CSUM);
features |= (1 << VIRTIO_NET_F_GUEST_CSUM);
features |= (1 << VIRTIO_NET_F_GUEST_TSO4);
diff --git a/qemu/net.h b/qemu/net.h
index ae1a338..4891669 100644
--- a/qemu/net.h
+++ b/qemu/net.h
@@ -46,6 +46,7 @@ void qemu_handler_true(void *opaque);
void do_info_network(void);
int tap_has_vnet_hdr(void *opaque);
+void tap_using_vnet_hdr(void *opaque, int using_vnet_hdr);
int net_client_init(const char *device, const char *opts);
void net_client_uninit(NICInfo *nd);
diff --git a/qemu/vl.c b/qemu/vl.c
index f5aacf0..63e21f2 100644
--- a/qemu/vl.c
+++ b/qemu/vl.c
@@ -4347,6 +4347,10 @@ int tap_has_vnet_hdr(void *opaque)
return 0;
}
+void tap_using_vnet_hdr(void *opaque, int using_vnet_hdr)
+{
+}
+
#else /* !defined(_WIN32) */
#ifndef IFF_VNET_HDR
@@ -4367,10 +4371,11 @@ typedef struct TAPState {
char buf[TAP_BUFSIZE];
int size;
unsigned int has_vnet_hdr : 1;
+ unsigned int using_vnet_hdr : 1;
} TAPState;
-static ssize_t tap_receive_iov(void *opaque, const struct iovec *iov,
- int iovcnt)
+static ssize_t tap_writev(void *opaque, const struct iovec *iov,
+ int iovcnt)
{
TAPState *s = opaque;
ssize_t len;
@@ -4382,17 +4387,51 @@ static ssize_t tap_receive_iov(void *opaque, const struct iovec *iov,
return len;
}
+static ssize_t tap_receive_iov(void *opaque, const struct iovec *iov,
+ int iovcnt)
+{
+#ifdef IFF_VNET_HDR
+ TAPState *s = opaque;
+
+ if (s->has_vnet_hdr && !s->using_vnet_hdr) {
+ struct iovec *iov_copy;
+ struct virtio_net_hdr hdr = { 0, };
+
+ iov_copy = alloca(sizeof(struct iovec) * (iovcnt + 1));
+
+ iov_copy[0].iov_base = &hdr;
+ iov_copy[0].iov_len = sizeof(hdr);
+
+ memcpy(&iov_copy[1], iov, sizeof(struct iovec) * iovcnt);
+
+ return tap_writev(opaque, iov_copy, iovcnt + 1);
+ }
+#endif
+
+ return tap_writev(opaque, iov, iovcnt);
+}
+
static void tap_receive(void *opaque, const uint8_t *buf, int size)
{
+ struct iovec iov[2];
+ int i = 0;
+
+#ifdef IFF_VNET_HDR
TAPState *s = opaque;
- int ret;
- for(;;) {
- ret = write(s->fd, buf, size);
- if (ret < 0 && (errno == EINTR || errno == EAGAIN)) {
- } else {
- break;
- }
+ struct virtio_net_hdr hdr = { 0, };
+
+ if (s->has_vnet_hdr && !s->using_vnet_hdr) {
+ iov[i].iov_base = &hdr;
+ iov[i].iov_len = sizeof(hdr);
+ i++;
}
+#endif
+
+ iov[i].iov_base = (char *) buf;
+ iov[i].iov_len = size;
+ i++;
+
+ tap_writev(opaque, iov, i);
}
static int tap_can_send(void *opaque)
@@ -4421,6 +4460,21 @@ static int tap_can_send(void *opaque)
return can_receive;
}
+static int tap_send_packet(TAPState *s)
+{
+ uint8_t *buf = s->buf;
+ int size = s->size;
+
+#ifdef IFF_VNET_HDR
+ if (s->has_vnet_hdr && !s->using_vnet_hdr) {
+ buf += sizeof(struct virtio_net_hdr);
+ size -= sizeof(struct virtio_net_hdr);
+ }
+#endif
+
+ return qemu_send_packet(s->vc, buf, size);
+}
+
static void tap_send(void *opaque)
{
TAPState *s = opaque;
@@ -4430,7 +4484,7 @@ static void tap_send(void *opaque)
int err;
/* If noone can receive the packet, buffer it */
- err = qemu_send_packet(s->vc, s->buf, s->size);
+ err = tap_send_packet(s);
if (err == -EAGAIN)
return;
}
@@ -4454,7 +4508,7 @@ static void tap_send(void *opaque)
int err;
/* If noone can receive the packet, buffer it */
- err = qemu_send_packet(s->vc, s->buf, s->size);
+ err = tap_send_packet(s);
if (err == -EAGAIN)
break;
}
@@ -4469,6 +4523,17 @@ int tap_has_vnet_hdr(void *opaque)
return s ? s->has_vnet_hdr : 0;
}
+void tap_using_vnet_hdr(void *opaque, int using_vnet_hdr)
+{
+ VLANClientState *vc = opaque;
+ TAPState *s = vc->opaque;
+
+ if (!s || !s->has_vnet_hdr)
+ return;
+
+ s->using_vnet_hdr = using_vnet_hdr != 0;
+}
+
#ifdef TUNSETOFFLOAD
static void tap_set_offload(VLANClientState *vc, int csum, int tso4, int tso6,
int ecn)
--
1.5.4.1
next prev parent reply other threads:[~2008-08-12 17:41 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-11 20:12 [PATCH 0/12] virtio_net perf patches Mark McLoughlin
2008-08-11 20:12 ` [PATCH 01/12] kvm: qemu: Fix virtio_net tx timer Mark McLoughlin
2008-08-11 20:12 ` [PATCH 02/12] kvm: qemu: Remove virtio_net tx ring-full heuristic Mark McLoughlin
2008-08-11 20:12 ` [PATCH 03/12] kvm: qemu: Add VIRTIO_F_NOTIFY_ON_EMPTY Mark McLoughlin
2008-08-11 20:12 ` [PATCH 04/12] kvm: qemu: Disable recv notifications until avail buffers exhausted Mark McLoughlin
2008-08-11 20:12 ` [PATCH 05/12] kvm: qemu: Add support for partial csums and GSO Mark McLoughlin
2008-08-11 20:12 ` [PATCH 06/12] kvm: qemu: Rename tap_readv() to tap_receive_iov() Mark McLoughlin
2008-08-11 20:12 ` [PATCH 07/12] kvm: qemu: Move some code around for the next commit Mark McLoughlin
2008-08-11 20:12 ` [PATCH 08/12] kvm: qemu: Don't require all drivers to use virtio_net_hdr Mark McLoughlin
2008-08-11 20:12 ` [PATCH 09/12] kvm: qemu: Actually enable GSO support Mark McLoughlin
2008-08-11 20:12 ` [PATCH 10/12] kvm: qemu: Add a -net tap,fd=X,vnet_hdr=on option Mark McLoughlin
2008-08-11 20:12 ` [PATCH 11/12] kvm: qemu: Increase size of virtio_net rings Mark McLoughlin
2008-08-11 20:12 ` [PATCH 12/12] kvm: qemu: Drop the mutex while reading from tapfd Mark McLoughlin
2008-08-11 20:30 ` [PATCH 10/12] kvm: qemu: Add a -net tap,fd=X,vnet_hdr=on option Anthony Liguori
2008-08-12 17:41 ` Mark McLoughlin [this message]
2008-08-13 9:13 ` [PATCH 08/12] kvm: qemu: Don't require all drivers to use virtio_net_hdr Avi Kivity
2008-08-11 20:30 ` [PATCH 0/12] virtio_net perf patches Anthony Liguori
2008-08-12 18:12 ` Mark McLoughlin
2008-08-12 18:28 ` Anthony Liguori
2008-08-12 23:39 ` Herbert Xu
2008-08-12 13:51 ` Avi Kivity
2008-08-12 14:55 ` Avi Kivity
2008-08-13 14:39 ` [PATCH 1/1] kvm: qemu: Handle tap fds with IFF_VNET_HDR Mark McLoughlin
2008-08-13 16:24 ` Avi Kivity
2008-08-13 16:28 ` Daniel P. Berrange
2008-08-20 17:04 ` [PATCH] " Mark McLoughlin
2008-08-20 17:09 ` Mark McLoughlin
2008-08-20 17:27 ` Avi Kivity
2008-08-20 17:49 ` Anthony Liguori
2008-08-20 17:51 ` Avi Kivity
2008-08-20 18:01 ` Anthony Liguori
2008-08-21 9:30 ` Mark McLoughlin
2008-08-21 13:55 ` Avi Kivity
2008-08-21 13:58 ` Anthony Liguori
2008-08-20 18:11 ` Daniel P. Berrange
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=1218562865.29159.1.camel@muff \
--to=markmc@redhat.com \
--cc=avi@qumranet.com \
--cc=kvm@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.