svc.c 19 KB

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