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;
946 * Error-check and convert a string of mount options from user space into
947 * a data structure. The whole mount string is processed; bad options are
948 * skipped as they are encountered. If there were no errors, return 1;
949 * otherwise return 0 (zero).
951 static int nfs_parse_mount_options(char *raw,
952 struct nfs_parsed_mount_data *mnt)
954 char *p, *string, *secdata;
955 int rc, sloppy = 0, invalid_option = 0;
958 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
961 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
963 secdata = alloc_secdata();
967 rc = security_sb_copy_data(raw, secdata);
969 goto out_security_failure;
971 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
973 goto out_security_failure;
975 free_secdata(secdata);
977 while ((p = strsep(&raw, ",")) != NULL) {
978 substring_t args[MAX_OPT_ARGS];
984 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
986 token = match_token(p, nfs_mount_option_tokens, args);
990 * boolean options: foo/nofoo
993 mnt->flags |= NFS_MOUNT_SOFT;
996 mnt->flags &= ~NFS_MOUNT_SOFT;
999 mnt->flags |= NFS_MOUNT_POSIX;
1002 mnt->flags &= ~NFS_MOUNT_POSIX;
1005 mnt->flags &= ~NFS_MOUNT_NOCTO;
1008 mnt->flags |= NFS_MOUNT_NOCTO;
1011 mnt->flags &= ~NFS_MOUNT_NOAC;
1014 mnt->flags |= NFS_MOUNT_NOAC;
1017 mnt->flags &= ~NFS_MOUNT_NONLM;
1020 mnt->flags |= NFS_MOUNT_NONLM;
1023 mnt->flags &= ~NFS_MOUNT_VER3;
1026 mnt->flags |= NFS_MOUNT_VER3;
1029 mnt->flags &= ~NFS_MOUNT_TCP;
1030 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1033 mnt->flags |= NFS_MOUNT_TCP;
1034 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1037 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1038 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1039 xprt_load_transport(p);
1042 mnt->flags &= ~NFS_MOUNT_NOACL;
1045 mnt->flags |= NFS_MOUNT_NOACL;
1048 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1050 case Opt_nordirplus:
1051 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1053 case Opt_sharecache:
1054 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1056 case Opt_nosharecache:
1057 mnt->flags |= NFS_MOUNT_UNSHARED;
1060 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1062 case Opt_noresvport:
1063 mnt->flags |= NFS_MOUNT_NORESVPORT;
1066 mnt->options |= NFS_OPTION_FSCACHE;
1067 kfree(mnt->fscache_uniq);
1068 mnt->fscache_uniq = NULL;
1071 mnt->options &= ~NFS_OPTION_FSCACHE;
1072 kfree(mnt->fscache_uniq);
1073 mnt->fscache_uniq = NULL;
1075 case Opt_fscache_uniq:
1076 string = match_strdup(args);
1079 kfree(mnt->fscache_uniq);
1080 mnt->fscache_uniq = string;
1081 mnt->options |= NFS_OPTION_FSCACHE;
1085 * options that take numeric values
1088 if (match_int(args, &option) ||
1089 option < 0 || option > USHORT_MAX)
1090 goto out_invalid_value;
1091 mnt->nfs_server.port = option;
1094 if (match_int(args, &option) || option < 0)
1095 goto out_invalid_value;
1096 mnt->rsize = option;
1099 if (match_int(args, &option) || option < 0)
1100 goto out_invalid_value;
1101 mnt->wsize = option;
1104 if (match_int(args, &option) || option < 0)
1105 goto out_invalid_value;
1106 mnt->bsize = option;
1109 if (match_int(args, &option) || option <= 0)
1110 goto out_invalid_value;
1111 mnt->timeo = option;
1114 if (match_int(args, &option) || option <= 0)
1115 goto out_invalid_value;
1116 mnt->retrans = option;
1119 if (match_int(args, &option) || option < 0)
1120 goto out_invalid_value;
1121 mnt->acregmin = option;
1124 if (match_int(args, &option) || option < 0)
1125 goto out_invalid_value;
1126 mnt->acregmax = option;
1129 if (match_int(args, &option) || option < 0)
1130 goto out_invalid_value;
1131 mnt->acdirmin = option;
1134 if (match_int(args, &option) || option < 0)
1135 goto out_invalid_value;
1136 mnt->acdirmax = option;
1139 if (match_int(args, &option) || option < 0)
1140 goto out_invalid_value;
1141 mnt->acregmin = mnt->acregmax =
1142 mnt->acdirmin = mnt->acdirmax = option;
1145 if (match_int(args, &option) || option < 0)
1146 goto out_invalid_value;
1147 mnt->namlen = option;
1150 if (match_int(args, &option) ||
1151 option < 0 || option > USHORT_MAX)
1152 goto out_invalid_value;
1153 mnt->mount_server.port = option;
1156 if (match_int(args, &option) ||
1157 option < NFS_MNT_VERSION ||
1158 option > NFS_MNT3_VERSION)
1159 goto out_invalid_value;
1160 mnt->mount_server.version = option;
1163 if (match_int(args, &option))
1164 goto out_invalid_value;
1167 mnt->flags &= ~NFS_MOUNT_VER3;
1170 mnt->flags |= NFS_MOUNT_VER3;
1173 goto out_invalid_value;
1178 * options that take text values
1181 string = match_strdup(args);
1184 rc = nfs_parse_security_flavors(string, mnt);
1187 dfprintk(MOUNT, "NFS: unrecognized "
1188 "security flavor\n");
1193 string = match_strdup(args);
1196 token = match_token(string,
1197 nfs_xprt_protocol_tokens, args);
1201 mnt->flags &= ~NFS_MOUNT_TCP;
1202 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1206 mnt->flags |= NFS_MOUNT_TCP;
1207 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1211 /* vector side protocols to TCP */
1212 mnt->flags |= NFS_MOUNT_TCP;
1213 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1214 xprt_load_transport(string);
1218 dfprintk(MOUNT, "NFS: unrecognized "
1219 "transport protocol\n");
1223 case Opt_mountproto:
1224 string = match_strdup(args);
1227 token = match_token(string,
1228 nfs_xprt_protocol_tokens, args);
1233 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
1236 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
1238 case Opt_xprt_rdma: /* not used for side protocols */
1240 dfprintk(MOUNT, "NFS: unrecognized "
1241 "transport protocol\n");
1246 string = match_strdup(args);
1249 nfs_parse_ip_address(string, strlen(string),
1251 &mnt->nfs_server.address,
1252 &mnt->nfs_server.addrlen);
1255 case Opt_clientaddr:
1256 string = match_strdup(args);
1259 kfree(mnt->client_address);
1260 mnt->client_address = string;
1263 string = match_strdup(args);
1266 kfree(mnt->mount_server.hostname);
1267 mnt->mount_server.hostname = string;
1270 string = match_strdup(args);
1273 nfs_parse_ip_address(string, strlen(string),
1275 &mnt->mount_server.address,
1276 &mnt->mount_server.addrlen);
1279 case Opt_lookupcache:
1280 string = match_strdup(args);
1283 token = match_token(string,
1284 nfs_lookupcache_tokens, args);
1287 case Opt_lookupcache_all:
1288 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1290 case Opt_lookupcache_positive:
1291 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1292 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1294 case Opt_lookupcache_none:
1295 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1298 dfprintk(MOUNT, "NFS: invalid "
1299 "lookupcache argument\n");
1309 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1312 case Opt_deprecated:
1313 dfprintk(MOUNT, "NFS: ignoring mount option "
1319 dfprintk(MOUNT, "NFS: unrecognized mount option "
1324 if (!sloppy && invalid_option)
1330 printk(KERN_INFO "NFS: bad mount option value specified: %s \n", p);
1333 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1335 out_security_failure:
1336 free_secdata(secdata);
1337 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1342 * Use the remote server's MOUNT service to request the NFS file handle
1343 * corresponding to the provided path.
1345 static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1346 struct nfs_fh *root_fh)
1348 unsigned int auth_flavor_len = 0;
1349 struct nfs_mount_request request = {
1350 .sap = (struct sockaddr *)
1351 &args->mount_server.address,
1352 .dirpath = args->nfs_server.export_path,
1353 .protocol = args->mount_server.protocol,
1355 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
1356 .auth_flav_len = &auth_flavor_len,
1360 if (args->mount_server.version == 0) {
1361 if (args->flags & NFS_MOUNT_VER3)
1362 args->mount_server.version = NFS_MNT3_VERSION;
1364 args->mount_server.version = NFS_MNT_VERSION;
1366 request.version = args->mount_server.version;
1368 if (args->mount_server.hostname)
1369 request.hostname = args->mount_server.hostname;
1371 request.hostname = args->nfs_server.hostname;
1374 * Construct the mount server's address.
1376 if (args->mount_server.address.ss_family == AF_UNSPEC) {
1377 memcpy(request.sap, &args->nfs_server.address,
1378 args->nfs_server.addrlen);
1379 args->mount_server.addrlen = args->nfs_server.addrlen;
1381 request.salen = args->mount_server.addrlen;
1384 * autobind will be used if mount_server.port == 0
1386 nfs_set_port(request.sap, args->mount_server.port);
1389 * Now ask the mount server to map our export path
1392 status = nfs_mount(&request);
1396 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1397 request.hostname, status);
1401 static int nfs_parse_simple_hostname(const char *dev_name,
1402 char **hostname, size_t maxnamlen,
1403 char **export_path, size_t maxpathlen)
1406 char *colon, *comma;
1408 colon = strchr(dev_name, ':');
1410 goto out_bad_devname;
1412 len = colon - dev_name;
1413 if (len > maxnamlen)
1416 /* N.B. caller will free nfs_server.hostname in all cases */
1417 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
1421 /* kill possible hostname list: not supported */
1422 comma = strchr(*hostname, ',');
1423 if (comma != NULL) {
1424 if (comma == *hostname)
1425 goto out_bad_devname;
1430 len = strlen(colon);
1431 if (len > maxpathlen)
1433 *export_path = kstrndup(colon, len, GFP_KERNEL);
1437 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1441 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1445 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1449 dfprintk(MOUNT, "NFS: server hostname too long\n");
1450 return -ENAMETOOLONG;
1453 dfprintk(MOUNT, "NFS: export pathname too long\n");
1454 return -ENAMETOOLONG;
1458 * Hostname has square brackets around it because it contains one or
1459 * more colons. We look for the first closing square bracket, and a
1460 * colon must follow it.
1462 static int nfs_parse_protected_hostname(const char *dev_name,
1463 char **hostname, size_t maxnamlen,
1464 char **export_path, size_t maxpathlen)
1469 start = (char *)(dev_name + 1);
1471 end = strchr(start, ']');
1473 goto out_bad_devname;
1474 if (*(end + 1) != ':')
1475 goto out_bad_devname;
1478 if (len > maxnamlen)
1481 /* N.B. caller will free nfs_server.hostname in all cases */
1482 *hostname = kstrndup(start, len, GFP_KERNEL);
1483 if (*hostname == NULL)
1488 if (len > maxpathlen)
1490 *export_path = kstrndup(end, len, GFP_KERNEL);
1497 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1501 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1505 dfprintk(MOUNT, "NFS: server hostname too long\n");
1506 return -ENAMETOOLONG;
1509 dfprintk(MOUNT, "NFS: export pathname too long\n");
1510 return -ENAMETOOLONG;
1514 * Split "dev_name" into "hostname:export_path".
1516 * The leftmost colon demarks the split between the server's hostname
1517 * and the export path. If the hostname starts with a left square
1518 * bracket, then it may contain colons.
1520 * Note: caller frees hostname and export path, even on error.
1522 static int nfs_parse_devname(const char *dev_name,
1523 char **hostname, size_t maxnamlen,
1524 char **export_path, size_t maxpathlen)
1526 if (*dev_name == '[')
1527 return nfs_parse_protected_hostname(dev_name,
1528 hostname, maxnamlen,
1529 export_path, maxpathlen);
1531 return nfs_parse_simple_hostname(dev_name,
1532 hostname, maxnamlen,
1533 export_path, maxpathlen);
1537 * Validate the NFS2/NFS3 mount data
1538 * - fills in the mount root filehandle
1540 * For option strings, user space handles the following behaviors:
1542 * + DNS: mapping server host name to IP address ("addr=" option)
1544 * + failure mode: how to behave if a mount request can't be handled
1545 * immediately ("fg/bg" option)
1547 * + retry: how often to retry a mount request ("retry=" option)
1549 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1550 * mountproto=tcp after mountproto=udp, and so on
1552 static int nfs_validate_mount_data(void *options,
1553 struct nfs_parsed_mount_data *args,
1554 struct nfs_fh *mntfh,
1555 const char *dev_name)
1557 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
1562 args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
1563 args->rsize = NFS_MAX_FILE_IO_SIZE;
1564 args->wsize = NFS_MAX_FILE_IO_SIZE;
1565 args->acregmin = NFS_DEF_ACREGMIN;
1566 args->acregmax = NFS_DEF_ACREGMAX;
1567 args->acdirmin = NFS_DEF_ACDIRMIN;
1568 args->acdirmax = NFS_DEF_ACDIRMAX;
1569 args->mount_server.port = 0; /* autobind unless user sets port */
1570 args->nfs_server.port = 0; /* autobind unless user sets port */
1571 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1572 args->auth_flavors[0] = RPC_AUTH_UNIX;
1574 switch (data->version) {
1580 if (data->flags & NFS_MOUNT_VER3)
1582 data->root.size = NFS2_FHSIZE;
1583 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1585 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1588 memset(data->context, 0, sizeof(data->context));
1590 if (data->flags & NFS_MOUNT_VER3) {
1591 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1592 goto out_invalid_fh;
1593 mntfh->size = data->root.size;
1595 mntfh->size = NFS2_FHSIZE;
1598 memcpy(mntfh->data, data->root.data, mntfh->size);
1599 if (mntfh->size < sizeof(mntfh->data))
1600 memset(mntfh->data + mntfh->size, 0,
1601 sizeof(mntfh->data) - mntfh->size);
1604 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1607 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
1608 args->rsize = data->rsize;
1609 args->wsize = data->wsize;
1610 args->timeo = data->timeo;
1611 args->retrans = data->retrans;
1612 args->acregmin = data->acregmin;
1613 args->acregmax = data->acregmax;
1614 args->acdirmin = data->acdirmin;
1615 args->acdirmax = data->acdirmax;
1617 memcpy(&args->nfs_server.address, &data->addr,
1618 sizeof(data->addr));
1619 args->nfs_server.addrlen = sizeof(data->addr);
1620 if (!nfs_verify_server_address((struct sockaddr *)
1621 &args->nfs_server.address))
1622 goto out_no_address;
1624 if (!(data->flags & NFS_MOUNT_TCP))
1625 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1626 /* N.B. caller will free nfs_server.hostname in all cases */
1627 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1628 args->namlen = data->namlen;
1629 args->bsize = data->bsize;
1631 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1632 args->auth_flavors[0] = data->pseudoflavor;
1633 if (!args->nfs_server.hostname)
1637 * The legacy version 6 binary mount data from userspace has a
1638 * field used only to transport selinux information into the
1639 * the kernel. To continue to support that functionality we
1640 * have a touch of selinux knowledge here in the NFS code. The
1641 * userspace code converted context=blah to just blah so we are
1642 * converting back to the full string selinux understands.
1644 if (data->context[0]){
1645 #ifdef CONFIG_SECURITY_SELINUX
1647 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1650 strcpy(opts_str, "context=");
1651 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1652 strcat(opts_str, &data->context[0]);
1653 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1666 if (nfs_parse_mount_options((char *)options, args) == 0)
1669 if (!nfs_verify_server_address((struct sockaddr *)
1670 &args->nfs_server.address))
1671 goto out_no_address;
1673 nfs_set_port((struct sockaddr *)&args->nfs_server.address,
1674 args->nfs_server.port);
1676 nfs_set_mount_transport_protocol(args);
1678 status = nfs_parse_devname(dev_name,
1679 &args->nfs_server.hostname,
1681 &args->nfs_server.export_path,
1684 status = nfs_try_mount(args, mntfh);
1686 kfree(args->nfs_server.export_path);
1687 args->nfs_server.export_path = NULL;
1696 #ifndef CONFIG_NFS_V3
1697 if (args->flags & NFS_MOUNT_VER3)
1698 goto out_v3_not_compiled;
1699 #endif /* !CONFIG_NFS_V3 */
1704 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1708 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1713 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1716 #ifndef CONFIG_NFS_V3
1717 out_v3_not_compiled:
1718 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1719 return -EPROTONOSUPPORT;
1720 #endif /* !CONFIG_NFS_V3 */
1723 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
1727 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1731 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1736 nfs_compare_remount_data(struct nfs_server *nfss,
1737 struct nfs_parsed_mount_data *data)
1739 if (data->flags != nfss->flags ||
1740 data->rsize != nfss->rsize ||
1741 data->wsize != nfss->wsize ||
1742 data->retrans != nfss->client->cl_timeout->to_retries ||
1743 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
1744 data->acregmin != nfss->acregmin / HZ ||
1745 data->acregmax != nfss->acregmax / HZ ||
1746 data->acdirmin != nfss->acdirmin / HZ ||
1747 data->acdirmax != nfss->acdirmax / HZ ||
1748 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
1749 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
1750 memcmp(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1751 data->nfs_server.addrlen) != 0)
1758 nfs_remount(struct super_block *sb, int *flags, char *raw_data)
1761 struct nfs_server *nfss = sb->s_fs_info;
1762 struct nfs_parsed_mount_data *data;
1763 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
1764 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
1765 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
1768 * Userspace mount programs that send binary options generally send
1769 * them populated with default values. We have no way to know which
1770 * ones were explicitly specified. Fall back to legacy behavior and
1771 * just return success.
1773 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
1774 (nfsvers <= 3 && (!options || (options->version >= 1 &&
1775 options->version <= 6))))
1778 data = kzalloc(sizeof(*data), GFP_KERNEL);
1783 /* fill out struct with values from existing mount */
1784 data->flags = nfss->flags;
1785 data->rsize = nfss->rsize;
1786 data->wsize = nfss->wsize;
1787 data->retrans = nfss->client->cl_timeout->to_retries;
1788 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
1789 data->acregmin = nfss->acregmin / HZ;
1790 data->acregmax = nfss->acregmax / HZ;
1791 data->acdirmin = nfss->acdirmin / HZ;
1792 data->acdirmax = nfss->acdirmax / HZ;
1793 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
1794 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
1795 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1796 data->nfs_server.addrlen);
1798 /* overwrite those values with any that were specified */
1799 error = nfs_parse_mount_options((char *)options, data);
1803 /* compare new mount options with old ones */
1804 error = nfs_compare_remount_data(nfss, data);
1812 * Initialise the common bits of the superblock
1814 static inline void nfs_initialise_sb(struct super_block *sb)
1816 struct nfs_server *server = NFS_SB(sb);
1818 sb->s_magic = NFS_SUPER_MAGIC;
1820 /* We probably want something more informative here */
1821 snprintf(sb->s_id, sizeof(sb->s_id),
1822 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1824 if (sb->s_blocksize == 0)
1825 sb->s_blocksize = nfs_block_bits(server->wsize,
1826 &sb->s_blocksize_bits);
1828 if (server->flags & NFS_MOUNT_NOAC)
1829 sb->s_flags |= MS_SYNCHRONOUS;
1831 nfs_super_set_maxbytes(sb, server->maxfilesize);
1835 * Finish setting up an NFS2/3 superblock
1837 static void nfs_fill_super(struct super_block *sb,
1838 struct nfs_parsed_mount_data *data)
1840 struct nfs_server *server = NFS_SB(sb);
1842 sb->s_blocksize_bits = 0;
1843 sb->s_blocksize = 0;
1845 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1847 if (server->flags & NFS_MOUNT_VER3) {
1848 /* The VFS shouldn't apply the umask to mode bits. We will do
1849 * so ourselves when necessary.
1851 sb->s_flags |= MS_POSIXACL;
1852 sb->s_time_gran = 1;
1855 sb->s_op = &nfs_sops;
1856 nfs_initialise_sb(sb);
1860 * Finish setting up a cloned NFS2/3 superblock
1862 static void nfs_clone_super(struct super_block *sb,
1863 const struct super_block *old_sb)
1865 struct nfs_server *server = NFS_SB(sb);
1867 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1868 sb->s_blocksize = old_sb->s_blocksize;
1869 sb->s_maxbytes = old_sb->s_maxbytes;
1871 if (server->flags & NFS_MOUNT_VER3) {
1872 /* The VFS shouldn't apply the umask to mode bits. We will do
1873 * so ourselves when necessary.
1875 sb->s_flags |= MS_POSIXACL;
1876 sb->s_time_gran = 1;
1879 sb->s_op = old_sb->s_op;
1880 nfs_initialise_sb(sb);
1883 static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
1885 const struct nfs_server *a = s->s_fs_info;
1886 const struct rpc_clnt *clnt_a = a->client;
1887 const struct rpc_clnt *clnt_b = b->client;
1889 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
1891 if (a->nfs_client != b->nfs_client)
1893 if (a->flags != b->flags)
1895 if (a->wsize != b->wsize)
1897 if (a->rsize != b->rsize)
1899 if (a->acregmin != b->acregmin)
1901 if (a->acregmax != b->acregmax)
1903 if (a->acdirmin != b->acdirmin)
1905 if (a->acdirmax != b->acdirmax)
1907 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
1914 struct nfs_sb_mountdata {
1915 struct nfs_server *server;
1919 static int nfs_set_super(struct super_block *s, void *data)
1921 struct nfs_sb_mountdata *sb_mntdata = data;
1922 struct nfs_server *server = sb_mntdata->server;
1925 s->s_flags = sb_mntdata->mntflags;
1926 s->s_fs_info = server;
1927 ret = set_anon_super(s, server);
1929 server->s_dev = s->s_dev;
1933 static int nfs_compare_super_address(struct nfs_server *server1,
1934 struct nfs_server *server2)
1936 struct sockaddr *sap1, *sap2;
1938 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
1939 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
1941 if (sap1->sa_family != sap2->sa_family)
1944 switch (sap1->sa_family) {
1946 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
1947 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
1948 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
1950 if (sin1->sin_port != sin2->sin_port)
1955 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
1956 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
1957 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
1959 if (sin1->sin6_port != sin2->sin6_port)
1970 static int nfs_compare_super(struct super_block *sb, void *data)
1972 struct nfs_sb_mountdata *sb_mntdata = data;
1973 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
1974 int mntflags = sb_mntdata->mntflags;
1976 if (!nfs_compare_super_address(old, server))
1978 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1979 if (old->flags & NFS_MOUNT_UNSHARED)
1981 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
1983 return nfs_compare_mount_options(sb, server, mntflags);
1986 static int nfs_bdi_register(struct nfs_server *server)
1988 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
1991 static int nfs_get_sb(struct file_system_type *fs_type,
1992 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1994 struct nfs_server *server = NULL;
1995 struct super_block *s;
1996 struct nfs_parsed_mount_data *data;
1997 struct nfs_fh *mntfh;
1998 struct dentry *mntroot;
1999 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2000 struct nfs_sb_mountdata sb_mntdata = {
2003 int error = -ENOMEM;
2005 data = kzalloc(sizeof(*data), GFP_KERNEL);
2006 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
2007 if (data == NULL || mntfh == NULL)
2010 security_init_mnt_opts(&data->lsm_opts);
2012 /* Validate the mount data */
2013 error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
2017 /* Get a volume representation */
2018 server = nfs_create_server(data, mntfh);
2019 if (IS_ERR(server)) {
2020 error = PTR_ERR(server);
2023 sb_mntdata.server = server;
2025 if (server->flags & NFS_MOUNT_UNSHARED)
2026 compare_super = NULL;
2028 /* Get a superblock - note that we may end up sharing one that already exists */
2029 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
2035 if (s->s_fs_info != server) {
2036 nfs_free_server(server);
2039 error = nfs_bdi_register(server);
2041 goto error_splat_super;
2045 /* initial superblock/root creation */
2046 nfs_fill_super(s, data);
2047 nfs_fscache_get_super_cookie(s, data);
2050 mntroot = nfs_get_root(s, mntfh);
2051 if (IS_ERR(mntroot)) {
2052 error = PTR_ERR(mntroot);
2053 goto error_splat_super;
2056 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
2058 goto error_splat_root;
2060 s->s_flags |= MS_ACTIVE;
2062 mnt->mnt_root = mntroot;
2066 kfree(data->nfs_server.hostname);
2067 kfree(data->mount_server.hostname);
2068 kfree(data->fscache_uniq);
2069 security_free_mnt_opts(&data->lsm_opts);
2076 nfs_free_server(server);
2082 deactivate_locked_super(s);
2087 * Destroy an NFS2/3 superblock
2089 static void nfs_kill_super(struct super_block *s)
2091 struct nfs_server *server = NFS_SB(s);
2093 bdi_unregister(&server->backing_dev_info);
2095 nfs_fscache_release_super_cookie(s);
2096 nfs_free_server(server);
2100 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2102 static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
2103 const char *dev_name, void *raw_data,
2104 struct vfsmount *mnt)
2106 struct nfs_clone_mount *data = raw_data;
2107 struct super_block *s;
2108 struct nfs_server *server;
2109 struct dentry *mntroot;
2110 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2111 struct nfs_sb_mountdata sb_mntdata = {
2116 dprintk("--> nfs_xdev_get_sb()\n");
2118 /* create a new volume representation */
2119 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2120 if (IS_ERR(server)) {
2121 error = PTR_ERR(server);
2122 goto out_err_noserver;
2124 sb_mntdata.server = server;
2126 if (server->flags & NFS_MOUNT_UNSHARED)
2127 compare_super = NULL;
2129 /* Get a superblock - note that we may end up sharing one that already exists */
2130 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2136 if (s->s_fs_info != server) {
2137 nfs_free_server(server);
2140 error = nfs_bdi_register(server);
2142 goto error_splat_super;
2146 /* initial superblock/root creation */
2147 nfs_clone_super(s, data->sb);
2150 mntroot = nfs_get_root(s, data->fh);
2151 if (IS_ERR(mntroot)) {
2152 error = PTR_ERR(mntroot);
2153 goto error_splat_super;
2155 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2158 goto error_splat_super;
2161 s->s_flags |= MS_ACTIVE;
2163 mnt->mnt_root = mntroot;
2165 /* clone any lsm security options from the parent to the new sb */
2166 security_sb_clone_mnt_opts(data->sb, s);
2168 dprintk("<-- nfs_xdev_get_sb() = 0\n");
2172 nfs_free_server(server);
2174 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
2178 deactivate_locked_super(s);
2179 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
2183 #ifdef CONFIG_NFS_V4
2186 * Finish setting up a cloned NFS4 superblock
2188 static void nfs4_clone_super(struct super_block *sb,
2189 const struct super_block *old_sb)
2191 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2192 sb->s_blocksize = old_sb->s_blocksize;
2193 sb->s_maxbytes = old_sb->s_maxbytes;
2194 sb->s_time_gran = 1;
2195 sb->s_op = old_sb->s_op;
2196 nfs_initialise_sb(sb);
2200 * Set up an NFS4 superblock
2202 static void nfs4_fill_super(struct super_block *sb)
2204 sb->s_time_gran = 1;
2205 sb->s_op = &nfs4_sops;
2206 nfs_initialise_sb(sb);
2209 static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2211 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3);
2215 * Validate NFSv4 mount options
2217 static int nfs4_validate_mount_data(void *options,
2218 struct nfs_parsed_mount_data *args,
2219 const char *dev_name)
2221 struct sockaddr_in *ap;
2222 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
2228 args->rsize = NFS_MAX_FILE_IO_SIZE;
2229 args->wsize = NFS_MAX_FILE_IO_SIZE;
2230 args->acregmin = NFS_DEF_ACREGMIN;
2231 args->acregmax = NFS_DEF_ACREGMAX;
2232 args->acdirmin = NFS_DEF_ACDIRMIN;
2233 args->acdirmax = NFS_DEF_ACDIRMAX;
2234 args->nfs_server.port = NFS_PORT; /* 2049 unless user set port= */
2235 args->auth_flavors[0] = RPC_AUTH_UNIX;
2236 args->auth_flavor_len = 0;
2238 switch (data->version) {
2240 ap = (struct sockaddr_in *)&args->nfs_server.address;
2241 if (data->host_addrlen > sizeof(args->nfs_server.address))
2242 goto out_no_address;
2243 if (data->host_addrlen == 0)
2244 goto out_no_address;
2245 args->nfs_server.addrlen = data->host_addrlen;
2246 if (copy_from_user(ap, data->host_addr, data->host_addrlen))
2248 if (!nfs_verify_server_address((struct sockaddr *)
2249 &args->nfs_server.address))
2250 goto out_no_address;
2252 if (data->auth_flavourlen) {
2253 if (data->auth_flavourlen > 1)
2254 goto out_inval_auth;
2255 if (copy_from_user(&args->auth_flavors[0],
2256 data->auth_flavours,
2257 sizeof(args->auth_flavors[0])))
2261 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2264 args->nfs_server.hostname = c;
2266 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2269 args->nfs_server.export_path = c;
2270 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
2272 c = strndup_user(data->client_addr.data, 16);
2275 args->client_address = c;
2278 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2282 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2283 args->rsize = data->rsize;
2284 args->wsize = data->wsize;
2285 args->timeo = data->timeo;
2286 args->retrans = data->retrans;
2287 args->acregmin = data->acregmin;
2288 args->acregmax = data->acregmax;
2289 args->acdirmin = data->acdirmin;
2290 args->acdirmax = data->acdirmax;
2291 args->nfs_server.protocol = data->proto;
2292 nfs_validate_transport_protocol(args);
2298 if (nfs_parse_mount_options((char *)options, args) == 0)
2301 if (!nfs_verify_server_address((struct sockaddr *)
2302 &args->nfs_server.address))
2305 nfs_set_port((struct sockaddr *)&args->nfs_server.address,
2306 args->nfs_server.port);
2308 nfs_validate_transport_protocol(args);
2310 nfs4_validate_mount_flags(args);
2312 if (args->auth_flavor_len > 1)
2313 goto out_inval_auth;
2315 if (args->client_address == NULL)
2316 goto out_no_client_address;
2318 status = nfs_parse_devname(dev_name,
2319 &args->nfs_server.hostname,
2321 &args->nfs_server.export_path,
2333 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2337 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2338 data->auth_flavourlen);
2342 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2345 out_no_client_address:
2346 dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
2351 * Get the superblock for an NFS4 mountpoint
2353 static int nfs4_get_sb(struct file_system_type *fs_type,
2354 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2356 struct nfs_parsed_mount_data *data;
2357 struct super_block *s;
2358 struct nfs_server *server;
2359 struct nfs_fh *mntfh;
2360 struct dentry *mntroot;
2361 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2362 struct nfs_sb_mountdata sb_mntdata = {
2365 int error = -ENOMEM;
2367 data = kzalloc(sizeof(*data), GFP_KERNEL);
2368 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
2369 if (data == NULL || mntfh == NULL)
2372 security_init_mnt_opts(&data->lsm_opts);
2374 /* Validate the mount data */
2375 error = nfs4_validate_mount_data(raw_data, data, dev_name);
2379 /* Get a volume representation */
2380 server = nfs4_create_server(data, mntfh);
2381 if (IS_ERR(server)) {
2382 error = PTR_ERR(server);
2385 sb_mntdata.server = server;
2387 if (server->flags & NFS4_MOUNT_UNSHARED)
2388 compare_super = NULL;
2390 /* Get a superblock - note that we may end up sharing one that already exists */
2391 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
2397 if (s->s_fs_info != server) {
2398 nfs_free_server(server);
2401 error = nfs_bdi_register(server);
2403 goto error_splat_super;
2407 /* initial superblock/root creation */
2409 nfs_fscache_get_super_cookie(s, data);
2412 mntroot = nfs4_get_root(s, mntfh);
2413 if (IS_ERR(mntroot)) {
2414 error = PTR_ERR(mntroot);
2415 goto error_splat_super;
2418 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
2420 goto error_splat_root;
2422 s->s_flags |= MS_ACTIVE;
2424 mnt->mnt_root = mntroot;
2428 kfree(data->client_address);
2429 kfree(data->nfs_server.export_path);
2430 kfree(data->nfs_server.hostname);
2431 kfree(data->fscache_uniq);
2432 security_free_mnt_opts(&data->lsm_opts);
2439 nfs_free_server(server);
2445 deactivate_locked_super(s);
2449 static void nfs4_kill_super(struct super_block *sb)
2451 struct nfs_server *server = NFS_SB(sb);
2453 nfs_super_return_all_delegations(sb);
2454 kill_anon_super(sb);
2456 nfs4_renewd_prepare_shutdown(server);
2457 nfs_fscache_release_super_cookie(sb);
2458 nfs_free_server(server);
2462 * Clone an NFS4 server record on xdev traversal (FSID-change)
2464 static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
2465 const char *dev_name, void *raw_data,
2466 struct vfsmount *mnt)
2468 struct nfs_clone_mount *data = raw_data;
2469 struct super_block *s;
2470 struct nfs_server *server;
2471 struct dentry *mntroot;
2472 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2473 struct nfs_sb_mountdata sb_mntdata = {
2478 dprintk("--> nfs4_xdev_get_sb()\n");
2480 /* create a new volume representation */
2481 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2482 if (IS_ERR(server)) {
2483 error = PTR_ERR(server);
2484 goto out_err_noserver;
2486 sb_mntdata.server = server;
2488 if (server->flags & NFS4_MOUNT_UNSHARED)
2489 compare_super = NULL;
2491 /* Get a superblock - note that we may end up sharing one that already exists */
2492 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2498 if (s->s_fs_info != server) {
2499 nfs_free_server(server);
2502 error = nfs_bdi_register(server);
2504 goto error_splat_super;
2508 /* initial superblock/root creation */
2509 nfs4_clone_super(s, data->sb);
2512 mntroot = nfs4_get_root(s, data->fh);
2513 if (IS_ERR(mntroot)) {
2514 error = PTR_ERR(mntroot);
2515 goto error_splat_super;
2517 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2520 goto error_splat_super;
2523 s->s_flags |= MS_ACTIVE;
2525 mnt->mnt_root = mntroot;
2527 security_sb_clone_mnt_opts(data->sb, s);
2529 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2533 nfs_free_server(server);
2535 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
2539 deactivate_locked_super(s);
2540 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
2545 * Create an NFS4 server record on referral traversal
2547 static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
2548 const char *dev_name, void *raw_data,
2549 struct vfsmount *mnt)
2551 struct nfs_clone_mount *data = raw_data;
2552 struct super_block *s;
2553 struct nfs_server *server;
2554 struct dentry *mntroot;
2555 struct nfs_fh mntfh;
2556 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2557 struct nfs_sb_mountdata sb_mntdata = {
2562 dprintk("--> nfs4_referral_get_sb()\n");
2564 /* create a new volume representation */
2565 server = nfs4_create_referral_server(data, &mntfh);
2566 if (IS_ERR(server)) {
2567 error = PTR_ERR(server);
2568 goto out_err_noserver;
2570 sb_mntdata.server = server;
2572 if (server->flags & NFS4_MOUNT_UNSHARED)
2573 compare_super = NULL;
2575 /* Get a superblock - note that we may end up sharing one that already exists */
2576 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2582 if (s->s_fs_info != server) {
2583 nfs_free_server(server);
2586 error = nfs_bdi_register(server);
2588 goto error_splat_super;
2592 /* initial superblock/root creation */
2596 mntroot = nfs4_get_root(s, &mntfh);
2597 if (IS_ERR(mntroot)) {
2598 error = PTR_ERR(mntroot);
2599 goto error_splat_super;
2601 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2604 goto error_splat_super;
2607 s->s_flags |= MS_ACTIVE;
2609 mnt->mnt_root = mntroot;
2611 security_sb_clone_mnt_opts(data->sb, s);
2613 dprintk("<-- nfs4_referral_get_sb() = 0\n");
2617 nfs_free_server(server);
2619 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
2623 deactivate_locked_super(s);
2624 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
2628 #endif /* CONFIG_NFS_V4 */