svc.c 18 KB

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