diff options
author | Eric W. Biederman <ebiederm@xmission.com> | 2012-01-09 20:24:30 -0500 |
---|---|---|
committer | Eric W. Biederman <ebiederm@xmission.com> | 2012-01-24 19:40:28 -0500 |
commit | 938aaa4f9249aa1519fd0db07fc72125de2df338 (patch) | |
tree | fd248564e8988e95966cd425f3f96ce7d094ae1c | |
parent | 3cc3e04636d603778d921854b84ae7bd34a349a2 (diff) |
sysctl: Initial support for auto-unregistering sysctl tables.
Add nreg to ctl_table_header. When nreg drops to 0 the ctl_table_header
will be unregistered.
Factor out drop_sysctl_table from unregister_sysctl_table, and add
the logic for decrementing nreg.
Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
-rw-r--r-- | fs/proc/proc_sysctl.c | 28 | ||||
-rw-r--r-- | include/linux/sysctl.h | 1 |
2 files changed, 20 insertions, 9 deletions
diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c index 15444850b3e8..13faa48c467e 100644 --- a/fs/proc/proc_sysctl.c +++ b/fs/proc/proc_sysctl.c | |||
@@ -29,8 +29,9 @@ static struct ctl_table root_table[1]; | |||
29 | static struct ctl_table_root sysctl_table_root; | 29 | static struct ctl_table_root sysctl_table_root; |
30 | static struct ctl_table_header root_table_header = { | 30 | static struct ctl_table_header root_table_header = { |
31 | {{.count = 1, | 31 | {{.count = 1, |
32 | .ctl_table = root_table, | 32 | .nreg = 1, |
33 | .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),}}, | 33 | .ctl_table = root_table, |
34 | .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),}}, | ||
34 | .root = &sysctl_table_root, | 35 | .root = &sysctl_table_root, |
35 | .set = &sysctl_table_root.default_set, | 36 | .set = &sysctl_table_root.default_set, |
36 | }; | 37 | }; |
@@ -938,6 +939,7 @@ struct ctl_table_header *__register_sysctl_table( | |||
938 | header->unregistering = NULL; | 939 | header->unregistering = NULL; |
939 | header->root = root; | 940 | header->root = root; |
940 | header->count = 1; | 941 | header->count = 1; |
942 | header->nreg = 1; | ||
941 | if (sysctl_check_table(path, table)) | 943 | if (sysctl_check_table(path, table)) |
942 | goto fail; | 944 | goto fail; |
943 | 945 | ||
@@ -1192,6 +1194,20 @@ struct ctl_table_header *register_sysctl_table(struct ctl_table *table) | |||
1192 | } | 1194 | } |
1193 | EXPORT_SYMBOL(register_sysctl_table); | 1195 | EXPORT_SYMBOL(register_sysctl_table); |
1194 | 1196 | ||
1197 | static void drop_sysctl_table(struct ctl_table_header *header) | ||
1198 | { | ||
1199 | if (--header->nreg) | ||
1200 | return; | ||
1201 | |||
1202 | start_unregistering(header); | ||
1203 | if (!--header->parent->count) { | ||
1204 | WARN_ON(1); | ||
1205 | kfree_rcu(header->parent, rcu); | ||
1206 | } | ||
1207 | if (!--header->count) | ||
1208 | kfree_rcu(header, rcu); | ||
1209 | } | ||
1210 | |||
1195 | /** | 1211 | /** |
1196 | * unregister_sysctl_table - unregister a sysctl table hierarchy | 1212 | * unregister_sysctl_table - unregister a sysctl table hierarchy |
1197 | * @header: the header returned from register_sysctl_table | 1213 | * @header: the header returned from register_sysctl_table |
@@ -1224,13 +1240,7 @@ void unregister_sysctl_table(struct ctl_table_header * header) | |||
1224 | } | 1240 | } |
1225 | 1241 | ||
1226 | spin_lock(&sysctl_lock); | 1242 | spin_lock(&sysctl_lock); |
1227 | start_unregistering(header); | 1243 | drop_sysctl_table(header); |
1228 | if (!--header->parent->count) { | ||
1229 | WARN_ON(1); | ||
1230 | kfree_rcu(header->parent, rcu); | ||
1231 | } | ||
1232 | if (!--header->count) | ||
1233 | kfree_rcu(header, rcu); | ||
1234 | spin_unlock(&sysctl_lock); | 1244 | spin_unlock(&sysctl_lock); |
1235 | } | 1245 | } |
1236 | EXPORT_SYMBOL(unregister_sysctl_table); | 1246 | EXPORT_SYMBOL(unregister_sysctl_table); |
diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h index 094bc5ccf1e2..e40b8f6e5d0e 100644 --- a/include/linux/sysctl.h +++ b/include/linux/sysctl.h | |||
@@ -1032,6 +1032,7 @@ struct ctl_table_header | |||
1032 | struct list_head ctl_entry; | 1032 | struct list_head ctl_entry; |
1033 | int used; | 1033 | int used; |
1034 | int count; | 1034 | int count; |
1035 | int nreg; | ||
1035 | }; | 1036 | }; |
1036 | struct rcu_head rcu; | 1037 | struct rcu_head rcu; |
1037 | }; | 1038 | }; |