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/smp_lock.h>
43 #include <linux/seq_file.h>
44 #include <linux/mount.h>
45 #include <linux/mnt_namespace.h>
46 #include <linux/namei.h>
47 #include <linux/nfs_idmap.h>
48 #include <linux/vfs.h>
49 #include <linux/inet.h>
50 #include <linux/in6.h>
51 #include <linux/slab.h>
53 #include <linux/netdevice.h>
54 #include <linux/nfs_xdr.h>
55 #include <linux/magic.h>
56 #include <linux/parser.h>
58 #include <asm/system.h>
59 #include <asm/uaccess.h>
63 #include "delegation.h"
68 #define NFSDBG_FACILITY NFSDBG_VFS
71 /* Mount options that take no arguments */
73 Opt_posix, Opt_noposix,
77 Opt_v2, Opt_v3, Opt_v4,
78 Opt_udp, Opt_tcp, Opt_rdma,
80 Opt_rdirplus, Opt_nordirplus,
81 Opt_sharecache, Opt_nosharecache,
82 Opt_resvport, Opt_noresvport,
83 Opt_fscache, Opt_nofscache,
85 /* Mount options that take integer arguments */
87 Opt_rsize, Opt_wsize, Opt_bsize,
88 Opt_timeo, Opt_retrans,
89 Opt_acregmin, Opt_acregmax,
90 Opt_acdirmin, Opt_acdirmax,
98 /* Mount options that take string arguments */
99 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
100 Opt_addr, Opt_mountaddr, Opt_clientaddr,
104 /* Special mount options */
105 Opt_userspace, Opt_deprecated, Opt_sloppy,
110 static const match_table_t nfs_mount_option_tokens = {
111 { Opt_userspace, "bg" },
112 { Opt_userspace, "fg" },
113 { Opt_userspace, "retry=%s" },
115 { Opt_sloppy, "sloppy" },
117 { Opt_soft, "soft" },
118 { Opt_hard, "hard" },
119 { Opt_deprecated, "intr" },
120 { Opt_deprecated, "nointr" },
121 { Opt_posix, "posix" },
122 { Opt_noposix, "noposix" },
124 { Opt_nocto, "nocto" },
126 { Opt_noac, "noac" },
127 { Opt_lock, "lock" },
128 { Opt_nolock, "nolock" },
134 { Opt_rdma, "rdma" },
136 { Opt_noacl, "noacl" },
137 { Opt_rdirplus, "rdirplus" },
138 { Opt_nordirplus, "nordirplus" },
139 { Opt_sharecache, "sharecache" },
140 { Opt_nosharecache, "nosharecache" },
141 { Opt_resvport, "resvport" },
142 { Opt_noresvport, "noresvport" },
143 { Opt_fscache, "fsc" },
144 { Opt_nofscache, "nofsc" },
146 { Opt_port, "port=%s" },
147 { Opt_rsize, "rsize=%s" },
148 { Opt_wsize, "wsize=%s" },
149 { Opt_bsize, "bsize=%s" },
150 { Opt_timeo, "timeo=%s" },
151 { Opt_retrans, "retrans=%s" },
152 { Opt_acregmin, "acregmin=%s" },
153 { Opt_acregmax, "acregmax=%s" },
154 { Opt_acdirmin, "acdirmin=%s" },
155 { Opt_acdirmax, "acdirmax=%s" },
156 { Opt_actimeo, "actimeo=%s" },
157 { Opt_namelen, "namlen=%s" },
158 { Opt_mountport, "mountport=%s" },
159 { Opt_mountvers, "mountvers=%s" },
160 { Opt_nfsvers, "nfsvers=%s" },
161 { Opt_nfsvers, "vers=%s" },
162 { Opt_minorversion, "minorversion=%s" },
164 { Opt_sec, "sec=%s" },
165 { Opt_proto, "proto=%s" },
166 { Opt_mountproto, "mountproto=%s" },
167 { Opt_addr, "addr=%s" },
168 { Opt_clientaddr, "clientaddr=%s" },
169 { Opt_mounthost, "mounthost=%s" },
170 { Opt_mountaddr, "mountaddr=%s" },
172 { Opt_lookupcache, "lookupcache=%s" },
173 { Opt_fscache_uniq, "fsc=%s" },
179 Opt_xprt_udp, Opt_xprt_udp6, Opt_xprt_tcp, Opt_xprt_tcp6, Opt_xprt_rdma,
184 static const match_table_t nfs_xprt_protocol_tokens = {
185 { Opt_xprt_udp, "udp" },
186 { Opt_xprt_udp6, "udp6" },
187 { Opt_xprt_tcp, "tcp" },
188 { Opt_xprt_tcp6, "tcp6" },
189 { Opt_xprt_rdma, "rdma" },
191 { Opt_xprt_err, NULL }
195 Opt_sec_none, Opt_sec_sys,
196 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
197 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
198 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
203 static const match_table_t nfs_secflavor_tokens = {
204 { Opt_sec_none, "none" },
205 { Opt_sec_none, "null" },
206 { Opt_sec_sys, "sys" },
208 { Opt_sec_krb5, "krb5" },
209 { Opt_sec_krb5i, "krb5i" },
210 { Opt_sec_krb5p, "krb5p" },
212 { Opt_sec_lkey, "lkey" },
213 { Opt_sec_lkeyi, "lkeyi" },
214 { Opt_sec_lkeyp, "lkeyp" },
216 { Opt_sec_spkm, "spkm3" },
217 { Opt_sec_spkmi, "spkm3i" },
218 { Opt_sec_spkmp, "spkm3p" },
220 { Opt_sec_err, NULL }
224 Opt_lookupcache_all, Opt_lookupcache_positive,
225 Opt_lookupcache_none,
230 static match_table_t nfs_lookupcache_tokens = {
231 { Opt_lookupcache_all, "all" },
232 { Opt_lookupcache_positive, "pos" },
233 { Opt_lookupcache_positive, "positive" },
234 { Opt_lookupcache_none, "none" },
236 { Opt_lookupcache_err, NULL }
240 static void nfs_umount_begin(struct super_block *);
241 static int nfs_statfs(struct dentry *, struct kstatfs *);
242 static int nfs_show_options(struct seq_file *, struct vfsmount *);
243 static int nfs_show_stats(struct seq_file *, struct vfsmount *);
244 static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
245 static int nfs_xdev_get_sb(struct file_system_type *fs_type,
246 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
247 static void nfs_put_super(struct super_block *);
248 static void nfs_kill_super(struct super_block *);
249 static int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
251 static struct file_system_type nfs_fs_type = {
252 .owner = THIS_MODULE,
254 .get_sb = nfs_get_sb,
255 .kill_sb = nfs_kill_super,
256 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
259 struct file_system_type nfs_xdev_fs_type = {
260 .owner = THIS_MODULE,
262 .get_sb = nfs_xdev_get_sb,
263 .kill_sb = nfs_kill_super,
264 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
267 static const struct super_operations nfs_sops = {
268 .alloc_inode = nfs_alloc_inode,
269 .destroy_inode = nfs_destroy_inode,
270 .write_inode = nfs_write_inode,
271 .put_super = nfs_put_super,
272 .statfs = nfs_statfs,
273 .clear_inode = nfs_clear_inode,
274 .umount_begin = nfs_umount_begin,
275 .show_options = nfs_show_options,
276 .show_stats = nfs_show_stats,
277 .remount_fs = nfs_remount,
281 static int nfs4_validate_text_mount_data(void *options,
282 struct nfs_parsed_mount_data *args, const char *dev_name);
283 static int nfs4_try_mount(int flags, const char *dev_name,
284 struct nfs_parsed_mount_data *data, struct vfsmount *mnt);
285 static int nfs4_get_sb(struct file_system_type *fs_type,
286 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
287 static int nfs4_remote_get_sb(struct file_system_type *fs_type,
288 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
289 static int nfs4_xdev_get_sb(struct file_system_type *fs_type,
290 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
291 static int nfs4_referral_get_sb(struct file_system_type *fs_type,
292 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
293 static int nfs4_remote_referral_get_sb(struct file_system_type *fs_type,
294 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
295 static void nfs4_kill_super(struct super_block *sb);
297 static struct file_system_type nfs4_fs_type = {
298 .owner = THIS_MODULE,
300 .get_sb = nfs4_get_sb,
301 .kill_sb = nfs4_kill_super,
302 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
305 static struct file_system_type nfs4_remote_fs_type = {
306 .owner = THIS_MODULE,
308 .get_sb = nfs4_remote_get_sb,
309 .kill_sb = nfs4_kill_super,
310 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
313 struct file_system_type nfs4_xdev_fs_type = {
314 .owner = THIS_MODULE,
316 .get_sb = nfs4_xdev_get_sb,
317 .kill_sb = nfs4_kill_super,
318 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
321 static struct file_system_type nfs4_remote_referral_fs_type = {
322 .owner = THIS_MODULE,
324 .get_sb = nfs4_remote_referral_get_sb,
325 .kill_sb = nfs4_kill_super,
326 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
329 struct file_system_type nfs4_referral_fs_type = {
330 .owner = THIS_MODULE,
332 .get_sb = nfs4_referral_get_sb,
333 .kill_sb = nfs4_kill_super,
334 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
337 static const struct super_operations nfs4_sops = {
338 .alloc_inode = nfs_alloc_inode,
339 .destroy_inode = nfs_destroy_inode,
340 .write_inode = nfs_write_inode,
341 .put_super = nfs_put_super,
342 .statfs = nfs_statfs,
343 .clear_inode = nfs4_clear_inode,
344 .umount_begin = nfs_umount_begin,
345 .show_options = nfs_show_options,
346 .show_stats = nfs_show_stats,
347 .remount_fs = nfs_remount,
351 static struct shrinker acl_shrinker = {
352 .shrink = nfs_access_cache_shrinker,
353 .seeks = DEFAULT_SEEKS,
357 * Register the NFS filesystems
359 int __init register_nfs_fs(void)
363 ret = register_filesystem(&nfs_fs_type);
367 ret = nfs_register_sysctl();
371 ret = register_filesystem(&nfs4_fs_type);
375 register_shrinker(&acl_shrinker);
380 nfs_unregister_sysctl();
383 unregister_filesystem(&nfs_fs_type);
389 * Unregister the NFS filesystems
391 void __exit unregister_nfs_fs(void)
393 unregister_shrinker(&acl_shrinker);
395 unregister_filesystem(&nfs4_fs_type);
397 nfs_unregister_sysctl();
398 unregister_filesystem(&nfs_fs_type);
401 void nfs_sb_active(struct super_block *sb)
403 struct nfs_server *server = NFS_SB(sb);
405 if (atomic_inc_return(&server->active) == 1)
406 atomic_inc(&sb->s_active);
409 void nfs_sb_deactive(struct super_block *sb)
411 struct nfs_server *server = NFS_SB(sb);
413 if (atomic_dec_and_test(&server->active))
414 deactivate_super(sb);
418 * Deliver file system statistics to userspace
420 static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
422 struct nfs_server *server = NFS_SB(dentry->d_sb);
423 unsigned char blockbits;
424 unsigned long blockres;
425 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
426 struct nfs_fsstat res;
429 res.fattr = nfs_alloc_fattr();
430 if (res.fattr == NULL)
433 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
435 nfs_free_fattr(res.fattr);
439 buf->f_type = NFS_SUPER_MAGIC;
442 * Current versions of glibc do not correctly handle the
443 * case where f_frsize != f_bsize. Eventually we want to
444 * report the value of wtmult in this field.
446 buf->f_frsize = dentry->d_sb->s_blocksize;
449 * On most *nix systems, f_blocks, f_bfree, and f_bavail
450 * are reported in units of f_frsize. Linux hasn't had
451 * an f_frsize field in its statfs struct until recently,
452 * thus historically Linux's sys_statfs reports these
453 * fields in units of f_bsize.
455 buf->f_bsize = dentry->d_sb->s_blocksize;
456 blockbits = dentry->d_sb->s_blocksize_bits;
457 blockres = (1 << blockbits) - 1;
458 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
459 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
460 buf->f_bavail = (res.abytes + blockres) >> blockbits;
462 buf->f_files = res.tfiles;
463 buf->f_ffree = res.afiles;
465 buf->f_namelen = server->namelen;
470 dprintk("%s: statfs error = %d\n", __func__, -error);
475 * Map the security flavour number to a name
477 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
479 static const struct {
480 rpc_authflavor_t flavour;
483 { RPC_AUTH_NULL, "null" },
484 { RPC_AUTH_UNIX, "sys" },
485 { RPC_AUTH_GSS_KRB5, "krb5" },
486 { RPC_AUTH_GSS_KRB5I, "krb5i" },
487 { RPC_AUTH_GSS_KRB5P, "krb5p" },
488 { RPC_AUTH_GSS_LKEY, "lkey" },
489 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
490 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
491 { RPC_AUTH_GSS_SPKM, "spkm" },
492 { RPC_AUTH_GSS_SPKMI, "spkmi" },
493 { RPC_AUTH_GSS_SPKMP, "spkmp" },
494 { UINT_MAX, "unknown" }
498 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
499 if (sec_flavours[i].flavour == flavour)
502 return sec_flavours[i].str;
505 static void nfs_show_mountd_netid(struct seq_file *m, struct nfs_server *nfss,
508 struct sockaddr *sap = (struct sockaddr *) &nfss->mountd_address;
510 seq_printf(m, ",mountproto=");
511 switch (sap->sa_family) {
513 switch (nfss->mountd_protocol) {
515 seq_printf(m, RPCBIND_NETID_UDP);
518 seq_printf(m, RPCBIND_NETID_TCP);
522 seq_printf(m, "auto");
526 switch (nfss->mountd_protocol) {
528 seq_printf(m, RPCBIND_NETID_UDP6);
531 seq_printf(m, RPCBIND_NETID_TCP6);
535 seq_printf(m, "auto");
540 seq_printf(m, "auto");
544 static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
547 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
549 if (nfss->flags & NFS_MOUNT_LEGACY_INTERFACE)
552 switch (sap->sa_family) {
554 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
555 seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
559 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
560 seq_printf(m, ",mountaddr=%pI6c", &sin6->sin6_addr);
565 seq_printf(m, ",mountaddr=unspecified");
568 if (nfss->mountd_version || showdefaults)
569 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
570 if (nfss->mountd_port || showdefaults)
571 seq_printf(m, ",mountport=%u", nfss->mountd_port);
573 nfs_show_mountd_netid(m, nfss, showdefaults);
577 static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
580 struct nfs_client *clp = nfss->nfs_client;
582 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
583 seq_printf(m, ",minorversion=%u", clp->cl_minorversion);
586 static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
593 * Describe the mount options in force on this server representation
595 static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
598 static const struct proc_nfs_info {
603 { NFS_MOUNT_SOFT, ",soft", ",hard" },
604 { NFS_MOUNT_POSIX, ",posix", "" },
605 { NFS_MOUNT_NOCTO, ",nocto", "" },
606 { NFS_MOUNT_NOAC, ",noac", "" },
607 { NFS_MOUNT_NONLM, ",nolock", "" },
608 { NFS_MOUNT_NOACL, ",noacl", "" },
609 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
610 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
611 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
614 const struct proc_nfs_info *nfs_infop;
615 struct nfs_client *clp = nfss->nfs_client;
616 u32 version = clp->rpc_ops->version;
618 seq_printf(m, ",vers=%u", version);
619 seq_printf(m, ",rsize=%u", nfss->rsize);
620 seq_printf(m, ",wsize=%u", nfss->wsize);
621 if (nfss->bsize != 0)
622 seq_printf(m, ",bsize=%u", nfss->bsize);
623 seq_printf(m, ",namlen=%u", nfss->namelen);
624 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
625 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
626 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
627 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
628 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
629 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
630 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
631 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
632 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
633 if (nfss->flags & nfs_infop->flag)
634 seq_puts(m, nfs_infop->str);
636 seq_puts(m, nfs_infop->nostr);
638 seq_printf(m, ",proto=%s",
639 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
641 if (nfss->port != NFS_PORT)
642 seq_printf(m, ",port=%u", nfss->port);
645 seq_printf(m, ",port=%u", nfss->port);
647 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
648 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
649 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
652 nfs_show_mountd_options(m, nfss, showdefaults);
654 nfs_show_nfsv4_options(m, nfss, showdefaults);
656 if (nfss->options & NFS_OPTION_FSCACHE)
657 seq_printf(m, ",fsc");
661 * Describe the mount options on this VFS mountpoint
663 static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
665 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
667 nfs_show_mount_options(m, nfss, 0);
669 seq_printf(m, ",addr=%s",
670 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
677 * Present statistical information for this VFS mountpoint
679 static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
682 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
683 struct rpc_auth *auth = nfss->client->cl_auth;
684 struct nfs_iostats totals = { };
686 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
689 * Display all mount option settings
691 seq_printf(m, "\n\topts:\t");
692 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
693 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
694 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
695 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
696 nfs_show_mount_options(m, nfss, 1);
698 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
700 seq_printf(m, "\n\tcaps:\t");
701 seq_printf(m, "caps=0x%x", nfss->caps);
702 seq_printf(m, ",wtmult=%u", nfss->wtmult);
703 seq_printf(m, ",dtsize=%u", nfss->dtsize);
704 seq_printf(m, ",bsize=%u", nfss->bsize);
705 seq_printf(m, ",namlen=%u", nfss->namelen);
708 if (nfss->nfs_client->rpc_ops->version == 4) {
709 seq_printf(m, "\n\tnfsv4:\t");
710 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
711 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
712 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
717 * Display security flavor in effect for this mount
719 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
721 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
724 * Display superblock I/O counters
726 for_each_possible_cpu(cpu) {
727 struct nfs_iostats *stats;
730 stats = per_cpu_ptr(nfss->io_stats, cpu);
732 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
733 totals.events[i] += stats->events[i];
734 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
735 totals.bytes[i] += stats->bytes[i];
736 #ifdef CONFIG_NFS_FSCACHE
737 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
738 totals.fscache[i] += stats->fscache[i];
744 seq_printf(m, "\n\tevents:\t");
745 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
746 seq_printf(m, "%lu ", totals.events[i]);
747 seq_printf(m, "\n\tbytes:\t");
748 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
749 seq_printf(m, "%Lu ", totals.bytes[i]);
750 #ifdef CONFIG_NFS_FSCACHE
751 if (nfss->options & NFS_OPTION_FSCACHE) {
752 seq_printf(m, "\n\tfsc:\t");
753 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
754 seq_printf(m, "%Lu ", totals.bytes[i]);
759 rpc_print_iostats(m, nfss->client);
765 * Begin unmount by attempting to remove all automounted mountpoints we added
766 * in response to xdev traversals and referrals
768 static void nfs_umount_begin(struct super_block *sb)
770 struct nfs_server *server;
771 struct rpc_clnt *rpc;
774 /* -EIO all pending I/O */
775 rpc = server->client_acl;
777 rpc_killall_tasks(rpc);
778 rpc = server->client;
780 rpc_killall_tasks(rpc);
783 static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(unsigned int version)
785 struct nfs_parsed_mount_data *data;
787 data = kzalloc(sizeof(*data), GFP_KERNEL);
789 data->acregmin = NFS_DEF_ACREGMIN;
790 data->acregmax = NFS_DEF_ACREGMAX;
791 data->acdirmin = NFS_DEF_ACDIRMIN;
792 data->acdirmax = NFS_DEF_ACDIRMAX;
793 data->mount_server.port = NFS_UNSPEC_PORT;
794 data->nfs_server.port = NFS_UNSPEC_PORT;
795 data->nfs_server.protocol = XPRT_TRANSPORT_TCP;
796 data->auth_flavors[0] = RPC_AUTH_UNIX;
797 data->auth_flavor_len = 1;
798 data->version = version;
799 data->minorversion = 0;
805 * Sanity-check a server address provided by the mount command.
807 * Address family must be initialized, and address must not be
808 * the ANY address for that family.
810 static int nfs_verify_server_address(struct sockaddr *addr)
812 switch (addr->sa_family) {
814 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
815 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
818 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
819 return !ipv6_addr_any(sa);
823 dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
828 * Select between a default port value and a user-specified port value.
829 * If a zero value is set, then autobind will be used.
831 static void nfs_set_port(struct sockaddr *sap, int *port,
832 const unsigned short default_port)
834 if (*port == NFS_UNSPEC_PORT)
835 *port = default_port;
837 rpc_set_port(sap, *port);
841 * Sanity check the NFS transport protocol.
844 static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
846 switch (mnt->nfs_server.protocol) {
847 case XPRT_TRANSPORT_UDP:
848 case XPRT_TRANSPORT_TCP:
849 case XPRT_TRANSPORT_RDMA:
852 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
857 * For text based NFSv2/v3 mounts, the mount protocol transport default
858 * settings should depend upon the specified NFS transport.
860 static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
862 nfs_validate_transport_protocol(mnt);
864 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
865 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
867 switch (mnt->nfs_server.protocol) {
868 case XPRT_TRANSPORT_UDP:
869 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
871 case XPRT_TRANSPORT_TCP:
872 case XPRT_TRANSPORT_RDMA:
873 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
878 * Parse the value of the 'sec=' option.
880 static int nfs_parse_security_flavors(char *value,
881 struct nfs_parsed_mount_data *mnt)
883 substring_t args[MAX_OPT_ARGS];
885 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
887 switch (match_token(value, nfs_secflavor_tokens, args)) {
889 mnt->auth_flavors[0] = RPC_AUTH_NULL;
892 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
895 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
898 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
901 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
904 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
907 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
910 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
913 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
916 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
919 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
925 mnt->auth_flavor_len = 1;
930 * Error-check and convert a string of mount options from user space into
931 * a data structure. The whole mount string is processed; bad options are
932 * skipped as they are encountered. If there were no errors, return 1;
933 * otherwise return 0 (zero).
935 static int nfs_parse_mount_options(char *raw,
936 struct nfs_parsed_mount_data *mnt)
938 char *p, *string, *secdata;
939 int rc, sloppy = 0, invalid_option = 0;
940 unsigned short protofamily = AF_UNSPEC;
941 unsigned short mountfamily = AF_UNSPEC;
944 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
947 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
949 secdata = alloc_secdata();
953 rc = security_sb_copy_data(raw, secdata);
955 goto out_security_failure;
957 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
959 goto out_security_failure;
961 free_secdata(secdata);
963 while ((p = strsep(&raw, ",")) != NULL) {
964 substring_t args[MAX_OPT_ARGS];
965 unsigned long option;
971 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
973 token = match_token(p, nfs_mount_option_tokens, args);
977 * boolean options: foo/nofoo
980 mnt->flags |= NFS_MOUNT_SOFT;
983 mnt->flags &= ~NFS_MOUNT_SOFT;
986 mnt->flags |= NFS_MOUNT_POSIX;
989 mnt->flags &= ~NFS_MOUNT_POSIX;
992 mnt->flags &= ~NFS_MOUNT_NOCTO;
995 mnt->flags |= NFS_MOUNT_NOCTO;
998 mnt->flags &= ~NFS_MOUNT_NOAC;
1001 mnt->flags |= NFS_MOUNT_NOAC;
1004 mnt->flags &= ~NFS_MOUNT_NONLM;
1007 mnt->flags |= NFS_MOUNT_NONLM;
1010 mnt->flags &= ~NFS_MOUNT_VER3;
1014 mnt->flags |= NFS_MOUNT_VER3;
1017 #ifdef CONFIG_NFS_V4
1019 mnt->flags &= ~NFS_MOUNT_VER3;
1024 mnt->flags &= ~NFS_MOUNT_TCP;
1025 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1028 mnt->flags |= NFS_MOUNT_TCP;
1029 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1032 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1033 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1034 xprt_load_transport(p);
1037 mnt->flags &= ~NFS_MOUNT_NOACL;
1040 mnt->flags |= NFS_MOUNT_NOACL;
1043 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1045 case Opt_nordirplus:
1046 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1048 case Opt_sharecache:
1049 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1051 case Opt_nosharecache:
1052 mnt->flags |= NFS_MOUNT_UNSHARED;
1055 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1057 case Opt_noresvport:
1058 mnt->flags |= NFS_MOUNT_NORESVPORT;
1061 mnt->options |= NFS_OPTION_FSCACHE;
1062 kfree(mnt->fscache_uniq);
1063 mnt->fscache_uniq = NULL;
1066 mnt->options &= ~NFS_OPTION_FSCACHE;
1067 kfree(mnt->fscache_uniq);
1068 mnt->fscache_uniq = NULL;
1072 * options that take numeric values
1075 string = match_strdup(args);
1078 rc = strict_strtoul(string, 10, &option);
1080 if (rc != 0 || option > USHRT_MAX)
1081 goto out_invalid_value;
1082 mnt->nfs_server.port = option;
1085 string = match_strdup(args);
1088 rc = strict_strtoul(string, 10, &option);
1091 goto out_invalid_value;
1092 mnt->rsize = option;
1095 string = match_strdup(args);
1098 rc = strict_strtoul(string, 10, &option);
1101 goto out_invalid_value;
1102 mnt->wsize = option;
1105 string = match_strdup(args);
1108 rc = strict_strtoul(string, 10, &option);
1111 goto out_invalid_value;
1112 mnt->bsize = option;
1115 string = match_strdup(args);
1118 rc = strict_strtoul(string, 10, &option);
1120 if (rc != 0 || option == 0)
1121 goto out_invalid_value;
1122 mnt->timeo = option;
1125 string = match_strdup(args);
1128 rc = strict_strtoul(string, 10, &option);
1130 if (rc != 0 || option == 0)
1131 goto out_invalid_value;
1132 mnt->retrans = option;
1135 string = match_strdup(args);
1138 rc = strict_strtoul(string, 10, &option);
1141 goto out_invalid_value;
1142 mnt->acregmin = option;
1145 string = match_strdup(args);
1148 rc = strict_strtoul(string, 10, &option);
1151 goto out_invalid_value;
1152 mnt->acregmax = option;
1155 string = match_strdup(args);
1158 rc = strict_strtoul(string, 10, &option);
1161 goto out_invalid_value;
1162 mnt->acdirmin = option;
1165 string = match_strdup(args);
1168 rc = strict_strtoul(string, 10, &option);
1171 goto out_invalid_value;
1172 mnt->acdirmax = option;
1175 string = match_strdup(args);
1178 rc = strict_strtoul(string, 10, &option);
1181 goto out_invalid_value;
1182 mnt->acregmin = mnt->acregmax =
1183 mnt->acdirmin = mnt->acdirmax = option;
1186 string = match_strdup(args);
1189 rc = strict_strtoul(string, 10, &option);
1192 goto out_invalid_value;
1193 mnt->namlen = option;
1196 string = match_strdup(args);
1199 rc = strict_strtoul(string, 10, &option);
1201 if (rc != 0 || option > USHRT_MAX)
1202 goto out_invalid_value;
1203 mnt->mount_server.port = option;
1206 string = match_strdup(args);
1209 rc = strict_strtoul(string, 10, &option);
1212 option < NFS_MNT_VERSION ||
1213 option > NFS_MNT3_VERSION)
1214 goto out_invalid_value;
1215 mnt->mount_server.version = option;
1218 string = match_strdup(args);
1221 rc = strict_strtoul(string, 10, &option);
1224 goto out_invalid_value;
1227 mnt->flags &= ~NFS_MOUNT_VER3;
1231 mnt->flags |= NFS_MOUNT_VER3;
1234 #ifdef CONFIG_NFS_V4
1236 mnt->flags &= ~NFS_MOUNT_VER3;
1241 goto out_invalid_value;
1244 case Opt_minorversion:
1245 string = match_strdup(args);
1248 rc = strict_strtoul(string, 10, &option);
1251 goto out_invalid_value;
1252 if (option > NFS4_MAX_MINOR_VERSION)
1253 goto out_invalid_value;
1254 mnt->minorversion = option;
1258 * options that take text values
1261 string = match_strdup(args);
1264 rc = nfs_parse_security_flavors(string, mnt);
1267 dfprintk(MOUNT, "NFS: unrecognized "
1268 "security flavor\n");
1273 string = match_strdup(args);
1276 token = match_token(string,
1277 nfs_xprt_protocol_tokens, args);
1279 protofamily = AF_INET;
1282 protofamily = AF_INET6;
1284 mnt->flags &= ~NFS_MOUNT_TCP;
1285 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1289 protofamily = AF_INET6;
1291 mnt->flags |= NFS_MOUNT_TCP;
1292 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1296 /* vector side protocols to TCP */
1297 mnt->flags |= NFS_MOUNT_TCP;
1298 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1299 xprt_load_transport(string);
1303 dfprintk(MOUNT, "NFS: unrecognized "
1304 "transport protocol\n");
1309 case Opt_mountproto:
1310 string = match_strdup(args);
1313 token = match_token(string,
1314 nfs_xprt_protocol_tokens, args);
1317 mountfamily = AF_INET;
1320 mountfamily = AF_INET6;
1322 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
1325 mountfamily = AF_INET6;
1327 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
1329 case Opt_xprt_rdma: /* not used for side protocols */
1331 dfprintk(MOUNT, "NFS: unrecognized "
1332 "transport protocol\n");
1337 string = match_strdup(args);
1340 mnt->nfs_server.addrlen =
1341 rpc_pton(string, strlen(string),
1343 &mnt->nfs_server.address,
1344 sizeof(mnt->nfs_server.address));
1346 if (mnt->nfs_server.addrlen == 0)
1347 goto out_invalid_address;
1349 case Opt_clientaddr:
1350 string = match_strdup(args);
1353 kfree(mnt->client_address);
1354 mnt->client_address = string;
1357 string = match_strdup(args);
1360 kfree(mnt->mount_server.hostname);
1361 mnt->mount_server.hostname = string;
1364 string = match_strdup(args);
1367 mnt->mount_server.addrlen =
1368 rpc_pton(string, strlen(string),
1370 &mnt->mount_server.address,
1371 sizeof(mnt->mount_server.address));
1373 if (mnt->mount_server.addrlen == 0)
1374 goto out_invalid_address;
1376 case Opt_lookupcache:
1377 string = match_strdup(args);
1380 token = match_token(string,
1381 nfs_lookupcache_tokens, args);
1384 case Opt_lookupcache_all:
1385 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1387 case Opt_lookupcache_positive:
1388 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1389 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1391 case Opt_lookupcache_none:
1392 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1395 dfprintk(MOUNT, "NFS: invalid "
1396 "lookupcache argument\n");
1400 case Opt_fscache_uniq:
1401 string = match_strdup(args);
1404 kfree(mnt->fscache_uniq);
1405 mnt->fscache_uniq = string;
1406 mnt->options |= NFS_OPTION_FSCACHE;
1414 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1417 case Opt_deprecated:
1418 dfprintk(MOUNT, "NFS: ignoring mount option "
1424 dfprintk(MOUNT, "NFS: unrecognized mount option "
1429 if (!sloppy && invalid_option)
1433 * verify that any proto=/mountproto= options match the address
1434 * familiies in the addr=/mountaddr= options.
1436 if (protofamily != AF_UNSPEC &&
1437 protofamily != mnt->nfs_server.address.ss_family)
1438 goto out_proto_mismatch;
1440 if (mountfamily != AF_UNSPEC) {
1441 if (mnt->mount_server.addrlen) {
1442 if (mountfamily != mnt->mount_server.address.ss_family)
1443 goto out_mountproto_mismatch;
1445 if (mountfamily != mnt->nfs_server.address.ss_family)
1446 goto out_mountproto_mismatch;
1452 out_mountproto_mismatch:
1453 printk(KERN_INFO "NFS: mount server address does not match mountproto= "
1457 printk(KERN_INFO "NFS: server address does not match proto= option\n");
1459 out_invalid_address:
1460 printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
1463 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
1466 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1468 out_security_failure:
1469 free_secdata(secdata);
1470 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1475 * Match the requested auth flavors with the list returned by
1476 * the server. Returns zero and sets the mount's authentication
1477 * flavor on success; returns -EACCES if server does not support
1478 * the requested flavor.
1480 static int nfs_walk_authlist(struct nfs_parsed_mount_data *args,
1481 struct nfs_mount_request *request)
1483 unsigned int i, j, server_authlist_len = *(request->auth_flav_len);
1486 * Certain releases of Linux's mountd return an empty
1487 * flavor list. To prevent behavioral regression with
1488 * these servers (ie. rejecting mounts that used to
1489 * succeed), revert to pre-2.6.32 behavior (no checking)
1490 * if the returned flavor list is empty.
1492 if (server_authlist_len == 0)
1496 * We avoid sophisticated negotiating here, as there are
1497 * plenty of cases where we can get it wrong, providing
1498 * either too little or too much security.
1500 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1501 * flavor listed first. However, some servers list
1502 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1503 * preferred default, in args->auth_flavors[0] if user
1504 * didn't specify sec= mount option.
1506 for (i = 0; i < args->auth_flavor_len; i++)
1507 for (j = 0; j < server_authlist_len; j++)
1508 if (args->auth_flavors[i] == request->auth_flavs[j]) {
1509 dfprintk(MOUNT, "NFS: using auth flavor %d\n",
1510 request->auth_flavs[j]);
1511 args->auth_flavors[0] = request->auth_flavs[j];
1515 dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n");
1516 nfs_umount(request);
1521 * Use the remote server's MOUNT service to request the NFS file handle
1522 * corresponding to the provided path.
1524 static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1525 struct nfs_fh *root_fh)
1527 rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS];
1528 unsigned int server_authlist_len = ARRAY_SIZE(server_authlist);
1529 struct nfs_mount_request request = {
1530 .sap = (struct sockaddr *)
1531 &args->mount_server.address,
1532 .dirpath = args->nfs_server.export_path,
1533 .protocol = args->mount_server.protocol,
1535 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
1536 .auth_flav_len = &server_authlist_len,
1537 .auth_flavs = server_authlist,
1541 if (args->mount_server.version == 0) {
1542 switch (args->version) {
1544 args->mount_server.version = NFS_MNT3_VERSION;
1547 args->mount_server.version = NFS_MNT_VERSION;
1550 request.version = args->mount_server.version;
1552 if (args->mount_server.hostname)
1553 request.hostname = args->mount_server.hostname;
1555 request.hostname = args->nfs_server.hostname;
1558 * Construct the mount server's address.
1560 if (args->mount_server.address.ss_family == AF_UNSPEC) {
1561 memcpy(request.sap, &args->nfs_server.address,
1562 args->nfs_server.addrlen);
1563 args->mount_server.addrlen = args->nfs_server.addrlen;
1565 request.salen = args->mount_server.addrlen;
1566 nfs_set_port(request.sap, &args->mount_server.port, 0);
1569 * Now ask the mount server to map our export path
1572 status = nfs_mount(&request);
1574 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1575 request.hostname, status);
1580 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1582 if (args->mount_server.version != NFS_MNT3_VERSION)
1584 return nfs_walk_authlist(args, &request);
1587 static int nfs_parse_simple_hostname(const char *dev_name,
1588 char **hostname, size_t maxnamlen,
1589 char **export_path, size_t maxpathlen)
1592 char *colon, *comma;
1594 colon = strchr(dev_name, ':');
1596 goto out_bad_devname;
1598 len = colon - dev_name;
1599 if (len > maxnamlen)
1602 /* N.B. caller will free nfs_server.hostname in all cases */
1603 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
1607 /* kill possible hostname list: not supported */
1608 comma = strchr(*hostname, ',');
1609 if (comma != NULL) {
1610 if (comma == *hostname)
1611 goto out_bad_devname;
1616 len = strlen(colon);
1617 if (len > maxpathlen)
1619 *export_path = kstrndup(colon, len, GFP_KERNEL);
1623 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1627 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1631 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1635 dfprintk(MOUNT, "NFS: server hostname too long\n");
1636 return -ENAMETOOLONG;
1639 dfprintk(MOUNT, "NFS: export pathname too long\n");
1640 return -ENAMETOOLONG;
1644 * Hostname has square brackets around it because it contains one or
1645 * more colons. We look for the first closing square bracket, and a
1646 * colon must follow it.
1648 static int nfs_parse_protected_hostname(const char *dev_name,
1649 char **hostname, size_t maxnamlen,
1650 char **export_path, size_t maxpathlen)
1655 start = (char *)(dev_name + 1);
1657 end = strchr(start, ']');
1659 goto out_bad_devname;
1660 if (*(end + 1) != ':')
1661 goto out_bad_devname;
1664 if (len > maxnamlen)
1667 /* N.B. caller will free nfs_server.hostname in all cases */
1668 *hostname = kstrndup(start, len, GFP_KERNEL);
1669 if (*hostname == NULL)
1674 if (len > maxpathlen)
1676 *export_path = kstrndup(end, len, GFP_KERNEL);
1683 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1687 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1691 dfprintk(MOUNT, "NFS: server hostname too long\n");
1692 return -ENAMETOOLONG;
1695 dfprintk(MOUNT, "NFS: export pathname too long\n");
1696 return -ENAMETOOLONG;
1700 * Split "dev_name" into "hostname:export_path".
1702 * The leftmost colon demarks the split between the server's hostname
1703 * and the export path. If the hostname starts with a left square
1704 * bracket, then it may contain colons.
1706 * Note: caller frees hostname and export path, even on error.
1708 static int nfs_parse_devname(const char *dev_name,
1709 char **hostname, size_t maxnamlen,
1710 char **export_path, size_t maxpathlen)
1712 if (*dev_name == '[')
1713 return nfs_parse_protected_hostname(dev_name,
1714 hostname, maxnamlen,
1715 export_path, maxpathlen);
1717 return nfs_parse_simple_hostname(dev_name,
1718 hostname, maxnamlen,
1719 export_path, maxpathlen);
1723 * Validate the NFS2/NFS3 mount data
1724 * - fills in the mount root filehandle
1726 * For option strings, user space handles the following behaviors:
1728 * + DNS: mapping server host name to IP address ("addr=" option)
1730 * + failure mode: how to behave if a mount request can't be handled
1731 * immediately ("fg/bg" option)
1733 * + retry: how often to retry a mount request ("retry=" option)
1735 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1736 * mountproto=tcp after mountproto=udp, and so on
1738 static int nfs_validate_mount_data(void *options,
1739 struct nfs_parsed_mount_data *args,
1740 struct nfs_fh *mntfh,
1741 const char *dev_name)
1743 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
1744 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
1749 switch (data->version) {
1755 if (data->flags & NFS_MOUNT_VER3)
1757 data->root.size = NFS2_FHSIZE;
1758 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1760 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1763 memset(data->context, 0, sizeof(data->context));
1765 if (data->flags & NFS_MOUNT_VER3) {
1766 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1767 goto out_invalid_fh;
1768 mntfh->size = data->root.size;
1771 mntfh->size = NFS2_FHSIZE;
1776 memcpy(mntfh->data, data->root.data, mntfh->size);
1777 if (mntfh->size < sizeof(mntfh->data))
1778 memset(mntfh->data + mntfh->size, 0,
1779 sizeof(mntfh->data) - mntfh->size);
1782 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1785 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
1786 args->flags |= NFS_MOUNT_LEGACY_INTERFACE;
1787 args->rsize = data->rsize;
1788 args->wsize = data->wsize;
1789 args->timeo = data->timeo;
1790 args->retrans = data->retrans;
1791 args->acregmin = data->acregmin;
1792 args->acregmax = data->acregmax;
1793 args->acdirmin = data->acdirmin;
1794 args->acdirmax = data->acdirmax;
1796 memcpy(sap, &data->addr, sizeof(data->addr));
1797 args->nfs_server.addrlen = sizeof(data->addr);
1798 if (!nfs_verify_server_address(sap))
1799 goto out_no_address;
1801 if (!(data->flags & NFS_MOUNT_TCP))
1802 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1803 /* N.B. caller will free nfs_server.hostname in all cases */
1804 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1805 args->namlen = data->namlen;
1806 args->bsize = data->bsize;
1808 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1809 args->auth_flavors[0] = data->pseudoflavor;
1810 if (!args->nfs_server.hostname)
1814 * The legacy version 6 binary mount data from userspace has a
1815 * field used only to transport selinux information into the
1816 * the kernel. To continue to support that functionality we
1817 * have a touch of selinux knowledge here in the NFS code. The
1818 * userspace code converted context=blah to just blah so we are
1819 * converting back to the full string selinux understands.
1821 if (data->context[0]){
1822 #ifdef CONFIG_SECURITY_SELINUX
1824 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1827 strcpy(opts_str, "context=");
1828 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1829 strcat(opts_str, &data->context[0]);
1830 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1843 if (nfs_parse_mount_options((char *)options, args) == 0)
1846 if (!nfs_verify_server_address(sap))
1847 goto out_no_address;
1849 if (args->version == 4)
1850 #ifdef CONFIG_NFS_V4
1851 return nfs4_validate_text_mount_data(options,
1854 goto out_v4_not_compiled;
1857 nfs_set_port(sap, &args->nfs_server.port, 0);
1859 nfs_set_mount_transport_protocol(args);
1861 status = nfs_parse_devname(dev_name,
1862 &args->nfs_server.hostname,
1864 &args->nfs_server.export_path,
1867 status = nfs_try_mount(args, mntfh);
1869 kfree(args->nfs_server.export_path);
1870 args->nfs_server.export_path = NULL;
1879 #ifndef CONFIG_NFS_V3
1880 if (args->version == 3)
1881 goto out_v3_not_compiled;
1882 #endif /* !CONFIG_NFS_V3 */
1887 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1891 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1896 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1899 #ifndef CONFIG_NFS_V3
1900 out_v3_not_compiled:
1901 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1902 return -EPROTONOSUPPORT;
1903 #endif /* !CONFIG_NFS_V3 */
1905 #ifndef CONFIG_NFS_V4
1906 out_v4_not_compiled:
1907 dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n");
1908 return -EPROTONOSUPPORT;
1909 #endif /* !CONFIG_NFS_V4 */
1912 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
1916 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1920 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1925 nfs_compare_remount_data(struct nfs_server *nfss,
1926 struct nfs_parsed_mount_data *data)
1928 if (data->flags != nfss->flags ||
1929 data->rsize != nfss->rsize ||
1930 data->wsize != nfss->wsize ||
1931 data->retrans != nfss->client->cl_timeout->to_retries ||
1932 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
1933 data->acregmin != nfss->acregmin / HZ ||
1934 data->acregmax != nfss->acregmax / HZ ||
1935 data->acdirmin != nfss->acdirmin / HZ ||
1936 data->acdirmax != nfss->acdirmax / HZ ||
1937 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
1938 data->nfs_server.port != nfss->port ||
1939 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
1940 !rpc_cmp_addr((struct sockaddr *)&data->nfs_server.address,
1941 (struct sockaddr *)&nfss->nfs_client->cl_addr))
1948 nfs_remount(struct super_block *sb, int *flags, char *raw_data)
1951 struct nfs_server *nfss = sb->s_fs_info;
1952 struct nfs_parsed_mount_data *data;
1953 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
1954 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
1955 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
1958 * Userspace mount programs that send binary options generally send
1959 * them populated with default values. We have no way to know which
1960 * ones were explicitly specified. Fall back to legacy behavior and
1961 * just return success.
1963 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
1964 (nfsvers <= 3 && (!options || (options->version >= 1 &&
1965 options->version <= 6))))
1968 data = kzalloc(sizeof(*data), GFP_KERNEL);
1972 /* fill out struct with values from existing mount */
1973 data->flags = nfss->flags;
1974 data->rsize = nfss->rsize;
1975 data->wsize = nfss->wsize;
1976 data->retrans = nfss->client->cl_timeout->to_retries;
1977 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
1978 data->acregmin = nfss->acregmin / HZ;
1979 data->acregmax = nfss->acregmax / HZ;
1980 data->acdirmin = nfss->acdirmin / HZ;
1981 data->acdirmax = nfss->acdirmax / HZ;
1982 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
1983 data->nfs_server.port = nfss->port;
1984 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
1985 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1986 data->nfs_server.addrlen);
1988 /* overwrite those values with any that were specified */
1989 error = nfs_parse_mount_options((char *)options, data);
1993 /* compare new mount options with old ones */
1994 error = nfs_compare_remount_data(nfss, data);
2001 * Initialise the common bits of the superblock
2003 static inline void nfs_initialise_sb(struct super_block *sb)
2005 struct nfs_server *server = NFS_SB(sb);
2007 sb->s_magic = NFS_SUPER_MAGIC;
2009 /* We probably want something more informative here */
2010 snprintf(sb->s_id, sizeof(sb->s_id),
2011 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
2013 if (sb->s_blocksize == 0)
2014 sb->s_blocksize = nfs_block_bits(server->wsize,
2015 &sb->s_blocksize_bits);
2017 if (server->flags & NFS_MOUNT_NOAC)
2018 sb->s_flags |= MS_SYNCHRONOUS;
2020 sb->s_bdi = &server->backing_dev_info;
2022 nfs_super_set_maxbytes(sb, server->maxfilesize);
2026 * Finish setting up an NFS2/3 superblock
2028 static void nfs_fill_super(struct super_block *sb,
2029 struct nfs_parsed_mount_data *data)
2031 struct nfs_server *server = NFS_SB(sb);
2033 sb->s_blocksize_bits = 0;
2034 sb->s_blocksize = 0;
2036 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
2038 if (server->nfs_client->rpc_ops->version == 3) {
2039 /* The VFS shouldn't apply the umask to mode bits. We will do
2040 * so ourselves when necessary.
2042 sb->s_flags |= MS_POSIXACL;
2043 sb->s_time_gran = 1;
2046 sb->s_op = &nfs_sops;
2047 nfs_initialise_sb(sb);
2051 * Finish setting up a cloned NFS2/3 superblock
2053 static void nfs_clone_super(struct super_block *sb,
2054 const struct super_block *old_sb)
2056 struct nfs_server *server = NFS_SB(sb);
2058 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2059 sb->s_blocksize = old_sb->s_blocksize;
2060 sb->s_maxbytes = old_sb->s_maxbytes;
2062 if (server->nfs_client->rpc_ops->version == 3) {
2063 /* The VFS shouldn't apply the umask to mode bits. We will do
2064 * so ourselves when necessary.
2066 sb->s_flags |= MS_POSIXACL;
2067 sb->s_time_gran = 1;
2070 sb->s_op = old_sb->s_op;
2071 nfs_initialise_sb(sb);
2074 static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
2076 const struct nfs_server *a = s->s_fs_info;
2077 const struct rpc_clnt *clnt_a = a->client;
2078 const struct rpc_clnt *clnt_b = b->client;
2080 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
2082 if (a->nfs_client != b->nfs_client)
2084 if (a->flags != b->flags)
2086 if (a->wsize != b->wsize)
2088 if (a->rsize != b->rsize)
2090 if (a->acregmin != b->acregmin)
2092 if (a->acregmax != b->acregmax)
2094 if (a->acdirmin != b->acdirmin)
2096 if (a->acdirmax != b->acdirmax)
2098 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
2105 struct nfs_sb_mountdata {
2106 struct nfs_server *server;
2110 static int nfs_set_super(struct super_block *s, void *data)
2112 struct nfs_sb_mountdata *sb_mntdata = data;
2113 struct nfs_server *server = sb_mntdata->server;
2116 s->s_flags = sb_mntdata->mntflags;
2117 s->s_fs_info = server;
2118 ret = set_anon_super(s, server);
2120 server->s_dev = s->s_dev;
2124 static int nfs_compare_super_address(struct nfs_server *server1,
2125 struct nfs_server *server2)
2127 struct sockaddr *sap1, *sap2;
2129 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
2130 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
2132 if (sap1->sa_family != sap2->sa_family)
2135 switch (sap1->sa_family) {
2137 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
2138 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
2139 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
2141 if (sin1->sin_port != sin2->sin_port)
2146 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
2147 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
2148 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
2150 if (sin1->sin6_port != sin2->sin6_port)
2161 static int nfs_compare_super(struct super_block *sb, void *data)
2163 struct nfs_sb_mountdata *sb_mntdata = data;
2164 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2165 int mntflags = sb_mntdata->mntflags;
2167 if (!nfs_compare_super_address(old, server))
2169 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2170 if (old->flags & NFS_MOUNT_UNSHARED)
2172 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2174 return nfs_compare_mount_options(sb, server, mntflags);
2177 static int nfs_bdi_register(struct nfs_server *server)
2179 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
2182 static int nfs_get_sb(struct file_system_type *fs_type,
2183 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2185 struct nfs_server *server = NULL;
2186 struct super_block *s;
2187 struct nfs_parsed_mount_data *data;
2188 struct nfs_fh *mntfh;
2189 struct dentry *mntroot;
2190 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2191 struct nfs_sb_mountdata sb_mntdata = {
2194 int error = -ENOMEM;
2196 data = nfs_alloc_parsed_mount_data(3);
2197 mntfh = nfs_alloc_fhandle();
2198 if (data == NULL || mntfh == NULL)
2201 security_init_mnt_opts(&data->lsm_opts);
2203 /* Validate the mount data */
2204 error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
2208 #ifdef CONFIG_NFS_V4
2209 if (data->version == 4) {
2210 error = nfs4_try_mount(flags, dev_name, data, mnt);
2211 kfree(data->client_address);
2212 kfree(data->nfs_server.export_path);
2215 #endif /* CONFIG_NFS_V4 */
2217 /* Get a volume representation */
2218 server = nfs_create_server(data, mntfh);
2219 if (IS_ERR(server)) {
2220 error = PTR_ERR(server);
2223 sb_mntdata.server = server;
2225 if (server->flags & NFS_MOUNT_UNSHARED)
2226 compare_super = NULL;
2228 /* Get a superblock - note that we may end up sharing one that already exists */
2229 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
2235 if (s->s_fs_info != server) {
2236 nfs_free_server(server);
2239 error = nfs_bdi_register(server);
2241 goto error_splat_bdi;
2245 /* initial superblock/root creation */
2246 nfs_fill_super(s, data);
2247 nfs_fscache_get_super_cookie(
2248 s, data ? data->fscache_uniq : NULL, NULL);
2251 mntroot = nfs_get_root(s, mntfh);
2252 if (IS_ERR(mntroot)) {
2253 error = PTR_ERR(mntroot);
2254 goto error_splat_super;
2257 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
2259 goto error_splat_root;
2261 s->s_flags |= MS_ACTIVE;
2263 mnt->mnt_root = mntroot;
2267 kfree(data->nfs_server.hostname);
2268 kfree(data->mount_server.hostname);
2269 kfree(data->fscache_uniq);
2270 security_free_mnt_opts(&data->lsm_opts);
2272 nfs_free_fhandle(mntfh);
2277 nfs_free_server(server);
2283 if (server && !s->s_root)
2284 bdi_unregister(&server->backing_dev_info);
2286 deactivate_locked_super(s);
2291 * Ensure that we unregister the bdi before kill_anon_super
2292 * releases the device name
2294 static void nfs_put_super(struct super_block *s)
2296 struct nfs_server *server = NFS_SB(s);
2298 bdi_unregister(&server->backing_dev_info);
2302 * Destroy an NFS2/3 superblock
2304 static void nfs_kill_super(struct super_block *s)
2306 struct nfs_server *server = NFS_SB(s);
2309 nfs_fscache_release_super_cookie(s);
2310 nfs_free_server(server);
2314 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2316 static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
2317 const char *dev_name, void *raw_data,
2318 struct vfsmount *mnt)
2320 struct nfs_clone_mount *data = raw_data;
2321 struct super_block *s;
2322 struct nfs_server *server;
2323 struct dentry *mntroot;
2324 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2325 struct nfs_sb_mountdata sb_mntdata = {
2330 dprintk("--> nfs_xdev_get_sb()\n");
2332 /* create a new volume representation */
2333 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2334 if (IS_ERR(server)) {
2335 error = PTR_ERR(server);
2336 goto out_err_noserver;
2338 sb_mntdata.server = server;
2340 if (server->flags & NFS_MOUNT_UNSHARED)
2341 compare_super = NULL;
2343 /* Get a superblock - note that we may end up sharing one that already exists */
2344 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2350 if (s->s_fs_info != server) {
2351 nfs_free_server(server);
2354 error = nfs_bdi_register(server);
2356 goto error_splat_bdi;
2360 /* initial superblock/root creation */
2361 nfs_clone_super(s, data->sb);
2362 nfs_fscache_get_super_cookie(s, NULL, data);
2365 mntroot = nfs_get_root(s, data->fh);
2366 if (IS_ERR(mntroot)) {
2367 error = PTR_ERR(mntroot);
2368 goto error_splat_super;
2370 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2373 goto error_splat_super;
2376 s->s_flags |= MS_ACTIVE;
2378 mnt->mnt_root = mntroot;
2380 /* clone any lsm security options from the parent to the new sb */
2381 security_sb_clone_mnt_opts(data->sb, s);
2383 dprintk("<-- nfs_xdev_get_sb() = 0\n");
2387 nfs_free_server(server);
2389 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
2393 if (server && !s->s_root)
2394 bdi_unregister(&server->backing_dev_info);
2396 deactivate_locked_super(s);
2397 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
2401 #ifdef CONFIG_NFS_V4
2404 * Finish setting up a cloned NFS4 superblock
2406 static void nfs4_clone_super(struct super_block *sb,
2407 const struct super_block *old_sb)
2409 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2410 sb->s_blocksize = old_sb->s_blocksize;
2411 sb->s_maxbytes = old_sb->s_maxbytes;
2412 sb->s_time_gran = 1;
2413 sb->s_op = old_sb->s_op;
2414 nfs_initialise_sb(sb);
2418 * Set up an NFS4 superblock
2420 static void nfs4_fill_super(struct super_block *sb)
2422 sb->s_time_gran = 1;
2423 sb->s_op = &nfs4_sops;
2424 nfs_initialise_sb(sb);
2427 static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2429 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3);
2432 static int nfs4_validate_text_mount_data(void *options,
2433 struct nfs_parsed_mount_data *args,
2434 const char *dev_name)
2436 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2438 nfs_set_port(sap, &args->nfs_server.port, NFS_PORT);
2440 nfs_validate_transport_protocol(args);
2442 nfs4_validate_mount_flags(args);
2444 if (args->version != 4) {
2446 "NFS4: Illegal mount version\n");
2450 if (args->auth_flavor_len > 1) {
2452 "NFS4: Too many RPC auth flavours specified\n");
2456 if (args->client_address == NULL) {
2458 "NFS4: mount program didn't pass callback address\n");
2462 return nfs_parse_devname(dev_name,
2463 &args->nfs_server.hostname,
2465 &args->nfs_server.export_path,
2470 * Validate NFSv4 mount options
2472 static int nfs4_validate_mount_data(void *options,
2473 struct nfs_parsed_mount_data *args,
2474 const char *dev_name)
2476 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2477 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
2483 switch (data->version) {
2485 if (data->host_addrlen > sizeof(args->nfs_server.address))
2486 goto out_no_address;
2487 if (data->host_addrlen == 0)
2488 goto out_no_address;
2489 args->nfs_server.addrlen = data->host_addrlen;
2490 if (copy_from_user(sap, data->host_addr, data->host_addrlen))
2492 if (!nfs_verify_server_address(sap))
2493 goto out_no_address;
2495 if (data->auth_flavourlen) {
2496 if (data->auth_flavourlen > 1)
2497 goto out_inval_auth;
2498 if (copy_from_user(&args->auth_flavors[0],
2499 data->auth_flavours,
2500 sizeof(args->auth_flavors[0])))
2504 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2507 args->nfs_server.hostname = c;
2509 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2512 args->nfs_server.export_path = c;
2513 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
2515 c = strndup_user(data->client_addr.data, 16);
2518 args->client_address = c;
2521 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2525 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2526 args->rsize = data->rsize;
2527 args->wsize = data->wsize;
2528 args->timeo = data->timeo;
2529 args->retrans = data->retrans;
2530 args->acregmin = data->acregmin;
2531 args->acregmax = data->acregmax;
2532 args->acdirmin = data->acdirmin;
2533 args->acdirmax = data->acdirmax;
2534 args->nfs_server.protocol = data->proto;
2535 nfs_validate_transport_protocol(args);
2539 if (nfs_parse_mount_options((char *)options, args) == 0)
2542 if (!nfs_verify_server_address(sap))
2545 return nfs4_validate_text_mount_data(options, args, dev_name);
2551 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2555 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2556 data->auth_flavourlen);
2560 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2565 * Get the superblock for the NFS4 root partition
2567 static int nfs4_remote_get_sb(struct file_system_type *fs_type,
2568 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2570 struct nfs_parsed_mount_data *data = raw_data;
2571 struct super_block *s;
2572 struct nfs_server *server;
2573 struct nfs_fh *mntfh;
2574 struct dentry *mntroot;
2575 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2576 struct nfs_sb_mountdata sb_mntdata = {
2579 int error = -ENOMEM;
2581 mntfh = nfs_alloc_fhandle();
2582 if (data == NULL || mntfh == NULL)
2585 security_init_mnt_opts(&data->lsm_opts);
2587 /* Get a volume representation */
2588 server = nfs4_create_server(data, mntfh);
2589 if (IS_ERR(server)) {
2590 error = PTR_ERR(server);
2593 sb_mntdata.server = server;
2595 if (server->flags & NFS4_MOUNT_UNSHARED)
2596 compare_super = NULL;
2598 /* Get a superblock - note that we may end up sharing one that already exists */
2599 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2605 if (s->s_fs_info != server) {
2606 nfs_free_server(server);
2609 error = nfs_bdi_register(server);
2611 goto error_splat_bdi;
2615 /* initial superblock/root creation */
2617 nfs_fscache_get_super_cookie(
2618 s, data ? data->fscache_uniq : NULL, NULL);
2621 mntroot = nfs4_get_root(s, mntfh);
2622 if (IS_ERR(mntroot)) {
2623 error = PTR_ERR(mntroot);
2624 goto error_splat_super;
2627 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
2629 goto error_splat_root;
2631 s->s_flags |= MS_ACTIVE;
2633 mnt->mnt_root = mntroot;
2637 security_free_mnt_opts(&data->lsm_opts);
2639 nfs_free_fhandle(mntfh);
2643 nfs_free_server(server);
2649 if (server && !s->s_root)
2650 bdi_unregister(&server->backing_dev_info);
2652 deactivate_locked_super(s);
2656 static struct vfsmount *nfs_do_root_mount(struct file_system_type *fs_type,
2657 int flags, void *data, const char *hostname)
2659 struct vfsmount *root_mnt;
2663 len = strlen(hostname) + 3;
2664 root_devname = kmalloc(len, GFP_KERNEL);
2665 if (root_devname == NULL)
2666 return ERR_PTR(-ENOMEM);
2667 snprintf(root_devname, len, "%s:/", hostname);
2668 root_mnt = vfs_kern_mount(fs_type, flags, root_devname, data);
2669 kfree(root_devname);
2673 static void nfs_fix_devname(const struct path *path, struct vfsmount *mnt)
2675 char *page = (char *) __get_free_page(GFP_KERNEL);
2676 char *devname, *tmp;
2680 devname = nfs_path(path->mnt->mnt_devname,
2681 path->mnt->mnt_root, path->dentry,
2683 if (IS_ERR(devname))
2685 tmp = kstrdup(devname, GFP_KERNEL);
2688 kfree(mnt->mnt_devname);
2689 mnt->mnt_devname = tmp;
2691 free_page((unsigned long)page);
2694 struct nfs_referral_count {
2695 struct list_head list;
2696 const struct task_struct *task;
2697 unsigned int referral_count;
2700 static LIST_HEAD(nfs_referral_count_list);
2701 static DEFINE_SPINLOCK(nfs_referral_count_list_lock);
2703 static struct nfs_referral_count *nfs_find_referral_count(void)
2705 struct nfs_referral_count *p;
2707 list_for_each_entry(p, &nfs_referral_count_list, list) {
2708 if (p->task == current)
2714 #define NFS_MAX_NESTED_REFERRALS 2
2716 static int nfs_referral_loop_protect(void)
2718 struct nfs_referral_count *p, *new;
2721 new = kmalloc(sizeof(*new), GFP_KERNEL);
2724 new->task = current;
2725 new->referral_count = 1;
2728 spin_lock(&nfs_referral_count_list_lock);
2729 p = nfs_find_referral_count();
2731 if (p->referral_count >= NFS_MAX_NESTED_REFERRALS)
2734 p->referral_count++;
2736 list_add(&new->list, &nfs_referral_count_list);
2739 spin_unlock(&nfs_referral_count_list_lock);
2745 static void nfs_referral_loop_unprotect(void)
2747 struct nfs_referral_count *p;
2749 spin_lock(&nfs_referral_count_list_lock);
2750 p = nfs_find_referral_count();
2751 p->referral_count--;
2752 if (p->referral_count == 0)
2756 spin_unlock(&nfs_referral_count_list_lock);
2760 static int nfs_follow_remote_path(struct vfsmount *root_mnt,
2761 const char *export_path, struct vfsmount *mnt_target)
2763 struct nameidata *nd = NULL;
2764 struct mnt_namespace *ns_private;
2765 struct super_block *s;
2768 nd = kmalloc(sizeof(*nd), GFP_KERNEL);
2772 ns_private = create_mnt_ns(root_mnt);
2773 ret = PTR_ERR(ns_private);
2774 if (IS_ERR(ns_private))
2777 ret = nfs_referral_loop_protect();
2779 goto out_put_mnt_ns;
2781 ret = vfs_path_lookup(root_mnt->mnt_root, root_mnt,
2782 export_path, LOOKUP_FOLLOW, nd);
2784 nfs_referral_loop_unprotect();
2785 put_mnt_ns(ns_private);
2790 s = nd->path.mnt->mnt_sb;
2791 atomic_inc(&s->s_active);
2792 mnt_target->mnt_sb = s;
2793 mnt_target->mnt_root = dget(nd->path.dentry);
2795 /* Correct the device pathname */
2796 nfs_fix_devname(&nd->path, mnt_target);
2798 path_put(&nd->path);
2800 down_write(&s->s_umount);
2803 put_mnt_ns(ns_private);
2811 static int nfs4_try_mount(int flags, const char *dev_name,
2812 struct nfs_parsed_mount_data *data,
2813 struct vfsmount *mnt)
2816 struct vfsmount *root_mnt;
2819 dfprintk(MOUNT, "--> nfs4_try_mount()\n");
2821 export_path = data->nfs_server.export_path;
2822 data->nfs_server.export_path = "/";
2823 root_mnt = nfs_do_root_mount(&nfs4_remote_fs_type, flags, data,
2824 data->nfs_server.hostname);
2825 data->nfs_server.export_path = export_path;
2827 error = PTR_ERR(root_mnt);
2828 if (IS_ERR(root_mnt))
2831 error = nfs_follow_remote_path(root_mnt, export_path, mnt);
2834 dfprintk(MOUNT, "<-- nfs4_try_mount() = %d%s\n", error,
2835 error != 0 ? " [error]" : "");
2840 * Get the superblock for an NFS4 mountpoint
2842 static int nfs4_get_sb(struct file_system_type *fs_type,
2843 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2845 struct nfs_parsed_mount_data *data;
2846 int error = -ENOMEM;
2848 data = nfs_alloc_parsed_mount_data(4);
2852 /* Validate the mount data */
2853 error = nfs4_validate_mount_data(raw_data, data, dev_name);
2857 error = nfs4_try_mount(flags, dev_name, data, mnt);
2860 kfree(data->client_address);
2861 kfree(data->nfs_server.export_path);
2862 kfree(data->nfs_server.hostname);
2863 kfree(data->fscache_uniq);
2866 dprintk("<-- nfs4_get_sb() = %d%s\n", error,
2867 error != 0 ? " [error]" : "");
2871 static void nfs4_kill_super(struct super_block *sb)
2873 struct nfs_server *server = NFS_SB(sb);
2875 dprintk("--> %s\n", __func__);
2876 nfs_super_return_all_delegations(sb);
2877 kill_anon_super(sb);
2878 nfs_fscache_release_super_cookie(sb);
2879 nfs_free_server(server);
2880 dprintk("<-- %s\n", __func__);
2884 * Clone an NFS4 server record on xdev traversal (FSID-change)
2886 static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
2887 const char *dev_name, void *raw_data,
2888 struct vfsmount *mnt)
2890 struct nfs_clone_mount *data = raw_data;
2891 struct super_block *s;
2892 struct nfs_server *server;
2893 struct dentry *mntroot;
2894 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2895 struct nfs_sb_mountdata sb_mntdata = {
2900 dprintk("--> nfs4_xdev_get_sb()\n");
2902 /* create a new volume representation */
2903 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2904 if (IS_ERR(server)) {
2905 error = PTR_ERR(server);
2906 goto out_err_noserver;
2908 sb_mntdata.server = server;
2910 if (server->flags & NFS4_MOUNT_UNSHARED)
2911 compare_super = NULL;
2913 /* Get a superblock - note that we may end up sharing one that already exists */
2914 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2920 if (s->s_fs_info != server) {
2921 nfs_free_server(server);
2924 error = nfs_bdi_register(server);
2926 goto error_splat_bdi;
2930 /* initial superblock/root creation */
2931 nfs4_clone_super(s, data->sb);
2932 nfs_fscache_get_super_cookie(s, NULL, data);
2935 mntroot = nfs4_get_root(s, data->fh);
2936 if (IS_ERR(mntroot)) {
2937 error = PTR_ERR(mntroot);
2938 goto error_splat_super;
2940 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2943 goto error_splat_super;
2946 s->s_flags |= MS_ACTIVE;
2948 mnt->mnt_root = mntroot;
2950 security_sb_clone_mnt_opts(data->sb, s);
2952 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2956 nfs_free_server(server);
2958 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
2962 if (server && !s->s_root)
2963 bdi_unregister(&server->backing_dev_info);
2965 deactivate_locked_super(s);
2966 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
2970 static int nfs4_remote_referral_get_sb(struct file_system_type *fs_type,
2971 int flags, const char *dev_name, void *raw_data,
2972 struct vfsmount *mnt)
2974 struct nfs_clone_mount *data = raw_data;
2975 struct super_block *s;
2976 struct nfs_server *server;
2977 struct dentry *mntroot;
2978 struct nfs_fh *mntfh;
2979 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2980 struct nfs_sb_mountdata sb_mntdata = {
2983 int error = -ENOMEM;
2985 dprintk("--> nfs4_referral_get_sb()\n");
2987 mntfh = nfs_alloc_fhandle();
2991 /* create a new volume representation */
2992 server = nfs4_create_referral_server(data, mntfh);
2993 if (IS_ERR(server)) {
2994 error = PTR_ERR(server);
2995 goto out_err_noserver;
2997 sb_mntdata.server = server;
2999 if (server->flags & NFS4_MOUNT_UNSHARED)
3000 compare_super = NULL;
3002 /* Get a superblock - note that we may end up sharing one that already exists */
3003 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
3009 if (s->s_fs_info != server) {
3010 nfs_free_server(server);
3013 error = nfs_bdi_register(server);
3015 goto error_splat_bdi;
3019 /* initial superblock/root creation */
3021 nfs_fscache_get_super_cookie(s, NULL, data);
3024 mntroot = nfs4_get_root(s, mntfh);
3025 if (IS_ERR(mntroot)) {
3026 error = PTR_ERR(mntroot);
3027 goto error_splat_super;
3029 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
3032 goto error_splat_super;
3035 s->s_flags |= MS_ACTIVE;
3037 mnt->mnt_root = mntroot;
3039 security_sb_clone_mnt_opts(data->sb, s);
3041 nfs_free_fhandle(mntfh);
3042 dprintk("<-- nfs4_referral_get_sb() = 0\n");
3046 nfs_free_server(server);
3048 nfs_free_fhandle(mntfh);
3050 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
3054 if (server && !s->s_root)
3055 bdi_unregister(&server->backing_dev_info);
3057 deactivate_locked_super(s);
3058 nfs_free_fhandle(mntfh);
3059 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
3064 * Create an NFS4 server record on referral traversal
3066 static int nfs4_referral_get_sb(struct file_system_type *fs_type,
3067 int flags, const char *dev_name, void *raw_data,
3068 struct vfsmount *mnt)
3070 struct nfs_clone_mount *data = raw_data;
3072 struct vfsmount *root_mnt;
3075 dprintk("--> nfs4_referral_get_sb()\n");
3077 export_path = data->mnt_path;
3078 data->mnt_path = "/";
3080 root_mnt = nfs_do_root_mount(&nfs4_remote_referral_fs_type,
3081 flags, data, data->hostname);
3082 data->mnt_path = export_path;
3084 error = PTR_ERR(root_mnt);
3085 if (IS_ERR(root_mnt))
3088 error = nfs_follow_remote_path(root_mnt, export_path, mnt);
3090 dprintk("<-- nfs4_referral_get_sb() = %d%s\n", error,
3091 error != 0 ? " [error]" : "");
3095 #endif /* CONFIG_NFS_V4 */