patch-2.1.79 linux/net/sunrpc/stats.c

Next file: linux/net/sunrpc/sysctl.c
Previous file: linux/net/sunrpc/sched.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.1.78/linux/net/sunrpc/stats.c linux/net/sunrpc/stats.c
@@ -12,6 +12,8 @@
  * Copyright (C) 1995, 1996, 1997 Olaf Kirch <okir@monad.swb.de>
  */
 
+#include <linux/module.h>
+
 #include <linux/kernel.h>
 #include <linux/sched.h>
 #include <linux/proc_fs.h>
@@ -20,7 +22,7 @@
 
 #define RPCDBG_FACILITY	RPCDBG_MISC
 
-static struct proc_dir_entry	*proc_net_rpc = 0;
+static struct proc_dir_entry	*proc_net_rpc = NULL;
 
 /*
  * Get RPC client stats
@@ -161,15 +163,61 @@
 rpc_proc_init(void)
 {
 	dprintk("RPC: registering /proc/net/rpc\n");
-	if (!proc_net_rpc)
-		proc_net_rpc = create_proc_entry("net/rpc", S_IFDIR, 0);
+	if (!proc_net_rpc) {
+		struct proc_dir_entry *ent;
+		ent = create_proc_entry("net/rpc", S_IFDIR, 0);
+		if (ent) {
+#ifdef MODULE
+			ent->fill_inode = rpc_modcount;
+#endif
+			proc_net_rpc = ent;
+		}
+	}
 }
 
 void
 rpc_proc_exit(void)
 {
 	dprintk("RPC: unregistering /proc/net/rpc\n");
-	if (proc_net_rpc)
+	if (proc_net_rpc) {
+		proc_net_rpc = NULL;
 		remove_proc_entry("net/rpc", 0);
-	proc_net_rpc = 0;
+	}
+}
+
+#ifdef MODULE
+/*
+ * This is called as the proc_dir_entry fill_inode function
+ * when an inode is going into or out of service (fill == 1
+ * or 0 respectively).
+ *
+ * We use it here to keep the module from being unloaded
+ * while /proc inodes are in use.
+ */
+void rpc_modcount(struct inode *inode, int fill)
+{
+	if (fill)
+		MOD_INC_USE_COUNT;
+	else
+		MOD_DEC_USE_COUNT;
+}
+
+int
+init_module(void)
+{
+#ifdef RPC_DEBUG
+	rpc_register_sysctl();
+#endif
+	rpc_proc_init();
+	return 0;
+}
+
+void
+cleanup_module(void)
+{
+#ifdef RPC_DEBUG
+	rpc_unregister_sysctl();
+#endif
+	rpc_proc_exit();
 }
+#endif

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov