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,
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_mountvers, "mountvers=%u" },
141 { Opt_nfsvers, "nfsvers=%u" },
142 { Opt_nfsvers, "vers=%u" },
144 { Opt_sec, "sec=%s" },
145 { Opt_proto, "proto=%s" },
146 { Opt_mountproto, "mountproto=%s" },
147 { Opt_addr, "addr=%s" },
148 { Opt_clientaddr, "clientaddr=%s" },
149 { Opt_userspace, "mounthost=%s" },
150 { Opt_mountaddr, "mountaddr=%s" },
156 Opt_xprt_udp, Opt_xprt_tcp, Opt_xprt_rdma,
161 static match_table_t nfs_xprt_protocol_tokens = {
162 { Opt_xprt_udp, "udp" },
163 { Opt_xprt_tcp, "tcp" },
164 { Opt_xprt_rdma, "rdma" },
166 { Opt_xprt_err, NULL }
170 Opt_sec_none, Opt_sec_sys,
171 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
172 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
173 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
178 static match_table_t nfs_secflavor_tokens = {
179 { Opt_sec_none, "none" },
180 { Opt_sec_none, "null" },
181 { Opt_sec_sys, "sys" },
183 { Opt_sec_krb5, "krb5" },
184 { Opt_sec_krb5i, "krb5i" },
185 { Opt_sec_krb5p, "krb5p" },
187 { Opt_sec_lkey, "lkey" },
188 { Opt_sec_lkeyi, "lkeyi" },
189 { Opt_sec_lkeyp, "lkeyp" },
191 { Opt_sec_err, NULL }
195 static void nfs_umount_begin(struct vfsmount *, int);
196 static int nfs_statfs(struct dentry *, struct kstatfs *);
197 static int nfs_show_options(struct seq_file *, struct vfsmount *);
198 static int nfs_show_stats(struct seq_file *, struct vfsmount *);
199 static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
200 static int nfs_xdev_get_sb(struct file_system_type *fs_type,
201 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
202 static void nfs_kill_super(struct super_block *);
203 static void nfs_put_super(struct super_block *);
205 static struct file_system_type nfs_fs_type = {
206 .owner = THIS_MODULE,
208 .get_sb = nfs_get_sb,
209 .kill_sb = nfs_kill_super,
210 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
213 struct file_system_type nfs_xdev_fs_type = {
214 .owner = THIS_MODULE,
216 .get_sb = nfs_xdev_get_sb,
217 .kill_sb = nfs_kill_super,
218 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
221 static const struct super_operations nfs_sops = {
222 .alloc_inode = nfs_alloc_inode,
223 .destroy_inode = nfs_destroy_inode,
224 .write_inode = nfs_write_inode,
225 .put_super = nfs_put_super,
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);
328 void nfs_sb_active(struct nfs_server *server)
330 atomic_inc(&server->active);
333 void nfs_sb_deactive(struct nfs_server *server)
335 if (atomic_dec_and_test(&server->active))
336 wake_up(&server->active_wq);
339 static void nfs_put_super(struct super_block *sb)
341 struct nfs_server *server = NFS_SB(sb);
343 * Make sure there are no outstanding ops to this server.
344 * If so, wait for them to finish before allowing the
345 * unmount to continue.
347 wait_event(server->active_wq, atomic_read(&server->active) == 0);
351 * Deliver file system statistics to userspace
353 static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
355 struct nfs_server *server = NFS_SB(dentry->d_sb);
356 unsigned char blockbits;
357 unsigned long blockres;
358 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
359 struct nfs_fattr fattr;
360 struct nfs_fsstat res = {
367 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
370 buf->f_type = NFS_SUPER_MAGIC;
373 * Current versions of glibc do not correctly handle the
374 * case where f_frsize != f_bsize. Eventually we want to
375 * report the value of wtmult in this field.
377 buf->f_frsize = dentry->d_sb->s_blocksize;
380 * On most *nix systems, f_blocks, f_bfree, and f_bavail
381 * are reported in units of f_frsize. Linux hasn't had
382 * an f_frsize field in its statfs struct until recently,
383 * thus historically Linux's sys_statfs reports these
384 * fields in units of f_bsize.
386 buf->f_bsize = dentry->d_sb->s_blocksize;
387 blockbits = dentry->d_sb->s_blocksize_bits;
388 blockres = (1 << blockbits) - 1;
389 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
390 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
391 buf->f_bavail = (res.abytes + blockres) >> blockbits;
393 buf->f_files = res.tfiles;
394 buf->f_ffree = res.afiles;
396 buf->f_namelen = server->namelen;
402 dprintk("%s: statfs error = %d\n", __FUNCTION__, -error);
408 * Map the security flavour number to a name
410 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
412 static const struct {
413 rpc_authflavor_t flavour;
416 { RPC_AUTH_NULL, "null" },
417 { RPC_AUTH_UNIX, "sys" },
418 { RPC_AUTH_GSS_KRB5, "krb5" },
419 { RPC_AUTH_GSS_KRB5I, "krb5i" },
420 { RPC_AUTH_GSS_KRB5P, "krb5p" },
421 { RPC_AUTH_GSS_LKEY, "lkey" },
422 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
423 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
424 { RPC_AUTH_GSS_SPKM, "spkm" },
425 { RPC_AUTH_GSS_SPKMI, "spkmi" },
426 { RPC_AUTH_GSS_SPKMP, "spkmp" },
427 { UINT_MAX, "unknown" }
431 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
432 if (sec_flavours[i].flavour == flavour)
435 return sec_flavours[i].str;
439 * Describe the mount options in force on this server representation
441 static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss, int showdefaults)
443 static const struct proc_nfs_info {
448 { NFS_MOUNT_SOFT, ",soft", ",hard" },
449 { NFS_MOUNT_INTR, ",intr", ",nointr" },
450 { NFS_MOUNT_NOCTO, ",nocto", "" },
451 { NFS_MOUNT_NOAC, ",noac", "" },
452 { NFS_MOUNT_NONLM, ",nolock", "" },
453 { NFS_MOUNT_NOACL, ",noacl", "" },
454 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
455 { NFS_MOUNT_UNSHARED, ",nosharecache", ""},
458 const struct proc_nfs_info *nfs_infop;
459 struct nfs_client *clp = nfss->nfs_client;
461 seq_printf(m, ",vers=%d", clp->rpc_ops->version);
462 seq_printf(m, ",rsize=%d", nfss->rsize);
463 seq_printf(m, ",wsize=%d", nfss->wsize);
464 if (nfss->acregmin != 3*HZ || showdefaults)
465 seq_printf(m, ",acregmin=%d", nfss->acregmin/HZ);
466 if (nfss->acregmax != 60*HZ || showdefaults)
467 seq_printf(m, ",acregmax=%d", nfss->acregmax/HZ);
468 if (nfss->acdirmin != 30*HZ || showdefaults)
469 seq_printf(m, ",acdirmin=%d", nfss->acdirmin/HZ);
470 if (nfss->acdirmax != 60*HZ || showdefaults)
471 seq_printf(m, ",acdirmax=%d", nfss->acdirmax/HZ);
472 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
473 if (nfss->flags & nfs_infop->flag)
474 seq_puts(m, nfs_infop->str);
476 seq_puts(m, nfs_infop->nostr);
478 seq_printf(m, ",proto=%s",
479 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_PROTO));
480 seq_printf(m, ",timeo=%lu", 10U * clp->retrans_timeo / HZ);
481 seq_printf(m, ",retrans=%u", clp->retrans_count);
482 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
486 * Describe the mount options on this VFS mountpoint
488 static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
490 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
492 nfs_show_mount_options(m, nfss, 0);
494 seq_printf(m, ",addr="NIPQUAD_FMT,
495 NIPQUAD(nfss->nfs_client->cl_addr.sin_addr));
501 * Present statistical information for this VFS mountpoint
503 static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
506 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
507 struct rpc_auth *auth = nfss->client->cl_auth;
508 struct nfs_iostats totals = { };
510 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
513 * Display all mount option settings
515 seq_printf(m, "\n\topts:\t");
516 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
517 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
518 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
519 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
520 nfs_show_mount_options(m, nfss, 1);
522 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
524 seq_printf(m, "\n\tcaps:\t");
525 seq_printf(m, "caps=0x%x", nfss->caps);
526 seq_printf(m, ",wtmult=%d", nfss->wtmult);
527 seq_printf(m, ",dtsize=%d", nfss->dtsize);
528 seq_printf(m, ",bsize=%d", nfss->bsize);
529 seq_printf(m, ",namelen=%d", nfss->namelen);
532 if (nfss->nfs_client->cl_nfsversion == 4) {
533 seq_printf(m, "\n\tnfsv4:\t");
534 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
535 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
536 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
541 * Display security flavor in effect for this mount
543 seq_printf(m, "\n\tsec:\tflavor=%d", auth->au_ops->au_flavor);
545 seq_printf(m, ",pseudoflavor=%d", auth->au_flavor);
548 * Display superblock I/O counters
550 for_each_possible_cpu(cpu) {
551 struct nfs_iostats *stats;
554 stats = per_cpu_ptr(nfss->io_stats, cpu);
556 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
557 totals.events[i] += stats->events[i];
558 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
559 totals.bytes[i] += stats->bytes[i];
564 seq_printf(m, "\n\tevents:\t");
565 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
566 seq_printf(m, "%lu ", totals.events[i]);
567 seq_printf(m, "\n\tbytes:\t");
568 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
569 seq_printf(m, "%Lu ", totals.bytes[i]);
572 rpc_print_iostats(m, nfss->client);
578 * Begin unmount by attempting to remove all automounted mountpoints we added
579 * in response to xdev traversals and referrals
581 static void nfs_umount_begin(struct vfsmount *vfsmnt, int flags)
583 struct nfs_server *server = NFS_SB(vfsmnt->mnt_sb);
584 struct rpc_clnt *rpc;
586 shrink_submounts(vfsmnt, &nfs_automount_list);
588 if (!(flags & MNT_FORCE))
590 /* -EIO all pending I/O */
591 rpc = server->client_acl;
593 rpc_killall_tasks(rpc);
594 rpc = server->client;
596 rpc_killall_tasks(rpc);
600 * Sanity-check a server address provided by the mount command
602 static int nfs_verify_server_address(struct sockaddr *addr)
604 switch (addr->sa_family) {
606 struct sockaddr_in *sa = (struct sockaddr_in *) addr;
607 if (sa->sin_addr.s_addr != INADDR_ANY)
617 * Error-check and convert a string of mount options from user space into
620 static int nfs_parse_mount_options(char *raw,
621 struct nfs_parsed_mount_data *mnt)
626 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
629 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
631 while ((p = strsep(&raw, ",")) != NULL) {
632 substring_t args[MAX_OPT_ARGS];
638 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
640 token = match_token(p, nfs_mount_option_tokens, args);
643 mnt->flags |= NFS_MOUNT_SOFT;
646 mnt->flags &= ~NFS_MOUNT_SOFT;
649 mnt->flags |= NFS_MOUNT_INTR;
652 mnt->flags &= ~NFS_MOUNT_INTR;
655 mnt->flags |= NFS_MOUNT_POSIX;
658 mnt->flags &= ~NFS_MOUNT_POSIX;
661 mnt->flags &= ~NFS_MOUNT_NOCTO;
664 mnt->flags |= NFS_MOUNT_NOCTO;
667 mnt->flags &= ~NFS_MOUNT_NOAC;
670 mnt->flags |= NFS_MOUNT_NOAC;
673 mnt->flags &= ~NFS_MOUNT_NONLM;
676 mnt->flags |= NFS_MOUNT_NONLM;
679 mnt->flags &= ~NFS_MOUNT_VER3;
682 mnt->flags |= NFS_MOUNT_VER3;
685 mnt->flags &= ~NFS_MOUNT_TCP;
686 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
691 mnt->flags |= NFS_MOUNT_TCP;
692 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
697 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
698 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
703 mnt->flags &= ~NFS_MOUNT_NOACL;
706 mnt->flags |= NFS_MOUNT_NOACL;
709 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
712 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
715 mnt->flags &= ~NFS_MOUNT_UNSHARED;
717 case Opt_nosharecache:
718 mnt->flags |= NFS_MOUNT_UNSHARED;
722 if (match_int(args, &option))
724 if (option < 0 || option > 65535)
726 mnt->nfs_server.address.sin_port = htons(option);
729 if (match_int(args, &mnt->rsize))
733 if (match_int(args, &mnt->wsize))
737 if (match_int(args, &option))
744 if (match_int(args, &mnt->timeo))
748 if (match_int(args, &mnt->retrans))
752 if (match_int(args, &mnt->acregmin))
756 if (match_int(args, &mnt->acregmax))
760 if (match_int(args, &mnt->acdirmin))
764 if (match_int(args, &mnt->acdirmax))
768 if (match_int(args, &option))
775 mnt->acdirmax = option;
778 if (match_int(args, &mnt->namlen))
782 if (match_int(args, &option))
784 if (option < 0 || option > 65535)
786 mnt->mount_server.port = option;
789 if (match_int(args, &option))
793 mnt->mount_server.version = option;
796 if (match_int(args, &option))
800 mnt->flags &= ~NFS_MOUNT_VER3;
803 mnt->flags |= NFS_MOUNT_VER3;
811 string = match_strdup(args);
814 token = match_token(string, nfs_secflavor_tokens, args);
818 * The flags setting is for v2/v3. The flavor_len
819 * setting is for v4. v2/v3 also need to know the
820 * difference between NULL and UNIX.
824 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
825 mnt->auth_flavor_len = 0;
826 mnt->auth_flavors[0] = RPC_AUTH_NULL;
829 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
830 mnt->auth_flavor_len = 0;
831 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
834 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
835 mnt->auth_flavor_len = 1;
836 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
839 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
840 mnt->auth_flavor_len = 1;
841 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
844 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
845 mnt->auth_flavor_len = 1;
846 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
849 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
850 mnt->auth_flavor_len = 1;
851 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
854 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
855 mnt->auth_flavor_len = 1;
856 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
859 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
860 mnt->auth_flavor_len = 1;
861 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
864 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
865 mnt->auth_flavor_len = 1;
866 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
869 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
870 mnt->auth_flavor_len = 1;
871 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
874 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
875 mnt->auth_flavor_len = 1;
876 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
883 string = match_strdup(args);
886 token = match_token(string,
887 nfs_xprt_protocol_tokens, args);
892 mnt->flags &= ~NFS_MOUNT_TCP;
893 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
898 mnt->flags |= NFS_MOUNT_TCP;
899 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
904 /* vector side protocols to TCP */
905 mnt->flags |= NFS_MOUNT_TCP;
906 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
915 string = match_strdup(args);
918 token = match_token(string,
919 nfs_xprt_protocol_tokens, args);
924 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
927 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
929 case Opt_xprt_rdma: /* not used for side protocols */
935 string = match_strdup(args);
938 mnt->nfs_server.address.sin_family = AF_INET;
939 mnt->nfs_server.address.sin_addr.s_addr =
944 string = match_strdup(args);
947 mnt->client_address = string;
950 string = match_strdup(args);
953 mnt->mount_server.address.sin_family = AF_INET;
954 mnt->mount_server.address.sin_addr.s_addr =
971 printk(KERN_INFO "NFS: not enough memory to parse option\n");
975 printk(KERN_INFO "NFS: unrecognized NFS version number\n");
979 printk(KERN_INFO "NFS: unrecognized transport protocol\n");
983 printk(KERN_INFO "NFS: unrecognized security flavor\n");
987 printk(KERN_INFO "NFS: unknown mount option: %s\n", p);
992 * Use the remote server's MOUNT service to request the NFS file handle
993 * corresponding to the provided path.
995 static int nfs_try_mount(struct nfs_parsed_mount_data *args,
996 struct nfs_fh *root_fh)
998 struct sockaddr_in sin;
1001 if (args->mount_server.version == 0) {
1002 if (args->flags & NFS_MOUNT_VER3)
1003 args->mount_server.version = NFS_MNT3_VERSION;
1005 args->mount_server.version = NFS_MNT_VERSION;
1009 * Construct the mount server's address.
1011 if (args->mount_server.address.sin_addr.s_addr != INADDR_ANY)
1012 sin = args->mount_server.address;
1014 sin = args->nfs_server.address;
1016 * autobind will be used if mount_server.port == 0
1018 sin.sin_port = htons(args->mount_server.port);
1021 * Now ask the mount server to map our export path
1024 status = nfs_mount((struct sockaddr *) &sin,
1026 args->nfs_server.hostname,
1027 args->nfs_server.export_path,
1028 args->mount_server.version,
1029 args->mount_server.protocol,
1034 dfprintk(MOUNT, "NFS: unable to mount server " NIPQUAD_FMT
1035 ", error %d\n", NIPQUAD(sin.sin_addr.s_addr), status);
1040 * Validate the NFS2/NFS3 mount data
1041 * - fills in the mount root filehandle
1043 * For option strings, user space handles the following behaviors:
1045 * + DNS: mapping server host name to IP address ("addr=" option)
1047 * + failure mode: how to behave if a mount request can't be handled
1048 * immediately ("fg/bg" option)
1050 * + retry: how often to retry a mount request ("retry=" option)
1052 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1053 * mountproto=tcp after mountproto=udp, and so on
1055 static int nfs_validate_mount_data(void *options,
1056 struct nfs_parsed_mount_data *args,
1057 struct nfs_fh *mntfh,
1058 const char *dev_name)
1060 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
1062 memset(args, 0, sizeof(*args));
1067 args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
1068 args->rsize = NFS_MAX_FILE_IO_SIZE;
1069 args->wsize = NFS_MAX_FILE_IO_SIZE;
1073 args->acregmax = 60;
1074 args->acdirmin = 30;
1075 args->acdirmax = 60;
1076 args->mount_server.protocol = XPRT_TRANSPORT_UDP;
1077 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1079 switch (data->version) {
1085 if (data->flags & NFS_MOUNT_VER3)
1087 data->root.size = NFS2_FHSIZE;
1088 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1090 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1093 memset(data->context, 0, sizeof(data->context));
1095 if (data->flags & NFS_MOUNT_VER3)
1096 mntfh->size = data->root.size;
1098 mntfh->size = NFS2_FHSIZE;
1100 if (mntfh->size > sizeof(mntfh->data))
1101 goto out_invalid_fh;
1103 memcpy(mntfh->data, data->root.data, mntfh->size);
1104 if (mntfh->size < sizeof(mntfh->data))
1105 memset(mntfh->data + mntfh->size, 0,
1106 sizeof(mntfh->data) - mntfh->size);
1108 if (!nfs_verify_server_address((struct sockaddr *) &data->addr))
1109 goto out_no_address;
1112 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1115 args->flags = data->flags;
1116 args->rsize = data->rsize;
1117 args->wsize = data->wsize;
1118 args->flags = data->flags;
1119 args->timeo = data->timeo;
1120 args->retrans = data->retrans;
1121 args->acregmin = data->acregmin;
1122 args->acregmax = data->acregmax;
1123 args->acdirmin = data->acdirmin;
1124 args->acdirmax = data->acdirmax;
1125 args->nfs_server.address = data->addr;
1126 if (!(data->flags & NFS_MOUNT_TCP))
1127 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1128 /* N.B. caller will free nfs_server.hostname in all cases */
1129 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1130 args->namlen = data->namlen;
1131 args->bsize = data->bsize;
1132 args->auth_flavors[0] = data->pseudoflavor;
1139 if (nfs_parse_mount_options((char *)options, args) == 0)
1142 if (!nfs_verify_server_address((struct sockaddr *)
1143 &args->nfs_server.address))
1144 goto out_no_address;
1146 c = strchr(dev_name, ':');
1150 /* N.B. caller will free nfs_server.hostname in all cases */
1151 args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL);
1154 if (strlen(c) > NFS_MAXPATHLEN)
1155 return -ENAMETOOLONG;
1156 args->nfs_server.export_path = c;
1158 status = nfs_try_mount(args, mntfh);
1166 if (!(args->flags & NFS_MOUNT_SECFLAVOUR))
1167 args->auth_flavors[0] = RPC_AUTH_UNIX;
1169 #ifndef CONFIG_NFS_V3
1170 if (args->flags & NFS_MOUNT_VER3)
1171 goto out_v3_not_compiled;
1172 #endif /* !CONFIG_NFS_V3 */
1177 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1181 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1186 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1189 #ifndef CONFIG_NFS_V3
1190 out_v3_not_compiled:
1191 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1192 return -EPROTONOSUPPORT;
1193 #endif /* !CONFIG_NFS_V3 */
1196 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1200 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1205 * Initialise the common bits of the superblock
1207 static inline void nfs_initialise_sb(struct super_block *sb)
1209 struct nfs_server *server = NFS_SB(sb);
1211 sb->s_magic = NFS_SUPER_MAGIC;
1213 /* We probably want something more informative here */
1214 snprintf(sb->s_id, sizeof(sb->s_id),
1215 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1217 if (sb->s_blocksize == 0)
1218 sb->s_blocksize = nfs_block_bits(server->wsize,
1219 &sb->s_blocksize_bits);
1221 if (server->flags & NFS_MOUNT_NOAC)
1222 sb->s_flags |= MS_SYNCHRONOUS;
1224 nfs_super_set_maxbytes(sb, server->maxfilesize);
1228 * Finish setting up an NFS2/3 superblock
1230 static void nfs_fill_super(struct super_block *sb,
1231 struct nfs_parsed_mount_data *data)
1233 struct nfs_server *server = NFS_SB(sb);
1235 sb->s_blocksize_bits = 0;
1236 sb->s_blocksize = 0;
1238 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1240 if (server->flags & NFS_MOUNT_VER3) {
1241 /* The VFS shouldn't apply the umask to mode bits. We will do
1242 * so ourselves when necessary.
1244 sb->s_flags |= MS_POSIXACL;
1245 sb->s_time_gran = 1;
1248 sb->s_op = &nfs_sops;
1249 nfs_initialise_sb(sb);
1253 * Finish setting up a cloned NFS2/3 superblock
1255 static void nfs_clone_super(struct super_block *sb,
1256 const struct super_block *old_sb)
1258 struct nfs_server *server = NFS_SB(sb);
1260 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1261 sb->s_blocksize = old_sb->s_blocksize;
1262 sb->s_maxbytes = old_sb->s_maxbytes;
1264 if (server->flags & NFS_MOUNT_VER3) {
1265 /* The VFS shouldn't apply the umask to mode bits. We will do
1266 * so ourselves when necessary.
1268 sb->s_flags |= MS_POSIXACL;
1269 sb->s_time_gran = 1;
1272 sb->s_op = old_sb->s_op;
1273 nfs_initialise_sb(sb);
1276 #define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
1278 static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
1280 const struct nfs_server *a = s->s_fs_info;
1281 const struct rpc_clnt *clnt_a = a->client;
1282 const struct rpc_clnt *clnt_b = b->client;
1284 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
1286 if (a->nfs_client != b->nfs_client)
1288 if (a->flags != b->flags)
1290 if (a->wsize != b->wsize)
1292 if (a->rsize != b->rsize)
1294 if (a->acregmin != b->acregmin)
1296 if (a->acregmax != b->acregmax)
1298 if (a->acdirmin != b->acdirmin)
1300 if (a->acdirmax != b->acdirmax)
1302 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
1309 struct nfs_sb_mountdata {
1310 struct nfs_server *server;
1314 static int nfs_set_super(struct super_block *s, void *data)
1316 struct nfs_sb_mountdata *sb_mntdata = data;
1317 struct nfs_server *server = sb_mntdata->server;
1320 s->s_flags = sb_mntdata->mntflags;
1321 s->s_fs_info = server;
1322 ret = set_anon_super(s, server);
1324 server->s_dev = s->s_dev;
1328 static int nfs_compare_super(struct super_block *sb, void *data)
1330 struct nfs_sb_mountdata *sb_mntdata = data;
1331 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
1332 int mntflags = sb_mntdata->mntflags;
1334 if (memcmp(&old->nfs_client->cl_addr,
1335 &server->nfs_client->cl_addr,
1336 sizeof(old->nfs_client->cl_addr)) != 0)
1338 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1339 if (old->flags & NFS_MOUNT_UNSHARED)
1341 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
1343 return nfs_compare_mount_options(sb, server, mntflags);
1346 static int nfs_get_sb(struct file_system_type *fs_type,
1347 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1349 struct nfs_server *server = NULL;
1350 struct super_block *s;
1351 struct nfs_fh mntfh;
1352 struct nfs_parsed_mount_data data;
1353 struct dentry *mntroot;
1354 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
1355 struct nfs_sb_mountdata sb_mntdata = {
1360 /* Validate the mount data */
1361 error = nfs_validate_mount_data(raw_data, &data, &mntfh, dev_name);
1365 /* Get a volume representation */
1366 server = nfs_create_server(&data, &mntfh);
1367 if (IS_ERR(server)) {
1368 error = PTR_ERR(server);
1371 sb_mntdata.server = server;
1373 if (server->flags & NFS_MOUNT_UNSHARED)
1374 compare_super = NULL;
1376 /* Get a superblock - note that we may end up sharing one that already exists */
1377 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
1383 if (s->s_fs_info != server) {
1384 nfs_free_server(server);
1389 /* initial superblock/root creation */
1390 nfs_fill_super(s, &data);
1393 mntroot = nfs_get_root(s, &mntfh);
1394 if (IS_ERR(mntroot)) {
1395 error = PTR_ERR(mntroot);
1396 goto error_splat_super;
1399 s->s_flags |= MS_ACTIVE;
1401 mnt->mnt_root = mntroot;
1405 kfree(data.nfs_server.hostname);
1409 nfs_free_server(server);
1413 up_write(&s->s_umount);
1414 deactivate_super(s);
1419 * Destroy an NFS2/3 superblock
1421 static void nfs_kill_super(struct super_block *s)
1423 struct nfs_server *server = NFS_SB(s);
1426 nfs_free_server(server);
1430 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
1432 static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
1433 const char *dev_name, void *raw_data,
1434 struct vfsmount *mnt)
1436 struct nfs_clone_mount *data = raw_data;
1437 struct super_block *s;
1438 struct nfs_server *server;
1439 struct dentry *mntroot;
1440 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
1441 struct nfs_sb_mountdata sb_mntdata = {
1446 dprintk("--> nfs_xdev_get_sb()\n");
1448 /* create a new volume representation */
1449 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1450 if (IS_ERR(server)) {
1451 error = PTR_ERR(server);
1452 goto out_err_noserver;
1454 sb_mntdata.server = server;
1456 if (server->flags & NFS_MOUNT_UNSHARED)
1457 compare_super = NULL;
1459 /* Get a superblock - note that we may end up sharing one that already exists */
1460 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
1466 if (s->s_fs_info != server) {
1467 nfs_free_server(server);
1472 /* initial superblock/root creation */
1473 nfs_clone_super(s, data->sb);
1476 mntroot = nfs_get_root(s, data->fh);
1477 if (IS_ERR(mntroot)) {
1478 error = PTR_ERR(mntroot);
1479 goto error_splat_super;
1481 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
1484 goto error_splat_super;
1487 s->s_flags |= MS_ACTIVE;
1489 mnt->mnt_root = mntroot;
1491 dprintk("<-- nfs_xdev_get_sb() = 0\n");
1495 nfs_free_server(server);
1497 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
1501 up_write(&s->s_umount);
1502 deactivate_super(s);
1503 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
1507 #ifdef CONFIG_NFS_V4
1510 * Finish setting up a cloned NFS4 superblock
1512 static void nfs4_clone_super(struct super_block *sb,
1513 const struct super_block *old_sb)
1515 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1516 sb->s_blocksize = old_sb->s_blocksize;
1517 sb->s_maxbytes = old_sb->s_maxbytes;
1518 sb->s_time_gran = 1;
1519 sb->s_op = old_sb->s_op;
1520 nfs_initialise_sb(sb);
1524 * Set up an NFS4 superblock
1526 static void nfs4_fill_super(struct super_block *sb)
1528 sb->s_time_gran = 1;
1529 sb->s_op = &nfs4_sops;
1530 nfs_initialise_sb(sb);
1534 * Validate NFSv4 mount options
1536 static int nfs4_validate_mount_data(void *options,
1537 struct nfs_parsed_mount_data *args,
1538 const char *dev_name)
1540 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
1543 memset(args, 0, sizeof(*args));
1548 args->rsize = NFS_MAX_FILE_IO_SIZE;
1549 args->wsize = NFS_MAX_FILE_IO_SIZE;
1553 args->acregmax = 60;
1554 args->acdirmin = 30;
1555 args->acdirmax = 60;
1556 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1558 switch (data->version) {
1560 if (data->host_addrlen != sizeof(args->nfs_server.address))
1561 goto out_no_address;
1562 if (copy_from_user(&args->nfs_server.address,
1564 sizeof(args->nfs_server.address)))
1566 if (args->nfs_server.address.sin_port == 0)
1567 args->nfs_server.address.sin_port = htons(NFS_PORT);
1568 if (!nfs_verify_server_address((struct sockaddr *)
1569 &args->nfs_server.address))
1570 goto out_no_address;
1572 switch (data->auth_flavourlen) {
1574 args->auth_flavors[0] = RPC_AUTH_UNIX;
1577 if (copy_from_user(&args->auth_flavors[0],
1578 data->auth_flavours,
1579 sizeof(args->auth_flavors[0])))
1583 goto out_inval_auth;
1586 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
1589 args->nfs_server.hostname = c;
1591 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
1594 args->nfs_server.export_path = c;
1595 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
1597 c = strndup_user(data->client_addr.data, 16);
1600 args->client_address = c;
1603 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
1607 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
1608 args->rsize = data->rsize;
1609 args->wsize = data->wsize;
1610 args->timeo = data->timeo;
1611 args->retrans = data->retrans;
1612 args->acregmin = data->acregmin;
1613 args->acregmax = data->acregmax;
1614 args->acdirmin = data->acdirmin;
1615 args->acdirmax = data->acdirmax;
1616 args->nfs_server.protocol = data->proto;
1622 if (nfs_parse_mount_options((char *)options, args) == 0)
1625 if (args->nfs_server.address.sin_port == 0)
1626 args->nfs_server.address.sin_port = htons(NFS_PORT);
1627 if (!nfs_verify_server_address((struct sockaddr *)
1628 &args->nfs_server.address))
1631 switch (args->auth_flavor_len) {
1633 args->auth_flavors[0] = RPC_AUTH_UNIX;
1638 goto out_inval_auth;
1642 * Split "dev_name" into "hostname:mntpath".
1644 c = strchr(dev_name, ':');
1647 /* while calculating len, pretend ':' is '\0' */
1649 if (len > NFS4_MAXNAMLEN)
1650 return -ENAMETOOLONG;
1651 args->nfs_server.hostname = kzalloc(len, GFP_KERNEL);
1652 if (args->nfs_server.hostname == NULL)
1654 strncpy(args->nfs_server.hostname, dev_name, len - 1);
1656 c++; /* step over the ':' */
1658 if (len > NFS4_MAXPATHLEN)
1659 return -ENAMETOOLONG;
1660 args->nfs_server.export_path = kzalloc(len + 1, GFP_KERNEL);
1661 if (args->nfs_server.export_path == NULL)
1663 strncpy(args->nfs_server.export_path, c, len);
1665 dprintk("MNTPATH: %s\n", args->nfs_server.export_path);
1667 if (args->client_address == NULL)
1668 goto out_no_client_address;
1677 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
1681 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
1682 data->auth_flavourlen);
1686 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
1689 out_no_client_address:
1690 dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
1695 * Get the superblock for an NFS4 mountpoint
1697 static int nfs4_get_sb(struct file_system_type *fs_type,
1698 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1700 struct nfs_parsed_mount_data data;
1701 struct super_block *s;
1702 struct nfs_server *server;
1703 struct nfs_fh mntfh;
1704 struct dentry *mntroot;
1705 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
1706 struct nfs_sb_mountdata sb_mntdata = {
1711 /* Validate the mount data */
1712 error = nfs4_validate_mount_data(raw_data, &data, dev_name);
1716 /* Get a volume representation */
1717 server = nfs4_create_server(&data, &mntfh);
1718 if (IS_ERR(server)) {
1719 error = PTR_ERR(server);
1722 sb_mntdata.server = server;
1724 if (server->flags & NFS4_MOUNT_UNSHARED)
1725 compare_super = NULL;
1727 /* Get a superblock - note that we may end up sharing one that already exists */
1728 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
1734 if (s->s_fs_info != server) {
1735 nfs_free_server(server);
1740 /* initial superblock/root creation */
1744 mntroot = nfs4_get_root(s, &mntfh);
1745 if (IS_ERR(mntroot)) {
1746 error = PTR_ERR(mntroot);
1747 goto error_splat_super;
1750 s->s_flags |= MS_ACTIVE;
1752 mnt->mnt_root = mntroot;
1756 kfree(data.client_address);
1757 kfree(data.nfs_server.export_path);
1758 kfree(data.nfs_server.hostname);
1762 nfs_free_server(server);
1766 up_write(&s->s_umount);
1767 deactivate_super(s);
1771 static void nfs4_kill_super(struct super_block *sb)
1773 struct nfs_server *server = NFS_SB(sb);
1775 nfs_return_all_delegations(sb);
1776 kill_anon_super(sb);
1778 nfs4_renewd_prepare_shutdown(server);
1779 nfs_free_server(server);
1783 * Clone an NFS4 server record on xdev traversal (FSID-change)
1785 static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
1786 const char *dev_name, void *raw_data,
1787 struct vfsmount *mnt)
1789 struct nfs_clone_mount *data = raw_data;
1790 struct super_block *s;
1791 struct nfs_server *server;
1792 struct dentry *mntroot;
1793 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
1794 struct nfs_sb_mountdata sb_mntdata = {
1799 dprintk("--> nfs4_xdev_get_sb()\n");
1801 /* create a new volume representation */
1802 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1803 if (IS_ERR(server)) {
1804 error = PTR_ERR(server);
1805 goto out_err_noserver;
1807 sb_mntdata.server = server;
1809 if (server->flags & NFS4_MOUNT_UNSHARED)
1810 compare_super = NULL;
1812 /* Get a superblock - note that we may end up sharing one that already exists */
1813 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
1819 if (s->s_fs_info != server) {
1820 nfs_free_server(server);
1825 /* initial superblock/root creation */
1826 nfs4_clone_super(s, data->sb);
1829 mntroot = nfs4_get_root(s, data->fh);
1830 if (IS_ERR(mntroot)) {
1831 error = PTR_ERR(mntroot);
1832 goto error_splat_super;
1834 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
1837 goto error_splat_super;
1840 s->s_flags |= MS_ACTIVE;
1842 mnt->mnt_root = mntroot;
1844 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
1848 nfs_free_server(server);
1850 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
1854 up_write(&s->s_umount);
1855 deactivate_super(s);
1856 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
1861 * Create an NFS4 server record on referral traversal
1863 static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
1864 const char *dev_name, void *raw_data,
1865 struct vfsmount *mnt)
1867 struct nfs_clone_mount *data = raw_data;
1868 struct super_block *s;
1869 struct nfs_server *server;
1870 struct dentry *mntroot;
1871 struct nfs_fh mntfh;
1872 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
1873 struct nfs_sb_mountdata sb_mntdata = {
1878 dprintk("--> nfs4_referral_get_sb()\n");
1880 /* create a new volume representation */
1881 server = nfs4_create_referral_server(data, &mntfh);
1882 if (IS_ERR(server)) {
1883 error = PTR_ERR(server);
1884 goto out_err_noserver;
1886 sb_mntdata.server = server;
1888 if (server->flags & NFS4_MOUNT_UNSHARED)
1889 compare_super = NULL;
1891 /* Get a superblock - note that we may end up sharing one that already exists */
1892 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
1898 if (s->s_fs_info != server) {
1899 nfs_free_server(server);
1904 /* initial superblock/root creation */
1908 mntroot = nfs4_get_root(s, &mntfh);
1909 if (IS_ERR(mntroot)) {
1910 error = PTR_ERR(mntroot);
1911 goto error_splat_super;
1913 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
1916 goto error_splat_super;
1919 s->s_flags |= MS_ACTIVE;
1921 mnt->mnt_root = mntroot;
1923 dprintk("<-- nfs4_referral_get_sb() = 0\n");
1927 nfs_free_server(server);
1929 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
1933 up_write(&s->s_umount);
1934 deactivate_super(s);
1935 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
1939 #endif /* CONFIG_NFS_V4 */