Hi David, Please consider pulling from:
rsync://rsync.kernel.org/pub/scm/linux/kernel/git/acme/net-2.6.git/ -- - Arnaldo
tree b2d1a14c34bd0880d421a31a909de6a9c2400f75 parent 18cdbd737f99ac20a3cd9a700d5f616a7db2ebd1 author Arnaldo Carvalho de Melo <[EMAIL PROTECTED]> 1121896161 -0300 committer Arnaldo Carvalho de Melo <[EMAIL PROTECTED]> 1121896161 -0300 [NET] cleanup INET_REFCNT_DEBUG code And also the copy'n'pasted equivalents in some other protocols, taking advantage that all protocols now use proto_register and have sk->sk_prot at least minimally used. Signed-off-by: Arnaldo Carvalho de Melo <[EMAIL PROTECTED]> Signed-off-by: David S. Miller <[EMAIL PROTECTED]> ------------------------------------------------------------------------------ include/net/inet_common.h | 1 - include/net/sock.h | 30 ++++++++++++++++++++++++++++++ include/net/tcp.h | 2 +- net/core/sock.c | 6 +----- net/ipv4/af_inet.c | 25 ++++++------------------- net/ipv4/tcp.c | 7 +------ net/ipv4/tcp_minisocks.c | 6 ++---- net/ipv6/af_inet6.c | 23 +++-------------------- net/ipv6/ipv6_sockglue.c | 4 +--- net/ipv6/tcp_ipv6.c | 12 ------------ net/ipx/af_ipx.c | 21 +++------------------ net/ipx/ipx_proc.c | 11 ++--------- net/llc/af_llc.c | 1 + net/llc/llc_conn.c | 24 ++---------------------- net/packet/af_packet.c | 11 ++--------- net/sctp/ipv6.c | 5 +---- net/sctp/protocol.c | 4 +--- 17 files changed, 57 insertions(+), 136 deletions(-) ------------------------------------------------------------------------------ diff --git a/include/net/inet_common.h b/include/net/inet_common.h --- a/include/net/inet_common.h +++ b/include/net/inet_common.h @@ -29,7 +29,6 @@ extern unsigned int inet_poll(struct fi extern int inet_listen(struct socket *sock, int backlog); extern void inet_sock_destruct(struct sock *sk); -extern atomic_t inet_sock_nr; extern int inet_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len); diff --git a/include/net/sock.h b/include/net/sock.h --- a/include/net/sock.h +++ b/include/net/sock.h @@ -486,6 +486,8 @@ extern int sk_wait_data(struct sock *sk, struct request_sock_ops; +#undef SOCK_REFCNT_DEBUG + /* Networking protocol blocks we attach to sockets. * socket layer -> transport layer interface * transport -> network interface is defined by struct inet_proto @@ -561,8 +563,36 @@ struct proto { int inuse; u8 __pad[SMP_CACHE_BYTES - sizeof(int)]; } stats[NR_CPUS]; +#ifdef SOCK_REFCNT_DEBUG + atomic_t socks; +#endif }; +#ifdef SOCK_REFCNT_DEBUG +static inline void sk_refcnt_debug_inc(struct sock *sk) +{ + atomic_inc(&sk->sk_prot->socks); +} + +static inline void sk_refcnt_debug_dec(struct sock *sk) +{ + atomic_dec(&sk->sk_prot->socks); + printk(KERN_DEBUG "%s socket %p released, %d are still alive\n", + sk->sk_prot->name, sk, atomic_read(&sk->sk_prot->socks)); +} + +static inline void sk_refcnt_debug_release(struct sock *sk) +{ + if (atomic_read(&sk->sk_refcnt) != 1) + printk(KERN_DEBUG "Destruction of the %s socket %p delayed, refcnt=%d\n", + sk->sk_prot->name, sk, atomic_read(&sk->sk_refcnt)); +} +#else /* SOCK_REFCNT_DEBUG */ +#define sk_refcnt_debug_inc(sk) +#define sk_refcnt_debug_dec(sk) +#define sk_refcnt_debug_release(sk) +#endif /* SOCK_REFCNT_DEBUG */ + extern int proto_register(struct proto *prot, int alloc_slab); extern void proto_unregister(struct proto *prot); diff --git a/include/net/tcp.h b/include/net/tcp.h --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -306,7 +306,7 @@ extern kmem_cache_t *tcp_timewait_cachep static inline void tcp_tw_put(struct tcp_tw_bucket *tw) { if (atomic_dec_and_test(&tw->tw_refcnt)) { -#ifdef INET_REFCNT_DEBUG +#ifdef SOCK_REFCNT_DEBUG printk(KERN_DEBUG "tw_bucket %p released\n", tw); #endif kmem_cache_free(tcp_timewait_cachep, tw); diff --git a/net/core/sock.c b/net/core/sock.c --- a/net/core/sock.c +++ b/net/core/sock.c @@ -1352,11 +1352,7 @@ void sk_common_release(struct sock *sk) xfrm_sk_free_policy(sk); -#ifdef INET_REFCNT_DEBUG - if (atomic_read(&sk->sk_refcnt) != 1) - printk(KERN_DEBUG "Destruction of the socket %p delayed, c=%d\n", - sk, atomic_read(&sk->sk_refcnt)); -#endif + sk_refcnt_debug_release(sk); sock_put(sk); } diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c --- a/net/ipv4/af_inet.c +++ b/net/ipv4/af_inet.c @@ -114,10 +114,6 @@ DEFINE_SNMP_STAT(struct linux_mib, net_statistics); -#ifdef INET_REFCNT_DEBUG -atomic_t inet_sock_nr; -#endif - extern void ip_mc_drop_socket(struct sock *sk); /* The inetsw table contains everything that inet_create needs to @@ -136,12 +132,13 @@ void inet_sock_destruct(struct sock *sk) __skb_queue_purge(&sk->sk_error_queue); if (sk->sk_type == SOCK_STREAM && sk->sk_state != TCP_CLOSE) { - printk("Attempt to release TCP socket in state %d %p\n", - sk->sk_state, sk); + printk(KERN_ERR "%s: Attempt to release %s socket in state %d %p\n", + __FUNCTION__, sk->sk_prot->name, sk->sk_state, sk); return; } if (!sock_flag(sk, SOCK_DEAD)) { - printk("Attempt to release alive inet socket %p\n", sk); + printk(KERN_ERR "%s: Attempt to release alive %s socket %p\n", + __FUNCTION__, sk->sk_prot->name, sk); return; } @@ -153,11 +150,7 @@ void inet_sock_destruct(struct sock *sk) if (inet->opt) kfree(inet->opt); dst_release(sk->sk_dst_cache); -#ifdef INET_REFCNT_DEBUG - atomic_dec(&inet_sock_nr); - printk(KERN_DEBUG "INET socket %p released, %d are still alive\n", - sk, atomic_read(&inet_sock_nr)); -#endif + sk_refcnt_debug_dec(sk); } /* @@ -317,9 +310,7 @@ static int inet_create(struct socket *so inet->mc_index = 0; inet->mc_list = NULL; -#ifdef INET_REFCNT_DEBUG - atomic_inc(&inet_sock_nr); -#endif + sk_refcnt_debug_inc(sk); if (inet->num) { /* It assumes that any protocol which allows @@ -1205,7 +1196,3 @@ EXPORT_SYMBOL(inet_stream_ops); EXPORT_SYMBOL(inet_unregister_protosw); EXPORT_SYMBOL(net_statistics); EXPORT_SYMBOL(sysctl_ip_nonlocal_bind); - -#ifdef INET_REFCNT_DEBUG -EXPORT_SYMBOL(inet_sock_nr); -#endif diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -1580,12 +1580,7 @@ void tcp_destroy_sock(struct sock *sk) xfrm_sk_free_policy(sk); -#ifdef INET_REFCNT_DEBUG - if (atomic_read(&sk->sk_refcnt) != 1) { - printk(KERN_DEBUG "Destruction TCP %p delayed, c=%d\n", - sk, atomic_read(&sk->sk_refcnt)); - } -#endif + sk_refcnt_debug_release(sk); atomic_dec(&tcp_orphan_count); sock_put(sk); diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c --- a/net/ipv4/tcp_minisocks.c +++ b/net/ipv4/tcp_minisocks.c @@ -84,7 +84,7 @@ static void tcp_timewait_kill(struct tcp tcp_bucket_destroy(tb); spin_unlock(&bhead->lock); -#ifdef INET_REFCNT_DEBUG +#ifdef SOCK_REFCNT_DEBUG if (atomic_read(&tw->tw_refcnt) != 1) { printk(KERN_DEBUG "tw_bucket %p refcnt=%d\n", tw, atomic_read(&tw->tw_refcnt)); @@ -799,9 +799,7 @@ struct sock *tcp_create_openreq_child(st newsk->sk_err = 0; newsk->sk_priority = 0; atomic_set(&newsk->sk_refcnt, 2); -#ifdef INET_REFCNT_DEBUG - atomic_inc(&inet_sock_nr); -#endif + sk_refcnt_debug_inc(newsk); atomic_inc(&tcp_sockets_allocated); if (sock_flag(newsk, SOCK_KEEPOPEN)) diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c --- a/net/ipv6/af_inet6.c +++ b/net/ipv6/af_inet6.c @@ -85,26 +85,12 @@ extern void if6_proc_exit(void); int sysctl_ipv6_bindv6only; -#ifdef INET_REFCNT_DEBUG -atomic_t inet6_sock_nr; -EXPORT_SYMBOL(inet6_sock_nr); -#endif - /* The inetsw table contains everything that inet_create needs to * build a new socket. */ static struct list_head inetsw6[SOCK_MAX]; static DEFINE_SPINLOCK(inetsw6_lock); -static void inet6_sock_destruct(struct sock *sk) -{ - inet_sock_destruct(sk); - -#ifdef INET_REFCNT_DEBUG - atomic_dec(&inet6_sock_nr); -#endif -} - static __inline__ struct ipv6_pinfo *inet6_sk_generic(struct sock *sk) { const int offset = sk->sk_prot->obj_size - sizeof(struct ipv6_pinfo); @@ -185,7 +171,7 @@ static int inet6_create(struct socket *s inet->hdrincl = 1; } - sk->sk_destruct = inet6_sock_destruct; + sk->sk_destruct = inet_sock_destruct; sk->sk_family = PF_INET6; sk->sk_protocol = protocol; @@ -213,11 +199,8 @@ static int inet6_create(struct socket *s else inet->pmtudisc = IP_PMTUDISC_WANT; - -#ifdef INET_REFCNT_DEBUG - atomic_inc(&inet6_sock_nr); - atomic_inc(&inet_sock_nr); -#endif + sk_refcnt_debug_inc(sk); + if (inet->num) { /* It assumes that any protocol which allows * the user to assign a number at socket diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c --- a/net/ipv6/ipv6_sockglue.c +++ b/net/ipv6/ipv6_sockglue.c @@ -192,9 +192,7 @@ int ipv6_setsockopt(struct sock *sk, int kfree_skb(pktopt); sk->sk_destruct = inet_sock_destruct; -#ifdef INET_REFCNT_DEBUG - atomic_dec(&inet6_sock_nr); -#endif + sk_refcnt_debug_dec(sk); module_put(THIS_MODULE); retv = 0; break; diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -1402,13 +1402,6 @@ static struct sock * tcp_v6_syn_recv_soc newnp->mcast_oif = tcp_v6_iif(skb); newnp->mcast_hops = skb->nh.ipv6h->hop_limit; - /* Charge newly allocated IPv6 socket. Though it is mapped, - * it is IPv6 yet. - */ -#ifdef INET_REFCNT_DEBUG - atomic_inc(&inet6_sock_nr); -#endif - /* It is tricky place. Until this moment IPv4 tcp worked with IPv6 af_tcp.af_specific. Sync it now. @@ -1462,11 +1455,6 @@ static struct sock * tcp_v6_syn_recv_soc if (newsk == NULL) goto out; - /* Charge newly allocated IPv6 socket */ -#ifdef INET_REFCNT_DEBUG - atomic_inc(&inet6_sock_nr); -#endif - ip6_dst_store(newsk, dst, NULL); newsk->sk_route_caps = dst->dev->features & ~(NETIF_F_IP_CSUM | NETIF_F_TSO); diff --git a/net/ipx/af_ipx.c b/net/ipx/af_ipx.c --- a/net/ipx/af_ipx.c +++ b/net/ipx/af_ipx.c @@ -92,11 +92,6 @@ extern int ipxrtr_route_skb(struct sk_bu extern struct ipx_route *ipxrtr_lookup(__u32 net); extern int ipxrtr_ioctl(unsigned int cmd, void __user *arg); -#undef IPX_REFCNT_DEBUG -#ifdef IPX_REFCNT_DEBUG -atomic_t ipx_sock_nr; -#endif - struct ipx_interface *ipx_interfaces_head(void) { struct ipx_interface *rc = NULL; @@ -151,14 +146,7 @@ static void ipx_destroy_socket(struct so { ipx_remove_socket(sk); skb_queue_purge(&sk->sk_receive_queue); -#ifdef IPX_REFCNT_DEBUG - atomic_dec(&ipx_sock_nr); - printk(KERN_DEBUG "IPX socket %p released, %d are still alive\n", sk, - atomic_read(&ipx_sock_nr)); - if (atomic_read(&sk->sk_refcnt) != 1) - printk(KERN_DEBUG "Destruction sock ipx %p delayed, cnt=%d\n", - sk, atomic_read(&sk->sk_refcnt)); -#endif + sk_refcnt_debug_dec(sk); sock_put(sk); } @@ -1369,11 +1357,7 @@ static int ipx_create(struct socket *soc sk = sk_alloc(PF_IPX, GFP_KERNEL, &ipx_proto, 1); if (!sk) goto out; -#ifdef IPX_REFCNT_DEBUG - atomic_inc(&ipx_sock_nr); - printk(KERN_DEBUG "IPX socket %p created, now we have %d alive\n", sk, - atomic_read(&ipx_sock_nr)); -#endif + sk_refcnt_debug_inc(sk); sock_init_data(sock, sk); sk->sk_no_check = 1; /* Checksum off by default */ sock->ops = &ipx_dgram_ops; @@ -1394,6 +1378,7 @@ static int ipx_release(struct socket *so sock_set_flag(sk, SOCK_DEAD); sock->sk = NULL; + sk_refcnt_debug_release(sk); ipx_destroy_socket(sk); out: return 0; diff --git a/net/ipx/ipx_proc.c b/net/ipx/ipx_proc.c --- a/net/ipx/ipx_proc.c +++ b/net/ipx/ipx_proc.c @@ -65,11 +65,7 @@ static int ipx_seq_interface_show(struct if (v == SEQ_START_TOKEN) { seq_puts(seq, "Network Node_Address Primary Device " - "Frame_Type"); -#ifdef IPX_REFCNT_DEBUG - seq_puts(seq, " refcnt"); -#endif - seq_puts(seq, "\n"); + "Frame_Type refcnt\n"); goto out; } @@ -81,10 +77,7 @@ static int ipx_seq_interface_show(struct seq_printf(seq, "%-9s", i == ipx_primary_net ? "Yes" : "No"); seq_printf(seq, "%-11s", ipx_device_name(i)); seq_printf(seq, "%-9s", ipx_frame_name(i->if_dlink_type)); -#ifdef IPX_REFCNT_DEBUG - seq_printf(seq, "%6d", atomic_read(&i->refcnt)); -#endif - seq_puts(seq, "\n"); + seq_printf(seq, "%6d\n", atomic_read(&i->refcnt)); out: return 0; } diff --git a/net/llc/af_llc.c b/net/llc/af_llc.c --- a/net/llc/af_llc.c +++ b/net/llc/af_llc.c @@ -195,6 +195,7 @@ static int llc_ui_release(struct socket } if (llc->dev) dev_put(llc->dev); + sk_refcnt_debug_release(sk); sock_put(sk); llc_sk_free(sk); out: diff --git a/net/llc/llc_conn.c b/net/llc/llc_conn.c --- a/net/llc/llc_conn.c +++ b/net/llc/llc_conn.c @@ -712,11 +712,6 @@ drop: kfree_skb(skb); } -#undef LLC_REFCNT_DEBUG -#ifdef LLC_REFCNT_DEBUG -static atomic_t llc_sock_nr; -#endif - /** * llc_release_sockets - releases all sockets in a sap * @sap: sap to release its sockets @@ -838,11 +833,7 @@ struct sock *llc_sk_alloc(int family, in goto out; llc_sk_init(sk); sock_init_data(NULL, sk); -#ifdef LLC_REFCNT_DEBUG - atomic_inc(&llc_sock_nr); - printk(KERN_DEBUG "LLC socket %p created in %s, now we have %d alive\n", sk, - __FUNCTION__, atomic_read(&llc_sock_nr)); -#endif + sk_refcnt_debug_inc(sk); out: return sk; } @@ -868,18 +859,7 @@ void llc_sk_free(struct sock *sk) skb_queue_purge(&sk->sk_receive_queue); skb_queue_purge(&sk->sk_write_queue); skb_queue_purge(&llc->pdu_unack_q); -#ifdef LLC_REFCNT_DEBUG - if (atomic_read(&sk->sk_refcnt) != 1) { - printk(KERN_DEBUG "Destruction of LLC sock %p delayed in %s, cnt=%d\n", - sk, __FUNCTION__, atomic_read(&sk->sk_refcnt)); - printk(KERN_DEBUG "%d LLC sockets are still alive\n", - atomic_read(&llc_sock_nr)); - } else { - atomic_dec(&llc_sock_nr); - printk(KERN_DEBUG "LLC socket %p released in %s, %d are still alive\n", sk, - __FUNCTION__, atomic_read(&llc_sock_nr)); - } -#endif + sk_refcnt_debug_dec(sk); sock_put(sk); } diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -148,9 +148,6 @@ dev->hard_header == NULL (ll header is a static HLIST_HEAD(packet_sklist); static DEFINE_RWLOCK(packet_sklist_lock); -static atomic_t packet_socks_nr; - - /* Private packet socket structures. */ #ifdef CONFIG_PACKET_MULTICAST @@ -228,11 +225,7 @@ static void packet_sock_destruct(struct printk("Attempt to release alive packet socket: %p\n", sk); return; } - - atomic_dec(&packet_socks_nr); -#ifdef PACKET_REFCNT_DEBUG - printk(KERN_DEBUG "PACKET socket %p is free, %d are alive\n", sk, atomic_read(&packet_socks_nr)); -#endif + sk_refcnt_debug_dec(sk); } @@ -1005,8 +998,8 @@ static int packet_create(struct socket * po->num = protocol; sk->sk_destruct = packet_sock_destruct; - atomic_inc(&packet_socks_nr); + sk_refcnt_debug_inc(sk); /* * Attach a protocol block */ diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c --- a/net/sctp/ipv6.c +++ b/net/sctp/ipv6.c @@ -642,10 +642,7 @@ static struct sock *sctp_v6_create_accep else newinet->pmtudisc = IP_PMTUDISC_WANT; -#ifdef INET_REFCNT_DEBUG - atomic_inc(&inet6_sock_nr); - atomic_inc(&inet_sock_nr); -#endif + sk_refcnt_debug_inc(newsk); if (newsk->sk_prot->init(newsk)) { sk_common_release(newsk); diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c --- a/net/sctp/protocol.c +++ b/net/sctp/protocol.c @@ -593,9 +593,7 @@ static struct sock *sctp_v4_create_accep newinet->mc_index = 0; newinet->mc_list = NULL; -#ifdef INET_REFCNT_DEBUG - atomic_inc(&inet_sock_nr); -#endif + sk_refcnt_debug_inc(newsk); if (newsk->sk_prot->init(newsk)) { sk_common_release(newsk);