4 * Copyright (C) 1992 Rick Sladkey
6 * nfs superblock handling functions
8 * Modularised by Alan Cox <alan@lxorguk.ukuu.org.uk>, while hacking some
9 * experimental NFS changes. Modularisation taken straight from SYS5 fs.
11 * Change to nfs_read_super() to permit NFS mounts to multi-homed hosts.
12 * J.S.Peatfield@damtp.cam.ac.uk
14 * Split from inode.c by David Howells <dhowells@redhat.com>
16 * - superblocks are indexed on server only - all inodes, dentries, etc. associated with a
17 * particular server are held in the same superblock
18 * - NFS superblocks can have several effective roots to the dentry tree
19 * - directory type roots are spliced into the tree when a path from one root reaches the root
20 * of another (see nfs_lookup())
23 #include <linux/module.h>
24 #include <linux/init.h>
26 #include <linux/time.h>
27 #include <linux/kernel.h>
29 #include <linux/string.h>
30 #include <linux/stat.h>
31 #include <linux/errno.h>
32 #include <linux/unistd.h>
33 #include <linux/sunrpc/clnt.h>
34 #include <linux/sunrpc/stats.h>
35 #include <linux/sunrpc/metrics.h>
36 #include <linux/sunrpc/xprtsock.h>
37 #include <linux/sunrpc/xprtrdma.h>
38 #include <linux/nfs_fs.h>
39 #include <linux/nfs_mount.h>
40 #include <linux/nfs4_mount.h>
41 #include <linux/lockd/bind.h>
42 #include <linux/seq_file.h>
43 #include <linux/mount.h>
44 #include <linux/namei.h>
45 #include <linux/nfs_idmap.h>
46 #include <linux/vfs.h>
47 #include <linux/inet.h>
48 #include <linux/in6.h>
49 #include <linux/slab.h>
51 #include <linux/netdevice.h>
52 #include <linux/nfs_xdr.h>
53 #include <linux/magic.h>
54 #include <linux/parser.h>
55 #include <linux/nsproxy.h>
56 #include <linux/rcupdate.h>
58 #include <asm/uaccess.h>
62 #include "delegation.h"
69 #define NFSDBG_FACILITY NFSDBG_VFS
70 #define NFS_TEXT_DATA 1
73 #define NFS_DEFAULT_VERSION 3
75 #define NFS_DEFAULT_VERSION 2
79 /* Mount options that take no arguments */
81 Opt_posix, Opt_noposix,
85 Opt_udp, Opt_tcp, Opt_rdma,
87 Opt_rdirplus, Opt_nordirplus,
88 Opt_sharecache, Opt_nosharecache,
89 Opt_resvport, Opt_noresvport,
90 Opt_fscache, Opt_nofscache,
92 /* Mount options that take integer arguments */
94 Opt_rsize, Opt_wsize, Opt_bsize,
95 Opt_timeo, Opt_retrans,
96 Opt_acregmin, Opt_acregmax,
97 Opt_acdirmin, Opt_acdirmax,
104 /* Mount options that take string arguments */
106 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
107 Opt_addr, Opt_mountaddr, Opt_clientaddr,
112 /* Special mount options */
113 Opt_userspace, Opt_deprecated, Opt_sloppy,
118 static const match_table_t nfs_mount_option_tokens = {
119 { Opt_userspace, "bg" },
120 { Opt_userspace, "fg" },
121 { Opt_userspace, "retry=%s" },
123 { Opt_sloppy, "sloppy" },
125 { Opt_soft, "soft" },
126 { Opt_hard, "hard" },
127 { Opt_deprecated, "intr" },
128 { Opt_deprecated, "nointr" },
129 { Opt_posix, "posix" },
130 { Opt_noposix, "noposix" },
132 { Opt_nocto, "nocto" },
134 { Opt_noac, "noac" },
135 { Opt_lock, "lock" },
136 { 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_minorversion, "minorversion=%s" },
167 { Opt_nfsvers, "nfsvers=%s" },
168 { Opt_nfsvers, "vers=%s" },
170 { Opt_sec, "sec=%s" },
171 { Opt_proto, "proto=%s" },
172 { Opt_mountproto, "mountproto=%s" },
173 { Opt_addr, "addr=%s" },
174 { Opt_clientaddr, "clientaddr=%s" },
175 { Opt_mounthost, "mounthost=%s" },
176 { Opt_mountaddr, "mountaddr=%s" },
178 { Opt_lookupcache, "lookupcache=%s" },
179 { Opt_fscache_uniq, "fsc=%s" },
180 { Opt_local_lock, "local_lock=%s" },
182 /* The following needs to be listed after all other options */
183 { Opt_nfsvers, "v%s" },
189 Opt_xprt_udp, Opt_xprt_udp6, Opt_xprt_tcp, Opt_xprt_tcp6, Opt_xprt_rdma,
194 static const match_table_t nfs_xprt_protocol_tokens = {
195 { Opt_xprt_udp, "udp" },
196 { Opt_xprt_udp6, "udp6" },
197 { Opt_xprt_tcp, "tcp" },
198 { Opt_xprt_tcp6, "tcp6" },
199 { Opt_xprt_rdma, "rdma" },
201 { Opt_xprt_err, NULL }
205 Opt_sec_none, Opt_sec_sys,
206 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
207 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
208 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
213 static const match_table_t nfs_secflavor_tokens = {
214 { Opt_sec_none, "none" },
215 { Opt_sec_none, "null" },
216 { Opt_sec_sys, "sys" },
218 { Opt_sec_krb5, "krb5" },
219 { Opt_sec_krb5i, "krb5i" },
220 { Opt_sec_krb5p, "krb5p" },
222 { Opt_sec_lkey, "lkey" },
223 { Opt_sec_lkeyi, "lkeyi" },
224 { Opt_sec_lkeyp, "lkeyp" },
226 { Opt_sec_spkm, "spkm3" },
227 { Opt_sec_spkmi, "spkm3i" },
228 { Opt_sec_spkmp, "spkm3p" },
230 { Opt_sec_err, NULL }
234 Opt_lookupcache_all, Opt_lookupcache_positive,
235 Opt_lookupcache_none,
240 static match_table_t nfs_lookupcache_tokens = {
241 { Opt_lookupcache_all, "all" },
242 { Opt_lookupcache_positive, "pos" },
243 { Opt_lookupcache_positive, "positive" },
244 { Opt_lookupcache_none, "none" },
246 { Opt_lookupcache_err, NULL }
250 Opt_local_lock_all, Opt_local_lock_flock, Opt_local_lock_posix,
256 static match_table_t nfs_local_lock_tokens = {
257 { Opt_local_lock_all, "all" },
258 { Opt_local_lock_flock, "flock" },
259 { Opt_local_lock_posix, "posix" },
260 { Opt_local_lock_none, "none" },
262 { Opt_local_lock_err, NULL }
266 Opt_vers_2, Opt_vers_3, Opt_vers_4, Opt_vers_4_0,
272 static match_table_t nfs_vers_tokens = {
276 { Opt_vers_4_0, "4.0" },
277 { Opt_vers_4_1, "4.1" },
279 { Opt_vers_err, NULL }
282 static struct dentry *nfs_xdev_mount(struct file_system_type *fs_type,
283 int flags, const char *dev_name, void *raw_data);
285 struct file_system_type nfs_fs_type = {
286 .owner = THIS_MODULE,
288 .mount = nfs_fs_mount,
289 .kill_sb = nfs_kill_super,
290 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
293 struct file_system_type nfs_xdev_fs_type = {
294 .owner = THIS_MODULE,
296 .mount = nfs_xdev_mount,
297 .kill_sb = nfs_kill_super,
298 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
301 const struct super_operations nfs_sops = {
302 .alloc_inode = nfs_alloc_inode,
303 .destroy_inode = nfs_destroy_inode,
304 .write_inode = nfs_write_inode,
305 .put_super = nfs_put_super,
306 .statfs = nfs_statfs,
307 .evict_inode = nfs_evict_inode,
308 .umount_begin = nfs_umount_begin,
309 .show_options = nfs_show_options,
310 .show_devname = nfs_show_devname,
311 .show_path = nfs_show_path,
312 .show_stats = nfs_show_stats,
313 .remount_fs = nfs_remount,
317 static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *);
318 static int nfs4_validate_mount_data(void *options,
319 struct nfs_parsed_mount_data *args, const char *dev_name);
322 static struct shrinker acl_shrinker = {
323 .shrink = nfs_access_cache_shrinker,
324 .seeks = DEFAULT_SEEKS,
328 * Register the NFS filesystems
330 int __init register_nfs_fs(void)
334 ret = register_filesystem(&nfs_fs_type);
338 ret = nfs_register_sysctl();
341 register_shrinker(&acl_shrinker);
345 unregister_filesystem(&nfs_fs_type);
351 * Unregister the NFS filesystems
353 void __exit unregister_nfs_fs(void)
355 unregister_shrinker(&acl_shrinker);
356 nfs_unregister_sysctl();
357 unregister_filesystem(&nfs_fs_type);
360 void nfs_sb_active(struct super_block *sb)
362 struct nfs_server *server = NFS_SB(sb);
364 if (atomic_inc_return(&server->active) == 1)
365 atomic_inc(&sb->s_active);
368 void nfs_sb_deactive(struct super_block *sb)
370 struct nfs_server *server = NFS_SB(sb);
372 if (atomic_dec_and_test(&server->active))
373 deactivate_super(sb);
377 * Deliver file system statistics to userspace
379 int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
381 struct nfs_server *server = NFS_SB(dentry->d_sb);
382 unsigned char blockbits;
383 unsigned long blockres;
384 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
385 struct nfs_fsstat res;
388 res.fattr = nfs_alloc_fattr();
389 if (res.fattr == NULL)
392 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
393 if (unlikely(error == -ESTALE)) {
394 struct dentry *pd_dentry;
396 pd_dentry = dget_parent(dentry);
397 if (pd_dentry != NULL) {
398 nfs_zap_caches(pd_dentry->d_inode);
402 nfs_free_fattr(res.fattr);
406 buf->f_type = NFS_SUPER_MAGIC;
409 * Current versions of glibc do not correctly handle the
410 * case where f_frsize != f_bsize. Eventually we want to
411 * report the value of wtmult in this field.
413 buf->f_frsize = dentry->d_sb->s_blocksize;
416 * On most *nix systems, f_blocks, f_bfree, and f_bavail
417 * are reported in units of f_frsize. Linux hasn't had
418 * an f_frsize field in its statfs struct until recently,
419 * thus historically Linux's sys_statfs reports these
420 * fields in units of f_bsize.
422 buf->f_bsize = dentry->d_sb->s_blocksize;
423 blockbits = dentry->d_sb->s_blocksize_bits;
424 blockres = (1 << blockbits) - 1;
425 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
426 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
427 buf->f_bavail = (res.abytes + blockres) >> blockbits;
429 buf->f_files = res.tfiles;
430 buf->f_ffree = res.afiles;
432 buf->f_namelen = server->namelen;
437 dprintk("%s: statfs error = %d\n", __func__, -error);
442 * Map the security flavour number to a name
444 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
446 static const struct {
447 rpc_authflavor_t flavour;
450 { RPC_AUTH_NULL, "null" },
451 { RPC_AUTH_UNIX, "sys" },
452 { RPC_AUTH_GSS_KRB5, "krb5" },
453 { RPC_AUTH_GSS_KRB5I, "krb5i" },
454 { RPC_AUTH_GSS_KRB5P, "krb5p" },
455 { RPC_AUTH_GSS_LKEY, "lkey" },
456 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
457 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
458 { RPC_AUTH_GSS_SPKM, "spkm" },
459 { RPC_AUTH_GSS_SPKMI, "spkmi" },
460 { RPC_AUTH_GSS_SPKMP, "spkmp" },
461 { UINT_MAX, "unknown" }
465 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
466 if (sec_flavours[i].flavour == flavour)
469 return sec_flavours[i].str;
472 static void nfs_show_mountd_netid(struct seq_file *m, struct nfs_server *nfss,
475 struct sockaddr *sap = (struct sockaddr *) &nfss->mountd_address;
477 seq_printf(m, ",mountproto=");
478 switch (sap->sa_family) {
480 switch (nfss->mountd_protocol) {
482 seq_printf(m, RPCBIND_NETID_UDP);
485 seq_printf(m, RPCBIND_NETID_TCP);
489 seq_printf(m, "auto");
493 switch (nfss->mountd_protocol) {
495 seq_printf(m, RPCBIND_NETID_UDP6);
498 seq_printf(m, RPCBIND_NETID_TCP6);
502 seq_printf(m, "auto");
507 seq_printf(m, "auto");
511 static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
514 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
516 if (nfss->flags & NFS_MOUNT_LEGACY_INTERFACE)
519 switch (sap->sa_family) {
521 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
522 seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
526 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
527 seq_printf(m, ",mountaddr=%pI6c", &sin6->sin6_addr);
532 seq_printf(m, ",mountaddr=unspecified");
535 if (nfss->mountd_version || showdefaults)
536 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
537 if ((nfss->mountd_port &&
538 nfss->mountd_port != (unsigned short)NFS_UNSPEC_PORT) ||
540 seq_printf(m, ",mountport=%u", nfss->mountd_port);
542 nfs_show_mountd_netid(m, nfss, showdefaults);
546 static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
549 struct nfs_client *clp = nfss->nfs_client;
551 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
554 static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
560 static void nfs_show_nfs_version(struct seq_file *m,
561 unsigned int version,
562 unsigned int minorversion)
564 seq_printf(m, ",vers=%u", version);
566 seq_printf(m, ".%u", minorversion);
570 * Describe the mount options in force on this server representation
572 static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
575 static const struct proc_nfs_info {
580 { NFS_MOUNT_SOFT, ",soft", ",hard" },
581 { NFS_MOUNT_POSIX, ",posix", "" },
582 { NFS_MOUNT_NOCTO, ",nocto", "" },
583 { NFS_MOUNT_NOAC, ",noac", "" },
584 { NFS_MOUNT_NONLM, ",nolock", "" },
585 { NFS_MOUNT_NOACL, ",noacl", "" },
586 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
587 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
588 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
591 const struct proc_nfs_info *nfs_infop;
592 struct nfs_client *clp = nfss->nfs_client;
593 u32 version = clp->rpc_ops->version;
594 int local_flock, local_fcntl;
596 nfs_show_nfs_version(m, version, clp->cl_minorversion);
597 seq_printf(m, ",rsize=%u", nfss->rsize);
598 seq_printf(m, ",wsize=%u", nfss->wsize);
599 if (nfss->bsize != 0)
600 seq_printf(m, ",bsize=%u", nfss->bsize);
601 seq_printf(m, ",namlen=%u", nfss->namelen);
602 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
603 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
604 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
605 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
606 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
607 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
608 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
609 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
610 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
611 if (nfss->flags & nfs_infop->flag)
612 seq_puts(m, nfs_infop->str);
614 seq_puts(m, nfs_infop->nostr);
617 seq_printf(m, ",proto=%s",
618 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
621 if (nfss->port != NFS_PORT)
622 seq_printf(m, ",port=%u", nfss->port);
625 seq_printf(m, ",port=%u", nfss->port);
627 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
628 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
629 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
632 nfs_show_mountd_options(m, nfss, showdefaults);
634 nfs_show_nfsv4_options(m, nfss, showdefaults);
636 if (nfss->options & NFS_OPTION_FSCACHE)
637 seq_printf(m, ",fsc");
639 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONEG) {
640 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONE)
641 seq_printf(m, ",lookupcache=none");
643 seq_printf(m, ",lookupcache=pos");
646 local_flock = nfss->flags & NFS_MOUNT_LOCAL_FLOCK;
647 local_fcntl = nfss->flags & NFS_MOUNT_LOCAL_FCNTL;
649 if (!local_flock && !local_fcntl)
650 seq_printf(m, ",local_lock=none");
651 else if (local_flock && local_fcntl)
652 seq_printf(m, ",local_lock=all");
653 else if (local_flock)
654 seq_printf(m, ",local_lock=flock");
656 seq_printf(m, ",local_lock=posix");
660 * Describe the mount options on this VFS mountpoint
662 int nfs_show_options(struct seq_file *m, struct dentry *root)
664 struct nfs_server *nfss = NFS_SB(root->d_sb);
666 nfs_show_mount_options(m, nfss, 0);
669 seq_printf(m, ",addr=%s",
670 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
678 #ifdef CONFIG_NFS_V4_1
679 static void show_sessions(struct seq_file *m, struct nfs_server *server)
681 if (nfs4_has_session(server->nfs_client))
682 seq_printf(m, ",sessions");
685 static void show_sessions(struct seq_file *m, struct nfs_server *server) {}
689 #ifdef CONFIG_NFS_V4_1
690 static void show_pnfs(struct seq_file *m, struct nfs_server *server)
692 seq_printf(m, ",pnfs=");
693 if (server->pnfs_curr_ld)
694 seq_printf(m, "%s", server->pnfs_curr_ld->name);
696 seq_printf(m, "not configured");
699 static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
701 if (nfss->nfs_client && nfss->nfs_client->cl_implid) {
702 struct nfs41_impl_id *impl_id = nfss->nfs_client->cl_implid;
703 seq_printf(m, "\n\timpl_id:\tname='%s',domain='%s',"
705 impl_id->name, impl_id->domain,
706 impl_id->date.seconds, impl_id->date.nseconds);
711 static void show_pnfs(struct seq_file *m, struct nfs_server *server)
715 static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
720 int nfs_show_devname(struct seq_file *m, struct dentry *root)
722 char *page = (char *) __get_free_page(GFP_KERNEL);
723 char *devname, *dummy;
727 devname = nfs_path(&dummy, root, page, PAGE_SIZE);
729 err = PTR_ERR(devname);
731 seq_escape(m, devname, " \t\n\\");
732 free_page((unsigned long)page);
736 int nfs_show_path(struct seq_file *m, struct dentry *dentry)
743 * Present statistical information for this VFS mountpoint
745 int nfs_show_stats(struct seq_file *m, struct dentry *root)
748 struct nfs_server *nfss = NFS_SB(root->d_sb);
749 struct rpc_auth *auth = nfss->client->cl_auth;
750 struct nfs_iostats totals = { };
752 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
755 * Display all mount option settings
757 seq_printf(m, "\n\topts:\t");
758 seq_puts(m, root->d_sb->s_flags & MS_RDONLY ? "ro" : "rw");
759 seq_puts(m, root->d_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
760 seq_puts(m, root->d_sb->s_flags & MS_NOATIME ? ",noatime" : "");
761 seq_puts(m, root->d_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
762 nfs_show_mount_options(m, nfss, 1);
764 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
766 show_implementation_id(m, nfss);
768 seq_printf(m, "\n\tcaps:\t");
769 seq_printf(m, "caps=0x%x", nfss->caps);
770 seq_printf(m, ",wtmult=%u", nfss->wtmult);
771 seq_printf(m, ",dtsize=%u", nfss->dtsize);
772 seq_printf(m, ",bsize=%u", nfss->bsize);
773 seq_printf(m, ",namlen=%u", nfss->namelen);
776 if (nfss->nfs_client->rpc_ops->version == 4) {
777 seq_printf(m, "\n\tnfsv4:\t");
778 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
779 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
780 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
781 show_sessions(m, nfss);
787 * Display security flavor in effect for this mount
789 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
791 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
794 * Display superblock I/O counters
796 for_each_possible_cpu(cpu) {
797 struct nfs_iostats *stats;
800 stats = per_cpu_ptr(nfss->io_stats, cpu);
802 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
803 totals.events[i] += stats->events[i];
804 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
805 totals.bytes[i] += stats->bytes[i];
806 #ifdef CONFIG_NFS_FSCACHE
807 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
808 totals.fscache[i] += stats->fscache[i];
814 seq_printf(m, "\n\tevents:\t");
815 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
816 seq_printf(m, "%lu ", totals.events[i]);
817 seq_printf(m, "\n\tbytes:\t");
818 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
819 seq_printf(m, "%Lu ", totals.bytes[i]);
820 #ifdef CONFIG_NFS_FSCACHE
821 if (nfss->options & NFS_OPTION_FSCACHE) {
822 seq_printf(m, "\n\tfsc:\t");
823 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
824 seq_printf(m, "%Lu ", totals.bytes[i]);
829 rpc_print_iostats(m, nfss->client);
835 * Begin unmount by attempting to remove all automounted mountpoints we added
836 * in response to xdev traversals and referrals
838 void nfs_umount_begin(struct super_block *sb)
840 struct nfs_server *server;
841 struct rpc_clnt *rpc;
844 /* -EIO all pending I/O */
845 rpc = server->client_acl;
847 rpc_killall_tasks(rpc);
848 rpc = server->client;
850 rpc_killall_tasks(rpc);
853 static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(void)
855 struct nfs_parsed_mount_data *data;
857 data = kzalloc(sizeof(*data), GFP_KERNEL);
859 data->acregmin = NFS_DEF_ACREGMIN;
860 data->acregmax = NFS_DEF_ACREGMAX;
861 data->acdirmin = NFS_DEF_ACDIRMIN;
862 data->acdirmax = NFS_DEF_ACDIRMAX;
863 data->mount_server.port = NFS_UNSPEC_PORT;
864 data->nfs_server.port = NFS_UNSPEC_PORT;
865 data->nfs_server.protocol = XPRT_TRANSPORT_TCP;
866 data->auth_flavors[0] = RPC_AUTH_UNIX;
867 data->auth_flavor_len = 1;
868 data->minorversion = 0;
869 data->need_mount = true;
870 data->net = current->nsproxy->net_ns;
871 security_init_mnt_opts(&data->lsm_opts);
876 static void nfs_free_parsed_mount_data(struct nfs_parsed_mount_data *data)
879 kfree(data->client_address);
880 kfree(data->mount_server.hostname);
881 kfree(data->nfs_server.export_path);
882 kfree(data->nfs_server.hostname);
883 kfree(data->fscache_uniq);
884 security_free_mnt_opts(&data->lsm_opts);
890 * Sanity-check a server address provided by the mount command.
892 * Address family must be initialized, and address must not be
893 * the ANY address for that family.
895 static int nfs_verify_server_address(struct sockaddr *addr)
897 switch (addr->sa_family) {
899 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
900 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
903 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
904 return !ipv6_addr_any(sa);
908 dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
913 * Select between a default port value and a user-specified port value.
914 * If a zero value is set, then autobind will be used.
916 static void nfs_set_port(struct sockaddr *sap, int *port,
917 const unsigned short default_port)
919 if (*port == NFS_UNSPEC_PORT)
920 *port = default_port;
922 rpc_set_port(sap, *port);
926 * Sanity check the NFS transport protocol.
929 static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
931 switch (mnt->nfs_server.protocol) {
932 case XPRT_TRANSPORT_UDP:
933 case XPRT_TRANSPORT_TCP:
934 case XPRT_TRANSPORT_RDMA:
937 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
942 * For text based NFSv2/v3 mounts, the mount protocol transport default
943 * settings should depend upon the specified NFS transport.
945 static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
947 nfs_validate_transport_protocol(mnt);
949 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
950 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
952 switch (mnt->nfs_server.protocol) {
953 case XPRT_TRANSPORT_UDP:
954 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
956 case XPRT_TRANSPORT_TCP:
957 case XPRT_TRANSPORT_RDMA:
958 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
963 * Parse the value of the 'sec=' option.
965 static int nfs_parse_security_flavors(char *value,
966 struct nfs_parsed_mount_data *mnt)
968 substring_t args[MAX_OPT_ARGS];
970 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
972 switch (match_token(value, nfs_secflavor_tokens, args)) {
974 mnt->auth_flavors[0] = RPC_AUTH_NULL;
977 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
980 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
983 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
986 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
989 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
992 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
995 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
998 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
1001 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
1004 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
1010 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
1011 mnt->auth_flavor_len = 1;
1015 static int nfs_parse_version_string(char *string,
1016 struct nfs_parsed_mount_data *mnt,
1019 mnt->flags &= ~NFS_MOUNT_VER3;
1020 switch (match_token(string, nfs_vers_tokens, args)) {
1025 mnt->flags |= NFS_MOUNT_VER3;
1029 /* Backward compatibility option. In future,
1030 * the mount program should always supply
1031 * a NFSv4 minor version number.
1037 mnt->minorversion = 0;
1041 mnt->minorversion = 1;
1049 static int nfs_get_option_str(substring_t args[], char **option)
1052 *option = match_strdup(args);
1056 static int nfs_get_option_ul(substring_t args[], unsigned long *option)
1061 string = match_strdup(args);
1064 rc = strict_strtoul(string, 10, option);
1071 * Error-check and convert a string of mount options from user space into
1072 * a data structure. The whole mount string is processed; bad options are
1073 * skipped as they are encountered. If there were no errors, return 1;
1074 * otherwise return 0 (zero).
1076 static int nfs_parse_mount_options(char *raw,
1077 struct nfs_parsed_mount_data *mnt)
1079 char *p, *string, *secdata;
1080 int rc, sloppy = 0, invalid_option = 0;
1081 unsigned short protofamily = AF_UNSPEC;
1082 unsigned short mountfamily = AF_UNSPEC;
1085 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
1088 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
1090 secdata = alloc_secdata();
1094 rc = security_sb_copy_data(raw, secdata);
1096 goto out_security_failure;
1098 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
1100 goto out_security_failure;
1102 free_secdata(secdata);
1104 while ((p = strsep(&raw, ",")) != NULL) {
1105 substring_t args[MAX_OPT_ARGS];
1106 unsigned long option;
1112 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
1114 token = match_token(p, nfs_mount_option_tokens, args);
1118 * boolean options: foo/nofoo
1121 mnt->flags |= NFS_MOUNT_SOFT;
1124 mnt->flags &= ~NFS_MOUNT_SOFT;
1127 mnt->flags |= NFS_MOUNT_POSIX;
1130 mnt->flags &= ~NFS_MOUNT_POSIX;
1133 mnt->flags &= ~NFS_MOUNT_NOCTO;
1136 mnt->flags |= NFS_MOUNT_NOCTO;
1139 mnt->flags &= ~NFS_MOUNT_NOAC;
1142 mnt->flags |= NFS_MOUNT_NOAC;
1145 mnt->flags &= ~NFS_MOUNT_NONLM;
1146 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1147 NFS_MOUNT_LOCAL_FCNTL);
1150 mnt->flags |= NFS_MOUNT_NONLM;
1151 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1152 NFS_MOUNT_LOCAL_FCNTL);
1155 mnt->flags &= ~NFS_MOUNT_TCP;
1156 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1159 mnt->flags |= NFS_MOUNT_TCP;
1160 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1163 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1164 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1165 xprt_load_transport(p);
1168 mnt->flags &= ~NFS_MOUNT_NOACL;
1171 mnt->flags |= NFS_MOUNT_NOACL;
1174 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1176 case Opt_nordirplus:
1177 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1179 case Opt_sharecache:
1180 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1182 case Opt_nosharecache:
1183 mnt->flags |= NFS_MOUNT_UNSHARED;
1186 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1188 case Opt_noresvport:
1189 mnt->flags |= NFS_MOUNT_NORESVPORT;
1192 mnt->options |= NFS_OPTION_FSCACHE;
1193 kfree(mnt->fscache_uniq);
1194 mnt->fscache_uniq = NULL;
1197 mnt->options &= ~NFS_OPTION_FSCACHE;
1198 kfree(mnt->fscache_uniq);
1199 mnt->fscache_uniq = NULL;
1203 * options that take numeric values
1206 if (nfs_get_option_ul(args, &option) ||
1208 goto out_invalid_value;
1209 mnt->nfs_server.port = option;
1212 if (nfs_get_option_ul(args, &option))
1213 goto out_invalid_value;
1214 mnt->rsize = option;
1217 if (nfs_get_option_ul(args, &option))
1218 goto out_invalid_value;
1219 mnt->wsize = option;
1222 if (nfs_get_option_ul(args, &option))
1223 goto out_invalid_value;
1224 mnt->bsize = option;
1227 if (nfs_get_option_ul(args, &option) || option == 0)
1228 goto out_invalid_value;
1229 mnt->timeo = option;
1232 if (nfs_get_option_ul(args, &option) || option == 0)
1233 goto out_invalid_value;
1234 mnt->retrans = option;
1237 if (nfs_get_option_ul(args, &option))
1238 goto out_invalid_value;
1239 mnt->acregmin = option;
1242 if (nfs_get_option_ul(args, &option))
1243 goto out_invalid_value;
1244 mnt->acregmax = option;
1247 if (nfs_get_option_ul(args, &option))
1248 goto out_invalid_value;
1249 mnt->acdirmin = option;
1252 if (nfs_get_option_ul(args, &option))
1253 goto out_invalid_value;
1254 mnt->acdirmax = option;
1257 if (nfs_get_option_ul(args, &option))
1258 goto out_invalid_value;
1259 mnt->acregmin = mnt->acregmax =
1260 mnt->acdirmin = mnt->acdirmax = option;
1263 if (nfs_get_option_ul(args, &option))
1264 goto out_invalid_value;
1265 mnt->namlen = option;
1268 if (nfs_get_option_ul(args, &option) ||
1270 goto out_invalid_value;
1271 mnt->mount_server.port = option;
1274 if (nfs_get_option_ul(args, &option) ||
1275 option < NFS_MNT_VERSION ||
1276 option > NFS_MNT3_VERSION)
1277 goto out_invalid_value;
1278 mnt->mount_server.version = option;
1280 case Opt_minorversion:
1281 if (nfs_get_option_ul(args, &option))
1282 goto out_invalid_value;
1283 if (option > NFS4_MAX_MINOR_VERSION)
1284 goto out_invalid_value;
1285 mnt->minorversion = option;
1289 * options that take text values
1292 string = match_strdup(args);
1295 rc = nfs_parse_version_string(string, mnt, args);
1298 goto out_invalid_value;
1301 string = match_strdup(args);
1304 rc = nfs_parse_security_flavors(string, mnt);
1307 dfprintk(MOUNT, "NFS: unrecognized "
1308 "security flavor\n");
1313 string = match_strdup(args);
1316 token = match_token(string,
1317 nfs_xprt_protocol_tokens, args);
1319 protofamily = AF_INET;
1322 protofamily = AF_INET6;
1324 mnt->flags &= ~NFS_MOUNT_TCP;
1325 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1328 protofamily = AF_INET6;
1330 mnt->flags |= NFS_MOUNT_TCP;
1331 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1334 /* vector side protocols to TCP */
1335 mnt->flags |= NFS_MOUNT_TCP;
1336 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1337 xprt_load_transport(string);
1340 dfprintk(MOUNT, "NFS: unrecognized "
1341 "transport protocol\n");
1347 case Opt_mountproto:
1348 string = match_strdup(args);
1351 token = match_token(string,
1352 nfs_xprt_protocol_tokens, args);
1355 mountfamily = AF_INET;
1358 mountfamily = AF_INET6;
1360 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
1363 mountfamily = AF_INET6;
1365 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
1367 case Opt_xprt_rdma: /* not used for side protocols */
1369 dfprintk(MOUNT, "NFS: unrecognized "
1370 "transport protocol\n");
1375 string = match_strdup(args);
1378 mnt->nfs_server.addrlen =
1379 rpc_pton(mnt->net, string, strlen(string),
1381 &mnt->nfs_server.address,
1382 sizeof(mnt->nfs_server.address));
1384 if (mnt->nfs_server.addrlen == 0)
1385 goto out_invalid_address;
1387 case Opt_clientaddr:
1388 if (nfs_get_option_str(args, &mnt->client_address))
1392 if (nfs_get_option_str(args,
1393 &mnt->mount_server.hostname))
1397 string = match_strdup(args);
1400 mnt->mount_server.addrlen =
1401 rpc_pton(mnt->net, string, strlen(string),
1403 &mnt->mount_server.address,
1404 sizeof(mnt->mount_server.address));
1406 if (mnt->mount_server.addrlen == 0)
1407 goto out_invalid_address;
1409 case Opt_lookupcache:
1410 string = match_strdup(args);
1413 token = match_token(string,
1414 nfs_lookupcache_tokens, args);
1417 case Opt_lookupcache_all:
1418 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1420 case Opt_lookupcache_positive:
1421 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1422 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1424 case Opt_lookupcache_none:
1425 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1428 dfprintk(MOUNT, "NFS: invalid "
1429 "lookupcache argument\n");
1433 case Opt_fscache_uniq:
1434 if (nfs_get_option_str(args, &mnt->fscache_uniq))
1436 mnt->options |= NFS_OPTION_FSCACHE;
1438 case Opt_local_lock:
1439 string = match_strdup(args);
1442 token = match_token(string, nfs_local_lock_tokens,
1446 case Opt_local_lock_all:
1447 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1448 NFS_MOUNT_LOCAL_FCNTL);
1450 case Opt_local_lock_flock:
1451 mnt->flags |= NFS_MOUNT_LOCAL_FLOCK;
1453 case Opt_local_lock_posix:
1454 mnt->flags |= NFS_MOUNT_LOCAL_FCNTL;
1456 case Opt_local_lock_none:
1457 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1458 NFS_MOUNT_LOCAL_FCNTL);
1461 dfprintk(MOUNT, "NFS: invalid "
1462 "local_lock argument\n");
1472 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1475 case Opt_deprecated:
1476 dfprintk(MOUNT, "NFS: ignoring mount option "
1482 dfprintk(MOUNT, "NFS: unrecognized mount option "
1487 if (!sloppy && invalid_option)
1490 if (mnt->minorversion && mnt->version != 4)
1491 goto out_minorversion_mismatch;
1494 * verify that any proto=/mountproto= options match the address
1495 * familiies in the addr=/mountaddr= options.
1497 if (protofamily != AF_UNSPEC &&
1498 protofamily != mnt->nfs_server.address.ss_family)
1499 goto out_proto_mismatch;
1501 if (mountfamily != AF_UNSPEC) {
1502 if (mnt->mount_server.addrlen) {
1503 if (mountfamily != mnt->mount_server.address.ss_family)
1504 goto out_mountproto_mismatch;
1506 if (mountfamily != mnt->nfs_server.address.ss_family)
1507 goto out_mountproto_mismatch;
1513 out_mountproto_mismatch:
1514 printk(KERN_INFO "NFS: mount server address does not match mountproto= "
1518 printk(KERN_INFO "NFS: server address does not match proto= option\n");
1520 out_invalid_address:
1521 printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
1524 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
1526 out_minorversion_mismatch:
1527 printk(KERN_INFO "NFS: mount option vers=%u does not support "
1528 "minorversion=%u\n", mnt->version, mnt->minorversion);
1531 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1533 out_security_failure:
1534 free_secdata(secdata);
1535 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1540 * Match the requested auth flavors with the list returned by
1541 * the server. Returns zero and sets the mount's authentication
1542 * flavor on success; returns -EACCES if server does not support
1543 * the requested flavor.
1545 static int nfs_walk_authlist(struct nfs_parsed_mount_data *args,
1546 struct nfs_mount_request *request)
1548 unsigned int i, j, server_authlist_len = *(request->auth_flav_len);
1551 * Certain releases of Linux's mountd return an empty
1552 * flavor list. To prevent behavioral regression with
1553 * these servers (ie. rejecting mounts that used to
1554 * succeed), revert to pre-2.6.32 behavior (no checking)
1555 * if the returned flavor list is empty.
1557 if (server_authlist_len == 0)
1561 * We avoid sophisticated negotiating here, as there are
1562 * plenty of cases where we can get it wrong, providing
1563 * either too little or too much security.
1565 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1566 * flavor listed first. However, some servers list
1567 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1568 * preferred default, in args->auth_flavors[0] if user
1569 * didn't specify sec= mount option.
1571 for (i = 0; i < args->auth_flavor_len; i++)
1572 for (j = 0; j < server_authlist_len; j++)
1573 if (args->auth_flavors[i] == request->auth_flavs[j]) {
1574 dfprintk(MOUNT, "NFS: using auth flavor %d\n",
1575 request->auth_flavs[j]);
1576 args->auth_flavors[0] = request->auth_flavs[j];
1580 dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n");
1581 nfs_umount(request);
1586 * Use the remote server's MOUNT service to request the NFS file handle
1587 * corresponding to the provided path.
1589 static int nfs_request_mount(struct nfs_parsed_mount_data *args,
1590 struct nfs_fh *root_fh)
1592 rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS];
1593 unsigned int server_authlist_len = ARRAY_SIZE(server_authlist);
1594 struct nfs_mount_request request = {
1595 .sap = (struct sockaddr *)
1596 &args->mount_server.address,
1597 .dirpath = args->nfs_server.export_path,
1598 .protocol = args->mount_server.protocol,
1600 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
1601 .auth_flav_len = &server_authlist_len,
1602 .auth_flavs = server_authlist,
1607 if (args->mount_server.version == 0) {
1608 switch (args->version) {
1610 args->mount_server.version = NFS_MNT3_VERSION;
1613 args->mount_server.version = NFS_MNT_VERSION;
1616 request.version = args->mount_server.version;
1618 if (args->mount_server.hostname)
1619 request.hostname = args->mount_server.hostname;
1621 request.hostname = args->nfs_server.hostname;
1624 * Construct the mount server's address.
1626 if (args->mount_server.address.ss_family == AF_UNSPEC) {
1627 memcpy(request.sap, &args->nfs_server.address,
1628 args->nfs_server.addrlen);
1629 args->mount_server.addrlen = args->nfs_server.addrlen;
1631 request.salen = args->mount_server.addrlen;
1632 nfs_set_port(request.sap, &args->mount_server.port, 0);
1635 * Now ask the mount server to map our export path
1638 status = nfs_mount(&request);
1640 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1641 request.hostname, status);
1646 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1648 if (args->mount_server.version != NFS_MNT3_VERSION)
1650 return nfs_walk_authlist(args, &request);
1653 struct dentry *nfs_try_mount(int flags, const char *dev_name,
1654 struct nfs_mount_info *mount_info,
1655 struct nfs_subversion *nfs_mod)
1658 struct nfs_server *server;
1660 if (mount_info->parsed->need_mount) {
1661 status = nfs_request_mount(mount_info->parsed, mount_info->mntfh);
1663 return ERR_PTR(status);
1666 /* Get a volume representation */
1667 server = nfs_mod->rpc_ops->create_server(mount_info, nfs_mod);
1669 return ERR_CAST(server);
1671 return nfs_fs_mount_common(server, flags, dev_name, mount_info, nfs_mod);
1675 * Split "dev_name" into "hostname:export_path".
1677 * The leftmost colon demarks the split between the server's hostname
1678 * and the export path. If the hostname starts with a left square
1679 * bracket, then it may contain colons.
1681 * Note: caller frees hostname and export path, even on error.
1683 static int nfs_parse_devname(const char *dev_name,
1684 char **hostname, size_t maxnamlen,
1685 char **export_path, size_t maxpathlen)
1690 /* Is the host name protected with square brakcets? */
1691 if (*dev_name == '[') {
1692 end = strchr(++dev_name, ']');
1693 if (end == NULL || end[1] != ':')
1694 goto out_bad_devname;
1696 len = end - dev_name;
1701 end = strchr(dev_name, ':');
1703 goto out_bad_devname;
1704 len = end - dev_name;
1706 /* kill possible hostname list: not supported */
1707 comma = strchr(dev_name, ',');
1708 if (comma != NULL && comma < end)
1712 if (len > maxnamlen)
1715 /* N.B. caller will free nfs_server.hostname in all cases */
1716 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
1717 if (*hostname == NULL)
1719 len = strlen(++end);
1720 if (len > maxpathlen)
1722 *export_path = kstrndup(end, len, GFP_KERNEL);
1726 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1730 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1734 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1738 dfprintk(MOUNT, "NFS: server hostname too long\n");
1739 return -ENAMETOOLONG;
1742 dfprintk(MOUNT, "NFS: export pathname too long\n");
1743 return -ENAMETOOLONG;
1747 * Validate the NFS2/NFS3 mount data
1748 * - fills in the mount root filehandle
1750 * For option strings, user space handles the following behaviors:
1752 * + DNS: mapping server host name to IP address ("addr=" option)
1754 * + failure mode: how to behave if a mount request can't be handled
1755 * immediately ("fg/bg" option)
1757 * + retry: how often to retry a mount request ("retry=" option)
1759 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1760 * mountproto=tcp after mountproto=udp, and so on
1762 static int nfs23_validate_mount_data(void *options,
1763 struct nfs_parsed_mount_data *args,
1764 struct nfs_fh *mntfh,
1765 const char *dev_name)
1767 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
1768 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
1773 args->version = NFS_DEFAULT_VERSION;
1774 switch (data->version) {
1780 if (data->flags & NFS_MOUNT_VER3)
1782 data->root.size = NFS2_FHSIZE;
1783 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1785 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1788 memset(data->context, 0, sizeof(data->context));
1790 if (data->flags & NFS_MOUNT_VER3) {
1791 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1792 goto out_invalid_fh;
1793 mntfh->size = data->root.size;
1796 mntfh->size = NFS2_FHSIZE;
1801 memcpy(mntfh->data, data->root.data, mntfh->size);
1802 if (mntfh->size < sizeof(mntfh->data))
1803 memset(mntfh->data + mntfh->size, 0,
1804 sizeof(mntfh->data) - mntfh->size);
1807 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1810 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
1811 args->flags |= NFS_MOUNT_LEGACY_INTERFACE;
1812 args->rsize = data->rsize;
1813 args->wsize = data->wsize;
1814 args->timeo = data->timeo;
1815 args->retrans = data->retrans;
1816 args->acregmin = data->acregmin;
1817 args->acregmax = data->acregmax;
1818 args->acdirmin = data->acdirmin;
1819 args->acdirmax = data->acdirmax;
1820 args->need_mount = false;
1822 memcpy(sap, &data->addr, sizeof(data->addr));
1823 args->nfs_server.addrlen = sizeof(data->addr);
1824 if (!nfs_verify_server_address(sap))
1825 goto out_no_address;
1827 if (!(data->flags & NFS_MOUNT_TCP))
1828 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1829 /* N.B. caller will free nfs_server.hostname in all cases */
1830 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1831 args->namlen = data->namlen;
1832 args->bsize = data->bsize;
1834 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1835 args->auth_flavors[0] = data->pseudoflavor;
1836 if (!args->nfs_server.hostname)
1839 if (!(data->flags & NFS_MOUNT_NONLM))
1840 args->flags &= ~(NFS_MOUNT_LOCAL_FLOCK|
1841 NFS_MOUNT_LOCAL_FCNTL);
1843 args->flags |= (NFS_MOUNT_LOCAL_FLOCK|
1844 NFS_MOUNT_LOCAL_FCNTL);
1846 * The legacy version 6 binary mount data from userspace has a
1847 * field used only to transport selinux information into the
1848 * the kernel. To continue to support that functionality we
1849 * have a touch of selinux knowledge here in the NFS code. The
1850 * userspace code converted context=blah to just blah so we are
1851 * converting back to the full string selinux understands.
1853 if (data->context[0]){
1854 #ifdef CONFIG_SECURITY_SELINUX
1856 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1859 strcpy(opts_str, "context=");
1860 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1861 strcat(opts_str, &data->context[0]);
1862 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1873 return NFS_TEXT_DATA;
1876 #ifndef CONFIG_NFS_V3
1877 if (args->version == 3)
1878 goto out_v3_not_compiled;
1879 #endif /* !CONFIG_NFS_V3 */
1884 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1888 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1893 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1896 #ifndef CONFIG_NFS_V3
1897 out_v3_not_compiled:
1898 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1899 return -EPROTONOSUPPORT;
1900 #endif /* !CONFIG_NFS_V3 */
1903 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
1907 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1911 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1915 #ifdef CONFIG_NFS_V4
1916 static int nfs_validate_mount_data(struct file_system_type *fs_type,
1918 struct nfs_parsed_mount_data *args,
1919 struct nfs_fh *mntfh,
1920 const char *dev_name)
1922 if (fs_type == &nfs_fs_type)
1923 return nfs23_validate_mount_data(options, args, mntfh, dev_name);
1924 return nfs4_validate_mount_data(options, args, dev_name);
1927 static int nfs_validate_mount_data(struct file_system_type *fs_type,
1929 struct nfs_parsed_mount_data *args,
1930 struct nfs_fh *mntfh,
1931 const char *dev_name)
1933 return nfs23_validate_mount_data(options, args, mntfh, dev_name);
1937 static int nfs_validate_text_mount_data(void *options,
1938 struct nfs_parsed_mount_data *args,
1939 const char *dev_name)
1942 int max_namelen = PAGE_SIZE;
1943 int max_pathlen = NFS_MAXPATHLEN;
1944 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
1946 if (nfs_parse_mount_options((char *)options, args) == 0)
1949 if (!nfs_verify_server_address(sap))
1950 goto out_no_address;
1952 if (args->version == 4) {
1953 #ifdef CONFIG_NFS_V4
1955 max_namelen = NFS4_MAXNAMLEN;
1956 max_pathlen = NFS4_MAXPATHLEN;
1957 nfs_validate_transport_protocol(args);
1958 nfs4_validate_mount_flags(args);
1960 goto out_v4_not_compiled;
1961 #endif /* CONFIG_NFS_V4 */
1963 nfs_set_mount_transport_protocol(args);
1965 nfs_set_port(sap, &args->nfs_server.port, port);
1967 if (args->auth_flavor_len > 1)
1970 return nfs_parse_devname(dev_name,
1971 &args->nfs_server.hostname,
1973 &args->nfs_server.export_path,
1976 #ifndef CONFIG_NFS_V4
1977 out_v4_not_compiled:
1978 dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n");
1979 return -EPROTONOSUPPORT;
1980 #endif /* !CONFIG_NFS_V4 */
1983 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1987 dfprintk(MOUNT, "NFS: Too many RPC auth flavours specified\n");
1992 nfs_compare_remount_data(struct nfs_server *nfss,
1993 struct nfs_parsed_mount_data *data)
1995 if (data->flags != nfss->flags ||
1996 data->rsize != nfss->rsize ||
1997 data->wsize != nfss->wsize ||
1998 data->retrans != nfss->client->cl_timeout->to_retries ||
1999 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
2000 data->acregmin != nfss->acregmin / HZ ||
2001 data->acregmax != nfss->acregmax / HZ ||
2002 data->acdirmin != nfss->acdirmin / HZ ||
2003 data->acdirmax != nfss->acdirmax / HZ ||
2004 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
2005 data->nfs_server.port != nfss->port ||
2006 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
2007 !rpc_cmp_addr((struct sockaddr *)&data->nfs_server.address,
2008 (struct sockaddr *)&nfss->nfs_client->cl_addr))
2015 nfs_remount(struct super_block *sb, int *flags, char *raw_data)
2018 struct nfs_server *nfss = sb->s_fs_info;
2019 struct nfs_parsed_mount_data *data;
2020 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
2021 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
2022 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
2025 * Userspace mount programs that send binary options generally send
2026 * them populated with default values. We have no way to know which
2027 * ones were explicitly specified. Fall back to legacy behavior and
2028 * just return success.
2030 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
2031 (nfsvers <= 3 && (!options || (options->version >= 1 &&
2032 options->version <= 6))))
2035 data = kzalloc(sizeof(*data), GFP_KERNEL);
2039 /* fill out struct with values from existing mount */
2040 data->flags = nfss->flags;
2041 data->rsize = nfss->rsize;
2042 data->wsize = nfss->wsize;
2043 data->retrans = nfss->client->cl_timeout->to_retries;
2044 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
2045 data->acregmin = nfss->acregmin / HZ;
2046 data->acregmax = nfss->acregmax / HZ;
2047 data->acdirmin = nfss->acdirmin / HZ;
2048 data->acdirmax = nfss->acdirmax / HZ;
2049 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
2050 data->nfs_server.port = nfss->port;
2051 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
2052 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
2053 data->nfs_server.addrlen);
2055 /* overwrite those values with any that were specified */
2056 error = nfs_parse_mount_options((char *)options, data);
2061 * noac is a special case. It implies -o sync, but that's not
2062 * necessarily reflected in the mtab options. do_remount_sb
2063 * will clear MS_SYNCHRONOUS if -o sync wasn't specified in the
2064 * remount options, so we have to explicitly reset it.
2066 if (data->flags & NFS_MOUNT_NOAC)
2067 *flags |= MS_SYNCHRONOUS;
2069 /* compare new mount options with old ones */
2070 error = nfs_compare_remount_data(nfss, data);
2077 * Initialise the common bits of the superblock
2079 inline void nfs_initialise_sb(struct super_block *sb)
2081 struct nfs_server *server = NFS_SB(sb);
2083 sb->s_magic = NFS_SUPER_MAGIC;
2085 /* We probably want something more informative here */
2086 snprintf(sb->s_id, sizeof(sb->s_id),
2087 "%u:%u", MAJOR(sb->s_dev), MINOR(sb->s_dev));
2089 if (sb->s_blocksize == 0)
2090 sb->s_blocksize = nfs_block_bits(server->wsize,
2091 &sb->s_blocksize_bits);
2093 sb->s_bdi = &server->backing_dev_info;
2095 nfs_super_set_maxbytes(sb, server->maxfilesize);
2099 * Finish setting up an NFS2/3 superblock
2101 void nfs_fill_super(struct super_block *sb, struct nfs_mount_info *mount_info)
2103 struct nfs_parsed_mount_data *data = mount_info->parsed;
2104 struct nfs_server *server = NFS_SB(sb);
2106 sb->s_blocksize_bits = 0;
2107 sb->s_blocksize = 0;
2108 sb->s_xattr = server->nfs_client->cl_nfs_mod->xattr;
2109 sb->s_op = server->nfs_client->cl_nfs_mod->sops;
2110 if (data && data->bsize)
2111 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
2113 if (server->nfs_client->rpc_ops->version != 2) {
2114 /* The VFS shouldn't apply the umask to mode bits. We will do
2115 * so ourselves when necessary.
2117 sb->s_flags |= MS_POSIXACL;
2118 sb->s_time_gran = 1;
2121 nfs_initialise_sb(sb);
2125 * Finish setting up a cloned NFS2/3/4 superblock
2127 void nfs_clone_super(struct super_block *sb, struct nfs_mount_info *mount_info)
2129 const struct super_block *old_sb = mount_info->cloned->sb;
2130 struct nfs_server *server = NFS_SB(sb);
2132 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2133 sb->s_blocksize = old_sb->s_blocksize;
2134 sb->s_maxbytes = old_sb->s_maxbytes;
2135 sb->s_xattr = old_sb->s_xattr;
2136 sb->s_op = old_sb->s_op;
2137 sb->s_time_gran = 1;
2139 if (server->nfs_client->rpc_ops->version != 2) {
2140 /* The VFS shouldn't apply the umask to mode bits. We will do
2141 * so ourselves when necessary.
2143 sb->s_flags |= MS_POSIXACL;
2146 nfs_initialise_sb(sb);
2149 static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
2151 const struct nfs_server *a = s->s_fs_info;
2152 const struct rpc_clnt *clnt_a = a->client;
2153 const struct rpc_clnt *clnt_b = b->client;
2155 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
2157 if (a->nfs_client != b->nfs_client)
2159 if (a->flags != b->flags)
2161 if (a->wsize != b->wsize)
2163 if (a->rsize != b->rsize)
2165 if (a->acregmin != b->acregmin)
2167 if (a->acregmax != b->acregmax)
2169 if (a->acdirmin != b->acdirmin)
2171 if (a->acdirmax != b->acdirmax)
2173 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
2180 struct nfs_sb_mountdata {
2181 struct nfs_server *server;
2185 static int nfs_set_super(struct super_block *s, void *data)
2187 struct nfs_sb_mountdata *sb_mntdata = data;
2188 struct nfs_server *server = sb_mntdata->server;
2191 s->s_flags = sb_mntdata->mntflags;
2192 s->s_fs_info = server;
2193 s->s_d_op = server->nfs_client->rpc_ops->dentry_ops;
2194 ret = set_anon_super(s, server);
2196 server->s_dev = s->s_dev;
2200 static int nfs_compare_super_address(struct nfs_server *server1,
2201 struct nfs_server *server2)
2203 struct sockaddr *sap1, *sap2;
2205 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
2206 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
2208 if (sap1->sa_family != sap2->sa_family)
2211 switch (sap1->sa_family) {
2213 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
2214 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
2215 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
2217 if (sin1->sin_port != sin2->sin_port)
2222 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
2223 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
2224 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
2226 if (sin1->sin6_port != sin2->sin6_port)
2237 static int nfs_compare_super(struct super_block *sb, void *data)
2239 struct nfs_sb_mountdata *sb_mntdata = data;
2240 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2241 int mntflags = sb_mntdata->mntflags;
2243 if (!nfs_compare_super_address(old, server))
2245 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2246 if (old->flags & NFS_MOUNT_UNSHARED)
2248 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2250 return nfs_compare_mount_options(sb, server, mntflags);
2253 #ifdef CONFIG_NFS_FSCACHE
2254 static void nfs_get_cache_cookie(struct super_block *sb,
2255 struct nfs_parsed_mount_data *parsed,
2256 struct nfs_clone_mount *cloned)
2261 if (parsed && parsed->fscache_uniq) {
2262 uniq = parsed->fscache_uniq;
2263 ulen = strlen(parsed->fscache_uniq);
2264 } else if (cloned) {
2265 struct nfs_server *mnt_s = NFS_SB(cloned->sb);
2266 if (mnt_s->fscache_key) {
2267 uniq = mnt_s->fscache_key->key.uniquifier;
2268 ulen = mnt_s->fscache_key->key.uniq_len;
2272 nfs_fscache_get_super_cookie(sb, uniq, ulen);
2275 static void nfs_get_cache_cookie(struct super_block *sb,
2276 struct nfs_parsed_mount_data *parsed,
2277 struct nfs_clone_mount *cloned)
2282 static int nfs_bdi_register(struct nfs_server *server)
2284 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
2287 int nfs_set_sb_security(struct super_block *s, struct dentry *mntroot,
2288 struct nfs_mount_info *mount_info)
2290 return security_sb_set_mnt_opts(s, &mount_info->parsed->lsm_opts);
2293 int nfs_clone_sb_security(struct super_block *s, struct dentry *mntroot,
2294 struct nfs_mount_info *mount_info)
2296 /* clone any lsm security options from the parent to the new sb */
2297 security_sb_clone_mnt_opts(mount_info->cloned->sb, s);
2298 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops)
2303 struct dentry *nfs_fs_mount_common(struct nfs_server *server,
2304 int flags, const char *dev_name,
2305 struct nfs_mount_info *mount_info,
2306 struct nfs_subversion *nfs_mod)
2308 struct super_block *s;
2309 struct dentry *mntroot = ERR_PTR(-ENOMEM);
2310 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2311 struct nfs_sb_mountdata sb_mntdata = {
2317 if (server->flags & NFS_MOUNT_UNSHARED)
2318 compare_super = NULL;
2320 /* -o noac implies -o sync */
2321 if (server->flags & NFS_MOUNT_NOAC)
2322 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2324 /* Get a superblock - note that we may end up sharing one that already exists */
2325 s = sget(nfs_mod->nfs_fs, compare_super, nfs_set_super, flags, &sb_mntdata);
2327 mntroot = ERR_CAST(s);
2331 if (s->s_fs_info != server) {
2332 nfs_free_server(server);
2335 error = nfs_bdi_register(server);
2337 mntroot = ERR_PTR(error);
2338 goto error_splat_bdi;
2343 /* initial superblock/root creation */
2344 mount_info->fill_super(s, mount_info);
2345 nfs_get_cache_cookie(s, mount_info->parsed, mount_info->cloned);
2348 mntroot = nfs_get_root(s, mount_info->mntfh, dev_name);
2349 if (IS_ERR(mntroot))
2350 goto error_splat_super;
2352 error = mount_info->set_security(s, mntroot, mount_info);
2354 goto error_splat_root;
2356 s->s_flags |= MS_ACTIVE;
2362 nfs_free_server(server);
2367 mntroot = ERR_PTR(error);
2369 if (server && !s->s_root)
2370 bdi_unregister(&server->backing_dev_info);
2372 deactivate_locked_super(s);
2376 struct dentry *nfs_fs_mount(struct file_system_type *fs_type,
2377 int flags, const char *dev_name, void *raw_data)
2379 struct nfs_mount_info mount_info = {
2380 .fill_super = nfs_fill_super,
2381 .set_security = nfs_set_sb_security,
2383 struct dentry *mntroot = ERR_PTR(-ENOMEM);
2384 struct nfs_subversion *nfs_mod;
2387 mount_info.parsed = nfs_alloc_parsed_mount_data();
2388 mount_info.mntfh = nfs_alloc_fhandle();
2389 if (mount_info.parsed == NULL || mount_info.mntfh == NULL)
2392 /* Validate the mount data */
2393 error = nfs_validate_mount_data(fs_type, raw_data, mount_info.parsed, mount_info.mntfh, dev_name);
2394 if (error == NFS_TEXT_DATA)
2395 error = nfs_validate_text_mount_data(raw_data, mount_info.parsed, dev_name);
2397 mntroot = ERR_PTR(error);
2401 nfs_mod = get_nfs_version(mount_info.parsed->version);
2402 if (IS_ERR(nfs_mod)) {
2403 mntroot = ERR_CAST(nfs_mod);
2407 mntroot = nfs_mod->rpc_ops->try_mount(flags, dev_name, &mount_info, nfs_mod);
2409 put_nfs_version(nfs_mod);
2411 nfs_free_parsed_mount_data(mount_info.parsed);
2412 nfs_free_fhandle(mount_info.mntfh);
2417 * Ensure that we unregister the bdi before kill_anon_super
2418 * releases the device name
2420 void nfs_put_super(struct super_block *s)
2422 struct nfs_server *server = NFS_SB(s);
2424 bdi_unregister(&server->backing_dev_info);
2428 * Destroy an NFS2/3 superblock
2430 void nfs_kill_super(struct super_block *s)
2432 struct nfs_server *server = NFS_SB(s);
2435 nfs_fscache_release_super_cookie(s);
2436 nfs_free_server(server);
2440 * Clone an NFS2/3/4 server record on xdev traversal (FSID-change)
2443 nfs_xdev_mount(struct file_system_type *fs_type, int flags,
2444 const char *dev_name, void *raw_data)
2446 struct nfs_clone_mount *data = raw_data;
2447 struct nfs_mount_info mount_info = {
2448 .fill_super = nfs_clone_super,
2449 .set_security = nfs_clone_sb_security,
2452 struct nfs_server *server;
2453 struct dentry *mntroot = ERR_PTR(-ENOMEM);
2454 struct nfs_subversion *nfs_mod = NFS_SB(data->sb)->nfs_client->cl_nfs_mod;
2457 dprintk("--> nfs_xdev_mount_common()\n");
2459 mount_info.mntfh = mount_info.cloned->fh;
2461 /* create a new volume representation */
2462 server = nfs_mod->rpc_ops->clone_server(NFS_SB(data->sb), data->fh, data->fattr, data->authflavor);
2463 if (IS_ERR(server)) {
2464 error = PTR_ERR(server);
2468 mntroot = nfs_fs_mount_common(server, flags, dev_name, &mount_info, nfs_mod);
2469 dprintk("<-- nfs_xdev_mount_common() = 0\n");
2474 dprintk("<-- nfs_xdev_mount_common() = %d [error]\n", error);
2478 #ifdef CONFIG_NFS_V4
2480 static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2482 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3|
2483 NFS_MOUNT_LOCAL_FLOCK|NFS_MOUNT_LOCAL_FCNTL);
2487 * Validate NFSv4 mount options
2489 static int nfs4_validate_mount_data(void *options,
2490 struct nfs_parsed_mount_data *args,
2491 const char *dev_name)
2493 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2494 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
2502 switch (data->version) {
2504 if (data->host_addrlen > sizeof(args->nfs_server.address))
2505 goto out_no_address;
2506 if (data->host_addrlen == 0)
2507 goto out_no_address;
2508 args->nfs_server.addrlen = data->host_addrlen;
2509 if (copy_from_user(sap, data->host_addr, data->host_addrlen))
2511 if (!nfs_verify_server_address(sap))
2512 goto out_no_address;
2514 if (data->auth_flavourlen) {
2515 if (data->auth_flavourlen > 1)
2516 goto out_inval_auth;
2517 if (copy_from_user(&args->auth_flavors[0],
2518 data->auth_flavours,
2519 sizeof(args->auth_flavors[0])))
2523 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2526 args->nfs_server.hostname = c;
2528 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2531 args->nfs_server.export_path = c;
2532 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
2534 c = strndup_user(data->client_addr.data, 16);
2537 args->client_address = c;
2540 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2544 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2545 args->rsize = data->rsize;
2546 args->wsize = data->wsize;
2547 args->timeo = data->timeo;
2548 args->retrans = data->retrans;
2549 args->acregmin = data->acregmin;
2550 args->acregmax = data->acregmax;
2551 args->acdirmin = data->acdirmin;
2552 args->acdirmax = data->acdirmax;
2553 args->nfs_server.protocol = data->proto;
2554 nfs_validate_transport_protocol(args);
2558 return NFS_TEXT_DATA;
2564 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2568 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2569 data->auth_flavourlen);
2573 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2577 #endif /* CONFIG_NFS_V4 */