4 * Copyright (C) 1992 Rick Sladkey
6 * nfs superblock handling functions
8 * Modularised by Alan Cox <Alan.Cox@linux.org>, while hacking some
9 * experimental NFS changes. Modularisation taken straight from SYS5 fs.
11 * Change to nfs_read_super() to permit NFS mounts to multi-homed hosts.
12 * J.S.Peatfield@damtp.cam.ac.uk
14 * Split from inode.c by David Howells <dhowells@redhat.com>
16 * - superblocks are indexed on server only - all inodes, dentries, etc. associated with a
17 * particular server are held in the same superblock
18 * - NFS superblocks can have several effective roots to the dentry tree
19 * - directory type roots are spliced into the tree when a path from one root reaches the root
20 * of another (see nfs_lookup())
23 #include <linux/module.h>
24 #include <linux/init.h>
26 #include <linux/time.h>
27 #include <linux/kernel.h>
29 #include <linux/string.h>
30 #include <linux/stat.h>
31 #include <linux/errno.h>
32 #include <linux/unistd.h>
33 #include <linux/sunrpc/clnt.h>
34 #include <linux/sunrpc/stats.h>
35 #include <linux/sunrpc/metrics.h>
36 #include <linux/sunrpc/xprtsock.h>
37 #include <linux/sunrpc/xprtrdma.h>
38 #include <linux/nfs_fs.h>
39 #include <linux/nfs_mount.h>
40 #include <linux/nfs4_mount.h>
41 #include <linux/lockd/bind.h>
42 #include <linux/smp_lock.h>
43 #include <linux/seq_file.h>
44 #include <linux/mount.h>
45 #include <linux/nfs_idmap.h>
46 #include <linux/vfs.h>
47 #include <linux/inet.h>
48 #include <linux/in6.h>
50 #include <linux/nfs_xdr.h>
51 #include <linux/magic.h>
52 #include <linux/parser.h>
54 #include <asm/system.h>
55 #include <asm/uaccess.h>
59 #include "delegation.h"
63 #define NFSDBG_FACILITY NFSDBG_VFS
66 /* Mount options that take no arguments */
69 Opt_posix, Opt_noposix,
74 Opt_udp, Opt_tcp, Opt_rdma,
76 Opt_rdirplus, Opt_nordirplus,
77 Opt_sharecache, Opt_nosharecache,
79 /* Mount options that take integer arguments */
81 Opt_rsize, Opt_wsize, Opt_bsize,
82 Opt_timeo, Opt_retrans,
83 Opt_acregmin, Opt_acregmax,
84 Opt_acdirmin, Opt_acdirmax,
91 /* Mount options that take string arguments */
92 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
93 Opt_addr, Opt_mountaddr, Opt_clientaddr,
95 /* Mount options that are ignored */
96 Opt_userspace, Opt_deprecated,
101 static match_table_t nfs_mount_option_tokens = {
102 { Opt_userspace, "bg" },
103 { Opt_userspace, "fg" },
104 { Opt_soft, "soft" },
105 { Opt_hard, "hard" },
106 { Opt_intr, "intr" },
107 { Opt_nointr, "nointr" },
108 { Opt_posix, "posix" },
109 { Opt_noposix, "noposix" },
111 { Opt_nocto, "nocto" },
113 { Opt_noac, "noac" },
114 { Opt_lock, "lock" },
115 { Opt_nolock, "nolock" },
120 { Opt_rdma, "rdma" },
122 { Opt_noacl, "noacl" },
123 { Opt_rdirplus, "rdirplus" },
124 { Opt_nordirplus, "nordirplus" },
125 { Opt_sharecache, "sharecache" },
126 { Opt_nosharecache, "nosharecache" },
128 { Opt_port, "port=%u" },
129 { Opt_rsize, "rsize=%u" },
130 { Opt_wsize, "wsize=%u" },
131 { Opt_bsize, "bsize=%u" },
132 { Opt_timeo, "timeo=%u" },
133 { Opt_retrans, "retrans=%u" },
134 { Opt_acregmin, "acregmin=%u" },
135 { Opt_acregmax, "acregmax=%u" },
136 { Opt_acdirmin, "acdirmin=%u" },
137 { Opt_acdirmax, "acdirmax=%u" },
138 { Opt_actimeo, "actimeo=%u" },
139 { Opt_userspace, "retry=%u" },
140 { Opt_namelen, "namlen=%u" },
141 { Opt_mountport, "mountport=%u" },
142 { Opt_mountvers, "mountvers=%u" },
143 { Opt_nfsvers, "nfsvers=%u" },
144 { Opt_nfsvers, "vers=%u" },
146 { Opt_sec, "sec=%s" },
147 { Opt_proto, "proto=%s" },
148 { Opt_mountproto, "mountproto=%s" },
149 { Opt_addr, "addr=%s" },
150 { Opt_clientaddr, "clientaddr=%s" },
151 { Opt_mounthost, "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_spkm, "spkm3" },
194 { Opt_sec_spkmi, "spkm3i" },
195 { Opt_sec_spkmp, "spkm3p" },
197 { Opt_sec_err, NULL }
201 static void nfs_umount_begin(struct super_block *);
202 static int nfs_statfs(struct dentry *, struct kstatfs *);
203 static int nfs_show_options(struct seq_file *, struct vfsmount *);
204 static int nfs_show_stats(struct seq_file *, struct vfsmount *);
205 static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
206 static int nfs_xdev_get_sb(struct file_system_type *fs_type,
207 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
208 static void nfs_kill_super(struct super_block *);
209 static void nfs_put_super(struct super_block *);
211 static struct file_system_type nfs_fs_type = {
212 .owner = THIS_MODULE,
214 .get_sb = nfs_get_sb,
215 .kill_sb = nfs_kill_super,
216 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
219 struct file_system_type nfs_xdev_fs_type = {
220 .owner = THIS_MODULE,
222 .get_sb = nfs_xdev_get_sb,
223 .kill_sb = nfs_kill_super,
224 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
227 static const struct super_operations nfs_sops = {
228 .alloc_inode = nfs_alloc_inode,
229 .destroy_inode = nfs_destroy_inode,
230 .write_inode = nfs_write_inode,
231 .put_super = nfs_put_super,
232 .statfs = nfs_statfs,
233 .clear_inode = nfs_clear_inode,
234 .umount_begin = nfs_umount_begin,
235 .show_options = nfs_show_options,
236 .show_stats = nfs_show_stats,
240 static int nfs4_get_sb(struct file_system_type *fs_type,
241 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
242 static int nfs4_xdev_get_sb(struct file_system_type *fs_type,
243 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
244 static int nfs4_referral_get_sb(struct file_system_type *fs_type,
245 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
246 static void nfs4_kill_super(struct super_block *sb);
248 static struct file_system_type nfs4_fs_type = {
249 .owner = THIS_MODULE,
251 .get_sb = nfs4_get_sb,
252 .kill_sb = nfs4_kill_super,
253 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
256 struct file_system_type nfs4_xdev_fs_type = {
257 .owner = THIS_MODULE,
259 .get_sb = nfs4_xdev_get_sb,
260 .kill_sb = nfs4_kill_super,
261 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
264 struct file_system_type nfs4_referral_fs_type = {
265 .owner = THIS_MODULE,
267 .get_sb = nfs4_referral_get_sb,
268 .kill_sb = nfs4_kill_super,
269 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
272 static const struct super_operations nfs4_sops = {
273 .alloc_inode = nfs_alloc_inode,
274 .destroy_inode = nfs_destroy_inode,
275 .write_inode = nfs_write_inode,
276 .statfs = nfs_statfs,
277 .clear_inode = nfs4_clear_inode,
278 .umount_begin = nfs_umount_begin,
279 .show_options = nfs_show_options,
280 .show_stats = nfs_show_stats,
284 static struct shrinker acl_shrinker = {
285 .shrink = nfs_access_cache_shrinker,
286 .seeks = DEFAULT_SEEKS,
290 * Register the NFS filesystems
292 int __init register_nfs_fs(void)
296 ret = register_filesystem(&nfs_fs_type);
300 ret = nfs_register_sysctl();
304 ret = register_filesystem(&nfs4_fs_type);
308 register_shrinker(&acl_shrinker);
313 nfs_unregister_sysctl();
316 unregister_filesystem(&nfs_fs_type);
322 * Unregister the NFS filesystems
324 void __exit unregister_nfs_fs(void)
326 unregister_shrinker(&acl_shrinker);
328 unregister_filesystem(&nfs4_fs_type);
330 nfs_unregister_sysctl();
331 unregister_filesystem(&nfs_fs_type);
334 void nfs_sb_active(struct nfs_server *server)
336 atomic_inc(&server->active);
339 void nfs_sb_deactive(struct nfs_server *server)
341 if (atomic_dec_and_test(&server->active))
342 wake_up(&server->active_wq);
345 static void nfs_put_super(struct super_block *sb)
347 struct nfs_server *server = NFS_SB(sb);
349 * Make sure there are no outstanding ops to this server.
350 * If so, wait for them to finish before allowing the
351 * unmount to continue.
353 wait_event(server->active_wq, atomic_read(&server->active) == 0);
357 * Deliver file system statistics to userspace
359 static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
361 struct nfs_server *server = NFS_SB(dentry->d_sb);
362 unsigned char blockbits;
363 unsigned long blockres;
364 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
365 struct nfs_fattr fattr;
366 struct nfs_fsstat res = {
373 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
376 buf->f_type = NFS_SUPER_MAGIC;
379 * Current versions of glibc do not correctly handle the
380 * case where f_frsize != f_bsize. Eventually we want to
381 * report the value of wtmult in this field.
383 buf->f_frsize = dentry->d_sb->s_blocksize;
386 * On most *nix systems, f_blocks, f_bfree, and f_bavail
387 * are reported in units of f_frsize. Linux hasn't had
388 * an f_frsize field in its statfs struct until recently,
389 * thus historically Linux's sys_statfs reports these
390 * fields in units of f_bsize.
392 buf->f_bsize = dentry->d_sb->s_blocksize;
393 blockbits = dentry->d_sb->s_blocksize_bits;
394 blockres = (1 << blockbits) - 1;
395 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
396 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
397 buf->f_bavail = (res.abytes + blockres) >> blockbits;
399 buf->f_files = res.tfiles;
400 buf->f_ffree = res.afiles;
402 buf->f_namelen = server->namelen;
408 dprintk("%s: statfs error = %d\n", __func__, -error);
414 * Map the security flavour number to a name
416 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
418 static const struct {
419 rpc_authflavor_t flavour;
422 { RPC_AUTH_NULL, "null" },
423 { RPC_AUTH_UNIX, "sys" },
424 { RPC_AUTH_GSS_KRB5, "krb5" },
425 { RPC_AUTH_GSS_KRB5I, "krb5i" },
426 { RPC_AUTH_GSS_KRB5P, "krb5p" },
427 { RPC_AUTH_GSS_LKEY, "lkey" },
428 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
429 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
430 { RPC_AUTH_GSS_SPKM, "spkm" },
431 { RPC_AUTH_GSS_SPKMI, "spkmi" },
432 { RPC_AUTH_GSS_SPKMP, "spkmp" },
433 { UINT_MAX, "unknown" }
437 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
438 if (sec_flavours[i].flavour == flavour)
441 return sec_flavours[i].str;
444 static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
447 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
449 switch (sap->sa_family) {
451 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
452 seq_printf(m, ",mountaddr=" NIPQUAD_FMT,
453 NIPQUAD(sin->sin_addr.s_addr));
457 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
458 seq_printf(m, ",mountaddr=" NIP6_FMT,
459 NIP6(sin6->sin6_addr));
464 seq_printf(m, ",mountaddr=unspecified");
467 if (nfss->mountd_version || showdefaults)
468 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
469 if (nfss->mountd_port || showdefaults)
470 seq_printf(m, ",mountport=%u", nfss->mountd_port);
472 switch (nfss->mountd_protocol) {
474 seq_printf(m, ",mountproto=udp");
477 seq_printf(m, ",mountproto=tcp");
481 seq_printf(m, ",mountproto=auto");
486 * Describe the mount options in force on this server representation
488 static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
491 static const struct proc_nfs_info {
496 { NFS_MOUNT_SOFT, ",soft", ",hard" },
497 { NFS_MOUNT_INTR, ",intr", ",nointr" },
498 { NFS_MOUNT_POSIX, ",posix", "" },
499 { NFS_MOUNT_NOCTO, ",nocto", "" },
500 { NFS_MOUNT_NOAC, ",noac", "" },
501 { NFS_MOUNT_NONLM, ",nolock", "" },
502 { NFS_MOUNT_NOACL, ",noacl", "" },
503 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
504 { NFS_MOUNT_UNSHARED, ",nosharecache", ""},
507 const struct proc_nfs_info *nfs_infop;
508 struct nfs_client *clp = nfss->nfs_client;
509 u32 version = clp->rpc_ops->version;
511 seq_printf(m, ",vers=%u", version);
512 seq_printf(m, ",rsize=%u", nfss->rsize);
513 seq_printf(m, ",wsize=%u", nfss->wsize);
514 if (nfss->bsize != 0)
515 seq_printf(m, ",bsize=%u", nfss->bsize);
516 seq_printf(m, ",namlen=%u", nfss->namelen);
517 if (nfss->acregmin != 3*HZ || showdefaults)
518 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
519 if (nfss->acregmax != 60*HZ || showdefaults)
520 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
521 if (nfss->acdirmin != 30*HZ || showdefaults)
522 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
523 if (nfss->acdirmax != 60*HZ || showdefaults)
524 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
525 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
526 if (nfss->flags & nfs_infop->flag)
527 seq_puts(m, nfs_infop->str);
529 seq_puts(m, nfs_infop->nostr);
531 seq_printf(m, ",proto=%s",
532 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_PROTO));
534 if (nfss->port != NFS_PORT)
535 seq_printf(m, ",port=%u", nfss->port);
538 seq_printf(m, ",port=%u", nfss->port);
540 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
541 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
542 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
545 nfs_show_mountd_options(m, nfss, showdefaults);
548 if (clp->rpc_ops->version == 4)
549 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
554 * Describe the mount options on this VFS mountpoint
556 static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
558 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
560 nfs_show_mount_options(m, nfss, 0);
562 seq_printf(m, ",addr=%s",
563 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
570 * Present statistical information for this VFS mountpoint
572 static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
575 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
576 struct rpc_auth *auth = nfss->client->cl_auth;
577 struct nfs_iostats totals = { };
579 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
582 * Display all mount option settings
584 seq_printf(m, "\n\topts:\t");
585 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
586 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
587 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
588 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
589 nfs_show_mount_options(m, nfss, 1);
591 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
593 seq_printf(m, "\n\tcaps:\t");
594 seq_printf(m, "caps=0x%x", nfss->caps);
595 seq_printf(m, ",wtmult=%u", nfss->wtmult);
596 seq_printf(m, ",dtsize=%u", nfss->dtsize);
597 seq_printf(m, ",bsize=%u", nfss->bsize);
598 seq_printf(m, ",namlen=%u", nfss->namelen);
601 if (nfss->nfs_client->rpc_ops->version == 4) {
602 seq_printf(m, "\n\tnfsv4:\t");
603 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
604 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
605 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
610 * Display security flavor in effect for this mount
612 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
614 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
617 * Display superblock I/O counters
619 for_each_possible_cpu(cpu) {
620 struct nfs_iostats *stats;
623 stats = per_cpu_ptr(nfss->io_stats, cpu);
625 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
626 totals.events[i] += stats->events[i];
627 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
628 totals.bytes[i] += stats->bytes[i];
633 seq_printf(m, "\n\tevents:\t");
634 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
635 seq_printf(m, "%lu ", totals.events[i]);
636 seq_printf(m, "\n\tbytes:\t");
637 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
638 seq_printf(m, "%Lu ", totals.bytes[i]);
641 rpc_print_iostats(m, nfss->client);
647 * Begin unmount by attempting to remove all automounted mountpoints we added
648 * in response to xdev traversals and referrals
650 static void nfs_umount_begin(struct super_block *sb)
652 struct nfs_server *server = NFS_SB(sb);
653 struct rpc_clnt *rpc;
655 /* -EIO all pending I/O */
656 rpc = server->client_acl;
658 rpc_killall_tasks(rpc);
659 rpc = server->client;
661 rpc_killall_tasks(rpc);
665 * Set the port number in an address. Be agnostic about the address family.
667 static void nfs_set_port(struct sockaddr *sap, unsigned short port)
669 switch (sap->sa_family) {
671 struct sockaddr_in *ap = (struct sockaddr_in *)sap;
672 ap->sin_port = htons(port);
676 struct sockaddr_in6 *ap = (struct sockaddr_in6 *)sap;
677 ap->sin6_port = htons(port);
684 * Sanity-check a server address provided by the mount command.
686 * Address family must be initialized, and address must not be
687 * the ANY address for that family.
689 static int nfs_verify_server_address(struct sockaddr *addr)
691 switch (addr->sa_family) {
693 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
694 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
697 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
698 return !ipv6_addr_any(sa);
706 * Parse string addresses passed in via a mount option,
707 * and construct a sockaddr based on the result.
709 * If address parsing fails, set the sockaddr's address
710 * family to AF_UNSPEC to force nfs_verify_server_address()
713 static void nfs_parse_server_address(char *value,
714 struct sockaddr *sap,
717 if (strchr(value, ':')) {
718 struct sockaddr_in6 *ap = (struct sockaddr_in6 *)sap;
719 u8 *addr = (u8 *)&ap->sin6_addr.in6_u;
721 ap->sin6_family = AF_INET6;
723 if (in6_pton(value, -1, addr, '\0', NULL))
726 struct sockaddr_in *ap = (struct sockaddr_in *)sap;
727 u8 *addr = (u8 *)&ap->sin_addr.s_addr;
729 ap->sin_family = AF_INET;
731 if (in4_pton(value, -1, addr, '\0', NULL))
735 sap->sa_family = AF_UNSPEC;
740 * Error-check and convert a string of mount options from user space into
743 static int nfs_parse_mount_options(char *raw,
744 struct nfs_parsed_mount_data *mnt)
746 char *p, *string, *secdata;
750 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
753 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
755 secdata = alloc_secdata();
759 rc = security_sb_copy_data(raw, secdata);
761 goto out_security_failure;
763 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
765 goto out_security_failure;
767 free_secdata(secdata);
769 while ((p = strsep(&raw, ",")) != NULL) {
770 substring_t args[MAX_OPT_ARGS];
776 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
778 token = match_token(p, nfs_mount_option_tokens, args);
781 mnt->flags |= NFS_MOUNT_SOFT;
784 mnt->flags &= ~NFS_MOUNT_SOFT;
790 mnt->flags |= NFS_MOUNT_POSIX;
793 mnt->flags &= ~NFS_MOUNT_POSIX;
796 mnt->flags &= ~NFS_MOUNT_NOCTO;
799 mnt->flags |= NFS_MOUNT_NOCTO;
802 mnt->flags &= ~NFS_MOUNT_NOAC;
805 mnt->flags |= NFS_MOUNT_NOAC;
808 mnt->flags &= ~NFS_MOUNT_NONLM;
811 mnt->flags |= NFS_MOUNT_NONLM;
814 mnt->flags &= ~NFS_MOUNT_VER3;
817 mnt->flags |= NFS_MOUNT_VER3;
820 mnt->flags &= ~NFS_MOUNT_TCP;
821 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
826 mnt->flags |= NFS_MOUNT_TCP;
827 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
832 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
833 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
838 mnt->flags &= ~NFS_MOUNT_NOACL;
841 mnt->flags |= NFS_MOUNT_NOACL;
844 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
847 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
850 mnt->flags &= ~NFS_MOUNT_UNSHARED;
852 case Opt_nosharecache:
853 mnt->flags |= NFS_MOUNT_UNSHARED;
857 if (match_int(args, &option))
859 if (option < 0 || option > 65535)
861 mnt->nfs_server.port = option;
864 if (match_int(args, &mnt->rsize))
868 if (match_int(args, &mnt->wsize))
872 if (match_int(args, &option))
879 if (match_int(args, &mnt->timeo))
883 if (match_int(args, &mnt->retrans))
887 if (match_int(args, &mnt->acregmin))
891 if (match_int(args, &mnt->acregmax))
895 if (match_int(args, &mnt->acdirmin))
899 if (match_int(args, &mnt->acdirmax))
903 if (match_int(args, &option))
910 mnt->acdirmax = option;
913 if (match_int(args, &mnt->namlen))
917 if (match_int(args, &option))
919 if (option < 0 || option > 65535)
921 mnt->mount_server.port = option;
924 if (match_int(args, &option))
928 mnt->mount_server.version = option;
931 if (match_int(args, &option))
935 mnt->flags &= ~NFS_MOUNT_VER3;
938 mnt->flags |= NFS_MOUNT_VER3;
946 string = match_strdup(args);
949 token = match_token(string, nfs_secflavor_tokens, args);
953 * The flags setting is for v2/v3. The flavor_len
954 * setting is for v4. v2/v3 also need to know the
955 * difference between NULL and UNIX.
959 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
960 mnt->auth_flavor_len = 0;
961 mnt->auth_flavors[0] = RPC_AUTH_NULL;
964 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
965 mnt->auth_flavor_len = 0;
966 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
969 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
970 mnt->auth_flavor_len = 1;
971 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
974 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
975 mnt->auth_flavor_len = 1;
976 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
979 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
980 mnt->auth_flavor_len = 1;
981 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
984 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
985 mnt->auth_flavor_len = 1;
986 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
989 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
990 mnt->auth_flavor_len = 1;
991 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
994 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
995 mnt->auth_flavor_len = 1;
996 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
999 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
1000 mnt->auth_flavor_len = 1;
1001 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
1004 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
1005 mnt->auth_flavor_len = 1;
1006 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
1009 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
1010 mnt->auth_flavor_len = 1;
1011 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
1018 string = match_strdup(args);
1021 token = match_token(string,
1022 nfs_xprt_protocol_tokens, args);
1027 mnt->flags &= ~NFS_MOUNT_TCP;
1028 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1033 mnt->flags |= NFS_MOUNT_TCP;
1034 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1039 /* vector side protocols to TCP */
1040 mnt->flags |= NFS_MOUNT_TCP;
1041 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1046 goto out_unrec_xprt;
1049 case Opt_mountproto:
1050 string = match_strdup(args);
1053 token = match_token(string,
1054 nfs_xprt_protocol_tokens, args);
1059 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
1062 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
1064 case Opt_xprt_rdma: /* not used for side protocols */
1066 goto out_unrec_xprt;
1070 string = match_strdup(args);
1073 nfs_parse_server_address(string, (struct sockaddr *)
1074 &mnt->nfs_server.address,
1075 &mnt->nfs_server.addrlen);
1078 case Opt_clientaddr:
1079 string = match_strdup(args);
1082 kfree(mnt->client_address);
1083 mnt->client_address = string;
1086 string = match_strdup(args);
1089 kfree(mnt->mount_server.hostname);
1090 mnt->mount_server.hostname = string;
1093 string = match_strdup(args);
1096 nfs_parse_server_address(string, (struct sockaddr *)
1097 &mnt->mount_server.address,
1098 &mnt->mount_server.addrlen);
1103 case Opt_deprecated:
1111 nfs_set_port((struct sockaddr *)&mnt->nfs_server.address,
1112 mnt->nfs_server.port);
1117 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1119 out_security_failure:
1120 free_secdata(secdata);
1121 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1124 printk(KERN_INFO "NFS: unrecognized NFS version number\n");
1128 printk(KERN_INFO "NFS: unrecognized transport protocol\n");
1132 printk(KERN_INFO "NFS: unrecognized security flavor\n");
1136 printk(KERN_INFO "NFS: unknown mount option: %s\n", p);
1141 * Use the remote server's MOUNT service to request the NFS file handle
1142 * corresponding to the provided path.
1144 static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1145 struct nfs_fh *root_fh)
1147 struct sockaddr *sap = (struct sockaddr *)&args->mount_server.address;
1151 if (args->mount_server.version == 0) {
1152 if (args->flags & NFS_MOUNT_VER3)
1153 args->mount_server.version = NFS_MNT3_VERSION;
1155 args->mount_server.version = NFS_MNT_VERSION;
1158 if (args->mount_server.hostname)
1159 hostname = args->mount_server.hostname;
1161 hostname = args->nfs_server.hostname;
1164 * Construct the mount server's address.
1166 if (args->mount_server.address.ss_family == AF_UNSPEC) {
1167 memcpy(sap, &args->nfs_server.address,
1168 args->nfs_server.addrlen);
1169 args->mount_server.addrlen = args->nfs_server.addrlen;
1173 * autobind will be used if mount_server.port == 0
1175 nfs_set_port(sap, args->mount_server.port);
1178 * Now ask the mount server to map our export path
1181 status = nfs_mount(sap,
1182 args->mount_server.addrlen,
1184 args->nfs_server.export_path,
1185 args->mount_server.version,
1186 args->mount_server.protocol,
1191 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d",
1197 * Validate the NFS2/NFS3 mount data
1198 * - fills in the mount root filehandle
1200 * For option strings, user space handles the following behaviors:
1202 * + DNS: mapping server host name to IP address ("addr=" option)
1204 * + failure mode: how to behave if a mount request can't be handled
1205 * immediately ("fg/bg" option)
1207 * + retry: how often to retry a mount request ("retry=" option)
1209 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1210 * mountproto=tcp after mountproto=udp, and so on
1212 static int nfs_validate_mount_data(void *options,
1213 struct nfs_parsed_mount_data *args,
1214 struct nfs_fh *mntfh,
1215 const char *dev_name)
1217 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
1222 args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
1223 args->rsize = NFS_MAX_FILE_IO_SIZE;
1224 args->wsize = NFS_MAX_FILE_IO_SIZE;
1228 args->acregmax = 60;
1229 args->acdirmin = 30;
1230 args->acdirmax = 60;
1231 args->mount_server.port = 0; /* autobind unless user sets port */
1232 args->mount_server.protocol = XPRT_TRANSPORT_UDP;
1233 args->nfs_server.port = 0; /* autobind unless user sets port */
1234 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1236 switch (data->version) {
1242 if (data->flags & NFS_MOUNT_VER3)
1244 data->root.size = NFS2_FHSIZE;
1245 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1247 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1250 memset(data->context, 0, sizeof(data->context));
1252 if (data->flags & NFS_MOUNT_VER3) {
1253 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1254 goto out_invalid_fh;
1255 mntfh->size = data->root.size;
1257 mntfh->size = NFS2_FHSIZE;
1260 memcpy(mntfh->data, data->root.data, mntfh->size);
1261 if (mntfh->size < sizeof(mntfh->data))
1262 memset(mntfh->data + mntfh->size, 0,
1263 sizeof(mntfh->data) - mntfh->size);
1266 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1269 args->flags = data->flags;
1270 args->rsize = data->rsize;
1271 args->wsize = data->wsize;
1272 args->timeo = data->timeo;
1273 args->retrans = data->retrans;
1274 args->acregmin = data->acregmin;
1275 args->acregmax = data->acregmax;
1276 args->acdirmin = data->acdirmin;
1277 args->acdirmax = data->acdirmax;
1279 memcpy(&args->nfs_server.address, &data->addr,
1280 sizeof(data->addr));
1281 args->nfs_server.addrlen = sizeof(data->addr);
1282 if (!nfs_verify_server_address((struct sockaddr *)
1283 &args->nfs_server.address))
1284 goto out_no_address;
1286 if (!(data->flags & NFS_MOUNT_TCP))
1287 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1288 /* N.B. caller will free nfs_server.hostname in all cases */
1289 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1290 args->namlen = data->namlen;
1291 args->bsize = data->bsize;
1292 args->auth_flavors[0] = data->pseudoflavor;
1293 if (!args->nfs_server.hostname)
1297 * The legacy version 6 binary mount data from userspace has a
1298 * field used only to transport selinux information into the
1299 * the kernel. To continue to support that functionality we
1300 * have a touch of selinux knowledge here in the NFS code. The
1301 * userspace code converted context=blah to just blah so we are
1302 * converting back to the full string selinux understands.
1304 if (data->context[0]){
1305 #ifdef CONFIG_SECURITY_SELINUX
1307 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1310 strcpy(opts_str, "context=");
1311 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1312 strcat(opts_str, &data->context[0]);
1313 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1328 if (nfs_parse_mount_options((char *)options, args) == 0)
1331 if (!nfs_verify_server_address((struct sockaddr *)
1332 &args->nfs_server.address))
1333 goto out_no_address;
1335 c = strchr(dev_name, ':');
1339 /* N.B. caller will free nfs_server.hostname in all cases */
1340 args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL);
1341 if (!args->nfs_server.hostname)
1345 if (strlen(c) > NFS_MAXPATHLEN)
1346 return -ENAMETOOLONG;
1347 args->nfs_server.export_path = c;
1349 status = nfs_try_mount(args, mntfh);
1357 if (!(args->flags & NFS_MOUNT_SECFLAVOUR))
1358 args->auth_flavors[0] = RPC_AUTH_UNIX;
1360 #ifndef CONFIG_NFS_V3
1361 if (args->flags & NFS_MOUNT_VER3)
1362 goto out_v3_not_compiled;
1363 #endif /* !CONFIG_NFS_V3 */
1368 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1372 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1377 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1380 #ifndef CONFIG_NFS_V3
1381 out_v3_not_compiled:
1382 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1383 return -EPROTONOSUPPORT;
1384 #endif /* !CONFIG_NFS_V3 */
1387 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
1391 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1395 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1400 * Initialise the common bits of the superblock
1402 static inline void nfs_initialise_sb(struct super_block *sb)
1404 struct nfs_server *server = NFS_SB(sb);
1406 sb->s_magic = NFS_SUPER_MAGIC;
1408 /* We probably want something more informative here */
1409 snprintf(sb->s_id, sizeof(sb->s_id),
1410 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1412 if (sb->s_blocksize == 0)
1413 sb->s_blocksize = nfs_block_bits(server->wsize,
1414 &sb->s_blocksize_bits);
1416 if (server->flags & NFS_MOUNT_NOAC)
1417 sb->s_flags |= MS_SYNCHRONOUS;
1419 nfs_super_set_maxbytes(sb, server->maxfilesize);
1423 * Finish setting up an NFS2/3 superblock
1425 static void nfs_fill_super(struct super_block *sb,
1426 struct nfs_parsed_mount_data *data)
1428 struct nfs_server *server = NFS_SB(sb);
1430 sb->s_blocksize_bits = 0;
1431 sb->s_blocksize = 0;
1433 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1435 if (server->flags & NFS_MOUNT_VER3) {
1436 /* The VFS shouldn't apply the umask to mode bits. We will do
1437 * so ourselves when necessary.
1439 sb->s_flags |= MS_POSIXACL;
1440 sb->s_time_gran = 1;
1443 sb->s_op = &nfs_sops;
1444 nfs_initialise_sb(sb);
1448 * Finish setting up a cloned NFS2/3 superblock
1450 static void nfs_clone_super(struct super_block *sb,
1451 const struct super_block *old_sb)
1453 struct nfs_server *server = NFS_SB(sb);
1455 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1456 sb->s_blocksize = old_sb->s_blocksize;
1457 sb->s_maxbytes = old_sb->s_maxbytes;
1459 if (server->flags & NFS_MOUNT_VER3) {
1460 /* The VFS shouldn't apply the umask to mode bits. We will do
1461 * so ourselves when necessary.
1463 sb->s_flags |= MS_POSIXACL;
1464 sb->s_time_gran = 1;
1467 sb->s_op = old_sb->s_op;
1468 nfs_initialise_sb(sb);
1471 #define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
1473 static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
1475 const struct nfs_server *a = s->s_fs_info;
1476 const struct rpc_clnt *clnt_a = a->client;
1477 const struct rpc_clnt *clnt_b = b->client;
1479 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
1481 if (a->nfs_client != b->nfs_client)
1483 if (a->flags != b->flags)
1485 if (a->wsize != b->wsize)
1487 if (a->rsize != b->rsize)
1489 if (a->acregmin != b->acregmin)
1491 if (a->acregmax != b->acregmax)
1493 if (a->acdirmin != b->acdirmin)
1495 if (a->acdirmax != b->acdirmax)
1497 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
1504 struct nfs_sb_mountdata {
1505 struct nfs_server *server;
1509 static int nfs_set_super(struct super_block *s, void *data)
1511 struct nfs_sb_mountdata *sb_mntdata = data;
1512 struct nfs_server *server = sb_mntdata->server;
1515 s->s_flags = sb_mntdata->mntflags;
1516 s->s_fs_info = server;
1517 ret = set_anon_super(s, server);
1519 server->s_dev = s->s_dev;
1523 static int nfs_compare_super_address(struct nfs_server *server1,
1524 struct nfs_server *server2)
1526 struct sockaddr *sap1, *sap2;
1528 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
1529 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
1531 if (sap1->sa_family != sap2->sa_family)
1534 switch (sap1->sa_family) {
1536 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
1537 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
1538 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
1540 if (sin1->sin_port != sin2->sin_port)
1545 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
1546 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
1547 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
1549 if (sin1->sin6_port != sin2->sin6_port)
1560 static int nfs_compare_super(struct super_block *sb, void *data)
1562 struct nfs_sb_mountdata *sb_mntdata = data;
1563 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
1564 int mntflags = sb_mntdata->mntflags;
1566 if (!nfs_compare_super_address(old, server))
1568 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1569 if (old->flags & NFS_MOUNT_UNSHARED)
1571 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
1573 return nfs_compare_mount_options(sb, server, mntflags);
1576 static int nfs_bdi_register(struct nfs_server *server)
1578 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
1581 static int nfs_get_sb(struct file_system_type *fs_type,
1582 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1584 struct nfs_server *server = NULL;
1585 struct super_block *s;
1586 struct nfs_parsed_mount_data *data;
1587 struct nfs_fh *mntfh;
1588 struct dentry *mntroot;
1589 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
1590 struct nfs_sb_mountdata sb_mntdata = {
1593 int error = -ENOMEM;
1595 data = kzalloc(sizeof(*data), GFP_KERNEL);
1596 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
1597 if (data == NULL || mntfh == NULL)
1600 security_init_mnt_opts(&data->lsm_opts);
1602 /* Validate the mount data */
1603 error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
1607 /* Get a volume representation */
1608 server = nfs_create_server(data, mntfh);
1609 if (IS_ERR(server)) {
1610 error = PTR_ERR(server);
1613 sb_mntdata.server = server;
1615 if (server->flags & NFS_MOUNT_UNSHARED)
1616 compare_super = NULL;
1618 /* Get a superblock - note that we may end up sharing one that already exists */
1619 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
1625 if (s->s_fs_info != server) {
1626 nfs_free_server(server);
1629 error = nfs_bdi_register(server);
1631 goto error_splat_super;
1635 /* initial superblock/root creation */
1636 nfs_fill_super(s, data);
1639 mntroot = nfs_get_root(s, mntfh);
1640 if (IS_ERR(mntroot)) {
1641 error = PTR_ERR(mntroot);
1642 goto error_splat_super;
1645 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
1647 goto error_splat_root;
1649 s->s_flags |= MS_ACTIVE;
1651 mnt->mnt_root = mntroot;
1655 kfree(data->nfs_server.hostname);
1656 kfree(data->mount_server.hostname);
1657 security_free_mnt_opts(&data->lsm_opts);
1664 nfs_free_server(server);
1670 up_write(&s->s_umount);
1671 deactivate_super(s);
1676 * Destroy an NFS2/3 superblock
1678 static void nfs_kill_super(struct super_block *s)
1680 struct nfs_server *server = NFS_SB(s);
1682 bdi_unregister(&server->backing_dev_info);
1684 nfs_free_server(server);
1688 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
1690 static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
1691 const char *dev_name, void *raw_data,
1692 struct vfsmount *mnt)
1694 struct nfs_clone_mount *data = raw_data;
1695 struct super_block *s;
1696 struct nfs_server *server;
1697 struct dentry *mntroot;
1698 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
1699 struct nfs_sb_mountdata sb_mntdata = {
1704 dprintk("--> nfs_xdev_get_sb()\n");
1706 /* create a new volume representation */
1707 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1708 if (IS_ERR(server)) {
1709 error = PTR_ERR(server);
1710 goto out_err_noserver;
1712 sb_mntdata.server = server;
1714 if (server->flags & NFS_MOUNT_UNSHARED)
1715 compare_super = NULL;
1717 /* Get a superblock - note that we may end up sharing one that already exists */
1718 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
1724 if (s->s_fs_info != server) {
1725 nfs_free_server(server);
1728 error = nfs_bdi_register(server);
1730 goto error_splat_super;
1734 /* initial superblock/root creation */
1735 nfs_clone_super(s, data->sb);
1738 mntroot = nfs_get_root(s, data->fh);
1739 if (IS_ERR(mntroot)) {
1740 error = PTR_ERR(mntroot);
1741 goto error_splat_super;
1743 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
1746 goto error_splat_super;
1749 s->s_flags |= MS_ACTIVE;
1751 mnt->mnt_root = mntroot;
1753 /* clone any lsm security options from the parent to the new sb */
1754 security_sb_clone_mnt_opts(data->sb, s);
1756 dprintk("<-- nfs_xdev_get_sb() = 0\n");
1760 nfs_free_server(server);
1762 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
1766 up_write(&s->s_umount);
1767 deactivate_super(s);
1768 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
1772 #ifdef CONFIG_NFS_V4
1775 * Finish setting up a cloned NFS4 superblock
1777 static void nfs4_clone_super(struct super_block *sb,
1778 const struct super_block *old_sb)
1780 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1781 sb->s_blocksize = old_sb->s_blocksize;
1782 sb->s_maxbytes = old_sb->s_maxbytes;
1783 sb->s_time_gran = 1;
1784 sb->s_op = old_sb->s_op;
1785 nfs_initialise_sb(sb);
1789 * Set up an NFS4 superblock
1791 static void nfs4_fill_super(struct super_block *sb)
1793 sb->s_time_gran = 1;
1794 sb->s_op = &nfs4_sops;
1795 nfs_initialise_sb(sb);
1799 * Validate NFSv4 mount options
1801 static int nfs4_validate_mount_data(void *options,
1802 struct nfs_parsed_mount_data *args,
1803 const char *dev_name)
1805 struct sockaddr_in *ap;
1806 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
1812 args->rsize = NFS_MAX_FILE_IO_SIZE;
1813 args->wsize = NFS_MAX_FILE_IO_SIZE;
1817 args->acregmax = 60;
1818 args->acdirmin = 30;
1819 args->acdirmax = 60;
1820 args->nfs_server.port = NFS_PORT; /* 2049 unless user set port= */
1821 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1823 switch (data->version) {
1825 ap = (struct sockaddr_in *)&args->nfs_server.address;
1826 if (data->host_addrlen > sizeof(args->nfs_server.address))
1827 goto out_no_address;
1828 if (data->host_addrlen == 0)
1829 goto out_no_address;
1830 args->nfs_server.addrlen = data->host_addrlen;
1831 if (copy_from_user(ap, data->host_addr, data->host_addrlen))
1833 if (!nfs_verify_server_address((struct sockaddr *)
1834 &args->nfs_server.address))
1835 goto out_no_address;
1837 switch (data->auth_flavourlen) {
1839 args->auth_flavors[0] = RPC_AUTH_UNIX;
1842 if (copy_from_user(&args->auth_flavors[0],
1843 data->auth_flavours,
1844 sizeof(args->auth_flavors[0])))
1848 goto out_inval_auth;
1851 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
1854 args->nfs_server.hostname = c;
1856 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
1859 args->nfs_server.export_path = c;
1860 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
1862 c = strndup_user(data->client_addr.data, 16);
1865 args->client_address = c;
1868 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
1872 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
1873 args->rsize = data->rsize;
1874 args->wsize = data->wsize;
1875 args->timeo = data->timeo;
1876 args->retrans = data->retrans;
1877 args->acregmin = data->acregmin;
1878 args->acregmax = data->acregmax;
1879 args->acdirmin = data->acdirmin;
1880 args->acdirmax = data->acdirmax;
1881 args->nfs_server.protocol = data->proto;
1887 if (nfs_parse_mount_options((char *)options, args) == 0)
1890 if (!nfs_verify_server_address((struct sockaddr *)
1891 &args->nfs_server.address))
1894 switch (args->auth_flavor_len) {
1896 args->auth_flavors[0] = RPC_AUTH_UNIX;
1901 goto out_inval_auth;
1905 * Split "dev_name" into "hostname:mntpath".
1907 c = strchr(dev_name, ':');
1910 /* while calculating len, pretend ':' is '\0' */
1912 if (len > NFS4_MAXNAMLEN)
1913 return -ENAMETOOLONG;
1914 /* N.B. caller will free nfs_server.hostname in all cases */
1915 args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL);
1916 if (!args->nfs_server.hostname)
1919 c++; /* step over the ':' */
1921 if (len > NFS4_MAXPATHLEN)
1922 return -ENAMETOOLONG;
1923 args->nfs_server.export_path = kstrndup(c, len, GFP_KERNEL);
1924 if (!args->nfs_server.export_path)
1927 dprintk("NFS: MNTPATH: '%s'\n", args->nfs_server.export_path);
1929 if (args->client_address == NULL)
1930 goto out_no_client_address;
1939 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
1943 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
1944 data->auth_flavourlen);
1948 dfprintk(MOUNT, "NFS4: not enough memory to handle mount options\n");
1952 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
1955 out_no_client_address:
1956 dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
1961 * Get the superblock for an NFS4 mountpoint
1963 static int nfs4_get_sb(struct file_system_type *fs_type,
1964 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1966 struct nfs_parsed_mount_data *data;
1967 struct super_block *s;
1968 struct nfs_server *server;
1969 struct nfs_fh *mntfh;
1970 struct dentry *mntroot;
1971 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
1972 struct nfs_sb_mountdata sb_mntdata = {
1975 int error = -ENOMEM;
1977 data = kzalloc(sizeof(*data), GFP_KERNEL);
1978 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
1979 if (data == NULL || mntfh == NULL)
1982 security_init_mnt_opts(&data->lsm_opts);
1984 /* Validate the mount data */
1985 error = nfs4_validate_mount_data(raw_data, data, dev_name);
1989 /* Get a volume representation */
1990 server = nfs4_create_server(data, mntfh);
1991 if (IS_ERR(server)) {
1992 error = PTR_ERR(server);
1995 sb_mntdata.server = server;
1997 if (server->flags & NFS4_MOUNT_UNSHARED)
1998 compare_super = NULL;
2000 /* Get a superblock - note that we may end up sharing one that already exists */
2001 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
2007 if (s->s_fs_info != server) {
2008 nfs_free_server(server);
2011 error = nfs_bdi_register(server);
2013 goto error_splat_super;
2017 /* initial superblock/root creation */
2021 mntroot = nfs4_get_root(s, mntfh);
2022 if (IS_ERR(mntroot)) {
2023 error = PTR_ERR(mntroot);
2024 goto error_splat_super;
2027 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
2029 goto error_splat_root;
2031 s->s_flags |= MS_ACTIVE;
2033 mnt->mnt_root = mntroot;
2037 kfree(data->client_address);
2038 kfree(data->nfs_server.export_path);
2039 kfree(data->nfs_server.hostname);
2040 security_free_mnt_opts(&data->lsm_opts);
2047 nfs_free_server(server);
2053 up_write(&s->s_umount);
2054 deactivate_super(s);
2058 static void nfs4_kill_super(struct super_block *sb)
2060 struct nfs_server *server = NFS_SB(sb);
2062 nfs_return_all_delegations(sb);
2063 kill_anon_super(sb);
2065 nfs4_renewd_prepare_shutdown(server);
2066 nfs_free_server(server);
2070 * Clone an NFS4 server record on xdev traversal (FSID-change)
2072 static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
2073 const char *dev_name, void *raw_data,
2074 struct vfsmount *mnt)
2076 struct nfs_clone_mount *data = raw_data;
2077 struct super_block *s;
2078 struct nfs_server *server;
2079 struct dentry *mntroot;
2080 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2081 struct nfs_sb_mountdata sb_mntdata = {
2086 dprintk("--> nfs4_xdev_get_sb()\n");
2088 /* create a new volume representation */
2089 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2090 if (IS_ERR(server)) {
2091 error = PTR_ERR(server);
2092 goto out_err_noserver;
2094 sb_mntdata.server = server;
2096 if (server->flags & NFS4_MOUNT_UNSHARED)
2097 compare_super = NULL;
2099 /* Get a superblock - note that we may end up sharing one that already exists */
2100 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2106 if (s->s_fs_info != server) {
2107 nfs_free_server(server);
2110 error = nfs_bdi_register(server);
2112 goto error_splat_super;
2116 /* initial superblock/root creation */
2117 nfs4_clone_super(s, data->sb);
2120 mntroot = nfs4_get_root(s, data->fh);
2121 if (IS_ERR(mntroot)) {
2122 error = PTR_ERR(mntroot);
2123 goto error_splat_super;
2125 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2128 goto error_splat_super;
2131 s->s_flags |= MS_ACTIVE;
2133 mnt->mnt_root = mntroot;
2135 security_sb_clone_mnt_opts(data->sb, s);
2137 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2141 nfs_free_server(server);
2143 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
2147 up_write(&s->s_umount);
2148 deactivate_super(s);
2149 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
2154 * Create an NFS4 server record on referral traversal
2156 static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
2157 const char *dev_name, void *raw_data,
2158 struct vfsmount *mnt)
2160 struct nfs_clone_mount *data = raw_data;
2161 struct super_block *s;
2162 struct nfs_server *server;
2163 struct dentry *mntroot;
2164 struct nfs_fh mntfh;
2165 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2166 struct nfs_sb_mountdata sb_mntdata = {
2171 dprintk("--> nfs4_referral_get_sb()\n");
2173 /* create a new volume representation */
2174 server = nfs4_create_referral_server(data, &mntfh);
2175 if (IS_ERR(server)) {
2176 error = PTR_ERR(server);
2177 goto out_err_noserver;
2179 sb_mntdata.server = server;
2181 if (server->flags & NFS4_MOUNT_UNSHARED)
2182 compare_super = NULL;
2184 /* Get a superblock - note that we may end up sharing one that already exists */
2185 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2191 if (s->s_fs_info != server) {
2192 nfs_free_server(server);
2195 error = nfs_bdi_register(server);
2197 goto error_splat_super;
2201 /* initial superblock/root creation */
2205 mntroot = nfs4_get_root(s, &mntfh);
2206 if (IS_ERR(mntroot)) {
2207 error = PTR_ERR(mntroot);
2208 goto error_splat_super;
2210 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2213 goto error_splat_super;
2216 s->s_flags |= MS_ACTIVE;
2218 mnt->mnt_root = mntroot;
2220 security_sb_clone_mnt_opts(data->sb, s);
2222 dprintk("<-- nfs4_referral_get_sb() = 0\n");
2226 nfs_free_server(server);
2228 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
2232 up_write(&s->s_umount);
2233 deactivate_super(s);
2234 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
2238 #endif /* CONFIG_NFS_V4 */