super.c 72 KB
Newer Older
David Howells's avatar
David Howells committed
1
2
3
4
5
6
7
/*
 *  linux/fs/nfs/super.c
 *
 *  Copyright (C) 1992  Rick Sladkey
 *
 *  nfs superblock handling functions
 *
8
 *  Modularised by Alan Cox <alan@lxorguk.ukuu.org.uk>, while hacking some
David Howells's avatar
David Howells committed
9
10
11
12
13
14
15
 *  experimental NFS changes. Modularisation taken straight from SYS5 fs.
 *
 *  Change to nfs_read_super() to permit NFS mounts to multi-homed hosts.
 *  J.S.Peatfield@damtp.cam.ac.uk
 *
 *  Split from inode.c by David Howells <dhowells@redhat.com>
 *
16
17
18
19
20
 * - superblocks are indexed on server only - all inodes, dentries, etc. associated with a
 *   particular server are held in the same superblock
 * - NFS superblocks can have several effective roots to the dentry tree
 * - directory type roots are spliced into the tree when a path from one root reaches the root
 *   of another (see nfs_lookup())
David Howells's avatar
David Howells committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
 */

#include <linux/module.h>
#include <linux/init.h>

#include <linux/time.h>
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/string.h>
#include <linux/stat.h>
#include <linux/errno.h>
#include <linux/unistd.h>
#include <linux/sunrpc/clnt.h>
#include <linux/sunrpc/stats.h>
#include <linux/sunrpc/metrics.h>
36
#include <linux/sunrpc/xprtsock.h>
\"Talpey, Thomas\'s avatar
\"Talpey, Thomas\ committed
37
#include <linux/sunrpc/xprtrdma.h>
David Howells's avatar
David Howells committed
38
39
40
41
42
43
44
#include <linux/nfs_fs.h>
#include <linux/nfs_mount.h>
#include <linux/nfs4_mount.h>
#include <linux/lockd/bind.h>
#include <linux/smp_lock.h>
#include <linux/seq_file.h>
#include <linux/mount.h>
45
46
#include <linux/mnt_namespace.h>
#include <linux/namei.h>
David Howells's avatar
David Howells committed
47
48
49
#include <linux/nfs_idmap.h>
#include <linux/vfs.h>
#include <linux/inet.h>
50
51
#include <linux/in6.h>
#include <net/ipv6.h>
52
#include <linux/netdevice.h>
David Howells's avatar
David Howells committed
53
#include <linux/nfs_xdr.h>
54
#include <linux/magic.h>
55
#include <linux/parser.h>
David Howells's avatar
David Howells committed
56
57
58
59
60
61
62
63
64

#include <asm/system.h>
#include <asm/uaccess.h>

#include "nfs4_fs.h"
#include "callback.h"
#include "delegation.h"
#include "iostat.h"
#include "internal.h"
65
#include "fscache.h"
David Howells's avatar
David Howells committed
66
67
68

#define NFSDBG_FACILITY		NFSDBG_VFS

69
70
71
72
73
74
75
enum {
	/* Mount options that take no arguments */
	Opt_soft, Opt_hard,
	Opt_posix, Opt_noposix,
	Opt_cto, Opt_nocto,
	Opt_ac, Opt_noac,
	Opt_lock, Opt_nolock,
76
	Opt_v2, Opt_v3, Opt_v4,
\"Talpey, Thomas\'s avatar
\"Talpey, Thomas\ committed
77
	Opt_udp, Opt_tcp, Opt_rdma,
78
79
	Opt_acl, Opt_noacl,
	Opt_rdirplus, Opt_nordirplus,
80
	Opt_sharecache, Opt_nosharecache,
81
	Opt_resvport, Opt_noresvport,
82
	Opt_fscache, Opt_nofscache,
83
84
85
86
87
88
89
90
91
92

	/* Mount options that take integer arguments */
	Opt_port,
	Opt_rsize, Opt_wsize, Opt_bsize,
	Opt_timeo, Opt_retrans,
	Opt_acregmin, Opt_acregmax,
	Opt_acdirmin, Opt_acdirmax,
	Opt_actimeo,
	Opt_namelen,
	Opt_mountport,
93
	Opt_mountvers,
94
	Opt_nfsvers,
95
	Opt_minorversion,
96
97

	/* Mount options that take string arguments */
98
	Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
99
	Opt_addr, Opt_mountaddr, Opt_clientaddr,
100
	Opt_lookupcache,
101
	Opt_fscache_uniq,
102

103
104
	/* Special mount options */
	Opt_userspace, Opt_deprecated, Opt_sloppy,
105
106
107
108

	Opt_err
};

