linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Per Svennerbrandt <per.svennerbrandt@lbi.se>
To: Per Liden <per@fukt.bth.se>, Greg KH <greg@kroah.com>
Cc: linux-hotplug-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org
Subject: [PATCH][RFC] __request_module: fixed argument request_module with waitflag
Date: Wed, 18 May 2005 23:00:47 +0000	[thread overview]
Message-ID: <20050518230046.GB3011@tsiryulnik> (raw)
In-Reply-To: <Pine.LNX.4.63.0505102351300.8637@1-1-2-5a.f.sth.bostream.se>

The following extracts the code in request_module which is responsible
for executing modprobe into a new helper function called __request_module.
This new function takes the wait flag which gets passed down to
call_usermodeheper as an argument, allowing async execution of modprobe.

During the writing of this I've had a bit of a mental struggle about
whether or not maybe call_modprobe is a better name for this and thus
I'm fine with either one if anyone else has a preference.

Signed-off-by: Per Svennerbrandt <per.svennerbrandt@lbi.se>

--- linux-2.6.12-rc2/kernel/kmod.c.orig	2005-04-16 19:08:22.000000000 +0200
+++ linux-2.6.12-rc2/kernel/kmod.c	2005-05-12 23:50:00.000000000 +0200
@@ -49,6 +49,49 @@
 */
 char modprobe_path[KMOD_PATH_LEN] = "/sbin/modprobe";
 
+int __request_module(char *name, int wait)
+{
+	int ret;
+	unsigned int max_modprobes;
+	static atomic_t kmod_concurrent = ATOMIC_INIT(0);
+#define MAX_KMOD_CONCURRENT 50	/* Completely arbitrary value - KAO */
+	static int kmod_loop_msg;
+	
+	char *argv[] = { modprobe_path, "-q", "--", name, NULL };
+	static char *envp[] = { "HOME=/",
+				"TERM=linux",
+				"PATH=/sbin:/usr/sbin:/bin:/usr/bin",
+				NULL };
+				
+	/* If modprobe needs a service that is in a module, we get a recursive
+	 * loop.  Limit the number of running kmod threads to max_threads/2 or
+	 * MAX_KMOD_CONCURRENT, whichever is the smaller.  A cleaner method
+	 * would be to run the parents of this process, counting how many times
+	 * kmod was invoked.  That would mean accessing the internals of the
+	 * process tables to get the command line, proc_pid_cmdline is static
+	 * and it is not worth changing the proc code just to handle this case. 
+	 * KAO.
+	 *
+	 * "trace the ppid" is simple, but will fail if someone's
+	 * parent exits.  I think this is as good as it gets. --RR
+	 */
+	max_modprobes = min(max_threads/2, MAX_KMOD_CONCURRENT);
+	atomic_inc(&kmod_concurrent);
+	if (atomic_read(&kmod_concurrent) > max_modprobes) {
+		/* We may be blaming an innocent here, but unlikely */
+		if (kmod_loop_msg++ < 5)
+			printk(KERN_ERR
+			       "request_module: runaway loop modprobe %s\n",
+			       name);
+		atomic_dec(&kmod_concurrent);
+		return -ENOMEM;
+	}
+	ret = call_usermodehelper(modprobe_path, argv, envp, wait);
+	atomic_dec(&kmod_concurrent);
+	return ret;
+}
+EXPORT_SYMBOL(__request_module);
+
 /**
  * request_module - try to load a kernel module
  * @fmt:     printf style format string for the name of the module
@@ -67,50 +110,15 @@ int request_module(const char *fmt, ...)
 {
 	va_list args;
 	char module_name[MODULE_NAME_LEN];
-	unsigned int max_modprobes;
 	int ret;
-	char *argv[] = { modprobe_path, "-q", "--", module_name, NULL };
-	static char *envp[] = { "HOME=/",
-				"TERM=linux",
-				"PATH=/sbin:/usr/sbin:/bin:/usr/bin",
-				NULL };
-	static atomic_t kmod_concurrent = ATOMIC_INIT(0);
-#define MAX_KMOD_CONCURRENT 50	/* Completely arbitrary value - KAO */
-	static int kmod_loop_msg;
 
 	va_start(args, fmt);
 	ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
 	va_end(args);
 	if (ret >= MODULE_NAME_LEN)
 		return -ENAMETOOLONG;
 
-	/* If modprobe needs a service that is in a module, we get a recursive
-	 * loop.  Limit the number of running kmod threads to max_threads/2 or
-	 * MAX_KMOD_CONCURRENT, whichever is the smaller.  A cleaner method
-	 * would be to run the parents of this process, counting how many times
-	 * kmod was invoked.  That would mean accessing the internals of the
-	 * process tables to get the command line, proc_pid_cmdline is static
-	 * and it is not worth changing the proc code just to handle this case. 
-	 * KAO.
-	 *
-	 * "trace the ppid" is simple, but will fail if someone's
-	 * parent exits.  I think this is as good as it gets. --RR
-	 */
-	max_modprobes = min(max_threads/2, MAX_KMOD_CONCURRENT);
-	atomic_inc(&kmod_concurrent);
-	if (atomic_read(&kmod_concurrent) > max_modprobes) {
-		/* We may be blaming an innocent here, but unlikely */
-		if (kmod_loop_msg++ < 5)
-			printk(KERN_ERR
-			       "request_module: runaway loop modprobe %s\n",
-			       module_name);
-		atomic_dec(&kmod_concurrent);
-		return -ENOMEM;
-	}
-
-	ret = call_usermodehelper(modprobe_path, argv, envp, 1);
-	atomic_dec(&kmod_concurrent);
-	return ret;
+	return __request_module(module_name, 1);
 }
 EXPORT_SYMBOL(request_module);
 #endif /* CONFIG_KMOD */
