blob: 0475c5a5d061e989ab90e8090563f61e3bf89cfe [file] [log] [blame]
Thomas Gleixner09c434b2019-05-19 13:08:20 +01001// SPDX-License-Identifier: GPL-2.0-only
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/module.h>
17#include <linux/init.h>
18#include <linux/sysctl.h>
19#include <linux/moduleparam.h>
20
Ingo Molnar3f07c012017-02-08 18:51:30 +010021#include <linux/sched/signal.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/errno.h>
23#include <linux/in.h>
24#include <linux/uio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <linux/smp.h>
Ingo Molnar353ab6e2006-03-26 01:37:12 -080026#include <linux/mutex.h>
Jeff Laytond751a7c2008-02-07 16:34:55 -050027#include <linux/kthread.h>
Rafael J. Wysocki83144182007-07-17 04:03:35 -070028#include <linux/freezer.h>
Scott Mayhew0751ddf2015-12-11 16:46:00 -050029#include <linux/inetdevice.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
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>
Scott Mayhew0751ddf2015-12-11 16:46:00 -050036#include <linux/sunrpc/svc_xprt.h>
NeilBrown24e36662006-10-02 02:17:45 -070037#include <net/ip.h>
Scott Mayhew0751ddf2015-12-11 16:46:00 -050038#include <net/addrconf.h>
39#include <net/ipv6.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/lockd/lockd.h>
41#include <linux/nfs.h>
42
Stanislav Kinsburskya9c5d732012-01-31 15:07:57 +040043#include "netns.h"
Jeff Laytond68e3c42014-09-12 16:40:20 -040044#include "procfs.h"
Stanislav Kinsburskya9c5d732012-01-31 15:07:57 +040045
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#define NLMDBG_FACILITY NLMDBG_SVC
47#define LOCKD_BUFSIZE (1024 + NLMSVC_XDRSIZE)
48#define ALLOWED_SIGS (sigmask(SIGKILL))
49
50static struct svc_program nlmsvc_program;
51
Julia Lawall2a297452015-12-23 22:25:13 +010052const struct nlmsvc_binding *nlmsvc_ops;
Trond Myklebust2de59872008-12-23 15:21:33 -050053EXPORT_SYMBOL_GPL(nlmsvc_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
Ingo Molnar353ab6e2006-03-26 01:37:12 -080055static DEFINE_MUTEX(nlmsvc_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056static unsigned int nlmsvc_users;
NeilBrown2840fe82021-11-29 15:51:25 +110057static struct svc_serv *nlmsvc_serv;
Linus Torvalds1da177e2005-04-16 15:20:36 -070058unsigned long nlmsvc_timeout;
59
Alexey Dobriyanc7d03a02016-11-17 04:58:21 +030060unsigned int lockd_net_id;
Stanislav Kinsburskya9c5d732012-01-31 15:07:57 +040061
Linus Torvalds1da177e2005-04-16 15:20:36 -070062/*
63 * These can be set at insmod time (useful for NFS as root filesystem),
64 * and also changed through the sysctl interface. -- Jamie Lokier, Aug 2003
65 */
66static unsigned long nlm_grace_period;
67static unsigned long nlm_timeout = LOCKD_DFLT_TIMEO;
68static int nlm_udpport, nlm_tcpport;
69
Jeff Laytonc72a4762008-10-20 11:51:58 -040070/* RLIM_NOFILE defaults to 1024. That seems like a reasonable default here. */
71static unsigned int nlm_max_connections = 1024;
72
Linus Torvalds1da177e2005-04-16 15:20:36 -070073/*
74 * Constants needed for the sysctl interface.
75 */
76static const unsigned long nlm_grace_period_min = 0;
77static const unsigned long nlm_grace_period_max = 240;
78static const unsigned long nlm_timeout_min = 3;
79static const unsigned long nlm_timeout_max = 20;
80static const int nlm_port_min = 0, nlm_port_max = 65535;
81
Chuck Lever90d5b182008-03-14 14:18:30 -040082#ifdef CONFIG_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -070083static struct ctl_table_header * nlm_sysctl_table;
Chuck Lever90d5b182008-03-14 14:18:30 -040084#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
Marc Eshel9a8db972007-07-17 04:04:35 -070086static unsigned long get_lockd_grace_period(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070087{
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 /* Note: nlm_timeout should always be nonzero */
89 if (nlm_grace_period)
Marc Eshel9a8db972007-07-17 04:04:35 -070090 return roundup(nlm_grace_period, nlm_timeout) * HZ;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 else
Marc Eshel9a8db972007-07-17 04:04:35 -070092 return nlm_timeout * 5 * HZ;
93}
94
Stanislav Kinsbursky08d44a32012-07-25 16:56:50 +040095static void grace_ender(struct work_struct *grace)
Linus Torvalds1da177e2005-04-16 15:20:36 -070096{
Geliang Tangea444632016-01-01 22:06:29 +080097 struct delayed_work *dwork = to_delayed_work(grace);
Stanislav Kinsbursky08d44a32012-07-25 16:56:50 +040098 struct lockd_net *ln = container_of(dwork, struct lockd_net,
99 grace_period_end);
100
101 locks_end_grace(&ln->lockd_manager);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102}
103
Stanislav Kinsbursky5ccb0062012-07-25 16:57:22 +0400104static void set_grace_period(struct net *net)
J. Bruce Fieldsc8ab5f22008-03-18 19:00:19 -0400105{
J. Bruce Fieldsaf558e32007-09-06 12:34:25 -0400106 unsigned long grace_period = get_lockd_grace_period();
Stanislav Kinsbursky5ccb0062012-07-25 16:57:22 +0400107 struct lockd_net *ln = net_generic(net, lockd_net_id);
J. Bruce Fieldsc8ab5f22008-03-18 19:00:19 -0400108
Stanislav Kinsbursky5ccb0062012-07-25 16:57:22 +0400109 locks_start_grace(net, &ln->lockd_manager);
Stanislav Kinsbursky66547b02012-07-25 16:56:43 +0400110 cancel_delayed_work_sync(&ln->grace_period_end);
111 schedule_delayed_work(&ln->grace_period_end, grace_period);
J. Bruce Fieldsc8ab5f22008-03-18 19:00:19 -0400112}
113
J. Bruce Fields89996df2009-05-06 16:32:54 -0400114static void restart_grace(void)
115{
116 if (nlmsvc_ops) {
Stanislav Kinsbursky5ccb0062012-07-25 16:57:22 +0400117 struct net *net = &init_net;
118 struct lockd_net *ln = net_generic(net, lockd_net_id);
Stanislav Kinsbursky66547b02012-07-25 16:56:43 +0400119
120 cancel_delayed_work_sync(&ln->grace_period_end);
Stanislav Kinsbursky08d44a32012-07-25 16:56:50 +0400121 locks_end_grace(&ln->lockd_manager);
J. Bruce Fields89996df2009-05-06 16:32:54 -0400122 nlmsvc_invalidate_all();
Stanislav Kinsbursky5ccb0062012-07-25 16:57:22 +0400123 set_grace_period(net);
J. Bruce Fields89996df2009-05-06 16:32:54 -0400124 }
125}
126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127/*
128 * This is the lockd kernel thread
129 */
Jeff Laytond751a7c2008-02-07 16:34:55 -0500130static int
131lockd(void *vrqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132{
J. Bruce Fields5b444cc2012-08-17 21:47:53 -0400133 int err = 0;
Jeff Laytond751a7c2008-02-07 16:34:55 -0500134 struct svc_rqst *rqstp = vrqstp;
J. Bruce Fieldsefda7602017-03-28 21:25:08 -0400135 struct net *net = &init_net;
136 struct lockd_net *ln = net_generic(net, lockd_net_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
Jeff Laytond751a7c2008-02-07 16:34:55 -0500138 /* try_to_freeze() is called from svc_recv() */
Rafael J. Wysocki83144182007-07-17 04:03:35 -0700139 set_freezable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
Jeff Laytond751a7c2008-02-07 16:34:55 -0500141 /* Allow SIGKILL to tell lockd to drop all of its locks */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 allow_signal(SIGKILL);
143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 dprintk("NFS locking service started (ver " LOCKD_VERSION ").\n");
145
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 /*
147 * The main request loop. We don't terminate until the last
Jeff Laytond751a7c2008-02-07 16:34:55 -0500148 * NFS mount or NFS daemon has gone away.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 */
Jeff Laytond751a7c2008-02-07 16:34:55 -0500150 while (!kthread_should_stop()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 long timeout = MAX_SCHEDULE_TIMEOUT;
Pavel Emelyanov5216a8e2008-02-21 10:57:45 +0300152 RPC_IFDEBUG(char buf[RPC_MAX_ADDRBUFLEN]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
Jeff Laytonc72a4762008-10-20 11:51:58 -0400154 /* update sv_maxconn if it has changed */
155 rqstp->rq_server->sv_maxconn = nlm_max_connections;
156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 if (signalled()) {
158 flush_signals(current);
J. Bruce Fields89996df2009-05-06 16:32:54 -0400159 restart_grace();
Jeff Laytond751a7c2008-02-07 16:34:55 -0500160 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 }
162
J. Bruce Fields8fafa902008-01-24 11:11:34 -0500163 timeout = nlmsvc_retry_blocked();
164
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 /*
166 * Find a socket with data available and call its
167 * recvfrom routine.
168 */
NeilBrown6fb2b472006-10-02 02:17:50 -0700169 err = svc_recv(rqstp, timeout);
J. Bruce Fields5b444cc2012-08-17 21:47:53 -0400170 if (err == -EAGAIN || err == -EINTR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 continue;
Chuck Leverad06e4b2007-02-12 00:53:32 -0800172 dprintk("lockd: request from %s\n",
173 svc_print_addr(rqstp, buf, sizeof(buf)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
NeilBrown6fb2b472006-10-02 02:17:50 -0700175 svc_process(rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 }
Trond Myklebust2bd61572006-01-03 09:55:19 +0100177 flush_signals(current);
Jeff Laytond751a7c2008-02-07 16:34:55 -0500178 if (nlmsvc_ops)
179 nlmsvc_invalidate_all();
180 nlm_shutdown_hosts();
J. Bruce Fieldsefda7602017-03-28 21:25:08 -0400181 cancel_delayed_work_sync(&ln->grace_period_end);
182 locks_end_grace(&ln->lockd_manager);
NeilBrown6a4e2522021-11-29 15:51:25 +1100183
184 dprintk("lockd_down: service stopped\n");
185
186 svc_exit_thread(rqstp);
187
Linus Torvalds35ce8ae2022-01-17 05:49:30 +0200188 module_put_and_kthread_exit(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189}
190
Chuck Levereb16e902009-03-18 20:47:59 -0400191static int create_lockd_listener(struct svc_serv *serv, const char *name,
Stanislav Kinsburskyc228fa22012-01-31 15:07:48 +0400192 struct net *net, const int family,
Trond Myklebust40373b12019-04-09 12:13:39 -0400193 const unsigned short port,
194 const struct cred *cred)
Chuck Leverd3fe5ea2008-12-31 16:06:04 -0500195{
196 struct svc_xprt *xprt;
197
Stanislav Kinsburskyc228fa22012-01-31 15:07:48 +0400198 xprt = svc_find_xprt(serv, name, net, family, 0);
Chuck Leverd3fe5ea2008-12-31 16:06:04 -0500199 if (xprt == NULL)
Stanislav Kinsburskyc228fa22012-01-31 15:07:48 +0400200 return svc_create_xprt(serv, name, net, family, port,
Trond Myklebust4df493a2019-04-09 12:13:37 -0400201 SVC_SOCK_DEFAULTS, cred);
Chuck Leverd3fe5ea2008-12-31 16:06:04 -0500202 svc_xprt_put(xprt);
203 return 0;
204}
205
Stanislav Kinsburskyc228fa22012-01-31 15:07:48 +0400206static int create_lockd_family(struct svc_serv *serv, struct net *net,
Trond Myklebust40373b12019-04-09 12:13:39 -0400207 const int family, const struct cred *cred)
Chuck Levereb16e902009-03-18 20:47:59 -0400208{
209 int err;
210
Trond Myklebust40373b12019-04-09 12:13:39 -0400211 err = create_lockd_listener(serv, "udp", net, family, nlm_udpport,
212 cred);
Chuck Levereb16e902009-03-18 20:47:59 -0400213 if (err < 0)
214 return err;
215
Trond Myklebust40373b12019-04-09 12:13:39 -0400216 return create_lockd_listener(serv, "tcp", net, family, nlm_tcpport,
217 cred);
Chuck Levereb16e902009-03-18 20:47:59 -0400218}
219
Chuck Lever482fb942007-02-12 00:53:29 -0800220/*
Chuck Lever8c3916f2008-10-03 17:15:23 -0400221 * Ensure there are active UDP and TCP listeners for lockd.
222 *
223 * Even if we have only TCP NFS mounts and/or TCP NFSDs, some
224 * local services (such as rpc.statd) still require UDP, and
225 * some NFS servers do not yet support NLM over TCP.
226 *
227 * Returns zero if all listeners are available; otherwise a
228 * negative errno value is returned.
Chuck Lever482fb942007-02-12 00:53:29 -0800229 */
Trond Myklebust40373b12019-04-09 12:13:39 -0400230static int make_socks(struct svc_serv *serv, struct net *net,
231 const struct cred *cred)
NeilBrown24e36662006-10-02 02:17:45 -0700232{
Chuck Lever482fb942007-02-12 00:53:29 -0800233 static int warned;
Chuck Lever0dba7c22008-12-31 16:06:11 -0500234 int err;
Chuck Lever482fb942007-02-12 00:53:29 -0800235
Trond Myklebust40373b12019-04-09 12:13:39 -0400236 err = create_lockd_family(serv, net, PF_INET, cred);
Chuck Lever0dba7c22008-12-31 16:06:11 -0500237 if (err < 0)
238 goto out_err;
239
Trond Myklebust40373b12019-04-09 12:13:39 -0400240 err = create_lockd_family(serv, net, PF_INET6, cred);
Chuck Levereb16e902009-03-18 20:47:59 -0400241 if (err < 0 && err != -EAFNOSUPPORT)
Chuck Lever0dba7c22008-12-31 16:06:11 -0500242 goto out_err;
243
244 warned = 0;
245 return 0;
246
247out_err:
248 if (warned++ == 0)
NeilBrown7dcf91e2006-10-02 02:17:52 -0700249 printk(KERN_WARNING
Chuck Lever0dba7c22008-12-31 16:06:11 -0500250 "lockd_up: makesock failed, error=%d\n", err);
Jeff Layton679b0332014-03-25 11:55:26 -0700251 svc_shutdown_net(serv, net);
NeilBrown24e36662006-10-02 02:17:45 -0700252 return err;
253}
254
Trond Myklebust40373b12019-04-09 12:13:39 -0400255static int lockd_up_net(struct svc_serv *serv, struct net *net,
256 const struct cred *cred)
Stanislav Kinsburskybb2224d2012-01-31 15:08:05 +0400257{
258 struct lockd_net *ln = net_generic(net, lockd_net_id);
Stanislav Kinsburskybb2224d2012-01-31 15:08:05 +0400259 int error;
260
Stanislav Kinsbursky786185b2012-05-04 12:49:41 +0400261 if (ln->nlmsvc_users++)
Stanislav Kinsburskybb2224d2012-01-31 15:08:05 +0400262 return 0;
263
Stanislav Kinsburskydbf9b5d72012-04-25 18:22:47 +0400264 error = svc_bind(serv, net);
Stanislav Kinsburskybb2224d2012-01-31 15:08:05 +0400265 if (error)
Stanislav Kinsburskydbf9b5d72012-04-25 18:22:47 +0400266 goto err_bind;
Stanislav Kinsburskybb2224d2012-01-31 15:08:05 +0400267
Trond Myklebust40373b12019-04-09 12:13:39 -0400268 error = make_socks(serv, net, cred);
Stanislav Kinsburskybb2224d2012-01-31 15:08:05 +0400269 if (error < 0)
J. Bruce Fields7c177052014-08-29 16:25:50 -0400270 goto err_bind;
Stanislav Kinsbursky5630f7f2012-07-25 16:57:29 +0400271 set_grace_period(net);
Vasily Averine919b072017-11-08 08:55:55 +0300272 dprintk("%s: per-net data created; net=%x\n", __func__, net->ns.inum);
Stanislav Kinsburskybb2224d2012-01-31 15:08:05 +0400273 return 0;
274
Stanislav Kinsburskydbf9b5d72012-04-25 18:22:47 +0400275err_bind:
Stanislav Kinsbursky786185b2012-05-04 12:49:41 +0400276 ln->nlmsvc_users--;
Stanislav Kinsburskybb2224d2012-01-31 15:08:05 +0400277 return error;
278}
279
Stanislav Kinsbursky4db77692012-04-25 18:22:40 +0400280static void lockd_down_net(struct svc_serv *serv, struct net *net)
Stanislav Kinsburskybb2224d2012-01-31 15:08:05 +0400281{
282 struct lockd_net *ln = net_generic(net, lockd_net_id);
Stanislav Kinsburskybb2224d2012-01-31 15:08:05 +0400283
284 if (ln->nlmsvc_users) {
Stanislav Kinsbursky3b647392012-01-31 15:08:29 +0400285 if (--ln->nlmsvc_users == 0) {
286 nlm_shutdown_hosts_net(net);
Vasily Averin3a2b19d2017-11-02 13:03:42 +0300287 cancel_delayed_work_sync(&ln->grace_period_end);
288 locks_end_grace(&ln->lockd_manager);
Stanislav Kinsburskybb2224d2012-01-31 15:08:05 +0400289 svc_shutdown_net(serv, net);
Vasily Averine919b072017-11-08 08:55:55 +0300290 dprintk("%s: per-net data destroyed; net=%x\n",
291 __func__, net->ns.inum);
Stanislav Kinsbursky3b647392012-01-31 15:08:29 +0400292 }
Stanislav Kinsburskybb2224d2012-01-31 15:08:05 +0400293 } else {
NeilBrown6b044fb2021-11-29 15:51:25 +1100294 pr_err("%s: no users! net=%x\n",
295 __func__, net->ns.inum);
Stanislav Kinsburskybb2224d2012-01-31 15:08:05 +0400296 BUG();
297 }
298}
299
Scott Mayhew0751ddf2015-12-11 16:46:00 -0500300static int lockd_inetaddr_event(struct notifier_block *this,
301 unsigned long event, void *ptr)
302{
303 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
304 struct sockaddr_in sin;
305
NeilBrown5a8a7ff2021-11-29 15:51:25 +1100306 if (event != NETDEV_DOWN)
Scott Mayhew0751ddf2015-12-11 16:46:00 -0500307 goto out;
308
NeilBrown2840fe82021-11-29 15:51:25 +1100309 if (nlmsvc_serv) {
Scott Mayhew0751ddf2015-12-11 16:46:00 -0500310 dprintk("lockd_inetaddr_event: removed %pI4\n",
311 &ifa->ifa_local);
312 sin.sin_family = AF_INET;
313 sin.sin_addr.s_addr = ifa->ifa_local;
NeilBrown2840fe82021-11-29 15:51:25 +1100314 svc_age_temp_xprts_now(nlmsvc_serv, (struct sockaddr *)&sin);
Scott Mayhew0751ddf2015-12-11 16:46:00 -0500315 }
316
317out:
318 return NOTIFY_DONE;
319}
320
321static struct notifier_block lockd_inetaddr_notifier = {
322 .notifier_call = lockd_inetaddr_event,
323};
324
325#if IS_ENABLED(CONFIG_IPV6)
326static int lockd_inet6addr_event(struct notifier_block *this,
327 unsigned long event, void *ptr)
328{
329 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
330 struct sockaddr_in6 sin6;
331
NeilBrown5a8a7ff2021-11-29 15:51:25 +1100332 if (event != NETDEV_DOWN)
Scott Mayhew0751ddf2015-12-11 16:46:00 -0500333 goto out;
334
NeilBrown2840fe82021-11-29 15:51:25 +1100335 if (nlmsvc_serv) {
Scott Mayhew0751ddf2015-12-11 16:46:00 -0500336 dprintk("lockd_inet6addr_event: removed %pI6\n", &ifa->addr);
337 sin6.sin6_family = AF_INET6;
338 sin6.sin6_addr = ifa->addr;
Scott Mayhewc01410f2017-01-05 16:34:50 -0500339 if (ipv6_addr_type(&sin6.sin6_addr) & IPV6_ADDR_LINKLOCAL)
340 sin6.sin6_scope_id = ifa->idev->dev->ifindex;
NeilBrown2840fe82021-11-29 15:51:25 +1100341 svc_age_temp_xprts_now(nlmsvc_serv, (struct sockaddr *)&sin6);
Scott Mayhew0751ddf2015-12-11 16:46:00 -0500342 }
343
344out:
345 return NOTIFY_DONE;
346}
347
348static struct notifier_block lockd_inet6addr_notifier = {
349 .notifier_call = lockd_inet6addr_event,
350};
351#endif
352
Chuck Leverafea5652017-08-01 12:00:06 -0400353static const struct svc_serv_ops lockd_sv_ops = {
Jeff Laytonb9e13cd2015-06-08 12:06:51 -0700354 .svo_shutdown = svc_rpcb_cleanup,
NeilBrown6b044fb2021-11-29 15:51:25 +1100355 .svo_function = lockd,
Jeff Laytonb9e13cd2015-06-08 12:06:51 -0700356 .svo_enqueue_xprt = svc_xprt_do_enqueue,
NeilBrown6b044fb2021-11-29 15:51:25 +1100357 .svo_module = THIS_MODULE,
Jeff Laytonea126e72015-06-08 12:03:32 -0700358};
359
NeilBrownecd3ad62021-11-29 15:51:25 +1100360static int lockd_get(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361{
Jeff Laytond751a7c2008-02-07 16:34:55 -0500362 struct svc_serv *serv;
NeilBrownb73a2972021-11-29 15:51:25 +1100363 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364
NeilBrown2840fe82021-11-29 15:51:25 +1100365 if (nlmsvc_serv) {
366 svc_get(nlmsvc_serv);
NeilBrownecd3ad62021-11-29 15:51:25 +1100367 nlmsvc_users++;
NeilBrown2840fe82021-11-29 15:51:25 +1100368 return 0;
369 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
371 /*
372 * Sanity check: if there's no pid,
373 * we should be the first user ...
374 */
NeilBrown4a3ae422006-10-02 02:17:53 -0700375 if (nlmsvc_users)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 printk(KERN_WARNING
377 "lockd_up: no pid, %d users??\n", nlmsvc_users);
378
Trond Myklebust06bed7d2015-01-02 15:05:25 -0500379 if (!nlm_timeout)
380 nlm_timeout = LOCKD_DFLT_TIMEO;
381 nlmsvc_timeout = nlm_timeout * HZ;
382
Jeff Laytonea126e72015-06-08 12:03:32 -0700383 serv = svc_create(&nlmsvc_program, LOCKD_BUFSIZE, &lockd_sv_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 if (!serv) {
385 printk(KERN_WARNING "lockd_up: create service failed\n");
NeilBrown2840fe82021-11-29 15:51:25 +1100386 return -ENOMEM;
Stanislav Kinsbursky24452232012-04-25 18:22:54 +0400387 }
NeilBrownb73a2972021-11-29 15:51:25 +1100388
NeilBrown6b044fb2021-11-29 15:51:25 +1100389 serv->sv_maxconn = nlm_max_connections;
390 error = svc_set_num_threads(serv, NULL, 1);
NeilBrownb73a2972021-11-29 15:51:25 +1100391 /* The thread now holds the only reference */
392 svc_put(serv);
393 if (error < 0)
394 return error;
395
NeilBrown2840fe82021-11-29 15:51:25 +1100396 nlmsvc_serv = serv;
Scott Mayhew0751ddf2015-12-11 16:46:00 -0500397 register_inetaddr_notifier(&lockd_inetaddr_notifier);
398#if IS_ENABLED(CONFIG_IPV6)
399 register_inet6addr_notifier(&lockd_inet6addr_notifier);
400#endif
Stanislav Kinsbursky8dbf28e2012-04-25 18:23:16 +0400401 dprintk("lockd_up: service created\n");
NeilBrownecd3ad62021-11-29 15:51:25 +1100402 nlmsvc_users++;
NeilBrown2840fe82021-11-29 15:51:25 +1100403 return 0;
Stanislav Kinsbursky24452232012-04-25 18:22:54 +0400404}
405
NeilBrown865b6742021-11-29 15:51:25 +1100406static void lockd_put(void)
407{
408 if (WARN(nlmsvc_users <= 0, "lockd_down: no users!\n"))
409 return;
410 if (--nlmsvc_users)
411 return;
412
413 unregister_inetaddr_notifier(&lockd_inetaddr_notifier);
414#if IS_ENABLED(CONFIG_IPV6)
415 unregister_inet6addr_notifier(&lockd_inet6addr_notifier);
416#endif
417
NeilBrown6b044fb2021-11-29 15:51:25 +1100418 svc_set_num_threads(nlmsvc_serv, NULL, 0);
NeilBrown865b6742021-11-29 15:51:25 +1100419 nlmsvc_serv = NULL;
420 dprintk("lockd_down: service destroyed\n");
421}
422
Stanislav Kinsbursky24452232012-04-25 18:22:54 +0400423/*
424 * Bring up the lockd process if it's not already up.
425 */
Trond Myklebust40373b12019-04-09 12:13:39 -0400426int lockd_up(struct net *net, const struct cred *cred)
Stanislav Kinsbursky24452232012-04-25 18:22:54 +0400427{
Stanislav Kinsbursky7d13ec72012-04-25 18:23:02 +0400428 int error;
Stanislav Kinsbursky24452232012-04-25 18:22:54 +0400429
430 mutex_lock(&nlmsvc_mutex);
431
NeilBrownecd3ad62021-11-29 15:51:25 +1100432 error = lockd_get();
NeilBrown2840fe82021-11-29 15:51:25 +1100433 if (error)
NeilBrown865b6742021-11-29 15:51:25 +1100434 goto err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
NeilBrownb73a2972021-11-29 15:51:25 +1100436 error = lockd_up_net(nlmsvc_serv, net, cred);
Vasily Averindc3033e2017-10-20 17:33:18 +0300437 if (error < 0) {
NeilBrown865b6742021-11-29 15:51:25 +1100438 lockd_put();
439 goto err;
Vasily Averindc3033e2017-10-20 17:33:18 +0300440 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441
NeilBrown865b6742021-11-29 15:51:25 +1100442err:
Ingo Molnar353ab6e2006-03-26 01:37:12 -0800443 mutex_unlock(&nlmsvc_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 return error;
445}
Trond Myklebust2de59872008-12-23 15:21:33 -0500446EXPORT_SYMBOL_GPL(lockd_up);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
448/*
449 * Decrement the user count and bring down lockd if we're the last.
450 */
451void
Stanislav Kinsburskye3f70ea2012-03-29 18:54:33 +0400452lockd_down(struct net *net)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453{
Ingo Molnar353ab6e2006-03-26 01:37:12 -0800454 mutex_lock(&nlmsvc_mutex);
NeilBrown2840fe82021-11-29 15:51:25 +1100455 lockd_down_net(nlmsvc_serv, net);
NeilBrown865b6742021-11-29 15:51:25 +1100456 lockd_put();
Ingo Molnar353ab6e2006-03-26 01:37:12 -0800457 mutex_unlock(&nlmsvc_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458}
Trond Myklebust2de59872008-12-23 15:21:33 -0500459EXPORT_SYMBOL_GPL(lockd_down);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460
Chuck Lever90d5b182008-03-14 14:18:30 -0400461#ifdef CONFIG_SYSCTL
462
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463/*
464 * Sysctl parameters (same as module parameters, different interface).
465 */
466
Joe Perches7ac9fe52014-06-06 14:38:02 -0700467static struct ctl_table nlm_sysctls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 .procname = "nlm_grace_period",
470 .data = &nlm_grace_period,
Steve Dickson7ee91ec2005-07-13 01:10:47 -0700471 .maxlen = sizeof(unsigned long),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800473 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 .extra1 = (unsigned long *) &nlm_grace_period_min,
475 .extra2 = (unsigned long *) &nlm_grace_period_max,
476 },
477 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 .procname = "nlm_timeout",
479 .data = &nlm_timeout,
Steve Dickson7ee91ec2005-07-13 01:10:47 -0700480 .maxlen = sizeof(unsigned long),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800482 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 .extra1 = (unsigned long *) &nlm_timeout_min,
484 .extra2 = (unsigned long *) &nlm_timeout_max,
485 },
486 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 .procname = "nlm_udpport",
488 .data = &nlm_udpport,
489 .maxlen = sizeof(int),
490 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800491 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 .extra1 = (int *) &nlm_port_min,
493 .extra2 = (int *) &nlm_port_max,
494 },
495 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 .procname = "nlm_tcpport",
497 .data = &nlm_tcpport,
498 .maxlen = sizeof(int),
499 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800500 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 .extra1 = (int *) &nlm_port_min,
502 .extra2 = (int *) &nlm_port_max,
503 },
Olaf Kirchabd1f502006-10-04 02:16:01 -0700504 {
Olaf Kirchabd1f502006-10-04 02:16:01 -0700505 .procname = "nsm_use_hostnames",
506 .data = &nsm_use_hostnames,
507 .maxlen = sizeof(int),
508 .mode = 0644,
Jia Hed02a3a22021-08-03 12:59:37 +0200509 .proc_handler = proc_dobool,
Olaf Kirchabd1f502006-10-04 02:16:01 -0700510 },
Olaf Kirch460f5ca2006-10-04 02:16:03 -0700511 {
Olaf Kirch460f5ca2006-10-04 02:16:03 -0700512 .procname = "nsm_local_state",
513 .data = &nsm_local_state,
514 .maxlen = sizeof(int),
515 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800516 .proc_handler = proc_dointvec,
Olaf Kirch460f5ca2006-10-04 02:16:03 -0700517 },
Eric W. Biedermanab092032009-11-05 14:25:10 -0800518 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519};
520
Joe Perches7ac9fe52014-06-06 14:38:02 -0700521static struct ctl_table nlm_sysctl_dir[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 .procname = "nfs",
524 .mode = 0555,
525 .child = nlm_sysctls,
526 },
Eric W. Biedermanab092032009-11-05 14:25:10 -0800527 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528};
529
Joe Perches7ac9fe52014-06-06 14:38:02 -0700530static struct ctl_table nlm_sysctl_root[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 .procname = "fs",
533 .mode = 0555,
534 .child = nlm_sysctl_dir,
535 },
Eric W. Biedermanab092032009-11-05 14:25:10 -0800536 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537};
538
Chuck Lever90d5b182008-03-14 14:18:30 -0400539#endif /* CONFIG_SYSCTL */
540
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541/*
Robert P. J. Day405ae7d2007-02-17 19:13:42 +0100542 * Module (and sysfs) parameters.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 */
544
545#define param_set_min_max(name, type, which_strtol, min, max) \
Kees Cooke4dca7b2017-10-17 19:04:42 -0700546static int param_set_##name(const char *val, const struct kernel_param *kp) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547{ \
548 char *endp; \
549 __typeof__(type) num = which_strtol(val, &endp, 0); \
550 if (endp == val || *endp || num < (min) || num > (max)) \
551 return -EINVAL; \
NeilBrownde5b8e82012-02-07 15:35:42 +1100552 *((type *) kp->arg) = num; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 return 0; \
554}
555
556static inline int is_callback(u32 proc)
557{
558 return proc == NLMPROC_GRANTED
559 || proc == NLMPROC_GRANTED_MSG
560 || proc == NLMPROC_TEST_RES
561 || proc == NLMPROC_LOCK_RES
562 || proc == NLMPROC_CANCEL_RES
563 || proc == NLMPROC_UNLOCK_RES
564 || proc == NLMPROC_NSM_NOTIFY;
565}
566
567
568static int lockd_authenticate(struct svc_rqst *rqstp)
569{
570 rqstp->rq_client = NULL;
571 switch (rqstp->rq_authop->flavour) {
572 case RPC_AUTH_NULL:
573 case RPC_AUTH_UNIX:
Chuck Lever5c2465d2021-07-15 15:52:12 -0400574 rqstp->rq_auth_stat = rpc_auth_ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 if (rqstp->rq_proc == 0)
576 return SVC_OK;
577 if (is_callback(rqstp->rq_proc)) {
578 /* Leave it to individual procedures to
579 * call nlmsvc_lookup_host(rqstp)
580 */
581 return SVC_OK;
582 }
583 return svc_set_client(rqstp);
584 }
Chuck Lever5c2465d2021-07-15 15:52:12 -0400585 rqstp->rq_auth_stat = rpc_autherr_badcred;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 return SVC_DENIED;
587}
588
589
590param_set_min_max(port, int, simple_strtol, 0, 65535)
591param_set_min_max(grace_period, unsigned long, simple_strtoul,
592 nlm_grace_period_min, nlm_grace_period_max)
593param_set_min_max(timeout, unsigned long, simple_strtoul,
594 nlm_timeout_min, nlm_timeout_max)
595
596MODULE_AUTHOR("Olaf Kirch <okir@monad.swb.de>");
597MODULE_DESCRIPTION("NFS file locking service version " LOCKD_VERSION ".");
598MODULE_LICENSE("GPL");
599
600module_param_call(nlm_grace_period, param_set_grace_period, param_get_ulong,
601 &nlm_grace_period, 0644);
602module_param_call(nlm_timeout, param_set_timeout, param_get_ulong,
603 &nlm_timeout, 0644);
604module_param_call(nlm_udpport, param_set_port, param_get_int,
605 &nlm_udpport, 0644);
606module_param_call(nlm_tcpport, param_set_port, param_get_int,
607 &nlm_tcpport, 0644);
Olaf Kirchabd1f502006-10-04 02:16:01 -0700608module_param(nsm_use_hostnames, bool, 0644);
Jeff Laytonc72a4762008-10-20 11:51:58 -0400609module_param(nlm_max_connections, uint, 0644);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
Stanislav Kinsburskya9c5d732012-01-31 15:07:57 +0400611static int lockd_init_net(struct net *net)
612{
Stanislav Kinsbursky66547b02012-07-25 16:56:43 +0400613 struct lockd_net *ln = net_generic(net, lockd_net_id);
614
615 INIT_DELAYED_WORK(&ln->grace_period_end, grace_ender);
Jeff Laytonf7790022014-09-12 16:40:20 -0400616 INIT_LIST_HEAD(&ln->lockd_manager.list);
J. Bruce Fieldsc87fb4a2015-08-06 12:47:02 -0400617 ln->lockd_manager.block_opens = false;
Andrey Ryabinin0ad95472015-09-23 15:49:29 +0300618 INIT_LIST_HEAD(&ln->nsm_handles);
Stanislav Kinsburskya9c5d732012-01-31 15:07:57 +0400619 return 0;
620}
621
622static void lockd_exit_net(struct net *net)
623{
Vasily Averina3152f12017-11-06 16:23:24 +0300624 struct lockd_net *ln = net_generic(net, lockd_net_id);
625
626 WARN_ONCE(!list_empty(&ln->lockd_manager.list),
627 "net %x %s: lockd_manager.list is not empty\n",
628 net->ns.inum, __func__);
629 WARN_ONCE(!list_empty(&ln->nsm_handles),
630 "net %x %s: nsm_handles list is not empty\n",
631 net->ns.inum, __func__);
632 WARN_ONCE(delayed_work_pending(&ln->grace_period_end),
633 "net %x %s: grace_period_end was not cancelled\n",
634 net->ns.inum, __func__);
Stanislav Kinsburskya9c5d732012-01-31 15:07:57 +0400635}
636
637static struct pernet_operations lockd_net_ops = {
638 .init = lockd_init_net,
639 .exit = lockd_exit_net,
640 .id = &lockd_net_id,
641 .size = sizeof(struct lockd_net),
642};
643
644
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645/*
646 * Initialising and terminating the module.
647 */
648
649static int __init init_nlm(void)
650{
Stanislav Kinsburskya9c5d732012-01-31 15:07:57 +0400651 int err;
652
Chuck Lever90d5b182008-03-14 14:18:30 -0400653#ifdef CONFIG_SYSCTL
Stanislav Kinsburskya9c5d732012-01-31 15:07:57 +0400654 err = -ENOMEM;
Eric W. Biederman0b4d4142007-02-14 00:34:09 -0800655 nlm_sysctl_table = register_sysctl_table(nlm_sysctl_root);
Stanislav Kinsburskya9c5d732012-01-31 15:07:57 +0400656 if (nlm_sysctl_table == NULL)
657 goto err_sysctl;
Chuck Lever90d5b182008-03-14 14:18:30 -0400658#endif
Stanislav Kinsburskya9c5d732012-01-31 15:07:57 +0400659 err = register_pernet_subsys(&lockd_net_ops);
660 if (err)
661 goto err_pernet;
Jeff Laytond68e3c42014-09-12 16:40:20 -0400662
663 err = lockd_create_procfs();
664 if (err)
665 goto err_procfs;
666
Stanislav Kinsburskya9c5d732012-01-31 15:07:57 +0400667 return 0;
668
Jeff Laytond68e3c42014-09-12 16:40:20 -0400669err_procfs:
670 unregister_pernet_subsys(&lockd_net_ops);
Stanislav Kinsburskya9c5d732012-01-31 15:07:57 +0400671err_pernet:
672#ifdef CONFIG_SYSCTL
673 unregister_sysctl_table(nlm_sysctl_table);
Stanislav Kinsburskya9c5d732012-01-31 15:07:57 +0400674err_sysctl:
Kees Cook12dd7ec2014-05-01 14:15:02 -0700675#endif
Stanislav Kinsburskya9c5d732012-01-31 15:07:57 +0400676 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677}
678
679static void __exit exit_nlm(void)
680{
681 /* FIXME: delete all NLM clients */
682 nlm_shutdown_hosts();
Jeff Laytond68e3c42014-09-12 16:40:20 -0400683 lockd_remove_procfs();
Stanislav Kinsburskya9c5d732012-01-31 15:07:57 +0400684 unregister_pernet_subsys(&lockd_net_ops);
Chuck Lever90d5b182008-03-14 14:18:30 -0400685#ifdef CONFIG_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 unregister_sysctl_table(nlm_sysctl_table);
Chuck Lever90d5b182008-03-14 14:18:30 -0400687#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688}
689
690module_init(init_nlm);
691module_exit(exit_nlm);
692
Chuck Levera9ad1a82021-06-03 16:50:46 -0400693/**
694 * nlmsvc_dispatch - Process an NLM Request
695 * @rqstp: incoming request
696 * @statp: pointer to location of accept_stat field in RPC Reply buffer
697 *
698 * Return values:
699 * %0: Processing complete; do not send a Reply
700 * %1: Processing complete; send Reply in rqstp->rq_res
701 */
702static int nlmsvc_dispatch(struct svc_rqst *rqstp, __be32 *statp)
703{
704 const struct svc_procedure *procp = rqstp->rq_procinfo;
Chuck Levera9ad1a82021-06-03 16:50:46 -0400705
706 svcxdr_init_decode(rqstp);
Chuck Lever16c66362021-10-12 11:57:22 -0400707 if (!procp->pc_decode(rqstp, &rqstp->rq_arg_stream))
Chuck Levera9ad1a82021-06-03 16:50:46 -0400708 goto out_decode_err;
709
710 *statp = procp->pc_func(rqstp);
711 if (*statp == rpc_drop_reply)
712 return 0;
713 if (*statp != rpc_success)
714 return 1;
715
716 svcxdr_init_encode(rqstp);
Chuck Leverfda49442021-10-13 10:41:06 -0400717 if (!procp->pc_encode(rqstp, &rqstp->rq_res_stream))
Chuck Levera9ad1a82021-06-03 16:50:46 -0400718 goto out_encode_err;
719
720 return 1;
721
722out_decode_err:
723 *statp = rpc_garbage_args;
724 return 1;
725
726out_encode_err:
727 *statp = rpc_system_err;
728 return 1;
729}
730
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731/*
732 * Define NLM program and procedures
733 */
Christoph Hellwig7fd38af2017-05-08 23:40:27 +0200734static unsigned int nlmsvc_version1_count[17];
Christoph Hellwige9679182017-05-12 16:21:37 +0200735static const struct svc_version nlmsvc_version1 = {
736 .vs_vers = 1,
737 .vs_nproc = 17,
738 .vs_proc = nlmsvc_procedures,
739 .vs_count = nlmsvc_version1_count,
Chuck Levera9ad1a82021-06-03 16:50:46 -0400740 .vs_dispatch = nlmsvc_dispatch,
Christoph Hellwige9679182017-05-12 16:21:37 +0200741 .vs_xdrsize = NLMSVC_XDRSIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742};
Christoph Hellwig7fd38af2017-05-08 23:40:27 +0200743static unsigned int nlmsvc_version3_count[24];
Christoph Hellwige9679182017-05-12 16:21:37 +0200744static const struct svc_version nlmsvc_version3 = {
745 .vs_vers = 3,
746 .vs_nproc = 24,
747 .vs_proc = nlmsvc_procedures,
748 .vs_count = nlmsvc_version3_count,
Chuck Levera9ad1a82021-06-03 16:50:46 -0400749 .vs_dispatch = nlmsvc_dispatch,
Christoph Hellwige9679182017-05-12 16:21:37 +0200750 .vs_xdrsize = NLMSVC_XDRSIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751};
752#ifdef CONFIG_LOCKD_V4
Christoph Hellwig7fd38af2017-05-08 23:40:27 +0200753static unsigned int nlmsvc_version4_count[24];
Christoph Hellwige9679182017-05-12 16:21:37 +0200754static const struct svc_version nlmsvc_version4 = {
755 .vs_vers = 4,
756 .vs_nproc = 24,
757 .vs_proc = nlmsvc_procedures4,
758 .vs_count = nlmsvc_version4_count,
Chuck Levera9ad1a82021-06-03 16:50:46 -0400759 .vs_dispatch = nlmsvc_dispatch,
Christoph Hellwige9679182017-05-12 16:21:37 +0200760 .vs_xdrsize = NLMSVC_XDRSIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761};
762#endif
Christoph Hellwige9679182017-05-12 16:21:37 +0200763static const struct svc_version *nlmsvc_version[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 [1] = &nlmsvc_version1,
765 [3] = &nlmsvc_version3,
766#ifdef CONFIG_LOCKD_V4
767 [4] = &nlmsvc_version4,
768#endif
769};
770
771static struct svc_stat nlmsvc_stats;
772
Tobias Klausere8c96f82006-03-24 03:15:34 -0800773#define NLM_NRVERS ARRAY_SIZE(nlmsvc_version)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774static struct svc_program nlmsvc_program = {
775 .pg_prog = NLM_PROGRAM, /* program number */
776 .pg_nvers = NLM_NRVERS, /* number of entries in nlmsvc_version */
777 .pg_vers = nlmsvc_version, /* version table */
778 .pg_name = "lockd", /* service name */
779 .pg_class = "nfsd", /* share authentication with nfsd */
780 .pg_stats = &nlmsvc_stats, /* stats table */
Trond Myklebust8e5b6772019-04-09 11:46:15 -0400781 .pg_authenticate = &lockd_authenticate, /* export authentication */
782 .pg_init_request = svc_generic_init_request,
Trond Myklebust642ee6b2019-04-09 11:46:17 -0400783 .pg_rpcbind_set = svc_generic_rpcbind_set,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784};