nfsctl.c 39 KB

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