nfsctl.c 37 KB

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