nfsctl.c 36 KB

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