Skip to contentSkip to conversation

Add kernel statd

PATCH In review Olaf Kirch 1 participant 1 message Aug 5, 2006

Subsystems (3)
lore
Share & tools
lore

Olaf Kirch

author
#0 lore raw

PATCH 22/22 Add kernel statd

From: Olaf Kirch <[email protected]>
Subject: [lockd] Add kernel statd

This patch adds the kernel statd, and allows the switchable statd support to use this instead of the upcalls to user land statd.

 fs/buffer.c                    |    1 
 fs/lockd/Makefile              |    2 
 fs/lockd/statd.c               |  405 +++++++++++++++++++++++++++++++++++++++++
 fs/lockd/svc.c                 |   59 +++++
 include/linux/lockd/lockd.h    |    1 
 include/linux/lockd/sm_inter.h |    5 
 6 files changed, 469 insertions(+), 4 deletions(-)
fs/lockd/svc.c +56 -3
Index: build/fs/lockd/svc.c
===================================================================
@@ -40,6 +40,7 @@
 #define ALLOWED_SIGS		(sigmask(SIGKILL))
 
 static struct svc_program	nlmsvc_program;
+extern struct svc_program	nsmsvc_program;
 
 struct nlmsvc_binding *		nlmsvc_ops;
 EXPORT_SYMBOL(nlmsvc_ops);
@@ -62,6 +63,7 @@ static unsigned long		nlm_timeout = LOCK
 static int			nlm_udpport, nlm_tcpport;
 int				nlm_max_hosts = 256;
 int				nsm_use_hostnames = 0;
+static int			nsm_use_kstatd = 0;
 
 /*
  * Constants needed for the sysctl interface.
@@ -119,8 +121,17 @@ lockd(struct svc_rqst *rqstp)
 
 	daemonize("lockd");
 
-	/* Initialize the statd upcalls to rpc.statd */
-	nsm_statd_upcalls_init();
+	/* See if we should use the kernel statd. If not,
+	 * or if setting up the kernel statd fails, try
+	 * falling back to user land upcalls.
+	 */
+	if (nsm_use_kstatd && nsm_kernel_statd_init() < 0)
+		nsm_use_kstatd = 0;
+
+	if (nsm_use_kstatd == 0) {
+		/* Initialize the statd upcalls to rpc.statd */
+		nsm_statd_upcalls_init();
+	}
 
 	/* Process request with signals blocked, but allow SIGKILL.  */
 	allow_signal(SIGKILL);
@@ -218,6 +229,7 @@ int
 lockd_up(void)
 {
 	static int		warned;
+	struct svc_program *	prog;
 	struct svc_serv *	serv;
 	int			error = 0;
 
@@ -241,8 +253,12 @@ lockd_up(void)
 		printk(KERN_WARNING
 			"lockd_up: no pid, %d users??\n", nlmsvc_users);
 
+	/* Register NLM program and possibly NSM (if using kstatd) */
 	error = -ENOMEM;
-	serv = svc_create(&nlmsvc_program, LOCKD_BUFSIZE);
+	prog = &nlmsvc_program;
+	if (nsm_use_kstatd)
+		prog = &nsmsvc_program;
+	serv = svc_create(prog, LOCKD_BUFSIZE);
 	if (!serv) {
 		printk(KERN_WARNING "lockd_up: create service failed\n");
 		goto out;
@@ -397,6 +413,15 @@ static ctl_table nlm_sysctls[] = {
 		.mode		= 0644,
 		.proc_handler	= &proc_dointvec,
 	},
+	{
+		.ctl_name	= CTL_UNNUMBERED,
+		.procname	= "nsm_use_kstatd",
+		.data		= &nsm_use_kstatd,
+		.maxlen		= sizeof(int),
+		.mode		= 0444,
+		.proc_handler	= &proc_dointvec,
+	},
+
 
 	{ .ctl_name = 0 }
 };
@@ -466,6 +491,7 @@ module_param_call(nlm_udpport, param_set
 		  &nlm_udpport, 0644);
 module_param_call(nlm_tcpport, param_set_port, param_get_int,
 		  &nlm_tcpport, 0644);
+module_param(nsm_use_kstatd, int, 0444);
 
 /*
  * Initialising and terminating the module.
@@ -536,3 +562,30 @@ static struct svc_program	nlmsvc_program
 	.pg_stats		= &nlmsvc_stats,	/* stats table */
 	.pg_authenticate = &lockd_authenticate	/* export authentication */
 };
