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/mnt_namespace.h>
45 #include <linux/namei.h>
46 #include <linux/nfs_idmap.h>
47 #include <linux/vfs.h>
48 #include <linux/inet.h>
49 #include <linux/in6.h>
50 #include <linux/slab.h>
52 #include <linux/netdevice.h>
53 #include <linux/nfs_xdr.h>
54 #include <linux/magic.h>
55 #include <linux/parser.h>
57 #include <asm/system.h>
58 #include <asm/uaccess.h>
62 #include "delegation.h"
67 #define NFSDBG_FACILITY NFSDBG_VFS
70 #define NFS_DEFAULT_VERSION 3
72 #define NFS_DEFAULT_VERSION 2
76 /* Mount options that take no arguments */
78 Opt_posix, Opt_noposix,
82 Opt_v2, Opt_v3, Opt_v4,
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,
103 /* 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" },
140 { Opt_rdma, "rdma" },
142 { Opt_noacl, "noacl" },
143 { Opt_rdirplus, "rdirplus" },
144 { Opt_nordirplus, "nordirplus" },
145 { Opt_sharecache, "sharecache" },
146 { Opt_nosharecache, "nosharecache" },
147 { Opt_resvport, "resvport" },
148 { Opt_noresvport, "noresvport" },
149 { Opt_fscache, "fsc" },
150 { Opt_nofscache, "nofsc" },
152 { Opt_port, "port=%s" },
153 { Opt_rsize, "rsize=%s" },
154 { Opt_wsize, "wsize=%s" },
155 { Opt_bsize, "bsize=%s" },
156 { Opt_timeo, "timeo=%s" },
157 { Opt_retrans, "retrans=%s" },
158 { Opt_acregmin, "acregmin=%s" },
159 { Opt_acregmax, "acregmax=%s" },
160 { Opt_acdirmin, "acdirmin=%s" },
161 { Opt_acdirmax, "acdirmax=%s" },
162 { Opt_actimeo, "actimeo=%s" },
163 { Opt_namelen, "namlen=%s" },
164 { Opt_mountport, "mountport=%s" },
165 { Opt_mountvers, "mountvers=%s" },
166 { Opt_nfsvers, "nfsvers=%s" },
167 { Opt_nfsvers, "vers=%s" },
168 { Opt_minorversion, "minorversion=%s" },
170 { Opt_sec, "sec=%s" },
171 { Opt_proto, "proto=%s" },
172 { Opt_mountproto, "mountproto=%s" },
173 { Opt_addr, "addr=%s" },
174 { Opt_clientaddr, "clientaddr=%s" },
175 { Opt_mounthost, "mounthost=%s" },
176 { Opt_mountaddr, "mountaddr=%s" },
178 { Opt_lookupcache, "lookupcache=%s" },
179 { Opt_fscache_uniq, "fsc=%s" },
180 { Opt_local_lock, "local_lock=%s" },
186 Opt_xprt_udp, Opt_xprt_udp6, Opt_xprt_tcp, Opt_xprt_tcp6, Opt_xprt_rdma,
191 static const match_table_t nfs_xprt_protocol_tokens = {
192 { Opt_xprt_udp, "udp" },
193 { Opt_xprt_udp6, "udp6" },
194 { Opt_xprt_tcp, "tcp" },
195 { Opt_xprt_tcp6, "tcp6" },
196 { Opt_xprt_rdma, "rdma" },
198 { Opt_xprt_err, NULL }
202 Opt_sec_none, Opt_sec_sys,
203 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
204 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
205 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
210 static const match_table_t nfs_secflavor_tokens = {
211 { Opt_sec_none, "none" },
212 { Opt_sec_none, "null" },
213 { Opt_sec_sys, "sys" },
215 { Opt_sec_krb5, "krb5" },
216 { Opt_sec_krb5i, "krb5i" },
217 { Opt_sec_krb5p, "krb5p" },
219 { Opt_sec_lkey, "lkey" },
220 { Opt_sec_lkeyi, "lkeyi" },
221 { Opt_sec_lkeyp, "lkeyp" },
223 { Opt_sec_spkm, "spkm3" },
224 { Opt_sec_spkmi, "spkm3i" },
225 { Opt_sec_spkmp, "spkm3p" },
227 { Opt_sec_err, NULL }
231 Opt_lookupcache_all, Opt_lookupcache_positive,
232 Opt_lookupcache_none,
237 static match_table_t nfs_lookupcache_tokens = {
238 { Opt_lookupcache_all, "all" },
239 { Opt_lookupcache_positive, "pos" },
240 { Opt_lookupcache_positive, "positive" },
241 { Opt_lookupcache_none, "none" },
243 { Opt_lookupcache_err, NULL }
247 Opt_local_lock_all, Opt_local_lock_flock, Opt_local_lock_posix,
253 static match_table_t nfs_local_lock_tokens = {
254 { Opt_local_lock_all, "all" },
255 { Opt_local_lock_flock, "flock" },
256 { Opt_local_lock_posix, "posix" },
257 { Opt_local_lock_none, "none" },
259 { Opt_local_lock_err, NULL }
263 static void nfs_umount_begin(struct super_block *);
264 static int nfs_statfs(struct dentry *, struct kstatfs *);
265 static int nfs_show_options(struct seq_file *, struct vfsmount *);
266 static int nfs_show_stats(struct seq_file *, struct vfsmount *);
267 static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
268 static struct dentry *nfs_xdev_mount(struct file_system_type *fs_type,
269 int flags, const char *dev_name, void *raw_data);
270 static void nfs_put_super(struct super_block *);
271 static void nfs_kill_super(struct super_block *);
272 static int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
274 static struct file_system_type nfs_fs_type = {
275 .owner = THIS_MODULE,
277 .get_sb = nfs_get_sb,
278 .kill_sb = nfs_kill_super,
279 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
282 struct file_system_type nfs_xdev_fs_type = {
283 .owner = THIS_MODULE,
285 .mount = nfs_xdev_mount,
286 .kill_sb = nfs_kill_super,
287 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
290 static const struct super_operations nfs_sops = {
291 .alloc_inode = nfs_alloc_inode,
292 .destroy_inode = nfs_destroy_inode,
293 .write_inode = nfs_write_inode,
294 .put_super = nfs_put_super,
295 .statfs = nfs_statfs,
296 .evict_inode = nfs_evict_inode,
297 .umount_begin = nfs_umount_begin,
298 .show_options = nfs_show_options,
299 .show_stats = nfs_show_stats,
300 .remount_fs = nfs_remount,
304 static int nfs4_validate_text_mount_data(void *options,
305 struct nfs_parsed_mount_data *args, const char *dev_name);
306 static int nfs4_try_mount(int flags, const char *dev_name,
307 struct nfs_parsed_mount_data *data, struct vfsmount *mnt);
308 static int nfs4_get_sb(struct file_system_type *fs_type,
309 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
310 static struct dentry *nfs4_remote_mount(struct file_system_type *fs_type,
311 int flags, const char *dev_name, void *raw_data);
312 static struct dentry *nfs4_xdev_mount(struct file_system_type *fs_type,
313 int flags, const char *dev_name, void *raw_data);
314 static int nfs4_referral_get_sb(struct file_system_type *fs_type,
315 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
316 static struct dentry *nfs4_remote_referral_mount(struct file_system_type *fs_type,
317 int flags, const char *dev_name, void *raw_data);
318 static void nfs4_kill_super(struct super_block *sb);
320 static struct file_system_type nfs4_fs_type = {
321 .owner = THIS_MODULE,
323 .get_sb = nfs4_get_sb,
324 .kill_sb = nfs4_kill_super,
325 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
328 static struct file_system_type nfs4_remote_fs_type = {
329 .owner = THIS_MODULE,
331 .mount = nfs4_remote_mount,
332 .kill_sb = nfs4_kill_super,
333 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
336 struct file_system_type nfs4_xdev_fs_type = {
337 .owner = THIS_MODULE,
339 .mount = nfs4_xdev_mount,
340 .kill_sb = nfs4_kill_super,
341 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
344 static struct file_system_type nfs4_remote_referral_fs_type = {
345 .owner = THIS_MODULE,
347 .mount = nfs4_remote_referral_mount,
348 .kill_sb = nfs4_kill_super,
349 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
352 struct file_system_type nfs4_referral_fs_type = {
353 .owner = THIS_MODULE,
355 .get_sb = nfs4_referral_get_sb,
356 .kill_sb = nfs4_kill_super,
357 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
360 static const struct super_operations nfs4_sops = {
361 .alloc_inode = nfs_alloc_inode,
362 .destroy_inode = nfs_destroy_inode,
363 .write_inode = nfs_write_inode,
364 .put_super = nfs_put_super,
365 .statfs = nfs_statfs,
366 .evict_inode = nfs4_evict_inode,
367 .umount_begin = nfs_umount_begin,
368 .show_options = nfs_show_options,
369 .show_stats = nfs_show_stats,
370 .remount_fs = nfs_remount,
374 static struct shrinker acl_shrinker = {
375 .shrink = nfs_access_cache_shrinker,
376 .seeks = DEFAULT_SEEKS,
380 * Register the NFS filesystems
382 int __init register_nfs_fs(void)
386 ret = register_filesystem(&nfs_fs_type);
390 ret = nfs_register_sysctl();
394 ret = register_filesystem(&nfs4_fs_type);
398 register_shrinker(&acl_shrinker);
403 nfs_unregister_sysctl();
406 unregister_filesystem(&nfs_fs_type);
412 * Unregister the NFS filesystems
414 void __exit unregister_nfs_fs(void)
416 unregister_shrinker(&acl_shrinker);
418 unregister_filesystem(&nfs4_fs_type);
420 nfs_unregister_sysctl();
421 unregister_filesystem(&nfs_fs_type);
424 void nfs_sb_active(struct super_block *sb)
426 struct nfs_server *server = NFS_SB(sb);
428 if (atomic_inc_return(&server->active) == 1)
429 atomic_inc(&sb->s_active);
432 void nfs_sb_deactive(struct super_block *sb)
434 struct nfs_server *server = NFS_SB(sb);
436 if (atomic_dec_and_test(&server->active))
437 deactivate_super(sb);
441 * Deliver file system statistics to userspace
443 static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
445 struct nfs_server *server = NFS_SB(dentry->d_sb);
446 unsigned char blockbits;
447 unsigned long blockres;
448 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
449 struct nfs_fsstat res;
452 res.fattr = nfs_alloc_fattr();
453 if (res.fattr == NULL)
456 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
457 if (unlikely(error == -ESTALE)) {
458 struct dentry *pd_dentry;
460 pd_dentry = dget_parent(dentry);
461 if (pd_dentry != NULL) {
462 nfs_zap_caches(pd_dentry->d_inode);
466 nfs_free_fattr(res.fattr);
470 buf->f_type = NFS_SUPER_MAGIC;
473 * Current versions of glibc do not correctly handle the
474 * case where f_frsize != f_bsize. Eventually we want to
475 * report the value of wtmult in this field.
477 buf->f_frsize = dentry->d_sb->s_blocksize;
480 * On most *nix systems, f_blocks, f_bfree, and f_bavail
481 * are reported in units of f_frsize. Linux hasn't had
482 * an f_frsize field in its statfs struct until recently,
483 * thus historically Linux's sys_statfs reports these
484 * fields in units of f_bsize.
486 buf->f_bsize = dentry->d_sb->s_blocksize;
487 blockbits = dentry->d_sb->s_blocksize_bits;
488 blockres = (1 << blockbits) - 1;
489 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
490 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
491 buf->f_bavail = (res.abytes + blockres) >> blockbits;
493 buf->f_files = res.tfiles;
494 buf->f_ffree = res.afiles;
496 buf->f_namelen = server->namelen;
501 dprintk("%s: statfs error = %d\n", __func__, -error);
506 * Map the security flavour number to a name
508 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
510 static const struct {
511 rpc_authflavor_t flavour;
514 { RPC_AUTH_NULL, "null" },
515 { RPC_AUTH_UNIX, "sys" },
516 { RPC_AUTH_GSS_KRB5, "krb5" },
517 { RPC_AUTH_GSS_KRB5I, "krb5i" },
518 { RPC_AUTH_GSS_KRB5P, "krb5p" },
519 { RPC_AUTH_GSS_LKEY, "lkey" },
520 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
521 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
522 { RPC_AUTH_GSS_SPKM, "spkm" },
523 { RPC_AUTH_GSS_SPKMI, "spkmi" },
524 { RPC_AUTH_GSS_SPKMP, "spkmp" },
525 { UINT_MAX, "unknown" }
529 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
530 if (sec_flavours[i].flavour == flavour)
533 return sec_flavours[i].str;
536 static void nfs_show_mountd_netid(struct seq_file *m, struct nfs_server *nfss,
539 struct sockaddr *sap = (struct sockaddr *) &nfss->mountd_address;
541 seq_printf(m, ",mountproto=");
542 switch (sap->sa_family) {
544 switch (nfss->mountd_protocol) {
546 seq_printf(m, RPCBIND_NETID_UDP);
549 seq_printf(m, RPCBIND_NETID_TCP);
553 seq_printf(m, "auto");
557 switch (nfss->mountd_protocol) {
559 seq_printf(m, RPCBIND_NETID_UDP6);
562 seq_printf(m, RPCBIND_NETID_TCP6);
566 seq_printf(m, "auto");
571 seq_printf(m, "auto");
575 static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
578 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
580 if (nfss->flags & NFS_MOUNT_LEGACY_INTERFACE)
583 switch (sap->sa_family) {
585 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
586 seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
590 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
591 seq_printf(m, ",mountaddr=%pI6c", &sin6->sin6_addr);
596 seq_printf(m, ",mountaddr=unspecified");
599 if (nfss->mountd_version || showdefaults)
600 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
601 if ((nfss->mountd_port &&
602 nfss->mountd_port != (unsigned short)NFS_UNSPEC_PORT) ||
604 seq_printf(m, ",mountport=%u", nfss->mountd_port);
606 nfs_show_mountd_netid(m, nfss, showdefaults);
610 static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
613 struct nfs_client *clp = nfss->nfs_client;
615 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
616 seq_printf(m, ",minorversion=%u", clp->cl_minorversion);
619 static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
626 * Describe the mount options in force on this server representation
628 static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
631 static const struct proc_nfs_info {
636 { NFS_MOUNT_SOFT, ",soft", ",hard" },
637 { NFS_MOUNT_POSIX, ",posix", "" },
638 { NFS_MOUNT_NOCTO, ",nocto", "" },
639 { NFS_MOUNT_NOAC, ",noac", "" },
640 { NFS_MOUNT_NONLM, ",nolock", "" },
641 { NFS_MOUNT_NOACL, ",noacl", "" },
642 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
643 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
644 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
647 const struct proc_nfs_info *nfs_infop;
648 struct nfs_client *clp = nfss->nfs_client;
649 u32 version = clp->rpc_ops->version;
650 int local_flock, local_fcntl;
652 seq_printf(m, ",vers=%u", version);
653 seq_printf(m, ",rsize=%u", nfss->rsize);
654 seq_printf(m, ",wsize=%u", nfss->wsize);
655 if (nfss->bsize != 0)
656 seq_printf(m, ",bsize=%u", nfss->bsize);
657 seq_printf(m, ",namlen=%u", nfss->namelen);
658 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
659 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
660 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
661 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
662 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
663 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
664 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
665 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
666 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
667 if (nfss->flags & nfs_infop->flag)
668 seq_puts(m, nfs_infop->str);
670 seq_puts(m, nfs_infop->nostr);
672 seq_printf(m, ",proto=%s",
673 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
675 if (nfss->port != NFS_PORT)
676 seq_printf(m, ",port=%u", nfss->port);
679 seq_printf(m, ",port=%u", nfss->port);
681 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
682 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
683 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
686 nfs_show_mountd_options(m, nfss, showdefaults);
688 nfs_show_nfsv4_options(m, nfss, showdefaults);
690 if (nfss->options & NFS_OPTION_FSCACHE)
691 seq_printf(m, ",fsc");
693 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONEG) {
694 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONE)
695 seq_printf(m, ",lookupcache=none");
697 seq_printf(m, ",lookupcache=pos");
700 local_flock = nfss->flags & NFS_MOUNT_LOCAL_FLOCK;
701 local_fcntl = nfss->flags & NFS_MOUNT_LOCAL_FCNTL;
703 if (!local_flock && !local_fcntl)
704 seq_printf(m, ",local_lock=none");
705 else if (local_flock && local_fcntl)
706 seq_printf(m, ",local_lock=all");
707 else if (local_flock)
708 seq_printf(m, ",local_lock=flock");
710 seq_printf(m, ",local_lock=posix");
714 * Describe the mount options on this VFS mountpoint
716 static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
718 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
720 nfs_show_mount_options(m, nfss, 0);
722 seq_printf(m, ",addr=%s",
723 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
730 * Present statistical information for this VFS mountpoint
732 static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
735 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
736 struct rpc_auth *auth = nfss->client->cl_auth;
737 struct nfs_iostats totals = { };
739 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
742 * Display all mount option settings
744 seq_printf(m, "\n\topts:\t");
745 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
746 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
747 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
748 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
749 nfs_show_mount_options(m, nfss, 1);
751 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
753 seq_printf(m, "\n\tcaps:\t");
754 seq_printf(m, "caps=0x%x", nfss->caps);
755 seq_printf(m, ",wtmult=%u", nfss->wtmult);
756 seq_printf(m, ",dtsize=%u", nfss->dtsize);
757 seq_printf(m, ",bsize=%u", nfss->bsize);
758 seq_printf(m, ",namlen=%u", nfss->namelen);
761 if (nfss->nfs_client->rpc_ops->version == 4) {
762 seq_printf(m, "\n\tnfsv4:\t");
763 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
764 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
765 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
770 * Display security flavor in effect for this mount
772 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
774 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
777 * Display superblock I/O counters
779 for_each_possible_cpu(cpu) {
780 struct nfs_iostats *stats;
783 stats = per_cpu_ptr(nfss->io_stats, cpu);
785 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
786 totals.events[i] += stats->events[i];
787 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
788 totals.bytes[i] += stats->bytes[i];
789 #ifdef CONFIG_NFS_FSCACHE
790 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
791 totals.fscache[i] += stats->fscache[i];
797 seq_printf(m, "\n\tevents:\t");
798 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
799 seq_printf(m, "%lu ", totals.events[i]);
800 seq_printf(m, "\n\tbytes:\t");
801 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
802 seq_printf(m, "%Lu ", totals.bytes[i]);
803 #ifdef CONFIG_NFS_FSCACHE
804 if (nfss->options & NFS_OPTION_FSCACHE) {
805 seq_printf(m, "\n\tfsc:\t");
806 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
807 seq_printf(m, "%Lu ", totals.bytes[i]);
812 rpc_print_iostats(m, nfss->client);
818 * Begin unmount by attempting to remove all automounted mountpoints we added
819 * in response to xdev traversals and referrals
821 static void nfs_umount_begin(struct super_block *sb)
823 struct nfs_server *server;
824 struct rpc_clnt *rpc;
827 /* -EIO all pending I/O */
828 rpc = server->client_acl;
830 rpc_killall_tasks(rpc);
831 rpc = server->client;
833 rpc_killall_tasks(rpc);
836 static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(unsigned int version)
838 struct nfs_parsed_mount_data *data;
840 data = kzalloc(sizeof(*data), GFP_KERNEL);
842 data->acregmin = NFS_DEF_ACREGMIN;
843 data->acregmax = NFS_DEF_ACREGMAX;
844 data->acdirmin = NFS_DEF_ACDIRMIN;
845 data->acdirmax = NFS_DEF_ACDIRMAX;
846 data->mount_server.port = NFS_UNSPEC_PORT;
847 data->nfs_server.port = NFS_UNSPEC_PORT;
848 data->nfs_server.protocol = XPRT_TRANSPORT_TCP;
849 data->auth_flavors[0] = RPC_AUTH_UNIX;
850 data->auth_flavor_len = 1;
851 data->version = version;
852 data->minorversion = 0;
858 * Sanity-check a server address provided by the mount command.
860 * Address family must be initialized, and address must not be
861 * the ANY address for that family.
863 static int nfs_verify_server_address(struct sockaddr *addr)
865 switch (addr->sa_family) {
867 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
868 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
871 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
872 return !ipv6_addr_any(sa);
876 dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
881 * Select between a default port value and a user-specified port value.
882 * If a zero value is set, then autobind will be used.
884 static void nfs_set_port(struct sockaddr *sap, int *port,
885 const unsigned short default_port)
887 if (*port == NFS_UNSPEC_PORT)
888 *port = default_port;
890 rpc_set_port(sap, *port);
894 * Sanity check the NFS transport protocol.
897 static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
899 switch (mnt->nfs_server.protocol) {
900 case XPRT_TRANSPORT_UDP:
901 case XPRT_TRANSPORT_TCP:
902 case XPRT_TRANSPORT_RDMA:
905 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
910 * For text based NFSv2/v3 mounts, the mount protocol transport default
911 * settings should depend upon the specified NFS transport.
913 static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
915 nfs_validate_transport_protocol(mnt);
917 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
918 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
920 switch (mnt->nfs_server.protocol) {
921 case XPRT_TRANSPORT_UDP:
922 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
924 case XPRT_TRANSPORT_TCP:
925 case XPRT_TRANSPORT_RDMA:
926 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
931 * Parse the value of the 'sec=' option.
933 static int nfs_parse_security_flavors(char *value,
934 struct nfs_parsed_mount_data *mnt)
936 substring_t args[MAX_OPT_ARGS];
938 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
940 switch (match_token(value, nfs_secflavor_tokens, args)) {
942 mnt->auth_flavors[0] = RPC_AUTH_NULL;
945 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
948 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
951 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
954 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
957 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
960 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
963 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
966 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
969 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
972 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
978 mnt->auth_flavor_len = 1;
983 * Error-check and convert a string of mount options from user space into
984 * a data structure. The whole mount string is processed; bad options are
985 * skipped as they are encountered. If there were no errors, return 1;
986 * otherwise return 0 (zero).
988 static int nfs_parse_mount_options(char *raw,
989 struct nfs_parsed_mount_data *mnt)
991 char *p, *string, *secdata;
992 int rc, sloppy = 0, invalid_option = 0;
993 unsigned short protofamily = AF_UNSPEC;
994 unsigned short mountfamily = AF_UNSPEC;
997 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
1000 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
1002 secdata = alloc_secdata();
1006 rc = security_sb_copy_data(raw, secdata);
1008 goto out_security_failure;
1010 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
1012 goto out_security_failure;
1014 free_secdata(secdata);
1016 while ((p = strsep(&raw, ",")) != NULL) {
1017 substring_t args[MAX_OPT_ARGS];
1018 unsigned long option;
1024 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
1026 token = match_token(p, nfs_mount_option_tokens, args);
1030 * boolean options: foo/nofoo
1033 mnt->flags |= NFS_MOUNT_SOFT;
1036 mnt->flags &= ~NFS_MOUNT_SOFT;
1039 mnt->flags |= NFS_MOUNT_POSIX;
1042 mnt->flags &= ~NFS_MOUNT_POSIX;
1045 mnt->flags &= ~NFS_MOUNT_NOCTO;
1048 mnt->flags |= NFS_MOUNT_NOCTO;
1051 mnt->flags &= ~NFS_MOUNT_NOAC;
1054 mnt->flags |= NFS_MOUNT_NOAC;
1057 mnt->flags &= ~NFS_MOUNT_NONLM;
1058 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1059 NFS_MOUNT_LOCAL_FCNTL);
1062 mnt->flags |= NFS_MOUNT_NONLM;
1063 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1064 NFS_MOUNT_LOCAL_FCNTL);
1067 mnt->flags &= ~NFS_MOUNT_VER3;
1071 mnt->flags |= NFS_MOUNT_VER3;
1075 mnt->flags &= ~NFS_MOUNT_VER3;
1079 mnt->flags &= ~NFS_MOUNT_TCP;
1080 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1083 mnt->flags |= NFS_MOUNT_TCP;
1084 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1087 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1088 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1089 xprt_load_transport(p);
1092 mnt->flags &= ~NFS_MOUNT_NOACL;
1095 mnt->flags |= NFS_MOUNT_NOACL;
1098 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1100 case Opt_nordirplus:
1101 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1103 case Opt_sharecache:
1104 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1106 case Opt_nosharecache:
1107 mnt->flags |= NFS_MOUNT_UNSHARED;
1110 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1112 case Opt_noresvport:
1113 mnt->flags |= NFS_MOUNT_NORESVPORT;
1116 mnt->options |= NFS_OPTION_FSCACHE;
1117 kfree(mnt->fscache_uniq);
1118 mnt->fscache_uniq = NULL;
1121 mnt->options &= ~NFS_OPTION_FSCACHE;
1122 kfree(mnt->fscache_uniq);
1123 mnt->fscache_uniq = NULL;
1127 * options that take numeric values
1130 string = match_strdup(args);
1133 rc = strict_strtoul(string, 10, &option);
1135 if (rc != 0 || option > USHRT_MAX)
1136 goto out_invalid_value;
1137 mnt->nfs_server.port = option;
1140 string = match_strdup(args);
1143 rc = strict_strtoul(string, 10, &option);
1146 goto out_invalid_value;
1147 mnt->rsize = option;
1150 string = match_strdup(args);
1153 rc = strict_strtoul(string, 10, &option);
1156 goto out_invalid_value;
1157 mnt->wsize = option;
1160 string = match_strdup(args);
1163 rc = strict_strtoul(string, 10, &option);
1166 goto out_invalid_value;
1167 mnt->bsize = option;
1170 string = match_strdup(args);
1173 rc = strict_strtoul(string, 10, &option);
1175 if (rc != 0 || option == 0)
1176 goto out_invalid_value;
1177 mnt->timeo = option;
1180 string = match_strdup(args);
1183 rc = strict_strtoul(string, 10, &option);
1185 if (rc != 0 || option == 0)
1186 goto out_invalid_value;
1187 mnt->retrans = option;
1190 string = match_strdup(args);
1193 rc = strict_strtoul(string, 10, &option);
1196 goto out_invalid_value;
1197 mnt->acregmin = option;
1200 string = match_strdup(args);
1203 rc = strict_strtoul(string, 10, &option);
1206 goto out_invalid_value;
1207 mnt->acregmax = option;
1210 string = match_strdup(args);
1213 rc = strict_strtoul(string, 10, &option);
1216 goto out_invalid_value;
1217 mnt->acdirmin = option;
1220 string = match_strdup(args);
1223 rc = strict_strtoul(string, 10, &option);
1226 goto out_invalid_value;
1227 mnt->acdirmax = option;
1230 string = match_strdup(args);
1233 rc = strict_strtoul(string, 10, &option);
1236 goto out_invalid_value;
1237 mnt->acregmin = mnt->acregmax =
1238 mnt->acdirmin = mnt->acdirmax = option;
1241 string = match_strdup(args);
1244 rc = strict_strtoul(string, 10, &option);
1247 goto out_invalid_value;
1248 mnt->namlen = option;
1251 string = match_strdup(args);
1254 rc = strict_strtoul(string, 10, &option);
1256 if (rc != 0 || option > USHRT_MAX)
1257 goto out_invalid_value;
1258 mnt->mount_server.port = option;
1261 string = match_strdup(args);
1264 rc = strict_strtoul(string, 10, &option);
1267 option < NFS_MNT_VERSION ||
1268 option > NFS_MNT3_VERSION)
1269 goto out_invalid_value;
1270 mnt->mount_server.version = option;
1273 string = match_strdup(args);
1276 rc = strict_strtoul(string, 10, &option);
1279 goto out_invalid_value;
1282 mnt->flags &= ~NFS_MOUNT_VER3;
1286 mnt->flags |= NFS_MOUNT_VER3;
1290 mnt->flags &= ~NFS_MOUNT_VER3;
1294 goto out_invalid_value;
1297 case Opt_minorversion:
1298 string = match_strdup(args);
1301 rc = strict_strtoul(string, 10, &option);
1304 goto out_invalid_value;
1305 if (option > NFS4_MAX_MINOR_VERSION)
1306 goto out_invalid_value;
1307 mnt->minorversion = option;
1311 * options that take text values
1314 string = match_strdup(args);
1317 rc = nfs_parse_security_flavors(string, mnt);
1320 dfprintk(MOUNT, "NFS: unrecognized "
1321 "security flavor\n");
1326 string = match_strdup(args);
1329 token = match_token(string,
1330 nfs_xprt_protocol_tokens, args);
1332 protofamily = AF_INET;
1335 protofamily = AF_INET6;
1337 mnt->flags &= ~NFS_MOUNT_TCP;
1338 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1342 protofamily = AF_INET6;
1344 mnt->flags |= NFS_MOUNT_TCP;
1345 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1349 /* vector side protocols to TCP */
1350 mnt->flags |= NFS_MOUNT_TCP;
1351 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1352 xprt_load_transport(string);
1356 dfprintk(MOUNT, "NFS: unrecognized "
1357 "transport protocol\n");
1362 case Opt_mountproto:
1363 string = match_strdup(args);
1366 token = match_token(string,
1367 nfs_xprt_protocol_tokens, args);
1370 mountfamily = AF_INET;
1373 mountfamily = AF_INET6;
1375 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
1378 mountfamily = AF_INET6;
1380 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
1382 case Opt_xprt_rdma: /* not used for side protocols */
1384 dfprintk(MOUNT, "NFS: unrecognized "
1385 "transport protocol\n");
1390 string = match_strdup(args);
1393 mnt->nfs_server.addrlen =
1394 rpc_pton(string, strlen(string),
1396 &mnt->nfs_server.address,
1397 sizeof(mnt->nfs_server.address));
1399 if (mnt->nfs_server.addrlen == 0)
1400 goto out_invalid_address;
1402 case Opt_clientaddr:
1403 string = match_strdup(args);
1406 kfree(mnt->client_address);
1407 mnt->client_address = string;
1410 string = match_strdup(args);
1413 kfree(mnt->mount_server.hostname);
1414 mnt->mount_server.hostname = string;
1417 string = match_strdup(args);
1420 mnt->mount_server.addrlen =
1421 rpc_pton(string, strlen(string),
1423 &mnt->mount_server.address,
1424 sizeof(mnt->mount_server.address));
1426 if (mnt->mount_server.addrlen == 0)
1427 goto out_invalid_address;
1429 case Opt_lookupcache:
1430 string = match_strdup(args);
1433 token = match_token(string,
1434 nfs_lookupcache_tokens, args);
1437 case Opt_lookupcache_all:
1438 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1440 case Opt_lookupcache_positive:
1441 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1442 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1444 case Opt_lookupcache_none:
1445 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1448 dfprintk(MOUNT, "NFS: invalid "
1449 "lookupcache argument\n");
1453 case Opt_fscache_uniq:
1454 string = match_strdup(args);
1457 kfree(mnt->fscache_uniq);
1458 mnt->fscache_uniq = string;
1459 mnt->options |= NFS_OPTION_FSCACHE;
1461 case Opt_local_lock:
1462 string = match_strdup(args);
1465 token = match_token(string, nfs_local_lock_tokens,
1469 case Opt_local_lock_all:
1470 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1471 NFS_MOUNT_LOCAL_FCNTL);
1473 case Opt_local_lock_flock:
1474 mnt->flags |= NFS_MOUNT_LOCAL_FLOCK;
1476 case Opt_local_lock_posix:
1477 mnt->flags |= NFS_MOUNT_LOCAL_FCNTL;
1479 case Opt_local_lock_none:
1480 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1481 NFS_MOUNT_LOCAL_FCNTL);
1484 dfprintk(MOUNT, "NFS: invalid "
1485 "local_lock argument\n");
1495 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1498 case Opt_deprecated:
1499 dfprintk(MOUNT, "NFS: ignoring mount option "
1505 dfprintk(MOUNT, "NFS: unrecognized mount option "
1510 if (!sloppy && invalid_option)
1514 * verify that any proto=/mountproto= options match the address
1515 * familiies in the addr=/mountaddr= options.
1517 if (protofamily != AF_UNSPEC &&
1518 protofamily != mnt->nfs_server.address.ss_family)
1519 goto out_proto_mismatch;
1521 if (mountfamily != AF_UNSPEC) {
1522 if (mnt->mount_server.addrlen) {
1523 if (mountfamily != mnt->mount_server.address.ss_family)
1524 goto out_mountproto_mismatch;
1526 if (mountfamily != mnt->nfs_server.address.ss_family)
1527 goto out_mountproto_mismatch;
1533 out_mountproto_mismatch:
1534 printk(KERN_INFO "NFS: mount server address does not match mountproto= "
1538 printk(KERN_INFO "NFS: server address does not match proto= option\n");
1540 out_invalid_address:
1541 printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
1544 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
1547 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1549 out_security_failure:
1550 free_secdata(secdata);
1551 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1556 * Match the requested auth flavors with the list returned by
1557 * the server. Returns zero and sets the mount's authentication
1558 * flavor on success; returns -EACCES if server does not support
1559 * the requested flavor.
1561 static int nfs_walk_authlist(struct nfs_parsed_mount_data *args,
1562 struct nfs_mount_request *request)
1564 unsigned int i, j, server_authlist_len = *(request->auth_flav_len);
1567 * Certain releases of Linux's mountd return an empty
1568 * flavor list. To prevent behavioral regression with
1569 * these servers (ie. rejecting mounts that used to
1570 * succeed), revert to pre-2.6.32 behavior (no checking)
1571 * if the returned flavor list is empty.
1573 if (server_authlist_len == 0)
1577 * We avoid sophisticated negotiating here, as there are
1578 * plenty of cases where we can get it wrong, providing
1579 * either too little or too much security.
1581 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1582 * flavor listed first. However, some servers list
1583 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1584 * preferred default, in args->auth_flavors[0] if user
1585 * didn't specify sec= mount option.
1587 for (i = 0; i < args->auth_flavor_len; i++)
1588 for (j = 0; j < server_authlist_len; j++)
1589 if (args->auth_flavors[i] == request->auth_flavs[j]) {
1590 dfprintk(MOUNT, "NFS: using auth flavor %d\n",
1591 request->auth_flavs[j]);
1592 args->auth_flavors[0] = request->auth_flavs[j];
1596 dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n");
1597 nfs_umount(request);
1602 * Use the remote server's MOUNT service to request the NFS file handle
1603 * corresponding to the provided path.
1605 static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1606 struct nfs_fh *root_fh)
1608 rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS];
1609 unsigned int server_authlist_len = ARRAY_SIZE(server_authlist);
1610 struct nfs_mount_request request = {
1611 .sap = (struct sockaddr *)
1612 &args->mount_server.address,
1613 .dirpath = args->nfs_server.export_path,
1614 .protocol = args->mount_server.protocol,
1616 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
1617 .auth_flav_len = &server_authlist_len,
1618 .auth_flavs = server_authlist,
1622 if (args->mount_server.version == 0) {
1623 switch (args->version) {
1625 args->mount_server.version = NFS_MNT3_VERSION;
1628 args->mount_server.version = NFS_MNT_VERSION;
1631 request.version = args->mount_server.version;
1633 if (args->mount_server.hostname)
1634 request.hostname = args->mount_server.hostname;
1636 request.hostname = args->nfs_server.hostname;
1639 * Construct the mount server's address.
1641 if (args->mount_server.address.ss_family == AF_UNSPEC) {
1642 memcpy(request.sap, &args->nfs_server.address,
1643 args->nfs_server.addrlen);
1644 args->mount_server.addrlen = args->nfs_server.addrlen;
1646 request.salen = args->mount_server.addrlen;
1647 nfs_set_port(request.sap, &args->mount_server.port, 0);
1650 * Now ask the mount server to map our export path
1653 status = nfs_mount(&request);
1655 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1656 request.hostname, status);
1661 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1663 if (args->mount_server.version != NFS_MNT3_VERSION)
1665 return nfs_walk_authlist(args, &request);
1668 static int nfs_parse_simple_hostname(const char *dev_name,
1669 char **hostname, size_t maxnamlen,
1670 char **export_path, size_t maxpathlen)
1673 char *colon, *comma;
1675 colon = strchr(dev_name, ':');
1677 goto out_bad_devname;
1679 len = colon - dev_name;
1680 if (len > maxnamlen)
1683 /* N.B. caller will free nfs_server.hostname in all cases */
1684 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
1688 /* kill possible hostname list: not supported */
1689 comma = strchr(*hostname, ',');
1690 if (comma != NULL) {
1691 if (comma == *hostname)
1692 goto out_bad_devname;
1697 len = strlen(colon);
1698 if (len > maxpathlen)
1700 *export_path = kstrndup(colon, len, GFP_KERNEL);
1704 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1708 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1712 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1716 dfprintk(MOUNT, "NFS: server hostname too long\n");
1717 return -ENAMETOOLONG;
1720 dfprintk(MOUNT, "NFS: export pathname too long\n");
1721 return -ENAMETOOLONG;
1725 * Hostname has square brackets around it because it contains one or
1726 * more colons. We look for the first closing square bracket, and a
1727 * colon must follow it.
1729 static int nfs_parse_protected_hostname(const char *dev_name,
1730 char **hostname, size_t maxnamlen,
1731 char **export_path, size_t maxpathlen)
1736 start = (char *)(dev_name + 1);
1738 end = strchr(start, ']');
1740 goto out_bad_devname;
1741 if (*(end + 1) != ':')
1742 goto out_bad_devname;
1745 if (len > maxnamlen)
1748 /* N.B. caller will free nfs_server.hostname in all cases */
1749 *hostname = kstrndup(start, len, GFP_KERNEL);
1750 if (*hostname == NULL)
1755 if (len > maxpathlen)
1757 *export_path = kstrndup(end, len, GFP_KERNEL);
1764 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1768 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1772 dfprintk(MOUNT, "NFS: server hostname too long\n");
1773 return -ENAMETOOLONG;
1776 dfprintk(MOUNT, "NFS: export pathname too long\n");
1777 return -ENAMETOOLONG;
1781 * Split "dev_name" into "hostname:export_path".
1783 * The leftmost colon demarks the split between the server's hostname
1784 * and the export path. If the hostname starts with a left square
1785 * bracket, then it may contain colons.
1787 * Note: caller frees hostname and export path, even on error.
1789 static int nfs_parse_devname(const char *dev_name,
1790 char **hostname, size_t maxnamlen,
1791 char **export_path, size_t maxpathlen)
1793 if (*dev_name == '[')
1794 return nfs_parse_protected_hostname(dev_name,
1795 hostname, maxnamlen,
1796 export_path, maxpathlen);
1798 return nfs_parse_simple_hostname(dev_name,
1799 hostname, maxnamlen,
1800 export_path, maxpathlen);
1804 * Validate the NFS2/NFS3 mount data
1805 * - fills in the mount root filehandle
1807 * For option strings, user space handles the following behaviors:
1809 * + DNS: mapping server host name to IP address ("addr=" option)
1811 * + failure mode: how to behave if a mount request can't be handled
1812 * immediately ("fg/bg" option)
1814 * + retry: how often to retry a mount request ("retry=" option)
1816 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1817 * mountproto=tcp after mountproto=udp, and so on
1819 static int nfs_validate_mount_data(void *options,
1820 struct nfs_parsed_mount_data *args,
1821 struct nfs_fh *mntfh,
1822 const char *dev_name)
1824 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
1825 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
1830 switch (data->version) {
1836 if (data->flags & NFS_MOUNT_VER3)
1838 data->root.size = NFS2_FHSIZE;
1839 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1841 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1844 memset(data->context, 0, sizeof(data->context));
1846 if (data->flags & NFS_MOUNT_VER3) {
1847 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1848 goto out_invalid_fh;
1849 mntfh->size = data->root.size;
1852 mntfh->size = NFS2_FHSIZE;
1857 memcpy(mntfh->data, data->root.data, mntfh->size);
1858 if (mntfh->size < sizeof(mntfh->data))
1859 memset(mntfh->data + mntfh->size, 0,
1860 sizeof(mntfh->data) - mntfh->size);
1863 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1866 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
1867 args->flags |= NFS_MOUNT_LEGACY_INTERFACE;
1868 args->rsize = data->rsize;
1869 args->wsize = data->wsize;
1870 args->timeo = data->timeo;
1871 args->retrans = data->retrans;
1872 args->acregmin = data->acregmin;
1873 args->acregmax = data->acregmax;
1874 args->acdirmin = data->acdirmin;
1875 args->acdirmax = data->acdirmax;
1877 memcpy(sap, &data->addr, sizeof(data->addr));
1878 args->nfs_server.addrlen = sizeof(data->addr);
1879 if (!nfs_verify_server_address(sap))
1880 goto out_no_address;
1882 if (!(data->flags & NFS_MOUNT_TCP))
1883 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1884 /* N.B. caller will free nfs_server.hostname in all cases */
1885 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1886 args->namlen = data->namlen;
1887 args->bsize = data->bsize;
1889 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1890 args->auth_flavors[0] = data->pseudoflavor;
1891 if (!args->nfs_server.hostname)
1894 if (!(data->flags & NFS_MOUNT_NONLM))
1895 args->flags &= ~(NFS_MOUNT_LOCAL_FLOCK|
1896 NFS_MOUNT_LOCAL_FCNTL);
1898 args->flags |= (NFS_MOUNT_LOCAL_FLOCK|
1899 NFS_MOUNT_LOCAL_FCNTL);
1901 * The legacy version 6 binary mount data from userspace has a
1902 * field used only to transport selinux information into the
1903 * the kernel. To continue to support that functionality we
1904 * have a touch of selinux knowledge here in the NFS code. The
1905 * userspace code converted context=blah to just blah so we are
1906 * converting back to the full string selinux understands.
1908 if (data->context[0]){
1909 #ifdef CONFIG_SECURITY_SELINUX
1911 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1914 strcpy(opts_str, "context=");
1915 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1916 strcat(opts_str, &data->context[0]);
1917 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1930 if (nfs_parse_mount_options((char *)options, args) == 0)
1933 if (!nfs_verify_server_address(sap))
1934 goto out_no_address;
1936 if (args->version == 4)
1937 #ifdef CONFIG_NFS_V4
1938 return nfs4_validate_text_mount_data(options,
1941 goto out_v4_not_compiled;
1944 nfs_set_port(sap, &args->nfs_server.port, 0);
1946 nfs_set_mount_transport_protocol(args);
1948 status = nfs_parse_devname(dev_name,
1949 &args->nfs_server.hostname,
1951 &args->nfs_server.export_path,
1954 status = nfs_try_mount(args, mntfh);
1956 kfree(args->nfs_server.export_path);
1957 args->nfs_server.export_path = NULL;
1966 #ifndef CONFIG_NFS_V3
1967 if (args->version == 3)
1968 goto out_v3_not_compiled;
1969 #endif /* !CONFIG_NFS_V3 */
1974 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1978 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1983 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1986 #ifndef CONFIG_NFS_V3
1987 out_v3_not_compiled:
1988 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1989 return -EPROTONOSUPPORT;
1990 #endif /* !CONFIG_NFS_V3 */
1992 #ifndef CONFIG_NFS_V4
1993 out_v4_not_compiled:
1994 dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n");
1995 return -EPROTONOSUPPORT;
1996 #endif /* !CONFIG_NFS_V4 */
1999 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
2003 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
2007 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
2012 nfs_compare_remount_data(struct nfs_server *nfss,
2013 struct nfs_parsed_mount_data *data)
2015 if (data->flags != nfss->flags ||
2016 data->rsize != nfss->rsize ||
2017 data->wsize != nfss->wsize ||
2018 data->retrans != nfss->client->cl_timeout->to_retries ||
2019 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
2020 data->acregmin != nfss->acregmin / HZ ||
2021 data->acregmax != nfss->acregmax / HZ ||
2022 data->acdirmin != nfss->acdirmin / HZ ||
2023 data->acdirmax != nfss->acdirmax / HZ ||
2024 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
2025 data->nfs_server.port != nfss->port ||
2026 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
2027 !rpc_cmp_addr((struct sockaddr *)&data->nfs_server.address,
2028 (struct sockaddr *)&nfss->nfs_client->cl_addr))
2035 nfs_remount(struct super_block *sb, int *flags, char *raw_data)
2038 struct nfs_server *nfss = sb->s_fs_info;
2039 struct nfs_parsed_mount_data *data;
2040 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
2041 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
2042 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
2045 * Userspace mount programs that send binary options generally send
2046 * them populated with default values. We have no way to know which
2047 * ones were explicitly specified. Fall back to legacy behavior and
2048 * just return success.
2050 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
2051 (nfsvers <= 3 && (!options || (options->version >= 1 &&
2052 options->version <= 6))))
2055 data = kzalloc(sizeof(*data), GFP_KERNEL);
2059 /* fill out struct with values from existing mount */
2060 data->flags = nfss->flags;
2061 data->rsize = nfss->rsize;
2062 data->wsize = nfss->wsize;
2063 data->retrans = nfss->client->cl_timeout->to_retries;
2064 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
2065 data->acregmin = nfss->acregmin / HZ;
2066 data->acregmax = nfss->acregmax / HZ;
2067 data->acdirmin = nfss->acdirmin / HZ;
2068 data->acdirmax = nfss->acdirmax / HZ;
2069 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
2070 data->nfs_server.port = nfss->port;
2071 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
2072 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
2073 data->nfs_server.addrlen);
2075 /* overwrite those values with any that were specified */
2076 error = nfs_parse_mount_options((char *)options, data);
2080 /* compare new mount options with old ones */
2081 error = nfs_compare_remount_data(nfss, data);
2088 * Initialise the common bits of the superblock
2090 static inline void nfs_initialise_sb(struct super_block *sb)
2092 struct nfs_server *server = NFS_SB(sb);
2094 sb->s_magic = NFS_SUPER_MAGIC;
2096 /* We probably want something more informative here */
2097 snprintf(sb->s_id, sizeof(sb->s_id),
2098 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
2100 if (sb->s_blocksize == 0)
2101 sb->s_blocksize = nfs_block_bits(server->wsize,
2102 &sb->s_blocksize_bits);
2104 if (server->flags & NFS_MOUNT_NOAC)
2105 sb->s_flags |= MS_SYNCHRONOUS;
2107 sb->s_bdi = &server->backing_dev_info;
2109 nfs_super_set_maxbytes(sb, server->maxfilesize);
2113 * Finish setting up an NFS2/3 superblock
2115 static void nfs_fill_super(struct super_block *sb,
2116 struct nfs_parsed_mount_data *data)
2118 struct nfs_server *server = NFS_SB(sb);
2120 sb->s_blocksize_bits = 0;
2121 sb->s_blocksize = 0;
2123 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
2125 if (server->nfs_client->rpc_ops->version == 3) {
2126 /* The VFS shouldn't apply the umask to mode bits. We will do
2127 * so ourselves when necessary.
2129 sb->s_flags |= MS_POSIXACL;
2130 sb->s_time_gran = 1;
2133 sb->s_op = &nfs_sops;
2134 nfs_initialise_sb(sb);
2138 * Finish setting up a cloned NFS2/3 superblock
2140 static void nfs_clone_super(struct super_block *sb,
2141 const struct super_block *old_sb)
2143 struct nfs_server *server = NFS_SB(sb);
2145 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2146 sb->s_blocksize = old_sb->s_blocksize;
2147 sb->s_maxbytes = old_sb->s_maxbytes;
2149 if (server->nfs_client->rpc_ops->version == 3) {
2150 /* The VFS shouldn't apply the umask to mode bits. We will do
2151 * so ourselves when necessary.
2153 sb->s_flags |= MS_POSIXACL;
2154 sb->s_time_gran = 1;
2157 sb->s_op = old_sb->s_op;
2158 nfs_initialise_sb(sb);
2161 static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
2163 const struct nfs_server *a = s->s_fs_info;
2164 const struct rpc_clnt *clnt_a = a->client;
2165 const struct rpc_clnt *clnt_b = b->client;
2167 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
2169 if (a->nfs_client != b->nfs_client)
2171 if (a->flags != b->flags)
2173 if (a->wsize != b->wsize)
2175 if (a->rsize != b->rsize)
2177 if (a->acregmin != b->acregmin)
2179 if (a->acregmax != b->acregmax)
2181 if (a->acdirmin != b->acdirmin)
2183 if (a->acdirmax != b->acdirmax)
2185 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
2192 struct nfs_sb_mountdata {
2193 struct nfs_server *server;
2197 static int nfs_set_super(struct super_block *s, void *data)
2199 struct nfs_sb_mountdata *sb_mntdata = data;
2200 struct nfs_server *server = sb_mntdata->server;
2203 s->s_flags = sb_mntdata->mntflags;
2204 s->s_fs_info = server;
2205 ret = set_anon_super(s, server);
2207 server->s_dev = s->s_dev;
2211 static int nfs_compare_super_address(struct nfs_server *server1,
2212 struct nfs_server *server2)
2214 struct sockaddr *sap1, *sap2;
2216 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
2217 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
2219 if (sap1->sa_family != sap2->sa_family)
2222 switch (sap1->sa_family) {
2224 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
2225 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
2226 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
2228 if (sin1->sin_port != sin2->sin_port)
2233 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
2234 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
2235 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
2237 if (sin1->sin6_port != sin2->sin6_port)
2248 static int nfs_compare_super(struct super_block *sb, void *data)
2250 struct nfs_sb_mountdata *sb_mntdata = data;
2251 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2252 int mntflags = sb_mntdata->mntflags;
2254 if (!nfs_compare_super_address(old, server))
2256 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2257 if (old->flags & NFS_MOUNT_UNSHARED)
2259 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2261 return nfs_compare_mount_options(sb, server, mntflags);
2264 static int nfs_bdi_register(struct nfs_server *server)
2266 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
2269 static int nfs_get_sb(struct file_system_type *fs_type,
2270 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2272 struct nfs_server *server = NULL;
2273 struct super_block *s;
2274 struct nfs_parsed_mount_data *data;
2275 struct nfs_fh *mntfh;
2276 struct dentry *mntroot;
2277 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2278 struct nfs_sb_mountdata sb_mntdata = {
2281 int error = -ENOMEM;
2283 data = nfs_alloc_parsed_mount_data(NFS_DEFAULT_VERSION);
2284 mntfh = nfs_alloc_fhandle();
2285 if (data == NULL || mntfh == NULL)
2288 security_init_mnt_opts(&data->lsm_opts);
2290 /* Validate the mount data */
2291 error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
2295 #ifdef CONFIG_NFS_V4
2296 if (data->version == 4) {
2297 error = nfs4_try_mount(flags, dev_name, data, mnt);
2298 kfree(data->client_address);
2299 kfree(data->nfs_server.export_path);
2302 #endif /* CONFIG_NFS_V4 */
2304 /* Get a volume representation */
2305 server = nfs_create_server(data, mntfh);
2306 if (IS_ERR(server)) {
2307 error = PTR_ERR(server);
2310 sb_mntdata.server = server;
2312 if (server->flags & NFS_MOUNT_UNSHARED)
2313 compare_super = NULL;
2315 /* Get a superblock - note that we may end up sharing one that already exists */
2316 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
2322 if (s->s_fs_info != server) {
2323 nfs_free_server(server);
2326 error = nfs_bdi_register(server);
2328 goto error_splat_bdi;
2332 /* initial superblock/root creation */
2333 nfs_fill_super(s, data);
2334 nfs_fscache_get_super_cookie(
2335 s, data ? data->fscache_uniq : NULL, NULL);
2338 mntroot = nfs_get_root(s, mntfh);
2339 if (IS_ERR(mntroot)) {
2340 error = PTR_ERR(mntroot);
2341 goto error_splat_super;
2344 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
2346 goto error_splat_root;
2348 s->s_flags |= MS_ACTIVE;
2350 mnt->mnt_root = mntroot;
2354 kfree(data->nfs_server.hostname);
2355 kfree(data->mount_server.hostname);
2356 kfree(data->fscache_uniq);
2357 security_free_mnt_opts(&data->lsm_opts);
2359 nfs_free_fhandle(mntfh);
2364 nfs_free_server(server);
2370 if (server && !s->s_root)
2371 bdi_unregister(&server->backing_dev_info);
2373 deactivate_locked_super(s);
2378 * Ensure that we unregister the bdi before kill_anon_super
2379 * releases the device name
2381 static void nfs_put_super(struct super_block *s)
2383 struct nfs_server *server = NFS_SB(s);
2385 bdi_unregister(&server->backing_dev_info);
2389 * Destroy an NFS2/3 superblock
2391 static void nfs_kill_super(struct super_block *s)
2393 struct nfs_server *server = NFS_SB(s);
2396 nfs_fscache_release_super_cookie(s);
2397 nfs_free_server(server);
2401 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2403 static struct dentry *
2404 nfs_xdev_mount(struct file_system_type *fs_type, int flags,
2405 const char *dev_name, void *raw_data)
2407 struct nfs_clone_mount *data = raw_data;
2408 struct super_block *s;
2409 struct nfs_server *server;
2410 struct dentry *mntroot;
2411 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2412 struct nfs_sb_mountdata sb_mntdata = {
2417 dprintk("--> nfs_xdev_mount()\n");
2419 /* create a new volume representation */
2420 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2421 if (IS_ERR(server)) {
2422 error = PTR_ERR(server);
2423 goto out_err_noserver;
2425 sb_mntdata.server = server;
2427 if (server->flags & NFS_MOUNT_UNSHARED)
2428 compare_super = NULL;
2430 /* Get a superblock - note that we may end up sharing one that already exists */
2431 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2437 if (s->s_fs_info != server) {
2438 nfs_free_server(server);
2441 error = nfs_bdi_register(server);
2443 goto error_splat_bdi;
2447 /* initial superblock/root creation */
2448 nfs_clone_super(s, data->sb);
2449 nfs_fscache_get_super_cookie(s, NULL, data);
2452 mntroot = nfs_get_root(s, data->fh);
2453 if (IS_ERR(mntroot)) {
2454 error = PTR_ERR(mntroot);
2455 goto error_splat_super;
2457 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2460 goto error_splat_super;
2463 s->s_flags |= MS_ACTIVE;
2465 /* clone any lsm security options from the parent to the new sb */
2466 security_sb_clone_mnt_opts(data->sb, s);
2468 dprintk("<-- nfs_xdev_mount() = 0\n");
2472 nfs_free_server(server);
2474 dprintk("<-- nfs_xdev_mount() = %d [error]\n", error);
2475 return ERR_PTR(error);
2478 if (server && !s->s_root)
2479 bdi_unregister(&server->backing_dev_info);
2481 deactivate_locked_super(s);
2482 dprintk("<-- nfs_xdev_mount() = %d [splat]\n", error);
2483 return ERR_PTR(error);
2486 #ifdef CONFIG_NFS_V4
2489 * Finish setting up a cloned NFS4 superblock
2491 static void nfs4_clone_super(struct super_block *sb,
2492 const struct super_block *old_sb)
2494 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2495 sb->s_blocksize = old_sb->s_blocksize;
2496 sb->s_maxbytes = old_sb->s_maxbytes;
2497 sb->s_time_gran = 1;
2498 sb->s_op = old_sb->s_op;
2500 * The VFS shouldn't apply the umask to mode bits. We will do
2501 * so ourselves when necessary.
2503 sb->s_flags |= MS_POSIXACL;
2504 sb->s_xattr = old_sb->s_xattr;
2505 nfs_initialise_sb(sb);
2509 * Set up an NFS4 superblock
2511 static void nfs4_fill_super(struct super_block *sb)
2513 sb->s_time_gran = 1;
2514 sb->s_op = &nfs4_sops;
2516 * The VFS shouldn't apply the umask to mode bits. We will do
2517 * so ourselves when necessary.
2519 sb->s_flags |= MS_POSIXACL;
2520 sb->s_xattr = nfs4_xattr_handlers;
2521 nfs_initialise_sb(sb);
2524 static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2526 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3|
2527 NFS_MOUNT_LOCAL_FLOCK|NFS_MOUNT_LOCAL_FCNTL);
2530 static int nfs4_validate_text_mount_data(void *options,
2531 struct nfs_parsed_mount_data *args,
2532 const char *dev_name)
2534 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2536 nfs_set_port(sap, &args->nfs_server.port, NFS_PORT);
2538 nfs_validate_transport_protocol(args);
2540 nfs4_validate_mount_flags(args);
2542 if (args->version != 4) {
2544 "NFS4: Illegal mount version\n");
2548 if (args->auth_flavor_len > 1) {
2550 "NFS4: Too many RPC auth flavours specified\n");
2554 if (args->client_address == NULL) {
2556 "NFS4: mount program didn't pass callback address\n");
2560 return nfs_parse_devname(dev_name,
2561 &args->nfs_server.hostname,
2563 &args->nfs_server.export_path,
2568 * Validate NFSv4 mount options
2570 static int nfs4_validate_mount_data(void *options,
2571 struct nfs_parsed_mount_data *args,
2572 const char *dev_name)
2574 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2575 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
2581 switch (data->version) {
2583 if (data->host_addrlen > sizeof(args->nfs_server.address))
2584 goto out_no_address;
2585 if (data->host_addrlen == 0)
2586 goto out_no_address;
2587 args->nfs_server.addrlen = data->host_addrlen;
2588 if (copy_from_user(sap, data->host_addr, data->host_addrlen))
2590 if (!nfs_verify_server_address(sap))
2591 goto out_no_address;
2593 if (data->auth_flavourlen) {
2594 if (data->auth_flavourlen > 1)
2595 goto out_inval_auth;
2596 if (copy_from_user(&args->auth_flavors[0],
2597 data->auth_flavours,
2598 sizeof(args->auth_flavors[0])))
2602 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2605 args->nfs_server.hostname = c;
2607 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2610 args->nfs_server.export_path = c;
2611 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
2613 c = strndup_user(data->client_addr.data, 16);
2616 args->client_address = c;
2619 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2623 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2624 args->rsize = data->rsize;
2625 args->wsize = data->wsize;
2626 args->timeo = data->timeo;
2627 args->retrans = data->retrans;
2628 args->acregmin = data->acregmin;
2629 args->acregmax = data->acregmax;
2630 args->acdirmin = data->acdirmin;
2631 args->acdirmax = data->acdirmax;
2632 args->nfs_server.protocol = data->proto;
2633 nfs_validate_transport_protocol(args);
2637 if (nfs_parse_mount_options((char *)options, args) == 0)
2640 if (!nfs_verify_server_address(sap))
2643 return nfs4_validate_text_mount_data(options, args, dev_name);
2649 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2653 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2654 data->auth_flavourlen);
2658 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2663 * Get the superblock for the NFS4 root partition
2665 static struct dentry *
2666 nfs4_remote_mount(struct file_system_type *fs_type, int flags,
2667 const char *dev_name, void *raw_data)
2669 struct nfs_parsed_mount_data *data = raw_data;
2670 struct super_block *s;
2671 struct nfs_server *server;
2672 struct nfs_fh *mntfh;
2673 struct dentry *mntroot;
2674 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2675 struct nfs_sb_mountdata sb_mntdata = {
2678 int error = -ENOMEM;
2680 mntfh = nfs_alloc_fhandle();
2681 if (data == NULL || mntfh == NULL)
2684 security_init_mnt_opts(&data->lsm_opts);
2686 /* Get a volume representation */
2687 server = nfs4_create_server(data, mntfh);
2688 if (IS_ERR(server)) {
2689 error = PTR_ERR(server);
2692 sb_mntdata.server = server;
2694 if (server->flags & NFS4_MOUNT_UNSHARED)
2695 compare_super = NULL;
2697 /* Get a superblock - note that we may end up sharing one that already exists */
2698 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2704 if (s->s_fs_info != server) {
2705 nfs_free_server(server);
2708 error = nfs_bdi_register(server);
2710 goto error_splat_bdi;
2714 /* initial superblock/root creation */
2716 nfs_fscache_get_super_cookie(
2717 s, data ? data->fscache_uniq : NULL, NULL);
2720 mntroot = nfs4_get_root(s, mntfh);
2721 if (IS_ERR(mntroot)) {
2722 error = PTR_ERR(mntroot);
2723 goto error_splat_super;
2726 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
2728 goto error_splat_root;
2730 s->s_flags |= MS_ACTIVE;
2732 security_free_mnt_opts(&data->lsm_opts);
2733 nfs_free_fhandle(mntfh);
2737 security_free_mnt_opts(&data->lsm_opts);
2739 nfs_free_fhandle(mntfh);
2740 return ERR_PTR(error);
2743 nfs_free_server(server);
2749 if (server && !s->s_root)
2750 bdi_unregister(&server->backing_dev_info);
2752 deactivate_locked_super(s);
2756 static struct vfsmount *nfs_do_root_mount(struct file_system_type *fs_type,
2757 int flags, void *data, const char *hostname)
2759 struct vfsmount *root_mnt;
2763 len = strlen(hostname) + 3;
2764 root_devname = kmalloc(len, GFP_KERNEL);
2765 if (root_devname == NULL)
2766 return ERR_PTR(-ENOMEM);
2767 snprintf(root_devname, len, "%s:/", hostname);
2768 root_mnt = vfs_kern_mount(fs_type, flags, root_devname, data);
2769 kfree(root_devname);
2773 static void nfs_fix_devname(const struct path *path, struct vfsmount *mnt)
2775 char *page = (char *) __get_free_page(GFP_KERNEL);
2776 char *devname, *tmp;
2780 devname = nfs_path(path->mnt->mnt_devname,
2781 path->mnt->mnt_root, path->dentry,
2783 if (IS_ERR(devname))
2785 tmp = kstrdup(devname, GFP_KERNEL);
2788 kfree(mnt->mnt_devname);
2789 mnt->mnt_devname = tmp;
2791 free_page((unsigned long)page);
2794 struct nfs_referral_count {
2795 struct list_head list;
2796 const struct task_struct *task;
2797 unsigned int referral_count;
2800 static LIST_HEAD(nfs_referral_count_list);
2801 static DEFINE_SPINLOCK(nfs_referral_count_list_lock);
2803 static struct nfs_referral_count *nfs_find_referral_count(void)
2805 struct nfs_referral_count *p;
2807 list_for_each_entry(p, &nfs_referral_count_list, list) {
2808 if (p->task == current)
2814 #define NFS_MAX_NESTED_REFERRALS 2
2816 static int nfs_referral_loop_protect(void)
2818 struct nfs_referral_count *p, *new;
2821 new = kmalloc(sizeof(*new), GFP_KERNEL);
2824 new->task = current;
2825 new->referral_count = 1;
2828 spin_lock(&nfs_referral_count_list_lock);
2829 p = nfs_find_referral_count();
2831 if (p->referral_count >= NFS_MAX_NESTED_REFERRALS)
2834 p->referral_count++;
2836 list_add(&new->list, &nfs_referral_count_list);
2839 spin_unlock(&nfs_referral_count_list_lock);
2845 static void nfs_referral_loop_unprotect(void)
2847 struct nfs_referral_count *p;
2849 spin_lock(&nfs_referral_count_list_lock);
2850 p = nfs_find_referral_count();
2851 p->referral_count--;
2852 if (p->referral_count == 0)
2856 spin_unlock(&nfs_referral_count_list_lock);
2860 static int nfs_follow_remote_path(struct vfsmount *root_mnt,
2861 const char *export_path, struct vfsmount *mnt_target)
2863 struct nameidata *nd = NULL;
2864 struct mnt_namespace *ns_private;
2865 struct super_block *s;
2868 nd = kmalloc(sizeof(*nd), GFP_KERNEL);
2872 ns_private = create_mnt_ns(root_mnt);
2873 ret = PTR_ERR(ns_private);
2874 if (IS_ERR(ns_private))
2877 ret = nfs_referral_loop_protect();
2879 goto out_put_mnt_ns;
2881 ret = vfs_path_lookup(root_mnt->mnt_root, root_mnt,
2882 export_path, LOOKUP_FOLLOW, nd);
2884 nfs_referral_loop_unprotect();
2885 put_mnt_ns(ns_private);
2890 s = nd->path.mnt->mnt_sb;
2891 atomic_inc(&s->s_active);
2892 mnt_target->mnt_sb = s;
2893 mnt_target->mnt_root = dget(nd->path.dentry);
2895 /* Correct the device pathname */
2896 nfs_fix_devname(&nd->path, mnt_target);
2898 path_put(&nd->path);
2900 down_write(&s->s_umount);
2903 put_mnt_ns(ns_private);
2911 static int nfs4_try_mount(int flags, const char *dev_name,
2912 struct nfs_parsed_mount_data *data,
2913 struct vfsmount *mnt)
2916 struct vfsmount *root_mnt;
2919 dfprintk(MOUNT, "--> nfs4_try_mount()\n");
2921 export_path = data->nfs_server.export_path;
2922 data->nfs_server.export_path = "/";
2923 root_mnt = nfs_do_root_mount(&nfs4_remote_fs_type, flags, data,
2924 data->nfs_server.hostname);
2925 data->nfs_server.export_path = export_path;
2927 error = PTR_ERR(root_mnt);
2928 if (IS_ERR(root_mnt))
2931 error = nfs_follow_remote_path(root_mnt, export_path, mnt);
2934 dfprintk(MOUNT, "<-- nfs4_try_mount() = %d%s\n", error,
2935 error != 0 ? " [error]" : "");
2940 * Get the superblock for an NFS4 mountpoint
2942 static int nfs4_get_sb(struct file_system_type *fs_type,
2943 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2945 struct nfs_parsed_mount_data *data;
2946 int error = -ENOMEM;
2948 data = nfs_alloc_parsed_mount_data(4);
2952 /* Validate the mount data */
2953 error = nfs4_validate_mount_data(raw_data, data, dev_name);
2957 error = nfs4_try_mount(flags, dev_name, data, mnt);
2960 kfree(data->client_address);
2961 kfree(data->nfs_server.export_path);
2962 kfree(data->nfs_server.hostname);
2963 kfree(data->fscache_uniq);
2966 dprintk("<-- nfs4_get_sb() = %d%s\n", error,
2967 error != 0 ? " [error]" : "");
2971 static void nfs4_kill_super(struct super_block *sb)
2973 struct nfs_server *server = NFS_SB(sb);
2975 dprintk("--> %s\n", __func__);
2976 nfs_super_return_all_delegations(sb);
2977 kill_anon_super(sb);
2978 nfs_fscache_release_super_cookie(sb);
2979 nfs_free_server(server);
2980 dprintk("<-- %s\n", __func__);
2984 * Clone an NFS4 server record on xdev traversal (FSID-change)
2986 static struct dentry *
2987 nfs4_xdev_mount(struct file_system_type *fs_type, int flags,
2988 const char *dev_name, void *raw_data)
2990 struct nfs_clone_mount *data = raw_data;
2991 struct super_block *s;
2992 struct nfs_server *server;
2993 struct dentry *mntroot;
2994 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2995 struct nfs_sb_mountdata sb_mntdata = {
3000 dprintk("--> nfs4_xdev_mount()\n");
3002 /* create a new volume representation */
3003 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
3004 if (IS_ERR(server)) {
3005 error = PTR_ERR(server);
3006 goto out_err_noserver;
3008 sb_mntdata.server = server;
3010 if (server->flags & NFS4_MOUNT_UNSHARED)
3011 compare_super = NULL;
3013 /* Get a superblock - note that we may end up sharing one that already exists */
3014 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
3020 if (s->s_fs_info != server) {
3021 nfs_free_server(server);
3024 error = nfs_bdi_register(server);
3026 goto error_splat_bdi;
3030 /* initial superblock/root creation */
3031 nfs4_clone_super(s, data->sb);
3032 nfs_fscache_get_super_cookie(s, NULL, data);
3035 mntroot = nfs4_get_root(s, data->fh);
3036 if (IS_ERR(mntroot)) {
3037 error = PTR_ERR(mntroot);
3038 goto error_splat_super;
3040 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
3043 goto error_splat_super;
3046 s->s_flags |= MS_ACTIVE;
3048 security_sb_clone_mnt_opts(data->sb, s);
3050 dprintk("<-- nfs4_xdev_mount() = 0\n");
3054 nfs_free_server(server);
3056 dprintk("<-- nfs4_xdev_mount() = %d [error]\n", error);
3057 return ERR_PTR(error);
3060 if (server && !s->s_root)
3061 bdi_unregister(&server->backing_dev_info);
3063 deactivate_locked_super(s);
3064 dprintk("<-- nfs4_xdev_mount() = %d [splat]\n", error);
3065 return ERR_PTR(error);
3068 static struct dentry *
3069 nfs4_remote_referral_mount(struct file_system_type *fs_type, int flags,
3070 const char *dev_name, void *raw_data)
3072 struct nfs_clone_mount *data = raw_data;
3073 struct super_block *s;
3074 struct nfs_server *server;
3075 struct dentry *mntroot;
3076 struct nfs_fh *mntfh;
3077 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
3078 struct nfs_sb_mountdata sb_mntdata = {
3081 int error = -ENOMEM;
3083 dprintk("--> nfs4_referral_get_sb()\n");
3085 mntfh = nfs_alloc_fhandle();
3089 /* create a new volume representation */
3090 server = nfs4_create_referral_server(data, mntfh);
3091 if (IS_ERR(server)) {
3092 error = PTR_ERR(server);
3093 goto out_err_noserver;
3095 sb_mntdata.server = server;
3097 if (server->flags & NFS4_MOUNT_UNSHARED)
3098 compare_super = NULL;
3100 /* Get a superblock - note that we may end up sharing one that already exists */
3101 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
3107 if (s->s_fs_info != server) {
3108 nfs_free_server(server);
3111 error = nfs_bdi_register(server);
3113 goto error_splat_bdi;
3117 /* initial superblock/root creation */
3119 nfs_fscache_get_super_cookie(s, NULL, data);
3122 mntroot = nfs4_get_root(s, mntfh);
3123 if (IS_ERR(mntroot)) {
3124 error = PTR_ERR(mntroot);
3125 goto error_splat_super;
3127 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
3130 goto error_splat_super;
3133 s->s_flags |= MS_ACTIVE;
3135 security_sb_clone_mnt_opts(data->sb, s);
3137 nfs_free_fhandle(mntfh);
3138 dprintk("<-- nfs4_referral_get_sb() = 0\n");
3142 nfs_free_server(server);
3144 nfs_free_fhandle(mntfh);
3146 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
3147 return ERR_PTR(error);
3150 if (server && !s->s_root)
3151 bdi_unregister(&server->backing_dev_info);
3153 deactivate_locked_super(s);
3154 nfs_free_fhandle(mntfh);
3155 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
3156 return ERR_PTR(error);
3160 * Create an NFS4 server record on referral traversal
3162 static int nfs4_referral_get_sb(struct file_system_type *fs_type,
3163 int flags, const char *dev_name, void *raw_data,
3164 struct vfsmount *mnt)
3166 struct nfs_clone_mount *data = raw_data;
3168 struct vfsmount *root_mnt;
3171 dprintk("--> nfs4_referral_get_sb()\n");
3173 export_path = data->mnt_path;
3174 data->mnt_path = "/";
3176 root_mnt = nfs_do_root_mount(&nfs4_remote_referral_fs_type,
3177 flags, data, data->hostname);
3178 data->mnt_path = export_path;
3180 error = PTR_ERR(root_mnt);
3181 if (IS_ERR(root_mnt))
3184 error = nfs_follow_remote_path(root_mnt, export_path, mnt);
3186 dprintk("<-- nfs4_referral_get_sb() = %d%s\n", error,
3187 error != 0 ? " [error]" : "");
3191 #endif /* CONFIG_NFS_V4 */