From: Amit Gud <agud@redhat.com>
To: linux-kernel@vger.kernel.org
Subject: [RFC] [PATCH] sysctl for the latecomers
Date: Tue, 01 Aug 2006 10:49:20 -0400 [thread overview]
Message-ID: <44CF69F0.6040801@redhat.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 701 bytes --]
/etc/sysctl.conf values are of no use to kernel modules that are
inserted after init scripts call sysctl for the values in /etc/sysctl.conf
For modules to use the values stored in the file /etc/sysctl.conf,
sysctl kernel code can keep record of 'limited' values, for sysctl
entries which haven't been registered yet. During registration, sysctl
code can check against the stored values and call the appropriate
strategy and proc_handler routines if a match is found.
Attached patch does just that. This patch is NOT tested and is just to
get opinions, if something like this is a right way of addressing this
problem.
Thanks,
AG
--
May the source be with you.
http://www.cis.ksu.edu/~gud
[-- Attachment #2: sysctl-pending-values-v0.1.patch --]
[-- Type: text/plain, Size: 3651 bytes --]
* Warning: This patch is a prototype and is NOT tested. *
Signed-off-by: Amit Gud <agud@redhat.com>
---
--- kernel/sysctl.c.orig 2006-07-20 16:56:09.000000000 -0400
+++ kernel/sysctl.c 2006-07-20 19:33:18.000000000 -0400
@@ -133,6 +133,9 @@ extern int no_unaligned_warning;
static int parse_table(int __user *, int, void __user *, size_t __user *, void __user *, size_t,
ctl_table *, void **);
+static void check_pending_values(ctl_table *);
+static void store_pending_val(int, void *, size_t);
+static void init_pending_value_table();
static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
void __user *buffer, size_t *lenp, loff_t *ppos);
@@ -158,6 +161,23 @@ extern ctl_table inotify_table[];
int sysctl_legacy_va_layout;
#endif
+/* struct ctl_pending_values is used for temporarily storing data values
+ for the entries which are not found at the _sysctl(2) time. This is
+ useful for the modules which are required to use the values stored
+ in /etc/sysctl.conf. During regiter_sysctl_table() these ctl_names
+ are checked against the ctl_names that are being registered and
+ 'strategy' and 'proc_handler' is called if previous entry is found. */
+#define NR_TEMP_VALUES 32 /* temporary storage for the data for unmatched ctl_names */
+
+struct ctl_pending_val_s {
+ int name;
+ void *data;
+ size_t len;
+} ctl_pending_values[NR_TEMP_VALUES];
+
+static int ctl_index = 0;
+spinlock_t ctl_pending_lock = SPIN_LOCK_UNLOCKED;
+
/* /proc declarations: */
#ifdef CONFIG_PROC_FS
@@ -1099,12 +1119,20 @@ static void start_unregistering(struct c
list_del_init(&p->ctl_entry);
}
+static void init_pending_value_table()
+{
+ int i;
+ for(i = 0; i < NR_TEMP_VALUES; i++)
+ ctl_pending_values[i].name = 0;
+}
+
void __init sysctl_init(void)
{
#ifdef CONFIG_PROC_FS
register_proc_table(root_table, proc_sys_root, &root_table_header);
init_irq_proc();
#endif
+ init_pending_value_table();
}
int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
@@ -1186,6 +1214,20 @@ static inline int ctl_perm(ctl_table *ta
return test_perm(table->mode, op);
}
+static void store_pending_val(int n, void *newval, size_t newlen)
+{
+ spin_lock(&ctl_pending_lock);
+ kfree(ctl_pending_values[ctl_index].data);
+
+ ctl_pending_values[ctl_index].name = n;
+ ctl_pending_values[ctl_index].data = kmalloc(newlen, GFP_ATOMIC);
+ memcpy(ctl_pending_values[ctl_index].data, newval, newlen);
+ ctl_pending_values[ctl_index].len = newlen;
+
+ ctl_index = (++ctl_index % NR_TEMP_VALUES);
+ spin_unlock(&ctl_pending_lock);
+}
+
static int parse_table(int __user *name, int nlen,
void __user *oldval, size_t __user *oldlenp,
void __user *newval, size_t newlen,
@@ -1222,9 +1264,26 @@ repeat:
return error;
}
}
+ store_pending_val(n, newval, newlen);
return -ENOTDIR;
}
+static void check_pending_values(ctl_table *table)
+{
+ int i;
+ spin_lock(&ctl_pending_lock);
+ for(i = 0; i < NR_TEMP_VALUES; i++) {
+ int error;
+ void *context = NULL;
+ error = parse_table(&ctl_pending_values[i].name, 1, 0, 0, ctl_pending_values[i].data,
+ ctl_pending_values[i].len, table, &context);
+ kfree(context);
+ if(!error)
+ ctl_pending_values[i].name = 0;
+ }
+ spin_unlock(&ctl_pending_lock);
+}
+
/* Perform the actual read/write of a sysctl table entry. */
int do_sysctl_strategy (ctl_table *table,
int __user *name, int nlen,
@@ -1365,6 +1424,7 @@ struct ctl_table_header *register_sysctl
#ifdef CONFIG_PROC_FS
register_proc_table(table, proc_sys_root, tmp);
#endif
+ check_pending_values(table);
return tmp;
}
next reply other threads:[~2006-08-01 14:45 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-08-01 14:49 Amit Gud [this message]
2006-08-01 15:25 ` [RFC] [PATCH] sysctl for the latecomers Frederik Deweerdt
2006-08-01 16:56 ` Chase Venters
2006-08-01 17:22 ` Chase Venters
2006-08-01 19:04 ` Amit Gud
2006-08-01 20:36 ` Chase Venters
2006-08-02 14:56 ` Horst H. von Brand
2006-08-01 17:41 ` H. Peter Anvin
2006-08-01 18:54 ` Andi Kleen
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=44CF69F0.6040801@redhat.com \
--to=agud@redhat.com \
--cc=linux-kernel@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.