109
static const match_table_t nfs_mount_option_tokens = {
110
111
	{ Opt_userspace, "bg" },
	{ Opt_userspace, "fg" },
112
113
	{ Opt_userspace, "retry=%s" },

114
115
	{ Opt_sloppy, "sloppy" },

116
117
	{ Opt_soft, "soft" },
	{ Opt_hard, "hard" },
118
119
	{ Opt_deprecated, "intr" },
	{ Opt_deprecated, "nointr" },
120
121
122
123
124
125
126
127
128
129
	{ Opt_posix, "posix" },
	{ Opt_noposix, "noposix" },
	{ Opt_cto, "cto" },
	{ Opt_nocto, "nocto" },
	{ Opt_ac, "ac" },
	{ Opt_noac, "noac" },
	{ Opt_lock, "lock" },
	{ Opt_nolock, "nolock" },
	{ Opt_v2, "v2" },
	{ Opt_v3, "v3" },
130
	{ Opt_v4, "v4" },
131
132
	{ Opt_udp, "udp" },
	{ Opt_tcp, "tcp" },
\"Talpey, Thomas\'s avatar
\"Talpey, Thomas\ committed
133
	{ Opt_rdma, "rdma" },
134
135
136
137
	{ Opt_acl, "acl" },
	{ Opt_noacl, "noacl" },
	{ Opt_rdirplus, "rdirplus" },
	{ Opt_nordirplus, "nordirplus" },
138
139
	{ Opt_sharecache, "sharecache" },
	{ Opt_nosharecache, "nosharecache" },
140
141
	{ Opt_resvport, "resvport" },
	{ Opt_noresvport, "noresvport" },
142
143
144
	{ Opt_fscache, "fsc" },
	{ Opt_fscache_uniq, "fsc=%s" },
	{ Opt_nofscache, "nofsc" },
145

146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
	{ Opt_port, "port=%s" },
	{ Opt_rsize, "rsize=%s" },
	{ Opt_wsize, "wsize=%s" },
	{ Opt_bsize, "bsize=%s" },
	{ Opt_timeo, "timeo=%s" },
	{ Opt_retrans, "retrans=%s" },
	{ Opt_acregmin, "acregmin=%s" },
	{ Opt_acregmax, "acregmax=%s" },
	{ Opt_acdirmin, "acdirmin=%s" },
	{ Opt_acdirmax, "acdirmax=%s" },
	{ Opt_actimeo, "actimeo=%s" },
	{ Opt_namelen, "namlen=%s" },
	{ Opt_mountport, "mountport=%s" },
	{ Opt_mountvers, "mountvers=%s" },
	{ Opt_nfsvers, "nfsvers=%s" },
	{ Opt_nfsvers, "vers=%s" },
162
	{ Opt_minorversion, "minorversion=%s" },
163
164
165
166
167
168

	{ Opt_sec, "sec=%s" },
	{ Opt_proto, "proto=%s" },
	{ Opt_mountproto, "mountproto=%s" },
	{ Opt_addr, "addr=%s" },
	{ Opt_clientaddr, "clientaddr=%s" },
169
	{ Opt_mounthost, "mounthost=%s" },
170
	{ Opt_mountaddr, "mountaddr=%s" },
171

172
173
	{ Opt_lookupcache, "lookupcache=%s" },

174
175
176
177
	{ Opt_err, NULL }
};

enum {
\"Talpey, Thomas\'s avatar
\"Talpey, Thomas\ committed
178
	Opt_xprt_udp, Opt_xprt_tcp, Opt_xprt_rdma,
179
180
181
182

	Opt_xprt_err
};

183
static const match_table_t nfs_xprt_protocol_tokens = {
184
185
	{ Opt_xprt_udp, "udp" },
	{ Opt_xprt_tcp, "tcp" },
\"Talpey, Thomas\'s avatar
\"Talpey, Thomas\ committed
186
	{ Opt_xprt_rdma, "rdma" },
187
188
189
190
191
192
193
194
195
196
197
198
199

	{ Opt_xprt_err, NULL }
};

enum {
	Opt_sec_none, Opt_sec_sys,
	Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
	Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
	Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,

	Opt_sec_err
};

200
static const match_table_t nfs_secflavor_tokens = {
201
202
203
204
205
206
207
208
209
210
211
212
	{ Opt_sec_none, "none" },
	{ Opt_sec_none, "null" },
	{ Opt_sec_sys, "sys" },

	{ Opt_sec_krb5, "krb5" },
	{ Opt_sec_krb5i, "krb5i" },
	{ Opt_sec_krb5p, "krb5p" },

	{ Opt_sec_lkey, "lkey" },
	{ Opt_sec_lkeyi, "lkeyi" },
	{ Opt_sec_lkeyp, "lkeyp" },

213
214
215
216
	{ Opt_sec_spkm, "spkm3" },
	{ Opt_sec_spkmi, "spkm3i" },
	{ Opt_sec_spkmp, "spkm3p" },

217
218
219
	{ Opt_sec_err, NULL }
};

220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
enum {
	Opt_lookupcache_all, Opt_lookupcache_positive,
	Opt_lookupcache_none,

	Opt_lookupcache_err
};

static match_table_t nfs_lookupcache_tokens = {
	{ Opt_lookupcache_all, "all" },
	{ Opt_lookupcache_positive, "pos" },
	{ Opt_lookupcache_positive, "positive" },
	{ Opt_lookupcache_none, "none" },

	{ Opt_lookupcache_err, NULL }
};

236

237
static void nfs_umount_begin(struct super_block *);
238
static int  nfs_statfs(struct dentry *, struct kstatfs *);
David Howells's avatar
David Howells committed
239
240
static int  nfs_show_options(struct seq_file *, struct vfsmount *);
static int  nfs_show_stats(struct seq_file *, struct vfsmount *);
241
static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
242
static int nfs_xdev_get_sb(struct file_system_type *fs_type,
243
		int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howells's avatar
David Howells committed
244
static void nfs_kill_super(struct super_block *);
245
static int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
David Howells's avatar
David Howells committed
246
247
248
249
250
251

static struct file_system_type nfs_fs_type = {
	.owner		= THIS_MODULE,
	.name		= "nfs",
	.get_sb		= nfs_get_sb,
	.kill_sb	= nfs_kill_super,
252
	.fs_flags	= FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howells's avatar
David Howells committed
253
254
};

255
struct file_system_type nfs_xdev_fs_type = {
David Howells's avatar
David Howells committed
256
257
	.owner		= THIS_MODULE,
	.name		= "nfs",
258
	.get_sb		= nfs_xdev_get_sb,
David Howells's avatar
David Howells committed
259
	.kill_sb	= nfs_kill_super,
260
	.fs_flags	= FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howells's avatar
David Howells committed
261
262
};

263
static const struct super_operations nfs_sops = {
David Howells's avatar
David Howells committed
264
265
266
267
268
269
270
271
	.alloc_inode	= nfs_alloc_inode,
	.destroy_inode	= nfs_destroy_inode,
	.write_inode	= nfs_write_inode,
	.statfs		= nfs_statfs,
	.clear_inode	= nfs_clear_inode,
	.umount_begin	= nfs_umount_begin,
	.show_options	= nfs_show_options,
	.show_stats	= nfs_show_stats,
272
	.remount_fs	= nfs_remount,
David Howells's avatar
David Howells committed
273
274
275
};

#ifdef CONFIG_NFS_V4
276
277
static int nfs4_validate_text_mount_data(void *options,
	struct nfs_parsed_mount_data *args, const char *dev_name);
278
279
static int nfs4_try_mount(int flags, const char *dev_name,
	struct nfs_parsed_mount_data *data, struct vfsmount *mnt);
280
281
static int nfs4_get_sb(struct file_system_type *fs_type,
	int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
282
283
static int nfs4_remote_get_sb(struct file_system_type *fs_type,
	int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
284
285
286
287
static int nfs4_xdev_get_sb(struct file_system_type *fs_type,
	int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
static int nfs4_referral_get_sb(struct file_system_type *fs_type,
	int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
288
289
static int nfs4_remote_referral_get_sb(struct file_system_type *fs_type,
	int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howells's avatar
David Howells committed
290
291
292
293
294
295
296
static void nfs4_kill_super(struct super_block *sb);

static struct file_system_type nfs4_fs_type = {
	.owner		= THIS_MODULE,
	.name		= "nfs4",
	.get_sb		= nfs4_get_sb,
	.kill_sb	= nfs4_kill_super,
297
	.fs_flags	= FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howells's avatar
David Howells committed
298
299
};

300
301
302
303
304
305
306
307
static struct file_system_type nfs4_remote_fs_type = {
	.owner		= THIS_MODULE,
	.name		= "nfs4",
	.get_sb		= nfs4_remote_get_sb,
	.kill_sb	= nfs4_kill_super,
	.fs_flags	= FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
};

308
struct file_system_type nfs4_xdev_fs_type = {
David Howells's avatar
David Howells committed
309
310
	.owner		= THIS_MODULE,
	.name		= "nfs4",
311
	.get_sb		= nfs4_xdev_get_sb,
David Howells's avatar
David Howells committed
312
	.kill_sb	= nfs4_kill_super,
313
	.fs_flags	= FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howells's avatar
David Howells committed
314
315
};

316
317
318
319
320
321
322
323
static struct file_system_type nfs4_remote_referral_fs_type = {
	.owner		= THIS_MODULE,
	.name		= "nfs4",
	.get_sb		= nfs4_remote_referral_get_sb,
	.kill_sb	= nfs4_kill_super,
	.fs_flags	= FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
};

324
struct file_system_type nfs4_referral_fs_type = {
David Howells's avatar
David Howells committed
325
326
	.owner		= THIS_MODULE,
	.name		= "nfs4",
327
	.get_sb		= nfs4_referral_get_sb,
David Howells's avatar
David Howells committed
328
	.kill_sb	= nfs4_kill_super,
329
	.fs_flags	= FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howells's avatar
David Howells committed
330
331
};

332
static const struct super_operations nfs4_sops = {
David Howells's avatar
David Howells committed
333
334
335
336
337
338
339
340
	.alloc_inode	= nfs_alloc_inode,
	.destroy_inode	= nfs_destroy_inode,
	.write_inode	= nfs_write_inode,
	.statfs		= nfs_statfs,
	.clear_inode	= nfs4_clear_inode,
	.umount_begin	= nfs_umount_begin,
	.show_options	= nfs_show_options,
	.show_stats	= nfs_show_stats,
341
	.remount_fs	= nfs_remount,
David Howells's avatar
David Howells committed
342
343
344
};
#endif

345
346
347
348
static struct shrinker acl_shrinker = {
	.shrink		= nfs_access_cache_shrinker,
	.seeks		= DEFAULT_SEEKS,
};
349

David Howells's avatar
David Howells committed
350
351
352
353
354
355
356
357
358
359
360
361
362
363
/*
 * Register the NFS filesystems
 */
int __init register_nfs_fs(void)
{
	int ret;

        ret = register_filesystem(&nfs_fs_type);
	if (ret < 0)
		goto error_0;

	ret = nfs_register_sysctl();
	if (ret < 0)
		goto error_1;
364
#ifdef CONFIG_NFS_V4
David Howells's avatar
David Howells committed
365
366
367
368
	ret = register_filesystem(&nfs4_fs_type);
	if (ret < 0)
		goto error_2;
#endif
369
	register_shrinker(&acl_shrinker);
David Howells's avatar
David Howells committed
370
371
372
373
374
	return 0;

#ifdef CONFIG_NFS_V4
error_2:
	nfs_unregister_sysctl();
375
#endif
David Howells's avatar
David Howells committed
376
377
378
379
380
381
382
383
384
385
386
error_1:
	unregister_filesystem(&nfs_fs_type);
error_0:
	return ret;
}

/*
 * Unregister the NFS filesystems
 */
void __exit unregister_nfs_fs(void)
{
387
	unregister_shrinker(&acl_shrinker);
David Howells's avatar
David Howells committed
388
389
390
#ifdef CONFIG_NFS_V4
	unregister_filesystem(&nfs4_fs_type);
#endif
391
	nfs_unregister_sysctl();
David Howells's avatar
David Howells committed
392
393
394
	unregister_filesystem(&nfs_fs_type);
}

395
void nfs_sb_active(struct super_block *sb)
396
{
397
	struct nfs_server *server = NFS_SB(sb);
398

399
400
	if (atomic_inc_return(&server->active) == 1)
		atomic_inc(&sb->s_active);
401
402
}

403
void nfs_sb_deactive(struct super_block *sb)
404
405
{
	struct nfs_server *server = NFS_SB(sb);
406
407
408

	if (atomic_dec_and_test(&server->active))
		deactivate_super(sb);
409
410
}

David Howells's avatar
David Howells committed
411
412
413
/*
 * Deliver file system statistics to userspace
 */
414
static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
David Howells's avatar
David Howells committed
415
{
416
	struct nfs_server *server = NFS_SB(dentry->d_sb);
David Howells's avatar
David Howells committed
417
418
	unsigned char blockbits;
	unsigned long blockres;
419
	struct nfs_fh *fh = NFS_FH(dentry->d_inode);
David Howells's avatar
David Howells committed
420
421
422
423
424
425
	struct nfs_fattr fattr;
	struct nfs_fsstat res = {
			.fattr = &fattr,
	};
	int error;

426
	error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
David Howells's avatar
David Howells committed
427
428
	if (error < 0)
		goto out_err;
429
	buf->f_type = NFS_SUPER_MAGIC;
David Howells's avatar
David Howells committed
430
431
432
433
434
435

	/*
	 * Current versions of glibc do not correctly handle the
	 * case where f_frsize != f_bsize.  Eventually we want to
	 * report the value of wtmult in this field.
	 */
436
	buf->f_frsize = dentry->d_sb->s_blocksize;
David Howells's avatar
David Howells committed
437
438
439
440
441
442
443
444

	/*
	 * On most *nix systems, f_blocks, f_bfree, and f_bavail
	 * are reported in units of f_frsize.  Linux hasn't had
	 * an f_frsize field in its statfs struct until recently,
	 * thus historically Linux's sys_statfs reports these
	 * fields in units of f_bsize.
	 */
445
446
	buf->f_bsize = dentry->d_sb->s_blocksize;
	blockbits = dentry->d_sb->s_blocksize_bits;
David Howells's avatar
David Howells committed
447
448
449
450
451
452
453
454
455
	blockres = (1 << blockbits) - 1;
	buf->f_blocks = (res.tbytes + blockres) >> blockbits;
	buf->f_bfree = (res.fbytes + blockres) >> blockbits;
	buf->f_bavail = (res.abytes + blockres) >> blockbits;

	buf->f_files = res.tfiles;
	buf->f_ffree = res.afiles;

	buf->f_namelen = server->namelen;
456

David Howells's avatar
David Howells committed
457
458
459
	return 0;

 out_err:
460
	dprintk("%s: statfs error = %d\n", __func__, -error);
461
	return error;
David Howells's avatar
David Howells committed
462
463
}

464
465
466
/*
 * Map the security flavour number to a name
 */
467
468
static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
{
469
	static const struct {
470
471
472
473
474
475
476
477
478
479
480
481
482
483
		rpc_authflavor_t flavour;
		const char *str;
	} sec_flavours[] = {
		{ RPC_AUTH_NULL, "null" },
		{ RPC_AUTH_UNIX, "sys" },
		{ RPC_AUTH_GSS_KRB5, "krb5" },
		{ RPC_AUTH_GSS_KRB5I, "krb5i" },
		{ RPC_AUTH_GSS_KRB5P, "krb5p" },
		{ RPC_AUTH_GSS_LKEY, "lkey" },
		{ RPC_AUTH_GSS_LKEYI, "lkeyi" },
		{ RPC_AUTH_GSS_LKEYP, "lkeyp" },
		{ RPC_AUTH_GSS_SPKM, "spkm" },
		{ RPC_AUTH_GSS_SPKMI, "spkmi" },
		{ RPC_AUTH_GSS_SPKMP, "spkmp" },
484
		{ UINT_MAX, "unknown" }
485
486
487
	};
	int i;

488
	for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
489
490
491
492
493
494
		if (sec_flavours[i].flavour == flavour)
			break;
	}
	return sec_flavours[i].str;
}

495
496
497
498
499
500
501
502
static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
				    int showdefaults)
{
	struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;

	switch (sap->sa_family) {
	case AF_INET: {
		struct sockaddr_in *sin = (struct sockaddr_in *)sap;
Harvey Harrison's avatar
Harvey Harrison committed
503
		seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
504
505
506
507
		break;
	}
	case AF_INET6: {
		struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
Harvey Harrison's avatar
Harvey Harrison committed
508
		seq_printf(m, ",mountaddr=%pI6", &sin6->sin6_addr);
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
		break;
	}
	default:
		if (showdefaults)
			seq_printf(m, ",mountaddr=unspecified");
	}

	if (nfss->mountd_version || showdefaults)
		seq_printf(m, ",mountvers=%u", nfss->mountd_version);
	if (nfss->mountd_port || showdefaults)
		seq_printf(m, ",mountport=%u", nfss->mountd_port);

	switch (nfss->mountd_protocol) {
	case IPPROTO_UDP:
		seq_printf(m, ",mountproto=udp");
		break;
	case IPPROTO_TCP:
		seq_printf(m, ",mountproto=tcp");
		break;
	default:
		if (showdefaults)
			seq_printf(m, ",mountproto=auto");
	}
}

David Howells's avatar
David Howells committed
534
535
536
/*
 * Describe the mount options in force on this server representation
 */
537
538
static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
				   int showdefaults)
David Howells's avatar
David Howells committed
539
{
540
	static const struct proc_nfs_info {
David Howells's avatar
David Howells committed
541
		int flag;
542
543
		const char *str;
		const char *nostr;
David Howells's avatar
David Howells committed
544
545
	} nfs_info[] = {
		{ NFS_MOUNT_SOFT, ",soft", ",hard" },
546
		{ NFS_MOUNT_POSIX, ",posix", "" },
David Howells's avatar
David Howells committed
547
548
549
550
		{ NFS_MOUNT_NOCTO, ",nocto", "" },
		{ NFS_MOUNT_NOAC, ",noac", "" },
		{ NFS_MOUNT_NONLM, ",nolock", "" },
		{ NFS_MOUNT_NOACL, ",noacl", "" },
551
		{ NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
552
553
		{ NFS_MOUNT_UNSHARED, ",nosharecache", "" },
		{ NFS_MOUNT_NORESVPORT, ",noresvport", "" },
David Howells's avatar
David Howells committed
554
555
		{ 0, NULL, NULL }
	};
556
	const struct proc_nfs_info *nfs_infop;
557
	struct nfs_client *clp = nfss->nfs_client;
558
	u32 version = clp->rpc_ops->version;
David Howells's avatar
David Howells committed
559

560
	seq_printf(m, ",vers=%u", version);
561
562
	seq_printf(m, ",rsize=%u", nfss->rsize);
	seq_printf(m, ",wsize=%u", nfss->wsize);
563
564
565
	if (nfss->bsize != 0)
		seq_printf(m, ",bsize=%u", nfss->bsize);
	seq_printf(m, ",namlen=%u", nfss->namelen);
566
	if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
567
		seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
568
	if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
569
		seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
570
	if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
571
		seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
572
	if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
573
		seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
David Howells's avatar
David Howells committed
574
575
576
577
578
579
	for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
		if (nfss->flags & nfs_infop->flag)
			seq_puts(m, nfs_infop->str);
		else
			seq_puts(m, nfs_infop->nostr);
	}
580
581
	seq_printf(m, ",proto=%s",
		   rpc_peeraddr2str(nfss->client, RPC_DISPLAY_PROTO));
582
583
584
585
586
587
588
	if (version == 4) {
		if (nfss->port != NFS_PORT)
			seq_printf(m, ",port=%u", nfss->port);
	} else
		if (nfss->port)
			seq_printf(m, ",port=%u", nfss->port);

589
590
	seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
	seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
591
	seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
592
593
594
595
596
597
598
599

	if (version != 4)
		nfs_show_mountd_options(m, nfss, showdefaults);

#ifdef CONFIG_NFS_V4
	if (clp->rpc_ops->version == 4)
		seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
#endif
600
601
	if (nfss->options & NFS_OPTION_FSCACHE)
		seq_printf(m, ",fsc");
David Howells's avatar
David Howells committed
602
603
604
605
606
607
608
609
610
611
612
}

/*
 * Describe the mount options on this VFS mountpoint
 */
static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
{
	struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);

	nfs_show_mount_options(m, nfss, 0);

613
614
615
	seq_printf(m, ",addr=%s",
			rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
							RPC_DISPLAY_ADDR));
David Howells's avatar
David Howells committed
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645

	return 0;
}

/*
 * Present statistical information for this VFS mountpoint
 */
static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
{
	int i, cpu;
	struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
	struct rpc_auth *auth = nfss->client->cl_auth;
	struct nfs_iostats totals = { };

	seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);

	/*
	 * Display all mount option settings
	 */
	seq_printf(m, "\n\topts:\t");
	seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
	seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
	seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
	seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
	nfs_show_mount_options(m, nfss, 1);

	seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);

	seq_printf(m, "\n\tcaps:\t");
	seq_printf(m, "caps=0x%x", nfss->caps);
