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/netdevice.h>
51 #include <linux/nfs_xdr.h>
52 #include <linux/magic.h>
53 #include <linux/parser.h>
55 #include <asm/system.h>
56 #include <asm/uaccess.h>
60 #include "delegation.h"
64 #define NFSDBG_FACILITY NFSDBG_VFS
67 /* 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_userspace, "retry=%s" },
106 { Opt_soft, "soft" },
107 { Opt_hard, "hard" },
108 { Opt_deprecated, "intr" },
109 { Opt_deprecated, "nointr" },
110 { Opt_posix, "posix" },
111 { Opt_noposix, "noposix" },
113 { Opt_nocto, "nocto" },
115 { Opt_noac, "noac" },
116 { Opt_lock, "lock" },
117 { Opt_nolock, "nolock" },
122 { Opt_rdma, "rdma" },
124 { Opt_noacl, "noacl" },
125 { Opt_rdirplus, "rdirplus" },
126 { Opt_nordirplus, "nordirplus" },
127 { Opt_sharecache, "sharecache" },
128 { Opt_nosharecache, "nosharecache" },
130 { Opt_port, "port=%u" },
131 { Opt_rsize, "rsize=%u" },
132 { Opt_wsize, "wsize=%u" },
133 { Opt_bsize, "bsize=%u" },
134 { Opt_timeo, "timeo=%u" },
135 { Opt_retrans, "retrans=%u" },
136 { Opt_acregmin, "acregmin=%u" },
137 { Opt_acregmax, "acregmax=%u" },
138 { Opt_acdirmin, "acdirmin=%u" },
139 { Opt_acdirmax, "acdirmax=%u" },
140 { Opt_actimeo, "actimeo=%u" },
141 { Opt_namelen, "namlen=%u" },
142 { Opt_mountport, "mountport=%u" },
143 { Opt_mountvers, "mountvers=%u" },
144 { Opt_nfsvers, "nfsvers=%u" },
145 { Opt_nfsvers, "vers=%u" },
147 { Opt_sec, "sec=%s" },
148 { Opt_proto, "proto=%s" },
149 { Opt_mountproto, "mountproto=%s" },
150 { Opt_addr, "addr=%s" },
151 { Opt_clientaddr, "clientaddr=%s" },
152 { Opt_mounthost, "mounthost=%s" },
153 { Opt_mountaddr, "mountaddr=%s" },
159 Opt_xprt_udp, Opt_xprt_tcp, Opt_xprt_rdma,
164 static match_table_t nfs_xprt_protocol_tokens = {
165 { Opt_xprt_udp, "udp" },
166 { Opt_xprt_tcp, "tcp" },
167 { Opt_xprt_rdma, "rdma" },
169 { Opt_xprt_err, NULL }
173 Opt_sec_none, Opt_sec_sys,
174 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
175 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
176 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
181 static match_table_t nfs_secflavor_tokens = {
182 { Opt_sec_none, "none" },
183 { Opt_sec_none, "null" },
184 { Opt_sec_sys, "sys" },
186 { Opt_sec_krb5, "krb5" },
187 { Opt_sec_krb5i, "krb5i" },
188 { Opt_sec_krb5p, "krb5p" },
190 { Opt_sec_lkey, "lkey" },
191 { Opt_sec_lkeyi, "lkeyi" },
192 { Opt_sec_lkeyp, "lkeyp" },
194 { Opt_sec_spkm, "spkm3" },
195 { Opt_sec_spkmi, "spkm3i" },
196 { Opt_sec_spkmp, "spkm3p" },
198 { Opt_sec_err, NULL }
202 static void nfs_umount_begin(struct super_block *);
203 static int nfs_statfs(struct dentry *, struct kstatfs *);
204 static int nfs_show_options(struct seq_file *, struct vfsmount *);
205 static int nfs_show_stats(struct seq_file *, struct vfsmount *);
206 static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
207 static int nfs_xdev_get_sb(struct file_system_type *fs_type,
208 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
209 static void nfs_kill_super(struct super_block *);
210 static void nfs_put_super(struct super_block *);
211 static int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
213 static struct file_system_type nfs_fs_type = {
214 .owner = THIS_MODULE,
216 .get_sb = nfs_get_sb,
217 .kill_sb = nfs_kill_super,
218 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
221 struct file_system_type nfs_xdev_fs_type = {
222 .owner = THIS_MODULE,
224 .get_sb = nfs_xdev_get_sb,
225 .kill_sb = nfs_kill_super,
226 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
229 static const struct super_operations nfs_sops = {
230 .alloc_inode = nfs_alloc_inode,
231 .destroy_inode = nfs_destroy_inode,
232 .write_inode = nfs_write_inode,
233 .put_super = nfs_put_super,
234 .statfs = nfs_statfs,
235 .clear_inode = nfs_clear_inode,
236 .umount_begin = nfs_umount_begin,
237 .show_options = nfs_show_options,
238 .show_stats = nfs_show_stats,
239 .remount_fs = nfs_remount,
243 static int nfs4_get_sb(struct file_system_type *fs_type,
244 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
245 static int nfs4_xdev_get_sb(struct file_system_type *fs_type,
246 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
247 static int nfs4_referral_get_sb(struct file_system_type *fs_type,
248 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
249 static void nfs4_kill_super(struct super_block *sb);
251 static struct file_system_type nfs4_fs_type = {
252 .owner = THIS_MODULE,
254 .get_sb = nfs4_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_xdev_fs_type = {
260 .owner = THIS_MODULE,
262 .get_sb = nfs4_xdev_get_sb,
263 .kill_sb = nfs4_kill_super,
264 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
267 struct file_system_type nfs4_referral_fs_type = {
268 .owner = THIS_MODULE,
270 .get_sb = nfs4_referral_get_sb,
271 .kill_sb = nfs4_kill_super,
272 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
275 static const struct super_operations nfs4_sops = {
276 .alloc_inode = nfs_alloc_inode,
277 .destroy_inode = nfs_destroy_inode,
278 .write_inode = nfs_write_inode,
279 .statfs = nfs_statfs,
280 .clear_inode = nfs4_clear_inode,
281 .umount_begin = nfs_umount_begin,
282 .show_options = nfs_show_options,
283 .show_stats = nfs_show_stats,
284 .remount_fs = nfs_remount,
288 static struct shrinker acl_shrinker = {
289 .shrink = nfs_access_cache_shrinker,
290 .seeks = DEFAULT_SEEKS,
294 * Register the NFS filesystems
296 int __init register_nfs_fs(void)
300 ret = register_filesystem(&nfs_fs_type);
304 ret = nfs_register_sysctl();
308 ret = register_filesystem(&nfs4_fs_type);
312 register_shrinker(&acl_shrinker);
317 nfs_unregister_sysctl();
320 unregister_filesystem(&nfs_fs_type);
326 * Unregister the NFS filesystems
328 void __exit unregister_nfs_fs(void)
330 unregister_shrinker(&acl_shrinker);
332 unregister_filesystem(&nfs4_fs_type);
334 nfs_unregister_sysctl();
335 unregister_filesystem(&nfs_fs_type);
338 void nfs_sb_active(struct nfs_server *server)
340 atomic_inc(&server->active);
343 void nfs_sb_deactive(struct nfs_server *server)
345 if (atomic_dec_and_test(&server->active))
346 wake_up(&server->active_wq);
349 static void nfs_put_super(struct super_block *sb)
351 struct nfs_server *server = NFS_SB(sb);
353 * Make sure there are no outstanding ops to this server.
354 * If so, wait for them to finish before allowing the
355 * unmount to continue.
357 wait_event(server->active_wq, atomic_read(&server->active) == 0);
361 * Deliver file system statistics to userspace
363 static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
365 struct nfs_server *server = NFS_SB(dentry->d_sb);
366 unsigned char blockbits;
367 unsigned long blockres;
368 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
369 struct nfs_fattr fattr;
370 struct nfs_fsstat res = {
377 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
380 buf->f_type = NFS_SUPER_MAGIC;
383 * Current versions of glibc do not correctly handle the
384 * case where f_frsize != f_bsize. Eventually we want to
385 * report the value of wtmult in this field.
387 buf->f_frsize = dentry->d_sb->s_blocksize;
390 * On most *nix systems, f_blocks, f_bfree, and f_bavail
391 * are reported in units of f_frsize. Linux hasn't had
392 * an f_frsize field in its statfs struct until recently,
393 * thus historically Linux's sys_statfs reports these
394 * fields in units of f_bsize.
396 buf->f_bsize = dentry->d_sb->s_blocksize;
397 blockbits = dentry->d_sb->s_blocksize_bits;
398 blockres = (1 << blockbits) - 1;
399 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
400 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
401 buf->f_bavail = (res.abytes + blockres) >> blockbits;
403 buf->f_files = res.tfiles;
404 buf->f_ffree = res.afiles;
406 buf->f_namelen = server->namelen;
412 dprintk("%s: statfs error = %d\n", __func__, -error);
418 * Map the security flavour number to a name
420 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
422 static const struct {
423 rpc_authflavor_t flavour;
426 { RPC_AUTH_NULL, "null" },
427 { RPC_AUTH_UNIX, "sys" },
428 { RPC_AUTH_GSS_KRB5, "krb5" },
429 { RPC_AUTH_GSS_KRB5I, "krb5i" },
430 { RPC_AUTH_GSS_KRB5P, "krb5p" },
431 { RPC_AUTH_GSS_LKEY, "lkey" },
432 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
433 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
434 { RPC_AUTH_GSS_SPKM, "spkm" },
435 { RPC_AUTH_GSS_SPKMI, "spkmi" },
436 { RPC_AUTH_GSS_SPKMP, "spkmp" },
437 { UINT_MAX, "unknown" }
441 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
442 if (sec_flavours[i].flavour == flavour)
445 return sec_flavours[i].str;
448 static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
451 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
453 switch (sap->sa_family) {
455 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
456 seq_printf(m, ",mountaddr=" NIPQUAD_FMT,
457 NIPQUAD(sin->sin_addr.s_addr));
461 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
462 seq_printf(m, ",mountaddr=" NIP6_FMT,
463 NIP6(sin6->sin6_addr));
468 seq_printf(m, ",mountaddr=unspecified");
471 if (nfss->mountd_version || showdefaults)
472 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
473 if (nfss->mountd_port || showdefaults)
474 seq_printf(m, ",mountport=%u", nfss->mountd_port);
476 switch (nfss->mountd_protocol) {
478 seq_printf(m, ",mountproto=udp");
481 seq_printf(m, ",mountproto=tcp");
485 seq_printf(m, ",mountproto=auto");
490 * Describe the mount options in force on this server representation
492 static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
495 static const struct proc_nfs_info {
500 { NFS_MOUNT_SOFT, ",soft", ",hard" },
501 { NFS_MOUNT_INTR, ",intr", ",nointr" },
502 { NFS_MOUNT_POSIX, ",posix", "" },
503 { NFS_MOUNT_NOCTO, ",nocto", "" },
504 { NFS_MOUNT_NOAC, ",noac", "" },
505 { NFS_MOUNT_NONLM, ",nolock", "" },
506 { NFS_MOUNT_NOACL, ",noacl", "" },
507 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
508 { NFS_MOUNT_UNSHARED, ",nosharecache", ""},
511 const struct proc_nfs_info *nfs_infop;
512 struct nfs_client *clp = nfss->nfs_client;
513 u32 version = clp->rpc_ops->version;
515 seq_printf(m, ",vers=%u", version);
516 seq_printf(m, ",rsize=%u", nfss->rsize);
517 seq_printf(m, ",wsize=%u", nfss->wsize);
518 if (nfss->bsize != 0)
519 seq_printf(m, ",bsize=%u", nfss->bsize);
520 seq_printf(m, ",namlen=%u", nfss->namelen);
521 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
522 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
523 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
524 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
525 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
526 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
527 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
528 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
529 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
530 if (nfss->flags & nfs_infop->flag)
531 seq_puts(m, nfs_infop->str);
533 seq_puts(m, nfs_infop->nostr);
535 seq_printf(m, ",proto=%s",
536 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_PROTO));
538 if (nfss->port != NFS_PORT)
539 seq_printf(m, ",port=%u", nfss->port);
542 seq_printf(m, ",port=%u", nfss->port);
544 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
545 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
546 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
549 nfs_show_mountd_options(m, nfss, showdefaults);
552 if (clp->rpc_ops->version == 4)
553 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
558 * Describe the mount options on this VFS mountpoint
560 static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
562 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
564 nfs_show_mount_options(m, nfss, 0);
566 seq_printf(m, ",addr=%s",
567 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
574 * Present statistical information for this VFS mountpoint
576 static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
579 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
580 struct rpc_auth *auth = nfss->client->cl_auth;
581 struct nfs_iostats totals = { };
583 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
586 * Display all mount option settings
588 seq_printf(m, "\n\topts:\t");
589 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
590 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
591 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
592 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
593 nfs_show_mount_options(m, nfss, 1);
595 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
597 seq_printf(m, "\n\tcaps:\t");
598 seq_printf(m, "caps=0x%x", nfss->caps);
599 seq_printf(m, ",wtmult=%u", nfss->wtmult);
600 seq_printf(m, ",dtsize=%u", nfss->dtsize);
601 seq_printf(m, ",bsize=%u", nfss->bsize);
602 seq_printf(m, ",namlen=%u", nfss->namelen);
605 if (nfss->nfs_client->rpc_ops->version == 4) {
606 seq_printf(m, "\n\tnfsv4:\t");
607 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
608 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
609 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
614 * Display security flavor in effect for this mount
616 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
618 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
621 * Display superblock I/O counters
623 for_each_possible_cpu(cpu) {
624 struct nfs_iostats *stats;
627 stats = per_cpu_ptr(nfss->io_stats, cpu);
629 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
630 totals.events[i] += stats->events[i];
631 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
632 totals.bytes[i] += stats->bytes[i];
637 seq_printf(m, "\n\tevents:\t");
638 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
639 seq_printf(m, "%lu ", totals.events[i]);
640 seq_printf(m, "\n\tbytes:\t");
641 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
642 seq_printf(m, "%Lu ", totals.bytes[i]);
645 rpc_print_iostats(m, nfss->client);
651 * Begin unmount by attempting to remove all automounted mountpoints we added
652 * in response to xdev traversals and referrals
654 static void nfs_umount_begin(struct super_block *sb)
656 struct nfs_server *server = NFS_SB(sb);
657 struct rpc_clnt *rpc;
659 /* -EIO all pending I/O */
660 rpc = server->client_acl;
662 rpc_killall_tasks(rpc);
663 rpc = server->client;
665 rpc_killall_tasks(rpc);
669 * Set the port number in an address. Be agnostic about the address family.
671 static void nfs_set_port(struct sockaddr *sap, unsigned short port)
673 switch (sap->sa_family) {
675 struct sockaddr_in *ap = (struct sockaddr_in *)sap;
676 ap->sin_port = htons(port);
680 struct sockaddr_in6 *ap = (struct sockaddr_in6 *)sap;
681 ap->sin6_port = htons(port);
688 * Sanity-check a server address provided by the mount command.
690 * Address family must be initialized, and address must not be
691 * the ANY address for that family.
693 static int nfs_verify_server_address(struct sockaddr *addr)
695 switch (addr->sa_family) {
697 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
698 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
701 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
702 return !ipv6_addr_any(sa);
709 static void nfs_parse_ipv4_address(char *string, size_t str_len,
710 struct sockaddr *sap, size_t *addr_len)
712 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
713 u8 *addr = (u8 *)&sin->sin_addr.s_addr;
715 if (str_len <= INET_ADDRSTRLEN) {
716 dfprintk(MOUNT, "NFS: parsing IPv4 address %*s\n",
717 (int)str_len, string);
719 sin->sin_family = AF_INET;
720 *addr_len = sizeof(*sin);
721 if (in4_pton(string, str_len, addr, '\0', NULL))
725 sap->sa_family = AF_UNSPEC;
729 #define IPV6_SCOPE_DELIMITER '%'
731 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
732 static void nfs_parse_ipv6_scope_id(const char *string, const size_t str_len,
734 struct sockaddr_in6 *sin6)
739 if (!(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL))
741 if (*delim != IPV6_SCOPE_DELIMITER)
744 len = (string + str_len) - delim - 1;
745 p = kstrndup(delim + 1, len, GFP_KERNEL);
747 unsigned long scope_id = 0;
748 struct net_device *dev;
750 dev = dev_get_by_name(&init_net, p);
752 scope_id = dev->ifindex;
755 /* scope_id is set to zero on error */
756 strict_strtoul(p, 10, &scope_id);
760 sin6->sin6_scope_id = scope_id;
761 dfprintk(MOUNT, "NFS: IPv6 scope ID = %lu\n", scope_id);
765 static void nfs_parse_ipv6_address(char *string, size_t str_len,
766 struct sockaddr *sap, size_t *addr_len)
768 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
769 u8 *addr = (u8 *)&sin6->sin6_addr.in6_u;
772 if (str_len <= INET6_ADDRSTRLEN) {
773 dfprintk(MOUNT, "NFS: parsing IPv6 address %*s\n",
774 (int)str_len, string);
776 sin6->sin6_family = AF_INET6;
777 *addr_len = sizeof(*sin6);
778 if (in6_pton(string, str_len, addr, IPV6_SCOPE_DELIMITER, &delim)) {
779 nfs_parse_ipv6_scope_id(string, str_len, delim, sin6);
784 sap->sa_family = AF_UNSPEC;
788 static void nfs_parse_ipv6_address(char *string, size_t str_len,
789 struct sockaddr *sap, size_t *addr_len)
791 sap->sa_family = AF_UNSPEC;
797 * Construct a sockaddr based on the contents of a string that contains
798 * an IP address in presentation format.
800 * If there is a problem constructing the new sockaddr, set the address
801 * family to AF_UNSPEC.
803 static void nfs_parse_ip_address(char *string, size_t str_len,
804 struct sockaddr *sap, size_t *addr_len)
806 unsigned int i, colons;
809 for (i = 0; i < str_len; i++)
810 if (string[i] == ':')
814 nfs_parse_ipv6_address(string, str_len, sap, addr_len);
816 nfs_parse_ipv4_address(string, str_len, sap, addr_len);
820 * Sanity check the NFS transport protocol.
823 static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
825 switch (mnt->nfs_server.protocol) {
826 case XPRT_TRANSPORT_UDP:
827 case XPRT_TRANSPORT_TCP:
828 case XPRT_TRANSPORT_RDMA:
831 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
836 * For text based NFSv2/v3 mounts, the mount protocol transport default
837 * settings should depend upon the specified NFS transport.
839 static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
841 nfs_validate_transport_protocol(mnt);
843 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
844 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
846 switch (mnt->nfs_server.protocol) {
847 case XPRT_TRANSPORT_UDP:
848 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
850 case XPRT_TRANSPORT_TCP:
851 case XPRT_TRANSPORT_RDMA:
852 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
857 * Error-check and convert a string of mount options from user space into
860 static int nfs_parse_mount_options(char *raw,
861 struct nfs_parsed_mount_data *mnt)
863 char *p, *string, *secdata;
867 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
870 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
872 secdata = alloc_secdata();
876 rc = security_sb_copy_data(raw, secdata);
878 goto out_security_failure;
880 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
882 goto out_security_failure;
884 free_secdata(secdata);
886 while ((p = strsep(&raw, ",")) != NULL) {
887 substring_t args[MAX_OPT_ARGS];
893 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
895 token = match_token(p, nfs_mount_option_tokens, args);
898 mnt->flags |= NFS_MOUNT_SOFT;
901 mnt->flags &= ~NFS_MOUNT_SOFT;
904 mnt->flags |= NFS_MOUNT_POSIX;
907 mnt->flags &= ~NFS_MOUNT_POSIX;
910 mnt->flags &= ~NFS_MOUNT_NOCTO;
913 mnt->flags |= NFS_MOUNT_NOCTO;
916 mnt->flags &= ~NFS_MOUNT_NOAC;
919 mnt->flags |= NFS_MOUNT_NOAC;
922 mnt->flags &= ~NFS_MOUNT_NONLM;
925 mnt->flags |= NFS_MOUNT_NONLM;
928 mnt->flags &= ~NFS_MOUNT_VER3;
931 mnt->flags |= NFS_MOUNT_VER3;
934 mnt->flags &= ~NFS_MOUNT_TCP;
935 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
938 mnt->flags |= NFS_MOUNT_TCP;
939 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
942 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
943 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
946 mnt->flags &= ~NFS_MOUNT_NOACL;
949 mnt->flags |= NFS_MOUNT_NOACL;
952 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
955 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
958 mnt->flags &= ~NFS_MOUNT_UNSHARED;
960 case Opt_nosharecache:
961 mnt->flags |= NFS_MOUNT_UNSHARED;
965 if (match_int(args, &option))
967 if (option < 0 || option > 65535)
969 mnt->nfs_server.port = option;
972 if (match_int(args, &mnt->rsize))
976 if (match_int(args, &mnt->wsize))
980 if (match_int(args, &option))
987 if (match_int(args, &mnt->timeo))
991 if (match_int(args, &mnt->retrans))
995 if (match_int(args, &mnt->acregmin))
999 if (match_int(args, &mnt->acregmax))
1003 if (match_int(args, &mnt->acdirmin))
1007 if (match_int(args, &mnt->acdirmax))
1011 if (match_int(args, &option))
1018 mnt->acdirmax = option;
1021 if (match_int(args, &mnt->namlen))
1025 if (match_int(args, &option))
1027 if (option < 0 || option > 65535)
1029 mnt->mount_server.port = option;
1032 if (match_int(args, &option))
1036 mnt->mount_server.version = option;
1039 if (match_int(args, &option))
1043 mnt->flags &= ~NFS_MOUNT_VER3;
1046 mnt->flags |= NFS_MOUNT_VER3;
1049 goto out_unrec_vers;
1054 string = match_strdup(args);
1057 token = match_token(string, nfs_secflavor_tokens, args);
1061 * The flags setting is for v2/v3. The flavor_len
1062 * setting is for v4. v2/v3 also need to know the
1063 * difference between NULL and UNIX.
1067 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
1068 mnt->auth_flavor_len = 0;
1069 mnt->auth_flavors[0] = RPC_AUTH_NULL;
1072 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
1073 mnt->auth_flavor_len = 0;
1074 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
1077 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
1078 mnt->auth_flavor_len = 1;
1079 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
1082 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
1083 mnt->auth_flavor_len = 1;
1084 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
1087 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
1088 mnt->auth_flavor_len = 1;
1089 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
1092 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
1093 mnt->auth_flavor_len = 1;
1094 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
1097 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
1098 mnt->auth_flavor_len = 1;
1099 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
1102 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
1103 mnt->auth_flavor_len = 1;
1104 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
1107 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
1108 mnt->auth_flavor_len = 1;
1109 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
1112 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
1113 mnt->auth_flavor_len = 1;
1114 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
1117 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
1118 mnt->auth_flavor_len = 1;
1119 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
1126 string = match_strdup(args);
1129 token = match_token(string,
1130 nfs_xprt_protocol_tokens, args);
1135 mnt->flags &= ~NFS_MOUNT_TCP;
1136 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1139 mnt->flags |= NFS_MOUNT_TCP;
1140 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1143 /* vector side protocols to TCP */
1144 mnt->flags |= NFS_MOUNT_TCP;
1145 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1148 goto out_unrec_xprt;
1151 case Opt_mountproto:
1152 string = match_strdup(args);
1155 token = match_token(string,
1156 nfs_xprt_protocol_tokens, args);
1161 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
1164 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
1166 case Opt_xprt_rdma: /* not used for side protocols */
1168 goto out_unrec_xprt;
1172 string = match_strdup(args);
1175 nfs_parse_ip_address(string, strlen(string),
1177 &mnt->nfs_server.address,
1178 &mnt->nfs_server.addrlen);
1181 case Opt_clientaddr:
1182 string = match_strdup(args);
1185 kfree(mnt->client_address);
1186 mnt->client_address = string;
1189 string = match_strdup(args);
1192 kfree(mnt->mount_server.hostname);
1193 mnt->mount_server.hostname = string;
1196 string = match_strdup(args);
1199 nfs_parse_ip_address(string, strlen(string),
1201 &mnt->mount_server.address,
1202 &mnt->mount_server.addrlen);
1207 case Opt_deprecated:
1208 dfprintk(MOUNT, "NFS: ignoring mount option "
1220 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1222 out_security_failure:
1223 free_secdata(secdata);
1224 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1227 printk(KERN_INFO "NFS: unrecognized NFS version number\n");
1231 printk(KERN_INFO "NFS: unrecognized transport protocol\n");
1235 printk(KERN_INFO "NFS: unrecognized security flavor\n");
1239 printk(KERN_INFO "NFS: unknown mount option: %s\n", p);
1244 * Use the remote server's MOUNT service to request the NFS file handle
1245 * corresponding to the provided path.
1247 static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1248 struct nfs_fh *root_fh)
1250 struct sockaddr *sap = (struct sockaddr *)&args->mount_server.address;
1254 if (args->mount_server.version == 0) {
1255 if (args->flags & NFS_MOUNT_VER3)
1256 args->mount_server.version = NFS_MNT3_VERSION;
1258 args->mount_server.version = NFS_MNT_VERSION;
1261 if (args->mount_server.hostname)
1262 hostname = args->mount_server.hostname;
1264 hostname = args->nfs_server.hostname;
1267 * Construct the mount server's address.
1269 if (args->mount_server.address.ss_family == AF_UNSPEC) {
1270 memcpy(sap, &args->nfs_server.address,
1271 args->nfs_server.addrlen);
1272 args->mount_server.addrlen = args->nfs_server.addrlen;
1276 * autobind will be used if mount_server.port == 0
1278 nfs_set_port(sap, args->mount_server.port);
1281 * Now ask the mount server to map our export path
1284 status = nfs_mount(sap,
1285 args->mount_server.addrlen,
1287 args->nfs_server.export_path,
1288 args->mount_server.version,
1289 args->mount_server.protocol,
1294 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1299 static int nfs_parse_simple_hostname(const char *dev_name,
1300 char **hostname, size_t maxnamlen,
1301 char **export_path, size_t maxpathlen)
1304 char *colon, *comma;
1306 colon = strchr(dev_name, ':');
1308 goto out_bad_devname;
1310 len = colon - dev_name;
1311 if (len > maxnamlen)
1314 /* N.B. caller will free nfs_server.hostname in all cases */
1315 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
1319 /* kill possible hostname list: not supported */
1320 comma = strchr(*hostname, ',');
1321 if (comma != NULL) {
1322 if (comma == *hostname)
1323 goto out_bad_devname;
1328 len = strlen(colon);
1329 if (len > maxpathlen)
1331 *export_path = kstrndup(colon, len, GFP_KERNEL);
1335 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1339 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1343 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1347 dfprintk(MOUNT, "NFS: server hostname too long\n");
1348 return -ENAMETOOLONG;
1351 dfprintk(MOUNT, "NFS: export pathname too long\n");
1352 return -ENAMETOOLONG;
1356 * Hostname has square brackets around it because it contains one or
1357 * more colons. We look for the first closing square bracket, and a
1358 * colon must follow it.
1360 static int nfs_parse_protected_hostname(const char *dev_name,
1361 char **hostname, size_t maxnamlen,
1362 char **export_path, size_t maxpathlen)
1367 start = (char *)(dev_name + 1);
1369 end = strchr(start, ']');
1371 goto out_bad_devname;
1372 if (*(end + 1) != ':')
1373 goto out_bad_devname;
1376 if (len > maxnamlen)
1379 /* N.B. caller will free nfs_server.hostname in all cases */
1380 *hostname = kstrndup(start, len, GFP_KERNEL);
1381 if (*hostname == NULL)
1386 if (len > maxpathlen)
1388 *export_path = kstrndup(end, len, GFP_KERNEL);
1395 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1399 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1403 dfprintk(MOUNT, "NFS: server hostname too long\n");
1404 return -ENAMETOOLONG;
1407 dfprintk(MOUNT, "NFS: export pathname too long\n");
1408 return -ENAMETOOLONG;
1412 * Split "dev_name" into "hostname:export_path".
1414 * The leftmost colon demarks the split between the server's hostname
1415 * and the export path. If the hostname starts with a left square
1416 * bracket, then it may contain colons.
1418 * Note: caller frees hostname and export path, even on error.
1420 static int nfs_parse_devname(const char *dev_name,
1421 char **hostname, size_t maxnamlen,
1422 char **export_path, size_t maxpathlen)
1424 if (*dev_name == '[')
1425 return nfs_parse_protected_hostname(dev_name,
1426 hostname, maxnamlen,
1427 export_path, maxpathlen);
1429 return nfs_parse_simple_hostname(dev_name,
1430 hostname, maxnamlen,
1431 export_path, maxpathlen);
1435 * Validate the NFS2/NFS3 mount data
1436 * - fills in the mount root filehandle
1438 * For option strings, user space handles the following behaviors:
1440 * + DNS: mapping server host name to IP address ("addr=" option)
1442 * + failure mode: how to behave if a mount request can't be handled
1443 * immediately ("fg/bg" option)
1445 * + retry: how often to retry a mount request ("retry=" option)
1447 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1448 * mountproto=tcp after mountproto=udp, and so on
1450 static int nfs_validate_mount_data(void *options,
1451 struct nfs_parsed_mount_data *args,
1452 struct nfs_fh *mntfh,
1453 const char *dev_name)
1455 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
1460 args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
1461 args->rsize = NFS_MAX_FILE_IO_SIZE;
1462 args->wsize = NFS_MAX_FILE_IO_SIZE;
1463 args->acregmin = NFS_DEF_ACREGMIN;
1464 args->acregmax = NFS_DEF_ACREGMAX;
1465 args->acdirmin = NFS_DEF_ACDIRMIN;
1466 args->acdirmax = NFS_DEF_ACDIRMAX;
1467 args->mount_server.port = 0; /* autobind unless user sets port */
1468 args->nfs_server.port = 0; /* autobind unless user sets port */
1469 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1471 switch (data->version) {
1477 if (data->flags & NFS_MOUNT_VER3)
1479 data->root.size = NFS2_FHSIZE;
1480 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1482 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1485 memset(data->context, 0, sizeof(data->context));
1487 if (data->flags & NFS_MOUNT_VER3) {
1488 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1489 goto out_invalid_fh;
1490 mntfh->size = data->root.size;
1492 mntfh->size = NFS2_FHSIZE;
1495 memcpy(mntfh->data, data->root.data, mntfh->size);
1496 if (mntfh->size < sizeof(mntfh->data))
1497 memset(mntfh->data + mntfh->size, 0,
1498 sizeof(mntfh->data) - mntfh->size);
1501 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1504 args->flags = data->flags;
1505 args->rsize = data->rsize;
1506 args->wsize = data->wsize;
1507 args->timeo = data->timeo;
1508 args->retrans = data->retrans;
1509 args->acregmin = data->acregmin;
1510 args->acregmax = data->acregmax;
1511 args->acdirmin = data->acdirmin;
1512 args->acdirmax = data->acdirmax;
1514 memcpy(&args->nfs_server.address, &data->addr,
1515 sizeof(data->addr));
1516 args->nfs_server.addrlen = sizeof(data->addr);
1517 if (!nfs_verify_server_address((struct sockaddr *)
1518 &args->nfs_server.address))
1519 goto out_no_address;
1521 if (!(data->flags & NFS_MOUNT_TCP))
1522 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1523 /* N.B. caller will free nfs_server.hostname in all cases */
1524 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1525 args->namlen = data->namlen;
1526 args->bsize = data->bsize;
1527 args->auth_flavors[0] = data->pseudoflavor;
1528 if (!args->nfs_server.hostname)
1532 * The legacy version 6 binary mount data from userspace has a
1533 * field used only to transport selinux information into the
1534 * the kernel. To continue to support that functionality we
1535 * have a touch of selinux knowledge here in the NFS code. The
1536 * userspace code converted context=blah to just blah so we are
1537 * converting back to the full string selinux understands.
1539 if (data->context[0]){
1540 #ifdef CONFIG_SECURITY_SELINUX
1542 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1545 strcpy(opts_str, "context=");
1546 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1547 strcat(opts_str, &data->context[0]);
1548 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1561 if (nfs_parse_mount_options((char *)options, args) == 0)
1564 if (!nfs_verify_server_address((struct sockaddr *)
1565 &args->nfs_server.address))
1566 goto out_no_address;
1568 nfs_set_port((struct sockaddr *)&args->nfs_server.address,
1569 args->nfs_server.port);
1571 nfs_set_mount_transport_protocol(args);
1573 status = nfs_parse_devname(dev_name,
1574 &args->nfs_server.hostname,
1576 &args->nfs_server.export_path,
1579 status = nfs_try_mount(args, mntfh);
1581 kfree(args->nfs_server.export_path);
1582 args->nfs_server.export_path = NULL;
1591 if (!(args->flags & NFS_MOUNT_SECFLAVOUR))
1592 args->auth_flavors[0] = RPC_AUTH_UNIX;
1594 #ifndef CONFIG_NFS_V3
1595 if (args->flags & NFS_MOUNT_VER3)
1596 goto out_v3_not_compiled;
1597 #endif /* !CONFIG_NFS_V3 */
1602 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1606 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1611 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1614 #ifndef CONFIG_NFS_V3
1615 out_v3_not_compiled:
1616 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1617 return -EPROTONOSUPPORT;
1618 #endif /* !CONFIG_NFS_V3 */
1621 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
1625 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1629 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1634 nfs_compare_remount_data(struct nfs_server *nfss,
1635 struct nfs_parsed_mount_data *data)
1637 if (data->flags != nfss->flags ||
1638 data->rsize != nfss->rsize ||
1639 data->wsize != nfss->wsize ||
1640 data->retrans != nfss->client->cl_timeout->to_retries ||
1641 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
1642 data->acregmin != nfss->acregmin / HZ ||
1643 data->acregmax != nfss->acregmax / HZ ||
1644 data->acdirmin != nfss->acdirmin / HZ ||
1645 data->acdirmax != nfss->acdirmax / HZ ||
1646 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
1647 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
1648 memcmp(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1649 data->nfs_server.addrlen) != 0)
1656 nfs_remount(struct super_block *sb, int *flags, char *raw_data)
1659 struct nfs_server *nfss = sb->s_fs_info;
1660 struct nfs_parsed_mount_data *data;
1661 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
1662 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
1663 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
1666 * Userspace mount programs that send binary options generally send
1667 * them populated with default values. We have no way to know which
1668 * ones were explicitly specified. Fall back to legacy behavior and
1669 * just return success.
1671 if ((nfsvers == 4 && options4->version == 1) ||
1672 (nfsvers <= 3 && options->version >= 1 &&
1673 options->version <= 6))
1676 data = kzalloc(sizeof(*data), GFP_KERNEL);
1680 /* fill out struct with values from existing mount */
1681 data->flags = nfss->flags;
1682 data->rsize = nfss->rsize;
1683 data->wsize = nfss->wsize;
1684 data->retrans = nfss->client->cl_timeout->to_retries;
1685 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
1686 data->acregmin = nfss->acregmin / HZ;
1687 data->acregmax = nfss->acregmax / HZ;
1688 data->acdirmin = nfss->acdirmin / HZ;
1689 data->acdirmax = nfss->acdirmax / HZ;
1690 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
1691 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
1692 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1693 data->nfs_server.addrlen);
1695 /* overwrite those values with any that were specified */
1696 error = nfs_parse_mount_options((char *)options, data);
1700 /* compare new mount options with old ones */
1701 error = nfs_compare_remount_data(nfss, data);
1708 * Initialise the common bits of the superblock
1710 static inline void nfs_initialise_sb(struct super_block *sb)
1712 struct nfs_server *server = NFS_SB(sb);
1714 sb->s_magic = NFS_SUPER_MAGIC;
1716 /* We probably want something more informative here */
1717 snprintf(sb->s_id, sizeof(sb->s_id),
1718 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1720 if (sb->s_blocksize == 0)
1721 sb->s_blocksize = nfs_block_bits(server->wsize,
1722 &sb->s_blocksize_bits);
1724 if (server->flags & NFS_MOUNT_NOAC)
1725 sb->s_flags |= MS_SYNCHRONOUS;
1727 nfs_super_set_maxbytes(sb, server->maxfilesize);
1731 * Finish setting up an NFS2/3 superblock
1733 static void nfs_fill_super(struct super_block *sb,
1734 struct nfs_parsed_mount_data *data)
1736 struct nfs_server *server = NFS_SB(sb);
1738 sb->s_blocksize_bits = 0;
1739 sb->s_blocksize = 0;
1741 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1743 if (server->flags & NFS_MOUNT_VER3) {
1744 /* The VFS shouldn't apply the umask to mode bits. We will do
1745 * so ourselves when necessary.
1747 sb->s_flags |= MS_POSIXACL;
1748 sb->s_time_gran = 1;
1751 sb->s_op = &nfs_sops;
1752 nfs_initialise_sb(sb);
1756 * Finish setting up a cloned NFS2/3 superblock
1758 static void nfs_clone_super(struct super_block *sb,
1759 const struct super_block *old_sb)
1761 struct nfs_server *server = NFS_SB(sb);
1763 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1764 sb->s_blocksize = old_sb->s_blocksize;
1765 sb->s_maxbytes = old_sb->s_maxbytes;
1767 if (server->flags & NFS_MOUNT_VER3) {
1768 /* The VFS shouldn't apply the umask to mode bits. We will do
1769 * so ourselves when necessary.
1771 sb->s_flags |= MS_POSIXACL;
1772 sb->s_time_gran = 1;
1775 sb->s_op = old_sb->s_op;
1776 nfs_initialise_sb(sb);
1779 #define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
1781 static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
1783 const struct nfs_server *a = s->s_fs_info;
1784 const struct rpc_clnt *clnt_a = a->client;
1785 const struct rpc_clnt *clnt_b = b->client;
1787 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
1789 if (a->nfs_client != b->nfs_client)
1791 if (a->flags != b->flags)
1793 if (a->wsize != b->wsize)
1795 if (a->rsize != b->rsize)
1797 if (a->acregmin != b->acregmin)
1799 if (a->acregmax != b->acregmax)
1801 if (a->acdirmin != b->acdirmin)
1803 if (a->acdirmax != b->acdirmax)
1805 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
1812 struct nfs_sb_mountdata {
1813 struct nfs_server *server;
1817 static int nfs_set_super(struct super_block *s, void *data)
1819 struct nfs_sb_mountdata *sb_mntdata = data;
1820 struct nfs_server *server = sb_mntdata->server;
1823 s->s_flags = sb_mntdata->mntflags;
1824 s->s_fs_info = server;
1825 ret = set_anon_super(s, server);
1827 server->s_dev = s->s_dev;
1831 static int nfs_compare_super_address(struct nfs_server *server1,
1832 struct nfs_server *server2)
1834 struct sockaddr *sap1, *sap2;
1836 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
1837 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
1839 if (sap1->sa_family != sap2->sa_family)
1842 switch (sap1->sa_family) {
1844 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
1845 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
1846 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
1848 if (sin1->sin_port != sin2->sin_port)
1853 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
1854 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
1855 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
1857 if (sin1->sin6_port != sin2->sin6_port)
1868 static int nfs_compare_super(struct super_block *sb, void *data)
1870 struct nfs_sb_mountdata *sb_mntdata = data;
1871 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
1872 int mntflags = sb_mntdata->mntflags;
1874 if (!nfs_compare_super_address(old, server))
1876 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1877 if (old->flags & NFS_MOUNT_UNSHARED)
1879 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
1881 return nfs_compare_mount_options(sb, server, mntflags);
1884 static int nfs_bdi_register(struct nfs_server *server)
1886 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
1889 static int nfs_get_sb(struct file_system_type *fs_type,
1890 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1892 struct nfs_server *server = NULL;
1893 struct super_block *s;
1894 struct nfs_parsed_mount_data *data;
1895 struct nfs_fh *mntfh;
1896 struct dentry *mntroot;
1897 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
1898 struct nfs_sb_mountdata sb_mntdata = {
1901 int error = -ENOMEM;
1903 data = kzalloc(sizeof(*data), GFP_KERNEL);
1904 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
1905 if (data == NULL || mntfh == NULL)
1908 security_init_mnt_opts(&data->lsm_opts);
1910 /* Validate the mount data */
1911 error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
1915 /* Get a volume representation */
1916 server = nfs_create_server(data, mntfh);
1917 if (IS_ERR(server)) {
1918 error = PTR_ERR(server);
1921 sb_mntdata.server = server;
1923 if (server->flags & NFS_MOUNT_UNSHARED)
1924 compare_super = NULL;
1926 /* Get a superblock - note that we may end up sharing one that already exists */
1927 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
1933 if (s->s_fs_info != server) {
1934 nfs_free_server(server);
1937 error = nfs_bdi_register(server);
1939 goto error_splat_super;
1943 /* initial superblock/root creation */
1944 nfs_fill_super(s, data);
1947 mntroot = nfs_get_root(s, mntfh);
1948 if (IS_ERR(mntroot)) {
1949 error = PTR_ERR(mntroot);
1950 goto error_splat_super;
1953 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
1955 goto error_splat_root;
1957 s->s_flags |= MS_ACTIVE;
1959 mnt->mnt_root = mntroot;
1963 kfree(data->nfs_server.hostname);
1964 kfree(data->mount_server.hostname);
1965 security_free_mnt_opts(&data->lsm_opts);
1972 nfs_free_server(server);
1978 up_write(&s->s_umount);
1979 deactivate_super(s);
1984 * Destroy an NFS2/3 superblock
1986 static void nfs_kill_super(struct super_block *s)
1988 struct nfs_server *server = NFS_SB(s);
1990 bdi_unregister(&server->backing_dev_info);
1992 nfs_free_server(server);
1996 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
1998 static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
1999 const char *dev_name, void *raw_data,
2000 struct vfsmount *mnt)
2002 struct nfs_clone_mount *data = raw_data;
2003 struct super_block *s;
2004 struct nfs_server *server;
2005 struct dentry *mntroot;
2006 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2007 struct nfs_sb_mountdata sb_mntdata = {
2012 dprintk("--> nfs_xdev_get_sb()\n");
2014 /* create a new volume representation */
2015 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2016 if (IS_ERR(server)) {
2017 error = PTR_ERR(server);
2018 goto out_err_noserver;
2020 sb_mntdata.server = server;
2022 if (server->flags & NFS_MOUNT_UNSHARED)
2023 compare_super = NULL;
2025 /* Get a superblock - note that we may end up sharing one that already exists */
2026 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2032 if (s->s_fs_info != server) {
2033 nfs_free_server(server);
2036 error = nfs_bdi_register(server);
2038 goto error_splat_super;
2042 /* initial superblock/root creation */
2043 nfs_clone_super(s, data->sb);
2046 mntroot = nfs_get_root(s, data->fh);
2047 if (IS_ERR(mntroot)) {
2048 error = PTR_ERR(mntroot);
2049 goto error_splat_super;
2051 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2054 goto error_splat_super;
2057 s->s_flags |= MS_ACTIVE;
2059 mnt->mnt_root = mntroot;
2061 /* clone any lsm security options from the parent to the new sb */
2062 security_sb_clone_mnt_opts(data->sb, s);
2064 dprintk("<-- nfs_xdev_get_sb() = 0\n");
2068 nfs_free_server(server);
2070 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
2074 up_write(&s->s_umount);
2075 deactivate_super(s);
2076 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
2080 #ifdef CONFIG_NFS_V4
2083 * Finish setting up a cloned NFS4 superblock
2085 static void nfs4_clone_super(struct super_block *sb,
2086 const struct super_block *old_sb)
2088 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2089 sb->s_blocksize = old_sb->s_blocksize;
2090 sb->s_maxbytes = old_sb->s_maxbytes;
2091 sb->s_time_gran = 1;
2092 sb->s_op = old_sb->s_op;
2093 nfs_initialise_sb(sb);
2097 * Set up an NFS4 superblock
2099 static void nfs4_fill_super(struct super_block *sb)
2101 sb->s_time_gran = 1;
2102 sb->s_op = &nfs4_sops;
2103 nfs_initialise_sb(sb);
2107 * Validate NFSv4 mount options
2109 static int nfs4_validate_mount_data(void *options,
2110 struct nfs_parsed_mount_data *args,
2111 const char *dev_name)
2113 struct sockaddr_in *ap;
2114 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
2120 args->rsize = NFS_MAX_FILE_IO_SIZE;
2121 args->wsize = NFS_MAX_FILE_IO_SIZE;
2122 args->acregmin = NFS_DEF_ACREGMIN;
2123 args->acregmax = NFS_DEF_ACREGMAX;
2124 args->acdirmin = NFS_DEF_ACDIRMIN;
2125 args->acdirmax = NFS_DEF_ACDIRMAX;
2126 args->nfs_server.port = NFS_PORT; /* 2049 unless user set port= */
2128 switch (data->version) {
2130 ap = (struct sockaddr_in *)&args->nfs_server.address;
2131 if (data->host_addrlen > sizeof(args->nfs_server.address))
2132 goto out_no_address;
2133 if (data->host_addrlen == 0)
2134 goto out_no_address;
2135 args->nfs_server.addrlen = data->host_addrlen;
2136 if (copy_from_user(ap, data->host_addr, data->host_addrlen))
2138 if (!nfs_verify_server_address((struct sockaddr *)
2139 &args->nfs_server.address))
2140 goto out_no_address;
2142 switch (data->auth_flavourlen) {
2144 args->auth_flavors[0] = RPC_AUTH_UNIX;
2147 if (copy_from_user(&args->auth_flavors[0],
2148 data->auth_flavours,
2149 sizeof(args->auth_flavors[0])))
2153 goto out_inval_auth;
2156 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2159 args->nfs_server.hostname = c;
2161 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2164 args->nfs_server.export_path = c;
2165 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
2167 c = strndup_user(data->client_addr.data, 16);
2170 args->client_address = c;
2173 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2177 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2178 args->rsize = data->rsize;
2179 args->wsize = data->wsize;
2180 args->timeo = data->timeo;
2181 args->retrans = data->retrans;
2182 args->acregmin = data->acregmin;
2183 args->acregmax = data->acregmax;
2184 args->acdirmin = data->acdirmin;
2185 args->acdirmax = data->acdirmax;
2186 args->nfs_server.protocol = data->proto;
2187 nfs_validate_transport_protocol(args);
2193 if (nfs_parse_mount_options((char *)options, args) == 0)
2196 if (!nfs_verify_server_address((struct sockaddr *)
2197 &args->nfs_server.address))
2200 nfs_set_port((struct sockaddr *)&args->nfs_server.address,
2201 args->nfs_server.port);
2203 nfs_validate_transport_protocol(args);
2205 switch (args->auth_flavor_len) {
2207 args->auth_flavors[0] = RPC_AUTH_UNIX;
2212 goto out_inval_auth;
2215 if (args->client_address == NULL)
2216 goto out_no_client_address;
2218 status = nfs_parse_devname(dev_name,
2219 &args->nfs_server.hostname,
2221 &args->nfs_server.export_path,
2233 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2237 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2238 data->auth_flavourlen);
2242 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2245 out_no_client_address:
2246 dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
2251 * Get the superblock for an NFS4 mountpoint
2253 static int nfs4_get_sb(struct file_system_type *fs_type,
2254 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2256 struct nfs_parsed_mount_data *data;
2257 struct super_block *s;
2258 struct nfs_server *server;
2259 struct nfs_fh *mntfh;
2260 struct dentry *mntroot;
2261 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2262 struct nfs_sb_mountdata sb_mntdata = {
2265 int error = -ENOMEM;
2267 data = kzalloc(sizeof(*data), GFP_KERNEL);
2268 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
2269 if (data == NULL || mntfh == NULL)
2272 security_init_mnt_opts(&data->lsm_opts);
2274 /* Validate the mount data */
2275 error = nfs4_validate_mount_data(raw_data, data, dev_name);
2279 /* Get a volume representation */
2280 server = nfs4_create_server(data, mntfh);
2281 if (IS_ERR(server)) {
2282 error = PTR_ERR(server);
2285 sb_mntdata.server = server;
2287 if (server->flags & NFS4_MOUNT_UNSHARED)
2288 compare_super = NULL;
2290 /* Get a superblock - note that we may end up sharing one that already exists */
2291 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
2297 if (s->s_fs_info != server) {
2298 nfs_free_server(server);
2301 error = nfs_bdi_register(server);
2303 goto error_splat_super;
2307 /* initial superblock/root creation */
2311 mntroot = nfs4_get_root(s, mntfh);
2312 if (IS_ERR(mntroot)) {
2313 error = PTR_ERR(mntroot);
2314 goto error_splat_super;
2317 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
2319 goto error_splat_root;
2321 s->s_flags |= MS_ACTIVE;
2323 mnt->mnt_root = mntroot;
2327 kfree(data->client_address);
2328 kfree(data->nfs_server.export_path);
2329 kfree(data->nfs_server.hostname);
2330 security_free_mnt_opts(&data->lsm_opts);
2337 nfs_free_server(server);
2343 up_write(&s->s_umount);
2344 deactivate_super(s);
2348 static void nfs4_kill_super(struct super_block *sb)
2350 struct nfs_server *server = NFS_SB(sb);
2352 nfs_return_all_delegations(sb);
2353 kill_anon_super(sb);
2355 nfs4_renewd_prepare_shutdown(server);
2356 nfs_free_server(server);
2360 * Clone an NFS4 server record on xdev traversal (FSID-change)
2362 static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
2363 const char *dev_name, void *raw_data,
2364 struct vfsmount *mnt)
2366 struct nfs_clone_mount *data = raw_data;
2367 struct super_block *s;
2368 struct nfs_server *server;
2369 struct dentry *mntroot;
2370 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2371 struct nfs_sb_mountdata sb_mntdata = {
2376 dprintk("--> nfs4_xdev_get_sb()\n");
2378 /* create a new volume representation */
2379 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2380 if (IS_ERR(server)) {
2381 error = PTR_ERR(server);
2382 goto out_err_noserver;
2384 sb_mntdata.server = server;
2386 if (server->flags & NFS4_MOUNT_UNSHARED)
2387 compare_super = NULL;
2389 /* Get a superblock - note that we may end up sharing one that already exists */
2390 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2396 if (s->s_fs_info != server) {
2397 nfs_free_server(server);
2400 error = nfs_bdi_register(server);
2402 goto error_splat_super;
2406 /* initial superblock/root creation */
2407 nfs4_clone_super(s, data->sb);
2410 mntroot = nfs4_get_root(s, data->fh);
2411 if (IS_ERR(mntroot)) {
2412 error = PTR_ERR(mntroot);
2413 goto error_splat_super;
2415 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2418 goto error_splat_super;
2421 s->s_flags |= MS_ACTIVE;
2423 mnt->mnt_root = mntroot;
2425 security_sb_clone_mnt_opts(data->sb, s);
2427 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2431 nfs_free_server(server);
2433 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
2437 up_write(&s->s_umount);
2438 deactivate_super(s);
2439 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
2444 * Create an NFS4 server record on referral traversal
2446 static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
2447 const char *dev_name, void *raw_data,
2448 struct vfsmount *mnt)
2450 struct nfs_clone_mount *data = raw_data;
2451 struct super_block *s;
2452 struct nfs_server *server;
2453 struct dentry *mntroot;
2454 struct nfs_fh mntfh;
2455 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2456 struct nfs_sb_mountdata sb_mntdata = {
2461 dprintk("--> nfs4_referral_get_sb()\n");
2463 /* create a new volume representation */
2464 server = nfs4_create_referral_server(data, &mntfh);
2465 if (IS_ERR(server)) {
2466 error = PTR_ERR(server);
2467 goto out_err_noserver;
2469 sb_mntdata.server = server;
2471 if (server->flags & NFS4_MOUNT_UNSHARED)
2472 compare_super = NULL;
2474 /* Get a superblock - note that we may end up sharing one that already exists */
2475 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2481 if (s->s_fs_info != server) {
2482 nfs_free_server(server);
2485 error = nfs_bdi_register(server);
2487 goto error_splat_super;
2491 /* initial superblock/root creation */
2495 mntroot = nfs4_get_root(s, &mntfh);
2496 if (IS_ERR(mntroot)) {
2497 error = PTR_ERR(mntroot);
2498 goto error_splat_super;
2500 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2503 goto error_splat_super;
2506 s->s_flags |= MS_ACTIVE;
2508 mnt->mnt_root = mntroot;
2510 security_sb_clone_mnt_opts(data->sb, s);
2512 dprintk("<-- nfs4_referral_get_sb() = 0\n");
2516 nfs_free_server(server);
2518 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
2522 up_write(&s->s_umount);
2523 deactivate_super(s);
2524 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
2528 #endif /* CONFIG_NFS_V4 */