svc.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  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_unregister_notifiers(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. }
  287. static void lockd_svc_exit_thread(void)
  288. {
  289. lockd_unregister_notifiers();
  290. svc_exit_thread(nlmsvc_rqst);
  291. }
  292. static int lockd_start_svc(struct svc_serv *serv)
  293. {
  294. int error;
  295. if (nlmsvc_rqst)
  296. return 0;
  297. /*
  298. * Create the kernel thread and wait for it to start.
  299. */
  300. nlmsvc_rqst = svc_prepare_thread(serv, &serv->sv_pools[0], NUMA_NO_NODE);
  301. if (IS_ERR(nlmsvc_rqst)) {
  302. error = PTR_ERR(nlmsvc_rqst);
  303. printk(KERN_WARNING
  304. "lockd_up: svc_rqst allocation failed, error=%d\n",
  305. error);
  306. goto out_rqst;
  307. }
  308. svc_sock_update_bufs(serv);
  309. serv->sv_maxconn = nlm_max_connections;
  310. nlmsvc_task = kthread_create(lockd, nlmsvc_rqst, "%s", serv->sv_name);
  311. if (IS_ERR(nlmsvc_task)) {
  312. error = PTR_ERR(nlmsvc_task);
  313. printk(KERN_WARNING
  314. "lockd_up: kthread_run failed, error=%d\n", error);
  315. goto out_task;
  316. }
  317. nlmsvc_rqst->rq_task = nlmsvc_task;
  318. wake_up_process(nlmsvc_task);
  319. dprintk("lockd_up: service started\n");
  320. return 0;
  321. out_task:
  322. lockd_svc_exit_thread();
  323. nlmsvc_task = NULL;
  324. out_rqst:
  325. nlmsvc_rqst = NULL;
  326. return error;
  327. }
  328. static struct svc_serv_ops lockd_sv_ops = {
  329. .svo_shutdown = svc_rpcb_cleanup,
  330. .svo_enqueue_xprt = svc_xprt_do_enqueue,
  331. };
  332. static struct svc_serv *lockd_create_svc(void)
  333. {
  334. struct svc_serv *serv;
  335. /*
  336. * Check whether we're already up and running.
  337. */
  338. if (nlmsvc_rqst) {
  339. /*
  340. * Note: increase service usage, because later in case of error
  341. * svc_destroy() will be called.
  342. */
  343. svc_get(nlmsvc_rqst->rq_server);
  344. return nlmsvc_rqst->rq_server;
  345. }
  346. /*
  347. * Sanity check: if there's no pid,
  348. * we should be the first user ...
  349. */
  350. if (nlmsvc_users)
  351. printk(KERN_WARNING
  352. "lockd_up: no pid, %d users??\n", nlmsvc_users);
  353. if (!nlm_timeout)
  354. nlm_timeout = LOCKD_DFLT_TIMEO;
  355. nlmsvc_timeout = nlm_timeout * HZ;
  356. serv = svc_create(&nlmsvc_program, LOCKD_BUFSIZE, &lockd_sv_ops);
  357. if (!serv) {
  358. printk(KERN_WARNING "lockd_up: create service failed\n");
  359. return ERR_PTR(-ENOMEM);
  360. }
  361. register_inetaddr_notifier(&lockd_inetaddr_notifier);
  362. #if IS_ENABLED(CONFIG_IPV6)
  363. register_inet6addr_notifier(&lockd_inet6addr_notifier);
  364. #endif
  365. dprintk("lockd_up: service created\n");
  366. return serv;
  367. }
  368. /*
  369. * Bring up the lockd process if it's not already up.
  370. */
  371. int lockd_up(struct net *net)
  372. {
  373. struct svc_serv *serv;
  374. int error;
  375. mutex_lock(&nlmsvc_mutex);
  376. serv = lockd_create_svc();
  377. if (IS_ERR(serv)) {
  378. error = PTR_ERR(serv);
  379. goto err_create;
  380. }
  381. error = lockd_up_net(serv, net);
  382. if (error < 0)
  383. goto err_net;
  384. error = lockd_start_svc(serv);
  385. if (error < 0)
  386. goto err_start;
  387. nlmsvc_users++;
  388. /*
  389. * Note: svc_serv structures have an initial use count of 1,
  390. * so we exit through here on both success and failure.
  391. */
  392. err_put:
  393. svc_destroy(serv);
  394. err_create:
  395. mutex_unlock(&nlmsvc_mutex);
  396. return error;
  397. err_start:
  398. lockd_down_net(serv, net);
  399. err_net:
  400. lockd_unregister_notifiers();
  401. goto err_put;
  402. }
  403. EXPORT_SYMBOL_GPL(lockd_up);
  404. /*
  405. * Decrement the user count and bring down lockd if we're the last.
  406. */
  407. void
  408. lockd_down(struct net *net)
  409. {
  410. mutex_lock(&nlmsvc_mutex);
  411. lockd_down_net(nlmsvc_rqst->rq_server, net);
  412. if (nlmsvc_users) {
  413. if (--nlmsvc_users)
  414. goto out;
  415. } else {
  416. printk(KERN_ERR "lockd_down: no users! task=%p\n",
  417. nlmsvc_task);
  418. BUG();
  419. }
  420. if (!nlmsvc_task) {
  421. printk(KERN_ERR "lockd_down: no lockd running.\n");
  422. BUG();
  423. }
  424. kthread_stop(nlmsvc_task);
  425. dprintk("lockd_down: service stopped\n");
  426. lockd_svc_exit_thread();
  427. dprintk("lockd_down: service destroyed\n");
  428. nlmsvc_task = NULL;
  429. nlmsvc_rqst = NULL;
  430. out:
  431. mutex_unlock(&nlmsvc_mutex);
  432. }
  433. EXPORT_SYMBOL_GPL(lockd_down);
  434. #ifdef CONFIG_SYSCTL
  435. /*
  436. * Sysctl parameters (same as module parameters, different interface).
  437. */
  438. static struct ctl_table nlm_sysctls[] = {
  439. {
  440. .procname = "nlm_grace_period",
  441. .data = &nlm_grace_period,
  442. .maxlen = sizeof(unsigned long),
  443. .mode = 0644,
  444. .proc_handler = proc_doulongvec_minmax,
  445. .extra1 = (unsigned long *) &nlm_grace_period_min,
  446. .extra2 = (unsigned long *) &nlm_grace_period_max,
  447. },
  448. {
  449. .procname = "nlm_timeout",
  450. .data = &nlm_timeout,
  451. .maxlen = sizeof(unsigned long),
  452. .mode = 0644,
  453. .proc_handler = proc_doulongvec_minmax,
  454. .extra1 = (unsigned long *) &nlm_timeout_min,
  455. .extra2 = (unsigned long *) &nlm_timeout_max,
  456. },
  457. {
  458. .procname = "nlm_udpport",
  459. .data = &nlm_udpport,
  460. .maxlen = sizeof(int),
  461. .mode = 0644,
  462. .proc_handler = proc_dointvec_minmax,
  463. .extra1 = (int *) &nlm_port_min,
  464. .extra2 = (int *) &nlm_port_max,
  465. },
  466. {
  467. .procname = "nlm_tcpport",
  468. .data = &nlm_tcpport,
  469. .maxlen = sizeof(int),
  470. .mode = 0644,
  471. .proc_handler = proc_dointvec_minmax,
  472. .extra1 = (int *) &nlm_port_min,
  473. .extra2 = (int *) &nlm_port_max,
  474. },
  475. {
  476. .procname = "nsm_use_hostnames",
  477. .data = &nsm_use_hostnames,
  478. .maxlen = sizeof(int),
  479. .mode = 0644,
  480. .proc_handler = proc_dointvec,
  481. },
  482. {
  483. .procname = "nsm_local_state",
  484. .data = &nsm_local_state,
  485. .maxlen = sizeof(int),
  486. .mode = 0644,
  487. .proc_handler = proc_dointvec,
  488. },
  489. { }
  490. };
  491. static struct ctl_table nlm_sysctl_dir[] = {
  492. {
  493. .procname = "nfs",
  494. .mode = 0555,
  495. .child = nlm_sysctls,
  496. },
  497. { }
  498. };
  499. static struct ctl_table nlm_sysctl_root[] = {
  500. {
  501. .procname = "fs",
  502. .mode = 0555,
  503. .child = nlm_sysctl_dir,
  504. },
  505. { }
  506. };
  507. #endif /* CONFIG_SYSCTL */
  508. /*
  509. * Module (and sysfs) parameters.
  510. */
  511. #define param_set_min_max(name, type, which_strtol, min, max) \
  512. static int param_set_##name(const char *val, struct kernel_param *kp) \
  513. { \
  514. char *endp; \
  515. __typeof__(type) num = which_strtol(val, &endp, 0); \
  516. if (endp == val || *endp || num < (min) || num > (max)) \
  517. return -EINVAL; \
  518. *((type *) kp->arg) = num; \
  519. return 0; \
  520. }
  521. static inline int is_callback(u32 proc)
  522. {
  523. return proc == NLMPROC_GRANTED
  524. || proc == NLMPROC_GRANTED_MSG
  525. || proc == NLMPROC_TEST_RES
  526. || proc == NLMPROC_LOCK_RES
  527. || proc == NLMPROC_CANCEL_RES
  528. || proc == NLMPROC_UNLOCK_RES
  529. || proc == NLMPROC_NSM_NOTIFY;
  530. }
  531. static int lockd_authenticate(struct svc_rqst *rqstp)
  532. {
  533. rqstp->rq_client = NULL;
  534. switch (rqstp->rq_authop->flavour) {
  535. case RPC_AUTH_NULL:
  536. case RPC_AUTH_UNIX:
  537. if (rqstp->rq_proc == 0)
  538. return SVC_OK;
  539. if (is_callback(rqstp->rq_proc)) {
  540. /* Leave it to individual procedures to
  541. * call nlmsvc_lookup_host(rqstp)
  542. */
  543. return SVC_OK;
  544. }
  545. return svc_set_client(rqstp);
  546. }
  547. return SVC_DENIED;
  548. }
  549. param_set_min_max(port, int, simple_strtol, 0, 65535)
  550. param_set_min_max(grace_period, unsigned long, simple_strtoul,
  551. nlm_grace_period_min, nlm_grace_period_max)
  552. param_set_min_max(timeout, unsigned long, simple_strtoul,
  553. nlm_timeout_min, nlm_timeout_max)
  554. MODULE_AUTHOR("Olaf Kirch <okir@monad.swb.de>");
  555. MODULE_DESCRIPTION("NFS file locking service version " LOCKD_VERSION ".");
  556. MODULE_LICENSE("GPL");
  557. module_param_call(nlm_grace_period, param_set_grace_period, param_get_ulong,
  558. &nlm_grace_period, 0644);
  559. module_param_call(nlm_timeout, param_set_timeout, param_get_ulong,
  560. &nlm_timeout, 0644);
  561. module_param_call(nlm_udpport, param_set_port, param_get_int,
  562. &nlm_udpport, 0644);
  563. module_param_call(nlm_tcpport, param_set_port, param_get_int,
  564. &nlm_tcpport, 0644);
  565. module_param(nsm_use_hostnames, bool, 0644);
  566. module_param(nlm_max_connections, uint, 0644);
  567. static int lockd_init_net(struct net *net)
  568. {
  569. struct lockd_net *ln = net_generic(net, lockd_net_id);
  570. INIT_DELAYED_WORK(&ln->grace_period_end, grace_ender);
  571. INIT_LIST_HEAD(&ln->lockd_manager.list);
  572. ln->lockd_manager.block_opens = false;
  573. INIT_LIST_HEAD(&ln->nsm_handles);
  574. return 0;
  575. }
  576. static void lockd_exit_net(struct net *net)
  577. {
  578. }
  579. static struct pernet_operations lockd_net_ops = {
  580. .init = lockd_init_net,
  581. .exit = lockd_exit_net,
  582. .id = &lockd_net_id,
  583. .size = sizeof(struct lockd_net),
  584. };
  585. /*
  586. * Initialising and terminating the module.
  587. */
  588. static int __init init_nlm(void)
  589. {
  590. int err;
  591. #ifdef CONFIG_SYSCTL
  592. err = -ENOMEM;
  593. nlm_sysctl_table = register_sysctl_table(nlm_sysctl_root);
  594. if (nlm_sysctl_table == NULL)
  595. goto err_sysctl;
  596. #endif
  597. err = register_pernet_subsys(&lockd_net_ops);
  598. if (err)
  599. goto err_pernet;
  600. err = lockd_create_procfs();
  601. if (err)
  602. goto err_procfs;
  603. return 0;
  604. err_procfs:
  605. unregister_pernet_subsys(&lockd_net_ops);
  606. err_pernet:
  607. #ifdef CONFIG_SYSCTL
  608. unregister_sysctl_table(nlm_sysctl_table);
  609. err_sysctl:
  610. #endif
  611. return err;
  612. }
  613. static void __exit exit_nlm(void)
  614. {
  615. /* FIXME: delete all NLM clients */
  616. nlm_shutdown_hosts();
  617. lockd_remove_procfs();
  618. unregister_pernet_subsys(&lockd_net_ops);
  619. #ifdef CONFIG_SYSCTL
  620. unregister_sysctl_table(nlm_sysctl_table);
  621. #endif
  622. }
  623. module_init(init_nlm);
  624. module_exit(exit_nlm);
  625. /*
  626. * Define NLM program and procedures
  627. */
  628. static struct svc_version nlmsvc_version1 = {
  629. .vs_vers = 1,
  630. .vs_nproc = 17,
  631. .vs_proc = nlmsvc_procedures,
  632. .vs_xdrsize = NLMSVC_XDRSIZE,
  633. };
  634. static struct svc_version nlmsvc_version3 = {
  635. .vs_vers = 3,
  636. .vs_nproc = 24,
  637. .vs_proc = nlmsvc_procedures,
  638. .vs_xdrsize = NLMSVC_XDRSIZE,
  639. };
  640. #ifdef CONFIG_LOCKD_V4
  641. static struct svc_version nlmsvc_version4 = {
  642. .vs_vers = 4,
  643. .vs_nproc = 24,
  644. .vs_proc = nlmsvc_procedures4,
  645. .vs_xdrsize = NLMSVC_XDRSIZE,
  646. };
  647. #endif
  648. static struct svc_version * nlmsvc_version[] = {
  649. [1] = &nlmsvc_version1,
  650. [3] = &nlmsvc_version3,
  651. #ifdef CONFIG_LOCKD_V4
  652. [4] = &nlmsvc_version4,
  653. #endif
  654. };
  655. static struct svc_stat nlmsvc_stats;
  656. #define NLM_NRVERS ARRAY_SIZE(nlmsvc_version)
  657. static struct svc_program nlmsvc_program = {
  658. .pg_prog = NLM_PROGRAM, /* program number */
  659. .pg_nvers = NLM_NRVERS, /* number of entries in nlmsvc_version */
  660. .pg_vers = nlmsvc_version, /* version table */
  661. .pg_name = "lockd", /* service name */
  662. .pg_class = "nfsd", /* share authentication with nfsd */
  663. .pg_stats = &nlmsvc_stats, /* stats table */
  664. .pg_authenticate = &lockd_authenticate /* export authentication */
  665. };