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/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/nfs_xdr.h>
49 #include <linux/magic.h>
50 #include <linux/parser.h>
52 #include <asm/system.h>
53 #include <asm/uaccess.h>
57 #include "delegation.h"
61 #define NFSDBG_FACILITY NFSDBG_VFS
64 /* Mount options that take no arguments */
67 Opt_posix, Opt_noposix,
72 Opt_udp, Opt_tcp, Opt_rdma,
74 Opt_rdirplus, Opt_nordirplus,
75 Opt_sharecache, Opt_nosharecache,
77 /* Mount options that take integer arguments */
79 Opt_rsize, Opt_wsize, Opt_bsize,
80 Opt_timeo, Opt_retrans,
81 Opt_acregmin, Opt_acregmax,
82 Opt_acdirmin, Opt_acdirmax,
86 Opt_mountprog, Opt_mountvers,
87 Opt_nfsprog, Opt_nfsvers,
89 /* Mount options that take string arguments */
90 Opt_sec, Opt_proto, Opt_mountproto,
91 Opt_addr, Opt_mountaddr, Opt_clientaddr,
93 /* Mount options that are ignored */
94 Opt_userspace, Opt_deprecated,
99 static match_table_t nfs_mount_option_tokens = {
100 { Opt_userspace, "bg" },
101 { Opt_userspace, "fg" },
102 { Opt_soft, "soft" },
103 { Opt_hard, "hard" },
104 { Opt_intr, "intr" },
105 { Opt_nointr, "nointr" },
106 { Opt_posix, "posix" },
107 { Opt_noposix, "noposix" },
109 { Opt_nocto, "nocto" },
111 { Opt_noac, "noac" },
112 { Opt_lock, "lock" },
113 { Opt_nolock, "nolock" },
118 { Opt_rdma, "rdma" },
120 { Opt_noacl, "noacl" },
121 { Opt_rdirplus, "rdirplus" },
122 { Opt_nordirplus, "nordirplus" },
123 { Opt_sharecache, "sharecache" },
124 { Opt_nosharecache, "nosharecache" },
126 { Opt_port, "port=%u" },
127 { Opt_rsize, "rsize=%u" },
128 { Opt_wsize, "wsize=%u" },
129 { Opt_bsize, "bsize=%u" },
130 { Opt_timeo, "timeo=%u" },
131 { Opt_retrans, "retrans=%u" },
132 { Opt_acregmin, "acregmin=%u" },
133 { Opt_acregmax, "acregmax=%u" },
134 { Opt_acdirmin, "acdirmin=%u" },
135 { Opt_acdirmax, "acdirmax=%u" },
136 { Opt_actimeo, "actimeo=%u" },
137 { Opt_userspace, "retry=%u" },
138 { Opt_namelen, "namlen=%u" },
139 { Opt_mountport, "mountport=%u" },
140 { Opt_mountprog, "mountprog=%u" },
141 { Opt_mountvers, "mountvers=%u" },
142 { Opt_nfsprog, "nfsprog=%u" },
143 { Opt_nfsvers, "nfsvers=%u" },
144 { Opt_nfsvers, "vers=%u" },
146 { Opt_sec, "sec=%s" },
147 { Opt_proto, "proto=%s" },
148 { Opt_mountproto, "mountproto=%s" },
149 { Opt_addr, "addr=%s" },
150 { Opt_clientaddr, "clientaddr=%s" },
151 { Opt_userspace, "mounthost=%s" },
152 { Opt_mountaddr, "mountaddr=%s" },
158 Opt_xprt_udp, Opt_xprt_tcp, Opt_xprt_rdma,
163 static match_table_t nfs_xprt_protocol_tokens = {
164 { Opt_xprt_udp, "udp" },
165 { Opt_xprt_tcp, "tcp" },
166 { Opt_xprt_rdma, "rdma" },
168 { Opt_xprt_err, NULL }
172 Opt_sec_none, Opt_sec_sys,
173 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
174 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
175 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
180 static match_table_t nfs_secflavor_tokens = {
181 { Opt_sec_none, "none" },
182 { Opt_sec_none, "null" },
183 { Opt_sec_sys, "sys" },
185 { Opt_sec_krb5, "krb5" },
186 { Opt_sec_krb5i, "krb5i" },
187 { Opt_sec_krb5p, "krb5p" },
189 { Opt_sec_lkey, "lkey" },
190 { Opt_sec_lkeyi, "lkeyi" },
191 { Opt_sec_lkeyp, "lkeyp" },
193 { Opt_sec_err, NULL }
197 static void nfs_umount_begin(struct vfsmount *, int);
198 static int nfs_statfs(struct dentry *, struct kstatfs *);
199 static int nfs_show_options(struct seq_file *, struct vfsmount *);
200 static int nfs_show_stats(struct seq_file *, struct vfsmount *);
201 static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
202 static int nfs_xdev_get_sb(struct file_system_type *fs_type,
203 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
204 static void nfs_kill_super(struct super_block *);
205 static void nfs_put_super(struct super_block *);
207 static struct file_system_type nfs_fs_type = {
208 .owner = THIS_MODULE,
210 .get_sb = nfs_get_sb,
211 .kill_sb = nfs_kill_super,
212 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
215 struct file_system_type nfs_xdev_fs_type = {
216 .owner = THIS_MODULE,
218 .get_sb = nfs_xdev_get_sb,
219 .kill_sb = nfs_kill_super,
220 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
223 static const struct super_operations nfs_sops = {
224 .alloc_inode = nfs_alloc_inode,
225 .destroy_inode = nfs_destroy_inode,
226 .write_inode = nfs_write_inode,
227 .put_super = nfs_put_super,
228 .statfs = nfs_statfs,
229 .clear_inode = nfs_clear_inode,
230 .umount_begin = nfs_umount_begin,
231 .show_options = nfs_show_options,
232 .show_stats = nfs_show_stats,
236 static int nfs4_get_sb(struct file_system_type *fs_type,
237 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
238 static int nfs4_xdev_get_sb(struct file_system_type *fs_type,
239 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
240 static int nfs4_referral_get_sb(struct file_system_type *fs_type,
241 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
242 static void nfs4_kill_super(struct super_block *sb);
244 static struct file_system_type nfs4_fs_type = {
245 .owner = THIS_MODULE,
247 .get_sb = nfs4_get_sb,
248 .kill_sb = nfs4_kill_super,
249 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
252 struct file_system_type nfs4_xdev_fs_type = {
253 .owner = THIS_MODULE,
255 .get_sb = nfs4_xdev_get_sb,
256 .kill_sb = nfs4_kill_super,
257 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
260 struct file_system_type nfs4_referral_fs_type = {
261 .owner = THIS_MODULE,
263 .get_sb = nfs4_referral_get_sb,
264 .kill_sb = nfs4_kill_super,
265 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
268 static const struct super_operations nfs4_sops = {
269 .alloc_inode = nfs_alloc_inode,
270 .destroy_inode = nfs_destroy_inode,
271 .write_inode = nfs_write_inode,
272 .statfs = nfs_statfs,
273 .clear_inode = nfs4_clear_inode,
274 .umount_begin = nfs_umount_begin,
275 .show_options = nfs_show_options,
276 .show_stats = nfs_show_stats,
280 static struct shrinker acl_shrinker = {
281 .shrink = nfs_access_cache_shrinker,
282 .seeks = DEFAULT_SEEKS,
286 * Register the NFS filesystems
288 int __init register_nfs_fs(void)
292 ret = register_filesystem(&nfs_fs_type);
296 ret = nfs_register_sysctl();
300 ret = register_filesystem(&nfs4_fs_type);
304 register_shrinker(&acl_shrinker);
309 nfs_unregister_sysctl();
312 unregister_filesystem(&nfs_fs_type);
318 * Unregister the NFS filesystems
320 void __exit unregister_nfs_fs(void)
322 unregister_shrinker(&acl_shrinker);
324 unregister_filesystem(&nfs4_fs_type);
326 nfs_unregister_sysctl();
327 unregister_filesystem(&nfs_fs_type);
330 void nfs_sb_active(struct nfs_server *server)
332 atomic_inc(&server->active);
335 void nfs_sb_deactive(struct nfs_server *server)
337 if (atomic_dec_and_test(&server->active))
338 wake_up(&server->active_wq);
341 static void nfs_put_super(struct super_block *sb)
343 struct nfs_server *server = NFS_SB(sb);
345 * Make sure there are no outstanding ops to this server.
346 * If so, wait for them to finish before allowing the
347 * unmount to continue.
349 wait_event(server->active_wq, atomic_read(&server->active) == 0);
353 * Deliver file system statistics to userspace
355 static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
357 struct nfs_server *server = NFS_SB(dentry->d_sb);
358 unsigned char blockbits;
359 unsigned long blockres;
360 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
361 struct nfs_fattr fattr;
362 struct nfs_fsstat res = {
369 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
372 buf->f_type = NFS_SUPER_MAGIC;
375 * Current versions of glibc do not correctly handle the
376 * case where f_frsize != f_bsize. Eventually we want to
377 * report the value of wtmult in this field.
379 buf->f_frsize = dentry->d_sb->s_blocksize;
382 * On most *nix systems, f_blocks, f_bfree, and f_bavail
383 * are reported in units of f_frsize. Linux hasn't had
384 * an f_frsize field in its statfs struct until recently,
385 * thus historically Linux's sys_statfs reports these
386 * fields in units of f_bsize.
388 buf->f_bsize = dentry->d_sb->s_blocksize;
389 blockbits = dentry->d_sb->s_blocksize_bits;
390 blockres = (1 << blockbits) - 1;
391 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
392 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
393 buf->f_bavail = (res.abytes + blockres) >> blockbits;
395 buf->f_files = res.tfiles;
396 buf->f_ffree = res.afiles;
398 buf->f_namelen = server->namelen;
404 dprintk("%s: statfs error = %d\n", __FUNCTION__, -error);
410 * Map the security flavour number to a name
412 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
414 static const struct {
415 rpc_authflavor_t flavour;
418 { RPC_AUTH_NULL, "null" },
419 { RPC_AUTH_UNIX, "sys" },
420 { RPC_AUTH_GSS_KRB5, "krb5" },
421 { RPC_AUTH_GSS_KRB5I, "krb5i" },
422 { RPC_AUTH_GSS_KRB5P, "krb5p" },
423 { RPC_AUTH_GSS_LKEY, "lkey" },
424 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
425 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
426 { RPC_AUTH_GSS_SPKM, "spkm" },
427 { RPC_AUTH_GSS_SPKMI, "spkmi" },
428 { RPC_AUTH_GSS_SPKMP, "spkmp" },
429 { UINT_MAX, "unknown" }
433 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
434 if (sec_flavours[i].flavour == flavour)
437 return sec_flavours[i].str;
441 * Describe the mount options in force on this server representation
443 static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss, int showdefaults)
445 static const struct proc_nfs_info {
450 { NFS_MOUNT_SOFT, ",soft", ",hard" },
451 { NFS_MOUNT_INTR, ",intr", ",nointr" },
452 { NFS_MOUNT_NOCTO, ",nocto", "" },
453 { NFS_MOUNT_NOAC, ",noac", "" },
454 { NFS_MOUNT_NONLM, ",nolock", "" },
455 { NFS_MOUNT_NOACL, ",noacl", "" },
456 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
457 { NFS_MOUNT_UNSHARED, ",nosharecache", ""},
460 const struct proc_nfs_info *nfs_infop;
461 struct nfs_client *clp = nfss->nfs_client;
463 seq_printf(m, ",vers=%d", clp->rpc_ops->version);
464 seq_printf(m, ",rsize=%d", nfss->rsize);
465 seq_printf(m, ",wsize=%d", nfss->wsize);
466 if (nfss->acregmin != 3*HZ || showdefaults)
467 seq_printf(m, ",acregmin=%d", nfss->acregmin/HZ);
468 if (nfss->acregmax != 60*HZ || showdefaults)
469 seq_printf(m, ",acregmax=%d", nfss->acregmax/HZ);
470 if (nfss->acdirmin != 30*HZ || showdefaults)
471 seq_printf(m, ",acdirmin=%d", nfss->acdirmin/HZ);
472 if (nfss->acdirmax != 60*HZ || showdefaults)
473 seq_printf(m, ",acdirmax=%d", nfss->acdirmax/HZ);
474 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
475 if (nfss->flags & nfs_infop->flag)
476 seq_puts(m, nfs_infop->str);
478 seq_puts(m, nfs_infop->nostr);
480 seq_printf(m, ",proto=%s",
481 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_PROTO));
482 seq_printf(m, ",timeo=%lu", 10U * clp->retrans_timeo / HZ);
483 seq_printf(m, ",retrans=%u", clp->retrans_count);
484 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
488 * Describe the mount options on this VFS mountpoint
490 static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
492 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
494 nfs_show_mount_options(m, nfss, 0);
496 seq_printf(m, ",addr="NIPQUAD_FMT,
497 NIPQUAD(nfss->nfs_client->cl_addr.sin_addr));
503 * Present statistical information for this VFS mountpoint
505 static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
508 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
509 struct rpc_auth *auth = nfss->client->cl_auth;
510 struct nfs_iostats totals = { };
512 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
515 * Display all mount option settings
517 seq_printf(m, "\n\topts:\t");
518 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
519 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
520 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
521 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
522 nfs_show_mount_options(m, nfss, 1);
524 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
526 seq_printf(m, "\n\tcaps:\t");
527 seq_printf(m, "caps=0x%x", nfss->caps);
528 seq_printf(m, ",wtmult=%d", nfss->wtmult);
529 seq_printf(m, ",dtsize=%d", nfss->dtsize);
530 seq_printf(m, ",bsize=%d", nfss->bsize);
531 seq_printf(m, ",namelen=%d", nfss->namelen);
534 if (nfss->nfs_client->cl_nfsversion == 4) {
535 seq_printf(m, "\n\tnfsv4:\t");
536 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
537 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
538 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
543 * Display security flavor in effect for this mount
545 seq_printf(m, "\n\tsec:\tflavor=%d", auth->au_ops->au_flavor);
547 seq_printf(m, ",pseudoflavor=%d", auth->au_flavor);
550 * Display superblock I/O counters
552 for_each_possible_cpu(cpu) {
553 struct nfs_iostats *stats;
556 stats = per_cpu_ptr(nfss->io_stats, cpu);
558 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
559 totals.events[i] += stats->events[i];
560 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
561 totals.bytes[i] += stats->bytes[i];
566 seq_printf(m, "\n\tevents:\t");
567 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
568 seq_printf(m, "%lu ", totals.events[i]);
569 seq_printf(m, "\n\tbytes:\t");
570 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
571 seq_printf(m, "%Lu ", totals.bytes[i]);
574 rpc_print_iostats(m, nfss->client);
580 * Begin unmount by attempting to remove all automounted mountpoints we added
581 * in response to xdev traversals and referrals
583 static void nfs_umount_begin(struct vfsmount *vfsmnt, int flags)
585 struct nfs_server *server = NFS_SB(vfsmnt->mnt_sb);
586 struct rpc_clnt *rpc;
588 shrink_submounts(vfsmnt, &nfs_automount_list);
590 if (!(flags & MNT_FORCE))
592 /* -EIO all pending I/O */
593 rpc = server->client_acl;
595 rpc_killall_tasks(rpc);
596 rpc = server->client;
598 rpc_killall_tasks(rpc);
602 * Sanity-check a server address provided by the mount command
604 static int nfs_verify_server_address(struct sockaddr *addr)
606 switch (addr->sa_family) {
608 struct sockaddr_in *sa = (struct sockaddr_in *) addr;
609 if (sa->sin_addr.s_addr != INADDR_ANY)
619 * Error-check and convert a string of mount options from user space into
622 static int nfs_parse_mount_options(char *raw,
623 struct nfs_parsed_mount_data *mnt)
628 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
631 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
633 while ((p = strsep(&raw, ",")) != NULL) {
634 substring_t args[MAX_OPT_ARGS];
640 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
642 token = match_token(p, nfs_mount_option_tokens, args);
645 mnt->flags |= NFS_MOUNT_SOFT;
648 mnt->flags &= ~NFS_MOUNT_SOFT;
651 mnt->flags |= NFS_MOUNT_INTR;
654 mnt->flags &= ~NFS_MOUNT_INTR;
657 mnt->flags |= NFS_MOUNT_POSIX;
660 mnt->flags &= ~NFS_MOUNT_POSIX;
663 mnt->flags &= ~NFS_MOUNT_NOCTO;
666 mnt->flags |= NFS_MOUNT_NOCTO;
669 mnt->flags &= ~NFS_MOUNT_NOAC;
672 mnt->flags |= NFS_MOUNT_NOAC;
675 mnt->flags &= ~NFS_MOUNT_NONLM;
678 mnt->flags |= NFS_MOUNT_NONLM;
681 mnt->flags &= ~NFS_MOUNT_VER3;
684 mnt->flags |= NFS_MOUNT_VER3;
687 mnt->flags &= ~NFS_MOUNT_TCP;
688 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
693 mnt->flags |= NFS_MOUNT_TCP;
694 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
699 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
700 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
705 mnt->flags &= ~NFS_MOUNT_NOACL;
708 mnt->flags |= NFS_MOUNT_NOACL;
711 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
714 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
717 mnt->flags &= ~NFS_MOUNT_UNSHARED;
719 case Opt_nosharecache:
720 mnt->flags |= NFS_MOUNT_UNSHARED;
724 if (match_int(args, &option))
726 if (option < 0 || option > 65535)
728 mnt->nfs_server.address.sin_port = htons(option);
731 if (match_int(args, &mnt->rsize))
735 if (match_int(args, &mnt->wsize))
739 if (match_int(args, &option))
746 if (match_int(args, &mnt->timeo))
750 if (match_int(args, &mnt->retrans))
754 if (match_int(args, &mnt->acregmin))
758 if (match_int(args, &mnt->acregmax))
762 if (match_int(args, &mnt->acdirmin))
766 if (match_int(args, &mnt->acdirmax))
770 if (match_int(args, &option))
777 mnt->acdirmax = option;
780 if (match_int(args, &mnt->namlen))
784 if (match_int(args, &option))
786 if (option < 0 || option > 65535)
788 mnt->mount_server.port = option;
791 if (match_int(args, &option))
795 mnt->mount_server.program = option;
798 if (match_int(args, &option))
802 mnt->mount_server.version = option;
805 if (match_int(args, &option))
809 mnt->nfs_server.program = option;
812 if (match_int(args, &option))
816 mnt->flags &= ~NFS_MOUNT_VER3;
819 mnt->flags |= NFS_MOUNT_VER3;
827 string = match_strdup(args);
830 token = match_token(string, nfs_secflavor_tokens, args);
834 * The flags setting is for v2/v3. The flavor_len
835 * setting is for v4. v2/v3 also need to know the
836 * difference between NULL and UNIX.
840 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
841 mnt->auth_flavor_len = 0;
842 mnt->auth_flavors[0] = RPC_AUTH_NULL;
845 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
846 mnt->auth_flavor_len = 0;
847 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
850 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
851 mnt->auth_flavor_len = 1;
852 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
855 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
856 mnt->auth_flavor_len = 1;
857 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
860 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
861 mnt->auth_flavor_len = 1;
862 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
865 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
866 mnt->auth_flavor_len = 1;
867 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
870 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
871 mnt->auth_flavor_len = 1;
872 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
875 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
876 mnt->auth_flavor_len = 1;
877 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
880 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
881 mnt->auth_flavor_len = 1;
882 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
885 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
886 mnt->auth_flavor_len = 1;
887 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
890 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
891 mnt->auth_flavor_len = 1;
892 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
899 string = match_strdup(args);
902 token = match_token(string,
903 nfs_xprt_protocol_tokens, args);
908 mnt->flags &= ~NFS_MOUNT_TCP;
909 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
914 mnt->flags |= NFS_MOUNT_TCP;
915 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
920 /* vector side protocols to TCP */
921 mnt->flags |= NFS_MOUNT_TCP;
922 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
931 string = match_strdup(args);
934 token = match_token(string,
935 nfs_xprt_protocol_tokens, args);
940 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
943 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
945 case Opt_xprt_rdma: /* not used for side protocols */
951 string = match_strdup(args);
954 mnt->nfs_server.address.sin_family = AF_INET;
955 mnt->nfs_server.address.sin_addr.s_addr =
960 string = match_strdup(args);
963 mnt->client_address = string;
966 string = match_strdup(args);
969 mnt->mount_server.address.sin_family = AF_INET;
970 mnt->mount_server.address.sin_addr.s_addr =
987 printk(KERN_INFO "NFS: not enough memory to parse option\n");
991 printk(KERN_INFO "NFS: unrecognized NFS version number\n");
995 printk(KERN_INFO "NFS: unrecognized transport protocol\n");
999 printk(KERN_INFO "NFS: unrecognized security flavor\n");
1003 printk(KERN_INFO "NFS: unknown mount option: %s\n", p);
1008 * Use the remote server's MOUNT service to request the NFS file handle
1009 * corresponding to the provided path.
1011 static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1012 struct nfs_fh *root_fh)
1014 struct sockaddr_in sin;
1017 if (args->mount_server.version == 0) {
1018 if (args->flags & NFS_MOUNT_VER3)
1019 args->mount_server.version = NFS_MNT3_VERSION;
1021 args->mount_server.version = NFS_MNT_VERSION;
1025 * Construct the mount server's address.
1027 if (args->mount_server.address.sin_addr.s_addr != INADDR_ANY)
1028 sin = args->mount_server.address;
1030 sin = args->nfs_server.address;
1032 * autobind will be used if mount_server.port == 0
1034 sin.sin_port = htons(args->mount_server.port);
1037 * Now ask the mount server to map our export path
1040 status = nfs_mount((struct sockaddr *) &sin,
1042 args->nfs_server.hostname,
1043 args->nfs_server.export_path,
1044 args->mount_server.version,
1045 args->mount_server.protocol,
1050 dfprintk(MOUNT, "NFS: unable to mount server " NIPQUAD_FMT
1051 ", error %d\n", NIPQUAD(sin.sin_addr.s_addr), status);
1056 * Validate the NFS2/NFS3 mount data
1057 * - fills in the mount root filehandle
1059 * For option strings, user space handles the following behaviors:
1061 * + DNS: mapping server host name to IP address ("addr=" option)
1063 * + failure mode: how to behave if a mount request can't be handled
1064 * immediately ("fg/bg" option)
1066 * + retry: how often to retry a mount request ("retry=" option)
1068 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1069 * mountproto=tcp after mountproto=udp, and so on
1071 * XXX: as far as I can tell, changing the NFS program number is not
1072 * supported in the NFS client.
1074 static int nfs_validate_mount_data(void *options,
1075 struct nfs_parsed_mount_data *args,
1076 struct nfs_fh *mntfh,
1077 const char *dev_name)
1079 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
1081 memset(args, 0, sizeof(*args));
1086 args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
1087 args->rsize = NFS_MAX_FILE_IO_SIZE;
1088 args->wsize = NFS_MAX_FILE_IO_SIZE;
1092 args->acregmax = 60;
1093 args->acdirmin = 30;
1094 args->acdirmax = 60;
1095 args->mount_server.protocol = XPRT_TRANSPORT_UDP;
1096 args->mount_server.program = NFS_MNT_PROGRAM;
1097 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1098 args->nfs_server.program = NFS_PROGRAM;
1100 switch (data->version) {
1106 if (data->flags & NFS_MOUNT_VER3)
1108 data->root.size = NFS2_FHSIZE;
1109 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1111 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1114 memset(data->context, 0, sizeof(data->context));
1116 if (data->flags & NFS_MOUNT_VER3)
1117 mntfh->size = data->root.size;
1119 mntfh->size = NFS2_FHSIZE;
1121 if (mntfh->size > sizeof(mntfh->data))
1122 goto out_invalid_fh;
1124 memcpy(mntfh->data, data->root.data, mntfh->size);
1125 if (mntfh->size < sizeof(mntfh->data))
1126 memset(mntfh->data + mntfh->size, 0,
1127 sizeof(mntfh->data) - mntfh->size);
1129 if (!nfs_verify_server_address((struct sockaddr *) &data->addr))
1130 goto out_no_address;
1133 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1136 args->flags = data->flags;
1137 args->rsize = data->rsize;
1138 args->wsize = data->wsize;
1139 args->flags = data->flags;
1140 args->timeo = data->timeo;
1141 args->retrans = data->retrans;
1142 args->acregmin = data->acregmin;
1143 args->acregmax = data->acregmax;
1144 args->acdirmin = data->acdirmin;
1145 args->acdirmax = data->acdirmax;
1146 args->nfs_server.address = data->addr;
1147 if (!(data->flags & NFS_MOUNT_TCP))
1148 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1149 /* N.B. caller will free nfs_server.hostname in all cases */
1150 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1151 args->namlen = data->namlen;
1152 args->bsize = data->bsize;
1153 args->auth_flavors[0] = data->pseudoflavor;
1160 if (nfs_parse_mount_options((char *)options, args) == 0)
1163 if (!nfs_verify_server_address((struct sockaddr *)
1164 &args->nfs_server.address))
1165 goto out_no_address;
1167 c = strchr(dev_name, ':');
1171 /* N.B. caller will free nfs_server.hostname in all cases */
1172 args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL);
1175 if (strlen(c) > NFS_MAXPATHLEN)
1176 return -ENAMETOOLONG;
1177 args->nfs_server.export_path = c;
1179 status = nfs_try_mount(args, mntfh);
1187 if (!(args->flags & NFS_MOUNT_SECFLAVOUR))
1188 args->auth_flavors[0] = RPC_AUTH_UNIX;
1190 #ifndef CONFIG_NFS_V3
1191 if (args->flags & NFS_MOUNT_VER3)
1192 goto out_v3_not_compiled;
1193 #endif /* !CONFIG_NFS_V3 */
1198 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1202 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1207 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1210 #ifndef CONFIG_NFS_V3
1211 out_v3_not_compiled:
1212 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1213 return -EPROTONOSUPPORT;
1214 #endif /* !CONFIG_NFS_V3 */
1217 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1221 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1226 * Initialise the common bits of the superblock
1228 static inline void nfs_initialise_sb(struct super_block *sb)
1230 struct nfs_server *server = NFS_SB(sb);
1232 sb->s_magic = NFS_SUPER_MAGIC;
1234 /* We probably want something more informative here */
1235 snprintf(sb->s_id, sizeof(sb->s_id),
1236 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1238 if (sb->s_blocksize == 0)
1239 sb->s_blocksize = nfs_block_bits(server->wsize,
1240 &sb->s_blocksize_bits);
1242 if (server->flags & NFS_MOUNT_NOAC)
1243 sb->s_flags |= MS_SYNCHRONOUS;
1245 nfs_super_set_maxbytes(sb, server->maxfilesize);
1249 * Finish setting up an NFS2/3 superblock
1251 static void nfs_fill_super(struct super_block *sb,
1252 struct nfs_parsed_mount_data *data)
1254 struct nfs_server *server = NFS_SB(sb);
1256 sb->s_blocksize_bits = 0;
1257 sb->s_blocksize = 0;
1259 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1261 if (server->flags & NFS_MOUNT_VER3) {
1262 /* The VFS shouldn't apply the umask to mode bits. We will do
1263 * so ourselves when necessary.
1265 sb->s_flags |= MS_POSIXACL;
1266 sb->s_time_gran = 1;
1269 sb->s_op = &nfs_sops;
1270 nfs_initialise_sb(sb);
1274 * Finish setting up a cloned NFS2/3 superblock
1276 static void nfs_clone_super(struct super_block *sb,
1277 const struct super_block *old_sb)
1279 struct nfs_server *server = NFS_SB(sb);
1281 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1282 sb->s_blocksize = old_sb->s_blocksize;
1283 sb->s_maxbytes = old_sb->s_maxbytes;
1285 if (server->flags & NFS_MOUNT_VER3) {
1286 /* The VFS shouldn't apply the umask to mode bits. We will do
1287 * so ourselves when necessary.
1289 sb->s_flags |= MS_POSIXACL;
1290 sb->s_time_gran = 1;
1293 sb->s_op = old_sb->s_op;
1294 nfs_initialise_sb(sb);
1297 #define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
1299 static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
1301 const struct nfs_server *a = s->s_fs_info;
1302 const struct rpc_clnt *clnt_a = a->client;
1303 const struct rpc_clnt *clnt_b = b->client;
1305 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
1307 if (a->nfs_client != b->nfs_client)
1309 if (a->flags != b->flags)
1311 if (a->wsize != b->wsize)
1313 if (a->rsize != b->rsize)
1315 if (a->acregmin != b->acregmin)
1317 if (a->acregmax != b->acregmax)
1319 if (a->acdirmin != b->acdirmin)
1321 if (a->acdirmax != b->acdirmax)
1323 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
1330 struct nfs_sb_mountdata {
1331 struct nfs_server *server;
1335 static int nfs_set_super(struct super_block *s, void *data)
1337 struct nfs_sb_mountdata *sb_mntdata = data;
1338 struct nfs_server *server = sb_mntdata->server;
1341 s->s_flags = sb_mntdata->mntflags;
1342 s->s_fs_info = server;
1343 ret = set_anon_super(s, server);
1345 server->s_dev = s->s_dev;
1349 static int nfs_compare_super(struct super_block *sb, void *data)
1351 struct nfs_sb_mountdata *sb_mntdata = data;
1352 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
1353 int mntflags = sb_mntdata->mntflags;
1355 if (memcmp(&old->nfs_client->cl_addr,
1356 &server->nfs_client->cl_addr,
1357 sizeof(old->nfs_client->cl_addr)) != 0)
1359 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1360 if (old->flags & NFS_MOUNT_UNSHARED)
1362 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
1364 return nfs_compare_mount_options(sb, server, mntflags);
1367 static int nfs_get_sb(struct file_system_type *fs_type,
1368 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1370 struct nfs_server *server = NULL;
1371 struct super_block *s;
1372 struct nfs_fh mntfh;
1373 struct nfs_parsed_mount_data data;
1374 struct dentry *mntroot;
1375 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
1376 struct nfs_sb_mountdata sb_mntdata = {
1381 /* Validate the mount data */
1382 error = nfs_validate_mount_data(raw_data, &data, &mntfh, dev_name);
1386 /* Get a volume representation */
1387 server = nfs_create_server(&data, &mntfh);
1388 if (IS_ERR(server)) {
1389 error = PTR_ERR(server);
1392 sb_mntdata.server = server;
1394 if (server->flags & NFS_MOUNT_UNSHARED)
1395 compare_super = NULL;
1397 /* Get a superblock - note that we may end up sharing one that already exists */
1398 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
1404 if (s->s_fs_info != server) {
1405 nfs_free_server(server);
1410 /* initial superblock/root creation */
1411 nfs_fill_super(s, &data);
1414 mntroot = nfs_get_root(s, &mntfh);
1415 if (IS_ERR(mntroot)) {
1416 error = PTR_ERR(mntroot);
1417 goto error_splat_super;
1420 s->s_flags |= MS_ACTIVE;
1422 mnt->mnt_root = mntroot;
1426 kfree(data.nfs_server.hostname);
1430 nfs_free_server(server);
1434 up_write(&s->s_umount);
1435 deactivate_super(s);
1440 * Destroy an NFS2/3 superblock
1442 static void nfs_kill_super(struct super_block *s)
1444 struct nfs_server *server = NFS_SB(s);
1447 nfs_free_server(server);
1451 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
1453 static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
1454 const char *dev_name, void *raw_data,
1455 struct vfsmount *mnt)
1457 struct nfs_clone_mount *data = raw_data;
1458 struct super_block *s;
1459 struct nfs_server *server;
1460 struct dentry *mntroot;
1461 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
1462 struct nfs_sb_mountdata sb_mntdata = {
1467 dprintk("--> nfs_xdev_get_sb()\n");
1469 /* create a new volume representation */
1470 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1471 if (IS_ERR(server)) {
1472 error = PTR_ERR(server);
1473 goto out_err_noserver;
1475 sb_mntdata.server = server;
1477 if (server->flags & NFS_MOUNT_UNSHARED)
1478 compare_super = NULL;
1480 /* Get a superblock - note that we may end up sharing one that already exists */
1481 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
1487 if (s->s_fs_info != server) {
1488 nfs_free_server(server);
1493 /* initial superblock/root creation */
1494 nfs_clone_super(s, data->sb);
1497 mntroot = nfs_get_root(s, data->fh);
1498 if (IS_ERR(mntroot)) {
1499 error = PTR_ERR(mntroot);
1500 goto error_splat_super;
1502 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
1505 goto error_splat_super;
1508 s->s_flags |= MS_ACTIVE;
1510 mnt->mnt_root = mntroot;
1512 dprintk("<-- nfs_xdev_get_sb() = 0\n");
1516 nfs_free_server(server);
1518 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
1522 up_write(&s->s_umount);
1523 deactivate_super(s);
1524 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
1528 #ifdef CONFIG_NFS_V4
1531 * Finish setting up a cloned NFS4 superblock
1533 static void nfs4_clone_super(struct super_block *sb,
1534 const struct super_block *old_sb)
1536 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1537 sb->s_blocksize = old_sb->s_blocksize;
1538 sb->s_maxbytes = old_sb->s_maxbytes;
1539 sb->s_time_gran = 1;
1540 sb->s_op = old_sb->s_op;
1541 nfs_initialise_sb(sb);
1545 * Set up an NFS4 superblock
1547 static void nfs4_fill_super(struct super_block *sb)
1549 sb->s_time_gran = 1;
1550 sb->s_op = &nfs4_sops;
1551 nfs_initialise_sb(sb);
1555 * Validate NFSv4 mount options
1557 static int nfs4_validate_mount_data(void *options,
1558 struct nfs_parsed_mount_data *args,
1559 const char *dev_name)
1561 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
1564 memset(args, 0, sizeof(*args));
1569 args->rsize = NFS_MAX_FILE_IO_SIZE;
1570 args->wsize = NFS_MAX_FILE_IO_SIZE;
1574 args->acregmax = 60;
1575 args->acdirmin = 30;
1576 args->acdirmax = 60;
1577 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1579 switch (data->version) {
1581 if (data->host_addrlen != sizeof(args->nfs_server.address))
1582 goto out_no_address;
1583 if (copy_from_user(&args->nfs_server.address,
1585 sizeof(args->nfs_server.address)))
1587 if (args->nfs_server.address.sin_port == 0)
1588 args->nfs_server.address.sin_port = htons(NFS_PORT);
1589 if (!nfs_verify_server_address((struct sockaddr *)
1590 &args->nfs_server.address))
1591 goto out_no_address;
1593 switch (data->auth_flavourlen) {
1595 args->auth_flavors[0] = RPC_AUTH_UNIX;
1598 if (copy_from_user(&args->auth_flavors[0],
1599 data->auth_flavours,
1600 sizeof(args->auth_flavors[0])))
1604 goto out_inval_auth;
1607 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
1610 args->nfs_server.hostname = c;
1612 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
1615 args->nfs_server.export_path = c;
1616 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
1618 c = strndup_user(data->client_addr.data, 16);
1621 args->client_address = c;
1624 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
1628 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
1629 args->rsize = data->rsize;
1630 args->wsize = data->wsize;
1631 args->timeo = data->timeo;
1632 args->retrans = data->retrans;
1633 args->acregmin = data->acregmin;
1634 args->acregmax = data->acregmax;
1635 args->acdirmin = data->acdirmin;
1636 args->acdirmax = data->acdirmax;
1637 args->nfs_server.protocol = data->proto;
1643 if (nfs_parse_mount_options((char *)options, args) == 0)
1646 if (!nfs_verify_server_address((struct sockaddr *)
1647 &args->nfs_server.address))
1650 switch (args->auth_flavor_len) {
1652 args->auth_flavors[0] = RPC_AUTH_UNIX;
1657 goto out_inval_auth;
1661 * Split "dev_name" into "hostname:mntpath".
1663 c = strchr(dev_name, ':');
1666 /* while calculating len, pretend ':' is '\0' */
1668 if (len > NFS4_MAXNAMLEN)
1669 return -ENAMETOOLONG;
1670 args->nfs_server.hostname = kzalloc(len, GFP_KERNEL);
1671 if (args->nfs_server.hostname == NULL)
1673 strncpy(args->nfs_server.hostname, dev_name, len - 1);
1675 c++; /* step over the ':' */
1677 if (len > NFS4_MAXPATHLEN)
1678 return -ENAMETOOLONG;
1679 args->nfs_server.export_path = kzalloc(len + 1, GFP_KERNEL);
1680 if (args->nfs_server.export_path == NULL)
1682 strncpy(args->nfs_server.export_path, c, len);
1684 dprintk("MNTPATH: %s\n", args->nfs_server.export_path);
1686 if (args->client_address == NULL)
1687 goto out_no_client_address;
1696 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
1700 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
1701 data->auth_flavourlen);
1705 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
1708 out_no_client_address:
1709 dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
1714 * Get the superblock for an NFS4 mountpoint
1716 static int nfs4_get_sb(struct file_system_type *fs_type,
1717 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1719 struct nfs_parsed_mount_data data;
1720 struct super_block *s;
1721 struct nfs_server *server;
1722 struct nfs_fh mntfh;
1723 struct dentry *mntroot;
1724 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
1725 struct nfs_sb_mountdata sb_mntdata = {
1730 /* Validate the mount data */
1731 error = nfs4_validate_mount_data(raw_data, &data, dev_name);
1735 /* Get a volume representation */
1736 server = nfs4_create_server(&data, &mntfh);
1737 if (IS_ERR(server)) {
1738 error = PTR_ERR(server);
1741 sb_mntdata.server = server;
1743 if (server->flags & NFS4_MOUNT_UNSHARED)
1744 compare_super = NULL;
1746 /* Get a superblock - note that we may end up sharing one that already exists */
1747 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
1753 if (s->s_fs_info != server) {
1754 nfs_free_server(server);
1759 /* initial superblock/root creation */
1763 mntroot = nfs4_get_root(s, &mntfh);
1764 if (IS_ERR(mntroot)) {
1765 error = PTR_ERR(mntroot);
1766 goto error_splat_super;
1769 s->s_flags |= MS_ACTIVE;
1771 mnt->mnt_root = mntroot;
1775 kfree(data.client_address);
1776 kfree(data.nfs_server.export_path);
1777 kfree(data.nfs_server.hostname);
1781 nfs_free_server(server);
1785 up_write(&s->s_umount);
1786 deactivate_super(s);
1790 static void nfs4_kill_super(struct super_block *sb)
1792 struct nfs_server *server = NFS_SB(sb);
1794 nfs_return_all_delegations(sb);
1795 kill_anon_super(sb);
1797 nfs4_renewd_prepare_shutdown(server);
1798 nfs_free_server(server);
1802 * Clone an NFS4 server record on xdev traversal (FSID-change)
1804 static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
1805 const char *dev_name, void *raw_data,
1806 struct vfsmount *mnt)
1808 struct nfs_clone_mount *data = raw_data;
1809 struct super_block *s;
1810 struct nfs_server *server;
1811 struct dentry *mntroot;
1812 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
1813 struct nfs_sb_mountdata sb_mntdata = {
1818 dprintk("--> nfs4_xdev_get_sb()\n");
1820 /* create a new volume representation */
1821 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1822 if (IS_ERR(server)) {
1823 error = PTR_ERR(server);
1824 goto out_err_noserver;
1826 sb_mntdata.server = server;
1828 if (server->flags & NFS4_MOUNT_UNSHARED)
1829 compare_super = NULL;
1831 /* Get a superblock - note that we may end up sharing one that already exists */
1832 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
1838 if (s->s_fs_info != server) {
1839 nfs_free_server(server);
1844 /* initial superblock/root creation */
1845 nfs4_clone_super(s, data->sb);
1848 mntroot = nfs4_get_root(s, data->fh);
1849 if (IS_ERR(mntroot)) {
1850 error = PTR_ERR(mntroot);
1851 goto error_splat_super;
1853 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
1856 goto error_splat_super;
1859 s->s_flags |= MS_ACTIVE;
1861 mnt->mnt_root = mntroot;
1863 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
1867 nfs_free_server(server);
1869 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
1873 up_write(&s->s_umount);
1874 deactivate_super(s);
1875 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
1880 * Create an NFS4 server record on referral traversal
1882 static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
1883 const char *dev_name, void *raw_data,
1884 struct vfsmount *mnt)
1886 struct nfs_clone_mount *data = raw_data;
1887 struct super_block *s;
1888 struct nfs_server *server;
1889 struct dentry *mntroot;
1890 struct nfs_fh mntfh;
1891 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
1892 struct nfs_sb_mountdata sb_mntdata = {
1897 dprintk("--> nfs4_referral_get_sb()\n");
1899 /* create a new volume representation */
1900 server = nfs4_create_referral_server(data, &mntfh);
1901 if (IS_ERR(server)) {
1902 error = PTR_ERR(server);
1903 goto out_err_noserver;
1905 sb_mntdata.server = server;
1907 if (server->flags & NFS4_MOUNT_UNSHARED)
1908 compare_super = NULL;
1910 /* Get a superblock - note that we may end up sharing one that already exists */
1911 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
1917 if (s->s_fs_info != server) {
1918 nfs_free_server(server);
1923 /* initial superblock/root creation */
1927 mntroot = nfs4_get_root(s, &mntfh);
1928 if (IS_ERR(mntroot)) {
1929 error = PTR_ERR(mntroot);
1930 goto error_splat_super;
1932 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
1935 goto error_splat_super;
1938 s->s_flags |= MS_ACTIVE;
1940 mnt->mnt_root = mntroot;
1942 dprintk("<-- nfs4_referral_get_sb() = 0\n");
1946 nfs_free_server(server);
1948 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
1952 up_write(&s->s_umount);
1953 deactivate_super(s);
1954 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
1958 #endif /* CONFIG_NFS_V4 */