4 * Copyright (C) 1992 Rick Sladkey
6 * nfs superblock handling functions
8 * Modularised by Alan Cox <alan@lxorguk.ukuu.org.uk>, while hacking some
9 * experimental NFS changes. Modularisation taken straight from SYS5 fs.
11 * Change to nfs_read_super() to permit NFS mounts to multi-homed hosts.
12 * J.S.Peatfield@damtp.cam.ac.uk
14 * Split from inode.c by David Howells <dhowells@redhat.com>
16 * - superblocks are indexed on server only - all inodes, dentries, etc. associated with a
17 * particular server are held in the same superblock
18 * - NFS superblocks can have several effective roots to the dentry tree
19 * - directory type roots are spliced into the tree when a path from one root reaches the root
20 * of another (see nfs_lookup())
23 #include <linux/module.h>
24 #include <linux/init.h>
26 #include <linux/time.h>
27 #include <linux/kernel.h>
29 #include <linux/string.h>
30 #include <linux/stat.h>
31 #include <linux/errno.h>
32 #include <linux/unistd.h>
33 #include <linux/sunrpc/clnt.h>
34 #include <linux/sunrpc/stats.h>
35 #include <linux/sunrpc/metrics.h>
36 #include <linux/sunrpc/xprtsock.h>
37 #include <linux/sunrpc/xprtrdma.h>
38 #include <linux/nfs_fs.h>
39 #include <linux/nfs_mount.h>
40 #include <linux/nfs4_mount.h>
41 #include <linux/lockd/bind.h>
42 #include <linux/seq_file.h>
43 #include <linux/mount.h>
44 #include <linux/namei.h>
45 #include <linux/nfs_idmap.h>
46 #include <linux/vfs.h>
47 #include <linux/inet.h>
48 #include <linux/in6.h>
49 #include <linux/slab.h>
51 #include <linux/netdevice.h>
52 #include <linux/nfs_xdr.h>
53 #include <linux/magic.h>
54 #include <linux/parser.h>
55 #include <linux/nsproxy.h>
56 #include <linux/rcupdate.h>
58 #include <asm/uaccess.h>
62 #include "delegation.h"
68 #define NFSDBG_FACILITY NFSDBG_VFS
71 #define NFS_DEFAULT_VERSION 3
73 #define NFS_DEFAULT_VERSION 2
77 /* Mount options that take no arguments */
79 Opt_posix, Opt_noposix,
83 Opt_udp, Opt_tcp, Opt_rdma,
85 Opt_rdirplus, Opt_nordirplus,
86 Opt_sharecache, Opt_nosharecache,
87 Opt_resvport, Opt_noresvport,
88 Opt_fscache, Opt_nofscache,
90 /* Mount options that take integer arguments */
92 Opt_rsize, Opt_wsize, Opt_bsize,
93 Opt_timeo, Opt_retrans,
94 Opt_acregmin, Opt_acregmax,
95 Opt_acdirmin, Opt_acdirmax,
102 /* Mount options that take string arguments */
104 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
105 Opt_addr, Opt_mountaddr, Opt_clientaddr,
110 /* Special mount options */
111 Opt_userspace, Opt_deprecated, Opt_sloppy,
116 static const match_table_t nfs_mount_option_tokens = {
117 { Opt_userspace, "bg" },
118 { Opt_userspace, "fg" },
119 { Opt_userspace, "retry=%s" },
121 { Opt_sloppy, "sloppy" },
123 { Opt_soft, "soft" },
124 { Opt_hard, "hard" },
125 { Opt_deprecated, "intr" },
126 { Opt_deprecated, "nointr" },
127 { Opt_posix, "posix" },
128 { Opt_noposix, "noposix" },
130 { Opt_nocto, "nocto" },
132 { Opt_noac, "noac" },
133 { Opt_lock, "lock" },
134 { Opt_nolock, "nolock" },
137 { Opt_rdma, "rdma" },
139 { Opt_noacl, "noacl" },
140 { Opt_rdirplus, "rdirplus" },
141 { Opt_nordirplus, "nordirplus" },
142 { Opt_sharecache, "sharecache" },
143 { Opt_nosharecache, "nosharecache" },
144 { Opt_resvport, "resvport" },
145 { Opt_noresvport, "noresvport" },
146 { Opt_fscache, "fsc" },
147 { Opt_nofscache, "nofsc" },
149 { Opt_port, "port=%s" },
150 { Opt_rsize, "rsize=%s" },
151 { Opt_wsize, "wsize=%s" },
152 { Opt_bsize, "bsize=%s" },
153 { Opt_timeo, "timeo=%s" },
154 { Opt_retrans, "retrans=%s" },
155 { Opt_acregmin, "acregmin=%s" },
156 { Opt_acregmax, "acregmax=%s" },
157 { Opt_acdirmin, "acdirmin=%s" },
158 { Opt_acdirmax, "acdirmax=%s" },
159 { Opt_actimeo, "actimeo=%s" },
160 { Opt_namelen, "namlen=%s" },
161 { Opt_mountport, "mountport=%s" },
162 { Opt_mountvers, "mountvers=%s" },
163 { Opt_minorversion, "minorversion=%s" },
165 { Opt_nfsvers, "nfsvers=%s" },
166 { Opt_nfsvers, "vers=%s" },
168 { Opt_sec, "sec=%s" },
169 { Opt_proto, "proto=%s" },
170 { Opt_mountproto, "mountproto=%s" },
171 { Opt_addr, "addr=%s" },
172 { Opt_clientaddr, "clientaddr=%s" },
173 { Opt_mounthost, "mounthost=%s" },
174 { Opt_mountaddr, "mountaddr=%s" },
176 { Opt_lookupcache, "lookupcache=%s" },
177 { Opt_fscache_uniq, "fsc=%s" },
178 { Opt_local_lock, "local_lock=%s" },
180 /* The following needs to be listed after all other options */
181 { Opt_nfsvers, "v%s" },
187 Opt_xprt_udp, Opt_xprt_udp6, Opt_xprt_tcp, Opt_xprt_tcp6, Opt_xprt_rdma,
192 static const match_table_t nfs_xprt_protocol_tokens = {
193 { Opt_xprt_udp, "udp" },
194 { Opt_xprt_udp6, "udp6" },
195 { Opt_xprt_tcp, "tcp" },
196 { Opt_xprt_tcp6, "tcp6" },
197 { Opt_xprt_rdma, "rdma" },
199 { Opt_xprt_err, NULL }
203 Opt_sec_none, Opt_sec_sys,
204 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
205 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
206 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
211 static const match_table_t nfs_secflavor_tokens = {
212 { Opt_sec_none, "none" },
213 { Opt_sec_none, "null" },
214 { Opt_sec_sys, "sys" },
216 { Opt_sec_krb5, "krb5" },
217 { Opt_sec_krb5i, "krb5i" },
218 { Opt_sec_krb5p, "krb5p" },
220 { Opt_sec_lkey, "lkey" },
221 { Opt_sec_lkeyi, "lkeyi" },
222 { Opt_sec_lkeyp, "lkeyp" },
224 { Opt_sec_spkm, "spkm3" },
225 { Opt_sec_spkmi, "spkm3i" },
226 { Opt_sec_spkmp, "spkm3p" },
228 { Opt_sec_err, NULL }
232 Opt_lookupcache_all, Opt_lookupcache_positive,
233 Opt_lookupcache_none,
238 static match_table_t nfs_lookupcache_tokens = {
239 { Opt_lookupcache_all, "all" },
240 { Opt_lookupcache_positive, "pos" },
241 { Opt_lookupcache_positive, "positive" },
242 { Opt_lookupcache_none, "none" },
244 { Opt_lookupcache_err, NULL }
248 Opt_local_lock_all, Opt_local_lock_flock, Opt_local_lock_posix,
254 static match_table_t nfs_local_lock_tokens = {
255 { Opt_local_lock_all, "all" },
256 { Opt_local_lock_flock, "flock" },
257 { Opt_local_lock_posix, "posix" },
258 { Opt_local_lock_none, "none" },
260 { Opt_local_lock_err, NULL }
264 Opt_vers_2, Opt_vers_3, Opt_vers_4, Opt_vers_4_0,
270 static match_table_t nfs_vers_tokens = {
274 { Opt_vers_4_0, "4.0" },
275 { Opt_vers_4_1, "4.1" },
277 { Opt_vers_err, NULL }
280 struct nfs_mount_info {
281 void (*fill_super)(struct super_block *, struct nfs_mount_info *);
282 int (*set_security)(struct super_block *, struct dentry *, struct nfs_mount_info *);
283 struct nfs_parsed_mount_data *parsed;
284 struct nfs_clone_mount *cloned;
287 static void nfs_umount_begin(struct super_block *);
288 static int nfs_statfs(struct dentry *, struct kstatfs *);
289 static int nfs_show_options(struct seq_file *, struct dentry *);
290 static int nfs_show_devname(struct seq_file *, struct dentry *);
291 static int nfs_show_path(struct seq_file *, struct dentry *);
292 static int nfs_show_stats(struct seq_file *, struct dentry *);
293 static struct dentry *nfs_fs_mount(struct file_system_type *,
294 int, const char *, void *);
295 static struct dentry *nfs_xdev_mount(struct file_system_type *fs_type,
296 int flags, const char *dev_name, void *raw_data);
297 static void nfs_put_super(struct super_block *);
298 static void nfs_kill_super(struct super_block *);
299 static int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
301 static struct file_system_type nfs_fs_type = {
302 .owner = THIS_MODULE,
304 .mount = nfs_fs_mount,
305 .kill_sb = nfs_kill_super,
306 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
309 struct file_system_type nfs_xdev_fs_type = {
310 .owner = THIS_MODULE,
312 .mount = nfs_xdev_mount,
313 .kill_sb = nfs_kill_super,
314 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
317 static const struct super_operations nfs_sops = {
318 .alloc_inode = nfs_alloc_inode,
319 .destroy_inode = nfs_destroy_inode,
320 .write_inode = nfs_write_inode,
321 .put_super = nfs_put_super,
322 .statfs = nfs_statfs,
323 .evict_inode = nfs_evict_inode,
324 .umount_begin = nfs_umount_begin,
325 .show_options = nfs_show_options,
326 .show_devname = nfs_show_devname,
327 .show_path = nfs_show_path,
328 .show_stats = nfs_show_stats,
329 .remount_fs = nfs_remount,
333 static int nfs4_validate_text_mount_data(void *options,
334 struct nfs_parsed_mount_data *args, const char *dev_name);
335 static struct dentry *nfs4_try_mount(int flags, const char *dev_name,
336 struct nfs_parsed_mount_data *data);
337 static struct dentry *nfs4_mount(struct file_system_type *fs_type,
338 int flags, const char *dev_name, void *raw_data);
339 static struct dentry *nfs4_remote_mount(struct file_system_type *fs_type,
340 int flags, const char *dev_name, void *raw_data);
341 static struct dentry *nfs4_xdev_mount(struct file_system_type *fs_type,
342 int flags, const char *dev_name, void *raw_data);
343 static struct dentry *nfs4_referral_mount(struct file_system_type *fs_type,
344 int flags, const char *dev_name, void *raw_data);
345 static struct dentry *nfs4_remote_referral_mount(struct file_system_type *fs_type,
346 int flags, const char *dev_name, void *raw_data);
347 static void nfs4_kill_super(struct super_block *sb);
349 static struct file_system_type nfs4_fs_type = {
350 .owner = THIS_MODULE,
353 .kill_sb = nfs4_kill_super,
354 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
357 static struct file_system_type nfs4_remote_fs_type = {
358 .owner = THIS_MODULE,
360 .mount = nfs4_remote_mount,
361 .kill_sb = nfs4_kill_super,
362 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
365 struct file_system_type nfs4_xdev_fs_type = {
366 .owner = THIS_MODULE,
368 .mount = nfs4_xdev_mount,
369 .kill_sb = nfs4_kill_super,
370 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
373 static struct file_system_type nfs4_remote_referral_fs_type = {
374 .owner = THIS_MODULE,
376 .mount = nfs4_remote_referral_mount,
377 .kill_sb = nfs4_kill_super,
378 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
381 struct file_system_type nfs4_referral_fs_type = {
382 .owner = THIS_MODULE,
384 .mount = nfs4_referral_mount,
385 .kill_sb = nfs4_kill_super,
386 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
389 static const struct super_operations nfs4_sops = {
390 .alloc_inode = nfs_alloc_inode,
391 .destroy_inode = nfs_destroy_inode,
392 .write_inode = nfs_write_inode,
393 .put_super = nfs_put_super,
394 .statfs = nfs_statfs,
395 .evict_inode = nfs4_evict_inode,
396 .umount_begin = nfs_umount_begin,
397 .show_options = nfs_show_options,
398 .show_devname = nfs_show_devname,
399 .show_path = nfs_show_path,
400 .show_stats = nfs_show_stats,
401 .remount_fs = nfs_remount,
405 static struct shrinker acl_shrinker = {
406 .shrink = nfs_access_cache_shrinker,
407 .seeks = DEFAULT_SEEKS,
411 * Register the NFS filesystems
413 int __init register_nfs_fs(void)
417 ret = register_filesystem(&nfs_fs_type);
421 ret = nfs_register_sysctl();
425 ret = register_filesystem(&nfs4_fs_type);
429 register_shrinker(&acl_shrinker);
434 nfs_unregister_sysctl();
437 unregister_filesystem(&nfs_fs_type);
443 * Unregister the NFS filesystems
445 void __exit unregister_nfs_fs(void)
447 unregister_shrinker(&acl_shrinker);
449 unregister_filesystem(&nfs4_fs_type);
451 nfs_unregister_sysctl();
452 unregister_filesystem(&nfs_fs_type);
455 void nfs_sb_active(struct super_block *sb)
457 struct nfs_server *server = NFS_SB(sb);
459 if (atomic_inc_return(&server->active) == 1)
460 atomic_inc(&sb->s_active);
463 void nfs_sb_deactive(struct super_block *sb)
465 struct nfs_server *server = NFS_SB(sb);
467 if (atomic_dec_and_test(&server->active))
468 deactivate_super(sb);
472 * Deliver file system statistics to userspace
474 static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
476 struct nfs_server *server = NFS_SB(dentry->d_sb);
477 unsigned char blockbits;
478 unsigned long blockres;
479 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
480 struct nfs_fsstat res;
483 res.fattr = nfs_alloc_fattr();
484 if (res.fattr == NULL)
487 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
488 if (unlikely(error == -ESTALE)) {
489 struct dentry *pd_dentry;
491 pd_dentry = dget_parent(dentry);
492 if (pd_dentry != NULL) {
493 nfs_zap_caches(pd_dentry->d_inode);
497 nfs_free_fattr(res.fattr);
501 buf->f_type = NFS_SUPER_MAGIC;
504 * Current versions of glibc do not correctly handle the
505 * case where f_frsize != f_bsize. Eventually we want to
506 * report the value of wtmult in this field.
508 buf->f_frsize = dentry->d_sb->s_blocksize;
511 * On most *nix systems, f_blocks, f_bfree, and f_bavail
512 * are reported in units of f_frsize. Linux hasn't had
513 * an f_frsize field in its statfs struct until recently,
514 * thus historically Linux's sys_statfs reports these
515 * fields in units of f_bsize.
517 buf->f_bsize = dentry->d_sb->s_blocksize;
518 blockbits = dentry->d_sb->s_blocksize_bits;
519 blockres = (1 << blockbits) - 1;
520 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
521 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
522 buf->f_bavail = (res.abytes + blockres) >> blockbits;
524 buf->f_files = res.tfiles;
525 buf->f_ffree = res.afiles;
527 buf->f_namelen = server->namelen;
532 dprintk("%s: statfs error = %d\n", __func__, -error);
537 * Map the security flavour number to a name
539 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
541 static const struct {
542 rpc_authflavor_t flavour;
545 { RPC_AUTH_NULL, "null" },
546 { RPC_AUTH_UNIX, "sys" },
547 { RPC_AUTH_GSS_KRB5, "krb5" },
548 { RPC_AUTH_GSS_KRB5I, "krb5i" },
549 { RPC_AUTH_GSS_KRB5P, "krb5p" },
550 { RPC_AUTH_GSS_LKEY, "lkey" },
551 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
552 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
553 { RPC_AUTH_GSS_SPKM, "spkm" },
554 { RPC_AUTH_GSS_SPKMI, "spkmi" },
555 { RPC_AUTH_GSS_SPKMP, "spkmp" },
556 { UINT_MAX, "unknown" }
560 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
561 if (sec_flavours[i].flavour == flavour)
564 return sec_flavours[i].str;
567 static void nfs_show_mountd_netid(struct seq_file *m, struct nfs_server *nfss,
570 struct sockaddr *sap = (struct sockaddr *) &nfss->mountd_address;
572 seq_printf(m, ",mountproto=");
573 switch (sap->sa_family) {
575 switch (nfss->mountd_protocol) {
577 seq_printf(m, RPCBIND_NETID_UDP);
580 seq_printf(m, RPCBIND_NETID_TCP);
584 seq_printf(m, "auto");
588 switch (nfss->mountd_protocol) {
590 seq_printf(m, RPCBIND_NETID_UDP6);
593 seq_printf(m, RPCBIND_NETID_TCP6);
597 seq_printf(m, "auto");
602 seq_printf(m, "auto");
606 static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
609 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
611 if (nfss->flags & NFS_MOUNT_LEGACY_INTERFACE)
614 switch (sap->sa_family) {
616 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
617 seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
621 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
622 seq_printf(m, ",mountaddr=%pI6c", &sin6->sin6_addr);
627 seq_printf(m, ",mountaddr=unspecified");
630 if (nfss->mountd_version || showdefaults)
631 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
632 if ((nfss->mountd_port &&
633 nfss->mountd_port != (unsigned short)NFS_UNSPEC_PORT) ||
635 seq_printf(m, ",mountport=%u", nfss->mountd_port);
637 nfs_show_mountd_netid(m, nfss, showdefaults);
641 static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
644 struct nfs_client *clp = nfss->nfs_client;
646 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
649 static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
655 static void nfs_show_nfs_version(struct seq_file *m,
656 unsigned int version,
657 unsigned int minorversion)
659 seq_printf(m, ",vers=%u", version);
661 seq_printf(m, ".%u", minorversion);
665 * Describe the mount options in force on this server representation
667 static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
670 static const struct proc_nfs_info {
675 { NFS_MOUNT_SOFT, ",soft", ",hard" },
676 { NFS_MOUNT_POSIX, ",posix", "" },
677 { NFS_MOUNT_NOCTO, ",nocto", "" },
678 { NFS_MOUNT_NOAC, ",noac", "" },
679 { NFS_MOUNT_NONLM, ",nolock", "" },
680 { NFS_MOUNT_NOACL, ",noacl", "" },
681 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
682 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
683 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
686 const struct proc_nfs_info *nfs_infop;
687 struct nfs_client *clp = nfss->nfs_client;
688 u32 version = clp->rpc_ops->version;
689 int local_flock, local_fcntl;
691 nfs_show_nfs_version(m, version, clp->cl_minorversion);
692 seq_printf(m, ",rsize=%u", nfss->rsize);
693 seq_printf(m, ",wsize=%u", nfss->wsize);
694 if (nfss->bsize != 0)
695 seq_printf(m, ",bsize=%u", nfss->bsize);
696 seq_printf(m, ",namlen=%u", nfss->namelen);
697 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
698 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
699 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
700 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
701 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
702 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
703 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
704 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
705 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
706 if (nfss->flags & nfs_infop->flag)
707 seq_puts(m, nfs_infop->str);
709 seq_puts(m, nfs_infop->nostr);
712 seq_printf(m, ",proto=%s",
713 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
716 if (nfss->port != NFS_PORT)
717 seq_printf(m, ",port=%u", nfss->port);
720 seq_printf(m, ",port=%u", nfss->port);
722 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
723 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
724 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
727 nfs_show_mountd_options(m, nfss, showdefaults);
729 nfs_show_nfsv4_options(m, nfss, showdefaults);
731 if (nfss->options & NFS_OPTION_FSCACHE)
732 seq_printf(m, ",fsc");
734 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONEG) {
735 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONE)
736 seq_printf(m, ",lookupcache=none");
738 seq_printf(m, ",lookupcache=pos");
741 local_flock = nfss->flags & NFS_MOUNT_LOCAL_FLOCK;
742 local_fcntl = nfss->flags & NFS_MOUNT_LOCAL_FCNTL;
744 if (!local_flock && !local_fcntl)
745 seq_printf(m, ",local_lock=none");
746 else if (local_flock && local_fcntl)
747 seq_printf(m, ",local_lock=all");
748 else if (local_flock)
749 seq_printf(m, ",local_lock=flock");
751 seq_printf(m, ",local_lock=posix");
755 * Describe the mount options on this VFS mountpoint
757 static int nfs_show_options(struct seq_file *m, struct dentry *root)
759 struct nfs_server *nfss = NFS_SB(root->d_sb);
761 nfs_show_mount_options(m, nfss, 0);
764 seq_printf(m, ",addr=%s",
765 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
773 #ifdef CONFIG_NFS_V4_1
774 static void show_sessions(struct seq_file *m, struct nfs_server *server)
776 if (nfs4_has_session(server->nfs_client))
777 seq_printf(m, ",sessions");
780 static void show_sessions(struct seq_file *m, struct nfs_server *server) {}
784 #ifdef CONFIG_NFS_V4_1
785 static void show_pnfs(struct seq_file *m, struct nfs_server *server)
787 seq_printf(m, ",pnfs=");
788 if (server->pnfs_curr_ld)
789 seq_printf(m, "%s", server->pnfs_curr_ld->name);
791 seq_printf(m, "not configured");
794 static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
796 if (nfss->nfs_client && nfss->nfs_client->impl_id) {
797 struct nfs41_impl_id *impl_id = nfss->nfs_client->impl_id;
798 seq_printf(m, "\n\timpl_id:\tname='%s',domain='%s',"
800 impl_id->name, impl_id->domain,
801 impl_id->date.seconds, impl_id->date.nseconds);
806 static void show_pnfs(struct seq_file *m, struct nfs_server *server)
810 static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
815 static int nfs_show_devname(struct seq_file *m, struct dentry *root)
817 char *page = (char *) __get_free_page(GFP_KERNEL);
818 char *devname, *dummy;
822 devname = nfs_path(&dummy, root, page, PAGE_SIZE);
824 err = PTR_ERR(devname);
826 seq_escape(m, devname, " \t\n\\");
827 free_page((unsigned long)page);
831 static int nfs_show_path(struct seq_file *m, struct dentry *dentry)
838 * Present statistical information for this VFS mountpoint
840 static int nfs_show_stats(struct seq_file *m, struct dentry *root)
843 struct nfs_server *nfss = NFS_SB(root->d_sb);
844 struct rpc_auth *auth = nfss->client->cl_auth;
845 struct nfs_iostats totals = { };
847 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
850 * Display all mount option settings
852 seq_printf(m, "\n\topts:\t");
853 seq_puts(m, root->d_sb->s_flags & MS_RDONLY ? "ro" : "rw");
854 seq_puts(m, root->d_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
855 seq_puts(m, root->d_sb->s_flags & MS_NOATIME ? ",noatime" : "");
856 seq_puts(m, root->d_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
857 nfs_show_mount_options(m, nfss, 1);
859 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
861 show_implementation_id(m, nfss);
863 seq_printf(m, "\n\tcaps:\t");
864 seq_printf(m, "caps=0x%x", nfss->caps);
865 seq_printf(m, ",wtmult=%u", nfss->wtmult);
866 seq_printf(m, ",dtsize=%u", nfss->dtsize);
867 seq_printf(m, ",bsize=%u", nfss->bsize);
868 seq_printf(m, ",namlen=%u", nfss->namelen);
871 if (nfss->nfs_client->rpc_ops->version == 4) {
872 seq_printf(m, "\n\tnfsv4:\t");
873 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
874 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
875 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
876 show_sessions(m, nfss);
882 * Display security flavor in effect for this mount
884 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
886 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
889 * Display superblock I/O counters
891 for_each_possible_cpu(cpu) {
892 struct nfs_iostats *stats;
895 stats = per_cpu_ptr(nfss->io_stats, cpu);
897 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
898 totals.events[i] += stats->events[i];
899 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
900 totals.bytes[i] += stats->bytes[i];
901 #ifdef CONFIG_NFS_FSCACHE
902 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
903 totals.fscache[i] += stats->fscache[i];
909 seq_printf(m, "\n\tevents:\t");
910 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
911 seq_printf(m, "%lu ", totals.events[i]);
912 seq_printf(m, "\n\tbytes:\t");
913 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
914 seq_printf(m, "%Lu ", totals.bytes[i]);
915 #ifdef CONFIG_NFS_FSCACHE
916 if (nfss->options & NFS_OPTION_FSCACHE) {
917 seq_printf(m, "\n\tfsc:\t");
918 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
919 seq_printf(m, "%Lu ", totals.bytes[i]);
924 rpc_print_iostats(m, nfss->client);
930 * Begin unmount by attempting to remove all automounted mountpoints we added
931 * in response to xdev traversals and referrals
933 static void nfs_umount_begin(struct super_block *sb)
935 struct nfs_server *server;
936 struct rpc_clnt *rpc;
939 /* -EIO all pending I/O */
940 rpc = server->client_acl;
942 rpc_killall_tasks(rpc);
943 rpc = server->client;
945 rpc_killall_tasks(rpc);
948 static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(unsigned int version)
950 struct nfs_parsed_mount_data *data;
952 data = kzalloc(sizeof(*data), GFP_KERNEL);
954 data->acregmin = NFS_DEF_ACREGMIN;
955 data->acregmax = NFS_DEF_ACREGMAX;
956 data->acdirmin = NFS_DEF_ACDIRMIN;
957 data->acdirmax = NFS_DEF_ACDIRMAX;
958 data->mount_server.port = NFS_UNSPEC_PORT;
959 data->nfs_server.port = NFS_UNSPEC_PORT;
960 data->nfs_server.protocol = XPRT_TRANSPORT_TCP;
961 data->auth_flavors[0] = RPC_AUTH_UNIX;
962 data->auth_flavor_len = 1;
963 data->version = version;
964 data->minorversion = 0;
965 data->net = current->nsproxy->net_ns;
966 security_init_mnt_opts(&data->lsm_opts);
971 static void nfs_free_parsed_mount_data(struct nfs_parsed_mount_data *data)
974 kfree(data->client_address);
975 kfree(data->mount_server.hostname);
976 kfree(data->nfs_server.export_path);
977 kfree(data->nfs_server.hostname);
978 kfree(data->fscache_uniq);
979 security_free_mnt_opts(&data->lsm_opts);
985 * Sanity-check a server address provided by the mount command.
987 * Address family must be initialized, and address must not be
988 * the ANY address for that family.
990 static int nfs_verify_server_address(struct sockaddr *addr)
992 switch (addr->sa_family) {
994 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
995 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
998 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
999 return !ipv6_addr_any(sa);
1003 dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
1008 * Select between a default port value and a user-specified port value.
1009 * If a zero value is set, then autobind will be used.
1011 static void nfs_set_port(struct sockaddr *sap, int *port,
1012 const unsigned short default_port)
1014 if (*port == NFS_UNSPEC_PORT)
1015 *port = default_port;
1017 rpc_set_port(sap, *port);
1021 * Sanity check the NFS transport protocol.
1024 static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
1026 switch (mnt->nfs_server.protocol) {
1027 case XPRT_TRANSPORT_UDP:
1028 case XPRT_TRANSPORT_TCP:
1029 case XPRT_TRANSPORT_RDMA:
1032 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1037 * For text based NFSv2/v3 mounts, the mount protocol transport default
1038 * settings should depend upon the specified NFS transport.
1040 static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
1042 nfs_validate_transport_protocol(mnt);
1044 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
1045 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
1047 switch (mnt->nfs_server.protocol) {
1048 case XPRT_TRANSPORT_UDP:
1049 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
1051 case XPRT_TRANSPORT_TCP:
1052 case XPRT_TRANSPORT_RDMA:
1053 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
1058 * Parse the value of the 'sec=' option.
1060 static int nfs_parse_security_flavors(char *value,
1061 struct nfs_parsed_mount_data *mnt)
1063 substring_t args[MAX_OPT_ARGS];
1065 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
1067 switch (match_token(value, nfs_secflavor_tokens, args)) {
1069 mnt->auth_flavors[0] = RPC_AUTH_NULL;
1072 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
1075 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
1078 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
1081 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
1084 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
1087 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
1090 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
1093 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
1096 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
1099 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
1105 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
1106 mnt->auth_flavor_len = 1;
1110 static int nfs_parse_version_string(char *string,
1111 struct nfs_parsed_mount_data *mnt,
1114 mnt->flags &= ~NFS_MOUNT_VER3;
1115 switch (match_token(string, nfs_vers_tokens, args)) {
1120 mnt->flags |= NFS_MOUNT_VER3;
1124 /* Backward compatibility option. In future,
1125 * the mount program should always supply
1126 * a NFSv4 minor version number.
1132 mnt->minorversion = 0;
1136 mnt->minorversion = 1;
1144 static int nfs_get_option_str(substring_t args[], char **option)
1147 *option = match_strdup(args);
1151 static int nfs_get_option_ul(substring_t args[], unsigned long *option)
1156 string = match_strdup(args);
1159 rc = strict_strtoul(string, 10, option);
1166 * Error-check and convert a string of mount options from user space into
1167 * a data structure. The whole mount string is processed; bad options are
1168 * skipped as they are encountered. If there were no errors, return 1;
1169 * otherwise return 0 (zero).
1171 static int nfs_parse_mount_options(char *raw,
1172 struct nfs_parsed_mount_data *mnt)
1174 char *p, *string, *secdata;
1175 int rc, sloppy = 0, invalid_option = 0;
1176 unsigned short protofamily = AF_UNSPEC;
1177 unsigned short mountfamily = AF_UNSPEC;
1180 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
1183 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
1185 secdata = alloc_secdata();
1189 rc = security_sb_copy_data(raw, secdata);
1191 goto out_security_failure;
1193 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
1195 goto out_security_failure;
1197 free_secdata(secdata);
1199 while ((p = strsep(&raw, ",")) != NULL) {
1200 substring_t args[MAX_OPT_ARGS];
1201 unsigned long option;
1207 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
1209 token = match_token(p, nfs_mount_option_tokens, args);
1213 * boolean options: foo/nofoo
1216 mnt->flags |= NFS_MOUNT_SOFT;
1219 mnt->flags &= ~NFS_MOUNT_SOFT;
1222 mnt->flags |= NFS_MOUNT_POSIX;
1225 mnt->flags &= ~NFS_MOUNT_POSIX;
1228 mnt->flags &= ~NFS_MOUNT_NOCTO;
1231 mnt->flags |= NFS_MOUNT_NOCTO;
1234 mnt->flags &= ~NFS_MOUNT_NOAC;
1237 mnt->flags |= NFS_MOUNT_NOAC;
1240 mnt->flags &= ~NFS_MOUNT_NONLM;
1241 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1242 NFS_MOUNT_LOCAL_FCNTL);
1245 mnt->flags |= NFS_MOUNT_NONLM;
1246 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1247 NFS_MOUNT_LOCAL_FCNTL);
1250 mnt->flags &= ~NFS_MOUNT_TCP;
1251 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1254 mnt->flags |= NFS_MOUNT_TCP;
1255 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1258 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1259 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1260 xprt_load_transport(p);
1263 mnt->flags &= ~NFS_MOUNT_NOACL;
1266 mnt->flags |= NFS_MOUNT_NOACL;
1269 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1271 case Opt_nordirplus:
1272 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1274 case Opt_sharecache:
1275 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1277 case Opt_nosharecache:
1278 mnt->flags |= NFS_MOUNT_UNSHARED;
1281 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1283 case Opt_noresvport:
1284 mnt->flags |= NFS_MOUNT_NORESVPORT;
1287 mnt->options |= NFS_OPTION_FSCACHE;
1288 kfree(mnt->fscache_uniq);
1289 mnt->fscache_uniq = NULL;
1292 mnt->options &= ~NFS_OPTION_FSCACHE;
1293 kfree(mnt->fscache_uniq);
1294 mnt->fscache_uniq = NULL;
1298 * options that take numeric values
1301 if (nfs_get_option_ul(args, &option) ||
1303 goto out_invalid_value;
1304 mnt->nfs_server.port = option;
1307 if (nfs_get_option_ul(args, &option))
1308 goto out_invalid_value;
1309 mnt->rsize = option;
1312 if (nfs_get_option_ul(args, &option))
1313 goto out_invalid_value;
1314 mnt->wsize = option;
1317 if (nfs_get_option_ul(args, &option))
1318 goto out_invalid_value;
1319 mnt->bsize = option;
1322 if (nfs_get_option_ul(args, &option) || option == 0)
1323 goto out_invalid_value;
1324 mnt->timeo = option;
1327 if (nfs_get_option_ul(args, &option) || option == 0)
1328 goto out_invalid_value;
1329 mnt->retrans = option;
1332 if (nfs_get_option_ul(args, &option))
1333 goto out_invalid_value;
1334 mnt->acregmin = option;
1337 if (nfs_get_option_ul(args, &option))
1338 goto out_invalid_value;
1339 mnt->acregmax = option;
1342 if (nfs_get_option_ul(args, &option))
1343 goto out_invalid_value;
1344 mnt->acdirmin = option;
1347 if (nfs_get_option_ul(args, &option))
1348 goto out_invalid_value;
1349 mnt->acdirmax = option;
1352 if (nfs_get_option_ul(args, &option))
1353 goto out_invalid_value;
1354 mnt->acregmin = mnt->acregmax =
1355 mnt->acdirmin = mnt->acdirmax = option;
1358 if (nfs_get_option_ul(args, &option))
1359 goto out_invalid_value;
1360 mnt->namlen = option;
1363 if (nfs_get_option_ul(args, &option) ||
1365 goto out_invalid_value;
1366 mnt->mount_server.port = option;
1369 if (nfs_get_option_ul(args, &option) ||
1370 option < NFS_MNT_VERSION ||
1371 option > NFS_MNT3_VERSION)
1372 goto out_invalid_value;
1373 mnt->mount_server.version = option;
1375 case Opt_minorversion:
1376 if (nfs_get_option_ul(args, &option))
1377 goto out_invalid_value;
1378 if (option > NFS4_MAX_MINOR_VERSION)
1379 goto out_invalid_value;
1380 mnt->minorversion = option;
1384 * options that take text values
1387 string = match_strdup(args);
1390 rc = nfs_parse_version_string(string, mnt, args);
1393 goto out_invalid_value;
1396 string = match_strdup(args);
1399 rc = nfs_parse_security_flavors(string, mnt);
1402 dfprintk(MOUNT, "NFS: unrecognized "
1403 "security flavor\n");
1408 string = match_strdup(args);
1411 token = match_token(string,
1412 nfs_xprt_protocol_tokens, args);
1414 protofamily = AF_INET;
1417 protofamily = AF_INET6;
1419 mnt->flags &= ~NFS_MOUNT_TCP;
1420 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1423 protofamily = AF_INET6;
1425 mnt->flags |= NFS_MOUNT_TCP;
1426 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1429 /* vector side protocols to TCP */
1430 mnt->flags |= NFS_MOUNT_TCP;
1431 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1432 xprt_load_transport(string);
1435 dfprintk(MOUNT, "NFS: unrecognized "
1436 "transport protocol\n");
1442 case Opt_mountproto:
1443 string = match_strdup(args);
1446 token = match_token(string,
1447 nfs_xprt_protocol_tokens, args);
1450 mountfamily = AF_INET;
1453 mountfamily = AF_INET6;
1455 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
1458 mountfamily = AF_INET6;
1460 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
1462 case Opt_xprt_rdma: /* not used for side protocols */
1464 dfprintk(MOUNT, "NFS: unrecognized "
1465 "transport protocol\n");
1470 string = match_strdup(args);
1473 mnt->nfs_server.addrlen =
1474 rpc_pton(mnt->net, string, strlen(string),
1476 &mnt->nfs_server.address,
1477 sizeof(mnt->nfs_server.address));
1479 if (mnt->nfs_server.addrlen == 0)
1480 goto out_invalid_address;
1482 case Opt_clientaddr:
1483 if (nfs_get_option_str(args, &mnt->client_address))
1487 if (nfs_get_option_str(args,
1488 &mnt->mount_server.hostname))
1492 string = match_strdup(args);
1495 mnt->mount_server.addrlen =
1496 rpc_pton(mnt->net, string, strlen(string),
1498 &mnt->mount_server.address,
1499 sizeof(mnt->mount_server.address));
1501 if (mnt->mount_server.addrlen == 0)
1502 goto out_invalid_address;
1504 case Opt_lookupcache:
1505 string = match_strdup(args);
1508 token = match_token(string,
1509 nfs_lookupcache_tokens, args);
1512 case Opt_lookupcache_all:
1513 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1515 case Opt_lookupcache_positive:
1516 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1517 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1519 case Opt_lookupcache_none:
1520 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1523 dfprintk(MOUNT, "NFS: invalid "
1524 "lookupcache argument\n");
1528 case Opt_fscache_uniq:
1529 if (nfs_get_option_str(args, &mnt->fscache_uniq))
1531 mnt->options |= NFS_OPTION_FSCACHE;
1533 case Opt_local_lock:
1534 string = match_strdup(args);
1537 token = match_token(string, nfs_local_lock_tokens,
1541 case Opt_local_lock_all:
1542 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1543 NFS_MOUNT_LOCAL_FCNTL);
1545 case Opt_local_lock_flock:
1546 mnt->flags |= NFS_MOUNT_LOCAL_FLOCK;
1548 case Opt_local_lock_posix:
1549 mnt->flags |= NFS_MOUNT_LOCAL_FCNTL;
1551 case Opt_local_lock_none:
1552 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1553 NFS_MOUNT_LOCAL_FCNTL);
1556 dfprintk(MOUNT, "NFS: invalid "
1557 "local_lock argument\n");
1567 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1570 case Opt_deprecated:
1571 dfprintk(MOUNT, "NFS: ignoring mount option "
1577 dfprintk(MOUNT, "NFS: unrecognized mount option "
1582 if (!sloppy && invalid_option)
1585 if (mnt->minorversion && mnt->version != 4)
1586 goto out_minorversion_mismatch;
1589 * verify that any proto=/mountproto= options match the address
1590 * familiies in the addr=/mountaddr= options.
1592 if (protofamily != AF_UNSPEC &&
1593 protofamily != mnt->nfs_server.address.ss_family)
1594 goto out_proto_mismatch;
1596 if (mountfamily != AF_UNSPEC) {
1597 if (mnt->mount_server.addrlen) {
1598 if (mountfamily != mnt->mount_server.address.ss_family)
1599 goto out_mountproto_mismatch;
1601 if (mountfamily != mnt->nfs_server.address.ss_family)
1602 goto out_mountproto_mismatch;
1608 out_mountproto_mismatch:
1609 printk(KERN_INFO "NFS: mount server address does not match mountproto= "
1613 printk(KERN_INFO "NFS: server address does not match proto= option\n");
1615 out_invalid_address:
1616 printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
1619 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
1621 out_minorversion_mismatch:
1622 printk(KERN_INFO "NFS: mount option vers=%u does not support "
1623 "minorversion=%u\n", mnt->version, mnt->minorversion);
1626 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1628 out_security_failure:
1629 free_secdata(secdata);
1630 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1635 * Match the requested auth flavors with the list returned by
1636 * the server. Returns zero and sets the mount's authentication
1637 * flavor on success; returns -EACCES if server does not support
1638 * the requested flavor.
1640 static int nfs_walk_authlist(struct nfs_parsed_mount_data *args,
1641 struct nfs_mount_request *request)
1643 unsigned int i, j, server_authlist_len = *(request->auth_flav_len);
1646 * Certain releases of Linux's mountd return an empty
1647 * flavor list. To prevent behavioral regression with
1648 * these servers (ie. rejecting mounts that used to
1649 * succeed), revert to pre-2.6.32 behavior (no checking)
1650 * if the returned flavor list is empty.
1652 if (server_authlist_len == 0)
1656 * We avoid sophisticated negotiating here, as there are
1657 * plenty of cases where we can get it wrong, providing
1658 * either too little or too much security.
1660 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1661 * flavor listed first. However, some servers list
1662 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1663 * preferred default, in args->auth_flavors[0] if user
1664 * didn't specify sec= mount option.
1666 for (i = 0; i < args->auth_flavor_len; i++)
1667 for (j = 0; j < server_authlist_len; j++)
1668 if (args->auth_flavors[i] == request->auth_flavs[j]) {
1669 dfprintk(MOUNT, "NFS: using auth flavor %d\n",
1670 request->auth_flavs[j]);
1671 args->auth_flavors[0] = request->auth_flavs[j];
1675 dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n");
1676 nfs_umount(request);
1681 * Use the remote server's MOUNT service to request the NFS file handle
1682 * corresponding to the provided path.
1684 static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1685 struct nfs_fh *root_fh)
1687 rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS];
1688 unsigned int server_authlist_len = ARRAY_SIZE(server_authlist);
1689 struct nfs_mount_request request = {
1690 .sap = (struct sockaddr *)
1691 &args->mount_server.address,
1692 .dirpath = args->nfs_server.export_path,
1693 .protocol = args->mount_server.protocol,
1695 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
1696 .auth_flav_len = &server_authlist_len,
1697 .auth_flavs = server_authlist,
1702 if (args->mount_server.version == 0) {
1703 switch (args->version) {
1705 args->mount_server.version = NFS_MNT3_VERSION;
1708 args->mount_server.version = NFS_MNT_VERSION;
1711 request.version = args->mount_server.version;
1713 if (args->mount_server.hostname)
1714 request.hostname = args->mount_server.hostname;
1716 request.hostname = args->nfs_server.hostname;
1719 * Construct the mount server's address.
1721 if (args->mount_server.address.ss_family == AF_UNSPEC) {
1722 memcpy(request.sap, &args->nfs_server.address,
1723 args->nfs_server.addrlen);
1724 args->mount_server.addrlen = args->nfs_server.addrlen;
1726 request.salen = args->mount_server.addrlen;
1727 nfs_set_port(request.sap, &args->mount_server.port, 0);
1730 * Now ask the mount server to map our export path
1733 status = nfs_mount(&request);
1735 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1736 request.hostname, status);
1741 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1743 if (args->mount_server.version != NFS_MNT3_VERSION)
1745 return nfs_walk_authlist(args, &request);
1749 * Split "dev_name" into "hostname:export_path".
1751 * The leftmost colon demarks the split between the server's hostname
1752 * and the export path. If the hostname starts with a left square
1753 * bracket, then it may contain colons.
1755 * Note: caller frees hostname and export path, even on error.
1757 static int nfs_parse_devname(const char *dev_name,
1758 char **hostname, size_t maxnamlen,
1759 char **export_path, size_t maxpathlen)
1764 /* Is the host name protected with square brakcets? */
1765 if (*dev_name == '[') {
1766 end = strchr(++dev_name, ']');
1767 if (end == NULL || end[1] != ':')
1768 goto out_bad_devname;
1770 len = end - dev_name;
1775 end = strchr(dev_name, ':');
1777 goto out_bad_devname;
1778 len = end - dev_name;
1780 /* kill possible hostname list: not supported */
1781 comma = strchr(dev_name, ',');
1782 if (comma != NULL && comma < end)
1786 if (len > maxnamlen)
1789 /* N.B. caller will free nfs_server.hostname in all cases */
1790 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
1791 if (*hostname == NULL)
1793 len = strlen(++end);
1794 if (len > maxpathlen)
1796 *export_path = kstrndup(end, len, GFP_KERNEL);
1800 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1804 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1808 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1812 dfprintk(MOUNT, "NFS: server hostname too long\n");
1813 return -ENAMETOOLONG;
1816 dfprintk(MOUNT, "NFS: export pathname too long\n");
1817 return -ENAMETOOLONG;
1821 * Validate the NFS2/NFS3 mount data
1822 * - fills in the mount root filehandle
1824 * For option strings, user space handles the following behaviors:
1826 * + DNS: mapping server host name to IP address ("addr=" option)
1828 * + failure mode: how to behave if a mount request can't be handled
1829 * immediately ("fg/bg" option)
1831 * + retry: how often to retry a mount request ("retry=" option)
1833 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1834 * mountproto=tcp after mountproto=udp, and so on
1836 static int nfs_validate_mount_data(void *options,
1837 struct nfs_parsed_mount_data *args,
1838 struct nfs_fh *mntfh,
1839 const char *dev_name)
1841 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
1842 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
1847 switch (data->version) {
1853 if (data->flags & NFS_MOUNT_VER3)
1855 data->root.size = NFS2_FHSIZE;
1856 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1858 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1861 memset(data->context, 0, sizeof(data->context));
1863 if (data->flags & NFS_MOUNT_VER3) {
1864 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1865 goto out_invalid_fh;
1866 mntfh->size = data->root.size;
1869 mntfh->size = NFS2_FHSIZE;
1874 memcpy(mntfh->data, data->root.data, mntfh->size);
1875 if (mntfh->size < sizeof(mntfh->data))
1876 memset(mntfh->data + mntfh->size, 0,
1877 sizeof(mntfh->data) - mntfh->size);
1880 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1883 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
1884 args->flags |= NFS_MOUNT_LEGACY_INTERFACE;
1885 args->rsize = data->rsize;
1886 args->wsize = data->wsize;
1887 args->timeo = data->timeo;
1888 args->retrans = data->retrans;
1889 args->acregmin = data->acregmin;
1890 args->acregmax = data->acregmax;
1891 args->acdirmin = data->acdirmin;
1892 args->acdirmax = data->acdirmax;
1894 memcpy(sap, &data->addr, sizeof(data->addr));
1895 args->nfs_server.addrlen = sizeof(data->addr);
1896 if (!nfs_verify_server_address(sap))
1897 goto out_no_address;
1899 if (!(data->flags & NFS_MOUNT_TCP))
1900 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1901 /* N.B. caller will free nfs_server.hostname in all cases */
1902 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1903 args->namlen = data->namlen;
1904 args->bsize = data->bsize;
1906 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1907 args->auth_flavors[0] = data->pseudoflavor;
1908 if (!args->nfs_server.hostname)
1911 if (!(data->flags & NFS_MOUNT_NONLM))
1912 args->flags &= ~(NFS_MOUNT_LOCAL_FLOCK|
1913 NFS_MOUNT_LOCAL_FCNTL);
1915 args->flags |= (NFS_MOUNT_LOCAL_FLOCK|
1916 NFS_MOUNT_LOCAL_FCNTL);
1918 * The legacy version 6 binary mount data from userspace has a
1919 * field used only to transport selinux information into the
1920 * the kernel. To continue to support that functionality we
1921 * have a touch of selinux knowledge here in the NFS code. The
1922 * userspace code converted context=blah to just blah so we are
1923 * converting back to the full string selinux understands.
1925 if (data->context[0]){
1926 #ifdef CONFIG_SECURITY_SELINUX
1928 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1931 strcpy(opts_str, "context=");
1932 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1933 strcat(opts_str, &data->context[0]);
1934 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1947 if (nfs_parse_mount_options((char *)options, args) == 0)
1950 if (!nfs_verify_server_address(sap))
1951 goto out_no_address;
1953 if (args->version == 4)
1954 #ifdef CONFIG_NFS_V4
1955 return nfs4_validate_text_mount_data(options,
1958 goto out_v4_not_compiled;
1961 nfs_set_port(sap, &args->nfs_server.port, 0);
1963 nfs_set_mount_transport_protocol(args);
1965 status = nfs_parse_devname(dev_name,
1966 &args->nfs_server.hostname,
1968 &args->nfs_server.export_path,
1971 status = nfs_try_mount(args, mntfh);
1973 kfree(args->nfs_server.export_path);
1974 args->nfs_server.export_path = NULL;
1983 #ifndef CONFIG_NFS_V3
1984 if (args->version == 3)
1985 goto out_v3_not_compiled;
1986 #endif /* !CONFIG_NFS_V3 */
1991 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1995 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
2000 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
2003 #ifndef CONFIG_NFS_V3
2004 out_v3_not_compiled:
2005 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
2006 return -EPROTONOSUPPORT;
2007 #endif /* !CONFIG_NFS_V3 */
2009 #ifndef CONFIG_NFS_V4
2010 out_v4_not_compiled:
2011 dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n");
2012 return -EPROTONOSUPPORT;
2013 #endif /* !CONFIG_NFS_V4 */
2016 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
2020 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
2024 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
2029 nfs_compare_remount_data(struct nfs_server *nfss,
2030 struct nfs_parsed_mount_data *data)
2032 if (data->flags != nfss->flags ||
2033 data->rsize != nfss->rsize ||
2034 data->wsize != nfss->wsize ||
2035 data->retrans != nfss->client->cl_timeout->to_retries ||
2036 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
2037 data->acregmin != nfss->acregmin / HZ ||
2038 data->acregmax != nfss->acregmax / HZ ||
2039 data->acdirmin != nfss->acdirmin / HZ ||
2040 data->acdirmax != nfss->acdirmax / HZ ||
2041 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
2042 data->nfs_server.port != nfss->port ||
2043 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
2044 !rpc_cmp_addr((struct sockaddr *)&data->nfs_server.address,
2045 (struct sockaddr *)&nfss->nfs_client->cl_addr))
2052 nfs_remount(struct super_block *sb, int *flags, char *raw_data)
2055 struct nfs_server *nfss = sb->s_fs_info;
2056 struct nfs_parsed_mount_data *data;
2057 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
2058 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
2059 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
2062 * Userspace mount programs that send binary options generally send
2063 * them populated with default values. We have no way to know which
2064 * ones were explicitly specified. Fall back to legacy behavior and
2065 * just return success.
2067 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
2068 (nfsvers <= 3 && (!options || (options->version >= 1 &&
2069 options->version <= 6))))
2072 data = kzalloc(sizeof(*data), GFP_KERNEL);
2076 /* fill out struct with values from existing mount */
2077 data->flags = nfss->flags;
2078 data->rsize = nfss->rsize;
2079 data->wsize = nfss->wsize;
2080 data->retrans = nfss->client->cl_timeout->to_retries;
2081 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
2082 data->acregmin = nfss->acregmin / HZ;
2083 data->acregmax = nfss->acregmax / HZ;
2084 data->acdirmin = nfss->acdirmin / HZ;
2085 data->acdirmax = nfss->acdirmax / HZ;
2086 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
2087 data->nfs_server.port = nfss->port;
2088 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
2089 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
2090 data->nfs_server.addrlen);
2092 /* overwrite those values with any that were specified */
2093 error = nfs_parse_mount_options((char *)options, data);
2098 * noac is a special case. It implies -o sync, but that's not
2099 * necessarily reflected in the mtab options. do_remount_sb
2100 * will clear MS_SYNCHRONOUS if -o sync wasn't specified in the
2101 * remount options, so we have to explicitly reset it.
2103 if (data->flags & NFS_MOUNT_NOAC)
2104 *flags |= MS_SYNCHRONOUS;
2106 /* compare new mount options with old ones */
2107 error = nfs_compare_remount_data(nfss, data);
2114 * Initialise the common bits of the superblock
2116 static inline void nfs_initialise_sb(struct super_block *sb)
2118 struct nfs_server *server = NFS_SB(sb);
2120 sb->s_magic = NFS_SUPER_MAGIC;
2122 /* We probably want something more informative here */
2123 snprintf(sb->s_id, sizeof(sb->s_id),
2124 "%u:%u", MAJOR(sb->s_dev), MINOR(sb->s_dev));
2126 if (sb->s_blocksize == 0)
2127 sb->s_blocksize = nfs_block_bits(server->wsize,
2128 &sb->s_blocksize_bits);
2130 sb->s_bdi = &server->backing_dev_info;
2132 nfs_super_set_maxbytes(sb, server->maxfilesize);
2136 * Finish setting up an NFS2/3 superblock
2138 static void nfs_fill_super(struct super_block *sb,
2139 struct nfs_mount_info *mount_info)
2141 struct nfs_parsed_mount_data *data = mount_info->parsed;
2142 struct nfs_server *server = NFS_SB(sb);
2144 sb->s_blocksize_bits = 0;
2145 sb->s_blocksize = 0;
2147 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
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 = &nfs_sops;
2158 nfs_initialise_sb(sb);
2162 * Finish setting up a cloned NFS2/3 superblock
2164 static void nfs_clone_super(struct super_block *sb,
2165 struct nfs_mount_info *mount_info)
2167 const struct super_block *old_sb = mount_info->cloned->sb;
2168 struct nfs_server *server = NFS_SB(sb);
2170 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2171 sb->s_blocksize = old_sb->s_blocksize;
2172 sb->s_maxbytes = old_sb->s_maxbytes;
2174 if (server->nfs_client->rpc_ops->version == 3) {
2175 /* The VFS shouldn't apply the umask to mode bits. We will do
2176 * so ourselves when necessary.
2178 sb->s_flags |= MS_POSIXACL;
2179 sb->s_time_gran = 1;
2182 sb->s_op = old_sb->s_op;
2183 nfs_initialise_sb(sb);
2186 static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
2188 const struct nfs_server *a = s->s_fs_info;
2189 const struct rpc_clnt *clnt_a = a->client;
2190 const struct rpc_clnt *clnt_b = b->client;
2192 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
2194 if (a->nfs_client != b->nfs_client)
2196 if (a->flags != b->flags)
2198 if (a->wsize != b->wsize)
2200 if (a->rsize != b->rsize)
2202 if (a->acregmin != b->acregmin)
2204 if (a->acregmax != b->acregmax)
2206 if (a->acdirmin != b->acdirmin)
2208 if (a->acdirmax != b->acdirmax)
2210 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
2217 struct nfs_sb_mountdata {
2218 struct nfs_server *server;
2222 static int nfs_set_super(struct super_block *s, void *data)
2224 struct nfs_sb_mountdata *sb_mntdata = data;
2225 struct nfs_server *server = sb_mntdata->server;
2228 s->s_flags = sb_mntdata->mntflags;
2229 s->s_fs_info = server;
2230 s->s_d_op = server->nfs_client->rpc_ops->dentry_ops;
2231 ret = set_anon_super(s, server);
2233 server->s_dev = s->s_dev;
2237 static int nfs_compare_super_address(struct nfs_server *server1,
2238 struct nfs_server *server2)
2240 struct sockaddr *sap1, *sap2;
2242 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
2243 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
2245 if (sap1->sa_family != sap2->sa_family)
2248 switch (sap1->sa_family) {
2250 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
2251 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
2252 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
2254 if (sin1->sin_port != sin2->sin_port)
2259 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
2260 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
2261 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
2263 if (sin1->sin6_port != sin2->sin6_port)
2274 static int nfs_compare_super(struct super_block *sb, void *data)
2276 struct nfs_sb_mountdata *sb_mntdata = data;
2277 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2278 int mntflags = sb_mntdata->mntflags;
2280 if (!nfs_compare_super_address(old, server))
2282 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2283 if (old->flags & NFS_MOUNT_UNSHARED)
2285 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2287 return nfs_compare_mount_options(sb, server, mntflags);
2290 static void nfs_get_cache_cookie(struct super_block *sb,
2291 struct nfs_parsed_mount_data *parsed,
2292 struct nfs_clone_mount *cloned)
2297 if (parsed && parsed->fscache_uniq) {
2298 uniq = parsed->fscache_uniq;
2299 ulen = strlen(parsed->fscache_uniq);
2300 } else if (cloned) {
2301 struct nfs_server *mnt_s = NFS_SB(cloned->sb);
2302 if (mnt_s->fscache_key) {
2303 uniq = mnt_s->fscache_key->key.uniquifier;
2304 ulen = mnt_s->fscache_key->key.uniq_len;
2308 nfs_fscache_get_super_cookie(sb, uniq, ulen);
2311 static int nfs_bdi_register(struct nfs_server *server)
2313 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
2316 static int nfs_set_sb_security(struct super_block *s, struct dentry *mntroot,
2317 struct nfs_mount_info *mount_info)
2319 return security_sb_set_mnt_opts(s, &mount_info->parsed->lsm_opts);
2322 static int nfs_clone_sb_security(struct super_block *s, struct dentry *mntroot,
2323 struct nfs_mount_info *mount_info)
2325 /* clone any lsm security options from the parent to the new sb */
2326 security_sb_clone_mnt_opts(mount_info->cloned->sb, s);
2327 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops)
2332 static struct dentry *nfs_fs_mount_common(struct file_system_type *fs_type,
2333 struct nfs_server *server,
2334 int flags, const char *dev_name,
2335 struct nfs_fh *mntfh,
2336 struct nfs_mount_info *mount_info)
2338 struct super_block *s;
2339 struct dentry *mntroot = ERR_PTR(-ENOMEM);
2340 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2341 struct nfs_sb_mountdata sb_mntdata = {
2347 if (server->flags & NFS_MOUNT_UNSHARED)
2348 compare_super = NULL;
2350 /* -o noac implies -o sync */
2351 if (server->flags & NFS_MOUNT_NOAC)
2352 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2354 /* Get a superblock - note that we may end up sharing one that already exists */
2355 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
2357 mntroot = ERR_CAST(s);
2361 if (s->s_fs_info != server) {
2362 nfs_free_server(server);
2365 error = nfs_bdi_register(server);
2367 mntroot = ERR_PTR(error);
2368 goto error_splat_bdi;
2373 /* initial superblock/root creation */
2374 mount_info->fill_super(s, mount_info);
2375 nfs_get_cache_cookie(s, mount_info->parsed, mount_info->cloned);
2378 mntroot = nfs_get_root(s, mntfh, dev_name);
2379 if (IS_ERR(mntroot))
2380 goto error_splat_super;
2382 error = mount_info->set_security(s, mntroot, mount_info);
2384 goto error_splat_root;
2386 s->s_flags |= MS_ACTIVE;
2392 nfs_free_server(server);
2397 mntroot = ERR_PTR(error);
2399 if (server && !s->s_root)
2400 bdi_unregister(&server->backing_dev_info);
2402 deactivate_locked_super(s);
2406 static struct dentry *nfs_fs_mount(struct file_system_type *fs_type,
2407 int flags, const char *dev_name, void *raw_data)
2409 struct nfs_server *server;
2410 struct nfs_parsed_mount_data *data = NULL;
2411 struct nfs_mount_info mount_info = {
2412 .fill_super = nfs_fill_super,
2413 .set_security = nfs_set_sb_security,
2415 struct nfs_fh *mntfh;
2416 struct dentry *mntroot = ERR_PTR(-ENOMEM);
2419 data = nfs_alloc_parsed_mount_data(NFS_DEFAULT_VERSION);
2420 mntfh = nfs_alloc_fhandle();
2421 if (data == NULL || mntfh == NULL)
2424 /* Validate the mount data */
2425 error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
2427 mntroot = ERR_PTR(error);
2430 mount_info.parsed = data;
2432 #ifdef CONFIG_NFS_V4
2433 if (data->version == 4) {
2434 mntroot = nfs4_try_mount(flags, dev_name, data);
2437 #endif /* CONFIG_NFS_V4 */
2439 /* Get a volume representation */
2440 server = nfs_create_server(data, mntfh);
2441 if (IS_ERR(server)) {
2442 mntroot = ERR_CAST(server);
2446 mntroot = nfs_fs_mount_common(fs_type, server, flags, dev_name, mntfh, &mount_info);
2448 nfs_free_parsed_mount_data(data);
2449 nfs_free_fhandle(mntfh);
2454 * Ensure that we unregister the bdi before kill_anon_super
2455 * releases the device name
2457 static void nfs_put_super(struct super_block *s)
2459 struct nfs_server *server = NFS_SB(s);
2461 bdi_unregister(&server->backing_dev_info);
2465 * Destroy an NFS2/3 superblock
2467 static void nfs_kill_super(struct super_block *s)
2469 struct nfs_server *server = NFS_SB(s);
2472 nfs_fscache_release_super_cookie(s);
2473 nfs_free_server(server);
2477 * Clone an NFS2/3/4 server record on xdev traversal (FSID-change)
2479 static struct dentry *
2480 nfs_xdev_mount_common(struct file_system_type *fs_type, int flags,
2481 const char *dev_name, struct nfs_mount_info *mount_info)
2483 struct nfs_clone_mount *data = mount_info->cloned;
2484 struct nfs_server *server;
2485 struct dentry *mntroot = ERR_PTR(-ENOMEM);
2488 dprintk("--> nfs_xdev_mount_common()\n");
2490 /* create a new volume representation */
2491 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr, data->authflavor);
2492 if (IS_ERR(server)) {
2493 error = PTR_ERR(server);
2497 mntroot = nfs_fs_mount_common(fs_type, server, flags, dev_name, data->fh, mount_info);
2498 dprintk("<-- nfs_xdev_mount_common() = 0\n");
2503 dprintk("<-- nfs_xdev_mount_common() = %d [error]\n", error);
2508 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2510 static struct dentry *
2511 nfs_xdev_mount(struct file_system_type *fs_type, int flags,
2512 const char *dev_name, void *raw_data)
2514 struct nfs_mount_info mount_info = {
2515 .fill_super = nfs_clone_super,
2516 .set_security = nfs_clone_sb_security,
2519 return nfs_xdev_mount_common(&nfs_fs_type, flags, dev_name, &mount_info);
2522 #ifdef CONFIG_NFS_V4
2525 * Finish setting up a cloned NFS4 superblock
2527 static void nfs4_clone_super(struct super_block *sb,
2528 struct nfs_mount_info *mount_info)
2530 const struct super_block *old_sb = mount_info->cloned->sb;
2531 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2532 sb->s_blocksize = old_sb->s_blocksize;
2533 sb->s_maxbytes = old_sb->s_maxbytes;
2534 sb->s_time_gran = 1;
2535 sb->s_op = old_sb->s_op;
2537 * The VFS shouldn't apply the umask to mode bits. We will do
2538 * so ourselves when necessary.
2540 sb->s_flags |= MS_POSIXACL;
2541 sb->s_xattr = old_sb->s_xattr;
2542 nfs_initialise_sb(sb);
2546 * Set up an NFS4 superblock
2548 static void nfs4_fill_super(struct super_block *sb,
2549 struct nfs_mount_info *mount_info)
2551 sb->s_time_gran = 1;
2552 sb->s_op = &nfs4_sops;
2554 * The VFS shouldn't apply the umask to mode bits. We will do
2555 * so ourselves when necessary.
2557 sb->s_flags |= MS_POSIXACL;
2558 sb->s_xattr = nfs4_xattr_handlers;
2559 nfs_initialise_sb(sb);
2562 static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2564 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3|
2565 NFS_MOUNT_LOCAL_FLOCK|NFS_MOUNT_LOCAL_FCNTL);
2568 static int nfs4_validate_text_mount_data(void *options,
2569 struct nfs_parsed_mount_data *args,
2570 const char *dev_name)
2572 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2574 nfs_set_port(sap, &args->nfs_server.port, NFS_PORT);
2576 nfs_validate_transport_protocol(args);
2578 nfs4_validate_mount_flags(args);
2580 if (args->version != 4) {
2582 "NFS4: Illegal mount version\n");
2586 if (args->auth_flavor_len > 1) {
2588 "NFS4: Too many RPC auth flavours specified\n");
2592 return nfs_parse_devname(dev_name,
2593 &args->nfs_server.hostname,
2595 &args->nfs_server.export_path,
2600 * Validate NFSv4 mount options
2602 static int nfs4_validate_mount_data(void *options,
2603 struct nfs_parsed_mount_data *args,
2604 const char *dev_name)
2606 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2607 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
2613 switch (data->version) {
2615 if (data->host_addrlen > sizeof(args->nfs_server.address))
2616 goto out_no_address;
2617 if (data->host_addrlen == 0)
2618 goto out_no_address;
2619 args->nfs_server.addrlen = data->host_addrlen;
2620 if (copy_from_user(sap, data->host_addr, data->host_addrlen))
2622 if (!nfs_verify_server_address(sap))
2623 goto out_no_address;
2625 if (data->auth_flavourlen) {
2626 if (data->auth_flavourlen > 1)
2627 goto out_inval_auth;
2628 if (copy_from_user(&args->auth_flavors[0],
2629 data->auth_flavours,
2630 sizeof(args->auth_flavors[0])))
2634 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2637 args->nfs_server.hostname = c;
2639 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2642 args->nfs_server.export_path = c;
2643 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
2645 c = strndup_user(data->client_addr.data, 16);
2648 args->client_address = c;
2651 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2655 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2656 args->rsize = data->rsize;
2657 args->wsize = data->wsize;
2658 args->timeo = data->timeo;
2659 args->retrans = data->retrans;
2660 args->acregmin = data->acregmin;
2661 args->acregmax = data->acregmax;
2662 args->acdirmin = data->acdirmin;
2663 args->acdirmax = data->acdirmax;
2664 args->nfs_server.protocol = data->proto;
2665 nfs_validate_transport_protocol(args);
2669 if (nfs_parse_mount_options((char *)options, args) == 0)
2672 if (!nfs_verify_server_address(sap))
2675 return nfs4_validate_text_mount_data(options, args, dev_name);
2681 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2685 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2686 data->auth_flavourlen);
2690 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2695 * Get the superblock for the NFS4 root partition
2697 static struct dentry *
2698 nfs4_remote_mount(struct file_system_type *fs_type, int flags,
2699 const char *dev_name, void *raw_data)
2701 struct nfs_mount_info mount_info = {
2702 .fill_super = nfs4_fill_super,
2703 .set_security = nfs_set_sb_security,
2706 struct nfs_server *server;
2707 struct nfs_fh *mntfh;
2708 struct dentry *mntroot = ERR_PTR(-ENOMEM);
2710 mntfh = nfs_alloc_fhandle();
2711 if (mount_info.parsed == NULL || mntfh == NULL)
2714 /* Get a volume representation */
2715 server = nfs4_create_server(mount_info.parsed, mntfh);
2716 if (IS_ERR(server)) {
2717 mntroot = ERR_CAST(server);
2721 mntroot = nfs_fs_mount_common(fs_type, server, flags,
2722 dev_name, mntfh, &mount_info);
2725 nfs_free_fhandle(mntfh);
2729 static struct vfsmount *nfs_do_root_mount(struct file_system_type *fs_type,
2730 int flags, void *data, const char *hostname)
2732 struct vfsmount *root_mnt;
2736 len = strlen(hostname) + 5;
2737 root_devname = kmalloc(len, GFP_KERNEL);
2738 if (root_devname == NULL)
2739 return ERR_PTR(-ENOMEM);
2740 /* Does hostname needs to be enclosed in brackets? */
2741 if (strchr(hostname, ':'))
2742 snprintf(root_devname, len, "[%s]:/", hostname);
2744 snprintf(root_devname, len, "%s:/", hostname);
2745 root_mnt = vfs_kern_mount(fs_type, flags, root_devname, data);
2746 kfree(root_devname);
2750 struct nfs_referral_count {
2751 struct list_head list;
2752 const struct task_struct *task;
2753 unsigned int referral_count;
2756 static LIST_HEAD(nfs_referral_count_list);
2757 static DEFINE_SPINLOCK(nfs_referral_count_list_lock);
2759 static struct nfs_referral_count *nfs_find_referral_count(void)
2761 struct nfs_referral_count *p;
2763 list_for_each_entry(p, &nfs_referral_count_list, list) {
2764 if (p->task == current)
2770 #define NFS_MAX_NESTED_REFERRALS 2
2772 static int nfs_referral_loop_protect(void)
2774 struct nfs_referral_count *p, *new;
2777 new = kmalloc(sizeof(*new), GFP_KERNEL);
2780 new->task = current;
2781 new->referral_count = 1;
2784 spin_lock(&nfs_referral_count_list_lock);
2785 p = nfs_find_referral_count();
2787 if (p->referral_count >= NFS_MAX_NESTED_REFERRALS)
2790 p->referral_count++;
2792 list_add(&new->list, &nfs_referral_count_list);
2795 spin_unlock(&nfs_referral_count_list_lock);
2801 static void nfs_referral_loop_unprotect(void)
2803 struct nfs_referral_count *p;
2805 spin_lock(&nfs_referral_count_list_lock);
2806 p = nfs_find_referral_count();
2807 p->referral_count--;
2808 if (p->referral_count == 0)
2812 spin_unlock(&nfs_referral_count_list_lock);
2816 static struct dentry *nfs_follow_remote_path(struct vfsmount *root_mnt,
2817 const char *export_path)
2819 struct dentry *dentry;
2822 if (IS_ERR(root_mnt))
2823 return ERR_CAST(root_mnt);
2825 err = nfs_referral_loop_protect();
2828 return ERR_PTR(err);
2831 dentry = mount_subtree(root_mnt, export_path);
2832 nfs_referral_loop_unprotect();
2837 static struct dentry *nfs4_try_mount(int flags, const char *dev_name,
2838 struct nfs_parsed_mount_data *data)
2841 struct vfsmount *root_mnt;
2844 dfprintk(MOUNT, "--> nfs4_try_mount()\n");
2846 export_path = data->nfs_server.export_path;
2847 data->nfs_server.export_path = "/";
2848 root_mnt = nfs_do_root_mount(&nfs4_remote_fs_type, flags, data,
2849 data->nfs_server.hostname);
2850 data->nfs_server.export_path = export_path;
2852 res = nfs_follow_remote_path(root_mnt, export_path);
2854 dfprintk(MOUNT, "<-- nfs4_try_mount() = %ld%s\n",
2855 IS_ERR(res) ? PTR_ERR(res) : 0,
2856 IS_ERR(res) ? " [error]" : "");
2861 * Get the superblock for an NFS4 mountpoint
2863 static struct dentry *nfs4_mount(struct file_system_type *fs_type,
2864 int flags, const char *dev_name, void *raw_data)
2866 struct nfs_parsed_mount_data *data;
2867 int error = -ENOMEM;
2868 struct dentry *res = ERR_PTR(-ENOMEM);
2870 data = nfs_alloc_parsed_mount_data(4);
2874 /* Validate the mount data */
2875 error = nfs4_validate_mount_data(raw_data, data, dev_name);
2877 res = ERR_PTR(error);
2881 res = nfs4_try_mount(flags, dev_name, data);
2883 error = PTR_ERR(res);
2886 nfs_free_parsed_mount_data(data);
2887 dprintk("<-- nfs4_mount() = %d%s\n", error,
2888 error != 0 ? " [error]" : "");
2892 static void nfs4_kill_super(struct super_block *sb)
2894 struct nfs_server *server = NFS_SB(sb);
2896 dprintk("--> %s\n", __func__);
2897 nfs_super_return_all_delegations(sb);
2898 kill_anon_super(sb);
2899 nfs_fscache_release_super_cookie(sb);
2900 nfs_free_server(server);
2901 dprintk("<-- %s\n", __func__);
2905 * Clone an NFS4 server record on xdev traversal (FSID-change)
2907 static struct dentry *
2908 nfs4_xdev_mount(struct file_system_type *fs_type, int flags,
2909 const char *dev_name, void *raw_data)
2911 struct nfs_mount_info mount_info = {
2912 .fill_super = nfs4_clone_super,
2913 .set_security = nfs_clone_sb_security,
2916 return nfs_xdev_mount_common(&nfs4_fs_type, flags, dev_name, &mount_info);
2919 static struct dentry *
2920 nfs4_remote_referral_mount(struct file_system_type *fs_type, int flags,
2921 const char *dev_name, void *raw_data)
2923 struct nfs_clone_mount *data = raw_data;
2924 struct super_block *s;
2925 struct nfs_server *server;
2926 struct dentry *mntroot;
2927 struct nfs_fh *mntfh;
2928 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2929 struct nfs_sb_mountdata sb_mntdata = {
2932 int error = -ENOMEM;
2934 dprintk("--> nfs4_referral_get_sb()\n");
2936 mntfh = nfs_alloc_fhandle();
2940 /* create a new volume representation */
2941 server = nfs4_create_referral_server(data, mntfh);
2942 if (IS_ERR(server)) {
2943 error = PTR_ERR(server);
2944 goto out_err_noserver;
2946 sb_mntdata.server = server;
2948 if (server->flags & NFS_MOUNT_UNSHARED)
2949 compare_super = NULL;
2951 /* -o noac implies -o sync */
2952 if (server->flags & NFS_MOUNT_NOAC)
2953 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2955 /* Get a superblock - note that we may end up sharing one that already exists */
2956 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2962 if (s->s_fs_info != server) {
2963 nfs_free_server(server);
2966 error = nfs_bdi_register(server);
2968 goto error_splat_bdi;
2972 /* initial superblock/root creation */
2973 nfs4_fill_super(s, NULL);
2974 nfs_get_cache_cookie(s, NULL, data);
2977 mntroot = nfs_get_root(s, mntfh, dev_name);
2978 if (IS_ERR(mntroot)) {
2979 error = PTR_ERR(mntroot);
2980 goto error_splat_super;
2982 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2985 goto error_splat_super;
2988 s->s_flags |= MS_ACTIVE;
2990 security_sb_clone_mnt_opts(data->sb, s);
2992 nfs_free_fhandle(mntfh);
2993 dprintk("<-- nfs4_referral_get_sb() = 0\n");
2997 nfs_free_server(server);
2999 nfs_free_fhandle(mntfh);
3001 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
3002 return ERR_PTR(error);
3005 if (server && !s->s_root)
3006 bdi_unregister(&server->backing_dev_info);
3008 deactivate_locked_super(s);
3009 nfs_free_fhandle(mntfh);
3010 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
3011 return ERR_PTR(error);
3015 * Create an NFS4 server record on referral traversal
3017 static struct dentry *nfs4_referral_mount(struct file_system_type *fs_type,
3018 int flags, const char *dev_name, void *raw_data)
3020 struct nfs_clone_mount *data = raw_data;
3022 struct vfsmount *root_mnt;
3025 dprintk("--> nfs4_referral_mount()\n");
3027 export_path = data->mnt_path;
3028 data->mnt_path = "/";
3030 root_mnt = nfs_do_root_mount(&nfs4_remote_referral_fs_type,
3031 flags, data, data->hostname);
3032 data->mnt_path = export_path;
3034 res = nfs_follow_remote_path(root_mnt, export_path);
3035 dprintk("<-- nfs4_referral_mount() = %ld%s\n",
3036 IS_ERR(res) ? PTR_ERR(res) : 0,
3037 IS_ERR(res) ? " [error]" : "");
3041 #endif /* CONFIG_NFS_V4 */