nfsctl.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  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/fcntl.h>
  14. #include <linux/net.h>
  15. #include <linux/in.h>
  16. #include <linux/syscalls.h>
  17. #include <linux/unistd.h>
  18. #include <linux/slab.h>
  19. #include <linux/proc_fs.h>
  20. #include <linux/seq_file.h>
  21. #include <linux/pagemap.h>
  22. #include <linux/init.h>
  23. #include <linux/string.h>
  24. #include <linux/smp_lock.h>
  25. #include <linux/ctype.h>
  26. #include <linux/nfs.h>
  27. #include <linux/nfsd_idmap.h>
  28. #include <linux/lockd/bind.h>
  29. #include <linux/sunrpc/svc.h>
  30. #include <linux/sunrpc/svcsock.h>
  31. #include <linux/nfsd/nfsd.h>
  32. #include <linux/nfsd/cache.h>
  33. #include <linux/nfsd/xdr.h>
  34. #include <linux/nfsd/syscall.h>
  35. #include <linux/nfsd/interface.h>
  36. #include <asm/uaccess.h>
  37. /*
  38. * We have a single directory with 9 nodes in it.
  39. */
  40. enum {
  41. NFSD_Root = 1,
  42. NFSD_Svc,
  43. NFSD_Add,
  44. NFSD_Del,
  45. NFSD_Export,
  46. NFSD_Unexport,
  47. NFSD_Getfd,
  48. NFSD_Getfs,
  49. NFSD_List,
  50. NFSD_Fh,
  51. NFSD_Threads,
  52. NFSD_Pool_Threads,
  53. NFSD_Versions,
  54. NFSD_Ports,
  55. NFSD_MaxBlkSize,
  56. /*
  57. * The below MUST come last. Otherwise we leave a hole in nfsd_files[]
  58. * with !CONFIG_NFSD_V4 and simple_fill_super() goes oops
  59. */
  60. #ifdef CONFIG_NFSD_V4
  61. NFSD_Leasetime,
  62. NFSD_RecoveryDir,
  63. #endif
  64. };
  65. /*
  66. * write() for these nodes.
  67. */
  68. static ssize_t write_svc(struct file *file, char *buf, size_t size);
  69. static ssize_t write_add(struct file *file, char *buf, size_t size);
  70. static ssize_t write_del(struct file *file, char *buf, size_t size);
  71. static ssize_t write_export(struct file *file, char *buf, size_t size);
  72. static ssize_t write_unexport(struct file *file, char *buf, size_t size);
  73. static ssize_t write_getfd(struct file *file, char *buf, size_t size);
  74. static ssize_t write_getfs(struct file *file, char *buf, size_t size);
  75. static ssize_t write_filehandle(struct file *file, char *buf, size_t size);
  76. static ssize_t write_threads(struct file *file, char *buf, size_t size);
  77. static ssize_t write_pool_threads(struct file *file, char *buf, size_t size);
  78. static ssize_t write_versions(struct file *file, char *buf, size_t size);
  79. static ssize_t write_ports(struct file *file, char *buf, size_t size);
  80. static ssize_t write_maxblksize(struct file *file, char *buf, size_t size);
  81. #ifdef CONFIG_NFSD_V4
  82. static ssize_t write_leasetime(struct file *file, char *buf, size_t size);
  83. static ssize_t write_recoverydir(struct file *file, char *buf, size_t size);
  84. #endif
  85. static ssize_t (*write_op[])(struct file *, char *, size_t) = {
  86. [NFSD_Svc] = write_svc,
  87. [NFSD_Add] = write_add,
  88. [NFSD_Del] = write_del,
  89. [NFSD_Export] = write_export,
  90. [NFSD_Unexport] = write_unexport,
  91. [NFSD_Getfd] = write_getfd,
  92. [NFSD_Getfs] = write_getfs,
  93. [NFSD_Fh] = write_filehandle,
  94. [NFSD_Threads] = write_threads,
  95. [NFSD_Pool_Threads] = write_pool_threads,
  96. [NFSD_Versions] = write_versions,
  97. [NFSD_Ports] = write_ports,
  98. [NFSD_MaxBlkSize] = write_maxblksize,
  99. #ifdef CONFIG_NFSD_V4
  100. [NFSD_Leasetime] = write_leasetime,
  101. [NFSD_RecoveryDir] = write_recoverydir,
  102. #endif
  103. };
  104. static ssize_t nfsctl_transaction_write(struct file *file, const char __user *buf, size_t size, loff_t *pos)
  105. {
  106. ino_t ino = file->f_path.dentry->d_inode->i_ino;
  107. char *data;
  108. ssize_t rv;
  109. if (ino >= ARRAY_SIZE(write_op) || !write_op[ino])
  110. return -EINVAL;
  111. data = simple_transaction_get(file, buf, size);
  112. if (IS_ERR(data))
  113. return PTR_ERR(data);
  114. rv = write_op[ino](file, data, size);
  115. if (rv >= 0) {
  116. simple_transaction_set(file, rv);
  117. rv = size;
  118. }
  119. return rv;
  120. }
  121. static ssize_t nfsctl_transaction_read(struct file *file, char __user *buf, size_t size, loff_t *pos)
  122. {
  123. if (! file->private_data) {
  124. /* An attempt to read a transaction file without writing
  125. * causes a 0-byte write so that the file can return
  126. * state information
  127. */
  128. ssize_t rv = nfsctl_transaction_write(file, buf, 0, pos);
  129. if (rv < 0)
  130. return rv;
  131. }
  132. return simple_transaction_read(file, buf, size, pos);
  133. }
  134. static const struct file_operations transaction_ops = {
  135. .write = nfsctl_transaction_write,
  136. .read = nfsctl_transaction_read,
  137. .release = simple_transaction_release,
  138. };
  139. extern struct seq_operations nfs_exports_op;
  140. static int exports_open(struct inode *inode, struct file *file)
  141. {
  142. return seq_open(file, &nfs_exports_op);
  143. }
  144. static const struct file_operations exports_operations = {
  145. .open = exports_open,
  146. .read = seq_read,
  147. .llseek = seq_lseek,
  148. .release = seq_release,
  149. };
  150. /*----------------------------------------------------------------------------*/
  151. /*
  152. * payload - write methods
  153. * If the method has a response, the response should be put in buf,
  154. * and the length returned. Otherwise return 0 or and -error.
  155. */
  156. static ssize_t write_svc(struct file *file, char *buf, size_t size)
  157. {
  158. struct nfsctl_svc *data;
  159. if (size < sizeof(*data))
  160. return -EINVAL;
  161. data = (struct nfsctl_svc*) buf;
  162. return nfsd_svc(data->svc_port, data->svc_nthreads);
  163. }
  164. static ssize_t write_add(struct file *file, char *buf, size_t size)
  165. {
  166. struct nfsctl_client *data;
  167. if (size < sizeof(*data))
  168. return -EINVAL;
  169. data = (struct nfsctl_client *)buf;
  170. return exp_addclient(data);
  171. }
  172. static ssize_t write_del(struct file *file, char *buf, size_t size)
  173. {
  174. struct nfsctl_client *data;
  175. if (size < sizeof(*data))
  176. return -EINVAL;
  177. data = (struct nfsctl_client *)buf;
  178. return exp_delclient(data);
  179. }
  180. static ssize_t write_export(struct file *file, char *buf, size_t size)
  181. {
  182. struct nfsctl_export *data;
  183. if (size < sizeof(*data))
  184. return -EINVAL;
  185. data = (struct nfsctl_export*)buf;
  186. return exp_export(data);
  187. }
  188. static ssize_t write_unexport(struct file *file, char *buf, size_t size)
  189. {
  190. struct nfsctl_export *data;
  191. if (size < sizeof(*data))
  192. return -EINVAL;
  193. data = (struct nfsctl_export*)buf;
  194. return exp_unexport(data);
  195. }
  196. static ssize_t write_getfs(struct file *file, char *buf, size_t size)
  197. {
  198. struct nfsctl_fsparm *data;
  199. struct sockaddr_in *sin;
  200. struct auth_domain *clp;
  201. int err = 0;
  202. struct knfsd_fh *res;
  203. if (size < sizeof(*data))
  204. return -EINVAL;
  205. data = (struct nfsctl_fsparm*)buf;
  206. err = -EPROTONOSUPPORT;
  207. if (data->gd_addr.sa_family != AF_INET)
  208. goto out;
  209. sin = (struct sockaddr_in *)&data->gd_addr;
  210. if (data->gd_maxlen > NFS3_FHSIZE)
  211. data->gd_maxlen = NFS3_FHSIZE;
  212. res = (struct knfsd_fh*)buf;
  213. exp_readlock();
  214. if (!(clp = auth_unix_lookup(sin->sin_addr)))
  215. err = -EPERM;
  216. else {
  217. err = exp_rootfh(clp, data->gd_path, res, data->gd_maxlen);
  218. auth_domain_put(clp);
  219. }
  220. exp_readunlock();
  221. if (err == 0)
  222. err = res->fh_size + (int)&((struct knfsd_fh*)0)->fh_base;
  223. out:
  224. return err;
  225. }
  226. static ssize_t write_getfd(struct file *file, char *buf, size_t size)
  227. {
  228. struct nfsctl_fdparm *data;
  229. struct sockaddr_in *sin;
  230. struct auth_domain *clp;
  231. int err = 0;
  232. struct knfsd_fh fh;
  233. char *res;
  234. if (size < sizeof(*data))
  235. return -EINVAL;
  236. data = (struct nfsctl_fdparm*)buf;
  237. err = -EPROTONOSUPPORT;
  238. if (data->gd_addr.sa_family != AF_INET)
  239. goto out;
  240. err = -EINVAL;
  241. if (data->gd_version < 2 || data->gd_version > NFSSVC_MAXVERS)
  242. goto out;
  243. res = buf;
  244. sin = (struct sockaddr_in *)&data->gd_addr;
  245. exp_readlock();
  246. if (!(clp = auth_unix_lookup(sin->sin_addr)))
  247. err = -EPERM;
  248. else {
  249. err = exp_rootfh(clp, data->gd_path, &fh, NFS_FHSIZE);
  250. auth_domain_put(clp);
  251. }
  252. exp_readunlock();
  253. if (err == 0) {
  254. memset(res,0, NFS_FHSIZE);
  255. memcpy(res, &fh.fh_base, fh.fh_size);
  256. err = NFS_FHSIZE;
  257. }
  258. out:
  259. return err;
  260. }
  261. static ssize_t write_filehandle(struct file *file, char *buf, size_t size)
  262. {
  263. /* request is:
  264. * domain path maxsize
  265. * response is
  266. * filehandle
  267. *
  268. * qword quoting is used, so filehandle will be \x....
  269. */
  270. char *dname, *path;
  271. int maxsize;
  272. char *mesg = buf;
  273. int len;
  274. struct auth_domain *dom;
  275. struct knfsd_fh fh;
  276. if (buf[size-1] != '\n')
  277. return -EINVAL;
  278. buf[size-1] = 0;
  279. dname = mesg;
  280. len = qword_get(&mesg, dname, size);
  281. if (len <= 0) return -EINVAL;
  282. path = dname+len+1;
  283. len = qword_get(&mesg, path, size);
  284. if (len <= 0) return -EINVAL;
  285. len = get_int(&mesg, &maxsize);
  286. if (len)
  287. return len;
  288. if (maxsize < NFS_FHSIZE)
  289. return -EINVAL;
  290. if (maxsize > NFS3_FHSIZE)
  291. maxsize = NFS3_FHSIZE;
  292. if (qword_get(&mesg, mesg, size)>0)
  293. return -EINVAL;
  294. /* we have all the words, they are in buf.. */
  295. dom = unix_domain_find(dname);
  296. if (!dom)
  297. return -ENOMEM;
  298. len = exp_rootfh(dom, path, &fh, maxsize);
  299. auth_domain_put(dom);
  300. if (len)
  301. return len;
  302. mesg = buf; len = SIMPLE_TRANSACTION_LIMIT;
  303. qword_addhex(&mesg, &len, (char*)&fh.fh_base, fh.fh_size);
  304. mesg[-1] = '\n';
  305. return mesg - buf;
  306. }
  307. extern int nfsd_nrthreads(void);
  308. static ssize_t write_threads(struct file *file, char *buf, size_t size)
  309. {
  310. /* if size > 0, look for a number of threads and call nfsd_svc
  311. * then write out number of threads as reply
  312. */
  313. char *mesg = buf;
  314. int rv;
  315. if (size > 0) {
  316. int newthreads;
  317. rv = get_int(&mesg, &newthreads);
  318. if (rv)
  319. return rv;
  320. if (newthreads <0)
  321. return -EINVAL;
  322. rv = nfsd_svc(2049, newthreads);
  323. if (rv)
  324. return rv;
  325. }
  326. sprintf(buf, "%d\n", nfsd_nrthreads());
  327. return strlen(buf);
  328. }
  329. extern int nfsd_nrpools(void);
  330. extern int nfsd_get_nrthreads(int n, int *);
  331. extern int nfsd_set_nrthreads(int n, int *);
  332. static ssize_t write_pool_threads(struct file *file, char *buf, size_t size)
  333. {
  334. /* if size > 0, look for an array of number of threads per node
  335. * and apply them then write out number of threads per node as reply
  336. */
  337. char *mesg = buf;
  338. int i;
  339. int rv;
  340. int len;
  341. int npools = nfsd_nrpools();
  342. int *nthreads;
  343. if (npools == 0) {
  344. /*
  345. * NFS is shut down. The admin can start it by
  346. * writing to the threads file but NOT the pool_threads
  347. * file, sorry. Report zero threads.
  348. */
  349. strcpy(buf, "0\n");
  350. return strlen(buf);
  351. }
  352. nthreads = kcalloc(npools, sizeof(int), GFP_KERNEL);
  353. if (nthreads == NULL)
  354. return -ENOMEM;
  355. if (size > 0) {
  356. for (i = 0; i < npools; i++) {
  357. rv = get_int(&mesg, &nthreads[i]);
  358. if (rv == -ENOENT)
  359. break; /* fewer numbers than pools */
  360. if (rv)
  361. goto out_free; /* syntax error */
  362. rv = -EINVAL;
  363. if (nthreads[i] < 0)
  364. goto out_free;
  365. }
  366. rv = nfsd_set_nrthreads(i, nthreads);
  367. if (rv)
  368. goto out_free;
  369. }
  370. rv = nfsd_get_nrthreads(npools, nthreads);
  371. if (rv)
  372. goto out_free;
  373. mesg = buf;
  374. size = SIMPLE_TRANSACTION_LIMIT;
  375. for (i = 0; i < npools && size > 0; i++) {
  376. snprintf(mesg, size, "%d%c", nthreads[i], (i == npools-1 ? '\n' : ' '));
  377. len = strlen(mesg);
  378. size -= len;
  379. mesg += len;
  380. }
  381. return (mesg-buf);
  382. out_free:
  383. kfree(nthreads);
  384. return rv;
  385. }
  386. static ssize_t write_versions(struct file *file, char *buf, size_t size)
  387. {
  388. /*
  389. * Format:
  390. * [-/+]vers [-/+]vers ...
  391. */
  392. char *mesg = buf;
  393. char *vers, sign;
  394. int len, num;
  395. ssize_t tlen = 0;
  396. char *sep;
  397. if (size>0) {
  398. if (nfsd_serv)
  399. /* Cannot change versions without updating
  400. * nfsd_serv->sv_xdrsize, and reallocing
  401. * rq_argp and rq_resp
  402. */
  403. return -EBUSY;
  404. if (buf[size-1] != '\n')
  405. return -EINVAL;
  406. buf[size-1] = 0;
  407. vers = mesg;
  408. len = qword_get(&mesg, vers, size);
  409. if (len <= 0) return -EINVAL;
  410. do {
  411. sign = *vers;
  412. if (sign == '+' || sign == '-')
  413. num = simple_strtol((vers+1), NULL, 0);
  414. else
  415. num = simple_strtol(vers, NULL, 0);
  416. switch(num) {
  417. case 2:
  418. case 3:
  419. case 4:
  420. nfsd_vers(num, sign == '-' ? NFSD_CLEAR : NFSD_SET);
  421. break;
  422. default:
  423. return -EINVAL;
  424. }
  425. vers += len + 1;
  426. tlen += len;
  427. } while ((len = qword_get(&mesg, vers, size)) > 0);
  428. /* If all get turned off, turn them back on, as
  429. * having no versions is BAD
  430. */
  431. nfsd_reset_versions();
  432. }
  433. /* Now write current state into reply buffer */
  434. len = 0;
  435. sep = "";
  436. for (num=2 ; num <= 4 ; num++)
  437. if (nfsd_vers(num, NFSD_AVAIL)) {
  438. len += sprintf(buf+len, "%s%c%d", sep,
  439. nfsd_vers(num, NFSD_TEST)?'+':'-',
  440. num);
  441. sep = " ";
  442. }
  443. len += sprintf(buf+len, "\n");
  444. return len;
  445. }
  446. static ssize_t write_ports(struct file *file, char *buf, size_t size)
  447. {
  448. if (size == 0) {
  449. int len = 0;
  450. lock_kernel();
  451. if (nfsd_serv)
  452. len = svc_sock_names(buf, nfsd_serv, NULL);
  453. unlock_kernel();
  454. return len;
  455. }
  456. /* Either a single 'fd' number is written, in which
  457. * case it must be for a socket of a supported family/protocol,
  458. * and we use it as an nfsd socket, or
  459. * A '-' followed by the 'name' of a socket in which case
  460. * we close the socket.
  461. */
  462. if (isdigit(buf[0])) {
  463. char *mesg = buf;
  464. int fd;
  465. int err;
  466. err = get_int(&mesg, &fd);
  467. if (err)
  468. return -EINVAL;
  469. if (fd < 0)
  470. return -EINVAL;
  471. err = nfsd_create_serv();
  472. if (!err) {
  473. int proto = 0;
  474. err = svc_addsock(nfsd_serv, fd, buf, &proto);
  475. if (err >= 0) {
  476. err = lockd_up(proto);
  477. if (err < 0)
  478. svc_sock_names(buf+strlen(buf)+1, nfsd_serv, buf);
  479. }
  480. /* Decrease the count, but don't shutdown the
  481. * the service
  482. */
  483. lock_kernel();
  484. nfsd_serv->sv_nrthreads--;
  485. unlock_kernel();
  486. }
  487. return err < 0 ? err : 0;
  488. }
  489. if (buf[0] == '-') {
  490. char *toclose = kstrdup(buf+1, GFP_KERNEL);
  491. int len = 0;
  492. if (!toclose)
  493. return -ENOMEM;
  494. lock_kernel();
  495. if (nfsd_serv)
  496. len = svc_sock_names(buf, nfsd_serv, toclose);
  497. unlock_kernel();
  498. if (len >= 0)
  499. lockd_down();
  500. kfree(toclose);
  501. return len;
  502. }
  503. return -EINVAL;
  504. }
  505. int nfsd_max_blksize;
  506. static ssize_t write_maxblksize(struct file *file, char *buf, size_t size)
  507. {
  508. char *mesg = buf;
  509. if (size > 0) {
  510. int bsize;
  511. int rv = get_int(&mesg, &bsize);
  512. if (rv)
  513. return rv;
  514. /* force bsize into allowed range and
  515. * required alignment.
  516. */
  517. if (bsize < 1024)
  518. bsize = 1024;
  519. if (bsize > NFSSVC_MAXBLKSIZE)
  520. bsize = NFSSVC_MAXBLKSIZE;
  521. bsize &= ~(1024-1);
  522. lock_kernel();
  523. if (nfsd_serv && nfsd_serv->sv_nrthreads) {
  524. unlock_kernel();
  525. return -EBUSY;
  526. }
  527. nfsd_max_blksize = bsize;
  528. unlock_kernel();
  529. }
  530. return sprintf(buf, "%d\n", nfsd_max_blksize);
  531. }
  532. #ifdef CONFIG_NFSD_V4
  533. extern time_t nfs4_leasetime(void);
  534. static ssize_t write_leasetime(struct file *file, char *buf, size_t size)
  535. {
  536. /* if size > 10 seconds, call
  537. * nfs4_reset_lease() then write out the new lease (seconds) as reply
  538. */
  539. char *mesg = buf;
  540. int rv;
  541. if (size > 0) {
  542. int lease;
  543. rv = get_int(&mesg, &lease);
  544. if (rv)
  545. return rv;
  546. if (lease < 10 || lease > 3600)
  547. return -EINVAL;
  548. nfs4_reset_lease(lease);
  549. }
  550. sprintf(buf, "%ld\n", nfs4_lease_time());
  551. return strlen(buf);
  552. }
  553. static ssize_t write_recoverydir(struct file *file, char *buf, size_t size)
  554. {
  555. char *mesg = buf;
  556. char *recdir;
  557. int len, status;
  558. if (size > PATH_MAX || buf[size-1] != '\n')
  559. return -EINVAL;
  560. buf[size-1] = 0;
  561. recdir = mesg;
  562. len = qword_get(&mesg, recdir, size);
  563. if (len <= 0)
  564. return -EINVAL;
  565. status = nfs4_reset_recoverydir(recdir);
  566. return strlen(buf);
  567. }
  568. #endif
  569. /*----------------------------------------------------------------------------*/
  570. /*
  571. * populating the filesystem.
  572. */
  573. static int nfsd_fill_super(struct super_block * sb, void * data, int silent)
  574. {
  575. static struct tree_descr nfsd_files[] = {
  576. [NFSD_Svc] = {".svc", &transaction_ops, S_IWUSR},
  577. [NFSD_Add] = {".add", &transaction_ops, S_IWUSR},
  578. [NFSD_Del] = {".del", &transaction_ops, S_IWUSR},
  579. [NFSD_Export] = {".export", &transaction_ops, S_IWUSR},
  580. [NFSD_Unexport] = {".unexport", &transaction_ops, S_IWUSR},
  581. [NFSD_Getfd] = {".getfd", &transaction_ops, S_IWUSR|S_IRUSR},
  582. [NFSD_Getfs] = {".getfs", &transaction_ops, S_IWUSR|S_IRUSR},
  583. [NFSD_List] = {"exports", &exports_operations, S_IRUGO},
  584. [NFSD_Fh] = {"filehandle", &transaction_ops, S_IWUSR|S_IRUSR},
  585. [NFSD_Threads] = {"threads", &transaction_ops, S_IWUSR|S_IRUSR},
  586. [NFSD_Pool_Threads] = {"pool_threads", &transaction_ops, S_IWUSR|S_IRUSR},
  587. [NFSD_Versions] = {"versions", &transaction_ops, S_IWUSR|S_IRUSR},
  588. [NFSD_Ports] = {"portlist", &transaction_ops, S_IWUSR|S_IRUGO},
  589. [NFSD_MaxBlkSize] = {"max_block_size", &transaction_ops, S_IWUSR|S_IRUGO},
  590. #ifdef CONFIG_NFSD_V4
  591. [NFSD_Leasetime] = {"nfsv4leasetime", &transaction_ops, S_IWUSR|S_IRUSR},
  592. [NFSD_RecoveryDir] = {"nfsv4recoverydir", &transaction_ops, S_IWUSR|S_IRUSR},
  593. #endif
  594. /* last one */ {""}
  595. };
  596. return simple_fill_super(sb, 0x6e667364, nfsd_files);
  597. }
  598. static int nfsd_get_sb(struct file_system_type *fs_type,
  599. int flags, const char *dev_name, void *data, struct vfsmount *mnt)
  600. {
  601. return get_sb_single(fs_type, flags, data, nfsd_fill_super, mnt);
  602. }
  603. static struct file_system_type nfsd_fs_type = {
  604. .owner = THIS_MODULE,
  605. .name = "nfsd",
  606. .get_sb = nfsd_get_sb,
  607. .kill_sb = kill_litter_super,
  608. };
  609. static int __init init_nfsd(void)
  610. {
  611. int retval;
  612. printk(KERN_INFO "Installing knfsd (copyright (C) 1996 okir@monad.swb.de).\n");
  613. nfsd_stat_init(); /* Statistics */
  614. nfsd_cache_init(); /* RPC reply cache */
  615. nfsd_export_init(); /* Exports table */
  616. nfsd_lockd_init(); /* lockd->nfsd callbacks */
  617. nfs4_state_init(); /* NFSv4 locking state */
  618. nfsd_idmap_init(); /* Name to ID mapping */
  619. if (proc_mkdir("fs/nfs", NULL)) {
  620. struct proc_dir_entry *entry;
  621. entry = create_proc_entry("fs/nfs/exports", 0, NULL);
  622. if (entry)
  623. entry->proc_fops = &exports_operations;
  624. }
  625. retval = register_filesystem(&nfsd_fs_type);
  626. if (retval) {
  627. nfsd_export_shutdown();
  628. nfsd_cache_shutdown();
  629. remove_proc_entry("fs/nfs/exports", NULL);
  630. remove_proc_entry("fs/nfs", NULL);
  631. nfsd_stat_shutdown();
  632. nfsd_lockd_shutdown();
  633. }
  634. return retval;
  635. }
  636. static void __exit exit_nfsd(void)
  637. {
  638. nfsd_export_shutdown();
  639. nfsd_cache_shutdown();
  640. remove_proc_entry("fs/nfs/exports", NULL);
  641. remove_proc_entry("fs/nfs", NULL);
  642. nfsd_stat_shutdown();
  643. nfsd_lockd_shutdown();
  644. nfsd_idmap_shutdown();
  645. unregister_filesystem(&nfsd_fs_type);
  646. }
  647. MODULE_AUTHOR("Olaf Kirch <okir@monad.swb.de>");
  648. MODULE_LICENSE("GPL");
  649. module_init(init_nfsd)
  650. module_exit(exit_nfsd)