* [v2 077/115] sysctl: add duplicate entry and sanity ctl_table checks
From: Lucian Adrian Grijincu @ 2011-05-08 22:39 UTC (permalink / raw)
To: linux-kernel; +Cc: netdev, Lucian Adrian Grijincu
In-Reply-To: <1304894407-32201-1-git-send-email-lucian.grijincu@gmail.com>
Signed-off-by: Lucian Adrian Grijincu <lucian.grijincu@gmail.com>
---
include/linux/sysctl.h | 7 ++
kernel/sysctl.c | 19 ++++++-
kernel/sysctl_check.c | 153 +++++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 177 insertions(+), 2 deletions(-)
diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
index b626271..22b6eb8 100644
--- a/include/linux/sysctl.h
+++ b/include/linux/sysctl.h
@@ -1092,6 +1092,13 @@ extern struct ctl_table_header *register_sysctl_paths(const struct ctl_path *pat
struct ctl_table *table);
extern void unregister_sysctl_table(struct ctl_table_header *table);
+#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
+extern int sysctl_check_table(const struct ctl_path *path,
+ int nr_dirs,
+ struct ctl_table *table);
+extern int sysctl_check_duplicates(struct ctl_table_header *header);
+#endif /* CONFIG_SYSCTL_SYSCALL_CHECK */
+
#endif /* __KERNEL__ */
#endif /* _LINUX_SYSCTL_H */
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index cbf33b1..d777e89 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -1977,8 +1977,14 @@ struct ctl_table_header *__register_sysctl_paths(struct ctl_table_group *group,
const struct ctl_path *path, struct ctl_table *table)
{
struct ctl_table_header *header;
+ int failed_duplicate_check = 0;
int nr_dirs = ctl_path_items(path);
+#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
+ if (sysctl_check_table(path, nr_dirs, table))
+ return NULL;
+#endif
+
header = alloc_sysctl_header(group);
if (!header)
return NULL;
@@ -1993,9 +1999,20 @@ struct ctl_table_header *__register_sysctl_paths(struct ctl_table_group *group,
header->ctl_header_refs = 1;
sysctl_write_lock_head(header->parent);
- list_add_tail(&header->ctl_entry, &header->parent->ctl_tables);
+
+#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
+ failed_duplicate_check = sysctl_check_duplicates(header);
+#endif
+ if (!failed_duplicate_check)
+ list_add_tail(&header->ctl_entry, &header->parent->ctl_tables);
+
sysctl_write_unlock_head(header->parent);
+ if (failed_duplicate_check) {
+ unregister_sysctl_table(header);
+ return NULL;
+ }
+
return header;
}
diff --git a/kernel/sysctl_check.c b/kernel/sysctl_check.c
index e9a7a58..4e0bce5 100644
--- a/kernel/sysctl_check.c
+++ b/kernel/sysctl_check.c
@@ -1 +1,152 @@
-/* will be rewritten */
+#include <linux/sysctl.h>
+#include <linux/string.h>
+
+/*
+ * @path: the path to the offender
+ * @offender is the name of a file or directory that violated some sysctl rules.
+ * @str: a message accompanying the error
+ */
+static void fail(const struct ctl_path *path,
+ const char *offender,
+ const char *str)
+{
+ printk(KERN_ERR "sysctl sanity check failed: ");
+
+ for (; path->procname; path++)
+ printk("/%s", path->procname);
+
+ if (offender)
+ printk("/%s", offender);
+
+ printk(": %s\n", str);
+}
+
+#define FAIL(str) do { fail(path, t->procname, str); error = -EINVAL;} while (0)
+
+int sysctl_check_table(const struct ctl_path *path,
+ int nr_dirs,
+ struct ctl_table *table)
+{
+ struct ctl_table *t;
+ int error = 0;
+
+ if (nr_dirs > CTL_MAXNAME - 1) {
+ fail(path, NULL, "tree too deep");
+ error = -EINVAL;
+ }
+
+ for(t = table; t->procname; t++) {
+ if ((t->proc_handler == proc_dostring) ||
+ (t->proc_handler == proc_dointvec) ||
+ (t->proc_handler == proc_dointvec_minmax) ||
+ (t->proc_handler == proc_dointvec_jiffies) ||
+ (t->proc_handler == proc_dointvec_userhz_jiffies) ||
+ (t->proc_handler == proc_dointvec_ms_jiffies) ||
+ (t->proc_handler == proc_doulongvec_minmax) ||
+ (t->proc_handler == proc_doulongvec_ms_jiffies_minmax)) {
+ if (!t->data)
+ FAIL("No data");
+ if (!t->maxlen)
+ FAIL("No maxlen");
+ }
+#ifdef CONFIG_PROC_SYSCTL
+ if (!t->proc_handler)
+ FAIL("No proc_handler");
+#endif
+ if (t->mode > 0777)
+ FAIL("bogus .mode");
+ }
+
+ if (error)
+ dump_stack();
+
+ return error;
+}
+
+
+/*
+ * @dir: the directory imediately above the offender
+ * @offender is the name of a file or directory that violated some sysctl rules.
+ */
+static void duplicate_error(struct ctl_table_header *dir,
+ const char *offender)
+{
+ const char *names[CTL_MAXNAME];
+ int i = 0;
+
+ printk(KERN_ERR "sysctl duplicate check failed: ");
+
+ for (; dir->parent; dir = dir->parent)
+ /* ctl_dirname can be NULL: netns-correspondent
+ * directories do not have a ctl_dirname. Their only
+ * pourpose is to hold the list of
+ * subdirs/subtables. They hold netns-specific
+ * information for the parent directory. */
+ if (dir->ctl_dirname) {
+ names[i] = dir->ctl_dirname;
+ i++;
+ }
+
+ /* Print the names in the normal path order, not reversed */
+ for(i--; i >= 0; i--)
+ printk("/%s", names[i]);
+
+ printk("/%s \n", offender);
+}
+
+/* is there an entry in the table with the same procname? */
+static int match(struct ctl_table *table, const char *name)
+{
+ for ( ; table->procname; table++) {
+
+ if (strcmp(table->procname, name) == 0)
+ return 1;
+ }
+ return 0;
+}
+
+
+/* Called under header->parent write lock.
+ *
+ * checks whether this header's table introduces items that have the
+ * same names as other items at the same level (other files or
+ * subdirectories of the current dir). */
+int sysctl_check_duplicates(struct ctl_table_header *header)
+{
+ int has_duplicates = 0;
+ struct ctl_table *table = header->ctl_table_arg;
+ struct ctl_table_header *dir = header->parent;
+ struct ctl_table_header *h;
+
+ list_for_each_entry(h, &dir->ctl_subdirs, ctl_entry) {
+ if (IS_ERR(sysctl_use_header(h)))
+ continue;
+
+ if (match(table, h->ctl_dirname)) {
+ has_duplicates = 1;
+ duplicate_error(dir, h->ctl_dirname);
+ }
+
+ sysctl_unuse_header(h);
+ }
+
+ list_for_each_entry(h, &dir->ctl_tables, ctl_entry) {
+ ctl_table *t;
+
+ if (IS_ERR(sysctl_use_header(h)))
+ continue;
+
+ for (t = h->ctl_table_arg; t->procname; t++) {
+ if (match(table, t->procname)) {
+ has_duplicates = 1;
+ duplicate_error(dir, t->procname);
+ }
+ }
+ sysctl_unuse_header(h);
+ }
+
+ if (has_duplicates)
+ dump_stack();
+
+ return has_duplicates;
+}
--
1.7.5.134.g1c08b
^ permalink raw reply related
* [v2 075/115] sysctl: move removal from list out of start_unregistering
From: Lucian Adrian Grijincu @ 2011-05-08 22:39 UTC (permalink / raw)
To: linux-kernel; +Cc: netdev, Lucian Adrian Grijincu
In-Reply-To: <1304894407-32201-1-git-send-email-lucian.grijincu@gmail.com>
Later on we'll switch form a global list protected by the sysctl_lock
spin lock to rwsem protected per-header lists.
At that point we'll need to hold the parent header's rwlock to remove
the header from the list, not the sysctl_lock spin lock.
As start_unregistering is called under the sysctl_lock, we move the
list removal out.
Signed-off-by: Lucian Adrian Grijincu <lucian.grijincu@gmail.com>
---
kernel/sysctl.c | 12 +++++++-----
1 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 8dde087..a863b56 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -1552,11 +1552,6 @@ static void start_unregistering(struct ctl_table_header *p)
/* anything non-NULL; we'll never dereference it */
p->unregistering = ERR_PTR(-EINVAL);
}
- /*
- * do not remove from the list until nobody holds it; walking the
- * list in do_sysctl() relies on that.
- */
- list_del_init(&p->ctl_entry);
}
void sysctl_proc_inode_get(struct ctl_table_header *head)
@@ -1949,6 +1944,13 @@ void unregister_sysctl_table(struct ctl_table_header * header)
spin_lock(&sysctl_lock);
start_unregistering(header);
+
+ /* after start_unregistering has finished no one holds a
+ * ctl_use_refs or is able to acquire one => no one is going
+ * to access internal fields of this object, so we can remove
+ * it from the list and schedule it for deletion. */
+ list_del_init(&p->ctl_entry);
+
if (!--header->parent->ctl_header_refs) {
WARN_ON(1);
if (!header->parent->ctl_procfs_refs)
--
1.7.5.134.g1c08b
^ permalink raw reply related
* [v2 072/115] sysctl: simplify ->permissions hook
From: Lucian Adrian Grijincu @ 2011-05-08 22:39 UTC (permalink / raw)
To: linux-kernel; +Cc: netdev, Lucian Adrian Grijincu
In-Reply-To: <1304894407-32201-1-git-send-email-lucian.grijincu@gmail.com>
The @root parameter was not used at all.
The @namespaces parameter was used to transmit current->nsproxy. We
can access current->nsproxy directly in the ->permissions function, no
need to send it.
Signed-off-by: Lucian Adrian Grijincu <lucian.grijincu@gmail.com>
---
include/linux/sysctl.h | 3 +--
kernel/sysctl.c | 2 +-
net/sysctl_net.c | 9 +++------
3 files changed, 5 insertions(+), 9 deletions(-)
diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
index e265880..1af4ed5 100644
--- a/include/linux/sysctl.h
+++ b/include/linux/sysctl.h
@@ -1034,8 +1034,7 @@ struct ctl_table_root {
struct ctl_table_set default_set;
struct ctl_table_set *(*lookup)(struct ctl_table_root *root,
struct nsproxy *namespaces);
- int (*permissions)(struct ctl_table_root *root,
- struct nsproxy *namespaces, struct ctl_table *table);
+ int (*permissions)(struct ctl_table *table);
};
/* struct ctl_table_header is used to maintain dynamic lists of
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 1281827..6e4e32b 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -1664,7 +1664,7 @@ int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
int mode;
if (root->permissions)
- mode = root->permissions(root, current->nsproxy, table);
+ mode = root->permissions(table);
else
mode = table->mode;
diff --git a/net/sysctl_net.c b/net/sysctl_net.c
index 1197d9c..1c0cb57 100644
--- a/net/sysctl_net.c
+++ b/net/sysctl_net.c
@@ -41,9 +41,7 @@ static int is_seen(struct ctl_table_set *set)
}
/* Return standard mode bits for table entry. */
-static int net_ctl_permissions(struct ctl_table_root *root,
- struct nsproxy *nsproxy,
- struct ctl_table *table)
+static int net_ctl_permissions(struct ctl_table *table)
{
/* Allow network administrator to have same access as root. */
if (capable(CAP_NET_ADMIN)) {
@@ -58,10 +56,9 @@ static struct ctl_table_root net_sysctl_root = {
.permissions = net_ctl_permissions,
};
-static int net_ctl_ro_header_perms(struct ctl_table_root *root,
- struct nsproxy *namespaces, struct ctl_table *table)
+static int net_ctl_ro_header_perms(ctl_table *table)
{
- if (net_eq(namespaces->net_ns, &init_net))
+ if (net_eq(current->nsproxy->net_ns, &init_net))
return table->mode;
else
return table->mode & ~0222;
--
1.7.5.134.g1c08b
^ permalink raw reply related
* [v2 069/115] sysctl: split ->count into ctl_procfs_refs and ctl_header_refs
From: Lucian Adrian Grijincu @ 2011-05-08 22:39 UTC (permalink / raw)
To: linux-kernel; +Cc: netdev, Lucian Adrian Grijincu
In-Reply-To: <1304894407-32201-1-git-send-email-lucian.grijincu@gmail.com>
This is not necessary at this point, but will be later when we replace
the sysctl implementation with one that uses ctl_table_header objects
as directories.
Signed-off-by: Lucian Adrian Grijincu <lucian.grijincu@gmail.com>
---
include/linux/sysctl.h | 8 +++++++-
kernel/sysctl.c | 21 ++++++++++++---------
2 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
index 4ed5235..0f41beb 100644
--- a/include/linux/sysctl.h
+++ b/include/linux/sysctl.h
@@ -1046,7 +1046,13 @@ struct ctl_table_header
/* references to this header from contexts that
* can access fields of this header */
int ctl_use_refs;
- int count;
+ /* references to this header from procfs inodes.
+ * procfs embeds a pointer to the header in proc_inode */
+ int ctl_procfs_refs;
+ /* counts references to this header from other
+ * headers (through ->parent) plus the reference
+ * returned by __register_sysctl_paths */
+ int ctl_header_refs;
};
struct rcu_head rcu;
};
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index e4ec23e..48a1ffd 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -200,7 +200,7 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
static struct ctl_table root_table[];
static struct ctl_table_root sysctl_table_root;
static struct ctl_table_header root_table_header = {
- {{.count = 1,
+ {{.ctl_header_refs = 1,
.ctl_table = root_table,
.ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),}},
.root = &sysctl_table_root,
@@ -1554,7 +1554,7 @@ static void start_unregistering(struct ctl_table_header *p)
void sysctl_head_get(struct ctl_table_header *head)
{
spin_lock(&sysctl_lock);
- head->count++;
+ head->ctl_procfs_refs++;
spin_unlock(&sysctl_lock);
}
@@ -1566,7 +1566,8 @@ static void free_head(struct rcu_head *rcu)
void sysctl_head_put(struct ctl_table_header *head)
{
spin_lock(&sysctl_lock);
- if (!--head->count)
+ head->ctl_procfs_refs--;
+ if ((head->ctl_procfs_refs == 0) && (head->ctl_header_refs == 0))
call_rcu(&head->rcu, free_head);
spin_unlock(&sysctl_lock);
}
@@ -1877,7 +1878,7 @@ struct ctl_table_header *__register_sysctl_paths(
INIT_LIST_HEAD(&header->ctl_entry);
header->unregistering = NULL;
header->root = root;
- header->count = 1;
+ header->ctl_header_refs = 1;
#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
if (sysctl_check_table(namespaces, header->ctl_table)) {
kfree(header);
@@ -1897,7 +1898,7 @@ struct ctl_table_header *__register_sysctl_paths(
try_attach(p, header);
}
}
- header->parent->count++;
+ header->parent->ctl_header_refs++;
list_add_tail(&header->ctl_entry, &header->set->list);
spin_unlock(&sysctl_lock);
@@ -1937,12 +1938,14 @@ void unregister_sysctl_table(struct ctl_table_header * header)
spin_lock(&sysctl_lock);
start_unregistering(header);
- if (!--header->parent->count) {
+ if (!--header->parent->ctl_header_refs) {
WARN_ON(1);
- call_rcu(&header->parent->rcu, free_head);
+ if (!header->parent->ctl_procfs_refs)
+ call_rcu(&header->parent->rcu, free_head);
}
- if (!--header->count)
- call_rcu(&header->rcu, free_head);
+ if (!--header->ctl_header_refs)
+ if (!header->ctl_procfs_refs)
+ call_rcu(&header->rcu, free_head);
spin_unlock(&sysctl_lock);
}
--
1.7.5.134.g1c08b
^ permalink raw reply related
* [v2 066/115] sysctl: rename ->used to ->ctl_use_refs
From: Lucian Adrian Grijincu @ 2011-05-08 22:39 UTC (permalink / raw)
To: linux-kernel; +Cc: netdev, Lucian Adrian Grijincu
In-Reply-To: <1304894407-32201-1-git-send-email-lucian.grijincu@gmail.com>
In a later patch I will split the 'count' counter. We need to have a
clear distinction between the three counters to be able to understand
the code.
This counts the number of references to this object from places that
can tinker with it's internals (e.g. ctl_table, ctl_entry,
attached_to, attached_by, etc.).
Signed-off-by: Lucian Adrian Grijincu <lucian.grijincu@gmail.com>
---
include/linux/sysctl.h | 4 +++-
kernel/sysctl.c | 9 ++++-----
2 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
index 1c41dbd..fe13067 100644
--- a/include/linux/sysctl.h
+++ b/include/linux/sysctl.h
@@ -1043,7 +1043,9 @@ struct ctl_table_header
struct {
struct ctl_table *ctl_table;
struct list_head ctl_entry;
- int used;
+ /* references to this header from contexts that
+ * can access fields of this header */
+ int ctl_use_refs;
int count;
};
struct rcu_head rcu;
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 8b56695..ab242b4 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -1494,14 +1494,14 @@ static int use_table(struct ctl_table_header *p)
{
if (unlikely(p->unregistering))
return 0;
- p->used++;
+ p->ctl_use_refs++;
return 1;
}
/* called under sysctl_lock */
static void unuse_table(struct ctl_table_header *p)
{
- if (!--p->used)
+ if (!--p->ctl_use_refs)
if (unlikely(p->unregistering))
complete(p->unregistering);
}
@@ -1510,10 +1510,10 @@ static void unuse_table(struct ctl_table_header *p)
static void start_unregistering(struct ctl_table_header *p)
{
/*
- * if p->used is 0, nobody will ever touch that entry again;
+ * if p->ctl_use_refs is 0, nobody will ever touch that entry again;
* we'll eliminate all paths to it before dropping sysctl_lock
*/
- if (unlikely(p->used)) {
+ if (unlikely(p->ctl_use_refs)) {
struct completion wait;
init_completion(&wait);
p->unregistering = &wait;
@@ -1875,7 +1875,6 @@ struct ctl_table_header *__register_sysctl_paths(
header->ctl_table_arg = table;
INIT_LIST_HEAD(&header->ctl_entry);
- header->used = 0;
header->unregistering = NULL;
header->root = root;
header->count = 1;
--
1.7.5.134.g1c08b
^ permalink raw reply related
* [v2 064/115] sysctl: sysctl_head_grab defaults to root header on NULL
From: Lucian Adrian Grijincu @ 2011-05-08 22:39 UTC (permalink / raw)
To: linux-kernel; +Cc: netdev, Lucian Adrian Grijincu
In-Reply-To: <1304894407-32201-1-git-send-email-lucian.grijincu@gmail.com>
The code that could send NULL to sysctl_head_grab is grab_header
because for the root sysctl directory ('/proc/sys/')
PROC_I(inode)->sysctl is NULL.
For it we used to return root_table_header indirectly through a call
to sysctl_head_next(NULL). Now we default to the root header here.
The BUG() has not been triggered until now so we can assume no one
else is sending NULL here.
Signed-off-by: Lucian Adrian Grijincu <lucian.grijincu@gmail.com>
---
fs/proc/proc_sysctl.c | 5 +----
kernel/sysctl.c | 2 +-
2 files changed, 2 insertions(+), 5 deletions(-)
diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
index d1640bc..93962b0 100644
--- a/fs/proc/proc_sysctl.c
+++ b/fs/proc/proc_sysctl.c
@@ -64,10 +64,7 @@ static struct ctl_table *find_in_table(struct ctl_table *p, struct qstr *name)
static struct ctl_table_header *grab_header(struct inode *inode)
{
- if (PROC_I(inode)->sysctl)
- return sysctl_head_grab(PROC_I(inode)->sysctl);
- else
- return sysctl_head_next(NULL);
+ return sysctl_head_grab(PROC_I(inode)->sysctl);
}
static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 0450d3d..8b56695 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -1554,7 +1554,7 @@ void sysctl_head_put(struct ctl_table_header *head)
struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
{
if (!head)
- BUG();
+ head = &root_table_header;
spin_lock(&sysctl_lock);
if (!use_table(head))
head = ERR_PTR(-ENOENT);
--
1.7.5.134.g1c08b
^ permalink raw reply related
* [v2 063/115] sysctl: simplify find_in_table
From: Lucian Adrian Grijincu @ 2011-05-08 22:39 UTC (permalink / raw)
To: linux-kernel; +Cc: netdev, Lucian Adrian Grijincu
In-Reply-To: <1304894407-32201-1-git-send-email-lucian.grijincu@gmail.com>
The if (!p->procname) check is useless because the loop condition
prevents it from happening.
Signed-off-by: Lucian Adrian Grijincu <lucian.grijincu@gmail.com>
---
fs/proc/proc_sysctl.c | 10 ++--------
1 files changed, 2 insertions(+), 8 deletions(-)
diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
index f50133c..d1640bc 100644
--- a/fs/proc/proc_sysctl.c
+++ b/fs/proc/proc_sysctl.c
@@ -52,18 +52,12 @@ static struct ctl_table *find_in_table(struct ctl_table *p, struct qstr *name)
int len;
for ( ; p->procname; p++) {
- if (!p->procname)
- continue;
-
len = strlen(p->procname);
if (len != name->len)
continue;
- if (memcmp(p->procname, name->name, len) != 0)
- continue;
-
- /* I have a match */
- return p;
+ if (memcmp(p->procname, name->name, len) == 0)
+ return p;
}
return NULL;
}
--
1.7.5.134.g1c08b
^ permalink raw reply related
* [v2 062/115] sysctl: remove useless ctl_table->parent field
From: Lucian Adrian Grijincu @ 2011-05-08 22:39 UTC (permalink / raw)
To: linux-kernel; +Cc: netdev, Lucian Adrian Grijincu
In-Reply-To: <1304894407-32201-1-git-send-email-lucian.grijincu@gmail.com>
The 'parent' field was added for selinux in:
commit d912b0cc1a617d7c590d57b7ea971d50c7f02503
[PATCH] sysctl: add a parent entry to ctl_table and set the parent entry
and then was used for sysctl_check_table.
Both of the users have found other implementations.
Signed-off-by: Lucian Adrian Grijincu <lucian.grijincu@gmail.com>
---
include/linux/sysctl.h | 1 -
kernel/sysctl.c | 12 ------------
kernel/sysctl_check.c | 5 +++--
3 files changed, 3 insertions(+), 15 deletions(-)
diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
index 095df3a..1c41dbd 100644
--- a/include/linux/sysctl.h
+++ b/include/linux/sysctl.h
@@ -1021,7 +1021,6 @@ struct ctl_table
int maxlen;
mode_t mode;
struct ctl_table *child;
- struct ctl_table *parent; /* Automatically set */
proc_handler *proc_handler; /* Callback for text formatting */
void *extra1;
void *extra2;
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index edacbdc..0450d3d 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -1671,15 +1671,6 @@ int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
return test_perm(mode, op);
}
-static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
-{
- for (; table->procname; table++) {
- table->parent = parent;
- if (table->child)
- sysctl_set_parent(table, table->child);
- }
-}
-
__init int sysctl_init(void)
{
struct ctl_table_header *kern_header, *vm_header, *fs_header,
@@ -1688,8 +1679,6 @@ __init int sysctl_init(void)
struct ctl_table_header *binfmt_misc_header;
#endif
- sysctl_set_parent(NULL, root_table);
-
kern_header = register_sysctl_paths(kern_path, kern_table);
if (kern_header == NULL)
goto fail_register_kern;
@@ -1889,7 +1878,6 @@ struct ctl_table_header *__register_sysctl_paths(
header->used = 0;
header->unregistering = NULL;
header->root = root;
- sysctl_set_parent(NULL, header->ctl_table);
header->count = 1;
#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
if (sysctl_check_table(namespaces, header->ctl_table)) {
diff --git a/kernel/sysctl_check.c b/kernel/sysctl_check.c
index cc26490..52f4810 100644
--- a/kernel/sysctl_check.c
+++ b/kernel/sysctl_check.c
@@ -100,8 +100,9 @@ static int __sysctl_check_table(struct nsproxy *namespaces,
for (; table->procname; table++) {
fail = NULL;
- if (table->parent) {
- if (!table->parent->procname)
+
+ if (depth != 0) { /* has parent */
+ if (!parents[depth - 1]->procname)
SET_FAIL("Parent without procname");
}
if (table->child) {
--
1.7.5.134.g1c08b
^ permalink raw reply related
* [v2 061/115] sysctl: faster reimplementation of sysctl_check_table
From: Lucian Adrian Grijincu @ 2011-05-08 22:39 UTC (permalink / raw)
To: linux-kernel; +Cc: netdev, Lucian Adrian Grijincu
In-Reply-To: <1304894407-32201-1-git-send-email-lucian.grijincu@gmail.com>
Determining the parent of a node at depth d
- previous implementation: O(d)
- current implementation: O(1)
Printing the path to a node at depth d
- previous implementation: O(d^2)
- current implementation: O(d)
This comes with a small cost: we use an array ('parents') holding as many
pointers as there can be sysctl levels (currently CTL_MAXNAME=10).
The 'parents' array of pointers holds the same values as the
ctl_table->parents field because the function that updates ->parents
(sysctl_set_parent) is called with either NULL (for root nodes) or
with sysctl_set_parent(table, table->child).
Signed-off-by: Lucian Adrian Grijincu <lucian.grijincu@gmail.com>
---
kernel/sysctl_check.c | 118 ++++++++++++++++++++++++++-----------------------
1 files changed, 62 insertions(+), 56 deletions(-)
diff --git a/kernel/sysctl_check.c b/kernel/sysctl_check.c
index 4e4932a..cc26490 100644
--- a/kernel/sysctl_check.c
+++ b/kernel/sysctl_check.c
@@ -6,58 +6,34 @@
#include <net/ip_vs.h>
-static int sysctl_depth(struct ctl_table *table)
-{
- struct ctl_table *tmp;
- int depth;
-
- depth = 0;
- for (tmp = table; tmp->parent; tmp = tmp->parent)
- depth++;
-
- return depth;
-}
-
-static struct ctl_table *sysctl_parent(struct ctl_table *table, int n)
+static void sysctl_print_path(struct ctl_table *table,
+ struct ctl_table **parents, int depth)
{
+ struct ctl_table *p;
int i;
-
- for (i = 0; table && i < n; i++)
- table = table->parent;
-
- return table;
-}
-
-
-static void sysctl_print_path(struct ctl_table *table)
-{
- struct ctl_table *tmp;
- int depth, i;
- depth = sysctl_depth(table);
if (table->procname) {
- for (i = depth; i >= 0; i--) {
- tmp = sysctl_parent(table, i);
- printk("/%s", tmp->procname?tmp->procname:"");
+ for (i = 0; i < depth; i++) {
+ p = parents[i];
+ printk("/%s", p->procname ? p->procname : "");
}
+ printk("/%s", table->procname);
}
printk(" ");
}
static struct ctl_table *sysctl_check_lookup(struct nsproxy *namespaces,
- struct ctl_table *table)
+ struct ctl_table *table, struct ctl_table **parents, int depth)
{
struct ctl_table_header *head;
struct ctl_table *ref, *test;
- int depth, cur_depth;
-
- depth = sysctl_depth(table);
+ int cur_depth;
for (head = __sysctl_head_next(namespaces, NULL); head;
head = __sysctl_head_next(namespaces, head)) {
cur_depth = depth;
ref = head->ctl_table;
repeat:
- test = sysctl_parent(table, cur_depth);
+ test = parents[depth - cur_depth];
for (; ref->procname; ref++) {
int match = 0;
if (cur_depth && !ref->child)
@@ -83,11 +59,12 @@ out:
return ref;
}
-static void set_fail(const char **fail, struct ctl_table *table, const char *str)
+static void set_fail(const char **fail, struct ctl_table *table,
+ const char *str, struct ctl_table **parents, int depth)
{
if (*fail) {
printk(KERN_ERR "sysctl table check failed: ");
- sysctl_print_path(table);
+ sysctl_print_path(table, parents, depth);
printk(" %s\n", *fail);
dump_stack();
}
@@ -95,38 +72,51 @@ static void set_fail(const char **fail, struct ctl_table *table, const char *str
}
static void sysctl_check_leaf(struct nsproxy *namespaces,
- struct ctl_table *table, const char **fail)
+ struct ctl_table *table, const char **fail,
+ struct ctl_table **parents, int depth)
{
struct ctl_table *ref;
- ref = sysctl_check_lookup(namespaces, table);
+ ref = sysctl_check_lookup(namespaces, table, parents, depth);
if (ref && (ref != table))
- set_fail(fail, table, "Sysctl already exists");
+ set_fail(fail, table, "Sysctl already exists", parents, depth);
}
-int sysctl_check_table(struct nsproxy *namespaces, struct ctl_table *table)
+
+
+#define SET_FAIL(str) set_fail(&fail, table, str, parents, depth)
+
+static int __sysctl_check_table(struct nsproxy *namespaces,
+ struct ctl_table *table, struct ctl_table **parents, int depth)
{
+ const char *fail = NULL;
int error = 0;
+
+ if (depth >= CTL_MAXNAME) {
+ SET_FAIL("Sysctl tree too deep");
+ return -EINVAL;
+ }
+
for (; table->procname; table++) {
- const char *fail = NULL;
+ fail = NULL;
if (table->parent) {
if (!table->parent->procname)
- set_fail(&fail, table, "Parent without procname");
+ SET_FAIL("Parent without procname");
}
if (table->child) {
if (table->data)
- set_fail(&fail, table, "Directory with data?");
+ SET_FAIL("Directory with data?");
if (table->maxlen)
- set_fail(&fail, table, "Directory with maxlen?");
+ SET_FAIL("Directory with maxlen?");
if ((table->mode & (S_IRUGO|S_IXUGO)) != table->mode)
- set_fail(&fail, table, "Writable sysctl directory");
+ SET_FAIL("Writable sysctl directory");
if (table->proc_handler)
- set_fail(&fail, table, "Directory with proc_handler");
+ SET_FAIL("Directory with proc_handler");
if (table->extra1)
- set_fail(&fail, table, "Directory with extra1");
+ SET_FAIL("Directory with extra1");
if (table->extra2)
- set_fail(&fail, table, "Directory with extra2");
+ SET_FAIL("Directory with extra2");
} else {
if ((table->proc_handler == proc_dostring) ||
(table->proc_handler == proc_dointvec) ||
@@ -137,24 +127,40 @@ int sysctl_check_table(struct nsproxy *namespaces, struct ctl_table *table)
(table->proc_handler == proc_doulongvec_minmax) ||
(table->proc_handler == proc_doulongvec_ms_jiffies_minmax)) {
if (!table->data)
- set_fail(&fail, table, "No data");
+ SET_FAIL("No data");
if (!table->maxlen)
- set_fail(&fail, table, "No maxlen");
+ SET_FAIL("No maxlen");
}
#ifdef CONFIG_PROC_SYSCTL
if (!table->proc_handler)
- set_fail(&fail, table, "No proc_handler");
+ SET_FAIL("No proc_handler");
#endif
- sysctl_check_leaf(namespaces, table, &fail);
+ parents[depth] = table;
+ sysctl_check_leaf(namespaces, table, &fail,
+ parents, depth);
}
if (table->mode > 0777)
- set_fail(&fail, table, "bogus .mode");
+ SET_FAIL("bogus .mode");
if (fail) {
- set_fail(&fail, table, NULL);
+ SET_FAIL(NULL);
error = -EINVAL;
}
- if (table->child)
- error |= sysctl_check_table(namespaces, table->child);
+ if (table->child) {
+ parents[depth] = table;
+ error |= __sysctl_check_table(namespaces, table->child,
+ parents, depth + 1);
+ }
}
return error;
}
+
+
+int sysctl_check_table(struct nsproxy *namespaces, struct ctl_table *table)
+{
+ struct ctl_table *parents[CTL_MAXNAME];
+ /* Keep track of parents as we go down into the tree:
+ * - the node at depth 'd' will have the parent at parents[d-1].
+ * - the root node (depth=0) has no parent in this array.
+ */
+ return __sysctl_check_table(namespaces, table, parents, 0);
+}
--
1.7.5.134.g1c08b
^ permalink raw reply related
* [v2 060/115] sysctl: no-child: manually register root tables
From: Lucian Adrian Grijincu @ 2011-05-08 22:39 UTC (permalink / raw)
To: linux-kernel; +Cc: netdev, Lucian Adrian Grijincu
In-Reply-To: <1304894407-32201-1-git-send-email-lucian.grijincu@gmail.com>
Signed-off-by: Lucian Adrian Grijincu <lucian.grijincu@gmail.com>
---
kernel/sysctl.c | 121 +++++++++++++++++++++++++++++++++++++-----------------
1 files changed, 83 insertions(+), 38 deletions(-)
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 1797c01..edacbdc 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -211,12 +211,6 @@ static struct ctl_table_root sysctl_table_root = {
.default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
};
-static struct ctl_table kern_table[];
-static struct ctl_table vm_table[];
-static struct ctl_table fs_table[];
-static struct ctl_table debug_table[];
-static struct ctl_table dev_table[];
-
#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
int sysctl_legacy_va_layout;
#endif
@@ -224,31 +218,6 @@ int sysctl_legacy_va_layout;
/* The default sysctl tables: */
static struct ctl_table root_table[] = {
- {
- .procname = "kernel",
- .mode = 0555,
- .child = kern_table,
- },
- {
- .procname = "vm",
- .mode = 0555,
- .child = vm_table,
- },
- {
- .procname = "fs",
- .mode = 0555,
- .child = fs_table,
- },
- {
- .procname = "debug",
- .mode = 0555,
- .child = debug_table,
- },
- {
- .procname = "dev",
- .mode = 0555,
- .child = dev_table,
- },
{ }
};
@@ -266,6 +235,11 @@ static int min_extfrag_threshold;
static int max_extfrag_threshold = 1000;
#endif
+static const __initdata struct ctl_path kern_path [] = {
+ { .procname = "kernel" },
+ { },
+};
+
static struct ctl_table kern_table[] = {
{
.procname = "sched_child_runs_first",
@@ -955,6 +929,11 @@ static struct ctl_table kern_table[] = {
{ }
};
+static const __initdata struct ctl_path vm_path [] = {
+ { .procname = "vm" },
+ { },
+};
+
static struct ctl_table vm_table[] = {
{
.procname = "overcommit_memory",
@@ -1324,11 +1303,23 @@ static struct ctl_table vm_table[] = {
};
#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
+
+static const __initdata struct ctl_path binfmt_misc_path [] = {
+ { .procname = "fs" },
+ { .procname = "binfmt_misc" },
+ { },
+};
+
static struct ctl_table binfmt_misc_table[] = {
{ }
};
#endif
+static const __initdata struct ctl_path fs_path [] = {
+ { .procname = "fs" },
+ { },
+};
+
static struct ctl_table fs_table[] = {
{
.procname = "inode-nr",
@@ -1446,13 +1437,6 @@ static struct ctl_table fs_table[] = {
.extra1 = &zero,
.extra2 = &two,
},
-#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
- {
- .procname = "binfmt_misc",
- .mode = 0555,
- .child = binfmt_misc_table,
- },
-#endif
{
.procname = "pipe-max-size",
.data = &pipe_max_size,
@@ -1464,6 +1448,11 @@ static struct ctl_table fs_table[] = {
{ }
};
+static const __initdata struct ctl_path debug_path [] = {
+ { .procname = "debug" },
+ { },
+};
+
static struct ctl_table debug_table[] = {
#if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
defined(CONFIG_S390)
@@ -1489,6 +1478,11 @@ static struct ctl_table debug_table[] = {
{ }
};
+static const __initdata struct ctl_path dev_path [] = {
+ { .procname = "dev" },
+ { },
+};
+
static struct ctl_table dev_table[] = {
{ }
};
@@ -1688,11 +1682,62 @@ static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
__init int sysctl_init(void)
{
+ struct ctl_table_header *kern_header, *vm_header, *fs_header,
+ *debug_header, *dev_header;
+#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
+ struct ctl_table_header *binfmt_misc_header;
+#endif
+
sysctl_set_parent(NULL, root_table);
+
+ kern_header = register_sysctl_paths(kern_path, kern_table);
+ if (kern_header == NULL)
+ goto fail_register_kern;
+
+ vm_header = register_sysctl_paths(vm_path, vm_table);
+ if (vm_header == NULL)
+ goto fail_register_vm;
+
+ fs_header = register_sysctl_paths(fs_path, fs_table);
+ if (fs_header == NULL)
+ goto fail_register_fs;
+
+ debug_header = register_sysctl_paths(debug_path, debug_table);
+ if (debug_header == NULL)
+ goto fail_register_debug;
+
+ dev_header = register_sysctl_paths(dev_path, dev_table);
+ if (dev_header == NULL)
+ goto fail_register_dev;
+
+#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
+ binfmt_misc_header = register_sysctl_paths(binfmt_misc_path, binfmt_misc_table);
+ if (binfmt_misc_header == NULL)
+ goto fail_register_binfmt_misc;
+#endif
+
+
#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
sysctl_check_table(current->nsproxy, root_table);
#endif
return 0;
+
+
+#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
+fail_register_binfmt_misc:
+ unregister_sysctl_table(dev_header);
+#endif
+
+fail_register_dev:
+ unregister_sysctl_table(debug_header);
+fail_register_debug:
+ unregister_sysctl_table(fs_header);
+fail_register_fs:
+ unregister_sysctl_table(vm_header);
+fail_register_vm:
+ unregister_sysctl_table(kern_header);
+fail_register_kern:
+ return -ENOMEM;
}
static struct ctl_table *is_branch_in(struct ctl_table *branch,
--
1.7.5.134.g1c08b
^ permalink raw reply related
* [v2 059/115] sysctl: no-child: manually register fs/epoll
From: Lucian Adrian Grijincu @ 2011-05-08 22:39 UTC (permalink / raw)
To: linux-kernel; +Cc: netdev, Lucian Adrian Grijincu
In-Reply-To: <1304894407-32201-1-git-send-email-lucian.grijincu@gmail.com>
Signed-off-by: Lucian Adrian Grijincu <lucian.grijincu@gmail.com>
---
fs/eventpoll.c | 22 +++++++++++++++++++---
include/linux/poll.h | 2 --
kernel/sysctl.c | 10 ----------
3 files changed, 19 insertions(+), 15 deletions(-)
diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index f9cfd16..2dbcd0c 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -246,14 +246,14 @@ static struct kmem_cache *epi_cache __read_mostly;
/* Slab cache used to allocate "struct eppoll_entry" */
static struct kmem_cache *pwq_cache __read_mostly;
-#ifdef CONFIG_SYSCTL
+#if defined(CONFIG_SYSCTL) && defined (CONFIG_MMU)
#include <linux/sysctl.h>
static long zero;
static long long_max = LONG_MAX;
-ctl_table epoll_table[] = {
+static struct ctl_table epoll_table[] = {
{
.procname = "max_user_watches",
.data = &max_user_watches,
@@ -265,7 +265,22 @@ ctl_table epoll_table[] = {
},
{ }
};
-#endif /* CONFIG_SYSCTL */
+static const __initdata struct ctl_path epoll_path[] = {
+ { .procname = "fs" },
+ { .procname = "epoll" },
+ { }
+};
+static struct ctl_table_header *epoll_header;
+static int __init register_epoll_sysctls(void)
+{
+ epoll_header = register_sysctl_paths(epoll_path, epoll_table);
+ if (epoll_header == NULL)
+ return -ENOMEM;
+ return 0;
+}
+#else /* CONFIG_SYSCTL && CONFIG_MMU */
+static int __init register_epoll_sysctls(void) { return 0; }
+#endif /* CONFIG_SYSCTL && CONFIG_MMU */
/* Setup the structure that is used as key for the RB tree */
@@ -1586,6 +1601,7 @@ static int __init eventpoll_init(void)
pwq_cache = kmem_cache_create("eventpoll_pwq",
sizeof(struct eppoll_entry), 0, SLAB_PANIC, NULL);
+ register_epoll_sysctls();
return 0;
}
fs_initcall(eventpoll_init);
diff --git a/include/linux/poll.h b/include/linux/poll.h
index cf40010..314331c 100644
--- a/include/linux/poll.h
+++ b/include/linux/poll.h
@@ -10,10 +10,8 @@
#include <linux/wait.h>
#include <linux/string.h>
#include <linux/fs.h>
-#include <linux/sysctl.h>
#include <asm/uaccess.h>
-extern struct ctl_table epoll_table[]; /* for sysctl */
/* ~832 bytes of stack space used max in sys_select/sys_poll before allocating
additional memory. */
#define MAX_STACK_ALLOC 832
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 9520e2b..1797c01 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -216,9 +216,6 @@ static struct ctl_table vm_table[];
static struct ctl_table fs_table[];
static struct ctl_table debug_table[];
static struct ctl_table dev_table[];
-#ifdef CONFIG_EPOLL
-extern struct ctl_table epoll_table[];
-#endif
#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
int sysctl_legacy_va_layout;
@@ -1439,13 +1436,6 @@ static struct ctl_table fs_table[] = {
.proc_handler = proc_doulongvec_minmax,
},
#endif /* CONFIG_AIO */
-#ifdef CONFIG_EPOLL
- {
- .procname = "epoll",
- .mode = 0555,
- .child = epoll_table,
- },
-#endif
#endif
{
.procname = "suid_dumpable",
--
1.7.5.134.g1c08b
^ permalink raw reply related
* [v2 058/115] sysctl: no-child: manually register fs/inotify
From: Lucian Adrian Grijincu @ 2011-05-08 22:39 UTC (permalink / raw)
To: linux-kernel; +Cc: netdev, Lucian Adrian Grijincu
In-Reply-To: <1304894407-32201-1-git-send-email-lucian.grijincu@gmail.com>
Signed-off-by: Lucian Adrian Grijincu <lucian.grijincu@gmail.com>
---
fs/notify/inotify/inotify_user.c | 22 +++++++++++++++++++---
include/linux/inotify.h | 2 --
kernel/sysctl.c | 7 -------
3 files changed, 19 insertions(+), 12 deletions(-)
diff --git a/fs/notify/inotify/inotify_user.c b/fs/notify/inotify/inotify_user.c
index 8445fbc..ba618c2 100644
--- a/fs/notify/inotify/inotify_user.c
+++ b/fs/notify/inotify/inotify_user.c
@@ -51,13 +51,13 @@ static int inotify_max_user_watches __read_mostly;
static struct kmem_cache *inotify_inode_mark_cachep __read_mostly;
struct kmem_cache *event_priv_cachep __read_mostly;
-#ifdef CONFIG_SYSCTL
+#if defined(CONFIG_SYSCTL) && defined(CONFIG_MMU)
#include <linux/sysctl.h>
static int zero;
-ctl_table inotify_table[] = {
+static struct ctl_table inotify_table[] = {
{
.procname = "max_user_instances",
.data = &inotify_max_user_instances,
@@ -84,7 +84,22 @@ ctl_table inotify_table[] = {
},
{ }
};
-#endif /* CONFIG_SYSCTL */
+static const __initdata struct ctl_path inotify_path[] = {
+ { .procname = "fs" },
+ { .procname = "inotify" },
+ { }
+};
+static struct ctl_table_header *inotify_header;
+static int __init register_inotify_sysctls(void)
+{
+ inotify_header = register_sysctl_paths(inotify_path, inotify_table);
+ if (inotify_header == NULL)
+ return -ENOMEM;
+ return 0;
+}
+#else /* CONFIG_SYSCTL && CONFIG_MMU */
+static int __init register_inotify_sysctls(void) { return 0; }
+#endif /* CONFIG_SYSCTL && CONFIG_MMU */
static inline __u32 inotify_arg_to_mask(u32 arg)
{
@@ -862,6 +877,7 @@ static int __init inotify_user_setup(void)
inotify_max_user_instances = 128;
inotify_max_user_watches = 8192;
+ register_inotify_sysctls();
return 0;
}
module_init(inotify_user_setup);
diff --git a/include/linux/inotify.h b/include/linux/inotify.h
index d33041e..89b3bfe 100644
--- a/include/linux/inotify.h
+++ b/include/linux/inotify.h
@@ -71,8 +71,6 @@ struct inotify_event {
#define IN_NONBLOCK O_NONBLOCK
#ifdef __KERNEL__
-#include <linux/sysctl.h>
-extern struct ctl_table inotify_table[]; /* for sysctl */
#define ALL_INOTIFY_BITS (IN_ACCESS | IN_MODIFY | IN_ATTRIB | IN_CLOSE_WRITE | \
IN_CLOSE_NOWRITE | IN_OPEN | IN_MOVED_FROM | \
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 33d5e2e..9520e2b 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -1439,13 +1439,6 @@ static struct ctl_table fs_table[] = {
.proc_handler = proc_doulongvec_minmax,
},
#endif /* CONFIG_AIO */
-#ifdef CONFIG_INOTIFY_USER
- {
- .procname = "inotify",
- .mode = 0555,
- .child = inotify_table,
- },
-#endif
#ifdef CONFIG_EPOLL
{
.procname = "epoll",
--
1.7.5.134.g1c08b
^ permalink raw reply related
* [v2 056/115] sysctl: no-child: manually register kernel/random
From: Lucian Adrian Grijincu @ 2011-05-08 22:39 UTC (permalink / raw)
To: linux-kernel; +Cc: netdev, Lucian Adrian Grijincu
In-Reply-To: <1304894407-32201-1-git-send-email-lucian.grijincu@gmail.com>
Signed-off-by: Lucian Adrian Grijincu <lucian.grijincu@gmail.com>
---
drivers/char/random.c | 27 ++++++++++++++++++++++++++-
kernel/sysctl.c | 6 ------
2 files changed, 26 insertions(+), 7 deletions(-)
diff --git a/drivers/char/random.c b/drivers/char/random.c
index d4ddeba..8893c4b 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -959,8 +959,15 @@ static void init_std_data(struct entropy_store *r)
mix_pool_bytes(r, utsname(), sizeof(*(utsname())));
}
+static int __init register_random_sysctls(void);
+
static int rand_initialize(void)
{
+ int rc;
+ rc = register_random_sysctls();
+ if (!rc)
+ return rc;
+
init_std_data(&input_pool);
init_std_data(&blocking_pool);
init_std_data(&nonblocking_pool);
@@ -1250,7 +1257,7 @@ static int proc_do_uuid(ctl_table *table, int write,
}
static int sysctl_poolsize = INPUT_POOL_WORDS * 32;
-ctl_table random_table[] = {
+static struct ctl_table random_table[] = {
{
.procname = "poolsize",
.data = &sysctl_poolsize,
@@ -1298,6 +1305,24 @@ ctl_table random_table[] = {
},
{ }
};
+
+static const __initdata struct ctl_path random_path[] = {
+ { .procname = "kernel" },
+ { .procname = "random" },
+ { }
+};
+
+static struct ctl_table_header *random_header;
+
+static int __init register_random_sysctls(void)
+{
+ random_header = register_sysctl_paths(random_path, random_table);
+ if (!random_header)
+ return -ENOMEM;
+ return 0;
+}
+#else /* CONFIG_SYSCTL */
+static int __init register_random_sysctls(void) { return 0; }
#endif /* CONFIG_SYSCTL */
/********************************************************************
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 6167daa..b020156 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -216,7 +216,6 @@ static struct ctl_table vm_table[];
static struct ctl_table fs_table[];
static struct ctl_table debug_table[];
static struct ctl_table dev_table[];
-extern struct ctl_table random_table[];
#ifdef CONFIG_EPOLL
extern struct ctl_table epoll_table[];
#endif
@@ -611,11 +610,6 @@ static struct ctl_table kern_table[] = {
.proc_handler = proc_dointvec,
},
{
- .procname = "random",
- .mode = 0555,
- .child = random_table,
- },
- {
.procname = "overflowuid",
.data = &overflowuid,
.maxlen = sizeof(int),
--
1.7.5.134.g1c08b
^ permalink raw reply related
* [v2 055/115] sysctl: call sysctl_init before the first sysctl registration
From: Lucian Adrian Grijincu @ 2011-05-08 22:39 UTC (permalink / raw)
To: linux-kernel; +Cc: netdev, Lucian Adrian Grijincu
In-Reply-To: <1304894407-32201-1-git-send-email-lucian.grijincu@gmail.com>
In the next patch key_init() will be changed to register a sysctl
table. In preparation, we call sysctl_init() before it.
Also, rename net/sysctl_net.c's sysctl_init so the two don't clash.
Signed-off-by: Lucian Adrian Grijincu <lucian.grijincu@gmail.com>
---
include/linux/sysctl.h | 2 ++
init/main.c | 1 +
kernel/sysctl.c | 4 +---
net/sysctl_net.c | 4 ++--
4 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
index 470e06a..095df3a 100644
--- a/include/linux/sysctl.h
+++ b/include/linux/sysctl.h
@@ -943,6 +943,8 @@ struct ctl_table_set {
int (*is_seen)(struct ctl_table_set *);
};
+extern __init int sysctl_init(void);
+
extern void setup_sysctl_set(struct ctl_table_set *p,
struct ctl_table_set *parent,
int (*is_seen)(struct ctl_table_set *));
diff --git a/init/main.c b/init/main.c
index 4a9479e..d52a89a 100644
--- a/init/main.c
+++ b/init/main.c
@@ -599,6 +599,7 @@ asmlinkage void __init start_kernel(void)
fork_init(totalram_pages);
proc_caches_init();
buffer_init();
+ sysctl_init();
key_init();
security_init();
dbg_late_init();
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index b813724..6167daa 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -1716,7 +1716,7 @@ static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
}
}
-static __init int sysctl_init(void)
+__init int sysctl_init(void)
{
sysctl_set_parent(NULL, root_table);
#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
@@ -1725,8 +1725,6 @@ static __init int sysctl_init(void)
return 0;
}
-core_initcall(sysctl_init);
-
static struct ctl_table *is_branch_in(struct ctl_table *branch,
struct ctl_table *table)
{
diff --git a/net/sysctl_net.c b/net/sysctl_net.c
index ca84212..1197d9c 100644
--- a/net/sysctl_net.c
+++ b/net/sysctl_net.c
@@ -89,7 +89,7 @@ static struct pernet_operations sysctl_pernet_ops = {
.exit = sysctl_net_exit,
};
-static __init int sysctl_init(void)
+static __init int net_sysctl_init(void)
{
int ret;
ret = register_pernet_subsys(&sysctl_pernet_ops);
@@ -101,7 +101,7 @@ static __init int sysctl_init(void)
out:
return ret;
}
-subsys_initcall(sysctl_init);
+subsys_initcall(net_sysctl_init);
struct ctl_table_header *register_net_sysctl_table(struct net *net,
const struct ctl_path *path, struct ctl_table *table)
--
1.7.5.134.g1c08b
^ permalink raw reply related
* [v2 053/115] sysctl: remove .child from net/ipv6/route, net/ipv6/icmp, net/ipv6 tables
From: Lucian Adrian Grijincu @ 2011-05-08 22:39 UTC (permalink / raw)
To: linux-kernel; +Cc: netdev, Lucian Adrian Grijincu
In-Reply-To: <1304894407-32201-1-git-send-email-lucian.grijincu@gmail.com>
Signed-off-by: Lucian Adrian Grijincu <lucian.grijincu@gmail.com>
---
include/net/netns/ipv6.h | 4 +-
net/ipv6/sysctl_net_ipv6.c | 101 +++++++++++++++++++++++++-------------------
2 files changed, 60 insertions(+), 45 deletions(-)
diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
index 81abfcb..2d9c6f1 100644
--- a/include/net/netns/ipv6.h
+++ b/include/net/netns/ipv6.h
@@ -12,7 +12,9 @@ struct ctl_table_header;
struct netns_sysctl_ipv6 {
#ifdef CONFIG_SYSCTL
- struct ctl_table_header *table;
+ struct ctl_table_header *bindv6only_hdr;
+ struct ctl_table_header *route6_hdr;
+ struct ctl_table_header *icmp6_hdr;
struct ctl_table_header *frags_hdr;
#endif
int bindv6only;
diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
index a0d9916..1d2d8c7 100644
--- a/net/ipv6/sysctl_net_ipv6.c
+++ b/net/ipv6/sysctl_net_ipv6.c
@@ -17,19 +17,7 @@
static struct ctl_table empty[1];
-static ctl_table ipv6_table_template[] = {
- {
- .procname = "route",
- .maxlen = 0,
- .mode = 0555,
- .child = ipv6_route_table_template
- },
- {
- .procname = "icmp",
- .maxlen = 0,
- .mode = 0555,
- .child = ipv6_icmp_table_template
- },
+static ctl_table ipv6_bindv6only_template[] = {
{
.procname = "bindv6only",
.data = &init_net.ipv6.sysctl.bindv6only,
@@ -58,64 +46,89 @@ struct ctl_path net_ipv6_ctl_path[] = {
};
EXPORT_SYMBOL_GPL(net_ipv6_ctl_path);
+static const struct ctl_path net_ipv6_route_path[] = {
+ { .procname = "net", },
+ { .procname = "ipv6", },
+ { .procname = "route", },
+ { },
+};
+
+static const struct ctl_path net_ipv6_icmp_path[] = {
+ { .procname = "net", },
+ { .procname = "ipv6", },
+ { .procname = "icmp", },
+ { },
+};
+
static int __net_init ipv6_sysctl_net_init(struct net *net)
{
- struct ctl_table *ipv6_table;
+ struct ctl_table *ipv6_bindv6only_table;
struct ctl_table *ipv6_route_table;
struct ctl_table *ipv6_icmp_table;
- int err;
- err = -ENOMEM;
- ipv6_table = kmemdup(ipv6_table_template, sizeof(ipv6_table_template),
- GFP_KERNEL);
- if (!ipv6_table)
- goto out;
+ ipv6_bindv6only_table = kmemdup(ipv6_bindv6only_template,
+ sizeof(ipv6_bindv6only_template), GFP_KERNEL);
+ if (!ipv6_bindv6only_table)
+ goto fail_alloc_ipv6_bindv6only_table;
+ ipv6_bindv6only_table[0].data = &net->ipv6.sysctl.bindv6only;
ipv6_route_table = ipv6_route_sysctl_init(net);
if (!ipv6_route_table)
- goto out_ipv6_table;
- ipv6_table[0].child = ipv6_route_table;
+ goto fail_alloc_ipv6_route_table;
ipv6_icmp_table = ipv6_icmp_sysctl_init(net);
if (!ipv6_icmp_table)
- goto out_ipv6_route_table;
- ipv6_table[1].child = ipv6_icmp_table;
+ goto fail_alloc_ipv6_icmp_table;
- ipv6_table[2].data = &net->ipv6.sysctl.bindv6only;
- net->ipv6.sysctl.table = register_net_sysctl_table(net, net_ipv6_ctl_path,
- ipv6_table);
- if (!net->ipv6.sysctl.table)
- goto out_ipv6_icmp_table;
+ net->ipv6.sysctl.bindv6only_hdr = register_net_sysctl_table(
+ net, net_ipv6_ctl_path, ipv6_bindv6only_table);
+ if (!net->ipv6.sysctl.bindv6only_hdr)
+ goto fail_reg_bindv6only_hdr;
- err = 0;
-out:
- return err;
+ net->ipv6.sysctl.route6_hdr = register_net_sysctl_table(
+ net, net_ipv6_route_path, ipv6_route_table);
+ if (!net->ipv6.sysctl.route6_hdr)
+ goto fail_reg_route6_hdr;
+
+ net->ipv6.sysctl.icmp6_hdr = register_net_sysctl_table(
+ net, net_ipv6_icmp_path, ipv6_icmp_table);
+ if (!net->ipv6.sysctl.icmp6_hdr)
+ goto fail_reg_icmp6_hdr;
-out_ipv6_icmp_table:
+ return 0;
+
+fail_reg_icmp6_hdr:
+ unregister_net_sysctl_table(net->ipv6.sysctl.route6_hdr);
+fail_reg_route6_hdr:
+ unregister_net_sysctl_table(net->ipv6.sysctl.bindv6only_hdr);
+fail_reg_bindv6only_hdr:
kfree(ipv6_icmp_table);
-out_ipv6_route_table:
+fail_alloc_ipv6_icmp_table:
kfree(ipv6_route_table);
-out_ipv6_table:
- kfree(ipv6_table);
- goto out;
+fail_alloc_ipv6_route_table:
+ kfree(ipv6_bindv6only_table);
+fail_alloc_ipv6_bindv6only_table:
+ return -ENOMEM;
}
static void __net_exit ipv6_sysctl_net_exit(struct net *net)
{
- struct ctl_table *ipv6_table;
+ struct ctl_table *ipv6_bindv6only_table;
struct ctl_table *ipv6_route_table;
struct ctl_table *ipv6_icmp_table;
- ipv6_table = net->ipv6.sysctl.table->ctl_table_arg;
- ipv6_route_table = ipv6_table[0].child;
- ipv6_icmp_table = ipv6_table[1].child;
+ ipv6_bindv6only_table = net->ipv6.sysctl.bindv6only_hdr->ctl_table_arg;
+ ipv6_route_table = net->ipv6.sysctl.route6_hdr->ctl_table_arg;
+ ipv6_icmp_table = net->ipv6.sysctl.icmp6_hdr->ctl_table_arg;
- unregister_net_sysctl_table(net->ipv6.sysctl.table);
+ unregister_net_sysctl_table(net->ipv6.sysctl.icmp6_hdr);
+ unregister_net_sysctl_table(net->ipv6.sysctl.route6_hdr);
+ unregister_net_sysctl_table(net->ipv6.sysctl.bindv6only_hdr);
- kfree(ipv6_table);
- kfree(ipv6_route_table);
kfree(ipv6_icmp_table);
+ kfree(ipv6_route_table);
+ kfree(ipv6_bindv6only_table);
}
static struct pernet_operations ipv6_sysctl_net_ops = {
--
1.7.5.134.g1c08b
^ permalink raw reply related
* [v2 052/115] sysctl: remove .child from net/ipv4/neigh table
From: Lucian Adrian Grijincu @ 2011-05-08 22:39 UTC (permalink / raw)
To: linux-kernel; +Cc: netdev, Lucian Adrian Grijincu
In-Reply-To: <1304894407-32201-1-git-send-email-lucian.grijincu@gmail.com>
Signed-off-by: Lucian Adrian Grijincu <lucian.grijincu@gmail.com>
---
net/ipv6/sysctl_net_ipv6.c | 18 +++++++-----------
1 files changed, 7 insertions(+), 11 deletions(-)
diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
index 6dcf5e7..a0d9916 100644
--- a/net/ipv6/sysctl_net_ipv6.c
+++ b/net/ipv6/sysctl_net_ipv6.c
@@ -17,16 +17,6 @@
static struct ctl_table empty[1];
-static ctl_table ipv6_static_skeleton[] = {
- {
- .procname = "neigh",
- .maxlen = 0,
- .mode = 0555,
- .child = empty,
- },
- { }
-};
-
static ctl_table ipv6_table_template[] = {
{
.procname = "route",
@@ -160,11 +150,17 @@ void ipv6_sysctl_unregister(void)
unregister_pernet_subsys(&ipv6_sysctl_net_ops);
}
+static const struct ctl_path net_ipv6_neigh_path[] = {
+ { .procname = "net", },
+ { .procname = "ipv6", },
+ { .procname = "neigh", },
+ { },
+};
static struct ctl_table_header *ip6_base;
int ipv6_static_sysctl_register(void)
{
- ip6_base = register_sysctl_paths(net_ipv6_ctl_path, ipv6_static_skeleton);
+ ip6_base = register_sysctl_paths(net_ipv6_neigh_path, empty);
if (ip6_base == NULL)
return -ENOMEM;
return 0;
--
1.7.5.134.g1c08b
^ permalink raw reply related
* [v2 051/115] sysctl: remove .child from net/ipv4/route and net/ipv4/neigh tables
From: Lucian Adrian Grijincu @ 2011-05-08 22:39 UTC (permalink / raw)
To: linux-kernel; +Cc: netdev, Lucian Adrian Grijincu
In-Reply-To: <1304894407-32201-1-git-send-email-lucian.grijincu@gmail.com>
Signed-off-by: Lucian Adrian Grijincu <lucian.grijincu@gmail.com>
---
net/ipv4/route.c | 15 ++++-----------
1 files changed, 4 insertions(+), 11 deletions(-)
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 99e6e4b..46c7b3d 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -3153,18 +3153,10 @@ static ctl_table ipv4_route_table[] = {
static struct ctl_table empty[1];
-static struct ctl_table ipv4_skeleton[] =
-{
- { .procname = "route",
- .mode = 0555, .child = ipv4_route_table},
- { .procname = "neigh",
- .mode = 0555, .child = empty},
- { }
-};
-
-static __net_initdata struct ctl_path ipv4_path[] = {
+static __net_initdata struct ctl_path ipv4_neigh_path[] = {
{ .procname = "net", },
{ .procname = "ipv4", },
+ { .procname = "neigh", },
{ },
};
@@ -3317,6 +3309,7 @@ int __init ip_rt_init(void)
*/
void __init ip_static_sysctl_init(void)
{
- register_sysctl_paths(ipv4_path, ipv4_skeleton);
+ register_sysctl_paths(ipv4_route_path, ipv4_route_table);
+ register_sysctl_paths(ipv4_neigh_path, empty);
}
#endif
--
1.7.5.134.g1c08b
^ permalink raw reply related
* [v2 048/115] sysctl: remove .child from sh64/unaligned_fixup/
From: Lucian Adrian Grijincu @ 2011-05-08 22:39 UTC (permalink / raw)
To: linux-kernel; +Cc: netdev, Lucian Adrian Grijincu
In-Reply-To: <1304894407-32201-1-git-send-email-lucian.grijincu@gmail.com>
Signed-off-by: Lucian Adrian Grijincu <lucian.grijincu@gmail.com>
---
arch/sh/kernel/traps_64.c | 21 +++++----------------
1 files changed, 5 insertions(+), 16 deletions(-)
diff --git a/arch/sh/kernel/traps_64.c b/arch/sh/kernel/traps_64.c
index 6713ca9..8b355b4 100644
--- a/arch/sh/kernel/traps_64.c
+++ b/arch/sh/kernel/traps_64.c
@@ -908,27 +908,16 @@ static ctl_table unaligned_table[] = {
{}
};
-static ctl_table unaligned_root[] = {
- {
- .procname = "unaligned_fixup",
- .mode = 0555,
- .child = unaligned_table
- },
- {}
+static const __initdata struct ctl_table unaligned_path[] = {
+ { .procname = "sh64" },
+ { .procname = "unaligned_fixup" },
+ { }
};
-static ctl_table sh64_root[] = {
- {
- .procname = "sh64",
- .mode = 0555,
- .child = unaligned_root
- },
- {}
-};
static struct ctl_table_header *sysctl_header;
static int __init init_sysctl(void)
{
- sysctl_header = register_sysctl_table(sh64_root);
+ sysctl_header = register_sysctl_paths(unaligned_path, unaligned_table);
return 0;
}
--
1.7.5.134.g1c08b
^ permalink raw reply related
* [v2 047/115] sysctl: remove .child from frv/
From: Lucian Adrian Grijincu @ 2011-05-08 22:38 UTC (permalink / raw)
To: linux-kernel; +Cc: netdev, Lucian Adrian Grijincu
In-Reply-To: <1304894407-32201-1-git-send-email-lucian.grijincu@gmail.com>
Signed-off-by: Lucian Adrian Grijincu <lucian.grijincu@gmail.com>
---
arch/frv/kernel/sysctl.c | 12 ++++--------
1 files changed, 4 insertions(+), 8 deletions(-)
diff --git a/arch/frv/kernel/sysctl.c b/arch/frv/kernel/sysctl.c
index 6c155d6..e5c20a2 100644
--- a/arch/frv/kernel/sysctl.c
+++ b/arch/frv/kernel/sysctl.c
@@ -199,14 +199,10 @@ static struct ctl_table frv_table[] =
* Use a temporary sysctl number. Horrid, but will be cleaned up in 2.6
* when all the PM interfaces exist nicely.
*/
-static struct ctl_table frv_dir_table[] =
+static const __initdata struct ctl_path frv_path[] =
{
- {
- .procname = "frv",
- .mode = 0555,
- .child = frv_table
- },
- {}
+ { .procname = "frv" },
+ { }
};
/*
@@ -214,7 +210,7 @@ static struct ctl_table frv_dir_table[] =
*/
static int __init frv_sysctl_init(void)
{
- register_sysctl_table(frv_dir_table);
+ register_sysctl_paths(frv_path, frv_table);
return 0;
}
--
1.7.5.134.g1c08b
^ permalink raw reply related
* [v2 044/115] sysctl: remove .child from kernel/ (ia64/kdump)
From: Lucian Adrian Grijincu @ 2011-05-08 22:38 UTC (permalink / raw)
To: linux-kernel; +Cc: netdev, Lucian Adrian Grijincu
In-Reply-To: <1304894407-32201-1-git-send-email-lucian.grijincu@gmail.com>
Signed-off-by: Lucian Adrian Grijincu <lucian.grijincu@gmail.com>
---
arch/ia64/kernel/crash.c | 13 +++++--------
1 files changed, 5 insertions(+), 8 deletions(-)
diff --git a/arch/ia64/kernel/crash.c b/arch/ia64/kernel/crash.c
index b942f40..e54aea5 100644
--- a/arch/ia64/kernel/crash.c
+++ b/arch/ia64/kernel/crash.c
@@ -255,17 +255,14 @@ static ctl_table kdump_ctl_table[] = {
{ }
};
-static ctl_table sys_table[] = {
- {
- .procname = "kernel",
- .mode = 0555,
- .child = kdump_ctl_table,
- },
+static const __initdata struct ctl_path kdump_path[] = {
+ { .procname = "kernel" },
{ }
};
+
#endif
-static int
+static __init int
machine_crash_setup(void)
{
/* be notified before default_monarch_init_process */
@@ -277,7 +274,7 @@ machine_crash_setup(void)
if((ret = register_die_notifier(&kdump_init_notifier_nb)) != 0)
return ret;
#ifdef CONFIG_SYSCTL
- register_sysctl_table(sys_table);
+ register_sysctl_paths(kdump_path, kdump_ctl_table);
#endif
return 0;
}
--
1.7.5.134.g1c08b
^ permalink raw reply related
* [v2 043/115] sysctl: remove .child from kernel/perfmon/ (ia64)
From: Lucian Adrian Grijincu @ 2011-05-08 22:38 UTC (permalink / raw)
To: linux-kernel; +Cc: netdev, Lucian Adrian Grijincu
In-Reply-To: <1304894407-32201-1-git-send-email-lucian.grijincu@gmail.com>
Signed-off-by: Lucian Adrian Grijincu <lucian.grijincu@gmail.com>
---
arch/ia64/kernel/perfmon.c | 23 +++++++----------------
1 files changed, 7 insertions(+), 16 deletions(-)
diff --git a/arch/ia64/kernel/perfmon.c b/arch/ia64/kernel/perfmon.c
index 89accc6..96743dd 100644
--- a/arch/ia64/kernel/perfmon.c
+++ b/arch/ia64/kernel/perfmon.c
@@ -552,22 +552,13 @@ static ctl_table pfm_ctl_table[]={
},
{}
};
-static ctl_table pfm_sysctl_dir[] = {
- {
- .procname = "perfmon",
- .mode = 0555,
- .child = pfm_ctl_table,
- },
- {}
-};
-static ctl_table pfm_sysctl_root[] = {
- {
- .procname = "kernel",
- .mode = 0555,
- .child = pfm_sysctl_dir,
- },
- {}
+
+static const __initdata struct ctl_path pfm_path[] = {
+ { .procname = "kernel" },
+ { .procname = "perfmon" },
+ { }
};
+
static struct ctl_table_header *pfm_sysctl_header;
static int pfm_context_unload(pfm_context_t *ctx, void *arg, int count, struct pt_regs *regs);
@@ -6687,7 +6678,7 @@ pfm_init(void)
/*
* create /proc/sys/kernel/perfmon (for debugging purposes)
*/
- pfm_sysctl_header = register_sysctl_table(pfm_sysctl_root);
+ pfm_sysctl_header = register_sysctl_paths(pfm_path, pfm_ctl_table);
/*
* initialize all our spinlocks
--
1.7.5.134.g1c08b
^ permalink raw reply related
* [v2 041/115] sysctl: remove .child from s390dbf/
From: Lucian Adrian Grijincu @ 2011-05-08 22:38 UTC (permalink / raw)
To: linux-kernel; +Cc: netdev, Lucian Adrian Grijincu
In-Reply-To: <1304894407-32201-1-git-send-email-lucian.grijincu@gmail.com>
Signed-off-by: Lucian Adrian Grijincu <lucian.grijincu@gmail.com>
---
arch/s390/kernel/debug.c | 13 ++++---------
1 files changed, 4 insertions(+), 9 deletions(-)
diff --git a/arch/s390/kernel/debug.c b/arch/s390/kernel/debug.c
index 5ad6bc0..384f67b 100644
--- a/arch/s390/kernel/debug.c
+++ b/arch/s390/kernel/debug.c
@@ -902,7 +902,7 @@ static struct ctl_table s390dbf_table[] = {
.mode = S_IRUGO | S_IWUSR,
.proc_handler = proc_dointvec,
},
- {
+ {
.procname = "debug_active",
.data = &debug_active,
.maxlen = sizeof(int),
@@ -912,13 +912,8 @@ static struct ctl_table s390dbf_table[] = {
{ }
};
-static struct ctl_table s390dbf_dir_table[] = {
- {
- .procname = "s390dbf",
- .maxlen = 0,
- .mode = S_IRUGO | S_IXUGO,
- .child = s390dbf_table,
- },
+static const __initdata struct ctl_path s390dbf_path[] = {
+ { .procname = "s390dbf" },
{ }
};
@@ -1071,7 +1066,7 @@ __init debug_init(void)
{
int rc = 0;
- s390dbf_sysctl_header = register_sysctl_table(s390dbf_dir_table);
+ s390dbf_sysctl_header = register_sysctl_paths(s390dbf_path, s390dbf_table);
mutex_lock(&debug_mutex);
debug_debugfs_root_entry = debugfs_create_dir(DEBUG_DIR_ROOT,NULL);
initialized = 1;
--
1.7.5.134.g1c08b
^ permalink raw reply related
* [v2 040/115] sysctl: remove .child from appldata/ (s390)
From: Lucian Adrian Grijincu @ 2011-05-08 22:38 UTC (permalink / raw)
To: linux-kernel; +Cc: netdev, Lucian Adrian Grijincu
In-Reply-To: <1304894407-32201-1-git-send-email-lucian.grijincu@gmail.com>
Signed-off-by: Lucian Adrian Grijincu <lucian.grijincu@gmail.com>
---
arch/s390/appldata/appldata_base.c | 42 ++++++++++++++++++------------------
1 files changed, 21 insertions(+), 21 deletions(-)
diff --git a/arch/s390/appldata/appldata_base.c b/arch/s390/appldata/appldata_base.c
index 5c91995..0f336a8 100644
--- a/arch/s390/appldata/appldata_base.c
+++ b/arch/s390/appldata/appldata_base.c
@@ -49,7 +49,6 @@ static struct platform_device *appldata_pdev;
/*
* /proc entries (sysctl)
*/
-static const char appldata_proc_name[APPLDATA_PROC_NAME_LENGTH] = "appldata";
static int appldata_timer_handler(ctl_table *ctl, int write,
void __user *buffer, size_t *lenp, loff_t *ppos);
static int appldata_interval_handler(ctl_table *ctl, int write,
@@ -71,14 +70,9 @@ static struct ctl_table appldata_table[] = {
{ },
};
-static struct ctl_table appldata_dir_table[] = {
- {
- .procname = appldata_proc_name,
- .maxlen = 0,
- .mode = S_IRUGO | S_IXUGO,
- .child = appldata_table,
- },
- { },
+static const struct ctl_path appldata_path[] = {
+ { .procname = "appldata" },
+ { }
};
/*
@@ -424,6 +418,18 @@ out:
/************************* module-ops management *****************************/
+
+static const struct ctl_table appldata_ops_template[2] = {
+ {
+ .procname = NULL, /* ops->name */
+ .data = NULL, /* ops */
+ .maxlen = 0,
+ .mode = S_IRUGO | S_IWUSR,
+ .proc_handler = appldata_generic_handler,
+ },
+ { }
+};
+
/*
* appldata_register_ops()
*
@@ -434,7 +440,8 @@ int appldata_register_ops(struct appldata_ops *ops)
if (ops->size > APPLDATA_MAX_REC_SIZE)
return -EINVAL;
- ops->ctl_table = kzalloc(4 * sizeof(struct ctl_table), GFP_KERNEL);
+ ops->ctl_table = kmemdup(&appldata_ops_template,
+ sizeof(appldata_ops_template), GFP_KERNEL);
if (!ops->ctl_table)
return -ENOMEM;
@@ -442,17 +449,10 @@ int appldata_register_ops(struct appldata_ops *ops)
list_add(&ops->list, &appldata_ops_list);
mutex_unlock(&appldata_ops_mutex);
- ops->ctl_table[0].procname = appldata_proc_name;
- ops->ctl_table[0].maxlen = 0;
- ops->ctl_table[0].mode = S_IRUGO | S_IXUGO;
- ops->ctl_table[0].child = &ops->ctl_table[2];
-
- ops->ctl_table[2].procname = ops->name;
- ops->ctl_table[2].mode = S_IRUGO | S_IWUSR;
- ops->ctl_table[2].proc_handler = appldata_generic_handler;
- ops->ctl_table[2].data = ops;
+ ops->ctl_table[0].procname = ops->name;
+ ops->ctl_table[0].data = ops;
- ops->sysctl_header = register_sysctl_table(ops->ctl_table);
+ ops->sysctl_header = register_sysctl_paths(appldata_path, ops->ctl_table);
if (!ops->sysctl_header)
goto out;
return 0;
@@ -649,7 +649,7 @@ static int __init appldata_init(void)
/* Register cpu hotplug notifier */
register_hotcpu_notifier(&appldata_nb);
- appldata_sysctl_header = register_sysctl_table(appldata_dir_table);
+ appldata_sysctl_header = register_sysctl_paths(appldata_path, appldata_table);
return 0;
out_device:
--
1.7.5.134.g1c08b
^ permalink raw reply related
* [v2 039/115] sysctl: remove .child from lasat/ (mips)
From: Lucian Adrian Grijincu @ 2011-05-08 22:38 UTC (permalink / raw)
To: linux-kernel; +Cc: netdev, Lucian Adrian Grijincu
In-Reply-To: <1304894407-32201-1-git-send-email-lucian.grijincu@gmail.com>
Signed-off-by: Lucian Adrian Grijincu <lucian.grijincu@gmail.com>
---
arch/mips/lasat/sysctl.c | 13 ++++---------
1 files changed, 4 insertions(+), 9 deletions(-)
diff --git a/arch/mips/lasat/sysctl.c b/arch/mips/lasat/sysctl.c
index d87ffd0..a6191f0 100644
--- a/arch/mips/lasat/sysctl.c
+++ b/arch/mips/lasat/sysctl.c
@@ -262,21 +262,16 @@ static ctl_table lasat_table[] = {
{}
};
-static ctl_table lasat_root_table[] = {
- {
- .procname = "lasat",
- .mode = 0555,
- .child = lasat_table
- },
- {}
+static const __initdata struct ctl_path lasat_path[] = {
+ { .procname = "lasat" },
+ { }
};
static int __init lasat_register_sysctl(void)
{
struct ctl_table_header *lasat_table_header;
- lasat_table_header =
- register_sysctl_table(lasat_root_table);
+ lasat_table_header = register_sysctl_paths(lasat_path, lasat_table);
if (!lasat_table_header) {
printk(KERN_ERR "Unable to register LASAT sysctl\n");
return -ENOMEM;
--
1.7.5.134.g1c08b
^ permalink raw reply related
* [v2 038/115] sysctl: remove .child from reboot/warm (arm)
From: Lucian Adrian Grijincu @ 2011-05-08 22:38 UTC (permalink / raw)
To: linux-kernel; +Cc: netdev, Lucian Adrian Grijincu
In-Reply-To: <1304894407-32201-1-git-send-email-lucian.grijincu@gmail.com>
Signed-off-by: Lucian Adrian Grijincu <lucian.grijincu@gmail.com>
---
arch/arm/mach-bcmring/arch.c | 25 ++++++++++++-------------
1 files changed, 12 insertions(+), 13 deletions(-)
diff --git a/arch/arm/mach-bcmring/arch.c b/arch/arm/mach-bcmring/arch.c
index 73eb066..33c10fd 100644
--- a/arch/arm/mach-bcmring/arch.c
+++ b/arch/arm/mach-bcmring/arch.c
@@ -55,20 +55,18 @@ static struct ctl_table_header *bcmring_sysctl_header;
static struct ctl_table bcmring_sysctl_warm_reboot[] = {
{
- .procname = "warm",
- .data = &bcmring_arch_warm_reboot,
- .maxlen = sizeof(int),
- .mode = 0644,
- .proc_handler = proc_dointvec},
- {}
+ .procname = "warm",
+ .data = &bcmring_arch_warm_reboot,
+ .maxlen = sizeof(int),
+ .mode = 0644,
+ .proc_handler = proc_dointvec,
+ },
+ { }
};
-static struct ctl_table bcmring_sysctl_reboot[] = {
- {
- .procname = "reboot",
- .mode = 0555,
- .child = bcmring_sysctl_warm_reboot},
- {}
+static const __initdata struct ctl_path bcmring_sysctl_path[] = {
+ { .procname = "reboot" },
+ { }
};
static struct resource nand_resource[] = {
@@ -117,7 +115,8 @@ static struct platform_device *devices[] __initdata = {
static void __init bcmring_init_machine(void)
{
- bcmring_sysctl_header = register_sysctl_table(bcmring_sysctl_reboot);
+ bcmring_sysctl_header = register_sysctl_paths(bcmring_sysctl_path,
+ bcmring_sysctl_warm_reboot);
/* Enable spread spectrum */
chipcHw_enableSpreadSpectrum();
--
1.7.5.134.g1c08b
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox