Skip to content

Commit c29a0bc

Browse files
xemuldavem330
authored andcommitted
[SOCK][NETNS]: Add a struct net argument to sock_prot_inuse_add and _get.
This counter is about to become per-proto-and-per-net, so we'll need two arguments to determine which cell in this "table" to work with. All the places, but proc already pass proper net to it - proc will be tuned a bit later. Some indentation with spaces in proc files is done to keep the file coding style consistent. Signed-off-by: Pavel Emelyanov <xemul@openvz.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 8efa6e9 commit c29a0bc

11 files changed

Lines changed: 34 additions & 28 deletions

File tree

‎include/net/sock.h‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -635,10 +635,11 @@ static inline void sk_refcnt_debug_release(const struct sock *sk)
635635

636636
#ifdef CONFIG_PROC_FS
637637
/* Called with local bh disabled */
638-
extern void sock_prot_inuse_add(struct proto *prot, int inc);
639-
extern int sock_prot_inuse_get(struct proto *proto);
638+
extern void sock_prot_inuse_add(struct net *net, struct proto *prot, int inc);
639+
extern int sock_prot_inuse_get(struct net *net, struct proto *proto);
640640
#else
641-
static void inline sock_prot_inuse_add(struct proto *prot, int inc)
641+
static void inline sock_prot_inuse_add(struct net *net, struct proto *prot,
642+
int inc)
642643
{
643644
}
644645
#endif

‎include/net/udp.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ static inline void udp_lib_unhash(struct sock *sk)
115115
write_lock_bh(&udp_hash_lock);
116116
if (sk_del_node_init(sk)) {
117117
inet_sk(sk)->num = 0;
118-
sock_prot_inuse_add(sk->sk_prot, -1);
118+
sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1);
119119
}
120120
write_unlock_bh(&udp_hash_lock);
121121
}

‎net/core/sock.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1949,13 +1949,13 @@ struct prot_inuse {
19491949
static DECLARE_BITMAP(proto_inuse_idx, PROTO_INUSE_NR);
19501950
static DEFINE_PER_CPU(struct prot_inuse, prot_inuse);
19511951

1952-
void sock_prot_inuse_add(struct proto *prot, int val)
1952+
void sock_prot_inuse_add(struct net *net, struct proto *prot, int val)
19531953
{
19541954
__get_cpu_var(prot_inuse).val[prot->inuse_idx] += val;
19551955
}
19561956
EXPORT_SYMBOL_GPL(sock_prot_inuse_add);
19571957

1958-
int sock_prot_inuse_get(struct proto *prot)
1958+
int sock_prot_inuse_get(struct net *net, struct proto *prot)
19591959
{
19601960
int cpu, idx = prot->inuse_idx;
19611961
int res = 0;

‎net/ipv4/inet_hashtables.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ static int __inet_check_established(struct inet_timewait_death_row *death_row,
288288
sk->sk_hash = hash;
289289
BUG_TRAP(sk_unhashed(sk));
290290
__sk_add_node(sk, &head->chain);
291-
sock_prot_inuse_add(sk->sk_prot, 1);
291+
sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
292292
write_unlock(lock);
293293

294294
if (twp) {
@@ -332,7 +332,7 @@ void __inet_hash_nolisten(struct sock *sk)
332332

333333
write_lock(lock);
334334
__sk_add_node(sk, list);
335-
sock_prot_inuse_add(sk->sk_prot, 1);
335+
sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
336336
write_unlock(lock);
337337
}
338338
EXPORT_SYMBOL_GPL(__inet_hash_nolisten);
@@ -354,7 +354,7 @@ static void __inet_hash(struct sock *sk)
354354

355355
inet_listen_wlock(hashinfo);
356356
__sk_add_node(sk, list);
357-
sock_prot_inuse_add(sk->sk_prot, 1);
357+
sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
358358
write_unlock(lock);
359359
wake_up(&hashinfo->lhash_wait);
360360
}
@@ -387,7 +387,7 @@ void inet_unhash(struct sock *sk)
387387
}
388388

389389
if (__sk_del_node_init(sk))
390-
sock_prot_inuse_add(sk->sk_prot, -1);
390+
sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1);
391391
write_unlock_bh(lock);
392392
out:
393393
if (sk->sk_state == TCP_LISTEN)

‎net/ipv4/inet_timewait_sock.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void __inet_twsk_hashdance(struct inet_timewait_sock *tw, struct sock *sk,
9191

9292
/* Step 2: Remove SK from established hash. */
9393
if (__sk_del_node_init(sk))
94-
sock_prot_inuse_add(sk->sk_prot, -1);
94+
sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1);
9595

9696
/* Step 3: Hash TW into TIMEWAIT chain. */
9797
inet_twsk_add_node(tw, &ehead->twchain);

‎net/ipv4/proc.c‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,17 @@ static int sockstat_seq_show(struct seq_file *seq, void *v)
5353
{
5454
socket_seq_show(seq);
5555
seq_printf(seq, "TCP: inuse %d orphan %d tw %d alloc %d mem %d\n",
56-
sock_prot_inuse_get(&tcp_prot),
56+
sock_prot_inuse_get(&init_net, &tcp_prot),
5757
atomic_read(&tcp_orphan_count),
5858
tcp_death_row.tw_count, atomic_read(&tcp_sockets_allocated),
5959
atomic_read(&tcp_memory_allocated));
60-
seq_printf(seq, "UDP: inuse %d mem %d\n", sock_prot_inuse_get(&udp_prot),
60+
seq_printf(seq, "UDP: inuse %d mem %d\n",
61+
sock_prot_inuse_get(&init_net, &udp_prot),
6162
atomic_read(&udp_memory_allocated));
62-
seq_printf(seq, "UDPLITE: inuse %d\n", sock_prot_inuse_get(&udplite_prot));
63-
seq_printf(seq, "RAW: inuse %d\n", sock_prot_inuse_get(&raw_prot));
63+
seq_printf(seq, "UDPLITE: inuse %d\n",
64+
sock_prot_inuse_get(&init_net, &udplite_prot));
65+
seq_printf(seq, "RAW: inuse %d\n",
66+
sock_prot_inuse_get(&init_net, &raw_prot));
6467
seq_printf(seq, "FRAG: inuse %d memory %d\n",
6568
ip_frag_nqueues(&init_net), ip_frag_mem(&init_net));
6669
return 0;

‎net/ipv4/raw.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ void raw_hash_sk(struct sock *sk)
9393

9494
write_lock_bh(&h->lock);
9595
sk_add_node(sk, head);
96-
sock_prot_inuse_add(sk->sk_prot, 1);
96+
sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
9797
write_unlock_bh(&h->lock);
9898
}
9999
EXPORT_SYMBOL_GPL(raw_hash_sk);
@@ -104,7 +104,7 @@ void raw_unhash_sk(struct sock *sk)
104104

105105
write_lock_bh(&h->lock);
106106
if (sk_del_node_init(sk))
107-
sock_prot_inuse_add(sk->sk_prot, -1);
107+
sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1);
108108
write_unlock_bh(&h->lock);
109109
}
110110
EXPORT_SYMBOL_GPL(raw_unhash_sk);

‎net/ipv4/udp.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ int udp_lib_get_port(struct sock *sk, unsigned short snum,
231231
if (sk_unhashed(sk)) {
232232
head = &udptable[snum & (UDP_HTABLE_SIZE - 1)];
233233
sk_add_node(sk, head);
234-
sock_prot_inuse_add(sk->sk_prot, 1);
234+
sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
235235
}
236236
error = 0;
237237
fail:

‎net/ipv6/inet6_hashtables.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void __inet6_hash(struct sock *sk)
4343
}
4444

4545
__sk_add_node(sk, list);
46-
sock_prot_inuse_add(sk->sk_prot, 1);
46+
sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
4747
write_unlock(lock);
4848
}
4949
EXPORT_SYMBOL(__inet6_hash);
@@ -204,7 +204,7 @@ static int __inet6_check_established(struct inet_timewait_death_row *death_row,
204204
BUG_TRAP(sk_unhashed(sk));
205205
__sk_add_node(sk, &head->chain);
206206
sk->sk_hash = hash;
207-
sock_prot_inuse_add(sk->sk_prot, 1);
207+
sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
208208
write_unlock(lock);
209209

210210
if (twp != NULL) {

‎net/ipv6/ipv6_sockglue.c‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,11 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
155155

156156
if (sk->sk_protocol == IPPROTO_TCP) {
157157
struct inet_connection_sock *icsk = inet_csk(sk);
158+
struct net *net = sock_net(sk);
158159

159160
local_bh_disable();
160-
sock_prot_inuse_add(sk->sk_prot, -1);
161-
sock_prot_inuse_add(&tcp_prot, 1);
161+
sock_prot_inuse_add(net, sk->sk_prot, -1);
162+
sock_prot_inuse_add(net, &tcp_prot, 1);
162163
local_bh_enable();
163164
sk->sk_prot = &tcp_prot;
164165
icsk->icsk_af_ops = &ipv4_specific;
@@ -167,12 +168,13 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
167168
tcp_sync_mss(sk, icsk->icsk_pmtu_cookie);
168169
} else {
169170
struct proto *prot = &udp_prot;
171+
struct net *net = sock_net(sk);
170172

171173
if (sk->sk_protocol == IPPROTO_UDPLITE)
172174
prot = &udplite_prot;
173175
local_bh_disable();
174-
sock_prot_inuse_add(sk->sk_prot, -1);
175-
sock_prot_inuse_add(prot, 1);
176+
sock_prot_inuse_add(net, sk->sk_prot, -1);
177+
sock_prot_inuse_add(net, prot, 1);
176178
local_bh_enable();
177179
sk->sk_prot = prot;
178180
sk->sk_socket->ops = &inet_dgram_ops;

0 commit comments

Comments
 (0)