svc.c 18 KB

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