client.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309
  1. /* client.c: NFS client sharing and management code
  2. *
  3. * Copyright (C) 2006 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/init.h>
  13. #include <linux/sched.h>
  14. #include <linux/time.h>
  15. #include <linux/kernel.h>
  16. #include <linux/mm.h>
  17. #include <linux/string.h>
  18. #include <linux/stat.h>
  19. #include <linux/errno.h>
  20. #include <linux/unistd.h>
  21. #include <linux/sunrpc/addr.h>
  22. #include <linux/sunrpc/clnt.h>
  23. #include <linux/sunrpc/stats.h>
  24. #include <linux/sunrpc/metrics.h>
  25. #include <linux/sunrpc/xprtsock.h>
  26. #include <linux/sunrpc/xprtrdma.h>
  27. #include <linux/nfs_fs.h>
  28. #include <linux/nfs_mount.h>
  29. #include <linux/nfs4_mount.h>
  30. #include <linux/lockd/bind.h>
  31. #include <linux/seq_file.h>
  32. #include <linux/mount.h>
  33. #include <linux/vfs.h>
  34. #include <linux/inet.h>
  35. #include <linux/in6.h>
  36. #include <linux/slab.h>
  37. #include <linux/idr.h>
  38. #include <net/ipv6.h>
  39. #include <linux/nfs_xdr.h>
  40. #include <linux/sunrpc/bc_xprt.h>
  41. #include <linux/nsproxy.h>
  42. #include <linux/pid_namespace.h>
  43. #include "nfs4_fs.h"
  44. #include "callback.h"
  45. #include "delegation.h"
  46. #include "iostat.h"
  47. #include "internal.h"
  48. #include "fscache.h"
  49. #include "pnfs.h"
  50. #include "nfs.h"
  51. #include "netns.h"
  52. #define NFSDBG_FACILITY NFSDBG_CLIENT
  53. static DECLARE_WAIT_QUEUE_HEAD(nfs_client_active_wq);
  54. static DEFINE_SPINLOCK(nfs_version_lock);
  55. static DEFINE_MUTEX(nfs_version_mutex);
  56. static LIST_HEAD(nfs_versions);
  57. /*
  58. * RPC cruft for NFS
  59. */
  60. static const struct rpc_version *nfs_version[5] = {
  61. [2] = NULL,
  62. [3] = NULL,
  63. [4] = NULL,
  64. };
  65. const struct rpc_program nfs_program = {
  66. .name = "nfs",
  67. .number = NFS_PROGRAM,
  68. .nrvers = ARRAY_SIZE(nfs_version),
  69. .version = nfs_version,
  70. .stats = &nfs_rpcstat,
  71. .pipe_dir_name = NFS_PIPE_DIRNAME,
  72. };
  73. struct rpc_stat nfs_rpcstat = {
  74. .program = &nfs_program
  75. };
  76. static struct nfs_subversion *find_nfs_version(unsigned int version)
  77. {
  78. struct nfs_subversion *nfs;
  79. spin_lock(&nfs_version_lock);
  80. list_for_each_entry(nfs, &nfs_versions, list) {
  81. if (nfs->rpc_ops->version == version) {
  82. spin_unlock(&nfs_version_lock);
  83. return nfs;
  84. }
  85. }
  86. spin_unlock(&nfs_version_lock);
  87. return ERR_PTR(-EPROTONOSUPPORT);
  88. }
  89. struct nfs_subversion *get_nfs_version(unsigned int version)
  90. {
  91. struct nfs_subversion *nfs = find_nfs_version(version);
  92. if (IS_ERR(nfs)) {
  93. mutex_lock(&nfs_version_mutex);
  94. request_module("nfsv%d", version);
  95. nfs = find_nfs_version(version);
  96. mutex_unlock(&nfs_version_mutex);
  97. }
  98. if (!IS_ERR(nfs) && !try_module_get(nfs->owner))
  99. return ERR_PTR(-EAGAIN);
  100. return nfs;
  101. }
  102. void put_nfs_version(struct nfs_subversion *nfs)
  103. {
  104. module_put(nfs->owner);
  105. }
  106. void register_nfs_version(struct nfs_subversion *nfs)
  107. {
  108. spin_lock(&nfs_version_lock);
  109. list_add(&nfs->list, &nfs_versions);
  110. nfs_version[nfs->rpc_ops->version] = nfs->rpc_vers;
  111. spin_unlock(&nfs_version_lock);
  112. }
  113. EXPORT_SYMBOL_GPL(register_nfs_version);
  114. void unregister_nfs_version(struct nfs_subversion *nfs)
  115. {
  116. spin_lock(&nfs_version_lock);
  117. nfs_version[nfs->rpc_ops->version] = NULL;
  118. list_del(&nfs->list);
  119. spin_unlock(&nfs_version_lock);
  120. }
  121. EXPORT_SYMBOL_GPL(unregister_nfs_version);
  122. /*
  123. * Allocate a shared client record
  124. *
  125. * Since these are allocated/deallocated very rarely, we don't
  126. * bother putting them in a slab cache...
  127. */
  128. struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_init)
  129. {
  130. struct nfs_client *clp;
  131. struct rpc_cred *cred;
  132. int err = -ENOMEM;
  133. if ((clp = kzalloc(sizeof(*clp), GFP_KERNEL)) == NULL)
  134. goto error_0;
  135. clp->cl_minorversion = cl_init->minorversion;
  136. clp->cl_nfs_mod = cl_init->nfs_mod;
  137. if (!try_module_get(clp->cl_nfs_mod->owner))
  138. goto error_dealloc;
  139. clp->rpc_ops = clp->cl_nfs_mod->rpc_ops;
  140. refcount_set(&clp->cl_count, 1);
  141. clp->cl_cons_state = NFS_CS_INITING;
  142. memcpy(&clp->cl_addr, cl_init->addr, cl_init->addrlen);
  143. clp->cl_addrlen = cl_init->addrlen;
  144. if (cl_init->hostname) {
  145. err = -ENOMEM;
  146. clp->cl_hostname = kstrdup(cl_init->hostname, GFP_KERNEL);
  147. if (!clp->cl_hostname)
  148. goto error_cleanup;
  149. }
  150. INIT_LIST_HEAD(&clp->cl_superblocks);
  151. clp->cl_rpcclient = ERR_PTR(-EINVAL);
  152. clp->cl_proto = cl_init->proto;
  153. clp->cl_net = get_net(cl_init->net);
  154. cred = rpc_lookup_machine_cred("*");
  155. if (!IS_ERR(cred))
  156. clp->cl_machine_cred = cred;
  157. nfs_fscache_get_client_cookie(clp);
  158. return clp;
  159. error_cleanup:
  160. put_nfs_version(clp->cl_nfs_mod);
  161. error_dealloc:
  162. kfree(clp);
  163. error_0:
  164. return ERR_PTR(err);
  165. }
  166. EXPORT_SYMBOL_GPL(nfs_alloc_client);
  167. #if IS_ENABLED(CONFIG_NFS_V4)
  168. void nfs_cleanup_cb_ident_idr(struct net *net)
  169. {
  170. struct nfs_net *nn = net_generic(net, nfs_net_id);
  171. idr_destroy(&nn->cb_ident_idr);
  172. }
  173. /* nfs_client_lock held */
  174. static void nfs_cb_idr_remove_locked(struct nfs_client *clp)
  175. {
  176. struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
  177. if (clp->cl_cb_ident)
  178. idr_remove(&nn->cb_ident_idr, clp->cl_cb_ident);
  179. }
  180. static void pnfs_init_server(struct nfs_server *server)
  181. {
  182. rpc_init_wait_queue(&server->roc_rpcwaitq, "pNFS ROC");
  183. }
  184. #else
  185. void nfs_cleanup_cb_ident_idr(struct net *net)
  186. {
  187. }
  188. static void nfs_cb_idr_remove_locked(struct nfs_client *clp)
  189. {
  190. }
  191. static void pnfs_init_server(struct nfs_server *server)
  192. {
  193. }
  194. #endif /* CONFIG_NFS_V4 */
  195. /*
  196. * Destroy a shared client record
  197. */
  198. void nfs_free_client(struct nfs_client *clp)
  199. {
  200. nfs_fscache_release_client_cookie(clp);
  201. /* -EIO all pending I/O */
  202. if (!IS_ERR(clp->cl_rpcclient))
  203. rpc_shutdown_client(clp->cl_rpcclient);
  204. if (clp->cl_machine_cred != NULL)
  205. put_rpccred(clp->cl_machine_cred);
  206. put_net(clp->cl_net);
  207. put_nfs_version(clp->cl_nfs_mod);
  208. kfree(clp->cl_hostname);
  209. kfree(clp->cl_acceptor);
  210. kfree(clp);
  211. }
  212. EXPORT_SYMBOL_GPL(nfs_free_client);
  213. /*
  214. * Release a reference to a shared client record
  215. */
  216. void nfs_put_client(struct nfs_client *clp)
  217. {
  218. struct nfs_net *nn;
  219. if (!clp)
  220. return;
  221. nn = net_generic(clp->cl_net, nfs_net_id);
  222. if (refcount_dec_and_lock(&clp->cl_count, &nn->nfs_client_lock)) {
  223. list_del(&clp->cl_share_link);
  224. nfs_cb_idr_remove_locked(clp);
  225. spin_unlock(&nn->nfs_client_lock);
  226. WARN_ON_ONCE(!list_empty(&clp->cl_superblocks));
  227. clp->rpc_ops->free_client(clp);
  228. }
  229. }
  230. EXPORT_SYMBOL_GPL(nfs_put_client);
  231. /*
  232. * Find an nfs_client on the list that matches the initialisation data
  233. * that is supplied.
  234. */
  235. static struct nfs_client *nfs_match_client(const struct nfs_client_initdata *data)
  236. {
  237. struct nfs_client *clp;
  238. const struct sockaddr *sap = data->addr;
  239. struct nfs_net *nn = net_generic(data->net, nfs_net_id);
  240. int error;
  241. again:
  242. list_for_each_entry(clp, &nn->nfs_client_list, cl_share_link) {
  243. const struct sockaddr *clap = (struct sockaddr *)&clp->cl_addr;
  244. /* Don't match clients that failed to initialise properly */
  245. if (clp->cl_cons_state < 0)
  246. continue;
  247. /* If a client is still initializing then we need to wait */
  248. if (clp->cl_cons_state > NFS_CS_READY) {
  249. refcount_inc(&clp->cl_count);
  250. spin_unlock(&nn->nfs_client_lock);
  251. error = nfs_wait_client_init_complete(clp);
  252. nfs_put_client(clp);
  253. spin_lock(&nn->nfs_client_lock);
  254. if (error < 0)
  255. return ERR_PTR(error);
  256. goto again;
  257. }
  258. /* Different NFS versions cannot share the same nfs_client */
  259. if (clp->rpc_ops != data->nfs_mod->rpc_ops)
  260. continue;
  261. if (clp->cl_proto != data->proto)
  262. continue;
  263. /* Match nfsv4 minorversion */
  264. if (clp->cl_minorversion != data->minorversion)
  265. continue;
  266. /* Match the full socket address */
  267. if (!rpc_cmp_addr_port(sap, clap))
  268. /* Match all xprt_switch full socket addresses */
  269. if (IS_ERR(clp->cl_rpcclient) ||
  270. !rpc_clnt_xprt_switch_has_addr(clp->cl_rpcclient,
  271. sap))
  272. continue;
  273. refcount_inc(&clp->cl_count);
  274. return clp;
  275. }
  276. return NULL;
  277. }
  278. /*
  279. * Return true if @clp is done initializing, false if still working on it.
  280. *
  281. * Use nfs_client_init_status to check if it was successful.
  282. */
  283. bool nfs_client_init_is_complete(const struct nfs_client *clp)
  284. {
  285. return clp->cl_cons_state <= NFS_CS_READY;
  286. }
  287. EXPORT_SYMBOL_GPL(nfs_client_init_is_complete);
  288. /*
  289. * Return 0 if @clp was successfully initialized, -errno otherwise.
  290. *
  291. * This must be called *after* nfs_client_init_is_complete() returns true,
  292. * otherwise it will pop WARN_ON_ONCE and return -EINVAL
  293. */
  294. int nfs_client_init_status(const struct nfs_client *clp)
  295. {
  296. /* called without checking nfs_client_init_is_complete */
  297. if (clp->cl_cons_state > NFS_CS_READY) {
  298. WARN_ON_ONCE(1);
  299. return -EINVAL;
  300. }
  301. return clp->cl_cons_state;
  302. }
  303. EXPORT_SYMBOL_GPL(nfs_client_init_status);
  304. int nfs_wait_client_init_complete(const struct nfs_client *clp)
  305. {
  306. return wait_event_killable(nfs_client_active_wq,
  307. nfs_client_init_is_complete(clp));
  308. }
  309. EXPORT_SYMBOL_GPL(nfs_wait_client_init_complete);
  310. /*
  311. * Found an existing client. Make sure it's ready before returning.
  312. */
  313. static struct nfs_client *
  314. nfs_found_client(const struct nfs_client_initdata *cl_init,
  315. struct nfs_client *clp)
  316. {
  317. int error;
  318. error = nfs_wait_client_init_complete(clp);
  319. if (error < 0) {
  320. nfs_put_client(clp);
  321. return ERR_PTR(-ERESTARTSYS);
  322. }
  323. if (clp->cl_cons_state < NFS_CS_READY) {
  324. error = clp->cl_cons_state;
  325. nfs_put_client(clp);
  326. return ERR_PTR(error);
  327. }
  328. smp_rmb();
  329. return clp;
  330. }
  331. /*
  332. * Look up a client by IP address and protocol version
  333. * - creates a new record if one doesn't yet exist
  334. */
  335. struct nfs_client *nfs_get_client(const struct nfs_client_initdata *cl_init)
  336. {
  337. struct nfs_client *clp, *new = NULL;
  338. struct nfs_net *nn = net_generic(cl_init->net, nfs_net_id);
  339. const struct nfs_rpc_ops *rpc_ops = cl_init->nfs_mod->rpc_ops;
  340. if (cl_init->hostname == NULL) {
  341. WARN_ON(1);
  342. return NULL;
  343. }
  344. /* see if the client already exists */
  345. do {
  346. spin_lock(&nn->nfs_client_lock);
  347. clp = nfs_match_client(cl_init);
  348. if (clp) {
  349. spin_unlock(&nn->nfs_client_lock);
  350. if (new)
  351. new->rpc_ops->free_client(new);
  352. if (IS_ERR(clp))
  353. return clp;
  354. return nfs_found_client(cl_init, clp);
  355. }
  356. if (new) {
  357. list_add_tail(&new->cl_share_link,
  358. &nn->nfs_client_list);
  359. spin_unlock(&nn->nfs_client_lock);
  360. new->cl_flags = cl_init->init_flags;
  361. return rpc_ops->init_client(new, cl_init);
  362. }
  363. spin_unlock(&nn->nfs_client_lock);
  364. new = rpc_ops->alloc_client(cl_init);
  365. } while (!IS_ERR(new));
  366. return new;
  367. }
  368. EXPORT_SYMBOL_GPL(nfs_get_client);
  369. /*
  370. * Mark a server as ready or failed
  371. */
  372. void nfs_mark_client_ready(struct nfs_client *clp, int state)
  373. {
  374. smp_wmb();
  375. clp->cl_cons_state = state;
  376. wake_up_all(&nfs_client_active_wq);
  377. }
  378. EXPORT_SYMBOL_GPL(nfs_mark_client_ready);
  379. /*
  380. * Initialise the timeout values for a connection
  381. */
  382. void nfs_init_timeout_values(struct rpc_timeout *to, int proto,
  383. int timeo, int retrans)
  384. {
  385. to->to_initval = timeo * HZ / 10;
  386. to->to_retries = retrans;
  387. switch (proto) {
  388. case XPRT_TRANSPORT_TCP:
  389. case XPRT_TRANSPORT_RDMA:
  390. if (retrans == NFS_UNSPEC_RETRANS)
  391. to->to_retries = NFS_DEF_TCP_RETRANS;
  392. if (timeo == NFS_UNSPEC_TIMEO || to->to_initval == 0)
  393. to->to_initval = NFS_DEF_TCP_TIMEO * HZ / 10;
  394. if (to->to_initval > NFS_MAX_TCP_TIMEOUT)
  395. to->to_initval = NFS_MAX_TCP_TIMEOUT;
  396. to->to_increment = to->to_initval;
  397. to->to_maxval = to->to_initval + (to->to_increment * to->to_retries);
  398. if (to->to_maxval > NFS_MAX_TCP_TIMEOUT)
  399. to->to_maxval = NFS_MAX_TCP_TIMEOUT;
  400. if (to->to_maxval < to->to_initval)
  401. to->to_maxval = to->to_initval;
  402. to->to_exponential = 0;
  403. break;
  404. case XPRT_TRANSPORT_UDP:
  405. if (retrans == NFS_UNSPEC_RETRANS)
  406. to->to_retries = NFS_DEF_UDP_RETRANS;
  407. if (timeo == NFS_UNSPEC_TIMEO || to->to_initval == 0)
  408. to->to_initval = NFS_DEF_UDP_TIMEO * HZ / 10;
  409. if (to->to_initval > NFS_MAX_UDP_TIMEOUT)
  410. to->to_initval = NFS_MAX_UDP_TIMEOUT;
  411. to->to_maxval = NFS_MAX_UDP_TIMEOUT;
  412. to->to_exponential = 1;
  413. break;
  414. default:
  415. BUG();
  416. }
  417. }
  418. EXPORT_SYMBOL_GPL(nfs_init_timeout_values);
  419. /*
  420. * Create an RPC client handle
  421. */
  422. int nfs_create_rpc_client(struct nfs_client *clp,
  423. const struct nfs_client_initdata *cl_init,
  424. rpc_authflavor_t flavor)
  425. {
  426. struct rpc_clnt *clnt = NULL;
  427. struct rpc_create_args args = {
  428. .net = clp->cl_net,
  429. .protocol = clp->cl_proto,
  430. .address = (struct sockaddr *)&clp->cl_addr,
  431. .addrsize = clp->cl_addrlen,
  432. .timeout = cl_init->timeparms,
  433. .servername = clp->cl_hostname,
  434. .nodename = cl_init->nodename,
  435. .program = &nfs_program,
  436. .version = clp->rpc_ops->version,
  437. .authflavor = flavor,
  438. };
  439. if (test_bit(NFS_CS_DISCRTRY, &clp->cl_flags))
  440. args.flags |= RPC_CLNT_CREATE_DISCRTRY;
  441. if (test_bit(NFS_CS_NO_RETRANS_TIMEOUT, &clp->cl_flags))
  442. args.flags |= RPC_CLNT_CREATE_NO_RETRANS_TIMEOUT;
  443. if (test_bit(NFS_CS_NORESVPORT, &clp->cl_flags))
  444. args.flags |= RPC_CLNT_CREATE_NONPRIVPORT;
  445. if (test_bit(NFS_CS_INFINITE_SLOTS, &clp->cl_flags))
  446. args.flags |= RPC_CLNT_CREATE_INFINITE_SLOTS;
  447. if (!IS_ERR(clp->cl_rpcclient))
  448. return 0;
  449. clnt = rpc_create(&args);
  450. if (IS_ERR(clnt)) {
  451. dprintk("%s: cannot create RPC client. Error = %ld\n",
  452. __func__, PTR_ERR(clnt));
  453. return PTR_ERR(clnt);
  454. }
  455. clp->cl_rpcclient = clnt;
  456. return 0;
  457. }
  458. EXPORT_SYMBOL_GPL(nfs_create_rpc_client);
  459. /*
  460. * Version 2 or 3 client destruction
  461. */
  462. static void nfs_destroy_server(struct nfs_server *server)
  463. {
  464. if (server->nlm_host)
  465. nlmclnt_done(server->nlm_host);
  466. }
  467. /*
  468. * Version 2 or 3 lockd setup
  469. */
  470. static int nfs_start_lockd(struct nfs_server *server)
  471. {
  472. struct nlm_host *host;
  473. struct nfs_client *clp = server->nfs_client;
  474. struct nlmclnt_initdata nlm_init = {
  475. .hostname = clp->cl_hostname,
  476. .address = (struct sockaddr *)&clp->cl_addr,
  477. .addrlen = clp->cl_addrlen,
  478. .nfs_version = clp->rpc_ops->version,
  479. .noresvport = server->flags & NFS_MOUNT_NORESVPORT ?
  480. 1 : 0,
  481. .net = clp->cl_net,
  482. .nlmclnt_ops = clp->cl_nfs_mod->rpc_ops->nlmclnt_ops,
  483. };
  484. if (nlm_init.nfs_version > 3)
  485. return 0;
  486. if ((server->flags & NFS_MOUNT_LOCAL_FLOCK) &&
  487. (server->flags & NFS_MOUNT_LOCAL_FCNTL))
  488. return 0;
  489. switch (clp->cl_proto) {
  490. default:
  491. nlm_init.protocol = IPPROTO_TCP;
  492. break;
  493. case XPRT_TRANSPORT_UDP:
  494. nlm_init.protocol = IPPROTO_UDP;
  495. }
  496. host = nlmclnt_init(&nlm_init);
  497. if (IS_ERR(host))
  498. return PTR_ERR(host);
  499. server->nlm_host = host;
  500. server->destroy = nfs_destroy_server;
  501. return 0;
  502. }
  503. /*
  504. * Create a general RPC client
  505. */
  506. int nfs_init_server_rpcclient(struct nfs_server *server,
  507. const struct rpc_timeout *timeo,
  508. rpc_authflavor_t pseudoflavour)
  509. {
  510. struct nfs_client *clp = server->nfs_client;
  511. server->client = rpc_clone_client_set_auth(clp->cl_rpcclient,
  512. pseudoflavour);
  513. if (IS_ERR(server->client)) {
  514. dprintk("%s: couldn't create rpc_client!\n", __func__);
  515. return PTR_ERR(server->client);
  516. }
  517. memcpy(&server->client->cl_timeout_default,
  518. timeo,
  519. sizeof(server->client->cl_timeout_default));
  520. server->client->cl_timeout = &server->client->cl_timeout_default;
  521. server->client->cl_softrtry = 0;
  522. if (server->flags & NFS_MOUNT_SOFT)
  523. server->client->cl_softrtry = 1;
  524. return 0;
  525. }
  526. EXPORT_SYMBOL_GPL(nfs_init_server_rpcclient);
  527. /**
  528. * nfs_init_client - Initialise an NFS2 or NFS3 client
  529. *
  530. * @clp: nfs_client to initialise
  531. * @cl_init: Initialisation parameters
  532. *
  533. * Returns pointer to an NFS client, or an ERR_PTR value.
  534. */
  535. struct nfs_client *nfs_init_client(struct nfs_client *clp,
  536. const struct nfs_client_initdata *cl_init)
  537. {
  538. int error;
  539. /* the client is already initialised */
  540. if (clp->cl_cons_state == NFS_CS_READY)
  541. return clp;
  542. /*
  543. * Create a client RPC handle for doing FSSTAT with UNIX auth only
  544. * - RFC 2623, sec 2.3.2
  545. */
  546. error = nfs_create_rpc_client(clp, cl_init, RPC_AUTH_UNIX);
  547. nfs_mark_client_ready(clp, error == 0 ? NFS_CS_READY : error);
  548. if (error < 0) {
  549. nfs_put_client(clp);
  550. clp = ERR_PTR(error);
  551. }
  552. return clp;
  553. }
  554. EXPORT_SYMBOL_GPL(nfs_init_client);
  555. /*
  556. * Create a version 2 or 3 client
  557. */
  558. static int nfs_init_server(struct nfs_server *server,
  559. const struct nfs_parsed_mount_data *data,
  560. struct nfs_subversion *nfs_mod)
  561. {
  562. struct rpc_timeout timeparms;
  563. struct nfs_client_initdata cl_init = {
  564. .hostname = data->nfs_server.hostname,
  565. .addr = (const struct sockaddr *)&data->nfs_server.address,
  566. .addrlen = data->nfs_server.addrlen,
  567. .nfs_mod = nfs_mod,
  568. .proto = data->nfs_server.protocol,
  569. .net = data->net,
  570. .timeparms = &timeparms,
  571. };
  572. struct nfs_client *clp;
  573. int error;
  574. nfs_init_timeout_values(&timeparms, data->nfs_server.protocol,
  575. data->timeo, data->retrans);
  576. if (data->flags & NFS_MOUNT_NORESVPORT)
  577. set_bit(NFS_CS_NORESVPORT, &cl_init.init_flags);
  578. /* Allocate or find a client reference we can use */
  579. clp = nfs_get_client(&cl_init);
  580. if (IS_ERR(clp))
  581. return PTR_ERR(clp);
  582. server->nfs_client = clp;
  583. /* Initialise the client representation from the mount data */
  584. server->flags = data->flags;
  585. server->options = data->options;
  586. server->caps |= NFS_CAP_HARDLINKS|NFS_CAP_SYMLINKS|NFS_CAP_FILEID|
  587. NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER|NFS_CAP_OWNER_GROUP|
  588. NFS_CAP_ATIME|NFS_CAP_CTIME|NFS_CAP_MTIME;
  589. if (data->rsize)
  590. server->rsize = nfs_block_size(data->rsize, NULL);
  591. if (data->wsize)
  592. server->wsize = nfs_block_size(data->wsize, NULL);
  593. server->acregmin = data->acregmin * HZ;
  594. server->acregmax = data->acregmax * HZ;
  595. server->acdirmin = data->acdirmin * HZ;
  596. server->acdirmax = data->acdirmax * HZ;
  597. /* Start lockd here, before we might error out */
  598. error = nfs_start_lockd(server);
  599. if (error < 0)
  600. goto error;
  601. server->port = data->nfs_server.port;
  602. server->auth_info = data->auth_info;
  603. error = nfs_init_server_rpcclient(server, &timeparms,
  604. data->selected_flavor);
  605. if (error < 0)
  606. goto error;
  607. /* Preserve the values of mount_server-related mount options */
  608. if (data->mount_server.addrlen) {
  609. memcpy(&server->mountd_address, &data->mount_server.address,
  610. data->mount_server.addrlen);
  611. server->mountd_addrlen = data->mount_server.addrlen;
  612. }
  613. server->mountd_version = data->mount_server.version;
  614. server->mountd_port = data->mount_server.port;
  615. server->mountd_protocol = data->mount_server.protocol;
  616. server->namelen = data->namlen;
  617. return 0;
  618. error:
  619. server->nfs_client = NULL;
  620. nfs_put_client(clp);
  621. return error;
  622. }
  623. /*
  624. * Load up the server record from information gained in an fsinfo record
  625. */
  626. static void nfs_server_set_fsinfo(struct nfs_server *server,
  627. struct nfs_fsinfo *fsinfo)
  628. {
  629. unsigned long max_rpc_payload;
  630. /* Work out a lot of parameters */
  631. if (server->rsize == 0)
  632. server->rsize = nfs_block_size(fsinfo->rtpref, NULL);
  633. if (server->wsize == 0)
  634. server->wsize = nfs_block_size(fsinfo->wtpref, NULL);
  635. if (fsinfo->rtmax >= 512 && server->rsize > fsinfo->rtmax)
  636. server->rsize = nfs_block_size(fsinfo->rtmax, NULL);
  637. if (fsinfo->wtmax >= 512 && server->wsize > fsinfo->wtmax)
  638. server->wsize = nfs_block_size(fsinfo->wtmax, NULL);
  639. max_rpc_payload = nfs_block_size(rpc_max_payload(server->client), NULL);
  640. if (server->rsize > max_rpc_payload)
  641. server->rsize = max_rpc_payload;
  642. if (server->rsize > NFS_MAX_FILE_IO_SIZE)
  643. server->rsize = NFS_MAX_FILE_IO_SIZE;
  644. server->rpages = (server->rsize + PAGE_SIZE - 1) >> PAGE_SHIFT;
  645. if (server->wsize > max_rpc_payload)
  646. server->wsize = max_rpc_payload;
  647. if (server->wsize > NFS_MAX_FILE_IO_SIZE)
  648. server->wsize = NFS_MAX_FILE_IO_SIZE;
  649. server->wpages = (server->wsize + PAGE_SIZE - 1) >> PAGE_SHIFT;
  650. server->wtmult = nfs_block_bits(fsinfo->wtmult, NULL);
  651. server->dtsize = nfs_block_size(fsinfo->dtpref, NULL);
  652. if (server->dtsize > PAGE_SIZE * NFS_MAX_READDIR_PAGES)
  653. server->dtsize = PAGE_SIZE * NFS_MAX_READDIR_PAGES;
  654. if (server->dtsize > server->rsize)
  655. server->dtsize = server->rsize;
  656. if (server->flags & NFS_MOUNT_NOAC) {
  657. server->acregmin = server->acregmax = 0;
  658. server->acdirmin = server->acdirmax = 0;
  659. }
  660. server->maxfilesize = fsinfo->maxfilesize;
  661. server->time_delta = fsinfo->time_delta;
  662. server->clone_blksize = fsinfo->clone_blksize;
  663. /* We're airborne Set socket buffersize */
  664. rpc_setbufsize(server->client, server->wsize + 100, server->rsize + 100);
  665. }
  666. /*
  667. * Probe filesystem information, including the FSID on v2/v3
  668. */
  669. int nfs_probe_fsinfo(struct nfs_server *server, struct nfs_fh *mntfh, struct nfs_fattr *fattr)
  670. {
  671. struct nfs_fsinfo fsinfo;
  672. struct nfs_client *clp = server->nfs_client;
  673. int error;
  674. if (clp->rpc_ops->set_capabilities != NULL) {
  675. error = clp->rpc_ops->set_capabilities(server, mntfh);
  676. if (error < 0)
  677. return error;
  678. }
  679. fsinfo.fattr = fattr;
  680. fsinfo.nlayouttypes = 0;
  681. memset(fsinfo.layouttype, 0, sizeof(fsinfo.layouttype));
  682. error = clp->rpc_ops->fsinfo(server, mntfh, &fsinfo);
  683. if (error < 0)
  684. return error;
  685. nfs_server_set_fsinfo(server, &fsinfo);
  686. /* Get some general file system info */
  687. if (server->namelen == 0) {
  688. struct nfs_pathconf pathinfo;
  689. pathinfo.fattr = fattr;
  690. nfs_fattr_init(fattr);
  691. if (clp->rpc_ops->pathconf(server, mntfh, &pathinfo) >= 0)
  692. server->namelen = pathinfo.max_namelen;
  693. }
  694. return 0;
  695. }
  696. EXPORT_SYMBOL_GPL(nfs_probe_fsinfo);
  697. /*
  698. * Copy useful information when duplicating a server record
  699. */
  700. void nfs_server_copy_userdata(struct nfs_server *target, struct nfs_server *source)
  701. {
  702. target->flags = source->flags;
  703. target->rsize = source->rsize;
  704. target->wsize = source->wsize;
  705. target->acregmin = source->acregmin;
  706. target->acregmax = source->acregmax;
  707. target->acdirmin = source->acdirmin;
  708. target->acdirmax = source->acdirmax;
  709. target->caps = source->caps;
  710. target->options = source->options;
  711. target->auth_info = source->auth_info;
  712. target->port = source->port;
  713. }
  714. EXPORT_SYMBOL_GPL(nfs_server_copy_userdata);
  715. void nfs_server_insert_lists(struct nfs_server *server)
  716. {
  717. struct nfs_client *clp = server->nfs_client;
  718. struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
  719. spin_lock(&nn->nfs_client_lock);
  720. list_add_tail_rcu(&server->client_link, &clp->cl_superblocks);
  721. list_add_tail(&server->master_link, &nn->nfs_volume_list);
  722. clear_bit(NFS_CS_STOP_RENEW, &clp->cl_res_state);
  723. spin_unlock(&nn->nfs_client_lock);
  724. }
  725. EXPORT_SYMBOL_GPL(nfs_server_insert_lists);
  726. void nfs_server_remove_lists(struct nfs_server *server)
  727. {
  728. struct nfs_client *clp = server->nfs_client;
  729. struct nfs_net *nn;
  730. if (clp == NULL)
  731. return;
  732. nn = net_generic(clp->cl_net, nfs_net_id);
  733. spin_lock(&nn->nfs_client_lock);
  734. list_del_rcu(&server->client_link);
  735. if (list_empty(&clp->cl_superblocks))
  736. set_bit(NFS_CS_STOP_RENEW, &clp->cl_res_state);
  737. list_del(&server->master_link);
  738. spin_unlock(&nn->nfs_client_lock);
  739. synchronize_rcu();
  740. }
  741. EXPORT_SYMBOL_GPL(nfs_server_remove_lists);
  742. /*
  743. * Allocate and initialise a server record
  744. */
  745. struct nfs_server *nfs_alloc_server(void)
  746. {
  747. struct nfs_server *server;
  748. server = kzalloc(sizeof(struct nfs_server), GFP_KERNEL);
  749. if (!server)
  750. return NULL;
  751. server->client = server->client_acl = ERR_PTR(-EINVAL);
  752. /* Zero out the NFS state stuff */
  753. INIT_LIST_HEAD(&server->client_link);
  754. INIT_LIST_HEAD(&server->master_link);
  755. INIT_LIST_HEAD(&server->delegations);
  756. INIT_LIST_HEAD(&server->layouts);
  757. INIT_LIST_HEAD(&server->state_owners_lru);
  758. INIT_LIST_HEAD(&server->ss_copies);
  759. atomic_set(&server->active, 0);
  760. server->io_stats = nfs_alloc_iostats();
  761. if (!server->io_stats) {
  762. kfree(server);
  763. return NULL;
  764. }
  765. ida_init(&server->openowner_id);
  766. ida_init(&server->lockowner_id);
  767. pnfs_init_server(server);
  768. rpc_init_wait_queue(&server->uoc_rpcwaitq, "NFS UOC");
  769. return server;
  770. }
  771. EXPORT_SYMBOL_GPL(nfs_alloc_server);
  772. /*
  773. * Free up a server record
  774. */
  775. void nfs_free_server(struct nfs_server *server)
  776. {
  777. nfs_server_remove_lists(server);
  778. if (server->destroy != NULL)
  779. server->destroy(server);
  780. if (!IS_ERR(server->client_acl))
  781. rpc_shutdown_client(server->client_acl);
  782. if (!IS_ERR(server->client))
  783. rpc_shutdown_client(server->client);
  784. nfs_put_client(server->nfs_client);
  785. ida_destroy(&server->lockowner_id);
  786. ida_destroy(&server->openowner_id);
  787. nfs_free_iostats(server->io_stats);
  788. kfree(server);
  789. nfs_release_automount_timer();
  790. }
  791. EXPORT_SYMBOL_GPL(nfs_free_server);
  792. /*
  793. * Create a version 2 or 3 volume record
  794. * - keyed on server and FSID
  795. */
  796. struct nfs_server *nfs_create_server(struct nfs_mount_info *mount_info,
  797. struct nfs_subversion *nfs_mod)
  798. {
  799. struct nfs_server *server;
  800. struct nfs_fattr *fattr;
  801. int error;
  802. server = nfs_alloc_server();
  803. if (!server)
  804. return ERR_PTR(-ENOMEM);
  805. error = -ENOMEM;
  806. fattr = nfs_alloc_fattr();
  807. if (fattr == NULL)
  808. goto error;
  809. /* Get a client representation */
  810. error = nfs_init_server(server, mount_info->parsed, nfs_mod);
  811. if (error < 0)
  812. goto error;
  813. /* Probe the root fh to retrieve its FSID */
  814. error = nfs_probe_fsinfo(server, mount_info->mntfh, fattr);
  815. if (error < 0)
  816. goto error;
  817. if (server->nfs_client->rpc_ops->version == 3) {
  818. if (server->namelen == 0 || server->namelen > NFS3_MAXNAMLEN)
  819. server->namelen = NFS3_MAXNAMLEN;
  820. if (!(mount_info->parsed->flags & NFS_MOUNT_NORDIRPLUS))
  821. server->caps |= NFS_CAP_READDIRPLUS;
  822. } else {
  823. if (server->namelen == 0 || server->namelen > NFS2_MAXNAMLEN)
  824. server->namelen = NFS2_MAXNAMLEN;
  825. }
  826. if (!(fattr->valid & NFS_ATTR_FATTR)) {
  827. error = nfs_mod->rpc_ops->getattr(server, mount_info->mntfh,
  828. fattr, NULL, NULL);
  829. if (error < 0) {
  830. dprintk("nfs_create_server: getattr error = %d\n", -error);
  831. goto error;
  832. }
  833. }
  834. memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid));
  835. dprintk("Server FSID: %llx:%llx\n",
  836. (unsigned long long) server->fsid.major,
  837. (unsigned long long) server->fsid.minor);
  838. nfs_server_insert_lists(server);
  839. server->mount_time = jiffies;
  840. nfs_free_fattr(fattr);
  841. return server;
  842. error:
  843. nfs_free_fattr(fattr);
  844. nfs_free_server(server);
  845. return ERR_PTR(error);
  846. }
  847. EXPORT_SYMBOL_GPL(nfs_create_server);
  848. /*
  849. * Clone an NFS2, NFS3 or NFS4 server record
  850. */
  851. struct nfs_server *nfs_clone_server(struct nfs_server *source,
  852. struct nfs_fh *fh,
  853. struct nfs_fattr *fattr,
  854. rpc_authflavor_t flavor)
  855. {
  856. struct nfs_server *server;
  857. struct nfs_fattr *fattr_fsinfo;
  858. int error;
  859. server = nfs_alloc_server();
  860. if (!server)
  861. return ERR_PTR(-ENOMEM);
  862. error = -ENOMEM;
  863. fattr_fsinfo = nfs_alloc_fattr();
  864. if (fattr_fsinfo == NULL)
  865. goto out_free_server;
  866. /* Copy data from the source */
  867. server->nfs_client = source->nfs_client;
  868. server->destroy = source->destroy;
  869. refcount_inc(&server->nfs_client->cl_count);
  870. nfs_server_copy_userdata(server, source);
  871. server->fsid = fattr->fsid;
  872. error = nfs_init_server_rpcclient(server,
  873. source->client->cl_timeout,
  874. flavor);
  875. if (error < 0)
  876. goto out_free_server;
  877. /* probe the filesystem info for this server filesystem */
  878. error = nfs_probe_fsinfo(server, fh, fattr_fsinfo);
  879. if (error < 0)
  880. goto out_free_server;
  881. if (server->namelen == 0 || server->namelen > NFS4_MAXNAMLEN)
  882. server->namelen = NFS4_MAXNAMLEN;
  883. error = nfs_start_lockd(server);
  884. if (error < 0)
  885. goto out_free_server;
  886. nfs_server_insert_lists(server);
  887. server->mount_time = jiffies;
  888. nfs_free_fattr(fattr_fsinfo);
  889. return server;
  890. out_free_server:
  891. nfs_free_fattr(fattr_fsinfo);
  892. nfs_free_server(server);
  893. return ERR_PTR(error);
  894. }
  895. EXPORT_SYMBOL_GPL(nfs_clone_server);
  896. void nfs_clients_init(struct net *net)
  897. {
  898. struct nfs_net *nn = net_generic(net, nfs_net_id);
  899. INIT_LIST_HEAD(&nn->nfs_client_list);
  900. INIT_LIST_HEAD(&nn->nfs_volume_list);
  901. #if IS_ENABLED(CONFIG_NFS_V4)
  902. idr_init(&nn->cb_ident_idr);
  903. #endif
  904. spin_lock_init(&nn->nfs_client_lock);
  905. nn->boot_time = ktime_get_real();
  906. }
  907. #ifdef CONFIG_PROC_FS
  908. static void *nfs_server_list_start(struct seq_file *p, loff_t *pos);
  909. static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos);
  910. static void nfs_server_list_stop(struct seq_file *p, void *v);
  911. static int nfs_server_list_show(struct seq_file *m, void *v);
  912. static const struct seq_operations nfs_server_list_ops = {
  913. .start = nfs_server_list_start,
  914. .next = nfs_server_list_next,
  915. .stop = nfs_server_list_stop,
  916. .show = nfs_server_list_show,
  917. };
  918. static void *nfs_volume_list_start(struct seq_file *p, loff_t *pos);
  919. static void *nfs_volume_list_next(struct seq_file *p, void *v, loff_t *pos);
  920. static void nfs_volume_list_stop(struct seq_file *p, void *v);
  921. static int nfs_volume_list_show(struct seq_file *m, void *v);
  922. static const struct seq_operations nfs_volume_list_ops = {
  923. .start = nfs_volume_list_start,
  924. .next = nfs_volume_list_next,
  925. .stop = nfs_volume_list_stop,
  926. .show = nfs_volume_list_show,
  927. };
  928. /*
  929. * set up the iterator to start reading from the server list and return the first item
  930. */
  931. static void *nfs_server_list_start(struct seq_file *m, loff_t *_pos)
  932. __acquires(&nn->nfs_client_lock)
  933. {
  934. struct nfs_net *nn = net_generic(seq_file_net(m), nfs_net_id);
  935. /* lock the list against modification */
  936. spin_lock(&nn->nfs_client_lock);
  937. return seq_list_start_head(&nn->nfs_client_list, *_pos);
  938. }
  939. /*
  940. * move to next server
  941. */
  942. static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos)
  943. {
  944. struct nfs_net *nn = net_generic(seq_file_net(p), nfs_net_id);
  945. return seq_list_next(v, &nn->nfs_client_list, pos);
  946. }
  947. /*
  948. * clean up after reading from the transports list
  949. */
  950. static void nfs_server_list_stop(struct seq_file *p, void *v)
  951. __releases(&nn->nfs_client_lock)
  952. {
  953. struct nfs_net *nn = net_generic(seq_file_net(p), nfs_net_id);
  954. spin_unlock(&nn->nfs_client_lock);
  955. }
  956. /*
  957. * display a header line followed by a load of call lines
  958. */
  959. static int nfs_server_list_show(struct seq_file *m, void *v)
  960. {
  961. struct nfs_client *clp;
  962. struct nfs_net *nn = net_generic(seq_file_net(m), nfs_net_id);
  963. /* display header on line 1 */
  964. if (v == &nn->nfs_client_list) {
  965. seq_puts(m, "NV SERVER PORT USE HOSTNAME\n");
  966. return 0;
  967. }
  968. /* display one transport per line on subsequent lines */
  969. clp = list_entry(v, struct nfs_client, cl_share_link);
  970. /* Check if the client is initialized */
  971. if (clp->cl_cons_state != NFS_CS_READY)
  972. return 0;
  973. rcu_read_lock();
  974. seq_printf(m, "v%u %s %s %3d %s\n",
  975. clp->rpc_ops->version,
  976. rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_ADDR),
  977. rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_PORT),
  978. refcount_read(&clp->cl_count),
  979. clp->cl_hostname);
  980. rcu_read_unlock();
  981. return 0;
  982. }
  983. /*
  984. * set up the iterator to start reading from the volume list and return the first item
  985. */
  986. static void *nfs_volume_list_start(struct seq_file *m, loff_t *_pos)
  987. __acquires(&nn->nfs_client_lock)
  988. {
  989. struct nfs_net *nn = net_generic(seq_file_net(m), nfs_net_id);
  990. /* lock the list against modification */
  991. spin_lock(&nn->nfs_client_lock);
  992. return seq_list_start_head(&nn->nfs_volume_list, *_pos);
  993. }
  994. /*
  995. * move to next volume
  996. */
  997. static void *nfs_volume_list_next(struct seq_file *p, void *v, loff_t *pos)
  998. {
  999. struct nfs_net *nn = net_generic(seq_file_net(p), nfs_net_id);
  1000. return seq_list_next(v, &nn->nfs_volume_list, pos);
  1001. }
  1002. /*
  1003. * clean up after reading from the transports list
  1004. */
  1005. static void nfs_volume_list_stop(struct seq_file *p, void *v)
  1006. __releases(&nn->nfs_client_lock)
  1007. {
  1008. struct nfs_net *nn = net_generic(seq_file_net(p), nfs_net_id);
  1009. spin_unlock(&nn->nfs_client_lock);
  1010. }
  1011. /*
  1012. * display a header line followed by a load of call lines
  1013. */
  1014. static int nfs_volume_list_show(struct seq_file *m, void *v)
  1015. {
  1016. struct nfs_server *server;
  1017. struct nfs_client *clp;
  1018. char dev[13]; // 8 for 2^24, 1 for ':', 3 for 2^8, 1 for '\0'
  1019. char fsid[34]; // 2 * 16 for %llx, 1 for ':', 1 for '\0'
  1020. struct nfs_net *nn = net_generic(seq_file_net(m), nfs_net_id);
  1021. /* display header on line 1 */
  1022. if (v == &nn->nfs_volume_list) {
  1023. seq_puts(m, "NV SERVER PORT DEV FSID"
  1024. " FSC\n");
  1025. return 0;
  1026. }
  1027. /* display one transport per line on subsequent lines */
  1028. server = list_entry(v, struct nfs_server, master_link);
  1029. clp = server->nfs_client;
  1030. snprintf(dev, sizeof(dev), "%u:%u",
  1031. MAJOR(server->s_dev), MINOR(server->s_dev));
  1032. snprintf(fsid, sizeof(fsid), "%llx:%llx",
  1033. (unsigned long long) server->fsid.major,
  1034. (unsigned long long) server->fsid.minor);
  1035. rcu_read_lock();
  1036. seq_printf(m, "v%u %s %s %-12s %-33s %s\n",
  1037. clp->rpc_ops->version,
  1038. rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_ADDR),
  1039. rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_PORT),
  1040. dev,
  1041. fsid,
  1042. nfs_server_fscache_state(server));
  1043. rcu_read_unlock();
  1044. return 0;
  1045. }
  1046. int nfs_fs_proc_net_init(struct net *net)
  1047. {
  1048. struct nfs_net *nn = net_generic(net, nfs_net_id);
  1049. struct proc_dir_entry *p;
  1050. nn->proc_nfsfs = proc_net_mkdir(net, "nfsfs", net->proc_net);
  1051. if (!nn->proc_nfsfs)
  1052. goto error_0;
  1053. /* a file of servers with which we're dealing */
  1054. p = proc_create_net("servers", S_IFREG|S_IRUGO, nn->proc_nfsfs,
  1055. &nfs_server_list_ops, sizeof(struct seq_net_private));
  1056. if (!p)
  1057. goto error_1;
  1058. /* a file of volumes that we have mounted */
  1059. p = proc_create_net("volumes", S_IFREG|S_IRUGO, nn->proc_nfsfs,
  1060. &nfs_volume_list_ops, sizeof(struct seq_net_private));
  1061. if (!p)
  1062. goto error_1;
  1063. return 0;
  1064. error_1:
  1065. remove_proc_subtree("nfsfs", net->proc_net);
  1066. error_0:
  1067. return -ENOMEM;
  1068. }
  1069. void nfs_fs_proc_net_exit(struct net *net)
  1070. {
  1071. remove_proc_subtree("nfsfs", net->proc_net);
  1072. }
  1073. /*
  1074. * initialise the /proc/fs/nfsfs/ directory
  1075. */
  1076. int __init nfs_fs_proc_init(void)
  1077. {
  1078. if (!proc_mkdir("fs/nfsfs", NULL))
  1079. goto error_0;
  1080. /* a file of servers with which we're dealing */
  1081. if (!proc_symlink("fs/nfsfs/servers", NULL, "../../net/nfsfs/servers"))
  1082. goto error_1;
  1083. /* a file of volumes that we have mounted */
  1084. if (!proc_symlink("fs/nfsfs/volumes", NULL, "../../net/nfsfs/volumes"))
  1085. goto error_1;
  1086. return 0;
  1087. error_1:
  1088. remove_proc_subtree("fs/nfsfs", NULL);
  1089. error_0:
  1090. return -ENOMEM;
  1091. }
  1092. /*
  1093. * clean up the /proc/fs/nfsfs/ directory
  1094. */
  1095. void nfs_fs_proc_exit(void)
  1096. {
  1097. remove_proc_subtree("fs/nfsfs", NULL);
  1098. }
  1099. #endif /* CONFIG_PROC_FS */