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,
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_nfsvers, "nfsvers=%u" },
143 { Opt_nfsvers, "vers=%u" },
145 { Opt_sec, "sec=%s" },
146 { Opt_proto, "proto=%s" },
147 { Opt_mountproto, "mountproto=%s" },
148 { Opt_addr, "addr=%s" },
149 { Opt_clientaddr, "clientaddr=%s" },
150 { Opt_userspace, "mounthost=%s" },
151 { Opt_mountaddr, "mountaddr=%s" },
157 Opt_xprt_udp, Opt_xprt_tcp, Opt_xprt_rdma,
162 static match_table_t nfs_xprt_protocol_tokens = {
163 { Opt_xprt_udp, "udp" },
164 { Opt_xprt_tcp, "tcp" },
165 { Opt_xprt_rdma, "rdma" },
167 { Opt_xprt_err, NULL }
171 Opt_sec_none, Opt_sec_sys,
172 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
173 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
174 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
179 static match_table_t nfs_secflavor_tokens = {
180 { Opt_sec_none, "none" },
181 { Opt_sec_none, "null" },
182 { Opt_sec_sys, "sys" },
184 { Opt_sec_krb5, "krb5" },
185 { Opt_sec_krb5i, "krb5i" },
186 { Opt_sec_krb5p, "krb5p" },
188 { Opt_sec_lkey, "lkey" },
189 { Opt_sec_lkeyi, "lkeyi" },
190 { Opt_sec_lkeyp, "lkeyp" },
192 { Opt_sec_err, NULL }
196 static void nfs_umount_begin(struct vfsmount *, int);
197 static int nfs_statfs(struct dentry *, struct kstatfs *);
198 static int nfs_show_options(struct seq_file *, struct vfsmount *);
199 static int nfs_show_stats(struct seq_file *, struct vfsmount *);
200 static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
201 static int nfs_xdev_get_sb(struct file_system_type *fs_type,
202 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
203 static void nfs_kill_super(struct super_block *);
204 static void nfs_put_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 .put_super = nfs_put_super,
227 .statfs = nfs_statfs,
228 .clear_inode = nfs_clear_inode,
229 .umount_begin = nfs_umount_begin,
230 .show_options = nfs_show_options,
231 .show_stats = nfs_show_stats,
235 static int nfs4_get_sb(struct file_system_type *fs_type,
236 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
237 static int nfs4_xdev_get_sb(struct file_system_type *fs_type,
238 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
239 static int nfs4_referral_get_sb(struct file_system_type *fs_type,
240 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
241 static void nfs4_kill_super(struct super_block *sb);
243 static struct file_system_type nfs4_fs_type = {
244 .owner = THIS_MODULE,
246 .get_sb = nfs4_get_sb,
247 .kill_sb = nfs4_kill_super,
248 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
251 struct file_system_type nfs4_xdev_fs_type = {
252 .owner = THIS_MODULE,
254 .get_sb = nfs4_xdev_get_sb,
255 .kill_sb = nfs4_kill_super,
256 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
259 struct file_system_type nfs4_referral_fs_type = {
260 .owner = THIS_MODULE,
262 .get_sb = nfs4_referral_get_sb,
263 .kill_sb = nfs4_kill_super,
264 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
267 static const struct super_operations nfs4_sops = {
268 .alloc_inode = nfs_alloc_inode,
269 .destroy_inode = nfs_destroy_inode,
270 .write_inode = nfs_write_inode,
271 .statfs = nfs_statfs,
272 .clear_inode = nfs4_clear_inode,
273 .umount_begin = nfs_umount_begin,
274 .show_options = nfs_show_options,
275 .show_stats = nfs_show_stats,
279 static struct shrinker acl_shrinker = {
280 .shrink = nfs_access_cache_shrinker,
281 .seeks = DEFAULT_SEEKS,
285 * Register the NFS filesystems
287 int __init register_nfs_fs(void)
291 ret = register_filesystem(&nfs_fs_type);
295 ret = nfs_register_sysctl();
299 ret = register_filesystem(&nfs4_fs_type);
303 register_shrinker(&acl_shrinker);
308 nfs_unregister_sysctl();
311 unregister_filesystem(&nfs_fs_type);
317 * Unregister the NFS filesystems
319 void __exit unregister_nfs_fs(void)
321 unregister_shrinker(&acl_shrinker);
323 unregister_filesystem(&nfs4_fs_type);
325 nfs_unregister_sysctl();
326 unregister_filesystem(&nfs_fs_type);
329 void nfs_sb_active(struct nfs_server *server)
331 atomic_inc(&server->active);
334 void nfs_sb_deactive(struct nfs_server *server)
336 if (atomic_dec_and_test(&server->active))
337 wake_up(&server->active_wq);
340 static void nfs_put_super(struct super_block *sb)
342 struct nfs_server *server = NFS_SB(sb);
344 * Make sure there are no outstanding ops to this server.
345 * If so, wait for them to finish before allowing the
346 * unmount to continue.
348 wait_event(server->active_wq, atomic_read(&server->active) == 0);
352 * Deliver file system statistics to userspace
354 static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
356 struct nfs_server *server = NFS_SB(dentry->d_sb);
357 unsigned char blockbits;
358 unsigned long blockres;
359 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
360 struct nfs_fattr fattr;
361 struct nfs_fsstat res = {
368 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
371 buf->f_type = NFS_SUPER_MAGIC;
374 * Current versions of glibc do not correctly handle the
375 * case where f_frsize != f_bsize. Eventually we want to
376 * report the value of wtmult in this field.
378 buf->f_frsize = dentry->d_sb->s_blocksize;
381 * On most *nix systems, f_blocks, f_bfree, and f_bavail
382 * are reported in units of f_frsize. Linux hasn't had
383 * an f_frsize field in its statfs struct until recently,
384 * thus historically Linux's sys_statfs reports these
385 * fields in units of f_bsize.
387 buf->f_bsize = dentry->d_sb->s_blocksize;
388 blockbits = dentry->d_sb->s_blocksize_bits;
389 blockres = (1 << blockbits) - 1;
390 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
391 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
392 buf->f_bavail = (res.abytes + blockres) >> blockbits;
394 buf->f_files = res.tfiles;
395 buf->f_ffree = res.afiles;
397 buf->f_namelen = server->namelen;
403 dprintk("%s: statfs error = %d\n", __FUNCTION__, -error);
409 * Map the security flavour number to a name
411 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
413 static const struct {
414 rpc_authflavor_t flavour;
417 { RPC_AUTH_NULL, "null" },
418 { RPC_AUTH_UNIX, "sys" },
419 { RPC_AUTH_GSS_KRB5, "krb5" },
420 { RPC_AUTH_GSS_KRB5I, "krb5i" },
421 { RPC_AUTH_GSS_KRB5P, "krb5p" },
422 { RPC_AUTH_GSS_LKEY, "lkey" },
423 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
424 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
425 { RPC_AUTH_GSS_SPKM, "spkm" },
426 { RPC_AUTH_GSS_SPKMI, "spkmi" },
427 { RPC_AUTH_GSS_SPKMP, "spkmp" },
428 { UINT_MAX, "unknown" }
432 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
433 if (sec_flavours[i].flavour == flavour)
436 return sec_flavours[i].str;
440 * Describe the mount options in force on this server representation
442 static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss, int showdefaults)
444 static const struct proc_nfs_info {
449 { NFS_MOUNT_SOFT, ",soft", ",hard" },
450 { NFS_MOUNT_INTR, ",intr", ",nointr" },
451 { NFS_MOUNT_NOCTO, ",nocto", "" },
452 { NFS_MOUNT_NOAC, ",noac", "" },
453 { NFS_MOUNT_NONLM, ",nolock", "" },
454 { NFS_MOUNT_NOACL, ",noacl", "" },
455 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
456 { NFS_MOUNT_UNSHARED, ",nosharecache", ""},
459 const struct proc_nfs_info *nfs_infop;
460 struct nfs_client *clp = nfss->nfs_client;
462 seq_printf(m, ",vers=%d", clp->rpc_ops->version);
463 seq_printf(m, ",rsize=%d", nfss->rsize);
464 seq_printf(m, ",wsize=%d", nfss->wsize);
465 if (nfss->acregmin != 3*HZ || showdefaults)
466 seq_printf(m, ",acregmin=%d", nfss->acregmin/HZ);
467 if (nfss->acregmax != 60*HZ || showdefaults)
468 seq_printf(m, ",acregmax=%d", nfss->acregmax/HZ);
469 if (nfss->acdirmin != 30*HZ || showdefaults)
470 seq_printf(m, ",acdirmin=%d", nfss->acdirmin/HZ);
471 if (nfss->acdirmax != 60*HZ || showdefaults)
472 seq_printf(m, ",acdirmax=%d", nfss->acdirmax/HZ);
473 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
474 if (nfss->flags & nfs_infop->flag)
475 seq_puts(m, nfs_infop->str);
477 seq_puts(m, nfs_infop->nostr);
479 seq_printf(m, ",proto=%s",
480 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_PROTO));
481 seq_printf(m, ",timeo=%lu", 10U * clp->retrans_timeo / HZ);
482 seq_printf(m, ",retrans=%u", clp->retrans_count);
483 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
487 * Describe the mount options on this VFS mountpoint
489 static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
491 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
493 nfs_show_mount_options(m, nfss, 0);
495 seq_printf(m, ",addr="NIPQUAD_FMT,
496 NIPQUAD(nfss->nfs_client->cl_addr.sin_addr));
502 * Present statistical information for this VFS mountpoint
504 static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
507 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
508 struct rpc_auth *auth = nfss->client->cl_auth;
509 struct nfs_iostats totals = { };
511 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
514 * Display all mount option settings
516 seq_printf(m, "\n\topts:\t");
517 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
518 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
519 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
520 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
521 nfs_show_mount_options(m, nfss, 1);
523 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
525 seq_printf(m, "\n\tcaps:\t");
526 seq_printf(m, "caps=0x%x", nfss->caps);
527 seq_printf(m, ",wtmult=%d", nfss->wtmult);
528 seq_printf(m, ",dtsize=%d", nfss->dtsize);
529 seq_printf(m, ",bsize=%d", nfss->bsize);
530 seq_printf(m, ",namelen=%d", nfss->namelen);
533 if (nfss->nfs_client->cl_nfsversion == 4) {
534 seq_printf(m, "\n\tnfsv4:\t");
535 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
536 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
537 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
542 * Display security flavor in effect for this mount
544 seq_printf(m, "\n\tsec:\tflavor=%d", auth->au_ops->au_flavor);
546 seq_printf(m, ",pseudoflavor=%d", auth->au_flavor);
549 * Display superblock I/O counters
551 for_each_possible_cpu(cpu) {
552 struct nfs_iostats *stats;
555 stats = per_cpu_ptr(nfss->io_stats, cpu);
557 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
558 totals.events[i] += stats->events[i];
559 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
560 totals.bytes[i] += stats->bytes[i];
565 seq_printf(m, "\n\tevents:\t");
566 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
567 seq_printf(m, "%lu ", totals.events[i]);
568 seq_printf(m, "\n\tbytes:\t");
569 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
570 seq_printf(m, "%Lu ", totals.bytes[i]);
573 rpc_print_iostats(m, nfss->client);
579 * Begin unmount by attempting to remove all automounted mountpoints we added
580 * in response to xdev traversals and referrals
582 static void nfs_umount_begin(struct vfsmount *vfsmnt, int flags)
584 struct nfs_server *server = NFS_SB(vfsmnt->mnt_sb);
585 struct rpc_clnt *rpc;
587 shrink_submounts(vfsmnt, &nfs_automount_list);
589 if (!(flags & MNT_FORCE))
591 /* -EIO all pending I/O */
592 rpc = server->client_acl;
594 rpc_killall_tasks(rpc);
595 rpc = server->client;
597 rpc_killall_tasks(rpc);
601 * Sanity-check a server address provided by the mount command
603 static int nfs_verify_server_address(struct sockaddr *addr)
605 switch (addr->sa_family) {
607 struct sockaddr_in *sa = (struct sockaddr_in *) addr;
608 if (sa->sin_addr.s_addr != INADDR_ANY)
618 * Error-check and convert a string of mount options from user space into
621 static int nfs_parse_mount_options(char *raw,
622 struct nfs_parsed_mount_data *mnt)
627 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
630 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
632 while ((p = strsep(&raw, ",")) != NULL) {
633 substring_t args[MAX_OPT_ARGS];
639 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
641 token = match_token(p, nfs_mount_option_tokens, args);
644 mnt->flags |= NFS_MOUNT_SOFT;
647 mnt->flags &= ~NFS_MOUNT_SOFT;
650 mnt->flags |= NFS_MOUNT_INTR;
653 mnt->flags &= ~NFS_MOUNT_INTR;
656 mnt->flags |= NFS_MOUNT_POSIX;
659 mnt->flags &= ~NFS_MOUNT_POSIX;
662 mnt->flags &= ~NFS_MOUNT_NOCTO;
665 mnt->flags |= NFS_MOUNT_NOCTO;
668 mnt->flags &= ~NFS_MOUNT_NOAC;
671 mnt->flags |= NFS_MOUNT_NOAC;
674 mnt->flags &= ~NFS_MOUNT_NONLM;
677 mnt->flags |= NFS_MOUNT_NONLM;
680 mnt->flags &= ~NFS_MOUNT_VER3;
683 mnt->flags |= NFS_MOUNT_VER3;
686 mnt->flags &= ~NFS_MOUNT_TCP;
687 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
692 mnt->flags |= NFS_MOUNT_TCP;
693 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
698 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
699 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
704 mnt->flags &= ~NFS_MOUNT_NOACL;
707 mnt->flags |= NFS_MOUNT_NOACL;
710 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
713 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
716 mnt->flags &= ~NFS_MOUNT_UNSHARED;
718 case Opt_nosharecache:
719 mnt->flags |= NFS_MOUNT_UNSHARED;
723 if (match_int(args, &option))
725 if (option < 0 || option > 65535)
727 mnt->nfs_server.address.sin_port = htons(option);
730 if (match_int(args, &mnt->rsize))
734 if (match_int(args, &mnt->wsize))
738 if (match_int(args, &option))
745 if (match_int(args, &mnt->timeo))
749 if (match_int(args, &mnt->retrans))
753 if (match_int(args, &mnt->acregmin))
757 if (match_int(args, &mnt->acregmax))
761 if (match_int(args, &mnt->acdirmin))
765 if (match_int(args, &mnt->acdirmax))
769 if (match_int(args, &option))
776 mnt->acdirmax = option;
779 if (match_int(args, &mnt->namlen))
783 if (match_int(args, &option))
785 if (option < 0 || option > 65535)
787 mnt->mount_server.port = option;
790 if (match_int(args, &option))
794 mnt->mount_server.program = option;
797 if (match_int(args, &option))
801 mnt->mount_server.version = option;
804 if (match_int(args, &option))
808 mnt->flags &= ~NFS_MOUNT_VER3;
811 mnt->flags |= NFS_MOUNT_VER3;
819 string = match_strdup(args);
822 token = match_token(string, nfs_secflavor_tokens, args);
826 * The flags setting is for v2/v3. The flavor_len
827 * setting is for v4. v2/v3 also need to know the
828 * difference between NULL and UNIX.
832 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
833 mnt->auth_flavor_len = 0;
834 mnt->auth_flavors[0] = RPC_AUTH_NULL;
837 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
838 mnt->auth_flavor_len = 0;
839 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
842 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
843 mnt->auth_flavor_len = 1;
844 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
847 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
848 mnt->auth_flavor_len = 1;
849 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
852 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
853 mnt->auth_flavor_len = 1;
854 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
857 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
858 mnt->auth_flavor_len = 1;
859 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
862 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
863 mnt->auth_flavor_len = 1;
864 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
867 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
868 mnt->auth_flavor_len = 1;
869 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
872 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
873 mnt->auth_flavor_len = 1;
874 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
877 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
878 mnt->auth_flavor_len = 1;
879 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
882 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
883 mnt->auth_flavor_len = 1;
884 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
891 string = match_strdup(args);
894 token = match_token(string,
895 nfs_xprt_protocol_tokens, args);
900 mnt->flags &= ~NFS_MOUNT_TCP;
901 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
906 mnt->flags |= NFS_MOUNT_TCP;
907 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
912 /* vector side protocols to TCP */
913 mnt->flags |= NFS_MOUNT_TCP;
914 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
923 string = match_strdup(args);
926 token = match_token(string,
927 nfs_xprt_protocol_tokens, args);
932 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
935 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
937 case Opt_xprt_rdma: /* not used for side protocols */
943 string = match_strdup(args);
946 mnt->nfs_server.address.sin_family = AF_INET;
947 mnt->nfs_server.address.sin_addr.s_addr =
952 string = match_strdup(args);
955 mnt->client_address = string;
958 string = match_strdup(args);
961 mnt->mount_server.address.sin_family = AF_INET;
962 mnt->mount_server.address.sin_addr.s_addr =
979 printk(KERN_INFO "NFS: not enough memory to parse option\n");
983 printk(KERN_INFO "NFS: unrecognized NFS version number\n");
987 printk(KERN_INFO "NFS: unrecognized transport protocol\n");
991 printk(KERN_INFO "NFS: unrecognized security flavor\n");
995 printk(KERN_INFO "NFS: unknown mount option: %s\n", p);
1000 * Use the remote server's MOUNT service to request the NFS file handle
1001 * corresponding to the provided path.
1003 static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1004 struct nfs_fh *root_fh)
1006 struct sockaddr_in sin;
1009 if (args->mount_server.version == 0) {
1010 if (args->flags & NFS_MOUNT_VER3)
1011 args->mount_server.version = NFS_MNT3_VERSION;
1013 args->mount_server.version = NFS_MNT_VERSION;
1017 * Construct the mount server's address.
1019 if (args->mount_server.address.sin_addr.s_addr != INADDR_ANY)
1020 sin = args->mount_server.address;
1022 sin = args->nfs_server.address;
1024 * autobind will be used if mount_server.port == 0
1026 sin.sin_port = htons(args->mount_server.port);
1029 * Now ask the mount server to map our export path
1032 status = nfs_mount((struct sockaddr *) &sin,
1034 args->nfs_server.hostname,
1035 args->nfs_server.export_path,
1036 args->mount_server.version,
1037 args->mount_server.protocol,
1042 dfprintk(MOUNT, "NFS: unable to mount server " NIPQUAD_FMT
1043 ", error %d\n", NIPQUAD(sin.sin_addr.s_addr), status);
1048 * Validate the NFS2/NFS3 mount data
1049 * - fills in the mount root filehandle
1051 * For option strings, user space handles the following behaviors:
1053 * + DNS: mapping server host name to IP address ("addr=" option)
1055 * + failure mode: how to behave if a mount request can't be handled
1056 * immediately ("fg/bg" option)
1058 * + retry: how often to retry a mount request ("retry=" option)
1060 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1061 * mountproto=tcp after mountproto=udp, and so on
1063 static int nfs_validate_mount_data(void *options,
1064 struct nfs_parsed_mount_data *args,
1065 struct nfs_fh *mntfh,
1066 const char *dev_name)
1068 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
1070 memset(args, 0, sizeof(*args));
1075 args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
1076 args->rsize = NFS_MAX_FILE_IO_SIZE;
1077 args->wsize = NFS_MAX_FILE_IO_SIZE;
1081 args->acregmax = 60;
1082 args->acdirmin = 30;
1083 args->acdirmax = 60;
1084 args->mount_server.protocol = XPRT_TRANSPORT_UDP;
1085 args->mount_server.program = NFS_MNT_PROGRAM;
1086 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1088 switch (data->version) {
1094 if (data->flags & NFS_MOUNT_VER3)
1096 data->root.size = NFS2_FHSIZE;
1097 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1099 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1102 memset(data->context, 0, sizeof(data->context));
1104 if (data->flags & NFS_MOUNT_VER3)
1105 mntfh->size = data->root.size;
1107 mntfh->size = NFS2_FHSIZE;
1109 if (mntfh->size > sizeof(mntfh->data))
1110 goto out_invalid_fh;
1112 memcpy(mntfh->data, data->root.data, mntfh->size);
1113 if (mntfh->size < sizeof(mntfh->data))
1114 memset(mntfh->data + mntfh->size, 0,
1115 sizeof(mntfh->data) - mntfh->size);
1117 if (!nfs_verify_server_address((struct sockaddr *) &data->addr))
1118 goto out_no_address;
1121 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1124 args->flags = data->flags;
1125 args->rsize = data->rsize;
1126 args->wsize = data->wsize;
1127 args->flags = data->flags;
1128 args->timeo = data->timeo;
1129 args->retrans = data->retrans;
1130 args->acregmin = data->acregmin;
1131 args->acregmax = data->acregmax;
1132 args->acdirmin = data->acdirmin;
1133 args->acdirmax = data->acdirmax;
1134 args->nfs_server.address = data->addr;
1135 if (!(data->flags & NFS_MOUNT_TCP))
1136 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1137 /* N.B. caller will free nfs_server.hostname in all cases */
1138 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1139 args->namlen = data->namlen;
1140 args->bsize = data->bsize;
1141 args->auth_flavors[0] = data->pseudoflavor;
1148 if (nfs_parse_mount_options((char *)options, args) == 0)
1151 if (!nfs_verify_server_address((struct sockaddr *)
1152 &args->nfs_server.address))
1153 goto out_no_address;
1155 c = strchr(dev_name, ':');
1159 /* N.B. caller will free nfs_server.hostname in all cases */
1160 args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL);
1163 if (strlen(c) > NFS_MAXPATHLEN)
1164 return -ENAMETOOLONG;
1165 args->nfs_server.export_path = c;
1167 status = nfs_try_mount(args, mntfh);
1175 if (!(args->flags & NFS_MOUNT_SECFLAVOUR))
1176 args->auth_flavors[0] = RPC_AUTH_UNIX;
1178 #ifndef CONFIG_NFS_V3
1179 if (args->flags & NFS_MOUNT_VER3)
1180 goto out_v3_not_compiled;
1181 #endif /* !CONFIG_NFS_V3 */
1186 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1190 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1195 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1198 #ifndef CONFIG_NFS_V3
1199 out_v3_not_compiled:
1200 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1201 return -EPROTONOSUPPORT;
1202 #endif /* !CONFIG_NFS_V3 */
1205 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1209 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1214 * Initialise the common bits of the superblock
1216 static inline void nfs_initialise_sb(struct super_block *sb)
1218 struct nfs_server *server = NFS_SB(sb);
1220 sb->s_magic = NFS_SUPER_MAGIC;
1222 /* We probably want something more informative here */
1223 snprintf(sb->s_id, sizeof(sb->s_id),
1224 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1226 if (sb->s_blocksize == 0)
1227 sb->s_blocksize = nfs_block_bits(server->wsize,
1228 &sb->s_blocksize_bits);
1230 if (server->flags & NFS_MOUNT_NOAC)
1231 sb->s_flags |= MS_SYNCHRONOUS;
1233 nfs_super_set_maxbytes(sb, server->maxfilesize);
1237 * Finish setting up an NFS2/3 superblock
1239 static void nfs_fill_super(struct super_block *sb,
1240 struct nfs_parsed_mount_data *data)
1242 struct nfs_server *server = NFS_SB(sb);
1244 sb->s_blocksize_bits = 0;
1245 sb->s_blocksize = 0;
1247 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1249 if (server->flags & NFS_MOUNT_VER3) {
1250 /* The VFS shouldn't apply the umask to mode bits. We will do
1251 * so ourselves when necessary.
1253 sb->s_flags |= MS_POSIXACL;
1254 sb->s_time_gran = 1;
1257 sb->s_op = &nfs_sops;
1258 nfs_initialise_sb(sb);
1262 * Finish setting up a cloned NFS2/3 superblock
1264 static void nfs_clone_super(struct super_block *sb,
1265 const struct super_block *old_sb)
1267 struct nfs_server *server = NFS_SB(sb);
1269 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1270 sb->s_blocksize = old_sb->s_blocksize;
1271 sb->s_maxbytes = old_sb->s_maxbytes;
1273 if (server->flags & NFS_MOUNT_VER3) {
1274 /* The VFS shouldn't apply the umask to mode bits. We will do
1275 * so ourselves when necessary.
1277 sb->s_flags |= MS_POSIXACL;
1278 sb->s_time_gran = 1;
1281 sb->s_op = old_sb->s_op;
1282 nfs_initialise_sb(sb);
1285 #define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
1287 static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
1289 const struct nfs_server *a = s->s_fs_info;
1290 const struct rpc_clnt *clnt_a = a->client;
1291 const struct rpc_clnt *clnt_b = b->client;
1293 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
1295 if (a->nfs_client != b->nfs_client)
1297 if (a->flags != b->flags)
1299 if (a->wsize != b->wsize)
1301 if (a->rsize != b->rsize)
1303 if (a->acregmin != b->acregmin)
1305 if (a->acregmax != b->acregmax)
1307 if (a->acdirmin != b->acdirmin)
1309 if (a->acdirmax != b->acdirmax)
1311 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
1318 struct nfs_sb_mountdata {
1319 struct nfs_server *server;
1323 static int nfs_set_super(struct super_block *s, void *data)
1325 struct nfs_sb_mountdata *sb_mntdata = data;
1326 struct nfs_server *server = sb_mntdata->server;
1329 s->s_flags = sb_mntdata->mntflags;
1330 s->s_fs_info = server;
1331 ret = set_anon_super(s, server);
1333 server->s_dev = s->s_dev;
1337 static int nfs_compare_super(struct super_block *sb, void *data)
1339 struct nfs_sb_mountdata *sb_mntdata = data;
1340 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
1341 int mntflags = sb_mntdata->mntflags;
1343 if (memcmp(&old->nfs_client->cl_addr,
1344 &server->nfs_client->cl_addr,
1345 sizeof(old->nfs_client->cl_addr)) != 0)
1347 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1348 if (old->flags & NFS_MOUNT_UNSHARED)
1350 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
1352 return nfs_compare_mount_options(sb, server, mntflags);
1355 static int nfs_get_sb(struct file_system_type *fs_type,
1356 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1358 struct nfs_server *server = NULL;
1359 struct super_block *s;
1360 struct nfs_fh mntfh;
1361 struct nfs_parsed_mount_data data;
1362 struct dentry *mntroot;
1363 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
1364 struct nfs_sb_mountdata sb_mntdata = {
1369 /* Validate the mount data */
1370 error = nfs_validate_mount_data(raw_data, &data, &mntfh, dev_name);
1374 /* Get a volume representation */
1375 server = nfs_create_server(&data, &mntfh);
1376 if (IS_ERR(server)) {
1377 error = PTR_ERR(server);
1380 sb_mntdata.server = server;
1382 if (server->flags & NFS_MOUNT_UNSHARED)
1383 compare_super = NULL;
1385 /* Get a superblock - note that we may end up sharing one that already exists */
1386 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
1392 if (s->s_fs_info != server) {
1393 nfs_free_server(server);
1398 /* initial superblock/root creation */
1399 nfs_fill_super(s, &data);
1402 mntroot = nfs_get_root(s, &mntfh);
1403 if (IS_ERR(mntroot)) {
1404 error = PTR_ERR(mntroot);
1405 goto error_splat_super;
1408 s->s_flags |= MS_ACTIVE;
1410 mnt->mnt_root = mntroot;
1414 kfree(data.nfs_server.hostname);
1418 nfs_free_server(server);
1422 up_write(&s->s_umount);
1423 deactivate_super(s);
1428 * Destroy an NFS2/3 superblock
1430 static void nfs_kill_super(struct super_block *s)
1432 struct nfs_server *server = NFS_SB(s);
1435 nfs_free_server(server);
1439 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
1441 static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
1442 const char *dev_name, void *raw_data,
1443 struct vfsmount *mnt)
1445 struct nfs_clone_mount *data = raw_data;
1446 struct super_block *s;
1447 struct nfs_server *server;
1448 struct dentry *mntroot;
1449 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
1450 struct nfs_sb_mountdata sb_mntdata = {
1455 dprintk("--> nfs_xdev_get_sb()\n");
1457 /* create a new volume representation */
1458 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1459 if (IS_ERR(server)) {
1460 error = PTR_ERR(server);
1461 goto out_err_noserver;
1463 sb_mntdata.server = server;
1465 if (server->flags & NFS_MOUNT_UNSHARED)
1466 compare_super = NULL;
1468 /* Get a superblock - note that we may end up sharing one that already exists */
1469 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
1475 if (s->s_fs_info != server) {
1476 nfs_free_server(server);
1481 /* initial superblock/root creation */
1482 nfs_clone_super(s, data->sb);
1485 mntroot = nfs_get_root(s, data->fh);
1486 if (IS_ERR(mntroot)) {
1487 error = PTR_ERR(mntroot);
1488 goto error_splat_super;
1490 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
1493 goto error_splat_super;
1496 s->s_flags |= MS_ACTIVE;
1498 mnt->mnt_root = mntroot;
1500 dprintk("<-- nfs_xdev_get_sb() = 0\n");
1504 nfs_free_server(server);
1506 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
1510 up_write(&s->s_umount);
1511 deactivate_super(s);
1512 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
1516 #ifdef CONFIG_NFS_V4
1519 * Finish setting up a cloned NFS4 superblock
1521 static void nfs4_clone_super(struct super_block *sb,
1522 const struct super_block *old_sb)
1524 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1525 sb->s_blocksize = old_sb->s_blocksize;
1526 sb->s_maxbytes = old_sb->s_maxbytes;
1527 sb->s_time_gran = 1;
1528 sb->s_op = old_sb->s_op;
1529 nfs_initialise_sb(sb);
1533 * Set up an NFS4 superblock
1535 static void nfs4_fill_super(struct super_block *sb)
1537 sb->s_time_gran = 1;
1538 sb->s_op = &nfs4_sops;
1539 nfs_initialise_sb(sb);
1543 * Validate NFSv4 mount options
1545 static int nfs4_validate_mount_data(void *options,
1546 struct nfs_parsed_mount_data *args,
1547 const char *dev_name)
1549 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
1552 memset(args, 0, sizeof(*args));
1557 args->rsize = NFS_MAX_FILE_IO_SIZE;
1558 args->wsize = NFS_MAX_FILE_IO_SIZE;
1562 args->acregmax = 60;
1563 args->acdirmin = 30;
1564 args->acdirmax = 60;
1565 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1567 switch (data->version) {
1569 if (data->host_addrlen != sizeof(args->nfs_server.address))
1570 goto out_no_address;
1571 if (copy_from_user(&args->nfs_server.address,
1573 sizeof(args->nfs_server.address)))
1575 if (args->nfs_server.address.sin_port == 0)
1576 args->nfs_server.address.sin_port = htons(NFS_PORT);
1577 if (!nfs_verify_server_address((struct sockaddr *)
1578 &args->nfs_server.address))
1579 goto out_no_address;
1581 switch (data->auth_flavourlen) {
1583 args->auth_flavors[0] = RPC_AUTH_UNIX;
1586 if (copy_from_user(&args->auth_flavors[0],
1587 data->auth_flavours,
1588 sizeof(args->auth_flavors[0])))
1592 goto out_inval_auth;
1595 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
1598 args->nfs_server.hostname = c;
1600 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
1603 args->nfs_server.export_path = c;
1604 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
1606 c = strndup_user(data->client_addr.data, 16);
1609 args->client_address = c;
1612 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
1616 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
1617 args->rsize = data->rsize;
1618 args->wsize = data->wsize;
1619 args->timeo = data->timeo;
1620 args->retrans = data->retrans;
1621 args->acregmin = data->acregmin;
1622 args->acregmax = data->acregmax;
1623 args->acdirmin = data->acdirmin;
1624 args->acdirmax = data->acdirmax;
1625 args->nfs_server.protocol = data->proto;
1631 if (nfs_parse_mount_options((char *)options, args) == 0)
1634 if (args->nfs_server.address.sin_port == 0)
1635 args->nfs_server.address.sin_port = htons(NFS_PORT);
1636 if (!nfs_verify_server_address((struct sockaddr *)
1637 &args->nfs_server.address))
1640 switch (args->auth_flavor_len) {
1642 args->auth_flavors[0] = RPC_AUTH_UNIX;
1647 goto out_inval_auth;
1651 * Split "dev_name" into "hostname:mntpath".
1653 c = strchr(dev_name, ':');
1656 /* while calculating len, pretend ':' is '\0' */
1658 if (len > NFS4_MAXNAMLEN)
1659 return -ENAMETOOLONG;
1660 args->nfs_server.hostname = kzalloc(len, GFP_KERNEL);
1661 if (args->nfs_server.hostname == NULL)
1663 strncpy(args->nfs_server.hostname, dev_name, len - 1);
1665 c++; /* step over the ':' */
1667 if (len > NFS4_MAXPATHLEN)
1668 return -ENAMETOOLONG;
1669 args->nfs_server.export_path = kzalloc(len + 1, GFP_KERNEL);
1670 if (args->nfs_server.export_path == NULL)
1672 strncpy(args->nfs_server.export_path, c, len);
1674 dprintk("MNTPATH: %s\n", args->nfs_server.export_path);
1676 if (args->client_address == NULL)
1677 goto out_no_client_address;
1686 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
1690 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
1691 data->auth_flavourlen);
1695 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
1698 out_no_client_address:
1699 dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
1704 * Get the superblock for an NFS4 mountpoint
1706 static int nfs4_get_sb(struct file_system_type *fs_type,
1707 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1709 struct nfs_parsed_mount_data data;
1710 struct super_block *s;
1711 struct nfs_server *server;
1712 struct nfs_fh mntfh;
1713 struct dentry *mntroot;
1714 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
1715 struct nfs_sb_mountdata sb_mntdata = {
1720 /* Validate the mount data */
1721 error = nfs4_validate_mount_data(raw_data, &data, dev_name);
1725 /* Get a volume representation */
1726 server = nfs4_create_server(&data, &mntfh);
1727 if (IS_ERR(server)) {
1728 error = PTR_ERR(server);
1731 sb_mntdata.server = server;
1733 if (server->flags & NFS4_MOUNT_UNSHARED)
1734 compare_super = NULL;
1736 /* Get a superblock - note that we may end up sharing one that already exists */
1737 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
1743 if (s->s_fs_info != server) {
1744 nfs_free_server(server);
1749 /* initial superblock/root creation */
1753 mntroot = nfs4_get_root(s, &mntfh);
1754 if (IS_ERR(mntroot)) {
1755 error = PTR_ERR(mntroot);
1756 goto error_splat_super;
1759 s->s_flags |= MS_ACTIVE;
1761 mnt->mnt_root = mntroot;
1765 kfree(data.client_address);
1766 kfree(data.nfs_server.export_path);
1767 kfree(data.nfs_server.hostname);
1771 nfs_free_server(server);
1775 up_write(&s->s_umount);
1776 deactivate_super(s);
1780 static void nfs4_kill_super(struct super_block *sb)
1782 struct nfs_server *server = NFS_SB(sb);
1784 nfs_return_all_delegations(sb);
1785 kill_anon_super(sb);
1787 nfs4_renewd_prepare_shutdown(server);
1788 nfs_free_server(server);
1792 * Clone an NFS4 server record on xdev traversal (FSID-change)
1794 static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
1795 const char *dev_name, void *raw_data,
1796 struct vfsmount *mnt)
1798 struct nfs_clone_mount *data = raw_data;
1799 struct super_block *s;
1800 struct nfs_server *server;
1801 struct dentry *mntroot;
1802 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
1803 struct nfs_sb_mountdata sb_mntdata = {
1808 dprintk("--> nfs4_xdev_get_sb()\n");
1810 /* create a new volume representation */
1811 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1812 if (IS_ERR(server)) {
1813 error = PTR_ERR(server);
1814 goto out_err_noserver;
1816 sb_mntdata.server = server;
1818 if (server->flags & NFS4_MOUNT_UNSHARED)
1819 compare_super = NULL;
1821 /* Get a superblock - note that we may end up sharing one that already exists */
1822 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
1828 if (s->s_fs_info != server) {
1829 nfs_free_server(server);
1834 /* initial superblock/root creation */
1835 nfs4_clone_super(s, data->sb);
1838 mntroot = nfs4_get_root(s, data->fh);
1839 if (IS_ERR(mntroot)) {
1840 error = PTR_ERR(mntroot);
1841 goto error_splat_super;
1843 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
1846 goto error_splat_super;
1849 s->s_flags |= MS_ACTIVE;
1851 mnt->mnt_root = mntroot;
1853 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
1857 nfs_free_server(server);
1859 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
1863 up_write(&s->s_umount);
1864 deactivate_super(s);
1865 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
1870 * Create an NFS4 server record on referral traversal
1872 static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
1873 const char *dev_name, void *raw_data,
1874 struct vfsmount *mnt)
1876 struct nfs_clone_mount *data = raw_data;
1877 struct super_block *s;
1878 struct nfs_server *server;
1879 struct dentry *mntroot;
1880 struct nfs_fh mntfh;
1881 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
1882 struct nfs_sb_mountdata sb_mntdata = {
1887 dprintk("--> nfs4_referral_get_sb()\n");
1889 /* create a new volume representation */
1890 server = nfs4_create_referral_server(data, &mntfh);
1891 if (IS_ERR(server)) {
1892 error = PTR_ERR(server);
1893 goto out_err_noserver;
1895 sb_mntdata.server = server;
1897 if (server->flags & NFS4_MOUNT_UNSHARED)
1898 compare_super = NULL;
1900 /* Get a superblock - note that we may end up sharing one that already exists */
1901 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
1907 if (s->s_fs_info != server) {
1908 nfs_free_server(server);
1913 /* initial superblock/root creation */
1917 mntroot = nfs4_get_root(s, &mntfh);
1918 if (IS_ERR(mntroot)) {
1919 error = PTR_ERR(mntroot);
1920 goto error_splat_super;
1922 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
1925 goto error_splat_super;
1928 s->s_flags |= MS_ACTIVE;
1930 mnt->mnt_root = mntroot;
1932 dprintk("<-- nfs4_referral_get_sb() = 0\n");
1936 nfs_free_server(server);
1938 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
1942 up_write(&s->s_umount);
1943 deactivate_super(s);
1944 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
1948 #endif /* CONFIG_NFS_V4 */