From patchwork Fri May 3 20:29:16 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 2519301 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 3176C3FE80 for ; Fri, 3 May 2013 20:30:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934302Ab3ECUaR (ORCPT ); Fri, 3 May 2013 16:30:17 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:47594 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934180Ab3ECUaP (ORCPT ); Fri, 3 May 2013 16:30:15 -0400 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by aserp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r43KU8vd003237 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 3 May 2013 20:30:09 GMT Received: from aserz7022.oracle.com (aserz7022.oracle.com [141.146.126.231]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r43KU8pF023172 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Fri, 3 May 2013 20:30:08 GMT Received: from abhmt114.oracle.com (abhmt114.oracle.com [141.146.116.66]) by aserz7022.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r43KU8Up023164; Fri, 3 May 2013 20:30:08 GMT Received: from lappy.us.oracle.com (/10.159.134.53) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 03 May 2013 13:30:07 -0700 From: Sasha Levin To: penberg@kernel.org, asias@redhat.com Cc: kvm@vger.kernel.org, Sasha Levin Subject: [PATCH 7/8] kvm tools: use iovec functions in uip_rx Date: Fri, 3 May 2013 16:29:16 -0400 Message-Id: <1367612957-6719-7-git-send-email-sasha.levin@oracle.com> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: <1367612957-6719-1-git-send-email-sasha.levin@oracle.com> References: <1367612957-6719-1-git-send-email-sasha.levin@oracle.com> X-Source-IP: acsinet22.oracle.com [141.146.126.238] Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Simplifies the code a lot. Signed-off-by: Sasha Levin --- 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 #include #include +#include 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; }