Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

sysctl: add ctl_cookie and ctl_cookie_handler

The cookie represent a piece of data and a handler for it that is
associated with the header.

No one uses this at this point. Patches will passing cookie + handler
will be submitted later in various kernel subsystems that can benefit
from this.

The handler is meant to create a new ctl_table based on a template
ctl_table and the cookie. This is useful in lots of places in the
kernel where we kmemdup() an array of template ctl_tables and change
fields in a predictable way.

Signed-off-by: Lucian Adrian Grijincu <lucian.grijincu@gmail.com>
  • Loading branch information...
commit ac5ea7398d0635203675161f0cb081db9e040c00 1 parent b5d970b
@luciang authored
View
4 fs/proc/proc_sysctl.c
@@ -166,6 +166,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
struct inode *inode = filp->f_path.dentry->d_inode;
struct ctl_table_header *head = sysctl_use_header(PROC_I(inode)->sysctl);
struct ctl_table *table = PROC_I(inode)->sysctl_entry;
+ struct ctl_table tmp;
ssize_t error;
size_t res;
@@ -185,6 +186,9 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
if (!table->proc_handler)
goto out;
+ if (head->ctl_cookie_handler)
+ table = head->ctl_cookie_handler(&tmp, table, head);
+
/* careful: calling conventions are nasty here */
res = count;
error = table->proc_handler(table, write, buf, &res, ppos);
View
14 include/linux/sysctl.h
@@ -1073,6 +1073,11 @@ struct ctl_table_group {
};
+/* use this to create dynamic ctl_table elements based on the @src and @head */
+typedef struct ctl_table* ctl_cookie_handler_t(struct ctl_table *dst,
+ struct ctl_table *src,
+ struct ctl_table_header *head);
+
#define CTL_TYPE_FILE_WRAPPER 1
#define CTL_TYPE_DIR 2
#define CTL_TYPE_NETNS_DIR 3
@@ -1098,9 +1103,12 @@ struct ctl_table_header {
struct rb_root ctl_rb_subdirs;
struct rb_node ctl_rb_node;
};
-
- /* only used in CTL_TYPE_FILE_WRAPPER */
- struct list_head ctl_entry;
+ struct {
+ /* only used in CTL_TYPE_FILE_WRAPPER */
+ struct list_head ctl_entry;
+ ctl_cookie_handler_t *ctl_cookie_handler;
+ void *ctl_cookie;
+ };
};
View
3  kernel/sysctl.c
@@ -2151,6 +2151,9 @@ struct ctl_table_header *__register_sysctl_paths_impl(struct ctl_table_group *gr
header->ctl_table_arg = table;
header->ctl_header_refs = 1;
header->ctl_owned_dirs_refs = dirs_created;
+ header->ctl_cookie_handler = NULL;
+ header->ctl_cookie = NULL;
+
sysctl_write_lock_head(header->parent);
Please sign in to comment.
Something went wrong with that request. Please try again.