--- linux-2.6.12-rc2/include/linux/kmod.h.orig	2005-03-02 08:37:49.000000000 +0100
+++ linux-2.6.12-rc2/include/linux/kmod.h	2005-05-12 23:53:22.000000000 +0200
@@ -28,8 +28,10 @@
 #ifdef CONFIG_KMOD
 /* modprobe exit status on success, -ve on error.  Return value
  * usually useless though. */
+extern int __request_module(char *name, int wait);
 extern int request_module(const char * name, ...) __attribute__ ((format (printf, 1, 2)));
 #else
+static inline int __request_module(char *name, int wait) { return -ENOSYS; }
 static inline int request_module(const char * name, ...) { return -ENOSYS; }
 #endif
 


-------------------------------------------------------
This SF.Net email is sponsored by Oracle Space Sweepstakes
Want to be the first software developer in space?
Enter now for the Oracle Space Sweepstakes!
http://ads.osdn.com/?ad_idt12&alloc_id\x16344&op=click
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

  parent reply	other threads:[~2005-05-18 23:00 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-05-06 21:22 [ANNOUNCE] hotplug-ng 002 release Greg KH
2005-05-08 22:52 ` Per Liden
2005-05-09 21:13   ` Per Svennerbrandt
2005-05-10 22:17     ` Per Liden
2005-05-10 22:41       ` Greg KH
2005-05-10 23:56         ` Per Liden
2005-05-11  1:22           ` Brian Gerst
2005-05-11  5:33           ` Greg KH
2005-05-18 23:00       ` Per Svennerbrandt
2005-05-18 23:00       ` Per Svennerbrandt [this message]
2005-05-18 23:01       ` [PATCH][RFC] request_modalias: MODALIAS based module loading Per Svennerbrandt
2005-05-18 23:37         ` Per Svennerbrandt
2005-05-10 22:41     ` [ANNOUNCE] hotplug-ng 002 release Greg KH
2005-05-12 21:42     ` Greg KH
2005-05-13  8:19       ` Michael Tokarev
2005-05-13 16:02         ` Greg KH
2005-05-13 23:21       ` Per Svennerbrandt
2005-05-14  5:59         ` Greg KH
2005-05-18  9:27     ` David Weinehall
2005-05-09 23:22   ` Greg KH
2005-05-10 21:51     ` Per Liden
2005-05-11  5:36       ` Greg KH
2005-05-09  3:57 ` Rusty Russell
2005-05-09 23:21   ` Greg KH
2005-05-10  9:29     ` Rusty Russell
2005-05-10  9:43       ` Marco d'Itri
2005-05-10 12:58         ` Alexander E. Patrakov
2005-05-10 17:24           ` Marco d'Itri
2005-05-10 20:13             ` Greg KH
2005-05-10 20:28               ` Lee Revell
2005-05-10 20:59                 ` Greg KH
2005-05-10 21:02                   ` Marco d'Itri
2005-05-10 20:31               ` Marco d'Itri
2005-05-10 20:52                 ` Greg KH
2005-05-10 20:59                   ` Bill Nottingham
2005-05-10 21:08                   ` Marco d'Itri
2005-05-10 21:22                     ` Erik van Konijnenburg
2005-05-10 23:55                       ` [PATCH] " Erik van Konijnenburg
2005-05-11  0:05                         ` Marco d'Itri
2005-05-11  5:40                           ` Greg KH
2005-05-11  0:08                         ` [PATCH] " Rusty Russell
2005-05-11  1:11                           ` Erik van Konijnenburg
2005-05-11  3:39                             ` Rusty Russell
2005-05-11  9:59                               ` Erik van Konijnenburg
2005-05-11 10:52                                 ` Rusty Russell
2005-05-11 10:58                                   ` Marco d'Itri
2005-05-11 13:06                                     ` Erik van Konijnenburg
2005-05-12  4:39                                       ` Rusty Russell
2005-05-12  7:47                                         ` Erik van Konijnenburg
2005-05-11  0:01               ` Rusty Russell
2005-05-11  0:10                 ` Marco d'Itri
2005-05-11  1:09                   ` Rusty Russell
2005-05-11  7:31 ` Christian Zoz
2005-05-14 23:02 ` Michael Tokarev
2005-05-16 19:11   ` Greg KH
2005-05-16 21:24 ` Marco d'Itri

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=20050518230046.GB3011@tsiryulnik \
    --to=per.svennerbrandt@lbi.se \
    --cc=greg@kroah.com \
    --cc=linux-hotplug-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=per@fukt.bth.se \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).