nfsctl.c 39 KB

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