4 * Copyright (C) 1992 Rick Sladkey
6 * nfs superblock handling functions
9 * experimental NFS changes. Modularisation taken straight from SYS5 fs.
11 * Change to nfs_read_super() to permit NFS mounts to multi-homed hosts.
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/mnt_namespace.h>
46 #include <linux/namei.h>
47 #include <linux/nfs_idmap.h>
48 #include <linux/vfs.h>
49 #include <linux/inet.h>
50 #include <linux/in6.h>
52 #include <linux/netdevice.h>
53 #include <linux/nfs_xdr.h>
54 #include <linux/magic.h>
55 #include <linux/parser.h>
57 #include <asm/system.h>
58 #include <asm/uaccess.h>
62 #include "delegation.h"
67 #define NFSDBG_FACILITY NFSDBG_VFS
70 /* Mount options that take no arguments */
72 Opt_posix, Opt_noposix,
76 Opt_v2, Opt_v3, Opt_v4,
77 Opt_udp, Opt_tcp, Opt_rdma,
79 Opt_rdirplus, Opt_nordirplus,
80 Opt_sharecache, Opt_nosharecache,
81 Opt_resvport, Opt_noresvport,
82 Opt_fscache, Opt_nofscache,
84 /* Mount options that take integer arguments */
86 Opt_rsize, Opt_wsize, Opt_bsize,
87 Opt_timeo, Opt_retrans,
88 Opt_acregmin, Opt_acregmax,
89 Opt_acdirmin, Opt_acdirmax,
97 /* Mount options that take string arguments */
98 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
99 Opt_addr, Opt_mountaddr, Opt_clientaddr,
103 /* Special mount options */
104 Opt_userspace, Opt_deprecated, Opt_sloppy,
109 static const match_table_t nfs_mount_option_tokens = {
110 { Opt_userspace, "bg" },
111 { Opt_userspace, "fg" },
112 { Opt_userspace, "retry=%s" },
114 { Opt_sloppy, "sloppy" },
116 { Opt_soft, "soft" },
117 { Opt_hard, "hard" },
118 { Opt_deprecated, "intr" },
119 { Opt_deprecated, "nointr" },
120 { Opt_posix, "posix" },
121 { Opt_noposix, "noposix" },
123 { Opt_nocto, "nocto" },
125 { Opt_noac, "noac" },
126 { Opt_lock, "lock" },
127 { Opt_nolock, "nolock" },
133 { Opt_rdma, "rdma" },
135 { Opt_noacl, "noacl" },
136 { Opt_rdirplus, "rdirplus" },
137 { Opt_nordirplus, "nordirplus" },
138 { Opt_sharecache, "sharecache" },
139 { Opt_nosharecache, "nosharecache" },
140 { Opt_resvport, "resvport" },
141 { Opt_noresvport, "noresvport" },
142 { Opt_fscache, "fsc" },
143 { Opt_fscache_uniq, "fsc=%s" },
144 { Opt_nofscache, "nofsc" },
146 { Opt_port, "port=%s" },
147 { Opt_rsize, "rsize=%s" },
148 { Opt_wsize, "wsize=%s" },
149 { Opt_bsize, "bsize=%s" },
150 { Opt_timeo, "timeo=%s" },
151 { Opt_retrans, "retrans=%s" },
152 { Opt_acregmin, "acregmin=%s" },
153 { Opt_acregmax, "acregmax=%s" },
154 { Opt_acdirmin, "acdirmin=%s" },
155 { Opt_acdirmax, "acdirmax=%s" },
156 { Opt_actimeo, "actimeo=%s" },
157 { Opt_namelen, "namlen=%s" },
158 { Opt_mountport, "mountport=%s" },
159 { Opt_mountvers, "mountvers=%s" },
160 { Opt_nfsvers, "nfsvers=%s" },
161 { Opt_nfsvers, "vers=%s" },
162 { Opt_minorversion, "minorversion=%s" },
164 { Opt_sec, "sec=%s" },
165 { Opt_proto, "proto=%s" },
166 { Opt_mountproto, "mountproto=%s" },
167 { Opt_addr, "addr=%s" },
168 { Opt_clientaddr, "clientaddr=%s" },
169 { Opt_mounthost, "mounthost=%s" },
170 { Opt_mountaddr, "mountaddr=%s" },
172 { Opt_lookupcache, "lookupcache=%s" },
178 Opt_xprt_udp, Opt_xprt_udp6, Opt_xprt_tcp, Opt_xprt_tcp6, Opt_xprt_rdma,
183 static const match_table_t nfs_xprt_protocol_tokens = {
184 { Opt_xprt_udp, "udp" },
185 { Opt_xprt_udp6, "udp6" },
186 { Opt_xprt_tcp, "tcp" },
187 { Opt_xprt_tcp6, "tcp6" },
188 { Opt_xprt_rdma, "rdma" },
190 { Opt_xprt_err, NULL }
194 Opt_sec_none, Opt_sec_sys,
195 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
196 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
197 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
202 static const match_table_t nfs_secflavor_tokens = {
203 { Opt_sec_none, "none" },
204 { Opt_sec_none, "null" },
205 { Opt_sec_sys, "sys" },
207 { Opt_sec_krb5, "krb5" },
208 { Opt_sec_krb5i, "krb5i" },
209 { Opt_sec_krb5p, "krb5p" },
211 { Opt_sec_lkey, "lkey" },
212 { Opt_sec_lkeyi, "lkeyi" },
213 { Opt_sec_lkeyp, "lkeyp" },
215 { Opt_sec_spkm, "spkm3" },
216 { Opt_sec_spkmi, "spkm3i" },
217 { Opt_sec_spkmp, "spkm3p" },
219 { Opt_sec_err, NULL }
223 Opt_lookupcache_all, Opt_lookupcache_positive,
224 Opt_lookupcache_none,
229 static match_table_t nfs_lookupcache_tokens = {
230 { Opt_lookupcache_all, "all" },
231 { Opt_lookupcache_positive, "pos" },
232 { Opt_lookupcache_positive, "positive" },
233 { Opt_lookupcache_none, "none" },
235 { Opt_lookupcache_err, NULL }
239 static void nfs_umount_begin(struct super_block *);
240 static int nfs_statfs(struct dentry *, struct kstatfs *);
241 static int nfs_show_options(struct seq_file *, struct vfsmount *);
242 static int nfs_show_stats(struct seq_file *, struct vfsmount *);
243 static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
244 static int nfs_xdev_get_sb(struct file_system_type *fs_type,
245 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
246 static void nfs_kill_super(struct super_block *);
247 static int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
249 static struct file_system_type nfs_fs_type = {
250 .owner = THIS_MODULE,
252 .get_sb = nfs_get_sb,
253 .kill_sb = nfs_kill_super,
254 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
257 struct file_system_type nfs_xdev_fs_type = {
258 .owner = THIS_MODULE,
260 .get_sb = nfs_xdev_get_sb,
261 .kill_sb = nfs_kill_super,
262 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
265 static const struct super_operations nfs_sops = {
266 .alloc_inode = nfs_alloc_inode,
267 .destroy_inode = nfs_destroy_inode,
268 .write_inode = nfs_write_inode,
269 .statfs = nfs_statfs,
270 .clear_inode = nfs_clear_inode,
271 .umount_begin = nfs_umount_begin,
272 .show_options = nfs_show_options,
273 .show_stats = nfs_show_stats,
274 .remount_fs = nfs_remount,
278 static int nfs4_validate_text_mount_data(void *options,
279 struct nfs_parsed_mount_data *args, const char *dev_name);
280 static int nfs4_try_mount(int flags, const char *dev_name,
281 struct nfs_parsed_mount_data *data, struct vfsmount *mnt);
282 static int nfs4_get_sb(struct file_system_type *fs_type,
283 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
284 static int nfs4_remote_get_sb(struct file_system_type *fs_type,
285 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
286 static int nfs4_xdev_get_sb(struct file_system_type *fs_type,
287 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
288 static int nfs4_referral_get_sb(struct file_system_type *fs_type,
289 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
290 static int nfs4_remote_referral_get_sb(struct file_system_type *fs_type,
291 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
292 static void nfs4_kill_super(struct super_block *sb);
294 static struct file_system_type nfs4_fs_type = {
295 .owner = THIS_MODULE,
297 .get_sb = nfs4_get_sb,
298 .kill_sb = nfs4_kill_super,
299 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
302 static struct file_system_type nfs4_remote_fs_type = {
303 .owner = THIS_MODULE,
305 .get_sb = nfs4_remote_get_sb,
306 .kill_sb = nfs4_kill_super,
307 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
310 struct file_system_type nfs4_xdev_fs_type = {
311 .owner = THIS_MODULE,
313 .get_sb = nfs4_xdev_get_sb,
314 .kill_sb = nfs4_kill_super,
315 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
318 static struct file_system_type nfs4_remote_referral_fs_type = {
319 .owner = THIS_MODULE,
321 .get_sb = nfs4_remote_referral_get_sb,
322 .kill_sb = nfs4_kill_super,
323 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
326 struct file_system_type nfs4_referral_fs_type = {
327 .owner = THIS_MODULE,
329 .get_sb = nfs4_referral_get_sb,
330 .kill_sb = nfs4_kill_super,
331 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
334 static const struct super_operations nfs4_sops = {
335 .alloc_inode = nfs_alloc_inode,
336 .destroy_inode = nfs_destroy_inode,
337 .write_inode = nfs_write_inode,
338 .statfs = nfs_statfs,
339 .clear_inode = nfs4_clear_inode,
340 .umount_begin = nfs_umount_begin,
341 .show_options = nfs_show_options,
342 .show_stats = nfs_show_stats,
343 .remount_fs = nfs_remount,
347 static struct shrinker acl_shrinker = {
348 .shrink = nfs_access_cache_shrinker,
349 .seeks = DEFAULT_SEEKS,
353 * Register the NFS filesystems
355 int __init register_nfs_fs(void)
359 ret = register_filesystem(&nfs_fs_type);
363 ret = nfs_register_sysctl();
367 ret = register_filesystem(&nfs4_fs_type);
371 register_shrinker(&acl_shrinker);
376 nfs_unregister_sysctl();
379 unregister_filesystem(&nfs_fs_type);
385 * Unregister the NFS filesystems
387 void __exit unregister_nfs_fs(void)
389 unregister_shrinker(&acl_shrinker);
391 unregister_filesystem(&nfs4_fs_type);
393 nfs_unregister_sysctl();
394 unregister_filesystem(&nfs_fs_type);
397 void nfs_sb_active(struct super_block *sb)
399 struct nfs_server *server = NFS_SB(sb);
401 if (atomic_inc_return(&server->active) == 1)
402 atomic_inc(&sb->s_active);
405 void nfs_sb_deactive(struct super_block *sb)
407 struct nfs_server *server = NFS_SB(sb);
409 if (atomic_dec_and_test(&server->active))
410 deactivate_super(sb);
414 * Deliver file system statistics to userspace
416 static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
418 struct nfs_server *server = NFS_SB(dentry->d_sb);
419 unsigned char blockbits;
420 unsigned long blockres;
421 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
422 struct nfs_fattr fattr;
423 struct nfs_fsstat res = {
428 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
431 buf->f_type = NFS_SUPER_MAGIC;
434 * Current versions of glibc do not correctly handle the
435 * case where f_frsize != f_bsize. Eventually we want to
436 * report the value of wtmult in this field.
438 buf->f_frsize = dentry->d_sb->s_blocksize;
441 * On most *nix systems, f_blocks, f_bfree, and f_bavail
442 * are reported in units of f_frsize. Linux hasn't had
443 * an f_frsize field in its statfs struct until recently,
444 * thus historically Linux's sys_statfs reports these
445 * fields in units of f_bsize.
447 buf->f_bsize = dentry->d_sb->s_blocksize;
448 blockbits = dentry->d_sb->s_blocksize_bits;
449 blockres = (1 << blockbits) - 1;
450 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
451 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
452 buf->f_bavail = (res.abytes + blockres) >> blockbits;
454 buf->f_files = res.tfiles;
455 buf->f_ffree = res.afiles;
457 buf->f_namelen = server->namelen;
462 dprintk("%s: statfs error = %d\n", __func__, -error);
467 * Map the security flavour number to a name
469 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
471 static const struct {
472 rpc_authflavor_t flavour;
475 { RPC_AUTH_NULL, "null" },
476 { RPC_AUTH_UNIX, "sys" },
477 { RPC_AUTH_GSS_KRB5, "krb5" },
478 { RPC_AUTH_GSS_KRB5I, "krb5i" },
479 { RPC_AUTH_GSS_KRB5P, "krb5p" },
480 { RPC_AUTH_GSS_LKEY, "lkey" },
481 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
482 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
483 { RPC_AUTH_GSS_SPKM, "spkm" },
484 { RPC_AUTH_GSS_SPKMI, "spkmi" },
485 { RPC_AUTH_GSS_SPKMP, "spkmp" },
486 { UINT_MAX, "unknown" }
490 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
491 if (sec_flavours[i].flavour == flavour)
494 return sec_flavours[i].str;
497 static void nfs_show_mountd_netid(struct seq_file *m, struct nfs_server *nfss,
500 struct sockaddr *sap = (struct sockaddr *) &nfss->mountd_address;
502 seq_printf(m, ",mountproto=");
503 switch (sap->sa_family) {
505 switch (nfss->mountd_protocol) {
507 seq_printf(m, RPCBIND_NETID_UDP);
510 seq_printf(m, RPCBIND_NETID_TCP);
514 seq_printf(m, "auto");
518 switch (nfss->mountd_protocol) {
520 seq_printf(m, RPCBIND_NETID_UDP6);
523 seq_printf(m, RPCBIND_NETID_TCP6);
527 seq_printf(m, "auto");
532 seq_printf(m, "auto");
536 static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
539 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
541 switch (sap->sa_family) {
543 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
544 seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
548 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
549 seq_printf(m, ",mountaddr=%pI6c", &sin6->sin6_addr);
554 seq_printf(m, ",mountaddr=unspecified");
557 if (nfss->mountd_version || showdefaults)
558 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
559 if (nfss->mountd_port || showdefaults)
560 seq_printf(m, ",mountport=%u", nfss->mountd_port);
562 nfs_show_mountd_netid(m, nfss, showdefaults);
566 * Describe the mount options in force on this server representation
568 static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
571 static const struct proc_nfs_info {
576 { NFS_MOUNT_SOFT, ",soft", ",hard" },
577 { NFS_MOUNT_POSIX, ",posix", "" },
578 { NFS_MOUNT_NOCTO, ",nocto", "" },
579 { NFS_MOUNT_NOAC, ",noac", "" },
580 { NFS_MOUNT_NONLM, ",nolock", "" },
581 { NFS_MOUNT_NOACL, ",noacl", "" },
582 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
583 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
584 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
587 const struct proc_nfs_info *nfs_infop;
588 struct nfs_client *clp = nfss->nfs_client;
589 u32 version = clp->rpc_ops->version;
591 seq_printf(m, ",vers=%u", version);
592 seq_printf(m, ",rsize=%u", nfss->rsize);
593 seq_printf(m, ",wsize=%u", nfss->wsize);
594 if (nfss->bsize != 0)
595 seq_printf(m, ",bsize=%u", nfss->bsize);
596 seq_printf(m, ",namlen=%u", nfss->namelen);
597 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
598 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
599 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
600 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
601 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
602 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
603 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
604 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
605 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
606 if (nfss->flags & nfs_infop->flag)
607 seq_puts(m, nfs_infop->str);
609 seq_puts(m, nfs_infop->nostr);
611 seq_printf(m, ",proto=%s",
612 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
614 if (nfss->port != NFS_PORT)
615 seq_printf(m, ",port=%u", nfss->port);
618 seq_printf(m, ",port=%u", nfss->port);
620 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
621 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
622 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
625 nfs_show_mountd_options(m, nfss, showdefaults);
628 if (clp->rpc_ops->version == 4)
629 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
631 if (nfss->options & NFS_OPTION_FSCACHE)
632 seq_printf(m, ",fsc");
636 * Describe the mount options on this VFS mountpoint
638 static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
640 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
642 nfs_show_mount_options(m, nfss, 0);
644 seq_printf(m, ",addr=%s",
645 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
652 * Present statistical information for this VFS mountpoint
654 static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
657 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
658 struct rpc_auth *auth = nfss->client->cl_auth;
659 struct nfs_iostats totals = { };
661 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
664 * Display all mount option settings
666 seq_printf(m, "\n\topts:\t");
667 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
668 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
669 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
670 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
671 nfs_show_mount_options(m, nfss, 1);
673 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
675 seq_printf(m, "\n\tcaps:\t");
676 seq_printf(m, "caps=0x%x", nfss->caps);
677 seq_printf(m, ",wtmult=%u", nfss->wtmult);
678 seq_printf(m, ",dtsize=%u", nfss->dtsize);
679 seq_printf(m, ",bsize=%u", nfss->bsize);
680 seq_printf(m, ",namlen=%u", nfss->namelen);
683 if (nfss->nfs_client->rpc_ops->version == 4) {
684 seq_printf(m, "\n\tnfsv4:\t");
685 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
686 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
687 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
692 * Display security flavor in effect for this mount
694 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
696 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
699 * Display superblock I/O counters
701 for_each_possible_cpu(cpu) {
702 struct nfs_iostats *stats;
705 stats = per_cpu_ptr(nfss->io_stats, cpu);
707 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
708 totals.events[i] += stats->events[i];
709 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
710 totals.bytes[i] += stats->bytes[i];
711 #ifdef CONFIG_NFS_FSCACHE
712 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
713 totals.fscache[i] += stats->fscache[i];
719 seq_printf(m, "\n\tevents:\t");
720 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
721 seq_printf(m, "%lu ", totals.events[i]);
722 seq_printf(m, "\n\tbytes:\t");
723 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
724 seq_printf(m, "%Lu ", totals.bytes[i]);
725 #ifdef CONFIG_NFS_FSCACHE
726 if (nfss->options & NFS_OPTION_FSCACHE) {
727 seq_printf(m, "\n\tfsc:\t");
728 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
729 seq_printf(m, "%Lu ", totals.bytes[i]);
734 rpc_print_iostats(m, nfss->client);
740 * Begin unmount by attempting to remove all automounted mountpoints we added
741 * in response to xdev traversals and referrals
743 static void nfs_umount_begin(struct super_block *sb)
745 struct nfs_server *server;
746 struct rpc_clnt *rpc;
749 /* -EIO all pending I/O */
750 rpc = server->client_acl;
752 rpc_killall_tasks(rpc);
753 rpc = server->client;
755 rpc_killall_tasks(rpc);
758 static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(unsigned int version)
760 struct nfs_parsed_mount_data *data;
762 data = kzalloc(sizeof(*data), GFP_KERNEL);
764 data->acregmin = NFS_DEF_ACREGMIN;
765 data->acregmax = NFS_DEF_ACREGMAX;
766 data->acdirmin = NFS_DEF_ACDIRMIN;
767 data->acdirmax = NFS_DEF_ACDIRMAX;
768 data->mount_server.port = NFS_UNSPEC_PORT;
769 data->nfs_server.port = NFS_UNSPEC_PORT;
770 data->nfs_server.protocol = XPRT_TRANSPORT_TCP;
771 data->auth_flavors[0] = RPC_AUTH_UNIX;
772 data->auth_flavor_len = 1;
773 data->version = version;
774 data->minorversion = 0;
780 * Sanity-check a server address provided by the mount command.
782 * Address family must be initialized, and address must not be
783 * the ANY address for that family.
785 static int nfs_verify_server_address(struct sockaddr *addr)
787 switch (addr->sa_family) {
789 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
790 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
793 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
794 return !ipv6_addr_any(sa);
798 dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
803 * Select between a default port value and a user-specified port value.
804 * If a zero value is set, then autobind will be used.
806 static void nfs_set_port(struct sockaddr *sap, int *port,
807 const unsigned short default_port)
809 if (*port == NFS_UNSPEC_PORT)
810 *port = default_port;
812 rpc_set_port(sap, *port);
816 * Sanity check the NFS transport protocol.
819 static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
821 switch (mnt->nfs_server.protocol) {
822 case XPRT_TRANSPORT_UDP:
823 case XPRT_TRANSPORT_TCP:
824 case XPRT_TRANSPORT_RDMA:
827 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
832 * For text based NFSv2/v3 mounts, the mount protocol transport default
833 * settings should depend upon the specified NFS transport.
835 static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
837 nfs_validate_transport_protocol(mnt);
839 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
840 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
842 switch (mnt->nfs_server.protocol) {
843 case XPRT_TRANSPORT_UDP:
844 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
846 case XPRT_TRANSPORT_TCP:
847 case XPRT_TRANSPORT_RDMA:
848 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
853 * Parse the value of the 'sec=' option.
855 static int nfs_parse_security_flavors(char *value,
856 struct nfs_parsed_mount_data *mnt)
858 substring_t args[MAX_OPT_ARGS];
860 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
862 switch (match_token(value, nfs_secflavor_tokens, args)) {
864 mnt->auth_flavors[0] = RPC_AUTH_NULL;
867 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
870 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
873 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
876 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
879 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
882 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
885 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
888 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
891 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
894 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
900 mnt->auth_flavor_len = 1;
905 * Error-check and convert a string of mount options from user space into
906 * a data structure. The whole mount string is processed; bad options are
907 * skipped as they are encountered. If there were no errors, return 1;
908 * otherwise return 0 (zero).
910 static int nfs_parse_mount_options(char *raw,
911 struct nfs_parsed_mount_data *mnt)
913 char *p, *string, *secdata;
914 int rc, sloppy = 0, invalid_option = 0;
915 unsigned short protofamily = AF_UNSPEC;
916 unsigned short mountfamily = AF_UNSPEC;
919 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
922 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
924 secdata = alloc_secdata();
928 rc = security_sb_copy_data(raw, secdata);
930 goto out_security_failure;
932 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
934 goto out_security_failure;
936 free_secdata(secdata);
938 while ((p = strsep(&raw, ",")) != NULL) {
939 substring_t args[MAX_OPT_ARGS];
940 unsigned long option;
946 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
948 token = match_token(p, nfs_mount_option_tokens, args);
952 * boolean options: foo/nofoo
955 mnt->flags |= NFS_MOUNT_SOFT;
958 mnt->flags &= ~NFS_MOUNT_SOFT;
961 mnt->flags |= NFS_MOUNT_POSIX;
964 mnt->flags &= ~NFS_MOUNT_POSIX;
967 mnt->flags &= ~NFS_MOUNT_NOCTO;
970 mnt->flags |= NFS_MOUNT_NOCTO;
973 mnt->flags &= ~NFS_MOUNT_NOAC;
976 mnt->flags |= NFS_MOUNT_NOAC;
979 mnt->flags &= ~NFS_MOUNT_NONLM;
982 mnt->flags |= NFS_MOUNT_NONLM;
985 mnt->flags &= ~NFS_MOUNT_VER3;
989 mnt->flags |= NFS_MOUNT_VER3;
994 mnt->flags &= ~NFS_MOUNT_VER3;
999 mnt->flags &= ~NFS_MOUNT_TCP;
1000 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1003 mnt->flags |= NFS_MOUNT_TCP;
1004 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1007 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1008 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1009 xprt_load_transport(p);
1012 mnt->flags &= ~NFS_MOUNT_NOACL;
1015 mnt->flags |= NFS_MOUNT_NOACL;
1018 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1020 case Opt_nordirplus:
1021 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1023 case Opt_sharecache:
1024 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1026 case Opt_nosharecache:
1027 mnt->flags |= NFS_MOUNT_UNSHARED;
1030 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1032 case Opt_noresvport:
1033 mnt->flags |= NFS_MOUNT_NORESVPORT;
1036 mnt->options |= NFS_OPTION_FSCACHE;
1037 kfree(mnt->fscache_uniq);
1038 mnt->fscache_uniq = NULL;
1041 mnt->options &= ~NFS_OPTION_FSCACHE;
1042 kfree(mnt->fscache_uniq);
1043 mnt->fscache_uniq = NULL;
1045 case Opt_fscache_uniq:
1046 string = match_strdup(args);
1049 kfree(mnt->fscache_uniq);
1050 mnt->fscache_uniq = string;
1051 mnt->options |= NFS_OPTION_FSCACHE;
1055 * options that take numeric values
1058 string = match_strdup(args);
1061 rc = strict_strtoul(string, 10, &option);
1063 if (rc != 0 || option > USHORT_MAX)
1064 goto out_invalid_value;
1065 mnt->nfs_server.port = option;
1068 string = match_strdup(args);
1071 rc = strict_strtoul(string, 10, &option);
1074 goto out_invalid_value;
1075 mnt->rsize = option;
1078 string = match_strdup(args);
1081 rc = strict_strtoul(string, 10, &option);
1084 goto out_invalid_value;
1085 mnt->wsize = option;
1088 string = match_strdup(args);
1091 rc = strict_strtoul(string, 10, &option);
1094 goto out_invalid_value;
1095 mnt->bsize = option;
1098 string = match_strdup(args);
1101 rc = strict_strtoul(string, 10, &option);
1103 if (rc != 0 || option == 0)
1104 goto out_invalid_value;
1105 mnt->timeo = option;
1108 string = match_strdup(args);
1111 rc = strict_strtoul(string, 10, &option);
1113 if (rc != 0 || option == 0)
1114 goto out_invalid_value;
1115 mnt->retrans = option;
1118 string = match_strdup(args);
1121 rc = strict_strtoul(string, 10, &option);
1124 goto out_invalid_value;
1125 mnt->acregmin = option;
1128 string = match_strdup(args);
1131 rc = strict_strtoul(string, 10, &option);
1134 goto out_invalid_value;
1135 mnt->acregmax = option;
1138 string = match_strdup(args);
1141 rc = strict_strtoul(string, 10, &option);
1144 goto out_invalid_value;
1145 mnt->acdirmin = option;
1148 string = match_strdup(args);
1151 rc = strict_strtoul(string, 10, &option);
1154 goto out_invalid_value;
1155 mnt->acdirmax = option;
1158 string = match_strdup(args);
1161 rc = strict_strtoul(string, 10, &option);
1164 goto out_invalid_value;
1165 mnt->acregmin = mnt->acregmax =
1166 mnt->acdirmin = mnt->acdirmax = option;
1169 string = match_strdup(args);
1172 rc = strict_strtoul(string, 10, &option);
1175 goto out_invalid_value;
1176 mnt->namlen = option;
1179 string = match_strdup(args);
1182 rc = strict_strtoul(string, 10, &option);
1184 if (rc != 0 || option > USHORT_MAX)
1185 goto out_invalid_value;
1186 mnt->mount_server.port = option;
1189 string = match_strdup(args);
1192 rc = strict_strtoul(string, 10, &option);
1195 option < NFS_MNT_VERSION ||
1196 option > NFS_MNT3_VERSION)
1197 goto out_invalid_value;
1198 mnt->mount_server.version = option;
1201 string = match_strdup(args);
1204 rc = strict_strtoul(string, 10, &option);
1207 goto out_invalid_value;
1210 mnt->flags &= ~NFS_MOUNT_VER3;
1214 mnt->flags |= NFS_MOUNT_VER3;
1217 #ifdef CONFIG_NFS_V4
1219 mnt->flags &= ~NFS_MOUNT_VER3;
1224 goto out_invalid_value;
1227 case Opt_minorversion:
1228 string = match_strdup(args);
1231 rc = strict_strtoul(string, 10, &option);
1234 goto out_invalid_value;
1235 if (option > NFS4_MAX_MINOR_VERSION)
1236 goto out_invalid_value;
1237 mnt->minorversion = option;
1241 * options that take text values
1244 string = match_strdup(args);
1247 rc = nfs_parse_security_flavors(string, mnt);
1250 dfprintk(MOUNT, "NFS: unrecognized "
1251 "security flavor\n");
1256 string = match_strdup(args);
1259 token = match_token(string,
1260 nfs_xprt_protocol_tokens, args);
1262 protofamily = AF_INET;
1265 protofamily = AF_INET6;
1267 mnt->flags &= ~NFS_MOUNT_TCP;
1268 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1272 protofamily = AF_INET6;
1274 mnt->flags |= NFS_MOUNT_TCP;
1275 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1279 /* vector side protocols to TCP */
1280 mnt->flags |= NFS_MOUNT_TCP;
1281 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1282 xprt_load_transport(string);
1286 dfprintk(MOUNT, "NFS: unrecognized "
1287 "transport protocol\n");
1292 case Opt_mountproto:
1293 string = match_strdup(args);
1296 token = match_token(string,
1297 nfs_xprt_protocol_tokens, args);
1300 mountfamily = AF_INET;
1303 mountfamily = AF_INET6;
1305 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
1308 mountfamily = AF_INET6;
1310 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
1312 case Opt_xprt_rdma: /* not used for side protocols */
1314 dfprintk(MOUNT, "NFS: unrecognized "
1315 "transport protocol\n");
1320 string = match_strdup(args);
1323 mnt->nfs_server.addrlen =
1324 rpc_pton(string, strlen(string),
1326 &mnt->nfs_server.address,
1327 sizeof(mnt->nfs_server.address));
1329 if (mnt->nfs_server.addrlen == 0)
1330 goto out_invalid_address;
1332 case Opt_clientaddr:
1333 string = match_strdup(args);
1336 kfree(mnt->client_address);
1337 mnt->client_address = string;
1340 string = match_strdup(args);
1343 kfree(mnt->mount_server.hostname);
1344 mnt->mount_server.hostname = string;
1347 string = match_strdup(args);
1350 mnt->mount_server.addrlen =
1351 rpc_pton(string, strlen(string),
1353 &mnt->mount_server.address,
1354 sizeof(mnt->mount_server.address));
1356 if (mnt->mount_server.addrlen == 0)
1357 goto out_invalid_address;
1359 case Opt_lookupcache:
1360 string = match_strdup(args);
1363 token = match_token(string,
1364 nfs_lookupcache_tokens, args);
1367 case Opt_lookupcache_all:
1368 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1370 case Opt_lookupcache_positive:
1371 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1372 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1374 case Opt_lookupcache_none:
1375 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1378 dfprintk(MOUNT, "NFS: invalid "
1379 "lookupcache argument\n");
1389 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1392 case Opt_deprecated:
1393 dfprintk(MOUNT, "NFS: ignoring mount option "
1399 dfprintk(MOUNT, "NFS: unrecognized mount option "
1404 if (!sloppy && invalid_option)
1408 * verify that any proto=/mountproto= options match the address
1409 * familiies in the addr=/mountaddr= options.
1411 if (protofamily != AF_UNSPEC &&
1412 protofamily != mnt->nfs_server.address.ss_family)
1413 goto out_proto_mismatch;
1415 if (mountfamily != AF_UNSPEC) {
1416 if (mnt->mount_server.addrlen) {
1417 if (mountfamily != mnt->mount_server.address.ss_family)
1418 goto out_mountproto_mismatch;
1420 if (mountfamily != mnt->nfs_server.address.ss_family)
1421 goto out_mountproto_mismatch;
1427 out_mountproto_mismatch:
1428 printk(KERN_INFO "NFS: mount server address does not match mountproto= "
1432 printk(KERN_INFO "NFS: server address does not match proto= option\n");
1434 out_invalid_address:
1435 printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
1438 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
1441 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1443 out_security_failure:
1444 free_secdata(secdata);
1445 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1450 * Match the requested auth flavors with the list returned by
1451 * the server. Returns zero and sets the mount's authentication
1452 * flavor on success; returns -EACCES if server does not support
1453 * the requested flavor.
1455 static int nfs_walk_authlist(struct nfs_parsed_mount_data *args,
1456 struct nfs_mount_request *request)
1458 unsigned int i, j, server_authlist_len = *(request->auth_flav_len);
1461 * Certain releases of Linux's mountd return an empty
1462 * flavor list. To prevent behavioral regression with
1463 * these servers (ie. rejecting mounts that used to
1464 * succeed), revert to pre-2.6.32 behavior (no checking)
1465 * if the returned flavor list is empty.
1467 if (server_authlist_len == 0)
1471 * We avoid sophisticated negotiating here, as there are
1472 * plenty of cases where we can get it wrong, providing
1473 * either too little or too much security.
1475 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1476 * flavor listed first. However, some servers list
1477 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1478 * preferred default, in args->auth_flavors[0] if user
1479 * didn't specify sec= mount option.
1481 for (i = 0; i < args->auth_flavor_len; i++)
1482 for (j = 0; j < server_authlist_len; j++)
1483 if (args->auth_flavors[i] == request->auth_flavs[j]) {
1484 dfprintk(MOUNT, "NFS: using auth flavor %d\n",
1485 request->auth_flavs[j]);
1486 args->auth_flavors[0] = request->auth_flavs[j];
1490 dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n");
1491 nfs_umount(request);
1496 * Use the remote server's MOUNT service to request the NFS file handle
1497 * corresponding to the provided path.
1499 static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1500 struct nfs_fh *root_fh)
1502 rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS];
1503 unsigned int server_authlist_len = ARRAY_SIZE(server_authlist);
1504 struct nfs_mount_request request = {
1505 .sap = (struct sockaddr *)
1506 &args->mount_server.address,
1507 .dirpath = args->nfs_server.export_path,
1508 .protocol = args->mount_server.protocol,
1510 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
1511 .auth_flav_len = &server_authlist_len,
1512 .auth_flavs = server_authlist,
1516 if (args->mount_server.version == 0) {
1517 switch (args->version) {
1519 args->mount_server.version = NFS_MNT3_VERSION;
1522 args->mount_server.version = NFS_MNT_VERSION;
1525 request.version = args->mount_server.version;
1527 if (args->mount_server.hostname)
1528 request.hostname = args->mount_server.hostname;
1530 request.hostname = args->nfs_server.hostname;
1533 * Construct the mount server's address.
1535 if (args->mount_server.address.ss_family == AF_UNSPEC) {
1536 memcpy(request.sap, &args->nfs_server.address,
1537 args->nfs_server.addrlen);
1538 args->mount_server.addrlen = args->nfs_server.addrlen;
1540 request.salen = args->mount_server.addrlen;
1541 nfs_set_port(request.sap, &args->mount_server.port, 0);
1544 * Now ask the mount server to map our export path
1547 status = nfs_mount(&request);
1549 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1550 request.hostname, status);
1555 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1557 if (args->mount_server.version != NFS_MNT3_VERSION)
1559 return nfs_walk_authlist(args, &request);
1562 static int nfs_parse_simple_hostname(const char *dev_name,
1563 char **hostname, size_t maxnamlen,
1564 char **export_path, size_t maxpathlen)
1567 char *colon, *comma;
1569 colon = strchr(dev_name, ':');
1571 goto out_bad_devname;
1573 len = colon - dev_name;
1574 if (len > maxnamlen)
1577 /* N.B. caller will free nfs_server.hostname in all cases */
1578 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
1582 /* kill possible hostname list: not supported */
1583 comma = strchr(*hostname, ',');
1584 if (comma != NULL) {
1585 if (comma == *hostname)
1586 goto out_bad_devname;
1591 len = strlen(colon);
1592 if (len > maxpathlen)
1594 *export_path = kstrndup(colon, len, GFP_KERNEL);
1598 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1602 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1606 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1610 dfprintk(MOUNT, "NFS: server hostname too long\n");
1611 return -ENAMETOOLONG;
1614 dfprintk(MOUNT, "NFS: export pathname too long\n");
1615 return -ENAMETOOLONG;
1619 * Hostname has square brackets around it because it contains one or
1620 * more colons. We look for the first closing square bracket, and a
1621 * colon must follow it.
1623 static int nfs_parse_protected_hostname(const char *dev_name,
1624 char **hostname, size_t maxnamlen,
1625 char **export_path, size_t maxpathlen)
1630 start = (char *)(dev_name + 1);
1632 end = strchr(start, ']');
1634 goto out_bad_devname;
1635 if (*(end + 1) != ':')
1636 goto out_bad_devname;
1639 if (len > maxnamlen)
1642 /* N.B. caller will free nfs_server.hostname in all cases */
1643 *hostname = kstrndup(start, len, GFP_KERNEL);
1644 if (*hostname == NULL)
1649 if (len > maxpathlen)
1651 *export_path = kstrndup(end, len, GFP_KERNEL);
1658 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1662 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1666 dfprintk(MOUNT, "NFS: server hostname too long\n");
1667 return -ENAMETOOLONG;
1670 dfprintk(MOUNT, "NFS: export pathname too long\n");
1671 return -ENAMETOOLONG;
1675 * Split "dev_name" into "hostname:export_path".
1677 * The leftmost colon demarks the split between the server's hostname
1678 * and the export path. If the hostname starts with a left square
1679 * bracket, then it may contain colons.
1681 * Note: caller frees hostname and export path, even on error.
1683 static int nfs_parse_devname(const char *dev_name,
1684 char **hostname, size_t maxnamlen,
1685 char **export_path, size_t maxpathlen)
1687 if (*dev_name == '[')
1688 return nfs_parse_protected_hostname(dev_name,
1689 hostname, maxnamlen,
1690 export_path, maxpathlen);
1692 return nfs_parse_simple_hostname(dev_name,
1693 hostname, maxnamlen,
1694 export_path, maxpathlen);
1698 * Validate the NFS2/NFS3 mount data
1699 * - fills in the mount root filehandle
1701 * For option strings, user space handles the following behaviors:
1703 * + DNS: mapping server host name to IP address ("addr=" option)
1705 * + failure mode: how to behave if a mount request can't be handled
1706 * immediately ("fg/bg" option)
1708 * + retry: how often to retry a mount request ("retry=" option)
1710 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1711 * mountproto=tcp after mountproto=udp, and so on
1713 static int nfs_validate_mount_data(void *options,
1714 struct nfs_parsed_mount_data *args,
1715 struct nfs_fh *mntfh,
1716 const char *dev_name)
1718 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
1719 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
1724 switch (data->version) {
1730 if (data->flags & NFS_MOUNT_VER3)
1732 data->root.size = NFS2_FHSIZE;
1733 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1735 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1738 memset(data->context, 0, sizeof(data->context));
1740 if (data->flags & NFS_MOUNT_VER3) {
1741 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1742 goto out_invalid_fh;
1743 mntfh->size = data->root.size;
1746 mntfh->size = NFS2_FHSIZE;
1751 memcpy(mntfh->data, data->root.data, mntfh->size);
1752 if (mntfh->size < sizeof(mntfh->data))
1753 memset(mntfh->data + mntfh->size, 0,
1754 sizeof(mntfh->data) - mntfh->size);
1757 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1760 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
1761 args->rsize = data->rsize;
1762 args->wsize = data->wsize;
1763 args->timeo = data->timeo;
1764 args->retrans = data->retrans;
1765 args->acregmin = data->acregmin;
1766 args->acregmax = data->acregmax;
1767 args->acdirmin = data->acdirmin;
1768 args->acdirmax = data->acdirmax;
1770 memcpy(sap, &data->addr, sizeof(data->addr));
1771 args->nfs_server.addrlen = sizeof(data->addr);
1772 if (!nfs_verify_server_address(sap))
1773 goto out_no_address;
1775 if (!(data->flags & NFS_MOUNT_TCP))
1776 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1777 /* N.B. caller will free nfs_server.hostname in all cases */
1778 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1779 args->namlen = data->namlen;
1780 args->bsize = data->bsize;
1782 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1783 args->auth_flavors[0] = data->pseudoflavor;
1784 if (!args->nfs_server.hostname)
1788 * The legacy version 6 binary mount data from userspace has a
1789 * field used only to transport selinux information into the
1790 * the kernel. To continue to support that functionality we
1791 * have a touch of selinux knowledge here in the NFS code. The
1792 * userspace code converted context=blah to just blah so we are
1793 * converting back to the full string selinux understands.
1795 if (data->context[0]){
1796 #ifdef CONFIG_SECURITY_SELINUX
1798 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1801 strcpy(opts_str, "context=");
1802 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1803 strcat(opts_str, &data->context[0]);
1804 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1817 if (nfs_parse_mount_options((char *)options, args) == 0)
1820 if (!nfs_verify_server_address(sap))
1821 goto out_no_address;
1823 if (args->version == 4)
1824 #ifdef CONFIG_NFS_V4
1825 return nfs4_validate_text_mount_data(options,
1828 goto out_v4_not_compiled;
1831 nfs_set_port(sap, &args->nfs_server.port, 0);
1833 nfs_set_mount_transport_protocol(args);
1835 status = nfs_parse_devname(dev_name,
1836 &args->nfs_server.hostname,
1838 &args->nfs_server.export_path,
1841 status = nfs_try_mount(args, mntfh);
1843 kfree(args->nfs_server.export_path);
1844 args->nfs_server.export_path = NULL;
1853 #ifndef CONFIG_NFS_V3
1854 if (args->version == 3)
1855 goto out_v3_not_compiled;
1856 #endif /* !CONFIG_NFS_V3 */
1861 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1865 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1870 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1873 #ifndef CONFIG_NFS_V3
1874 out_v3_not_compiled:
1875 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1876 return -EPROTONOSUPPORT;
1877 #endif /* !CONFIG_NFS_V3 */
1879 #ifndef CONFIG_NFS_V4
1880 out_v4_not_compiled:
1881 dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n");
1882 return -EPROTONOSUPPORT;
1883 #endif /* !CONFIG_NFS_V4 */
1886 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
1890 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1894 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1899 nfs_compare_remount_data(struct nfs_server *nfss,
1900 struct nfs_parsed_mount_data *data)
1902 if (data->flags != nfss->flags ||
1903 data->rsize != nfss->rsize ||
1904 data->wsize != nfss->wsize ||
1905 data->retrans != nfss->client->cl_timeout->to_retries ||
1906 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
1907 data->acregmin != nfss->acregmin / HZ ||
1908 data->acregmax != nfss->acregmax / HZ ||
1909 data->acdirmin != nfss->acdirmin / HZ ||
1910 data->acdirmax != nfss->acdirmax / HZ ||
1911 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
1912 data->nfs_server.port != nfss->port ||
1913 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
1914 !rpc_cmp_addr((struct sockaddr *)&data->nfs_server.address,
1915 (struct sockaddr *)&nfss->nfs_client->cl_addr))
1922 nfs_remount(struct super_block *sb, int *flags, char *raw_data)
1925 struct nfs_server *nfss = sb->s_fs_info;
1926 struct nfs_parsed_mount_data *data;
1927 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
1928 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
1929 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
1932 * Userspace mount programs that send binary options generally send
1933 * them populated with default values. We have no way to know which
1934 * ones were explicitly specified. Fall back to legacy behavior and
1935 * just return success.
1937 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
1938 (nfsvers <= 3 && (!options || (options->version >= 1 &&
1939 options->version <= 6))))
1942 data = kzalloc(sizeof(*data), GFP_KERNEL);
1946 /* fill out struct with values from existing mount */
1947 data->flags = nfss->flags;
1948 data->rsize = nfss->rsize;
1949 data->wsize = nfss->wsize;
1950 data->retrans = nfss->client->cl_timeout->to_retries;
1951 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
1952 data->acregmin = nfss->acregmin / HZ;
1953 data->acregmax = nfss->acregmax / HZ;
1954 data->acdirmin = nfss->acdirmin / HZ;
1955 data->acdirmax = nfss->acdirmax / HZ;
1956 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
1957 data->nfs_server.port = nfss->port;
1958 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
1959 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1960 data->nfs_server.addrlen);
1962 /* overwrite those values with any that were specified */
1963 error = nfs_parse_mount_options((char *)options, data);
1967 /* compare new mount options with old ones */
1968 error = nfs_compare_remount_data(nfss, data);
1975 * Initialise the common bits of the superblock
1977 static inline void nfs_initialise_sb(struct super_block *sb)
1979 struct nfs_server *server = NFS_SB(sb);
1981 sb->s_magic = NFS_SUPER_MAGIC;
1983 /* We probably want something more informative here */
1984 snprintf(sb->s_id, sizeof(sb->s_id),
1985 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1987 if (sb->s_blocksize == 0)
1988 sb->s_blocksize = nfs_block_bits(server->wsize,
1989 &sb->s_blocksize_bits);
1991 if (server->flags & NFS_MOUNT_NOAC)
1992 sb->s_flags |= MS_SYNCHRONOUS;
1994 sb->s_bdi = &server->backing_dev_info;
1996 nfs_super_set_maxbytes(sb, server->maxfilesize);
2000 * Finish setting up an NFS2/3 superblock
2002 static void nfs_fill_super(struct super_block *sb,
2003 struct nfs_parsed_mount_data *data)
2005 struct nfs_server *server = NFS_SB(sb);
2007 sb->s_blocksize_bits = 0;
2008 sb->s_blocksize = 0;
2010 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
2012 if (server->nfs_client->rpc_ops->version == 3) {
2013 /* The VFS shouldn't apply the umask to mode bits. We will do
2014 * so ourselves when necessary.
2016 sb->s_flags |= MS_POSIXACL;
2017 sb->s_time_gran = 1;
2020 sb->s_op = &nfs_sops;
2021 nfs_initialise_sb(sb);
2025 * Finish setting up a cloned NFS2/3 superblock
2027 static void nfs_clone_super(struct super_block *sb,
2028 const struct super_block *old_sb)
2030 struct nfs_server *server = NFS_SB(sb);
2032 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2033 sb->s_blocksize = old_sb->s_blocksize;
2034 sb->s_maxbytes = old_sb->s_maxbytes;
2036 if (server->nfs_client->rpc_ops->version == 3) {
2037 /* The VFS shouldn't apply the umask to mode bits. We will do
2038 * so ourselves when necessary.
2040 sb->s_flags |= MS_POSIXACL;
2041 sb->s_time_gran = 1;
2044 sb->s_op = old_sb->s_op;
2045 nfs_initialise_sb(sb);
2048 static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
2050 const struct nfs_server *a = s->s_fs_info;
2051 const struct rpc_clnt *clnt_a = a->client;
2052 const struct rpc_clnt *clnt_b = b->client;
2054 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
2056 if (a->nfs_client != b->nfs_client)
2058 if (a->flags != b->flags)
2060 if (a->wsize != b->wsize)
2062 if (a->rsize != b->rsize)
2064 if (a->acregmin != b->acregmin)
2066 if (a->acregmax != b->acregmax)
2068 if (a->acdirmin != b->acdirmin)
2070 if (a->acdirmax != b->acdirmax)
2072 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
2079 struct nfs_sb_mountdata {
2080 struct nfs_server *server;
2084 static int nfs_set_super(struct super_block *s, void *data)
2086 struct nfs_sb_mountdata *sb_mntdata = data;
2087 struct nfs_server *server = sb_mntdata->server;
2090 s->s_flags = sb_mntdata->mntflags;
2091 s->s_fs_info = server;
2092 ret = set_anon_super(s, server);
2094 server->s_dev = s->s_dev;
2098 static int nfs_compare_super_address(struct nfs_server *server1,
2099 struct nfs_server *server2)
2101 struct sockaddr *sap1, *sap2;
2103 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
2104 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
2106 if (sap1->sa_family != sap2->sa_family)
2109 switch (sap1->sa_family) {
2111 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
2112 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
2113 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
2115 if (sin1->sin_port != sin2->sin_port)
2120 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
2121 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
2122 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
2124 if (sin1->sin6_port != sin2->sin6_port)
2135 static int nfs_compare_super(struct super_block *sb, void *data)
2137 struct nfs_sb_mountdata *sb_mntdata = data;
2138 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2139 int mntflags = sb_mntdata->mntflags;
2141 if (!nfs_compare_super_address(old, server))
2143 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2144 if (old->flags & NFS_MOUNT_UNSHARED)
2146 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2148 return nfs_compare_mount_options(sb, server, mntflags);
2151 static int nfs_bdi_register(struct nfs_server *server)
2153 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
2156 static int nfs_get_sb(struct file_system_type *fs_type,
2157 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2159 struct nfs_server *server = NULL;
2160 struct super_block *s;
2161 struct nfs_parsed_mount_data *data;
2162 struct nfs_fh *mntfh;
2163 struct dentry *mntroot;
2164 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2165 struct nfs_sb_mountdata sb_mntdata = {
2168 int error = -ENOMEM;
2170 data = nfs_alloc_parsed_mount_data(3);
2171 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
2172 if (data == NULL || mntfh == NULL)
2175 security_init_mnt_opts(&data->lsm_opts);
2177 /* Validate the mount data */
2178 error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
2182 #ifdef CONFIG_NFS_V4
2183 if (data->version == 4) {
2184 error = nfs4_try_mount(flags, dev_name, data, mnt);
2185 kfree(data->client_address);
2188 #endif /* CONFIG_NFS_V4 */
2190 /* Get a volume representation */
2191 server = nfs_create_server(data, mntfh);
2192 if (IS_ERR(server)) {
2193 error = PTR_ERR(server);
2196 sb_mntdata.server = server;
2198 if (server->flags & NFS_MOUNT_UNSHARED)
2199 compare_super = NULL;
2201 /* Get a superblock - note that we may end up sharing one that already exists */
2202 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
2208 if (s->s_fs_info != server) {
2209 nfs_free_server(server);
2212 error = nfs_bdi_register(server);
2214 goto error_splat_super;
2218 /* initial superblock/root creation */
2219 nfs_fill_super(s, data);
2220 nfs_fscache_get_super_cookie(
2221 s, data ? data->fscache_uniq : NULL, NULL);
2224 mntroot = nfs_get_root(s, mntfh);
2225 if (IS_ERR(mntroot)) {
2226 error = PTR_ERR(mntroot);
2227 goto error_splat_super;
2230 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
2232 goto error_splat_root;
2234 s->s_flags |= MS_ACTIVE;
2236 mnt->mnt_root = mntroot;
2240 kfree(data->nfs_server.hostname);
2241 kfree(data->mount_server.hostname);
2242 kfree(data->fscache_uniq);
2243 security_free_mnt_opts(&data->lsm_opts);
2250 nfs_free_server(server);
2256 deactivate_locked_super(s);
2261 * Destroy an NFS2/3 superblock
2263 static void nfs_kill_super(struct super_block *s)
2265 struct nfs_server *server = NFS_SB(s);
2268 bdi_unregister(&server->backing_dev_info);
2269 nfs_fscache_release_super_cookie(s);
2270 nfs_free_server(server);
2274 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2276 static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
2277 const char *dev_name, void *raw_data,
2278 struct vfsmount *mnt)
2280 struct nfs_clone_mount *data = raw_data;
2281 struct super_block *s;
2282 struct nfs_server *server;
2283 struct dentry *mntroot;
2284 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2285 struct nfs_sb_mountdata sb_mntdata = {
2290 dprintk("--> nfs_xdev_get_sb()\n");
2292 /* create a new volume representation */
2293 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2294 if (IS_ERR(server)) {
2295 error = PTR_ERR(server);
2296 goto out_err_noserver;
2298 sb_mntdata.server = server;
2300 if (server->flags & NFS_MOUNT_UNSHARED)
2301 compare_super = NULL;
2303 /* Get a superblock - note that we may end up sharing one that already exists */
2304 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2310 if (s->s_fs_info != server) {
2311 nfs_free_server(server);
2314 error = nfs_bdi_register(server);
2316 goto error_splat_super;
2320 /* initial superblock/root creation */
2321 nfs_clone_super(s, data->sb);
2322 nfs_fscache_get_super_cookie(s, NULL, data);
2325 mntroot = nfs_get_root(s, data->fh);
2326 if (IS_ERR(mntroot)) {
2327 error = PTR_ERR(mntroot);
2328 goto error_splat_super;
2330 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2333 goto error_splat_super;
2336 s->s_flags |= MS_ACTIVE;
2338 mnt->mnt_root = mntroot;
2340 /* clone any lsm security options from the parent to the new sb */
2341 security_sb_clone_mnt_opts(data->sb, s);
2343 dprintk("<-- nfs_xdev_get_sb() = 0\n");
2347 nfs_free_server(server);
2349 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
2353 deactivate_locked_super(s);
2354 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
2358 #ifdef CONFIG_NFS_V4
2361 * Finish setting up a cloned NFS4 superblock
2363 static void nfs4_clone_super(struct super_block *sb,
2364 const struct super_block *old_sb)
2366 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2367 sb->s_blocksize = old_sb->s_blocksize;
2368 sb->s_maxbytes = old_sb->s_maxbytes;
2369 sb->s_time_gran = 1;
2370 sb->s_op = old_sb->s_op;
2371 nfs_initialise_sb(sb);
2375 * Set up an NFS4 superblock
2377 static void nfs4_fill_super(struct super_block *sb)
2379 sb->s_time_gran = 1;
2380 sb->s_op = &nfs4_sops;
2381 nfs_initialise_sb(sb);
2384 static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2386 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3);
2389 static int nfs4_validate_text_mount_data(void *options,
2390 struct nfs_parsed_mount_data *args,
2391 const char *dev_name)
2393 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2395 nfs_set_port(sap, &args->nfs_server.port, NFS_PORT);
2397 nfs_validate_transport_protocol(args);
2399 nfs4_validate_mount_flags(args);
2401 if (args->version != 4) {
2403 "NFS4: Illegal mount version\n");
2407 if (args->auth_flavor_len > 1) {
2409 "NFS4: Too many RPC auth flavours specified\n");
2413 if (args->client_address == NULL) {
2415 "NFS4: mount program didn't pass callback address\n");
2419 return nfs_parse_devname(dev_name,
2420 &args->nfs_server.hostname,
2422 &args->nfs_server.export_path,
2427 * Validate NFSv4 mount options
2429 static int nfs4_validate_mount_data(void *options,
2430 struct nfs_parsed_mount_data *args,
2431 const char *dev_name)
2433 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2434 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
2440 switch (data->version) {
2442 if (data->host_addrlen > sizeof(args->nfs_server.address))
2443 goto out_no_address;
2444 if (data->host_addrlen == 0)
2445 goto out_no_address;
2446 args->nfs_server.addrlen = data->host_addrlen;
2447 if (copy_from_user(sap, data->host_addr, data->host_addrlen))
2449 if (!nfs_verify_server_address(sap))
2450 goto out_no_address;
2452 if (data->auth_flavourlen) {
2453 if (data->auth_flavourlen > 1)
2454 goto out_inval_auth;
2455 if (copy_from_user(&args->auth_flavors[0],
2456 data->auth_flavours,
2457 sizeof(args->auth_flavors[0])))
2461 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2464 args->nfs_server.hostname = c;
2466 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2469 args->nfs_server.export_path = c;
2470 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
2472 c = strndup_user(data->client_addr.data, 16);
2475 args->client_address = c;
2478 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2482 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2483 args->rsize = data->rsize;
2484 args->wsize = data->wsize;
2485 args->timeo = data->timeo;
2486 args->retrans = data->retrans;
2487 args->acregmin = data->acregmin;
2488 args->acregmax = data->acregmax;
2489 args->acdirmin = data->acdirmin;
2490 args->acdirmax = data->acdirmax;
2491 args->nfs_server.protocol = data->proto;
2492 nfs_validate_transport_protocol(args);
2496 if (nfs_parse_mount_options((char *)options, args) == 0)
2499 if (!nfs_verify_server_address(sap))
2502 return nfs4_validate_text_mount_data(options, args, dev_name);
2508 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2512 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2513 data->auth_flavourlen);
2517 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2522 * Get the superblock for the NFS4 root partition
2524 static int nfs4_remote_get_sb(struct file_system_type *fs_type,
2525 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2527 struct nfs_parsed_mount_data *data = raw_data;
2528 struct super_block *s;
2529 struct nfs_server *server;
2530 struct nfs_fh *mntfh;
2531 struct dentry *mntroot;
2532 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2533 struct nfs_sb_mountdata sb_mntdata = {
2536 int error = -ENOMEM;
2538 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
2539 if (data == NULL || mntfh == NULL)
2542 security_init_mnt_opts(&data->lsm_opts);
2544 /* Get a volume representation */
2545 server = nfs4_create_server(data, mntfh);
2546 if (IS_ERR(server)) {
2547 error = PTR_ERR(server);
2550 sb_mntdata.server = server;
2552 if (server->flags & NFS4_MOUNT_UNSHARED)
2553 compare_super = NULL;
2555 /* Get a superblock - note that we may end up sharing one that already exists */
2556 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2562 if (s->s_fs_info != server) {
2563 nfs_free_server(server);
2566 error = nfs_bdi_register(server);
2568 goto error_splat_super;
2572 /* initial superblock/root creation */
2574 nfs_fscache_get_super_cookie(
2575 s, data ? data->fscache_uniq : NULL, NULL);
2578 mntroot = nfs4_get_root(s, mntfh);
2579 if (IS_ERR(mntroot)) {
2580 error = PTR_ERR(mntroot);
2581 goto error_splat_super;
2584 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
2586 goto error_splat_root;
2588 s->s_flags |= MS_ACTIVE;
2590 mnt->mnt_root = mntroot;
2594 security_free_mnt_opts(&data->lsm_opts);
2600 nfs_free_server(server);
2606 deactivate_locked_super(s);
2610 static struct vfsmount *nfs_do_root_mount(struct file_system_type *fs_type,
2611 int flags, void *data, const char *hostname)
2613 struct vfsmount *root_mnt;
2617 len = strlen(hostname) + 3;
2618 root_devname = kmalloc(len, GFP_KERNEL);
2619 if (root_devname == NULL)
2620 return ERR_PTR(-ENOMEM);
2621 snprintf(root_devname, len, "%s:/", hostname);
2622 root_mnt = vfs_kern_mount(fs_type, flags, root_devname, data);
2623 kfree(root_devname);
2627 static void nfs_fix_devname(const struct path *path, struct vfsmount *mnt)
2629 char *page = (char *) __get_free_page(GFP_KERNEL);
2630 char *devname, *tmp;
2634 devname = nfs_path(path->mnt->mnt_devname,
2635 path->mnt->mnt_root, path->dentry,
2637 if (devname == NULL)
2639 tmp = kstrdup(devname, GFP_KERNEL);
2642 kfree(mnt->mnt_devname);
2643 mnt->mnt_devname = tmp;
2645 free_page((unsigned long)page);
2648 static int nfs_follow_remote_path(struct vfsmount *root_mnt,
2649 const char *export_path, struct vfsmount *mnt_target)
2651 struct mnt_namespace *ns_private;
2652 struct nameidata nd;
2653 struct super_block *s;
2656 ns_private = create_mnt_ns(root_mnt);
2657 ret = PTR_ERR(ns_private);
2658 if (IS_ERR(ns_private))
2661 ret = vfs_path_lookup(root_mnt->mnt_root, root_mnt,
2662 export_path, LOOKUP_FOLLOW, &nd);
2664 put_mnt_ns(ns_private);
2669 s = nd.path.mnt->mnt_sb;
2670 atomic_inc(&s->s_active);
2671 mnt_target->mnt_sb = s;
2672 mnt_target->mnt_root = dget(nd.path.dentry);
2674 /* Correct the device pathname */
2675 nfs_fix_devname(&nd.path, mnt_target);
2678 down_write(&s->s_umount);
2686 static int nfs4_try_mount(int flags, const char *dev_name,
2687 struct nfs_parsed_mount_data *data,
2688 struct vfsmount *mnt)
2691 struct vfsmount *root_mnt;
2694 dfprintk(MOUNT, "--> nfs4_try_mount()\n");
2696 export_path = data->nfs_server.export_path;
2697 data->nfs_server.export_path = "/";
2698 root_mnt = nfs_do_root_mount(&nfs4_remote_fs_type, flags, data,
2699 data->nfs_server.hostname);
2700 data->nfs_server.export_path = export_path;
2702 error = PTR_ERR(root_mnt);
2703 if (IS_ERR(root_mnt))
2706 error = nfs_follow_remote_path(root_mnt, export_path, mnt);
2709 dfprintk(MOUNT, "<-- nfs4_try_mount() = %d%s\n", error,
2710 error != 0 ? " [error]" : "");
2715 * Get the superblock for an NFS4 mountpoint
2717 static int nfs4_get_sb(struct file_system_type *fs_type,
2718 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2720 struct nfs_parsed_mount_data *data;
2721 int error = -ENOMEM;
2723 data = nfs_alloc_parsed_mount_data(4);
2727 /* Validate the mount data */
2728 error = nfs4_validate_mount_data(raw_data, data, dev_name);
2732 error = nfs4_try_mount(flags, dev_name, data, mnt);
2735 kfree(data->client_address);
2736 kfree(data->nfs_server.export_path);
2737 kfree(data->nfs_server.hostname);
2738 kfree(data->fscache_uniq);
2741 dprintk("<-- nfs4_get_sb() = %d%s\n", error,
2742 error != 0 ? " [error]" : "");
2746 static void nfs4_kill_super(struct super_block *sb)
2748 struct nfs_server *server = NFS_SB(sb);
2750 dprintk("--> %s\n", __func__);
2751 nfs_super_return_all_delegations(sb);
2752 kill_anon_super(sb);
2753 nfs_fscache_release_super_cookie(sb);
2754 nfs_free_server(server);
2755 dprintk("<-- %s\n", __func__);
2759 * Clone an NFS4 server record on xdev traversal (FSID-change)
2761 static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
2762 const char *dev_name, void *raw_data,
2763 struct vfsmount *mnt)
2765 struct nfs_clone_mount *data = raw_data;
2766 struct super_block *s;
2767 struct nfs_server *server;
2768 struct dentry *mntroot;
2769 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2770 struct nfs_sb_mountdata sb_mntdata = {
2775 dprintk("--> nfs4_xdev_get_sb()\n");
2777 /* create a new volume representation */
2778 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2779 if (IS_ERR(server)) {
2780 error = PTR_ERR(server);
2781 goto out_err_noserver;
2783 sb_mntdata.server = server;
2785 if (server->flags & NFS4_MOUNT_UNSHARED)
2786 compare_super = NULL;
2788 /* Get a superblock - note that we may end up sharing one that already exists */
2789 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2795 if (s->s_fs_info != server) {
2796 nfs_free_server(server);
2799 error = nfs_bdi_register(server);
2801 goto error_splat_super;
2805 /* initial superblock/root creation */
2806 nfs4_clone_super(s, data->sb);
2807 nfs_fscache_get_super_cookie(s, NULL, data);
2810 mntroot = nfs4_get_root(s, data->fh);
2811 if (IS_ERR(mntroot)) {
2812 error = PTR_ERR(mntroot);
2813 goto error_splat_super;
2815 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2818 goto error_splat_super;
2821 s->s_flags |= MS_ACTIVE;
2823 mnt->mnt_root = mntroot;
2825 security_sb_clone_mnt_opts(data->sb, s);
2827 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2831 nfs_free_server(server);
2833 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
2837 deactivate_locked_super(s);
2838 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
2842 static int nfs4_remote_referral_get_sb(struct file_system_type *fs_type,
2843 int flags, const char *dev_name, void *raw_data,
2844 struct vfsmount *mnt)
2846 struct nfs_clone_mount *data = raw_data;
2847 struct super_block *s;
2848 struct nfs_server *server;
2849 struct dentry *mntroot;
2850 struct nfs_fh mntfh;
2851 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2852 struct nfs_sb_mountdata sb_mntdata = {
2857 dprintk("--> nfs4_referral_get_sb()\n");
2859 /* create a new volume representation */
2860 server = nfs4_create_referral_server(data, &mntfh);
2861 if (IS_ERR(server)) {
2862 error = PTR_ERR(server);
2863 goto out_err_noserver;
2865 sb_mntdata.server = server;
2867 if (server->flags & NFS4_MOUNT_UNSHARED)
2868 compare_super = NULL;
2870 /* Get a superblock - note that we may end up sharing one that already exists */
2871 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2877 if (s->s_fs_info != server) {
2878 nfs_free_server(server);
2881 error = nfs_bdi_register(server);
2883 goto error_splat_super;
2887 /* initial superblock/root creation */
2889 nfs_fscache_get_super_cookie(s, NULL, data);
2892 mntroot = nfs4_get_root(s, &mntfh);
2893 if (IS_ERR(mntroot)) {
2894 error = PTR_ERR(mntroot);
2895 goto error_splat_super;
2897 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2900 goto error_splat_super;
2903 s->s_flags |= MS_ACTIVE;
2905 mnt->mnt_root = mntroot;
2907 security_sb_clone_mnt_opts(data->sb, s);
2909 dprintk("<-- nfs4_referral_get_sb() = 0\n");
2913 nfs_free_server(server);
2915 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
2919 deactivate_locked_super(s);
2920 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
2925 * Create an NFS4 server record on referral traversal
2927 static int nfs4_referral_get_sb(struct file_system_type *fs_type,
2928 int flags, const char *dev_name, void *raw_data,
2929 struct vfsmount *mnt)
2931 struct nfs_clone_mount *data = raw_data;
2933 struct vfsmount *root_mnt;
2936 dprintk("--> nfs4_referral_get_sb()\n");
2938 export_path = data->mnt_path;
2939 data->mnt_path = "/";
2941 root_mnt = nfs_do_root_mount(&nfs4_remote_referral_fs_type,
2942 flags, data, data->hostname);
2943 data->mnt_path = export_path;
2945 error = PTR_ERR(root_mnt);
2946 if (IS_ERR(root_mnt))
2949 error = nfs_follow_remote_path(root_mnt, export_path, mnt);
2951 dprintk("<-- nfs4_referral_get_sb() = %d%s\n", error,
2952 error != 0 ? " [error]" : "");
2956 #endif /* CONFIG_NFS_V4 */