nfsctl.c 36 KB

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