From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mark McLoughlin Subject: [PATCH 4/5] kvm: qemu: virtio-net: split iov_fill() out from virtio_net_receive() Date: Wed, 26 Nov 2008 14:50:37 +0000 Message-ID: <1227711038-21942-5-git-send-email-markmc@redhat.com> References: <1223991840.11098.29.camel@blaa> <1227711038-21942-1-git-send-email-markmc@redhat.com> <1227711038-21942-2-git-send-email-markmc@redhat.com> <1227711038-21942-3-git-send-email-markmc@redhat.com> <1227711038-21942-4-git-send-email-markmc@redhat.com> Cc: kvm@vger.kernel.org, Rusty Russell , Herbert Xu , Anthony Liguori , Mark McLoughlin To: Avi Kivity Return-path: Received: from mail02.svc.cra.dublin.eircom.net ([159.134.118.18]:33413 "HELO mail02.svc.cra.dublin.eircom.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1751796AbYKZOvx (ORCPT ); Wed, 26 Nov 2008 09:51:53 -0500 In-Reply-To: <1227711038-21942-4-git-send-email-markmc@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: Simplifies the current code, but more especially, simplifies the implementation of the mergeable receive buffers scheme. Signed-off-by: Mark McLoughlin --- qemu/hw/virtio-net.c | 27 ++++++++++++++++++--------- 1 files changed, 18 insertions(+), 9 deletions(-) diff --git a/qemu/hw/virtio-net.c b/qemu/hw/virtio-net.c index bc2ede6..2a52536 100644 --- a/qemu/hw/virtio-net.c +++ b/qemu/hw/virtio-net.c @@ -182,12 +182,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) @@ -212,14 +227,8 @@ static void virtio_net_receive(void *opaque, const uint8_t *buf, int size) } /* 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++; - } + total += 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