aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2008-07-14 21:22:20 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2008-07-26 20:53:08 -0400
commit734550921e9b7ab924a43aa3d0bd4239dac4fbf1 (patch)
tree7be4b0808ba9860f1d953b45120262a277866021
parent7ac6cd653d7c31ad6b7bb5b88c549c4ebf628c34 (diff)
[PATCH] beginning of sysctl cleanup - ctl_table_set
New object: set of sysctls [currently - root and per-net-ns]. Contains: pointer to parent set, list of tables and "should I see this set?" method (->is_seen(set)). Current lists of tables are subsumed by that; net-ns contains such a beast. ->lookup() for ctl_table_root returns pointer to ctl_table_set instead of that to ->list of that ctl_table_set. [folded compile fixes by rdd for configs without sysctl] Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
-rw-r--r--include/linux/sysctl.h15
-rw-r--r--include/net/net_namespace.h4
-rw-r--r--kernel/sysctl.c41
-rw-r--r--net/sysctl_net.c22
4 files changed, 57 insertions, 25 deletions
diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
index 24141b4d1a11..c1e0cf408af9 100644
--- a/include/linux/sysctl.h
+++ b/include/linux/sysctl.h
@@ -947,6 +947,16 @@ struct ctl_table;
947struct nsproxy; 947struct nsproxy;
948struct ctl_table_root; 948struct ctl_table_root;
949 949
950struct ctl_table_set {
951 struct list_head list;
952 struct ctl_table_set *parent;
953 int (*is_seen)(struct ctl_table_set *);
954};
955
956extern void setup_sysctl_set(struct ctl_table_set *p,
957 struct ctl_table_set *parent,
958 int (*is_seen)(struct ctl_table_set *));
959
950extern struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev); 960extern struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev);
951extern struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces, 961extern struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
952 struct ctl_table_header *prev); 962 struct ctl_table_header *prev);
@@ -1049,8 +1059,8 @@ struct ctl_table
1049 1059
1050struct ctl_table_root { 1060struct ctl_table_root {
1051 struct list_head root_list; 1061 struct list_head root_list;
1052 struct list_head header_list; 1062 struct ctl_table_set default_set;
1053 struct list_head *(*lookup)(struct ctl_table_root *root, 1063 struct ctl_table_set *(*lookup)(struct ctl_table_root *root,
1054 struct nsproxy *namespaces); 1064 struct nsproxy *namespaces);
1055 int (*permissions)(struct ctl_table_root *root, 1065 int (*permissions)(struct ctl_table_root *root,
1056 struct nsproxy *namespaces, struct ctl_table *table); 1066 struct nsproxy *namespaces, struct ctl_table *table);
@@ -1066,6 +1076,7 @@ struct ctl_table_header
1066 struct completion *unregistering; 1076 struct completion *unregistering;
1067 struct ctl_table *ctl_table_arg; 1077 struct ctl_table *ctl_table_arg;
1068 struct ctl_table_root *root; 1078 struct ctl_table_root *root;
1079 struct ctl_table_set *set;
1069}; 1080};
1070 1081
1071/* struct ctl_path describes where in the hierarchy a table is added */ 1082/* struct ctl_path describes where in the hierarchy a table is added */
diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
index 3855620b78a9..a8eb43cf0c7e 100644
--- a/include/net/net_namespace.h
+++ b/include/net/net_namespace.h
@@ -38,7 +38,9 @@ struct net {
38 struct proc_dir_entry *proc_net; 38 struct proc_dir_entry *proc_net;
39 struct proc_dir_entry *proc_net_stat; 39 struct proc_dir_entry *proc_net_stat;
40 40
41 struct list_head sysctl_table_headers; 41#ifdef CONFIG_SYSCTL
42 struct ctl_table_set sysctls;
43#endif
42 44
43 struct net_device *loopback_dev; /* The loopback */ 45 struct net_device *loopback_dev; /* The loopback */
44 46
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 35a50db9b6ce..8ee4a0619fbb 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -160,12 +160,13 @@ static struct ctl_table root_table[];
160static struct ctl_table_root sysctl_table_root; 160static struct ctl_table_root sysctl_table_root;
161static struct ctl_table_header root_table_header = { 161static struct ctl_table_header root_table_header = {
162 .ctl_table = root_table, 162 .ctl_table = root_table,
163 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.header_list), 163 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
164 .root = &sysctl_table_root, 164 .root = &sysctl_table_root,
165 .set = &sysctl_table_root.default_set,
165}; 166};
166static struct ctl_table_root sysctl_table_root = { 167static struct ctl_table_root sysctl_table_root = {
167 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list), 168 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
168 .header_list = LIST_HEAD_INIT(root_table_header.ctl_entry), 169 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
169}; 170};
170 171
171static struct ctl_table kern_table[]; 172static struct ctl_table kern_table[];
@@ -1403,14 +1404,20 @@ void sysctl_head_finish(struct ctl_table_header *head)
1403 spin_unlock(&sysctl_lock); 1404 spin_unlock(&sysctl_lock);
1404} 1405}
1405 1406
1407static struct ctl_table_set *
1408lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1409{
1410 struct ctl_table_set *set = &root->default_set;
1411 if (root->lookup)
1412 set = root->lookup(root, namespaces);
1413 return set;
1414}
1415
1406static struct list_head * 1416static struct list_head *
1407lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces) 1417lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1408{ 1418{
1409 struct list_head *header_list; 1419 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1410 header_list = &root->header_list; 1420 return &set->list;
1411 if (root->lookup)
1412 header_list = root->lookup(root, namespaces);
1413 return header_list;
1414} 1421}
1415 1422
1416struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces, 1423struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
@@ -1720,7 +1727,6 @@ struct ctl_table_header *__register_sysctl_paths(
1720 struct nsproxy *namespaces, 1727 struct nsproxy *namespaces,
1721 const struct ctl_path *path, struct ctl_table *table) 1728 const struct ctl_path *path, struct ctl_table *table)
1722{ 1729{
1723 struct list_head *header_list;
1724 struct ctl_table_header *header; 1730 struct ctl_table_header *header;
1725 struct ctl_table *new, **prevp; 1731 struct ctl_table *new, **prevp;
1726 unsigned int n, npath; 1732 unsigned int n, npath;
@@ -1772,8 +1778,8 @@ struct ctl_table_header *__register_sysctl_paths(
1772 } 1778 }
1773#endif 1779#endif
1774 spin_lock(&sysctl_lock); 1780 spin_lock(&sysctl_lock);
1775 header_list = lookup_header_list(root, namespaces); 1781 header->set = lookup_header_set(root, namespaces);
1776 list_add_tail(&header->ctl_entry, header_list); 1782 list_add_tail(&header->ctl_entry, &header->set->list);
1777 spin_unlock(&sysctl_lock); 1783 spin_unlock(&sysctl_lock);
1778 1784
1779 return header; 1785 return header;
@@ -1832,6 +1838,15 @@ void unregister_sysctl_table(struct ctl_table_header * header)
1832 kfree(header); 1838 kfree(header);
1833} 1839}
1834 1840
1841void setup_sysctl_set(struct ctl_table_set *p,
1842 struct ctl_table_set *parent,
1843 int (*is_seen)(struct ctl_table_set *))
1844{
1845 INIT_LIST_HEAD(&p->list);
1846 p->parent = parent ? parent : &sysctl_table_root.default_set;
1847 p->is_seen = is_seen;
1848}
1849
1835#else /* !CONFIG_SYSCTL */ 1850#else /* !CONFIG_SYSCTL */
1836struct ctl_table_header *register_sysctl_table(struct ctl_table * table) 1851struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1837{ 1852{
@@ -1848,6 +1863,12 @@ void unregister_sysctl_table(struct ctl_table_header * table)
1848{ 1863{
1849} 1864}
1850 1865
1866void setup_sysctl_set(struct ctl_table_set *p,
1867 struct ctl_table_set *parent,
1868 int (*is_seen)(struct ctl_table_set *))
1869{
1870}
1871
1851#endif /* CONFIG_SYSCTL */ 1872#endif /* CONFIG_SYSCTL */
1852 1873
1853/* 1874/*
diff --git a/net/sysctl_net.c b/net/sysctl_net.c
index 63ada437fc2f..cefbc367d8be 100644
--- a/net/sysctl_net.c
+++ b/net/sysctl_net.c
@@ -29,10 +29,15 @@
29#include <linux/if_tr.h> 29#include <linux/if_tr.h>
30#endif 30#endif
31 31
32static struct list_head * 32static struct ctl_table_set *
33net_ctl_header_lookup(struct ctl_table_root *root, struct nsproxy *namespaces) 33net_ctl_header_lookup(struct ctl_table_root *root, struct nsproxy *namespaces)
34{ 34{
35 return &namespaces->net_ns->sysctl_table_headers; 35 return &namespaces->net_ns->sysctls;
36}
37
38static int is_seen(struct ctl_table_set *set)
39{
40 return &current->nsproxy->net_ns->sysctls == set;
36} 41}
37 42
38/* Return standard mode bits for table entry. */ 43/* Return standard mode bits for table entry. */
@@ -53,13 +58,6 @@ static struct ctl_table_root net_sysctl_root = {
53 .permissions = net_ctl_permissions, 58 .permissions = net_ctl_permissions,
54}; 59};
55 60
56static LIST_HEAD(net_sysctl_ro_tables);
57static struct list_head *net_ctl_ro_header_lookup(struct ctl_table_root *root,
58 struct nsproxy *namespaces)
59{
60 return &net_sysctl_ro_tables;
61}
62
63static int net_ctl_ro_header_perms(struct ctl_table_root *root, 61static int net_ctl_ro_header_perms(struct ctl_table_root *root,
64 struct nsproxy *namespaces, struct ctl_table *table) 62 struct nsproxy *namespaces, struct ctl_table *table)
65{ 63{
@@ -70,19 +68,18 @@ static int net_ctl_ro_header_perms(struct ctl_table_root *root,
70} 68}
71 69
72static struct ctl_table_root net_sysctl_ro_root = { 70static struct ctl_table_root net_sysctl_ro_root = {
73 .lookup = net_ctl_ro_header_lookup,
74 .permissions = net_ctl_ro_header_perms, 71 .permissions = net_ctl_ro_header_perms,
75}; 72};
76 73
77static int sysctl_net_init(struct net *net) 74static int sysctl_net_init(struct net *net)
78{ 75{
79 INIT_LIST_HEAD(&net->sysctl_table_headers); 76 setup_sysctl_set(&net->sysctls, NULL, is_seen);
80 return 0; 77 return 0;
81} 78}
82 79
83static void sysctl_net_exit(struct net *net) 80static void sysctl_net_exit(struct net *net)
84{ 81{
85 WARN_ON(!list_empty(&net->sysctl_table_headers)); 82 WARN_ON(!list_empty(&net->sysctls.list));
86 return; 83 return;
87} 84}
88 85
@@ -98,6 +95,7 @@ static __init int sysctl_init(void)
98 if (ret) 95 if (ret)
99 goto out; 96 goto out;
100 register_sysctl_root(&net_sysctl_root); 97 register_sysctl_root(&net_sysctl_root);
98 setup_sysctl_set(&net_sysctl_ro_root.default_set, NULL, NULL);
101 register_sysctl_root(&net_sysctl_ro_root); 99 register_sysctl_root(&net_sysctl_ro_root);
102out: 100out:
103 return ret; 101 return ret;