4 * Copyright (C) 1992 Rick Sladkey
6 * nfs superblock handling functions
8 * Modularised by Alan Cox <Alan.Cox@linux.org>, 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/nfs_fs.h>
37 #include <linux/nfs_mount.h>
38 #include <linux/nfs4_mount.h>
39 #include <linux/lockd/bind.h>
40 #include <linux/smp_lock.h>
41 #include <linux/seq_file.h>
42 #include <linux/mount.h>
43 #include <linux/nfs_idmap.h>
44 #include <linux/vfs.h>
45 #include <linux/inet.h>
46 #include <linux/nfs_xdr.h>
47 #include <linux/magic.h>
48 #include <linux/parser.h>
50 #include <asm/system.h>
51 #include <asm/uaccess.h>
55 #include "delegation.h"
59 #define NFSDBG_FACILITY NFSDBG_VFS
62 /* Mount options that take no arguments */
65 Opt_posix, Opt_noposix,
72 Opt_rdirplus, Opt_nordirplus,
73 Opt_sharecache, Opt_nosharecache,
75 /* Mount options that take integer arguments */
77 Opt_rsize, Opt_wsize, Opt_bsize,
78 Opt_timeo, Opt_retrans,
79 Opt_acregmin, Opt_acregmax,
80 Opt_acdirmin, Opt_acdirmax,
84 Opt_mountprog, Opt_mountvers,
85 Opt_nfsprog, Opt_nfsvers,
87 /* Mount options that take string arguments */
88 Opt_sec, Opt_proto, Opt_mountproto,
89 Opt_addr, Opt_mountaddr, Opt_clientaddr,
91 /* Mount options that are ignored */
92 Opt_userspace, Opt_deprecated,
97 static match_table_t nfs_mount_option_tokens = {
98 { Opt_userspace, "bg" },
99 { Opt_userspace, "fg" },
100 { Opt_soft, "soft" },
101 { Opt_hard, "hard" },
102 { Opt_intr, "intr" },
103 { Opt_nointr, "nointr" },
104 { Opt_posix, "posix" },
105 { Opt_noposix, "noposix" },
107 { Opt_nocto, "nocto" },
109 { Opt_noac, "noac" },
110 { Opt_lock, "lock" },
111 { Opt_nolock, "nolock" },
117 { Opt_noacl, "noacl" },
118 { Opt_rdirplus, "rdirplus" },
119 { Opt_nordirplus, "nordirplus" },
120 { Opt_sharecache, "sharecache" },
121 { Opt_nosharecache, "nosharecache" },
123 { Opt_port, "port=%u" },
124 { Opt_rsize, "rsize=%u" },
125 { Opt_wsize, "wsize=%u" },
126 { Opt_bsize, "bsize=%u" },
127 { Opt_timeo, "timeo=%u" },
128 { Opt_retrans, "retrans=%u" },
129 { Opt_acregmin, "acregmin=%u" },
130 { Opt_acregmax, "acregmax=%u" },
131 { Opt_acdirmin, "acdirmin=%u" },
132 { Opt_acdirmax, "acdirmax=%u" },
133 { Opt_actimeo, "actimeo=%u" },
134 { Opt_userspace, "retry=%u" },
135 { Opt_namelen, "namlen=%u" },
136 { Opt_mountport, "mountport=%u" },
137 { Opt_mountprog, "mountprog=%u" },
138 { Opt_mountvers, "mountvers=%u" },
139 { Opt_nfsprog, "nfsprog=%u" },
140 { Opt_nfsvers, "nfsvers=%u" },
141 { Opt_nfsvers, "vers=%u" },
143 { Opt_sec, "sec=%s" },
144 { Opt_proto, "proto=%s" },
145 { Opt_mountproto, "mountproto=%s" },
146 { Opt_addr, "addr=%s" },
147 { Opt_clientaddr, "clientaddr=%s" },
148 { Opt_userspace, "mounthost=%s" },
149 { Opt_mountaddr, "mountaddr=%s" },
155 Opt_xprt_udp, Opt_xprt_tcp,
160 static match_table_t nfs_xprt_protocol_tokens = {
161 { Opt_xprt_udp, "udp" },
162 { Opt_xprt_tcp, "tcp" },
164 { Opt_xprt_err, NULL }
168 Opt_sec_none, Opt_sec_sys,
169 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
170 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
171 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
176 static match_table_t nfs_secflavor_tokens = {
177 { Opt_sec_none, "none" },
178 { Opt_sec_none, "null" },
179 { Opt_sec_sys, "sys" },
181 { Opt_sec_krb5, "krb5" },
182 { Opt_sec_krb5i, "krb5i" },
183 { Opt_sec_krb5p, "krb5p" },
185 { Opt_sec_lkey, "lkey" },
186 { Opt_sec_lkeyi, "lkeyi" },
187 { Opt_sec_lkeyp, "lkeyp" },
189 { Opt_sec_err, NULL }
193 static void nfs_umount_begin(struct vfsmount *, int);
194 static int nfs_statfs(struct dentry *, struct kstatfs *);
195 static int nfs_show_options(struct seq_file *, struct vfsmount *);
196 static int nfs_show_stats(struct seq_file *, struct vfsmount *);
197 static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
198 static int nfs_xdev_get_sb(struct file_system_type *fs_type,
199 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
200 static void nfs_kill_super(struct super_block *);
202 static struct file_system_type nfs_fs_type = {
203 .owner = THIS_MODULE,
205 .get_sb = nfs_get_sb,
206 .kill_sb = nfs_kill_super,
207 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
210 struct file_system_type nfs_xdev_fs_type = {
211 .owner = THIS_MODULE,
213 .get_sb = nfs_xdev_get_sb,
214 .kill_sb = nfs_kill_super,
215 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
218 static const struct super_operations nfs_sops = {
219 .alloc_inode = nfs_alloc_inode,
220 .destroy_inode = nfs_destroy_inode,
221 .write_inode = nfs_write_inode,
222 .statfs = nfs_statfs,
223 .clear_inode = nfs_clear_inode,
224 .umount_begin = nfs_umount_begin,
225 .show_options = nfs_show_options,
226 .show_stats = nfs_show_stats,
230 static int nfs4_get_sb(struct file_system_type *fs_type,
231 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
232 static int nfs4_xdev_get_sb(struct file_system_type *fs_type,
233 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
234 static int nfs4_referral_get_sb(struct file_system_type *fs_type,
235 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
236 static void nfs4_kill_super(struct super_block *sb);
238 static struct file_system_type nfs4_fs_type = {
239 .owner = THIS_MODULE,
241 .get_sb = nfs4_get_sb,
242 .kill_sb = nfs4_kill_super,
243 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
246 struct file_system_type nfs4_xdev_fs_type = {
247 .owner = THIS_MODULE,
249 .get_sb = nfs4_xdev_get_sb,
250 .kill_sb = nfs4_kill_super,
251 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
254 struct file_system_type nfs4_referral_fs_type = {
255 .owner = THIS_MODULE,
257 .get_sb = nfs4_referral_get_sb,
258 .kill_sb = nfs4_kill_super,
259 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
262 static const struct super_operations nfs4_sops = {
263 .alloc_inode = nfs_alloc_inode,
264 .destroy_inode = nfs_destroy_inode,
265 .write_inode = nfs_write_inode,
266 .statfs = nfs_statfs,
267 .clear_inode = nfs4_clear_inode,
268 .umount_begin = nfs_umount_begin,
269 .show_options = nfs_show_options,
270 .show_stats = nfs_show_stats,
274 static struct shrinker acl_shrinker = {
275 .shrink = nfs_access_cache_shrinker,
276 .seeks = DEFAULT_SEEKS,
280 * Register the NFS filesystems
282 int __init register_nfs_fs(void)
286 ret = register_filesystem(&nfs_fs_type);
290 ret = nfs_register_sysctl();
294 ret = register_filesystem(&nfs4_fs_type);
298 register_shrinker(&acl_shrinker);
303 nfs_unregister_sysctl();
306 unregister_filesystem(&nfs_fs_type);
312 * Unregister the NFS filesystems
314 void __exit unregister_nfs_fs(void)
316 unregister_shrinker(&acl_shrinker);
318 unregister_filesystem(&nfs4_fs_type);
320 nfs_unregister_sysctl();
321 unregister_filesystem(&nfs_fs_type);
325 * Deliver file system statistics to userspace
327 static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
329 struct nfs_server *server = NFS_SB(dentry->d_sb);
330 unsigned char blockbits;
331 unsigned long blockres;
332 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
333 struct nfs_fattr fattr;
334 struct nfs_fsstat res = {
341 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
344 buf->f_type = NFS_SUPER_MAGIC;
347 * Current versions of glibc do not correctly handle the
348 * case where f_frsize != f_bsize. Eventually we want to
349 * report the value of wtmult in this field.
351 buf->f_frsize = dentry->d_sb->s_blocksize;
354 * On most *nix systems, f_blocks, f_bfree, and f_bavail
355 * are reported in units of f_frsize. Linux hasn't had
356 * an f_frsize field in its statfs struct until recently,
357 * thus historically Linux's sys_statfs reports these
358 * fields in units of f_bsize.
360 buf->f_bsize = dentry->d_sb->s_blocksize;
361 blockbits = dentry->d_sb->s_blocksize_bits;
362 blockres = (1 << blockbits) - 1;
363 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
364 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
365 buf->f_bavail = (res.abytes + blockres) >> blockbits;
367 buf->f_files = res.tfiles;
368 buf->f_ffree = res.afiles;
370 buf->f_namelen = server->namelen;
376 dprintk("%s: statfs error = %d\n", __FUNCTION__, -error);
382 * Map the security flavour number to a name
384 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
386 static const struct {
387 rpc_authflavor_t flavour;
390 { RPC_AUTH_NULL, "null" },
391 { RPC_AUTH_UNIX, "sys" },
392 { RPC_AUTH_GSS_KRB5, "krb5" },
393 { RPC_AUTH_GSS_KRB5I, "krb5i" },
394 { RPC_AUTH_GSS_KRB5P, "krb5p" },
395 { RPC_AUTH_GSS_LKEY, "lkey" },
396 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
397 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
398 { RPC_AUTH_GSS_SPKM, "spkm" },
399 { RPC_AUTH_GSS_SPKMI, "spkmi" },
400 { RPC_AUTH_GSS_SPKMP, "spkmp" },
401 { UINT_MAX, "unknown" }
405 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
406 if (sec_flavours[i].flavour == flavour)
409 return sec_flavours[i].str;
413 * Describe the mount options in force on this server representation
415 static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss, int showdefaults)
417 static const struct proc_nfs_info {
422 { NFS_MOUNT_SOFT, ",soft", ",hard" },
423 { NFS_MOUNT_INTR, ",intr", "" },
424 { NFS_MOUNT_NOCTO, ",nocto", "" },
425 { NFS_MOUNT_NOAC, ",noac", "" },
426 { NFS_MOUNT_NONLM, ",nolock", "" },
427 { NFS_MOUNT_NOACL, ",noacl", "" },
428 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
429 { NFS_MOUNT_UNSHARED, ",nosharecache", ""},
432 const struct proc_nfs_info *nfs_infop;
433 struct nfs_client *clp = nfss->nfs_client;
437 seq_printf(m, ",vers=%d", clp->rpc_ops->version);
438 seq_printf(m, ",rsize=%d", nfss->rsize);
439 seq_printf(m, ",wsize=%d", nfss->wsize);
440 if (nfss->acregmin != 3*HZ || showdefaults)
441 seq_printf(m, ",acregmin=%d", nfss->acregmin/HZ);
442 if (nfss->acregmax != 60*HZ || showdefaults)
443 seq_printf(m, ",acregmax=%d", nfss->acregmax/HZ);
444 if (nfss->acdirmin != 30*HZ || showdefaults)
445 seq_printf(m, ",acdirmin=%d", nfss->acdirmin/HZ);
446 if (nfss->acdirmax != 60*HZ || showdefaults)
447 seq_printf(m, ",acdirmax=%d", nfss->acdirmax/HZ);
448 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
449 if (nfss->flags & nfs_infop->flag)
450 seq_puts(m, nfs_infop->str);
452 seq_puts(m, nfs_infop->nostr);
454 switch (nfss->client->cl_xprt->prot) {
462 snprintf(buf, sizeof(buf), "%u", nfss->client->cl_xprt->prot);
465 seq_printf(m, ",proto=%s", proto);
466 seq_printf(m, ",timeo=%lu", 10U * clp->retrans_timeo / HZ);
467 seq_printf(m, ",retrans=%u", clp->retrans_count);
468 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
472 * Describe the mount options on this VFS mountpoint
474 static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
476 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
478 nfs_show_mount_options(m, nfss, 0);
480 seq_printf(m, ",addr="NIPQUAD_FMT,
481 NIPQUAD(nfss->nfs_client->cl_addr.sin_addr));
487 * Present statistical information for this VFS mountpoint
489 static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
492 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
493 struct rpc_auth *auth = nfss->client->cl_auth;
494 struct nfs_iostats totals = { };
496 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
499 * Display all mount option settings
501 seq_printf(m, "\n\topts:\t");
502 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
503 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
504 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
505 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
506 nfs_show_mount_options(m, nfss, 1);
508 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
510 seq_printf(m, "\n\tcaps:\t");
511 seq_printf(m, "caps=0x%x", nfss->caps);
512 seq_printf(m, ",wtmult=%d", nfss->wtmult);
513 seq_printf(m, ",dtsize=%d", nfss->dtsize);
514 seq_printf(m, ",bsize=%d", nfss->bsize);
515 seq_printf(m, ",namelen=%d", nfss->namelen);
518 if (nfss->nfs_client->cl_nfsversion == 4) {
519 seq_printf(m, "\n\tnfsv4:\t");
520 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
521 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
522 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
527 * Display security flavor in effect for this mount
529 seq_printf(m, "\n\tsec:\tflavor=%d", auth->au_ops->au_flavor);
531 seq_printf(m, ",pseudoflavor=%d", auth->au_flavor);
534 * Display superblock I/O counters
536 for_each_possible_cpu(cpu) {
537 struct nfs_iostats *stats;
540 stats = per_cpu_ptr(nfss->io_stats, cpu);
542 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
543 totals.events[i] += stats->events[i];
544 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
545 totals.bytes[i] += stats->bytes[i];
550 seq_printf(m, "\n\tevents:\t");
551 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
552 seq_printf(m, "%lu ", totals.events[i]);
553 seq_printf(m, "\n\tbytes:\t");
554 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
555 seq_printf(m, "%Lu ", totals.bytes[i]);
558 rpc_print_iostats(m, nfss->client);
564 * Begin unmount by attempting to remove all automounted mountpoints we added
565 * in response to xdev traversals and referrals
567 static void nfs_umount_begin(struct vfsmount *vfsmnt, int flags)
569 struct nfs_server *server = NFS_SB(vfsmnt->mnt_sb);
570 struct rpc_clnt *rpc;
572 shrink_submounts(vfsmnt, &nfs_automount_list);
574 if (!(flags & MNT_FORCE))
576 /* -EIO all pending I/O */
577 rpc = server->client_acl;
579 rpc_killall_tasks(rpc);
580 rpc = server->client;
582 rpc_killall_tasks(rpc);
586 * Sanity-check a server address provided by the mount command
588 static int nfs_verify_server_address(struct sockaddr *addr)
590 switch (addr->sa_family) {
592 struct sockaddr_in *sa = (struct sockaddr_in *) addr;
593 if (sa->sin_addr.s_addr != INADDR_ANY)
603 * Error-check and convert a string of mount options from user space into
606 static int nfs_parse_mount_options(char *raw,
607 struct nfs_parsed_mount_data *mnt)
612 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
615 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
617 while ((p = strsep(&raw, ",")) != NULL) {
618 substring_t args[MAX_OPT_ARGS];
624 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
626 token = match_token(p, nfs_mount_option_tokens, args);
629 mnt->flags |= NFS_MOUNT_SOFT;
632 mnt->flags &= ~NFS_MOUNT_SOFT;
635 mnt->flags |= NFS_MOUNT_INTR;
638 mnt->flags &= ~NFS_MOUNT_INTR;
641 mnt->flags |= NFS_MOUNT_POSIX;
644 mnt->flags &= ~NFS_MOUNT_POSIX;
647 mnt->flags &= ~NFS_MOUNT_NOCTO;
650 mnt->flags |= NFS_MOUNT_NOCTO;
653 mnt->flags &= ~NFS_MOUNT_NOAC;
656 mnt->flags |= NFS_MOUNT_NOAC;
659 mnt->flags &= ~NFS_MOUNT_NONLM;
662 mnt->flags |= NFS_MOUNT_NONLM;
665 mnt->flags &= ~NFS_MOUNT_VER3;
668 mnt->flags |= NFS_MOUNT_VER3;
671 mnt->flags &= ~NFS_MOUNT_TCP;
672 mnt->nfs_server.protocol = IPPROTO_UDP;
677 mnt->flags |= NFS_MOUNT_TCP;
678 mnt->nfs_server.protocol = IPPROTO_TCP;
683 mnt->flags &= ~NFS_MOUNT_NOACL;
686 mnt->flags |= NFS_MOUNT_NOACL;
689 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
692 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
695 mnt->flags &= ~NFS_MOUNT_UNSHARED;
697 case Opt_nosharecache:
698 mnt->flags |= NFS_MOUNT_UNSHARED;
702 if (match_int(args, &option))
704 if (option < 0 || option > 65535)
706 mnt->nfs_server.address.sin_port = htons(option);
709 if (match_int(args, &mnt->rsize))
713 if (match_int(args, &mnt->wsize))
717 if (match_int(args, &option))
724 if (match_int(args, &mnt->timeo))
728 if (match_int(args, &mnt->retrans))
732 if (match_int(args, &mnt->acregmin))
736 if (match_int(args, &mnt->acregmax))
740 if (match_int(args, &mnt->acdirmin))
744 if (match_int(args, &mnt->acdirmax))
748 if (match_int(args, &option))
755 mnt->acdirmax = option;
758 if (match_int(args, &mnt->namlen))
762 if (match_int(args, &option))
764 if (option < 0 || option > 65535)
766 mnt->mount_server.port = option;
769 if (match_int(args, &option))
773 mnt->mount_server.program = option;
776 if (match_int(args, &option))
780 mnt->mount_server.version = option;
783 if (match_int(args, &option))
787 mnt->nfs_server.program = option;
790 if (match_int(args, &option))
794 mnt->flags &= ~NFS_MOUNT_VER3;
797 mnt->flags |= NFS_MOUNT_VER3;
805 string = match_strdup(args);
808 token = match_token(string, nfs_secflavor_tokens, args);
812 * The flags setting is for v2/v3. The flavor_len
813 * setting is for v4. v2/v3 also need to know the
814 * difference between NULL and UNIX.
818 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
819 mnt->auth_flavor_len = 0;
820 mnt->auth_flavors[0] = RPC_AUTH_NULL;
823 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
824 mnt->auth_flavor_len = 0;
825 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
828 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
829 mnt->auth_flavor_len = 1;
830 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
833 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
834 mnt->auth_flavor_len = 1;
835 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
838 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
839 mnt->auth_flavor_len = 1;
840 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
843 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
844 mnt->auth_flavor_len = 1;
845 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
848 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
849 mnt->auth_flavor_len = 1;
850 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
853 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
854 mnt->auth_flavor_len = 1;
855 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
858 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
859 mnt->auth_flavor_len = 1;
860 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
863 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
864 mnt->auth_flavor_len = 1;
865 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
868 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
869 mnt->auth_flavor_len = 1;
870 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
877 string = match_strdup(args);
880 token = match_token(string,
881 nfs_xprt_protocol_tokens, args);
886 mnt->flags &= ~NFS_MOUNT_TCP;
887 mnt->nfs_server.protocol = IPPROTO_UDP;
892 mnt->flags |= NFS_MOUNT_TCP;
893 mnt->nfs_server.protocol = IPPROTO_TCP;
902 string = match_strdup(args);
905 token = match_token(string,
906 nfs_xprt_protocol_tokens, args);
911 mnt->mount_server.protocol = IPPROTO_UDP;
914 mnt->mount_server.protocol = IPPROTO_TCP;
921 string = match_strdup(args);
924 mnt->nfs_server.address.sin_family = AF_INET;
925 mnt->nfs_server.address.sin_addr.s_addr =
930 string = match_strdup(args);
933 mnt->client_address = string;
936 string = match_strdup(args);
939 mnt->mount_server.address.sin_family = AF_INET;
940 mnt->mount_server.address.sin_addr.s_addr =
957 printk(KERN_INFO "NFS: not enough memory to parse option\n");
961 printk(KERN_INFO "NFS: unrecognized NFS version number\n");
965 printk(KERN_INFO "NFS: unrecognized transport protocol\n");
969 printk(KERN_INFO "NFS: unrecognized security flavor\n");
973 printk(KERN_INFO "NFS: unknown mount option: %s\n", p);
978 * Use the remote server's MOUNT service to request the NFS file handle
979 * corresponding to the provided path.
981 static int nfs_try_mount(struct nfs_parsed_mount_data *args,
982 struct nfs_fh *root_fh)
984 struct sockaddr_in sin;
987 if (args->mount_server.version == 0) {
988 if (args->flags & NFS_MOUNT_VER3)
989 args->mount_server.version = NFS_MNT3_VERSION;
991 args->mount_server.version = NFS_MNT_VERSION;
995 * Construct the mount server's address.
997 if (args->mount_server.address.sin_addr.s_addr != INADDR_ANY)
998 sin = args->mount_server.address;
1000 sin = args->nfs_server.address;
1002 * autobind will be used if mount_server.port == 0
1004 sin.sin_port = htons(args->mount_server.port);
1007 * Now ask the mount server to map our export path
1010 status = nfs_mount((struct sockaddr *) &sin,
1012 args->nfs_server.hostname,
1013 args->nfs_server.export_path,
1014 args->mount_server.version,
1015 args->mount_server.protocol,
1020 dfprintk(MOUNT, "NFS: unable to mount server " NIPQUAD_FMT
1021 ", error %d\n", NIPQUAD(sin.sin_addr.s_addr), status);
1026 * Validate the NFS2/NFS3 mount data
1027 * - fills in the mount root filehandle
1029 * For option strings, user space handles the following behaviors:
1031 * + DNS: mapping server host name to IP address ("addr=" option)
1033 * + failure mode: how to behave if a mount request can't be handled
1034 * immediately ("fg/bg" option)
1036 * + retry: how often to retry a mount request ("retry=" option)
1038 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1039 * mountproto=tcp after mountproto=udp, and so on
1041 * XXX: as far as I can tell, changing the NFS program number is not
1042 * supported in the NFS client.
1044 static int nfs_validate_mount_data(void *options,
1045 struct nfs_parsed_mount_data *args,
1046 struct nfs_fh *mntfh,
1047 const char *dev_name)
1049 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
1054 memset(args, 0, sizeof(*args));
1055 args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
1056 args->rsize = NFS_MAX_FILE_IO_SIZE;
1057 args->wsize = NFS_MAX_FILE_IO_SIZE;
1061 args->acregmax = 60;
1062 args->acdirmin = 30;
1063 args->acdirmax = 60;
1064 args->mount_server.protocol = IPPROTO_UDP;
1065 args->mount_server.program = NFS_MNT_PROGRAM;
1066 args->nfs_server.protocol = IPPROTO_TCP;
1067 args->nfs_server.program = NFS_PROGRAM;
1069 switch (data->version) {
1075 if (data->flags & NFS_MOUNT_VER3)
1077 data->root.size = NFS2_FHSIZE;
1078 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1080 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1083 memset(data->context, 0, sizeof(data->context));
1085 if (data->flags & NFS_MOUNT_VER3)
1086 mntfh->size = data->root.size;
1088 mntfh->size = NFS2_FHSIZE;
1090 if (mntfh->size > sizeof(mntfh->data))
1091 goto out_invalid_fh;
1093 memcpy(mntfh->data, data->root.data, mntfh->size);
1094 if (mntfh->size < sizeof(mntfh->data))
1095 memset(mntfh->data + mntfh->size, 0,
1096 sizeof(mntfh->data) - mntfh->size);
1098 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1101 args->flags = data->flags;
1102 args->rsize = data->rsize;
1103 args->wsize = data->wsize;
1104 args->flags = data->flags;
1105 args->timeo = data->timeo;
1106 args->retrans = data->retrans;
1107 args->acregmin = data->acregmin;
1108 args->acregmax = data->acregmax;
1109 args->acdirmin = data->acdirmin;
1110 args->acdirmax = data->acdirmax;
1111 args->nfs_server.address = data->addr;
1112 if (!(data->flags & NFS_MOUNT_TCP))
1113 args->nfs_server.protocol = IPPROTO_UDP;
1114 /* N.B. caller will free nfs_server.hostname in all cases */
1115 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1116 args->namlen = data->namlen;
1117 args->bsize = data->bsize;
1118 args->auth_flavors[0] = data->pseudoflavor;
1125 if (nfs_parse_mount_options((char *)options, args) == 0)
1128 c = strchr(dev_name, ':');
1132 /* N.B. caller will free nfs_server.hostname in all cases */
1133 args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL);
1136 if (strlen(c) > NFS_MAXPATHLEN)
1137 return -ENAMETOOLONG;
1138 args->nfs_server.export_path = c;
1140 status = nfs_try_mount(args, mntfh);
1148 if (!(args->flags & NFS_MOUNT_SECFLAVOUR))
1149 args->auth_flavors[0] = RPC_AUTH_UNIX;
1151 #ifndef CONFIG_NFS_V3
1152 if (args->flags & NFS_MOUNT_VER3)
1153 goto out_v3_not_compiled;
1154 #endif /* !CONFIG_NFS_V3 */
1156 if (!nfs_verify_server_address((struct sockaddr *)
1157 &args->nfs_server.address))
1158 goto out_no_address;
1163 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1167 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1172 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1175 #ifndef CONFIG_NFS_V3
1176 out_v3_not_compiled:
1177 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1178 return -EPROTONOSUPPORT;
1179 #endif /* !CONFIG_NFS_V3 */
1182 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1186 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1191 * Initialise the common bits of the superblock
1193 static inline void nfs_initialise_sb(struct super_block *sb)
1195 struct nfs_server *server = NFS_SB(sb);
1197 sb->s_magic = NFS_SUPER_MAGIC;
1199 /* We probably want something more informative here */
1200 snprintf(sb->s_id, sizeof(sb->s_id),
1201 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1203 if (sb->s_blocksize == 0)
1204 sb->s_blocksize = nfs_block_bits(server->wsize,
1205 &sb->s_blocksize_bits);
1207 if (server->flags & NFS_MOUNT_NOAC)
1208 sb->s_flags |= MS_SYNCHRONOUS;
1210 nfs_super_set_maxbytes(sb, server->maxfilesize);
1214 * Finish setting up an NFS2/3 superblock
1216 static void nfs_fill_super(struct super_block *sb,
1217 struct nfs_parsed_mount_data *data)
1219 struct nfs_server *server = NFS_SB(sb);
1221 sb->s_blocksize_bits = 0;
1222 sb->s_blocksize = 0;
1224 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1226 if (server->flags & NFS_MOUNT_VER3) {
1227 /* The VFS shouldn't apply the umask to mode bits. We will do
1228 * so ourselves when necessary.
1230 sb->s_flags |= MS_POSIXACL;
1231 sb->s_time_gran = 1;
1234 sb->s_op = &nfs_sops;
1235 nfs_initialise_sb(sb);
1239 * Finish setting up a cloned NFS2/3 superblock
1241 static void nfs_clone_super(struct super_block *sb,
1242 const struct super_block *old_sb)
1244 struct nfs_server *server = NFS_SB(sb);
1246 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1247 sb->s_blocksize = old_sb->s_blocksize;
1248 sb->s_maxbytes = old_sb->s_maxbytes;
1250 if (server->flags & NFS_MOUNT_VER3) {
1251 /* The VFS shouldn't apply the umask to mode bits. We will do
1252 * so ourselves when necessary.
1254 sb->s_flags |= MS_POSIXACL;
1255 sb->s_time_gran = 1;
1258 sb->s_op = old_sb->s_op;
1259 nfs_initialise_sb(sb);
1262 #define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
1264 static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
1266 const struct nfs_server *a = s->s_fs_info;
1267 const struct rpc_clnt *clnt_a = a->client;
1268 const struct rpc_clnt *clnt_b = b->client;
1270 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
1272 if (a->nfs_client != b->nfs_client)
1274 if (a->flags != b->flags)
1276 if (a->wsize != b->wsize)
1278 if (a->rsize != b->rsize)
1280 if (a->acregmin != b->acregmin)
1282 if (a->acregmax != b->acregmax)
1284 if (a->acdirmin != b->acdirmin)
1286 if (a->acdirmax != b->acdirmax)
1288 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
1295 struct nfs_sb_mountdata {
1296 struct nfs_server *server;
1300 static int nfs_set_super(struct super_block *s, void *data)
1302 struct nfs_sb_mountdata *sb_mntdata = data;
1303 struct nfs_server *server = sb_mntdata->server;
1306 s->s_flags = sb_mntdata->mntflags;
1307 s->s_fs_info = server;
1308 ret = set_anon_super(s, server);
1310 server->s_dev = s->s_dev;
1314 static int nfs_compare_super(struct super_block *sb, void *data)
1316 struct nfs_sb_mountdata *sb_mntdata = data;
1317 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
1318 int mntflags = sb_mntdata->mntflags;
1320 if (memcmp(&old->nfs_client->cl_addr,
1321 &server->nfs_client->cl_addr,
1322 sizeof(old->nfs_client->cl_addr)) != 0)
1324 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1325 if (old->flags & NFS_MOUNT_UNSHARED)
1327 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
1329 return nfs_compare_mount_options(sb, server, mntflags);
1332 static int nfs_get_sb(struct file_system_type *fs_type,
1333 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1335 struct nfs_server *server = NULL;
1336 struct super_block *s;
1337 struct nfs_fh mntfh;
1338 struct nfs_parsed_mount_data data;
1339 struct dentry *mntroot;
1340 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
1341 struct nfs_sb_mountdata sb_mntdata = {
1346 /* Validate the mount data */
1347 error = nfs_validate_mount_data(raw_data, &data, &mntfh, dev_name);
1351 /* Get a volume representation */
1352 server = nfs_create_server(&data, &mntfh);
1353 if (IS_ERR(server)) {
1354 error = PTR_ERR(server);
1357 sb_mntdata.server = server;
1359 if (server->flags & NFS_MOUNT_UNSHARED)
1360 compare_super = NULL;
1362 /* Get a superblock - note that we may end up sharing one that already exists */
1363 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
1369 if (s->s_fs_info != server) {
1370 nfs_free_server(server);
1375 /* initial superblock/root creation */
1376 nfs_fill_super(s, &data);
1379 mntroot = nfs_get_root(s, &mntfh);
1380 if (IS_ERR(mntroot)) {
1381 error = PTR_ERR(mntroot);
1382 goto error_splat_super;
1385 s->s_flags |= MS_ACTIVE;
1387 mnt->mnt_root = mntroot;
1391 kfree(data.nfs_server.hostname);
1395 nfs_free_server(server);
1399 up_write(&s->s_umount);
1400 deactivate_super(s);
1405 * Destroy an NFS2/3 superblock
1407 static void nfs_kill_super(struct super_block *s)
1409 struct nfs_server *server = NFS_SB(s);
1412 nfs_free_server(server);
1416 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
1418 static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
1419 const char *dev_name, void *raw_data,
1420 struct vfsmount *mnt)
1422 struct nfs_clone_mount *data = raw_data;
1423 struct super_block *s;
1424 struct nfs_server *server;
1425 struct dentry *mntroot;
1426 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
1427 struct nfs_sb_mountdata sb_mntdata = {
1432 dprintk("--> nfs_xdev_get_sb()\n");
1434 /* create a new volume representation */
1435 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1436 if (IS_ERR(server)) {
1437 error = PTR_ERR(server);
1438 goto out_err_noserver;
1440 sb_mntdata.server = server;
1442 if (server->flags & NFS_MOUNT_UNSHARED)
1443 compare_super = NULL;
1445 /* Get a superblock - note that we may end up sharing one that already exists */
1446 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
1452 if (s->s_fs_info != server) {
1453 nfs_free_server(server);
1458 /* initial superblock/root creation */
1459 nfs_clone_super(s, data->sb);
1462 mntroot = nfs_get_root(s, data->fh);
1463 if (IS_ERR(mntroot)) {
1464 error = PTR_ERR(mntroot);
1465 goto error_splat_super;
1468 s->s_flags |= MS_ACTIVE;
1470 mnt->mnt_root = mntroot;
1472 dprintk("<-- nfs_xdev_get_sb() = 0\n");
1476 nfs_free_server(server);
1478 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
1482 up_write(&s->s_umount);
1483 deactivate_super(s);
1484 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
1488 #ifdef CONFIG_NFS_V4
1491 * Finish setting up a cloned NFS4 superblock
1493 static void nfs4_clone_super(struct super_block *sb,
1494 const struct super_block *old_sb)
1496 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1497 sb->s_blocksize = old_sb->s_blocksize;
1498 sb->s_maxbytes = old_sb->s_maxbytes;
1499 sb->s_time_gran = 1;
1500 sb->s_op = old_sb->s_op;
1501 nfs_initialise_sb(sb);
1505 * Set up an NFS4 superblock
1507 static void nfs4_fill_super(struct super_block *sb)
1509 sb->s_time_gran = 1;
1510 sb->s_op = &nfs4_sops;
1511 nfs_initialise_sb(sb);
1515 * Validate NFSv4 mount options
1517 static int nfs4_validate_mount_data(void *options,
1518 struct nfs_parsed_mount_data *args,
1519 const char *dev_name)
1521 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
1527 memset(args, 0, sizeof(*args));
1528 args->rsize = NFS_MAX_FILE_IO_SIZE;
1529 args->wsize = NFS_MAX_FILE_IO_SIZE;
1533 args->acregmax = 60;
1534 args->acdirmin = 30;
1535 args->acdirmax = 60;
1536 args->nfs_server.protocol = IPPROTO_TCP;
1538 switch (data->version) {
1540 if (data->host_addrlen != sizeof(args->nfs_server.address))
1541 goto out_no_address;
1542 if (copy_from_user(&args->nfs_server.address,
1544 sizeof(&args->nfs_server.address)))
1546 if (args->nfs_server.address.sin_port == 0)
1547 args->nfs_server.address.sin_port = htons(NFS_PORT);
1548 if (!nfs_verify_server_address((struct sockaddr *)
1549 &args->nfs_server.address))
1550 goto out_no_address;
1552 switch (data->auth_flavourlen) {
1554 args->auth_flavors[0] = RPC_AUTH_UNIX;
1557 if (copy_from_user(args->auth_flavors,
1558 data->auth_flavours,
1559 sizeof(args->auth_flavors)))
1563 goto out_inval_auth;
1566 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
1569 args->nfs_server.hostname = c;
1571 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
1574 args->nfs_server.export_path = c;
1575 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
1577 c = strndup_user(data->client_addr.data, 16);
1580 args->client_address = c;
1583 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
1587 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
1588 args->rsize = data->rsize;
1589 args->wsize = data->wsize;
1590 args->timeo = data->timeo;
1591 args->retrans = data->retrans;
1592 args->acregmin = data->acregmin;
1593 args->acregmax = data->acregmax;
1594 args->acdirmin = data->acdirmin;
1595 args->acdirmax = data->acdirmax;
1596 args->nfs_server.protocol = data->proto;
1602 if (nfs_parse_mount_options((char *)options, args) == 0)
1605 if (!nfs_verify_server_address((struct sockaddr *)
1606 &args->nfs_server.address))
1609 switch (args->auth_flavor_len) {
1611 args->auth_flavors[0] = RPC_AUTH_UNIX;
1616 goto out_inval_auth;
1620 * Split "dev_name" into "hostname:mntpath".
1622 c = strchr(dev_name, ':');
1625 /* while calculating len, pretend ':' is '\0' */
1627 if (len > NFS4_MAXNAMLEN)
1628 return -ENAMETOOLONG;
1629 args->nfs_server.hostname = kzalloc(len, GFP_KERNEL);
1630 if (args->nfs_server.hostname == NULL)
1632 strncpy(args->nfs_server.hostname, dev_name, len - 1);
1634 c++; /* step over the ':' */
1636 if (len > NFS4_MAXPATHLEN)
1637 return -ENAMETOOLONG;
1638 args->nfs_server.export_path = kzalloc(len + 1, GFP_KERNEL);
1639 if (args->nfs_server.export_path == NULL)
1641 strncpy(args->nfs_server.export_path, c, len);
1643 dprintk("MNTPATH: %s\n", args->nfs_server.export_path);
1645 if (args->client_address == NULL)
1646 goto out_no_client_address;
1655 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
1659 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
1660 data->auth_flavourlen);
1664 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
1667 out_no_client_address:
1668 dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
1673 * Get the superblock for an NFS4 mountpoint
1675 static int nfs4_get_sb(struct file_system_type *fs_type,
1676 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1678 struct nfs_parsed_mount_data data;
1679 struct super_block *s;
1680 struct nfs_server *server;
1681 struct nfs_fh mntfh;
1682 struct dentry *mntroot;
1683 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
1684 struct nfs_sb_mountdata sb_mntdata = {
1689 /* Validate the mount data */
1690 error = nfs4_validate_mount_data(raw_data, &data, dev_name);
1694 /* Get a volume representation */
1695 server = nfs4_create_server(&data, &mntfh);
1696 if (IS_ERR(server)) {
1697 error = PTR_ERR(server);
1700 sb_mntdata.server = server;
1702 if (server->flags & NFS4_MOUNT_UNSHARED)
1703 compare_super = NULL;
1705 /* Get a superblock - note that we may end up sharing one that already exists */
1706 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
1712 if (s->s_fs_info != server) {
1713 nfs_free_server(server);
1718 /* initial superblock/root creation */
1722 mntroot = nfs4_get_root(s, &mntfh);
1723 if (IS_ERR(mntroot)) {
1724 error = PTR_ERR(mntroot);
1725 goto error_splat_super;
1728 s->s_flags |= MS_ACTIVE;
1730 mnt->mnt_root = mntroot;
1734 kfree(data.client_address);
1735 kfree(data.nfs_server.export_path);
1736 kfree(data.nfs_server.hostname);
1740 nfs_free_server(server);
1744 up_write(&s->s_umount);
1745 deactivate_super(s);
1749 static void nfs4_kill_super(struct super_block *sb)
1751 struct nfs_server *server = NFS_SB(sb);
1753 nfs_return_all_delegations(sb);
1754 kill_anon_super(sb);
1756 nfs4_renewd_prepare_shutdown(server);
1757 nfs_free_server(server);
1761 * Clone an NFS4 server record on xdev traversal (FSID-change)
1763 static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
1764 const char *dev_name, void *raw_data,
1765 struct vfsmount *mnt)
1767 struct nfs_clone_mount *data = raw_data;
1768 struct super_block *s;
1769 struct nfs_server *server;
1770 struct dentry *mntroot;
1771 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
1772 struct nfs_sb_mountdata sb_mntdata = {
1777 dprintk("--> nfs4_xdev_get_sb()\n");
1779 /* create a new volume representation */
1780 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1781 if (IS_ERR(server)) {
1782 error = PTR_ERR(server);
1783 goto out_err_noserver;
1785 sb_mntdata.server = server;
1787 if (server->flags & NFS4_MOUNT_UNSHARED)
1788 compare_super = NULL;
1790 /* Get a superblock - note that we may end up sharing one that already exists */
1791 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
1797 if (s->s_fs_info != server) {
1798 nfs_free_server(server);
1803 /* initial superblock/root creation */
1804 nfs4_clone_super(s, data->sb);
1807 mntroot = nfs4_get_root(s, data->fh);
1808 if (IS_ERR(mntroot)) {
1809 error = PTR_ERR(mntroot);
1810 goto error_splat_super;
1813 s->s_flags |= MS_ACTIVE;
1815 mnt->mnt_root = mntroot;
1817 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
1821 nfs_free_server(server);
1823 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
1827 up_write(&s->s_umount);
1828 deactivate_super(s);
1829 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
1834 * Create an NFS4 server record on referral traversal
1836 static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
1837 const char *dev_name, void *raw_data,
1838 struct vfsmount *mnt)
1840 struct nfs_clone_mount *data = raw_data;
1841 struct super_block *s;
1842 struct nfs_server *server;
1843 struct dentry *mntroot;
1844 struct nfs_fh mntfh;
1845 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
1846 struct nfs_sb_mountdata sb_mntdata = {
1851 dprintk("--> nfs4_referral_get_sb()\n");
1853 /* create a new volume representation */
1854 server = nfs4_create_referral_server(data, &mntfh);
1855 if (IS_ERR(server)) {
1856 error = PTR_ERR(server);
1857 goto out_err_noserver;
1859 sb_mntdata.server = server;
1861 if (server->flags & NFS4_MOUNT_UNSHARED)
1862 compare_super = NULL;
1864 /* Get a superblock - note that we may end up sharing one that already exists */
1865 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
1871 if (s->s_fs_info != server) {
1872 nfs_free_server(server);
1877 /* initial superblock/root creation */
1881 mntroot = nfs4_get_root(s, &mntfh);
1882 if (IS_ERR(mntroot)) {
1883 error = PTR_ERR(mntroot);
1884 goto error_splat_super;
1887 s->s_flags |= MS_ACTIVE;
1889 mnt->mnt_root = mntroot;
1891 dprintk("<-- nfs4_referral_get_sb() = 0\n");
1895 nfs_free_server(server);
1897 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
1901 up_write(&s->s_umount);
1902 deactivate_super(s);
1903 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
1907 #endif /* CONFIG_NFS_V4 */