From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mark McLoughlin Subject: [PATCH 4/5] kvm: qemu: Split iov_fill() out from virtio_net_receive() Date: Wed, 8 Oct 2008 20:35:12 +0100 Message-ID: <1223494513-18826-4-git-send-email-markmc@redhat.com> References: <> <1223494513-18826-1-git-send-email-markmc@redhat.com> <1223494513-18826-2-git-send-email-markmc@redhat.com> <1223494513-18826-3-git-send-email-markmc@redhat.com> Cc: kvm@vger.kernel.org, Rusty Russell , Mark McLoughlin To: Avi Kivity Return-path: Received: from mail23.svc.cra.dublin.eircom.net ([159.134.118.145]:41891 "HELO mail23.svc.cra.dublin.eircom.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1756144AbYJHTgA (ORCPT ); Wed, 8 Oct 2008 15:36:00 -0400 In-Reply-To: <1223494513-18826-3-git-send-email-markmc@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: Simplifies the current code, but more especially, the code in the next patch. Signed-off-by: Mark McLoughlin --- 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