All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rmmod notifier chain
@ 2005-09-08 15:03 Jan Beulich
  2005-09-08 15:11 ` Patrick McHardy
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Jan Beulich @ 2005-09-08 15:03 UTC (permalink / raw)
  To: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 3029 bytes --]

(Note: Patch also attached because the inline version is certain to get
line wrapped.)

Debugging and maintenance support code occasionally needs to know not
only of module insertions, but also modulke removals. This adds a
notifier
chain for this purpose.

Signed-off-by: Jan Beulich <jbeulich@novell.com>

diff -Npru 2.6.13/include/linux/module.h
2.6.13-rmmod-notifier/include/linux/module.h
--- 2.6.13/include/linux/module.h	2005-08-29 01:41:01.000000000
+0200
+++ 2.6.13-rmmod-notifier/include/linux/module.h	2005-09-01
11:32:12.000000000 +0200
@@ -431,6 +431,8 @@ const struct exception_table_entry *sear
 
 int register_module_notifier(struct notifier_block * nb);
 int unregister_module_notifier(struct notifier_block * nb);
+int register_rmmodule_notifier(struct notifier_block * nb);
+int unregister_rmmodule_notifier(struct notifier_block * nb);
 
 extern void print_modules(void);
 
diff -Npru 2.6.13/kernel/module.c
2.6.13-rmmod-notifier/kernel/module.c
--- 2.6.13/kernel/module.c	2005-08-29 01:41:01.000000000 +0200
+++ 2.6.13-rmmod-notifier/kernel/module.c	2005-09-02
09:46:24.000000000 +0200
@@ -62,6 +62,8 @@ static LIST_HEAD(modules);
 
 static DECLARE_MUTEX(notify_mutex);
 static struct notifier_block * module_notify_list;
+static DECLARE_MUTEX(rmmod_notify_mutex);
+static struct notifier_block * rmmodule_notify_list;
 
 int register_module_notifier(struct notifier_block * nb)
 {
@@ -83,6 +85,26 @@ int unregister_module_notifier(struct no
 }
 EXPORT_SYMBOL(unregister_module_notifier);
 
+int register_rmmodule_notifier(struct notifier_block * nb)
+{
+	int err;
+	down(&rmmod_notify_mutex);
+	err = notifier_chain_register(&rmmodule_notify_list, nb);
+	up(&rmmod_notify_mutex);
+	return err;
+}
+EXPORT_SYMBOL(register_rmmodule_notifier);
+
+int unregister_rmmodule_notifier(struct notifier_block * nb)
+{
+	int err;
+	down(&rmmod_notify_mutex);
+	err = notifier_chain_unregister(&rmmodule_notify_list, nb);
+	up(&rmmod_notify_mutex);
+	return err;
+}
+EXPORT_SYMBOL(unregister_rmmodule_notifier);
+
 /* We require a truly strong try_module_get() */
 static inline int strong_try_module_get(struct module *mod)
 {
@@ -1165,6 +1187,10 @@ static int __unlink_module(void *_mod)
 /* Free a module, remove from lists, etc (must hold module mutex). */
 static void free_module(struct module *mod)
 {
+	down(&rmmod_notify_mutex);
+	notifier_call_chain(&rmmodule_notify_list, MODULE_STATE_GOING,
mod);
+	up(&rmmod_notify_mutex);
+
 	/* Delete from various lists */
 	stop_machine_run(__unlink_module, mod, NR_CPUS);
 	remove_sect_attrs(mod);
@@ -1910,9 +1936,13 @@ sys_init_module(void __user *umod,
                    buggy refcounters. */
 		mod->state = MODULE_STATE_GOING;
 		synchronize_sched();
-		if (mod->unsafe)
+		if (mod->unsafe) {
 			printk(KERN_ERR "%s: module is now stuck!\n",
 			       mod->name);
+			down(&rmmod_notify_mutex);
+			notifier_call_chain(&rmmodule_notify_list,
MODULE_STATE_GOING, mod);
+			up(&rmmod_notify_mutex);
+		}
 		else {
 			module_put(mod);
 			down(&module_mutex);


[-- Attachment #2: linux-2.6.13-rmmod-notifier.patch --]
[-- Type: application/octet-stream, Size: 3028 bytes --]

(Note: Patch also attached because the inline version is certain to get
line wrapped.)

Debugging and maintenance support code occasionally needs to know not
only of module insertions, but also modulke removals. This adds a notifier
chain for this purpose.

Signed-off-by: Jan Beulich <jbeulich@novell.com>

diff -Npru 2.6.13/include/linux/module.h 2.6.13-rmmod-notifier/include/linux/module.h
--- 2.6.13/include/linux/module.h	2005-08-29 01:41:01.000000000 +0200
+++ 2.6.13-rmmod-notifier/include/linux/module.h	2005-09-01 11:32:12.000000000 +0200
@@ -431,6 +431,8 @@ const struct exception_table_entry *sear
 
 int register_module_notifier(struct notifier_block * nb);
 int unregister_module_notifier(struct notifier_block * nb);
+int register_rmmodule_notifier(struct notifier_block * nb);
+int unregister_rmmodule_notifier(struct notifier_block * nb);
 
 extern void print_modules(void);
 
diff -Npru 2.6.13/kernel/module.c 2.6.13-rmmod-notifier/kernel/module.c
--- 2.6.13/kernel/module.c	2005-08-29 01:41:01.000000000 +0200
+++ 2.6.13-rmmod-notifier/kernel/module.c	2005-09-02 09:46:24.000000000 +0200
@@ -62,6 +62,8 @@ static LIST_HEAD(modules);
 
 static DECLARE_MUTEX(notify_mutex);
 static struct notifier_block * module_notify_list;
+static DECLARE_MUTEX(rmmod_notify_mutex);
+static struct notifier_block * rmmodule_notify_list;
 
 int register_module_notifier(struct notifier_block * nb)
 {
@@ -83,6 +85,26 @@ int unregister_module_notifier(struct no
 }
 EXPORT_SYMBOL(unregister_module_notifier);
 
+int register_rmmodule_notifier(struct notifier_block * nb)
+{
+	int err;
+	down(&rmmod_notify_mutex);
+	err = notifier_chain_register(&rmmodule_notify_list, nb);
+	up(&rmmod_notify_mutex);
+	return err;
+}
+EXPORT_SYMBOL(register_rmmodule_notifier);
+
+int unregister_rmmodule_notifier(struct notifier_block * nb)
+{
+	int err;
+	down(&rmmod_notify_mutex);
+	err = notifier_chain_unregister(&rmmodule_notify_list, nb);
+	up(&rmmod_notify_mutex);
+	return err;
+}
+EXPORT_SYMBOL(unregister_rmmodule_notifier);
+
 /* We require a truly strong try_module_get() */
 static inline int strong_try_module_get(struct module *mod)
 {
@@ -1165,6 +1187,10 @@ static int __unlink_module(void *_mod)
 /* Free a module, remove from lists, etc (must hold module mutex). */
 static void free_module(struct module *mod)
 {
+	down(&rmmod_notify_mutex);
+	notifier_call_chain(&rmmodule_notify_list, MODULE_STATE_GOING, mod);
+	up(&rmmod_notify_mutex);
+
 	/* Delete from various lists */
 	stop_machine_run(__unlink_module, mod, NR_CPUS);
 	remove_sect_attrs(mod);
@@ -1910,9 +1936,13 @@ sys_init_module(void __user *umod,
                    buggy refcounters. */
 		mod->state = MODULE_STATE_GOING;
 		synchronize_sched();
-		if (mod->unsafe)
+		if (mod->unsafe) {
 			printk(KERN_ERR "%s: module is now stuck!\n",
 			       mod->name);
+			down(&rmmod_notify_mutex);
+			notifier_call_chain(&rmmodule_notify_list, MODULE_STATE_GOING, mod);
+			up(&rmmod_notify_mutex);
+		}
 		else {
 			module_put(mod);
 			down(&module_mutex);

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

end of thread, other threads:[~2005-09-12  7:10 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-09-08 15:03 [PATCH] rmmod notifier chain Jan Beulich
2005-09-08 15:11 ` Patrick McHardy
2005-09-08 15:16   ` Jan Beulich
2005-09-08 15:16 ` Christoph Hellwig
2005-09-08 15:20   ` viro
2005-09-08 15:22   ` Jan Beulich
2005-09-09  1:46     ` Andrew Morton
2005-09-09 12:44       ` Jan Beulich
2005-09-09 13:44         ` Jesper Juhl
2005-09-09 15:37         ` Paul Jackson
2005-09-09 18:27         ` Andrew Morton
2005-09-12  6:49           ` Jan Beulich
2005-09-12  7:10             ` Andrew Morton
2005-09-08 15:33 ` Tom Rini
2005-09-08 15:48   ` Jan Beulich
2005-09-09  9:42   ` [PATCH] rmmod notifier chain (attempt 2) Jan Beulich

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.