blob: 110f80e7bd4cebb5763378c64e1110213ea1defc [file] [log] [blame]
David Howells24c8dbb2006-08-22 20:06:10 -04001/* 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
12
13#include <linux/config.h>
14#include <linux/module.h>
15#include <linux/init.h>
16
17#include <linux/time.h>
18#include <linux/kernel.h>
19#include <linux/mm.h>
20#include <linux/string.h>
21#include <linux/stat.h>
22#include <linux/errno.h>
23#include <linux/unistd.h>
24#include <linux/sunrpc/clnt.h>
25#include <linux/sunrpc/stats.h>
26#include <linux/sunrpc/metrics.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/smp_lock.h>
32#include <linux/seq_file.h>
33#include <linux/mount.h>
34#include <linux/nfs_idmap.h>
35#include <linux/vfs.h>
36#include <linux/inet.h>
37#include <linux/nfs_xdr.h>
38
39#include <asm/system.h>
40
41#include "nfs4_fs.h"
42#include "callback.h"
43#include "delegation.h"
44#include "iostat.h"
45#include "internal.h"
46
47#define NFSDBG_FACILITY NFSDBG_CLIENT
48
49static DEFINE_SPINLOCK(nfs_client_lock);
50static LIST_HEAD(nfs_client_list);
David Howells54ceac42006-08-22 20:06:13 -040051static LIST_HEAD(nfs_volume_list);
David Howells24c8dbb2006-08-22 20:06:10 -040052static DECLARE_WAIT_QUEUE_HEAD(nfs_client_active_wq);
53
54/*
David Howells5006a762006-08-22 20:06:12 -040055 * RPC cruft for NFS
56 */
57static struct rpc_version *nfs_version[5] = {
58 [2] = &nfs_version2,
59#ifdef CONFIG_NFS_V3
60 [3] = &nfs_version3,
61#endif
62#ifdef CONFIG_NFS_V4
63 [4] = &nfs_version4,
64#endif
65};
66
67struct rpc_program nfs_program = {
68 .name = "nfs",
69 .number = NFS_PROGRAM,
70 .nrvers = ARRAY_SIZE(nfs_version),
71 .version = nfs_version,
72 .stats = &nfs_rpcstat,
73 .pipe_dir_name = "/nfs",
74};
75
76struct rpc_stat nfs_rpcstat = {
77 .program = &nfs_program
78};
79
80
81#ifdef CONFIG_NFS_V3_ACL
82static struct rpc_stat nfsacl_rpcstat = { &nfsacl_program };
83static struct rpc_version * nfsacl_version[] = {
84 [3] = &nfsacl_version3,
85};
86
87struct rpc_program nfsacl_program = {
88 .name = "nfsacl",
89 .number = NFS_ACL_PROGRAM,
90 .nrvers = ARRAY_SIZE(nfsacl_version),
91 .version = nfsacl_version,
92 .stats = &nfsacl_rpcstat,
93};
94#endif /* CONFIG_NFS_V3_ACL */
95
96/*
David Howells24c8dbb2006-08-22 20:06:10 -040097 * Allocate a shared client record
98 *
99 * Since these are allocated/deallocated very rarely, we don't
100 * bother putting them in a slab cache...
101 */
102static struct nfs_client *nfs_alloc_client(const char *hostname,
103 const struct sockaddr_in *addr,
104 int nfsversion)
105{
106 struct nfs_client *clp;
107 int error;
108
109 if ((clp = kzalloc(sizeof(*clp), GFP_KERNEL)) == NULL)
110 goto error_0;
111
112 error = rpciod_up();
113 if (error < 0) {
114 dprintk("%s: couldn't start rpciod! Error = %d\n",
115 __FUNCTION__, error);
David Howells24c8dbb2006-08-22 20:06:10 -0400116 goto error_1;
117 }
Trond Myklebust9c5bf382006-08-22 20:06:14 -0400118 __set_bit(NFS_CS_RPCIOD, &clp->cl_res_state);
David Howells24c8dbb2006-08-22 20:06:10 -0400119
120 if (nfsversion == 4) {
121 if (nfs_callback_up() < 0)
122 goto error_2;
123 __set_bit(NFS_CS_CALLBACK, &clp->cl_res_state);
124 }
125
126 atomic_set(&clp->cl_count, 1);
127 clp->cl_cons_state = NFS_CS_INITING;
128
129 clp->cl_nfsversion = nfsversion;
130 memcpy(&clp->cl_addr, addr, sizeof(clp->cl_addr));
131
132 if (hostname) {
133 clp->cl_hostname = kstrdup(hostname, GFP_KERNEL);
134 if (!clp->cl_hostname)
135 goto error_3;
136 }
137
138 INIT_LIST_HEAD(&clp->cl_superblocks);
139 clp->cl_rpcclient = ERR_PTR(-EINVAL);
140
141#ifdef CONFIG_NFS_V4
142 init_rwsem(&clp->cl_sem);
143 INIT_LIST_HEAD(&clp->cl_delegations);
144 INIT_LIST_HEAD(&clp->cl_state_owners);
145 INIT_LIST_HEAD(&clp->cl_unused);
146 spin_lock_init(&clp->cl_lock);
147 INIT_WORK(&clp->cl_renewd, nfs4_renew_state, clp);
148 rpc_init_wait_queue(&clp->cl_rpcwaitq, "NFS client");
149 clp->cl_boot_time = CURRENT_TIME;
150 clp->cl_state = 1 << NFS4CLNT_LEASE_EXPIRED;
151#endif
152
153 return clp;
154
155error_3:
Trond Myklebust9c5bf382006-08-22 20:06:14 -0400156 if (__test_and_clear_bit(NFS_CS_CALLBACK, &clp->cl_res_state))
157 nfs_callback_down();
David Howells24c8dbb2006-08-22 20:06:10 -0400158error_2:
159 rpciod_down();
160 __clear_bit(NFS_CS_RPCIOD, &clp->cl_res_state);
161error_1:
162 kfree(clp);
163error_0:
164 return NULL;
165}
166
Trond Myklebust5dd31772006-08-24 01:03:05 -0400167static void nfs4_shutdown_client(struct nfs_client *clp)
168{
169#ifdef CONFIG_NFS_V4
170 if (__test_and_clear_bit(NFS_CS_RENEWD, &clp->cl_res_state))
171 nfs4_kill_renewd(clp);
172 while (!list_empty(&clp->cl_unused)) {
173 struct nfs4_state_owner *sp;
174
175 sp = list_entry(clp->cl_unused.next,
176 struct nfs4_state_owner,
177 so_list);
178 list_del(&sp->so_list);
179 kfree(sp);
180 }
181 BUG_ON(!list_empty(&clp->cl_state_owners));
182 if (__test_and_clear_bit(NFS_CS_IDMAP, &clp->cl_res_state))
183 nfs_idmap_delete(clp);
184#endif
185}
186
David Howells24c8dbb2006-08-22 20:06:10 -0400187/*
188 * Destroy a shared client record
189 */
190static void nfs_free_client(struct nfs_client *clp)
191{
192 dprintk("--> nfs_free_client(%d)\n", clp->cl_nfsversion);
193
Trond Myklebust5dd31772006-08-24 01:03:05 -0400194 nfs4_shutdown_client(clp);
David Howells24c8dbb2006-08-22 20:06:10 -0400195
196 /* -EIO all pending I/O */
197 if (!IS_ERR(clp->cl_rpcclient))
198 rpc_shutdown_client(clp->cl_rpcclient);
199
200 if (__test_and_clear_bit(NFS_CS_CALLBACK, &clp->cl_res_state))
201 nfs_callback_down();
202
203 if (__test_and_clear_bit(NFS_CS_RPCIOD, &clp->cl_res_state))
Trond Myklebust9c5bf382006-08-22 20:06:14 -0400204 rpciod_down();
David Howells24c8dbb2006-08-22 20:06:10 -0400205
206 kfree(clp->cl_hostname);
207 kfree(clp);
208
209 dprintk("<-- nfs_free_client()\n");
210}
211
212/*
213 * Release a reference to a shared client record
214 */
215void nfs_put_client(struct nfs_client *clp)
216{
David Howells27ba8512006-07-30 14:40:56 -0400217 if (!clp)
218 return;
219
David Howells24c8dbb2006-08-22 20:06:10 -0400220 dprintk("--> nfs_put_client({%d})\n", atomic_read(&clp->cl_count));
221
222 if (atomic_dec_and_lock(&clp->cl_count, &nfs_client_lock)) {
223 list_del(&clp->cl_share_link);
224 spin_unlock(&nfs_client_lock);
225
226 BUG_ON(!list_empty(&clp->cl_superblocks));
227
228 nfs_free_client(clp);
229 }
230}
231
232/*
233 * Find a client by address
234 * - caller must hold nfs_client_lock
235 */
236static struct nfs_client *__nfs_find_client(const struct sockaddr_in *addr, int nfsversion)
237{
238 struct nfs_client *clp;
239
240 list_for_each_entry(clp, &nfs_client_list, cl_share_link) {
241 /* Different NFS versions cannot share the same nfs_client */
242 if (clp->cl_nfsversion != nfsversion)
243 continue;
244
245 if (memcmp(&clp->cl_addr.sin_addr, &addr->sin_addr,
246 sizeof(clp->cl_addr.sin_addr)) != 0)
247 continue;
248
249 if (clp->cl_addr.sin_port == addr->sin_port)
250 goto found;
251 }
252
253 return NULL;
254
255found:
256 atomic_inc(&clp->cl_count);
257 return clp;
258}
259
260/*
261 * Find a client by IP address and protocol version
262 * - returns NULL if no such client
263 */
264struct nfs_client *nfs_find_client(const struct sockaddr_in *addr, int nfsversion)
265{
266 struct nfs_client *clp;
267
268 spin_lock(&nfs_client_lock);
269 clp = __nfs_find_client(addr, nfsversion);
270 spin_unlock(&nfs_client_lock);
271
272 BUG_ON(clp->cl_cons_state == 0);
273
274 return clp;
275}
276
277/*
278 * Look up a client by IP address and protocol version
279 * - creates a new record if one doesn't yet exist
280 */
David Howells54ceac42006-08-22 20:06:13 -0400281static struct nfs_client *nfs_get_client(const char *hostname,
282 const struct sockaddr_in *addr,
283 int nfsversion)
David Howells24c8dbb2006-08-22 20:06:10 -0400284{
285 struct nfs_client *clp, *new = NULL;
286 int error;
287
288 dprintk("--> nfs_get_client(%s,"NIPQUAD_FMT":%d,%d)\n",
289 hostname ?: "", NIPQUAD(addr->sin_addr),
290 addr->sin_port, nfsversion);
291
292 /* see if the client already exists */
293 do {
294 spin_lock(&nfs_client_lock);
295
296 clp = __nfs_find_client(addr, nfsversion);
297 if (clp)
298 goto found_client;
299 if (new)
300 goto install_client;
301
302 spin_unlock(&nfs_client_lock);
303
304 new = nfs_alloc_client(hostname, addr, nfsversion);
305 } while (new);
306
307 return ERR_PTR(-ENOMEM);
308
309 /* install a new client and return with it unready */
310install_client:
311 clp = new;
312 list_add(&clp->cl_share_link, &nfs_client_list);
313 spin_unlock(&nfs_client_lock);
314 dprintk("--> nfs_get_client() = %p [new]\n", clp);
315 return clp;
316
317 /* found an existing client
318 * - make sure it's ready before returning
319 */
320found_client:
321 spin_unlock(&nfs_client_lock);
322
323 if (new)
324 nfs_free_client(new);
325
326 if (clp->cl_cons_state == NFS_CS_INITING) {
327 DECLARE_WAITQUEUE(myself, current);
328
329 add_wait_queue(&nfs_client_active_wq, &myself);
330
331 for (;;) {
332 set_current_state(TASK_INTERRUPTIBLE);
333 if (signal_pending(current) ||
334 clp->cl_cons_state > NFS_CS_READY)
335 break;
336 schedule();
337 }
338
339 remove_wait_queue(&nfs_client_active_wq, &myself);
340
341 if (signal_pending(current)) {
342 nfs_put_client(clp);
343 return ERR_PTR(-ERESTARTSYS);
344 }
345 }
346
347 if (clp->cl_cons_state < NFS_CS_READY) {
348 error = clp->cl_cons_state;
349 nfs_put_client(clp);
350 return ERR_PTR(error);
351 }
352
David Howells54ceac42006-08-22 20:06:13 -0400353 BUG_ON(clp->cl_cons_state != NFS_CS_READY);
354
David Howells24c8dbb2006-08-22 20:06:10 -0400355 dprintk("--> nfs_get_client() = %p [share]\n", clp);
356 return clp;
357}
358
359/*
360 * Mark a server as ready or failed
361 */
David Howells54ceac42006-08-22 20:06:13 -0400362static void nfs_mark_client_ready(struct nfs_client *clp, int state)
David Howells24c8dbb2006-08-22 20:06:10 -0400363{
364 clp->cl_cons_state = state;
365 wake_up_all(&nfs_client_active_wq);
366}
David Howells5006a762006-08-22 20:06:12 -0400367
368/*
369 * Initialise the timeout values for a connection
370 */
371static void nfs_init_timeout_values(struct rpc_timeout *to, int proto,
372 unsigned int timeo, unsigned int retrans)
373{
374 to->to_initval = timeo * HZ / 10;
375 to->to_retries = retrans;
376 if (!to->to_retries)
377 to->to_retries = 2;
378
379 switch (proto) {
380 case IPPROTO_TCP:
381 if (!to->to_initval)
382 to->to_initval = 60 * HZ;
383 if (to->to_initval > NFS_MAX_TCP_TIMEOUT)
384 to->to_initval = NFS_MAX_TCP_TIMEOUT;
385 to->to_increment = to->to_initval;
386 to->to_maxval = to->to_initval + (to->to_increment * to->to_retries);
387 to->to_exponential = 0;
388 break;
389 case IPPROTO_UDP:
390 default:
391 if (!to->to_initval)
392 to->to_initval = 11 * HZ / 10;
393 if (to->to_initval > NFS_MAX_UDP_TIMEOUT)
394 to->to_initval = NFS_MAX_UDP_TIMEOUT;
395 to->to_maxval = NFS_MAX_UDP_TIMEOUT;
396 to->to_exponential = 1;
397 break;
398 }
399}
400
401/*
402 * Create an RPC client handle
403 */
David Howells54ceac42006-08-22 20:06:13 -0400404static int nfs_create_rpc_client(struct nfs_client *clp, int proto,
405 unsigned int timeo,
406 unsigned int retrans,
407 rpc_authflavor_t flavor)
David Howells5006a762006-08-22 20:06:12 -0400408{
409 struct rpc_timeout timeparms;
David Howells5006a762006-08-22 20:06:12 -0400410 struct rpc_clnt *clnt = NULL;
Chuck Lever41877d22006-08-22 20:06:20 -0400411 struct rpc_create_args args = {
412 .protocol = proto,
413 .address = (struct sockaddr *)&clp->cl_addr,
414 .addrsize = sizeof(clp->cl_addr),
415 .timeout = &timeparms,
416 .servername = clp->cl_hostname,
417 .program = &nfs_program,
418 .version = clp->rpc_ops->version,
419 .authflavor = flavor,
420 };
David Howells5006a762006-08-22 20:06:12 -0400421
422 if (!IS_ERR(clp->cl_rpcclient))
423 return 0;
424
425 nfs_init_timeout_values(&timeparms, proto, timeo, retrans);
426 clp->retrans_timeo = timeparms.to_initval;
427 clp->retrans_count = timeparms.to_retries;
428
Chuck Lever41877d22006-08-22 20:06:20 -0400429 clnt = rpc_create(&args);
David Howells5006a762006-08-22 20:06:12 -0400430 if (IS_ERR(clnt)) {
431 dprintk("%s: cannot create RPC client. Error = %ld\n",
432 __FUNCTION__, PTR_ERR(clnt));
433 return PTR_ERR(clnt);
434 }
435
David Howells5006a762006-08-22 20:06:12 -0400436 clp->cl_rpcclient = clnt;
437 return 0;
438}
David Howells54ceac42006-08-22 20:06:13 -0400439
440/*
441 * Version 2 or 3 client destruction
442 */
443static void nfs_destroy_server(struct nfs_server *server)
444{
445 if (!IS_ERR(server->client_acl))
446 rpc_shutdown_client(server->client_acl);
447
448 if (!(server->flags & NFS_MOUNT_NONLM))
449 lockd_down(); /* release rpc.lockd */
450}
451
452/*
453 * Version 2 or 3 lockd setup
454 */
455static int nfs_start_lockd(struct nfs_server *server)
456{
457 int error = 0;
458
459 if (server->nfs_client->cl_nfsversion > 3)
460 goto out;
461 if (server->flags & NFS_MOUNT_NONLM)
462 goto out;
463 error = lockd_up();
464 if (error < 0)
465 server->flags |= NFS_MOUNT_NONLM;
466 else
467 server->destroy = nfs_destroy_server;
468out:
469 return error;
470}
471
472/*
473 * Initialise an NFSv3 ACL client connection
474 */
475#ifdef CONFIG_NFS_V3_ACL
476static void nfs_init_server_aclclient(struct nfs_server *server)
477{
478 if (server->nfs_client->cl_nfsversion != 3)
479 goto out_noacl;
480 if (server->flags & NFS_MOUNT_NOACL)
481 goto out_noacl;
482
483 server->client_acl = rpc_bind_new_program(server->client, &nfsacl_program, 3);
484 if (IS_ERR(server->client_acl))
485 goto out_noacl;
486
487 /* No errors! Assume that Sun nfsacls are supported */
488 server->caps |= NFS_CAP_ACLS;
489 return;
490
491out_noacl:
492 server->caps &= ~NFS_CAP_ACLS;
493}
494#else
495static inline void nfs_init_server_aclclient(struct nfs_server *server)
496{
497 server->flags &= ~NFS_MOUNT_NOACL;
498 server->caps &= ~NFS_CAP_ACLS;
499}
500#endif
501
502/*
503 * Create a general RPC client
504 */
505static int nfs_init_server_rpcclient(struct nfs_server *server, rpc_authflavor_t pseudoflavour)
506{
507 struct nfs_client *clp = server->nfs_client;
508
509 server->client = rpc_clone_client(clp->cl_rpcclient);
510 if (IS_ERR(server->client)) {
511 dprintk("%s: couldn't create rpc_client!\n", __FUNCTION__);
512 return PTR_ERR(server->client);
513 }
514
515 if (pseudoflavour != clp->cl_rpcclient->cl_auth->au_flavor) {
516 struct rpc_auth *auth;
517
518 auth = rpcauth_create(pseudoflavour, server->client);
519 if (IS_ERR(auth)) {
520 dprintk("%s: couldn't create credcache!\n", __FUNCTION__);
521 return PTR_ERR(auth);
522 }
523 }
524 server->client->cl_softrtry = 0;
525 if (server->flags & NFS_MOUNT_SOFT)
526 server->client->cl_softrtry = 1;
527
528 server->client->cl_intr = 0;
529 if (server->flags & NFS4_MOUNT_INTR)
530 server->client->cl_intr = 1;
531
532 return 0;
533}
534
535/*
536 * Initialise an NFS2 or NFS3 client
537 */
538static int nfs_init_client(struct nfs_client *clp, const struct nfs_mount_data *data)
539{
540 int proto = (data->flags & NFS_MOUNT_TCP) ? IPPROTO_TCP : IPPROTO_UDP;
541 int error;
542
543 if (clp->cl_cons_state == NFS_CS_READY) {
544 /* the client is already initialised */
545 dprintk("<-- nfs_init_client() = 0 [already %p]\n", clp);
546 return 0;
547 }
548
549 /* Check NFS protocol revision and initialize RPC op vector */
550 clp->rpc_ops = &nfs_v2_clientops;
551#ifdef CONFIG_NFS_V3
552 if (clp->cl_nfsversion == 3)
553 clp->rpc_ops = &nfs_v3_clientops;
554#endif
555 /*
556 * Create a client RPC handle for doing FSSTAT with UNIX auth only
557 * - RFC 2623, sec 2.3.2
558 */
559 error = nfs_create_rpc_client(clp, proto, data->timeo, data->retrans,
560 RPC_AUTH_UNIX);
561 if (error < 0)
562 goto error;
563 nfs_mark_client_ready(clp, NFS_CS_READY);
564 return 0;
565
566error:
567 nfs_mark_client_ready(clp, error);
568 dprintk("<-- nfs_init_client() = xerror %d\n", error);
569 return error;
570}
571
572/*
573 * Create a version 2 or 3 client
574 */
575static int nfs_init_server(struct nfs_server *server, const struct nfs_mount_data *data)
576{
577 struct nfs_client *clp;
578 int error, nfsvers = 2;
579
580 dprintk("--> nfs_init_server()\n");
581
582#ifdef CONFIG_NFS_V3
583 if (data->flags & NFS_MOUNT_VER3)
584 nfsvers = 3;
585#endif
586
587 /* Allocate or find a client reference we can use */
588 clp = nfs_get_client(data->hostname, &data->addr, nfsvers);
589 if (IS_ERR(clp)) {
590 dprintk("<-- nfs_init_server() = error %ld\n", PTR_ERR(clp));
591 return PTR_ERR(clp);
592 }
593
594 error = nfs_init_client(clp, data);
595 if (error < 0)
596 goto error;
597
598 server->nfs_client = clp;
599
600 /* Initialise the client representation from the mount data */
601 server->flags = data->flags & NFS_MOUNT_FLAGMASK;
602
603 if (data->rsize)
604 server->rsize = nfs_block_size(data->rsize, NULL);
605 if (data->wsize)
606 server->wsize = nfs_block_size(data->wsize, NULL);
607
608 server->acregmin = data->acregmin * HZ;
609 server->acregmax = data->acregmax * HZ;
610 server->acdirmin = data->acdirmin * HZ;
611 server->acdirmax = data->acdirmax * HZ;
612
613 /* Start lockd here, before we might error out */
614 error = nfs_start_lockd(server);
615 if (error < 0)
616 goto error;
617
618 error = nfs_init_server_rpcclient(server, data->pseudoflavor);
619 if (error < 0)
620 goto error;
621
622 server->namelen = data->namlen;
623 /* Create a client RPC handle for the NFSv3 ACL management interface */
624 nfs_init_server_aclclient(server);
625 if (clp->cl_nfsversion == 3) {
626 if (server->namelen == 0 || server->namelen > NFS3_MAXNAMLEN)
627 server->namelen = NFS3_MAXNAMLEN;
628 server->caps |= NFS_CAP_READDIRPLUS;
629 } else {
630 if (server->namelen == 0 || server->namelen > NFS2_MAXNAMLEN)
631 server->namelen = NFS2_MAXNAMLEN;
632 }
633
634 dprintk("<-- nfs_init_server() = 0 [new %p]\n", clp);
635 return 0;
636
637error:
638 server->nfs_client = NULL;
639 nfs_put_client(clp);
640 dprintk("<-- nfs_init_server() = xerror %d\n", error);
641 return error;
642}
643
644/*
645 * Load up the server record from information gained in an fsinfo record
646 */
647static void nfs_server_set_fsinfo(struct nfs_server *server, struct nfs_fsinfo *fsinfo)
648{
649 unsigned long max_rpc_payload;
650
651 /* Work out a lot of parameters */
652 if (server->rsize == 0)
653 server->rsize = nfs_block_size(fsinfo->rtpref, NULL);
654 if (server->wsize == 0)
655 server->wsize = nfs_block_size(fsinfo->wtpref, NULL);
656
657 if (fsinfo->rtmax >= 512 && server->rsize > fsinfo->rtmax)
658 server->rsize = nfs_block_size(fsinfo->rtmax, NULL);
659 if (fsinfo->wtmax >= 512 && server->wsize > fsinfo->wtmax)
660 server->wsize = nfs_block_size(fsinfo->wtmax, NULL);
661
662 max_rpc_payload = nfs_block_size(rpc_max_payload(server->client), NULL);
663 if (server->rsize > max_rpc_payload)
664 server->rsize = max_rpc_payload;
665 if (server->rsize > NFS_MAX_FILE_IO_SIZE)
666 server->rsize = NFS_MAX_FILE_IO_SIZE;
667 server->rpages = (server->rsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
668 server->backing_dev_info.ra_pages = server->rpages * NFS_MAX_READAHEAD;
669
670 if (server->wsize > max_rpc_payload)
671 server->wsize = max_rpc_payload;
672 if (server->wsize > NFS_MAX_FILE_IO_SIZE)
673 server->wsize = NFS_MAX_FILE_IO_SIZE;
674 server->wpages = (server->wsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
675 server->wtmult = nfs_block_bits(fsinfo->wtmult, NULL);
676
677 server->dtsize = nfs_block_size(fsinfo->dtpref, NULL);
678 if (server->dtsize > PAGE_CACHE_SIZE)
679 server->dtsize = PAGE_CACHE_SIZE;
680 if (server->dtsize > server->rsize)
681 server->dtsize = server->rsize;
682
683 if (server->flags & NFS_MOUNT_NOAC) {
684 server->acregmin = server->acregmax = 0;
685 server->acdirmin = server->acdirmax = 0;
686 }
687
688 server->maxfilesize = fsinfo->maxfilesize;
689
690 /* We're airborne Set socket buffersize */
691 rpc_setbufsize(server->client, server->wsize + 100, server->rsize + 100);
692}
693
694/*
695 * Probe filesystem information, including the FSID on v2/v3
696 */
697static int nfs_probe_fsinfo(struct nfs_server *server, struct nfs_fh *mntfh, struct nfs_fattr *fattr)
698{
699 struct nfs_fsinfo fsinfo;
700 struct nfs_client *clp = server->nfs_client;
701 int error;
702
703 dprintk("--> nfs_probe_fsinfo()\n");
704
705 if (clp->rpc_ops->set_capabilities != NULL) {
706 error = clp->rpc_ops->set_capabilities(server, mntfh);
707 if (error < 0)
708 goto out_error;
709 }
710
711 fsinfo.fattr = fattr;
712 nfs_fattr_init(fattr);
713 error = clp->rpc_ops->fsinfo(server, mntfh, &fsinfo);
714 if (error < 0)
715 goto out_error;
716
717 nfs_server_set_fsinfo(server, &fsinfo);
718
719 /* Get some general file system info */
720 if (server->namelen == 0) {
721 struct nfs_pathconf pathinfo;
722
723 pathinfo.fattr = fattr;
724 nfs_fattr_init(fattr);
725
726 if (clp->rpc_ops->pathconf(server, mntfh, &pathinfo) >= 0)
727 server->namelen = pathinfo.max_namelen;
728 }
729
730 dprintk("<-- nfs_probe_fsinfo() = 0\n");
731 return 0;
732
733out_error:
734 dprintk("nfs_probe_fsinfo: error = %d\n", -error);
735 return error;
736}
737
738/*
739 * Copy useful information when duplicating a server record
740 */
741static void nfs_server_copy_userdata(struct nfs_server *target, struct nfs_server *source)
742{
743 target->flags = source->flags;
744 target->acregmin = source->acregmin;
745 target->acregmax = source->acregmax;
746 target->acdirmin = source->acdirmin;
747 target->acdirmax = source->acdirmax;
748 target->caps = source->caps;
749}
750
751/*
752 * Allocate and initialise a server record
753 */
754static struct nfs_server *nfs_alloc_server(void)
755{
756 struct nfs_server *server;
757
758 server = kzalloc(sizeof(struct nfs_server), GFP_KERNEL);
759 if (!server)
760 return NULL;
761
762 server->client = server->client_acl = ERR_PTR(-EINVAL);
763
764 /* Zero out the NFS state stuff */
765 INIT_LIST_HEAD(&server->client_link);
766 INIT_LIST_HEAD(&server->master_link);
767
768 server->io_stats = nfs_alloc_iostats();
769 if (!server->io_stats) {
770 kfree(server);
771 return NULL;
772 }
773
774 return server;
775}
776
777/*
778 * Free up a server record
779 */
780void nfs_free_server(struct nfs_server *server)
781{
782 dprintk("--> nfs_free_server()\n");
783
784 spin_lock(&nfs_client_lock);
785 list_del(&server->client_link);
786 list_del(&server->master_link);
787 spin_unlock(&nfs_client_lock);
788
789 if (server->destroy != NULL)
790 server->destroy(server);
791 if (!IS_ERR(server->client))
792 rpc_shutdown_client(server->client);
793
794 nfs_put_client(server->nfs_client);
795
796 nfs_free_iostats(server->io_stats);
797 kfree(server);
798 nfs_release_automount_timer();
799 dprintk("<-- nfs_free_server()\n");
800}
801
802/*
803 * Create a version 2 or 3 volume record
804 * - keyed on server and FSID
805 */
806struct nfs_server *nfs_create_server(const struct nfs_mount_data *data,
807 struct nfs_fh *mntfh)
808{
809 struct nfs_server *server;
810 struct nfs_fattr fattr;
811 int error;
812
813 server = nfs_alloc_server();
814 if (!server)
815 return ERR_PTR(-ENOMEM);
816
817 /* Get a client representation */
818 error = nfs_init_server(server, data);
819 if (error < 0)
820 goto error;
821
822 BUG_ON(!server->nfs_client);
823 BUG_ON(!server->nfs_client->rpc_ops);
824 BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops);
825
826 /* Probe the root fh to retrieve its FSID */
827 error = nfs_probe_fsinfo(server, mntfh, &fattr);
828 if (error < 0)
829 goto error;
830 if (!(fattr.valid & NFS_ATTR_FATTR)) {
831 error = server->nfs_client->rpc_ops->getattr(server, mntfh, &fattr);
832 if (error < 0) {
833 dprintk("nfs_create_server: getattr error = %d\n", -error);
834 goto error;
835 }
836 }
837 memcpy(&server->fsid, &fattr.fsid, sizeof(server->fsid));
838
David Howells6daabf12006-08-24 15:44:16 -0400839 dprintk("Server FSID: %llx:%llx\n",
840 (unsigned long long) server->fsid.major,
841 (unsigned long long) server->fsid.minor);
David Howells54ceac42006-08-22 20:06:13 -0400842
843 BUG_ON(!server->nfs_client);
844 BUG_ON(!server->nfs_client->rpc_ops);
845 BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops);
846
847 spin_lock(&nfs_client_lock);
848 list_add_tail(&server->client_link, &server->nfs_client->cl_superblocks);
849 list_add_tail(&server->master_link, &nfs_volume_list);
850 spin_unlock(&nfs_client_lock);
851
852 server->mount_time = jiffies;
853 return server;
854
855error:
856 nfs_free_server(server);
857 return ERR_PTR(error);
858}
859
860#ifdef CONFIG_NFS_V4
861/*
862 * Initialise an NFS4 client record
863 */
864static int nfs4_init_client(struct nfs_client *clp,
865 int proto, int timeo, int retrans,
866 rpc_authflavor_t authflavour)
867{
868 int error;
869
870 if (clp->cl_cons_state == NFS_CS_READY) {
871 /* the client is initialised already */
872 dprintk("<-- nfs4_init_client() = 0 [already %p]\n", clp);
873 return 0;
874 }
875
876 /* Check NFS protocol revision and initialize RPC op vector */
877 clp->rpc_ops = &nfs_v4_clientops;
878
879 error = nfs_create_rpc_client(clp, proto, timeo, retrans, authflavour);
880 if (error < 0)
881 goto error;
882
883 error = nfs_idmap_new(clp);
884 if (error < 0) {
885 dprintk("%s: failed to create idmapper. Error = %d\n",
886 __FUNCTION__, error);
David Howells54ceac42006-08-22 20:06:13 -0400887 goto error;
888 }
Trond Myklebust9c5bf382006-08-22 20:06:14 -0400889 __set_bit(NFS_CS_IDMAP, &clp->cl_res_state);
David Howells54ceac42006-08-22 20:06:13 -0400890
891 nfs_mark_client_ready(clp, NFS_CS_READY);
892 return 0;
893
894error:
895 nfs_mark_client_ready(clp, error);
896 dprintk("<-- nfs4_init_client() = xerror %d\n", error);
897 return error;
898}
899
900/*
901 * Set up an NFS4 client
902 */
903static int nfs4_set_client(struct nfs_server *server,
904 const char *hostname, const struct sockaddr_in *addr,
905 rpc_authflavor_t authflavour,
906 int proto, int timeo, int retrans)
907{
908 struct nfs_client *clp;
909 int error;
910
911 dprintk("--> nfs4_set_client()\n");
912
913 /* Allocate or find a client reference we can use */
914 clp = nfs_get_client(hostname, addr, 4);
915 if (IS_ERR(clp)) {
916 error = PTR_ERR(clp);
917 goto error;
918 }
919 error = nfs4_init_client(clp, proto, timeo, retrans, authflavour);
920 if (error < 0)
921 goto error_put;
922
923 server->nfs_client = clp;
924 dprintk("<-- nfs4_set_client() = 0 [new %p]\n", clp);
925 return 0;
926
927error_put:
928 nfs_put_client(clp);
929error:
930 dprintk("<-- nfs4_set_client() = xerror %d\n", error);
931 return error;
932}
933
934/*
935 * Create a version 4 volume record
936 */
937static int nfs4_init_server(struct nfs_server *server,
938 const struct nfs4_mount_data *data, rpc_authflavor_t authflavour)
939{
940 int error;
941
942 dprintk("--> nfs4_init_server()\n");
943
944 /* Initialise the client representation from the mount data */
945 server->flags = data->flags & NFS_MOUNT_FLAGMASK;
946 server->caps |= NFS_CAP_ATOMIC_OPEN;
947
948 if (data->rsize)
949 server->rsize = nfs_block_size(data->rsize, NULL);
950 if (data->wsize)
951 server->wsize = nfs_block_size(data->wsize, NULL);
952
953 server->acregmin = data->acregmin * HZ;
954 server->acregmax = data->acregmax * HZ;
955 server->acdirmin = data->acdirmin * HZ;
956 server->acdirmax = data->acdirmax * HZ;
957
958 error = nfs_init_server_rpcclient(server, authflavour);
959
960 /* Done */
961 dprintk("<-- nfs4_init_server() = %d\n", error);
962 return error;
963}
964
965/*
966 * Create a version 4 volume record
967 * - keyed on server and FSID
968 */
969struct nfs_server *nfs4_create_server(const struct nfs4_mount_data *data,
970 const char *hostname,
971 const struct sockaddr_in *addr,
972 const char *mntpath,
973 const char *ip_addr,
974 rpc_authflavor_t authflavour,
975 struct nfs_fh *mntfh)
976{
977 struct nfs_fattr fattr;
978 struct nfs_server *server;
979 int error;
980
981 dprintk("--> nfs4_create_server()\n");
982
983 server = nfs_alloc_server();
984 if (!server)
985 return ERR_PTR(-ENOMEM);
986
987 /* Get a client record */
988 error = nfs4_set_client(server, hostname, addr, authflavour,
989 data->proto, data->timeo, data->retrans);
990 if (error < 0)
991 goto error;
992
993 /* set up the general RPC client */
994 error = nfs4_init_server(server, data, authflavour);
995 if (error < 0)
996 goto error;
997
998 BUG_ON(!server->nfs_client);
999 BUG_ON(!server->nfs_client->rpc_ops);
1000 BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops);
1001
1002 /* Probe the root fh to retrieve its FSID */
1003 error = nfs4_path_walk(server, mntfh, mntpath);
1004 if (error < 0)
1005 goto error;
1006
David Howells6daabf12006-08-24 15:44:16 -04001007 dprintk("Server FSID: %llx:%llx\n",
1008 (unsigned long long) server->fsid.major,
1009 (unsigned long long) server->fsid.minor);
David Howells54ceac42006-08-22 20:06:13 -04001010 dprintk("Mount FH: %d\n", mntfh->size);
1011
1012 error = nfs_probe_fsinfo(server, mntfh, &fattr);
1013 if (error < 0)
1014 goto error;
1015
1016 BUG_ON(!server->nfs_client);
1017 BUG_ON(!server->nfs_client->rpc_ops);
1018 BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops);
1019
1020 spin_lock(&nfs_client_lock);
1021 list_add_tail(&server->client_link, &server->nfs_client->cl_superblocks);
1022 list_add_tail(&server->master_link, &nfs_volume_list);
1023 spin_unlock(&nfs_client_lock);
1024
1025 server->mount_time = jiffies;
1026 dprintk("<-- nfs4_create_server() = %p\n", server);
1027 return server;
1028
1029error:
1030 nfs_free_server(server);
1031 dprintk("<-- nfs4_create_server() = error %d\n", error);
1032 return ERR_PTR(error);
1033}
1034
1035/*
1036 * Create an NFS4 referral server record
1037 */
1038struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *data,
1039 struct nfs_fh *fh)
1040{
1041 struct nfs_client *parent_client;
1042 struct nfs_server *server, *parent_server;
1043 struct nfs_fattr fattr;
1044 int error;
1045
1046 dprintk("--> nfs4_create_referral_server()\n");
1047
1048 server = nfs_alloc_server();
1049 if (!server)
1050 return ERR_PTR(-ENOMEM);
1051
1052 parent_server = NFS_SB(data->sb);
1053 parent_client = parent_server->nfs_client;
1054
1055 /* Get a client representation.
1056 * Note: NFSv4 always uses TCP, */
1057 error = nfs4_set_client(server, data->hostname, data->addr,
1058 data->authflavor,
1059 parent_server->client->cl_xprt->prot,
1060 parent_client->retrans_timeo,
1061 parent_client->retrans_count);
andros@citi.umich.edu297de4f2006-08-29 12:19:41 -04001062 if (error < 0)
1063 goto error;
David Howells54ceac42006-08-22 20:06:13 -04001064
1065 /* Initialise the client representation from the parent server */
1066 nfs_server_copy_userdata(server, parent_server);
1067 server->caps |= NFS_CAP_ATOMIC_OPEN;
1068
1069 error = nfs_init_server_rpcclient(server, data->authflavor);
1070 if (error < 0)
1071 goto error;
1072
1073 BUG_ON(!server->nfs_client);
1074 BUG_ON(!server->nfs_client->rpc_ops);
1075 BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops);
1076
1077 /* probe the filesystem info for this server filesystem */
1078 error = nfs_probe_fsinfo(server, fh, &fattr);
1079 if (error < 0)
1080 goto error;
1081
1082 dprintk("Referral FSID: %llx:%llx\n",
David Howells6daabf12006-08-24 15:44:16 -04001083 (unsigned long long) server->fsid.major,
1084 (unsigned long long) server->fsid.minor);
David Howells54ceac42006-08-22 20:06:13 -04001085
1086 spin_lock(&nfs_client_lock);
1087 list_add_tail(&server->client_link, &server->nfs_client->cl_superblocks);
1088 list_add_tail(&server->master_link, &nfs_volume_list);
1089 spin_unlock(&nfs_client_lock);
1090
1091 server->mount_time = jiffies;
1092
1093 dprintk("<-- nfs_create_referral_server() = %p\n", server);
1094 return server;
1095
1096error:
1097 nfs_free_server(server);
1098 dprintk("<-- nfs4_create_referral_server() = error %d\n", error);
1099 return ERR_PTR(error);
1100}
1101
1102#endif /* CONFIG_NFS_V4 */
1103
1104/*
1105 * Clone an NFS2, NFS3 or NFS4 server record
1106 */
1107struct nfs_server *nfs_clone_server(struct nfs_server *source,
1108 struct nfs_fh *fh,
1109 struct nfs_fattr *fattr)
1110{
1111 struct nfs_server *server;
1112 struct nfs_fattr fattr_fsinfo;
1113 int error;
1114
1115 dprintk("--> nfs_clone_server(,%llx:%llx,)\n",
David Howells6daabf12006-08-24 15:44:16 -04001116 (unsigned long long) fattr->fsid.major,
1117 (unsigned long long) fattr->fsid.minor);
David Howells54ceac42006-08-22 20:06:13 -04001118
1119 server = nfs_alloc_server();
1120 if (!server)
1121 return ERR_PTR(-ENOMEM);
1122
1123 /* Copy data from the source */
1124 server->nfs_client = source->nfs_client;
1125 atomic_inc(&server->nfs_client->cl_count);
1126 nfs_server_copy_userdata(server, source);
1127
1128 server->fsid = fattr->fsid;
1129
1130 error = nfs_init_server_rpcclient(server, source->client->cl_auth->au_flavor);
1131 if (error < 0)
1132 goto out_free_server;
1133 if (!IS_ERR(source->client_acl))
1134 nfs_init_server_aclclient(server);
1135
1136 /* probe the filesystem info for this server filesystem */
1137 error = nfs_probe_fsinfo(server, fh, &fattr_fsinfo);
1138 if (error < 0)
1139 goto out_free_server;
1140
1141 dprintk("Cloned FSID: %llx:%llx\n",
David Howells6daabf12006-08-24 15:44:16 -04001142 (unsigned long long) server->fsid.major,
1143 (unsigned long long) server->fsid.minor);
David Howells54ceac42006-08-22 20:06:13 -04001144
1145 error = nfs_start_lockd(server);
1146 if (error < 0)
1147 goto out_free_server;
1148
1149 spin_lock(&nfs_client_lock);
1150 list_add_tail(&server->client_link, &server->nfs_client->cl_superblocks);
1151 list_add_tail(&server->master_link, &nfs_volume_list);
1152 spin_unlock(&nfs_client_lock);
1153
1154 server->mount_time = jiffies;
1155
1156 dprintk("<-- nfs_clone_server() = %p\n", server);
1157 return server;
1158
1159out_free_server:
1160 nfs_free_server(server);
1161 dprintk("<-- nfs_clone_server() = error %d\n", error);
1162 return ERR_PTR(error);
1163}
David Howells6aaca562006-08-22 20:06:13 -04001164
1165#ifdef CONFIG_PROC_FS
1166static struct proc_dir_entry *proc_fs_nfs;
1167
1168static int nfs_server_list_open(struct inode *inode, struct file *file);
1169static void *nfs_server_list_start(struct seq_file *p, loff_t *pos);
1170static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos);
1171static void nfs_server_list_stop(struct seq_file *p, void *v);
1172static int nfs_server_list_show(struct seq_file *m, void *v);
1173
1174static struct seq_operations nfs_server_list_ops = {
1175 .start = nfs_server_list_start,
1176 .next = nfs_server_list_next,
1177 .stop = nfs_server_list_stop,
1178 .show = nfs_server_list_show,
1179};
1180
1181static struct file_operations nfs_server_list_fops = {
1182 .open = nfs_server_list_open,
1183 .read = seq_read,
1184 .llseek = seq_lseek,
1185 .release = seq_release,
1186};
1187
1188static int nfs_volume_list_open(struct inode *inode, struct file *file);
1189static void *nfs_volume_list_start(struct seq_file *p, loff_t *pos);
1190static void *nfs_volume_list_next(struct seq_file *p, void *v, loff_t *pos);
1191static void nfs_volume_list_stop(struct seq_file *p, void *v);
1192static int nfs_volume_list_show(struct seq_file *m, void *v);
1193
1194static struct seq_operations nfs_volume_list_ops = {
1195 .start = nfs_volume_list_start,
1196 .next = nfs_volume_list_next,
1197 .stop = nfs_volume_list_stop,
1198 .show = nfs_volume_list_show,
1199};
1200
1201static struct file_operations nfs_volume_list_fops = {
1202 .open = nfs_volume_list_open,
1203 .read = seq_read,
1204 .llseek = seq_lseek,
1205 .release = seq_release,
1206};
1207
1208/*
1209 * open "/proc/fs/nfsfs/servers" which provides a summary of servers with which
1210 * we're dealing
1211 */
1212static int nfs_server_list_open(struct inode *inode, struct file *file)
1213{
1214 struct seq_file *m;
1215 int ret;
1216
1217 ret = seq_open(file, &nfs_server_list_ops);
1218 if (ret < 0)
1219 return ret;
1220
1221 m = file->private_data;
1222 m->private = PDE(inode)->data;
1223
1224 return 0;
1225}
1226
1227/*
1228 * set up the iterator to start reading from the server list and return the first item
1229 */
1230static void *nfs_server_list_start(struct seq_file *m, loff_t *_pos)
1231{
1232 struct list_head *_p;
1233 loff_t pos = *_pos;
1234
1235 /* lock the list against modification */
1236 spin_lock(&nfs_client_lock);
1237
1238 /* allow for the header line */
1239 if (!pos)
1240 return SEQ_START_TOKEN;
1241 pos--;
1242
1243 /* find the n'th element in the list */
1244 list_for_each(_p, &nfs_client_list)
1245 if (!pos--)
1246 break;
1247
1248 return _p != &nfs_client_list ? _p : NULL;
1249}
1250
1251/*
1252 * move to next server
1253 */
1254static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos)
1255{
1256 struct list_head *_p;
1257
1258 (*pos)++;
1259
1260 _p = v;
1261 _p = (v == SEQ_START_TOKEN) ? nfs_client_list.next : _p->next;
1262
1263 return _p != &nfs_client_list ? _p : NULL;
1264}
1265
1266/*
1267 * clean up after reading from the transports list
1268 */
1269static void nfs_server_list_stop(struct seq_file *p, void *v)
1270{
1271 spin_unlock(&nfs_client_lock);
1272}
1273
1274/*
1275 * display a header line followed by a load of call lines
1276 */
1277static int nfs_server_list_show(struct seq_file *m, void *v)
1278{
1279 struct nfs_client *clp;
1280
1281 /* display header on line 1 */
1282 if (v == SEQ_START_TOKEN) {
1283 seq_puts(m, "NV SERVER PORT USE HOSTNAME\n");
1284 return 0;
1285 }
1286
1287 /* display one transport per line on subsequent lines */
1288 clp = list_entry(v, struct nfs_client, cl_share_link);
1289
1290 seq_printf(m, "v%d %02x%02x%02x%02x %4hx %3d %s\n",
1291 clp->cl_nfsversion,
1292 NIPQUAD(clp->cl_addr.sin_addr),
1293 ntohs(clp->cl_addr.sin_port),
1294 atomic_read(&clp->cl_count),
1295 clp->cl_hostname);
1296
1297 return 0;
1298}
1299
1300/*
1301 * open "/proc/fs/nfsfs/volumes" which provides a summary of extant volumes
1302 */
1303static int nfs_volume_list_open(struct inode *inode, struct file *file)
1304{
1305 struct seq_file *m;
1306 int ret;
1307
1308 ret = seq_open(file, &nfs_volume_list_ops);
1309 if (ret < 0)
1310 return ret;
1311
1312 m = file->private_data;
1313 m->private = PDE(inode)->data;
1314
1315 return 0;
1316}
1317
1318/*
1319 * set up the iterator to start reading from the volume list and return the first item
1320 */
1321static void *nfs_volume_list_start(struct seq_file *m, loff_t *_pos)
1322{
1323 struct list_head *_p;
1324 loff_t pos = *_pos;
1325
1326 /* lock the list against modification */
1327 spin_lock(&nfs_client_lock);
1328
1329 /* allow for the header line */
1330 if (!pos)
1331 return SEQ_START_TOKEN;
1332 pos--;
1333
1334 /* find the n'th element in the list */
1335 list_for_each(_p, &nfs_volume_list)
1336 if (!pos--)
1337 break;
1338
1339 return _p != &nfs_volume_list ? _p : NULL;
1340}
1341
1342/*
1343 * move to next volume
1344 */
1345static void *nfs_volume_list_next(struct seq_file *p, void *v, loff_t *pos)
1346{
1347 struct list_head *_p;
1348
1349 (*pos)++;
1350
1351 _p = v;
1352 _p = (v == SEQ_START_TOKEN) ? nfs_volume_list.next : _p->next;
1353
1354 return _p != &nfs_volume_list ? _p : NULL;
1355}
1356
1357/*
1358 * clean up after reading from the transports list
1359 */
1360static void nfs_volume_list_stop(struct seq_file *p, void *v)
1361{
1362 spin_unlock(&nfs_client_lock);
1363}
1364
1365/*
1366 * display a header line followed by a load of call lines
1367 */
1368static int nfs_volume_list_show(struct seq_file *m, void *v)
1369{
1370 struct nfs_server *server;
1371 struct nfs_client *clp;
1372 char dev[8], fsid[17];
1373
1374 /* display header on line 1 */
1375 if (v == SEQ_START_TOKEN) {
1376 seq_puts(m, "NV SERVER PORT DEV FSID\n");
1377 return 0;
1378 }
1379 /* display one transport per line on subsequent lines */
1380 server = list_entry(v, struct nfs_server, master_link);
1381 clp = server->nfs_client;
1382
1383 snprintf(dev, 8, "%u:%u",
1384 MAJOR(server->s_dev), MINOR(server->s_dev));
1385
1386 snprintf(fsid, 17, "%llx:%llx",
David Howells6daabf12006-08-24 15:44:16 -04001387 (unsigned long long) server->fsid.major,
1388 (unsigned long long) server->fsid.minor);
David Howells6aaca562006-08-22 20:06:13 -04001389
1390 seq_printf(m, "v%d %02x%02x%02x%02x %4hx %-7s %-17s\n",
1391 clp->cl_nfsversion,
1392 NIPQUAD(clp->cl_addr.sin_addr),
1393 ntohs(clp->cl_addr.sin_port),
1394 dev,
1395 fsid);
1396
1397 return 0;
1398}
1399
1400/*
1401 * initialise the /proc/fs/nfsfs/ directory
1402 */
1403int __init nfs_fs_proc_init(void)
1404{
1405 struct proc_dir_entry *p;
1406
1407 proc_fs_nfs = proc_mkdir("nfsfs", proc_root_fs);
1408 if (!proc_fs_nfs)
1409 goto error_0;
1410
1411 proc_fs_nfs->owner = THIS_MODULE;
1412
1413 /* a file of servers with which we're dealing */
1414 p = create_proc_entry("servers", S_IFREG|S_IRUGO, proc_fs_nfs);
1415 if (!p)
1416 goto error_1;
1417
1418 p->proc_fops = &nfs_server_list_fops;
1419 p->owner = THIS_MODULE;
1420
1421 /* a file of volumes that we have mounted */
1422 p = create_proc_entry("volumes", S_IFREG|S_IRUGO, proc_fs_nfs);
1423 if (!p)
1424 goto error_2;
1425
1426 p->proc_fops = &nfs_volume_list_fops;
1427 p->owner = THIS_MODULE;
1428 return 0;
1429
1430error_2:
1431 remove_proc_entry("servers", proc_fs_nfs);
1432error_1:
1433 remove_proc_entry("nfsfs", proc_root_fs);
1434error_0:
1435 return -ENOMEM;
1436}
1437
1438/*
1439 * clean up the /proc/fs/nfsfs/ directory
1440 */
1441void nfs_fs_proc_exit(void)
1442{
1443 remove_proc_entry("volumes", proc_fs_nfs);
1444 remove_proc_entry("servers", proc_fs_nfs);
1445 remove_proc_entry("nfsfs", proc_root_fs);
1446}
1447
1448#endif /* CONFIG_PROC_FS */