646
647
648
649
	seq_printf(m, ",wtmult=%u", nfss->wtmult);
	seq_printf(m, ",dtsize=%u", nfss->dtsize);
	seq_printf(m, ",bsize=%u", nfss->bsize);
	seq_printf(m, ",namlen=%u", nfss->namelen);
David Howells's avatar
David Howells committed
650
651

#ifdef CONFIG_NFS_V4
652
	if (nfss->nfs_client->rpc_ops->version == 4) {
David Howells's avatar
David Howells committed
653
654
655
656
657
658
659
660
661
662
		seq_printf(m, "\n\tnfsv4:\t");
		seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
		seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
		seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
	}
#endif

	/*
	 * Display security flavor in effect for this mount
	 */
663
	seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
David Howells's avatar
David Howells committed
664
	if (auth->au_flavor)
665
		seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
David Howells's avatar
David Howells committed
666
667
668
669
670
671
672
673
674
675
676
677
678
679

	/*
	 * Display superblock I/O counters
	 */
	for_each_possible_cpu(cpu) {
		struct nfs_iostats *stats;

		preempt_disable();
		stats = per_cpu_ptr(nfss->io_stats, cpu);

		for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
			totals.events[i] += stats->events[i];
		for (i = 0; i < __NFSIOS_BYTESMAX; i++)
			totals.bytes[i] += stats->bytes[i];
680
681
682
683
#ifdef CONFIG_NFS_FSCACHE
		for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
			totals.fscache[i] += stats->fscache[i];
#endif
David Howells's avatar
David Howells committed
684
685
686
687
688
689
690
691
692
693

		preempt_enable();
	}

	seq_printf(m, "\n\tevents:\t");
	for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
		seq_printf(m, "%lu ", totals.events[i]);
	seq_printf(m, "\n\tbytes:\t");
	for (i = 0; i < __NFSIOS_BYTESMAX; i++)
		seq_printf(m, "%Lu ", totals.bytes[i]);
