From patchwork Sun Oct 3 03:10:14 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hillf Danton X-Patchwork-Id: 66591 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 5BF8FB6F01 for ; Sun, 3 Oct 2010 14:10:54 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752569Ab0JCDKR (ORCPT ); Sat, 2 Oct 2010 23:10:17 -0400 Received: from mail-wy0-f174.google.com ([74.125.82.174]:55512 "EHLO mail-wy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752440Ab0JCDKP (ORCPT ); Sat, 2 Oct 2010 23:10:15 -0400 Received: by wyb28 with SMTP id 28so4025308wyb.19 for ; Sat, 02 Oct 2010 20:10:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type; bh=FXzb3xTy4TPAXX3FgejfzyZ3+6nHOLTwHxeOczlAxQ4=; b=gxFoqIgVlds6NmP8c/tdZxscBU5OWEPlHyca8tDKIx8082U7//v0TS3Hl+H1WhsM/j GhvmWhUSZ0ozqkGQVWrp+S5ktX16PClqKEFy3tfFhXalqSjJze0avo2HUfGVWNYmWzbN 0Tly+mzqZ7wRiMLyGhJqEoUHnnHfKU/R1fKKM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=Upe+4EqUlV+ezdSXjtq/RxCMsMMdIISbG7kxzexXYMtYmPTfh4VrHtJTwguZKedFf3 PrsUiV469UGsFiK1ecMWW2MOUzbAA0tvNbu+2X/LionqOIqEErvcP7iMnp7FI8nNZ+xy hgtsRVtiEh4KCoy8ChnWGkQr08dYYMVYJZr4s= MIME-Version: 1.0 Received: by 10.227.128.14 with SMTP id i14mr6508892wbs.109.1286075414233; Sat, 02 Oct 2010 20:10:14 -0700 (PDT) Received: by 10.227.151.67 with HTTP; Sat, 2 Oct 2010 20:10:14 -0700 (PDT) In-Reply-To: <20101002.132056.226767861.davem@davemloft.net> References: <20101002.132056.226767861.davem@davemloft.net> Date: Sun, 3 Oct 2010 11:10:14 +0800 Message-ID: Subject: Re: Ask For Comment: add routines for exchanging data between sock buffer and scatter list From: Hillf Danton To: David Miller , netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, axboe@kernel.dk, robert.w.love@intel.com, James.Bottomley@suse.de Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org There seems no routines provided for exchanging data directly between sock buffer and scatter list in both scatterlist.c and skbuff.c, so comes this work. And it is hard to determine into which file these routines should be added, then a header file is added. Signed-off-by: Hillf Danton --- -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff -Npur o/linux-2.6.36-rc4/include/skb_sg.h m/linux-2.6.36-rc4/include/skb_sg.h --- o/linux-2.6.36-rc4/include/skb_sg.h 1970-01-01 08:00:00.000000000 +0800 +++ m/linux-2.6.36-rc4/include/skb_sg.h 2010-10-03 10:03:54.000000000 +0800 @@ -0,0 +1,113 @@ +/* + Definition for exchanging data between sock buffer and scatter list + + Copyright (C) Oct 2010 Hillf Danton + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, + MA 02110-1301 USA +*/ + +#ifndef __LINUX_SKB_SG_H +#define __LINUX_SKB_SG_H + +#include +#include + +/* + * sg_fill_skb_page_desc - fill skb frags with info in sg list + * @index the start index to fill + * + * return the number of filled frags + */ + +static int sg_fill_skb_page_desc(struct sk_buff *skb, int index, + struct scatterlist *sg) +{ + int old = index; + struct page *page; + + for (; sg && index < MAX_SKB_FRAGS; index++) { + page = sg_page(sg); + get_page(page); + skb_add_rx_frag(skb, index, page, sg->offset, sg->length); + sg = sg_next(sg); + } + + return index - old; +} + +/* + * skb_copy_bits_to_sg - copy data from skb to sg list + * @len length of data to be copied + * + * return the number of copied bytes + */ + +static int skb_copy_bits_to_sg(struct sk_buff *skb, int offset_in_skb, + struct scatterlist *sg, int offset_in_sg, + int len) +{ + int old = len; + struct sg_mapping_iter miter; + + if (offset_in_skb >= skb->len) + return 0; + + if (len > skb->len - offset_in_skb) + old = len = skb->len - offset_in_skb; + + /* skip offset in sg */ + while (sg && offset_in_sg >= sg->length) { + offset_in_sg -= sg->length; + sg = sg_next(sg); + } + if (! sg) + return 0; + + /* and go thru sg list */ + while (len > 0 && sg) { + int this_len; + int err; + + sg_miter_start(&miter, sg, 1, SG_MITER_ATOMIC|SG_MITER_TO_SG); + + if (offset_in_sg) { + /* we have to count this residual */ + miter.__offset = offset_in_sg; + offset_in_sg = 0; + } + + if (! sg_miter_next(&miter)) + break; + + this_len = min(miter.length, len); + + err = skb_copy_bits(skb, offset_in_skb, miter.addr, this_len); + + sg_miter_stop(&miter); + + if (err) + break; + + offset_in_skb += this_len; + len -= this_len; + + sg = sg_next(sg); + } + + return old - len; +} + +#endif /* __LINUX_SKB_SG_H */