mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Ask For Comment: add routines for exchanging data between sock buffer and scatter list
@ 2010-10-02 12:04 Hillf Danton
  2010-10-02 20:20 ` David Miller
  0 siblings, 1 reply; 4+ messages in thread
From: Hillf Danton @ 2010-10-02 12:04 UTC (permalink / raw)
  To: linux-kernel
  Cc: David S. Miller, Jens Axboe, Robert Love, James E.J. Bottomley

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,
so a head file is added.

Signed-off-by: Hillf Danton <dhillf@gmail.com>
---

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-02 19:21:18.000000000 +0800
@@ -0,0 +1,110 @@
+/*
+    Definition for exchanging data between sock buffer and scatter list
+
+    Copyright (C) Oct 2010 Hillf Danton <dhillf@gmail.com>
+
+    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 <linux/scatterlist.h>
+#include <linux/skbuff.h>
+
+/*
+ * 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;
+	
+	/* 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;	
+}
+
+/*
+ * 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;
+}
+
+#endif /* __LINUX_SKB_SG_H */

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Ask For Comment: add routines for exchanging data between sock buffer and scatter list
  2010-10-02 12:04 Ask For Comment: add routines for exchanging data between sock buffer and scatter list Hillf Danton
@ 2010-10-02 20:20 ` David Miller
  2010-10-03  2:37   ` Hillf Danton
  2010-10-03  3:10   ` Hillf Danton
  0 siblings, 2 replies; 4+ messages in thread
From: David Miller @ 2010-10-02 20:20 UTC (permalink / raw)
  To: dhillf; +Cc: linux-kernel, axboe, robert.w.love, James.Bottomley


All networking related patch postings should be sent with
netdev@vger.kernel.org at least on the CC: list.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Ask For Comment: add routines for exchanging data between sock buffer and scatter list
  2010-10-02 20:20 ` David Miller
@ 2010-10-03  2:37   ` Hillf Danton
  2010-10-03  3:10   ` Hillf Danton
  1 sibling, 0 replies; 4+ messages in thread
From: Hillf Danton @ 2010-10-03  2:37 UTC (permalink / raw)
  To: David Miller; +Cc: linux-kernel, axboe, robert.w.love, James.Bottomley

On Sun, Oct 3, 2010 at 4:20 AM, David Miller <davem@davemloft.net> wrote:
>
> All networking related patch postings should be sent with
> netdev@vger.kernel.org at least on the CC: list.
>

Node. And thanks for the chance to redeliver it since there is one line
messed by mailer.
And the check for the data length to be copied is added in the new version.
Hillf

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Ask For Comment: add routines for exchanging data between sock buffer and scatter list
  2010-10-02 20:20 ` David Miller
  2010-10-03  2:37   ` Hillf Danton
@ 2010-10-03  3:10   ` Hillf Danton
  1 sibling, 0 replies; 4+ messages in thread
From: Hillf Danton @ 2010-10-03  3:10 UTC (permalink / raw)
  To: David Miller, netdev; +Cc: linux-kernel, axboe, robert.w.love, James.Bottomley

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 <dhillf@gmail.com>
---

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 <dhillf@gmail.com>
+
+    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 <linux/scatterlist.h>
+#include <linux/skbuff.h>
+
+/*
+ * 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 */

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-10-03  3:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-02 12:04 Ask For Comment: add routines for exchanging data between sock buffer and scatter list Hillf Danton
2010-10-02 20:20 ` David Miller
2010-10-03  2:37   ` Hillf Danton
2010-10-03  3:10   ` Hillf Danton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®