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>
57 #include <asm/system.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_v2, Opt_v3, Opt_v4, Opt_v4_0, Opt_v4_1,
84 Opt_udp, Opt_tcp, Opt_rdma,
86 Opt_rdirplus, Opt_nordirplus,
87 Opt_sharecache, Opt_nosharecache,
88 Opt_resvport, Opt_noresvport,
89 Opt_fscache, Opt_nofscache,
91 /* Mount options that take integer arguments */
93 Opt_rsize, Opt_wsize, Opt_bsize,
94 Opt_timeo, Opt_retrans,
95 Opt_acregmin, Opt_acregmax,
96 Opt_acdirmin, Opt_acdirmax,
104 /* Mount options that take string arguments */
105 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
106 Opt_addr, Opt_mountaddr, Opt_clientaddr,
111 /* Special mount options */
112 Opt_userspace, Opt_deprecated, Opt_sloppy,
117 static const match_table_t nfs_mount_option_tokens = {
118 { Opt_userspace, "bg" },
119 { Opt_userspace, "fg" },
120 { Opt_userspace, "retry=%s" },
122 { Opt_sloppy, "sloppy" },
124 { Opt_soft, "soft" },
125 { Opt_hard, "hard" },
126 { Opt_deprecated, "intr" },
127 { Opt_deprecated, "nointr" },
128 { Opt_posix, "posix" },
129 { Opt_noposix, "noposix" },
131 { Opt_nocto, "nocto" },
133 { Opt_noac, "noac" },
134 { Opt_lock, "lock" },
135 { Opt_nolock, "nolock" },
139 { Opt_v4_0, "v4.0" },
140 { Opt_v4_1, "v4.1" },
143 { Opt_rdma, "rdma" },
145 { Opt_noacl, "noacl" },
146 { Opt_rdirplus, "rdirplus" },
147 { Opt_nordirplus, "nordirplus" },
148 { Opt_sharecache, "sharecache" },
149 { Opt_nosharecache, "nosharecache" },
150 { Opt_resvport, "resvport" },
151 { Opt_noresvport, "noresvport" },
152 { Opt_fscache, "fsc" },
153 { Opt_nofscache, "nofsc" },
155 { Opt_port, "port=%s" },
156 { Opt_rsize, "rsize=%s" },
157 { Opt_wsize, "wsize=%s" },
158 { Opt_bsize, "bsize=%s" },
159 { Opt_timeo, "timeo=%s" },
160 { Opt_retrans, "retrans=%s" },
161 { Opt_acregmin, "acregmin=%s" },
162 { Opt_acregmax, "acregmax=%s" },
163 { Opt_acdirmin, "acdirmin=%s" },
164 { Opt_acdirmax, "acdirmax=%s" },
165 { Opt_actimeo, "actimeo=%s" },
166 { Opt_namelen, "namlen=%s" },
167 { Opt_mountport, "mountport=%s" },
168 { Opt_mountvers, "mountvers=%s" },
169 { Opt_nfsvers, "nfsvers=%s" },
170 { Opt_nfsvers, "vers=%s" },
171 { Opt_minorversion, "minorversion=%s" },
173 { Opt_sec, "sec=%s" },
174 { Opt_proto, "proto=%s" },
175 { Opt_mountproto, "mountproto=%s" },
176 { Opt_addr, "addr=%s" },
177 { Opt_clientaddr, "clientaddr=%s" },
178 { Opt_mounthost, "mounthost=%s" },
179 { Opt_mountaddr, "mountaddr=%s" },
181 { Opt_lookupcache, "lookupcache=%s" },
182 { Opt_fscache_uniq, "fsc=%s" },
183 { Opt_local_lock, "local_lock=%s" },
189 Opt_xprt_udp, Opt_xprt_udp6, Opt_xprt_tcp, Opt_xprt_tcp6, Opt_xprt_rdma,
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" },
201 { Opt_xprt_err, NULL }
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,
213 static const match_table_t nfs_secflavor_tokens = {
214 { Opt_sec_none, "none" },
215 { Opt_sec_none, "null" },
216 { Opt_sec_sys, "sys" },
218 { Opt_sec_krb5, "krb5" },
219 { Opt_sec_krb5i, "krb5i" },
220 { Opt_sec_krb5p, "krb5p" },
222 { Opt_sec_lkey, "lkey" },
223 { Opt_sec_lkeyi, "lkeyi" },
224 { Opt_sec_lkeyp, "lkeyp" },
226 { Opt_sec_spkm, "spkm3" },
227 { Opt_sec_spkmi, "spkm3i" },
228 { Opt_sec_spkmp, "spkm3p" },
230 { Opt_sec_err, NULL }
234 Opt_lookupcache_all, Opt_lookupcache_positive,
235 Opt_lookupcache_none,
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" },
246 { Opt_lookupcache_err, NULL }
250 Opt_local_lock_all, Opt_local_lock_flock, Opt_local_lock_posix,
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" },
262 { Opt_local_lock_err, NULL }
266 static void nfs_umount_begin(struct super_block *);
267 static int nfs_statfs(struct dentry *, struct kstatfs *);
268 static int nfs_show_options(struct seq_file *, struct dentry *);
269 static int nfs_show_devname(struct seq_file *, struct dentry *);
270 static int nfs_show_path(struct seq_file *, struct dentry *);
271 static int nfs_show_stats(struct seq_file *, struct dentry *);
272 static struct dentry *nfs_fs_mount(struct file_system_type *,
273 int, const char *, void *);
274 static struct dentry *nfs_xdev_mount(struct file_system_type *fs_type,
275 int flags, const char *dev_name, void *raw_data);
276 static void nfs_put_super(struct super_block *);
277 static void nfs_kill_super(struct super_block *);
278 static int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
280 static struct file_system_type nfs_fs_type = {
281 .owner = THIS_MODULE,
283 .mount = nfs_fs_mount,
284 .kill_sb = nfs_kill_super,
285 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
288 struct file_system_type nfs_xdev_fs_type = {
289 .owner = THIS_MODULE,
291 .mount = nfs_xdev_mount,
292 .kill_sb = nfs_kill_super,
293 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
296 static const struct super_operations nfs_sops = {
297 .alloc_inode = nfs_alloc_inode,
298 .destroy_inode = nfs_destroy_inode,
299 .write_inode = nfs_write_inode,
300 .put_super = nfs_put_super,
301 .statfs = nfs_statfs,
302 .evict_inode = nfs_evict_inode,
303 .umount_begin = nfs_umount_begin,
304 .show_options = nfs_show_options,
305 .show_devname = nfs_show_devname,
306 .show_path = nfs_show_path,
307 .show_stats = nfs_show_stats,
308 .remount_fs = nfs_remount,
312 static int nfs4_validate_text_mount_data(void *options,
313 struct nfs_parsed_mount_data *args, const char *dev_name);
314 static struct dentry *nfs4_try_mount(int flags, const char *dev_name,
315 struct nfs_parsed_mount_data *data);
316 static struct dentry *nfs4_mount(struct file_system_type *fs_type,
317 int flags, const char *dev_name, void *raw_data);
318 static struct dentry *nfs4_remote_mount(struct file_system_type *fs_type,
319 int flags, const char *dev_name, void *raw_data);
320 static struct dentry *nfs4_xdev_mount(struct file_system_type *fs_type,
321 int flags, const char *dev_name, void *raw_data);
322 static struct dentry *nfs4_referral_mount(struct file_system_type *fs_type,
323 int flags, const char *dev_name, void *raw_data);
324 static struct dentry *nfs4_remote_referral_mount(struct file_system_type *fs_type,
325 int flags, const char *dev_name, void *raw_data);
326 static void nfs4_kill_super(struct super_block *sb);
328 static struct file_system_type nfs4_fs_type = {
329 .owner = THIS_MODULE,
332 .kill_sb = nfs4_kill_super,
333 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
336 static struct file_system_type nfs4_remote_fs_type = {
337 .owner = THIS_MODULE,
339 .mount = nfs4_remote_mount,
340 .kill_sb = nfs4_kill_super,
341 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
344 struct file_system_type nfs4_xdev_fs_type = {
345 .owner = THIS_MODULE,
347 .mount = nfs4_xdev_mount,
348 .kill_sb = nfs4_kill_super,
349 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
352 static struct file_system_type nfs4_remote_referral_fs_type = {
353 .owner = THIS_MODULE,
355 .mount = nfs4_remote_referral_mount,
356 .kill_sb = nfs4_kill_super,
357 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
360 struct file_system_type nfs4_referral_fs_type = {
361 .owner = THIS_MODULE,
363 .mount = nfs4_referral_mount,
364 .kill_sb = nfs4_kill_super,
365 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
368 static const struct super_operations nfs4_sops = {
369 .alloc_inode = nfs_alloc_inode,
370 .destroy_inode = nfs_destroy_inode,
371 .write_inode = nfs_write_inode,
372 .put_super = nfs_put_super,
373 .statfs = nfs_statfs,
374 .evict_inode = nfs4_evict_inode,
375 .umount_begin = nfs_umount_begin,
376 .show_options = nfs_show_options,
377 .show_devname = nfs_show_devname,
378 .show_path = nfs_show_path,
379 .show_stats = nfs_show_stats,
380 .remount_fs = nfs_remount,
384 static struct shrinker acl_shrinker = {
385 .shrink = nfs_access_cache_shrinker,
386 .seeks = DEFAULT_SEEKS,
390 * Register the NFS filesystems
392 int __init register_nfs_fs(void)
396 ret = register_filesystem(&nfs_fs_type);
400 ret = nfs_register_sysctl();
404 ret = register_filesystem(&nfs4_fs_type);
408 register_shrinker(&acl_shrinker);
413 nfs_unregister_sysctl();
416 unregister_filesystem(&nfs_fs_type);
422 * Unregister the NFS filesystems
424 void __exit unregister_nfs_fs(void)
426 unregister_shrinker(&acl_shrinker);
428 unregister_filesystem(&nfs4_fs_type);
430 nfs_unregister_sysctl();
431 unregister_filesystem(&nfs_fs_type);
434 void nfs_sb_active(struct super_block *sb)
436 struct nfs_server *server = NFS_SB(sb);
438 if (atomic_inc_return(&server->active) == 1)
439 atomic_inc(&sb->s_active);
442 void nfs_sb_deactive(struct super_block *sb)
444 struct nfs_server *server = NFS_SB(sb);
446 if (atomic_dec_and_test(&server->active))
447 deactivate_super(sb);
451 * Deliver file system statistics to userspace
453 static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
455 struct nfs_server *server = NFS_SB(dentry->d_sb);
456 unsigned char blockbits;
457 unsigned long blockres;
458 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
459 struct nfs_fsstat res;
462 res.fattr = nfs_alloc_fattr();
463 if (res.fattr == NULL)
466 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
467 if (unlikely(error == -ESTALE)) {
468 struct dentry *pd_dentry;
470 pd_dentry = dget_parent(dentry);
471 if (pd_dentry != NULL) {
472 nfs_zap_caches(pd_dentry->d_inode);
476 nfs_free_fattr(res.fattr);
480 buf->f_type = NFS_SUPER_MAGIC;
483 * Current versions of glibc do not correctly handle the
484 * case where f_frsize != f_bsize. Eventually we want to
485 * report the value of wtmult in this field.
487 buf->f_frsize = dentry->d_sb->s_blocksize;
490 * On most *nix systems, f_blocks, f_bfree, and f_bavail
491 * are reported in units of f_frsize. Linux hasn't had
492 * an f_frsize field in its statfs struct until recently,
493 * thus historically Linux's sys_statfs reports these
494 * fields in units of f_bsize.
496 buf->f_bsize = dentry->d_sb->s_blocksize;
497 blockbits = dentry->d_sb->s_blocksize_bits;
498 blockres = (1 << blockbits) - 1;
499 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
500 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
501 buf->f_bavail = (res.abytes + blockres) >> blockbits;
503 buf->f_files = res.tfiles;
504 buf->f_ffree = res.afiles;
506 buf->f_namelen = server->namelen;
511 dprintk("%s: statfs error = %d\n", __func__, -error);
516 * Map the security flavour number to a name
518 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
520 static const struct {
521 rpc_authflavor_t flavour;
524 { RPC_AUTH_NULL, "null" },
525 { RPC_AUTH_UNIX, "sys" },
526 { RPC_AUTH_GSS_KRB5, "krb5" },
527 { RPC_AUTH_GSS_KRB5I, "krb5i" },
528 { RPC_AUTH_GSS_KRB5P, "krb5p" },
529 { RPC_AUTH_GSS_LKEY, "lkey" },
530 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
531 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
532 { RPC_AUTH_GSS_SPKM, "spkm" },
533 { RPC_AUTH_GSS_SPKMI, "spkmi" },
534 { RPC_AUTH_GSS_SPKMP, "spkmp" },
535 { UINT_MAX, "unknown" }
539 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
540 if (sec_flavours[i].flavour == flavour)
543 return sec_flavours[i].str;
546 static void nfs_show_mountd_netid(struct seq_file *m, struct nfs_server *nfss,
549 struct sockaddr *sap = (struct sockaddr *) &nfss->mountd_address;
551 seq_printf(m, ",mountproto=");
552 switch (sap->sa_family) {
554 switch (nfss->mountd_protocol) {
556 seq_printf(m, RPCBIND_NETID_UDP);
559 seq_printf(m, RPCBIND_NETID_TCP);
563 seq_printf(m, "auto");
567 switch (nfss->mountd_protocol) {
569 seq_printf(m, RPCBIND_NETID_UDP6);
572 seq_printf(m, RPCBIND_NETID_TCP6);
576 seq_printf(m, "auto");
581 seq_printf(m, "auto");
585 static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
588 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
590 if (nfss->flags & NFS_MOUNT_LEGACY_INTERFACE)
593 switch (sap->sa_family) {
595 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
596 seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
600 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
601 seq_printf(m, ",mountaddr=%pI6c", &sin6->sin6_addr);
606 seq_printf(m, ",mountaddr=unspecified");
609 if (nfss->mountd_version || showdefaults)
610 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
611 if ((nfss->mountd_port &&
612 nfss->mountd_port != (unsigned short)NFS_UNSPEC_PORT) ||
614 seq_printf(m, ",mountport=%u", nfss->mountd_port);
616 nfs_show_mountd_netid(m, nfss, showdefaults);
620 static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
623 struct nfs_client *clp = nfss->nfs_client;
625 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
626 seq_printf(m, ",minorversion=%u", clp->cl_minorversion);
629 static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
636 * Describe the mount options in force on this server representation
638 static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
641 static const struct proc_nfs_info {
646 { NFS_MOUNT_SOFT, ",soft", ",hard" },
647 { NFS_MOUNT_POSIX, ",posix", "" },
648 { NFS_MOUNT_NOCTO, ",nocto", "" },
649 { NFS_MOUNT_NOAC, ",noac", "" },
650 { NFS_MOUNT_NONLM, ",nolock", "" },
651 { NFS_MOUNT_NOACL, ",noacl", "" },
652 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
653 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
654 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
657 const struct proc_nfs_info *nfs_infop;
658 struct nfs_client *clp = nfss->nfs_client;
659 u32 version = clp->rpc_ops->version;
660 int local_flock, local_fcntl;
662 seq_printf(m, ",vers=%u", version);
663 seq_printf(m, ",rsize=%u", nfss->rsize);
664 seq_printf(m, ",wsize=%u", nfss->wsize);
665 if (nfss->bsize != 0)
666 seq_printf(m, ",bsize=%u", nfss->bsize);
667 seq_printf(m, ",namlen=%u", nfss->namelen);
668 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
669 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
670 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
671 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
672 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
673 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
674 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
675 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
676 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
677 if (nfss->flags & nfs_infop->flag)
678 seq_puts(m, nfs_infop->str);
680 seq_puts(m, nfs_infop->nostr);
682 seq_printf(m, ",proto=%s",
683 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
685 if (nfss->port != NFS_PORT)
686 seq_printf(m, ",port=%u", nfss->port);
689 seq_printf(m, ",port=%u", nfss->port);
691 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
692 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
693 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
696 nfs_show_mountd_options(m, nfss, showdefaults);
698 nfs_show_nfsv4_options(m, nfss, showdefaults);
700 if (nfss->options & NFS_OPTION_FSCACHE)
701 seq_printf(m, ",fsc");
703 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONEG) {
704 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONE)
705 seq_printf(m, ",lookupcache=none");
707 seq_printf(m, ",lookupcache=pos");
710 local_flock = nfss->flags & NFS_MOUNT_LOCAL_FLOCK;
711 local_fcntl = nfss->flags & NFS_MOUNT_LOCAL_FCNTL;
713 if (!local_flock && !local_fcntl)
714 seq_printf(m, ",local_lock=none");
715 else if (local_flock && local_fcntl)
716 seq_printf(m, ",local_lock=all");
717 else if (local_flock)
718 seq_printf(m, ",local_lock=flock");
720 seq_printf(m, ",local_lock=posix");
724 * Describe the mount options on this VFS mountpoint
726 static int nfs_show_options(struct seq_file *m, struct dentry *root)
728 struct nfs_server *nfss = NFS_SB(root->d_sb);
730 nfs_show_mount_options(m, nfss, 0);
732 seq_printf(m, ",addr=%s",
733 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
740 #ifdef CONFIG_NFS_V4_1
741 static void show_sessions(struct seq_file *m, struct nfs_server *server)
743 if (nfs4_has_session(server->nfs_client))
744 seq_printf(m, ",sessions");
747 static void show_sessions(struct seq_file *m, struct nfs_server *server) {}
752 #ifdef CONFIG_NFS_V4_1
753 static void show_pnfs(struct seq_file *m, struct nfs_server *server)
755 seq_printf(m, ",pnfs=");
756 if (server->pnfs_curr_ld)
757 seq_printf(m, "%s", server->pnfs_curr_ld->name);
759 seq_printf(m, "not configured");
762 static void show_pnfs(struct seq_file *m, struct nfs_server *server) {}
766 static int nfs_show_devname(struct seq_file *m, struct dentry *root)
768 char *page = (char *) __get_free_page(GFP_KERNEL);
769 char *devname, *dummy;
773 devname = nfs_path(&dummy, root, page, PAGE_SIZE);
775 err = PTR_ERR(devname);
777 seq_escape(m, devname, " \t\n\\");
778 free_page((unsigned long)page);
782 static int nfs_show_path(struct seq_file *m, struct dentry *dentry)
789 * Present statistical information for this VFS mountpoint
791 static int nfs_show_stats(struct seq_file *m, struct dentry *root)
794 struct nfs_server *nfss = NFS_SB(root->d_sb);
795 struct rpc_auth *auth = nfss->client->cl_auth;
796 struct nfs_iostats totals = { };
798 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
801 * Display all mount option settings
803 seq_printf(m, "\n\topts:\t");
804 seq_puts(m, root->d_sb->s_flags & MS_RDONLY ? "ro" : "rw");
805 seq_puts(m, root->d_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
806 seq_puts(m, root->d_sb->s_flags & MS_NOATIME ? ",noatime" : "");
807 seq_puts(m, root->d_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
808 nfs_show_mount_options(m, nfss, 1);
810 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
812 if (nfss->nfs_client && nfss->nfs_client->impl_id) {
813 struct nfs41_impl_id *impl_id = nfss->nfs_client->impl_id;
814 seq_printf(m, "\n\timpl_id:\tname='%s',domain='%s',"
816 impl_id->name, impl_id->domain,
817 impl_id->date.seconds, impl_id->date.nseconds);
820 seq_printf(m, "\n\tcaps:\t");
821 seq_printf(m, "caps=0x%x", nfss->caps);
822 seq_printf(m, ",wtmult=%u", nfss->wtmult);
823 seq_printf(m, ",dtsize=%u", nfss->dtsize);
824 seq_printf(m, ",bsize=%u", nfss->bsize);
825 seq_printf(m, ",namlen=%u", nfss->namelen);
828 if (nfss->nfs_client->rpc_ops->version == 4) {
829 seq_printf(m, "\n\tnfsv4:\t");
830 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
831 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
832 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
833 show_sessions(m, nfss);
839 * Display security flavor in effect for this mount
841 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
843 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
846 * Display superblock I/O counters
848 for_each_possible_cpu(cpu) {
849 struct nfs_iostats *stats;
852 stats = per_cpu_ptr(nfss->io_stats, cpu);
854 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
855 totals.events[i] += stats->events[i];
856 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
857 totals.bytes[i] += stats->bytes[i];
858 #ifdef CONFIG_NFS_FSCACHE
859 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
860 totals.fscache[i] += stats->fscache[i];
866 seq_printf(m, "\n\tevents:\t");
867 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
868 seq_printf(m, "%lu ", totals.events[i]);
869 seq_printf(m, "\n\tbytes:\t");
870 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
871 seq_printf(m, "%Lu ", totals.bytes[i]);
872 #ifdef CONFIG_NFS_FSCACHE
873 if (nfss->options & NFS_OPTION_FSCACHE) {
874 seq_printf(m, "\n\tfsc:\t");
875 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
876 seq_printf(m, "%Lu ", totals.bytes[i]);
881 rpc_print_iostats(m, nfss->client);
887 * Begin unmount by attempting to remove all automounted mountpoints we added
888 * in response to xdev traversals and referrals
890 static void nfs_umount_begin(struct super_block *sb)
892 struct nfs_server *server;
893 struct rpc_clnt *rpc;
896 /* -EIO all pending I/O */
897 rpc = server->client_acl;
899 rpc_killall_tasks(rpc);
900 rpc = server->client;
902 rpc_killall_tasks(rpc);
905 static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(unsigned int version)
907 struct nfs_parsed_mount_data *data;
909 data = kzalloc(sizeof(*data), GFP_KERNEL);
911 data->acregmin = NFS_DEF_ACREGMIN;
912 data->acregmax = NFS_DEF_ACREGMAX;
913 data->acdirmin = NFS_DEF_ACDIRMIN;
914 data->acdirmax = NFS_DEF_ACDIRMAX;
915 data->mount_server.port = NFS_UNSPEC_PORT;
916 data->nfs_server.port = NFS_UNSPEC_PORT;
917 data->nfs_server.protocol = XPRT_TRANSPORT_TCP;
918 data->auth_flavors[0] = RPC_AUTH_UNIX;
919 data->auth_flavor_len = 1;
920 data->version = version;
921 data->minorversion = 0;
922 data->net = current->nsproxy->net_ns;
923 security_init_mnt_opts(&data->lsm_opts);
928 static void nfs_free_parsed_mount_data(struct nfs_parsed_mount_data *data)
931 kfree(data->client_address);
932 kfree(data->mount_server.hostname);
933 kfree(data->nfs_server.export_path);
934 kfree(data->nfs_server.hostname);
935 kfree(data->fscache_uniq);
936 security_free_mnt_opts(&data->lsm_opts);
942 * Sanity-check a server address provided by the mount command.
944 * Address family must be initialized, and address must not be
945 * the ANY address for that family.
947 static int nfs_verify_server_address(struct sockaddr *addr)
949 switch (addr->sa_family) {
951 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
952 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
955 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
956 return !ipv6_addr_any(sa);
960 dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
965 * Select between a default port value and a user-specified port value.
966 * If a zero value is set, then autobind will be used.
968 static void nfs_set_port(struct sockaddr *sap, int *port,
969 const unsigned short default_port)
971 if (*port == NFS_UNSPEC_PORT)
972 *port = default_port;
974 rpc_set_port(sap, *port);
978 * Sanity check the NFS transport protocol.
981 static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
983 switch (mnt->nfs_server.protocol) {
984 case XPRT_TRANSPORT_UDP:
985 case XPRT_TRANSPORT_TCP:
986 case XPRT_TRANSPORT_RDMA:
989 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
994 * For text based NFSv2/v3 mounts, the mount protocol transport default
995 * settings should depend upon the specified NFS transport.
997 static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
999 nfs_validate_transport_protocol(mnt);
1001 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
1002 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
1004 switch (mnt->nfs_server.protocol) {
1005 case XPRT_TRANSPORT_UDP:
1006 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
1008 case XPRT_TRANSPORT_TCP:
1009 case XPRT_TRANSPORT_RDMA:
1010 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
1015 * Parse the value of the 'sec=' option.
1017 static int nfs_parse_security_flavors(char *value,
1018 struct nfs_parsed_mount_data *mnt)
1020 substring_t args[MAX_OPT_ARGS];
1022 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
1024 switch (match_token(value, nfs_secflavor_tokens, args)) {
1026 mnt->auth_flavors[0] = RPC_AUTH_NULL;
1029 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
1032 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
1035 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
1038 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
1041 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
1044 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
1047 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
1050 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
1053 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
1056 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
1062 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
1063 mnt->auth_flavor_len = 1;
1067 static int nfs_get_option_str(substring_t args[], char **option)
1070 *option = match_strdup(args);
1074 static int nfs_get_option_ul(substring_t args[], unsigned long *option)
1079 string = match_strdup(args);
1082 rc = strict_strtoul(string, 10, option);
1089 * Error-check and convert a string of mount options from user space into
1090 * a data structure. The whole mount string is processed; bad options are
1091 * skipped as they are encountered. If there were no errors, return 1;
1092 * otherwise return 0 (zero).
1094 static int nfs_parse_mount_options(char *raw,
1095 struct nfs_parsed_mount_data *mnt)
1097 char *p, *string, *secdata;
1098 int rc, sloppy = 0, invalid_option = 0;
1099 unsigned short protofamily = AF_UNSPEC;
1100 unsigned short mountfamily = AF_UNSPEC;
1103 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
1106 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
1108 secdata = alloc_secdata();
1112 rc = security_sb_copy_data(raw, secdata);
1114 goto out_security_failure;
1116 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
1118 goto out_security_failure;
1120 free_secdata(secdata);
1122 while ((p = strsep(&raw, ",")) != NULL) {
1123 substring_t args[MAX_OPT_ARGS];
1124 unsigned long option;
1130 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
1132 token = match_token(p, nfs_mount_option_tokens, args);
1136 * boolean options: foo/nofoo
1139 mnt->flags |= NFS_MOUNT_SOFT;
1142 mnt->flags &= ~NFS_MOUNT_SOFT;
1145 mnt->flags |= NFS_MOUNT_POSIX;
1148 mnt->flags &= ~NFS_MOUNT_POSIX;
1151 mnt->flags &= ~NFS_MOUNT_NOCTO;
1154 mnt->flags |= NFS_MOUNT_NOCTO;
1157 mnt->flags &= ~NFS_MOUNT_NOAC;
1160 mnt->flags |= NFS_MOUNT_NOAC;
1163 mnt->flags &= ~NFS_MOUNT_NONLM;
1164 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1165 NFS_MOUNT_LOCAL_FCNTL);
1168 mnt->flags |= NFS_MOUNT_NONLM;
1169 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1170 NFS_MOUNT_LOCAL_FCNTL);
1173 mnt->flags &= ~NFS_MOUNT_VER3;
1177 mnt->flags |= NFS_MOUNT_VER3;
1181 mnt->flags &= ~NFS_MOUNT_VER3;
1185 mnt->flags &= ~NFS_MOUNT_VER3;
1187 mnt->minorversion = 0;
1190 mnt->flags &= ~NFS_MOUNT_VER3;
1192 mnt->minorversion = 1;
1195 mnt->flags &= ~NFS_MOUNT_TCP;
1196 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1199 mnt->flags |= NFS_MOUNT_TCP;
1200 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1203 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1204 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1205 xprt_load_transport(p);
1208 mnt->flags &= ~NFS_MOUNT_NOACL;
1211 mnt->flags |= NFS_MOUNT_NOACL;
1214 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1216 case Opt_nordirplus:
1217 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1219 case Opt_sharecache:
1220 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1222 case Opt_nosharecache:
1223 mnt->flags |= NFS_MOUNT_UNSHARED;
1226 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1228 case Opt_noresvport:
1229 mnt->flags |= NFS_MOUNT_NORESVPORT;
1232 mnt->options |= NFS_OPTION_FSCACHE;
1233 kfree(mnt->fscache_uniq);
1234 mnt->fscache_uniq = NULL;
1237 mnt->options &= ~NFS_OPTION_FSCACHE;
1238 kfree(mnt->fscache_uniq);
1239 mnt->fscache_uniq = NULL;
1243 * options that take numeric values
1246 if (nfs_get_option_ul(args, &option) ||
1248 goto out_invalid_value;
1249 mnt->nfs_server.port = option;
1252 if (nfs_get_option_ul(args, &option))
1253 goto out_invalid_value;
1254 mnt->rsize = option;
1257 if (nfs_get_option_ul(args, &option))
1258 goto out_invalid_value;
1259 mnt->wsize = option;
1262 if (nfs_get_option_ul(args, &option))
1263 goto out_invalid_value;
1264 mnt->bsize = option;
1267 if (nfs_get_option_ul(args, &option) || option == 0)
1268 goto out_invalid_value;
1269 mnt->timeo = option;
1272 if (nfs_get_option_ul(args, &option) || option == 0)
1273 goto out_invalid_value;
1274 mnt->retrans = option;
1277 if (nfs_get_option_ul(args, &option))
1278 goto out_invalid_value;
1279 mnt->acregmin = option;
1282 if (nfs_get_option_ul(args, &option))
1283 goto out_invalid_value;
1284 mnt->acregmax = option;
1287 if (nfs_get_option_ul(args, &option))
1288 goto out_invalid_value;
1289 mnt->acdirmin = option;
1292 if (nfs_get_option_ul(args, &option))
1293 goto out_invalid_value;
1294 mnt->acdirmax = option;
1297 if (nfs_get_option_ul(args, &option))
1298 goto out_invalid_value;
1299 mnt->acregmin = mnt->acregmax =
1300 mnt->acdirmin = mnt->acdirmax = option;
1303 if (nfs_get_option_ul(args, &option))
1304 goto out_invalid_value;
1305 mnt->namlen = option;
1308 if (nfs_get_option_ul(args, &option) ||
1310 goto out_invalid_value;
1311 mnt->mount_server.port = option;
1314 if (nfs_get_option_ul(args, &option) ||
1315 option < NFS_MNT_VERSION ||
1316 option > NFS_MNT3_VERSION)
1317 goto out_invalid_value;
1318 mnt->mount_server.version = option;
1321 if (nfs_get_option_ul(args, &option))
1322 goto out_invalid_value;
1325 mnt->flags &= ~NFS_MOUNT_VER3;
1329 mnt->flags |= NFS_MOUNT_VER3;
1333 mnt->flags &= ~NFS_MOUNT_VER3;
1337 goto out_invalid_value;
1340 case Opt_minorversion:
1341 if (nfs_get_option_ul(args, &option))
1342 goto out_invalid_value;
1343 if (option > NFS4_MAX_MINOR_VERSION)
1344 goto out_invalid_value;
1345 mnt->minorversion = option;
1349 * options that take text values
1352 string = match_strdup(args);
1355 rc = nfs_parse_security_flavors(string, mnt);
1358 dfprintk(MOUNT, "NFS: unrecognized "
1359 "security flavor\n");
1364 string = match_strdup(args);
1367 token = match_token(string,
1368 nfs_xprt_protocol_tokens, args);
1370 protofamily = AF_INET;
1373 protofamily = AF_INET6;
1375 mnt->flags &= ~NFS_MOUNT_TCP;
1376 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1379 protofamily = AF_INET6;
1381 mnt->flags |= NFS_MOUNT_TCP;
1382 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1385 /* vector side protocols to TCP */
1386 mnt->flags |= NFS_MOUNT_TCP;
1387 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1388 xprt_load_transport(string);
1391 dfprintk(MOUNT, "NFS: unrecognized "
1392 "transport protocol\n");
1398 case Opt_mountproto:
1399 string = match_strdup(args);
1402 token = match_token(string,
1403 nfs_xprt_protocol_tokens, args);
1406 mountfamily = AF_INET;
1409 mountfamily = AF_INET6;
1411 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
1414 mountfamily = AF_INET6;
1416 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
1418 case Opt_xprt_rdma: /* not used for side protocols */
1420 dfprintk(MOUNT, "NFS: unrecognized "
1421 "transport protocol\n");
1426 string = match_strdup(args);
1429 mnt->nfs_server.addrlen =
1430 rpc_pton(mnt->net, string, strlen(string),
1432 &mnt->nfs_server.address,
1433 sizeof(mnt->nfs_server.address));
1435 if (mnt->nfs_server.addrlen == 0)
1436 goto out_invalid_address;
1438 case Opt_clientaddr:
1439 if (nfs_get_option_str(args, &mnt->client_address))
1443 if (nfs_get_option_str(args,
1444 &mnt->mount_server.hostname))
1448 string = match_strdup(args);
1451 mnt->mount_server.addrlen =
1452 rpc_pton(mnt->net, string, strlen(string),
1454 &mnt->mount_server.address,
1455 sizeof(mnt->mount_server.address));
1457 if (mnt->mount_server.addrlen == 0)
1458 goto out_invalid_address;
1460 case Opt_lookupcache:
1461 string = match_strdup(args);
1464 token = match_token(string,
1465 nfs_lookupcache_tokens, args);
1468 case Opt_lookupcache_all:
1469 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1471 case Opt_lookupcache_positive:
1472 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1473 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1475 case Opt_lookupcache_none:
1476 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1479 dfprintk(MOUNT, "NFS: invalid "
1480 "lookupcache argument\n");
1484 case Opt_fscache_uniq:
1485 if (nfs_get_option_str(args, &mnt->fscache_uniq))
1487 mnt->options |= NFS_OPTION_FSCACHE;
1489 case Opt_local_lock:
1490 string = match_strdup(args);
1493 token = match_token(string, nfs_local_lock_tokens,
1497 case Opt_local_lock_all:
1498 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1499 NFS_MOUNT_LOCAL_FCNTL);
1501 case Opt_local_lock_flock:
1502 mnt->flags |= NFS_MOUNT_LOCAL_FLOCK;
1504 case Opt_local_lock_posix:
1505 mnt->flags |= NFS_MOUNT_LOCAL_FCNTL;
1507 case Opt_local_lock_none:
1508 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1509 NFS_MOUNT_LOCAL_FCNTL);
1512 dfprintk(MOUNT, "NFS: invalid "
1513 "local_lock argument\n");
1523 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1526 case Opt_deprecated:
1527 dfprintk(MOUNT, "NFS: ignoring mount option "
1533 dfprintk(MOUNT, "NFS: unrecognized mount option "
1538 if (!sloppy && invalid_option)
1541 if (mnt->minorversion && mnt->version != 4)
1542 goto out_minorversion_mismatch;
1545 * verify that any proto=/mountproto= options match the address
1546 * familiies in the addr=/mountaddr= options.
1548 if (protofamily != AF_UNSPEC &&
1549 protofamily != mnt->nfs_server.address.ss_family)
1550 goto out_proto_mismatch;
1552 if (mountfamily != AF_UNSPEC) {
1553 if (mnt->mount_server.addrlen) {
1554 if (mountfamily != mnt->mount_server.address.ss_family)
1555 goto out_mountproto_mismatch;
1557 if (mountfamily != mnt->nfs_server.address.ss_family)
1558 goto out_mountproto_mismatch;
1564 out_mountproto_mismatch:
1565 printk(KERN_INFO "NFS: mount server address does not match mountproto= "
1569 printk(KERN_INFO "NFS: server address does not match proto= option\n");
1571 out_invalid_address:
1572 printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
1575 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
1577 out_minorversion_mismatch:
1578 printk(KERN_INFO "NFS: mount option vers=%u does not support "
1579 "minorversion=%u\n", mnt->version, mnt->minorversion);
1582 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1584 out_security_failure:
1585 free_secdata(secdata);
1586 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1591 * Match the requested auth flavors with the list returned by
1592 * the server. Returns zero and sets the mount's authentication
1593 * flavor on success; returns -EACCES if server does not support
1594 * the requested flavor.
1596 static int nfs_walk_authlist(struct nfs_parsed_mount_data *args,
1597 struct nfs_mount_request *request)
1599 unsigned int i, j, server_authlist_len = *(request->auth_flav_len);
1602 * Certain releases of Linux's mountd return an empty
1603 * flavor list. To prevent behavioral regression with
1604 * these servers (ie. rejecting mounts that used to
1605 * succeed), revert to pre-2.6.32 behavior (no checking)
1606 * if the returned flavor list is empty.
1608 if (server_authlist_len == 0)
1612 * We avoid sophisticated negotiating here, as there are
1613 * plenty of cases where we can get it wrong, providing
1614 * either too little or too much security.
1616 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1617 * flavor listed first. However, some servers list
1618 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1619 * preferred default, in args->auth_flavors[0] if user
1620 * didn't specify sec= mount option.
1622 for (i = 0; i < args->auth_flavor_len; i++)
1623 for (j = 0; j < server_authlist_len; j++)
1624 if (args->auth_flavors[i] == request->auth_flavs[j]) {
1625 dfprintk(MOUNT, "NFS: using auth flavor %d\n",
1626 request->auth_flavs[j]);
1627 args->auth_flavors[0] = request->auth_flavs[j];
1631 dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n");
1632 nfs_umount(request);
1637 * Use the remote server's MOUNT service to request the NFS file handle
1638 * corresponding to the provided path.
1640 static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1641 struct nfs_fh *root_fh)
1643 rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS];
1644 unsigned int server_authlist_len = ARRAY_SIZE(server_authlist);
1645 struct nfs_mount_request request = {
1646 .sap = (struct sockaddr *)
1647 &args->mount_server.address,
1648 .dirpath = args->nfs_server.export_path,
1649 .protocol = args->mount_server.protocol,
1651 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
1652 .auth_flav_len = &server_authlist_len,
1653 .auth_flavs = server_authlist,
1658 if (args->mount_server.version == 0) {
1659 switch (args->version) {
1661 args->mount_server.version = NFS_MNT3_VERSION;
1664 args->mount_server.version = NFS_MNT_VERSION;
1667 request.version = args->mount_server.version;
1669 if (args->mount_server.hostname)
1670 request.hostname = args->mount_server.hostname;
1672 request.hostname = args->nfs_server.hostname;
1675 * Construct the mount server's address.
1677 if (args->mount_server.address.ss_family == AF_UNSPEC) {
1678 memcpy(request.sap, &args->nfs_server.address,
1679 args->nfs_server.addrlen);
1680 args->mount_server.addrlen = args->nfs_server.addrlen;
1682 request.salen = args->mount_server.addrlen;
1683 nfs_set_port(request.sap, &args->mount_server.port, 0);
1686 * Now ask the mount server to map our export path
1689 status = nfs_mount(&request);
1691 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1692 request.hostname, status);
1697 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1699 if (args->mount_server.version != NFS_MNT3_VERSION)
1701 return nfs_walk_authlist(args, &request);
1705 * Split "dev_name" into "hostname:export_path".
1707 * The leftmost colon demarks the split between the server's hostname
1708 * and the export path. If the hostname starts with a left square
1709 * bracket, then it may contain colons.
1711 * Note: caller frees hostname and export path, even on error.
1713 static int nfs_parse_devname(const char *dev_name,
1714 char **hostname, size_t maxnamlen,
1715 char **export_path, size_t maxpathlen)
1720 /* Is the host name protected with square brakcets? */
1721 if (*dev_name == '[') {
1722 end = strchr(++dev_name, ']');
1723 if (end == NULL || end[1] != ':')
1724 goto out_bad_devname;
1726 len = end - dev_name;
1731 end = strchr(dev_name, ':');
1733 goto out_bad_devname;
1734 len = end - dev_name;
1736 /* kill possible hostname list: not supported */
1737 comma = strchr(dev_name, ',');
1738 if (comma != NULL && comma < end)
1742 if (len > maxnamlen)
1745 /* N.B. caller will free nfs_server.hostname in all cases */
1746 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
1747 if (*hostname == NULL)
1749 len = strlen(++end);
1750 if (len > maxpathlen)
1752 *export_path = kstrndup(end, len, GFP_KERNEL);
1756 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1760 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1764 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1768 dfprintk(MOUNT, "NFS: server hostname too long\n");
1769 return -ENAMETOOLONG;
1772 dfprintk(MOUNT, "NFS: export pathname too long\n");
1773 return -ENAMETOOLONG;
1777 * Validate the NFS2/NFS3 mount data
1778 * - fills in the mount root filehandle
1780 * For option strings, user space handles the following behaviors:
1782 * + DNS: mapping server host name to IP address ("addr=" option)
1784 * + failure mode: how to behave if a mount request can't be handled
1785 * immediately ("fg/bg" option)
1787 * + retry: how often to retry a mount request ("retry=" option)
1789 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1790 * mountproto=tcp after mountproto=udp, and so on
1792 static int nfs_validate_mount_data(void *options,
1793 struct nfs_parsed_mount_data *args,
1794 struct nfs_fh *mntfh,
1795 const char *dev_name)
1797 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
1798 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
1803 switch (data->version) {
1809 if (data->flags & NFS_MOUNT_VER3)
1811 data->root.size = NFS2_FHSIZE;
1812 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1814 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1817 memset(data->context, 0, sizeof(data->context));
1819 if (data->flags & NFS_MOUNT_VER3) {
1820 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1821 goto out_invalid_fh;
1822 mntfh->size = data->root.size;
1825 mntfh->size = NFS2_FHSIZE;
1830 memcpy(mntfh->data, data->root.data, mntfh->size);
1831 if (mntfh->size < sizeof(mntfh->data))
1832 memset(mntfh->data + mntfh->size, 0,
1833 sizeof(mntfh->data) - mntfh->size);
1836 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1839 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
1840 args->flags |= NFS_MOUNT_LEGACY_INTERFACE;
1841 args->rsize = data->rsize;
1842 args->wsize = data->wsize;
1843 args->timeo = data->timeo;
1844 args->retrans = data->retrans;
1845 args->acregmin = data->acregmin;
1846 args->acregmax = data->acregmax;
1847 args->acdirmin = data->acdirmin;
1848 args->acdirmax = data->acdirmax;
1850 memcpy(sap, &data->addr, sizeof(data->addr));
1851 args->nfs_server.addrlen = sizeof(data->addr);
1852 if (!nfs_verify_server_address(sap))
1853 goto out_no_address;
1855 if (!(data->flags & NFS_MOUNT_TCP))
1856 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1857 /* N.B. caller will free nfs_server.hostname in all cases */
1858 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1859 args->namlen = data->namlen;
1860 args->bsize = data->bsize;
1862 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1863 args->auth_flavors[0] = data->pseudoflavor;
1864 if (!args->nfs_server.hostname)
1867 if (!(data->flags & NFS_MOUNT_NONLM))
1868 args->flags &= ~(NFS_MOUNT_LOCAL_FLOCK|
1869 NFS_MOUNT_LOCAL_FCNTL);
1871 args->flags |= (NFS_MOUNT_LOCAL_FLOCK|
1872 NFS_MOUNT_LOCAL_FCNTL);
1874 * The legacy version 6 binary mount data from userspace has a
1875 * field used only to transport selinux information into the
1876 * the kernel. To continue to support that functionality we
1877 * have a touch of selinux knowledge here in the NFS code. The
1878 * userspace code converted context=blah to just blah so we are
1879 * converting back to the full string selinux understands.
1881 if (data->context[0]){
1882 #ifdef CONFIG_SECURITY_SELINUX
1884 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1887 strcpy(opts_str, "context=");
1888 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1889 strcat(opts_str, &data->context[0]);
1890 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1903 if (nfs_parse_mount_options((char *)options, args) == 0)
1906 if (!nfs_verify_server_address(sap))
1907 goto out_no_address;
1909 if (args->version == 4)
1910 #ifdef CONFIG_NFS_V4
1911 return nfs4_validate_text_mount_data(options,
1914 goto out_v4_not_compiled;
1917 nfs_set_port(sap, &args->nfs_server.port, 0);
1919 nfs_set_mount_transport_protocol(args);
1921 status = nfs_parse_devname(dev_name,
1922 &args->nfs_server.hostname,
1924 &args->nfs_server.export_path,
1927 status = nfs_try_mount(args, mntfh);
1929 kfree(args->nfs_server.export_path);
1930 args->nfs_server.export_path = NULL;
1939 #ifndef CONFIG_NFS_V3
1940 if (args->version == 3)
1941 goto out_v3_not_compiled;
1942 #endif /* !CONFIG_NFS_V3 */
1947 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1951 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1956 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1959 #ifndef CONFIG_NFS_V3
1960 out_v3_not_compiled:
1961 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1962 return -EPROTONOSUPPORT;
1963 #endif /* !CONFIG_NFS_V3 */
1965 #ifndef CONFIG_NFS_V4
1966 out_v4_not_compiled:
1967 dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n");
1968 return -EPROTONOSUPPORT;
1969 #endif /* !CONFIG_NFS_V4 */
1972 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
1976 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1980 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1985 nfs_compare_remount_data(struct nfs_server *nfss,
1986 struct nfs_parsed_mount_data *data)
1988 if (data->flags != nfss->flags ||
1989 data->rsize != nfss->rsize ||
1990 data->wsize != nfss->wsize ||
1991 data->retrans != nfss->client->cl_timeout->to_retries ||
1992 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
1993 data->acregmin != nfss->acregmin / HZ ||
1994 data->acregmax != nfss->acregmax / HZ ||
1995 data->acdirmin != nfss->acdirmin / HZ ||
1996 data->acdirmax != nfss->acdirmax / HZ ||
1997 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
1998 data->nfs_server.port != nfss->port ||
1999 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
2000 !rpc_cmp_addr((struct sockaddr *)&data->nfs_server.address,
2001 (struct sockaddr *)&nfss->nfs_client->cl_addr))
2008 nfs_remount(struct super_block *sb, int *flags, char *raw_data)
2011 struct nfs_server *nfss = sb->s_fs_info;
2012 struct nfs_parsed_mount_data *data;
2013 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
2014 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
2015 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
2018 * Userspace mount programs that send binary options generally send
2019 * them populated with default values. We have no way to know which
2020 * ones were explicitly specified. Fall back to legacy behavior and
2021 * just return success.
2023 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
2024 (nfsvers <= 3 && (!options || (options->version >= 1 &&
2025 options->version <= 6))))
2028 data = kzalloc(sizeof(*data), GFP_KERNEL);
2032 /* fill out struct with values from existing mount */
2033 data->flags = nfss->flags;
2034 data->rsize = nfss->rsize;
2035 data->wsize = nfss->wsize;
2036 data->retrans = nfss->client->cl_timeout->to_retries;
2037 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
2038 data->acregmin = nfss->acregmin / HZ;
2039 data->acregmax = nfss->acregmax / HZ;
2040 data->acdirmin = nfss->acdirmin / HZ;
2041 data->acdirmax = nfss->acdirmax / HZ;
2042 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
2043 data->nfs_server.port = nfss->port;
2044 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
2045 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
2046 data->nfs_server.addrlen);
2048 /* overwrite those values with any that were specified */
2049 error = nfs_parse_mount_options((char *)options, data);
2054 * noac is a special case. It implies -o sync, but that's not
2055 * necessarily reflected in the mtab options. do_remount_sb
2056 * will clear MS_SYNCHRONOUS if -o sync wasn't specified in the
2057 * remount options, so we have to explicitly reset it.
2059 if (data->flags & NFS_MOUNT_NOAC)
2060 *flags |= MS_SYNCHRONOUS;
2062 /* compare new mount options with old ones */
2063 error = nfs_compare_remount_data(nfss, data);
2070 * Initialise the common bits of the superblock
2072 static inline void nfs_initialise_sb(struct super_block *sb)
2074 struct nfs_server *server = NFS_SB(sb);
2076 sb->s_magic = NFS_SUPER_MAGIC;
2078 /* We probably want something more informative here */
2079 snprintf(sb->s_id, sizeof(sb->s_id),
2080 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
2082 if (sb->s_blocksize == 0)
2083 sb->s_blocksize = nfs_block_bits(server->wsize,
2084 &sb->s_blocksize_bits);
2086 sb->s_bdi = &server->backing_dev_info;
2088 nfs_super_set_maxbytes(sb, server->maxfilesize);
2092 * Finish setting up an NFS2/3 superblock
2094 static void nfs_fill_super(struct super_block *sb,
2095 struct nfs_parsed_mount_data *data)
2097 struct nfs_server *server = NFS_SB(sb);
2099 sb->s_blocksize_bits = 0;
2100 sb->s_blocksize = 0;
2102 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
2104 if (server->nfs_client->rpc_ops->version == 3) {
2105 /* The VFS shouldn't apply the umask to mode bits. We will do
2106 * so ourselves when necessary.
2108 sb->s_flags |= MS_POSIXACL;
2109 sb->s_time_gran = 1;
2112 sb->s_op = &nfs_sops;
2113 nfs_initialise_sb(sb);
2117 * Finish setting up a cloned NFS2/3 superblock
2119 static void nfs_clone_super(struct super_block *sb,
2120 const struct super_block *old_sb)
2122 struct nfs_server *server = NFS_SB(sb);
2124 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2125 sb->s_blocksize = old_sb->s_blocksize;
2126 sb->s_maxbytes = old_sb->s_maxbytes;
2128 if (server->nfs_client->rpc_ops->version == 3) {
2129 /* The VFS shouldn't apply the umask to mode bits. We will do
2130 * so ourselves when necessary.
2132 sb->s_flags |= MS_POSIXACL;
2133 sb->s_time_gran = 1;
2136 sb->s_op = old_sb->s_op;
2137 nfs_initialise_sb(sb);
2140 static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
2142 const struct nfs_server *a = s->s_fs_info;
2143 const struct rpc_clnt *clnt_a = a->client;
2144 const struct rpc_clnt *clnt_b = b->client;
2146 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
2148 if (a->nfs_client != b->nfs_client)
2150 if (a->flags != b->flags)
2152 if (a->wsize != b->wsize)
2154 if (a->rsize != b->rsize)
2156 if (a->acregmin != b->acregmin)
2158 if (a->acregmax != b->acregmax)
2160 if (a->acdirmin != b->acdirmin)
2162 if (a->acdirmax != b->acdirmax)
2164 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
2171 struct nfs_sb_mountdata {
2172 struct nfs_server *server;
2176 static int nfs_set_super(struct super_block *s, void *data)
2178 struct nfs_sb_mountdata *sb_mntdata = data;
2179 struct nfs_server *server = sb_mntdata->server;
2182 s->s_flags = sb_mntdata->mntflags;
2183 s->s_fs_info = server;
2184 s->s_d_op = server->nfs_client->rpc_ops->dentry_ops;
2185 ret = set_anon_super(s, server);
2187 server->s_dev = s->s_dev;
2191 static int nfs_compare_super_address(struct nfs_server *server1,
2192 struct nfs_server *server2)
2194 struct sockaddr *sap1, *sap2;
2196 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
2197 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
2199 if (sap1->sa_family != sap2->sa_family)
2202 switch (sap1->sa_family) {
2204 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
2205 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
2206 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
2208 if (sin1->sin_port != sin2->sin_port)
2213 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
2214 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
2215 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
2217 if (sin1->sin6_port != sin2->sin6_port)
2228 static int nfs_compare_super(struct super_block *sb, void *data)
2230 struct nfs_sb_mountdata *sb_mntdata = data;
2231 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2232 int mntflags = sb_mntdata->mntflags;
2234 if (!nfs_compare_super_address(old, server))
2236 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2237 if (old->flags & NFS_MOUNT_UNSHARED)
2239 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2241 return nfs_compare_mount_options(sb, server, mntflags);
2244 static int nfs_bdi_register(struct nfs_server *server)
2246 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
2249 static struct dentry *nfs_fs_mount(struct file_system_type *fs_type,
2250 int flags, const char *dev_name, void *raw_data)
2252 struct nfs_server *server = NULL;
2253 struct super_block *s;
2254 struct nfs_parsed_mount_data *data;
2255 struct nfs_fh *mntfh;
2256 struct dentry *mntroot = ERR_PTR(-ENOMEM);
2257 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2258 struct nfs_sb_mountdata sb_mntdata = {
2263 data = nfs_alloc_parsed_mount_data(NFS_DEFAULT_VERSION);
2264 mntfh = nfs_alloc_fhandle();
2265 if (data == NULL || mntfh == NULL)
2268 /* Validate the mount data */
2269 error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
2271 mntroot = ERR_PTR(error);
2275 #ifdef CONFIG_NFS_V4
2276 if (data->version == 4) {
2277 mntroot = nfs4_try_mount(flags, dev_name, data);
2280 #endif /* CONFIG_NFS_V4 */
2282 /* Get a volume representation */
2283 server = nfs_create_server(data, mntfh);
2284 if (IS_ERR(server)) {
2285 mntroot = ERR_CAST(server);
2288 sb_mntdata.server = server;
2290 if (server->flags & NFS_MOUNT_UNSHARED)
2291 compare_super = NULL;
2293 /* -o noac implies -o sync */
2294 if (server->flags & NFS_MOUNT_NOAC)
2295 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2297 /* Get a superblock - note that we may end up sharing one that already exists */
2298 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
2300 mntroot = ERR_CAST(s);
2304 if (s->s_fs_info != server) {
2305 nfs_free_server(server);
2308 error = nfs_bdi_register(server);
2310 mntroot = ERR_PTR(error);
2311 goto error_splat_bdi;
2316 /* initial superblock/root creation */
2317 nfs_fill_super(s, data);
2318 nfs_fscache_get_super_cookie(s, data->fscache_uniq, NULL);
2321 mntroot = nfs_get_root(s, mntfh, dev_name);
2322 if (IS_ERR(mntroot))
2323 goto error_splat_super;
2325 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
2327 goto error_splat_root;
2329 s->s_flags |= MS_ACTIVE;
2332 nfs_free_parsed_mount_data(data);
2333 nfs_free_fhandle(mntfh);
2337 nfs_free_server(server);
2342 mntroot = ERR_PTR(error);
2344 if (server && !s->s_root)
2345 bdi_unregister(&server->backing_dev_info);
2347 deactivate_locked_super(s);
2352 * Ensure that we unregister the bdi before kill_anon_super
2353 * releases the device name
2355 static void nfs_put_super(struct super_block *s)
2357 struct nfs_server *server = NFS_SB(s);
2359 bdi_unregister(&server->backing_dev_info);
2363 * Destroy an NFS2/3 superblock
2365 static void nfs_kill_super(struct super_block *s)
2367 struct nfs_server *server = NFS_SB(s);
2370 nfs_fscache_release_super_cookie(s);
2371 nfs_free_server(server);
2375 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2377 static struct dentry *
2378 nfs_xdev_mount(struct file_system_type *fs_type, int flags,
2379 const char *dev_name, void *raw_data)
2381 struct nfs_clone_mount *data = raw_data;
2382 struct super_block *s;
2383 struct nfs_server *server;
2384 struct dentry *mntroot;
2385 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2386 struct nfs_sb_mountdata sb_mntdata = {
2391 dprintk("--> nfs_xdev_mount()\n");
2393 /* create a new volume representation */
2394 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2395 if (IS_ERR(server)) {
2396 error = PTR_ERR(server);
2397 goto out_err_noserver;
2399 sb_mntdata.server = server;
2401 if (server->flags & NFS_MOUNT_UNSHARED)
2402 compare_super = NULL;
2404 /* -o noac implies -o sync */
2405 if (server->flags & NFS_MOUNT_NOAC)
2406 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2408 /* Get a superblock - note that we may end up sharing one that already exists */
2409 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2415 if (s->s_fs_info != server) {
2416 nfs_free_server(server);
2419 error = nfs_bdi_register(server);
2421 goto error_splat_bdi;
2425 /* initial superblock/root creation */
2426 nfs_clone_super(s, data->sb);
2427 nfs_fscache_get_super_cookie(s, NULL, data);
2430 mntroot = nfs_get_root(s, data->fh, dev_name);
2431 if (IS_ERR(mntroot)) {
2432 error = PTR_ERR(mntroot);
2433 goto error_splat_super;
2435 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2438 goto error_splat_super;
2441 s->s_flags |= MS_ACTIVE;
2443 /* clone any lsm security options from the parent to the new sb */
2444 security_sb_clone_mnt_opts(data->sb, s);
2446 dprintk("<-- nfs_xdev_mount() = 0\n");
2450 nfs_free_server(server);
2452 dprintk("<-- nfs_xdev_mount() = %d [error]\n", error);
2453 return ERR_PTR(error);
2456 if (server && !s->s_root)
2457 bdi_unregister(&server->backing_dev_info);
2459 deactivate_locked_super(s);
2460 dprintk("<-- nfs_xdev_mount() = %d [splat]\n", error);
2461 return ERR_PTR(error);
2464 #ifdef CONFIG_NFS_V4
2467 * Finish setting up a cloned NFS4 superblock
2469 static void nfs4_clone_super(struct super_block *sb,
2470 const struct super_block *old_sb)
2472 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2473 sb->s_blocksize = old_sb->s_blocksize;
2474 sb->s_maxbytes = old_sb->s_maxbytes;
2475 sb->s_time_gran = 1;
2476 sb->s_op = old_sb->s_op;
2478 * The VFS shouldn't apply the umask to mode bits. We will do
2479 * so ourselves when necessary.
2481 sb->s_flags |= MS_POSIXACL;
2482 sb->s_xattr = old_sb->s_xattr;
2483 nfs_initialise_sb(sb);
2487 * Set up an NFS4 superblock
2489 static void nfs4_fill_super(struct super_block *sb)
2491 sb->s_time_gran = 1;
2492 sb->s_op = &nfs4_sops;
2494 * The VFS shouldn't apply the umask to mode bits. We will do
2495 * so ourselves when necessary.
2497 sb->s_flags |= MS_POSIXACL;
2498 sb->s_xattr = nfs4_xattr_handlers;
2499 nfs_initialise_sb(sb);
2502 static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2504 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3|
2505 NFS_MOUNT_LOCAL_FLOCK|NFS_MOUNT_LOCAL_FCNTL);
2508 static int nfs4_validate_text_mount_data(void *options,
2509 struct nfs_parsed_mount_data *args,
2510 const char *dev_name)
2512 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2514 nfs_set_port(sap, &args->nfs_server.port, NFS_PORT);
2516 nfs_validate_transport_protocol(args);
2518 nfs4_validate_mount_flags(args);
2520 if (args->version != 4) {
2522 "NFS4: Illegal mount version\n");
2526 if (args->auth_flavor_len > 1) {
2528 "NFS4: Too many RPC auth flavours specified\n");
2532 if (args->client_address == NULL) {
2534 "NFS4: mount program didn't pass callback address\n");
2538 return nfs_parse_devname(dev_name,
2539 &args->nfs_server.hostname,
2541 &args->nfs_server.export_path,
2546 * Validate NFSv4 mount options
2548 static int nfs4_validate_mount_data(void *options,
2549 struct nfs_parsed_mount_data *args,
2550 const char *dev_name)
2552 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2553 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
2559 switch (data->version) {
2561 if (data->host_addrlen > sizeof(args->nfs_server.address))
2562 goto out_no_address;
2563 if (data->host_addrlen == 0)
2564 goto out_no_address;
2565 args->nfs_server.addrlen = data->host_addrlen;
2566 if (copy_from_user(sap, data->host_addr, data->host_addrlen))
2568 if (!nfs_verify_server_address(sap))
2569 goto out_no_address;
2571 if (data->auth_flavourlen) {
2572 if (data->auth_flavourlen > 1)
2573 goto out_inval_auth;
2574 if (copy_from_user(&args->auth_flavors[0],
2575 data->auth_flavours,
2576 sizeof(args->auth_flavors[0])))
2580 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2583 args->nfs_server.hostname = c;
2585 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2588 args->nfs_server.export_path = c;
2589 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
2591 c = strndup_user(data->client_addr.data, 16);
2594 args->client_address = c;
2597 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2601 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2602 args->rsize = data->rsize;
2603 args->wsize = data->wsize;
2604 args->timeo = data->timeo;
2605 args->retrans = data->retrans;
2606 args->acregmin = data->acregmin;
2607 args->acregmax = data->acregmax;
2608 args->acdirmin = data->acdirmin;
2609 args->acdirmax = data->acdirmax;
2610 args->nfs_server.protocol = data->proto;
2611 nfs_validate_transport_protocol(args);
2615 if (nfs_parse_mount_options((char *)options, args) == 0)
2618 if (!nfs_verify_server_address(sap))
2621 return nfs4_validate_text_mount_data(options, args, dev_name);
2627 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2631 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2632 data->auth_flavourlen);
2636 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2641 * Get the superblock for the NFS4 root partition
2643 static struct dentry *
2644 nfs4_remote_mount(struct file_system_type *fs_type, int flags,
2645 const char *dev_name, void *raw_data)
2647 struct nfs_parsed_mount_data *data = raw_data;
2648 struct super_block *s;
2649 struct nfs_server *server;
2650 struct nfs_fh *mntfh;
2651 struct dentry *mntroot;
2652 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2653 struct nfs_sb_mountdata sb_mntdata = {
2656 int error = -ENOMEM;
2658 mntfh = nfs_alloc_fhandle();
2659 if (data == NULL || mntfh == NULL)
2662 /* Get a volume representation */
2663 server = nfs4_create_server(data, mntfh);
2664 if (IS_ERR(server)) {
2665 error = PTR_ERR(server);
2668 sb_mntdata.server = server;
2670 if (server->flags & NFS4_MOUNT_UNSHARED)
2671 compare_super = NULL;
2673 /* -o noac implies -o sync */
2674 if (server->flags & NFS_MOUNT_NOAC)
2675 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2677 /* Get a superblock - note that we may end up sharing one that already exists */
2678 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2684 if (s->s_fs_info != server) {
2685 nfs_free_server(server);
2688 error = nfs_bdi_register(server);
2690 goto error_splat_bdi;
2694 /* initial superblock/root creation */
2696 nfs_fscache_get_super_cookie(s, data->fscache_uniq, NULL);
2699 mntroot = nfs4_get_root(s, mntfh, dev_name);
2700 if (IS_ERR(mntroot)) {
2701 error = PTR_ERR(mntroot);
2702 goto error_splat_super;
2705 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
2707 goto error_splat_root;
2709 s->s_flags |= MS_ACTIVE;
2711 nfs_free_fhandle(mntfh);
2715 nfs_free_fhandle(mntfh);
2716 return ERR_PTR(error);
2719 nfs_free_server(server);
2725 if (server && !s->s_root)
2726 bdi_unregister(&server->backing_dev_info);
2728 deactivate_locked_super(s);
2732 static struct vfsmount *nfs_do_root_mount(struct file_system_type *fs_type,
2733 int flags, void *data, const char *hostname)
2735 struct vfsmount *root_mnt;
2739 len = strlen(hostname) + 3;
2740 root_devname = kmalloc(len, GFP_KERNEL);
2741 if (root_devname == NULL)
2742 return ERR_PTR(-ENOMEM);
2743 snprintf(root_devname, len, "%s:/", hostname);
2744 root_mnt = vfs_kern_mount(fs_type, flags, root_devname, data);
2745 kfree(root_devname);
2749 struct nfs_referral_count {
2750 struct list_head list;
2751 const struct task_struct *task;
2752 unsigned int referral_count;
2755 static LIST_HEAD(nfs_referral_count_list);
2756 static DEFINE_SPINLOCK(nfs_referral_count_list_lock);
2758 static struct nfs_referral_count *nfs_find_referral_count(void)
2760 struct nfs_referral_count *p;
2762 list_for_each_entry(p, &nfs_referral_count_list, list) {
2763 if (p->task == current)
2769 #define NFS_MAX_NESTED_REFERRALS 2
2771 static int nfs_referral_loop_protect(void)
2773 struct nfs_referral_count *p, *new;
2776 new = kmalloc(sizeof(*new), GFP_KERNEL);
2779 new->task = current;
2780 new->referral_count = 1;
2783 spin_lock(&nfs_referral_count_list_lock);
2784 p = nfs_find_referral_count();
2786 if (p->referral_count >= NFS_MAX_NESTED_REFERRALS)
2789 p->referral_count++;
2791 list_add(&new->list, &nfs_referral_count_list);
2794 spin_unlock(&nfs_referral_count_list_lock);
2800 static void nfs_referral_loop_unprotect(void)
2802 struct nfs_referral_count *p;
2804 spin_lock(&nfs_referral_count_list_lock);
2805 p = nfs_find_referral_count();
2806 p->referral_count--;
2807 if (p->referral_count == 0)
2811 spin_unlock(&nfs_referral_count_list_lock);
2815 static struct dentry *nfs_follow_remote_path(struct vfsmount *root_mnt,
2816 const char *export_path)
2818 struct dentry *dentry;
2821 if (IS_ERR(root_mnt))
2822 return ERR_CAST(root_mnt);
2824 err = nfs_referral_loop_protect();
2827 return ERR_PTR(err);
2830 dentry = mount_subtree(root_mnt, export_path);
2831 nfs_referral_loop_unprotect();
2836 static struct dentry *nfs4_try_mount(int flags, const char *dev_name,
2837 struct nfs_parsed_mount_data *data)
2840 struct vfsmount *root_mnt;
2843 dfprintk(MOUNT, "--> nfs4_try_mount()\n");
2845 export_path = data->nfs_server.export_path;
2846 data->nfs_server.export_path = "/";
2847 root_mnt = nfs_do_root_mount(&nfs4_remote_fs_type, flags, data,
2848 data->nfs_server.hostname);
2849 data->nfs_server.export_path = export_path;
2851 res = nfs_follow_remote_path(root_mnt, export_path);
2853 dfprintk(MOUNT, "<-- nfs4_try_mount() = %ld%s\n",
2854 IS_ERR(res) ? PTR_ERR(res) : 0,
2855 IS_ERR(res) ? " [error]" : "");
2860 * Get the superblock for an NFS4 mountpoint
2862 static struct dentry *nfs4_mount(struct file_system_type *fs_type,
2863 int flags, const char *dev_name, void *raw_data)
2865 struct nfs_parsed_mount_data *data;
2866 int error = -ENOMEM;
2867 struct dentry *res = ERR_PTR(-ENOMEM);
2869 data = nfs_alloc_parsed_mount_data(4);
2873 /* Validate the mount data */
2874 error = nfs4_validate_mount_data(raw_data, data, dev_name);
2876 res = ERR_PTR(error);
2880 res = nfs4_try_mount(flags, dev_name, data);
2882 error = PTR_ERR(res);
2885 nfs_free_parsed_mount_data(data);
2886 dprintk("<-- nfs4_mount() = %d%s\n", error,
2887 error != 0 ? " [error]" : "");
2891 static void nfs4_kill_super(struct super_block *sb)
2893 struct nfs_server *server = NFS_SB(sb);
2895 dprintk("--> %s\n", __func__);
2896 nfs_super_return_all_delegations(sb);
2897 kill_anon_super(sb);
2898 nfs_fscache_release_super_cookie(sb);
2899 nfs_free_server(server);
2900 dprintk("<-- %s\n", __func__);
2904 * Clone an NFS4 server record on xdev traversal (FSID-change)
2906 static struct dentry *
2907 nfs4_xdev_mount(struct file_system_type *fs_type, int flags,
2908 const char *dev_name, void *raw_data)
2910 struct nfs_clone_mount *data = raw_data;
2911 struct super_block *s;
2912 struct nfs_server *server;
2913 struct dentry *mntroot;
2914 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2915 struct nfs_sb_mountdata sb_mntdata = {
2920 dprintk("--> nfs4_xdev_mount()\n");
2922 /* create a new volume representation */
2923 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2924 if (IS_ERR(server)) {
2925 error = PTR_ERR(server);
2926 goto out_err_noserver;
2928 sb_mntdata.server = server;
2930 if (server->flags & NFS4_MOUNT_UNSHARED)
2931 compare_super = NULL;
2933 /* -o noac implies -o sync */
2934 if (server->flags & NFS_MOUNT_NOAC)
2935 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2937 /* Get a superblock - note that we may end up sharing one that already exists */
2938 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2944 if (s->s_fs_info != server) {
2945 nfs_free_server(server);
2948 error = nfs_bdi_register(server);
2950 goto error_splat_bdi;
2954 /* initial superblock/root creation */
2955 nfs4_clone_super(s, data->sb);
2956 nfs_fscache_get_super_cookie(s, NULL, data);
2959 mntroot = nfs4_get_root(s, data->fh, dev_name);
2960 if (IS_ERR(mntroot)) {
2961 error = PTR_ERR(mntroot);
2962 goto error_splat_super;
2964 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2967 goto error_splat_super;
2970 s->s_flags |= MS_ACTIVE;
2972 security_sb_clone_mnt_opts(data->sb, s);
2974 dprintk("<-- nfs4_xdev_mount() = 0\n");
2978 nfs_free_server(server);
2980 dprintk("<-- nfs4_xdev_mount() = %d [error]\n", error);
2981 return ERR_PTR(error);
2984 if (server && !s->s_root)
2985 bdi_unregister(&server->backing_dev_info);
2987 deactivate_locked_super(s);
2988 dprintk("<-- nfs4_xdev_mount() = %d [splat]\n", error);
2989 return ERR_PTR(error);
2992 static struct dentry *
2993 nfs4_remote_referral_mount(struct file_system_type *fs_type, int flags,
2994 const char *dev_name, void *raw_data)
2996 struct nfs_clone_mount *data = raw_data;
2997 struct super_block *s;
2998 struct nfs_server *server;
2999 struct dentry *mntroot;
3000 struct nfs_fh *mntfh;
3001 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
3002 struct nfs_sb_mountdata sb_mntdata = {
3005 int error = -ENOMEM;
3007 dprintk("--> nfs4_referral_get_sb()\n");
3009 mntfh = nfs_alloc_fhandle();
3013 /* create a new volume representation */
3014 server = nfs4_create_referral_server(data, mntfh);
3015 if (IS_ERR(server)) {
3016 error = PTR_ERR(server);
3017 goto out_err_noserver;
3019 sb_mntdata.server = server;
3021 if (server->flags & NFS4_MOUNT_UNSHARED)
3022 compare_super = NULL;
3024 /* -o noac implies -o sync */
3025 if (server->flags & NFS_MOUNT_NOAC)
3026 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
3028 /* Get a superblock - note that we may end up sharing one that already exists */
3029 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
3035 if (s->s_fs_info != server) {
3036 nfs_free_server(server);
3039 error = nfs_bdi_register(server);
3041 goto error_splat_bdi;
3045 /* initial superblock/root creation */
3047 nfs_fscache_get_super_cookie(s, NULL, data);
3050 mntroot = nfs4_get_root(s, mntfh, dev_name);
3051 if (IS_ERR(mntroot)) {
3052 error = PTR_ERR(mntroot);
3053 goto error_splat_super;
3055 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
3058 goto error_splat_super;
3061 s->s_flags |= MS_ACTIVE;
3063 security_sb_clone_mnt_opts(data->sb, s);
3065 nfs_free_fhandle(mntfh);
3066 dprintk("<-- nfs4_referral_get_sb() = 0\n");
3070 nfs_free_server(server);
3072 nfs_free_fhandle(mntfh);
3074 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
3075 return ERR_PTR(error);
3078 if (server && !s->s_root)
3079 bdi_unregister(&server->backing_dev_info);
3081 deactivate_locked_super(s);
3082 nfs_free_fhandle(mntfh);
3083 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
3084 return ERR_PTR(error);
3088 * Create an NFS4 server record on referral traversal
3090 static struct dentry *nfs4_referral_mount(struct file_system_type *fs_type,
3091 int flags, const char *dev_name, void *raw_data)
3093 struct nfs_clone_mount *data = raw_data;
3095 struct vfsmount *root_mnt;
3098 dprintk("--> nfs4_referral_mount()\n");
3100 export_path = data->mnt_path;
3101 data->mnt_path = "/";
3103 root_mnt = nfs_do_root_mount(&nfs4_remote_referral_fs_type,
3104 flags, data, data->hostname);
3105 data->mnt_path = export_path;
3107 res = nfs_follow_remote_path(root_mnt, export_path);
3108 dprintk("<-- nfs4_referral_mount() = %ld%s\n",
3109 IS_ERR(res) ? PTR_ERR(res) : 0,
3110 IS_ERR(res) ? " [error]" : "");
3114 #endif /* CONFIG_NFS_V4 */