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/in6.h>
50 #include <linux/nfs_xdr.h>
51 #include <linux/magic.h>
52 #include <linux/parser.h>
54 #include <asm/system.h>
55 #include <asm/uaccess.h>
59 #include "delegation.h"
63 #define NFSDBG_FACILITY NFSDBG_VFS
66 /* Mount options that take no arguments */
69 Opt_posix, Opt_noposix,
74 Opt_udp, Opt_tcp, Opt_rdma,
76 Opt_rdirplus, Opt_nordirplus,
77 Opt_sharecache, Opt_nosharecache,
79 /* Mount options that take integer arguments */
81 Opt_rsize, Opt_wsize, Opt_bsize,
82 Opt_timeo, Opt_retrans,
83 Opt_acregmin, Opt_acregmax,
84 Opt_acdirmin, Opt_acdirmax,
91 /* Mount options that take string arguments */
92 Opt_sec, Opt_proto, Opt_mountproto,
93 Opt_addr, Opt_mountaddr, Opt_clientaddr,
95 /* Mount options that are ignored */
96 Opt_userspace, Opt_deprecated,
101 static match_table_t nfs_mount_option_tokens = {
102 { Opt_userspace, "bg" },
103 { Opt_userspace, "fg" },
104 { Opt_soft, "soft" },
105 { Opt_hard, "hard" },
106 { Opt_intr, "intr" },
107 { Opt_nointr, "nointr" },
108 { Opt_posix, "posix" },
109 { Opt_noposix, "noposix" },
111 { Opt_nocto, "nocto" },
113 { Opt_noac, "noac" },
114 { Opt_lock, "lock" },
115 { Opt_nolock, "nolock" },
120 { Opt_rdma, "rdma" },
122 { Opt_noacl, "noacl" },
123 { Opt_rdirplus, "rdirplus" },
124 { Opt_nordirplus, "nordirplus" },
125 { Opt_sharecache, "sharecache" },
126 { Opt_nosharecache, "nosharecache" },
128 { Opt_port, "port=%u" },
129 { Opt_rsize, "rsize=%u" },
130 { Opt_wsize, "wsize=%u" },
131 { Opt_bsize, "bsize=%u" },
132 { Opt_timeo, "timeo=%u" },
133 { Opt_retrans, "retrans=%u" },
134 { Opt_acregmin, "acregmin=%u" },
135 { Opt_acregmax, "acregmax=%u" },
136 { Opt_acdirmin, "acdirmin=%u" },
137 { Opt_acdirmax, "acdirmax=%u" },
138 { Opt_actimeo, "actimeo=%u" },
139 { Opt_userspace, "retry=%u" },
140 { Opt_namelen, "namlen=%u" },
141 { Opt_mountport, "mountport=%u" },
142 { Opt_mountvers, "mountvers=%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=%s",
497 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
504 * Present statistical information for this VFS mountpoint
506 static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
509 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
510 struct rpc_auth *auth = nfss->client->cl_auth;
511 struct nfs_iostats totals = { };
513 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
516 * Display all mount option settings
518 seq_printf(m, "\n\topts:\t");
519 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
520 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
521 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
522 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
523 nfs_show_mount_options(m, nfss, 1);
525 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
527 seq_printf(m, "\n\tcaps:\t");
528 seq_printf(m, "caps=0x%x", nfss->caps);
529 seq_printf(m, ",wtmult=%d", nfss->wtmult);
530 seq_printf(m, ",dtsize=%d", nfss->dtsize);
531 seq_printf(m, ",bsize=%d", nfss->bsize);
532 seq_printf(m, ",namelen=%d", nfss->namelen);
535 if (nfss->nfs_client->rpc_ops->version == 4) {
536 seq_printf(m, "\n\tnfsv4:\t");
537 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
538 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
539 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
544 * Display security flavor in effect for this mount
546 seq_printf(m, "\n\tsec:\tflavor=%d", auth->au_ops->au_flavor);
548 seq_printf(m, ",pseudoflavor=%d", auth->au_flavor);
551 * Display superblock I/O counters
553 for_each_possible_cpu(cpu) {
554 struct nfs_iostats *stats;
557 stats = per_cpu_ptr(nfss->io_stats, cpu);
559 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
560 totals.events[i] += stats->events[i];
561 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
562 totals.bytes[i] += stats->bytes[i];
567 seq_printf(m, "\n\tevents:\t");
568 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
569 seq_printf(m, "%lu ", totals.events[i]);
570 seq_printf(m, "\n\tbytes:\t");
571 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
572 seq_printf(m, "%Lu ", totals.bytes[i]);
575 rpc_print_iostats(m, nfss->client);
581 * Begin unmount by attempting to remove all automounted mountpoints we added
582 * in response to xdev traversals and referrals
584 static void nfs_umount_begin(struct vfsmount *vfsmnt, int flags)
586 struct nfs_server *server = NFS_SB(vfsmnt->mnt_sb);
587 struct rpc_clnt *rpc;
589 shrink_submounts(vfsmnt, &nfs_automount_list);
591 if (!(flags & MNT_FORCE))
593 /* -EIO all pending I/O */
594 rpc = server->client_acl;
596 rpc_killall_tasks(rpc);
597 rpc = server->client;
599 rpc_killall_tasks(rpc);
603 * Sanity-check a server address provided by the mount command
605 static int nfs_verify_server_address(struct sockaddr *addr)
607 switch (addr->sa_family) {
609 struct sockaddr_in *sa = (struct sockaddr_in *) addr;
610 if (sa->sin_addr.s_addr != INADDR_ANY)
620 * Error-check and convert a string of mount options from user space into
623 static int nfs_parse_mount_options(char *raw,
624 struct nfs_parsed_mount_data *mnt)
629 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
632 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
634 while ((p = strsep(&raw, ",")) != NULL) {
635 substring_t args[MAX_OPT_ARGS];
641 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
643 token = match_token(p, nfs_mount_option_tokens, args);
646 mnt->flags |= NFS_MOUNT_SOFT;
649 mnt->flags &= ~NFS_MOUNT_SOFT;
652 mnt->flags |= NFS_MOUNT_INTR;
655 mnt->flags &= ~NFS_MOUNT_INTR;
658 mnt->flags |= NFS_MOUNT_POSIX;
661 mnt->flags &= ~NFS_MOUNT_POSIX;
664 mnt->flags &= ~NFS_MOUNT_NOCTO;
667 mnt->flags |= NFS_MOUNT_NOCTO;
670 mnt->flags &= ~NFS_MOUNT_NOAC;
673 mnt->flags |= NFS_MOUNT_NOAC;
676 mnt->flags &= ~NFS_MOUNT_NONLM;
679 mnt->flags |= NFS_MOUNT_NONLM;
682 mnt->flags &= ~NFS_MOUNT_VER3;
685 mnt->flags |= NFS_MOUNT_VER3;
688 mnt->flags &= ~NFS_MOUNT_TCP;
689 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
694 mnt->flags |= NFS_MOUNT_TCP;
695 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
700 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
701 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
706 mnt->flags &= ~NFS_MOUNT_NOACL;
709 mnt->flags |= NFS_MOUNT_NOACL;
712 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
715 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
718 mnt->flags &= ~NFS_MOUNT_UNSHARED;
720 case Opt_nosharecache:
721 mnt->flags |= NFS_MOUNT_UNSHARED;
725 if (match_int(args, &option))
727 if (option < 0 || option > 65535)
729 mnt->nfs_server.address.sin_port = htons(option);
732 if (match_int(args, &mnt->rsize))
736 if (match_int(args, &mnt->wsize))
740 if (match_int(args, &option))
747 if (match_int(args, &mnt->timeo))
751 if (match_int(args, &mnt->retrans))
755 if (match_int(args, &mnt->acregmin))
759 if (match_int(args, &mnt->acregmax))
763 if (match_int(args, &mnt->acdirmin))
767 if (match_int(args, &mnt->acdirmax))
771 if (match_int(args, &option))
778 mnt->acdirmax = option;
781 if (match_int(args, &mnt->namlen))
785 if (match_int(args, &option))
787 if (option < 0 || option > 65535)
789 mnt->mount_server.port = option;
792 if (match_int(args, &option))
796 mnt->mount_server.version = option;
799 if (match_int(args, &option))
803 mnt->flags &= ~NFS_MOUNT_VER3;
806 mnt->flags |= NFS_MOUNT_VER3;
814 string = match_strdup(args);
817 token = match_token(string, nfs_secflavor_tokens, args);
821 * The flags setting is for v2/v3. The flavor_len
822 * setting is for v4. v2/v3 also need to know the
823 * difference between NULL and UNIX.
827 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
828 mnt->auth_flavor_len = 0;
829 mnt->auth_flavors[0] = RPC_AUTH_NULL;
832 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
833 mnt->auth_flavor_len = 0;
834 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
837 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
838 mnt->auth_flavor_len = 1;
839 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
842 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
843 mnt->auth_flavor_len = 1;
844 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
847 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
848 mnt->auth_flavor_len = 1;
849 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
852 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
853 mnt->auth_flavor_len = 1;
854 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
857 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
858 mnt->auth_flavor_len = 1;
859 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
862 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
863 mnt->auth_flavor_len = 1;
864 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
867 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
868 mnt->auth_flavor_len = 1;
869 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
872 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
873 mnt->auth_flavor_len = 1;
874 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
877 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
878 mnt->auth_flavor_len = 1;
879 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
886 string = match_strdup(args);
889 token = match_token(string,
890 nfs_xprt_protocol_tokens, args);
895 mnt->flags &= ~NFS_MOUNT_TCP;
896 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
901 mnt->flags |= NFS_MOUNT_TCP;
902 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
907 /* vector side protocols to TCP */
908 mnt->flags |= NFS_MOUNT_TCP;
909 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
918 string = match_strdup(args);
921 token = match_token(string,
922 nfs_xprt_protocol_tokens, args);
927 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
930 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
932 case Opt_xprt_rdma: /* not used for side protocols */
938 string = match_strdup(args);
941 mnt->nfs_server.address.sin_family = AF_INET;
942 mnt->nfs_server.address.sin_addr.s_addr =
947 string = match_strdup(args);
950 mnt->client_address = string;
953 string = match_strdup(args);
956 mnt->mount_server.address.sin_family = AF_INET;
957 mnt->mount_server.address.sin_addr.s_addr =
974 printk(KERN_INFO "NFS: not enough memory to parse option\n");
978 printk(KERN_INFO "NFS: unrecognized NFS version number\n");
982 printk(KERN_INFO "NFS: unrecognized transport protocol\n");
986 printk(KERN_INFO "NFS: unrecognized security flavor\n");
990 printk(KERN_INFO "NFS: unknown mount option: %s\n", p);
995 * Use the remote server's MOUNT service to request the NFS file handle
996 * corresponding to the provided path.
998 static int nfs_try_mount(struct nfs_parsed_mount_data *args,
999 struct nfs_fh *root_fh)
1001 struct sockaddr_in sin;
1004 if (args->mount_server.version == 0) {
1005 if (args->flags & NFS_MOUNT_VER3)
1006 args->mount_server.version = NFS_MNT3_VERSION;
1008 args->mount_server.version = NFS_MNT_VERSION;
1012 * Construct the mount server's address.
1014 if (args->mount_server.address.sin_addr.s_addr != INADDR_ANY)
1015 sin = args->mount_server.address;
1017 sin = args->nfs_server.address;
1019 * autobind will be used if mount_server.port == 0
1021 sin.sin_port = htons(args->mount_server.port);
1024 * Now ask the mount server to map our export path
1027 status = nfs_mount((struct sockaddr *) &sin,
1029 args->nfs_server.hostname,
1030 args->nfs_server.export_path,
1031 args->mount_server.version,
1032 args->mount_server.protocol,
1037 dfprintk(MOUNT, "NFS: unable to mount server " NIPQUAD_FMT
1038 ", error %d\n", NIPQUAD(sin.sin_addr.s_addr), status);
1043 * Validate the NFS2/NFS3 mount data
1044 * - fills in the mount root filehandle
1046 * For option strings, user space handles the following behaviors:
1048 * + DNS: mapping server host name to IP address ("addr=" option)
1050 * + failure mode: how to behave if a mount request can't be handled
1051 * immediately ("fg/bg" option)
1053 * + retry: how often to retry a mount request ("retry=" option)
1055 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1056 * mountproto=tcp after mountproto=udp, and so on
1058 static int nfs_validate_mount_data(void *options,
1059 struct nfs_parsed_mount_data *args,
1060 struct nfs_fh *mntfh,
1061 const char *dev_name)
1063 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
1065 memset(args, 0, sizeof(*args));
1070 args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
1071 args->rsize = NFS_MAX_FILE_IO_SIZE;
1072 args->wsize = NFS_MAX_FILE_IO_SIZE;
1076 args->acregmax = 60;
1077 args->acdirmin = 30;
1078 args->acdirmax = 60;
1079 args->mount_server.protocol = XPRT_TRANSPORT_UDP;
1080 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1082 switch (data->version) {
1088 if (data->flags & NFS_MOUNT_VER3)
1090 data->root.size = NFS2_FHSIZE;
1091 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1093 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1096 memset(data->context, 0, sizeof(data->context));
1098 if (data->flags & NFS_MOUNT_VER3)
1099 mntfh->size = data->root.size;
1101 mntfh->size = NFS2_FHSIZE;
1103 if (mntfh->size > sizeof(mntfh->data))
1104 goto out_invalid_fh;
1106 memcpy(mntfh->data, data->root.data, mntfh->size);
1107 if (mntfh->size < sizeof(mntfh->data))
1108 memset(mntfh->data + mntfh->size, 0,
1109 sizeof(mntfh->data) - mntfh->size);
1111 if (!nfs_verify_server_address((struct sockaddr *) &data->addr))
1112 goto out_no_address;
1115 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1118 args->flags = data->flags;
1119 args->rsize = data->rsize;
1120 args->wsize = data->wsize;
1121 args->flags = data->flags;
1122 args->timeo = data->timeo;
1123 args->retrans = data->retrans;
1124 args->acregmin = data->acregmin;
1125 args->acregmax = data->acregmax;
1126 args->acdirmin = data->acdirmin;
1127 args->acdirmax = data->acdirmax;
1128 args->nfs_server.address = data->addr;
1129 if (!(data->flags & NFS_MOUNT_TCP))
1130 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1131 /* N.B. caller will free nfs_server.hostname in all cases */
1132 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1133 args->namlen = data->namlen;
1134 args->bsize = data->bsize;
1135 args->auth_flavors[0] = data->pseudoflavor;
1142 if (nfs_parse_mount_options((char *)options, args) == 0)
1145 if (!nfs_verify_server_address((struct sockaddr *)
1146 &args->nfs_server.address))
1147 goto out_no_address;
1149 c = strchr(dev_name, ':');
1153 /* N.B. caller will free nfs_server.hostname in all cases */
1154 args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL);
1157 if (strlen(c) > NFS_MAXPATHLEN)
1158 return -ENAMETOOLONG;
1159 args->nfs_server.export_path = c;
1161 status = nfs_try_mount(args, mntfh);
1169 if (!(args->flags & NFS_MOUNT_SECFLAVOUR))
1170 args->auth_flavors[0] = RPC_AUTH_UNIX;
1172 #ifndef CONFIG_NFS_V3
1173 if (args->flags & NFS_MOUNT_VER3)
1174 goto out_v3_not_compiled;
1175 #endif /* !CONFIG_NFS_V3 */
1180 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1184 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1189 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1192 #ifndef CONFIG_NFS_V3
1193 out_v3_not_compiled:
1194 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1195 return -EPROTONOSUPPORT;
1196 #endif /* !CONFIG_NFS_V3 */
1199 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1203 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1208 * Initialise the common bits of the superblock
1210 static inline void nfs_initialise_sb(struct super_block *sb)
1212 struct nfs_server *server = NFS_SB(sb);
1214 sb->s_magic = NFS_SUPER_MAGIC;
1216 /* We probably want something more informative here */
1217 snprintf(sb->s_id, sizeof(sb->s_id),
1218 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1220 if (sb->s_blocksize == 0)
1221 sb->s_blocksize = nfs_block_bits(server->wsize,
1222 &sb->s_blocksize_bits);
1224 if (server->flags & NFS_MOUNT_NOAC)
1225 sb->s_flags |= MS_SYNCHRONOUS;
1227 nfs_super_set_maxbytes(sb, server->maxfilesize);
1231 * Finish setting up an NFS2/3 superblock
1233 static void nfs_fill_super(struct super_block *sb,
1234 struct nfs_parsed_mount_data *data)
1236 struct nfs_server *server = NFS_SB(sb);
1238 sb->s_blocksize_bits = 0;
1239 sb->s_blocksize = 0;
1241 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1243 if (server->flags & NFS_MOUNT_VER3) {
1244 /* The VFS shouldn't apply the umask to mode bits. We will do
1245 * so ourselves when necessary.
1247 sb->s_flags |= MS_POSIXACL;
1248 sb->s_time_gran = 1;
1251 sb->s_op = &nfs_sops;
1252 nfs_initialise_sb(sb);
1256 * Finish setting up a cloned NFS2/3 superblock
1258 static void nfs_clone_super(struct super_block *sb,
1259 const struct super_block *old_sb)
1261 struct nfs_server *server = NFS_SB(sb);
1263 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1264 sb->s_blocksize = old_sb->s_blocksize;
1265 sb->s_maxbytes = old_sb->s_maxbytes;
1267 if (server->flags & NFS_MOUNT_VER3) {
1268 /* The VFS shouldn't apply the umask to mode bits. We will do
1269 * so ourselves when necessary.
1271 sb->s_flags |= MS_POSIXACL;
1272 sb->s_time_gran = 1;
1275 sb->s_op = old_sb->s_op;
1276 nfs_initialise_sb(sb);
1279 #define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
1281 static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
1283 const struct nfs_server *a = s->s_fs_info;
1284 const struct rpc_clnt *clnt_a = a->client;
1285 const struct rpc_clnt *clnt_b = b->client;
1287 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
1289 if (a->nfs_client != b->nfs_client)
1291 if (a->flags != b->flags)
1293 if (a->wsize != b->wsize)
1295 if (a->rsize != b->rsize)
1297 if (a->acregmin != b->acregmin)
1299 if (a->acregmax != b->acregmax)
1301 if (a->acdirmin != b->acdirmin)
1303 if (a->acdirmax != b->acdirmax)
1305 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
1312 struct nfs_sb_mountdata {
1313 struct nfs_server *server;
1317 static int nfs_set_super(struct super_block *s, void *data)
1319 struct nfs_sb_mountdata *sb_mntdata = data;
1320 struct nfs_server *server = sb_mntdata->server;
1323 s->s_flags = sb_mntdata->mntflags;
1324 s->s_fs_info = server;
1325 ret = set_anon_super(s, server);
1327 server->s_dev = s->s_dev;
1331 static int nfs_compare_super_address(struct nfs_server *server1,
1332 struct nfs_server *server2)
1334 struct sockaddr *sap1, *sap2;
1336 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
1337 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
1339 if (sap1->sa_family != sap2->sa_family)
1342 switch (sap1->sa_family) {
1344 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
1345 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
1346 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
1348 if (sin1->sin_port != sin2->sin_port)
1353 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
1354 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
1355 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
1357 if (sin1->sin6_port != sin2->sin6_port)
1368 static int nfs_compare_super(struct super_block *sb, void *data)
1370 struct nfs_sb_mountdata *sb_mntdata = data;
1371 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
1372 int mntflags = sb_mntdata->mntflags;
1374 if (!nfs_compare_super_address(old, server))
1376 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1377 if (old->flags & NFS_MOUNT_UNSHARED)
1379 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
1381 return nfs_compare_mount_options(sb, server, mntflags);
1384 static int nfs_get_sb(struct file_system_type *fs_type,
1385 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1387 struct nfs_server *server = NULL;
1388 struct super_block *s;
1389 struct nfs_fh mntfh;
1390 struct nfs_parsed_mount_data data;
1391 struct dentry *mntroot;
1392 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
1393 struct nfs_sb_mountdata sb_mntdata = {
1398 /* Validate the mount data */
1399 error = nfs_validate_mount_data(raw_data, &data, &mntfh, dev_name);
1403 /* Get a volume representation */
1404 server = nfs_create_server(&data, &mntfh);
1405 if (IS_ERR(server)) {
1406 error = PTR_ERR(server);
1409 sb_mntdata.server = server;
1411 if (server->flags & NFS_MOUNT_UNSHARED)
1412 compare_super = NULL;
1414 /* Get a superblock - note that we may end up sharing one that already exists */
1415 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
1421 if (s->s_fs_info != server) {
1422 nfs_free_server(server);
1427 /* initial superblock/root creation */
1428 nfs_fill_super(s, &data);
1431 mntroot = nfs_get_root(s, &mntfh);
1432 if (IS_ERR(mntroot)) {
1433 error = PTR_ERR(mntroot);
1434 goto error_splat_super;
1437 s->s_flags |= MS_ACTIVE;
1439 mnt->mnt_root = mntroot;
1443 kfree(data.nfs_server.hostname);
1447 nfs_free_server(server);
1451 up_write(&s->s_umount);
1452 deactivate_super(s);
1457 * Destroy an NFS2/3 superblock
1459 static void nfs_kill_super(struct super_block *s)
1461 struct nfs_server *server = NFS_SB(s);
1464 nfs_free_server(server);
1468 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
1470 static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
1471 const char *dev_name, void *raw_data,
1472 struct vfsmount *mnt)
1474 struct nfs_clone_mount *data = raw_data;
1475 struct super_block *s;
1476 struct nfs_server *server;
1477 struct dentry *mntroot;
1478 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
1479 struct nfs_sb_mountdata sb_mntdata = {
1484 dprintk("--> nfs_xdev_get_sb()\n");
1486 /* create a new volume representation */
1487 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1488 if (IS_ERR(server)) {
1489 error = PTR_ERR(server);
1490 goto out_err_noserver;
1492 sb_mntdata.server = server;
1494 if (server->flags & NFS_MOUNT_UNSHARED)
1495 compare_super = NULL;
1497 /* Get a superblock - note that we may end up sharing one that already exists */
1498 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
1504 if (s->s_fs_info != server) {
1505 nfs_free_server(server);
1510 /* initial superblock/root creation */
1511 nfs_clone_super(s, data->sb);
1514 mntroot = nfs_get_root(s, data->fh);
1515 if (IS_ERR(mntroot)) {
1516 error = PTR_ERR(mntroot);
1517 goto error_splat_super;
1519 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
1522 goto error_splat_super;
1525 s->s_flags |= MS_ACTIVE;
1527 mnt->mnt_root = mntroot;
1529 dprintk("<-- nfs_xdev_get_sb() = 0\n");
1533 nfs_free_server(server);
1535 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
1539 up_write(&s->s_umount);
1540 deactivate_super(s);
1541 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
1545 #ifdef CONFIG_NFS_V4
1548 * Finish setting up a cloned NFS4 superblock
1550 static void nfs4_clone_super(struct super_block *sb,
1551 const struct super_block *old_sb)
1553 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1554 sb->s_blocksize = old_sb->s_blocksize;
1555 sb->s_maxbytes = old_sb->s_maxbytes;
1556 sb->s_time_gran = 1;
1557 sb->s_op = old_sb->s_op;
1558 nfs_initialise_sb(sb);
1562 * Set up an NFS4 superblock
1564 static void nfs4_fill_super(struct super_block *sb)
1566 sb->s_time_gran = 1;
1567 sb->s_op = &nfs4_sops;
1568 nfs_initialise_sb(sb);
1572 * Validate NFSv4 mount options
1574 static int nfs4_validate_mount_data(void *options,
1575 struct nfs_parsed_mount_data *args,
1576 const char *dev_name)
1578 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
1581 memset(args, 0, sizeof(*args));
1586 args->rsize = NFS_MAX_FILE_IO_SIZE;
1587 args->wsize = NFS_MAX_FILE_IO_SIZE;
1591 args->acregmax = 60;
1592 args->acdirmin = 30;
1593 args->acdirmax = 60;
1594 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1596 switch (data->version) {
1598 if (data->host_addrlen != sizeof(args->nfs_server.address))
1599 goto out_no_address;
1600 if (copy_from_user(&args->nfs_server.address,
1602 sizeof(args->nfs_server.address)))
1604 if (args->nfs_server.address.sin_port == 0)
1605 args->nfs_server.address.sin_port = htons(NFS_PORT);
1606 if (!nfs_verify_server_address((struct sockaddr *)
1607 &args->nfs_server.address))
1608 goto out_no_address;
1610 switch (data->auth_flavourlen) {
1612 args->auth_flavors[0] = RPC_AUTH_UNIX;
1615 if (copy_from_user(&args->auth_flavors[0],
1616 data->auth_flavours,
1617 sizeof(args->auth_flavors[0])))
1621 goto out_inval_auth;
1624 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
1627 args->nfs_server.hostname = c;
1629 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
1632 args->nfs_server.export_path = c;
1633 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
1635 c = strndup_user(data->client_addr.data, 16);
1638 args->client_address = c;
1641 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
1645 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
1646 args->rsize = data->rsize;
1647 args->wsize = data->wsize;
1648 args->timeo = data->timeo;
1649 args->retrans = data->retrans;
1650 args->acregmin = data->acregmin;
1651 args->acregmax = data->acregmax;
1652 args->acdirmin = data->acdirmin;
1653 args->acdirmax = data->acdirmax;
1654 args->nfs_server.protocol = data->proto;
1660 if (nfs_parse_mount_options((char *)options, args) == 0)
1663 if (args->nfs_server.address.sin_port == 0)
1664 args->nfs_server.address.sin_port = htons(NFS_PORT);
1665 if (!nfs_verify_server_address((struct sockaddr *)
1666 &args->nfs_server.address))
1669 switch (args->auth_flavor_len) {
1671 args->auth_flavors[0] = RPC_AUTH_UNIX;
1676 goto out_inval_auth;
1680 * Split "dev_name" into "hostname:mntpath".
1682 c = strchr(dev_name, ':');
1685 /* while calculating len, pretend ':' is '\0' */
1687 if (len > NFS4_MAXNAMLEN)
1688 return -ENAMETOOLONG;
1689 /* N.B. caller will free nfs_server.hostname in all cases */
1690 args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL);
1692 c++; /* step over the ':' */
1694 if (len > NFS4_MAXPATHLEN)
1695 return -ENAMETOOLONG;
1696 args->nfs_server.export_path = kstrndup(c, len, GFP_KERNEL);
1698 dprintk("NFS: MNTPATH: '%s'\n", args->nfs_server.export_path);
1700 if (args->client_address == NULL)
1701 goto out_no_client_address;
1710 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
1714 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
1715 data->auth_flavourlen);
1719 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
1722 out_no_client_address:
1723 dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
1728 * Get the superblock for an NFS4 mountpoint
1730 static int nfs4_get_sb(struct file_system_type *fs_type,
1731 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1733 struct nfs_parsed_mount_data data;
1734 struct super_block *s;
1735 struct nfs_server *server;
1736 struct nfs_fh mntfh;
1737 struct dentry *mntroot;
1738 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
1739 struct nfs_sb_mountdata sb_mntdata = {
1744 /* Validate the mount data */
1745 error = nfs4_validate_mount_data(raw_data, &data, dev_name);
1749 /* Get a volume representation */
1750 server = nfs4_create_server(&data, &mntfh);
1751 if (IS_ERR(server)) {
1752 error = PTR_ERR(server);
1755 sb_mntdata.server = server;
1757 if (server->flags & NFS4_MOUNT_UNSHARED)
1758 compare_super = NULL;
1760 /* Get a superblock - note that we may end up sharing one that already exists */
1761 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
1767 if (s->s_fs_info != server) {
1768 nfs_free_server(server);
1773 /* initial superblock/root creation */
1777 mntroot = nfs4_get_root(s, &mntfh);
1778 if (IS_ERR(mntroot)) {
1779 error = PTR_ERR(mntroot);
1780 goto error_splat_super;
1783 s->s_flags |= MS_ACTIVE;
1785 mnt->mnt_root = mntroot;
1789 kfree(data.client_address);
1790 kfree(data.nfs_server.export_path);
1791 kfree(data.nfs_server.hostname);
1795 nfs_free_server(server);
1799 up_write(&s->s_umount);
1800 deactivate_super(s);
1804 static void nfs4_kill_super(struct super_block *sb)
1806 struct nfs_server *server = NFS_SB(sb);
1808 nfs_return_all_delegations(sb);
1809 kill_anon_super(sb);
1811 nfs4_renewd_prepare_shutdown(server);
1812 nfs_free_server(server);
1816 * Clone an NFS4 server record on xdev traversal (FSID-change)
1818 static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
1819 const char *dev_name, void *raw_data,
1820 struct vfsmount *mnt)
1822 struct nfs_clone_mount *data = raw_data;
1823 struct super_block *s;
1824 struct nfs_server *server;
1825 struct dentry *mntroot;
1826 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
1827 struct nfs_sb_mountdata sb_mntdata = {
1832 dprintk("--> nfs4_xdev_get_sb()\n");
1834 /* create a new volume representation */
1835 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1836 if (IS_ERR(server)) {
1837 error = PTR_ERR(server);
1838 goto out_err_noserver;
1840 sb_mntdata.server = server;
1842 if (server->flags & NFS4_MOUNT_UNSHARED)
1843 compare_super = NULL;
1845 /* Get a superblock - note that we may end up sharing one that already exists */
1846 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
1852 if (s->s_fs_info != server) {
1853 nfs_free_server(server);
1858 /* initial superblock/root creation */
1859 nfs4_clone_super(s, data->sb);
1862 mntroot = nfs4_get_root(s, data->fh);
1863 if (IS_ERR(mntroot)) {
1864 error = PTR_ERR(mntroot);
1865 goto error_splat_super;
1867 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
1870 goto error_splat_super;
1873 s->s_flags |= MS_ACTIVE;
1875 mnt->mnt_root = mntroot;
1877 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
1881 nfs_free_server(server);
1883 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
1887 up_write(&s->s_umount);
1888 deactivate_super(s);
1889 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
1894 * Create an NFS4 server record on referral traversal
1896 static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
1897 const char *dev_name, void *raw_data,
1898 struct vfsmount *mnt)
1900 struct nfs_clone_mount *data = raw_data;
1901 struct super_block *s;
1902 struct nfs_server *server;
1903 struct dentry *mntroot;
1904 struct nfs_fh mntfh;
1905 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
1906 struct nfs_sb_mountdata sb_mntdata = {
1911 dprintk("--> nfs4_referral_get_sb()\n");
1913 /* create a new volume representation */
1914 server = nfs4_create_referral_server(data, &mntfh);
1915 if (IS_ERR(server)) {
1916 error = PTR_ERR(server);
1917 goto out_err_noserver;
1919 sb_mntdata.server = server;
1921 if (server->flags & NFS4_MOUNT_UNSHARED)
1922 compare_super = NULL;
1924 /* Get a superblock - note that we may end up sharing one that already exists */
1925 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
1931 if (s->s_fs_info != server) {
1932 nfs_free_server(server);
1937 /* initial superblock/root creation */
1941 mntroot = nfs4_get_root(s, &mntfh);
1942 if (IS_ERR(mntroot)) {
1943 error = PTR_ERR(mntroot);
1944 goto error_splat_super;
1946 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
1949 goto error_splat_super;
1952 s->s_flags |= MS_ACTIVE;
1954 mnt->mnt_root = mntroot;
1956 dprintk("<-- nfs4_referral_get_sb() = 0\n");
1960 nfs_free_server(server);
1962 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
1966 up_write(&s->s_umount);
1967 deactivate_super(s);
1968 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
1972 #endif /* CONFIG_NFS_V4 */