It is often advantageous to pass parameters to built-in kernel modules at boot time using the convention <module>.<option>. However, this does not work with loadable modules where modprobe reads its options from the config files. This patch adds support for modprobe to read /proc/cmdline and add any options it finds when inserting the modules.
Signed-off-by: Dan Nicholson dbn.lists@gmail.com --- This is the patch I sent to Jon a couple days ago. It's working in my testing. We briefly discussed whether there should be a switch to modprobe to disable the kernel command line parsing since /proc/cmdline is read only. Without the switch, only passing an opposing option on the modprobe command line would override what you booted with. Jon decided to move along without it for now.
doc/modprobe.sgml | 4 +++- modprobe.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletions(-)
diff --git a/doc/modprobe.sgml b/doc/modprobe.sgml index 767582a..fbbe2e8 100644 --- a/doc/modprobe.sgml +++ b/doc/modprobe.sgml @@ -77,7 +77,9 @@ <filename>/etc/modprobe.d</filename> directory (see <citerefentry> <refentrytitle>modprobe.conf</refentrytitle><manvolnum>5</manvolnum> - </citerefentry>). + </citerefentry>). <command>modprobe</command> will also use module + options specified on the kernel command line in the form of + <module>.<option>. </para> <para> Note that this version of <command>modprobe</command> does not diff --git a/modprobe.c b/modprobe.c index 9b171cc..51b9d64 100644 --- a/modprobe.c +++ b/modprobe.c @@ -1257,6 +1257,46 @@ static void read_toplevel_config(const char *filename, } }
+/* Read possible module arguments from the kernel command line. */ +static int read_kcmdline(int dump_only, struct module_options **options) +{ + char *line; + unsigned int linenum = 0; + FILE *kcmdline; + + kcmdline = fopen("/proc/cmdline", "r"); + if (!kcmdline) + return 0; + + while ((line = getline_wrapped(kcmdline, &linenum)) != NULL) { + char *ptr = line; + char *arg; + + while ((arg = strsep_skipspace(&ptr, "\t ")) != NULL) { + char *sep, *modname, *opt; + + sep = strchr(arg, '.'); + if (sep) { + if (!strchr(sep, '=')) + continue; + modname = arg; + *sep = '\0'; + opt = ++sep; + + if (dump_only) + printf("options %s %s\n", modname, opt); + + *options = add_options(underscores(modname), + opt, *options); + } + } + + free(line); + } + fclose(kcmdline); + return 1; +} + static void add_to_env_var(const char *option) { const char *oldenv; @@ -1586,6 +1626,7 @@ int main(int argc, char *argv[])
read_toplevel_config(config, "", 1, 0, &modoptions, &commands, &aliases, &blacklist); + read_kcmdline(1, &modoptions); read_config(aliasfilename, "", 1, 0,&modoptions, &commands, &aliases, &blacklist); read_config(symfilename, "", 1, 0, &modoptions, &commands, @@ -1617,6 +1658,9 @@ int main(int argc, char *argv[]) read_toplevel_config(config, modulearg, 0, remove, &modoptions, &commands, &aliases, &blacklist);
+ /* Read module options from kernel command line */ + read_kcmdline(0, &modoptions); + /* No luck? Try symbol names, if starts with symbol:. */ if (!aliases && strncmp(modulearg, "symbol:", strlen("symbol:")) == 0)
On Thu, 04 Sep 2008 13:54:18 -0700, Dan Nicholson dbn.lists@gmail.com wrote:
@@ -1586,6 +1626,7 @@ int main(int argc, char *argv[])
read_toplevel_config(config, "", 1, 0, &modoptions, &commands, &aliases, &blacklist);
read_config(aliasfilename, "", 1, 0,&modoptions, &commands, &aliases, &blacklist); read_config(symfilename, "", 1, 0, &modoptions, &commands,read_kcmdline(1, &modoptions);
I see two of them. You didn't add it into insmod by any chance? If so, there has to be a way to override this.
-- Pete
On Thu, Sep 4, 2008 at 2:13 PM, Pete Zaitcev zaitcev@redhat.com wrote:
On Thu, 04 Sep 2008 13:54:18 -0700, Dan Nicholson dbn.lists@gmail.com wrote:
@@ -1586,6 +1626,7 @@ int main(int argc, char *argv[])
read_toplevel_config(config, "", 1, 0, &modoptions, &commands, &aliases, &blacklist);
read_kcmdline(1, &modoptions); read_config(aliasfilename, "", 1, 0,&modoptions, &commands, &aliases, &blacklist); read_config(symfilename, "", 1, 0, &modoptions, &commands,
I see two of them. You didn't add it into insmod by any chance? If so, there has to be a way to override this.
I didn't add it into insmod. The first call to read_kcmdline() is during the dump_only (-c) fast path. There's an exit(0) on the next line after this hunk. The second call is during the normal loop over the module names supplied. Later in that loop is where the actual insmod/rmmod is performed in handle_module(). Is that what you're asking?
-- Dan
On Thu, 4 Sep 2008 14:22:46 -0700, "Dan Nicholson" dbn.lists@gmail.com wrote:
I see two of them. You didn't add it into insmod by any chance? If so, there has to be a way to override this.
I didn't add it into insmod. The first call to read_kcmdline() is during the dump_only (-c) fast path. There's an exit(0) on the next line after this hunk. The second call is during the normal loop over the module names supplied. Later in that loop is where the actual insmod/rmmod is performed in handle_module(). Is that what you're asking?
Yes, thanks. Looks like a good idea to me. Although personally I'm used to modifying both grub.conf and modprobe.conf simultaneously.
-- Pete
On Thu, Sep 4, 2008 at 2:29 PM, Pete Zaitcev zaitcev@redhat.com wrote:
Yes, thanks. Looks like a good idea to me. Although personally I'm used to modifying both grub.conf and modprobe.conf simultaneously.
Ah, right, I hadn't really thought about grub.conf. I would hope people don't start shoehorning loadable module options there instead of modprobe.conf. I was thinking more about people with temporary options, like you're seeing a bug and the kernel maintainer tells you to boot with some option and see how it affects the situation. Anyway, thanks for the review.
-- Dan
On Thu, 2008-09-04 at 13:54 -0700, Dan Nicholson wrote:
It is often advantageous to pass parameters to built-in kernel modules at boot time using the convention <module>.<option>. However, this does not work with loadable modules where modprobe reads its options from the config files. This patch adds support for modprobe to read /proc/cmdline and add any options it finds when inserting the modules.
This is really nice and will allow us to drop some code both from the livecd boot path and the installer, both of which read things from /proc/cmdline and drop them into modprobe.conf if relevant
Jeremy
On Thu, Sep 4, 2008 at 3:30 PM, Jeremy Katz katzj@redhat.com wrote:
On Thu, 2008-09-04 at 13:54 -0700, Dan Nicholson wrote:
It is often advantageous to pass parameters to built-in kernel modules at boot time using the convention <module>.<option>. However, this does not work with loadable modules where modprobe reads its options from the config files. This patch adds support for modprobe to read /proc/cmdline and add any options it finds when inserting the modules.
This is really nice and will allow us to drop some code both from the livecd boot path and the installer, both of which read things from /proc/cmdline and drop them into modprobe.conf if relevant
Yeah, it seemed like a nice win overall. I originally tried to hack rc.sysinit to create a temporary file in /etc/modprobe.d from /proc/cmdline, but it didn't work because or readonly /. This is cleaner, anyways. Hope to see it in a module-init-tools release soon.
-- Dan
On Thu, 2008-09-04 at 18:30 -0400, Jeremy Katz wrote:
On Thu, 2008-09-04 at 13:54 -0700, Dan Nicholson wrote:
It is often advantageous to pass parameters to built-in kernel modules at boot time using the convention <module>.<option>. However, this does not work with loadable modules where modprobe reads its options from the config files. This patch adds support for modprobe to read /proc/cmdline and add any options it finds when inserting the modules.
This is really nice and will allow us to drop some code both from the livecd boot path and the installer, both of which read things from /proc/cmdline and drop them into modprobe.conf if relevant
Yeah, this is what we were talking about on IRC the other day and then Dan happened to randomly send my way - I tried forwarding the patch the other day but a Red Hat internal systems glitch dropped the attached patch from my email. Anyway, a timely idea.
Jon.
On Thu, 2008-09-04 at 23:56 -0400, Jon Masters wrote:
On Thu, 2008-09-04 at 18:30 -0400, Jeremy Katz wrote:
On Thu, 2008-09-04 at 13:54 -0700, Dan Nicholson wrote:
It is often advantageous to pass parameters to built-in kernel modules at boot time using the convention <module>.<option>. However, this does not work with loadable modules where modprobe reads its options from the config files. This patch adds support for modprobe to read /proc/cmdline and add any options it finds when inserting the modules.
This is really nice and will allow us to drop some code both from the livecd boot path and the installer, both of which read things from /proc/cmdline and drop them into modprobe.conf if relevant
Yeah, this is what we were talking about on IRC the other day and then Dan happened to randomly send my way - I tried forwarding the patch the other day but a Red Hat internal systems glitch dropped the attached patch from my email. Anyway, a timely idea.
This patch is in upstream and built for Fedora in today's rawhide.
Jon.
kernel@lists.fedoraproject.org