694
695
696
697
698
699
700
#ifdef CONFIG_NFS_FSCACHE
	if (nfss->options & NFS_OPTION_FSCACHE) {
		seq_printf(m, "\n\tfsc:\t");
		for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
			seq_printf(m, "%Lu ", totals.bytes[i]);
	}
#endif
David Howells's avatar
David Howells committed
701
702
703
704
705
706
707
708
709
	seq_printf(m, "\n");

	rpc_print_iostats(m, nfss->client);

	return 0;
}

/*
 * Begin unmount by attempting to remove all automounted mountpoints we added
710
 * in response to xdev traversals and referrals
David Howells's avatar
David Howells committed
711
 */
712
static void nfs_umount_begin(struct super_block *sb)
David Howells's avatar
David Howells committed
713
{
714
	struct nfs_server *server;
715
716
	struct rpc_clnt *rpc;

717
718
719
	lock_kernel();

	server = NFS_SB(sb);
720
721
722
723
724
725
726
	/* -EIO all pending I/O */
	rpc = server->client_acl;
	if (!IS_ERR(rpc))
		rpc_killall_tasks(rpc);
	rpc = server->client;
	if (!IS_ERR(rpc))
		rpc_killall_tasks(rpc);
727
728

	unlock_kernel();
David Howells's avatar
David Howells committed
729
730
}

