Re: [PATCH 1/3] modprobe: blacklist modules on kernel commandline

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 26 May 2011, Tom Gundersen wrote:

Modules mod1, mod2 and mod3 can now be blacklisted by passing

modprobe.blacklist=mod1,mod2,mod3

on the kernel command line.

This is useful in case a module prevents the system from booting.


I've got a patch from PiterPUNK in a local git tree for that, and
I *thought* we'd sent it to Jon back in November  :/  Here's the
patch (attached):

-RW
From fffdceb4f03bf3c6deaa60f1d37a800ee99ec5fc Mon Sep 17 00:00:00 2001
From: Piter PUNK <piterpunk@xxxxxxxxxxxxx>
Date: Sun, 28 Nov 2010 21:48:09 -0600
Subject: [PATCH] modprobe.c: Allow blacklisting modules from kernel
 commandline

In many cases, a module is discovered to cause a system hang,
but there's no good way to blacklist it without booting from
recovery media.  This patch provides a way to do so, e.g.,
blacklist modules foo and bar:

  boot: vmlinuz module.blacklist=foo:bar

The separator is currently ":" but could certainly be changed
to e.g. "," if desired.
---
 modprobe.c |   42 +++++++++++++++++++++++++++++++++---------
 1 files changed, 33 insertions(+), 9 deletions(-)

diff --git a/modprobe.c b/modprobe.c
index 26a7163..86b5b33 100644
--- a/modprobe.c
+++ b/modprobe.c
@@ -1133,8 +1133,10 @@ static void parse_toplevel_config(const char *filename,
 	parse_config_scan("/etc/modprobe.d", conf, dump_only, removing);
 }
 
-/* Read possible module arguments from the kernel command line. */
-static int parse_kcmdline(int dump_only, struct module_options **options)
+/* Read possible module options or blacklist modules from the kernel command line. */
+static int parse_kcmdline(int dump_only, 
+			  struct module_options **options, 
+			  struct module_blacklist **blacklist)
 {
 	char *line;
 	unsigned int linenum = 0;
@@ -1149,7 +1151,7 @@ static int parse_kcmdline(int dump_only, struct module_options **options)
 		char *arg;
 
 		while ((arg = strsep_skipspace(&ptr, "\t ")) != NULL) {
-			char *sep, *modname, *opt;
+			char *sep, *modname, *opt, *cmd;
 
 			sep = strchr(arg, '.');
 			if (sep) {
@@ -1159,11 +1161,33 @@ static int parse_kcmdline(int dump_only, struct module_options **options)
 				*sep = '\0';
 				opt = ++sep;
 
-				if (dump_only)
-					printf("options %s %s\n", modname, opt);
-
-				*options = add_options(underscores(modname),
-						       opt, *options);
+				if (streq(modname, "modprobe")) {
+					sep = strchr(opt, '=');
+					cmd = opt;
+					*sep = '\0';
+					opt = ++sep;
+
+					// By now, we only blacklist modules. Who knows
+					// what we'll do tomorrow?
+					if (!streq(cmd, "blacklist"))
+						continue;
+
+					while((modname = strsep(&opt, ":")) != NULL) {
+						if (strlen(modname) > 0) {
+							if (dump_only)
+								printf("blacklist %s\n", 
+									modname);
+							*blacklist = add_blacklist(
+									underscores(modname),
+								       	*blacklist);
+						}
+					}
+				} else {
+					if (dump_only)
+						printf("options %s %s\n", modname, opt);
+					*options = add_options(underscores(modname),
+							       opt, *options);
+				}
 			}
 		}
 
@@ -1836,7 +1860,7 @@ int main(int argc, char *argv[])
 	parse_toplevel_config(configname, &conf, dump_config, flags & mit_remove);
 
 	/* Read module options from kernel command line */
-	parse_kcmdline(dump_config, &conf.options);
+	parse_kcmdline(dump_config, &conf.options, &conf.blacklist);
 	
 	if (dump_config) {
 		char *aliasfilename, *symfilename;
-- 
1.7.5.1


[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux