All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mark McLoughlin <markmc@redhat.com>
To: Avi Kivity <avi@redhat.com>
Cc: kvm@vger.kernel.org, Rusty Russell <rusty@rustcorp.com.au>,
	Mark McLoughlin <markmc@redhat.com>
Subject: [PATCH 4/5] kvm: qemu: Split iov_fill() out from virtio_net_receive()
Date: Wed,  8 Oct 2008 20:35:12 +0100	[thread overview]
Message-ID: <1223494513-18826-4-git-send-email-markmc@redhat.com> (raw)
In-Reply-To: <1223494513-18826-3-git-send-email-markmc@redhat.com>

Simplifies the current code, but more especially, the code
in the next patch.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 qemu/hw/virtio-net.c |   32 +++++++++++++++++++++-----------
 1 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/qemu/hw/virtio-net.c b/qemu/hw/virtio-net.c
index 4b4c48b..403247b 100644
--- a/qemu/hw/virtio-net.c
+++ b/qemu/hw/virtio-net.c
@@ -183,12 +183,27 @@ static void work_around_broken_dhclient(struct virtio_net_hdr *hdr,
     }
 }
 
+static int iov_fill(struct iovec *iov, int iovcnt, const void *buf, int count)
+{
+    int offset, i;
+
+    offset = i = 0;
+    while (offset < count && i < iovcnt) {
+	int len = MIN(iov[i].iov_len, count - offset);
+	memcpy(iov[i].iov_base, buf + offset, len);
+	offset += len;
+	i++;
+    }
+
+    return offset;
+}
+
 static void virtio_net_receive(void *opaque, const uint8_t *buf, int size)
 {
     VirtIONet *n = opaque;
     VirtQueueElement elem;
     struct virtio_net_hdr *hdr;
-    int offset, i;
+    int offset;
     int total;
 
     if (virtqueue_pop(n->rx_vq, &elem) == 0)
@@ -204,23 +219,18 @@ static void virtio_net_receive(void *opaque, const uint8_t *buf, int size)
     hdr->gso_type = VIRTIO_NET_HDR_GSO_NONE;
 
     offset = 0;
-    total = sizeof(*hdr);
+    total = size + sizeof(*hdr);
 
     if (tap_has_vnet_hdr(n->vc->vlan->first_client)) {
 	memcpy(hdr, buf, sizeof(*hdr));
-	offset += total;
+	offset += sizeof(*hdr);
+	total -= offset;
         work_around_broken_dhclient(hdr, buf + offset, size - offset);
     }
 
     /* copy in packet.  ugh */
-    i = 1;
-    while (offset < size && i < elem.in_num) {
-	int len = MIN(elem.in_sg[i].iov_len, size - offset);
-	memcpy(elem.in_sg[i].iov_base, buf + offset, len);
-	offset += len;
-	total += len;
-	i++;
-    }
+    iov_fill(&elem.in_sg[1], elem.in_num - 1,
+	     buf + offset, size - offset);
 
     /* signal other side */
     virtqueue_push(n->rx_vq, &elem, total);
-- 
1.5.4.3


  reply	other threads:[~2008-10-08 19:36 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-08 19:35 [PATCH 1/5] kvm: qemu: Move virtqueue_next_desc() around Mark McLoughlin
2008-10-08 19:35 ` [PATCH 2/5] kvm: qemu: Introduce virtqueue_fill() and virtqueue_flush() Mark McLoughlin
2008-10-08 19:35   ` [PATCH 3/5] kvm: qemu: Simplify virtio_net_can_receive() a little Mark McLoughlin
2008-10-08 19:35     ` Mark McLoughlin [this message]
2008-10-08 19:35       ` [PATCH 5/5] kvm: qemu: Improve virtio_net recv buffer allocation scheme Mark McLoughlin
2008-10-12 10:00         ` Avi Kivity
2008-10-14 13:44           ` Mark McLoughlin
2008-10-14 15:47             ` Avi Kivity
2008-11-26 14:50             ` [PATCH 0/5] kvm: qemu: virtio_net: add support for mergeable rx buffers Mark McLoughlin
2008-11-26 14:50               ` [PATCH 1/5] kvm: qemu: virtio: move virtqueue_next_desc() around Mark McLoughlin
2008-11-26 14:50                 ` [PATCH 2/5] kvm: qemu: virtio: introduce virtqueue_fill() and virtqueue_flush() Mark McLoughlin
2008-11-26 14:50                   ` [PATCH 3/5] kvm: qemu: virtio: split some helpers out of virtqueue_pop() Mark McLoughlin
2008-11-26 14:50                     ` [PATCH 4/5] kvm: qemu: virtio-net: split iov_fill() out from virtio_net_receive() Mark McLoughlin
2008-11-26 14:50                       ` [PATCH 5/5] kvm: qemu: virtio-net: add a new virtio-net receive buffer scheme Mark McLoughlin
2008-11-27 12:45               ` [PATCH 0/5] kvm: qemu: virtio_net: add support for mergeable rx buffers Avi Kivity
2008-11-27 13:32                 ` Mark McLoughlin

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=1223494513-18826-4-git-send-email-markmc@redhat.com \
    --to=markmc@redhat.com \
    --cc=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=rusty@rustcorp.com.au \
    /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.