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 *);
206 static struct file_system_type nfs_fs_type = {
207 .owner = THIS_MODULE,
209 .get_sb = nfs_get_sb,
210 .kill_sb = nfs_kill_super,
211 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
214 struct file_system_type nfs_xdev_fs_type = {
215 .owner = THIS_MODULE,
217 .get_sb = nfs_xdev_get_sb,
218 .kill_sb = nfs_kill_super,
219 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
222 static const struct super_operations nfs_sops = {
223 .alloc_inode = nfs_alloc_inode,
224 .destroy_inode = nfs_destroy_inode,
225 .write_inode = nfs_write_inode,
226 .statfs = nfs_statfs,
227 .clear_inode = nfs_clear_inode,
228 .umount_begin = nfs_umount_begin,
229 .show_options = nfs_show_options,
230 .show_stats = nfs_show_stats,
234 static int nfs4_get_sb(struct file_system_type *fs_type,
235 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
236 static int nfs4_xdev_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_referral_get_sb(struct file_system_type *fs_type,
239 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
240 static void nfs4_kill_super(struct super_block *sb);
242 static struct file_system_type nfs4_fs_type = {
243 .owner = THIS_MODULE,
245 .get_sb = nfs4_get_sb,
246 .kill_sb = nfs4_kill_super,
247 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
250 struct file_system_type nfs4_xdev_fs_type = {
251 .owner = THIS_MODULE,
253 .get_sb = nfs4_xdev_get_sb,
254 .kill_sb = nfs4_kill_super,
255 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
258 struct file_system_type nfs4_referral_fs_type = {
259 .owner = THIS_MODULE,
261 .get_sb = nfs4_referral_get_sb,
262 .kill_sb = nfs4_kill_super,
263 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
266 static const struct super_operations nfs4_sops = {
267 .alloc_inode = nfs_alloc_inode,
268 .destroy_inode = nfs_destroy_inode,
269 .write_inode = nfs_write_inode,
270 .statfs = nfs_statfs,
271 .clear_inode = nfs4_clear_inode,
272 .umount_begin = nfs_umount_begin,
273 .show_options = nfs_show_options,
274 .show_stats = nfs_show_stats,
278 static struct shrinker acl_shrinker = {
279 .shrink = nfs_access_cache_shrinker,
280 .seeks = DEFAULT_SEEKS,
284 * Register the NFS filesystems
286 int __init register_nfs_fs(void)
290 ret = register_filesystem(&nfs_fs_type);
294 ret = nfs_register_sysctl();
298 ret = register_filesystem(&nfs4_fs_type);
302 register_shrinker(&acl_shrinker);
307 nfs_unregister_sysctl();
310 unregister_filesystem(&nfs_fs_type);
316 * Unregister the NFS filesystems
318 void __exit unregister_nfs_fs(void)
320 unregister_shrinker(&acl_shrinker);
322 unregister_filesystem(&nfs4_fs_type);
324 nfs_unregister_sysctl();
325 unregister_filesystem(&nfs_fs_type);
329 * Deliver file system statistics to userspace
331 static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
333 struct nfs_server *server = NFS_SB(dentry->d_sb);
334 unsigned char blockbits;
335 unsigned long blockres;
336 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
337 struct nfs_fattr fattr;
338 struct nfs_fsstat res = {
345 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
348 buf->f_type = NFS_SUPER_MAGIC;
351 * Current versions of glibc do not correctly handle the
352 * case where f_frsize != f_bsize. Eventually we want to
353 * report the value of wtmult in this field.
355 buf->f_frsize = dentry->d_sb->s_blocksize;
358 * On most *nix systems, f_blocks, f_bfree, and f_bavail
359 * are reported in units of f_frsize. Linux hasn't had
360 * an f_frsize field in its statfs struct until recently,
361 * thus historically Linux's sys_statfs reports these
362 * fields in units of f_bsize.
364 buf->f_bsize = dentry->d_sb->s_blocksize;
365 blockbits = dentry->d_sb->s_blocksize_bits;
366 blockres = (1 << blockbits) - 1;
367 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
368 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
369 buf->f_bavail = (res.abytes + blockres) >> blockbits;
371 buf->f_files = res.tfiles;
372 buf->f_ffree = res.afiles;
374 buf->f_namelen = server->namelen;
380 dprintk("%s: statfs error = %d\n", __FUNCTION__, -error);
386 * Map the security flavour number to a name
388 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
390 static const struct {
391 rpc_authflavor_t flavour;
394 { RPC_AUTH_NULL, "null" },
395 { RPC_AUTH_UNIX, "sys" },
396 { RPC_AUTH_GSS_KRB5, "krb5" },
397 { RPC_AUTH_GSS_KRB5I, "krb5i" },
398 { RPC_AUTH_GSS_KRB5P, "krb5p" },
399 { RPC_AUTH_GSS_LKEY, "lkey" },
400 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
401 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
402 { RPC_AUTH_GSS_SPKM, "spkm" },
403 { RPC_AUTH_GSS_SPKMI, "spkmi" },
404 { RPC_AUTH_GSS_SPKMP, "spkmp" },
405 { UINT_MAX, "unknown" }
409 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
410 if (sec_flavours[i].flavour == flavour)
413 return sec_flavours[i].str;
417 * Describe the mount options in force on this server representation
419 static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss, int showdefaults)
421 static const struct proc_nfs_info {
426 { NFS_MOUNT_SOFT, ",soft", ",hard" },
427 { NFS_MOUNT_INTR, ",intr", ",nointr" },
428 { NFS_MOUNT_NOCTO, ",nocto", "" },
429 { NFS_MOUNT_NOAC, ",noac", "" },
430 { NFS_MOUNT_NONLM, ",nolock", "" },
431 { NFS_MOUNT_NOACL, ",noacl", "" },
432 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
433 { NFS_MOUNT_UNSHARED, ",nosharecache", ""},
436 const struct proc_nfs_info *nfs_infop;
437 struct nfs_client *clp = nfss->nfs_client;
439 seq_printf(m, ",vers=%d", clp->rpc_ops->version);
440 seq_printf(m, ",rsize=%d", nfss->rsize);
441 seq_printf(m, ",wsize=%d", nfss->wsize);
442 if (nfss->acregmin != 3*HZ || showdefaults)
443 seq_printf(m, ",acregmin=%d", nfss->acregmin/HZ);
444 if (nfss->acregmax != 60*HZ || showdefaults)
445 seq_printf(m, ",acregmax=%d", nfss->acregmax/HZ);
446 if (nfss->acdirmin != 30*HZ || showdefaults)
447 seq_printf(m, ",acdirmin=%d", nfss->acdirmin/HZ);
448 if (nfss->acdirmax != 60*HZ || showdefaults)
449 seq_printf(m, ",acdirmax=%d", nfss->acdirmax/HZ);
450 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
451 if (nfss->flags & nfs_infop->flag)
452 seq_puts(m, nfs_infop->str);
454 seq_puts(m, nfs_infop->nostr);
456 seq_printf(m, ",proto=%s",
457 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_PROTO));
458 seq_printf(m, ",timeo=%lu", 10U * clp->retrans_timeo / HZ);
459 seq_printf(m, ",retrans=%u", clp->retrans_count);
460 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
464 * Describe the mount options on this VFS mountpoint
466 static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
468 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
470 nfs_show_mount_options(m, nfss, 0);
472 seq_printf(m, ",addr="NIPQUAD_FMT,
473 NIPQUAD(nfss->nfs_client->cl_addr.sin_addr));
479 * Present statistical information for this VFS mountpoint
481 static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
484 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
485 struct rpc_auth *auth = nfss->client->cl_auth;
486 struct nfs_iostats totals = { };
488 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
491 * Display all mount option settings
493 seq_printf(m, "\n\topts:\t");
494 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
495 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
496 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
497 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
498 nfs_show_mount_options(m, nfss, 1);
500 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
502 seq_printf(m, "\n\tcaps:\t");
503 seq_printf(m, "caps=0x%x", nfss->caps);
504 seq_printf(m, ",wtmult=%d", nfss->wtmult);
505 seq_printf(m, ",dtsize=%d", nfss->dtsize);
506 seq_printf(m, ",bsize=%d", nfss->bsize);
507 seq_printf(m, ",namelen=%d", nfss->namelen);
510 if (nfss->nfs_client->cl_nfsversion == 4) {
511 seq_printf(m, "\n\tnfsv4:\t");
512 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
513 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
514 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
519 * Display security flavor in effect for this mount
521 seq_printf(m, "\n\tsec:\tflavor=%d", auth->au_ops->au_flavor);
523 seq_printf(m, ",pseudoflavor=%d", auth->au_flavor);
526 * Display superblock I/O counters
528 for_each_possible_cpu(cpu) {
529 struct nfs_iostats *stats;
532 stats = per_cpu_ptr(nfss->io_stats, cpu);
534 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
535 totals.events[i] += stats->events[i];
536 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
537 totals.bytes[i] += stats->bytes[i];
542 seq_printf(m, "\n\tevents:\t");
543 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
544 seq_printf(m, "%lu ", totals.events[i]);
545 seq_printf(m, "\n\tbytes:\t");
546 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
547 seq_printf(m, "%Lu ", totals.bytes[i]);
550 rpc_print_iostats(m, nfss->client);
556 * Begin unmount by attempting to remove all automounted mountpoints we added
557 * in response to xdev traversals and referrals
559 static void nfs_umount_begin(struct vfsmount *vfsmnt, int flags)
561 struct nfs_server *server = NFS_SB(vfsmnt->mnt_sb);
562 struct rpc_clnt *rpc;
564 shrink_submounts(vfsmnt, &nfs_automount_list);
566 if (!(flags & MNT_FORCE))
568 /* -EIO all pending I/O */
569 rpc = server->client_acl;
571 rpc_killall_tasks(rpc);
572 rpc = server->client;
574 rpc_killall_tasks(rpc);
578 * Sanity-check a server address provided by the mount command
580 static int nfs_verify_server_address(struct sockaddr *addr)
582 switch (addr->sa_family) {
584 struct sockaddr_in *sa = (struct sockaddr_in *) addr;
585 if (sa->sin_addr.s_addr != INADDR_ANY)
595 * Error-check and convert a string of mount options from user space into
598 static int nfs_parse_mount_options(char *raw,
599 struct nfs_parsed_mount_data *mnt)
604 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
607 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
609 while ((p = strsep(&raw, ",")) != NULL) {
610 substring_t args[MAX_OPT_ARGS];
616 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
618 token = match_token(p, nfs_mount_option_tokens, args);
621 mnt->flags |= NFS_MOUNT_SOFT;
624 mnt->flags &= ~NFS_MOUNT_SOFT;
627 mnt->flags |= NFS_MOUNT_INTR;
630 mnt->flags &= ~NFS_MOUNT_INTR;
633 mnt->flags |= NFS_MOUNT_POSIX;
636 mnt->flags &= ~NFS_MOUNT_POSIX;
639 mnt->flags &= ~NFS_MOUNT_NOCTO;
642 mnt->flags |= NFS_MOUNT_NOCTO;
645 mnt->flags &= ~NFS_MOUNT_NOAC;
648 mnt->flags |= NFS_MOUNT_NOAC;
651 mnt->flags &= ~NFS_MOUNT_NONLM;
654 mnt->flags |= NFS_MOUNT_NONLM;
657 mnt->flags &= ~NFS_MOUNT_VER3;
660 mnt->flags |= NFS_MOUNT_VER3;
663 mnt->flags &= ~NFS_MOUNT_TCP;
664 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
669 mnt->flags |= NFS_MOUNT_TCP;
670 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
675 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
676 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
681 mnt->flags &= ~NFS_MOUNT_NOACL;
684 mnt->flags |= NFS_MOUNT_NOACL;
687 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
690 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
693 mnt->flags &= ~NFS_MOUNT_UNSHARED;
695 case Opt_nosharecache:
696 mnt->flags |= NFS_MOUNT_UNSHARED;
700 if (match_int(args, &option))
702 if (option < 0 || option > 65535)
704 mnt->nfs_server.address.sin_port = htons(option);
707 if (match_int(args, &mnt->rsize))
711 if (match_int(args, &mnt->wsize))
715 if (match_int(args, &option))
722 if (match_int(args, &mnt->timeo))
726 if (match_int(args, &mnt->retrans))
730 if (match_int(args, &mnt->acregmin))
734 if (match_int(args, &mnt->acregmax))
738 if (match_int(args, &mnt->acdirmin))
742 if (match_int(args, &mnt->acdirmax))
746 if (match_int(args, &option))
753 mnt->acdirmax = option;
756 if (match_int(args, &mnt->namlen))
760 if (match_int(args, &option))
762 if (option < 0 || option > 65535)
764 mnt->mount_server.port = option;
767 if (match_int(args, &option))
771 mnt->mount_server.program = option;
774 if (match_int(args, &option))
778 mnt->mount_server.version = option;
781 if (match_int(args, &option))
785 mnt->nfs_server.program = option;
788 if (match_int(args, &option))
792 mnt->flags &= ~NFS_MOUNT_VER3;
795 mnt->flags |= NFS_MOUNT_VER3;
803 string = match_strdup(args);
806 token = match_token(string, nfs_secflavor_tokens, args);
810 * The flags setting is for v2/v3. The flavor_len
811 * setting is for v4. v2/v3 also need to know the
812 * difference between NULL and UNIX.
816 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
817 mnt->auth_flavor_len = 0;
818 mnt->auth_flavors[0] = RPC_AUTH_NULL;
821 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
822 mnt->auth_flavor_len = 0;
823 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
826 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
827 mnt->auth_flavor_len = 1;
828 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
831 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
832 mnt->auth_flavor_len = 1;
833 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
836 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
837 mnt->auth_flavor_len = 1;
838 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
841 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
842 mnt->auth_flavor_len = 1;
843 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
846 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
847 mnt->auth_flavor_len = 1;
848 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
851 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
852 mnt->auth_flavor_len = 1;
853 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
856 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
857 mnt->auth_flavor_len = 1;
858 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
861 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
862 mnt->auth_flavor_len = 1;
863 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
866 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
867 mnt->auth_flavor_len = 1;
868 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
875 string = match_strdup(args);
878 token = match_token(string,
879 nfs_xprt_protocol_tokens, args);
884 mnt->flags &= ~NFS_MOUNT_TCP;
885 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
890 mnt->flags |= NFS_MOUNT_TCP;
891 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
896 /* vector side protocols to TCP */
897 mnt->flags |= NFS_MOUNT_TCP;
898 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
907 string = match_strdup(args);
910 token = match_token(string,
911 nfs_xprt_protocol_tokens, args);
916 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
919 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
921 case Opt_xprt_rdma: /* not used for side protocols */
927 string = match_strdup(args);
930 mnt->nfs_server.address.sin_family = AF_INET;
931 mnt->nfs_server.address.sin_addr.s_addr =
936 string = match_strdup(args);
939 mnt->client_address = string;
942 string = match_strdup(args);
945 mnt->mount_server.address.sin_family = AF_INET;
946 mnt->mount_server.address.sin_addr.s_addr =
963 printk(KERN_INFO "NFS: not enough memory to parse option\n");
967 printk(KERN_INFO "NFS: unrecognized NFS version number\n");
971 printk(KERN_INFO "NFS: unrecognized transport protocol\n");
975 printk(KERN_INFO "NFS: unrecognized security flavor\n");
979 printk(KERN_INFO "NFS: unknown mount option: %s\n", p);
984 * Use the remote server's MOUNT service to request the NFS file handle
985 * corresponding to the provided path.
987 static int nfs_try_mount(struct nfs_parsed_mount_data *args,
988 struct nfs_fh *root_fh)
990 struct sockaddr_in sin;
993 if (args->mount_server.version == 0) {
994 if (args->flags & NFS_MOUNT_VER3)
995 args->mount_server.version = NFS_MNT3_VERSION;
997 args->mount_server.version = NFS_MNT_VERSION;
1001 * Construct the mount server's address.
1003 if (args->mount_server.address.sin_addr.s_addr != INADDR_ANY)
1004 sin = args->mount_server.address;
1006 sin = args->nfs_server.address;
1008 * autobind will be used if mount_server.port == 0
1010 sin.sin_port = htons(args->mount_server.port);
1013 * Now ask the mount server to map our export path
1016 status = nfs_mount((struct sockaddr *) &sin,
1018 args->nfs_server.hostname,
1019 args->nfs_server.export_path,
1020 args->mount_server.version,
1021 args->mount_server.protocol,
1026 dfprintk(MOUNT, "NFS: unable to mount server " NIPQUAD_FMT
1027 ", error %d\n", NIPQUAD(sin.sin_addr.s_addr), status);
1032 * Validate the NFS2/NFS3 mount data
1033 * - fills in the mount root filehandle
1035 * For option strings, user space handles the following behaviors:
1037 * + DNS: mapping server host name to IP address ("addr=" option)
1039 * + failure mode: how to behave if a mount request can't be handled
1040 * immediately ("fg/bg" option)
1042 * + retry: how often to retry a mount request ("retry=" option)
1044 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1045 * mountproto=tcp after mountproto=udp, and so on
1047 * XXX: as far as I can tell, changing the NFS program number is not
1048 * supported in the NFS client.
1050 static int nfs_validate_mount_data(void *options,
1051 struct nfs_parsed_mount_data *args,
1052 struct nfs_fh *mntfh,
1053 const char *dev_name)
1055 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
1060 memset(args, 0, sizeof(*args));
1061 args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
1062 args->rsize = NFS_MAX_FILE_IO_SIZE;
1063 args->wsize = NFS_MAX_FILE_IO_SIZE;
1067 args->acregmax = 60;
1068 args->acdirmin = 30;
1069 args->acdirmax = 60;
1070 args->mount_server.protocol = XPRT_TRANSPORT_UDP;
1071 args->mount_server.program = NFS_MNT_PROGRAM;
1072 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1073 args->nfs_server.program = NFS_PROGRAM;
1075 switch (data->version) {
1081 if (data->flags & NFS_MOUNT_VER3)
1083 data->root.size = NFS2_FHSIZE;
1084 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1086 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1089 memset(data->context, 0, sizeof(data->context));
1091 if (data->flags & NFS_MOUNT_VER3)
1092 mntfh->size = data->root.size;
1094 mntfh->size = NFS2_FHSIZE;
1096 if (mntfh->size > sizeof(mntfh->data))
1097 goto out_invalid_fh;
1099 memcpy(mntfh->data, data->root.data, mntfh->size);
1100 if (mntfh->size < sizeof(mntfh->data))
1101 memset(mntfh->data + mntfh->size, 0,
1102 sizeof(mntfh->data) - mntfh->size);
1104 if (!nfs_verify_server_address((struct sockaddr *) &data->addr))
1105 goto out_no_address;
1108 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1111 args->flags = data->flags;
1112 args->rsize = data->rsize;
1113 args->wsize = data->wsize;
1114 args->flags = data->flags;
1115 args->timeo = data->timeo;
1116 args->retrans = data->retrans;
1117 args->acregmin = data->acregmin;
1118 args->acregmax = data->acregmax;
1119 args->acdirmin = data->acdirmin;
1120 args->acdirmax = data->acdirmax;
1121 args->nfs_server.address = data->addr;
1122 if (!(data->flags & NFS_MOUNT_TCP))
1123 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1124 /* N.B. caller will free nfs_server.hostname in all cases */
1125 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1126 args->namlen = data->namlen;
1127 args->bsize = data->bsize;
1128 args->auth_flavors[0] = data->pseudoflavor;
1135 if (nfs_parse_mount_options((char *)options, args) == 0)
1138 if (!nfs_verify_server_address((struct sockaddr *)
1139 &args->nfs_server.address))
1140 goto out_no_address;
1142 c = strchr(dev_name, ':');
1146 /* N.B. caller will free nfs_server.hostname in all cases */
1147 args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL);
1150 if (strlen(c) > NFS_MAXPATHLEN)
1151 return -ENAMETOOLONG;
1152 args->nfs_server.export_path = c;
1154 status = nfs_try_mount(args, mntfh);
1162 if (!(args->flags & NFS_MOUNT_SECFLAVOUR))
1163 args->auth_flavors[0] = RPC_AUTH_UNIX;
1165 #ifndef CONFIG_NFS_V3
1166 if (args->flags & NFS_MOUNT_VER3)
1167 goto out_v3_not_compiled;
1168 #endif /* !CONFIG_NFS_V3 */
1173 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1177 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1182 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1185 #ifndef CONFIG_NFS_V3
1186 out_v3_not_compiled:
1187 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1188 return -EPROTONOSUPPORT;
1189 #endif /* !CONFIG_NFS_V3 */
1192 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1196 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1201 * Initialise the common bits of the superblock
1203 static inline void nfs_initialise_sb(struct super_block *sb)
1205 struct nfs_server *server = NFS_SB(sb);
1207 sb->s_magic = NFS_SUPER_MAGIC;
1209 /* We probably want something more informative here */
1210 snprintf(sb->s_id, sizeof(sb->s_id),
1211 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1213 if (sb->s_blocksize == 0)
1214 sb->s_blocksize = nfs_block_bits(server->wsize,
1215 &sb->s_blocksize_bits);
1217 if (server->flags & NFS_MOUNT_NOAC)
1218 sb->s_flags |= MS_SYNCHRONOUS;
1220 nfs_super_set_maxbytes(sb, server->maxfilesize);
1224 * Finish setting up an NFS2/3 superblock
1226 static void nfs_fill_super(struct super_block *sb,
1227 struct nfs_parsed_mount_data *data)
1229 struct nfs_server *server = NFS_SB(sb);
1231 sb->s_blocksize_bits = 0;
1232 sb->s_blocksize = 0;
1234 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1236 if (server->flags & NFS_MOUNT_VER3) {
1237 /* The VFS shouldn't apply the umask to mode bits. We will do
1238 * so ourselves when necessary.
1240 sb->s_flags |= MS_POSIXACL;
1241 sb->s_time_gran = 1;
1244 sb->s_op = &nfs_sops;
1245 nfs_initialise_sb(sb);
1249 * Finish setting up a cloned NFS2/3 superblock
1251 static void nfs_clone_super(struct super_block *sb,
1252 const struct super_block *old_sb)
1254 struct nfs_server *server = NFS_SB(sb);
1256 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1257 sb->s_blocksize = old_sb->s_blocksize;
1258 sb->s_maxbytes = old_sb->s_maxbytes;
1260 if (server->flags & NFS_MOUNT_VER3) {
1261 /* The VFS shouldn't apply the umask to mode bits. We will do
1262 * so ourselves when necessary.
1264 sb->s_flags |= MS_POSIXACL;
1265 sb->s_time_gran = 1;
1268 sb->s_op = old_sb->s_op;
1269 nfs_initialise_sb(sb);
1272 #define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
1274 static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
1276 const struct nfs_server *a = s->s_fs_info;
1277 const struct rpc_clnt *clnt_a = a->client;
1278 const struct rpc_clnt *clnt_b = b->client;
1280 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
1282 if (a->nfs_client != b->nfs_client)
1284 if (a->flags != b->flags)
1286 if (a->wsize != b->wsize)
1288 if (a->rsize != b->rsize)
1290 if (a->acregmin != b->acregmin)
1292 if (a->acregmax != b->acregmax)
1294 if (a->acdirmin != b->acdirmin)
1296 if (a->acdirmax != b->acdirmax)
1298 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
1305 struct nfs_sb_mountdata {
1306 struct nfs_server *server;
1310 static int nfs_set_super(struct super_block *s, void *data)
1312 struct nfs_sb_mountdata *sb_mntdata = data;
1313 struct nfs_server *server = sb_mntdata->server;
1316 s->s_flags = sb_mntdata->mntflags;
1317 s->s_fs_info = server;
1318 ret = set_anon_super(s, server);
1320 server->s_dev = s->s_dev;
1324 static int nfs_compare_super(struct super_block *sb, void *data)
1326 struct nfs_sb_mountdata *sb_mntdata = data;
1327 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
1328 int mntflags = sb_mntdata->mntflags;
1330 if (memcmp(&old->nfs_client->cl_addr,
1331 &server->nfs_client->cl_addr,
1332 sizeof(old->nfs_client->cl_addr)) != 0)
1334 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1335 if (old->flags & NFS_MOUNT_UNSHARED)
1337 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
1339 return nfs_compare_mount_options(sb, server, mntflags);
1342 static int nfs_get_sb(struct file_system_type *fs_type,
1343 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1345 struct nfs_server *server = NULL;
1346 struct super_block *s;
1347 struct nfs_fh mntfh;
1348 struct nfs_parsed_mount_data data;
1349 struct dentry *mntroot;
1350 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
1351 struct nfs_sb_mountdata sb_mntdata = {
1356 /* Validate the mount data */
1357 error = nfs_validate_mount_data(raw_data, &data, &mntfh, dev_name);
1361 /* Get a volume representation */
1362 server = nfs_create_server(&data, &mntfh);
1363 if (IS_ERR(server)) {
1364 error = PTR_ERR(server);
1367 sb_mntdata.server = server;
1369 if (server->flags & NFS_MOUNT_UNSHARED)
1370 compare_super = NULL;
1372 /* Get a superblock - note that we may end up sharing one that already exists */
1373 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
1379 if (s->s_fs_info != server) {
1380 nfs_free_server(server);
1385 /* initial superblock/root creation */
1386 nfs_fill_super(s, &data);
1389 mntroot = nfs_get_root(s, &mntfh);
1390 if (IS_ERR(mntroot)) {
1391 error = PTR_ERR(mntroot);
1392 goto error_splat_super;
1395 s->s_flags |= MS_ACTIVE;
1397 mnt->mnt_root = mntroot;
1401 kfree(data.nfs_server.hostname);
1405 nfs_free_server(server);
1409 up_write(&s->s_umount);
1410 deactivate_super(s);
1415 * Destroy an NFS2/3 superblock
1417 static void nfs_kill_super(struct super_block *s)
1419 struct nfs_server *server = NFS_SB(s);
1422 nfs_free_server(server);
1426 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
1428 static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
1429 const char *dev_name, void *raw_data,
1430 struct vfsmount *mnt)
1432 struct nfs_clone_mount *data = raw_data;
1433 struct super_block *s;
1434 struct nfs_server *server;
1435 struct dentry *mntroot;
1436 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
1437 struct nfs_sb_mountdata sb_mntdata = {
1442 dprintk("--> nfs_xdev_get_sb()\n");
1444 /* create a new volume representation */
1445 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1446 if (IS_ERR(server)) {
1447 error = PTR_ERR(server);
1448 goto out_err_noserver;
1450 sb_mntdata.server = server;
1452 if (server->flags & NFS_MOUNT_UNSHARED)
1453 compare_super = NULL;
1455 /* Get a superblock - note that we may end up sharing one that already exists */
1456 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
1462 if (s->s_fs_info != server) {
1463 nfs_free_server(server);
1468 /* initial superblock/root creation */
1469 nfs_clone_super(s, data->sb);
1472 mntroot = nfs_get_root(s, data->fh);
1473 if (IS_ERR(mntroot)) {
1474 error = PTR_ERR(mntroot);
1475 goto error_splat_super;
1478 s->s_flags |= MS_ACTIVE;
1480 mnt->mnt_root = mntroot;
1482 dprintk("<-- nfs_xdev_get_sb() = 0\n");
1486 nfs_free_server(server);
1488 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
1492 up_write(&s->s_umount);
1493 deactivate_super(s);
1494 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
1498 #ifdef CONFIG_NFS_V4
1501 * Finish setting up a cloned NFS4 superblock
1503 static void nfs4_clone_super(struct super_block *sb,
1504 const struct super_block *old_sb)
1506 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1507 sb->s_blocksize = old_sb->s_blocksize;
1508 sb->s_maxbytes = old_sb->s_maxbytes;
1509 sb->s_time_gran = 1;
1510 sb->s_op = old_sb->s_op;
1511 nfs_initialise_sb(sb);
1515 * Set up an NFS4 superblock
1517 static void nfs4_fill_super(struct super_block *sb)
1519 sb->s_time_gran = 1;
1520 sb->s_op = &nfs4_sops;
1521 nfs_initialise_sb(sb);
1525 * Validate NFSv4 mount options
1527 static int nfs4_validate_mount_data(void *options,
1528 struct nfs_parsed_mount_data *args,
1529 const char *dev_name)
1531 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
1537 memset(args, 0, sizeof(*args));
1538 args->rsize = NFS_MAX_FILE_IO_SIZE;
1539 args->wsize = NFS_MAX_FILE_IO_SIZE;
1543 args->acregmax = 60;
1544 args->acdirmin = 30;
1545 args->acdirmax = 60;
1546 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1548 switch (data->version) {
1550 if (data->host_addrlen != sizeof(args->nfs_server.address))
1551 goto out_no_address;
1552 if (copy_from_user(&args->nfs_server.address,
1554 sizeof(args->nfs_server.address)))
1556 if (args->nfs_server.address.sin_port == 0)
1557 args->nfs_server.address.sin_port = htons(NFS_PORT);
1558 if (!nfs_verify_server_address((struct sockaddr *)
1559 &args->nfs_server.address))
1560 goto out_no_address;
1562 switch (data->auth_flavourlen) {
1564 args->auth_flavors[0] = RPC_AUTH_UNIX;
1567 if (copy_from_user(&args->auth_flavors[0],
1568 data->auth_flavours,
1569 sizeof(args->auth_flavors[0])))
1573 goto out_inval_auth;
1576 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
1579 args->nfs_server.hostname = c;
1581 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
1584 args->nfs_server.export_path = c;
1585 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
1587 c = strndup_user(data->client_addr.data, 16);
1590 args->client_address = c;
1593 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
1597 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
1598 args->rsize = data->rsize;
1599 args->wsize = data->wsize;
1600 args->timeo = data->timeo;
1601 args->retrans = data->retrans;
1602 args->acregmin = data->acregmin;
1603 args->acregmax = data->acregmax;
1604 args->acdirmin = data->acdirmin;
1605 args->acdirmax = data->acdirmax;
1606 args->nfs_server.protocol = data->proto;
1612 if (nfs_parse_mount_options((char *)options, args) == 0)
1615 if (!nfs_verify_server_address((struct sockaddr *)
1616 &args->nfs_server.address))
1619 switch (args->auth_flavor_len) {
1621 args->auth_flavors[0] = RPC_AUTH_UNIX;
1626 goto out_inval_auth;
1630 * Split "dev_name" into "hostname:mntpath".
1632 c = strchr(dev_name, ':');
1635 /* while calculating len, pretend ':' is '\0' */
1637 if (len > NFS4_MAXNAMLEN)
1638 return -ENAMETOOLONG;
1639 args->nfs_server.hostname = kzalloc(len, GFP_KERNEL);
1640 if (args->nfs_server.hostname == NULL)
1642 strncpy(args->nfs_server.hostname, dev_name, len - 1);
1644 c++; /* step over the ':' */
1646 if (len > NFS4_MAXPATHLEN)
1647 return -ENAMETOOLONG;
1648 args->nfs_server.export_path = kzalloc(len + 1, GFP_KERNEL);
1649 if (args->nfs_server.export_path == NULL)
1651 strncpy(args->nfs_server.export_path, c, len);
1653 dprintk("MNTPATH: %s\n", args->nfs_server.export_path);
1655 if (args->client_address == NULL)
1656 goto out_no_client_address;
1665 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
1669 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
1670 data->auth_flavourlen);
1674 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
1677 out_no_client_address:
1678 dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
1683 * Get the superblock for an NFS4 mountpoint
1685 static int nfs4_get_sb(struct file_system_type *fs_type,
1686 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1688 struct nfs_parsed_mount_data data;
1689 struct super_block *s;
1690 struct nfs_server *server;
1691 struct nfs_fh mntfh;
1692 struct dentry *mntroot;
1693 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
1694 struct nfs_sb_mountdata sb_mntdata = {
1699 /* Validate the mount data */
1700 error = nfs4_validate_mount_data(raw_data, &data, dev_name);
1704 /* Get a volume representation */
1705 server = nfs4_create_server(&data, &mntfh);
1706 if (IS_ERR(server)) {
1707 error = PTR_ERR(server);
1710 sb_mntdata.server = server;
1712 if (server->flags & NFS4_MOUNT_UNSHARED)
1713 compare_super = NULL;
1715 /* Get a superblock - note that we may end up sharing one that already exists */
1716 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
1722 if (s->s_fs_info != server) {
1723 nfs_free_server(server);
1728 /* initial superblock/root creation */
1732 mntroot = nfs4_get_root(s, &mntfh);
1733 if (IS_ERR(mntroot)) {
1734 error = PTR_ERR(mntroot);
1735 goto error_splat_super;
1738 s->s_flags |= MS_ACTIVE;
1740 mnt->mnt_root = mntroot;
1744 kfree(data.client_address);
1745 kfree(data.nfs_server.export_path);
1746 kfree(data.nfs_server.hostname);
1750 nfs_free_server(server);
1754 up_write(&s->s_umount);
1755 deactivate_super(s);
1759 static void nfs4_kill_super(struct super_block *sb)
1761 struct nfs_server *server = NFS_SB(sb);
1763 nfs_return_all_delegations(sb);
1764 kill_anon_super(sb);
1766 nfs4_renewd_prepare_shutdown(server);
1767 nfs_free_server(server);
1771 * Clone an NFS4 server record on xdev traversal (FSID-change)
1773 static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
1774 const char *dev_name, void *raw_data,
1775 struct vfsmount *mnt)
1777 struct nfs_clone_mount *data = raw_data;
1778 struct super_block *s;
1779 struct nfs_server *server;
1780 struct dentry *mntroot;
1781 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
1782 struct nfs_sb_mountdata sb_mntdata = {
1787 dprintk("--> nfs4_xdev_get_sb()\n");
1789 /* create a new volume representation */
1790 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1791 if (IS_ERR(server)) {
1792 error = PTR_ERR(server);
1793 goto out_err_noserver;
1795 sb_mntdata.server = server;
1797 if (server->flags & NFS4_MOUNT_UNSHARED)
1798 compare_super = NULL;
1800 /* Get a superblock - note that we may end up sharing one that already exists */
1801 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
1807 if (s->s_fs_info != server) {
1808 nfs_free_server(server);
1813 /* initial superblock/root creation */
1814 nfs4_clone_super(s, data->sb);
1817 mntroot = nfs4_get_root(s, data->fh);
1818 if (IS_ERR(mntroot)) {
1819 error = PTR_ERR(mntroot);
1820 goto error_splat_super;
1823 s->s_flags |= MS_ACTIVE;
1825 mnt->mnt_root = mntroot;
1827 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
1831 nfs_free_server(server);
1833 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
1837 up_write(&s->s_umount);
1838 deactivate_super(s);
1839 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
1844 * Create an NFS4 server record on referral traversal
1846 static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
1847 const char *dev_name, void *raw_data,
1848 struct vfsmount *mnt)
1850 struct nfs_clone_mount *data = raw_data;
1851 struct super_block *s;
1852 struct nfs_server *server;
1853 struct dentry *mntroot;
1854 struct nfs_fh mntfh;
1855 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
1856 struct nfs_sb_mountdata sb_mntdata = {
1861 dprintk("--> nfs4_referral_get_sb()\n");
1863 /* create a new volume representation */
1864 server = nfs4_create_referral_server(data, &mntfh);
1865 if (IS_ERR(server)) {
1866 error = PTR_ERR(server);
1867 goto out_err_noserver;
1869 sb_mntdata.server = server;
1871 if (server->flags & NFS4_MOUNT_UNSHARED)
1872 compare_super = NULL;
1874 /* Get a superblock - note that we may end up sharing one that already exists */
1875 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
1881 if (s->s_fs_info != server) {
1882 nfs_free_server(server);
1887 /* initial superblock/root creation */
1891 mntroot = nfs4_get_root(s, &mntfh);
1892 if (IS_ERR(mntroot)) {
1893 error = PTR_ERR(mntroot);
1894 goto error_splat_super;
1897 s->s_flags |= MS_ACTIVE;
1899 mnt->mnt_root = mntroot;
1901 dprintk("<-- nfs4_referral_get_sb() = 0\n");
1905 nfs_free_server(server);
1907 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
1911 up_write(&s->s_umount);
1912 deactivate_super(s);
1913 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
1917 #endif /* CONFIG_NFS_V4 */