Re: [PATCH 18/29] sysctl: Normalize the root_table data structure.

From: Lucian Adrian Grijincu
Date: Sun Jan 29 2012 - 12:36:44 EST


On Fri, Jan 27, 2012 at 6:51 AM, Eric W. Biederman
<ebiederm@xxxxxxxxxxxx> wrote:
> Every other directory has a .child member and we look at the .child
> for our entries. ÂDo the same for the root_table.
>
> Signed-off-by: Eric W. Biederman <ebiederm@xxxxxxxxxxxx>
> ---
> Âfs/proc/proc_sysctl.c | Â 15 +++++++++++----
> Â1 files changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
> index 7e96a26..88d1b06 100644
> --- a/fs/proc/proc_sysctl.c
> +++ b/fs/proc/proc_sysctl.c
> @@ -25,7 +25,14 @@ void proc_sys_poll_notify(struct ctl_table_poll *poll)
> Â Â Â Âwake_up_interruptible(&poll->wait);
> Â}
>
> -static struct ctl_table root_table[1];
> +static struct ctl_table root_table[] = {
> + Â Â Â {
> + Â Â Â Â Â Â Â .procname = "",
> + Â Â Â Â Â Â Â .mode = S_IRUGO|S_IXUGO,

Why not: .mode = S_IFDIR|S_IRUGO|S_IXUGO ?

You change it later and add IFDIR in patch 22/29 because of this
change (from 22/29):
- if (!table->child) {
+ if (!S_ISDIR(table->mode)) {

but if might as well be done here.


> + Â Â Â Â Â Â Â .child = &root_table[1],
> + Â Â Â },
> + Â Â Â { }
> +};
> Âstatic struct ctl_table_root sysctl_table_root;
> Âstatic struct ctl_table_header root_table_header = {
> Â Â Â Â{{.count = 1,
> @@ -319,7 +326,7 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
> Â Â Â Â Â Â Â Âgoto out;
> Â Â Â Â}

Somewhere above we have
struct ctl_table *table = PROC_I(inode)->sysctl_entry;
and sysctl_entry can take two values:
- NULL: fs/proc/inode.c:proc_alloc_inode()
- a non-NULL table in: proc_sys_make_inode()

The only inode that can be passed to proc_sys_lookup that can have
table=NULL is the root inode.
In that case head will be &root_table_header.


So head->ctl_table[1] == root_table_header.ctl_table[1] == root_table[1].


>
> - Â Â Â table = table ? table->child : head->ctl_table;
> + Â Â Â table = table ? table->child : &head->ctl_table[1];

I think this could be improved to something like this:
/* table == NULL only for the procfs root directory */
table = table ? table->child : &root_table[1];


It's not that important, as this code will go away in a few patches.

>
> Â Â Â Âp = find_in_table(table, name);
> Â Â Â Âif (!p) {
> @@ -510,7 +517,7 @@ static int proc_sys_readdir(struct file *filp, void *dirent, filldir_t filldir)
> Â Â Â Â Â Â Â Âgoto out;
> Â Â Â Â}
>
> - Â Â Â table = table ? table->child : head->ctl_table;
> + Â Â Â table = table ? table->child : &head->ctl_table[1];

Similar.

> Â Â Â Âret = 0;
> Â Â Â Â/* Avoid a switch here: arm builds fail with missing __cmpdi2 */
> @@ -966,7 +973,7 @@ struct ctl_table_header *__register_sysctl_table(
> Â Â Â Âspin_lock(&sysctl_lock);
> Â Â Â Âheader->set = lookup_header_set(root, namespaces);
> Â Â Â Âheader->attached_by = header->ctl_table;
> - Â Â Â header->attached_to = root_table;
> + Â Â Â header->attached_to = &root_table[1];
> Â Â Â Âheader->parent = &root_table_header;
> Â Â Â Âset = header->set;
> Â Â Â Âroot = header->root;
> --
> 1.7.2.5
>



--
Â.
..: Lucian
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/