svc.c 18 KB

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