nfsctl.c 38 KB

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