nfsctl.c 36 KB

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