From: Lucian Adrian Grijincu <lucian.grijincu@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: netdev@vger.kernel.org,
Lucian Adrian Grijincu <lucian.grijincu@gmail.com>
Subject: [v2 073/115] sysctl: group root-specific operations
Date: Mon, 9 May 2011 00:39:25 +0200 [thread overview]
Message-ID: <1304894407-32201-74-git-send-email-lucian.grijincu@gmail.com> (raw)
In-Reply-To: <1304894407-32201-1-git-send-email-lucian.grijincu@gmail.com>
No functional change, just moved stuff around.
->lookup was not moved to _ops because we'll get rid of it later.
This makes ctl_table_set occupy less space (the pointer to is_seen),
and that will means N*sizeof(void*) saved for N network
namespaces, but I don't that will impress anyone.
Signed-off-by: Lucian Adrian Grijincu <lucian.grijincu@gmail.com>
---
fs/proc/proc_sysctl.c | 4 ++--
include/linux/sysctl.h | 26 +++++++++++++++++++-------
kernel/sysctl.c | 25 ++++++++++++++-----------
net/sysctl_net.c | 20 ++++++++++++++------
4 files changed, 49 insertions(+), 26 deletions(-)
diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
index 125b679..55c9bd1 100644
--- a/fs/proc/proc_sysctl.c
+++ b/fs/proc/proc_sysctl.c
@@ -131,7 +131,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
* and won't be until we finish.
*/
error = -EPERM;
- if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
+ if (sysctl_perm(head->root->ctl_ops, table, write ? MAY_WRITE : MAY_READ))
goto out;
/* if that can happen at all, it should be -EINVAL, not -EISDIR */
@@ -305,7 +305,7 @@ static int proc_sys_permission(struct inode *inode, int mask,unsigned int flags)
if (!table) /* global root - r-xr-xr-x */
error = mask & MAY_WRITE ? -EACCES : 0;
else /* Use the permissions on the sysctl table entry */
- error = sysctl_perm(head->root, table, mask);
+ error = sysctl_perm(head->root->ctl_ops, table, mask);
sysctl_unuse_header(head);
return error;
diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
index 1af4ed5..8209d75 100644
--- a/include/linux/sysctl.h
+++ b/include/linux/sysctl.h
@@ -934,22 +934,21 @@ enum
/* For the /proc/sys support */
struct ctl_table;
+struct ctl_table_header;
+struct ctl_table_group_ops;
struct nsproxy;
struct ctl_table_root;
struct ctl_table_set {
struct list_head list;
struct ctl_table_set *parent;
- 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 *));
+ struct ctl_table_set *parent);
-struct ctl_table_header;
/* get/put a reference to this header that
* will be/was embedded in a procfs proc_inode */
@@ -962,8 +961,8 @@ extern struct ctl_table_header *sysctl_use_next_header(struct ctl_table_header *
extern struct ctl_table_header *__sysctl_use_next_header(struct nsproxy *namespaces,
struct ctl_table_header *prev);
extern void sysctl_unuse_header(struct ctl_table_header *prev);
-extern int sysctl_perm(struct ctl_table_root *root,
- struct ctl_table *table, int op);
+extern int sysctl_perm(const struct ctl_table_group_ops *ops,
+ struct ctl_table *table, int op);
typedef struct ctl_table ctl_table;
@@ -1029,12 +1028,25 @@ struct ctl_table
void *extra2;
};
+struct ctl_table_group_ops {
+ /* some sysctl entries are visible only in some situations.
+ * E.g.: /proc/sys/net/ipv4/conf/eth0/ is only visible in the
+ * netns in which that eth0 interface lives.
+ *
+ * If this hook is not set, then all the sysctl entries in
+ * this set are always visible. */
+ int (*is_seen)(struct ctl_table_set *set);
+
+ /* hook to alter permissions for some sysctl nodes at runtime */
+ int (*permissions)(struct ctl_table *table);
+};
+
struct ctl_table_root {
struct list_head root_list;
struct ctl_table_set default_set;
struct ctl_table_set *(*lookup)(struct ctl_table_root *root,
struct nsproxy *namespaces);
- int (*permissions)(struct ctl_table *table);
+ const struct ctl_table_group_ops *ctl_ops;
};
/* struct ctl_table_header is used to maintain dynamic lists of
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 6e4e32b..0f00b87 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -197,6 +197,9 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
#endif
+/* uses default ops */
+static const struct ctl_table_group_ops root_table_group_ops = { };
+
static struct ctl_table root_table[];
static struct ctl_table_root sysctl_table_root;
static struct ctl_table_header root_table_header = {
@@ -206,7 +209,9 @@ static struct ctl_table_header root_table_header = {
.root = &sysctl_table_root,
.set = &sysctl_table_root.default_set,
};
+
static struct ctl_table_root sysctl_table_root = {
+ .ctl_ops = &root_table_group_ops,
.root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
.default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
};
@@ -1659,12 +1664,13 @@ static int test_perm(int mode, int op)
return -EACCES;
}
-int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
+int sysctl_perm(const struct ctl_table_group_ops *ops,
+ struct ctl_table *table, int op)
{
int mode;
- if (root->permissions)
- mode = root->permissions(table);
+ if (ops->permissions)
+ mode = ops->permissions(table);
else
mode = table->mode;
@@ -1950,26 +1956,24 @@ void unregister_sysctl_table(struct ctl_table_header * header)
int sysctl_is_seen(struct ctl_table_header *p)
{
- struct ctl_table_set *set = p->set;
+ const struct ctl_table_group_ops *ops = p->root->ctl_ops;
int res;
spin_lock(&sysctl_lock);
if (p->unregistering)
res = 0;
- else if (!set->is_seen)
+ else if (!ops->is_seen)
res = 1;
else
- res = set->is_seen(set);
+ res = ops->is_seen(p->set);
spin_unlock(&sysctl_lock);
return res;
}
void setup_sysctl_set(struct ctl_table_set *p,
- struct ctl_table_set *parent,
- int (*is_seen)(struct ctl_table_set *))
+ struct ctl_table_set *parent)
{
INIT_LIST_HEAD(&p->list);
p->parent = parent ? parent : &sysctl_table_root.default_set;
- p->is_seen = is_seen;
}
#else /* !CONFIG_SYSCTL */
@@ -1984,8 +1988,7 @@ void unregister_sysctl_table(struct ctl_table_header * table)
}
void setup_sysctl_set(struct ctl_table_set *p,
- struct ctl_table_set *parent,
- int (*is_seen)(struct ctl_table_set *))
+ struct ctl_table_set *parent)
{
}
diff --git a/net/sysctl_net.c b/net/sysctl_net.c
index 1c0cb57..c0d7140 100644
--- a/net/sysctl_net.c
+++ b/net/sysctl_net.c
@@ -51,12 +51,17 @@ static int net_ctl_permissions(struct ctl_table *table)
return table->mode;
}
+static const struct ctl_table_group_ops net_sysctl_group_ops = {
+ .is_seen = is_seen,
+ .permissions = net_ctl_permissions,
+};
+
static struct ctl_table_root net_sysctl_root = {
.lookup = net_ctl_header_lookup,
- .permissions = net_ctl_permissions,
+ .ctl_ops = &net_sysctl_group_ops,
};
-static int net_ctl_ro_header_perms(ctl_table *table)
+static int net_ctl_ro_header_permissions(ctl_table *table)
{
if (net_eq(current->nsproxy->net_ns, &init_net))
return table->mode;
@@ -64,15 +69,18 @@ static int net_ctl_ro_header_perms(ctl_table *table)
return table->mode & ~0222;
}
+static const struct ctl_table_group_ops net_sysctl_ro_group_ops = {
+ .permissions = net_ctl_ro_header_permissions,
+};
+
static struct ctl_table_root net_sysctl_ro_root = {
- .permissions = net_ctl_ro_header_perms,
+ .ctl_ops = &net_sysctl_ro_group_ops,
};
static int __net_init sysctl_net_init(struct net *net)
{
setup_sysctl_set(&net->sysctls,
- &net_sysctl_ro_root.default_set,
- is_seen);
+ &net_sysctl_ro_root.default_set);
return 0;
}
@@ -93,7 +101,7 @@ static __init int net_sysctl_init(void)
if (ret)
goto out;
register_sysctl_root(&net_sysctl_root);
- setup_sysctl_set(&net_sysctl_ro_root.default_set, NULL, NULL);
+ setup_sysctl_set(&net_sysctl_ro_root.default_set, NULL);
register_sysctl_root(&net_sysctl_ro_root);
out:
return ret;
--
1.7.5.134.g1c08b
next prev parent reply other threads:[~2011-05-08 22:41 UTC|newest]
Thread overview: 100+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-08 22:38 [v2 000/115] faster tree-based sysctl implementation Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 001/115] sysctl: remove .child from dev/parport/default Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 002/115] sysctl: parport: reorder .child assignments to simplify review Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 003/115] sysctl: remove .child from dev/parport/PORT/devices/DEVICE Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 004/115] sysctl: remove .child from dev/parport/PORT/ Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 005/115] sysctl: remove .child from dev/parport/PORT/devices/ Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 006/115] sysctl: remove .child from kernel/vsyscall64 (x86) Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 007/115] sysctl: remove .child from abi/vsyscall32 (x86) Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 008/115] sysctl: remove .child from crypto/fips_enabled Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 009/115] sysctl: remove .child from dev/cdrom/ Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 010/115] sysctl: remove .child from dev/hpet/ Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 011/115] sysctl: remove .child from dev/ipmi/ Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 012/115] sysctl: remove .child from dev/rtc/ Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 013/115] sysctl: remove .child from dev/mac_hid/ Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 014/115] sysctl: remove .child from dev/raid/ Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 015/115] sysctl: remove .child from xpc/ Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 016/115] sysctl: remove .child from xpc/hb Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 017/115] sysctl: remove .child from kernel/sclp (s390) Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 018/115] sysctl: remove .child from dev/scsi Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 019/115] sysctl: remove .child from kernel/pty Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 020/115] sysctl: remove .child from coda/ Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 021/115] sysctl: remove .child from fscache/ Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 022/115] sysctl: remove .child from fs/nfs/ nlm_table table Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 023/115] sysctl: remove .child from fs/nfs/ nfs_cb_table Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 024/115] sysctl: remove .child from fs/ntfs-debug Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 025/115] sysctl: remove .child from fs/ocfs2/nm/ Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 026/115] sysctl: remove .child from fs/quota/ Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 027/115] sysctl: remove .child from fs/xfs/ Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 028/115] sysctl: remove .child from kernel/ (ipc) Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 029/115] sysctl: remove .child from fs/mqueue Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 030/115] sysctl: sched: add sd_table_template Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 031/115] sysctl: remove .child from kernel/sched_domain/cpuX/domainY/ Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 032/115] sysctl: remove .child from kernel/ (utsname) Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 033/115] sysctl: remove .child from sunrpc/ Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 034/115] sysctl: remove .child from sunrpc/svc_rdma Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 035/115] sysctl: remove .child from sunrpc/ (xprtrdma) Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 036/115] sysctl: remove .child from sunrpc/ (xprtsock) Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 037/115] sysctl: remove .child from bus/isa/ (arm) Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 038/115] sysctl: remove .child from reboot/warm (arm) Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 039/115] sysctl: remove .child from lasat/ (mips) Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 040/115] sysctl: remove .child from appldata/ (s390) Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 041/115] sysctl: remove .child from s390dbf/ Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 042/115] sysctl: remove .child from vm/ (s390) Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 043/115] sysctl: remove .child from kernel/perfmon/ (ia64) Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 044/115] sysctl: remove .child from kernel/ (ia64/kdump) Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 045/115] sysctl: remove .child from kernel/powersave-nap (powerpc) Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 046/115] sysctl: remove .child from pm/ (frv) Lucian Adrian Grijincu
2011-05-08 22:38 ` [v2 047/115] sysctl: remove .child from frv/ Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 048/115] sysctl: remove .child from sh64/unaligned_fixup/ Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 049/115] sysctl: delete unused register_sysctl_table function Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 050/115] sysctl: remove .child from ax25 table Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 051/115] sysctl: remove .child from net/ipv4/route and net/ipv4/neigh tables Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 052/115] sysctl: remove .child from net/ipv4/neigh table Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 053/115] sysctl: remove .child from net/ipv6/route, net/ipv6/icmp, net/ipv6 tables Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 054/115] sysctl: remove .child from net/llc tables Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 055/115] sysctl: call sysctl_init before the first sysctl registration Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 056/115] sysctl: no-child: manually register kernel/random Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 057/115] sysctl: no-child: manually register kernel/keys Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 058/115] sysctl: no-child: manually register fs/inotify Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 059/115] sysctl: no-child: manually register fs/epoll Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 060/115] sysctl: no-child: manually register root tables Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 061/115] sysctl: faster reimplementation of sysctl_check_table Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 062/115] sysctl: remove useless ctl_table->parent field Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 063/115] sysctl: simplify find_in_table Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 064/115] sysctl: sysctl_head_grab defaults to root header on NULL Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 065/115] sysctl: delete useless grab_header function Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 066/115] sysctl: rename ->used to ->ctl_use_refs Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 067/115] sysctl: rename sysctl_head_grab/finish to sysctl_use_header/unuse Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 068/115] sysctl: rename sysctl_head_next to sysctl_use_next_header Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 069/115] sysctl: split ->count into ctl_procfs_refs and ctl_header_refs Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 070/115] sysctl: rename sysctl_head_get/put to sysctl_proc_inode_get/put Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 071/115] sysctl: rename (un)use_table to __sysctl_(un)use_header Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 072/115] sysctl: simplify ->permissions hook Lucian Adrian Grijincu
2011-05-08 22:39 ` Lucian Adrian Grijincu [this message]
2011-05-08 22:39 ` [v2 074/115] sysctl: introduce ctl_table_group Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 075/115] sysctl: move removal from list out of start_unregistering Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 076/115] sysctl: faster tree-based sysctl implementation Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 077/115] sysctl: add duplicate entry and sanity ctl_table checks Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 078/115] sysctl: alloc ctl_table_header with kmem_cache Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 079/115] sysctl: single subheader path: optimisation for paths used only once Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 080/115] sysctl: single subheader path: net/ipv4/conf/DEVICE-NAME/ Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 081/115] sysctl: single subheader path: net/{ipv4|ipv6}/neigh/DEV/ Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 082/115] sysctl: single subheader path: net/ipv6/conf/DEVICE-NAME/ Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 083/115] sysctl: single subheader path: dev/parport/PORT/devices/DEVICE/ Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 084/115] sysctl: single subheader path: net/ax25/DEVICE Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 085/115] sysctl: single subheader path: kernel/sched_domain/CPU/DOMAIN/ Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 086/115] sysctl: single subheader path: net/decnet/conf/DEVNAME Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 087/115] sysctl: check netns-specific registration order respected Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 088/115] RFC: sysctl: convert read-write lock to RCU Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 089/115] RFC: sysctl: change type of ctl_procfs_refs to u8 Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 090/115] sysctl: warn if registration/unregistration order is not respected Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 091/115] sysctl: add register_sysctl_dir: register an empty sysctl directory Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 092/115] sysctl: sched: create empty dir with register_sysctl_dir Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 093/115] sysctl: ax25: " Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 094/115] sysctl: net/core: " Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 095/115] sysctl: net/ipv4/neigh: " Lucian Adrian Grijincu
2011-05-08 22:39 ` [v2 096/115] sysctl: net/ipv6/neigh: " Lucian Adrian Grijincu
2011-05-08 22:40 ` [v2 000/115] faster tree-based sysctl implementation David Miller
2011-05-09 3:11 ` Eric W. Biederman
2011-05-10 1:06 ` Lucian Adrian Grijincu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1304894407-32201-74-git-send-email-lucian.grijincu@gmail.com \
--to=lucian.grijincu@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).