Patchwork [9/9] net: add opaque struct around skb frag page

login
register
mail settings
Submitter Ian Campbell
Date Oct. 10, 2011, 11:11 a.m.
Message ID <1318245101-16890-9-git-send-email-ian.campbell@citrix.com>
Download mbox | patch
Permalink /patch/118699/
State Superseded
Delegated to: David Miller
Headers show

Comments

Ian Campbell - Oct. 10, 2011, 11:11 a.m.
I've split this bit out of the skb frag destructor patch since it helps enforce
the use of the fragment API.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
---
 include/linux/skbuff.h |   10 ++++++----
 net/core/skbuff.c      |    6 +++---
 2 files changed, 9 insertions(+), 7 deletions(-)
Eric Dumazet - Oct. 10, 2011, 3:09 p.m.
Le lundi 10 octobre 2011 à 12:11 +0100, Ian Campbell a écrit :
> I've split this bit out of the skb frag destructor patch since it helps enforce
> the use of the fragment API.
> 
> Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
> ---
>  include/linux/skbuff.h |   10 ++++++----
>  net/core/skbuff.c      |    6 +++---
>  2 files changed, 9 insertions(+), 7 deletions(-)
> 
> diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
> index ac6b05a..f881d75 100644
> --- a/include/linux/skbuff.h
> +++ b/include/linux/skbuff.h
> @@ -135,7 +135,9 @@ struct sk_buff;
>  typedef struct skb_frag_struct skb_frag_t;
>  
>  struct skb_frag_struct {
> -	struct page *page;
> +	struct {
> +		struct page *p;
> +	} page;

Oh well, why dont you rename page to something else, say frag_page ?



--
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
Ian Campbell - Oct. 10, 2011, 3:13 p.m.
On Mon, 2011-10-10 at 16:09 +0100, Eric Dumazet wrote:
> Le lundi 10 octobre 2011 à 12:11 +0100, Ian Campbell a écrit :
> > I've split this bit out of the skb frag destructor patch since it helps enforce
> > the use of the fragment API.
> > 
> > Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
> > ---
> >  include/linux/skbuff.h |   10 ++++++----
> >  net/core/skbuff.c      |    6 +++---
> >  2 files changed, 9 insertions(+), 7 deletions(-)
> > 
> > diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
> > index ac6b05a..f881d75 100644
> > --- a/include/linux/skbuff.h
> > +++ b/include/linux/skbuff.h
> > @@ -135,7 +135,9 @@ struct sk_buff;
> >  typedef struct skb_frag_struct skb_frag_t;
> >  
> >  struct skb_frag_struct {
> > -	struct page *page;
> > +	struct {
> > +		struct page *p;
> > +	} page;
> 
> Oh well, why dont you rename page to something else, say frag_page ?

I looked at renaming this field and the impact was far larger than this
(already huge) set of series.

Keeping the name for the outer struct also has the nice property that
when the struct becomes something like:

	struct {
		struct page *p;
		struct skb_frag_destructor *destr;
	} page;

existing code which does
	fraga->page = fragb->page
will carry the destructor along magically without needing modification.

Ian.

> 
> 
> 


--
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

Patch

diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index ac6b05a..f881d75 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -135,7 +135,9 @@  struct sk_buff;
 typedef struct skb_frag_struct skb_frag_t;
 
 struct skb_frag_struct {
-	struct page *page;
+	struct {
+		struct page *p;
+	} page;
 #if (BITS_PER_LONG > 32) || (PAGE_SIZE >= 65536)
 	__u32 page_offset;
 	__u32 size;
@@ -1149,7 +1151,7 @@  static inline void __skb_fill_page_desc(struct sk_buff *skb, int i,
 {
 	skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
 
-	frag->page		  = page;
+	frag->page.p		  = page;
 	frag->page_offset	  = off;
 	frag->size		  = size;
 }
@@ -1673,7 +1675,7 @@  static inline void netdev_free_page(struct net_device *dev, struct page *page)
  */
 static inline struct page *skb_frag_page(const skb_frag_t *frag)
 {
-	return frag->page;
+	return frag->page.p;
 }
 
 /**
@@ -1759,7 +1761,7 @@  static inline void *skb_frag_address_safe(const skb_frag_t *frag)
  */
 static inline void __skb_frag_set_page(skb_frag_t *frag, struct page *page)
 {
-	frag->page = page;
+	frag->page.p = page;
 	__skb_frag_ref(frag);
 }
 
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 5b2c5f1..6305076 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -657,14 +657,14 @@  int skb_copy_ubufs(struct sk_buff *skb, gfp_t gfp_mask)
 
 	/* skb frags release userspace buffers */
 	for (i = 0; i < skb_shinfo(skb)->nr_frags; i++)
-		put_page(skb_shinfo(skb)->frags[i].page);
+		skb_frag_unref(skb, i);
 
 	uarg->callback(uarg);
 
 	/* skb frags point to kernel buffers */
 	for (i = skb_shinfo(skb)->nr_frags; i > 0; i--) {
-		skb_shinfo(skb)->frags[i - 1].page_offset = 0;
-		skb_shinfo(skb)->frags[i - 1].page = head;
+		__skb_fill_page_desc(skb, i-1, head, 0,
+				     skb_shinfo(skb)->frags[i - 1].size);
 		head = (struct page *)head->private;
 	}