nfsctl.c 37 KB

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