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>
56 #include <asm/uaccess.h>
60 #include "delegation.h"
66 #define NFSDBG_FACILITY NFSDBG_VFS
69 #define NFS_DEFAULT_VERSION 3
71 #define NFS_DEFAULT_VERSION 2
75 /* Mount options that take no arguments */
77 Opt_posix, Opt_noposix,
81 Opt_v2, Opt_v3, Opt_v4,
82 Opt_udp, Opt_tcp, Opt_rdma,
84 Opt_rdirplus, Opt_nordirplus,
85 Opt_sharecache, Opt_nosharecache,
86 Opt_resvport, Opt_noresvport,
87 Opt_fscache, Opt_nofscache,
89 /* Mount options that take integer arguments */
91 Opt_rsize, Opt_wsize, Opt_bsize,
92 Opt_timeo, Opt_retrans,
93 Opt_acregmin, Opt_acregmax,
94 Opt_acdirmin, Opt_acdirmax,
102 /* Mount options that take string arguments */
103 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
104 Opt_addr, Opt_mountaddr, Opt_clientaddr,
109 /* Special mount options */
110 Opt_userspace, Opt_deprecated, Opt_sloppy,
115 static const match_table_t nfs_mount_option_tokens = {
116 { Opt_userspace, "bg" },
117 { Opt_userspace, "fg" },
118 { Opt_userspace, "retry=%s" },
120 { Opt_sloppy, "sloppy" },
122 { Opt_soft, "soft" },
123 { Opt_hard, "hard" },
124 { Opt_deprecated, "intr" },
125 { Opt_deprecated, "nointr" },
126 { Opt_posix, "posix" },
127 { Opt_noposix, "noposix" },
129 { Opt_nocto, "nocto" },
131 { Opt_noac, "noac" },
132 { Opt_lock, "lock" },
133 { Opt_nolock, "nolock" },
139 { Opt_rdma, "rdma" },
141 { Opt_noacl, "noacl" },
142 { Opt_rdirplus, "rdirplus" },
143 { Opt_nordirplus, "nordirplus" },
144 { Opt_sharecache, "sharecache" },
145 { Opt_nosharecache, "nosharecache" },
146 { Opt_resvport, "resvport" },
147 { Opt_noresvport, "noresvport" },
148 { Opt_fscache, "fsc" },
149 { Opt_nofscache, "nofsc" },
151 { Opt_port, "port=%s" },
152 { Opt_rsize, "rsize=%s" },
153 { Opt_wsize, "wsize=%s" },
154 { Opt_bsize, "bsize=%s" },
155 { Opt_timeo, "timeo=%s" },
156 { Opt_retrans, "retrans=%s" },
157 { Opt_acregmin, "acregmin=%s" },
158 { Opt_acregmax, "acregmax=%s" },
159 { Opt_acdirmin, "acdirmin=%s" },
160 { Opt_acdirmax, "acdirmax=%s" },
161 { Opt_actimeo, "actimeo=%s" },
162 { Opt_namelen, "namlen=%s" },
163 { Opt_mountport, "mountport=%s" },
164 { Opt_mountvers, "mountvers=%s" },
165 { Opt_nfsvers, "nfsvers=%s" },
166 { Opt_nfsvers, "vers=%s" },
167 { Opt_minorversion, "minorversion=%s" },
169 { Opt_sec, "sec=%s" },
170 { Opt_proto, "proto=%s" },
171 { Opt_mountproto, "mountproto=%s" },
172 { Opt_addr, "addr=%s" },
173 { Opt_clientaddr, "clientaddr=%s" },
174 { Opt_mounthost, "mounthost=%s" },
175 { Opt_mountaddr, "mountaddr=%s" },
177 { Opt_lookupcache, "lookupcache=%s" },
178 { Opt_fscache_uniq, "fsc=%s" },
179 { Opt_local_lock, "local_lock=%s" },
185 Opt_xprt_udp, Opt_xprt_udp6, Opt_xprt_tcp, Opt_xprt_tcp6, Opt_xprt_rdma,
190 static const match_table_t nfs_xprt_protocol_tokens = {
191 { Opt_xprt_udp, "udp" },
192 { Opt_xprt_udp6, "udp6" },
193 { Opt_xprt_tcp, "tcp" },
194 { Opt_xprt_tcp6, "tcp6" },
195 { Opt_xprt_rdma, "rdma" },
197 { Opt_xprt_err, NULL }
201 Opt_sec_none, Opt_sec_sys,
202 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
203 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
204 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
209 static const match_table_t nfs_secflavor_tokens = {
210 { Opt_sec_none, "none" },
211 { Opt_sec_none, "null" },
212 { Opt_sec_sys, "sys" },
214 { Opt_sec_krb5, "krb5" },
215 { Opt_sec_krb5i, "krb5i" },
216 { Opt_sec_krb5p, "krb5p" },
218 { Opt_sec_lkey, "lkey" },
219 { Opt_sec_lkeyi, "lkeyi" },
220 { Opt_sec_lkeyp, "lkeyp" },
222 { Opt_sec_spkm, "spkm3" },
223 { Opt_sec_spkmi, "spkm3i" },
224 { Opt_sec_spkmp, "spkm3p" },
226 { Opt_sec_err, NULL }
230 Opt_lookupcache_all, Opt_lookupcache_positive,
231 Opt_lookupcache_none,
236 static match_table_t nfs_lookupcache_tokens = {
237 { Opt_lookupcache_all, "all" },
238 { Opt_lookupcache_positive, "pos" },
239 { Opt_lookupcache_positive, "positive" },
240 { Opt_lookupcache_none, "none" },
242 { Opt_lookupcache_err, NULL }
246 Opt_local_lock_all, Opt_local_lock_flock, Opt_local_lock_posix,
252 static match_table_t nfs_local_lock_tokens = {
253 { Opt_local_lock_all, "all" },
254 { Opt_local_lock_flock, "flock" },
255 { Opt_local_lock_posix, "posix" },
256 { Opt_local_lock_none, "none" },
258 { Opt_local_lock_err, NULL }
262 static void nfs_umount_begin(struct super_block *);
263 static int nfs_statfs(struct dentry *, struct kstatfs *);
264 static int nfs_show_options(struct seq_file *, struct dentry *);
265 static int nfs_show_devname(struct seq_file *, struct dentry *);
266 static int nfs_show_path(struct seq_file *, struct dentry *);
267 static int nfs_show_stats(struct seq_file *, struct dentry *);
268 static struct dentry *nfs_fs_mount(struct file_system_type *,
269 int, const char *, void *);
270 static struct dentry *nfs_xdev_mount(struct file_system_type *fs_type,
271 int flags, const char *dev_name, void *raw_data);
272 static void nfs_put_super(struct super_block *);
273 static void nfs_kill_super(struct super_block *);
274 static int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
276 static struct file_system_type nfs_fs_type = {
277 .owner = THIS_MODULE,
279 .mount = nfs_fs_mount,
280 .kill_sb = nfs_kill_super,
281 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
284 struct file_system_type nfs_xdev_fs_type = {
285 .owner = THIS_MODULE,
287 .mount = nfs_xdev_mount,
288 .kill_sb = nfs_kill_super,
289 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
292 static const struct super_operations nfs_sops = {
293 .alloc_inode = nfs_alloc_inode,
294 .destroy_inode = nfs_destroy_inode,
295 .write_inode = nfs_write_inode,
296 .put_super = nfs_put_super,
297 .statfs = nfs_statfs,
298 .evict_inode = nfs_evict_inode,
299 .umount_begin = nfs_umount_begin,
300 .show_options = nfs_show_options,
301 .show_devname = nfs_show_devname,
302 .show_path = nfs_show_path,
303 .show_stats = nfs_show_stats,
304 .remount_fs = nfs_remount,
308 static int nfs4_validate_text_mount_data(void *options,
309 struct nfs_parsed_mount_data *args, const char *dev_name);
310 static struct dentry *nfs4_try_mount(int flags, const char *dev_name,
311 struct nfs_parsed_mount_data *data);
312 static struct dentry *nfs4_mount(struct file_system_type *fs_type,
313 int flags, const char *dev_name, void *raw_data);
314 static struct dentry *nfs4_remote_mount(struct file_system_type *fs_type,
315 int flags, const char *dev_name, void *raw_data);
316 static struct dentry *nfs4_xdev_mount(struct file_system_type *fs_type,
317 int flags, const char *dev_name, void *raw_data);
318 static struct dentry *nfs4_referral_mount(struct file_system_type *fs_type,
319 int flags, const char *dev_name, void *raw_data);
320 static struct dentry *nfs4_remote_referral_mount(struct file_system_type *fs_type,
321 int flags, const char *dev_name, void *raw_data);
322 static void nfs4_kill_super(struct super_block *sb);
324 static struct file_system_type nfs4_fs_type = {
325 .owner = THIS_MODULE,
328 .kill_sb = nfs4_kill_super,
329 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
332 static struct file_system_type nfs4_remote_fs_type = {
333 .owner = THIS_MODULE,
335 .mount = nfs4_remote_mount,
336 .kill_sb = nfs4_kill_super,
337 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
340 struct file_system_type nfs4_xdev_fs_type = {
341 .owner = THIS_MODULE,
343 .mount = nfs4_xdev_mount,
344 .kill_sb = nfs4_kill_super,
345 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
348 static struct file_system_type nfs4_remote_referral_fs_type = {
349 .owner = THIS_MODULE,
351 .mount = nfs4_remote_referral_mount,
352 .kill_sb = nfs4_kill_super,
353 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
356 struct file_system_type nfs4_referral_fs_type = {
357 .owner = THIS_MODULE,
359 .mount = nfs4_referral_mount,
360 .kill_sb = nfs4_kill_super,
361 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
364 static const struct super_operations nfs4_sops = {
365 .alloc_inode = nfs_alloc_inode,
366 .destroy_inode = nfs_destroy_inode,
367 .write_inode = nfs_write_inode,
368 .put_super = nfs_put_super,
369 .statfs = nfs_statfs,
370 .evict_inode = nfs4_evict_inode,
371 .umount_begin = nfs_umount_begin,
372 .show_options = nfs_show_options,
373 .show_devname = nfs_show_devname,
374 .show_path = nfs_show_path,
375 .show_stats = nfs_show_stats,
376 .remount_fs = nfs_remount,
380 static struct shrinker acl_shrinker = {
381 .shrink = nfs_access_cache_shrinker,
382 .seeks = DEFAULT_SEEKS,
386 * Register the NFS filesystems
388 int __init register_nfs_fs(void)
392 ret = register_filesystem(&nfs_fs_type);
396 ret = nfs_register_sysctl();
400 ret = register_filesystem(&nfs4_fs_type);
404 register_shrinker(&acl_shrinker);
409 nfs_unregister_sysctl();
412 unregister_filesystem(&nfs_fs_type);
418 * Unregister the NFS filesystems
420 void __exit unregister_nfs_fs(void)
422 unregister_shrinker(&acl_shrinker);
424 unregister_filesystem(&nfs4_fs_type);
426 nfs_unregister_sysctl();
427 unregister_filesystem(&nfs_fs_type);
430 void nfs_sb_active(struct super_block *sb)
432 struct nfs_server *server = NFS_SB(sb);
434 if (atomic_inc_return(&server->active) == 1)
435 atomic_inc(&sb->s_active);
438 void nfs_sb_deactive(struct super_block *sb)
440 struct nfs_server *server = NFS_SB(sb);
442 if (atomic_dec_and_test(&server->active))
443 deactivate_super(sb);
447 * Deliver file system statistics to userspace
449 static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
451 struct nfs_server *server = NFS_SB(dentry->d_sb);
452 unsigned char blockbits;
453 unsigned long blockres;
454 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
455 struct nfs_fsstat res;
458 res.fattr = nfs_alloc_fattr();
459 if (res.fattr == NULL)
462 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
463 if (unlikely(error == -ESTALE)) {
464 struct dentry *pd_dentry;
466 pd_dentry = dget_parent(dentry);
467 if (pd_dentry != NULL) {
468 nfs_zap_caches(pd_dentry->d_inode);
472 nfs_free_fattr(res.fattr);
476 buf->f_type = NFS_SUPER_MAGIC;
479 * Current versions of glibc do not correctly handle the
480 * case where f_frsize != f_bsize. Eventually we want to
481 * report the value of wtmult in this field.
483 buf->f_frsize = dentry->d_sb->s_blocksize;
486 * On most *nix systems, f_blocks, f_bfree, and f_bavail
487 * are reported in units of f_frsize. Linux hasn't had
488 * an f_frsize field in its statfs struct until recently,
489 * thus historically Linux's sys_statfs reports these
490 * fields in units of f_bsize.
492 buf->f_bsize = dentry->d_sb->s_blocksize;
493 blockbits = dentry->d_sb->s_blocksize_bits;
494 blockres = (1 << blockbits) - 1;
495 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
496 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
497 buf->f_bavail = (res.abytes + blockres) >> blockbits;
499 buf->f_files = res.tfiles;
500 buf->f_ffree = res.afiles;
502 buf->f_namelen = server->namelen;
507 dprintk("%s: statfs error = %d\n", __func__, -error);
512 * Map the security flavour number to a name
514 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
516 static const struct {
517 rpc_authflavor_t flavour;
520 { RPC_AUTH_NULL, "null" },
521 { RPC_AUTH_UNIX, "sys" },
522 { RPC_AUTH_GSS_KRB5, "krb5" },
523 { RPC_AUTH_GSS_KRB5I, "krb5i" },
524 { RPC_AUTH_GSS_KRB5P, "krb5p" },
525 { RPC_AUTH_GSS_LKEY, "lkey" },
526 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
527 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
528 { RPC_AUTH_GSS_SPKM, "spkm" },
529 { RPC_AUTH_GSS_SPKMI, "spkmi" },
530 { RPC_AUTH_GSS_SPKMP, "spkmp" },
531 { UINT_MAX, "unknown" }
535 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
536 if (sec_flavours[i].flavour == flavour)
539 return sec_flavours[i].str;
542 static void nfs_show_mountd_netid(struct seq_file *m, struct nfs_server *nfss,
545 struct sockaddr *sap = (struct sockaddr *) &nfss->mountd_address;
547 seq_printf(m, ",mountproto=");
548 switch (sap->sa_family) {
550 switch (nfss->mountd_protocol) {
552 seq_printf(m, RPCBIND_NETID_UDP);
555 seq_printf(m, RPCBIND_NETID_TCP);
559 seq_printf(m, "auto");
563 switch (nfss->mountd_protocol) {
565 seq_printf(m, RPCBIND_NETID_UDP6);
568 seq_printf(m, RPCBIND_NETID_TCP6);
572 seq_printf(m, "auto");
577 seq_printf(m, "auto");
581 static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
584 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
586 if (nfss->flags & NFS_MOUNT_LEGACY_INTERFACE)
589 switch (sap->sa_family) {
591 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
592 seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
596 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
597 seq_printf(m, ",mountaddr=%pI6c", &sin6->sin6_addr);
602 seq_printf(m, ",mountaddr=unspecified");
605 if (nfss->mountd_version || showdefaults)
606 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
607 if ((nfss->mountd_port &&
608 nfss->mountd_port != (unsigned short)NFS_UNSPEC_PORT) ||
610 seq_printf(m, ",mountport=%u", nfss->mountd_port);
612 nfs_show_mountd_netid(m, nfss, showdefaults);
616 static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
619 struct nfs_client *clp = nfss->nfs_client;
621 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
622 seq_printf(m, ",minorversion=%u", clp->cl_minorversion);
625 static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
632 * Describe the mount options in force on this server representation
634 static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
637 static const struct proc_nfs_info {
642 { NFS_MOUNT_SOFT, ",soft", ",hard" },
643 { NFS_MOUNT_POSIX, ",posix", "" },
644 { NFS_MOUNT_NOCTO, ",nocto", "" },
645 { NFS_MOUNT_NOAC, ",noac", "" },
646 { NFS_MOUNT_NONLM, ",nolock", "" },
647 { NFS_MOUNT_NOACL, ",noacl", "" },
648 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
649 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
650 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
653 const struct proc_nfs_info *nfs_infop;
654 struct nfs_client *clp = nfss->nfs_client;
655 u32 version = clp->rpc_ops->version;
656 int local_flock, local_fcntl;
658 seq_printf(m, ",vers=%u", version);
659 seq_printf(m, ",rsize=%u", nfss->rsize);
660 seq_printf(m, ",wsize=%u", nfss->wsize);
661 if (nfss->bsize != 0)
662 seq_printf(m, ",bsize=%u", nfss->bsize);
663 seq_printf(m, ",namlen=%u", nfss->namelen);
664 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
665 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
666 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
667 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
668 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
669 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
670 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
671 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
672 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
673 if (nfss->flags & nfs_infop->flag)
674 seq_puts(m, nfs_infop->str);
676 seq_puts(m, nfs_infop->nostr);
678 seq_printf(m, ",proto=%s",
679 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
681 if (nfss->port != NFS_PORT)
682 seq_printf(m, ",port=%u", nfss->port);
685 seq_printf(m, ",port=%u", nfss->port);
687 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
688 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
689 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
692 nfs_show_mountd_options(m, nfss, showdefaults);
694 nfs_show_nfsv4_options(m, nfss, showdefaults);
696 if (nfss->options & NFS_OPTION_FSCACHE)
697 seq_printf(m, ",fsc");
699 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONEG) {
700 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONE)
701 seq_printf(m, ",lookupcache=none");
703 seq_printf(m, ",lookupcache=pos");
706 local_flock = nfss->flags & NFS_MOUNT_LOCAL_FLOCK;
707 local_fcntl = nfss->flags & NFS_MOUNT_LOCAL_FCNTL;
709 if (!local_flock && !local_fcntl)
710 seq_printf(m, ",local_lock=none");
711 else if (local_flock && local_fcntl)
712 seq_printf(m, ",local_lock=all");
713 else if (local_flock)
714 seq_printf(m, ",local_lock=flock");
716 seq_printf(m, ",local_lock=posix");
720 * Describe the mount options on this VFS mountpoint
722 static int nfs_show_options(struct seq_file *m, struct dentry *root)
724 struct nfs_server *nfss = NFS_SB(root->d_sb);
726 nfs_show_mount_options(m, nfss, 0);
728 seq_printf(m, ",addr=%s",
729 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
736 #ifdef CONFIG_NFS_V4_1
737 static void show_sessions(struct seq_file *m, struct nfs_server *server)
739 if (nfs4_has_session(server->nfs_client))
740 seq_printf(m, ",sessions");
743 static void show_sessions(struct seq_file *m, struct nfs_server *server) {}
748 #ifdef CONFIG_NFS_V4_1
749 static void show_pnfs(struct seq_file *m, struct nfs_server *server)
751 seq_printf(m, ",pnfs=");
752 if (server->pnfs_curr_ld)
753 seq_printf(m, "%s", server->pnfs_curr_ld->name);
755 seq_printf(m, "not configured");
758 static void show_pnfs(struct seq_file *m, struct nfs_server *server) {}
762 static int nfs_show_devname(struct seq_file *m, struct dentry *root)
764 char *page = (char *) __get_free_page(GFP_KERNEL);
765 char *devname, *dummy;
769 devname = nfs_path(&dummy, root, page, PAGE_SIZE);
771 err = PTR_ERR(devname);
773 seq_escape(m, devname, " \t\n\\");
774 free_page((unsigned long)page);
778 static int nfs_show_path(struct seq_file *m, struct dentry *dentry)
785 * Present statistical information for this VFS mountpoint
787 static int nfs_show_stats(struct seq_file *m, struct dentry *root)
790 struct nfs_server *nfss = NFS_SB(root->d_sb);
791 struct rpc_auth *auth = nfss->client->cl_auth;
792 struct nfs_iostats totals = { };
794 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
797 * Display all mount option settings
799 seq_printf(m, "\n\topts:\t");
800 seq_puts(m, root->d_sb->s_flags & MS_RDONLY ? "ro" : "rw");
801 seq_puts(m, root->d_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
802 seq_puts(m, root->d_sb->s_flags & MS_NOATIME ? ",noatime" : "");
803 seq_puts(m, root->d_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
804 nfs_show_mount_options(m, nfss, 1);
806 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
808 seq_printf(m, "\n\tcaps:\t");
809 seq_printf(m, "caps=0x%x", nfss->caps);
810 seq_printf(m, ",wtmult=%u", nfss->wtmult);
811 seq_printf(m, ",dtsize=%u", nfss->dtsize);
812 seq_printf(m, ",bsize=%u", nfss->bsize);
813 seq_printf(m, ",namlen=%u", nfss->namelen);
816 if (nfss->nfs_client->rpc_ops->version == 4) {
817 seq_printf(m, "\n\tnfsv4:\t");
818 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
819 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
820 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
821 show_sessions(m, nfss);
827 * Display security flavor in effect for this mount
829 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
831 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
834 * Display superblock I/O counters
836 for_each_possible_cpu(cpu) {
837 struct nfs_iostats *stats;
840 stats = per_cpu_ptr(nfss->io_stats, cpu);
842 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
843 totals.events[i] += stats->events[i];
844 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
845 totals.bytes[i] += stats->bytes[i];
846 #ifdef CONFIG_NFS_FSCACHE
847 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
848 totals.fscache[i] += stats->fscache[i];
854 seq_printf(m, "\n\tevents:\t");
855 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
856 seq_printf(m, "%lu ", totals.events[i]);
857 seq_printf(m, "\n\tbytes:\t");
858 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
859 seq_printf(m, "%Lu ", totals.bytes[i]);
860 #ifdef CONFIG_NFS_FSCACHE
861 if (nfss->options & NFS_OPTION_FSCACHE) {
862 seq_printf(m, "\n\tfsc:\t");
863 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
864 seq_printf(m, "%Lu ", totals.bytes[i]);
869 rpc_print_iostats(m, nfss->client);
875 * Begin unmount by attempting to remove all automounted mountpoints we added
876 * in response to xdev traversals and referrals
878 static void nfs_umount_begin(struct super_block *sb)
880 struct nfs_server *server;
881 struct rpc_clnt *rpc;
884 /* -EIO all pending I/O */
885 rpc = server->client_acl;
887 rpc_killall_tasks(rpc);
888 rpc = server->client;
890 rpc_killall_tasks(rpc);
893 static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(unsigned int version)
895 struct nfs_parsed_mount_data *data;
897 data = kzalloc(sizeof(*data), GFP_KERNEL);
899 data->acregmin = NFS_DEF_ACREGMIN;
900 data->acregmax = NFS_DEF_ACREGMAX;
901 data->acdirmin = NFS_DEF_ACDIRMIN;
902 data->acdirmax = NFS_DEF_ACDIRMAX;
903 data->mount_server.port = NFS_UNSPEC_PORT;
904 data->nfs_server.port = NFS_UNSPEC_PORT;
905 data->nfs_server.protocol = XPRT_TRANSPORT_TCP;
906 data->auth_flavors[0] = RPC_AUTH_UNIX;
907 data->auth_flavor_len = 1;
908 data->version = version;
909 data->minorversion = 0;
910 security_init_mnt_opts(&data->lsm_opts);
915 static void nfs_free_parsed_mount_data(struct nfs_parsed_mount_data *data)
918 kfree(data->client_address);
919 kfree(data->mount_server.hostname);
920 kfree(data->nfs_server.export_path);
921 kfree(data->nfs_server.hostname);
922 kfree(data->fscache_uniq);
923 security_free_mnt_opts(&data->lsm_opts);
929 * Sanity-check a server address provided by the mount command.
931 * Address family must be initialized, and address must not be
932 * the ANY address for that family.
934 static int nfs_verify_server_address(struct sockaddr *addr)
936 switch (addr->sa_family) {
938 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
939 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
942 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
943 return !ipv6_addr_any(sa);
947 dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
952 * Select between a default port value and a user-specified port value.
953 * If a zero value is set, then autobind will be used.
955 static void nfs_set_port(struct sockaddr *sap, int *port,
956 const unsigned short default_port)
958 if (*port == NFS_UNSPEC_PORT)
959 *port = default_port;
961 rpc_set_port(sap, *port);
965 * Sanity check the NFS transport protocol.
968 static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
970 switch (mnt->nfs_server.protocol) {
971 case XPRT_TRANSPORT_UDP:
972 case XPRT_TRANSPORT_TCP:
973 case XPRT_TRANSPORT_RDMA:
976 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
981 * For text based NFSv2/v3 mounts, the mount protocol transport default
982 * settings should depend upon the specified NFS transport.
984 static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
986 nfs_validate_transport_protocol(mnt);
988 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
989 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
991 switch (mnt->nfs_server.protocol) {
992 case XPRT_TRANSPORT_UDP:
993 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
995 case XPRT_TRANSPORT_TCP:
996 case XPRT_TRANSPORT_RDMA:
997 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
1002 * Parse the value of the 'sec=' option.
1004 static int nfs_parse_security_flavors(char *value,
1005 struct nfs_parsed_mount_data *mnt)
1007 substring_t args[MAX_OPT_ARGS];
1009 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
1011 switch (match_token(value, nfs_secflavor_tokens, args)) {
1013 mnt->auth_flavors[0] = RPC_AUTH_NULL;
1016 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
1019 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
1022 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
1025 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
1028 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
1031 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
1034 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
1037 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
1040 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
1043 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
1049 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
1050 mnt->auth_flavor_len = 1;
1054 static int nfs_get_option_str(substring_t args[], char **option)
1057 *option = match_strdup(args);
1061 static int nfs_get_option_ul(substring_t args[], unsigned long *option)
1066 string = match_strdup(args);
1069 rc = strict_strtoul(string, 10, option);
1076 * Error-check and convert a string of mount options from user space into
1077 * a data structure. The whole mount string is processed; bad options are
1078 * skipped as they are encountered. If there were no errors, return 1;
1079 * otherwise return 0 (zero).
1081 static int nfs_parse_mount_options(char *raw,
1082 struct nfs_parsed_mount_data *mnt)
1084 char *p, *string, *secdata;
1085 int rc, sloppy = 0, invalid_option = 0;
1086 unsigned short protofamily = AF_UNSPEC;
1087 unsigned short mountfamily = AF_UNSPEC;
1090 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
1093 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
1095 secdata = alloc_secdata();
1099 rc = security_sb_copy_data(raw, secdata);
1101 goto out_security_failure;
1103 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
1105 goto out_security_failure;
1107 free_secdata(secdata);
1109 while ((p = strsep(&raw, ",")) != NULL) {
1110 substring_t args[MAX_OPT_ARGS];
1111 unsigned long option;
1117 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
1119 token = match_token(p, nfs_mount_option_tokens, args);
1123 * boolean options: foo/nofoo
1126 mnt->flags |= NFS_MOUNT_SOFT;
1129 mnt->flags &= ~NFS_MOUNT_SOFT;
1132 mnt->flags |= NFS_MOUNT_POSIX;
1135 mnt->flags &= ~NFS_MOUNT_POSIX;
1138 mnt->flags &= ~NFS_MOUNT_NOCTO;
1141 mnt->flags |= NFS_MOUNT_NOCTO;
1144 mnt->flags &= ~NFS_MOUNT_NOAC;
1147 mnt->flags |= NFS_MOUNT_NOAC;
1150 mnt->flags &= ~NFS_MOUNT_NONLM;
1151 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1152 NFS_MOUNT_LOCAL_FCNTL);
1155 mnt->flags |= NFS_MOUNT_NONLM;
1156 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1157 NFS_MOUNT_LOCAL_FCNTL);
1160 mnt->flags &= ~NFS_MOUNT_VER3;
1164 mnt->flags |= NFS_MOUNT_VER3;
1168 mnt->flags &= ~NFS_MOUNT_VER3;
1172 mnt->flags &= ~NFS_MOUNT_TCP;
1173 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1176 mnt->flags |= NFS_MOUNT_TCP;
1177 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1180 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1181 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1182 xprt_load_transport(p);
1185 mnt->flags &= ~NFS_MOUNT_NOACL;
1188 mnt->flags |= NFS_MOUNT_NOACL;
1191 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1193 case Opt_nordirplus:
1194 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1196 case Opt_sharecache:
1197 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1199 case Opt_nosharecache:
1200 mnt->flags |= NFS_MOUNT_UNSHARED;
1203 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1205 case Opt_noresvport:
1206 mnt->flags |= NFS_MOUNT_NORESVPORT;
1209 mnt->options |= NFS_OPTION_FSCACHE;
1210 kfree(mnt->fscache_uniq);
1211 mnt->fscache_uniq = NULL;
1214 mnt->options &= ~NFS_OPTION_FSCACHE;
1215 kfree(mnt->fscache_uniq);
1216 mnt->fscache_uniq = NULL;
1220 * options that take numeric values
1223 if (nfs_get_option_ul(args, &option) ||
1225 goto out_invalid_value;
1226 mnt->nfs_server.port = option;
1229 if (nfs_get_option_ul(args, &option))
1230 goto out_invalid_value;
1231 mnt->rsize = option;
1234 if (nfs_get_option_ul(args, &option))
1235 goto out_invalid_value;
1236 mnt->wsize = option;
1239 if (nfs_get_option_ul(args, &option))
1240 goto out_invalid_value;
1241 mnt->bsize = option;
1244 if (nfs_get_option_ul(args, &option) || option == 0)
1245 goto out_invalid_value;
1246 mnt->timeo = option;
1249 if (nfs_get_option_ul(args, &option) || option == 0)
1250 goto out_invalid_value;
1251 mnt->retrans = option;
1254 if (nfs_get_option_ul(args, &option))
1255 goto out_invalid_value;
1256 mnt->acregmin = option;
1259 if (nfs_get_option_ul(args, &option))
1260 goto out_invalid_value;
1261 mnt->acregmax = option;
1264 if (nfs_get_option_ul(args, &option))
1265 goto out_invalid_value;
1266 mnt->acdirmin = option;
1269 if (nfs_get_option_ul(args, &option))
1270 goto out_invalid_value;
1271 mnt->acdirmax = option;
1274 if (nfs_get_option_ul(args, &option))
1275 goto out_invalid_value;
1276 mnt->acregmin = mnt->acregmax =
1277 mnt->acdirmin = mnt->acdirmax = option;
1280 if (nfs_get_option_ul(args, &option))
1281 goto out_invalid_value;
1282 mnt->namlen = option;
1285 if (nfs_get_option_ul(args, &option) ||
1287 goto out_invalid_value;
1288 mnt->mount_server.port = option;
1291 if (nfs_get_option_ul(args, &option) ||
1292 option < NFS_MNT_VERSION ||
1293 option > NFS_MNT3_VERSION)
1294 goto out_invalid_value;
1295 mnt->mount_server.version = option;
1298 if (nfs_get_option_ul(args, &option))
1299 goto out_invalid_value;
1302 mnt->flags &= ~NFS_MOUNT_VER3;
1306 mnt->flags |= NFS_MOUNT_VER3;
1310 mnt->flags &= ~NFS_MOUNT_VER3;
1314 goto out_invalid_value;
1317 case Opt_minorversion:
1318 if (nfs_get_option_ul(args, &option))
1319 goto out_invalid_value;
1320 if (option > NFS4_MAX_MINOR_VERSION)
1321 goto out_invalid_value;
1322 mnt->minorversion = option;
1326 * options that take text values
1329 string = match_strdup(args);
1332 rc = nfs_parse_security_flavors(string, mnt);
1335 dfprintk(MOUNT, "NFS: unrecognized "
1336 "security flavor\n");
1341 string = match_strdup(args);
1344 token = match_token(string,
1345 nfs_xprt_protocol_tokens, args);
1347 protofamily = AF_INET;
1350 protofamily = AF_INET6;
1352 mnt->flags &= ~NFS_MOUNT_TCP;
1353 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1356 protofamily = AF_INET6;
1358 mnt->flags |= NFS_MOUNT_TCP;
1359 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1362 /* vector side protocols to TCP */
1363 mnt->flags |= NFS_MOUNT_TCP;
1364 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1365 xprt_load_transport(string);
1368 dfprintk(MOUNT, "NFS: unrecognized "
1369 "transport protocol\n");
1375 case Opt_mountproto:
1376 string = match_strdup(args);
1379 token = match_token(string,
1380 nfs_xprt_protocol_tokens, args);
1383 mountfamily = AF_INET;
1386 mountfamily = AF_INET6;
1388 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
1391 mountfamily = AF_INET6;
1393 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
1395 case Opt_xprt_rdma: /* not used for side protocols */
1397 dfprintk(MOUNT, "NFS: unrecognized "
1398 "transport protocol\n");
1403 string = match_strdup(args);
1406 mnt->nfs_server.addrlen =
1407 rpc_pton(string, strlen(string),
1409 &mnt->nfs_server.address,
1410 sizeof(mnt->nfs_server.address));
1412 if (mnt->nfs_server.addrlen == 0)
1413 goto out_invalid_address;
1415 case Opt_clientaddr:
1416 if (nfs_get_option_str(args, &mnt->client_address))
1420 if (nfs_get_option_str(args,
1421 &mnt->mount_server.hostname))
1425 string = match_strdup(args);
1428 mnt->mount_server.addrlen =
1429 rpc_pton(string, strlen(string),
1431 &mnt->mount_server.address,
1432 sizeof(mnt->mount_server.address));
1434 if (mnt->mount_server.addrlen == 0)
1435 goto out_invalid_address;
1437 case Opt_lookupcache:
1438 string = match_strdup(args);
1441 token = match_token(string,
1442 nfs_lookupcache_tokens, args);
1445 case Opt_lookupcache_all:
1446 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1448 case Opt_lookupcache_positive:
1449 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1450 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1452 case Opt_lookupcache_none:
1453 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1456 dfprintk(MOUNT, "NFS: invalid "
1457 "lookupcache argument\n");
1461 case Opt_fscache_uniq:
1462 if (nfs_get_option_str(args, &mnt->fscache_uniq))
1464 mnt->options |= NFS_OPTION_FSCACHE;
1466 case Opt_local_lock:
1467 string = match_strdup(args);
1470 token = match_token(string, nfs_local_lock_tokens,
1474 case Opt_local_lock_all:
1475 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1476 NFS_MOUNT_LOCAL_FCNTL);
1478 case Opt_local_lock_flock:
1479 mnt->flags |= NFS_MOUNT_LOCAL_FLOCK;
1481 case Opt_local_lock_posix:
1482 mnt->flags |= NFS_MOUNT_LOCAL_FCNTL;
1484 case Opt_local_lock_none:
1485 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1486 NFS_MOUNT_LOCAL_FCNTL);
1489 dfprintk(MOUNT, "NFS: invalid "
1490 "local_lock argument\n");
1500 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1503 case Opt_deprecated:
1504 dfprintk(MOUNT, "NFS: ignoring mount option "
1510 dfprintk(MOUNT, "NFS: unrecognized mount option "
1515 if (!sloppy && invalid_option)
1519 * verify that any proto=/mountproto= options match the address
1520 * familiies in the addr=/mountaddr= options.
1522 if (protofamily != AF_UNSPEC &&
1523 protofamily != mnt->nfs_server.address.ss_family)
1524 goto out_proto_mismatch;
1526 if (mountfamily != AF_UNSPEC) {
1527 if (mnt->mount_server.addrlen) {
1528 if (mountfamily != mnt->mount_server.address.ss_family)
1529 goto out_mountproto_mismatch;
1531 if (mountfamily != mnt->nfs_server.address.ss_family)
1532 goto out_mountproto_mismatch;
1538 out_mountproto_mismatch:
1539 printk(KERN_INFO "NFS: mount server address does not match mountproto= "
1543 printk(KERN_INFO "NFS: server address does not match proto= option\n");
1545 out_invalid_address:
1546 printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
1549 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
1552 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1554 out_security_failure:
1555 free_secdata(secdata);
1556 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1561 * Match the requested auth flavors with the list returned by
1562 * the server. Returns zero and sets the mount's authentication
1563 * flavor on success; returns -EACCES if server does not support
1564 * the requested flavor.
1566 static int nfs_walk_authlist(struct nfs_parsed_mount_data *args,
1567 struct nfs_mount_request *request)
1569 unsigned int i, j, server_authlist_len = *(request->auth_flav_len);
1572 * Certain releases of Linux's mountd return an empty
1573 * flavor list. To prevent behavioral regression with
1574 * these servers (ie. rejecting mounts that used to
1575 * succeed), revert to pre-2.6.32 behavior (no checking)
1576 * if the returned flavor list is empty.
1578 if (server_authlist_len == 0)
1582 * We avoid sophisticated negotiating here, as there are
1583 * plenty of cases where we can get it wrong, providing
1584 * either too little or too much security.
1586 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1587 * flavor listed first. However, some servers list
1588 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1589 * preferred default, in args->auth_flavors[0] if user
1590 * didn't specify sec= mount option.
1592 for (i = 0; i < args->auth_flavor_len; i++)
1593 for (j = 0; j < server_authlist_len; j++)
1594 if (args->auth_flavors[i] == request->auth_flavs[j]) {
1595 dfprintk(MOUNT, "NFS: using auth flavor %d\n",
1596 request->auth_flavs[j]);
1597 args->auth_flavors[0] = request->auth_flavs[j];
1601 dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n");
1602 nfs_umount(request);
1607 * Use the remote server's MOUNT service to request the NFS file handle
1608 * corresponding to the provided path.
1610 static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1611 struct nfs_fh *root_fh)
1613 rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS];
1614 unsigned int server_authlist_len = ARRAY_SIZE(server_authlist);
1615 struct nfs_mount_request request = {
1616 .sap = (struct sockaddr *)
1617 &args->mount_server.address,
1618 .dirpath = args->nfs_server.export_path,
1619 .protocol = args->mount_server.protocol,
1621 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
1622 .auth_flav_len = &server_authlist_len,
1623 .auth_flavs = server_authlist,
1627 if (args->mount_server.version == 0) {
1628 switch (args->version) {
1630 args->mount_server.version = NFS_MNT3_VERSION;
1633 args->mount_server.version = NFS_MNT_VERSION;
1636 request.version = args->mount_server.version;
1638 if (args->mount_server.hostname)
1639 request.hostname = args->mount_server.hostname;
1641 request.hostname = args->nfs_server.hostname;
1644 * Construct the mount server's address.
1646 if (args->mount_server.address.ss_family == AF_UNSPEC) {
1647 memcpy(request.sap, &args->nfs_server.address,
1648 args->nfs_server.addrlen);
1649 args->mount_server.addrlen = args->nfs_server.addrlen;
1651 request.salen = args->mount_server.addrlen;
1652 nfs_set_port(request.sap, &args->mount_server.port, 0);
1655 * Now ask the mount server to map our export path
1658 status = nfs_mount(&request);
1660 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1661 request.hostname, status);
1666 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1668 if (args->mount_server.version != NFS_MNT3_VERSION)
1670 return nfs_walk_authlist(args, &request);
1674 * Split "dev_name" into "hostname:export_path".
1676 * The leftmost colon demarks the split between the server's hostname
1677 * and the export path. If the hostname starts with a left square
1678 * bracket, then it may contain colons.
1680 * Note: caller frees hostname and export path, even on error.
1682 static int nfs_parse_devname(const char *dev_name,
1683 char **hostname, size_t maxnamlen,
1684 char **export_path, size_t maxpathlen)
1689 /* Is the host name protected with square brakcets? */
1690 if (*dev_name == '[') {
1691 end = strchr(++dev_name, ']');
1692 if (end == NULL || end[1] != ':')
1693 goto out_bad_devname;
1695 len = end - dev_name;
1700 end = strchr(dev_name, ':');
1702 goto out_bad_devname;
1703 len = end - dev_name;
1705 /* kill possible hostname list: not supported */
1706 comma = strchr(dev_name, ',');
1707 if (comma != NULL && comma < end)
1711 if (len > maxnamlen)
1714 /* N.B. caller will free nfs_server.hostname in all cases */
1715 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
1716 if (*hostname == NULL)
1718 len = strlen(++end);
1719 if (len > maxpathlen)
1721 *export_path = kstrndup(end, len, GFP_KERNEL);
1725 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1729 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1733 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1737 dfprintk(MOUNT, "NFS: server hostname too long\n");
1738 return -ENAMETOOLONG;
1741 dfprintk(MOUNT, "NFS: export pathname too long\n");
1742 return -ENAMETOOLONG;
1746 * Validate the NFS2/NFS3 mount data
1747 * - fills in the mount root filehandle
1749 * For option strings, user space handles the following behaviors:
1751 * + DNS: mapping server host name to IP address ("addr=" option)
1753 * + failure mode: how to behave if a mount request can't be handled
1754 * immediately ("fg/bg" option)
1756 * + retry: how often to retry a mount request ("retry=" option)
1758 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1759 * mountproto=tcp after mountproto=udp, and so on
1761 static int nfs_validate_mount_data(void *options,
1762 struct nfs_parsed_mount_data *args,
1763 struct nfs_fh *mntfh,
1764 const char *dev_name)
1766 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
1767 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
1772 switch (data->version) {
1778 if (data->flags & NFS_MOUNT_VER3)
1780 data->root.size = NFS2_FHSIZE;
1781 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1783 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1786 memset(data->context, 0, sizeof(data->context));
1788 if (data->flags & NFS_MOUNT_VER3) {
1789 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1790 goto out_invalid_fh;
1791 mntfh->size = data->root.size;
1794 mntfh->size = NFS2_FHSIZE;
1799 memcpy(mntfh->data, data->root.data, mntfh->size);
1800 if (mntfh->size < sizeof(mntfh->data))
1801 memset(mntfh->data + mntfh->size, 0,
1802 sizeof(mntfh->data) - mntfh->size);
1805 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1808 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
1809 args->flags |= NFS_MOUNT_LEGACY_INTERFACE;
1810 args->rsize = data->rsize;
1811 args->wsize = data->wsize;
1812 args->timeo = data->timeo;
1813 args->retrans = data->retrans;
1814 args->acregmin = data->acregmin;
1815 args->acregmax = data->acregmax;
1816 args->acdirmin = data->acdirmin;
1817 args->acdirmax = data->acdirmax;
1819 memcpy(sap, &data->addr, sizeof(data->addr));
1820 args->nfs_server.addrlen = sizeof(data->addr);
1821 if (!nfs_verify_server_address(sap))
1822 goto out_no_address;
1824 if (!(data->flags & NFS_MOUNT_TCP))
1825 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1826 /* N.B. caller will free nfs_server.hostname in all cases */
1827 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1828 args->namlen = data->namlen;
1829 args->bsize = data->bsize;
1831 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1832 args->auth_flavors[0] = data->pseudoflavor;
1833 if (!args->nfs_server.hostname)
1836 if (!(data->flags & NFS_MOUNT_NONLM))
1837 args->flags &= ~(NFS_MOUNT_LOCAL_FLOCK|
1838 NFS_MOUNT_LOCAL_FCNTL);
1840 args->flags |= (NFS_MOUNT_LOCAL_FLOCK|
1841 NFS_MOUNT_LOCAL_FCNTL);
1843 * The legacy version 6 binary mount data from userspace has a
1844 * field used only to transport selinux information into the
1845 * the kernel. To continue to support that functionality we
1846 * have a touch of selinux knowledge here in the NFS code. The
1847 * userspace code converted context=blah to just blah so we are
1848 * converting back to the full string selinux understands.
1850 if (data->context[0]){
1851 #ifdef CONFIG_SECURITY_SELINUX
1853 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1856 strcpy(opts_str, "context=");
1857 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1858 strcat(opts_str, &data->context[0]);
1859 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1872 if (nfs_parse_mount_options((char *)options, args) == 0)
1875 if (!nfs_verify_server_address(sap))
1876 goto out_no_address;
1878 if (args->version == 4)
1879 #ifdef CONFIG_NFS_V4
1880 return nfs4_validate_text_mount_data(options,
1883 goto out_v4_not_compiled;
1886 nfs_set_port(sap, &args->nfs_server.port, 0);
1888 nfs_set_mount_transport_protocol(args);
1890 status = nfs_parse_devname(dev_name,
1891 &args->nfs_server.hostname,
1893 &args->nfs_server.export_path,
1896 status = nfs_try_mount(args, mntfh);
1898 kfree(args->nfs_server.export_path);
1899 args->nfs_server.export_path = NULL;
1908 #ifndef CONFIG_NFS_V3
1909 if (args->version == 3)
1910 goto out_v3_not_compiled;
1911 #endif /* !CONFIG_NFS_V3 */
1916 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1920 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1925 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1928 #ifndef CONFIG_NFS_V3
1929 out_v3_not_compiled:
1930 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1931 return -EPROTONOSUPPORT;
1932 #endif /* !CONFIG_NFS_V3 */
1934 #ifndef CONFIG_NFS_V4
1935 out_v4_not_compiled:
1936 dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n");
1937 return -EPROTONOSUPPORT;
1938 #endif /* !CONFIG_NFS_V4 */
1941 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
1945 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1949 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1954 nfs_compare_remount_data(struct nfs_server *nfss,
1955 struct nfs_parsed_mount_data *data)
1957 if (data->flags != nfss->flags ||
1958 data->rsize != nfss->rsize ||
1959 data->wsize != nfss->wsize ||
1960 data->retrans != nfss->client->cl_timeout->to_retries ||
1961 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
1962 data->acregmin != nfss->acregmin / HZ ||
1963 data->acregmax != nfss->acregmax / HZ ||
1964 data->acdirmin != nfss->acdirmin / HZ ||
1965 data->acdirmax != nfss->acdirmax / HZ ||
1966 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
1967 data->nfs_server.port != nfss->port ||
1968 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
1969 !rpc_cmp_addr((struct sockaddr *)&data->nfs_server.address,
1970 (struct sockaddr *)&nfss->nfs_client->cl_addr))
1977 nfs_remount(struct super_block *sb, int *flags, char *raw_data)
1980 struct nfs_server *nfss = sb->s_fs_info;
1981 struct nfs_parsed_mount_data *data;
1982 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
1983 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
1984 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
1987 * Userspace mount programs that send binary options generally send
1988 * them populated with default values. We have no way to know which
1989 * ones were explicitly specified. Fall back to legacy behavior and
1990 * just return success.
1992 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
1993 (nfsvers <= 3 && (!options || (options->version >= 1 &&
1994 options->version <= 6))))
1997 data = kzalloc(sizeof(*data), GFP_KERNEL);
2001 /* fill out struct with values from existing mount */
2002 data->flags = nfss->flags;
2003 data->rsize = nfss->rsize;
2004 data->wsize = nfss->wsize;
2005 data->retrans = nfss->client->cl_timeout->to_retries;
2006 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
2007 data->acregmin = nfss->acregmin / HZ;
2008 data->acregmax = nfss->acregmax / HZ;
2009 data->acdirmin = nfss->acdirmin / HZ;
2010 data->acdirmax = nfss->acdirmax / HZ;
2011 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
2012 data->nfs_server.port = nfss->port;
2013 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
2014 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
2015 data->nfs_server.addrlen);
2017 /* overwrite those values with any that were specified */
2018 error = nfs_parse_mount_options((char *)options, data);
2023 * noac is a special case. It implies -o sync, but that's not
2024 * necessarily reflected in the mtab options. do_remount_sb
2025 * will clear MS_SYNCHRONOUS if -o sync wasn't specified in the
2026 * remount options, so we have to explicitly reset it.
2028 if (data->flags & NFS_MOUNT_NOAC)
2029 *flags |= MS_SYNCHRONOUS;
2031 /* compare new mount options with old ones */
2032 error = nfs_compare_remount_data(nfss, data);
2039 * Initialise the common bits of the superblock
2041 static inline void nfs_initialise_sb(struct super_block *sb)
2043 struct nfs_server *server = NFS_SB(sb);
2045 sb->s_magic = NFS_SUPER_MAGIC;
2047 /* We probably want something more informative here */
2048 snprintf(sb->s_id, sizeof(sb->s_id),
2049 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
2051 if (sb->s_blocksize == 0)
2052 sb->s_blocksize = nfs_block_bits(server->wsize,
2053 &sb->s_blocksize_bits);
2055 sb->s_bdi = &server->backing_dev_info;
2057 nfs_super_set_maxbytes(sb, server->maxfilesize);
2061 * Finish setting up an NFS2/3 superblock
2063 static void nfs_fill_super(struct super_block *sb,
2064 struct nfs_parsed_mount_data *data)
2066 struct nfs_server *server = NFS_SB(sb);
2068 sb->s_blocksize_bits = 0;
2069 sb->s_blocksize = 0;
2071 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
2073 if (server->nfs_client->rpc_ops->version == 3) {
2074 /* The VFS shouldn't apply the umask to mode bits. We will do
2075 * so ourselves when necessary.
2077 sb->s_flags |= MS_POSIXACL;
2078 sb->s_time_gran = 1;
2081 sb->s_op = &nfs_sops;
2082 nfs_initialise_sb(sb);
2086 * Finish setting up a cloned NFS2/3 superblock
2088 static void nfs_clone_super(struct super_block *sb,
2089 const struct super_block *old_sb)
2091 struct nfs_server *server = NFS_SB(sb);
2093 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2094 sb->s_blocksize = old_sb->s_blocksize;
2095 sb->s_maxbytes = old_sb->s_maxbytes;
2097 if (server->nfs_client->rpc_ops->version == 3) {
2098 /* The VFS shouldn't apply the umask to mode bits. We will do
2099 * so ourselves when necessary.
2101 sb->s_flags |= MS_POSIXACL;
2102 sb->s_time_gran = 1;
2105 sb->s_op = old_sb->s_op;
2106 nfs_initialise_sb(sb);
2109 static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
2111 const struct nfs_server *a = s->s_fs_info;
2112 const struct rpc_clnt *clnt_a = a->client;
2113 const struct rpc_clnt *clnt_b = b->client;
2115 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
2117 if (a->nfs_client != b->nfs_client)
2119 if (a->flags != b->flags)
2121 if (a->wsize != b->wsize)
2123 if (a->rsize != b->rsize)
2125 if (a->acregmin != b->acregmin)
2127 if (a->acregmax != b->acregmax)
2129 if (a->acdirmin != b->acdirmin)
2131 if (a->acdirmax != b->acdirmax)
2133 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
2140 struct nfs_sb_mountdata {
2141 struct nfs_server *server;
2145 static int nfs_set_super(struct super_block *s, void *data)
2147 struct nfs_sb_mountdata *sb_mntdata = data;
2148 struct nfs_server *server = sb_mntdata->server;
2151 s->s_flags = sb_mntdata->mntflags;
2152 s->s_fs_info = server;
2153 s->s_d_op = server->nfs_client->rpc_ops->dentry_ops;
2154 ret = set_anon_super(s, server);
2156 server->s_dev = s->s_dev;
2160 static int nfs_compare_super_address(struct nfs_server *server1,
2161 struct nfs_server *server2)
2163 struct sockaddr *sap1, *sap2;
2165 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
2166 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
2168 if (sap1->sa_family != sap2->sa_family)
2171 switch (sap1->sa_family) {
2173 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
2174 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
2175 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
2177 if (sin1->sin_port != sin2->sin_port)
2182 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
2183 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
2184 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
2186 if (sin1->sin6_port != sin2->sin6_port)
2197 static int nfs_compare_super(struct super_block *sb, void *data)
2199 struct nfs_sb_mountdata *sb_mntdata = data;
2200 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2201 int mntflags = sb_mntdata->mntflags;
2203 if (!nfs_compare_super_address(old, server))
2205 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2206 if (old->flags & NFS_MOUNT_UNSHARED)
2208 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2210 return nfs_compare_mount_options(sb, server, mntflags);
2213 static int nfs_bdi_register(struct nfs_server *server)
2215 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
2218 static struct dentry *nfs_fs_mount(struct file_system_type *fs_type,
2219 int flags, const char *dev_name, void *raw_data)
2221 struct nfs_server *server = NULL;
2222 struct super_block *s;
2223 struct nfs_parsed_mount_data *data;
2224 struct nfs_fh *mntfh;
2225 struct dentry *mntroot = ERR_PTR(-ENOMEM);
2226 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2227 struct nfs_sb_mountdata sb_mntdata = {
2232 data = nfs_alloc_parsed_mount_data(NFS_DEFAULT_VERSION);
2233 mntfh = nfs_alloc_fhandle();
2234 if (data == NULL || mntfh == NULL)
2237 /* Validate the mount data */
2238 error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
2240 mntroot = ERR_PTR(error);
2244 #ifdef CONFIG_NFS_V4
2245 if (data->version == 4) {
2246 mntroot = nfs4_try_mount(flags, dev_name, data);
2249 #endif /* CONFIG_NFS_V4 */
2251 /* Get a volume representation */
2252 server = nfs_create_server(data, mntfh);
2253 if (IS_ERR(server)) {
2254 mntroot = ERR_CAST(server);
2257 sb_mntdata.server = server;
2259 if (server->flags & NFS_MOUNT_UNSHARED)
2260 compare_super = NULL;
2262 /* -o noac implies -o sync */
2263 if (server->flags & NFS_MOUNT_NOAC)
2264 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2266 /* Get a superblock - note that we may end up sharing one that already exists */
2267 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
2269 mntroot = ERR_CAST(s);
2273 if (s->s_fs_info != server) {
2274 nfs_free_server(server);
2277 error = nfs_bdi_register(server);
2279 mntroot = ERR_PTR(error);
2280 goto error_splat_bdi;
2285 /* initial superblock/root creation */
2286 nfs_fill_super(s, data);
2287 nfs_fscache_get_super_cookie(s, data->fscache_uniq, NULL);
2290 mntroot = nfs_get_root(s, mntfh, dev_name);
2291 if (IS_ERR(mntroot))
2292 goto error_splat_super;
2294 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
2296 goto error_splat_root;
2298 s->s_flags |= MS_ACTIVE;
2301 nfs_free_parsed_mount_data(data);
2302 nfs_free_fhandle(mntfh);
2306 nfs_free_server(server);
2311 mntroot = ERR_PTR(error);
2313 if (server && !s->s_root)
2314 bdi_unregister(&server->backing_dev_info);
2316 deactivate_locked_super(s);
2321 * Ensure that we unregister the bdi before kill_anon_super
2322 * releases the device name
2324 static void nfs_put_super(struct super_block *s)
2326 struct nfs_server *server = NFS_SB(s);
2328 bdi_unregister(&server->backing_dev_info);
2332 * Destroy an NFS2/3 superblock
2334 static void nfs_kill_super(struct super_block *s)
2336 struct nfs_server *server = NFS_SB(s);
2339 nfs_fscache_release_super_cookie(s);
2340 nfs_free_server(server);
2344 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2346 static struct dentry *
2347 nfs_xdev_mount(struct file_system_type *fs_type, int flags,
2348 const char *dev_name, void *raw_data)
2350 struct nfs_clone_mount *data = raw_data;
2351 struct super_block *s;
2352 struct nfs_server *server;
2353 struct dentry *mntroot;
2354 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2355 struct nfs_sb_mountdata sb_mntdata = {
2360 dprintk("--> nfs_xdev_mount()\n");
2362 /* create a new volume representation */
2363 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2364 if (IS_ERR(server)) {
2365 error = PTR_ERR(server);
2366 goto out_err_noserver;
2368 sb_mntdata.server = server;
2370 if (server->flags & NFS_MOUNT_UNSHARED)
2371 compare_super = NULL;
2373 /* -o noac implies -o sync */
2374 if (server->flags & NFS_MOUNT_NOAC)
2375 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2377 /* Get a superblock - note that we may end up sharing one that already exists */
2378 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2384 if (s->s_fs_info != server) {
2385 nfs_free_server(server);
2388 error = nfs_bdi_register(server);
2390 goto error_splat_bdi;
2394 /* initial superblock/root creation */
2395 nfs_clone_super(s, data->sb);
2396 nfs_fscache_get_super_cookie(s, NULL, data);
2399 mntroot = nfs_get_root(s, data->fh, dev_name);
2400 if (IS_ERR(mntroot)) {
2401 error = PTR_ERR(mntroot);
2402 goto error_splat_super;
2404 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2407 goto error_splat_super;
2410 s->s_flags |= MS_ACTIVE;
2412 /* clone any lsm security options from the parent to the new sb */
2413 security_sb_clone_mnt_opts(data->sb, s);
2415 dprintk("<-- nfs_xdev_mount() = 0\n");
2419 nfs_free_server(server);
2421 dprintk("<-- nfs_xdev_mount() = %d [error]\n", error);
2422 return ERR_PTR(error);
2425 if (server && !s->s_root)
2426 bdi_unregister(&server->backing_dev_info);
2428 deactivate_locked_super(s);
2429 dprintk("<-- nfs_xdev_mount() = %d [splat]\n", error);
2430 return ERR_PTR(error);
2433 #ifdef CONFIG_NFS_V4
2436 * Finish setting up a cloned NFS4 superblock
2438 static void nfs4_clone_super(struct super_block *sb,
2439 const struct super_block *old_sb)
2441 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2442 sb->s_blocksize = old_sb->s_blocksize;
2443 sb->s_maxbytes = old_sb->s_maxbytes;
2444 sb->s_time_gran = 1;
2445 sb->s_op = old_sb->s_op;
2447 * The VFS shouldn't apply the umask to mode bits. We will do
2448 * so ourselves when necessary.
2450 sb->s_flags |= MS_POSIXACL;
2451 sb->s_xattr = old_sb->s_xattr;
2452 nfs_initialise_sb(sb);
2456 * Set up an NFS4 superblock
2458 static void nfs4_fill_super(struct super_block *sb)
2460 sb->s_time_gran = 1;
2461 sb->s_op = &nfs4_sops;
2463 * The VFS shouldn't apply the umask to mode bits. We will do
2464 * so ourselves when necessary.
2466 sb->s_flags |= MS_POSIXACL;
2467 sb->s_xattr = nfs4_xattr_handlers;
2468 nfs_initialise_sb(sb);
2471 static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2473 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3|
2474 NFS_MOUNT_LOCAL_FLOCK|NFS_MOUNT_LOCAL_FCNTL);
2477 static int nfs4_validate_text_mount_data(void *options,
2478 struct nfs_parsed_mount_data *args,
2479 const char *dev_name)
2481 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2483 nfs_set_port(sap, &args->nfs_server.port, NFS_PORT);
2485 nfs_validate_transport_protocol(args);
2487 nfs4_validate_mount_flags(args);
2489 if (args->version != 4) {
2491 "NFS4: Illegal mount version\n");
2495 if (args->auth_flavor_len > 1) {
2497 "NFS4: Too many RPC auth flavours specified\n");
2501 if (args->client_address == NULL) {
2503 "NFS4: mount program didn't pass callback address\n");
2507 return nfs_parse_devname(dev_name,
2508 &args->nfs_server.hostname,
2510 &args->nfs_server.export_path,
2515 * Validate NFSv4 mount options
2517 static int nfs4_validate_mount_data(void *options,
2518 struct nfs_parsed_mount_data *args,
2519 const char *dev_name)
2521 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2522 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
2528 switch (data->version) {
2530 if (data->host_addrlen > sizeof(args->nfs_server.address))
2531 goto out_no_address;
2532 if (data->host_addrlen == 0)
2533 goto out_no_address;
2534 args->nfs_server.addrlen = data->host_addrlen;
2535 if (copy_from_user(sap, data->host_addr, data->host_addrlen))
2537 if (!nfs_verify_server_address(sap))
2538 goto out_no_address;
2540 if (data->auth_flavourlen) {
2541 if (data->auth_flavourlen > 1)
2542 goto out_inval_auth;
2543 if (copy_from_user(&args->auth_flavors[0],
2544 data->auth_flavours,
2545 sizeof(args->auth_flavors[0])))
2549 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2552 args->nfs_server.hostname = c;
2554 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2557 args->nfs_server.export_path = c;
2558 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
2560 c = strndup_user(data->client_addr.data, 16);
2563 args->client_address = c;
2566 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2570 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2571 args->rsize = data->rsize;
2572 args->wsize = data->wsize;
2573 args->timeo = data->timeo;
2574 args->retrans = data->retrans;
2575 args->acregmin = data->acregmin;
2576 args->acregmax = data->acregmax;
2577 args->acdirmin = data->acdirmin;
2578 args->acdirmax = data->acdirmax;
2579 args->nfs_server.protocol = data->proto;
2580 nfs_validate_transport_protocol(args);
2584 if (nfs_parse_mount_options((char *)options, args) == 0)
2587 if (!nfs_verify_server_address(sap))
2590 return nfs4_validate_text_mount_data(options, args, dev_name);
2596 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2600 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2601 data->auth_flavourlen);
2605 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2610 * Get the superblock for the NFS4 root partition
2612 static struct dentry *
2613 nfs4_remote_mount(struct file_system_type *fs_type, int flags,
2614 const char *dev_name, void *raw_data)
2616 struct nfs_parsed_mount_data *data = raw_data;
2617 struct super_block *s;
2618 struct nfs_server *server;
2619 struct nfs_fh *mntfh;
2620 struct dentry *mntroot;
2621 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2622 struct nfs_sb_mountdata sb_mntdata = {
2625 int error = -ENOMEM;
2627 mntfh = nfs_alloc_fhandle();
2628 if (data == NULL || mntfh == NULL)
2631 /* Get a volume representation */
2632 server = nfs4_create_server(data, mntfh);
2633 if (IS_ERR(server)) {
2634 error = PTR_ERR(server);
2637 sb_mntdata.server = server;
2639 if (server->flags & NFS4_MOUNT_UNSHARED)
2640 compare_super = NULL;
2642 /* -o noac implies -o sync */
2643 if (server->flags & NFS_MOUNT_NOAC)
2644 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2646 /* Get a superblock - note that we may end up sharing one that already exists */
2647 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2653 if (s->s_fs_info != server) {
2654 nfs_free_server(server);
2657 error = nfs_bdi_register(server);
2659 goto error_splat_bdi;
2663 /* initial superblock/root creation */
2665 nfs_fscache_get_super_cookie(
2666 s, data ? data->fscache_uniq : NULL, NULL);
2669 mntroot = nfs4_get_root(s, mntfh, dev_name);
2670 if (IS_ERR(mntroot)) {
2671 error = PTR_ERR(mntroot);
2672 goto error_splat_super;
2675 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
2677 goto error_splat_root;
2679 s->s_flags |= MS_ACTIVE;
2681 nfs_free_fhandle(mntfh);
2685 nfs_free_fhandle(mntfh);
2686 return ERR_PTR(error);
2689 nfs_free_server(server);
2695 if (server && !s->s_root)
2696 bdi_unregister(&server->backing_dev_info);
2698 deactivate_locked_super(s);
2702 static struct vfsmount *nfs_do_root_mount(struct file_system_type *fs_type,
2703 int flags, void *data, const char *hostname)
2705 struct vfsmount *root_mnt;
2709 len = strlen(hostname) + 3;
2710 root_devname = kmalloc(len, GFP_KERNEL);
2711 if (root_devname == NULL)
2712 return ERR_PTR(-ENOMEM);
2713 snprintf(root_devname, len, "%s:/", hostname);
2714 root_mnt = vfs_kern_mount(fs_type, flags, root_devname, data);
2715 kfree(root_devname);
2719 struct nfs_referral_count {
2720 struct list_head list;
2721 const struct task_struct *task;
2722 unsigned int referral_count;
2725 static LIST_HEAD(nfs_referral_count_list);
2726 static DEFINE_SPINLOCK(nfs_referral_count_list_lock);
2728 static struct nfs_referral_count *nfs_find_referral_count(void)
2730 struct nfs_referral_count *p;
2732 list_for_each_entry(p, &nfs_referral_count_list, list) {
2733 if (p->task == current)
2739 #define NFS_MAX_NESTED_REFERRALS 2
2741 static int nfs_referral_loop_protect(void)
2743 struct nfs_referral_count *p, *new;
2746 new = kmalloc(sizeof(*new), GFP_KERNEL);
2749 new->task = current;
2750 new->referral_count = 1;
2753 spin_lock(&nfs_referral_count_list_lock);
2754 p = nfs_find_referral_count();
2756 if (p->referral_count >= NFS_MAX_NESTED_REFERRALS)
2759 p->referral_count++;
2761 list_add(&new->list, &nfs_referral_count_list);
2764 spin_unlock(&nfs_referral_count_list_lock);
2770 static void nfs_referral_loop_unprotect(void)
2772 struct nfs_referral_count *p;
2774 spin_lock(&nfs_referral_count_list_lock);
2775 p = nfs_find_referral_count();
2776 p->referral_count--;
2777 if (p->referral_count == 0)
2781 spin_unlock(&nfs_referral_count_list_lock);
2785 static struct dentry *nfs_follow_remote_path(struct vfsmount *root_mnt,
2786 const char *export_path)
2788 struct dentry *dentry;
2791 if (IS_ERR(root_mnt))
2792 return ERR_CAST(root_mnt);
2794 err = nfs_referral_loop_protect();
2797 return ERR_PTR(err);
2800 dentry = mount_subtree(root_mnt, export_path);
2801 nfs_referral_loop_unprotect();
2806 static struct dentry *nfs4_try_mount(int flags, const char *dev_name,
2807 struct nfs_parsed_mount_data *data)
2810 struct vfsmount *root_mnt;
2813 dfprintk(MOUNT, "--> nfs4_try_mount()\n");
2815 export_path = data->nfs_server.export_path;
2816 data->nfs_server.export_path = "/";
2817 root_mnt = nfs_do_root_mount(&nfs4_remote_fs_type, flags, data,
2818 data->nfs_server.hostname);
2819 data->nfs_server.export_path = export_path;
2821 res = nfs_follow_remote_path(root_mnt, export_path);
2823 dfprintk(MOUNT, "<-- nfs4_try_mount() = %ld%s\n",
2824 IS_ERR(res) ? PTR_ERR(res) : 0,
2825 IS_ERR(res) ? " [error]" : "");
2830 * Get the superblock for an NFS4 mountpoint
2832 static struct dentry *nfs4_mount(struct file_system_type *fs_type,
2833 int flags, const char *dev_name, void *raw_data)
2835 struct nfs_parsed_mount_data *data;
2836 int error = -ENOMEM;
2837 struct dentry *res = ERR_PTR(-ENOMEM);
2839 data = nfs_alloc_parsed_mount_data(4);
2843 /* Validate the mount data */
2844 error = nfs4_validate_mount_data(raw_data, data, dev_name);
2846 res = ERR_PTR(error);
2850 res = nfs4_try_mount(flags, dev_name, data);
2852 error = PTR_ERR(res);
2855 nfs_free_parsed_mount_data(data);
2856 dprintk("<-- nfs4_mount() = %d%s\n", error,
2857 error != 0 ? " [error]" : "");
2861 static void nfs4_kill_super(struct super_block *sb)
2863 struct nfs_server *server = NFS_SB(sb);
2865 dprintk("--> %s\n", __func__);
2866 nfs_super_return_all_delegations(sb);
2867 kill_anon_super(sb);
2868 nfs_fscache_release_super_cookie(sb);
2869 nfs_free_server(server);
2870 dprintk("<-- %s\n", __func__);
2874 * Clone an NFS4 server record on xdev traversal (FSID-change)
2876 static struct dentry *
2877 nfs4_xdev_mount(struct file_system_type *fs_type, int flags,
2878 const char *dev_name, void *raw_data)
2880 struct nfs_clone_mount *data = raw_data;
2881 struct super_block *s;
2882 struct nfs_server *server;
2883 struct dentry *mntroot;
2884 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2885 struct nfs_sb_mountdata sb_mntdata = {
2890 dprintk("--> nfs4_xdev_mount()\n");
2892 /* create a new volume representation */
2893 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2894 if (IS_ERR(server)) {
2895 error = PTR_ERR(server);
2896 goto out_err_noserver;
2898 sb_mntdata.server = server;
2900 if (server->flags & NFS4_MOUNT_UNSHARED)
2901 compare_super = NULL;
2903 /* -o noac implies -o sync */
2904 if (server->flags & NFS_MOUNT_NOAC)
2905 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2907 /* Get a superblock - note that we may end up sharing one that already exists */
2908 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2914 if (s->s_fs_info != server) {
2915 nfs_free_server(server);
2918 error = nfs_bdi_register(server);
2920 goto error_splat_bdi;
2924 /* initial superblock/root creation */
2925 nfs4_clone_super(s, data->sb);
2926 nfs_fscache_get_super_cookie(s, NULL, data);
2929 mntroot = nfs4_get_root(s, data->fh, dev_name);
2930 if (IS_ERR(mntroot)) {
2931 error = PTR_ERR(mntroot);
2932 goto error_splat_super;
2934 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2937 goto error_splat_super;
2940 s->s_flags |= MS_ACTIVE;
2942 security_sb_clone_mnt_opts(data->sb, s);
2944 dprintk("<-- nfs4_xdev_mount() = 0\n");
2948 nfs_free_server(server);
2950 dprintk("<-- nfs4_xdev_mount() = %d [error]\n", error);
2951 return ERR_PTR(error);
2954 if (server && !s->s_root)
2955 bdi_unregister(&server->backing_dev_info);
2957 deactivate_locked_super(s);
2958 dprintk("<-- nfs4_xdev_mount() = %d [splat]\n", error);
2959 return ERR_PTR(error);
2962 static struct dentry *
2963 nfs4_remote_referral_mount(struct file_system_type *fs_type, int flags,
2964 const char *dev_name, void *raw_data)
2966 struct nfs_clone_mount *data = raw_data;
2967 struct super_block *s;
2968 struct nfs_server *server;
2969 struct dentry *mntroot;
2970 struct nfs_fh *mntfh;
2971 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2972 struct nfs_sb_mountdata sb_mntdata = {
2975 int error = -ENOMEM;
2977 dprintk("--> nfs4_referral_get_sb()\n");
2979 mntfh = nfs_alloc_fhandle();
2983 /* create a new volume representation */
2984 server = nfs4_create_referral_server(data, mntfh);
2985 if (IS_ERR(server)) {
2986 error = PTR_ERR(server);
2987 goto out_err_noserver;
2989 sb_mntdata.server = server;
2991 if (server->flags & NFS4_MOUNT_UNSHARED)
2992 compare_super = NULL;
2994 /* -o noac implies -o sync */
2995 if (server->flags & NFS_MOUNT_NOAC)
2996 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2998 /* Get a superblock - note that we may end up sharing one that already exists */
2999 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
3005 if (s->s_fs_info != server) {
3006 nfs_free_server(server);
3009 error = nfs_bdi_register(server);
3011 goto error_splat_bdi;
3015 /* initial superblock/root creation */
3017 nfs_fscache_get_super_cookie(s, NULL, data);
3020 mntroot = nfs4_get_root(s, mntfh, dev_name);
3021 if (IS_ERR(mntroot)) {
3022 error = PTR_ERR(mntroot);
3023 goto error_splat_super;
3025 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
3028 goto error_splat_super;
3031 s->s_flags |= MS_ACTIVE;
3033 security_sb_clone_mnt_opts(data->sb, s);
3035 nfs_free_fhandle(mntfh);
3036 dprintk("<-- nfs4_referral_get_sb() = 0\n");
3040 nfs_free_server(server);
3042 nfs_free_fhandle(mntfh);
3044 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
3045 return ERR_PTR(error);
3048 if (server && !s->s_root)
3049 bdi_unregister(&server->backing_dev_info);
3051 deactivate_locked_super(s);
3052 nfs_free_fhandle(mntfh);
3053 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
3054 return ERR_PTR(error);
3058 * Create an NFS4 server record on referral traversal
3060 static struct dentry *nfs4_referral_mount(struct file_system_type *fs_type,
3061 int flags, const char *dev_name, void *raw_data)
3063 struct nfs_clone_mount *data = raw_data;
3065 struct vfsmount *root_mnt;
3068 dprintk("--> nfs4_referral_mount()\n");
3070 export_path = data->mnt_path;
3071 data->mnt_path = "/";
3073 root_mnt = nfs_do_root_mount(&nfs4_remote_referral_fs_type,
3074 flags, data, data->hostname);
3075 data->mnt_path = export_path;
3077 res = nfs_follow_remote_path(root_mnt, export_path);
3078 dprintk("<-- nfs4_referral_mount() = %ld%s\n",
3079 IS_ERR(res) ? PTR_ERR(res) : 0,
3080 IS_ERR(res) ? " [error]" : "");
3084 #endif /* CONFIG_NFS_V4 */