[netfilter-cvslog] r3592 - in trunk/nfsim: core kernelenv/include tools

rusty at netfilter.org rusty at netfilter.org
Wed Jan 12 12:37:11 CET 2005


Author: rusty at netfilter.org
Date: 2005-01-12 12:37:11 +0100 (Wed, 12 Jan 2005)
New Revision: 3592

Modified:
   trunk/nfsim/core/core.c
   trunk/nfsim/core/core.h
   trunk/nfsim/core/tui.c
   trunk/nfsim/kernelenv/include/kernelenv.h
   trunk/nfsim/tools/module.c
Log:
Implement module reference counts: otherwise ipt_recent tests with --failtest break.



Modified: trunk/nfsim/core/core.c
===================================================================
--- trunk/nfsim/core/core.c	2005-01-12 11:33:43 UTC (rev 3591)
+++ trunk/nfsim/core/core.c	2005-01-12 11:37:11 UTC (rev 3592)
@@ -467,8 +467,8 @@
 		     "Testing blossoms fail.");
 
 	message_cleanup();
-	unload_all_modules();
-	check_allocations();
+	if (unload_all_modules())
+		check_allocations();
 
 	return 0;
 }

Modified: trunk/nfsim/core/core.h
===================================================================
--- trunk/nfsim/core/core.h	2005-01-12 11:33:43 UTC (rev 3591)
+++ trunk/nfsim/core/core.h	2005-01-12 11:37:11 UTC (rev 3592)
@@ -273,7 +273,7 @@
 		int nonblock);
 
 bool load_all_modules(void);
-void unload_all_modules(void);
+bool unload_all_modules(void);
 
 void check_allocations(void);
 void netfilter_init(void);

Modified: trunk/nfsim/core/tui.c
===================================================================
--- trunk/nfsim/core/tui.c	2005-01-12 11:33:43 UTC (rev 3591)
+++ trunk/nfsim/core/tui.c	2005-01-12 11:37:11 UTC (rev 3592)
@@ -187,8 +187,8 @@
 	nfsim_log(LOG_UI, "%s", str);
 	talloc_free(str);
 
-	unload_all_modules();
-	check_allocations();
+	if (unload_all_modules())
+		check_allocations();
 
 	exit(EXIT_SCRIPTFAIL);
 }

Modified: trunk/nfsim/kernelenv/include/kernelenv.h
===================================================================
--- trunk/nfsim/kernelenv/include/kernelenv.h	2005-01-12 11:33:43 UTC (rev 3591)
+++ trunk/nfsim/kernelenv/include/kernelenv.h	2005-01-12 11:37:11 UTC (rev 3592)
@@ -1064,8 +1064,8 @@
 #define EXPORT_SYMBOL(x)
 #define EXPORT_SYMBOL_GPL(x)
 
-#define module_put(x) 
-#define try_module_get(x) 1
+void module_put(struct module *module);
+int try_module_get(struct module *module);
 #define try_then_request_module(x, mod...) ((x) ?: (request_module(mod), (x)))
 extern int request_module(const char * name, ...) __attribute__ ((format (printf, 1, 2)));
 
@@ -1085,13 +1085,15 @@
 
 #define MODULE_NAME_LEN (256 - sizeof(unsigned long) * 5)
 
+/* Large alignment ensures it's not padded in section. */
 struct module {
 	struct list_head list;
 	int (*init)(void);
 	void (*exit)(void);
 	long state;
+	unsigned int use;
 	char name[MODULE_NAME_LEN];
-};
+} __attribute__((aligned(64)));
 
 #ifdef KBUILD_MODNAME
 static struct module __this __attribute__((section("__modules"), unused)) = { .name = __stringify(KBUILD_MODNAME) };

Modified: trunk/nfsim/tools/module.c
===================================================================
--- trunk/nfsim/tools/module.c	2005-01-12 11:33:43 UTC (rev 3591)
+++ trunk/nfsim/tools/module.c	2005-01-12 11:37:11 UTC (rev 3592)
@@ -38,6 +38,37 @@
 	return NULL;
 }
 
+void module_put(struct module *module)
+{
+	if (!module)
+		return;
+
+	/* There is currently more than one struct per module. */
+	module = find_module(module->name);
+	if (!module)
+		barf("Unknown module put on %s\n", module->name);
+	if (module->use == 0)
+		barf("Module put too far on %s\n", module->name);
+	module->use--;
+}
+
+int try_module_get(struct module *module)
+{
+	if (should_i_fail_once(__func__))
+		return 0;
+
+	if (!module)
+		return 1;
+
+	/* There is currently more than one struct per module. */
+	module = find_module(module->name);
+	if (!module)
+		barf("Unknown module get on %s\n", module->name);
+	module->use++;
+	return 1;
+}
+
+
 static void populate_inits(void)
 {
 	extern struct __module_init __start_module_init[],__stop_module_init[];
@@ -215,18 +246,24 @@
 */
 }
 
-void unload_all_modules(void)
+bool unload_all_modules(void)
 {
 	struct module *mod;
 
 	list_for_each_entry_reverse(mod, &modules, list) {
 		if (!mod->state)
 			continue;
+		if (mod->use) {
+			nfsim_log(LOG_UI, "Module use count on %s still %u\n",
+				  mod->name, mod->use);
+			return false;
+		}
 		/* Make sure "running" timers are actually run */
 		schedule();
 		mod->exit();
 		mod->state = 0;
 	}
+	return true;
 }
 
 static bool rmmod(int argc, char *argv[])
@@ -238,10 +275,8 @@
 		return false;
 	}
 
-	if (streq(argv[1], "-a")) {
-		unload_all_modules();
-		return true;
-	}
+	if (streq(argv[1], "-a"))
+		return unload_all_modules();
 
 	mod = find_module(argv[1]);
 	if (!mod) {




More information about the netfilter-cvslog mailing list