nfsctl.c 36 KB

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