All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sasha.levin@oracle.com>
To: penberg@kernel.org, asias@redhat.com
Cc: kvm@vger.kernel.org, Sasha Levin <sasha.levin@oracle.com>
Subject: [PATCH 7/8] kvm tools: use iovec functions in uip_rx
Date: Fri,  3 May 2013 16:29:16 -0400	[thread overview]
Message-ID: <1367612957-6719-7-git-send-email-sasha.levin@oracle.com> (raw)
In-Reply-To: <1367612957-6719-1-git-send-email-sasha.levin@oracle.com>

Simplifies the code a lot.

Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
---
 tools/kvm/include/kvm/uip.h |  4 ++--
 tools/kvm/net/uip/core.c    | 47 +++------------------------------------------
 2 files changed, 5 insertions(+), 46 deletions(-)

diff --git a/tools/kvm/include/kvm/uip.h b/tools/kvm/include/kvm/uip.h
index 338582d..cb79e94 100644
--- a/tools/kvm/include/kvm/uip.h
+++ b/tools/kvm/include/kvm/uip.h
@@ -214,8 +214,8 @@ struct uip_buf {
 	int vnet_len;
 	int eth_len;
 	int status;
-	char *vnet;
-	char *eth;
+	unsigned char *vnet;
+	unsigned char *eth;
 	int id;
 };
 
diff --git a/tools/kvm/net/uip/core.c b/tools/kvm/net/uip/core.c
index 7a74261..e31efc2 100644
--- a/tools/kvm/net/uip/core.c
+++ b/tools/kvm/net/uip/core.c
@@ -4,6 +4,7 @@
 #include <linux/virtio_net.h>
 #include <linux/kernel.h>
 #include <linux/list.h>
+#include <kvm/iovec.h>
 
 int uip_tx(struct iovec *iov, u16 out, struct uip_info *info)
 {
@@ -76,61 +77,19 @@ int uip_tx(struct iovec *iov, u16 out, struct uip_info *info)
 
 int uip_rx(struct iovec *iov, u16 in, struct uip_info *info)
 {
-	struct virtio_net_hdr *vnet;
-	struct uip_eth *eth;
 	struct uip_buf *buf;
-	int vnet_len;
-	int eth_len;
-	char *p;
 	int len;
-	int cnt;
-	int i;
 
 	/*
 	 * Sleep until there is a buffer for guest
 	 */
 	buf = uip_buf_get_used(info);
 
-	/*
-	 * Fill device to guest buffer, vnet hdr fisrt
-	 */
-	vnet_len = iov[0].iov_len;
-	vnet = iov[0].iov_base;
-	if (buf->vnet_len > vnet_len) {
-		len = -1;
-		goto out;
-	}
-	memcpy(vnet, buf->vnet, buf->vnet_len);
-
-	/*
-	 * Then, the real eth data
-	 * Note: Be sure buf->eth_len is not bigger than the buffer len that guest provides
-	 */
-	cnt = buf->eth_len;
-	p = buf->eth;
-	for (i = 1; i < in; i++) {
-		eth_len = iov[i].iov_len;
-		eth = iov[i].iov_base;
-		if (cnt > eth_len) {
-			memcpy(eth, p, eth_len);
-			cnt -= eth_len;
-			p += eth_len;
-		} else {
-			memcpy(eth, p, cnt);
-			cnt -= cnt;
-			break;
-		}
-	}
-
-	if (cnt) {
-		pr_warning("uip_rx error");
-		len = -1;
-		goto out;
-	}
+	memcpy_toiovecend(iov, buf->vnet, 0, buf->vnet_len);
+	memcpy_toiovecend(iov, buf->eth, buf->vnet_len, buf->eth_len);
 
 	len = buf->vnet_len + buf->eth_len;
 
-out:
 	uip_buf_set_free(info, buf);
 	return len;
 }
-- 
1.8.2.1


  parent reply	other threads:[~2013-05-03 20:30 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-03 20:29 [PATCH 1/8] kvm tools: pass virtio header size to uip_init Sasha Levin
2013-05-03 20:29 ` [PATCH 2/8] kvm tools: fix vhost interaction with ctrl vq Sasha Levin
2013-05-03 20:29 ` [PATCH 3/8] kvm tools: add status notification hook for virtio Sasha Levin
2013-05-03 20:29 ` [PATCH 4/8] kvm tools: init network devices only when the virtio driver is ready to go Sasha Levin
2013-05-03 20:29 ` [PATCH 5/8] kvm tools: use correct vnet header size for mergable rx buffers Sasha Levin
2013-05-03 20:29 ` [PATCH 6/8] kvm tools: steal iovec handling routines from the kernel Sasha Levin
2013-05-03 20:29 ` Sasha Levin [this message]
2013-05-03 20:29 ` [PATCH 8/8] kvm tools: virtio-net mergable rx buffers Sasha Levin
2013-05-14 15:30 ` [PATCH 1/8] kvm tools: pass virtio header size to uip_init Pekka Enberg

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=1367612957-6719-7-git-send-email-sasha.levin@oracle.com \
    --to=sasha.levin@oracle.com \
    --cc=asias@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=penberg@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.