NFS: Add version registering framework
[deliverable/linux.git] / fs / nfs / super.c
1 /*
2 * linux/fs/nfs/super.c
3 *
4 * Copyright (C) 1992 Rick Sladkey
5 *
6 * nfs superblock handling functions
7 *
8 * Modularised by Alan Cox <alan@lxorguk.ukuu.org.uk>, while hacking some
9 * experimental NFS changes. Modularisation taken straight from SYS5 fs.
10 *
11 * Change to nfs_read_super() to permit NFS mounts to multi-homed hosts.
12 * J.S.Peatfield@damtp.cam.ac.uk
13 *
14 * Split from inode.c by David Howells <dhowells@redhat.com>
15 *
16 * - superblocks are indexed on server only - all inodes, dentries, etc. associated with a
17 * particular server are held in the same superblock
18 * - NFS superblocks can have several effective roots to the dentry tree
19 * - directory type roots are spliced into the tree when a path from one root reaches the root
20 * of another (see nfs_lookup())
21 */
22
23 #include <linux/module.h>
24 #include <linux/init.h>
25
26 #include <linux/time.h>
27 #include <linux/kernel.h>
28 #include <linux/mm.h>
29 #include <linux/string.h>
30 #include <linux/stat.h>
31 #include <linux/errno.h>
32 #include <linux/unistd.h>
33 #include <linux/sunrpc/clnt.h>
34 #include <linux/sunrpc/stats.h>
35 #include <linux/sunrpc/metrics.h>
36 #include <linux/sunrpc/xprtsock.h>
37 #include <linux/sunrpc/xprtrdma.h>
38 #include <linux/nfs_fs.h>
39 #include <linux/nfs_mount.h>
40 #include <linux/nfs4_mount.h>
41 #include <linux/lockd/bind.h>
42 #include <linux/seq_file.h>
43 #include <linux/mount.h>
44 #include <linux/namei.h>
45 #include <linux/nfs_idmap.h>
46 #include <linux/vfs.h>
47 #include <linux/inet.h>
48 #include <linux/in6.h>
49 #include <linux/slab.h>
50 #include <net/ipv6.h>
51 #include <linux/netdevice.h>
52 #include <linux/nfs_xdr.h>
53 #include <linux/magic.h>
54 #include <linux/parser.h>
55 #include <linux/nsproxy.h>
56 #include <linux/rcupdate.h>
57
58 #include <asm/uaccess.h>
59
60 #include "nfs4_fs.h"
61 #include "callback.h"
62 #include "delegation.h"
63 #include "iostat.h"
64 #include "internal.h"
65 #include "fscache.h"
66 #include "pnfs.h"
67 #include "nfs.h"
68
69 #define NFSDBG_FACILITY NFSDBG_VFS
70 #define NFS_TEXT_DATA 1
71
72 #ifdef CONFIG_NFS_V3
73 #define NFS_DEFAULT_VERSION 3
74 #else
75 #define NFS_DEFAULT_VERSION 2
76 #endif
77
78 enum {
79 /* Mount options that take no arguments */
80 Opt_soft, Opt_hard,
81 Opt_posix, Opt_noposix,
82 Opt_cto, Opt_nocto,
83 Opt_ac, Opt_noac,
84 Opt_lock, Opt_nolock,
85 Opt_udp, Opt_tcp, Opt_rdma,
86 Opt_acl, Opt_noacl,
87 Opt_rdirplus, Opt_nordirplus,
88 Opt_sharecache, Opt_nosharecache,
89 Opt_resvport, Opt_noresvport,
90 Opt_fscache, Opt_nofscache,
91
92 /* Mount options that take integer arguments */
93 Opt_port,
94 Opt_rsize, Opt_wsize, Opt_bsize,
95 Opt_timeo, Opt_retrans,
96 Opt_acregmin, Opt_acregmax,
97 Opt_acdirmin, Opt_acdirmax,
98 Opt_actimeo,
99 Opt_namelen,
100 Opt_mountport,
101 Opt_mountvers,
102 Opt_minorversion,
103
104 /* Mount options that take string arguments */
105 Opt_nfsvers,
106 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
107 Opt_addr, Opt_mountaddr, Opt_clientaddr,
108 Opt_lookupcache,
109 Opt_fscache_uniq,
110 Opt_local_lock,
111
112 /* Special mount options */
113 Opt_userspace, Opt_deprecated, Opt_sloppy,
114
115 Opt_err
116 };
117
118 static const match_table_t nfs_mount_option_tokens = {
119 { Opt_userspace, "bg" },
120 { Opt_userspace, "fg" },
121 { Opt_userspace, "retry=%s" },
122
123 { Opt_sloppy, "sloppy" },
124
125 { Opt_soft, "soft" },
126 { Opt_hard, "hard" },
127 { Opt_deprecated, "intr" },
128 { Opt_deprecated, "nointr" },
129 { Opt_posix, "posix" },
130 { Opt_noposix, "noposix" },
131 { Opt_cto, "cto" },
132 { Opt_nocto, "nocto" },
133 { Opt_ac, "ac" },
134 { Opt_noac, "noac" },
135 { Opt_lock, "lock" },
136 { Opt_nolock, "nolock" },
137 { Opt_udp, "udp" },
138 { Opt_tcp, "tcp" },
139 { Opt_rdma, "rdma" },
140 { Opt_acl, "acl" },
141 { Opt_noacl, "noacl" },
142 { Opt_rdirplus, "rdirplus" },
143 { Opt_nordirplus, "nordirplus" },
144 { Opt_sharecache, "sharecache" },
145 { Opt_nosharecache, "nosharecache" },
146 { Opt_resvport, "resvport" },
147 { Opt_noresvport, "noresvport" },
148 { Opt_fscache, "fsc" },
149 { Opt_nofscache, "nofsc" },
150
151 { Opt_port, "port=%s" },
152 { Opt_rsize, "rsize=%s" },
153 { Opt_wsize, "wsize=%s" },
154 { Opt_bsize, "bsize=%s" },
155 { Opt_timeo, "timeo=%s" },
156 { Opt_retrans, "retrans=%s" },
157 { Opt_acregmin, "acregmin=%s" },
158 { Opt_acregmax, "acregmax=%s" },
159 { Opt_acdirmin, "acdirmin=%s" },
160 { Opt_acdirmax, "acdirmax=%s" },
161 { Opt_actimeo, "actimeo=%s" },
162 { Opt_namelen, "namlen=%s" },
163 { Opt_mountport, "mountport=%s" },
164 { Opt_mountvers, "mountvers=%s" },
165 { Opt_minorversion, "minorversion=%s" },
166
167 { Opt_nfsvers, "nfsvers=%s" },
168 { Opt_nfsvers, "vers=%s" },
169
170 { Opt_sec, "sec=%s" },
171 { Opt_proto, "proto=%s" },
172 { Opt_mountproto, "mountproto=%s" },
173 { Opt_addr, "addr=%s" },
174 { Opt_clientaddr, "clientaddr=%s" },
175 { Opt_mounthost, "mounthost=%s" },
176 { Opt_mountaddr, "mountaddr=%s" },
177
178 { Opt_lookupcache, "lookupcache=%s" },
179 { Opt_fscache_uniq, "fsc=%s" },
180 { Opt_local_lock, "local_lock=%s" },
181
182 /* The following needs to be listed after all other options */
183 { Opt_nfsvers, "v%s" },
184
185 { Opt_err, NULL }
186 };
187
188 enum {
189 Opt_xprt_udp, Opt_xprt_udp6, Opt_xprt_tcp, Opt_xprt_tcp6, Opt_xprt_rdma,
190
191 Opt_xprt_err
192 };
193
194 static const match_table_t nfs_xprt_protocol_tokens = {
195 { Opt_xprt_udp, "udp" },
196 { Opt_xprt_udp6, "udp6" },
197 { Opt_xprt_tcp, "tcp" },
198 { Opt_xprt_tcp6, "tcp6" },
199 { Opt_xprt_rdma, "rdma" },
200
201 { Opt_xprt_err, NULL }
202 };
203
204 enum {
205 Opt_sec_none, Opt_sec_sys,
206 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
207 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
208 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
209
210 Opt_sec_err
211 };
212
213 static const match_table_t nfs_secflavor_tokens = {
214 { Opt_sec_none, "none" },
215 { Opt_sec_none, "null" },
216 { Opt_sec_sys, "sys" },
217
218 { Opt_sec_krb5, "krb5" },
219 { Opt_sec_krb5i, "krb5i" },
220 { Opt_sec_krb5p, "krb5p" },
221
222 { Opt_sec_lkey, "lkey" },
223 { Opt_sec_lkeyi, "lkeyi" },
224 { Opt_sec_lkeyp, "lkeyp" },
225
226 { Opt_sec_spkm, "spkm3" },
227 { Opt_sec_spkmi, "spkm3i" },
228 { Opt_sec_spkmp, "spkm3p" },
229
230 { Opt_sec_err, NULL }
231 };
232
233 enum {
234 Opt_lookupcache_all, Opt_lookupcache_positive,
235 Opt_lookupcache_none,
236
237 Opt_lookupcache_err
238 };
239
240 static match_table_t nfs_lookupcache_tokens = {
241 { Opt_lookupcache_all, "all" },
242 { Opt_lookupcache_positive, "pos" },
243 { Opt_lookupcache_positive, "positive" },
244 { Opt_lookupcache_none, "none" },
245
246 { Opt_lookupcache_err, NULL }
247 };
248
249 enum {
250 Opt_local_lock_all, Opt_local_lock_flock, Opt_local_lock_posix,
251 Opt_local_lock_none,
252
253 Opt_local_lock_err
254 };
255
256 static match_table_t nfs_local_lock_tokens = {
257 { Opt_local_lock_all, "all" },
258 { Opt_local_lock_flock, "flock" },
259 { Opt_local_lock_posix, "posix" },
260 { Opt_local_lock_none, "none" },
261
262 { Opt_local_lock_err, NULL }
263 };
264
265 enum {
266 Opt_vers_2, Opt_vers_3, Opt_vers_4, Opt_vers_4_0,
267 Opt_vers_4_1,
268
269 Opt_vers_err
270 };
271
272 static match_table_t nfs_vers_tokens = {
273 { Opt_vers_2, "2" },
274 { Opt_vers_3, "3" },
275 { Opt_vers_4, "4" },
276 { Opt_vers_4_0, "4.0" },
277 { Opt_vers_4_1, "4.1" },
278
279 { Opt_vers_err, NULL }
280 };
281
282 static struct dentry *nfs_xdev_mount(struct file_system_type *fs_type,
283 int flags, const char *dev_name, void *raw_data);
284
285 struct file_system_type nfs_fs_type = {
286 .owner = THIS_MODULE,
287 .name = "nfs",
288 .mount = nfs_fs_mount,
289 .kill_sb = nfs_kill_super,
290 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
291 };
292
293 struct file_system_type nfs_xdev_fs_type = {
294 .owner = THIS_MODULE,
295 .name = "nfs",
296 .mount = nfs_xdev_mount,
297 .kill_sb = nfs_kill_super,
298 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
299 };
300
301 static const struct super_operations nfs_sops = {
302 .alloc_inode = nfs_alloc_inode,
303 .destroy_inode = nfs_destroy_inode,
304 .write_inode = nfs_write_inode,
305 .put_super = nfs_put_super,
306 .statfs = nfs_statfs,
307 .evict_inode = nfs_evict_inode,
308 .umount_begin = nfs_umount_begin,
309 .show_options = nfs_show_options,
310 .show_devname = nfs_show_devname,
311 .show_path = nfs_show_path,
312 .show_stats = nfs_show_stats,
313 .remount_fs = nfs_remount,
314 };
315
316 #ifdef CONFIG_NFS_V4
317 static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *);
318 static int nfs4_validate_mount_data(void *options,
319 struct nfs_parsed_mount_data *args, const char *dev_name);
320 #endif
321
322 static struct shrinker acl_shrinker = {
323 .shrink = nfs_access_cache_shrinker,
324 .seeks = DEFAULT_SEEKS,
325 };
326
327 /*
328 * Register the NFS filesystems
329 */
330 int __init register_nfs_fs(void)
331 {
332 int ret;
333
334 ret = register_filesystem(&nfs_fs_type);
335 if (ret < 0)
336 goto error_0;
337
338 ret = nfs_register_sysctl();
339 if (ret < 0)
340 goto error_1;
341 register_shrinker(&acl_shrinker);
342 return 0;
343
344 error_1:
345 unregister_filesystem(&nfs_fs_type);
346 error_0:
347 return ret;
348 }
349
350 /*
351 * Unregister the NFS filesystems
352 */
353 void __exit unregister_nfs_fs(void)
354 {
355 unregister_shrinker(&acl_shrinker);
356 nfs_unregister_sysctl();
357 unregister_filesystem(&nfs_fs_type);
358 }
359
360 void nfs_sb_active(struct super_block *sb)
361 {
362 struct nfs_server *server = NFS_SB(sb);
363
364 if (atomic_inc_return(&server->active) == 1)
365 atomic_inc(&sb->s_active);
366 }
367
368 void nfs_sb_deactive(struct super_block *sb)
369 {
370 struct nfs_server *server = NFS_SB(sb);
371
372 if (atomic_dec_and_test(&server->active))
373 deactivate_super(sb);
374 }
375
376 /*
377 * Deliver file system statistics to userspace
378 */
379 int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
380 {
381 struct nfs_server *server = NFS_SB(dentry->d_sb);
382 unsigned char blockbits;
383 unsigned long blockres;
384 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
385 struct nfs_fsstat res;
386 int error = -ENOMEM;
387
388 res.fattr = nfs_alloc_fattr();
389 if (res.fattr == NULL)
390 goto out_err;
391
392 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
393 if (unlikely(error == -ESTALE)) {
394 struct dentry *pd_dentry;
395
396 pd_dentry = dget_parent(dentry);
397 if (pd_dentry != NULL) {
398 nfs_zap_caches(pd_dentry->d_inode);
399 dput(pd_dentry);
400 }
401 }
402 nfs_free_fattr(res.fattr);
403 if (error < 0)
404 goto out_err;
405
406 buf->f_type = NFS_SUPER_MAGIC;
407
408 /*
409 * Current versions of glibc do not correctly handle the
410 * case where f_frsize != f_bsize. Eventually we want to
411 * report the value of wtmult in this field.
412 */
413 buf->f_frsize = dentry->d_sb->s_blocksize;
414
415 /*
416 * On most *nix systems, f_blocks, f_bfree, and f_bavail
417 * are reported in units of f_frsize. Linux hasn't had
418 * an f_frsize field in its statfs struct until recently,
419 * thus historically Linux's sys_statfs reports these
420 * fields in units of f_bsize.
421 */
422 buf->f_bsize = dentry->d_sb->s_blocksize;
423 blockbits = dentry->d_sb->s_blocksize_bits;
424 blockres = (1 << blockbits) - 1;
425 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
426 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
427 buf->f_bavail = (res.abytes + blockres) >> blockbits;
428
429 buf->f_files = res.tfiles;
430 buf->f_ffree = res.afiles;
431
432 buf->f_namelen = server->namelen;
433
434 return 0;
435
436 out_err:
437 dprintk("%s: statfs error = %d\n", __func__, -error);
438 return error;
439 }
440
441 /*
442 * Map the security flavour number to a name
443 */
444 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
445 {
446 static const struct {
447 rpc_authflavor_t flavour;
448 const char *str;
449 } sec_flavours[] = {
450 { RPC_AUTH_NULL, "null" },
451 { RPC_AUTH_UNIX, "sys" },
452 { RPC_AUTH_GSS_KRB5, "krb5" },
453 { RPC_AUTH_GSS_KRB5I, "krb5i" },
454 { RPC_AUTH_GSS_KRB5P, "krb5p" },
455 { RPC_AUTH_GSS_LKEY, "lkey" },
456 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
457 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
458 { RPC_AUTH_GSS_SPKM, "spkm" },
459 { RPC_AUTH_GSS_SPKMI, "spkmi" },
460 { RPC_AUTH_GSS_SPKMP, "spkmp" },
461 { UINT_MAX, "unknown" }
462 };
463 int i;
464
465 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
466 if (sec_flavours[i].flavour == flavour)
467 break;
468 }
469 return sec_flavours[i].str;
470 }
471
472 static void nfs_show_mountd_netid(struct seq_file *m, struct nfs_server *nfss,
473 int showdefaults)
474 {
475 struct sockaddr *sap = (struct sockaddr *) &nfss->mountd_address;
476
477 seq_printf(m, ",mountproto=");
478 switch (sap->sa_family) {
479 case AF_INET:
480 switch (nfss->mountd_protocol) {
481 case IPPROTO_UDP:
482 seq_printf(m, RPCBIND_NETID_UDP);
483 break;
484 case IPPROTO_TCP:
485 seq_printf(m, RPCBIND_NETID_TCP);
486 break;
487 default:
488 if (showdefaults)
489 seq_printf(m, "auto");
490 }
491 break;
492 case AF_INET6:
493 switch (nfss->mountd_protocol) {
494 case IPPROTO_UDP:
495 seq_printf(m, RPCBIND_NETID_UDP6);
496 break;
497 case IPPROTO_TCP:
498 seq_printf(m, RPCBIND_NETID_TCP6);
499 break;
500 default:
501 if (showdefaults)
502 seq_printf(m, "auto");
503 }
504 break;
505 default:
506 if (showdefaults)
507 seq_printf(m, "auto");
508 }
509 }
510
511 static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
512 int showdefaults)
513 {
514 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
515
516 if (nfss->flags & NFS_MOUNT_LEGACY_INTERFACE)
517 return;
518
519 switch (sap->sa_family) {
520 case AF_INET: {
521 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
522 seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
523 break;
524 }
525 case AF_INET6: {
526 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
527 seq_printf(m, ",mountaddr=%pI6c", &sin6->sin6_addr);
528 break;
529 }
530 default:
531 if (showdefaults)
532 seq_printf(m, ",mountaddr=unspecified");
533 }
534
535 if (nfss->mountd_version || showdefaults)
536 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
537 if ((nfss->mountd_port &&
538 nfss->mountd_port != (unsigned short)NFS_UNSPEC_PORT) ||
539 showdefaults)
540 seq_printf(m, ",mountport=%u", nfss->mountd_port);
541
542 nfs_show_mountd_netid(m, nfss, showdefaults);
543 }
544
545 #ifdef CONFIG_NFS_V4
546 static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
547 int showdefaults)
548 {
549 struct nfs_client *clp = nfss->nfs_client;
550
551 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
552 }
553 #else
554 static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
555 int showdefaults)
556 {
557 }
558 #endif
559
560 static void nfs_show_nfs_version(struct seq_file *m,
561 unsigned int version,
562 unsigned int minorversion)
563 {
564 seq_printf(m, ",vers=%u", version);
565 if (version == 4)
566 seq_printf(m, ".%u", minorversion);
567 }
568
569 /*
570 * Describe the mount options in force on this server representation
571 */
572 static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
573 int showdefaults)
574 {
575 static const struct proc_nfs_info {
576 int flag;
577 const char *str;
578 const char *nostr;
579 } nfs_info[] = {
580 { NFS_MOUNT_SOFT, ",soft", ",hard" },
581 { NFS_MOUNT_POSIX, ",posix", "" },
582 { NFS_MOUNT_NOCTO, ",nocto", "" },
583 { NFS_MOUNT_NOAC, ",noac", "" },
584 { NFS_MOUNT_NONLM, ",nolock", "" },
585 { NFS_MOUNT_NOACL, ",noacl", "" },
586 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
587 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
588 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
589 { 0, NULL, NULL }
590 };
591 const struct proc_nfs_info *nfs_infop;
592 struct nfs_client *clp = nfss->nfs_client;
593 u32 version = clp->rpc_ops->version;
594 int local_flock, local_fcntl;
595
596 nfs_show_nfs_version(m, version, clp->cl_minorversion);
597 seq_printf(m, ",rsize=%u", nfss->rsize);
598 seq_printf(m, ",wsize=%u", nfss->wsize);
599 if (nfss->bsize != 0)
600 seq_printf(m, ",bsize=%u", nfss->bsize);
601 seq_printf(m, ",namlen=%u", nfss->namelen);
602 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
603 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
604 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
605 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
606 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
607 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
608 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
609 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
610 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
611 if (nfss->flags & nfs_infop->flag)
612 seq_puts(m, nfs_infop->str);
613 else
614 seq_puts(m, nfs_infop->nostr);
615 }
616 rcu_read_lock();
617 seq_printf(m, ",proto=%s",
618 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
619 rcu_read_unlock();
620 if (version == 4) {
621 if (nfss->port != NFS_PORT)
622 seq_printf(m, ",port=%u", nfss->port);
623 } else
624 if (nfss->port)
625 seq_printf(m, ",port=%u", nfss->port);
626
627 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
628 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
629 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
630
631 if (version != 4)
632 nfs_show_mountd_options(m, nfss, showdefaults);
633 else
634 nfs_show_nfsv4_options(m, nfss, showdefaults);
635
636 if (nfss->options & NFS_OPTION_FSCACHE)
637 seq_printf(m, ",fsc");
638
639 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONEG) {
640 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONE)
641 seq_printf(m, ",lookupcache=none");
642 else
643 seq_printf(m, ",lookupcache=pos");
644 }
645
646 local_flock = nfss->flags & NFS_MOUNT_LOCAL_FLOCK;
647 local_fcntl = nfss->flags & NFS_MOUNT_LOCAL_FCNTL;
648
649 if (!local_flock && !local_fcntl)
650 seq_printf(m, ",local_lock=none");
651 else if (local_flock && local_fcntl)
652 seq_printf(m, ",local_lock=all");
653 else if (local_flock)
654 seq_printf(m, ",local_lock=flock");
655 else
656 seq_printf(m, ",local_lock=posix");
657 }
658
659 /*
660 * Describe the mount options on this VFS mountpoint
661 */
662 int nfs_show_options(struct seq_file *m, struct dentry *root)
663 {
664 struct nfs_server *nfss = NFS_SB(root->d_sb);
665
666 nfs_show_mount_options(m, nfss, 0);
667
668 rcu_read_lock();
669 seq_printf(m, ",addr=%s",
670 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
671 RPC_DISPLAY_ADDR));
672 rcu_read_unlock();
673
674 return 0;
675 }
676
677 #ifdef CONFIG_NFS_V4
678 #ifdef CONFIG_NFS_V4_1
679 static void show_sessions(struct seq_file *m, struct nfs_server *server)
680 {
681 if (nfs4_has_session(server->nfs_client))
682 seq_printf(m, ",sessions");
683 }
684 #else
685 static void show_sessions(struct seq_file *m, struct nfs_server *server) {}
686 #endif
687 #endif
688
689 #ifdef CONFIG_NFS_V4_1
690 static void show_pnfs(struct seq_file *m, struct nfs_server *server)
691 {
692 seq_printf(m, ",pnfs=");
693 if (server->pnfs_curr_ld)
694 seq_printf(m, "%s", server->pnfs_curr_ld->name);
695 else
696 seq_printf(m, "not configured");
697 }
698
699 static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
700 {
701 if (nfss->nfs_client && nfss->nfs_client->cl_implid) {
702 struct nfs41_impl_id *impl_id = nfss->nfs_client->cl_implid;
703 seq_printf(m, "\n\timpl_id:\tname='%s',domain='%s',"
704 "date='%llu,%u'",
705 impl_id->name, impl_id->domain,
706 impl_id->date.seconds, impl_id->date.nseconds);
707 }
708 }
709 #else
710 #ifdef CONFIG_NFS_V4
711 static void show_pnfs(struct seq_file *m, struct nfs_server *server)
712 {
713 }
714 #endif
715 static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
716 {
717 }
718 #endif
719
720 int nfs_show_devname(struct seq_file *m, struct dentry *root)
721 {
722 char *page = (char *) __get_free_page(GFP_KERNEL);
723 char *devname, *dummy;
724 int err = 0;
725 if (!page)
726 return -ENOMEM;
727 devname = nfs_path(&dummy, root, page, PAGE_SIZE);
728 if (IS_ERR(devname))
729 err = PTR_ERR(devname);
730 else
731 seq_escape(m, devname, " \t\n\\");
732 free_page((unsigned long)page);
733 return err;
734 }
735
736 int nfs_show_path(struct seq_file *m, struct dentry *dentry)
737 {
738 seq_puts(m, "/");
739 return 0;
740 }
741
742 /*
743 * Present statistical information for this VFS mountpoint
744 */
745 int nfs_show_stats(struct seq_file *m, struct dentry *root)
746 {
747 int i, cpu;
748 struct nfs_server *nfss = NFS_SB(root->d_sb);
749 struct rpc_auth *auth = nfss->client->cl_auth;
750 struct nfs_iostats totals = { };
751
752 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
753
754 /*
755 * Display all mount option settings
756 */
757 seq_printf(m, "\n\topts:\t");
758 seq_puts(m, root->d_sb->s_flags & MS_RDONLY ? "ro" : "rw");
759 seq_puts(m, root->d_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
760 seq_puts(m, root->d_sb->s_flags & MS_NOATIME ? ",noatime" : "");
761 seq_puts(m, root->d_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
762 nfs_show_mount_options(m, nfss, 1);
763
764 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
765
766 show_implementation_id(m, nfss);
767
768 seq_printf(m, "\n\tcaps:\t");
769 seq_printf(m, "caps=0x%x", nfss->caps);
770 seq_printf(m, ",wtmult=%u", nfss->wtmult);
771 seq_printf(m, ",dtsize=%u", nfss->dtsize);
772 seq_printf(m, ",bsize=%u", nfss->bsize);
773 seq_printf(m, ",namlen=%u", nfss->namelen);
774
775 #ifdef CONFIG_NFS_V4
776 if (nfss->nfs_client->rpc_ops->version == 4) {
777 seq_printf(m, "\n\tnfsv4:\t");
778 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
779 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
780 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
781 show_sessions(m, nfss);
782 show_pnfs(m, nfss);
783 }
784 #endif
785
786 /*
787 * Display security flavor in effect for this mount
788 */
789 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
790 if (auth->au_flavor)
791 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
792
793 /*
794 * Display superblock I/O counters
795 */
796 for_each_possible_cpu(cpu) {
797 struct nfs_iostats *stats;
798
799 preempt_disable();
800 stats = per_cpu_ptr(nfss->io_stats, cpu);
801
802 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
803 totals.events[i] += stats->events[i];
804 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
805 totals.bytes[i] += stats->bytes[i];
806 #ifdef CONFIG_NFS_FSCACHE
807 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
808 totals.fscache[i] += stats->fscache[i];
809 #endif
810
811 preempt_enable();
812 }
813
814 seq_printf(m, "\n\tevents:\t");
815 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
816 seq_printf(m, "%lu ", totals.events[i]);
817 seq_printf(m, "\n\tbytes:\t");
818 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
819 seq_printf(m, "%Lu ", totals.bytes[i]);
820 #ifdef CONFIG_NFS_FSCACHE
821 if (nfss->options & NFS_OPTION_FSCACHE) {
822 seq_printf(m, "\n\tfsc:\t");
823 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
824 seq_printf(m, "%Lu ", totals.bytes[i]);
825 }
826 #endif
827 seq_printf(m, "\n");
828
829 rpc_print_iostats(m, nfss->client);
830
831 return 0;
832 }
833
834 /*
835 * Begin unmount by attempting to remove all automounted mountpoints we added
836 * in response to xdev traversals and referrals
837 */
838 void nfs_umount_begin(struct super_block *sb)
839 {
840 struct nfs_server *server;
841 struct rpc_clnt *rpc;
842
843 server = NFS_SB(sb);
844 /* -EIO all pending I/O */
845 rpc = server->client_acl;
846 if (!IS_ERR(rpc))
847 rpc_killall_tasks(rpc);
848 rpc = server->client;
849 if (!IS_ERR(rpc))
850 rpc_killall_tasks(rpc);
851 }
852
853 static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(void)
854 {
855 struct nfs_parsed_mount_data *data;
856
857 data = kzalloc(sizeof(*data), GFP_KERNEL);
858 if (data) {
859 data->acregmin = NFS_DEF_ACREGMIN;
860 data->acregmax = NFS_DEF_ACREGMAX;
861 data->acdirmin = NFS_DEF_ACDIRMIN;
862 data->acdirmax = NFS_DEF_ACDIRMAX;
863 data->mount_server.port = NFS_UNSPEC_PORT;
864 data->nfs_server.port = NFS_UNSPEC_PORT;
865 data->nfs_server.protocol = XPRT_TRANSPORT_TCP;
866 data->auth_flavors[0] = RPC_AUTH_UNIX;
867 data->auth_flavor_len = 1;
868 data->minorversion = 0;
869 data->need_mount = true;
870 data->net = current->nsproxy->net_ns;
871 security_init_mnt_opts(&data->lsm_opts);
872 }
873 return data;
874 }
875
876 static void nfs_free_parsed_mount_data(struct nfs_parsed_mount_data *data)
877 {
878 if (data) {
879 kfree(data->client_address);
880 kfree(data->mount_server.hostname);
881 kfree(data->nfs_server.export_path);
882 kfree(data->nfs_server.hostname);
883 kfree(data->fscache_uniq);
884 security_free_mnt_opts(&data->lsm_opts);
885 kfree(data);
886 }
887 }
888
889 /*
890 * Sanity-check a server address provided by the mount command.
891 *
892 * Address family must be initialized, and address must not be
893 * the ANY address for that family.
894 */
895 static int nfs_verify_server_address(struct sockaddr *addr)
896 {
897 switch (addr->sa_family) {
898 case AF_INET: {
899 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
900 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
901 }
902 case AF_INET6: {
903 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
904 return !ipv6_addr_any(sa);
905 }
906 }
907
908 dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
909 return 0;
910 }
911
912 /*
913 * Select between a default port value and a user-specified port value.
914 * If a zero value is set, then autobind will be used.
915 */
916 static void nfs_set_port(struct sockaddr *sap, int *port,
917 const unsigned short default_port)
918 {
919 if (*port == NFS_UNSPEC_PORT)
920 *port = default_port;
921
922 rpc_set_port(sap, *port);
923 }
924
925 /*
926 * Sanity check the NFS transport protocol.
927 *
928 */
929 static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
930 {
931 switch (mnt->nfs_server.protocol) {
932 case XPRT_TRANSPORT_UDP:
933 case XPRT_TRANSPORT_TCP:
934 case XPRT_TRANSPORT_RDMA:
935 break;
936 default:
937 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
938 }
939 }
940
941 /*
942 * For text based NFSv2/v3 mounts, the mount protocol transport default
943 * settings should depend upon the specified NFS transport.
944 */
945 static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
946 {
947 nfs_validate_transport_protocol(mnt);
948
949 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
950 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
951 return;
952 switch (mnt->nfs_server.protocol) {
953 case XPRT_TRANSPORT_UDP:
954 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
955 break;
956 case XPRT_TRANSPORT_TCP:
957 case XPRT_TRANSPORT_RDMA:
958 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
959 }
960 }
961
962 /*
963 * Parse the value of the 'sec=' option.
964 */
965 static int nfs_parse_security_flavors(char *value,
966 struct nfs_parsed_mount_data *mnt)
967 {
968 substring_t args[MAX_OPT_ARGS];
969
970 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
971
972 switch (match_token(value, nfs_secflavor_tokens, args)) {
973 case Opt_sec_none:
974 mnt->auth_flavors[0] = RPC_AUTH_NULL;
975 break;
976 case Opt_sec_sys:
977 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
978 break;
979 case Opt_sec_krb5:
980 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
981 break;
982 case Opt_sec_krb5i:
983 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
984 break;
985 case Opt_sec_krb5p:
986 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
987 break;
988 case Opt_sec_lkey:
989 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
990 break;
991 case Opt_sec_lkeyi:
992 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
993 break;
994 case Opt_sec_lkeyp:
995 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
996 break;
997 case Opt_sec_spkm:
998 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
999 break;
1000 case Opt_sec_spkmi:
1001 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
1002 break;
1003 case Opt_sec_spkmp:
1004 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
1005 break;
1006 default:
1007 return 0;
1008 }
1009
1010 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
1011 mnt->auth_flavor_len = 1;
1012 return 1;
1013 }
1014
1015 static int nfs_parse_version_string(char *string,
1016 struct nfs_parsed_mount_data *mnt,
1017 substring_t *args)
1018 {
1019 mnt->flags &= ~NFS_MOUNT_VER3;
1020 switch (match_token(string, nfs_vers_tokens, args)) {
1021 case Opt_vers_2:
1022 mnt->version = 2;
1023 break;
1024 case Opt_vers_3:
1025 mnt->flags |= NFS_MOUNT_VER3;
1026 mnt->version = 3;
1027 break;
1028 case Opt_vers_4:
1029 /* Backward compatibility option. In future,
1030 * the mount program should always supply
1031 * a NFSv4 minor version number.
1032 */
1033 mnt->version = 4;
1034 break;
1035 case Opt_vers_4_0:
1036 mnt->version = 4;
1037 mnt->minorversion = 0;
1038 break;
1039 case Opt_vers_4_1:
1040 mnt->version = 4;
1041 mnt->minorversion = 1;
1042 break;
1043 default:
1044 return 0;
1045 }
1046 return 1;
1047 }
1048
1049 static int nfs_get_option_str(substring_t args[], char **option)
1050 {
1051 kfree(*option);
1052 *option = match_strdup(args);
1053 return !option;
1054 }
1055
1056 static int nfs_get_option_ul(substring_t args[], unsigned long *option)
1057 {
1058 int rc;
1059 char *string;
1060
1061 string = match_strdup(args);
1062 if (string == NULL)
1063 return -ENOMEM;
1064 rc = strict_strtoul(string, 10, option);
1065 kfree(string);
1066
1067 return rc;
1068 }
1069
1070 /*
1071 * Error-check and convert a string of mount options from user space into
1072 * a data structure. The whole mount string is processed; bad options are
1073 * skipped as they are encountered. If there were no errors, return 1;
1074 * otherwise return 0 (zero).
1075 */
1076 static int nfs_parse_mount_options(char *raw,
1077 struct nfs_parsed_mount_data *mnt)
1078 {
1079 char *p, *string, *secdata;
1080 int rc, sloppy = 0, invalid_option = 0;
1081 unsigned short protofamily = AF_UNSPEC;
1082 unsigned short mountfamily = AF_UNSPEC;
1083
1084 if (!raw) {
1085 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
1086 return 1;
1087 }
1088 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
1089
1090 secdata = alloc_secdata();
1091 if (!secdata)
1092 goto out_nomem;
1093
1094 rc = security_sb_copy_data(raw, secdata);
1095 if (rc)
1096 goto out_security_failure;
1097
1098 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
1099 if (rc)
1100 goto out_security_failure;
1101
1102 free_secdata(secdata);
1103
1104 while ((p = strsep(&raw, ",")) != NULL) {
1105 substring_t args[MAX_OPT_ARGS];
1106 unsigned long option;
1107 int token;
1108
1109 if (!*p)
1110 continue;
1111
1112 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
1113
1114 token = match_token(p, nfs_mount_option_tokens, args);
1115 switch (token) {
1116
1117 /*
1118 * boolean options: foo/nofoo
1119 */
1120 case Opt_soft:
1121 mnt->flags |= NFS_MOUNT_SOFT;
1122 break;
1123 case Opt_hard:
1124 mnt->flags &= ~NFS_MOUNT_SOFT;
1125 break;
1126 case Opt_posix:
1127 mnt->flags |= NFS_MOUNT_POSIX;
1128 break;
1129 case Opt_noposix:
1130 mnt->flags &= ~NFS_MOUNT_POSIX;
1131 break;
1132 case Opt_cto:
1133 mnt->flags &= ~NFS_MOUNT_NOCTO;
1134 break;
1135 case Opt_nocto:
1136 mnt->flags |= NFS_MOUNT_NOCTO;
1137 break;
1138 case Opt_ac:
1139 mnt->flags &= ~NFS_MOUNT_NOAC;
1140 break;
1141 case Opt_noac:
1142 mnt->flags |= NFS_MOUNT_NOAC;
1143 break;
1144 case Opt_lock:
1145 mnt->flags &= ~NFS_MOUNT_NONLM;
1146 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1147 NFS_MOUNT_LOCAL_FCNTL);
1148 break;
1149 case Opt_nolock:
1150 mnt->flags |= NFS_MOUNT_NONLM;
1151 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1152 NFS_MOUNT_LOCAL_FCNTL);
1153 break;
1154 case Opt_udp:
1155 mnt->flags &= ~NFS_MOUNT_TCP;
1156 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1157 break;
1158 case Opt_tcp:
1159 mnt->flags |= NFS_MOUNT_TCP;
1160 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1161 break;
1162 case Opt_rdma:
1163 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1164 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1165 xprt_load_transport(p);
1166 break;
1167 case Opt_acl:
1168 mnt->flags &= ~NFS_MOUNT_NOACL;
1169 break;
1170 case Opt_noacl:
1171 mnt->flags |= NFS_MOUNT_NOACL;
1172 break;
1173 case Opt_rdirplus:
1174 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1175 break;
1176 case Opt_nordirplus:
1177 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1178 break;
1179 case Opt_sharecache:
1180 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1181 break;
1182 case Opt_nosharecache:
1183 mnt->flags |= NFS_MOUNT_UNSHARED;
1184 break;
1185 case Opt_resvport:
1186 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1187 break;
1188 case Opt_noresvport:
1189 mnt->flags |= NFS_MOUNT_NORESVPORT;
1190 break;
1191 case Opt_fscache:
1192 mnt->options |= NFS_OPTION_FSCACHE;
1193 kfree(mnt->fscache_uniq);
1194 mnt->fscache_uniq = NULL;
1195 break;
1196 case Opt_nofscache:
1197 mnt->options &= ~NFS_OPTION_FSCACHE;
1198 kfree(mnt->fscache_uniq);
1199 mnt->fscache_uniq = NULL;
1200 break;
1201
1202 /*
1203 * options that take numeric values
1204 */
1205 case Opt_port:
1206 if (nfs_get_option_ul(args, &option) ||
1207 option > USHRT_MAX)
1208 goto out_invalid_value;
1209 mnt->nfs_server.port = option;
1210 break;
1211 case Opt_rsize:
1212 if (nfs_get_option_ul(args, &option))
1213 goto out_invalid_value;
1214 mnt->rsize = option;
1215 break;
1216 case Opt_wsize:
1217 if (nfs_get_option_ul(args, &option))
1218 goto out_invalid_value;
1219 mnt->wsize = option;
1220 break;
1221 case Opt_bsize:
1222 if (nfs_get_option_ul(args, &option))
1223 goto out_invalid_value;
1224 mnt->bsize = option;
1225 break;
1226 case Opt_timeo:
1227 if (nfs_get_option_ul(args, &option) || option == 0)
1228 goto out_invalid_value;
1229 mnt->timeo = option;
1230 break;
1231 case Opt_retrans:
1232 if (nfs_get_option_ul(args, &option) || option == 0)
1233 goto out_invalid_value;
1234 mnt->retrans = option;
1235 break;
1236 case Opt_acregmin:
1237 if (nfs_get_option_ul(args, &option))
1238 goto out_invalid_value;
1239 mnt->acregmin = option;
1240 break;
1241 case Opt_acregmax:
1242 if (nfs_get_option_ul(args, &option))
1243 goto out_invalid_value;
1244 mnt->acregmax = option;
1245 break;
1246 case Opt_acdirmin:
1247 if (nfs_get_option_ul(args, &option))
1248 goto out_invalid_value;
1249 mnt->acdirmin = option;
1250 break;
1251 case Opt_acdirmax:
1252 if (nfs_get_option_ul(args, &option))
1253 goto out_invalid_value;
1254 mnt->acdirmax = option;
1255 break;
1256 case Opt_actimeo:
1257 if (nfs_get_option_ul(args, &option))
1258 goto out_invalid_value;
1259 mnt->acregmin = mnt->acregmax =
1260 mnt->acdirmin = mnt->acdirmax = option;
1261 break;
1262 case Opt_namelen:
1263 if (nfs_get_option_ul(args, &option))
1264 goto out_invalid_value;
1265 mnt->namlen = option;
1266 break;
1267 case Opt_mountport:
1268 if (nfs_get_option_ul(args, &option) ||
1269 option > USHRT_MAX)
1270 goto out_invalid_value;
1271 mnt->mount_server.port = option;
1272 break;
1273 case Opt_mountvers:
1274 if (nfs_get_option_ul(args, &option) ||
1275 option < NFS_MNT_VERSION ||
1276 option > NFS_MNT3_VERSION)
1277 goto out_invalid_value;
1278 mnt->mount_server.version = option;
1279 break;
1280 case Opt_minorversion:
1281 if (nfs_get_option_ul(args, &option))
1282 goto out_invalid_value;
1283 if (option > NFS4_MAX_MINOR_VERSION)
1284 goto out_invalid_value;
1285 mnt->minorversion = option;
1286 break;
1287
1288 /*
1289 * options that take text values
1290 */
1291 case Opt_nfsvers:
1292 string = match_strdup(args);
1293 if (string == NULL)
1294 goto out_nomem;
1295 rc = nfs_parse_version_string(string, mnt, args);
1296 kfree(string);
1297 if (!rc)
1298 goto out_invalid_value;
1299 break;
1300 case Opt_sec:
1301 string = match_strdup(args);
1302 if (string == NULL)
1303 goto out_nomem;
1304 rc = nfs_parse_security_flavors(string, mnt);
1305 kfree(string);
1306 if (!rc) {
1307 dfprintk(MOUNT, "NFS: unrecognized "
1308 "security flavor\n");
1309 return 0;
1310 }
1311 break;
1312 case Opt_proto:
1313 string = match_strdup(args);
1314 if (string == NULL)
1315 goto out_nomem;
1316 token = match_token(string,
1317 nfs_xprt_protocol_tokens, args);
1318
1319 protofamily = AF_INET;
1320 switch (token) {
1321 case Opt_xprt_udp6:
1322 protofamily = AF_INET6;
1323 case Opt_xprt_udp:
1324 mnt->flags &= ~NFS_MOUNT_TCP;
1325 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1326 break;
1327 case Opt_xprt_tcp6:
1328 protofamily = AF_INET6;
1329 case Opt_xprt_tcp:
1330 mnt->flags |= NFS_MOUNT_TCP;
1331 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1332 break;
1333 case Opt_xprt_rdma:
1334 /* vector side protocols to TCP */
1335 mnt->flags |= NFS_MOUNT_TCP;
1336 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1337 xprt_load_transport(string);
1338 break;
1339 default:
1340 dfprintk(MOUNT, "NFS: unrecognized "
1341 "transport protocol\n");
1342 kfree(string);
1343 return 0;
1344 }
1345 kfree(string);
1346 break;
1347 case Opt_mountproto:
1348 string = match_strdup(args);
1349 if (string == NULL)
1350 goto out_nomem;
1351 token = match_token(string,
1352 nfs_xprt_protocol_tokens, args);
1353 kfree(string);
1354
1355 mountfamily = AF_INET;
1356 switch (token) {
1357 case Opt_xprt_udp6:
1358 mountfamily = AF_INET6;
1359 case Opt_xprt_udp:
1360 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
1361 break;
1362 case Opt_xprt_tcp6:
1363 mountfamily = AF_INET6;
1364 case Opt_xprt_tcp:
1365 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
1366 break;
1367 case Opt_xprt_rdma: /* not used for side protocols */
1368 default:
1369 dfprintk(MOUNT, "NFS: unrecognized "
1370 "transport protocol\n");
1371 return 0;
1372 }
1373 break;
1374 case Opt_addr:
1375 string = match_strdup(args);
1376 if (string == NULL)
1377 goto out_nomem;
1378 mnt->nfs_server.addrlen =
1379 rpc_pton(mnt->net, string, strlen(string),
1380 (struct sockaddr *)
1381 &mnt->nfs_server.address,
1382 sizeof(mnt->nfs_server.address));
1383 kfree(string);
1384 if (mnt->nfs_server.addrlen == 0)
1385 goto out_invalid_address;
1386 break;
1387 case Opt_clientaddr:
1388 if (nfs_get_option_str(args, &mnt->client_address))
1389 goto out_nomem;
1390 break;
1391 case Opt_mounthost:
1392 if (nfs_get_option_str(args,
1393 &mnt->mount_server.hostname))
1394 goto out_nomem;
1395 break;
1396 case Opt_mountaddr:
1397 string = match_strdup(args);
1398 if (string == NULL)
1399 goto out_nomem;
1400 mnt->mount_server.addrlen =
1401 rpc_pton(mnt->net, string, strlen(string),
1402 (struct sockaddr *)
1403 &mnt->mount_server.address,
1404 sizeof(mnt->mount_server.address));
1405 kfree(string);
1406 if (mnt->mount_server.addrlen == 0)
1407 goto out_invalid_address;
1408 break;
1409 case Opt_lookupcache:
1410 string = match_strdup(args);
1411 if (string == NULL)
1412 goto out_nomem;
1413 token = match_token(string,
1414 nfs_lookupcache_tokens, args);
1415 kfree(string);
1416 switch (token) {
1417 case Opt_lookupcache_all:
1418 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1419 break;
1420 case Opt_lookupcache_positive:
1421 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1422 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1423 break;
1424 case Opt_lookupcache_none:
1425 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1426 break;
1427 default:
1428 dfprintk(MOUNT, "NFS: invalid "
1429 "lookupcache argument\n");
1430 return 0;
1431 };
1432 break;
1433 case Opt_fscache_uniq:
1434 if (nfs_get_option_str(args, &mnt->fscache_uniq))
1435 goto out_nomem;
1436 mnt->options |= NFS_OPTION_FSCACHE;
1437 break;
1438 case Opt_local_lock:
1439 string = match_strdup(args);
1440 if (string == NULL)
1441 goto out_nomem;
1442 token = match_token(string, nfs_local_lock_tokens,
1443 args);
1444 kfree(string);
1445 switch (token) {
1446 case Opt_local_lock_all:
1447 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1448 NFS_MOUNT_LOCAL_FCNTL);
1449 break;
1450 case Opt_local_lock_flock:
1451 mnt->flags |= NFS_MOUNT_LOCAL_FLOCK;
1452 break;
1453 case Opt_local_lock_posix:
1454 mnt->flags |= NFS_MOUNT_LOCAL_FCNTL;
1455 break;
1456 case Opt_local_lock_none:
1457 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1458 NFS_MOUNT_LOCAL_FCNTL);
1459 break;
1460 default:
1461 dfprintk(MOUNT, "NFS: invalid "
1462 "local_lock argument\n");
1463 return 0;
1464 };
1465 break;
1466
1467 /*
1468 * Special options
1469 */
1470 case Opt_sloppy:
1471 sloppy = 1;
1472 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1473 break;
1474 case Opt_userspace:
1475 case Opt_deprecated:
1476 dfprintk(MOUNT, "NFS: ignoring mount option "
1477 "'%s'\n", p);
1478 break;
1479
1480 default:
1481 invalid_option = 1;
1482 dfprintk(MOUNT, "NFS: unrecognized mount option "
1483 "'%s'\n", p);
1484 }
1485 }
1486
1487 if (!sloppy && invalid_option)
1488 return 0;
1489
1490 if (mnt->minorversion && mnt->version != 4)
1491 goto out_minorversion_mismatch;
1492
1493 /*
1494 * verify that any proto=/mountproto= options match the address
1495 * familiies in the addr=/mountaddr= options.
1496 */
1497 if (protofamily != AF_UNSPEC &&
1498 protofamily != mnt->nfs_server.address.ss_family)
1499 goto out_proto_mismatch;
1500
1501 if (mountfamily != AF_UNSPEC) {
1502 if (mnt->mount_server.addrlen) {
1503 if (mountfamily != mnt->mount_server.address.ss_family)
1504 goto out_mountproto_mismatch;
1505 } else {
1506 if (mountfamily != mnt->nfs_server.address.ss_family)
1507 goto out_mountproto_mismatch;
1508 }
1509 }
1510
1511 return 1;
1512
1513 out_mountproto_mismatch:
1514 printk(KERN_INFO "NFS: mount server address does not match mountproto= "
1515 "option\n");
1516 return 0;
1517 out_proto_mismatch:
1518 printk(KERN_INFO "NFS: server address does not match proto= option\n");
1519 return 0;
1520 out_invalid_address:
1521 printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
1522 return 0;
1523 out_invalid_value:
1524 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
1525 return 0;
1526 out_minorversion_mismatch:
1527 printk(KERN_INFO "NFS: mount option vers=%u does not support "
1528 "minorversion=%u\n", mnt->version, mnt->minorversion);
1529 return 0;
1530 out_nomem:
1531 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1532 return 0;
1533 out_security_failure:
1534 free_secdata(secdata);
1535 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1536 return 0;
1537 }
1538
1539 /*
1540 * Match the requested auth flavors with the list returned by
1541 * the server. Returns zero and sets the mount's authentication
1542 * flavor on success; returns -EACCES if server does not support
1543 * the requested flavor.
1544 */
1545 static int nfs_walk_authlist(struct nfs_parsed_mount_data *args,
1546 struct nfs_mount_request *request)
1547 {
1548 unsigned int i, j, server_authlist_len = *(request->auth_flav_len);
1549
1550 /*
1551 * Certain releases of Linux's mountd return an empty
1552 * flavor list. To prevent behavioral regression with
1553 * these servers (ie. rejecting mounts that used to
1554 * succeed), revert to pre-2.6.32 behavior (no checking)
1555 * if the returned flavor list is empty.
1556 */
1557 if (server_authlist_len == 0)
1558 return 0;
1559
1560 /*
1561 * We avoid sophisticated negotiating here, as there are
1562 * plenty of cases where we can get it wrong, providing
1563 * either too little or too much security.
1564 *
1565 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1566 * flavor listed first. However, some servers list
1567 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1568 * preferred default, in args->auth_flavors[0] if user
1569 * didn't specify sec= mount option.
1570 */
1571 for (i = 0; i < args->auth_flavor_len; i++)
1572 for (j = 0; j < server_authlist_len; j++)
1573 if (args->auth_flavors[i] == request->auth_flavs[j]) {
1574 dfprintk(MOUNT, "NFS: using auth flavor %d\n",
1575 request->auth_flavs[j]);
1576 args->auth_flavors[0] = request->auth_flavs[j];
1577 return 0;
1578 }
1579
1580 dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n");
1581 nfs_umount(request);
1582 return -EACCES;
1583 }
1584
1585 /*
1586 * Use the remote server's MOUNT service to request the NFS file handle
1587 * corresponding to the provided path.
1588 */
1589 static int nfs_request_mount(struct nfs_parsed_mount_data *args,
1590 struct nfs_fh *root_fh)
1591 {
1592 rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS];
1593 unsigned int server_authlist_len = ARRAY_SIZE(server_authlist);
1594 struct nfs_mount_request request = {
1595 .sap = (struct sockaddr *)
1596 &args->mount_server.address,
1597 .dirpath = args->nfs_server.export_path,
1598 .protocol = args->mount_server.protocol,
1599 .fh = root_fh,
1600 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
1601 .auth_flav_len = &server_authlist_len,
1602 .auth_flavs = server_authlist,
1603 .net = args->net,
1604 };
1605 int status;
1606
1607 if (args->mount_server.version == 0) {
1608 switch (args->version) {
1609 default:
1610 args->mount_server.version = NFS_MNT3_VERSION;
1611 break;
1612 case 2:
1613 args->mount_server.version = NFS_MNT_VERSION;
1614 }
1615 }
1616 request.version = args->mount_server.version;
1617
1618 if (args->mount_server.hostname)
1619 request.hostname = args->mount_server.hostname;
1620 else
1621 request.hostname = args->nfs_server.hostname;
1622
1623 /*
1624 * Construct the mount server's address.
1625 */
1626 if (args->mount_server.address.ss_family == AF_UNSPEC) {
1627 memcpy(request.sap, &args->nfs_server.address,
1628 args->nfs_server.addrlen);
1629 args->mount_server.addrlen = args->nfs_server.addrlen;
1630 }
1631 request.salen = args->mount_server.addrlen;
1632 nfs_set_port(request.sap, &args->mount_server.port, 0);
1633
1634 /*
1635 * Now ask the mount server to map our export path
1636 * to a file handle.
1637 */
1638 status = nfs_mount(&request);
1639 if (status != 0) {
1640 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1641 request.hostname, status);
1642 return status;
1643 }
1644
1645 /*
1646 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1647 */
1648 if (args->mount_server.version != NFS_MNT3_VERSION)
1649 return 0;
1650 return nfs_walk_authlist(args, &request);
1651 }
1652
1653 static struct dentry *nfs_try_mount(int flags, const char *dev_name,
1654 struct nfs_mount_info *mount_info,
1655 struct nfs_subversion *nfs_mod)
1656 {
1657 int status;
1658 struct nfs_server *server;
1659
1660 if (mount_info->parsed->need_mount) {
1661 status = nfs_request_mount(mount_info->parsed, mount_info->mntfh);
1662 if (status)
1663 return ERR_PTR(status);
1664 }
1665
1666 /* Get a volume representation */
1667 server = nfs_create_server(mount_info->parsed, mount_info->mntfh, nfs_mod);
1668 if (IS_ERR(server))
1669 return ERR_CAST(server);
1670
1671 return nfs_fs_mount_common(server, flags, dev_name, mount_info, nfs_mod);
1672 }
1673
1674 /*
1675 * Split "dev_name" into "hostname:export_path".
1676 *
1677 * The leftmost colon demarks the split between the server's hostname
1678 * and the export path. If the hostname starts with a left square
1679 * bracket, then it may contain colons.
1680 *
1681 * Note: caller frees hostname and export path, even on error.
1682 */
1683 static int nfs_parse_devname(const char *dev_name,
1684 char **hostname, size_t maxnamlen,
1685 char **export_path, size_t maxpathlen)
1686 {
1687 size_t len;
1688 char *end;
1689
1690 /* Is the host name protected with square brakcets? */
1691 if (*dev_name == '[') {
1692 end = strchr(++dev_name, ']');
1693 if (end == NULL || end[1] != ':')
1694 goto out_bad_devname;
1695
1696 len = end - dev_name;
1697 end++;
1698 } else {
1699 char *comma;
1700
1701 end = strchr(dev_name, ':');
1702 if (end == NULL)
1703 goto out_bad_devname;
1704 len = end - dev_name;
1705
1706 /* kill possible hostname list: not supported */
1707 comma = strchr(dev_name, ',');
1708 if (comma != NULL && comma < end)
1709 *comma = 0;
1710 }
1711
1712 if (len > maxnamlen)
1713 goto out_hostname;
1714
1715 /* N.B. caller will free nfs_server.hostname in all cases */
1716 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
1717 if (*hostname == NULL)
1718 goto out_nomem;
1719 len = strlen(++end);
1720 if (len > maxpathlen)
1721 goto out_path;
1722 *export_path = kstrndup(end, len, GFP_KERNEL);
1723 if (!*export_path)
1724 goto out_nomem;
1725
1726 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1727 return 0;
1728
1729 out_bad_devname:
1730 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1731 return -EINVAL;
1732
1733 out_nomem:
1734 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1735 return -ENOMEM;
1736
1737 out_hostname:
1738 dfprintk(MOUNT, "NFS: server hostname too long\n");
1739 return -ENAMETOOLONG;
1740
1741 out_path:
1742 dfprintk(MOUNT, "NFS: export pathname too long\n");
1743 return -ENAMETOOLONG;
1744 }
1745
1746 /*
1747 * Validate the NFS2/NFS3 mount data
1748 * - fills in the mount root filehandle
1749 *
1750 * For option strings, user space handles the following behaviors:
1751 *
1752 * + DNS: mapping server host name to IP address ("addr=" option)
1753 *
1754 * + failure mode: how to behave if a mount request can't be handled
1755 * immediately ("fg/bg" option)
1756 *
1757 * + retry: how often to retry a mount request ("retry=" option)
1758 *
1759 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1760 * mountproto=tcp after mountproto=udp, and so on
1761 */
1762 static int nfs23_validate_mount_data(void *options,
1763 struct nfs_parsed_mount_data *args,
1764 struct nfs_fh *mntfh,
1765 const char *dev_name)
1766 {
1767 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
1768 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
1769
1770 if (data == NULL)
1771 goto out_no_data;
1772
1773 args->version = NFS_DEFAULT_VERSION;
1774 switch (data->version) {
1775 case 1:
1776 data->namlen = 0;
1777 case 2:
1778 data->bsize = 0;
1779 case 3:
1780 if (data->flags & NFS_MOUNT_VER3)
1781 goto out_no_v3;
1782 data->root.size = NFS2_FHSIZE;
1783 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1784 case 4:
1785 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1786 goto out_no_sec;
1787 case 5:
1788 memset(data->context, 0, sizeof(data->context));
1789 case 6:
1790 if (data->flags & NFS_MOUNT_VER3) {
1791 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1792 goto out_invalid_fh;
1793 mntfh->size = data->root.size;
1794 args->version = 3;
1795 } else {
1796 mntfh->size = NFS2_FHSIZE;
1797 args->version = 2;
1798 }
1799
1800
1801 memcpy(mntfh->data, data->root.data, mntfh->size);
1802 if (mntfh->size < sizeof(mntfh->data))
1803 memset(mntfh->data + mntfh->size, 0,
1804 sizeof(mntfh->data) - mntfh->size);
1805
1806 /*
1807 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1808 * can deal with.
1809 */
1810 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
1811 args->flags |= NFS_MOUNT_LEGACY_INTERFACE;
1812 args->rsize = data->rsize;
1813 args->wsize = data->wsize;
1814 args->timeo = data->timeo;
1815 args->retrans = data->retrans;
1816 args->acregmin = data->acregmin;
1817 args->acregmax = data->acregmax;
1818 args->acdirmin = data->acdirmin;
1819 args->acdirmax = data->acdirmax;
1820 args->need_mount = false;
1821
1822 memcpy(sap, &data->addr, sizeof(data->addr));
1823 args->nfs_server.addrlen = sizeof(data->addr);
1824 if (!nfs_verify_server_address(sap))
1825 goto out_no_address;
1826
1827 if (!(data->flags & NFS_MOUNT_TCP))
1828 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1829 /* N.B. caller will free nfs_server.hostname in all cases */
1830 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1831 args->namlen = data->namlen;
1832 args->bsize = data->bsize;
1833
1834 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1835 args->auth_flavors[0] = data->pseudoflavor;
1836 if (!args->nfs_server.hostname)
1837 goto out_nomem;
1838
1839 if (!(data->flags & NFS_MOUNT_NONLM))
1840 args->flags &= ~(NFS_MOUNT_LOCAL_FLOCK|
1841 NFS_MOUNT_LOCAL_FCNTL);
1842 else
1843 args->flags |= (NFS_MOUNT_LOCAL_FLOCK|
1844 NFS_MOUNT_LOCAL_FCNTL);
1845 /*
1846 * The legacy version 6 binary mount data from userspace has a
1847 * field used only to transport selinux information into the
1848 * the kernel. To continue to support that functionality we
1849 * have a touch of selinux knowledge here in the NFS code. The
1850 * userspace code converted context=blah to just blah so we are
1851 * converting back to the full string selinux understands.
1852 */
1853 if (data->context[0]){
1854 #ifdef CONFIG_SECURITY_SELINUX
1855 int rc;
1856 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1857 if (!opts_str)
1858 return -ENOMEM;
1859 strcpy(opts_str, "context=");
1860 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1861 strcat(opts_str, &data->context[0]);
1862 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1863 kfree(opts_str);
1864 if (rc)
1865 return rc;
1866 #else
1867 return -EINVAL;
1868 #endif
1869 }
1870
1871 break;
1872 default:
1873 return NFS_TEXT_DATA;
1874 }
1875
1876 #ifndef CONFIG_NFS_V3
1877 if (args->version == 3)
1878 goto out_v3_not_compiled;
1879 #endif /* !CONFIG_NFS_V3 */
1880
1881 return 0;
1882
1883 out_no_data:
1884 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1885 return -EINVAL;
1886
1887 out_no_v3:
1888 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1889 data->version);
1890 return -EINVAL;
1891
1892 out_no_sec:
1893 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1894 return -EINVAL;
1895
1896 #ifndef CONFIG_NFS_V3
1897 out_v3_not_compiled:
1898 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1899 return -EPROTONOSUPPORT;
1900 #endif /* !CONFIG_NFS_V3 */
1901
1902 out_nomem:
1903 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
1904 return -ENOMEM;
1905
1906 out_no_address:
1907 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1908 return -EINVAL;
1909
1910 out_invalid_fh:
1911 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1912 return -EINVAL;
1913 }
1914
1915 #ifdef CONFIG_NFS_V4
1916 static int nfs_validate_mount_data(struct file_system_type *fs_type,
1917 void *options,
1918 struct nfs_parsed_mount_data *args,
1919 struct nfs_fh *mntfh,
1920 const char *dev_name)
1921 {
1922 if (fs_type == &nfs_fs_type)
1923 return nfs23_validate_mount_data(options, args, mntfh, dev_name);
1924 return nfs4_validate_mount_data(options, args, dev_name);
1925 }
1926 #else
1927 static int nfs_validate_mount_data(struct file_system_type *fs_type,
1928 void *options,
1929 struct nfs_parsed_mount_data *args,
1930 struct nfs_fh *mntfh,
1931 const char *dev_name)
1932 {
1933 return nfs23_validate_mount_data(options, args, mntfh, dev_name);
1934 }
1935 #endif
1936
1937 static int nfs_validate_text_mount_data(void *options,
1938 struct nfs_parsed_mount_data *args,
1939 const char *dev_name)
1940 {
1941 int port = 0;
1942 int max_namelen = PAGE_SIZE;
1943 int max_pathlen = NFS_MAXPATHLEN;
1944 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
1945
1946 if (nfs_parse_mount_options((char *)options, args) == 0)
1947 return -EINVAL;
1948
1949 if (!nfs_verify_server_address(sap))
1950 goto out_no_address;
1951
1952 if (args->version == 4) {
1953 #ifdef CONFIG_NFS_V4
1954 port = NFS_PORT;
1955 max_namelen = NFS4_MAXNAMLEN;
1956 max_pathlen = NFS4_MAXPATHLEN;
1957 nfs_validate_transport_protocol(args);
1958 nfs4_validate_mount_flags(args);
1959 #else
1960 goto out_v4_not_compiled;
1961 #endif /* CONFIG_NFS_V4 */
1962 } else
1963 nfs_set_mount_transport_protocol(args);
1964
1965 nfs_set_port(sap, &args->nfs_server.port, port);
1966
1967 if (args->auth_flavor_len > 1)
1968 goto out_bad_auth;
1969
1970 return nfs_parse_devname(dev_name,
1971 &args->nfs_server.hostname,
1972 max_namelen,
1973 &args->nfs_server.export_path,
1974 max_pathlen);
1975
1976 #ifndef CONFIG_NFS_V4
1977 out_v4_not_compiled:
1978 dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n");
1979 return -EPROTONOSUPPORT;
1980 #endif /* !CONFIG_NFS_V4 */
1981
1982 out_no_address:
1983 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1984 return -EINVAL;
1985
1986 out_bad_auth:
1987 dfprintk(MOUNT, "NFS: Too many RPC auth flavours specified\n");
1988 return -EINVAL;
1989 }
1990
1991 static int
1992 nfs_compare_remount_data(struct nfs_server *nfss,
1993 struct nfs_parsed_mount_data *data)
1994 {
1995 if (data->flags != nfss->flags ||
1996 data->rsize != nfss->rsize ||
1997 data->wsize != nfss->wsize ||
1998 data->retrans != nfss->client->cl_timeout->to_retries ||
1999 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
2000 data->acregmin != nfss->acregmin / HZ ||
2001 data->acregmax != nfss->acregmax / HZ ||
2002 data->acdirmin != nfss->acdirmin / HZ ||
2003 data->acdirmax != nfss->acdirmax / HZ ||
2004 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
2005 data->nfs_server.port != nfss->port ||
2006 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
2007 !rpc_cmp_addr((struct sockaddr *)&data->nfs_server.address,
2008 (struct sockaddr *)&nfss->nfs_client->cl_addr))
2009 return -EINVAL;
2010
2011 return 0;
2012 }
2013
2014 int
2015 nfs_remount(struct super_block *sb, int *flags, char *raw_data)
2016 {
2017 int error;
2018 struct nfs_server *nfss = sb->s_fs_info;
2019 struct nfs_parsed_mount_data *data;
2020 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
2021 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
2022 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
2023
2024 /*
2025 * Userspace mount programs that send binary options generally send
2026 * them populated with default values. We have no way to know which
2027 * ones were explicitly specified. Fall back to legacy behavior and
2028 * just return success.
2029 */
2030 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
2031 (nfsvers <= 3 && (!options || (options->version >= 1 &&
2032 options->version <= 6))))
2033 return 0;
2034
2035 data = kzalloc(sizeof(*data), GFP_KERNEL);
2036 if (data == NULL)
2037 return -ENOMEM;
2038
2039 /* fill out struct with values from existing mount */
2040 data->flags = nfss->flags;
2041 data->rsize = nfss->rsize;
2042 data->wsize = nfss->wsize;
2043 data->retrans = nfss->client->cl_timeout->to_retries;
2044 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
2045 data->acregmin = nfss->acregmin / HZ;
2046 data->acregmax = nfss->acregmax / HZ;
2047 data->acdirmin = nfss->acdirmin / HZ;
2048 data->acdirmax = nfss->acdirmax / HZ;
2049 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
2050 data->nfs_server.port = nfss->port;
2051 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
2052 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
2053 data->nfs_server.addrlen);
2054
2055 /* overwrite those values with any that were specified */
2056 error = nfs_parse_mount_options((char *)options, data);
2057 if (error < 0)
2058 goto out;
2059
2060 /*
2061 * noac is a special case. It implies -o sync, but that's not
2062 * necessarily reflected in the mtab options. do_remount_sb
2063 * will clear MS_SYNCHRONOUS if -o sync wasn't specified in the
2064 * remount options, so we have to explicitly reset it.
2065 */
2066 if (data->flags & NFS_MOUNT_NOAC)
2067 *flags |= MS_SYNCHRONOUS;
2068
2069 /* compare new mount options with old ones */
2070 error = nfs_compare_remount_data(nfss, data);
2071 out:
2072 kfree(data);
2073 return error;
2074 }
2075
2076 /*
2077 * Initialise the common bits of the superblock
2078 */
2079 inline void nfs_initialise_sb(struct super_block *sb)
2080 {
2081 struct nfs_server *server = NFS_SB(sb);
2082
2083 sb->s_magic = NFS_SUPER_MAGIC;
2084
2085 /* We probably want something more informative here */
2086 snprintf(sb->s_id, sizeof(sb->s_id),
2087 "%u:%u", MAJOR(sb->s_dev), MINOR(sb->s_dev));
2088
2089 if (sb->s_blocksize == 0)
2090 sb->s_blocksize = nfs_block_bits(server->wsize,
2091 &sb->s_blocksize_bits);
2092
2093 sb->s_bdi = &server->backing_dev_info;
2094
2095 nfs_super_set_maxbytes(sb, server->maxfilesize);
2096 }
2097
2098 /*
2099 * Finish setting up an NFS2/3 superblock
2100 */
2101 void nfs_fill_super(struct super_block *sb, struct nfs_mount_info *mount_info)
2102 {
2103 struct nfs_parsed_mount_data *data = mount_info->parsed;
2104 struct nfs_server *server = NFS_SB(sb);
2105
2106 sb->s_blocksize_bits = 0;
2107 sb->s_blocksize = 0;
2108 if (data->bsize)
2109 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
2110
2111 if (server->nfs_client->rpc_ops->version == 3) {
2112 /* The VFS shouldn't apply the umask to mode bits. We will do
2113 * so ourselves when necessary.
2114 */
2115 sb->s_flags |= MS_POSIXACL;
2116 sb->s_time_gran = 1;
2117 }
2118
2119 sb->s_op = &nfs_sops;
2120 nfs_initialise_sb(sb);
2121 }
2122
2123 /*
2124 * Finish setting up a cloned NFS2/3/4 superblock
2125 */
2126 void nfs_clone_super(struct super_block *sb, struct nfs_mount_info *mount_info)
2127 {
2128 const struct super_block *old_sb = mount_info->cloned->sb;
2129 struct nfs_server *server = NFS_SB(sb);
2130
2131 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2132 sb->s_blocksize = old_sb->s_blocksize;
2133 sb->s_maxbytes = old_sb->s_maxbytes;
2134 sb->s_xattr = old_sb->s_xattr;
2135 sb->s_op = old_sb->s_op;
2136 sb->s_time_gran = 1;
2137
2138 if (server->nfs_client->rpc_ops->version != 2) {
2139 /* The VFS shouldn't apply the umask to mode bits. We will do
2140 * so ourselves when necessary.
2141 */
2142 sb->s_flags |= MS_POSIXACL;
2143 }
2144
2145 nfs_initialise_sb(sb);
2146 }
2147
2148 static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
2149 {
2150 const struct nfs_server *a = s->s_fs_info;
2151 const struct rpc_clnt *clnt_a = a->client;
2152 const struct rpc_clnt *clnt_b = b->client;
2153
2154 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
2155 goto Ebusy;
2156 if (a->nfs_client != b->nfs_client)
2157 goto Ebusy;
2158 if (a->flags != b->flags)
2159 goto Ebusy;
2160 if (a->wsize != b->wsize)
2161 goto Ebusy;
2162 if (a->rsize != b->rsize)
2163 goto Ebusy;
2164 if (a->acregmin != b->acregmin)
2165 goto Ebusy;
2166 if (a->acregmax != b->acregmax)
2167 goto Ebusy;
2168 if (a->acdirmin != b->acdirmin)
2169 goto Ebusy;
2170 if (a->acdirmax != b->acdirmax)
2171 goto Ebusy;
2172 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
2173 goto Ebusy;
2174 return 1;
2175 Ebusy:
2176 return 0;
2177 }
2178
2179 struct nfs_sb_mountdata {
2180 struct nfs_server *server;
2181 int mntflags;
2182 };
2183
2184 static int nfs_set_super(struct super_block *s, void *data)
2185 {
2186 struct nfs_sb_mountdata *sb_mntdata = data;
2187 struct nfs_server *server = sb_mntdata->server;
2188 int ret;
2189
2190 s->s_flags = sb_mntdata->mntflags;
2191 s->s_fs_info = server;
2192 s->s_d_op = server->nfs_client->rpc_ops->dentry_ops;
2193 ret = set_anon_super(s, server);
2194 if (ret == 0)
2195 server->s_dev = s->s_dev;
2196 return ret;
2197 }
2198
2199 static int nfs_compare_super_address(struct nfs_server *server1,
2200 struct nfs_server *server2)
2201 {
2202 struct sockaddr *sap1, *sap2;
2203
2204 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
2205 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
2206
2207 if (sap1->sa_family != sap2->sa_family)
2208 return 0;
2209
2210 switch (sap1->sa_family) {
2211 case AF_INET: {
2212 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
2213 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
2214 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
2215 return 0;
2216 if (sin1->sin_port != sin2->sin_port)
2217 return 0;
2218 break;
2219 }
2220 case AF_INET6: {
2221 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
2222 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
2223 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
2224 return 0;
2225 if (sin1->sin6_port != sin2->sin6_port)
2226 return 0;
2227 break;
2228 }
2229 default:
2230 return 0;
2231 }
2232
2233 return 1;
2234 }
2235
2236 static int nfs_compare_super(struct super_block *sb, void *data)
2237 {
2238 struct nfs_sb_mountdata *sb_mntdata = data;
2239 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2240 int mntflags = sb_mntdata->mntflags;
2241
2242 if (!nfs_compare_super_address(old, server))
2243 return 0;
2244 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2245 if (old->flags & NFS_MOUNT_UNSHARED)
2246 return 0;
2247 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2248 return 0;
2249 return nfs_compare_mount_options(sb, server, mntflags);
2250 }
2251
2252 #ifdef CONFIG_NFS_FSCACHE
2253 static void nfs_get_cache_cookie(struct super_block *sb,
2254 struct nfs_parsed_mount_data *parsed,
2255 struct nfs_clone_mount *cloned)
2256 {
2257 char *uniq = NULL;
2258 int ulen = 0;
2259
2260 if (parsed && parsed->fscache_uniq) {
2261 uniq = parsed->fscache_uniq;
2262 ulen = strlen(parsed->fscache_uniq);
2263 } else if (cloned) {
2264 struct nfs_server *mnt_s = NFS_SB(cloned->sb);
2265 if (mnt_s->fscache_key) {
2266 uniq = mnt_s->fscache_key->key.uniquifier;
2267 ulen = mnt_s->fscache_key->key.uniq_len;
2268 };
2269 }
2270
2271 nfs_fscache_get_super_cookie(sb, uniq, ulen);
2272 }
2273 #else
2274 static void nfs_get_cache_cookie(struct super_block *sb,
2275 struct nfs_parsed_mount_data *parsed,
2276 struct nfs_clone_mount *cloned)
2277 {
2278 }
2279 #endif
2280
2281 static int nfs_bdi_register(struct nfs_server *server)
2282 {
2283 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
2284 }
2285
2286 int nfs_set_sb_security(struct super_block *s, struct dentry *mntroot,
2287 struct nfs_mount_info *mount_info)
2288 {
2289 return security_sb_set_mnt_opts(s, &mount_info->parsed->lsm_opts);
2290 }
2291
2292 int nfs_clone_sb_security(struct super_block *s, struct dentry *mntroot,
2293 struct nfs_mount_info *mount_info)
2294 {
2295 /* clone any lsm security options from the parent to the new sb */
2296 security_sb_clone_mnt_opts(mount_info->cloned->sb, s);
2297 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops)
2298 return -ESTALE;
2299 return 0;
2300 }
2301
2302 struct dentry *nfs_fs_mount_common(struct nfs_server *server,
2303 int flags, const char *dev_name,
2304 struct nfs_mount_info *mount_info,
2305 struct nfs_subversion *nfs_mod)
2306 {
2307 struct super_block *s;
2308 struct dentry *mntroot = ERR_PTR(-ENOMEM);
2309 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2310 struct nfs_sb_mountdata sb_mntdata = {
2311 .mntflags = flags,
2312 .server = server,
2313 };
2314 int error;
2315
2316 if (server->flags & NFS_MOUNT_UNSHARED)
2317 compare_super = NULL;
2318
2319 /* -o noac implies -o sync */
2320 if (server->flags & NFS_MOUNT_NOAC)
2321 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2322
2323 /* Get a superblock - note that we may end up sharing one that already exists */
2324 s = sget(nfs_mod->nfs_fs, compare_super, nfs_set_super, flags, &sb_mntdata);
2325 if (IS_ERR(s)) {
2326 mntroot = ERR_CAST(s);
2327 goto out_err_nosb;
2328 }
2329
2330 if (s->s_fs_info != server) {
2331 nfs_free_server(server);
2332 server = NULL;
2333 } else {
2334 error = nfs_bdi_register(server);
2335 if (error) {
2336 mntroot = ERR_PTR(error);
2337 goto error_splat_bdi;
2338 }
2339 }
2340
2341 if (!s->s_root) {
2342 /* initial superblock/root creation */
2343 mount_info->fill_super(s, mount_info);
2344 nfs_get_cache_cookie(s, mount_info->parsed, mount_info->cloned);
2345 }
2346
2347 mntroot = nfs_get_root(s, mount_info->mntfh, dev_name);
2348 if (IS_ERR(mntroot))
2349 goto error_splat_super;
2350
2351 error = mount_info->set_security(s, mntroot, mount_info);
2352 if (error)
2353 goto error_splat_root;
2354
2355 s->s_flags |= MS_ACTIVE;
2356
2357 out:
2358 return mntroot;
2359
2360 out_err_nosb:
2361 nfs_free_server(server);
2362 goto out;
2363
2364 error_splat_root:
2365 dput(mntroot);
2366 mntroot = ERR_PTR(error);
2367 error_splat_super:
2368 if (server && !s->s_root)
2369 bdi_unregister(&server->backing_dev_info);
2370 error_splat_bdi:
2371 deactivate_locked_super(s);
2372 goto out;
2373 }
2374
2375 struct dentry *nfs_fs_mount(struct file_system_type *fs_type,
2376 int flags, const char *dev_name, void *raw_data)
2377 {
2378 struct nfs_mount_info mount_info = {
2379 .fill_super = nfs_fill_super,
2380 .set_security = nfs_set_sb_security,
2381 };
2382 struct dentry *mntroot = ERR_PTR(-ENOMEM);
2383 struct nfs_subversion *nfs_mod;
2384 int error;
2385
2386 mount_info.parsed = nfs_alloc_parsed_mount_data();
2387 mount_info.mntfh = nfs_alloc_fhandle();
2388 if (mount_info.parsed == NULL || mount_info.mntfh == NULL)
2389 goto out;
2390
2391 /* Validate the mount data */
2392 error = nfs_validate_mount_data(fs_type, raw_data, mount_info.parsed, mount_info.mntfh, dev_name);
2393 if (error == NFS_TEXT_DATA)
2394 error = nfs_validate_text_mount_data(raw_data, mount_info.parsed, dev_name);
2395 if (error < 0) {
2396 mntroot = ERR_PTR(error);
2397 goto out;
2398 }
2399
2400 nfs_mod = get_nfs_version(mount_info.parsed->version);
2401 if (IS_ERR(nfs_mod)) {
2402 mntroot = ERR_CAST(nfs_mod);
2403 goto out;
2404 }
2405
2406 #ifdef CONFIG_NFS_V4
2407 if (mount_info.parsed->version == 4)
2408 mntroot = nfs4_try_mount(flags, dev_name, &mount_info);
2409 else
2410 #endif /* CONFIG_NFS_V4 */
2411 mntroot = nfs_try_mount(flags, dev_name, &mount_info, nfs_mod);
2412
2413 put_nfs_version(nfs_mod);
2414
2415 out:
2416 nfs_free_parsed_mount_data(mount_info.parsed);
2417 nfs_free_fhandle(mount_info.mntfh);
2418 return mntroot;
2419 }
2420
2421 /*
2422 * Ensure that we unregister the bdi before kill_anon_super
2423 * releases the device name
2424 */
2425 void nfs_put_super(struct super_block *s)
2426 {
2427 struct nfs_server *server = NFS_SB(s);
2428
2429 bdi_unregister(&server->backing_dev_info);
2430 }
2431
2432 /*
2433 * Destroy an NFS2/3 superblock
2434 */
2435 void nfs_kill_super(struct super_block *s)
2436 {
2437 struct nfs_server *server = NFS_SB(s);
2438
2439 kill_anon_super(s);
2440 nfs_fscache_release_super_cookie(s);
2441 nfs_free_server(server);
2442 }
2443
2444 /*
2445 * Clone an NFS2/3/4 server record on xdev traversal (FSID-change)
2446 */
2447 struct dentry *
2448 nfs_xdev_mount_common(struct file_system_type *fs_type, int flags,
2449 const char *dev_name, struct nfs_mount_info *mount_info)
2450 {
2451 struct nfs_clone_mount *data = mount_info->cloned;
2452 struct nfs_server *server;
2453 struct dentry *mntroot = ERR_PTR(-ENOMEM);
2454 struct nfs_subversion *nfs_mod = NFS_SB(data->sb)->nfs_client->cl_nfs_mod;
2455 int error;
2456
2457 dprintk("--> nfs_xdev_mount_common()\n");
2458
2459 mount_info->mntfh = data->fh;
2460
2461 /* create a new volume representation */
2462 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr, data->authflavor);
2463 if (IS_ERR(server)) {
2464 error = PTR_ERR(server);
2465 goto out_err;
2466 }
2467
2468 mntroot = nfs_fs_mount_common(server, flags, dev_name, mount_info, nfs_mod);
2469 dprintk("<-- nfs_xdev_mount_common() = 0\n");
2470 out:
2471 return mntroot;
2472
2473 out_err:
2474 dprintk("<-- nfs_xdev_mount_common() = %d [error]\n", error);
2475 goto out;
2476 }
2477
2478 /*
2479 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2480 */
2481 static struct dentry *
2482 nfs_xdev_mount(struct file_system_type *fs_type, int flags,
2483 const char *dev_name, void *raw_data)
2484 {
2485 struct nfs_mount_info mount_info = {
2486 .fill_super = nfs_clone_super,
2487 .set_security = nfs_clone_sb_security,
2488 .cloned = raw_data,
2489 };
2490 return nfs_xdev_mount_common(&nfs_fs_type, flags, dev_name, &mount_info);
2491 }
2492
2493 #ifdef CONFIG_NFS_V4
2494
2495 static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2496 {
2497 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3|
2498 NFS_MOUNT_LOCAL_FLOCK|NFS_MOUNT_LOCAL_FCNTL);
2499 }
2500
2501 /*
2502 * Validate NFSv4 mount options
2503 */
2504 static int nfs4_validate_mount_data(void *options,
2505 struct nfs_parsed_mount_data *args,
2506 const char *dev_name)
2507 {
2508 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2509 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
2510 char *c;
2511
2512 if (data == NULL)
2513 goto out_no_data;
2514
2515 args->version = 4;
2516
2517 switch (data->version) {
2518 case 1:
2519 if (data->host_addrlen > sizeof(args->nfs_server.address))
2520 goto out_no_address;
2521 if (data->host_addrlen == 0)
2522 goto out_no_address;
2523 args->nfs_server.addrlen = data->host_addrlen;
2524 if (copy_from_user(sap, data->host_addr, data->host_addrlen))
2525 return -EFAULT;
2526 if (!nfs_verify_server_address(sap))
2527 goto out_no_address;
2528
2529 if (data->auth_flavourlen) {
2530 if (data->auth_flavourlen > 1)
2531 goto out_inval_auth;
2532 if (copy_from_user(&args->auth_flavors[0],
2533 data->auth_flavours,
2534 sizeof(args->auth_flavors[0])))
2535 return -EFAULT;
2536 }
2537
2538 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2539 if (IS_ERR(c))
2540 return PTR_ERR(c);
2541 args->nfs_server.hostname = c;
2542
2543 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2544 if (IS_ERR(c))
2545 return PTR_ERR(c);
2546 args->nfs_server.export_path = c;
2547 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
2548
2549 c = strndup_user(data->client_addr.data, 16);
2550 if (IS_ERR(c))
2551 return PTR_ERR(c);
2552 args->client_address = c;
2553
2554 /*
2555 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2556 * can deal with.
2557 */
2558
2559 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2560 args->rsize = data->rsize;
2561 args->wsize = data->wsize;
2562 args->timeo = data->timeo;
2563 args->retrans = data->retrans;
2564 args->acregmin = data->acregmin;
2565 args->acregmax = data->acregmax;
2566 args->acdirmin = data->acdirmin;
2567 args->acdirmax = data->acdirmax;
2568 args->nfs_server.protocol = data->proto;
2569 nfs_validate_transport_protocol(args);
2570
2571 break;
2572 default:
2573 return NFS_TEXT_DATA;
2574 }
2575
2576 return 0;
2577
2578 out_no_data:
2579 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2580 return -EINVAL;
2581
2582 out_inval_auth:
2583 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2584 data->auth_flavourlen);
2585 return -EINVAL;
2586
2587 out_no_address:
2588 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2589 return -EINVAL;
2590 }
2591
2592 #endif /* CONFIG_NFS_V4 */
This page took 0.088962 seconds and 5 git commands to generate.