[NET] generalise tcp_set_owner_r and tcp_rfree

Will be used by the poor cousins
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@conectiva.com.br>
parent ce2ae3b7
...@@ -436,6 +436,16 @@ static inline int sk_stream_memory_free(struct sock *sk) ...@@ -436,6 +436,16 @@ static inline int sk_stream_memory_free(struct sock *sk)
return sk->sk_wmem_queued < sk->sk_sndbuf; return sk->sk_wmem_queued < sk->sk_sndbuf;
} }
extern void sk_stream_rfree(struct sk_buff *skb);
static inline void sk_stream_set_owner_r(struct sk_buff *skb, struct sock *sk)
{
skb->sk = sk;
skb->destructor = sk_stream_rfree;
atomic_add(skb->truesize, &sk->sk_rmem_alloc);
sk->sk_forward_alloc -= skb->truesize;
}
/* The per-socket spinlock must be held here. */ /* The per-socket spinlock must be held here. */
#define sk_add_backlog(__sk, __skb) \ #define sk_add_backlog(__sk, __skb) \
do { if (!(__sk)->sk_backlog.tail) { \ do { if (!(__sk)->sk_backlog.tail) { \
......
...@@ -1955,16 +1955,6 @@ static inline void tcp_writequeue_purge(struct sock *sk) ...@@ -1955,16 +1955,6 @@ static inline void tcp_writequeue_purge(struct sock *sk)
tcp_mem_reclaim(sk); tcp_mem_reclaim(sk);
} }
extern void tcp_rfree(struct sk_buff *skb);
static inline void tcp_set_owner_r(struct sk_buff *skb, struct sock *sk)
{
skb->sk = sk;
skb->destructor = tcp_rfree;
atomic_add(skb->truesize, &sk->sk_rmem_alloc);
sk->sk_forward_alloc -= skb->truesize;
}
extern void tcp_listen_wlock(void); extern void tcp_listen_wlock(void);
/* - We may sleep inside this lock. /* - We may sleep inside this lock.
......
...@@ -167,3 +167,13 @@ int sk_stream_wait_memory(struct sock *sk, long *timeo_p) ...@@ -167,3 +167,13 @@ int sk_stream_wait_memory(struct sock *sk, long *timeo_p)
} }
EXPORT_SYMBOL(sk_stream_wait_memory); EXPORT_SYMBOL(sk_stream_wait_memory);
void sk_stream_rfree(struct sk_buff *skb)
{
struct sock *sk = skb->sk;
atomic_sub(skb->truesize, &sk->sk_rmem_alloc);
sk->sk_forward_alloc += skb->truesize;
}
EXPORT_SYMBOL(sk_stream_rfree);
...@@ -360,14 +360,6 @@ void __tcp_mem_reclaim(struct sock *sk) ...@@ -360,14 +360,6 @@ void __tcp_mem_reclaim(struct sock *sk)
} }
} }
void tcp_rfree(struct sk_buff *skb)
{
struct sock *sk = skb->sk;
atomic_sub(skb->truesize, &sk->sk_rmem_alloc);
sk->sk_forward_alloc += skb->truesize;
}
/* /*
* LISTEN is a special case for poll.. * LISTEN is a special case for poll..
*/ */
......
...@@ -3453,7 +3453,7 @@ static void tcp_data_queue(struct sock *sk, struct sk_buff *skb) ...@@ -3453,7 +3453,7 @@ static void tcp_data_queue(struct sock *sk, struct sk_buff *skb)
if (tcp_prune_queue(sk) < 0 || !tcp_rmem_schedule(sk, skb)) if (tcp_prune_queue(sk) < 0 || !tcp_rmem_schedule(sk, skb))
goto drop; goto drop;
} }
tcp_set_owner_r(skb, sk); sk_stream_set_owner_r(skb, sk);
__skb_queue_tail(&sk->sk_receive_queue, skb); __skb_queue_tail(&sk->sk_receive_queue, skb);
} }
tp->rcv_nxt = TCP_SKB_CB(skb)->end_seq; tp->rcv_nxt = TCP_SKB_CB(skb)->end_seq;
...@@ -3534,7 +3534,7 @@ static void tcp_data_queue(struct sock *sk, struct sk_buff *skb) ...@@ -3534,7 +3534,7 @@ static void tcp_data_queue(struct sock *sk, struct sk_buff *skb)
SOCK_DEBUG(sk, "out of order segment: rcv_next %X seq %X - %X\n", SOCK_DEBUG(sk, "out of order segment: rcv_next %X seq %X - %X\n",
tp->rcv_nxt, TCP_SKB_CB(skb)->seq, TCP_SKB_CB(skb)->end_seq); tp->rcv_nxt, TCP_SKB_CB(skb)->seq, TCP_SKB_CB(skb)->end_seq);
tcp_set_owner_r(skb, sk); sk_stream_set_owner_r(skb, sk);
if (!skb_peek(&tp->out_of_order_queue)) { if (!skb_peek(&tp->out_of_order_queue)) {
/* Initial out of order segment, build 1 SACK. */ /* Initial out of order segment, build 1 SACK. */
...@@ -3673,7 +3673,7 @@ tcp_collapse(struct sock *sk, struct sk_buff *head, ...@@ -3673,7 +3673,7 @@ tcp_collapse(struct sock *sk, struct sk_buff *head,
memcpy(nskb->cb, skb->cb, sizeof(skb->cb)); memcpy(nskb->cb, skb->cb, sizeof(skb->cb));
TCP_SKB_CB(nskb)->seq = TCP_SKB_CB(nskb)->end_seq = start; TCP_SKB_CB(nskb)->seq = TCP_SKB_CB(nskb)->end_seq = start;
__skb_insert(nskb, skb->prev, skb, skb->list); __skb_insert(nskb, skb->prev, skb, skb->list);
tcp_set_owner_r(nskb, sk); sk_stream_set_owner_r(nskb, sk);
/* Copy data, releasing collapsed skbs. */ /* Copy data, releasing collapsed skbs. */
while (copy > 0) { while (copy > 0) {
...@@ -4234,7 +4234,7 @@ int tcp_rcv_established(struct sock *sk, struct sk_buff *skb, ...@@ -4234,7 +4234,7 @@ int tcp_rcv_established(struct sock *sk, struct sk_buff *skb,
/* Bulk data transfer: receiver */ /* Bulk data transfer: receiver */
__skb_pull(skb,tcp_header_len); __skb_pull(skb,tcp_header_len);
__skb_queue_tail(&sk->sk_receive_queue, skb); __skb_queue_tail(&sk->sk_receive_queue, skb);
tcp_set_owner_r(skb, sk); sk_stream_set_owner_r(skb, sk);
tp->rcv_nxt = TCP_SKB_CB(skb)->end_seq; tp->rcv_nxt = TCP_SKB_CB(skb)->end_seq;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment