xref: /openbmc/linux/fs/lockd/svc.c (revision 8db14cad)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * linux/fs/lockd/svc.c
4  *
5  * This is the central lockd service.
6  *
7  * FIXME: Separate the lockd NFS server functionality from the lockd NFS
8  * 	  client functionality. Oh why didn't Sun create two separate
9  *	  services in the first place?
10  *
11  * Authors:	Olaf Kirch (okir@monad.swb.de)
12  *
13  * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
14  */
15 
16 #include <linux/module.h>
17 #include <linux/init.h>
18 #include <linux/sysctl.h>
19 #include <linux/moduleparam.h>
20 
21 #include <linux/sched/signal.h>
22 #include <linux/errno.h>
23 #include <linux/in.h>
24 #include <linux/uio.h>
25 #include <linux/smp.h>
26 #include <linux/mutex.h>
27 #include <linux/kthread.h>
28 #include <linux/freezer.h>
29 #include <linux/inetdevice.h>
30 
31 #include <linux/sunrpc/types.h>
32 #include <linux/sunrpc/stats.h>
33 #include <linux/sunrpc/clnt.h>
34 #include <linux/sunrpc/svc.h>
35 #include <linux/sunrpc/svcsock.h>
36 #include <linux/sunrpc/svc_xprt.h>
37 #include <net/ip.h>
38 #include <net/addrconf.h>
39 #include <net/ipv6.h>
40 #include <linux/lockd/lockd.h>
41 #include <linux/nfs.h>
42 
43 #include "netns.h"
44 #include "procfs.h"
45 
46 #define NLMDBG_FACILITY		NLMDBG_SVC
47 #define LOCKD_BUFSIZE		(1024 + NLMSVC_XDRSIZE)
48 
49 static struct svc_program	nlmsvc_program;
50 
51 const struct nlmsvc_binding	*nlmsvc_ops;
52 EXPORT_SYMBOL_GPL(nlmsvc_ops);
53 
54 static DEFINE_MUTEX(nlmsvc_mutex);
55 static unsigned int		nlmsvc_users;
56 static struct svc_serv		*nlmsvc_serv;
57 unsigned long			nlmsvc_timeout;
58 
59 unsigned int lockd_net_id;
60 
61 /*
62  * These can be set at insmod time (useful for NFS as root filesystem),
63  * and also changed through the sysctl interface.  -- Jamie Lokier, Aug 2003
64  */
65 static unsigned long		nlm_grace_period;
66 static unsigned long		nlm_timeout = LOCKD_DFLT_TIMEO;
67 static int			nlm_udpport, nlm_tcpport;
68 
69 /* RLIM_NOFILE defaults to 1024. That seems like a reasonable default here. */
70 static unsigned int		nlm_max_connections = 1024;
71 
72 /*
73  * Constants needed for the sysctl interface.
74  */
75 static const unsigned long	nlm_grace_period_min = 0;
76 static const unsigned long	nlm_grace_period_max = 240;
77 static const unsigned long	nlm_timeout_min = 3;
78 static const unsigned long	nlm_timeout_max = 20;
79 
80 #ifdef CONFIG_SYSCTL
81 static const int		nlm_port_min = 0, nlm_port_max = 65535;
82 static struct ctl_table_header * nlm_sysctl_table;
83 #endif
84 
85 static unsigned long get_lockd_grace_period(void)
86 {
87 	/* Note: nlm_timeout should always be nonzero */
88 	if (nlm_grace_period)
89 		return roundup(nlm_grace_period, nlm_timeout) * HZ;
90 	else
91 		return nlm_timeout * 5 * HZ;
92 }
93 
94 static void grace_ender(struct work_struct *grace)
95 {
96 	struct delayed_work *dwork = to_delayed_work(grace);
97 	struct lockd_net *ln = container_of(dwork, struct lockd_net,
98 					    grace_period_end);
99 
100 	locks_end_grace(&ln->lockd_manager);
101 }
102 
103 static void set_grace_period(struct net *net)
104 {
105 	unsigned long grace_period = get_lockd_grace_period();
106 	struct lockd_net *ln = net_generic(net, lockd_net_id);
107 
108 	locks_start_grace(net, &ln->lockd_manager);
109 	cancel_delayed_work_sync(&ln->grace_period_end);
110 	schedule_delayed_work(&ln->grace_period_end, grace_period);
111 }
112 
113 /*
114  * This is the lockd kernel thread
115  */
116 static int
117 lockd(void *vrqstp)
118 {
119 	int		err = 0;
120 	struct svc_rqst *rqstp = vrqstp;
121 	struct net *net = &init_net;
122 	struct lockd_net *ln = net_generic(net, lockd_net_id);
123 
124 	/* try_to_freeze() is called from svc_recv() */
125 	set_freezable();
126 
127 	dprintk("NFS locking service started (ver " LOCKD_VERSION ").\n");
128 
129 	/*
130 	 * The main request loop. We don't terminate until the last
131 	 * NFS mount or NFS daemon has gone away.
132 	 */
133 	while (!kthread_should_stop()) {
134 		long timeout = MAX_SCHEDULE_TIMEOUT;
135 		RPC_IFDEBUG(char buf[RPC_MAX_ADDRBUFLEN]);
136 
137 		/* update sv_maxconn if it has changed */
138 		rqstp->rq_server->sv_maxconn = nlm_max_connections;
139 
140 		timeout = nlmsvc_retry_blocked();
141 
142 		/*
143 		 * Find a socket with data available and call its
144 		 * recvfrom routine.
145 		 */
146 		err = svc_recv(rqstp, timeout);
147 		if (err == -EAGAIN || err == -EINTR)
148 			continue;
149 		dprintk("lockd: request from %s\n",
150 				svc_print_addr(rqstp, buf, sizeof(buf)));
151 
152 		svc_process(rqstp);
153 	}
154 	if (nlmsvc_ops)
155 		nlmsvc_invalidate_all();
156 	nlm_shutdown_hosts();
157 	cancel_delayed_work_sync(&ln->grace_period_end);
158 	locks_end_grace(&ln->lockd_manager);
159 
160 	dprintk("lockd_down: service stopped\n");
161 
162 	svc_exit_thread(rqstp);
163 	return 0;
164 }
165 
166 static int create_lockd_listener(struct svc_serv *serv, const char *name,
167 				 struct net *net, const int family,
168 				 const unsigned short port,
169 				 const struct cred *cred)
170 {
171 	struct svc_xprt *xprt;
172 
173 	xprt = svc_find_xprt(serv, name, net, family, 0);
174 	if (xprt == NULL)
175 		return svc_xprt_create(serv, name, net, family, port,
176 				       SVC_SOCK_DEFAULTS, cred);
177 	svc_xprt_put(xprt);
178 	return 0;
179 }
180 
181 static int create_lockd_family(struct svc_serv *serv, struct net *net,
182 			       const int family, const struct cred *cred)
183 {
184 	int err;
185 
186 	err = create_lockd_listener(serv, "udp", net, family, nlm_udpport,
187 			cred);
188 	if (err < 0)
189 		return err;
190 
191 	return create_lockd_listener(serv, "tcp", net, family, nlm_tcpport,
192 			cred);
193 }
194 
195 /*
196  * Ensure there are active UDP and TCP listeners for lockd.
197  *
198  * Even if we have only TCP NFS mounts and/or TCP NFSDs, some
199  * local services (such as rpc.statd) still require UDP, and
200  * some NFS servers do not yet support NLM over TCP.
201  *
202  * Returns zero if all listeners are available; otherwise a
203  * negative errno value is returned.
204  */
205 static int make_socks(struct svc_serv *serv, struct net *net,
206 		const struct cred *cred)
207 {
208 	static int warned;
209 	int err;
210 
211 	err = create_lockd_family(serv, net, PF_INET, cred);
212 	if (err < 0)
213 		goto out_err;
214 
215 	err = create_lockd_family(serv, net, PF_INET6, cred);
216 	if (err < 0 && err != -EAFNOSUPPORT)
217 		goto out_err;
218 
219 	warned = 0;
220 	return 0;
221 
222 out_err:
223 	if (warned++ == 0)
224 		printk(KERN_WARNING
225 			"lockd_up: makesock failed, error=%d\n", err);
226 	svc_xprt_destroy_all(serv, net);
227 	svc_rpcb_cleanup(serv, net);
228 	return err;
229 }
230 
231 static int lockd_up_net(struct svc_serv *serv, struct net *net,
232 		const struct cred *cred)
233 {
234 	struct lockd_net *ln = net_generic(net, lockd_net_id);
235 	int error;
236 
237 	if (ln->nlmsvc_users++)
238 		return 0;
239 
240 	error = svc_bind(serv, net);
241 	if (error)
242 		goto err_bind;
243 
244 	error = make_socks(serv, net, cred);
245 	if (error < 0)
246 		goto err_bind;
247 	set_grace_period(net);
248 	dprintk("%s: per-net data created; net=%x\n", __func__, net->ns.inum);
249 	return 0;
250 
251 err_bind:
252 	ln->nlmsvc_users--;
253 	return error;
254 }
255 
256 static void lockd_down_net(struct svc_serv *serv, struct net *net)
257 {
258 	struct lockd_net *ln = net_generic(net, lockd_net_id);
259 
260 	if (ln->nlmsvc_users) {
261 		if (--ln->nlmsvc_users == 0) {
262 			nlm_shutdown_hosts_net(net);
263 			cancel_delayed_work_sync(&ln->grace_period_end);
264 			locks_end_grace(&ln->lockd_manager);
265 			svc_xprt_destroy_all(serv, net);
266 			svc_rpcb_cleanup(serv, net);
267 		}
268 	} else {
269 		pr_err("%s: no users! net=%x\n",
270 			__func__, net->ns.inum);
271 		BUG();
272 	}
273 }
274 
275 static int lockd_inetaddr_event(struct notifier_block *this,
276 	unsigned long event, void *ptr)
277 {
278 	struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
279 	struct sockaddr_in sin;
280 
281 	if (event != NETDEV_DOWN)
282 		goto out;
283 
284 	if (nlmsvc_serv) {
285 		dprintk("lockd_inetaddr_event: removed %pI4\n",
286 			&ifa->ifa_local);
287 		sin.sin_family = AF_INET;
288 		sin.sin_addr.s_addr = ifa->ifa_local;
289 		svc_age_temp_xprts_now(nlmsvc_serv, (struct sockaddr *)&sin);
290 	}
291 
292 out:
293 	return NOTIFY_DONE;
294 }
295 
296 static struct notifier_block lockd_inetaddr_notifier = {
297 	.notifier_call = lockd_inetaddr_event,
298 };
299 
300 #if IS_ENABLED(CONFIG_IPV6)
301 static int lockd_inet6addr_event(struct notifier_block *this,
302 	unsigned long event, void *ptr)
303 {
304 	struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
305 	struct sockaddr_in6 sin6;
306 
307 	if (event != NETDEV_DOWN)
308 		goto out;
309 
310 	if (nlmsvc_serv) {
311 		dprintk("lockd_inet6addr_event: removed %pI6\n", &ifa->addr);
312 		sin6.sin6_family = AF_INET6;
313 		sin6.sin6_addr = ifa->addr;
314 		if (ipv6_addr_type(&sin6.sin6_addr) & IPV6_ADDR_LINKLOCAL)
315 			sin6.sin6_scope_id = ifa->idev->dev->ifindex;
316 		svc_age_temp_xprts_now(nlmsvc_serv, (struct sockaddr *)&sin6);
317 	}
318 
319 out:
320 	return NOTIFY_DONE;
321 }
322 
323 static struct notifier_block lockd_inet6addr_notifier = {
324 	.notifier_call = lockd_inet6addr_event,
325 };
326 #endif
327 
328 static int lockd_get(void)
329 {
330 	struct svc_serv *serv;
331 	int error;
332 
333 	if (nlmsvc_serv) {
334 		nlmsvc_users++;
335 		return 0;
336 	}
337 
338 	/*
339 	 * Sanity check: if there's no pid,
340 	 * we should be the first user ...
341 	 */
342 	if (nlmsvc_users)
343 		printk(KERN_WARNING
344 			"lockd_up: no pid, %d users??\n", nlmsvc_users);
345 
346 	if (!nlm_timeout)
347 		nlm_timeout = LOCKD_DFLT_TIMEO;
348 	nlmsvc_timeout = nlm_timeout * HZ;
349 
350 	serv = svc_create(&nlmsvc_program, LOCKD_BUFSIZE, lockd);
351 	if (!serv) {
352 		printk(KERN_WARNING "lockd_up: create service failed\n");
353 		return -ENOMEM;
354 	}
355 
356 	serv->sv_maxconn = nlm_max_connections;
357 	error = svc_set_num_threads(serv, NULL, 1);
358 	/* The thread now holds the only reference */
359 	svc_put(serv);
360 	if (error < 0)
361 		return error;
362 
363 	nlmsvc_serv = serv;
364 	register_inetaddr_notifier(&lockd_inetaddr_notifier);
365 #if IS_ENABLED(CONFIG_IPV6)
366 	register_inet6addr_notifier(&lockd_inet6addr_notifier);
367 #endif
368 	dprintk("lockd_up: service created\n");
369 	nlmsvc_users++;
370 	return 0;
371 }
372 
373 static void lockd_put(void)
374 {
375 	if (WARN(nlmsvc_users <= 0, "lockd_down: no users!\n"))
376 		return;
377 	if (--nlmsvc_users)
378 		return;
379 
380 	unregister_inetaddr_notifier(&lockd_inetaddr_notifier);
381 #if IS_ENABLED(CONFIG_IPV6)
382 	unregister_inet6addr_notifier(&lockd_inet6addr_notifier);
383 #endif
384 
385 	svc_set_num_threads(nlmsvc_serv, NULL, 0);
386 	nlmsvc_serv = NULL;
387 	dprintk("lockd_down: service destroyed\n");
388 }
389 
390 /*
391  * Bring up the lockd process if it's not already up.
392  */
393 int lockd_up(struct net *net, const struct cred *cred)
394 {
395 	int error;
396 
397 	mutex_lock(&nlmsvc_mutex);
398 
399 	error = lockd_get();
400 	if (error)
401 		goto err;
402 
403 	error = lockd_up_net(nlmsvc_serv, net, cred);
404 	if (error < 0) {
405 		lockd_put();
406 		goto err;
407 	}
408 
409 err:
410 	mutex_unlock(&nlmsvc_mutex);
411 	return error;
412 }
413 EXPORT_SYMBOL_GPL(lockd_up);
414 
415 /*
416  * Decrement the user count and bring down lockd if we're the last.
417  */
418 void
419 lockd_down(struct net *net)
420 {
421 	mutex_lock(&nlmsvc_mutex);
422 	lockd_down_net(nlmsvc_serv, net);
423 	lockd_put();
424 	mutex_unlock(&nlmsvc_mutex);
425 }
426 EXPORT_SYMBOL_GPL(lockd_down);
427 
428 #ifdef CONFIG_SYSCTL
429 
430 /*
431  * Sysctl parameters (same as module parameters, different interface).
432  */
433 
434 static struct ctl_table nlm_sysctls[] = {
435 	{
436 		.procname	= "nlm_grace_period",
437 		.data		= &nlm_grace_period,
438 		.maxlen		= sizeof(unsigned long),
439 		.mode		= 0644,
440 		.proc_handler	= proc_doulongvec_minmax,
441 		.extra1		= (unsigned long *) &nlm_grace_period_min,
442 		.extra2		= (unsigned long *) &nlm_grace_period_max,
443 	},
444 	{
445 		.procname	= "nlm_timeout",
446 		.data		= &nlm_timeout,
447 		.maxlen		= sizeof(unsigned long),
448 		.mode		= 0644,
449 		.proc_handler	= proc_doulongvec_minmax,
450 		.extra1		= (unsigned long *) &nlm_timeout_min,
451 		.extra2		= (unsigned long *) &nlm_timeout_max,
452 	},
453 	{
454 		.procname	= "nlm_udpport",
455 		.data		= &nlm_udpport,
456 		.maxlen		= sizeof(int),
457 		.mode		= 0644,
458 		.proc_handler	= proc_dointvec_minmax,
459 		.extra1		= (int *) &nlm_port_min,
460 		.extra2		= (int *) &nlm_port_max,
461 	},
462 	{
463 		.procname	= "nlm_tcpport",
464 		.data		= &nlm_tcpport,
465 		.maxlen		= sizeof(int),
466 		.mode		= 0644,
467 		.proc_handler	= proc_dointvec_minmax,
468 		.extra1		= (int *) &nlm_port_min,
469 		.extra2		= (int *) &nlm_port_max,
470 	},
471 	{
472 		.procname	= "nsm_use_hostnames",
473 		.data		= &nsm_use_hostnames,
474 		.maxlen		= sizeof(bool),
475 		.mode		= 0644,
476 		.proc_handler	= proc_dobool,
477 	},
478 	{
479 		.procname	= "nsm_local_state",
480 		.data		= &nsm_local_state,
481 		.maxlen		= sizeof(int),
482 		.mode		= 0644,
483 		.proc_handler	= proc_dointvec,
484 	},
485 	{ }
486 };
487 
488 #endif	/* CONFIG_SYSCTL */
489 
490 /*
491  * Module (and sysfs) parameters.
492  */
493 
494 #define param_set_min_max(name, type, which_strtol, min, max)		\
495 static int param_set_##name(const char *val, const struct kernel_param *kp) \
496 {									\
497 	char *endp;							\
498 	__typeof__(type) num = which_strtol(val, &endp, 0);		\
499 	if (endp == val || *endp || num < (min) || num > (max))		\
500 		return -EINVAL;						\
501 	*((type *) kp->arg) = num;					\
502 	return 0;							\
503 }
504 
505 static inline int is_callback(u32 proc)
506 {
507 	return proc == NLMPROC_GRANTED
508 		|| proc == NLMPROC_GRANTED_MSG
509 		|| proc == NLMPROC_TEST_RES
510 		|| proc == NLMPROC_LOCK_RES
511 		|| proc == NLMPROC_CANCEL_RES
512 		|| proc == NLMPROC_UNLOCK_RES
513 		|| proc == NLMPROC_NSM_NOTIFY;
514 }
515 
516 
517 static int lockd_authenticate(struct svc_rqst *rqstp)
518 {
519 	rqstp->rq_client = NULL;
520 	switch (rqstp->rq_authop->flavour) {
521 		case RPC_AUTH_NULL:
522 		case RPC_AUTH_UNIX:
523 			rqstp->rq_auth_stat = rpc_auth_ok;
524 			if (rqstp->rq_proc == 0)
525 				return SVC_OK;
526 			if (is_callback(rqstp->rq_proc)) {
527 				/* Leave it to individual procedures to
528 				 * call nlmsvc_lookup_host(rqstp)
529 				 */
530 				return SVC_OK;
531 			}
532 			return svc_set_client(rqstp);
533 	}
534 	rqstp->rq_auth_stat = rpc_autherr_badcred;
535 	return SVC_DENIED;
536 }
537 
538 
539 param_set_min_max(port, int, simple_strtol, 0, 65535)
540 param_set_min_max(grace_period, unsigned long, simple_strtoul,
541 		  nlm_grace_period_min, nlm_grace_period_max)
542 param_set_min_max(timeout, unsigned long, simple_strtoul,
543 		  nlm_timeout_min, nlm_timeout_max)
544 
545 MODULE_AUTHOR("Olaf Kirch <okir@monad.swb.de>");
546 MODULE_DESCRIPTION("NFS file locking service version " LOCKD_VERSION ".");
547 MODULE_LICENSE("GPL");
548 
549 module_param_call(nlm_grace_period, param_set_grace_period, param_get_ulong,
550 		  &nlm_grace_period, 0644);
551 module_param_call(nlm_timeout, param_set_timeout, param_get_ulong,
552 		  &nlm_timeout, 0644);
553 module_param_call(nlm_udpport, param_set_port, param_get_int,
554 		  &nlm_udpport, 0644);
555 module_param_call(nlm_tcpport, param_set_port, param_get_int,
556 		  &nlm_tcpport, 0644);
557 module_param(nsm_use_hostnames, bool, 0644);
558 module_param(nlm_max_connections, uint, 0644);
559 
560 static int lockd_init_net(struct net *net)
561 {
562 	struct lockd_net *ln = net_generic(net, lockd_net_id);
563 
564 	INIT_DELAYED_WORK(&ln->grace_period_end, grace_ender);
565 	INIT_LIST_HEAD(&ln->lockd_manager.list);
566 	ln->lockd_manager.block_opens = false;
567 	INIT_LIST_HEAD(&ln->nsm_handles);
568 	return 0;
569 }
570 
571 static void lockd_exit_net(struct net *net)
572 {
573 	struct lockd_net *ln = net_generic(net, lockd_net_id);
574 
575 	WARN_ONCE(!list_empty(&ln->lockd_manager.list),
576 		  "net %x %s: lockd_manager.list is not empty\n",
577 		  net->ns.inum, __func__);
578 	WARN_ONCE(!list_empty(&ln->nsm_handles),
579 		  "net %x %s: nsm_handles list is not empty\n",
580 		  net->ns.inum, __func__);
581 	WARN_ONCE(delayed_work_pending(&ln->grace_period_end),
582 		  "net %x %s: grace_period_end was not cancelled\n",
583 		  net->ns.inum, __func__);
584 }
585 
586 static struct pernet_operations lockd_net_ops = {
587 	.init = lockd_init_net,
588 	.exit = lockd_exit_net,
589 	.id = &lockd_net_id,
590 	.size = sizeof(struct lockd_net),
591 };
592 
593 
594 /*
595  * Initialising and terminating the module.
596  */
597 
598 static int __init init_nlm(void)
599 {
600 	int err;
601 
602 #ifdef CONFIG_SYSCTL
603 	err = -ENOMEM;
604 	nlm_sysctl_table = register_sysctl("fs/nfs", nlm_sysctls);
605 	if (nlm_sysctl_table == NULL)
606 		goto err_sysctl;
607 #endif
608 	err = register_pernet_subsys(&lockd_net_ops);
609 	if (err)
610 		goto err_pernet;
611 
612 	err = lockd_create_procfs();
613 	if (err)
614 		goto err_procfs;
615 
616 	return 0;
617 
618 err_procfs:
619 	unregister_pernet_subsys(&lockd_net_ops);
620 err_pernet:
621 #ifdef CONFIG_SYSCTL
622 	unregister_sysctl_table(nlm_sysctl_table);
623 err_sysctl:
624 #endif
625 	return err;
626 }
627 
628 static void __exit exit_nlm(void)
629 {
630 	/* FIXME: delete all NLM clients */
631 	nlm_shutdown_hosts();
632 	lockd_remove_procfs();
633 	unregister_pernet_subsys(&lockd_net_ops);
634 #ifdef CONFIG_SYSCTL
635 	unregister_sysctl_table(nlm_sysctl_table);
636 #endif
637 }
638 
639 module_init(init_nlm);
640 module_exit(exit_nlm);
641 
642 /**
643  * nlmsvc_dispatch - Process an NLM Request
644  * @rqstp: incoming request
645  *
646  * Return values:
647  *  %0: Processing complete; do not send a Reply
648  *  %1: Processing complete; send Reply in rqstp->rq_res
649  */
650 static int nlmsvc_dispatch(struct svc_rqst *rqstp)
651 {
652 	const struct svc_procedure *procp = rqstp->rq_procinfo;
653 	__be32 *statp = rqstp->rq_accept_statp;
654 
655 	if (!procp->pc_decode(rqstp, &rqstp->rq_arg_stream))
656 		goto out_decode_err;
657 
658 	*statp = procp->pc_func(rqstp);
659 	if (*statp == rpc_drop_reply)
660 		return 0;
661 	if (*statp != rpc_success)
662 		return 1;
663 
664 	if (!procp->pc_encode(rqstp, &rqstp->rq_res_stream))
665 		goto out_encode_err;
666 
667 	return 1;
668 
669 out_decode_err:
670 	*statp = rpc_garbage_args;
671 	return 1;
672 
673 out_encode_err:
674 	*statp = rpc_system_err;
675 	return 1;
676 }
677 
678 /*
679  * Define NLM program and procedures
680  */
681 static DEFINE_PER_CPU_ALIGNED(unsigned long, nlmsvc_version1_count[17]);
682 static const struct svc_version	nlmsvc_version1 = {
683 	.vs_vers	= 1,
684 	.vs_nproc	= 17,
685 	.vs_proc	= nlmsvc_procedures,
686 	.vs_count	= nlmsvc_version1_count,
687 	.vs_dispatch	= nlmsvc_dispatch,
688 	.vs_xdrsize	= NLMSVC_XDRSIZE,
689 };
690 
691 static DEFINE_PER_CPU_ALIGNED(unsigned long,
692 			      nlmsvc_version3_count[ARRAY_SIZE(nlmsvc_procedures)]);
693 static const struct svc_version	nlmsvc_version3 = {
694 	.vs_vers	= 3,
695 	.vs_nproc	= ARRAY_SIZE(nlmsvc_procedures),
696 	.vs_proc	= nlmsvc_procedures,
697 	.vs_count	= nlmsvc_version3_count,
698 	.vs_dispatch	= nlmsvc_dispatch,
699 	.vs_xdrsize	= NLMSVC_XDRSIZE,
700 };
701 
702 #ifdef CONFIG_LOCKD_V4
703 static DEFINE_PER_CPU_ALIGNED(unsigned long,
704 			      nlmsvc_version4_count[ARRAY_SIZE(nlmsvc_procedures4)]);
705 static const struct svc_version	nlmsvc_version4 = {
706 	.vs_vers	= 4,
707 	.vs_nproc	= ARRAY_SIZE(nlmsvc_procedures4),
708 	.vs_proc	= nlmsvc_procedures4,
709 	.vs_count	= nlmsvc_version4_count,
710 	.vs_dispatch	= nlmsvc_dispatch,
711 	.vs_xdrsize	= NLMSVC_XDRSIZE,
712 };
713 #endif
714 
715 static const struct svc_version *nlmsvc_version[] = {
716 	[1] = &nlmsvc_version1,
717 	[3] = &nlmsvc_version3,
718 #ifdef CONFIG_LOCKD_V4
719 	[4] = &nlmsvc_version4,
720 #endif
721 };
722 
723 static struct svc_stat		nlmsvc_stats;
724 
725 #define NLM_NRVERS	ARRAY_SIZE(nlmsvc_version)
726 static struct svc_program	nlmsvc_program = {
727 	.pg_prog		= NLM_PROGRAM,		/* program number */
728 	.pg_nvers		= NLM_NRVERS,		/* number of entries in nlmsvc_version */
729 	.pg_vers		= nlmsvc_version,	/* version table */
730 	.pg_name		= "lockd",		/* service name */
731 	.pg_class		= "nfsd",		/* share authentication with nfsd */
732 	.pg_stats		= &nlmsvc_stats,	/* stats table */
733 	.pg_authenticate	= &lockd_authenticate,	/* export authentication */
734 	.pg_init_request	= svc_generic_init_request,
735 	.pg_rpcbind_set		= svc_generic_rpcbind_set,
736 };
737