nfsctl.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354
  1. /*
  2. * linux/fs/nfsd/nfsctl.c
  3. *
  4. * Syscall interface to knfsd.
  5. *
  6. * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
  7. */
  8. #include <linux/module.h>
  9. #include <linux/linkage.h>
  10. #include <linux/time.h>
  11. #include <linux/errno.h>
  12. #include <linux/fs.h>
  13. #include <linux/namei.h>
  14. #include <linux/fcntl.h>
  15. #include <linux/net.h>
  16. #include <linux/in.h>
  17. #include <linux/syscalls.h>
  18. #include <linux/unistd.h>
  19. #include <linux/slab.h>
  20. #include <linux/proc_fs.h>
  21. #include <linux/seq_file.h>
  22. #include <linux/pagemap.h>
  23. #include <linux/init.h>
  24. #include <linux/inet.h>
  25. #include <linux/string.h>
  26. #include <linux/smp_lock.h>
  27. #include <linux/ctype.h>
  28. #include <linux/nfs.h>
  29. #include <linux/nfsd_idmap.h>
  30. #include <linux/lockd/bind.h>
  31. #include <linux/sunrpc/svc.h>
  32. #include <linux/sunrpc/svcsock.h>
  33. #include <linux/nfsd/nfsd.h>
  34. #include <linux/nfsd/cache.h>
  35. #include <linux/nfsd/xdr.h>
  36. #include <linux/nfsd/syscall.h>
  37. #include <linux/lockd/lockd.h>
  38. #include <asm/uaccess.h>
  39. #include <net/ipv6.h>
  40. /*
  41. * We have a single directory with 9 nodes in it.
  42. */
  43. enum {
  44. NFSD_Root = 1,
  45. NFSD_Svc,
  46. NFSD_Add,
  47. NFSD_Del,
  48. NFSD_Export,
  49. NFSD_Unexport,
  50. NFSD_Getfd,
  51. NFSD_Getfs,
  52. NFSD_List,
  53. NFSD_Fh,
  54. NFSD_FO_UnlockIP,
  55. NFSD_FO_UnlockFS,
  56. NFSD_Threads,
  57. NFSD_Pool_Threads,
  58. NFSD_Versions,
  59. NFSD_Ports,
  60. NFSD_MaxBlkSize,
  61. /*
  62. * The below MUST come last. Otherwise we leave a hole in nfsd_files[]
  63. * with !CONFIG_NFSD_V4 and simple_fill_super() goes oops
  64. */
  65. #ifdef CONFIG_NFSD_V4
  66. NFSD_Leasetime,
  67. NFSD_RecoveryDir,
  68. #endif
  69. };
  70. /*
  71. * write() for these nodes.
  72. */
  73. static ssize_t write_svc(struct file *file, char *buf, size_t size);
  74. static ssize_t write_add(struct file *file, char *buf, size_t size);
  75. static ssize_t write_del(struct file *file, char *buf, size_t size);
  76. static ssize_t write_export(struct file *file, char *buf, size_t size);
  77. static ssize_t write_unexport(struct file *file, char *buf, size_t size);
  78. static ssize_t write_getfd(struct file *file, char *buf, size_t size);
  79. static ssize_t write_getfs(struct file *file, char *buf, size_t size);
  80. static ssize_t write_filehandle(struct file *file, char *buf, size_t size);
  81. static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size);
  82. static ssize_t write_unlock_fs(struct file *file, char *buf, size_t size);
  83. static ssize_t write_threads(struct file *file, char *buf, size_t size);
  84. static ssize_t write_pool_threads(struct file *file, char *buf, size_t size);
  85. static ssize_t write_versions(struct file *file, char *buf, size_t size);
  86. static ssize_t write_ports(struct file *file, char *buf, size_t size);
  87. static ssize_t write_maxblksize(struct file *file, char *buf, size_t size);
  88. #ifdef CONFIG_NFSD_V4
  89. static ssize_t write_leasetime(struct file *file, char *buf, size_t size);
  90. static ssize_t write_recoverydir(struct file *file, char *buf, size_t size);
  91. #endif
  92. static ssize_t (*write_op[])(struct file *, char *, size_t) = {
  93. [NFSD_Svc] = write_svc,
  94. [NFSD_Add] = write_add,
  95. [NFSD_Del] = write_del,
  96. [NFSD_Export] = write_export,
  97. [NFSD_Unexport] = write_unexport,
  98. [NFSD_Getfd] = write_getfd,
  99. [NFSD_Getfs] = write_getfs,
  100. [NFSD_Fh] = write_filehandle,
  101. [NFSD_FO_UnlockIP] = write_unlock_ip,
  102. [NFSD_FO_UnlockFS] = write_unlock_fs,
  103. [NFSD_Threads] = write_threads,
  104. [NFSD_Pool_Threads] = write_pool_threads,
  105. [NFSD_Versions] = write_versions,
  106. [NFSD_Ports] = write_ports,
  107. [NFSD_MaxBlkSize] = write_maxblksize,
  108. #ifdef CONFIG_NFSD_V4
  109. [NFSD_Leasetime] = write_leasetime,
  110. [NFSD_RecoveryDir] = write_recoverydir,
  111. #endif
  112. };
  113. static ssize_t nfsctl_transaction_write(struct file *file, const char __user *buf, size_t size, loff_t *pos)
  114. {
  115. ino_t ino = file->f_path.dentry->d_inode->i_ino;
  116. char *data;
  117. ssize_t rv;
  118. if (ino >= ARRAY_SIZE(write_op) || !write_op[ino])
  119. return -EINVAL;
  120. data = simple_transaction_get(file, buf, size);
  121. if (IS_ERR(data))
  122. return PTR_ERR(data);
  123. rv = write_op[ino](file, data, size);
  124. if (rv >= 0) {
  125. simple_transaction_set(file, rv);
  126. rv = size;
  127. }
  128. return rv;
  129. }
  130. static ssize_t nfsctl_transaction_read(struct file *file, char __user *buf, size_t size, loff_t *pos)
  131. {
  132. if (! file->private_data) {
  133. /* An attempt to read a transaction file without writing
  134. * causes a 0-byte write so that the file can return
  135. * state information
  136. */
  137. ssize_t rv = nfsctl_transaction_write(file, buf, 0, pos);
  138. if (rv < 0)
  139. return rv;
  140. }
  141. return simple_transaction_read(file, buf, size, pos);
  142. }
  143. static const struct file_operations transaction_ops = {
  144. .write = nfsctl_transaction_write,
  145. .read = nfsctl_transaction_read,
  146. .release = simple_transaction_release,
  147. };
  148. static int exports_open(struct inode *inode, struct file *file)
  149. {
  150. return seq_open(file, &nfs_exports_op);
  151. }
  152. static const struct file_operations exports_operations = {
  153. .open = exports_open,
  154. .read = seq_read,
  155. .llseek = seq_lseek,
  156. .release = seq_release,
  157. .owner = THIS_MODULE,
  158. };
  159. /*----------------------------------------------------------------------------*/
  160. /*
  161. * payload - write methods
  162. */
  163. /**
  164. * write_svc - Start kernel's NFSD server
  165. *
  166. * Deprecated. /proc/fs/nfsd/threads is preferred.
  167. * Function remains to support old versions of nfs-utils.
  168. *
  169. * Input:
  170. * buf: struct nfsctl_svc
  171. * svc_port: port number of this
  172. * server's listener
  173. * svc_nthreads: number of threads to start
  174. * size: size in bytes of passed in nfsctl_svc
  175. * Output:
  176. * On success: returns zero
  177. * On error: return code is negative errno value
  178. */
  179. static ssize_t write_svc(struct file *file, char *buf, size_t size)
  180. {
  181. struct nfsctl_svc *data;
  182. if (size < sizeof(*data))
  183. return -EINVAL;
  184. data = (struct nfsctl_svc*) buf;
  185. return nfsd_svc(data->svc_port, data->svc_nthreads);
  186. }
  187. /**
  188. * write_add - Add or modify client entry in auth unix cache
  189. *
  190. * Deprecated. /proc/net/rpc/auth.unix.ip is preferred.
  191. * Function remains to support old versions of nfs-utils.
  192. *
  193. * Input:
  194. * buf: struct nfsctl_client
  195. * cl_ident: '\0'-terminated C string
  196. * containing domain name
  197. * of client
  198. * cl_naddr: no. of items in cl_addrlist
  199. * cl_addrlist: array of client addresses
  200. * cl_fhkeytype: ignored
  201. * cl_fhkeylen: ignored
  202. * cl_fhkey: ignored
  203. * size: size in bytes of passed in nfsctl_client
  204. * Output:
  205. * On success: returns zero
  206. * On error: return code is negative errno value
  207. *
  208. * Note: Only AF_INET client addresses are passed in, since
  209. * nfsctl_client.cl_addrlist contains only in_addr fields for addresses.
  210. */
  211. static ssize_t write_add(struct file *file, char *buf, size_t size)
  212. {
  213. struct nfsctl_client *data;
  214. if (size < sizeof(*data))
  215. return -EINVAL;
  216. data = (struct nfsctl_client *)buf;
  217. return exp_addclient(data);
  218. }
  219. /**
  220. * write_del - Remove client from auth unix cache
  221. *
  222. * Deprecated. /proc/net/rpc/auth.unix.ip is preferred.
  223. * Function remains to support old versions of nfs-utils.
  224. *
  225. * Input:
  226. * buf: struct nfsctl_client
  227. * cl_ident: '\0'-terminated C string
  228. * containing domain name
  229. * of client
  230. * cl_naddr: ignored
  231. * cl_addrlist: ignored
  232. * cl_fhkeytype: ignored
  233. * cl_fhkeylen: ignored
  234. * cl_fhkey: ignored
  235. * size: size in bytes of passed in nfsctl_client
  236. * Output:
  237. * On success: returns zero
  238. * On error: return code is negative errno value
  239. *
  240. * Note: Only AF_INET client addresses are passed in, since
  241. * nfsctl_client.cl_addrlist contains only in_addr fields for addresses.
  242. */
  243. static ssize_t write_del(struct file *file, char *buf, size_t size)
  244. {
  245. struct nfsctl_client *data;
  246. if (size < sizeof(*data))
  247. return -EINVAL;
  248. data = (struct nfsctl_client *)buf;
  249. return exp_delclient(data);
  250. }
  251. /**
  252. * write_export - Export part or all of a local file system
  253. *
  254. * Deprecated. /proc/net/rpc/{nfsd.export,nfsd.fh} are preferred.
  255. * Function remains to support old versions of nfs-utils.
  256. *
  257. * Input:
  258. * buf: struct nfsctl_export
  259. * ex_client: '\0'-terminated C string
  260. * containing domain name
  261. * of client allowed to access
  262. * this export
  263. * ex_path: '\0'-terminated C string
  264. * containing pathname of
  265. * directory in local file system
  266. * ex_dev: fsid to use for this export
  267. * ex_ino: ignored
  268. * ex_flags: export flags for this export
  269. * ex_anon_uid: UID to use for anonymous
  270. * requests
  271. * ex_anon_gid: GID to use for anonymous
  272. * requests
  273. * size: size in bytes of passed in nfsctl_export
  274. * Output:
  275. * On success: returns zero
  276. * On error: return code is negative errno value
  277. */
  278. static ssize_t write_export(struct file *file, char *buf, size_t size)
  279. {
  280. struct nfsctl_export *data;
  281. if (size < sizeof(*data))
  282. return -EINVAL;
  283. data = (struct nfsctl_export*)buf;
  284. return exp_export(data);
  285. }
  286. /**
  287. * write_unexport - Unexport a previously exported file system
  288. *
  289. * Deprecated. /proc/net/rpc/{nfsd.export,nfsd.fh} are preferred.
  290. * Function remains to support old versions of nfs-utils.
  291. *
  292. * Input:
  293. * buf: struct nfsctl_export
  294. * ex_client: '\0'-terminated C string
  295. * containing domain name
  296. * of client no longer allowed
  297. * to access this export
  298. * ex_path: '\0'-terminated C string
  299. * containing pathname of
  300. * directory in local file system
  301. * ex_dev: ignored
  302. * ex_ino: ignored
  303. * ex_flags: ignored
  304. * ex_anon_uid: ignored
  305. * ex_anon_gid: ignored
  306. * size: size in bytes of passed in nfsctl_export
  307. * Output:
  308. * On success: returns zero
  309. * On error: return code is negative errno value
  310. */
  311. static ssize_t write_unexport(struct file *file, char *buf, size_t size)
  312. {
  313. struct nfsctl_export *data;
  314. if (size < sizeof(*data))
  315. return -EINVAL;
  316. data = (struct nfsctl_export*)buf;
  317. return exp_unexport(data);
  318. }
  319. /**
  320. * write_getfs - Get a variable-length NFS file handle by path
  321. *
  322. * Deprecated. /proc/fs/nfsd/filehandle is preferred.
  323. * Function remains to support old versions of nfs-utils.
  324. *
  325. * Input:
  326. * buf: struct nfsctl_fsparm
  327. * gd_addr: socket address of client
  328. * gd_path: '\0'-terminated C string
  329. * containing pathname of
  330. * directory in local file system
  331. * gd_maxlen: maximum size of returned file
  332. * handle
  333. * size: size in bytes of passed in nfsctl_fsparm
  334. * Output:
  335. * On success: passed-in buffer filled with a knfsd_fh structure
  336. * (a variable-length raw NFS file handle);
  337. * return code is the size in bytes of the file handle
  338. * On error: return code is negative errno value
  339. *
  340. * Note: Only AF_INET client addresses are passed in, since gd_addr
  341. * is the same size as a struct sockaddr_in.
  342. */
  343. static ssize_t write_getfs(struct file *file, char *buf, size_t size)
  344. {
  345. struct nfsctl_fsparm *data;
  346. struct sockaddr_in *sin;
  347. struct auth_domain *clp;
  348. int err = 0;
  349. struct knfsd_fh *res;
  350. struct in6_addr in6;
  351. if (size < sizeof(*data))
  352. return -EINVAL;
  353. data = (struct nfsctl_fsparm*)buf;
  354. err = -EPROTONOSUPPORT;
  355. if (data->gd_addr.sa_family != AF_INET)
  356. goto out;
  357. sin = (struct sockaddr_in *)&data->gd_addr;
  358. if (data->gd_maxlen > NFS3_FHSIZE)
  359. data->gd_maxlen = NFS3_FHSIZE;
  360. res = (struct knfsd_fh*)buf;
  361. exp_readlock();
  362. ipv6_addr_set_v4mapped(sin->sin_addr.s_addr, &in6);
  363. clp = auth_unix_lookup(&in6);
  364. if (!clp)
  365. err = -EPERM;
  366. else {
  367. err = exp_rootfh(clp, data->gd_path, res, data->gd_maxlen);
  368. auth_domain_put(clp);
  369. }
  370. exp_readunlock();
  371. if (err == 0)
  372. err = res->fh_size + offsetof(struct knfsd_fh, fh_base);
  373. out:
  374. return err;
  375. }
  376. /**
  377. * write_getfd - Get a fixed-length NFS file handle by path (used by mountd)
  378. *
  379. * Deprecated. /proc/fs/nfsd/filehandle is preferred.
  380. * Function remains to support old versions of nfs-utils.
  381. *
  382. * Input:
  383. * buf: struct nfsctl_fdparm
  384. * gd_addr: socket address of client
  385. * gd_path: '\0'-terminated C string
  386. * containing pathname of
  387. * directory in local file system
  388. * gd_version: fdparm structure version
  389. * size: size in bytes of passed in nfsctl_fdparm
  390. * Output:
  391. * On success: passed-in buffer filled with nfsctl_res
  392. * (a fixed-length raw NFS file handle);
  393. * return code is the size in bytes of the file handle
  394. * On error: return code is negative errno value
  395. *
  396. * Note: Only AF_INET client addresses are passed in, since gd_addr
  397. * is the same size as a struct sockaddr_in.
  398. */
  399. static ssize_t write_getfd(struct file *file, char *buf, size_t size)
  400. {
  401. struct nfsctl_fdparm *data;
  402. struct sockaddr_in *sin;
  403. struct auth_domain *clp;
  404. int err = 0;
  405. struct knfsd_fh fh;
  406. char *res;
  407. struct in6_addr in6;
  408. if (size < sizeof(*data))
  409. return -EINVAL;
  410. data = (struct nfsctl_fdparm*)buf;
  411. err = -EPROTONOSUPPORT;
  412. if (data->gd_addr.sa_family != AF_INET)
  413. goto out;
  414. err = -EINVAL;
  415. if (data->gd_version < 2 || data->gd_version > NFSSVC_MAXVERS)
  416. goto out;
  417. res = buf;
  418. sin = (struct sockaddr_in *)&data->gd_addr;
  419. exp_readlock();
  420. ipv6_addr_set_v4mapped(sin->sin_addr.s_addr, &in6);
  421. clp = auth_unix_lookup(&in6);
  422. if (!clp)
  423. err = -EPERM;
  424. else {
  425. err = exp_rootfh(clp, data->gd_path, &fh, NFS_FHSIZE);
  426. auth_domain_put(clp);
  427. }
  428. exp_readunlock();
  429. if (err == 0) {
  430. memset(res,0, NFS_FHSIZE);
  431. memcpy(res, &fh.fh_base, fh.fh_size);
  432. err = NFS_FHSIZE;
  433. }
  434. out:
  435. return err;
  436. }
  437. /**
  438. * write_unlock_ip - Release all locks used by a client
  439. *
  440. * Experimental.
  441. *
  442. * Input:
  443. * buf: '\n'-terminated C string containing a
  444. * presentation format IPv4 address
  445. * size: length of C string in @buf
  446. * Output:
  447. * On success: returns zero if all specified locks were released;
  448. * returns one if one or more locks were not released
  449. * On error: return code is negative errno value
  450. *
  451. * Note: Only AF_INET client addresses are passed in
  452. */
  453. static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size)
  454. {
  455. struct sockaddr_in sin = {
  456. .sin_family = AF_INET,
  457. };
  458. int b1, b2, b3, b4;
  459. char c;
  460. char *fo_path;
  461. /* sanity check */
  462. if (size == 0)
  463. return -EINVAL;
  464. if (buf[size-1] != '\n')
  465. return -EINVAL;
  466. fo_path = buf;
  467. if (qword_get(&buf, fo_path, size) < 0)
  468. return -EINVAL;
  469. /* get ipv4 address */
  470. if (sscanf(fo_path, "%u.%u.%u.%u%c", &b1, &b2, &b3, &b4, &c) != 4)
  471. return -EINVAL;
  472. if (b1 > 255 || b2 > 255 || b3 > 255 || b4 > 255)
  473. return -EINVAL;
  474. sin.sin_addr.s_addr = htonl((b1 << 24) | (b2 << 16) | (b3 << 8) | b4);
  475. return nlmsvc_unlock_all_by_ip((struct sockaddr *)&sin);
  476. }
  477. /**
  478. * write_unlock_fs - Release all locks on a local file system
  479. *
  480. * Experimental.
  481. *
  482. * Input:
  483. * buf: '\n'-terminated C string containing the
  484. * absolute pathname of a local file system
  485. * size: length of C string in @buf
  486. * Output:
  487. * On success: returns zero if all specified locks were released;
  488. * returns one if one or more locks were not released
  489. * On error: return code is negative errno value
  490. */
  491. static ssize_t write_unlock_fs(struct file *file, char *buf, size_t size)
  492. {
  493. struct path path;
  494. char *fo_path;
  495. int error;
  496. /* sanity check */
  497. if (size == 0)
  498. return -EINVAL;
  499. if (buf[size-1] != '\n')
  500. return -EINVAL;
  501. fo_path = buf;
  502. if (qword_get(&buf, fo_path, size) < 0)
  503. return -EINVAL;
  504. error = kern_path(fo_path, 0, &path);
  505. if (error)
  506. return error;
  507. /*
  508. * XXX: Needs better sanity checking. Otherwise we could end up
  509. * releasing locks on the wrong file system.
  510. *
  511. * For example:
  512. * 1. Does the path refer to a directory?
  513. * 2. Is that directory a mount point, or
  514. * 3. Is that directory the root of an exported file system?
  515. */
  516. error = nlmsvc_unlock_all_by_sb(path.mnt->mnt_sb);
  517. path_put(&path);
  518. return error;
  519. }
  520. /**
  521. * write_filehandle - Get a variable-length NFS file handle by path
  522. *
  523. * On input, the buffer contains a '\n'-terminated C string comprised of
  524. * three alphanumeric words separated by whitespace. The string may
  525. * contain escape sequences.
  526. *
  527. * Input:
  528. * buf:
  529. * domain: client domain name
  530. * path: export pathname
  531. * maxsize: numeric maximum size of
  532. * @buf
  533. * size: length of C string in @buf
  534. * Output:
  535. * On success: passed-in buffer filled with '\n'-terminated C
  536. * string containing a ASCII hex text version
  537. * of the NFS file handle;
  538. * return code is the size in bytes of the string
  539. * On error: return code is negative errno value
  540. */
  541. static ssize_t write_filehandle(struct file *file, char *buf, size_t size)
  542. {
  543. char *dname, *path;
  544. int uninitialized_var(maxsize);
  545. char *mesg = buf;
  546. int len;
  547. struct auth_domain *dom;
  548. struct knfsd_fh fh;
  549. if (size == 0)
  550. return -EINVAL;
  551. if (buf[size-1] != '\n')
  552. return -EINVAL;
  553. buf[size-1] = 0;
  554. dname = mesg;
  555. len = qword_get(&mesg, dname, size);
  556. if (len <= 0)
  557. return -EINVAL;
  558. path = dname+len+1;
  559. len = qword_get(&mesg, path, size);
  560. if (len <= 0)
  561. return -EINVAL;
  562. len = get_int(&mesg, &maxsize);
  563. if (len)
  564. return len;
  565. if (maxsize < NFS_FHSIZE)
  566. return -EINVAL;
  567. if (maxsize > NFS3_FHSIZE)
  568. maxsize = NFS3_FHSIZE;
  569. if (qword_get(&mesg, mesg, size)>0)
  570. return -EINVAL;
  571. /* we have all the words, they are in buf.. */
  572. dom = unix_domain_find(dname);
  573. if (!dom)
  574. return -ENOMEM;
  575. len = exp_rootfh(dom, path, &fh, maxsize);
  576. auth_domain_put(dom);
  577. if (len)
  578. return len;
  579. mesg = buf;
  580. len = SIMPLE_TRANSACTION_LIMIT;
  581. qword_addhex(&mesg, &len, (char*)&fh.fh_base, fh.fh_size);
  582. mesg[-1] = '\n';
  583. return mesg - buf;
  584. }
  585. /**
  586. * write_threads - Start NFSD, or report the current number of running threads
  587. *
  588. * Input:
  589. * buf: ignored
  590. * size: zero
  591. * Output:
  592. * On success: passed-in buffer filled with '\n'-terminated C
  593. * string numeric value representing the number of
  594. * running NFSD threads;
  595. * return code is the size in bytes of the string
  596. * On error: return code is zero
  597. *
  598. * OR
  599. *
  600. * Input:
  601. * buf: C string containing an unsigned
  602. * integer value representing the
  603. * number of NFSD threads to start
  604. * size: non-zero length of C string in @buf
  605. * Output:
  606. * On success: NFS service is started;
  607. * passed-in buffer filled with '\n'-terminated C
  608. * string numeric value representing the number of
  609. * running NFSD threads;
  610. * return code is the size in bytes of the string
  611. * On error: return code is zero or a negative errno value
  612. */
  613. static ssize_t write_threads(struct file *file, char *buf, size_t size)
  614. {
  615. char *mesg = buf;
  616. int rv;
  617. if (size > 0) {
  618. int newthreads;
  619. rv = get_int(&mesg, &newthreads);
  620. if (rv)
  621. return rv;
  622. if (newthreads < 0)
  623. return -EINVAL;
  624. rv = nfsd_svc(NFS_PORT, newthreads);
  625. if (rv)
  626. return rv;
  627. }
  628. sprintf(buf, "%d\n", nfsd_nrthreads());
  629. return strlen(buf);
  630. }
  631. /**
  632. * write_pool_threads - Set or report the current number of threads per pool
  633. *
  634. * Input:
  635. * buf: ignored
  636. * size: zero
  637. *
  638. * OR
  639. *
  640. * Input:
  641. * buf: C string containing whitespace-
  642. * separated unsigned integer values
  643. * representing the number of NFSD
  644. * threads to start in each pool
  645. * size: non-zero length of C string in @buf
  646. * Output:
  647. * On success: passed-in buffer filled with '\n'-terminated C
  648. * string containing integer values representing the
  649. * number of NFSD threads in each pool;
  650. * return code is the size in bytes of the string
  651. * On error: return code is zero or a negative errno value
  652. */
  653. static ssize_t write_pool_threads(struct file *file, char *buf, size_t size)
  654. {
  655. /* if size > 0, look for an array of number of threads per node
  656. * and apply them then write out number of threads per node as reply
  657. */
  658. char *mesg = buf;
  659. int i;
  660. int rv;
  661. int len;
  662. int npools;
  663. int *nthreads;
  664. mutex_lock(&nfsd_mutex);
  665. npools = nfsd_nrpools();
  666. if (npools == 0) {
  667. /*
  668. * NFS is shut down. The admin can start it by
  669. * writing to the threads file but NOT the pool_threads
  670. * file, sorry. Report zero threads.
  671. */
  672. mutex_unlock(&nfsd_mutex);
  673. strcpy(buf, "0\n");
  674. return strlen(buf);
  675. }
  676. nthreads = kcalloc(npools, sizeof(int), GFP_KERNEL);
  677. rv = -ENOMEM;
  678. if (nthreads == NULL)
  679. goto out_free;
  680. if (size > 0) {
  681. for (i = 0; i < npools; i++) {
  682. rv = get_int(&mesg, &nthreads[i]);
  683. if (rv == -ENOENT)
  684. break; /* fewer numbers than pools */
  685. if (rv)
  686. goto out_free; /* syntax error */
  687. rv = -EINVAL;
  688. if (nthreads[i] < 0)
  689. goto out_free;
  690. }
  691. rv = nfsd_set_nrthreads(i, nthreads);
  692. if (rv)
  693. goto out_free;
  694. }
  695. rv = nfsd_get_nrthreads(npools, nthreads);
  696. if (rv)
  697. goto out_free;
  698. mesg = buf;
  699. size = SIMPLE_TRANSACTION_LIMIT;
  700. for (i = 0; i < npools && size > 0; i++) {
  701. snprintf(mesg, size, "%d%c", nthreads[i], (i == npools-1 ? '\n' : ' '));
  702. len = strlen(mesg);
  703. size -= len;
  704. mesg += len;
  705. }
  706. mutex_unlock(&nfsd_mutex);
  707. return (mesg-buf);
  708. out_free:
  709. kfree(nthreads);
  710. mutex_unlock(&nfsd_mutex);
  711. return rv;
  712. }
  713. static ssize_t __write_versions(struct file *file, char *buf, size_t size)
  714. {
  715. char *mesg = buf;
  716. char *vers, sign;
  717. int len, num;
  718. ssize_t tlen = 0;
  719. char *sep;
  720. if (size>0) {
  721. if (nfsd_serv)
  722. /* Cannot change versions without updating
  723. * nfsd_serv->sv_xdrsize, and reallocing
  724. * rq_argp and rq_resp
  725. */
  726. return -EBUSY;
  727. if (buf[size-1] != '\n')
  728. return -EINVAL;
  729. buf[size-1] = 0;
  730. vers = mesg;
  731. len = qword_get(&mesg, vers, size);
  732. if (len <= 0) return -EINVAL;
  733. do {
  734. sign = *vers;
  735. if (sign == '+' || sign == '-')
  736. num = simple_strtol((vers+1), NULL, 0);
  737. else
  738. num = simple_strtol(vers, NULL, 0);
  739. switch(num) {
  740. case 2:
  741. case 3:
  742. case 4:
  743. nfsd_vers(num, sign == '-' ? NFSD_CLEAR : NFSD_SET);
  744. break;
  745. default:
  746. return -EINVAL;
  747. }
  748. vers += len + 1;
  749. tlen += len;
  750. } while ((len = qword_get(&mesg, vers, size)) > 0);
  751. /* If all get turned off, turn them back on, as
  752. * having no versions is BAD
  753. */
  754. nfsd_reset_versions();
  755. }
  756. /* Now write current state into reply buffer */
  757. len = 0;
  758. sep = "";
  759. for (num=2 ; num <= 4 ; num++)
  760. if (nfsd_vers(num, NFSD_AVAIL)) {
  761. len += sprintf(buf+len, "%s%c%d", sep,
  762. nfsd_vers(num, NFSD_TEST)?'+':'-',
  763. num);
  764. sep = " ";
  765. }
  766. len += sprintf(buf+len, "\n");
  767. return len;
  768. }
  769. /**
  770. * write_versions - Set or report the available NFS protocol versions
  771. *
  772. * Input:
  773. * buf: ignored
  774. * size: zero
  775. * Output:
  776. * On success: passed-in buffer filled with '\n'-terminated C
  777. * string containing positive or negative integer
  778. * values representing the current status of each
  779. * protocol version;
  780. * return code is the size in bytes of the string
  781. * On error: return code is zero or a negative errno value
  782. *
  783. * OR
  784. *
  785. * Input:
  786. * buf: C string containing whitespace-
  787. * separated positive or negative
  788. * integer values representing NFS
  789. * protocol versions to enable ("+n")
  790. * or disable ("-n")
  791. * size: non-zero length of C string in @buf
  792. * Output:
  793. * On success: status of zero or more protocol versions has
  794. * been updated; passed-in buffer filled with
  795. * '\n'-terminated C string containing positive
  796. * or negative integer values representing the
  797. * current status of each protocol version;
  798. * return code is the size in bytes of the string
  799. * On error: return code is zero or a negative errno value
  800. */
  801. static ssize_t write_versions(struct file *file, char *buf, size_t size)
  802. {
  803. ssize_t rv;
  804. mutex_lock(&nfsd_mutex);
  805. rv = __write_versions(file, buf, size);
  806. mutex_unlock(&nfsd_mutex);
  807. return rv;
  808. }
  809. static ssize_t __write_ports(struct file *file, char *buf, size_t size)
  810. {
  811. if (size == 0) {
  812. int len = 0;
  813. if (nfsd_serv)
  814. len = svc_xprt_names(nfsd_serv, buf, 0);
  815. return len;
  816. }
  817. /* Either a single 'fd' number is written, in which
  818. * case it must be for a socket of a supported family/protocol,
  819. * and we use it as an nfsd socket, or
  820. * A '-' followed by the 'name' of a socket in which case
  821. * we close the socket.
  822. */
  823. if (isdigit(buf[0])) {
  824. char *mesg = buf;
  825. int fd;
  826. int err;
  827. err = get_int(&mesg, &fd);
  828. if (err)
  829. return -EINVAL;
  830. if (fd < 0)
  831. return -EINVAL;
  832. err = nfsd_create_serv();
  833. if (!err) {
  834. err = svc_addsock(nfsd_serv, fd, buf);
  835. if (err >= 0) {
  836. err = lockd_up();
  837. if (err < 0)
  838. svc_sock_names(buf+strlen(buf)+1, nfsd_serv, buf);
  839. }
  840. /* Decrease the count, but don't shutdown the
  841. * the service
  842. */
  843. nfsd_serv->sv_nrthreads--;
  844. }
  845. return err < 0 ? err : 0;
  846. }
  847. if (buf[0] == '-' && isdigit(buf[1])) {
  848. char *toclose = kstrdup(buf+1, GFP_KERNEL);
  849. int len = 0;
  850. if (!toclose)
  851. return -ENOMEM;
  852. if (nfsd_serv)
  853. len = svc_sock_names(buf, nfsd_serv, toclose);
  854. if (len >= 0)
  855. lockd_down();
  856. kfree(toclose);
  857. return len;
  858. }
  859. /*
  860. * Add a transport listener by writing it's transport name
  861. */
  862. if (isalpha(buf[0])) {
  863. int err;
  864. char transport[16];
  865. int port;
  866. if (sscanf(buf, "%15s %4d", transport, &port) == 2) {
  867. if (port < 1 || port > 65535)
  868. return -EINVAL;
  869. err = nfsd_create_serv();
  870. if (!err) {
  871. err = svc_create_xprt(nfsd_serv,
  872. transport, port,
  873. SVC_SOCK_ANONYMOUS);
  874. if (err == -ENOENT)
  875. /* Give a reasonable perror msg for
  876. * bad transport string */
  877. err = -EPROTONOSUPPORT;
  878. }
  879. return err < 0 ? err : 0;
  880. }
  881. }
  882. /*
  883. * Remove a transport by writing it's transport name and port number
  884. */
  885. if (buf[0] == '-' && isalpha(buf[1])) {
  886. struct svc_xprt *xprt;
  887. int err = -EINVAL;
  888. char transport[16];
  889. int port;
  890. if (sscanf(&buf[1], "%15s %4d", transport, &port) == 2) {
  891. if (port < 1 || port > 65535)
  892. return -EINVAL;
  893. if (nfsd_serv) {
  894. xprt = svc_find_xprt(nfsd_serv, transport,
  895. AF_UNSPEC, port);
  896. if (xprt) {
  897. svc_close_xprt(xprt);
  898. svc_xprt_put(xprt);
  899. err = 0;
  900. } else
  901. err = -ENOTCONN;
  902. }
  903. return err < 0 ? err : 0;
  904. }
  905. }
  906. return -EINVAL;
  907. }
  908. /**
  909. * write_ports - Pass a socket file descriptor or transport name to listen on
  910. *
  911. * Input:
  912. * buf: ignored
  913. * size: zero
  914. * Output:
  915. * On success: passed-in buffer filled with a '\n'-terminated C
  916. * string containing a whitespace-separated list of
  917. * named NFSD listeners;
  918. * return code is the size in bytes of the string
  919. * On error: return code is zero or a negative errno value
  920. *
  921. * OR
  922. *
  923. * Input:
  924. * buf: C string containing an unsigned
  925. * integer value representing a bound
  926. * but unconnected socket that is to be
  927. * used as an NFSD listener
  928. * size: non-zero length of C string in @buf
  929. * Output:
  930. * On success: NFS service is started;
  931. * passed-in buffer filled with a '\n'-terminated C
  932. * string containing a unique alphanumeric name of
  933. * the listener;
  934. * return code is the size in bytes of the string
  935. * On error: return code is a negative errno value
  936. *
  937. * OR
  938. *
  939. * Input:
  940. * buf: C string containing a "-" followed
  941. * by an integer value representing a
  942. * previously passed in socket file
  943. * descriptor
  944. * size: non-zero length of C string in @buf
  945. * Output:
  946. * On success: NFS service no longer listens on that socket;
  947. * passed-in buffer filled with a '\n'-terminated C
  948. * string containing a unique name of the listener;
  949. * return code is the size in bytes of the string
  950. * On error: return code is a negative errno value
  951. *
  952. * OR
  953. *
  954. * Input:
  955. * buf: C string containing a transport
  956. * name and an unsigned integer value
  957. * representing the port to listen on,
  958. * separated by whitespace
  959. * size: non-zero length of C string in @buf
  960. * Output:
  961. * On success: returns zero; NFS service is started
  962. * On error: return code is a negative errno value
  963. *
  964. * OR
  965. *
  966. * Input:
  967. * buf: C string containing a "-" followed
  968. * by a transport name and an unsigned
  969. * integer value representing the port
  970. * to listen on, separated by whitespace
  971. * size: non-zero length of C string in @buf
  972. * Output:
  973. * On success: returns zero; NFS service no longer listens
  974. * on that transport
  975. * On error: return code is a negative errno value
  976. */
  977. static ssize_t write_ports(struct file *file, char *buf, size_t size)
  978. {
  979. ssize_t rv;
  980. mutex_lock(&nfsd_mutex);
  981. rv = __write_ports(file, buf, size);
  982. mutex_unlock(&nfsd_mutex);
  983. return rv;
  984. }
  985. int nfsd_max_blksize;
  986. /**
  987. * write_maxblksize - Set or report the current NFS blksize
  988. *
  989. * Input:
  990. * buf: ignored
  991. * size: zero
  992. *
  993. * OR
  994. *
  995. * Input:
  996. * buf: C string containing an unsigned
  997. * integer value representing the new
  998. * NFS blksize
  999. * size: non-zero length of C string in @buf
  1000. * Output:
  1001. * On success: passed-in buffer filled with '\n'-terminated C string
  1002. * containing numeric value of the current NFS blksize
  1003. * setting;
  1004. * return code is the size in bytes of the string
  1005. * On error: return code is zero or a negative errno value
  1006. */
  1007. static ssize_t write_maxblksize(struct file *file, char *buf, size_t size)
  1008. {
  1009. char *mesg = buf;
  1010. if (size > 0) {
  1011. int bsize;
  1012. int rv = get_int(&mesg, &bsize);
  1013. if (rv)
  1014. return rv;
  1015. /* force bsize into allowed range and
  1016. * required alignment.
  1017. */
  1018. if (bsize < 1024)
  1019. bsize = 1024;
  1020. if (bsize > NFSSVC_MAXBLKSIZE)
  1021. bsize = NFSSVC_MAXBLKSIZE;
  1022. bsize &= ~(1024-1);
  1023. mutex_lock(&nfsd_mutex);
  1024. if (nfsd_serv && nfsd_serv->sv_nrthreads) {
  1025. mutex_unlock(&nfsd_mutex);
  1026. return -EBUSY;
  1027. }
  1028. nfsd_max_blksize = bsize;
  1029. mutex_unlock(&nfsd_mutex);
  1030. }
  1031. return sprintf(buf, "%d\n", nfsd_max_blksize);
  1032. }
  1033. #ifdef CONFIG_NFSD_V4
  1034. extern time_t nfs4_leasetime(void);
  1035. static ssize_t __write_leasetime(struct file *file, char *buf, size_t size)
  1036. {
  1037. /* if size > 10 seconds, call
  1038. * nfs4_reset_lease() then write out the new lease (seconds) as reply
  1039. */
  1040. char *mesg = buf;
  1041. int rv, lease;
  1042. if (size > 0) {
  1043. if (nfsd_serv)
  1044. return -EBUSY;
  1045. rv = get_int(&mesg, &lease);
  1046. if (rv)
  1047. return rv;
  1048. if (lease < 10 || lease > 3600)
  1049. return -EINVAL;
  1050. nfs4_reset_lease(lease);
  1051. }
  1052. sprintf(buf, "%ld\n", nfs4_lease_time());
  1053. return strlen(buf);
  1054. }
  1055. /**
  1056. * write_leasetime - Set or report the current NFSv4 lease time
  1057. *
  1058. * Input:
  1059. * buf: ignored
  1060. * size: zero
  1061. *
  1062. * OR
  1063. *
  1064. * Input:
  1065. * buf: C string containing an unsigned
  1066. * integer value representing the new
  1067. * NFSv4 lease expiry time
  1068. * size: non-zero length of C string in @buf
  1069. * Output:
  1070. * On success: passed-in buffer filled with '\n'-terminated C
  1071. * string containing unsigned integer value of the
  1072. * current lease expiry time;
  1073. * return code is the size in bytes of the string
  1074. * On error: return code is zero or a negative errno value
  1075. */
  1076. static ssize_t write_leasetime(struct file *file, char *buf, size_t size)
  1077. {
  1078. ssize_t rv;
  1079. mutex_lock(&nfsd_mutex);
  1080. rv = __write_leasetime(file, buf, size);
  1081. mutex_unlock(&nfsd_mutex);
  1082. return rv;
  1083. }
  1084. extern char *nfs4_recoverydir(void);
  1085. static ssize_t __write_recoverydir(struct file *file, char *buf, size_t size)
  1086. {
  1087. char *mesg = buf;
  1088. char *recdir;
  1089. int len, status;
  1090. if (size > 0) {
  1091. if (nfsd_serv)
  1092. return -EBUSY;
  1093. if (size > PATH_MAX || buf[size-1] != '\n')
  1094. return -EINVAL;
  1095. buf[size-1] = 0;
  1096. recdir = mesg;
  1097. len = qword_get(&mesg, recdir, size);
  1098. if (len <= 0)
  1099. return -EINVAL;
  1100. status = nfs4_reset_recoverydir(recdir);
  1101. }
  1102. sprintf(buf, "%s\n", nfs4_recoverydir());
  1103. return strlen(buf);
  1104. }
  1105. /**
  1106. * write_recoverydir - Set or report the pathname of the recovery directory
  1107. *
  1108. * Input:
  1109. * buf: ignored
  1110. * size: zero
  1111. *
  1112. * OR
  1113. *
  1114. * Input:
  1115. * buf: C string containing the pathname
  1116. * of the directory on a local file
  1117. * system containing permanent NFSv4
  1118. * recovery data
  1119. * size: non-zero length of C string in @buf
  1120. * Output:
  1121. * On success: passed-in buffer filled with '\n'-terminated C string
  1122. * containing the current recovery pathname setting;
  1123. * return code is the size in bytes of the string
  1124. * On error: return code is zero or a negative errno value
  1125. */
  1126. static ssize_t write_recoverydir(struct file *file, char *buf, size_t size)
  1127. {
  1128. ssize_t rv;
  1129. mutex_lock(&nfsd_mutex);
  1130. rv = __write_recoverydir(file, buf, size);
  1131. mutex_unlock(&nfsd_mutex);
  1132. return rv;
  1133. }
  1134. #endif
  1135. /*----------------------------------------------------------------------------*/
  1136. /*
  1137. * populating the filesystem.
  1138. */
  1139. static int nfsd_fill_super(struct super_block * sb, void * data, int silent)
  1140. {
  1141. static struct tree_descr nfsd_files[] = {
  1142. [NFSD_Svc] = {".svc", &transaction_ops, S_IWUSR},
  1143. [NFSD_Add] = {".add", &transaction_ops, S_IWUSR},
  1144. [NFSD_Del] = {".del", &transaction_ops, S_IWUSR},
  1145. [NFSD_Export] = {".export", &transaction_ops, S_IWUSR},
  1146. [NFSD_Unexport] = {".unexport", &transaction_ops, S_IWUSR},
  1147. [NFSD_Getfd] = {".getfd", &transaction_ops, S_IWUSR|S_IRUSR},
  1148. [NFSD_Getfs] = {".getfs", &transaction_ops, S_IWUSR|S_IRUSR},
  1149. [NFSD_List] = {"exports", &exports_operations, S_IRUGO},
  1150. [NFSD_FO_UnlockIP] = {"unlock_ip",
  1151. &transaction_ops, S_IWUSR|S_IRUSR},
  1152. [NFSD_FO_UnlockFS] = {"unlock_filesystem",
  1153. &transaction_ops, S_IWUSR|S_IRUSR},
  1154. [NFSD_Fh] = {"filehandle", &transaction_ops, S_IWUSR|S_IRUSR},
  1155. [NFSD_Threads] = {"threads", &transaction_ops, S_IWUSR|S_IRUSR},
  1156. [NFSD_Pool_Threads] = {"pool_threads", &transaction_ops, S_IWUSR|S_IRUSR},
  1157. [NFSD_Versions] = {"versions", &transaction_ops, S_IWUSR|S_IRUSR},
  1158. [NFSD_Ports] = {"portlist", &transaction_ops, S_IWUSR|S_IRUGO},
  1159. [NFSD_MaxBlkSize] = {"max_block_size", &transaction_ops, S_IWUSR|S_IRUGO},
  1160. #ifdef CONFIG_NFSD_V4
  1161. [NFSD_Leasetime] = {"nfsv4leasetime", &transaction_ops, S_IWUSR|S_IRUSR},
  1162. [NFSD_RecoveryDir] = {"nfsv4recoverydir", &transaction_ops, S_IWUSR|S_IRUSR},
  1163. #endif
  1164. /* last one */ {""}
  1165. };
  1166. return simple_fill_super(sb, 0x6e667364, nfsd_files);
  1167. }
  1168. static int nfsd_get_sb(struct file_system_type *fs_type,
  1169. int flags, const char *dev_name, void *data, struct vfsmount *mnt)
  1170. {
  1171. return get_sb_single(fs_type, flags, data, nfsd_fill_super, mnt);
  1172. }
  1173. static struct file_system_type nfsd_fs_type = {
  1174. .owner = THIS_MODULE,
  1175. .name = "nfsd",
  1176. .get_sb = nfsd_get_sb,
  1177. .kill_sb = kill_litter_super,
  1178. };
  1179. #ifdef CONFIG_PROC_FS
  1180. static int create_proc_exports_entry(void)
  1181. {
  1182. struct proc_dir_entry *entry;
  1183. entry = proc_mkdir("fs/nfs", NULL);
  1184. if (!entry)
  1185. return -ENOMEM;
  1186. entry = proc_create("exports", 0, entry, &exports_operations);
  1187. if (!entry)
  1188. return -ENOMEM;
  1189. return 0;
  1190. }
  1191. #else /* CONFIG_PROC_FS */
  1192. static int create_proc_exports_entry(void)
  1193. {
  1194. return 0;
  1195. }
  1196. #endif
  1197. static int __init init_nfsd(void)
  1198. {
  1199. int retval;
  1200. printk(KERN_INFO "Installing knfsd (copyright (C) 1996 okir@monad.swb.de).\n");
  1201. retval = nfs4_state_init(); /* nfs4 locking state */
  1202. if (retval)
  1203. return retval;
  1204. nfsd_stat_init(); /* Statistics */
  1205. retval = nfsd_reply_cache_init();
  1206. if (retval)
  1207. goto out_free_stat;
  1208. retval = nfsd_export_init();
  1209. if (retval)
  1210. goto out_free_cache;
  1211. nfsd_lockd_init(); /* lockd->nfsd callbacks */
  1212. retval = nfsd_idmap_init();
  1213. if (retval)
  1214. goto out_free_lockd;
  1215. retval = create_proc_exports_entry();
  1216. if (retval)
  1217. goto out_free_idmap;
  1218. retval = register_filesystem(&nfsd_fs_type);
  1219. if (retval)
  1220. goto out_free_all;
  1221. return 0;
  1222. out_free_all:
  1223. remove_proc_entry("fs/nfs/exports", NULL);
  1224. remove_proc_entry("fs/nfs", NULL);
  1225. out_free_idmap:
  1226. nfsd_idmap_shutdown();
  1227. out_free_lockd:
  1228. nfsd_lockd_shutdown();
  1229. nfsd_export_shutdown();
  1230. out_free_cache:
  1231. nfsd_reply_cache_shutdown();
  1232. out_free_stat:
  1233. nfsd_stat_shutdown();
  1234. nfsd4_free_slabs();
  1235. return retval;
  1236. }
  1237. static void __exit exit_nfsd(void)
  1238. {
  1239. nfsd_export_shutdown();
  1240. nfsd_reply_cache_shutdown();
  1241. remove_proc_entry("fs/nfs/exports", NULL);
  1242. remove_proc_entry("fs/nfs", NULL);
  1243. nfsd_stat_shutdown();
  1244. nfsd_lockd_shutdown();
  1245. nfsd_idmap_shutdown();
  1246. nfsd4_free_slabs();
  1247. unregister_filesystem(&nfsd_fs_type);
  1248. }
  1249. MODULE_AUTHOR("Olaf Kirch <okir@monad.swb.de>");
  1250. MODULE_LICENSE("GPL");
  1251. module_init(init_nfsd)
  1252. module_exit(exit_nfsd)