nfsctl.c 20 KB

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