4 * Copyright (C) 1992 Rick Sladkey
6 * nfs superblock handling functions
8 * Modularised by Alan Cox <alan@lxorguk.ukuu.org.uk>, while hacking some
9 * experimental NFS changes. Modularisation taken straight from SYS5 fs.
11 * Change to nfs_read_super() to permit NFS mounts to multi-homed hosts.
12 * J.S.Peatfield@damtp.cam.ac.uk
14 * Split from inode.c by David Howells <dhowells@redhat.com>
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())
23 #include <linux/module.h>
24 #include <linux/init.h>
26 #include <linux/time.h>
27 #include <linux/kernel.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>
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>
58 #include <asm/uaccess.h>
62 #include "delegation.h"
68 #define NFSDBG_FACILITY NFSDBG_VFS
71 #define NFS_DEFAULT_VERSION 3
73 #define NFS_DEFAULT_VERSION 2
77 /* Mount options that take no arguments */
79 Opt_posix, Opt_noposix,
83 Opt_udp, Opt_tcp, Opt_rdma,
85 Opt_rdirplus, Opt_nordirplus,
86 Opt_sharecache, Opt_nosharecache,
87 Opt_resvport, Opt_noresvport,
88 Opt_fscache, Opt_nofscache,
90 /* Mount options that take integer arguments */
92 Opt_rsize, Opt_wsize, Opt_bsize,
93 Opt_timeo, Opt_retrans,
94 Opt_acregmin, Opt_acregmax,
95 Opt_acdirmin, Opt_acdirmax,
102 /* Mount options that take string arguments */
104 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
105 Opt_addr, Opt_mountaddr, Opt_clientaddr,
110 /* Special mount options */
111 Opt_userspace, Opt_deprecated, Opt_sloppy,
116 static const match_table_t nfs_mount_option_tokens = {
117 { Opt_userspace, "bg" },
118 { Opt_userspace, "fg" },
119 { Opt_userspace, "retry=%s" },
121 { Opt_sloppy, "sloppy" },
123 { Opt_soft, "soft" },
124 { Opt_hard, "hard" },
125 { Opt_deprecated, "intr" },
126 { Opt_deprecated, "nointr" },
127 { Opt_posix, "posix" },
128 { Opt_noposix, "noposix" },
130 { Opt_nocto, "nocto" },
132 { Opt_noac, "noac" },
133 { Opt_lock, "lock" },
134 { Opt_nolock, "nolock" },
137 { Opt_rdma, "rdma" },
139 { Opt_noacl, "noacl" },
140 { Opt_rdirplus, "rdirplus" },
141 { Opt_nordirplus, "nordirplus" },
142 { Opt_sharecache, "sharecache" },
143 { Opt_nosharecache, "nosharecache" },
144 { Opt_resvport, "resvport" },
145 { Opt_noresvport, "noresvport" },
146 { Opt_fscache, "fsc" },
147 { Opt_nofscache, "nofsc" },
149 { Opt_port, "port=%s" },
150 { Opt_rsize, "rsize=%s" },
151 { Opt_wsize, "wsize=%s" },
152 { Opt_bsize, "bsize=%s" },
153 { Opt_timeo, "timeo=%s" },
154 { Opt_retrans, "retrans=%s" },
155 { Opt_acregmin, "acregmin=%s" },
156 { Opt_acregmax, "acregmax=%s" },
157 { Opt_acdirmin, "acdirmin=%s" },
158 { Opt_acdirmax, "acdirmax=%s" },
159 { Opt_actimeo, "actimeo=%s" },
160 { Opt_namelen, "namlen=%s" },
161 { Opt_mountport, "mountport=%s" },
162 { Opt_mountvers, "mountvers=%s" },
163 { Opt_minorversion, "minorversion=%s" },
165 { Opt_nfsvers, "nfsvers=%s" },
166 { Opt_nfsvers, "vers=%s" },
168 { Opt_sec, "sec=%s" },
169 { Opt_proto, "proto=%s" },
170 { Opt_mountproto, "mountproto=%s" },
171 { Opt_addr, "addr=%s" },
172 { Opt_clientaddr, "clientaddr=%s" },
173 { Opt_mounthost, "mounthost=%s" },
174 { Opt_mountaddr, "mountaddr=%s" },
176 { Opt_lookupcache, "lookupcache=%s" },
177 { Opt_fscache_uniq, "fsc=%s" },
178 { Opt_local_lock, "local_lock=%s" },
180 /* The following needs to be listed after all other options */
181 { Opt_nfsvers, "v%s" },
187 Opt_xprt_udp, Opt_xprt_udp6, Opt_xprt_tcp, Opt_xprt_tcp6, Opt_xprt_rdma,
192 static const match_table_t nfs_xprt_protocol_tokens = {
193 { Opt_xprt_udp, "udp" },
194 { Opt_xprt_udp6, "udp6" },
195 { Opt_xprt_tcp, "tcp" },
196 { Opt_xprt_tcp6, "tcp6" },
197 { Opt_xprt_rdma, "rdma" },
199 { Opt_xprt_err, NULL }
203 Opt_sec_none, Opt_sec_sys,
204 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
205 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
206 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
211 static const match_table_t nfs_secflavor_tokens = {
212 { Opt_sec_none, "none" },
213 { Opt_sec_none, "null" },
214 { Opt_sec_sys, "sys" },
216 { Opt_sec_krb5, "krb5" },
217 { Opt_sec_krb5i, "krb5i" },
218 { Opt_sec_krb5p, "krb5p" },
220 { Opt_sec_lkey, "lkey" },
221 { Opt_sec_lkeyi, "lkeyi" },
222 { Opt_sec_lkeyp, "lkeyp" },
224 { Opt_sec_spkm, "spkm3" },
225 { Opt_sec_spkmi, "spkm3i" },
226 { Opt_sec_spkmp, "spkm3p" },
228 { Opt_sec_err, NULL }
232 Opt_lookupcache_all, Opt_lookupcache_positive,
233 Opt_lookupcache_none,
238 static match_table_t nfs_lookupcache_tokens = {
239 { Opt_lookupcache_all, "all" },
240 { Opt_lookupcache_positive, "pos" },
241 { Opt_lookupcache_positive, "positive" },
242 { Opt_lookupcache_none, "none" },
244 { Opt_lookupcache_err, NULL }
248 Opt_local_lock_all, Opt_local_lock_flock, Opt_local_lock_posix,
254 static match_table_t nfs_local_lock_tokens = {
255 { Opt_local_lock_all, "all" },
256 { Opt_local_lock_flock, "flock" },
257 { Opt_local_lock_posix, "posix" },
258 { Opt_local_lock_none, "none" },
260 { Opt_local_lock_err, NULL }
264 Opt_vers_2, Opt_vers_3, Opt_vers_4, Opt_vers_4_0,
270 static match_table_t nfs_vers_tokens = {
274 { Opt_vers_4_0, "4.0" },
275 { Opt_vers_4_1, "4.1" },
277 { Opt_vers_err, NULL }
280 struct nfs_mount_info {
281 void (*fill_super)(struct super_block *, struct nfs_mount_info *);
282 struct nfs_parsed_mount_data *parsed;
283 struct nfs_clone_mount *cloned;
286 static void nfs_umount_begin(struct super_block *);
287 static int nfs_statfs(struct dentry *, struct kstatfs *);
288 static int nfs_show_options(struct seq_file *, struct dentry *);
289 static int nfs_show_devname(struct seq_file *, struct dentry *);
290 static int nfs_show_path(struct seq_file *, struct dentry *);
291 static int nfs_show_stats(struct seq_file *, struct dentry *);
292 static struct dentry *nfs_fs_mount(struct file_system_type *,
293 int, const char *, void *);
294 static struct dentry *nfs_xdev_mount(struct file_system_type *fs_type,
295 int flags, const char *dev_name, void *raw_data);
296 static void nfs_put_super(struct super_block *);
297 static void nfs_kill_super(struct super_block *);
298 static int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
300 static struct file_system_type nfs_fs_type = {
301 .owner = THIS_MODULE,
303 .mount = nfs_fs_mount,
304 .kill_sb = nfs_kill_super,
305 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
308 struct file_system_type nfs_xdev_fs_type = {
309 .owner = THIS_MODULE,
311 .mount = nfs_xdev_mount,
312 .kill_sb = nfs_kill_super,
313 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
316 static const struct super_operations nfs_sops = {
317 .alloc_inode = nfs_alloc_inode,
318 .destroy_inode = nfs_destroy_inode,
319 .write_inode = nfs_write_inode,
320 .put_super = nfs_put_super,
321 .statfs = nfs_statfs,
322 .evict_inode = nfs_evict_inode,
323 .umount_begin = nfs_umount_begin,
324 .show_options = nfs_show_options,
325 .show_devname = nfs_show_devname,
326 .show_path = nfs_show_path,
327 .show_stats = nfs_show_stats,
328 .remount_fs = nfs_remount,
332 static int nfs4_validate_text_mount_data(void *options,
333 struct nfs_parsed_mount_data *args, const char *dev_name);
334 static struct dentry *nfs4_try_mount(int flags, const char *dev_name,
335 struct nfs_parsed_mount_data *data);
336 static struct dentry *nfs4_mount(struct file_system_type *fs_type,
337 int flags, const char *dev_name, void *raw_data);
338 static struct dentry *nfs4_remote_mount(struct file_system_type *fs_type,
339 int flags, const char *dev_name, void *raw_data);
340 static struct dentry *nfs4_xdev_mount(struct file_system_type *fs_type,
341 int flags, const char *dev_name, void *raw_data);
342 static struct dentry *nfs4_referral_mount(struct file_system_type *fs_type,
343 int flags, const char *dev_name, void *raw_data);
344 static struct dentry *nfs4_remote_referral_mount(struct file_system_type *fs_type,
345 int flags, const char *dev_name, void *raw_data);
346 static void nfs4_kill_super(struct super_block *sb);
348 static struct file_system_type nfs4_fs_type = {
349 .owner = THIS_MODULE,
352 .kill_sb = nfs4_kill_super,
353 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
356 static struct file_system_type nfs4_remote_fs_type = {
357 .owner = THIS_MODULE,
359 .mount = nfs4_remote_mount,
360 .kill_sb = nfs4_kill_super,
361 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
364 struct file_system_type nfs4_xdev_fs_type = {
365 .owner = THIS_MODULE,
367 .mount = nfs4_xdev_mount,
368 .kill_sb = nfs4_kill_super,
369 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
372 static struct file_system_type nfs4_remote_referral_fs_type = {
373 .owner = THIS_MODULE,
375 .mount = nfs4_remote_referral_mount,
376 .kill_sb = nfs4_kill_super,
377 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
380 struct file_system_type nfs4_referral_fs_type = {
381 .owner = THIS_MODULE,
383 .mount = nfs4_referral_mount,
384 .kill_sb = nfs4_kill_super,
385 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
388 static const struct super_operations nfs4_sops = {
389 .alloc_inode = nfs_alloc_inode,
390 .destroy_inode = nfs_destroy_inode,
391 .write_inode = nfs_write_inode,
392 .put_super = nfs_put_super,
393 .statfs = nfs_statfs,
394 .evict_inode = nfs4_evict_inode,
395 .umount_begin = nfs_umount_begin,
396 .show_options = nfs_show_options,
397 .show_devname = nfs_show_devname,
398 .show_path = nfs_show_path,
399 .show_stats = nfs_show_stats,
400 .remount_fs = nfs_remount,
404 static struct shrinker acl_shrinker = {
405 .shrink = nfs_access_cache_shrinker,
406 .seeks = DEFAULT_SEEKS,
410 * Register the NFS filesystems
412 int __init register_nfs_fs(void)
416 ret = register_filesystem(&nfs_fs_type);
420 ret = nfs_register_sysctl();
424 ret = register_filesystem(&nfs4_fs_type);
428 register_shrinker(&acl_shrinker);
433 nfs_unregister_sysctl();
436 unregister_filesystem(&nfs_fs_type);
442 * Unregister the NFS filesystems
444 void __exit unregister_nfs_fs(void)
446 unregister_shrinker(&acl_shrinker);
448 unregister_filesystem(&nfs4_fs_type);
450 nfs_unregister_sysctl();
451 unregister_filesystem(&nfs_fs_type);
454 void nfs_sb_active(struct super_block *sb)
456 struct nfs_server *server = NFS_SB(sb);
458 if (atomic_inc_return(&server->active) == 1)
459 atomic_inc(&sb->s_active);
462 void nfs_sb_deactive(struct super_block *sb)
464 struct nfs_server *server = NFS_SB(sb);
466 if (atomic_dec_and_test(&server->active))
467 deactivate_super(sb);
471 * Deliver file system statistics to userspace
473 static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
475 struct nfs_server *server = NFS_SB(dentry->d_sb);
476 unsigned char blockbits;
477 unsigned long blockres;
478 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
479 struct nfs_fsstat res;
482 res.fattr = nfs_alloc_fattr();
483 if (res.fattr == NULL)
486 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
487 if (unlikely(error == -ESTALE)) {
488 struct dentry *pd_dentry;
490 pd_dentry = dget_parent(dentry);
491 if (pd_dentry != NULL) {
492 nfs_zap_caches(pd_dentry->d_inode);
496 nfs_free_fattr(res.fattr);
500 buf->f_type = NFS_SUPER_MAGIC;
503 * Current versions of glibc do not correctly handle the
504 * case where f_frsize != f_bsize. Eventually we want to
505 * report the value of wtmult in this field.
507 buf->f_frsize = dentry->d_sb->s_blocksize;
510 * On most *nix systems, f_blocks, f_bfree, and f_bavail
511 * are reported in units of f_frsize. Linux hasn't had
512 * an f_frsize field in its statfs struct until recently,
513 * thus historically Linux's sys_statfs reports these
514 * fields in units of f_bsize.
516 buf->f_bsize = dentry->d_sb->s_blocksize;
517 blockbits = dentry->d_sb->s_blocksize_bits;
518 blockres = (1 << blockbits) - 1;
519 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
520 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
521 buf->f_bavail = (res.abytes + blockres) >> blockbits;
523 buf->f_files = res.tfiles;
524 buf->f_ffree = res.afiles;
526 buf->f_namelen = server->namelen;
531 dprintk("%s: statfs error = %d\n", __func__, -error);
536 * Map the security flavour number to a name
538 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
540 static const struct {
541 rpc_authflavor_t flavour;
544 { RPC_AUTH_NULL, "null" },
545 { RPC_AUTH_UNIX, "sys" },
546 { RPC_AUTH_GSS_KRB5, "krb5" },
547 { RPC_AUTH_GSS_KRB5I, "krb5i" },
548 { RPC_AUTH_GSS_KRB5P, "krb5p" },
549 { RPC_AUTH_GSS_LKEY, "lkey" },
550 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
551 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
552 { RPC_AUTH_GSS_SPKM, "spkm" },
553 { RPC_AUTH_GSS_SPKMI, "spkmi" },
554 { RPC_AUTH_GSS_SPKMP, "spkmp" },
555 { UINT_MAX, "unknown" }
559 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
560 if (sec_flavours[i].flavour == flavour)
563 return sec_flavours[i].str;
566 static void nfs_show_mountd_netid(struct seq_file *m, struct nfs_server *nfss,
569 struct sockaddr *sap = (struct sockaddr *) &nfss->mountd_address;
571 seq_printf(m, ",mountproto=");
572 switch (sap->sa_family) {
574 switch (nfss->mountd_protocol) {
576 seq_printf(m, RPCBIND_NETID_UDP);
579 seq_printf(m, RPCBIND_NETID_TCP);
583 seq_printf(m, "auto");
587 switch (nfss->mountd_protocol) {
589 seq_printf(m, RPCBIND_NETID_UDP6);
592 seq_printf(m, RPCBIND_NETID_TCP6);
596 seq_printf(m, "auto");
601 seq_printf(m, "auto");
605 static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
608 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
610 if (nfss->flags & NFS_MOUNT_LEGACY_INTERFACE)
613 switch (sap->sa_family) {
615 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
616 seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
620 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
621 seq_printf(m, ",mountaddr=%pI6c", &sin6->sin6_addr);
626 seq_printf(m, ",mountaddr=unspecified");
629 if (nfss->mountd_version || showdefaults)
630 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
631 if ((nfss->mountd_port &&
632 nfss->mountd_port != (unsigned short)NFS_UNSPEC_PORT) ||
634 seq_printf(m, ",mountport=%u", nfss->mountd_port);
636 nfs_show_mountd_netid(m, nfss, showdefaults);
640 static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
643 struct nfs_client *clp = nfss->nfs_client;
645 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
648 static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
654 static void nfs_show_nfs_version(struct seq_file *m,
655 unsigned int version,
656 unsigned int minorversion)
658 seq_printf(m, ",vers=%u", version);
660 seq_printf(m, ".%u", minorversion);
664 * Describe the mount options in force on this server representation
666 static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
669 static const struct proc_nfs_info {
674 { NFS_MOUNT_SOFT, ",soft", ",hard" },
675 { NFS_MOUNT_POSIX, ",posix", "" },
676 { NFS_MOUNT_NOCTO, ",nocto", "" },
677 { NFS_MOUNT_NOAC, ",noac", "" },
678 { NFS_MOUNT_NONLM, ",nolock", "" },
679 { NFS_MOUNT_NOACL, ",noacl", "" },
680 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
681 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
682 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
685 const struct proc_nfs_info *nfs_infop;
686 struct nfs_client *clp = nfss->nfs_client;
687 u32 version = clp->rpc_ops->version;
688 int local_flock, local_fcntl;
690 nfs_show_nfs_version(m, version, clp->cl_minorversion);
691 seq_printf(m, ",rsize=%u", nfss->rsize);
692 seq_printf(m, ",wsize=%u", nfss->wsize);
693 if (nfss->bsize != 0)
694 seq_printf(m, ",bsize=%u", nfss->bsize);
695 seq_printf(m, ",namlen=%u", nfss->namelen);
696 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
697 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
698 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
699 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
700 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
701 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
702 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
703 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
704 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
705 if (nfss->flags & nfs_infop->flag)
706 seq_puts(m, nfs_infop->str);
708 seq_puts(m, nfs_infop->nostr);
711 seq_printf(m, ",proto=%s",
712 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
715 if (nfss->port != NFS_PORT)
716 seq_printf(m, ",port=%u", nfss->port);
719 seq_printf(m, ",port=%u", nfss->port);
721 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
722 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
723 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
726 nfs_show_mountd_options(m, nfss, showdefaults);
728 nfs_show_nfsv4_options(m, nfss, showdefaults);
730 if (nfss->options & NFS_OPTION_FSCACHE)
731 seq_printf(m, ",fsc");
733 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONEG) {
734 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONE)
735 seq_printf(m, ",lookupcache=none");
737 seq_printf(m, ",lookupcache=pos");
740 local_flock = nfss->flags & NFS_MOUNT_LOCAL_FLOCK;
741 local_fcntl = nfss->flags & NFS_MOUNT_LOCAL_FCNTL;
743 if (!local_flock && !local_fcntl)
744 seq_printf(m, ",local_lock=none");
745 else if (local_flock && local_fcntl)
746 seq_printf(m, ",local_lock=all");
747 else if (local_flock)
748 seq_printf(m, ",local_lock=flock");
750 seq_printf(m, ",local_lock=posix");
754 * Describe the mount options on this VFS mountpoint
756 static int nfs_show_options(struct seq_file *m, struct dentry *root)
758 struct nfs_server *nfss = NFS_SB(root->d_sb);
760 nfs_show_mount_options(m, nfss, 0);
763 seq_printf(m, ",addr=%s",
764 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
772 #ifdef CONFIG_NFS_V4_1
773 static void show_sessions(struct seq_file *m, struct nfs_server *server)
775 if (nfs4_has_session(server->nfs_client))
776 seq_printf(m, ",sessions");
779 static void show_sessions(struct seq_file *m, struct nfs_server *server) {}
783 #ifdef CONFIG_NFS_V4_1
784 static void show_pnfs(struct seq_file *m, struct nfs_server *server)
786 seq_printf(m, ",pnfs=");
787 if (server->pnfs_curr_ld)
788 seq_printf(m, "%s", server->pnfs_curr_ld->name);
790 seq_printf(m, "not configured");
793 static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
795 if (nfss->nfs_client && nfss->nfs_client->impl_id) {
796 struct nfs41_impl_id *impl_id = nfss->nfs_client->impl_id;
797 seq_printf(m, "\n\timpl_id:\tname='%s',domain='%s',"
799 impl_id->name, impl_id->domain,
800 impl_id->date.seconds, impl_id->date.nseconds);
805 static void show_pnfs(struct seq_file *m, struct nfs_server *server)
809 static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
814 static int nfs_show_devname(struct seq_file *m, struct dentry *root)
816 char *page = (char *) __get_free_page(GFP_KERNEL);
817 char *devname, *dummy;
821 devname = nfs_path(&dummy, root, page, PAGE_SIZE);
823 err = PTR_ERR(devname);
825 seq_escape(m, devname, " \t\n\\");
826 free_page((unsigned long)page);
830 static int nfs_show_path(struct seq_file *m, struct dentry *dentry)
837 * Present statistical information for this VFS mountpoint
839 static int nfs_show_stats(struct seq_file *m, struct dentry *root)
842 struct nfs_server *nfss = NFS_SB(root->d_sb);
843 struct rpc_auth *auth = nfss->client->cl_auth;
844 struct nfs_iostats totals = { };
846 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
849 * Display all mount option settings
851 seq_printf(m, "\n\topts:\t");
852 seq_puts(m, root->d_sb->s_flags & MS_RDONLY ? "ro" : "rw");
853 seq_puts(m, root->d_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
854 seq_puts(m, root->d_sb->s_flags & MS_NOATIME ? ",noatime" : "");
855 seq_puts(m, root->d_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
856 nfs_show_mount_options(m, nfss, 1);
858 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
860 show_implementation_id(m, nfss);
862 seq_printf(m, "\n\tcaps:\t");
863 seq_printf(m, "caps=0x%x", nfss->caps);
864 seq_printf(m, ",wtmult=%u", nfss->wtmult);
865 seq_printf(m, ",dtsize=%u", nfss->dtsize);
866 seq_printf(m, ",bsize=%u", nfss->bsize);
867 seq_printf(m, ",namlen=%u", nfss->namelen);
870 if (nfss->nfs_client->rpc_ops->version == 4) {
871 seq_printf(m, "\n\tnfsv4:\t");
872 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
873 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
874 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
875 show_sessions(m, nfss);
881 * Display security flavor in effect for this mount
883 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
885 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
888 * Display superblock I/O counters
890 for_each_possible_cpu(cpu) {
891 struct nfs_iostats *stats;
894 stats = per_cpu_ptr(nfss->io_stats, cpu);
896 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
897 totals.events[i] += stats->events[i];
898 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
899 totals.bytes[i] += stats->bytes[i];
900 #ifdef CONFIG_NFS_FSCACHE
901 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
902 totals.fscache[i] += stats->fscache[i];
908 seq_printf(m, "\n\tevents:\t");
909 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
910 seq_printf(m, "%lu ", totals.events[i]);
911 seq_printf(m, "\n\tbytes:\t");
912 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
913 seq_printf(m, "%Lu ", totals.bytes[i]);
914 #ifdef CONFIG_NFS_FSCACHE
915 if (nfss->options & NFS_OPTION_FSCACHE) {
916 seq_printf(m, "\n\tfsc:\t");
917 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
918 seq_printf(m, "%Lu ", totals.bytes[i]);
923 rpc_print_iostats(m, nfss->client);
929 * Begin unmount by attempting to remove all automounted mountpoints we added
930 * in response to xdev traversals and referrals
932 static void nfs_umount_begin(struct super_block *sb)
934 struct nfs_server *server;
935 struct rpc_clnt *rpc;
938 /* -EIO all pending I/O */
939 rpc = server->client_acl;
941 rpc_killall_tasks(rpc);
942 rpc = server->client;
944 rpc_killall_tasks(rpc);
947 static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(unsigned int version)
949 struct nfs_parsed_mount_data *data;
951 data = kzalloc(sizeof(*data), GFP_KERNEL);
953 data->acregmin = NFS_DEF_ACREGMIN;
954 data->acregmax = NFS_DEF_ACREGMAX;
955 data->acdirmin = NFS_DEF_ACDIRMIN;
956 data->acdirmax = NFS_DEF_ACDIRMAX;
957 data->mount_server.port = NFS_UNSPEC_PORT;
958 data->nfs_server.port = NFS_UNSPEC_PORT;
959 data->nfs_server.protocol = XPRT_TRANSPORT_TCP;
960 data->auth_flavors[0] = RPC_AUTH_UNIX;
961 data->auth_flavor_len = 1;
962 data->version = version;
963 data->minorversion = 0;
964 data->net = current->nsproxy->net_ns;
965 security_init_mnt_opts(&data->lsm_opts);
970 static void nfs_free_parsed_mount_data(struct nfs_parsed_mount_data *data)
973 kfree(data->client_address);
974 kfree(data->mount_server.hostname);
975 kfree(data->nfs_server.export_path);
976 kfree(data->nfs_server.hostname);
977 kfree(data->fscache_uniq);
978 security_free_mnt_opts(&data->lsm_opts);
984 * Sanity-check a server address provided by the mount command.
986 * Address family must be initialized, and address must not be
987 * the ANY address for that family.
989 static int nfs_verify_server_address(struct sockaddr *addr)
991 switch (addr->sa_family) {
993 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
994 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
997 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
998 return !ipv6_addr_any(sa);
1002 dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
1007 * Select between a default port value and a user-specified port value.
1008 * If a zero value is set, then autobind will be used.
1010 static void nfs_set_port(struct sockaddr *sap, int *port,
1011 const unsigned short default_port)
1013 if (*port == NFS_UNSPEC_PORT)
1014 *port = default_port;
1016 rpc_set_port(sap, *port);
1020 * Sanity check the NFS transport protocol.
1023 static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
1025 switch (mnt->nfs_server.protocol) {
1026 case XPRT_TRANSPORT_UDP:
1027 case XPRT_TRANSPORT_TCP:
1028 case XPRT_TRANSPORT_RDMA:
1031 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1036 * For text based NFSv2/v3 mounts, the mount protocol transport default
1037 * settings should depend upon the specified NFS transport.
1039 static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
1041 nfs_validate_transport_protocol(mnt);
1043 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
1044 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
1046 switch (mnt->nfs_server.protocol) {
1047 case XPRT_TRANSPORT_UDP:
1048 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
1050 case XPRT_TRANSPORT_TCP:
1051 case XPRT_TRANSPORT_RDMA:
1052 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
1057 * Parse the value of the 'sec=' option.
1059 static int nfs_parse_security_flavors(char *value,
1060 struct nfs_parsed_mount_data *mnt)
1062 substring_t args[MAX_OPT_ARGS];
1064 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
1066 switch (match_token(value, nfs_secflavor_tokens, args)) {
1068 mnt->auth_flavors[0] = RPC_AUTH_NULL;
1071 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
1074 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
1077 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
1080 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
1083 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
1086 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
1089 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
1092 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
1095 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
1098 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
1104 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
1105 mnt->auth_flavor_len = 1;
1109 static int nfs_parse_version_string(char *string,
1110 struct nfs_parsed_mount_data *mnt,
1113 mnt->flags &= ~NFS_MOUNT_VER3;
1114 switch (match_token(string, nfs_vers_tokens, args)) {
1119 mnt->flags |= NFS_MOUNT_VER3;
1123 /* Backward compatibility option. In future,
1124 * the mount program should always supply
1125 * a NFSv4 minor version number.
1131 mnt->minorversion = 0;
1135 mnt->minorversion = 1;
1143 static int nfs_get_option_str(substring_t args[], char **option)
1146 *option = match_strdup(args);
1150 static int nfs_get_option_ul(substring_t args[], unsigned long *option)
1155 string = match_strdup(args);
1158 rc = strict_strtoul(string, 10, option);
1165 * Error-check and convert a string of mount options from user space into
1166 * a data structure. The whole mount string is processed; bad options are
1167 * skipped as they are encountered. If there were no errors, return 1;
1168 * otherwise return 0 (zero).
1170 static int nfs_parse_mount_options(char *raw,
1171 struct nfs_parsed_mount_data *mnt)
1173 char *p, *string, *secdata;
1174 int rc, sloppy = 0, invalid_option = 0;
1175 unsigned short protofamily = AF_UNSPEC;
1176 unsigned short mountfamily = AF_UNSPEC;
1179 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
1182 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
1184 secdata = alloc_secdata();
1188 rc = security_sb_copy_data(raw, secdata);
1190 goto out_security_failure;
1192 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
1194 goto out_security_failure;
1196 free_secdata(secdata);
1198 while ((p = strsep(&raw, ",")) != NULL) {
1199 substring_t args[MAX_OPT_ARGS];
1200 unsigned long option;
1206 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
1208 token = match_token(p, nfs_mount_option_tokens, args);
1212 * boolean options: foo/nofoo
1215 mnt->flags |= NFS_MOUNT_SOFT;
1218 mnt->flags &= ~NFS_MOUNT_SOFT;
1221 mnt->flags |= NFS_MOUNT_POSIX;
1224 mnt->flags &= ~NFS_MOUNT_POSIX;
1227 mnt->flags &= ~NFS_MOUNT_NOCTO;
1230 mnt->flags |= NFS_MOUNT_NOCTO;
1233 mnt->flags &= ~NFS_MOUNT_NOAC;
1236 mnt->flags |= NFS_MOUNT_NOAC;
1239 mnt->flags &= ~NFS_MOUNT_NONLM;
1240 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1241 NFS_MOUNT_LOCAL_FCNTL);
1244 mnt->flags |= NFS_MOUNT_NONLM;
1245 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1246 NFS_MOUNT_LOCAL_FCNTL);
1249 mnt->flags &= ~NFS_MOUNT_TCP;
1250 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1253 mnt->flags |= NFS_MOUNT_TCP;
1254 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1257 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1258 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1259 xprt_load_transport(p);
1262 mnt->flags &= ~NFS_MOUNT_NOACL;
1265 mnt->flags |= NFS_MOUNT_NOACL;
1268 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1270 case Opt_nordirplus:
1271 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1273 case Opt_sharecache:
1274 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1276 case Opt_nosharecache:
1277 mnt->flags |= NFS_MOUNT_UNSHARED;
1280 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1282 case Opt_noresvport:
1283 mnt->flags |= NFS_MOUNT_NORESVPORT;
1286 mnt->options |= NFS_OPTION_FSCACHE;
1287 kfree(mnt->fscache_uniq);
1288 mnt->fscache_uniq = NULL;
1291 mnt->options &= ~NFS_OPTION_FSCACHE;
1292 kfree(mnt->fscache_uniq);
1293 mnt->fscache_uniq = NULL;
1297 * options that take numeric values
1300 if (nfs_get_option_ul(args, &option) ||
1302 goto out_invalid_value;
1303 mnt->nfs_server.port = option;
1306 if (nfs_get_option_ul(args, &option))
1307 goto out_invalid_value;
1308 mnt->rsize = option;
1311 if (nfs_get_option_ul(args, &option))
1312 goto out_invalid_value;
1313 mnt->wsize = option;
1316 if (nfs_get_option_ul(args, &option))
1317 goto out_invalid_value;
1318 mnt->bsize = option;
1321 if (nfs_get_option_ul(args, &option) || option == 0)
1322 goto out_invalid_value;
1323 mnt->timeo = option;
1326 if (nfs_get_option_ul(args, &option) || option == 0)
1327 goto out_invalid_value;
1328 mnt->retrans = option;
1331 if (nfs_get_option_ul(args, &option))
1332 goto out_invalid_value;
1333 mnt->acregmin = option;
1336 if (nfs_get_option_ul(args, &option))
1337 goto out_invalid_value;
1338 mnt->acregmax = option;
1341 if (nfs_get_option_ul(args, &option))
1342 goto out_invalid_value;
1343 mnt->acdirmin = option;
1346 if (nfs_get_option_ul(args, &option))
1347 goto out_invalid_value;
1348 mnt->acdirmax = option;
1351 if (nfs_get_option_ul(args, &option))
1352 goto out_invalid_value;
1353 mnt->acregmin = mnt->acregmax =
1354 mnt->acdirmin = mnt->acdirmax = option;
1357 if (nfs_get_option_ul(args, &option))
1358 goto out_invalid_value;
1359 mnt->namlen = option;
1362 if (nfs_get_option_ul(args, &option) ||
1364 goto out_invalid_value;
1365 mnt->mount_server.port = option;
1368 if (nfs_get_option_ul(args, &option) ||
1369 option < NFS_MNT_VERSION ||
1370 option > NFS_MNT3_VERSION)
1371 goto out_invalid_value;
1372 mnt->mount_server.version = option;
1374 case Opt_minorversion:
1375 if (nfs_get_option_ul(args, &option))
1376 goto out_invalid_value;
1377 if (option > NFS4_MAX_MINOR_VERSION)
1378 goto out_invalid_value;
1379 mnt->minorversion = option;
1383 * options that take text values
1386 string = match_strdup(args);
1389 rc = nfs_parse_version_string(string, mnt, args);
1392 goto out_invalid_value;
1395 string = match_strdup(args);
1398 rc = nfs_parse_security_flavors(string, mnt);
1401 dfprintk(MOUNT, "NFS: unrecognized "
1402 "security flavor\n");
1407 string = match_strdup(args);
1410 token = match_token(string,
1411 nfs_xprt_protocol_tokens, args);
1413 protofamily = AF_INET;
1416 protofamily = AF_INET6;
1418 mnt->flags &= ~NFS_MOUNT_TCP;
1419 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1422 protofamily = AF_INET6;
1424 mnt->flags |= NFS_MOUNT_TCP;
1425 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1428 /* vector side protocols to TCP */
1429 mnt->flags |= NFS_MOUNT_TCP;
1430 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1431 xprt_load_transport(string);
1434 dfprintk(MOUNT, "NFS: unrecognized "
1435 "transport protocol\n");
1441 case Opt_mountproto:
1442 string = match_strdup(args);
1445 token = match_token(string,
1446 nfs_xprt_protocol_tokens, args);
1449 mountfamily = AF_INET;
1452 mountfamily = AF_INET6;
1454 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
1457 mountfamily = AF_INET6;
1459 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
1461 case Opt_xprt_rdma: /* not used for side protocols */
1463 dfprintk(MOUNT, "NFS: unrecognized "
1464 "transport protocol\n");
1469 string = match_strdup(args);
1472 mnt->nfs_server.addrlen =
1473 rpc_pton(mnt->net, string, strlen(string),
1475 &mnt->nfs_server.address,
1476 sizeof(mnt->nfs_server.address));
1478 if (mnt->nfs_server.addrlen == 0)
1479 goto out_invalid_address;
1481 case Opt_clientaddr:
1482 if (nfs_get_option_str(args, &mnt->client_address))
1486 if (nfs_get_option_str(args,
1487 &mnt->mount_server.hostname))
1491 string = match_strdup(args);
1494 mnt->mount_server.addrlen =
1495 rpc_pton(mnt->net, string, strlen(string),
1497 &mnt->mount_server.address,
1498 sizeof(mnt->mount_server.address));
1500 if (mnt->mount_server.addrlen == 0)
1501 goto out_invalid_address;
1503 case Opt_lookupcache:
1504 string = match_strdup(args);
1507 token = match_token(string,
1508 nfs_lookupcache_tokens, args);
1511 case Opt_lookupcache_all:
1512 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1514 case Opt_lookupcache_positive:
1515 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1516 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1518 case Opt_lookupcache_none:
1519 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1522 dfprintk(MOUNT, "NFS: invalid "
1523 "lookupcache argument\n");
1527 case Opt_fscache_uniq:
1528 if (nfs_get_option_str(args, &mnt->fscache_uniq))
1530 mnt->options |= NFS_OPTION_FSCACHE;
1532 case Opt_local_lock:
1533 string = match_strdup(args);
1536 token = match_token(string, nfs_local_lock_tokens,
1540 case Opt_local_lock_all:
1541 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1542 NFS_MOUNT_LOCAL_FCNTL);
1544 case Opt_local_lock_flock:
1545 mnt->flags |= NFS_MOUNT_LOCAL_FLOCK;
1547 case Opt_local_lock_posix:
1548 mnt->flags |= NFS_MOUNT_LOCAL_FCNTL;
1550 case Opt_local_lock_none:
1551 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1552 NFS_MOUNT_LOCAL_FCNTL);
1555 dfprintk(MOUNT, "NFS: invalid "
1556 "local_lock argument\n");
1566 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1569 case Opt_deprecated:
1570 dfprintk(MOUNT, "NFS: ignoring mount option "
1576 dfprintk(MOUNT, "NFS: unrecognized mount option "
1581 if (!sloppy && invalid_option)
1584 if (mnt->minorversion && mnt->version != 4)
1585 goto out_minorversion_mismatch;
1588 * verify that any proto=/mountproto= options match the address
1589 * familiies in the addr=/mountaddr= options.
1591 if (protofamily != AF_UNSPEC &&
1592 protofamily != mnt->nfs_server.address.ss_family)
1593 goto out_proto_mismatch;
1595 if (mountfamily != AF_UNSPEC) {
1596 if (mnt->mount_server.addrlen) {
1597 if (mountfamily != mnt->mount_server.address.ss_family)
1598 goto out_mountproto_mismatch;
1600 if (mountfamily != mnt->nfs_server.address.ss_family)
1601 goto out_mountproto_mismatch;
1607 out_mountproto_mismatch:
1608 printk(KERN_INFO "NFS: mount server address does not match mountproto= "
1612 printk(KERN_INFO "NFS: server address does not match proto= option\n");
1614 out_invalid_address:
1615 printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
1618 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
1620 out_minorversion_mismatch:
1621 printk(KERN_INFO "NFS: mount option vers=%u does not support "
1622 "minorversion=%u\n", mnt->version, mnt->minorversion);
1625 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1627 out_security_failure:
1628 free_secdata(secdata);
1629 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1634 * Match the requested auth flavors with the list returned by
1635 * the server. Returns zero and sets the mount's authentication
1636 * flavor on success; returns -EACCES if server does not support
1637 * the requested flavor.
1639 static int nfs_walk_authlist(struct nfs_parsed_mount_data *args,
1640 struct nfs_mount_request *request)
1642 unsigned int i, j, server_authlist_len = *(request->auth_flav_len);
1645 * Certain releases of Linux's mountd return an empty
1646 * flavor list. To prevent behavioral regression with
1647 * these servers (ie. rejecting mounts that used to
1648 * succeed), revert to pre-2.6.32 behavior (no checking)
1649 * if the returned flavor list is empty.
1651 if (server_authlist_len == 0)
1655 * We avoid sophisticated negotiating here, as there are
1656 * plenty of cases where we can get it wrong, providing
1657 * either too little or too much security.
1659 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1660 * flavor listed first. However, some servers list
1661 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1662 * preferred default, in args->auth_flavors[0] if user
1663 * didn't specify sec= mount option.
1665 for (i = 0; i < args->auth_flavor_len; i++)
1666 for (j = 0; j < server_authlist_len; j++)
1667 if (args->auth_flavors[i] == request->auth_flavs[j]) {
1668 dfprintk(MOUNT, "NFS: using auth flavor %d\n",
1669 request->auth_flavs[j]);
1670 args->auth_flavors[0] = request->auth_flavs[j];
1674 dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n");
1675 nfs_umount(request);
1680 * Use the remote server's MOUNT service to request the NFS file handle
1681 * corresponding to the provided path.
1683 static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1684 struct nfs_fh *root_fh)
1686 rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS];
1687 unsigned int server_authlist_len = ARRAY_SIZE(server_authlist);
1688 struct nfs_mount_request request = {
1689 .sap = (struct sockaddr *)
1690 &args->mount_server.address,
1691 .dirpath = args->nfs_server.export_path,
1692 .protocol = args->mount_server.protocol,
1694 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
1695 .auth_flav_len = &server_authlist_len,
1696 .auth_flavs = server_authlist,
1701 if (args->mount_server.version == 0) {
1702 switch (args->version) {
1704 args->mount_server.version = NFS_MNT3_VERSION;
1707 args->mount_server.version = NFS_MNT_VERSION;
1710 request.version = args->mount_server.version;
1712 if (args->mount_server.hostname)
1713 request.hostname = args->mount_server.hostname;
1715 request.hostname = args->nfs_server.hostname;
1718 * Construct the mount server's address.
1720 if (args->mount_server.address.ss_family == AF_UNSPEC) {
1721 memcpy(request.sap, &args->nfs_server.address,
1722 args->nfs_server.addrlen);
1723 args->mount_server.addrlen = args->nfs_server.addrlen;
1725 request.salen = args->mount_server.addrlen;
1726 nfs_set_port(request.sap, &args->mount_server.port, 0);
1729 * Now ask the mount server to map our export path
1732 status = nfs_mount(&request);
1734 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1735 request.hostname, status);
1740 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1742 if (args->mount_server.version != NFS_MNT3_VERSION)
1744 return nfs_walk_authlist(args, &request);
1748 * Split "dev_name" into "hostname:export_path".
1750 * The leftmost colon demarks the split between the server's hostname
1751 * and the export path. If the hostname starts with a left square
1752 * bracket, then it may contain colons.
1754 * Note: caller frees hostname and export path, even on error.
1756 static int nfs_parse_devname(const char *dev_name,
1757 char **hostname, size_t maxnamlen,
1758 char **export_path, size_t maxpathlen)
1763 /* Is the host name protected with square brakcets? */
1764 if (*dev_name == '[') {
1765 end = strchr(++dev_name, ']');
1766 if (end == NULL || end[1] != ':')
1767 goto out_bad_devname;
1769 len = end - dev_name;
1774 end = strchr(dev_name, ':');
1776 goto out_bad_devname;
1777 len = end - dev_name;
1779 /* kill possible hostname list: not supported */
1780 comma = strchr(dev_name, ',');
1781 if (comma != NULL && comma < end)
1785 if (len > maxnamlen)
1788 /* N.B. caller will free nfs_server.hostname in all cases */
1789 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
1790 if (*hostname == NULL)
1792 len = strlen(++end);
1793 if (len > maxpathlen)
1795 *export_path = kstrndup(end, len, GFP_KERNEL);
1799 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1803 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1807 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1811 dfprintk(MOUNT, "NFS: server hostname too long\n");
1812 return -ENAMETOOLONG;
1815 dfprintk(MOUNT, "NFS: export pathname too long\n");
1816 return -ENAMETOOLONG;
1820 * Validate the NFS2/NFS3 mount data
1821 * - fills in the mount root filehandle
1823 * For option strings, user space handles the following behaviors:
1825 * + DNS: mapping server host name to IP address ("addr=" option)
1827 * + failure mode: how to behave if a mount request can't be handled
1828 * immediately ("fg/bg" option)
1830 * + retry: how often to retry a mount request ("retry=" option)
1832 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1833 * mountproto=tcp after mountproto=udp, and so on
1835 static int nfs_validate_mount_data(void *options,
1836 struct nfs_parsed_mount_data *args,
1837 struct nfs_fh *mntfh,
1838 const char *dev_name)
1840 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
1841 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
1846 switch (data->version) {
1852 if (data->flags & NFS_MOUNT_VER3)
1854 data->root.size = NFS2_FHSIZE;
1855 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1857 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1860 memset(data->context, 0, sizeof(data->context));
1862 if (data->flags & NFS_MOUNT_VER3) {
1863 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1864 goto out_invalid_fh;
1865 mntfh->size = data->root.size;
1868 mntfh->size = NFS2_FHSIZE;
1873 memcpy(mntfh->data, data->root.data, mntfh->size);
1874 if (mntfh->size < sizeof(mntfh->data))
1875 memset(mntfh->data + mntfh->size, 0,
1876 sizeof(mntfh->data) - mntfh->size);
1879 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1882 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
1883 args->flags |= NFS_MOUNT_LEGACY_INTERFACE;
1884 args->rsize = data->rsize;
1885 args->wsize = data->wsize;
1886 args->timeo = data->timeo;
1887 args->retrans = data->retrans;
1888 args->acregmin = data->acregmin;
1889 args->acregmax = data->acregmax;
1890 args->acdirmin = data->acdirmin;
1891 args->acdirmax = data->acdirmax;
1893 memcpy(sap, &data->addr, sizeof(data->addr));
1894 args->nfs_server.addrlen = sizeof(data->addr);
1895 if (!nfs_verify_server_address(sap))
1896 goto out_no_address;
1898 if (!(data->flags & NFS_MOUNT_TCP))
1899 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1900 /* N.B. caller will free nfs_server.hostname in all cases */
1901 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1902 args->namlen = data->namlen;
1903 args->bsize = data->bsize;
1905 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1906 args->auth_flavors[0] = data->pseudoflavor;
1907 if (!args->nfs_server.hostname)
1910 if (!(data->flags & NFS_MOUNT_NONLM))
1911 args->flags &= ~(NFS_MOUNT_LOCAL_FLOCK|
1912 NFS_MOUNT_LOCAL_FCNTL);
1914 args->flags |= (NFS_MOUNT_LOCAL_FLOCK|
1915 NFS_MOUNT_LOCAL_FCNTL);
1917 * The legacy version 6 binary mount data from userspace has a
1918 * field used only to transport selinux information into the
1919 * the kernel. To continue to support that functionality we
1920 * have a touch of selinux knowledge here in the NFS code. The
1921 * userspace code converted context=blah to just blah so we are
1922 * converting back to the full string selinux understands.
1924 if (data->context[0]){
1925 #ifdef CONFIG_SECURITY_SELINUX
1927 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1930 strcpy(opts_str, "context=");
1931 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1932 strcat(opts_str, &data->context[0]);
1933 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1946 if (nfs_parse_mount_options((char *)options, args) == 0)
1949 if (!nfs_verify_server_address(sap))
1950 goto out_no_address;
1952 if (args->version == 4)
1953 #ifdef CONFIG_NFS_V4
1954 return nfs4_validate_text_mount_data(options,
1957 goto out_v4_not_compiled;
1960 nfs_set_port(sap, &args->nfs_server.port, 0);
1962 nfs_set_mount_transport_protocol(args);
1964 status = nfs_parse_devname(dev_name,
1965 &args->nfs_server.hostname,
1967 &args->nfs_server.export_path,
1970 status = nfs_try_mount(args, mntfh);
1972 kfree(args->nfs_server.export_path);
1973 args->nfs_server.export_path = NULL;
1982 #ifndef CONFIG_NFS_V3
1983 if (args->version == 3)
1984 goto out_v3_not_compiled;
1985 #endif /* !CONFIG_NFS_V3 */
1990 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1994 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1999 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
2002 #ifndef CONFIG_NFS_V3
2003 out_v3_not_compiled:
2004 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
2005 return -EPROTONOSUPPORT;
2006 #endif /* !CONFIG_NFS_V3 */
2008 #ifndef CONFIG_NFS_V4
2009 out_v4_not_compiled:
2010 dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n");
2011 return -EPROTONOSUPPORT;
2012 #endif /* !CONFIG_NFS_V4 */
2015 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
2019 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
2023 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
2028 nfs_compare_remount_data(struct nfs_server *nfss,
2029 struct nfs_parsed_mount_data *data)
2031 if (data->flags != nfss->flags ||
2032 data->rsize != nfss->rsize ||
2033 data->wsize != nfss->wsize ||
2034 data->retrans != nfss->client->cl_timeout->to_retries ||
2035 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
2036 data->acregmin != nfss->acregmin / HZ ||
2037 data->acregmax != nfss->acregmax / HZ ||
2038 data->acdirmin != nfss->acdirmin / HZ ||
2039 data->acdirmax != nfss->acdirmax / HZ ||
2040 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
2041 data->nfs_server.port != nfss->port ||
2042 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
2043 !rpc_cmp_addr((struct sockaddr *)&data->nfs_server.address,
2044 (struct sockaddr *)&nfss->nfs_client->cl_addr))
2051 nfs_remount(struct super_block *sb, int *flags, char *raw_data)
2054 struct nfs_server *nfss = sb->s_fs_info;
2055 struct nfs_parsed_mount_data *data;
2056 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
2057 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
2058 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
2061 * Userspace mount programs that send binary options generally send
2062 * them populated with default values. We have no way to know which
2063 * ones were explicitly specified. Fall back to legacy behavior and
2064 * just return success.
2066 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
2067 (nfsvers <= 3 && (!options || (options->version >= 1 &&
2068 options->version <= 6))))
2071 data = kzalloc(sizeof(*data), GFP_KERNEL);
2075 /* fill out struct with values from existing mount */
2076 data->flags = nfss->flags;
2077 data->rsize = nfss->rsize;
2078 data->wsize = nfss->wsize;
2079 data->retrans = nfss->client->cl_timeout->to_retries;
2080 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
2081 data->acregmin = nfss->acregmin / HZ;
2082 data->acregmax = nfss->acregmax / HZ;
2083 data->acdirmin = nfss->acdirmin / HZ;
2084 data->acdirmax = nfss->acdirmax / HZ;
2085 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
2086 data->nfs_server.port = nfss->port;
2087 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
2088 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
2089 data->nfs_server.addrlen);
2091 /* overwrite those values with any that were specified */
2092 error = nfs_parse_mount_options((char *)options, data);
2097 * noac is a special case. It implies -o sync, but that's not
2098 * necessarily reflected in the mtab options. do_remount_sb
2099 * will clear MS_SYNCHRONOUS if -o sync wasn't specified in the
2100 * remount options, so we have to explicitly reset it.
2102 if (data->flags & NFS_MOUNT_NOAC)
2103 *flags |= MS_SYNCHRONOUS;
2105 /* compare new mount options with old ones */
2106 error = nfs_compare_remount_data(nfss, data);
2113 * Initialise the common bits of the superblock
2115 static inline void nfs_initialise_sb(struct super_block *sb)
2117 struct nfs_server *server = NFS_SB(sb);
2119 sb->s_magic = NFS_SUPER_MAGIC;
2121 /* We probably want something more informative here */
2122 snprintf(sb->s_id, sizeof(sb->s_id),
2123 "%u:%u", MAJOR(sb->s_dev), MINOR(sb->s_dev));
2125 if (sb->s_blocksize == 0)
2126 sb->s_blocksize = nfs_block_bits(server->wsize,
2127 &sb->s_blocksize_bits);
2129 sb->s_bdi = &server->backing_dev_info;
2131 nfs_super_set_maxbytes(sb, server->maxfilesize);
2135 * Finish setting up an NFS2/3 superblock
2137 static void nfs_fill_super(struct super_block *sb,
2138 struct nfs_mount_info *mount_info)
2140 struct nfs_parsed_mount_data *data = mount_info->parsed;
2141 struct nfs_server *server = NFS_SB(sb);
2143 sb->s_blocksize_bits = 0;
2144 sb->s_blocksize = 0;
2146 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
2148 if (server->nfs_client->rpc_ops->version == 3) {
2149 /* The VFS shouldn't apply the umask to mode bits. We will do
2150 * so ourselves when necessary.
2152 sb->s_flags |= MS_POSIXACL;
2153 sb->s_time_gran = 1;
2156 sb->s_op = &nfs_sops;
2157 nfs_initialise_sb(sb);
2161 * Finish setting up a cloned NFS2/3 superblock
2163 static void nfs_clone_super(struct super_block *sb,
2164 struct nfs_mount_info *mount_info)
2166 const struct super_block *old_sb = mount_info->cloned->sb;
2167 struct nfs_server *server = NFS_SB(sb);
2169 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2170 sb->s_blocksize = old_sb->s_blocksize;
2171 sb->s_maxbytes = old_sb->s_maxbytes;
2173 if (server->nfs_client->rpc_ops->version == 3) {
2174 /* The VFS shouldn't apply the umask to mode bits. We will do
2175 * so ourselves when necessary.
2177 sb->s_flags |= MS_POSIXACL;
2178 sb->s_time_gran = 1;
2181 sb->s_op = old_sb->s_op;
2182 nfs_initialise_sb(sb);
2185 static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
2187 const struct nfs_server *a = s->s_fs_info;
2188 const struct rpc_clnt *clnt_a = a->client;
2189 const struct rpc_clnt *clnt_b = b->client;
2191 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
2193 if (a->nfs_client != b->nfs_client)
2195 if (a->flags != b->flags)
2197 if (a->wsize != b->wsize)
2199 if (a->rsize != b->rsize)
2201 if (a->acregmin != b->acregmin)
2203 if (a->acregmax != b->acregmax)
2205 if (a->acdirmin != b->acdirmin)
2207 if (a->acdirmax != b->acdirmax)
2209 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
2216 struct nfs_sb_mountdata {
2217 struct nfs_server *server;
2221 static int nfs_set_super(struct super_block *s, void *data)
2223 struct nfs_sb_mountdata *sb_mntdata = data;
2224 struct nfs_server *server = sb_mntdata->server;
2227 s->s_flags = sb_mntdata->mntflags;
2228 s->s_fs_info = server;
2229 s->s_d_op = server->nfs_client->rpc_ops->dentry_ops;
2230 ret = set_anon_super(s, server);
2232 server->s_dev = s->s_dev;
2236 static int nfs_compare_super_address(struct nfs_server *server1,
2237 struct nfs_server *server2)
2239 struct sockaddr *sap1, *sap2;
2241 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
2242 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
2244 if (sap1->sa_family != sap2->sa_family)
2247 switch (sap1->sa_family) {
2249 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
2250 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
2251 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
2253 if (sin1->sin_port != sin2->sin_port)
2258 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
2259 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
2260 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
2262 if (sin1->sin6_port != sin2->sin6_port)
2273 static int nfs_compare_super(struct super_block *sb, void *data)
2275 struct nfs_sb_mountdata *sb_mntdata = data;
2276 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2277 int mntflags = sb_mntdata->mntflags;
2279 if (!nfs_compare_super_address(old, server))
2281 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2282 if (old->flags & NFS_MOUNT_UNSHARED)
2284 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2286 return nfs_compare_mount_options(sb, server, mntflags);
2289 static void nfs_get_cache_cookie(struct super_block *sb,
2290 struct nfs_parsed_mount_data *parsed,
2291 struct nfs_clone_mount *cloned)
2296 if (parsed && parsed->fscache_uniq) {
2297 uniq = parsed->fscache_uniq;
2298 ulen = strlen(parsed->fscache_uniq);
2299 } else if (cloned) {
2300 struct nfs_server *mnt_s = NFS_SB(cloned->sb);
2301 if (mnt_s->fscache_key) {
2302 uniq = mnt_s->fscache_key->key.uniquifier;
2303 ulen = mnt_s->fscache_key->key.uniq_len;
2307 nfs_fscache_get_super_cookie(sb, uniq, ulen);
2310 static int nfs_bdi_register(struct nfs_server *server)
2312 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
2315 static struct dentry *nfs_fs_mount_common(struct file_system_type *fs_type,
2316 struct nfs_server *server,
2317 int flags, const char *dev_name,
2318 struct nfs_fh *mntfh,
2319 struct nfs_mount_info *mount_info)
2321 struct super_block *s;
2322 struct dentry *mntroot = ERR_PTR(-ENOMEM);
2323 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2324 struct nfs_sb_mountdata sb_mntdata = {
2330 if (server->flags & NFS_MOUNT_UNSHARED)
2331 compare_super = NULL;
2333 /* -o noac implies -o sync */
2334 if (server->flags & NFS_MOUNT_NOAC)
2335 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2337 /* Get a superblock - note that we may end up sharing one that already exists */
2338 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
2340 mntroot = ERR_CAST(s);
2344 if (s->s_fs_info != server) {
2345 nfs_free_server(server);
2348 error = nfs_bdi_register(server);
2350 mntroot = ERR_PTR(error);
2351 goto error_splat_bdi;
2356 /* initial superblock/root creation */
2357 mount_info->fill_super(s, mount_info);
2358 nfs_get_cache_cookie(s, mount_info->parsed, NULL);
2361 mntroot = nfs_get_root(s, mntfh, dev_name);
2362 if (IS_ERR(mntroot))
2363 goto error_splat_super;
2365 error = security_sb_set_mnt_opts(s, &mount_info->parsed->lsm_opts);
2367 goto error_splat_root;
2369 s->s_flags |= MS_ACTIVE;
2375 nfs_free_server(server);
2380 mntroot = ERR_PTR(error);
2382 if (server && !s->s_root)
2383 bdi_unregister(&server->backing_dev_info);
2385 deactivate_locked_super(s);
2389 static struct dentry *nfs_fs_mount(struct file_system_type *fs_type,
2390 int flags, const char *dev_name, void *raw_data)
2392 struct nfs_server *server;
2393 struct nfs_parsed_mount_data *data = NULL;
2394 struct nfs_mount_info mount_info = {
2395 .fill_super = nfs_fill_super,
2397 struct nfs_fh *mntfh;
2398 struct dentry *mntroot = ERR_PTR(-ENOMEM);
2401 data = nfs_alloc_parsed_mount_data(NFS_DEFAULT_VERSION);
2402 mntfh = nfs_alloc_fhandle();
2403 if (data == NULL || mntfh == NULL)
2406 /* Validate the mount data */
2407 error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
2409 mntroot = ERR_PTR(error);
2412 mount_info.parsed = data;
2414 #ifdef CONFIG_NFS_V4
2415 if (data->version == 4) {
2416 mntroot = nfs4_try_mount(flags, dev_name, data);
2419 #endif /* CONFIG_NFS_V4 */
2421 /* Get a volume representation */
2422 server = nfs_create_server(data, mntfh);
2423 if (IS_ERR(server)) {
2424 mntroot = ERR_CAST(server);
2428 mntroot = nfs_fs_mount_common(fs_type, server, flags, dev_name, mntfh, &mount_info);
2430 nfs_free_parsed_mount_data(data);
2431 nfs_free_fhandle(mntfh);
2436 * Ensure that we unregister the bdi before kill_anon_super
2437 * releases the device name
2439 static void nfs_put_super(struct super_block *s)
2441 struct nfs_server *server = NFS_SB(s);
2443 bdi_unregister(&server->backing_dev_info);
2447 * Destroy an NFS2/3 superblock
2449 static void nfs_kill_super(struct super_block *s)
2451 struct nfs_server *server = NFS_SB(s);
2454 nfs_fscache_release_super_cookie(s);
2455 nfs_free_server(server);
2459 * Clone an NFS2/3/4 server record on xdev traversal (FSID-change)
2461 static struct dentry *
2462 nfs_xdev_mount_common(struct file_system_type *fs_type, int flags,
2463 const char *dev_name, struct nfs_mount_info *mount_info)
2465 struct nfs_clone_mount *data = mount_info->cloned;
2466 struct super_block *s;
2467 struct nfs_server *server;
2468 struct dentry *mntroot;
2469 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2470 struct nfs_sb_mountdata sb_mntdata = {
2475 dprintk("--> nfs_xdev_mount_common()\n");
2477 /* create a new volume representation */
2478 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr, data->authflavor);
2479 if (IS_ERR(server)) {
2480 error = PTR_ERR(server);
2481 goto out_err_noserver;
2483 sb_mntdata.server = server;
2485 if (server->flags & NFS_MOUNT_UNSHARED)
2486 compare_super = NULL;
2488 /* -o noac implies -o sync */
2489 if (server->flags & NFS_MOUNT_NOAC)
2490 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2492 /* Get a superblock - note that we may end up sharing one that already exists */
2493 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2499 if (s->s_fs_info != server) {
2500 nfs_free_server(server);
2503 error = nfs_bdi_register(server);
2505 goto error_splat_bdi;
2509 /* initial superblock/root creation */
2510 mount_info->fill_super(s, mount_info);
2511 nfs_get_cache_cookie(s, NULL, data);
2514 mntroot = nfs_get_root(s, data->fh, dev_name);
2515 if (IS_ERR(mntroot)) {
2516 error = PTR_ERR(mntroot);
2517 goto error_splat_super;
2519 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2522 goto error_splat_super;
2525 s->s_flags |= MS_ACTIVE;
2527 /* clone any lsm security options from the parent to the new sb */
2528 security_sb_clone_mnt_opts(data->sb, s);
2530 dprintk("<-- nfs_xdev_mount_common() = 0\n");
2534 nfs_free_server(server);
2536 dprintk("<-- nfs_xdev_mount_common() = %d [error]\n", error);
2537 return ERR_PTR(error);
2540 if (server && !s->s_root)
2541 bdi_unregister(&server->backing_dev_info);
2543 deactivate_locked_super(s);
2544 dprintk("<-- nfs_xdev_mount_common() = %d [splat]\n", error);
2545 return ERR_PTR(error);
2549 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2551 static struct dentry *
2552 nfs_xdev_mount(struct file_system_type *fs_type, int flags,
2553 const char *dev_name, void *raw_data)
2555 struct nfs_mount_info mount_info = {
2556 .fill_super = nfs_clone_super,
2559 return nfs_xdev_mount_common(&nfs_fs_type, flags, dev_name, &mount_info);
2562 #ifdef CONFIG_NFS_V4
2565 * Finish setting up a cloned NFS4 superblock
2567 static void nfs4_clone_super(struct super_block *sb,
2568 struct nfs_mount_info *mount_info)
2570 const struct super_block *old_sb = mount_info->cloned->sb;
2571 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2572 sb->s_blocksize = old_sb->s_blocksize;
2573 sb->s_maxbytes = old_sb->s_maxbytes;
2574 sb->s_time_gran = 1;
2575 sb->s_op = old_sb->s_op;
2577 * The VFS shouldn't apply the umask to mode bits. We will do
2578 * so ourselves when necessary.
2580 sb->s_flags |= MS_POSIXACL;
2581 sb->s_xattr = old_sb->s_xattr;
2582 nfs_initialise_sb(sb);
2586 * Set up an NFS4 superblock
2588 static void nfs4_fill_super(struct super_block *sb,
2589 struct nfs_mount_info *mount_info)
2591 sb->s_time_gran = 1;
2592 sb->s_op = &nfs4_sops;
2594 * The VFS shouldn't apply the umask to mode bits. We will do
2595 * so ourselves when necessary.
2597 sb->s_flags |= MS_POSIXACL;
2598 sb->s_xattr = nfs4_xattr_handlers;
2599 nfs_initialise_sb(sb);
2602 static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2604 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3|
2605 NFS_MOUNT_LOCAL_FLOCK|NFS_MOUNT_LOCAL_FCNTL);
2608 static int nfs4_validate_text_mount_data(void *options,
2609 struct nfs_parsed_mount_data *args,
2610 const char *dev_name)
2612 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2614 nfs_set_port(sap, &args->nfs_server.port, NFS_PORT);
2616 nfs_validate_transport_protocol(args);
2618 nfs4_validate_mount_flags(args);
2620 if (args->version != 4) {
2622 "NFS4: Illegal mount version\n");
2626 if (args->auth_flavor_len > 1) {
2628 "NFS4: Too many RPC auth flavours specified\n");
2632 return nfs_parse_devname(dev_name,
2633 &args->nfs_server.hostname,
2635 &args->nfs_server.export_path,
2640 * Validate NFSv4 mount options
2642 static int nfs4_validate_mount_data(void *options,
2643 struct nfs_parsed_mount_data *args,
2644 const char *dev_name)
2646 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2647 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
2653 switch (data->version) {
2655 if (data->host_addrlen > sizeof(args->nfs_server.address))
2656 goto out_no_address;
2657 if (data->host_addrlen == 0)
2658 goto out_no_address;
2659 args->nfs_server.addrlen = data->host_addrlen;
2660 if (copy_from_user(sap, data->host_addr, data->host_addrlen))
2662 if (!nfs_verify_server_address(sap))
2663 goto out_no_address;
2665 if (data->auth_flavourlen) {
2666 if (data->auth_flavourlen > 1)
2667 goto out_inval_auth;
2668 if (copy_from_user(&args->auth_flavors[0],
2669 data->auth_flavours,
2670 sizeof(args->auth_flavors[0])))
2674 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2677 args->nfs_server.hostname = c;
2679 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2682 args->nfs_server.export_path = c;
2683 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
2685 c = strndup_user(data->client_addr.data, 16);
2688 args->client_address = c;
2691 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2695 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2696 args->rsize = data->rsize;
2697 args->wsize = data->wsize;
2698 args->timeo = data->timeo;
2699 args->retrans = data->retrans;
2700 args->acregmin = data->acregmin;
2701 args->acregmax = data->acregmax;
2702 args->acdirmin = data->acdirmin;
2703 args->acdirmax = data->acdirmax;
2704 args->nfs_server.protocol = data->proto;
2705 nfs_validate_transport_protocol(args);
2709 if (nfs_parse_mount_options((char *)options, args) == 0)
2712 if (!nfs_verify_server_address(sap))
2715 return nfs4_validate_text_mount_data(options, args, dev_name);
2721 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2725 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2726 data->auth_flavourlen);
2730 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2735 * Get the superblock for the NFS4 root partition
2737 static struct dentry *
2738 nfs4_remote_mount(struct file_system_type *fs_type, int flags,
2739 const char *dev_name, void *raw_data)
2741 struct nfs_mount_info mount_info = {
2742 .fill_super = nfs4_fill_super,
2745 struct nfs_server *server;
2746 struct nfs_fh *mntfh;
2747 struct dentry *mntroot = ERR_PTR(-ENOMEM);
2749 mntfh = nfs_alloc_fhandle();
2750 if (mount_info.parsed == NULL || mntfh == NULL)
2753 /* Get a volume representation */
2754 server = nfs4_create_server(mount_info.parsed, mntfh);
2755 if (IS_ERR(server)) {
2756 mntroot = ERR_CAST(server);
2760 mntroot = nfs_fs_mount_common(fs_type, server, flags,
2761 dev_name, mntfh, &mount_info);
2764 nfs_free_fhandle(mntfh);
2768 static struct vfsmount *nfs_do_root_mount(struct file_system_type *fs_type,
2769 int flags, void *data, const char *hostname)
2771 struct vfsmount *root_mnt;
2775 len = strlen(hostname) + 5;
2776 root_devname = kmalloc(len, GFP_KERNEL);
2777 if (root_devname == NULL)
2778 return ERR_PTR(-ENOMEM);
2779 /* Does hostname needs to be enclosed in brackets? */
2780 if (strchr(hostname, ':'))
2781 snprintf(root_devname, len, "[%s]:/", hostname);
2783 snprintf(root_devname, len, "%s:/", hostname);
2784 root_mnt = vfs_kern_mount(fs_type, flags, root_devname, data);
2785 kfree(root_devname);
2789 struct nfs_referral_count {
2790 struct list_head list;
2791 const struct task_struct *task;
2792 unsigned int referral_count;
2795 static LIST_HEAD(nfs_referral_count_list);
2796 static DEFINE_SPINLOCK(nfs_referral_count_list_lock);
2798 static struct nfs_referral_count *nfs_find_referral_count(void)
2800 struct nfs_referral_count *p;
2802 list_for_each_entry(p, &nfs_referral_count_list, list) {
2803 if (p->task == current)
2809 #define NFS_MAX_NESTED_REFERRALS 2
2811 static int nfs_referral_loop_protect(void)
2813 struct nfs_referral_count *p, *new;
2816 new = kmalloc(sizeof(*new), GFP_KERNEL);
2819 new->task = current;
2820 new->referral_count = 1;
2823 spin_lock(&nfs_referral_count_list_lock);
2824 p = nfs_find_referral_count();
2826 if (p->referral_count >= NFS_MAX_NESTED_REFERRALS)
2829 p->referral_count++;
2831 list_add(&new->list, &nfs_referral_count_list);
2834 spin_unlock(&nfs_referral_count_list_lock);
2840 static void nfs_referral_loop_unprotect(void)
2842 struct nfs_referral_count *p;
2844 spin_lock(&nfs_referral_count_list_lock);
2845 p = nfs_find_referral_count();
2846 p->referral_count--;
2847 if (p->referral_count == 0)
2851 spin_unlock(&nfs_referral_count_list_lock);
2855 static struct dentry *nfs_follow_remote_path(struct vfsmount *root_mnt,
2856 const char *export_path)
2858 struct dentry *dentry;
2861 if (IS_ERR(root_mnt))
2862 return ERR_CAST(root_mnt);
2864 err = nfs_referral_loop_protect();
2867 return ERR_PTR(err);
2870 dentry = mount_subtree(root_mnt, export_path);
2871 nfs_referral_loop_unprotect();
2876 static struct dentry *nfs4_try_mount(int flags, const char *dev_name,
2877 struct nfs_parsed_mount_data *data)
2880 struct vfsmount *root_mnt;
2883 dfprintk(MOUNT, "--> nfs4_try_mount()\n");
2885 export_path = data->nfs_server.export_path;
2886 data->nfs_server.export_path = "/";
2887 root_mnt = nfs_do_root_mount(&nfs4_remote_fs_type, flags, data,
2888 data->nfs_server.hostname);
2889 data->nfs_server.export_path = export_path;
2891 res = nfs_follow_remote_path(root_mnt, export_path);
2893 dfprintk(MOUNT, "<-- nfs4_try_mount() = %ld%s\n",
2894 IS_ERR(res) ? PTR_ERR(res) : 0,
2895 IS_ERR(res) ? " [error]" : "");
2900 * Get the superblock for an NFS4 mountpoint
2902 static struct dentry *nfs4_mount(struct file_system_type *fs_type,
2903 int flags, const char *dev_name, void *raw_data)
2905 struct nfs_parsed_mount_data *data;
2906 int error = -ENOMEM;
2907 struct dentry *res = ERR_PTR(-ENOMEM);
2909 data = nfs_alloc_parsed_mount_data(4);
2913 /* Validate the mount data */
2914 error = nfs4_validate_mount_data(raw_data, data, dev_name);
2916 res = ERR_PTR(error);
2920 res = nfs4_try_mount(flags, dev_name, data);
2922 error = PTR_ERR(res);
2925 nfs_free_parsed_mount_data(data);
2926 dprintk("<-- nfs4_mount() = %d%s\n", error,
2927 error != 0 ? " [error]" : "");
2931 static void nfs4_kill_super(struct super_block *sb)
2933 struct nfs_server *server = NFS_SB(sb);
2935 dprintk("--> %s\n", __func__);
2936 nfs_super_return_all_delegations(sb);
2937 kill_anon_super(sb);
2938 nfs_fscache_release_super_cookie(sb);
2939 nfs_free_server(server);
2940 dprintk("<-- %s\n", __func__);
2944 * Clone an NFS4 server record on xdev traversal (FSID-change)
2946 static struct dentry *
2947 nfs4_xdev_mount(struct file_system_type *fs_type, int flags,
2948 const char *dev_name, void *raw_data)
2950 struct nfs_mount_info mount_info = {
2951 .fill_super = nfs4_clone_super,
2954 return nfs_xdev_mount_common(&nfs4_fs_type, flags, dev_name, &mount_info);
2957 static struct dentry *
2958 nfs4_remote_referral_mount(struct file_system_type *fs_type, int flags,
2959 const char *dev_name, void *raw_data)
2961 struct nfs_clone_mount *data = raw_data;
2962 struct super_block *s;
2963 struct nfs_server *server;
2964 struct dentry *mntroot;
2965 struct nfs_fh *mntfh;
2966 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2967 struct nfs_sb_mountdata sb_mntdata = {
2970 int error = -ENOMEM;
2972 dprintk("--> nfs4_referral_get_sb()\n");
2974 mntfh = nfs_alloc_fhandle();
2978 /* create a new volume representation */
2979 server = nfs4_create_referral_server(data, mntfh);
2980 if (IS_ERR(server)) {
2981 error = PTR_ERR(server);
2982 goto out_err_noserver;
2984 sb_mntdata.server = server;
2986 if (server->flags & NFS_MOUNT_UNSHARED)
2987 compare_super = NULL;
2989 /* -o noac implies -o sync */
2990 if (server->flags & NFS_MOUNT_NOAC)
2991 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2993 /* Get a superblock - note that we may end up sharing one that already exists */
2994 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
3000 if (s->s_fs_info != server) {
3001 nfs_free_server(server);
3004 error = nfs_bdi_register(server);
3006 goto error_splat_bdi;
3010 /* initial superblock/root creation */
3011 nfs4_fill_super(s, NULL);
3012 nfs_get_cache_cookie(s, NULL, data);
3015 mntroot = nfs_get_root(s, mntfh, dev_name);
3016 if (IS_ERR(mntroot)) {
3017 error = PTR_ERR(mntroot);
3018 goto error_splat_super;
3020 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
3023 goto error_splat_super;
3026 s->s_flags |= MS_ACTIVE;
3028 security_sb_clone_mnt_opts(data->sb, s);
3030 nfs_free_fhandle(mntfh);
3031 dprintk("<-- nfs4_referral_get_sb() = 0\n");
3035 nfs_free_server(server);
3037 nfs_free_fhandle(mntfh);
3039 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
3040 return ERR_PTR(error);
3043 if (server && !s->s_root)
3044 bdi_unregister(&server->backing_dev_info);
3046 deactivate_locked_super(s);
3047 nfs_free_fhandle(mntfh);
3048 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
3049 return ERR_PTR(error);
3053 * Create an NFS4 server record on referral traversal
3055 static struct dentry *nfs4_referral_mount(struct file_system_type *fs_type,
3056 int flags, const char *dev_name, void *raw_data)
3058 struct nfs_clone_mount *data = raw_data;
3060 struct vfsmount *root_mnt;
3063 dprintk("--> nfs4_referral_mount()\n");
3065 export_path = data->mnt_path;
3066 data->mnt_path = "/";
3068 root_mnt = nfs_do_root_mount(&nfs4_remote_referral_fs_type,
3069 flags, data, data->hostname);
3070 data->mnt_path = export_path;
3072 res = nfs_follow_remote_path(root_mnt, export_path);
3073 dprintk("<-- nfs4_referral_mount() = %ld%s\n",
3074 IS_ERR(res) ? PTR_ERR(res) : 0,
3075 IS_ERR(res) ? " [error]" : "");
3079 #endif /* CONFIG_NFS_V4 */