nfsctl.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352
  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. err = nfsd_create_serv();
  868. if (!err) {
  869. err = svc_create_xprt(nfsd_serv,
  870. transport, port,
  871. SVC_SOCK_ANONYMOUS);
  872. if (err == -ENOENT)
  873. /* Give a reasonable perror msg for
  874. * bad transport string */
  875. err = -EPROTONOSUPPORT;
  876. }
  877. return err < 0 ? err : 0;
  878. }
  879. }
  880. /*
  881. * Remove a transport by writing it's transport name and port number
  882. */
  883. if (buf[0] == '-' && isalpha(buf[1])) {
  884. struct svc_xprt *xprt;
  885. int err = -EINVAL;
  886. char transport[16];
  887. int port;
  888. if (sscanf(&buf[1], "%15s %4d", transport, &port) == 2) {
  889. if (port == 0)
  890. return -EINVAL;
  891. if (nfsd_serv) {
  892. xprt = svc_find_xprt(nfsd_serv, transport,
  893. AF_UNSPEC, port);
  894. if (xprt) {
  895. svc_close_xprt(xprt);
  896. svc_xprt_put(xprt);
  897. err = 0;
  898. } else
  899. err = -ENOTCONN;
  900. }
  901. return err < 0 ? err : 0;
  902. }
  903. }
  904. return -EINVAL;
  905. }
  906. /**
  907. * write_ports - Pass a socket file descriptor or transport name to listen on
  908. *
  909. * Input:
  910. * buf: ignored
  911. * size: zero
  912. * Output:
  913. * On success: passed-in buffer filled with a '\n'-terminated C
  914. * string containing a whitespace-separated list of
  915. * named NFSD listeners;
  916. * return code is the size in bytes of the string
  917. * On error: return code is zero or a negative errno value
  918. *
  919. * OR
  920. *
  921. * Input:
  922. * buf: C string containing an unsigned
  923. * integer value representing a bound
  924. * but unconnected socket that is to be
  925. * used as an NFSD listener
  926. * size: non-zero length of C string in @buf
  927. * Output:
  928. * On success: NFS service is started;
  929. * passed-in buffer filled with a '\n'-terminated C
  930. * string containing a unique alphanumeric name of
  931. * the listener;
  932. * return code is the size in bytes of the string
  933. * On error: return code is a negative errno value
  934. *
  935. * OR
  936. *
  937. * Input:
  938. * buf: C string containing a "-" followed
  939. * by an integer value representing a
  940. * previously passed in socket file
  941. * descriptor
  942. * size: non-zero length of C string in @buf
  943. * Output:
  944. * On success: NFS service no longer listens on that socket;
  945. * passed-in buffer filled with a '\n'-terminated C
  946. * string containing a unique name of the listener;
  947. * return code is the size in bytes of the string
  948. * On error: return code is a negative errno value
  949. *
  950. * OR
  951. *
  952. * Input:
  953. * buf: C string containing a transport
  954. * name and an unsigned integer value
  955. * representing the port to listen on,
  956. * separated by whitespace
  957. * size: non-zero length of C string in @buf
  958. * Output:
  959. * On success: returns zero; NFS service is started
  960. * On error: return code is a negative errno value
  961. *
  962. * OR
  963. *
  964. * Input:
  965. * buf: C string containing a "-" followed
  966. * by a transport name and an unsigned
  967. * integer value representing the port
  968. * to listen on, separated by whitespace
  969. * size: non-zero length of C string in @buf
  970. * Output:
  971. * On success: returns zero; NFS service no longer listens
  972. * on that transport
  973. * On error: return code is a negative errno value
  974. */
  975. static ssize_t write_ports(struct file *file, char *buf, size_t size)
  976. {
  977. ssize_t rv;
  978. mutex_lock(&nfsd_mutex);
  979. rv = __write_ports(file, buf, size);
  980. mutex_unlock(&nfsd_mutex);
  981. return rv;
  982. }
  983. int nfsd_max_blksize;
  984. /**
  985. * write_maxblksize - Set or report the current NFS blksize
  986. *
  987. * Input:
  988. * buf: ignored
  989. * size: zero
  990. *
  991. * OR
  992. *
  993. * Input:
  994. * buf: C string containing an unsigned
  995. * integer value representing the new
  996. * NFS blksize
  997. * size: non-zero length of C string in @buf
  998. * Output:
  999. * On success: passed-in buffer filled with '\n'-terminated C string
  1000. * containing numeric value of the current NFS blksize
  1001. * setting;
  1002. * return code is the size in bytes of the string
  1003. * On error: return code is zero or a negative errno value
  1004. */
  1005. static ssize_t write_maxblksize(struct file *file, char *buf, size_t size)
  1006. {
  1007. char *mesg = buf;
  1008. if (size > 0) {
  1009. int bsize;
  1010. int rv = get_int(&mesg, &bsize);
  1011. if (rv)
  1012. return rv;
  1013. /* force bsize into allowed range and
  1014. * required alignment.
  1015. */
  1016. if (bsize < 1024)
  1017. bsize = 1024;
  1018. if (bsize > NFSSVC_MAXBLKSIZE)
  1019. bsize = NFSSVC_MAXBLKSIZE;
  1020. bsize &= ~(1024-1);
  1021. mutex_lock(&nfsd_mutex);
  1022. if (nfsd_serv && nfsd_serv->sv_nrthreads) {
  1023. mutex_unlock(&nfsd_mutex);
  1024. return -EBUSY;
  1025. }
  1026. nfsd_max_blksize = bsize;
  1027. mutex_unlock(&nfsd_mutex);
  1028. }
  1029. return sprintf(buf, "%d\n", nfsd_max_blksize);
  1030. }
  1031. #ifdef CONFIG_NFSD_V4
  1032. extern time_t nfs4_leasetime(void);
  1033. static ssize_t __write_leasetime(struct file *file, char *buf, size_t size)
  1034. {
  1035. /* if size > 10 seconds, call
  1036. * nfs4_reset_lease() then write out the new lease (seconds) as reply
  1037. */
  1038. char *mesg = buf;
  1039. int rv, lease;
  1040. if (size > 0) {
  1041. if (nfsd_serv)
  1042. return -EBUSY;
  1043. rv = get_int(&mesg, &lease);
  1044. if (rv)
  1045. return rv;
  1046. if (lease < 10 || lease > 3600)
  1047. return -EINVAL;
  1048. nfs4_reset_lease(lease);
  1049. }
  1050. sprintf(buf, "%ld\n", nfs4_lease_time());
  1051. return strlen(buf);
  1052. }
  1053. /**
  1054. * write_leasetime - Set or report the current NFSv4 lease time
  1055. *
  1056. * Input:
  1057. * buf: ignored
  1058. * size: zero
  1059. *
  1060. * OR
  1061. *
  1062. * Input:
  1063. * buf: C string containing an unsigned
  1064. * integer value representing the new
  1065. * NFSv4 lease expiry time
  1066. * size: non-zero length of C string in @buf
  1067. * Output:
  1068. * On success: passed-in buffer filled with '\n'-terminated C
  1069. * string containing unsigned integer value of the
  1070. * current lease expiry time;
  1071. * return code is the size in bytes of the string
  1072. * On error: return code is zero or a negative errno value
  1073. */
  1074. static ssize_t write_leasetime(struct file *file, char *buf, size_t size)
  1075. {
  1076. ssize_t rv;
  1077. mutex_lock(&nfsd_mutex);
  1078. rv = __write_leasetime(file, buf, size);
  1079. mutex_unlock(&nfsd_mutex);
  1080. return rv;
  1081. }
  1082. extern char *nfs4_recoverydir(void);
  1083. static ssize_t __write_recoverydir(struct file *file, char *buf, size_t size)
  1084. {
  1085. char *mesg = buf;
  1086. char *recdir;
  1087. int len, status;
  1088. if (size > 0) {
  1089. if (nfsd_serv)
  1090. return -EBUSY;
  1091. if (size > PATH_MAX || buf[size-1] != '\n')
  1092. return -EINVAL;
  1093. buf[size-1] = 0;
  1094. recdir = mesg;
  1095. len = qword_get(&mesg, recdir, size);
  1096. if (len <= 0)
  1097. return -EINVAL;
  1098. status = nfs4_reset_recoverydir(recdir);
  1099. }
  1100. sprintf(buf, "%s\n", nfs4_recoverydir());
  1101. return strlen(buf);
  1102. }
  1103. /**
  1104. * write_recoverydir - Set or report the pathname of the recovery directory
  1105. *
  1106. * Input:
  1107. * buf: ignored
  1108. * size: zero
  1109. *
  1110. * OR
  1111. *
  1112. * Input:
  1113. * buf: C string containing the pathname
  1114. * of the directory on a local file
  1115. * system containing permanent NFSv4
  1116. * recovery data
  1117. * size: non-zero length of C string in @buf
  1118. * Output:
  1119. * On success: passed-in buffer filled with '\n'-terminated C string
  1120. * containing the current recovery pathname setting;
  1121. * return code is the size in bytes of the string
  1122. * On error: return code is zero or a negative errno value
  1123. */
  1124. static ssize_t write_recoverydir(struct file *file, char *buf, size_t size)
  1125. {
  1126. ssize_t rv;
  1127. mutex_lock(&nfsd_mutex);
  1128. rv = __write_recoverydir(file, buf, size);
  1129. mutex_unlock(&nfsd_mutex);
  1130. return rv;
  1131. }
  1132. #endif
  1133. /*----------------------------------------------------------------------------*/
  1134. /*
  1135. * populating the filesystem.
  1136. */
  1137. static int nfsd_fill_super(struct super_block * sb, void * data, int silent)
  1138. {
  1139. static struct tree_descr nfsd_files[] = {
  1140. [NFSD_Svc] = {".svc", &transaction_ops, S_IWUSR},
  1141. [NFSD_Add] = {".add", &transaction_ops, S_IWUSR},
  1142. [NFSD_Del] = {".del", &transaction_ops, S_IWUSR},
  1143. [NFSD_Export] = {".export", &transaction_ops, S_IWUSR},
  1144. [NFSD_Unexport] = {".unexport", &transaction_ops, S_IWUSR},
  1145. [NFSD_Getfd] = {".getfd", &transaction_ops, S_IWUSR|S_IRUSR},
  1146. [NFSD_Getfs] = {".getfs", &transaction_ops, S_IWUSR|S_IRUSR},
  1147. [NFSD_List] = {"exports", &exports_operations, S_IRUGO},
  1148. [NFSD_FO_UnlockIP] = {"unlock_ip",
  1149. &transaction_ops, S_IWUSR|S_IRUSR},
  1150. [NFSD_FO_UnlockFS] = {"unlock_filesystem",
  1151. &transaction_ops, S_IWUSR|S_IRUSR},
  1152. [NFSD_Fh] = {"filehandle", &transaction_ops, S_IWUSR|S_IRUSR},
  1153. [NFSD_Threads] = {"threads", &transaction_ops, S_IWUSR|S_IRUSR},
  1154. [NFSD_Pool_Threads] = {"pool_threads", &transaction_ops, S_IWUSR|S_IRUSR},
  1155. [NFSD_Versions] = {"versions", &transaction_ops, S_IWUSR|S_IRUSR},
  1156. [NFSD_Ports] = {"portlist", &transaction_ops, S_IWUSR|S_IRUGO},
  1157. [NFSD_MaxBlkSize] = {"max_block_size", &transaction_ops, S_IWUSR|S_IRUGO},
  1158. #ifdef CONFIG_NFSD_V4
  1159. [NFSD_Leasetime] = {"nfsv4leasetime", &transaction_ops, S_IWUSR|S_IRUSR},
  1160. [NFSD_RecoveryDir] = {"nfsv4recoverydir", &transaction_ops, S_IWUSR|S_IRUSR},
  1161. #endif
  1162. /* last one */ {""}
  1163. };
  1164. return simple_fill_super(sb, 0x6e667364, nfsd_files);
  1165. }
  1166. static int nfsd_get_sb(struct file_system_type *fs_type,
  1167. int flags, const char *dev_name, void *data, struct vfsmount *mnt)
  1168. {
  1169. return get_sb_single(fs_type, flags, data, nfsd_fill_super, mnt);
  1170. }
  1171. static struct file_system_type nfsd_fs_type = {
  1172. .owner = THIS_MODULE,
  1173. .name = "nfsd",
  1174. .get_sb = nfsd_get_sb,
  1175. .kill_sb = kill_litter_super,
  1176. };
  1177. #ifdef CONFIG_PROC_FS
  1178. static int create_proc_exports_entry(void)
  1179. {
  1180. struct proc_dir_entry *entry;
  1181. entry = proc_mkdir("fs/nfs", NULL);
  1182. if (!entry)
  1183. return -ENOMEM;
  1184. entry = proc_create("exports", 0, entry, &exports_operations);
  1185. if (!entry)
  1186. return -ENOMEM;
  1187. return 0;
  1188. }
  1189. #else /* CONFIG_PROC_FS */
  1190. static int create_proc_exports_entry(void)
  1191. {
  1192. return 0;
  1193. }
  1194. #endif
  1195. static int __init init_nfsd(void)
  1196. {
  1197. int retval;
  1198. printk(KERN_INFO "Installing knfsd (copyright (C) 1996 okir@monad.swb.de).\n");
  1199. retval = nfs4_state_init(); /* nfs4 locking state */
  1200. if (retval)
  1201. return retval;
  1202. nfsd_stat_init(); /* Statistics */
  1203. retval = nfsd_reply_cache_init();
  1204. if (retval)
  1205. goto out_free_stat;
  1206. retval = nfsd_export_init();
  1207. if (retval)
  1208. goto out_free_cache;
  1209. nfsd_lockd_init(); /* lockd->nfsd callbacks */
  1210. retval = nfsd_idmap_init();
  1211. if (retval)
  1212. goto out_free_lockd;
  1213. retval = create_proc_exports_entry();
  1214. if (retval)
  1215. goto out_free_idmap;
  1216. retval = register_filesystem(&nfsd_fs_type);
  1217. if (retval)
  1218. goto out_free_all;
  1219. return 0;
  1220. out_free_all:
  1221. remove_proc_entry("fs/nfs/exports", NULL);
  1222. remove_proc_entry("fs/nfs", NULL);
  1223. out_free_idmap:
  1224. nfsd_idmap_shutdown();
  1225. out_free_lockd:
  1226. nfsd_lockd_shutdown();
  1227. nfsd_export_shutdown();
  1228. out_free_cache:
  1229. nfsd_reply_cache_shutdown();
  1230. out_free_stat:
  1231. nfsd_stat_shutdown();
  1232. nfsd4_free_slabs();
  1233. return retval;
  1234. }
  1235. static void __exit exit_nfsd(void)
  1236. {
  1237. nfsd_export_shutdown();
  1238. nfsd_reply_cache_shutdown();
  1239. remove_proc_entry("fs/nfs/exports", NULL);
  1240. remove_proc_entry("fs/nfs", NULL);
  1241. nfsd_stat_shutdown();
  1242. nfsd_lockd_shutdown();
  1243. nfsd_idmap_shutdown();
  1244. nfsd4_free_slabs();
  1245. unregister_filesystem(&nfsd_fs_type);
  1246. }
  1247. MODULE_AUTHOR("Olaf Kirch <okir@monad.swb.de>");
  1248. MODULE_LICENSE("GPL");
  1249. module_init(init_nfsd)
  1250. module_exit(exit_nfsd)