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/nfs_idmap.h>
46 #include <linux/vfs.h>
47 #include <linux/inet.h>
48 #include <linux/in6.h>
50 #include <linux/netdevice.h>
51 #include <linux/nfs_xdr.h>
52 #include <linux/magic.h>
53 #include <linux/parser.h>
55 #include <asm/system.h>
56 #include <asm/uaccess.h>
60 #include "delegation.h"
65 #define NFSDBG_FACILITY NFSDBG_VFS
68 /* Mount options that take no arguments */
70 Opt_posix, Opt_noposix,
75 Opt_udp, Opt_tcp, Opt_rdma,
77 Opt_rdirplus, Opt_nordirplus,
78 Opt_sharecache, Opt_nosharecache,
79 Opt_resvport, Opt_noresvport,
80 Opt_fscache, Opt_nofscache,
82 /* Mount options that take integer arguments */
84 Opt_rsize, Opt_wsize, Opt_bsize,
85 Opt_timeo, Opt_retrans,
86 Opt_acregmin, Opt_acregmax,
87 Opt_acdirmin, Opt_acdirmax,
94 /* Mount options that take string arguments */
95 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
96 Opt_addr, Opt_mountaddr, Opt_clientaddr,
100 /* Special mount options */
101 Opt_userspace, Opt_deprecated, Opt_sloppy,
106 static const match_table_t nfs_mount_option_tokens = {
107 { Opt_userspace, "bg" },
108 { Opt_userspace, "fg" },
109 { Opt_userspace, "retry=%s" },
111 { Opt_sloppy, "sloppy" },
113 { Opt_soft, "soft" },
114 { Opt_hard, "hard" },
115 { Opt_deprecated, "intr" },
116 { Opt_deprecated, "nointr" },
117 { Opt_posix, "posix" },
118 { Opt_noposix, "noposix" },
120 { Opt_nocto, "nocto" },
122 { Opt_noac, "noac" },
123 { Opt_lock, "lock" },
124 { Opt_nolock, "nolock" },
129 { Opt_rdma, "rdma" },
131 { Opt_noacl, "noacl" },
132 { Opt_rdirplus, "rdirplus" },
133 { Opt_nordirplus, "nordirplus" },
134 { Opt_sharecache, "sharecache" },
135 { Opt_nosharecache, "nosharecache" },
136 { Opt_resvport, "resvport" },
137 { Opt_noresvport, "noresvport" },
138 { Opt_fscache, "fsc" },
139 { Opt_fscache_uniq, "fsc=%s" },
140 { Opt_nofscache, "nofsc" },
142 { Opt_port, "port=%u" },
143 { Opt_rsize, "rsize=%u" },
144 { Opt_wsize, "wsize=%u" },
145 { Opt_bsize, "bsize=%u" },
146 { Opt_timeo, "timeo=%u" },
147 { Opt_retrans, "retrans=%u" },
148 { Opt_acregmin, "acregmin=%u" },
149 { Opt_acregmax, "acregmax=%u" },
150 { Opt_acdirmin, "acdirmin=%u" },
151 { Opt_acdirmax, "acdirmax=%u" },
152 { Opt_actimeo, "actimeo=%u" },
153 { Opt_namelen, "namlen=%u" },
154 { Opt_mountport, "mountport=%u" },
155 { Opt_mountvers, "mountvers=%u" },
156 { Opt_nfsvers, "nfsvers=%u" },
157 { Opt_nfsvers, "vers=%u" },
159 { Opt_sec, "sec=%s" },
160 { Opt_proto, "proto=%s" },
161 { Opt_mountproto, "mountproto=%s" },
162 { Opt_addr, "addr=%s" },
163 { Opt_clientaddr, "clientaddr=%s" },
164 { Opt_mounthost, "mounthost=%s" },
165 { Opt_mountaddr, "mountaddr=%s" },
167 { Opt_lookupcache, "lookupcache=%s" },
173 Opt_xprt_udp, Opt_xprt_tcp, Opt_xprt_rdma,
178 static const match_table_t nfs_xprt_protocol_tokens = {
179 { Opt_xprt_udp, "udp" },
180 { Opt_xprt_tcp, "tcp" },
181 { Opt_xprt_rdma, "rdma" },
183 { Opt_xprt_err, NULL }
187 Opt_sec_none, Opt_sec_sys,
188 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
189 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
190 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
195 static const match_table_t nfs_secflavor_tokens = {
196 { Opt_sec_none, "none" },
197 { Opt_sec_none, "null" },
198 { Opt_sec_sys, "sys" },
200 { Opt_sec_krb5, "krb5" },
201 { Opt_sec_krb5i, "krb5i" },
202 { Opt_sec_krb5p, "krb5p" },
204 { Opt_sec_lkey, "lkey" },
205 { Opt_sec_lkeyi, "lkeyi" },
206 { Opt_sec_lkeyp, "lkeyp" },
208 { Opt_sec_spkm, "spkm3" },
209 { Opt_sec_spkmi, "spkm3i" },
210 { Opt_sec_spkmp, "spkm3p" },
212 { Opt_sec_err, NULL }
216 Opt_lookupcache_all, Opt_lookupcache_positive,
217 Opt_lookupcache_none,
222 static match_table_t nfs_lookupcache_tokens = {
223 { Opt_lookupcache_all, "all" },
224 { Opt_lookupcache_positive, "pos" },
225 { Opt_lookupcache_positive, "positive" },
226 { Opt_lookupcache_none, "none" },
228 { Opt_lookupcache_err, NULL }
232 static void nfs_umount_begin(struct super_block *);
233 static int nfs_statfs(struct dentry *, struct kstatfs *);
234 static int nfs_show_options(struct seq_file *, struct vfsmount *);
235 static int nfs_show_stats(struct seq_file *, struct vfsmount *);
236 static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
237 static int nfs_xdev_get_sb(struct file_system_type *fs_type,
238 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
239 static void nfs_kill_super(struct super_block *);
240 static int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
242 static struct file_system_type nfs_fs_type = {
243 .owner = THIS_MODULE,
245 .get_sb = nfs_get_sb,
246 .kill_sb = nfs_kill_super,
247 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
250 struct file_system_type nfs_xdev_fs_type = {
251 .owner = THIS_MODULE,
253 .get_sb = nfs_xdev_get_sb,
254 .kill_sb = nfs_kill_super,
255 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
258 static const struct super_operations nfs_sops = {
259 .alloc_inode = nfs_alloc_inode,
260 .destroy_inode = nfs_destroy_inode,
261 .write_inode = nfs_write_inode,
262 .statfs = nfs_statfs,
263 .clear_inode = nfs_clear_inode,
264 .umount_begin = nfs_umount_begin,
265 .show_options = nfs_show_options,
266 .show_stats = nfs_show_stats,
267 .remount_fs = nfs_remount,
271 static int nfs4_get_sb(struct file_system_type *fs_type,
272 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
273 static int nfs4_xdev_get_sb(struct file_system_type *fs_type,
274 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
275 static int nfs4_referral_get_sb(struct file_system_type *fs_type,
276 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
277 static void nfs4_kill_super(struct super_block *sb);
279 static struct file_system_type nfs4_fs_type = {
280 .owner = THIS_MODULE,
282 .get_sb = nfs4_get_sb,
283 .kill_sb = nfs4_kill_super,
284 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
287 struct file_system_type nfs4_xdev_fs_type = {
288 .owner = THIS_MODULE,
290 .get_sb = nfs4_xdev_get_sb,
291 .kill_sb = nfs4_kill_super,
292 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
295 struct file_system_type nfs4_referral_fs_type = {
296 .owner = THIS_MODULE,
298 .get_sb = nfs4_referral_get_sb,
299 .kill_sb = nfs4_kill_super,
300 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
303 static const struct super_operations nfs4_sops = {
304 .alloc_inode = nfs_alloc_inode,
305 .destroy_inode = nfs_destroy_inode,
306 .write_inode = nfs_write_inode,
307 .statfs = nfs_statfs,
308 .clear_inode = nfs4_clear_inode,
309 .umount_begin = nfs_umount_begin,
310 .show_options = nfs_show_options,
311 .show_stats = nfs_show_stats,
312 .remount_fs = nfs_remount,
316 static struct shrinker acl_shrinker = {
317 .shrink = nfs_access_cache_shrinker,
318 .seeks = DEFAULT_SEEKS,
322 * Register the NFS filesystems
324 int __init register_nfs_fs(void)
328 ret = register_filesystem(&nfs_fs_type);
332 ret = nfs_register_sysctl();
336 ret = register_filesystem(&nfs4_fs_type);
340 register_shrinker(&acl_shrinker);
345 nfs_unregister_sysctl();
348 unregister_filesystem(&nfs_fs_type);
354 * Unregister the NFS filesystems
356 void __exit unregister_nfs_fs(void)
358 unregister_shrinker(&acl_shrinker);
360 unregister_filesystem(&nfs4_fs_type);
362 nfs_unregister_sysctl();
363 unregister_filesystem(&nfs_fs_type);
366 void nfs_sb_active(struct super_block *sb)
368 struct nfs_server *server = NFS_SB(sb);
370 if (atomic_inc_return(&server->active) == 1)
371 atomic_inc(&sb->s_active);
374 void nfs_sb_deactive(struct super_block *sb)
376 struct nfs_server *server = NFS_SB(sb);
378 if (atomic_dec_and_test(&server->active))
379 deactivate_super(sb);
383 * Deliver file system statistics to userspace
385 static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
387 struct nfs_server *server = NFS_SB(dentry->d_sb);
388 unsigned char blockbits;
389 unsigned long blockres;
390 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
391 struct nfs_fattr fattr;
392 struct nfs_fsstat res = {
397 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
400 buf->f_type = NFS_SUPER_MAGIC;
403 * Current versions of glibc do not correctly handle the
404 * case where f_frsize != f_bsize. Eventually we want to
405 * report the value of wtmult in this field.
407 buf->f_frsize = dentry->d_sb->s_blocksize;
410 * On most *nix systems, f_blocks, f_bfree, and f_bavail
411 * are reported in units of f_frsize. Linux hasn't had
412 * an f_frsize field in its statfs struct until recently,
413 * thus historically Linux's sys_statfs reports these
414 * fields in units of f_bsize.
416 buf->f_bsize = dentry->d_sb->s_blocksize;
417 blockbits = dentry->d_sb->s_blocksize_bits;
418 blockres = (1 << blockbits) - 1;
419 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
420 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
421 buf->f_bavail = (res.abytes + blockres) >> blockbits;
423 buf->f_files = res.tfiles;
424 buf->f_ffree = res.afiles;
426 buf->f_namelen = server->namelen;
431 dprintk("%s: statfs error = %d\n", __func__, -error);
436 * Map the security flavour number to a name
438 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
440 static const struct {
441 rpc_authflavor_t flavour;
444 { RPC_AUTH_NULL, "null" },
445 { RPC_AUTH_UNIX, "sys" },
446 { RPC_AUTH_GSS_KRB5, "krb5" },
447 { RPC_AUTH_GSS_KRB5I, "krb5i" },
448 { RPC_AUTH_GSS_KRB5P, "krb5p" },
449 { RPC_AUTH_GSS_LKEY, "lkey" },
450 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
451 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
452 { RPC_AUTH_GSS_SPKM, "spkm" },
453 { RPC_AUTH_GSS_SPKMI, "spkmi" },
454 { RPC_AUTH_GSS_SPKMP, "spkmp" },
455 { UINT_MAX, "unknown" }
459 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
460 if (sec_flavours[i].flavour == flavour)
463 return sec_flavours[i].str;
466 static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
469 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
471 switch (sap->sa_family) {
473 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
474 seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
478 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
479 seq_printf(m, ",mountaddr=%pI6", &sin6->sin6_addr);
484 seq_printf(m, ",mountaddr=unspecified");
487 if (nfss->mountd_version || showdefaults)
488 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
489 if (nfss->mountd_port || showdefaults)
490 seq_printf(m, ",mountport=%u", nfss->mountd_port);
492 switch (nfss->mountd_protocol) {
494 seq_printf(m, ",mountproto=udp");
497 seq_printf(m, ",mountproto=tcp");
501 seq_printf(m, ",mountproto=auto");
506 * Describe the mount options in force on this server representation
508 static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
511 static const struct proc_nfs_info {
516 { NFS_MOUNT_SOFT, ",soft", ",hard" },
517 { NFS_MOUNT_POSIX, ",posix", "" },
518 { NFS_MOUNT_NOCTO, ",nocto", "" },
519 { NFS_MOUNT_NOAC, ",noac", "" },
520 { NFS_MOUNT_NONLM, ",nolock", "" },
521 { NFS_MOUNT_NOACL, ",noacl", "" },
522 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
523 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
524 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
527 const struct proc_nfs_info *nfs_infop;
528 struct nfs_client *clp = nfss->nfs_client;
529 u32 version = clp->rpc_ops->version;
531 seq_printf(m, ",vers=%u", version);
532 seq_printf(m, ",rsize=%u", nfss->rsize);
533 seq_printf(m, ",wsize=%u", nfss->wsize);
534 if (nfss->bsize != 0)
535 seq_printf(m, ",bsize=%u", nfss->bsize);
536 seq_printf(m, ",namlen=%u", nfss->namelen);
537 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
538 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
539 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
540 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
541 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
542 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
543 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
544 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
545 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
546 if (nfss->flags & nfs_infop->flag)
547 seq_puts(m, nfs_infop->str);
549 seq_puts(m, nfs_infop->nostr);
551 seq_printf(m, ",proto=%s",
552 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_PROTO));
554 if (nfss->port != NFS_PORT)
555 seq_printf(m, ",port=%u", nfss->port);
558 seq_printf(m, ",port=%u", nfss->port);
560 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
561 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
562 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
565 nfs_show_mountd_options(m, nfss, showdefaults);
568 if (clp->rpc_ops->version == 4)
569 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
571 if (nfss->options & NFS_OPTION_FSCACHE)
572 seq_printf(m, ",fsc");
576 * Describe the mount options on this VFS mountpoint
578 static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
580 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
582 nfs_show_mount_options(m, nfss, 0);
584 seq_printf(m, ",addr=%s",
585 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
592 * Present statistical information for this VFS mountpoint
594 static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
597 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
598 struct rpc_auth *auth = nfss->client->cl_auth;
599 struct nfs_iostats totals = { };
601 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
604 * Display all mount option settings
606 seq_printf(m, "\n\topts:\t");
607 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
608 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
609 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
610 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
611 nfs_show_mount_options(m, nfss, 1);
613 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
615 seq_printf(m, "\n\tcaps:\t");
616 seq_printf(m, "caps=0x%x", nfss->caps);
617 seq_printf(m, ",wtmult=%u", nfss->wtmult);
618 seq_printf(m, ",dtsize=%u", nfss->dtsize);
619 seq_printf(m, ",bsize=%u", nfss->bsize);
620 seq_printf(m, ",namlen=%u", nfss->namelen);
623 if (nfss->nfs_client->rpc_ops->version == 4) {
624 seq_printf(m, "\n\tnfsv4:\t");
625 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
626 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
627 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
632 * Display security flavor in effect for this mount
634 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
636 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
639 * Display superblock I/O counters
641 for_each_possible_cpu(cpu) {
642 struct nfs_iostats *stats;
645 stats = per_cpu_ptr(nfss->io_stats, cpu);
647 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
648 totals.events[i] += stats->events[i];
649 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
650 totals.bytes[i] += stats->bytes[i];
651 #ifdef CONFIG_NFS_FSCACHE
652 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
653 totals.fscache[i] += stats->fscache[i];
659 seq_printf(m, "\n\tevents:\t");
660 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
661 seq_printf(m, "%lu ", totals.events[i]);
662 seq_printf(m, "\n\tbytes:\t");
663 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
664 seq_printf(m, "%Lu ", totals.bytes[i]);
665 #ifdef CONFIG_NFS_FSCACHE
666 if (nfss->options & NFS_OPTION_FSCACHE) {
667 seq_printf(m, "\n\tfsc:\t");
668 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
669 seq_printf(m, "%Lu ", totals.bytes[i]);
674 rpc_print_iostats(m, nfss->client);
680 * Begin unmount by attempting to remove all automounted mountpoints we added
681 * in response to xdev traversals and referrals
683 static void nfs_umount_begin(struct super_block *sb)
685 struct nfs_server *server;
686 struct rpc_clnt *rpc;
691 /* -EIO all pending I/O */
692 rpc = server->client_acl;
694 rpc_killall_tasks(rpc);
695 rpc = server->client;
697 rpc_killall_tasks(rpc);
703 * Sanity-check a server address provided by the mount command.
705 * Address family must be initialized, and address must not be
706 * the ANY address for that family.
708 static int nfs_verify_server_address(struct sockaddr *addr)
710 switch (addr->sa_family) {
712 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
713 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
716 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
717 return !ipv6_addr_any(sa);
724 static void nfs_parse_ipv4_address(char *string, size_t str_len,
725 struct sockaddr *sap, size_t *addr_len)
727 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
728 u8 *addr = (u8 *)&sin->sin_addr.s_addr;
730 if (str_len <= INET_ADDRSTRLEN) {
731 dfprintk(MOUNT, "NFS: parsing IPv4 address %*s\n",
732 (int)str_len, string);
734 sin->sin_family = AF_INET;
735 *addr_len = sizeof(*sin);
736 if (in4_pton(string, str_len, addr, '\0', NULL))
740 sap->sa_family = AF_UNSPEC;
744 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
745 static int nfs_parse_ipv6_scope_id(const char *string, const size_t str_len,
747 struct sockaddr_in6 *sin6)
752 if ((string + str_len) == delim)
755 if (*delim != IPV6_SCOPE_DELIMITER)
758 if (!(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL))
761 len = (string + str_len) - delim - 1;
762 p = kstrndup(delim + 1, len, GFP_KERNEL);
764 unsigned long scope_id = 0;
765 struct net_device *dev;
767 dev = dev_get_by_name(&init_net, p);
769 scope_id = dev->ifindex;
772 if (strict_strtoul(p, 10, &scope_id) == 0) {
780 sin6->sin6_scope_id = scope_id;
781 dfprintk(MOUNT, "NFS: IPv6 scope ID = %lu\n", scope_id);
788 static void nfs_parse_ipv6_address(char *string, size_t str_len,
789 struct sockaddr *sap, size_t *addr_len)
791 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
792 u8 *addr = (u8 *)&sin6->sin6_addr.in6_u;
795 if (str_len <= INET6_ADDRSTRLEN) {
796 dfprintk(MOUNT, "NFS: parsing IPv6 address %*s\n",
797 (int)str_len, string);
799 sin6->sin6_family = AF_INET6;
800 *addr_len = sizeof(*sin6);
801 if (in6_pton(string, str_len, addr,
802 IPV6_SCOPE_DELIMITER, &delim) != 0) {
803 if (nfs_parse_ipv6_scope_id(string, str_len,
809 sap->sa_family = AF_UNSPEC;
813 static void nfs_parse_ipv6_address(char *string, size_t str_len,
814 struct sockaddr *sap, size_t *addr_len)
816 sap->sa_family = AF_UNSPEC;
822 * Construct a sockaddr based on the contents of a string that contains
823 * an IP address in presentation format.
825 * If there is a problem constructing the new sockaddr, set the address
826 * family to AF_UNSPEC.
828 void nfs_parse_ip_address(char *string, size_t str_len,
829 struct sockaddr *sap, size_t *addr_len)
831 unsigned int i, colons;
834 for (i = 0; i < str_len; i++)
835 if (string[i] == ':')
839 nfs_parse_ipv6_address(string, str_len, sap, addr_len);
841 nfs_parse_ipv4_address(string, str_len, sap, addr_len);
845 * Sanity check the NFS transport protocol.
848 static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
850 switch (mnt->nfs_server.protocol) {
851 case XPRT_TRANSPORT_UDP:
852 case XPRT_TRANSPORT_TCP:
853 case XPRT_TRANSPORT_RDMA:
856 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
861 * For text based NFSv2/v3 mounts, the mount protocol transport default
862 * settings should depend upon the specified NFS transport.
864 static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
866 nfs_validate_transport_protocol(mnt);
868 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
869 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
871 switch (mnt->nfs_server.protocol) {
872 case XPRT_TRANSPORT_UDP:
873 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
875 case XPRT_TRANSPORT_TCP:
876 case XPRT_TRANSPORT_RDMA:
877 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
882 * Parse the value of the 'sec=' option.
884 * The flavor_len setting is for v4 mounts.
886 static int nfs_parse_security_flavors(char *value,
887 struct nfs_parsed_mount_data *mnt)
889 substring_t args[MAX_OPT_ARGS];
891 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
893 switch (match_token(value, nfs_secflavor_tokens, args)) {
895 mnt->auth_flavor_len = 0;
896 mnt->auth_flavors[0] = RPC_AUTH_NULL;
899 mnt->auth_flavor_len = 0;
900 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
903 mnt->auth_flavor_len = 1;
904 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
907 mnt->auth_flavor_len = 1;
908 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
911 mnt->auth_flavor_len = 1;
912 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
915 mnt->auth_flavor_len = 1;
916 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
919 mnt->auth_flavor_len = 1;
920 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
923 mnt->auth_flavor_len = 1;
924 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
927 mnt->auth_flavor_len = 1;
928 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
931 mnt->auth_flavor_len = 1;
932 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
935 mnt->auth_flavor_len = 1;
936 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
945 static void nfs_parse_invalid_value(const char *option)
947 dfprintk(MOUNT, "NFS: bad value specified for %s option\n", option);
951 * Error-check and convert a string of mount options from user space into
952 * a data structure. The whole mount string is processed; bad options are
953 * skipped as they are encountered. If there were no errors, return 1;
954 * otherwise return 0 (zero).
956 static int nfs_parse_mount_options(char *raw,
957 struct nfs_parsed_mount_data *mnt)
959 char *p, *string, *secdata;
960 int rc, sloppy = 0, errors = 0;
963 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
966 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
968 secdata = alloc_secdata();
972 rc = security_sb_copy_data(raw, secdata);
974 goto out_security_failure;
976 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
978 goto out_security_failure;
980 free_secdata(secdata);
982 while ((p = strsep(&raw, ",")) != NULL) {
983 substring_t args[MAX_OPT_ARGS];
989 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
991 token = match_token(p, nfs_mount_option_tokens, args);
995 * boolean options: foo/nofoo
998 mnt->flags |= NFS_MOUNT_SOFT;
1001 mnt->flags &= ~NFS_MOUNT_SOFT;
1004 mnt->flags |= NFS_MOUNT_POSIX;
1007 mnt->flags &= ~NFS_MOUNT_POSIX;
1010 mnt->flags &= ~NFS_MOUNT_NOCTO;
1013 mnt->flags |= NFS_MOUNT_NOCTO;
1016 mnt->flags &= ~NFS_MOUNT_NOAC;
1019 mnt->flags |= NFS_MOUNT_NOAC;
1022 mnt->flags &= ~NFS_MOUNT_NONLM;
1025 mnt->flags |= NFS_MOUNT_NONLM;
1028 mnt->flags &= ~NFS_MOUNT_VER3;
1031 mnt->flags |= NFS_MOUNT_VER3;
1034 mnt->flags &= ~NFS_MOUNT_TCP;
1035 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1038 mnt->flags |= NFS_MOUNT_TCP;
1039 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1042 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1043 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1044 xprt_load_transport(p);
1047 mnt->flags &= ~NFS_MOUNT_NOACL;
1050 mnt->flags |= NFS_MOUNT_NOACL;
1053 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1055 case Opt_nordirplus:
1056 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1058 case Opt_sharecache:
1059 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1061 case Opt_nosharecache:
1062 mnt->flags |= NFS_MOUNT_UNSHARED;
1065 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1067 case Opt_noresvport:
1068 mnt->flags |= NFS_MOUNT_NORESVPORT;
1071 mnt->options |= NFS_OPTION_FSCACHE;
1072 kfree(mnt->fscache_uniq);
1073 mnt->fscache_uniq = NULL;
1076 mnt->options &= ~NFS_OPTION_FSCACHE;
1077 kfree(mnt->fscache_uniq);
1078 mnt->fscache_uniq = NULL;
1080 case Opt_fscache_uniq:
1081 string = match_strdup(args);
1084 kfree(mnt->fscache_uniq);
1085 mnt->fscache_uniq = string;
1086 mnt->options |= NFS_OPTION_FSCACHE;
1090 * options that take numeric values
1093 if (match_int(args, &option) ||
1094 option < 0 || option > USHORT_MAX) {
1096 nfs_parse_invalid_value("port");
1098 mnt->nfs_server.port = option;
1101 if (match_int(args, &option) || option < 0) {
1103 nfs_parse_invalid_value("rsize");
1105 mnt->rsize = option;
1108 if (match_int(args, &option) || option < 0) {
1110 nfs_parse_invalid_value("wsize");
1112 mnt->wsize = option;
1115 if (match_int(args, &option) || option < 0) {
1117 nfs_parse_invalid_value("bsize");
1119 mnt->bsize = option;
1122 if (match_int(args, &option) || option <= 0) {
1124 nfs_parse_invalid_value("timeo");
1126 mnt->timeo = option;
1129 if (match_int(args, &option) || option <= 0) {
1131 nfs_parse_invalid_value("retrans");
1133 mnt->retrans = option;
1136 if (match_int(args, &option) || option < 0) {
1138 nfs_parse_invalid_value("acregmin");
1140 mnt->acregmin = option;
1143 if (match_int(args, &option) || option < 0) {
1145 nfs_parse_invalid_value("acregmax");
1147 mnt->acregmax = option;
1150 if (match_int(args, &option) || option < 0) {
1152 nfs_parse_invalid_value("acdirmin");
1154 mnt->acdirmin = option;
1157 if (match_int(args, &option) || option < 0) {
1159 nfs_parse_invalid_value("acdirmax");
1161 mnt->acdirmax = option;
1164 if (match_int(args, &option) || option < 0) {
1166 nfs_parse_invalid_value("actimeo");
1168 mnt->acregmin = mnt->acregmax =
1169 mnt->acdirmin = mnt->acdirmax = option;
1172 if (match_int(args, &option) || option < 0) {
1174 nfs_parse_invalid_value("namlen");
1176 mnt->namlen = option;
1179 if (match_int(args, &option) ||
1180 option < 0 || option > USHORT_MAX) {
1182 nfs_parse_invalid_value("mountport");
1184 mnt->mount_server.port = option;
1187 if (match_int(args, &option) ||
1188 option < NFS_MNT_VERSION ||
1189 option > NFS_MNT3_VERSION) {
1191 nfs_parse_invalid_value("mountvers");
1193 mnt->mount_server.version = option;
1196 if (match_int(args, &option)) {
1198 nfs_parse_invalid_value("nfsvers");
1203 mnt->flags &= ~NFS_MOUNT_VER3;
1206 mnt->flags |= NFS_MOUNT_VER3;
1210 nfs_parse_invalid_value("nfsvers");
1215 * options that take text values
1218 string = match_strdup(args);
1221 rc = nfs_parse_security_flavors(string, mnt);
1225 dfprintk(MOUNT, "NFS: unrecognized "
1226 "security flavor\n");
1230 string = match_strdup(args);
1233 token = match_token(string,
1234 nfs_xprt_protocol_tokens, args);
1238 mnt->flags &= ~NFS_MOUNT_TCP;
1239 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1242 mnt->flags |= NFS_MOUNT_TCP;
1243 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1246 /* vector side protocols to TCP */
1247 mnt->flags |= NFS_MOUNT_TCP;
1248 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1249 xprt_load_transport(string);
1253 dfprintk(MOUNT, "NFS: unrecognized "
1254 "transport protocol\n");
1258 case Opt_mountproto:
1259 string = match_strdup(args);
1262 token = match_token(string,
1263 nfs_xprt_protocol_tokens, args);
1268 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
1271 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
1273 case Opt_xprt_rdma: /* not used for side protocols */
1276 dfprintk(MOUNT, "NFS: unrecognized "
1277 "transport protocol\n");
1281 string = match_strdup(args);
1284 nfs_parse_ip_address(string, strlen(string),
1286 &mnt->nfs_server.address,
1287 &mnt->nfs_server.addrlen);
1290 case Opt_clientaddr:
1291 string = match_strdup(args);
1294 kfree(mnt->client_address);
1295 mnt->client_address = string;
1298 string = match_strdup(args);
1301 kfree(mnt->mount_server.hostname);
1302 mnt->mount_server.hostname = string;
1305 string = match_strdup(args);
1308 nfs_parse_ip_address(string, strlen(string),
1310 &mnt->mount_server.address,
1311 &mnt->mount_server.addrlen);
1314 case Opt_lookupcache:
1315 string = match_strdup(args);
1318 token = match_token(string,
1319 nfs_lookupcache_tokens, args);
1322 case Opt_lookupcache_all:
1323 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1325 case Opt_lookupcache_positive:
1326 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1327 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1329 case Opt_lookupcache_none:
1330 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1334 dfprintk(MOUNT, "NFS: invalid "
1335 "lookupcache argument\n");
1344 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1347 case Opt_deprecated:
1348 dfprintk(MOUNT, "NFS: ignoring mount option "
1354 dfprintk(MOUNT, "NFS: unrecognized mount option "
1360 dfprintk(MOUNT, "NFS: parsing encountered %d error%s\n",
1361 errors, (errors == 1 ? "" : "s"));
1368 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1370 out_security_failure:
1371 free_secdata(secdata);
1372 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1377 * Use the remote server's MOUNT service to request the NFS file handle
1378 * corresponding to the provided path.
1380 static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1381 struct nfs_fh *root_fh)
1383 unsigned int auth_flavor_len = 0;
1384 struct nfs_mount_request request = {
1385 .sap = (struct sockaddr *)
1386 &args->mount_server.address,
1387 .dirpath = args->nfs_server.export_path,
1388 .protocol = args->mount_server.protocol,
1390 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
1391 .auth_flav_len = &auth_flavor_len,
1395 if (args->mount_server.version == 0) {
1396 if (args->flags & NFS_MOUNT_VER3)
1397 args->mount_server.version = NFS_MNT3_VERSION;
1399 args->mount_server.version = NFS_MNT_VERSION;
1401 request.version = args->mount_server.version;
1403 if (args->mount_server.hostname)
1404 request.hostname = args->mount_server.hostname;
1406 request.hostname = args->nfs_server.hostname;
1409 * Construct the mount server's address.
1411 if (args->mount_server.address.ss_family == AF_UNSPEC) {
1412 memcpy(request.sap, &args->nfs_server.address,
1413 args->nfs_server.addrlen);
1414 args->mount_server.addrlen = args->nfs_server.addrlen;
1416 request.salen = args->mount_server.addrlen;
1419 * autobind will be used if mount_server.port == 0
1421 nfs_set_port(request.sap, args->mount_server.port);
1424 * Now ask the mount server to map our export path
1427 status = nfs_mount(&request);
1431 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1432 request.hostname, status);
1436 static int nfs_parse_simple_hostname(const char *dev_name,
1437 char **hostname, size_t maxnamlen,
1438 char **export_path, size_t maxpathlen)
1441 char *colon, *comma;
1443 colon = strchr(dev_name, ':');
1445 goto out_bad_devname;
1447 len = colon - dev_name;
1448 if (len > maxnamlen)
1451 /* N.B. caller will free nfs_server.hostname in all cases */
1452 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
1456 /* kill possible hostname list: not supported */
1457 comma = strchr(*hostname, ',');
1458 if (comma != NULL) {
1459 if (comma == *hostname)
1460 goto out_bad_devname;
1465 len = strlen(colon);
1466 if (len > maxpathlen)
1468 *export_path = kstrndup(colon, len, GFP_KERNEL);
1472 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1476 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1480 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1484 dfprintk(MOUNT, "NFS: server hostname too long\n");
1485 return -ENAMETOOLONG;
1488 dfprintk(MOUNT, "NFS: export pathname too long\n");
1489 return -ENAMETOOLONG;
1493 * Hostname has square brackets around it because it contains one or
1494 * more colons. We look for the first closing square bracket, and a
1495 * colon must follow it.
1497 static int nfs_parse_protected_hostname(const char *dev_name,
1498 char **hostname, size_t maxnamlen,
1499 char **export_path, size_t maxpathlen)
1504 start = (char *)(dev_name + 1);
1506 end = strchr(start, ']');
1508 goto out_bad_devname;
1509 if (*(end + 1) != ':')
1510 goto out_bad_devname;
1513 if (len > maxnamlen)
1516 /* N.B. caller will free nfs_server.hostname in all cases */
1517 *hostname = kstrndup(start, len, GFP_KERNEL);
1518 if (*hostname == NULL)
1523 if (len > maxpathlen)
1525 *export_path = kstrndup(end, len, GFP_KERNEL);
1532 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1536 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1540 dfprintk(MOUNT, "NFS: server hostname too long\n");
1541 return -ENAMETOOLONG;
1544 dfprintk(MOUNT, "NFS: export pathname too long\n");
1545 return -ENAMETOOLONG;
1549 * Split "dev_name" into "hostname:export_path".
1551 * The leftmost colon demarks the split between the server's hostname
1552 * and the export path. If the hostname starts with a left square
1553 * bracket, then it may contain colons.
1555 * Note: caller frees hostname and export path, even on error.
1557 static int nfs_parse_devname(const char *dev_name,
1558 char **hostname, size_t maxnamlen,
1559 char **export_path, size_t maxpathlen)
1561 if (*dev_name == '[')
1562 return nfs_parse_protected_hostname(dev_name,
1563 hostname, maxnamlen,
1564 export_path, maxpathlen);
1566 return nfs_parse_simple_hostname(dev_name,
1567 hostname, maxnamlen,
1568 export_path, maxpathlen);
1572 * Validate the NFS2/NFS3 mount data
1573 * - fills in the mount root filehandle
1575 * For option strings, user space handles the following behaviors:
1577 * + DNS: mapping server host name to IP address ("addr=" option)
1579 * + failure mode: how to behave if a mount request can't be handled
1580 * immediately ("fg/bg" option)
1582 * + retry: how often to retry a mount request ("retry=" option)
1584 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1585 * mountproto=tcp after mountproto=udp, and so on
1587 static int nfs_validate_mount_data(void *options,
1588 struct nfs_parsed_mount_data *args,
1589 struct nfs_fh *mntfh,
1590 const char *dev_name)
1592 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
1597 args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
1598 args->rsize = NFS_MAX_FILE_IO_SIZE;
1599 args->wsize = NFS_MAX_FILE_IO_SIZE;
1600 args->acregmin = NFS_DEF_ACREGMIN;
1601 args->acregmax = NFS_DEF_ACREGMAX;
1602 args->acdirmin = NFS_DEF_ACDIRMIN;
1603 args->acdirmax = NFS_DEF_ACDIRMAX;
1604 args->mount_server.port = 0; /* autobind unless user sets port */
1605 args->nfs_server.port = 0; /* autobind unless user sets port */
1606 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1607 args->auth_flavors[0] = RPC_AUTH_UNIX;
1609 switch (data->version) {
1615 if (data->flags & NFS_MOUNT_VER3)
1617 data->root.size = NFS2_FHSIZE;
1618 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1620 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1623 memset(data->context, 0, sizeof(data->context));
1625 if (data->flags & NFS_MOUNT_VER3) {
1626 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1627 goto out_invalid_fh;
1628 mntfh->size = data->root.size;
1630 mntfh->size = NFS2_FHSIZE;
1633 memcpy(mntfh->data, data->root.data, mntfh->size);
1634 if (mntfh->size < sizeof(mntfh->data))
1635 memset(mntfh->data + mntfh->size, 0,
1636 sizeof(mntfh->data) - mntfh->size);
1639 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1642 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
1643 args->rsize = data->rsize;
1644 args->wsize = data->wsize;
1645 args->timeo = data->timeo;
1646 args->retrans = data->retrans;
1647 args->acregmin = data->acregmin;
1648 args->acregmax = data->acregmax;
1649 args->acdirmin = data->acdirmin;
1650 args->acdirmax = data->acdirmax;
1652 memcpy(&args->nfs_server.address, &data->addr,
1653 sizeof(data->addr));
1654 args->nfs_server.addrlen = sizeof(data->addr);
1655 if (!nfs_verify_server_address((struct sockaddr *)
1656 &args->nfs_server.address))
1657 goto out_no_address;
1659 if (!(data->flags & NFS_MOUNT_TCP))
1660 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1661 /* N.B. caller will free nfs_server.hostname in all cases */
1662 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1663 args->namlen = data->namlen;
1664 args->bsize = data->bsize;
1666 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1667 args->auth_flavors[0] = data->pseudoflavor;
1668 if (!args->nfs_server.hostname)
1672 * The legacy version 6 binary mount data from userspace has a
1673 * field used only to transport selinux information into the
1674 * the kernel. To continue to support that functionality we
1675 * have a touch of selinux knowledge here in the NFS code. The
1676 * userspace code converted context=blah to just blah so we are
1677 * converting back to the full string selinux understands.
1679 if (data->context[0]){
1680 #ifdef CONFIG_SECURITY_SELINUX
1682 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1685 strcpy(opts_str, "context=");
1686 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1687 strcat(opts_str, &data->context[0]);
1688 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1701 if (nfs_parse_mount_options((char *)options, args) == 0)
1704 if (!nfs_verify_server_address((struct sockaddr *)
1705 &args->nfs_server.address))
1706 goto out_no_address;
1708 nfs_set_port((struct sockaddr *)&args->nfs_server.address,
1709 args->nfs_server.port);
1711 nfs_set_mount_transport_protocol(args);
1713 status = nfs_parse_devname(dev_name,
1714 &args->nfs_server.hostname,
1716 &args->nfs_server.export_path,
1719 status = nfs_try_mount(args, mntfh);
1721 kfree(args->nfs_server.export_path);
1722 args->nfs_server.export_path = NULL;
1731 #ifndef CONFIG_NFS_V3
1732 if (args->flags & NFS_MOUNT_VER3)
1733 goto out_v3_not_compiled;
1734 #endif /* !CONFIG_NFS_V3 */
1739 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1743 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1748 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1751 #ifndef CONFIG_NFS_V3
1752 out_v3_not_compiled:
1753 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1754 return -EPROTONOSUPPORT;
1755 #endif /* !CONFIG_NFS_V3 */
1758 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
1762 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1766 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1771 nfs_compare_remount_data(struct nfs_server *nfss,
1772 struct nfs_parsed_mount_data *data)
1774 if (data->flags != nfss->flags ||
1775 data->rsize != nfss->rsize ||
1776 data->wsize != nfss->wsize ||
1777 data->retrans != nfss->client->cl_timeout->to_retries ||
1778 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
1779 data->acregmin != nfss->acregmin / HZ ||
1780 data->acregmax != nfss->acregmax / HZ ||
1781 data->acdirmin != nfss->acdirmin / HZ ||
1782 data->acdirmax != nfss->acdirmax / HZ ||
1783 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
1784 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
1785 memcmp(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1786 data->nfs_server.addrlen) != 0)
1793 nfs_remount(struct super_block *sb, int *flags, char *raw_data)
1796 struct nfs_server *nfss = sb->s_fs_info;
1797 struct nfs_parsed_mount_data *data;
1798 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
1799 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
1800 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
1803 * Userspace mount programs that send binary options generally send
1804 * them populated with default values. We have no way to know which
1805 * ones were explicitly specified. Fall back to legacy behavior and
1806 * just return success.
1808 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
1809 (nfsvers <= 3 && (!options || (options->version >= 1 &&
1810 options->version <= 6))))
1813 data = kzalloc(sizeof(*data), GFP_KERNEL);
1818 /* fill out struct with values from existing mount */
1819 data->flags = nfss->flags;
1820 data->rsize = nfss->rsize;
1821 data->wsize = nfss->wsize;
1822 data->retrans = nfss->client->cl_timeout->to_retries;
1823 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
1824 data->acregmin = nfss->acregmin / HZ;
1825 data->acregmax = nfss->acregmax / HZ;
1826 data->acdirmin = nfss->acdirmin / HZ;
1827 data->acdirmax = nfss->acdirmax / HZ;
1828 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
1829 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
1830 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1831 data->nfs_server.addrlen);
1833 /* overwrite those values with any that were specified */
1834 error = nfs_parse_mount_options((char *)options, data);
1838 /* compare new mount options with old ones */
1839 error = nfs_compare_remount_data(nfss, data);
1847 * Initialise the common bits of the superblock
1849 static inline void nfs_initialise_sb(struct super_block *sb)
1851 struct nfs_server *server = NFS_SB(sb);
1853 sb->s_magic = NFS_SUPER_MAGIC;
1855 /* We probably want something more informative here */
1856 snprintf(sb->s_id, sizeof(sb->s_id),
1857 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1859 if (sb->s_blocksize == 0)
1860 sb->s_blocksize = nfs_block_bits(server->wsize,
1861 &sb->s_blocksize_bits);
1863 if (server->flags & NFS_MOUNT_NOAC)
1864 sb->s_flags |= MS_SYNCHRONOUS;
1866 nfs_super_set_maxbytes(sb, server->maxfilesize);
1870 * Finish setting up an NFS2/3 superblock
1872 static void nfs_fill_super(struct super_block *sb,
1873 struct nfs_parsed_mount_data *data)
1875 struct nfs_server *server = NFS_SB(sb);
1877 sb->s_blocksize_bits = 0;
1878 sb->s_blocksize = 0;
1880 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1882 if (server->flags & NFS_MOUNT_VER3) {
1883 /* The VFS shouldn't apply the umask to mode bits. We will do
1884 * so ourselves when necessary.
1886 sb->s_flags |= MS_POSIXACL;
1887 sb->s_time_gran = 1;
1890 sb->s_op = &nfs_sops;
1891 nfs_initialise_sb(sb);
1895 * Finish setting up a cloned NFS2/3 superblock
1897 static void nfs_clone_super(struct super_block *sb,
1898 const struct super_block *old_sb)
1900 struct nfs_server *server = NFS_SB(sb);
1902 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1903 sb->s_blocksize = old_sb->s_blocksize;
1904 sb->s_maxbytes = old_sb->s_maxbytes;
1906 if (server->flags & NFS_MOUNT_VER3) {
1907 /* The VFS shouldn't apply the umask to mode bits. We will do
1908 * so ourselves when necessary.
1910 sb->s_flags |= MS_POSIXACL;
1911 sb->s_time_gran = 1;
1914 sb->s_op = old_sb->s_op;
1915 nfs_initialise_sb(sb);
1918 static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
1920 const struct nfs_server *a = s->s_fs_info;
1921 const struct rpc_clnt *clnt_a = a->client;
1922 const struct rpc_clnt *clnt_b = b->client;
1924 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
1926 if (a->nfs_client != b->nfs_client)
1928 if (a->flags != b->flags)
1930 if (a->wsize != b->wsize)
1932 if (a->rsize != b->rsize)
1934 if (a->acregmin != b->acregmin)
1936 if (a->acregmax != b->acregmax)
1938 if (a->acdirmin != b->acdirmin)
1940 if (a->acdirmax != b->acdirmax)
1942 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
1949 struct nfs_sb_mountdata {
1950 struct nfs_server *server;
1954 static int nfs_set_super(struct super_block *s, void *data)
1956 struct nfs_sb_mountdata *sb_mntdata = data;
1957 struct nfs_server *server = sb_mntdata->server;
1960 s->s_flags = sb_mntdata->mntflags;
1961 s->s_fs_info = server;
1962 ret = set_anon_super(s, server);
1964 server->s_dev = s->s_dev;
1968 static int nfs_compare_super_address(struct nfs_server *server1,
1969 struct nfs_server *server2)
1971 struct sockaddr *sap1, *sap2;
1973 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
1974 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
1976 if (sap1->sa_family != sap2->sa_family)
1979 switch (sap1->sa_family) {
1981 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
1982 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
1983 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
1985 if (sin1->sin_port != sin2->sin_port)
1990 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
1991 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
1992 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
1994 if (sin1->sin6_port != sin2->sin6_port)
2005 static int nfs_compare_super(struct super_block *sb, void *data)
2007 struct nfs_sb_mountdata *sb_mntdata = data;
2008 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2009 int mntflags = sb_mntdata->mntflags;
2011 if (!nfs_compare_super_address(old, server))
2013 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2014 if (old->flags & NFS_MOUNT_UNSHARED)
2016 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2018 return nfs_compare_mount_options(sb, server, mntflags);
2021 static int nfs_bdi_register(struct nfs_server *server)
2023 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
2026 static int nfs_get_sb(struct file_system_type *fs_type,
2027 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2029 struct nfs_server *server = NULL;
2030 struct super_block *s;
2031 struct nfs_parsed_mount_data *data;
2032 struct nfs_fh *mntfh;
2033 struct dentry *mntroot;
2034 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2035 struct nfs_sb_mountdata sb_mntdata = {
2038 int error = -ENOMEM;
2040 data = kzalloc(sizeof(*data), GFP_KERNEL);
2041 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
2042 if (data == NULL || mntfh == NULL)
2045 security_init_mnt_opts(&data->lsm_opts);
2047 /* Validate the mount data */
2048 error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
2052 /* Get a volume representation */
2053 server = nfs_create_server(data, mntfh);
2054 if (IS_ERR(server)) {
2055 error = PTR_ERR(server);
2058 sb_mntdata.server = server;
2060 if (server->flags & NFS_MOUNT_UNSHARED)
2061 compare_super = NULL;
2063 /* Get a superblock - note that we may end up sharing one that already exists */
2064 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
2070 if (s->s_fs_info != server) {
2071 nfs_free_server(server);
2074 error = nfs_bdi_register(server);
2076 goto error_splat_super;
2080 /* initial superblock/root creation */
2081 nfs_fill_super(s, data);
2082 nfs_fscache_get_super_cookie(s, data);
2085 mntroot = nfs_get_root(s, mntfh);
2086 if (IS_ERR(mntroot)) {
2087 error = PTR_ERR(mntroot);
2088 goto error_splat_super;
2091 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
2093 goto error_splat_root;
2095 s->s_flags |= MS_ACTIVE;
2097 mnt->mnt_root = mntroot;
2101 kfree(data->nfs_server.hostname);
2102 kfree(data->mount_server.hostname);
2103 kfree(data->fscache_uniq);
2104 security_free_mnt_opts(&data->lsm_opts);
2111 nfs_free_server(server);
2117 deactivate_locked_super(s);
2122 * Destroy an NFS2/3 superblock
2124 static void nfs_kill_super(struct super_block *s)
2126 struct nfs_server *server = NFS_SB(s);
2128 bdi_unregister(&server->backing_dev_info);
2130 nfs_fscache_release_super_cookie(s);
2131 nfs_free_server(server);
2135 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2137 static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
2138 const char *dev_name, void *raw_data,
2139 struct vfsmount *mnt)
2141 struct nfs_clone_mount *data = raw_data;
2142 struct super_block *s;
2143 struct nfs_server *server;
2144 struct dentry *mntroot;
2145 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2146 struct nfs_sb_mountdata sb_mntdata = {
2151 dprintk("--> nfs_xdev_get_sb()\n");
2153 /* create a new volume representation */
2154 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2155 if (IS_ERR(server)) {
2156 error = PTR_ERR(server);
2157 goto out_err_noserver;
2159 sb_mntdata.server = server;
2161 if (server->flags & NFS_MOUNT_UNSHARED)
2162 compare_super = NULL;
2164 /* Get a superblock - note that we may end up sharing one that already exists */
2165 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2171 if (s->s_fs_info != server) {
2172 nfs_free_server(server);
2175 error = nfs_bdi_register(server);
2177 goto error_splat_super;
2181 /* initial superblock/root creation */
2182 nfs_clone_super(s, data->sb);
2185 mntroot = nfs_get_root(s, data->fh);
2186 if (IS_ERR(mntroot)) {
2187 error = PTR_ERR(mntroot);
2188 goto error_splat_super;
2190 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2193 goto error_splat_super;
2196 s->s_flags |= MS_ACTIVE;
2198 mnt->mnt_root = mntroot;
2200 /* clone any lsm security options from the parent to the new sb */
2201 security_sb_clone_mnt_opts(data->sb, s);
2203 dprintk("<-- nfs_xdev_get_sb() = 0\n");
2207 nfs_free_server(server);
2209 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
2213 deactivate_locked_super(s);
2214 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
2218 #ifdef CONFIG_NFS_V4
2221 * Finish setting up a cloned NFS4 superblock
2223 static void nfs4_clone_super(struct super_block *sb,
2224 const struct super_block *old_sb)
2226 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2227 sb->s_blocksize = old_sb->s_blocksize;
2228 sb->s_maxbytes = old_sb->s_maxbytes;
2229 sb->s_time_gran = 1;
2230 sb->s_op = old_sb->s_op;
2231 nfs_initialise_sb(sb);
2235 * Set up an NFS4 superblock
2237 static void nfs4_fill_super(struct super_block *sb)
2239 sb->s_time_gran = 1;
2240 sb->s_op = &nfs4_sops;
2241 nfs_initialise_sb(sb);
2244 static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2246 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3);
2250 * Validate NFSv4 mount options
2252 static int nfs4_validate_mount_data(void *options,
2253 struct nfs_parsed_mount_data *args,
2254 const char *dev_name)
2256 struct sockaddr_in *ap;
2257 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
2263 args->rsize = NFS_MAX_FILE_IO_SIZE;
2264 args->wsize = NFS_MAX_FILE_IO_SIZE;
2265 args->acregmin = NFS_DEF_ACREGMIN;
2266 args->acregmax = NFS_DEF_ACREGMAX;
2267 args->acdirmin = NFS_DEF_ACDIRMIN;
2268 args->acdirmax = NFS_DEF_ACDIRMAX;
2269 args->nfs_server.port = NFS_PORT; /* 2049 unless user set port= */
2270 args->auth_flavors[0] = RPC_AUTH_UNIX;
2271 args->auth_flavor_len = 0;
2273 switch (data->version) {
2275 ap = (struct sockaddr_in *)&args->nfs_server.address;
2276 if (data->host_addrlen > sizeof(args->nfs_server.address))
2277 goto out_no_address;
2278 if (data->host_addrlen == 0)
2279 goto out_no_address;
2280 args->nfs_server.addrlen = data->host_addrlen;
2281 if (copy_from_user(ap, data->host_addr, data->host_addrlen))
2283 if (!nfs_verify_server_address((struct sockaddr *)
2284 &args->nfs_server.address))
2285 goto out_no_address;
2287 if (data->auth_flavourlen) {
2288 if (data->auth_flavourlen > 1)
2289 goto out_inval_auth;
2290 if (copy_from_user(&args->auth_flavors[0],
2291 data->auth_flavours,
2292 sizeof(args->auth_flavors[0])))
2296 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2299 args->nfs_server.hostname = c;
2301 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2304 args->nfs_server.export_path = c;
2305 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
2307 c = strndup_user(data->client_addr.data, 16);
2310 args->client_address = c;
2313 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2317 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2318 args->rsize = data->rsize;
2319 args->wsize = data->wsize;
2320 args->timeo = data->timeo;
2321 args->retrans = data->retrans;
2322 args->acregmin = data->acregmin;
2323 args->acregmax = data->acregmax;
2324 args->acdirmin = data->acdirmin;
2325 args->acdirmax = data->acdirmax;
2326 args->nfs_server.protocol = data->proto;
2327 nfs_validate_transport_protocol(args);
2333 if (nfs_parse_mount_options((char *)options, args) == 0)
2336 if (!nfs_verify_server_address((struct sockaddr *)
2337 &args->nfs_server.address))
2340 nfs_set_port((struct sockaddr *)&args->nfs_server.address,
2341 args->nfs_server.port);
2343 nfs_validate_transport_protocol(args);
2345 nfs4_validate_mount_flags(args);
2347 if (args->auth_flavor_len > 1)
2348 goto out_inval_auth;
2350 if (args->client_address == NULL)
2351 goto out_no_client_address;
2353 status = nfs_parse_devname(dev_name,
2354 &args->nfs_server.hostname,
2356 &args->nfs_server.export_path,
2368 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2372 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2373 data->auth_flavourlen);
2377 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2380 out_no_client_address:
2381 dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
2386 * Get the superblock for an NFS4 mountpoint
2388 static int nfs4_get_sb(struct file_system_type *fs_type,
2389 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2391 struct nfs_parsed_mount_data *data;
2392 struct super_block *s;
2393 struct nfs_server *server;
2394 struct nfs_fh *mntfh;
2395 struct dentry *mntroot;
2396 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2397 struct nfs_sb_mountdata sb_mntdata = {
2400 int error = -ENOMEM;
2402 data = kzalloc(sizeof(*data), GFP_KERNEL);
2403 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
2404 if (data == NULL || mntfh == NULL)
2407 security_init_mnt_opts(&data->lsm_opts);
2409 /* Validate the mount data */
2410 error = nfs4_validate_mount_data(raw_data, data, dev_name);
2414 /* Get a volume representation */
2415 server = nfs4_create_server(data, mntfh);
2416 if (IS_ERR(server)) {
2417 error = PTR_ERR(server);
2420 sb_mntdata.server = server;
2422 if (server->flags & NFS4_MOUNT_UNSHARED)
2423 compare_super = NULL;
2425 /* Get a superblock - note that we may end up sharing one that already exists */
2426 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
2432 if (s->s_fs_info != server) {
2433 nfs_free_server(server);
2436 error = nfs_bdi_register(server);
2438 goto error_splat_super;
2442 /* initial superblock/root creation */
2444 nfs_fscache_get_super_cookie(s, data);
2447 mntroot = nfs4_get_root(s, mntfh);
2448 if (IS_ERR(mntroot)) {
2449 error = PTR_ERR(mntroot);
2450 goto error_splat_super;
2453 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
2455 goto error_splat_root;
2457 s->s_flags |= MS_ACTIVE;
2459 mnt->mnt_root = mntroot;
2463 kfree(data->client_address);
2464 kfree(data->nfs_server.export_path);
2465 kfree(data->nfs_server.hostname);
2466 kfree(data->fscache_uniq);
2467 security_free_mnt_opts(&data->lsm_opts);
2474 nfs_free_server(server);
2480 deactivate_locked_super(s);
2484 static void nfs4_kill_super(struct super_block *sb)
2486 struct nfs_server *server = NFS_SB(sb);
2488 nfs_super_return_all_delegations(sb);
2489 kill_anon_super(sb);
2491 nfs4_renewd_prepare_shutdown(server);
2492 nfs_fscache_release_super_cookie(sb);
2493 nfs_free_server(server);
2497 * Clone an NFS4 server record on xdev traversal (FSID-change)
2499 static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
2500 const char *dev_name, void *raw_data,
2501 struct vfsmount *mnt)
2503 struct nfs_clone_mount *data = raw_data;
2504 struct super_block *s;
2505 struct nfs_server *server;
2506 struct dentry *mntroot;
2507 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2508 struct nfs_sb_mountdata sb_mntdata = {
2513 dprintk("--> nfs4_xdev_get_sb()\n");
2515 /* create a new volume representation */
2516 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2517 if (IS_ERR(server)) {
2518 error = PTR_ERR(server);
2519 goto out_err_noserver;
2521 sb_mntdata.server = server;
2523 if (server->flags & NFS4_MOUNT_UNSHARED)
2524 compare_super = NULL;
2526 /* Get a superblock - note that we may end up sharing one that already exists */
2527 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2533 if (s->s_fs_info != server) {
2534 nfs_free_server(server);
2537 error = nfs_bdi_register(server);
2539 goto error_splat_super;
2543 /* initial superblock/root creation */
2544 nfs4_clone_super(s, data->sb);
2547 mntroot = nfs4_get_root(s, data->fh);
2548 if (IS_ERR(mntroot)) {
2549 error = PTR_ERR(mntroot);
2550 goto error_splat_super;
2552 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2555 goto error_splat_super;
2558 s->s_flags |= MS_ACTIVE;
2560 mnt->mnt_root = mntroot;
2562 security_sb_clone_mnt_opts(data->sb, s);
2564 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2568 nfs_free_server(server);
2570 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
2574 deactivate_locked_super(s);
2575 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
2580 * Create an NFS4 server record on referral traversal
2582 static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
2583 const char *dev_name, void *raw_data,
2584 struct vfsmount *mnt)
2586 struct nfs_clone_mount *data = raw_data;
2587 struct super_block *s;
2588 struct nfs_server *server;
2589 struct dentry *mntroot;
2590 struct nfs_fh mntfh;
2591 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2592 struct nfs_sb_mountdata sb_mntdata = {
2597 dprintk("--> nfs4_referral_get_sb()\n");
2599 /* create a new volume representation */
2600 server = nfs4_create_referral_server(data, &mntfh);
2601 if (IS_ERR(server)) {
2602 error = PTR_ERR(server);
2603 goto out_err_noserver;
2605 sb_mntdata.server = server;
2607 if (server->flags & NFS4_MOUNT_UNSHARED)
2608 compare_super = NULL;
2610 /* Get a superblock - note that we may end up sharing one that already exists */
2611 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2617 if (s->s_fs_info != server) {
2618 nfs_free_server(server);
2621 error = nfs_bdi_register(server);
2623 goto error_splat_super;
2627 /* initial superblock/root creation */
2631 mntroot = nfs4_get_root(s, &mntfh);
2632 if (IS_ERR(mntroot)) {
2633 error = PTR_ERR(mntroot);
2634 goto error_splat_super;
2636 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2639 goto error_splat_super;
2642 s->s_flags |= MS_ACTIVE;
2644 mnt->mnt_root = mntroot;
2646 security_sb_clone_mnt_opts(data->sb, s);
2648 dprintk("<-- nfs4_referral_get_sb() = 0\n");
2652 nfs_free_server(server);
2654 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
2658 deactivate_locked_super(s);
2659 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
2663 #endif /* CONFIG_NFS_V4 */