nfsctl.c 37 KB

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