public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] Module load notification take 3
@ 2003-03-25  2:03 John Levon
  2003-03-25  2:13 ` [PATCH 2/2] " John Levon
  2003-03-25  6:32 ` [PATCH 1/2] " Rusty Russell
  0 siblings, 2 replies; 7+ messages in thread
From: John Levon @ 2003-03-25  2:03 UTC (permalink / raw)
  To: oprofile-list, torvalds, linux-kernel, rusty


Implement a module load notifier for the benefit of OProfile, tested
with .66 on UP.

This patch (1/2) provides the general support for registering notifiers,
and calls the notifier when a module is loaded.

Please apply.

john


diff -X dontdiff -Naur linux-linus/include/linux/module.h linux-cvs/include/linux/module.h
--- linux-linus/include/linux/module.h	2003-03-25 01:38:51.000000000 +0000
+++ linux-cvs/include/linux/module.h	2003-03-25 01:34:42.000000000 +0000
@@ -138,6 +138,7 @@
 	const struct exception_table_entry *entry;
 };
 
+struct notifier_block;
 
 #ifdef CONFIG_MODULES
 
@@ -348,6 +349,9 @@
 /* For extable.c to search modules' exception tables. */
 const struct exception_table_entry *search_module_extables(unsigned long addr);
 
+int register_module_notifier(struct notifier_block * nb);
+int unregister_module_notifier(struct notifier_block * nb);
+
 #else /* !CONFIG_MODULES... */
 #define EXPORT_SYMBOL(sym)
 #define EXPORT_SYMBOL_GPL(sym)
@@ -392,6 +396,18 @@
 {
 	return NULL;
 }
+
+static inline int register_module_notifier(struct notifier_block * nb)
+{
+	/* no events will happen anyway, so this can always succeed */
+	return 0;
+}
+
+static inline int unregister_module_notifier(struct notifier_block * nb)
+{
+	return 0;
+}
+
 #endif /* CONFIG_MODULES */
 
 #ifdef MODULE
diff -X dontdiff -Naur linux-linus/kernel/module.c linux-cvs/kernel/module.c
--- linux-linus/kernel/module.c	2003-03-17 21:44:21.000000000 +0000
+++ linux-cvs/kernel/module.c	2003-03-25 01:31:40.000000000 +0000
@@ -31,6 +31,7 @@
 #include <linux/errno.h>
 #include <linux/err.h>
 #include <linux/vermagic.h>
+#include <linux/notifier.h>
 #include <asm/uaccess.h>
 #include <asm/semaphore.h>
 #include <asm/pgalloc.h>
@@ -61,6 +62,29 @@
 static LIST_HEAD(symbols);
 static LIST_HEAD(extables);
 
+static DECLARE_MUTEX(notify_mutex);
+static struct notifier_block * module_notify_list;
+
+int register_module_notifier(struct notifier_block * nb)
+{
+	int err;
+	down(&notify_mutex);
+	err = notifier_chain_register(&module_notify_list, nb);
+	up(&notify_mutex);
+	return err;
+}
+EXPORT_SYMBOL(register_module_notifier);
+
+int unregister_module_notifier(struct notifier_block * nb)
+{
+	int err;
+	down(&notify_mutex);
+	err = notifier_chain_unregister(&module_notify_list, nb);
+	up(&notify_mutex);
+	return err;
+}
+EXPORT_SYMBOL(unregister_module_notifier);
+
 /* We require a truly strong try_module_get() */
 static inline int strong_try_module_get(struct module *mod)
 {
@@ -1368,6 +1392,10 @@
 	/* Drop lock so they can recurse */
 	up(&module_mutex);
 
+	down(&notify_mutex);
+	notifier_call_chain(&module_notify_list, MODULE_STATE_COMING, mod);
+	up(&notify_mutex);
+
 	/* Start the module */
 	ret = mod->init();
 	if (ret < 0) {


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2003-03-27  6:18 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-03-25  2:03 [PATCH 1/2] Module load notification take 3 John Levon
2003-03-25  2:13 ` [PATCH 2/2] " John Levon
2003-03-25  6:32 ` [PATCH 1/2] " Rusty Russell
2003-03-25 11:41   ` John Levon
2003-03-27  2:20     ` Rusty Russell
2003-03-27  4:17       ` John Levon
2003-03-27  5:26         ` Rusty Russell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox