nfsctl.c 36 KB

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