731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(int flags)
{
	struct nfs_parsed_mount_data *data;

	data = kzalloc(sizeof(*data), GFP_KERNEL);
	if (data) {
		data->flags		= flags;
		data->rsize		= NFS_MAX_FILE_IO_SIZE;
		data->wsize		= NFS_MAX_FILE_IO_SIZE;
		data->acregmin		= NFS_DEF_ACREGMIN;
		data->acregmax		= NFS_DEF_ACREGMAX;
		data->acdirmin		= NFS_DEF_ACDIRMIN;
		data->acdirmax		= NFS_DEF_ACDIRMAX;
		data->nfs_server.port	= NFS_UNSPEC_PORT;
		data->auth_flavors[0]	= RPC_AUTH_UNIX;
		data->auth_flavor_len	= 1;
		data->minorversion	= 0;
	}
	return data;
}

752
/*
753
754
755
756
 * Sanity-check a server address provided by the mount command.
 *
 * Address family must be initialized, and address must not be
 * the ANY address for that family.
757
758
759
760
761
 */
static int nfs_verify_server_address(struct sockaddr *addr)
{
	switch (addr->sa_family) {
	case AF_INET: {
762
		struct sockaddr_in *sa = (struct sockaddr_in *)addr;
Al Viro's avatar
Al Viro committed
763
		return sa->sin_addr.s_addr != htonl(INADDR_ANY);
764
765
766
767
	}
	case AF_INET6: {
		struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
		return !ipv6_addr_any(sa);
768
769
770
	}
	}

771
	dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
772
773
774
	return 0;
}