+
+/*
+ * Define NSM program and procedures
+ */
+static struct svc_version	nsmsvc_version1 = {
+		.vs_vers	= 1,
+		.vs_nproc	= 7,
+		.vs_proc	= nsmsvc_procedures,
+		.vs_xdrsize	= SMSVC_XDRSIZE,
+};
+static struct svc_version *	nsmsvc_version[] = {
+	[1] = &nsmsvc_version1,
+};
+
+static struct svc_stat		nsmsvc_stats;
+
+#define SM_NRVERS	(sizeof(nsmsvc_version)/sizeof(nsmsvc_version[0]))
+struct svc_program	nsmsvc_program = {
+	.pg_next		= &nlmsvc_program,
+	.pg_prog		= SM_PROGRAM,		/* program number */
+	.pg_nvers		= SM_NRVERS,		/* number of entries in nlmsvc_version */
+	.pg_vers		= nsmsvc_version,	/* version table */
+	.pg_name		= "statd",		/* service name */
+	.pg_class		= "nfsd",		/* share authentication with nfsd */
+	.pg_stats		= &nsmsvc_stats,	/* stats table */
+	.pg_authenticate	= &nsmsvc_authenticate	/* no authentication :-( */
+};
include/linux/lockd/sm_inter.h +5 -0
Index: build/include/linux/lockd/sm_inter.h
===================================================================
@@ -19,6 +19,7 @@
 #define SM_NOTIFY	6
 
 #define SM_MAXSTRLEN	1024
+#define SMSVC_XDRSIZE	(sizeof(struct nsm_args) + SM_MAXSTRLEN)
 
 /*
  * Arguments for all calls to statd
@@ -30,6 +31,8 @@ struct nsm_args {
 	u32		proc;
 
 	char *		mon_name;
+	int		mon_name_len;
+	u32		state;
 };
 
 /*
@@ -41,6 +44,8 @@ struct nsm_res {
 };
 
 extern void	nsm_statd_upcalls_init(void);
+extern int	nsm_kernel_statd_init(void);
+extern int	nsmsvc_authenticate(struct svc_rqst *);
 extern int	(*nsm_monitor)(struct nlm_host *);
 extern int	(*nsm_unmonitor)(struct nlm_host *);
 extern int	nsm_local_state;
fs/buffer.c +1 -0
Index: build/fs/buffer.c
===================================================================
@@ -183,6 +183,7 @@ int fsync_super(struct super_block *sb)
 	__fsync_super(sb);
 	return sync_blockdev(sb->s_bdev);
 }
+EXPORT_SYMBOL_GPL(fsync_super);
 
 /*
  * Write out and wait upon all dirty data associated with this
fs/lockd/Makefile +1 -1
Index: build/fs/lockd/Makefile
===================================================================
@@ -5,6 +5,6 @@
 obj-$(CONFIG_LOCKD) += lockd.o
 
 lockd-objs-y := clntlock.o clntproc.o host.o svc.o svclock.o svcshare.o \
-	        svcproc.o svcsubs.o mon.o xdr.o
+	        svcproc.o svcsubs.o mon.o xdr.o statd.o
 lockd-objs-$(CONFIG_LOCKD_V4) += xdr4.o svc4proc.o
 lockd-objs		      := $(lockd-objs-y)
fs/lockd/statd.c new file +405 -0

405 lines not on this page · raw message

include/linux/lockd/lockd.h +1 -0
Index: build/include/linux/lockd/lockd.h
===================================================================
@@ -141,6 +141,7 @@ extern struct svc_procedure	nlmsvc_proce
 #ifdef CONFIG_LOCKD_V4
 extern struct svc_procedure	nlmsvc_procedures4[];
 #endif
+extern struct svc_procedure	nsmsvc_procedures[];
 extern int			nlmsvc_grace_period;
 extern unsigned long		nlmsvc_timeout;
 extern int			nlm_max_hosts;

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs