Skip to content

Commit a0a53c8

Browse files
dlunevdavem330
authored andcommitted
[NETNS]: struct net content re-work (v3)
Recently David Miller and Herbert Xu pointed out that struct net becomes overbloated and un-maintainable. There are two solutions: - provide a pointer to a network subsystem definition from struct net. This costs an additional dereferrence - place sub-system definition into the structure itself. This will speedup run-time access at the cost of recompilation time The second approach looks better for us. Other sub-systems will follow. Signed-off-by: Denis V. Lunev <den@openvz.org> Acked-by: Daniel Lezcano <dlezcano@fr.ibm.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 27147c9 commit a0a53c8

4 files changed

Lines changed: 24 additions & 11 deletions

File tree

‎include/net/net_namespace.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include <linux/workqueue.h>
99
#include <linux/list.h>
1010

11+
#include <net/netns/unix.h>
12+
1113
struct proc_dir_entry;
1214
struct net_device;
1315
struct sock;
@@ -45,9 +47,7 @@ struct net {
4547
rwlock_t packet_sklist_lock;
4648
struct hlist_head packet_sklist;
4749

48-
/* unix sockets */
49-
int sysctl_unix_max_dgram_qlen;
50-
struct ctl_table_header *unix_ctl;
50+
struct netns_unix unx;
5151
};
5252

5353
#ifdef CONFIG_NET

‎include/net/netns/unix.h‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Unix network namespace
3+
*/
4+
#ifndef __NETNS_UNIX_H__
5+
#define __NETNS_UNIX_H__
6+
7+
struct ctl_table_header;
8+
struct netns_unix {
9+
int sysctl_max_dgram_qlen;
10+
struct ctl_table_header *ctl;
11+
};
12+
13+
#endif /* __NETNS_UNIX_H__ */

‎net/unix/af_unix.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ static struct sock * unix_create1(struct net *net, struct socket *sock)
592592
&af_unix_sk_receive_queue_lock_key);
593593

594594
sk->sk_write_space = unix_write_space;
595-
sk->sk_max_ack_backlog = net->sysctl_unix_max_dgram_qlen;
595+
sk->sk_max_ack_backlog = net->unx.sysctl_max_dgram_qlen;
596596
sk->sk_destruct = unix_sock_destructor;
597597
u = unix_sk(sk);
598598
u->dentry = NULL;
@@ -2138,7 +2138,7 @@ static int unix_net_init(struct net *net)
21382138
{
21392139
int error = -ENOMEM;
21402140

2141-
net->sysctl_unix_max_dgram_qlen = 10;
2141+
net->unx.sysctl_max_dgram_qlen = 10;
21422142
if (unix_sysctl_register(net))
21432143
goto out;
21442144

‎net/unix/sysctl_net_unix.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ static ctl_table unix_table[] = {
1818
{
1919
.ctl_name = NET_UNIX_MAX_DGRAM_QLEN,
2020
.procname = "max_dgram_qlen",
21-
.data = &init_net.sysctl_unix_max_dgram_qlen,
21+
.data = &init_net.unx.sysctl_max_dgram_qlen,
2222
.maxlen = sizeof(int),
2323
.mode = 0644,
2424
.proc_handler = &proc_dointvec
@@ -40,9 +40,9 @@ int unix_sysctl_register(struct net *net)
4040
if (table == NULL)
4141
goto err_alloc;
4242

43-
table[0].data = &net->sysctl_unix_max_dgram_qlen;
44-
net->unix_ctl = register_net_sysctl_table(net, unix_path, table);
45-
if (net->unix_ctl == NULL)
43+
table[0].data = &net->unx.sysctl_max_dgram_qlen;
44+
net->unx.ctl = register_net_sysctl_table(net, unix_path, table);
45+
if (net->unx.ctl == NULL)
4646
goto err_reg;
4747

4848
return 0;
@@ -57,8 +57,8 @@ void unix_sysctl_unregister(struct net *net)
5757
{
5858
struct ctl_table *table;
5959

60-
table = net->unix_ctl->ctl_table_arg;
61-
unregister_sysctl_table(net->unix_ctl);
60+
table = net->unx.ctl->ctl_table_arg;
61+
unregister_sysctl_table(net->unx.ctl);
6262
kfree(table);
6363
}
6464

0 commit comments

Comments
 (0)