775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
/*
 * Select between a default port value and a user-specified port value.
 * If a zero value is set, then autobind will be used.
 */
static void nfs_set_default_port(struct sockaddr *sap, const int parsed_port,
				 const unsigned short default_port)
{
	unsigned short port = default_port;

	if (parsed_port != NFS_UNSPEC_PORT)
		port = parsed_port;

	rpc_set_port(sap, port);
}

790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
/*
 * Sanity check the NFS transport protocol.
 *
 */
static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
{
	switch (mnt->nfs_server.protocol) {
	case XPRT_TRANSPORT_UDP:
	case XPRT_TRANSPORT_TCP:
	case XPRT_TRANSPORT_RDMA:
		break;
	default:
		mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
	}
}

/*
 * For text based NFSv2/v3 mounts, the mount protocol transport default
 * settings should depend upon the specified NFS transport.
 */
static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
{
	nfs_validate_transport_protocol(mnt);

	if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
	    mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
			return;
	switch (mnt->nfs_server.protocol) {
	case XPRT_TRANSPORT_UDP:
		mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
		break;
	case XPRT_TRANSPORT_TCP:
	case XPRT_TRANSPORT_RDMA:
		mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
	}
}

827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
/*
 * Parse the value of the 'sec=' option.
 */
static int nfs_parse_security_flavors(char *value,
				      struct nfs_parsed_mount_data *mnt)
{
	substring_t args[MAX_OPT_ARGS];

	dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);

	switch (match_token(value, nfs_secflavor_tokens, args)) {
	case Opt_sec_none:
		mnt->auth_flavors[0] = RPC_AUTH_NULL;
		break;
	case Opt_sec_sys:
		mnt->auth_flavors[0] = RPC_AUTH_UNIX;
		break;
	case Opt_sec_krb5:
		mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
		break;
	case Opt_sec_krb5i:
		mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
		break;
	case Opt_sec_krb5p:
		mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
		break;
	case Opt_sec_lkey:
		mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
		break;
	case Opt_sec_lkeyi:
		mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
		break;
	case Opt_sec_lkeyp:
		mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
		break;
	case Opt_sec_spkm:
		mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
		break;
	case Opt_sec_spkmi:
		mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
		break;
	case Opt_sec_spkmp:
		mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
		break;
	default:
		return 0;
	}

875
	mnt->auth_flavor_len = 1;
876
877
878
	return 1;
}

879
880
/*
 * Error-check and convert a string of mount options from user space into
881
882
883
 * a data structure.  The whole mount string is processed; bad options are
 * skipped as they are encountered.  If there were no errors, return 1;
 * otherwise return 0 (zero).
884
885
886
887
 */
static int nfs_parse_mount_options(char *raw,
				   struct nfs_parsed_mount_data *mnt)
{
888
	char *p, *string, *secdata;
889
	int rc, sloppy = 0, invalid_option = 0;
890
891
892
893
894
895
896

	if (!raw) {
		dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
		return 1;
	}
	dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);

897
898
899
900
901
902
903
904
905
906
907
908
909
910
	secdata = alloc_secdata();
	if (!secdata)
		goto out_nomem;

	rc = security_sb_copy_data(raw, secdata);
	if (rc)
		goto out_security_failure;

	rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
	if (rc)
		goto out_security_failure;

	free_secdata(secdata);

911
912
	while ((p = strsep(&raw, ",")) != NULL) {
		substring_t args[MAX_OPT_ARGS];
913
914
		unsigned long option;
		int token;
915
916
917
918
919
920
921
922

		if (!*p)
			continue;

		dfprintk(MOUNT, "NFS:   parsing nfs mount option '%s'\n", p);

		token = match_token(p, nfs_mount_option_tokens, args);
		switch (token) {
923
924
925
926

		/*
		 * boolean options:  foo/nofoo
		 */
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
		case Opt_soft:
			mnt->flags |= NFS_MOUNT_SOFT;
			break;
		case Opt_hard:
			mnt->flags &= ~NFS_MOUNT_SOFT;
			break;
		case Opt_posix:
			mnt->flags |= NFS_MOUNT_POSIX;
			break;
		case Opt_noposix:
			mnt->flags &= ~NFS_MOUNT_POSIX;
			break;
		case Opt_cto:
			mnt->flags &= ~NFS_MOUNT_NOCTO;
			break;
		case Opt_nocto:
			mnt->flags |= NFS_MOUNT_NOCTO;
			break;
		case Opt_ac:
			mnt->flags &= ~NFS_MOUNT_NOAC;
			break;
		case Opt_noac:
			mnt->flags |= NFS_MOUNT_NOAC;
			break;
		case Opt_lock:
			mnt->flags &= ~NFS_MOUNT_NONLM;
			break;
		case Opt_nolock:
			mnt->flags |= NFS_MOUNT_NONLM;
			break;
		case Opt_v2:
			mnt->flags &= ~NFS_MOUNT_VER3;
959
			mnt->version = 2;
960
961
962
			break;
		case Opt_v3:
			mnt->flags |= NFS_MOUNT_VER3;
963
			mnt->version = 3;
964
			break;
965
966
967
968
969
970
#ifdef CONFIG_NFS_V4
		case Opt_v4:
			mnt->flags &= ~NFS_MOUNT_VER3;
			mnt->version = 4;
			break;
#endif
971
972
		case Opt_udp:
			mnt->flags &= ~NFS_MOUNT_TCP;
973
			mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
974
975
976
			break;
		case Opt_tcp:
			mnt->flags |= NFS_MOUNT_TCP;
977
			mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
978
			break;
\"Talpey, Thomas\'s avatar
\"Talpey, Thomas\ committed
979
980
981
		case Opt_rdma:
			mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
			mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
982
			xprt_load_transport(p);
\"Talpey, Thomas\'s avatar
\"Talpey, Thomas\ committed
983
			break;
984
985
986
987
988
989
990
991
992
993
994
995
		case Opt_acl:
			mnt->flags &= ~NFS_MOUNT_NOACL;
			break;
		case Opt_noacl:
			mnt->flags |= NFS_MOUNT_NOACL;
			break;
		case Opt_rdirplus:
			mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
			break;
		case Opt_nordirplus:
			mnt->flags |= NFS_MOUNT_NORDIRPLUS;
			break;
996
997
998
999
1000
		case Opt_sharecache:
			mnt->flags &= ~NFS_MOUNT_UNSHARED;
			break;
		case Opt_nosharecache:
			mnt->flags |= NFS_MOUNT_UNSHARED;