nfsctl.c 36 KB

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