nfsctl.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  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 <asm/uaccess.h>
  36. #include <net/ipv6.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. static int exports_open(struct inode *inode, struct file *file)
  140. {
  141. return seq_open(file, &nfs_exports_op);
  142. }
  143. static const struct file_operations exports_operations = {
  144. .open = exports_open,
  145. .read = seq_read,
  146. .llseek = seq_lseek,
  147. .release = seq_release,
  148. };
  149. /*----------------------------------------------------------------------------*/
  150. /*
  151. * payload - write methods
  152. * If the method has a response, the response should be put in buf,
  153. * and the length returned. Otherwise return 0 or and -error.
  154. */
  155. static ssize_t write_svc(struct file *file, char *buf, size_t size)
  156. {
  157. struct nfsctl_svc *data;
  158. if (size < sizeof(*data))
  159. return -EINVAL;
  160. data = (struct nfsctl_svc*) buf;
  161. return nfsd_svc(data->svc_port, data->svc_nthreads);
  162. }
  163. static ssize_t write_add(struct file *file, char *buf, size_t size)
  164. {
  165. struct nfsctl_client *data;
  166. if (size < sizeof(*data))
  167. return -EINVAL;
  168. data = (struct nfsctl_client *)buf;
  169. return exp_addclient(data);
  170. }
  171. static ssize_t write_del(struct file *file, char *buf, size_t size)
  172. {
  173. struct nfsctl_client *data;
  174. if (size < sizeof(*data))
  175. return -EINVAL;
  176. data = (struct nfsctl_client *)buf;
  177. return exp_delclient(data);
  178. }
  179. static ssize_t write_export(struct file *file, char *buf, size_t size)
  180. {
  181. struct nfsctl_export *data;
  182. if (size < sizeof(*data))
  183. return -EINVAL;
  184. data = (struct nfsctl_export*)buf;
  185. return exp_export(data);
  186. }
  187. static ssize_t write_unexport(struct file *file, char *buf, size_t size)
  188. {
  189. struct nfsctl_export *data;
  190. if (size < sizeof(*data))
  191. return -EINVAL;
  192. data = (struct nfsctl_export*)buf;
  193. return exp_unexport(data);
  194. }
  195. static ssize_t write_getfs(struct file *file, char *buf, size_t size)
  196. {
  197. struct nfsctl_fsparm *data;
  198. struct sockaddr_in *sin;
  199. struct auth_domain *clp;
  200. int err = 0;
  201. struct knfsd_fh *res;
  202. struct in6_addr in6;
  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. ipv6_addr_set_v4mapped(sin->sin_addr.s_addr, &in6);
  215. clp = auth_unix_lookup(&in6);
  216. if (!clp)
  217. err = -EPERM;
  218. else {
  219. err = exp_rootfh(clp, data->gd_path, res, data->gd_maxlen);
  220. auth_domain_put(clp);
  221. }
  222. exp_readunlock();
  223. if (err == 0)
  224. err = res->fh_size + offsetof(struct knfsd_fh, fh_base);
  225. out:
  226. return err;
  227. }
  228. static ssize_t write_getfd(struct file *file, char *buf, size_t size)
  229. {
  230. struct nfsctl_fdparm *data;
  231. struct sockaddr_in *sin;
  232. struct auth_domain *clp;
  233. int err = 0;
  234. struct knfsd_fh fh;
  235. char *res;
  236. struct in6_addr in6;
  237. if (size < sizeof(*data))
  238. return -EINVAL;
  239. data = (struct nfsctl_fdparm*)buf;
  240. err = -EPROTONOSUPPORT;
  241. if (data->gd_addr.sa_family != AF_INET)
  242. goto out;
  243. err = -EINVAL;
  244. if (data->gd_version < 2 || data->gd_version > NFSSVC_MAXVERS)
  245. goto out;
  246. res = buf;
  247. sin = (struct sockaddr_in *)&data->gd_addr;
  248. exp_readlock();
  249. ipv6_addr_set_v4mapped(sin->sin_addr.s_addr, &in6);
  250. clp = auth_unix_lookup(&in6);
  251. if (!clp)
  252. err = -EPERM;
  253. else {
  254. err = exp_rootfh(clp, data->gd_path, &fh, NFS_FHSIZE);
  255. auth_domain_put(clp);
  256. }
  257. exp_readunlock();
  258. if (err == 0) {
  259. memset(res,0, NFS_FHSIZE);
  260. memcpy(res, &fh.fh_base, fh.fh_size);
  261. err = NFS_FHSIZE;
  262. }
  263. out:
  264. return err;
  265. }
  266. static ssize_t write_filehandle(struct file *file, char *buf, size_t size)
  267. {
  268. /* request is:
  269. * domain path maxsize
  270. * response is
  271. * filehandle
  272. *
  273. * qword quoting is used, so filehandle will be \x....
  274. */
  275. char *dname, *path;
  276. int uninitialized_var(maxsize);
  277. char *mesg = buf;
  278. int len;
  279. struct auth_domain *dom;
  280. struct knfsd_fh fh;
  281. if (size == 0)
  282. return -EINVAL;
  283. if (buf[size-1] != '\n')
  284. return -EINVAL;
  285. buf[size-1] = 0;
  286. dname = mesg;
  287. len = qword_get(&mesg, dname, size);
  288. if (len <= 0) return -EINVAL;
  289. path = dname+len+1;
  290. len = qword_get(&mesg, path, size);
  291. if (len <= 0) return -EINVAL;
  292. len = get_int(&mesg, &maxsize);
  293. if (len)
  294. return len;
  295. if (maxsize < NFS_FHSIZE)
  296. return -EINVAL;
  297. if (maxsize > NFS3_FHSIZE)
  298. maxsize = NFS3_FHSIZE;
  299. if (qword_get(&mesg, mesg, size)>0)
  300. return -EINVAL;
  301. /* we have all the words, they are in buf.. */
  302. dom = unix_domain_find(dname);
  303. if (!dom)
  304. return -ENOMEM;
  305. len = exp_rootfh(dom, path, &fh, maxsize);
  306. auth_domain_put(dom);
  307. if (len)
  308. return len;
  309. mesg = buf; len = SIMPLE_TRANSACTION_LIMIT;
  310. qword_addhex(&mesg, &len, (char*)&fh.fh_base, fh.fh_size);
  311. mesg[-1] = '\n';
  312. return mesg - buf;
  313. }
  314. static ssize_t write_threads(struct file *file, char *buf, size_t size)
  315. {
  316. /* if size > 0, look for a number of threads and call nfsd_svc
  317. * then write out number of threads as reply
  318. */
  319. char *mesg = buf;
  320. int rv;
  321. if (size > 0) {
  322. int newthreads;
  323. rv = get_int(&mesg, &newthreads);
  324. if (rv)
  325. return rv;
  326. if (newthreads <0)
  327. return -EINVAL;
  328. rv = nfsd_svc(2049, newthreads);
  329. if (rv)
  330. return rv;
  331. }
  332. sprintf(buf, "%d\n", nfsd_nrthreads());
  333. return strlen(buf);
  334. }
  335. static ssize_t write_pool_threads(struct file *file, char *buf, size_t size)
  336. {
  337. /* if size > 0, look for an array of number of threads per node
  338. * and apply them then write out number of threads per node as reply
  339. */
  340. char *mesg = buf;
  341. int i;
  342. int rv;
  343. int len;
  344. int npools = nfsd_nrpools();
  345. int *nthreads;
  346. if (npools == 0) {
  347. /*
  348. * NFS is shut down. The admin can start it by
  349. * writing to the threads file but NOT the pool_threads
  350. * file, sorry. Report zero threads.
  351. */
  352. strcpy(buf, "0\n");
  353. return strlen(buf);
  354. }
  355. nthreads = kcalloc(npools, sizeof(int), GFP_KERNEL);
  356. if (nthreads == NULL)
  357. return -ENOMEM;
  358. if (size > 0) {
  359. for (i = 0; i < npools; i++) {
  360. rv = get_int(&mesg, &nthreads[i]);
  361. if (rv == -ENOENT)
  362. break; /* fewer numbers than pools */
  363. if (rv)
  364. goto out_free; /* syntax error */
  365. rv = -EINVAL;
  366. if (nthreads[i] < 0)
  367. goto out_free;
  368. }
  369. rv = nfsd_set_nrthreads(i, nthreads);
  370. if (rv)
  371. goto out_free;
  372. }
  373. rv = nfsd_get_nrthreads(npools, nthreads);
  374. if (rv)
  375. goto out_free;
  376. mesg = buf;
  377. size = SIMPLE_TRANSACTION_LIMIT;
  378. for (i = 0; i < npools && size > 0; i++) {
  379. snprintf(mesg, size, "%d%c", nthreads[i], (i == npools-1 ? '\n' : ' '));
  380. len = strlen(mesg);
  381. size -= len;
  382. mesg += len;
  383. }
  384. return (mesg-buf);
  385. out_free:
  386. kfree(nthreads);
  387. return rv;
  388. }
  389. static ssize_t write_versions(struct file *file, char *buf, size_t size)
  390. {
  391. /*
  392. * Format:
  393. * [-/+]vers [-/+]vers ...
  394. */
  395. char *mesg = buf;
  396. char *vers, sign;
  397. int len, num;
  398. ssize_t tlen = 0;
  399. char *sep;
  400. if (size>0) {
  401. if (nfsd_serv)
  402. /* Cannot change versions without updating
  403. * nfsd_serv->sv_xdrsize, and reallocing
  404. * rq_argp and rq_resp
  405. */
  406. return -EBUSY;
  407. if (buf[size-1] != '\n')
  408. return -EINVAL;
  409. buf[size-1] = 0;
  410. vers = mesg;
  411. len = qword_get(&mesg, vers, size);
  412. if (len <= 0) return -EINVAL;
  413. do {
  414. sign = *vers;
  415. if (sign == '+' || sign == '-')
  416. num = simple_strtol((vers+1), NULL, 0);
  417. else
  418. num = simple_strtol(vers, NULL, 0);
  419. switch(num) {
  420. case 2:
  421. case 3:
  422. case 4:
  423. nfsd_vers(num, sign == '-' ? NFSD_CLEAR : NFSD_SET);
  424. break;
  425. default:
  426. return -EINVAL;
  427. }
  428. vers += len + 1;
  429. tlen += len;
  430. } while ((len = qword_get(&mesg, vers, size)) > 0);
  431. /* If all get turned off, turn them back on, as
  432. * having no versions is BAD
  433. */
  434. nfsd_reset_versions();
  435. }
  436. /* Now write current state into reply buffer */
  437. len = 0;
  438. sep = "";
  439. for (num=2 ; num <= 4 ; num++)
  440. if (nfsd_vers(num, NFSD_AVAIL)) {
  441. len += sprintf(buf+len, "%s%c%d", sep,
  442. nfsd_vers(num, NFSD_TEST)?'+':'-',
  443. num);
  444. sep = " ";
  445. }
  446. len += sprintf(buf+len, "\n");
  447. return len;
  448. }
  449. static ssize_t write_ports(struct file *file, char *buf, size_t size)
  450. {
  451. if (size == 0) {
  452. int len = 0;
  453. lock_kernel();
  454. if (nfsd_serv)
  455. len = svc_xprt_names(nfsd_serv, buf, 0);
  456. unlock_kernel();
  457. return len;
  458. }
  459. /* Either a single 'fd' number is written, in which
  460. * case it must be for a socket of a supported family/protocol,
  461. * and we use it as an nfsd socket, or
  462. * A '-' followed by the 'name' of a socket in which case
  463. * we close the socket.
  464. */
  465. if (isdigit(buf[0])) {
  466. char *mesg = buf;
  467. int fd;
  468. int err;
  469. err = get_int(&mesg, &fd);
  470. if (err)
  471. return -EINVAL;
  472. if (fd < 0)
  473. return -EINVAL;
  474. err = nfsd_create_serv();
  475. if (!err) {
  476. int proto = 0;
  477. err = svc_addsock(nfsd_serv, fd, buf, &proto);
  478. if (err >= 0) {
  479. err = lockd_up(proto);
  480. if (err < 0)
  481. svc_sock_names(buf+strlen(buf)+1, nfsd_serv, buf);
  482. }
  483. /* Decrease the count, but don't shutdown the
  484. * the service
  485. */
  486. lock_kernel();
  487. nfsd_serv->sv_nrthreads--;
  488. unlock_kernel();
  489. }
  490. return err < 0 ? err : 0;
  491. }
  492. if (buf[0] == '-' && isdigit(buf[1])) {
  493. char *toclose = kstrdup(buf+1, GFP_KERNEL);
  494. int len = 0;
  495. if (!toclose)
  496. return -ENOMEM;
  497. lock_kernel();
  498. if (nfsd_serv)
  499. len = svc_sock_names(buf, nfsd_serv, toclose);
  500. unlock_kernel();
  501. if (len >= 0)
  502. lockd_down();
  503. kfree(toclose);
  504. return len;
  505. }
  506. /*
  507. * Add a transport listener by writing it's transport name
  508. */
  509. if (isalpha(buf[0])) {
  510. int err;
  511. char transport[16];
  512. int port;
  513. if (sscanf(buf, "%15s %4d", transport, &port) == 2) {
  514. err = nfsd_create_serv();
  515. if (!err) {
  516. err = svc_create_xprt(nfsd_serv,
  517. transport, port,
  518. SVC_SOCK_ANONYMOUS);
  519. if (err == -ENOENT)
  520. /* Give a reasonable perror msg for
  521. * bad transport string */
  522. err = -EPROTONOSUPPORT;
  523. }
  524. return err < 0 ? err : 0;
  525. }
  526. }
  527. /*
  528. * Remove a transport by writing it's transport name and port number
  529. */
  530. if (buf[0] == '-' && isalpha(buf[1])) {
  531. struct svc_xprt *xprt;
  532. int err = -EINVAL;
  533. char transport[16];
  534. int port;
  535. if (sscanf(&buf[1], "%15s %4d", transport, &port) == 2) {
  536. if (port == 0)
  537. return -EINVAL;
  538. lock_kernel();
  539. if (nfsd_serv) {
  540. xprt = svc_find_xprt(nfsd_serv, transport,
  541. AF_UNSPEC, port);
  542. if (xprt) {
  543. svc_close_xprt(xprt);
  544. svc_xprt_put(xprt);
  545. err = 0;
  546. } else
  547. err = -ENOTCONN;
  548. }
  549. unlock_kernel();
  550. return err < 0 ? err : 0;
  551. }
  552. }
  553. return -EINVAL;
  554. }
  555. int nfsd_max_blksize;
  556. static ssize_t write_maxblksize(struct file *file, char *buf, size_t size)
  557. {
  558. char *mesg = buf;
  559. if (size > 0) {
  560. int bsize;
  561. int rv = get_int(&mesg, &bsize);
  562. if (rv)
  563. return rv;
  564. /* force bsize into allowed range and
  565. * required alignment.
  566. */
  567. if (bsize < 1024)
  568. bsize = 1024;
  569. if (bsize > NFSSVC_MAXBLKSIZE)
  570. bsize = NFSSVC_MAXBLKSIZE;
  571. bsize &= ~(1024-1);
  572. lock_kernel();
  573. if (nfsd_serv && nfsd_serv->sv_nrthreads) {
  574. unlock_kernel();
  575. return -EBUSY;
  576. }
  577. nfsd_max_blksize = bsize;
  578. unlock_kernel();
  579. }
  580. return sprintf(buf, "%d\n", nfsd_max_blksize);
  581. }
  582. #ifdef CONFIG_NFSD_V4
  583. extern time_t nfs4_leasetime(void);
  584. static ssize_t write_leasetime(struct file *file, char *buf, size_t size)
  585. {
  586. /* if size > 10 seconds, call
  587. * nfs4_reset_lease() then write out the new lease (seconds) as reply
  588. */
  589. char *mesg = buf;
  590. int rv;
  591. if (size > 0) {
  592. int lease;
  593. rv = get_int(&mesg, &lease);
  594. if (rv)
  595. return rv;
  596. if (lease < 10 || lease > 3600)
  597. return -EINVAL;
  598. nfs4_reset_lease(lease);
  599. }
  600. sprintf(buf, "%ld\n", nfs4_lease_time());
  601. return strlen(buf);
  602. }
  603. static ssize_t write_recoverydir(struct file *file, char *buf, size_t size)
  604. {
  605. char *mesg = buf;
  606. char *recdir;
  607. int len, status;
  608. if (size == 0 || size > PATH_MAX || buf[size-1] != '\n')
  609. return -EINVAL;
  610. buf[size-1] = 0;
  611. recdir = mesg;
  612. len = qword_get(&mesg, recdir, size);
  613. if (len <= 0)
  614. return -EINVAL;
  615. status = nfs4_reset_recoverydir(recdir);
  616. return strlen(buf);
  617. }
  618. #endif
  619. /*----------------------------------------------------------------------------*/
  620. /*
  621. * populating the filesystem.
  622. */
  623. static int nfsd_fill_super(struct super_block * sb, void * data, int silent)
  624. {
  625. static struct tree_descr nfsd_files[] = {
  626. [NFSD_Svc] = {".svc", &transaction_ops, S_IWUSR},
  627. [NFSD_Add] = {".add", &transaction_ops, S_IWUSR},
  628. [NFSD_Del] = {".del", &transaction_ops, S_IWUSR},
  629. [NFSD_Export] = {".export", &transaction_ops, S_IWUSR},
  630. [NFSD_Unexport] = {".unexport", &transaction_ops, S_IWUSR},
  631. [NFSD_Getfd] = {".getfd", &transaction_ops, S_IWUSR|S_IRUSR},
  632. [NFSD_Getfs] = {".getfs", &transaction_ops, S_IWUSR|S_IRUSR},
  633. [NFSD_List] = {"exports", &exports_operations, S_IRUGO},
  634. [NFSD_Fh] = {"filehandle", &transaction_ops, S_IWUSR|S_IRUSR},
  635. [NFSD_Threads] = {"threads", &transaction_ops, S_IWUSR|S_IRUSR},
  636. [NFSD_Pool_Threads] = {"pool_threads", &transaction_ops, S_IWUSR|S_IRUSR},
  637. [NFSD_Versions] = {"versions", &transaction_ops, S_IWUSR|S_IRUSR},
  638. [NFSD_Ports] = {"portlist", &transaction_ops, S_IWUSR|S_IRUGO},
  639. [NFSD_MaxBlkSize] = {"max_block_size", &transaction_ops, S_IWUSR|S_IRUGO},
  640. #ifdef CONFIG_NFSD_V4
  641. [NFSD_Leasetime] = {"nfsv4leasetime", &transaction_ops, S_IWUSR|S_IRUSR},
  642. [NFSD_RecoveryDir] = {"nfsv4recoverydir", &transaction_ops, S_IWUSR|S_IRUSR},
  643. #endif
  644. /* last one */ {""}
  645. };
  646. return simple_fill_super(sb, 0x6e667364, nfsd_files);
  647. }
  648. static int nfsd_get_sb(struct file_system_type *fs_type,
  649. int flags, const char *dev_name, void *data, struct vfsmount *mnt)
  650. {
  651. return get_sb_single(fs_type, flags, data, nfsd_fill_super, mnt);
  652. }
  653. static struct file_system_type nfsd_fs_type = {
  654. .owner = THIS_MODULE,
  655. .name = "nfsd",
  656. .get_sb = nfsd_get_sb,
  657. .kill_sb = kill_litter_super,
  658. };
  659. #ifdef CONFIG_PROC_FS
  660. static int create_proc_exports_entry(void)
  661. {
  662. struct proc_dir_entry *entry;
  663. entry = proc_mkdir("fs/nfs", NULL);
  664. if (!entry)
  665. return -ENOMEM;
  666. entry = create_proc_entry("fs/nfs/exports", 0, NULL);
  667. if (!entry)
  668. return -ENOMEM;
  669. entry->proc_fops = &exports_operations;
  670. return 0;
  671. }
  672. #else /* CONFIG_PROC_FS */
  673. static int create_proc_exports_entry(void)
  674. {
  675. return 0;
  676. }
  677. #endif
  678. static int __init init_nfsd(void)
  679. {
  680. int retval;
  681. printk(KERN_INFO "Installing knfsd (copyright (C) 1996 okir@monad.swb.de).\n");
  682. retval = nfs4_state_init(); /* nfs4 locking state */
  683. if (retval)
  684. return retval;
  685. nfsd_stat_init(); /* Statistics */
  686. retval = nfsd_reply_cache_init();
  687. if (retval)
  688. goto out_free_stat;
  689. retval = nfsd_export_init();
  690. if (retval)
  691. goto out_free_cache;
  692. nfsd_lockd_init(); /* lockd->nfsd callbacks */
  693. retval = nfsd_idmap_init();
  694. if (retval)
  695. goto out_free_lockd;
  696. retval = create_proc_exports_entry();
  697. if (retval)
  698. goto out_free_idmap;
  699. retval = register_filesystem(&nfsd_fs_type);
  700. if (retval)
  701. goto out_free_all;
  702. return 0;
  703. out_free_all:
  704. remove_proc_entry("fs/nfs/exports", NULL);
  705. remove_proc_entry("fs/nfs", NULL);
  706. out_free_idmap:
  707. nfsd_idmap_shutdown();
  708. out_free_lockd:
  709. nfsd_lockd_shutdown();
  710. nfsd_export_shutdown();
  711. out_free_cache:
  712. nfsd_reply_cache_shutdown();
  713. out_free_stat:
  714. nfsd_stat_shutdown();
  715. nfsd4_free_slabs();
  716. return retval;
  717. }
  718. static void __exit exit_nfsd(void)
  719. {
  720. nfsd_export_shutdown();
  721. nfsd_reply_cache_shutdown();
  722. remove_proc_entry("fs/nfs/exports", NULL);
  723. remove_proc_entry("fs/nfs", NULL);
  724. nfsd_stat_shutdown();
  725. nfsd_lockd_shutdown();
  726. nfsd_idmap_shutdown();
  727. nfsd4_free_slabs();
  728. unregister_filesystem(&nfsd_fs_type);
  729. }
  730. MODULE_AUTHOR("Olaf Kirch <okir@monad.swb.de>");
  731. MODULE_LICENSE("GPL");
  732. module_init(init_nfsd)
  733. module_exit(exit_nfsd)