From patchwork Thu Apr 29 12:14:50 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Aneesh Kumar K.V" X-Patchwork-Id: 51285 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6A6D8B6EFF for ; Thu, 29 Apr 2010 22:47:00 +1000 (EST) Received: from localhost ([127.0.0.1]:54112 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O7Sx3-0001ws-Fu for incoming@patchwork.ozlabs.org; Thu, 29 Apr 2010 08:34:45 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O7See-0005en-7U for qemu-devel@nongnu.org; Thu, 29 Apr 2010 08:15:44 -0400 Received: from [140.186.70.92] (port=45851 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O7Sec-0005dY-C8 for qemu-devel@nongnu.org; Thu, 29 Apr 2010 08:15:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O7Sea-0006s4-GF for qemu-devel@nongnu.org; Thu, 29 Apr 2010 08:15:42 -0400 Received: from e23smtp03.au.ibm.com ([202.81.31.145]:56970) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O7SeZ-0006rh-Ve for qemu-devel@nongnu.org; Thu, 29 Apr 2010 08:15:40 -0400 Received: from d23relay05.au.ibm.com (d23relay05.au.ibm.com [202.81.31.247]) by e23smtp03.au.ibm.com (8.14.3/8.13.1) with ESMTP id o3TCCKu4013480 for ; Thu, 29 Apr 2010 22:12:20 +1000 Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139]) by d23relay05.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o3TC8mg51229024 for ; Thu, 29 Apr 2010 22:08:48 +1000 Received: from d23av04.au.ibm.com (loopback [127.0.0.1]) by d23av04.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id o3TCFa06019666 for ; Thu, 29 Apr 2010 22:15:38 +1000 Received: from skywalker.in.ibm.com ([9.124.222.113]) by d23av04.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVin) with ESMTP id o3TCF895018931; Thu, 29 Apr 2010 22:15:34 +1000 From: "Aneesh Kumar K.V" To: qemu-devel@nongnu.org Date: Thu, 29 Apr 2010 17:44:50 +0530 Message-Id: <1272543303-9830-9-git-send-email-aneesh.kumar@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.0.4.360.g11766c In-Reply-To: <1272543303-9830-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> References: <1272543303-9830-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: ericvh@gmail.com, aliguori@us.ibm.com, jvrao@linux.vnet.ibm.com, aneesh.kumar@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH -V6 08/21] virtio-9p: Add sg helper functions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Anthony Liguori Add scatter-gather helper functions. Signed-off-by: Anthony Liguori Signed-off-by: Aneesh Kumar K.V --- hw/virtio-9p.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 53 insertions(+), 0 deletions(-) diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c index b37cdf2..c31f48c 100644 --- a/hw/virtio-9p.c +++ b/hw/virtio-9p.c @@ -762,6 +762,56 @@ static int stat_to_v9stat(V9fsState *s, V9fsString *name, return 0; } +static struct iovec *adjust_sg(struct iovec *sg, int len, int *iovcnt) +{ + while (len && *iovcnt) { + if (len < sg->iov_len) { + sg->iov_len -= len; + sg->iov_base += len; + len = 0; + } else { + len -= sg->iov_len; + sg++; + *iovcnt -= 1; + } + } + + return sg; +} + +static struct iovec *cap_sg(struct iovec *sg, int cap, int *cnt) +{ + int i; + int total = 0; + + for (i = 0; i < *cnt; i++) { + if ((total + sg[i].iov_len) > cap) { + sg[i].iov_len -= ((total + sg[i].iov_len) - cap); + i++; + break; + } + total += sg[i].iov_len; + } + + *cnt = i; + + return sg; +} + +static void print_sg(struct iovec *sg, int cnt) +{ + int i; + + printf("sg[%d]: {", cnt); + for (i = 0; i < cnt; i++) { + if (i) { + printf(", "); + } + printf("(%p, %zd)", sg[i].iov_base, sg[i].iov_len); + } + printf("}\n"); +} + static void v9fs_dummy(V9fsState *s, V9fsPDU *pdu) { /* Note: The following have been added to prevent GCC from complaining @@ -786,6 +836,9 @@ static void v9fs_dummy(V9fsState *s, V9fsPDU *pdu) (void) donttouch_stat; (void) v9fs_stat_free; (void) stat_to_v9stat; + (void) adjust_sg; + (void) cap_sg; + (void) print_sg; } static void v9fs_version(V9fsState *s, V9fsPDU *pdu)