nfsctl.c 38 KB

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