4 * Copyright (C) 1992 Rick Sladkey
6 * nfs superblock handling functions
8 * Modularised by Alan Cox <alan@lxorguk.ukuu.org.uk>, 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/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,
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" },
132 { Opt_rdma, "rdma" },
134 { Opt_noacl, "noacl" },
135 { Opt_rdirplus, "rdirplus" },
136 { Opt_nordirplus, "nordirplus" },
137 { Opt_sharecache, "sharecache" },
138 { Opt_nosharecache, "nosharecache" },
139 { Opt_resvport, "resvport" },
140 { Opt_noresvport, "noresvport" },
141 { Opt_fscache, "fsc" },
142 { Opt_fscache_uniq, "fsc=%s" },
143 { Opt_nofscache, "nofsc" },
145 { Opt_port, "port=%s" },
146 { Opt_rsize, "rsize=%s" },
147 { Opt_wsize, "wsize=%s" },
148 { Opt_bsize, "bsize=%s" },
149 { Opt_timeo, "timeo=%s" },
150 { Opt_retrans, "retrans=%s" },
151 { Opt_acregmin, "acregmin=%s" },
152 { Opt_acregmax, "acregmax=%s" },
153 { Opt_acdirmin, "acdirmin=%s" },
154 { Opt_acdirmax, "acdirmax=%s" },
155 { Opt_actimeo, "actimeo=%s" },
156 { Opt_namelen, "namlen=%s" },
157 { Opt_mountport, "mountport=%s" },
158 { Opt_mountvers, "mountvers=%s" },
159 { Opt_nfsvers, "nfsvers=%s" },
160 { Opt_nfsvers, "vers=%s" },
161 { Opt_minorversion, "minorversion=%s" },
163 { Opt_sec, "sec=%s" },
164 { Opt_proto, "proto=%s" },
165 { Opt_mountproto, "mountproto=%s" },
166 { Opt_addr, "addr=%s" },
167 { Opt_clientaddr, "clientaddr=%s" },
168 { Opt_mounthost, "mounthost=%s" },
169 { Opt_mountaddr, "mountaddr=%s" },
171 { Opt_lookupcache, "lookupcache=%s" },
177 Opt_xprt_udp, Opt_xprt_tcp, Opt_xprt_rdma,
182 static const match_table_t nfs_xprt_protocol_tokens = {
183 { Opt_xprt_udp, "udp" },
184 { Opt_xprt_tcp, "tcp" },
185 { Opt_xprt_rdma, "rdma" },
187 { Opt_xprt_err, NULL }
191 Opt_sec_none, Opt_sec_sys,
192 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
193 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
194 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
199 static const match_table_t nfs_secflavor_tokens = {
200 { Opt_sec_none, "none" },
201 { Opt_sec_none, "null" },
202 { Opt_sec_sys, "sys" },
204 { Opt_sec_krb5, "krb5" },
205 { Opt_sec_krb5i, "krb5i" },
206 { Opt_sec_krb5p, "krb5p" },
208 { Opt_sec_lkey, "lkey" },
209 { Opt_sec_lkeyi, "lkeyi" },
210 { Opt_sec_lkeyp, "lkeyp" },
212 { Opt_sec_spkm, "spkm3" },
213 { Opt_sec_spkmi, "spkm3i" },
214 { Opt_sec_spkmp, "spkm3p" },
216 { Opt_sec_err, NULL }
220 Opt_lookupcache_all, Opt_lookupcache_positive,
221 Opt_lookupcache_none,
226 static match_table_t nfs_lookupcache_tokens = {
227 { Opt_lookupcache_all, "all" },
228 { Opt_lookupcache_positive, "pos" },
229 { Opt_lookupcache_positive, "positive" },
230 { Opt_lookupcache_none, "none" },
232 { Opt_lookupcache_err, NULL }
236 static void nfs_umount_begin(struct super_block *);
237 static int nfs_statfs(struct dentry *, struct kstatfs *);
238 static int nfs_show_options(struct seq_file *, struct vfsmount *);
239 static int nfs_show_stats(struct seq_file *, struct vfsmount *);
240 static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
241 static int nfs_xdev_get_sb(struct file_system_type *fs_type,
242 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
243 static void nfs_kill_super(struct super_block *);
244 static int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
246 static struct file_system_type nfs_fs_type = {
247 .owner = THIS_MODULE,
249 .get_sb = nfs_get_sb,
250 .kill_sb = nfs_kill_super,
251 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
254 struct file_system_type nfs_xdev_fs_type = {
255 .owner = THIS_MODULE,
257 .get_sb = nfs_xdev_get_sb,
258 .kill_sb = nfs_kill_super,
259 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
262 static const struct super_operations nfs_sops = {
263 .alloc_inode = nfs_alloc_inode,
264 .destroy_inode = nfs_destroy_inode,
265 .write_inode = nfs_write_inode,
266 .statfs = nfs_statfs,
267 .clear_inode = nfs_clear_inode,
268 .umount_begin = nfs_umount_begin,
269 .show_options = nfs_show_options,
270 .show_stats = nfs_show_stats,
271 .remount_fs = nfs_remount,
275 static int nfs4_validate_text_mount_data(void *options,
276 struct nfs_parsed_mount_data *args, const char *dev_name);
277 static int nfs4_get_sb(struct file_system_type *fs_type,
278 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
279 static int nfs4_remote_get_sb(struct file_system_type *fs_type,
280 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
281 static int nfs4_xdev_get_sb(struct file_system_type *fs_type,
282 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
283 static int nfs4_referral_get_sb(struct file_system_type *fs_type,
284 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
285 static int nfs4_remote_referral_get_sb(struct file_system_type *fs_type,
286 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
287 static void nfs4_kill_super(struct super_block *sb);
289 static struct file_system_type nfs4_fs_type = {
290 .owner = THIS_MODULE,
292 .get_sb = nfs4_get_sb,
293 .kill_sb = nfs4_kill_super,
294 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
297 static struct file_system_type nfs4_remote_fs_type = {
298 .owner = THIS_MODULE,
300 .get_sb = nfs4_remote_get_sb,
301 .kill_sb = nfs4_kill_super,
302 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
305 struct file_system_type nfs4_xdev_fs_type = {
306 .owner = THIS_MODULE,
308 .get_sb = nfs4_xdev_get_sb,
309 .kill_sb = nfs4_kill_super,
310 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
313 static struct file_system_type nfs4_remote_referral_fs_type = {
314 .owner = THIS_MODULE,
316 .get_sb = nfs4_remote_referral_get_sb,
317 .kill_sb = nfs4_kill_super,
318 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
321 struct file_system_type nfs4_referral_fs_type = {
322 .owner = THIS_MODULE,
324 .get_sb = nfs4_referral_get_sb,
325 .kill_sb = nfs4_kill_super,
326 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
329 static const struct super_operations nfs4_sops = {
330 .alloc_inode = nfs_alloc_inode,
331 .destroy_inode = nfs_destroy_inode,
332 .write_inode = nfs_write_inode,
333 .statfs = nfs_statfs,
334 .clear_inode = nfs4_clear_inode,
335 .umount_begin = nfs_umount_begin,
336 .show_options = nfs_show_options,
337 .show_stats = nfs_show_stats,
338 .remount_fs = nfs_remount,
342 static struct shrinker acl_shrinker = {
343 .shrink = nfs_access_cache_shrinker,
344 .seeks = DEFAULT_SEEKS,
348 * Register the NFS filesystems
350 int __init register_nfs_fs(void)
354 ret = register_filesystem(&nfs_fs_type);
358 ret = nfs_register_sysctl();
362 ret = register_filesystem(&nfs4_fs_type);
366 register_shrinker(&acl_shrinker);
371 nfs_unregister_sysctl();
374 unregister_filesystem(&nfs_fs_type);
380 * Unregister the NFS filesystems
382 void __exit unregister_nfs_fs(void)
384 unregister_shrinker(&acl_shrinker);
386 unregister_filesystem(&nfs4_fs_type);
388 nfs_unregister_sysctl();
389 unregister_filesystem(&nfs_fs_type);
392 void nfs_sb_active(struct super_block *sb)
394 struct nfs_server *server = NFS_SB(sb);
396 if (atomic_inc_return(&server->active) == 1)
397 atomic_inc(&sb->s_active);
400 void nfs_sb_deactive(struct super_block *sb)
402 struct nfs_server *server = NFS_SB(sb);
404 if (atomic_dec_and_test(&server->active))
405 deactivate_super(sb);
409 * Deliver file system statistics to userspace
411 static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
413 struct nfs_server *server = NFS_SB(dentry->d_sb);
414 unsigned char blockbits;
415 unsigned long blockres;
416 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
417 struct nfs_fattr fattr;
418 struct nfs_fsstat res = {
423 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
426 buf->f_type = NFS_SUPER_MAGIC;
429 * Current versions of glibc do not correctly handle the
430 * case where f_frsize != f_bsize. Eventually we want to
431 * report the value of wtmult in this field.
433 buf->f_frsize = dentry->d_sb->s_blocksize;
436 * On most *nix systems, f_blocks, f_bfree, and f_bavail
437 * are reported in units of f_frsize. Linux hasn't had
438 * an f_frsize field in its statfs struct until recently,
439 * thus historically Linux's sys_statfs reports these
440 * fields in units of f_bsize.
442 buf->f_bsize = dentry->d_sb->s_blocksize;
443 blockbits = dentry->d_sb->s_blocksize_bits;
444 blockres = (1 << blockbits) - 1;
445 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
446 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
447 buf->f_bavail = (res.abytes + blockres) >> blockbits;
449 buf->f_files = res.tfiles;
450 buf->f_ffree = res.afiles;
452 buf->f_namelen = server->namelen;
457 dprintk("%s: statfs error = %d\n", __func__, -error);
462 * Map the security flavour number to a name
464 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
466 static const struct {
467 rpc_authflavor_t flavour;
470 { RPC_AUTH_NULL, "null" },
471 { RPC_AUTH_UNIX, "sys" },
472 { RPC_AUTH_GSS_KRB5, "krb5" },
473 { RPC_AUTH_GSS_KRB5I, "krb5i" },
474 { RPC_AUTH_GSS_KRB5P, "krb5p" },
475 { RPC_AUTH_GSS_LKEY, "lkey" },
476 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
477 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
478 { RPC_AUTH_GSS_SPKM, "spkm" },
479 { RPC_AUTH_GSS_SPKMI, "spkmi" },
480 { RPC_AUTH_GSS_SPKMP, "spkmp" },
481 { UINT_MAX, "unknown" }
485 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
486 if (sec_flavours[i].flavour == flavour)
489 return sec_flavours[i].str;
492 static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
495 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
497 switch (sap->sa_family) {
499 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
500 seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
504 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
505 seq_printf(m, ",mountaddr=%pI6", &sin6->sin6_addr);
510 seq_printf(m, ",mountaddr=unspecified");
513 if (nfss->mountd_version || showdefaults)
514 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
515 if (nfss->mountd_port || showdefaults)
516 seq_printf(m, ",mountport=%u", nfss->mountd_port);
518 switch (nfss->mountd_protocol) {
520 seq_printf(m, ",mountproto=udp");
523 seq_printf(m, ",mountproto=tcp");
527 seq_printf(m, ",mountproto=auto");
532 * Describe the mount options in force on this server representation
534 static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
537 static const struct proc_nfs_info {
542 { NFS_MOUNT_SOFT, ",soft", ",hard" },
543 { NFS_MOUNT_POSIX, ",posix", "" },
544 { NFS_MOUNT_NOCTO, ",nocto", "" },
545 { NFS_MOUNT_NOAC, ",noac", "" },
546 { NFS_MOUNT_NONLM, ",nolock", "" },
547 { NFS_MOUNT_NOACL, ",noacl", "" },
548 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
549 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
550 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
553 const struct proc_nfs_info *nfs_infop;
554 struct nfs_client *clp = nfss->nfs_client;
555 u32 version = clp->rpc_ops->version;
557 seq_printf(m, ",vers=%u", version);
558 seq_printf(m, ",rsize=%u", nfss->rsize);
559 seq_printf(m, ",wsize=%u", nfss->wsize);
560 if (nfss->bsize != 0)
561 seq_printf(m, ",bsize=%u", nfss->bsize);
562 seq_printf(m, ",namlen=%u", nfss->namelen);
563 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
564 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
565 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
566 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
567 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
568 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
569 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
570 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
571 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
572 if (nfss->flags & nfs_infop->flag)
573 seq_puts(m, nfs_infop->str);
575 seq_puts(m, nfs_infop->nostr);
577 seq_printf(m, ",proto=%s",
578 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_PROTO));
580 if (nfss->port != NFS_PORT)
581 seq_printf(m, ",port=%u", nfss->port);
584 seq_printf(m, ",port=%u", nfss->port);
586 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
587 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
588 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
591 nfs_show_mountd_options(m, nfss, showdefaults);
594 if (clp->rpc_ops->version == 4)
595 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
597 if (nfss->options & NFS_OPTION_FSCACHE)
598 seq_printf(m, ",fsc");
602 * Describe the mount options on this VFS mountpoint
604 static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
606 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
608 nfs_show_mount_options(m, nfss, 0);
610 seq_printf(m, ",addr=%s",
611 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
618 * Present statistical information for this VFS mountpoint
620 static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
623 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
624 struct rpc_auth *auth = nfss->client->cl_auth;
625 struct nfs_iostats totals = { };
627 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
630 * Display all mount option settings
632 seq_printf(m, "\n\topts:\t");
633 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
634 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
635 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
636 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
637 nfs_show_mount_options(m, nfss, 1);
639 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
641 seq_printf(m, "\n\tcaps:\t");
642 seq_printf(m, "caps=0x%x", nfss->caps);
643 seq_printf(m, ",wtmult=%u", nfss->wtmult);
644 seq_printf(m, ",dtsize=%u", nfss->dtsize);
645 seq_printf(m, ",bsize=%u", nfss->bsize);
646 seq_printf(m, ",namlen=%u", nfss->namelen);
649 if (nfss->nfs_client->rpc_ops->version == 4) {
650 seq_printf(m, "\n\tnfsv4:\t");
651 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
652 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
653 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
658 * Display security flavor in effect for this mount
660 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
662 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
665 * Display superblock I/O counters
667 for_each_possible_cpu(cpu) {
668 struct nfs_iostats *stats;
671 stats = per_cpu_ptr(nfss->io_stats, cpu);
673 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
674 totals.events[i] += stats->events[i];
675 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
676 totals.bytes[i] += stats->bytes[i];
677 #ifdef CONFIG_NFS_FSCACHE
678 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
679 totals.fscache[i] += stats->fscache[i];
685 seq_printf(m, "\n\tevents:\t");
686 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
687 seq_printf(m, "%lu ", totals.events[i]);
688 seq_printf(m, "\n\tbytes:\t");
689 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
690 seq_printf(m, "%Lu ", totals.bytes[i]);
691 #ifdef CONFIG_NFS_FSCACHE
692 if (nfss->options & NFS_OPTION_FSCACHE) {
693 seq_printf(m, "\n\tfsc:\t");
694 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
695 seq_printf(m, "%Lu ", totals.bytes[i]);
700 rpc_print_iostats(m, nfss->client);
706 * Begin unmount by attempting to remove all automounted mountpoints we added
707 * in response to xdev traversals and referrals
709 static void nfs_umount_begin(struct super_block *sb)
711 struct nfs_server *server;
712 struct rpc_clnt *rpc;
717 /* -EIO all pending I/O */
718 rpc = server->client_acl;
720 rpc_killall_tasks(rpc);
721 rpc = server->client;
723 rpc_killall_tasks(rpc);
729 * Sanity-check a server address provided by the mount command.
731 * Address family must be initialized, and address must not be
732 * the ANY address for that family.
734 static int nfs_verify_server_address(struct sockaddr *addr)
736 switch (addr->sa_family) {
738 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
739 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
742 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
743 return !ipv6_addr_any(sa);
747 dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
752 * Select between a default port value and a user-specified port value.
753 * If a zero value is set, then autobind will be used.
755 static void nfs_set_default_port(struct sockaddr *sap, const int parsed_port,
756 const unsigned short default_port)
758 unsigned short port = default_port;
760 if (parsed_port != NFS_UNSPEC_PORT)
763 rpc_set_port(sap, port);
767 * Sanity check the NFS transport protocol.
770 static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
772 switch (mnt->nfs_server.protocol) {
773 case XPRT_TRANSPORT_UDP:
774 case XPRT_TRANSPORT_TCP:
775 case XPRT_TRANSPORT_RDMA:
778 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
783 * For text based NFSv2/v3 mounts, the mount protocol transport default
784 * settings should depend upon the specified NFS transport.
786 static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
788 nfs_validate_transport_protocol(mnt);
790 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
791 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
793 switch (mnt->nfs_server.protocol) {
794 case XPRT_TRANSPORT_UDP:
795 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
797 case XPRT_TRANSPORT_TCP:
798 case XPRT_TRANSPORT_RDMA:
799 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
804 * Parse the value of the 'sec=' option.
806 static int nfs_parse_security_flavors(char *value,
807 struct nfs_parsed_mount_data *mnt)
809 substring_t args[MAX_OPT_ARGS];
811 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
813 switch (match_token(value, nfs_secflavor_tokens, args)) {
815 mnt->auth_flavors[0] = RPC_AUTH_NULL;
818 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
821 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
824 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
827 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
830 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
833 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
836 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
839 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
842 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
845 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
851 mnt->auth_flavor_len = 1;
856 * Error-check and convert a string of mount options from user space into
857 * a data structure. The whole mount string is processed; bad options are
858 * skipped as they are encountered. If there were no errors, return 1;
859 * otherwise return 0 (zero).
861 static int nfs_parse_mount_options(char *raw,
862 struct nfs_parsed_mount_data *mnt)
864 char *p, *string, *secdata;
865 int rc, sloppy = 0, invalid_option = 0;
868 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
871 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
873 secdata = alloc_secdata();
877 rc = security_sb_copy_data(raw, secdata);
879 goto out_security_failure;
881 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
883 goto out_security_failure;
885 free_secdata(secdata);
887 while ((p = strsep(&raw, ",")) != NULL) {
888 substring_t args[MAX_OPT_ARGS];
889 unsigned long option;
895 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
897 token = match_token(p, nfs_mount_option_tokens, args);
901 * boolean options: foo/nofoo
904 mnt->flags |= NFS_MOUNT_SOFT;
907 mnt->flags &= ~NFS_MOUNT_SOFT;
910 mnt->flags |= NFS_MOUNT_POSIX;
913 mnt->flags &= ~NFS_MOUNT_POSIX;
916 mnt->flags &= ~NFS_MOUNT_NOCTO;
919 mnt->flags |= NFS_MOUNT_NOCTO;
922 mnt->flags &= ~NFS_MOUNT_NOAC;
925 mnt->flags |= NFS_MOUNT_NOAC;
928 mnt->flags &= ~NFS_MOUNT_NONLM;
931 mnt->flags |= NFS_MOUNT_NONLM;
934 mnt->flags &= ~NFS_MOUNT_VER3;
937 mnt->flags |= NFS_MOUNT_VER3;
940 mnt->flags &= ~NFS_MOUNT_TCP;
941 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
944 mnt->flags |= NFS_MOUNT_TCP;
945 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
948 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
949 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
950 xprt_load_transport(p);
953 mnt->flags &= ~NFS_MOUNT_NOACL;
956 mnt->flags |= NFS_MOUNT_NOACL;
959 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
962 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
965 mnt->flags &= ~NFS_MOUNT_UNSHARED;
967 case Opt_nosharecache:
968 mnt->flags |= NFS_MOUNT_UNSHARED;
971 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
974 mnt->flags |= NFS_MOUNT_NORESVPORT;
977 mnt->options |= NFS_OPTION_FSCACHE;
978 kfree(mnt->fscache_uniq);
979 mnt->fscache_uniq = NULL;
982 mnt->options &= ~NFS_OPTION_FSCACHE;
983 kfree(mnt->fscache_uniq);
984 mnt->fscache_uniq = NULL;
986 case Opt_fscache_uniq:
987 string = match_strdup(args);
990 kfree(mnt->fscache_uniq);
991 mnt->fscache_uniq = string;
992 mnt->options |= NFS_OPTION_FSCACHE;
996 * options that take numeric values
999 string = match_strdup(args);
1002 rc = strict_strtoul(string, 10, &option);
1004 if (rc != 0 || option > USHORT_MAX)
1005 goto out_invalid_value;
1006 mnt->nfs_server.port = option;
1009 string = match_strdup(args);
1012 rc = strict_strtoul(string, 10, &option);
1015 goto out_invalid_value;
1016 mnt->rsize = option;
1019 string = match_strdup(args);
1022 rc = strict_strtoul(string, 10, &option);
1025 goto out_invalid_value;
1026 mnt->wsize = option;
1029 string = match_strdup(args);
1032 rc = strict_strtoul(string, 10, &option);
1035 goto out_invalid_value;
1036 mnt->bsize = option;
1039 string = match_strdup(args);
1042 rc = strict_strtoul(string, 10, &option);
1044 if (rc != 0 || option == 0)
1045 goto out_invalid_value;
1046 mnt->timeo = option;
1049 string = match_strdup(args);
1052 rc = strict_strtoul(string, 10, &option);
1054 if (rc != 0 || option == 0)
1055 goto out_invalid_value;
1056 mnt->retrans = option;
1059 string = match_strdup(args);
1062 rc = strict_strtoul(string, 10, &option);
1065 goto out_invalid_value;
1066 mnt->acregmin = option;
1069 string = match_strdup(args);
1072 rc = strict_strtoul(string, 10, &option);
1075 goto out_invalid_value;
1076 mnt->acregmax = option;
1079 string = match_strdup(args);
1082 rc = strict_strtoul(string, 10, &option);
1085 goto out_invalid_value;
1086 mnt->acdirmin = option;
1089 string = match_strdup(args);
1092 rc = strict_strtoul(string, 10, &option);
1095 goto out_invalid_value;
1096 mnt->acdirmax = option;
1099 string = match_strdup(args);
1102 rc = strict_strtoul(string, 10, &option);
1105 goto out_invalid_value;
1106 mnt->acregmin = mnt->acregmax =
1107 mnt->acdirmin = mnt->acdirmax = option;
1110 string = match_strdup(args);
1113 rc = strict_strtoul(string, 10, &option);
1116 goto out_invalid_value;
1117 mnt->namlen = option;
1120 string = match_strdup(args);
1123 rc = strict_strtoul(string, 10, &option);
1125 if (rc != 0 || option > USHORT_MAX)
1126 goto out_invalid_value;
1127 mnt->mount_server.port = option;
1130 string = match_strdup(args);
1133 rc = strict_strtoul(string, 10, &option);
1136 option < NFS_MNT_VERSION ||
1137 option > NFS_MNT3_VERSION)
1138 goto out_invalid_value;
1139 mnt->mount_server.version = option;
1142 string = match_strdup(args);
1145 rc = strict_strtoul(string, 10, &option);
1148 goto out_invalid_value;
1151 mnt->flags &= ~NFS_MOUNT_VER3;
1154 mnt->flags |= NFS_MOUNT_VER3;
1157 goto out_invalid_value;
1160 case Opt_minorversion:
1161 string = match_strdup(args);
1164 rc = strict_strtoul(string, 10, &option);
1167 goto out_invalid_value;
1168 if (option > NFS4_MAX_MINOR_VERSION)
1169 goto out_invalid_value;
1170 mnt->minorversion = option;
1174 * options that take text values
1177 string = match_strdup(args);
1180 rc = nfs_parse_security_flavors(string, mnt);
1183 dfprintk(MOUNT, "NFS: unrecognized "
1184 "security flavor\n");
1189 string = match_strdup(args);
1192 token = match_token(string,
1193 nfs_xprt_protocol_tokens, args);
1197 mnt->flags &= ~NFS_MOUNT_TCP;
1198 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1202 mnt->flags |= NFS_MOUNT_TCP;
1203 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1207 /* vector side protocols to TCP */
1208 mnt->flags |= NFS_MOUNT_TCP;
1209 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1210 xprt_load_transport(string);
1214 dfprintk(MOUNT, "NFS: unrecognized "
1215 "transport protocol\n");
1219 case Opt_mountproto:
1220 string = match_strdup(args);
1223 token = match_token(string,
1224 nfs_xprt_protocol_tokens, args);
1229 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
1232 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
1234 case Opt_xprt_rdma: /* not used for side protocols */
1236 dfprintk(MOUNT, "NFS: unrecognized "
1237 "transport protocol\n");
1242 string = match_strdup(args);
1245 mnt->nfs_server.addrlen =
1246 rpc_pton(string, strlen(string),
1248 &mnt->nfs_server.address,
1249 sizeof(mnt->nfs_server.address));
1251 if (mnt->nfs_server.addrlen == 0)
1252 goto out_invalid_address;
1254 case Opt_clientaddr:
1255 string = match_strdup(args);
1258 kfree(mnt->client_address);
1259 mnt->client_address = string;
1262 string = match_strdup(args);
1265 kfree(mnt->mount_server.hostname);
1266 mnt->mount_server.hostname = string;
1269 string = match_strdup(args);
1272 mnt->mount_server.addrlen =
1273 rpc_pton(string, strlen(string),
1275 &mnt->mount_server.address,
1276 sizeof(mnt->mount_server.address));
1278 if (mnt->mount_server.addrlen == 0)
1279 goto out_invalid_address;
1281 case Opt_lookupcache:
1282 string = match_strdup(args);
1285 token = match_token(string,
1286 nfs_lookupcache_tokens, args);
1289 case Opt_lookupcache_all:
1290 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1292 case Opt_lookupcache_positive:
1293 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1294 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1296 case Opt_lookupcache_none:
1297 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1300 dfprintk(MOUNT, "NFS: invalid "
1301 "lookupcache argument\n");
1311 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1314 case Opt_deprecated:
1315 dfprintk(MOUNT, "NFS: ignoring mount option "
1321 dfprintk(MOUNT, "NFS: unrecognized mount option "
1326 if (!sloppy && invalid_option)
1331 out_invalid_address:
1332 printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
1335 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
1338 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1340 out_security_failure:
1341 free_secdata(secdata);
1342 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1347 * Match the requested auth flavors with the list returned by
1348 * the server. Returns zero and sets the mount's authentication
1349 * flavor on success; returns -EACCES if server does not support
1350 * the requested flavor.
1352 static int nfs_walk_authlist(struct nfs_parsed_mount_data *args,
1353 struct nfs_mount_request *request)
1355 unsigned int i, j, server_authlist_len = *(request->auth_flav_len);
1358 * Certain releases of Linux's mountd return an empty
1359 * flavor list. To prevent behavioral regression with
1360 * these servers (ie. rejecting mounts that used to
1361 * succeed), revert to pre-2.6.32 behavior (no checking)
1362 * if the returned flavor list is empty.
1364 if (server_authlist_len == 0)
1368 * We avoid sophisticated negotiating here, as there are
1369 * plenty of cases where we can get it wrong, providing
1370 * either too little or too much security.
1372 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1373 * flavor listed first. However, some servers list
1374 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1375 * preferred default, in args->auth_flavors[0] if user
1376 * didn't specify sec= mount option.
1378 for (i = 0; i < args->auth_flavor_len; i++)
1379 for (j = 0; j < server_authlist_len; j++)
1380 if (args->auth_flavors[i] == request->auth_flavs[j]) {
1381 dfprintk(MOUNT, "NFS: using auth flavor %d\n",
1382 request->auth_flavs[j]);
1383 args->auth_flavors[0] = request->auth_flavs[j];
1387 dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n");
1388 nfs_umount(request);
1393 * Use the remote server's MOUNT service to request the NFS file handle
1394 * corresponding to the provided path.
1396 static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1397 struct nfs_fh *root_fh)
1399 rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS];
1400 unsigned int server_authlist_len = ARRAY_SIZE(server_authlist);
1401 struct nfs_mount_request request = {
1402 .sap = (struct sockaddr *)
1403 &args->mount_server.address,
1404 .dirpath = args->nfs_server.export_path,
1405 .protocol = args->mount_server.protocol,
1407 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
1408 .auth_flav_len = &server_authlist_len,
1409 .auth_flavs = server_authlist,
1413 if (args->mount_server.version == 0) {
1414 if (args->flags & NFS_MOUNT_VER3)
1415 args->mount_server.version = NFS_MNT3_VERSION;
1417 args->mount_server.version = NFS_MNT_VERSION;
1419 request.version = args->mount_server.version;
1421 if (args->mount_server.hostname)
1422 request.hostname = args->mount_server.hostname;
1424 request.hostname = args->nfs_server.hostname;
1427 * Construct the mount server's address.
1429 if (args->mount_server.address.ss_family == AF_UNSPEC) {
1430 memcpy(request.sap, &args->nfs_server.address,
1431 args->nfs_server.addrlen);
1432 args->mount_server.addrlen = args->nfs_server.addrlen;
1434 request.salen = args->mount_server.addrlen;
1435 nfs_set_default_port(request.sap, args->mount_server.port, 0);
1438 * Now ask the mount server to map our export path
1441 status = nfs_mount(&request);
1443 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1444 request.hostname, status);
1449 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1451 if (args->mount_server.version != NFS_MNT3_VERSION)
1453 return nfs_walk_authlist(args, &request);
1456 static int nfs_parse_simple_hostname(const char *dev_name,
1457 char **hostname, size_t maxnamlen,
1458 char **export_path, size_t maxpathlen)
1461 char *colon, *comma;
1463 colon = strchr(dev_name, ':');
1465 goto out_bad_devname;
1467 len = colon - dev_name;
1468 if (len > maxnamlen)
1471 /* N.B. caller will free nfs_server.hostname in all cases */
1472 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
1476 /* kill possible hostname list: not supported */
1477 comma = strchr(*hostname, ',');
1478 if (comma != NULL) {
1479 if (comma == *hostname)
1480 goto out_bad_devname;
1485 len = strlen(colon);
1486 if (len > maxpathlen)
1488 *export_path = kstrndup(colon, len, GFP_KERNEL);
1492 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1496 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1500 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1504 dfprintk(MOUNT, "NFS: server hostname too long\n");
1505 return -ENAMETOOLONG;
1508 dfprintk(MOUNT, "NFS: export pathname too long\n");
1509 return -ENAMETOOLONG;
1513 * Hostname has square brackets around it because it contains one or
1514 * more colons. We look for the first closing square bracket, and a
1515 * colon must follow it.
1517 static int nfs_parse_protected_hostname(const char *dev_name,
1518 char **hostname, size_t maxnamlen,
1519 char **export_path, size_t maxpathlen)
1524 start = (char *)(dev_name + 1);
1526 end = strchr(start, ']');
1528 goto out_bad_devname;
1529 if (*(end + 1) != ':')
1530 goto out_bad_devname;
1533 if (len > maxnamlen)
1536 /* N.B. caller will free nfs_server.hostname in all cases */
1537 *hostname = kstrndup(start, len, GFP_KERNEL);
1538 if (*hostname == NULL)
1543 if (len > maxpathlen)
1545 *export_path = kstrndup(end, len, GFP_KERNEL);
1552 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1556 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1560 dfprintk(MOUNT, "NFS: server hostname too long\n");
1561 return -ENAMETOOLONG;
1564 dfprintk(MOUNT, "NFS: export pathname too long\n");
1565 return -ENAMETOOLONG;
1569 * Split "dev_name" into "hostname:export_path".
1571 * The leftmost colon demarks the split between the server's hostname
1572 * and the export path. If the hostname starts with a left square
1573 * bracket, then it may contain colons.
1575 * Note: caller frees hostname and export path, even on error.
1577 static int nfs_parse_devname(const char *dev_name,
1578 char **hostname, size_t maxnamlen,
1579 char **export_path, size_t maxpathlen)
1581 if (*dev_name == '[')
1582 return nfs_parse_protected_hostname(dev_name,
1583 hostname, maxnamlen,
1584 export_path, maxpathlen);
1586 return nfs_parse_simple_hostname(dev_name,
1587 hostname, maxnamlen,
1588 export_path, maxpathlen);
1592 * Validate the NFS2/NFS3 mount data
1593 * - fills in the mount root filehandle
1595 * For option strings, user space handles the following behaviors:
1597 * + DNS: mapping server host name to IP address ("addr=" option)
1599 * + failure mode: how to behave if a mount request can't be handled
1600 * immediately ("fg/bg" option)
1602 * + retry: how often to retry a mount request ("retry=" option)
1604 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1605 * mountproto=tcp after mountproto=udp, and so on
1607 static int nfs_validate_mount_data(void *options,
1608 struct nfs_parsed_mount_data *args,
1609 struct nfs_fh *mntfh,
1610 const char *dev_name)
1612 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
1613 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
1618 args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
1619 args->rsize = NFS_MAX_FILE_IO_SIZE;
1620 args->wsize = NFS_MAX_FILE_IO_SIZE;
1621 args->acregmin = NFS_DEF_ACREGMIN;
1622 args->acregmax = NFS_DEF_ACREGMAX;
1623 args->acdirmin = NFS_DEF_ACDIRMIN;
1624 args->acdirmax = NFS_DEF_ACDIRMAX;
1625 args->mount_server.port = NFS_UNSPEC_PORT;
1626 args->nfs_server.port = NFS_UNSPEC_PORT;
1627 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1628 args->auth_flavors[0] = RPC_AUTH_UNIX;
1629 args->auth_flavor_len = 1;
1631 switch (data->version) {
1637 if (data->flags & NFS_MOUNT_VER3)
1639 data->root.size = NFS2_FHSIZE;
1640 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1642 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1645 memset(data->context, 0, sizeof(data->context));
1647 if (data->flags & NFS_MOUNT_VER3) {
1648 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1649 goto out_invalid_fh;
1650 mntfh->size = data->root.size;
1652 mntfh->size = NFS2_FHSIZE;
1655 memcpy(mntfh->data, data->root.data, mntfh->size);
1656 if (mntfh->size < sizeof(mntfh->data))
1657 memset(mntfh->data + mntfh->size, 0,
1658 sizeof(mntfh->data) - mntfh->size);
1661 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1664 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
1665 args->rsize = data->rsize;
1666 args->wsize = data->wsize;
1667 args->timeo = data->timeo;
1668 args->retrans = data->retrans;
1669 args->acregmin = data->acregmin;
1670 args->acregmax = data->acregmax;
1671 args->acdirmin = data->acdirmin;
1672 args->acdirmax = data->acdirmax;
1674 memcpy(sap, &data->addr, sizeof(data->addr));
1675 args->nfs_server.addrlen = sizeof(data->addr);
1676 if (!nfs_verify_server_address(sap))
1677 goto out_no_address;
1679 if (!(data->flags & NFS_MOUNT_TCP))
1680 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1681 /* N.B. caller will free nfs_server.hostname in all cases */
1682 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1683 args->namlen = data->namlen;
1684 args->bsize = data->bsize;
1686 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1687 args->auth_flavors[0] = data->pseudoflavor;
1688 if (!args->nfs_server.hostname)
1692 * The legacy version 6 binary mount data from userspace has a
1693 * field used only to transport selinux information into the
1694 * the kernel. To continue to support that functionality we
1695 * have a touch of selinux knowledge here in the NFS code. The
1696 * userspace code converted context=blah to just blah so we are
1697 * converting back to the full string selinux understands.
1699 if (data->context[0]){
1700 #ifdef CONFIG_SECURITY_SELINUX
1702 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1705 strcpy(opts_str, "context=");
1706 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1707 strcat(opts_str, &data->context[0]);
1708 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1721 if (nfs_parse_mount_options((char *)options, args) == 0)
1724 if (!nfs_verify_server_address(sap))
1725 goto out_no_address;
1727 nfs_set_default_port(sap, args->nfs_server.port, 0);
1729 nfs_set_mount_transport_protocol(args);
1731 status = nfs_parse_devname(dev_name,
1732 &args->nfs_server.hostname,
1734 &args->nfs_server.export_path,
1737 status = nfs_try_mount(args, mntfh);
1739 kfree(args->nfs_server.export_path);
1740 args->nfs_server.export_path = NULL;
1749 #ifndef CONFIG_NFS_V3
1750 if (args->flags & NFS_MOUNT_VER3)
1751 goto out_v3_not_compiled;
1752 #endif /* !CONFIG_NFS_V3 */
1757 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1761 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1766 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1769 #ifndef CONFIG_NFS_V3
1770 out_v3_not_compiled:
1771 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1772 return -EPROTONOSUPPORT;
1773 #endif /* !CONFIG_NFS_V3 */
1776 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
1780 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1784 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1789 nfs_compare_remount_data(struct nfs_server *nfss,
1790 struct nfs_parsed_mount_data *data)
1792 if (data->flags != nfss->flags ||
1793 data->rsize != nfss->rsize ||
1794 data->wsize != nfss->wsize ||
1795 data->retrans != nfss->client->cl_timeout->to_retries ||
1796 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
1797 data->acregmin != nfss->acregmin / HZ ||
1798 data->acregmax != nfss->acregmax / HZ ||
1799 data->acdirmin != nfss->acdirmin / HZ ||
1800 data->acdirmax != nfss->acdirmax / HZ ||
1801 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
1802 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
1803 memcmp(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1804 data->nfs_server.addrlen) != 0)
1811 nfs_remount(struct super_block *sb, int *flags, char *raw_data)
1814 struct nfs_server *nfss = sb->s_fs_info;
1815 struct nfs_parsed_mount_data *data;
1816 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
1817 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
1818 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
1821 * Userspace mount programs that send binary options generally send
1822 * them populated with default values. We have no way to know which
1823 * ones were explicitly specified. Fall back to legacy behavior and
1824 * just return success.
1826 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
1827 (nfsvers <= 3 && (!options || (options->version >= 1 &&
1828 options->version <= 6))))
1831 data = kzalloc(sizeof(*data), GFP_KERNEL);
1836 /* fill out struct with values from existing mount */
1837 data->flags = nfss->flags;
1838 data->rsize = nfss->rsize;
1839 data->wsize = nfss->wsize;
1840 data->retrans = nfss->client->cl_timeout->to_retries;
1841 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
1842 data->acregmin = nfss->acregmin / HZ;
1843 data->acregmax = nfss->acregmax / HZ;
1844 data->acdirmin = nfss->acdirmin / HZ;
1845 data->acdirmax = nfss->acdirmax / HZ;
1846 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
1847 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
1848 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1849 data->nfs_server.addrlen);
1851 /* overwrite those values with any that were specified */
1852 error = nfs_parse_mount_options((char *)options, data);
1856 /* compare new mount options with old ones */
1857 error = nfs_compare_remount_data(nfss, data);
1865 * Initialise the common bits of the superblock
1867 static inline void nfs_initialise_sb(struct super_block *sb)
1869 struct nfs_server *server = NFS_SB(sb);
1871 sb->s_magic = NFS_SUPER_MAGIC;
1873 /* We probably want something more informative here */
1874 snprintf(sb->s_id, sizeof(sb->s_id),
1875 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1877 if (sb->s_blocksize == 0)
1878 sb->s_blocksize = nfs_block_bits(server->wsize,
1879 &sb->s_blocksize_bits);
1881 if (server->flags & NFS_MOUNT_NOAC)
1882 sb->s_flags |= MS_SYNCHRONOUS;
1884 nfs_super_set_maxbytes(sb, server->maxfilesize);
1888 * Finish setting up an NFS2/3 superblock
1890 static void nfs_fill_super(struct super_block *sb,
1891 struct nfs_parsed_mount_data *data)
1893 struct nfs_server *server = NFS_SB(sb);
1895 sb->s_blocksize_bits = 0;
1896 sb->s_blocksize = 0;
1898 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1900 if (server->flags & NFS_MOUNT_VER3) {
1901 /* The VFS shouldn't apply the umask to mode bits. We will do
1902 * so ourselves when necessary.
1904 sb->s_flags |= MS_POSIXACL;
1905 sb->s_time_gran = 1;
1908 sb->s_op = &nfs_sops;
1909 nfs_initialise_sb(sb);
1913 * Finish setting up a cloned NFS2/3 superblock
1915 static void nfs_clone_super(struct super_block *sb,
1916 const struct super_block *old_sb)
1918 struct nfs_server *server = NFS_SB(sb);
1920 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1921 sb->s_blocksize = old_sb->s_blocksize;
1922 sb->s_maxbytes = old_sb->s_maxbytes;
1924 if (server->flags & NFS_MOUNT_VER3) {
1925 /* The VFS shouldn't apply the umask to mode bits. We will do
1926 * so ourselves when necessary.
1928 sb->s_flags |= MS_POSIXACL;
1929 sb->s_time_gran = 1;
1932 sb->s_op = old_sb->s_op;
1933 nfs_initialise_sb(sb);
1936 static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
1938 const struct nfs_server *a = s->s_fs_info;
1939 const struct rpc_clnt *clnt_a = a->client;
1940 const struct rpc_clnt *clnt_b = b->client;
1942 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
1944 if (a->nfs_client != b->nfs_client)
1946 if (a->flags != b->flags)
1948 if (a->wsize != b->wsize)
1950 if (a->rsize != b->rsize)
1952 if (a->acregmin != b->acregmin)
1954 if (a->acregmax != b->acregmax)
1956 if (a->acdirmin != b->acdirmin)
1958 if (a->acdirmax != b->acdirmax)
1960 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
1967 struct nfs_sb_mountdata {
1968 struct nfs_server *server;
1972 static int nfs_set_super(struct super_block *s, void *data)
1974 struct nfs_sb_mountdata *sb_mntdata = data;
1975 struct nfs_server *server = sb_mntdata->server;
1978 s->s_flags = sb_mntdata->mntflags;
1979 s->s_fs_info = server;
1980 ret = set_anon_super(s, server);
1982 server->s_dev = s->s_dev;
1986 static int nfs_compare_super_address(struct nfs_server *server1,
1987 struct nfs_server *server2)
1989 struct sockaddr *sap1, *sap2;
1991 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
1992 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
1994 if (sap1->sa_family != sap2->sa_family)
1997 switch (sap1->sa_family) {
1999 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
2000 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
2001 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
2003 if (sin1->sin_port != sin2->sin_port)
2008 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
2009 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
2010 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
2012 if (sin1->sin6_port != sin2->sin6_port)
2023 static int nfs_compare_super(struct super_block *sb, void *data)
2025 struct nfs_sb_mountdata *sb_mntdata = data;
2026 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2027 int mntflags = sb_mntdata->mntflags;
2029 if (!nfs_compare_super_address(old, server))
2031 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2032 if (old->flags & NFS_MOUNT_UNSHARED)
2034 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2036 return nfs_compare_mount_options(sb, server, mntflags);
2039 static int nfs_bdi_register(struct nfs_server *server)
2041 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
2044 static int nfs_get_sb(struct file_system_type *fs_type,
2045 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2047 struct nfs_server *server = NULL;
2048 struct super_block *s;
2049 struct nfs_parsed_mount_data *data;
2050 struct nfs_fh *mntfh;
2051 struct dentry *mntroot;
2052 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2053 struct nfs_sb_mountdata sb_mntdata = {
2056 int error = -ENOMEM;
2058 data = kzalloc(sizeof(*data), GFP_KERNEL);
2059 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
2060 if (data == NULL || mntfh == NULL)
2063 security_init_mnt_opts(&data->lsm_opts);
2065 /* Validate the mount data */
2066 error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
2070 /* Get a volume representation */
2071 server = nfs_create_server(data, mntfh);
2072 if (IS_ERR(server)) {
2073 error = PTR_ERR(server);
2076 sb_mntdata.server = server;
2078 if (server->flags & NFS_MOUNT_UNSHARED)
2079 compare_super = NULL;
2081 /* Get a superblock - note that we may end up sharing one that already exists */
2082 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
2088 if (s->s_fs_info != server) {
2089 nfs_free_server(server);
2092 error = nfs_bdi_register(server);
2094 goto error_splat_super;
2098 /* initial superblock/root creation */
2099 nfs_fill_super(s, data);
2100 nfs_fscache_get_super_cookie(s, data);
2103 mntroot = nfs_get_root(s, mntfh);
2104 if (IS_ERR(mntroot)) {
2105 error = PTR_ERR(mntroot);
2106 goto error_splat_super;
2109 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
2111 goto error_splat_root;
2113 s->s_flags |= MS_ACTIVE;
2115 mnt->mnt_root = mntroot;
2119 kfree(data->nfs_server.hostname);
2120 kfree(data->mount_server.hostname);
2121 kfree(data->fscache_uniq);
2122 security_free_mnt_opts(&data->lsm_opts);
2129 nfs_free_server(server);
2135 deactivate_locked_super(s);
2140 * Destroy an NFS2/3 superblock
2142 static void nfs_kill_super(struct super_block *s)
2144 struct nfs_server *server = NFS_SB(s);
2146 bdi_unregister(&server->backing_dev_info);
2148 nfs_fscache_release_super_cookie(s);
2149 nfs_free_server(server);
2153 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2155 static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
2156 const char *dev_name, void *raw_data,
2157 struct vfsmount *mnt)
2159 struct nfs_clone_mount *data = raw_data;
2160 struct super_block *s;
2161 struct nfs_server *server;
2162 struct dentry *mntroot;
2163 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2164 struct nfs_sb_mountdata sb_mntdata = {
2169 dprintk("--> nfs_xdev_get_sb()\n");
2171 /* create a new volume representation */
2172 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2173 if (IS_ERR(server)) {
2174 error = PTR_ERR(server);
2175 goto out_err_noserver;
2177 sb_mntdata.server = server;
2179 if (server->flags & NFS_MOUNT_UNSHARED)
2180 compare_super = NULL;
2182 /* Get a superblock - note that we may end up sharing one that already exists */
2183 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2189 if (s->s_fs_info != server) {
2190 nfs_free_server(server);
2193 error = nfs_bdi_register(server);
2195 goto error_splat_super;
2199 /* initial superblock/root creation */
2200 nfs_clone_super(s, data->sb);
2203 mntroot = nfs_get_root(s, data->fh);
2204 if (IS_ERR(mntroot)) {
2205 error = PTR_ERR(mntroot);
2206 goto error_splat_super;
2208 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2211 goto error_splat_super;
2214 s->s_flags |= MS_ACTIVE;
2216 mnt->mnt_root = mntroot;
2218 /* clone any lsm security options from the parent to the new sb */
2219 security_sb_clone_mnt_opts(data->sb, s);
2221 dprintk("<-- nfs_xdev_get_sb() = 0\n");
2225 nfs_free_server(server);
2227 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
2231 deactivate_locked_super(s);
2232 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
2236 #ifdef CONFIG_NFS_V4
2239 * Finish setting up a cloned NFS4 superblock
2241 static void nfs4_clone_super(struct super_block *sb,
2242 const struct super_block *old_sb)
2244 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2245 sb->s_blocksize = old_sb->s_blocksize;
2246 sb->s_maxbytes = old_sb->s_maxbytes;
2247 sb->s_time_gran = 1;
2248 sb->s_op = old_sb->s_op;
2249 nfs_initialise_sb(sb);
2253 * Set up an NFS4 superblock
2255 static void nfs4_fill_super(struct super_block *sb)
2257 sb->s_time_gran = 1;
2258 sb->s_op = &nfs4_sops;
2259 nfs_initialise_sb(sb);
2262 static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2264 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3);
2267 static int nfs4_validate_text_mount_data(void *options,
2268 struct nfs_parsed_mount_data *args,
2269 const char *dev_name)
2271 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2273 nfs_set_default_port(sap, args->nfs_server.port, NFS_PORT);
2275 nfs_validate_transport_protocol(args);
2277 nfs4_validate_mount_flags(args);
2279 if (args->auth_flavor_len > 1) {
2281 "NFS4: Too many RPC auth flavours specified\n");
2285 if (args->client_address == NULL) {
2287 "NFS4: mount program didn't pass callback address\n");
2291 return nfs_parse_devname(dev_name,
2292 &args->nfs_server.hostname,
2294 &args->nfs_server.export_path,
2299 * Validate NFSv4 mount options
2301 static int nfs4_validate_mount_data(void *options,
2302 struct nfs_parsed_mount_data *args,
2303 const char *dev_name)
2305 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2306 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
2312 args->rsize = NFS_MAX_FILE_IO_SIZE;
2313 args->wsize = NFS_MAX_FILE_IO_SIZE;
2314 args->acregmin = NFS_DEF_ACREGMIN;
2315 args->acregmax = NFS_DEF_ACREGMAX;
2316 args->acdirmin = NFS_DEF_ACDIRMIN;
2317 args->acdirmax = NFS_DEF_ACDIRMAX;
2318 args->nfs_server.port = NFS_UNSPEC_PORT;
2319 args->auth_flavors[0] = RPC_AUTH_UNIX;
2320 args->auth_flavor_len = 1;
2321 args->minorversion = 0;
2323 switch (data->version) {
2325 if (data->host_addrlen > sizeof(args->nfs_server.address))
2326 goto out_no_address;
2327 if (data->host_addrlen == 0)
2328 goto out_no_address;
2329 args->nfs_server.addrlen = data->host_addrlen;
2330 if (copy_from_user(sap, data->host_addr, data->host_addrlen))
2332 if (!nfs_verify_server_address(sap))
2333 goto out_no_address;
2335 if (data->auth_flavourlen) {
2336 if (data->auth_flavourlen > 1)
2337 goto out_inval_auth;
2338 if (copy_from_user(&args->auth_flavors[0],
2339 data->auth_flavours,
2340 sizeof(args->auth_flavors[0])))
2344 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2347 args->nfs_server.hostname = c;
2349 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2352 args->nfs_server.export_path = c;
2353 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
2355 c = strndup_user(data->client_addr.data, 16);
2358 args->client_address = c;
2361 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2365 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2366 args->rsize = data->rsize;
2367 args->wsize = data->wsize;
2368 args->timeo = data->timeo;
2369 args->retrans = data->retrans;
2370 args->acregmin = data->acregmin;
2371 args->acregmax = data->acregmax;
2372 args->acdirmin = data->acdirmin;
2373 args->acdirmax = data->acdirmax;
2374 args->nfs_server.protocol = data->proto;
2375 nfs_validate_transport_protocol(args);
2379 if (nfs_parse_mount_options((char *)options, args) == 0)
2382 if (!nfs_verify_server_address(sap))
2385 return nfs4_validate_text_mount_data(options, args, dev_name);
2391 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2395 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2396 data->auth_flavourlen);
2400 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2405 * Get the superblock for the NFS4 root partition
2407 static int nfs4_remote_get_sb(struct file_system_type *fs_type,
2408 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2410 struct nfs_parsed_mount_data *data = raw_data;
2411 struct super_block *s;
2412 struct nfs_server *server;
2413 struct nfs_fh *mntfh;
2414 struct dentry *mntroot;
2415 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2416 struct nfs_sb_mountdata sb_mntdata = {
2419 int error = -ENOMEM;
2421 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
2422 if (data == NULL || mntfh == NULL)
2425 security_init_mnt_opts(&data->lsm_opts);
2427 /* Get a volume representation */
2428 server = nfs4_create_server(data, mntfh);
2429 if (IS_ERR(server)) {
2430 error = PTR_ERR(server);
2433 sb_mntdata.server = server;
2435 if (server->flags & NFS4_MOUNT_UNSHARED)
2436 compare_super = NULL;
2438 /* Get a superblock - note that we may end up sharing one that already exists */
2439 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2445 if (s->s_fs_info != server) {
2446 nfs_free_server(server);
2449 error = nfs_bdi_register(server);
2451 goto error_splat_super;
2455 /* initial superblock/root creation */
2457 nfs_fscache_get_super_cookie(s, data);
2460 mntroot = nfs4_get_root(s, mntfh);
2461 if (IS_ERR(mntroot)) {
2462 error = PTR_ERR(mntroot);
2463 goto error_splat_super;
2466 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
2468 goto error_splat_root;
2470 s->s_flags |= MS_ACTIVE;
2472 mnt->mnt_root = mntroot;
2476 security_free_mnt_opts(&data->lsm_opts);
2482 nfs_free_server(server);
2488 deactivate_locked_super(s);
2492 static struct vfsmount *nfs_do_root_mount(struct file_system_type *fs_type,
2493 int flags, void *data, const char *hostname)
2495 struct vfsmount *root_mnt;
2499 len = strlen(hostname) + 3;
2500 root_devname = kmalloc(len, GFP_KERNEL);
2501 if (root_devname == NULL)
2502 return ERR_PTR(-ENOMEM);
2503 snprintf(root_devname, len, "%s:/", hostname);
2504 root_mnt = vfs_kern_mount(fs_type, flags, root_devname, data);
2505 kfree(root_devname);
2509 static void nfs_fix_devname(const struct path *path, struct vfsmount *mnt)
2511 char *page = (char *) __get_free_page(GFP_KERNEL);
2512 char *devname, *tmp;
2516 devname = nfs_path(path->mnt->mnt_devname,
2517 path->mnt->mnt_root, path->dentry,
2519 if (devname == NULL)
2521 tmp = kstrdup(devname, GFP_KERNEL);
2524 kfree(mnt->mnt_devname);
2525 mnt->mnt_devname = tmp;
2527 free_page((unsigned long)page);
2530 static int nfs_follow_remote_path(struct vfsmount *root_mnt,
2531 const char *export_path, struct vfsmount *mnt_target)
2533 struct mnt_namespace *ns_private;
2534 struct nameidata nd;
2535 struct super_block *s;
2538 ns_private = create_mnt_ns(root_mnt);
2539 ret = PTR_ERR(ns_private);
2540 if (IS_ERR(ns_private))
2543 ret = vfs_path_lookup(root_mnt->mnt_root, root_mnt,
2544 export_path, LOOKUP_FOLLOW, &nd);
2546 put_mnt_ns(ns_private);
2551 s = nd.path.mnt->mnt_sb;
2552 atomic_inc(&s->s_active);
2553 mnt_target->mnt_sb = s;
2554 mnt_target->mnt_root = dget(nd.path.dentry);
2556 /* Correct the device pathname */
2557 nfs_fix_devname(&nd.path, mnt_target);
2560 down_write(&s->s_umount);
2569 * Get the superblock for an NFS4 mountpoint
2571 static int nfs4_get_sb(struct file_system_type *fs_type,
2572 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2574 struct nfs_parsed_mount_data *data;
2576 struct vfsmount *root_mnt;
2577 int error = -ENOMEM;
2579 data = kzalloc(sizeof(*data), GFP_KERNEL);
2583 /* Validate the mount data */
2584 error = nfs4_validate_mount_data(raw_data, data, dev_name);
2588 export_path = data->nfs_server.export_path;
2589 data->nfs_server.export_path = "/";
2590 root_mnt = nfs_do_root_mount(&nfs4_remote_fs_type, flags, data,
2591 data->nfs_server.hostname);
2592 data->nfs_server.export_path = export_path;
2594 error = PTR_ERR(root_mnt);
2595 if (IS_ERR(root_mnt))
2598 error = nfs_follow_remote_path(root_mnt, export_path, mnt);
2601 kfree(data->client_address);
2602 kfree(data->nfs_server.export_path);
2603 kfree(data->nfs_server.hostname);
2604 kfree(data->fscache_uniq);
2607 dprintk("<-- nfs4_get_sb() = %d%s\n", error,
2608 error != 0 ? " [error]" : "");
2612 static void nfs4_kill_super(struct super_block *sb)
2614 struct nfs_server *server = NFS_SB(sb);
2616 dprintk("--> %s\n", __func__);
2617 nfs_super_return_all_delegations(sb);
2618 kill_anon_super(sb);
2619 nfs4_renewd_prepare_shutdown(server);
2620 nfs_fscache_release_super_cookie(sb);
2621 nfs_free_server(server);
2622 dprintk("<-- %s\n", __func__);
2626 * Clone an NFS4 server record on xdev traversal (FSID-change)
2628 static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
2629 const char *dev_name, void *raw_data,
2630 struct vfsmount *mnt)
2632 struct nfs_clone_mount *data = raw_data;
2633 struct super_block *s;
2634 struct nfs_server *server;
2635 struct dentry *mntroot;
2636 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2637 struct nfs_sb_mountdata sb_mntdata = {
2642 dprintk("--> nfs4_xdev_get_sb()\n");
2644 /* create a new volume representation */
2645 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2646 if (IS_ERR(server)) {
2647 error = PTR_ERR(server);
2648 goto out_err_noserver;
2650 sb_mntdata.server = server;
2652 if (server->flags & NFS4_MOUNT_UNSHARED)
2653 compare_super = NULL;
2655 /* Get a superblock - note that we may end up sharing one that already exists */
2656 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2662 if (s->s_fs_info != server) {
2663 nfs_free_server(server);
2666 error = nfs_bdi_register(server);
2668 goto error_splat_super;
2672 /* initial superblock/root creation */
2673 nfs4_clone_super(s, data->sb);
2676 mntroot = nfs4_get_root(s, data->fh);
2677 if (IS_ERR(mntroot)) {
2678 error = PTR_ERR(mntroot);
2679 goto error_splat_super;
2681 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2684 goto error_splat_super;
2687 s->s_flags |= MS_ACTIVE;
2689 mnt->mnt_root = mntroot;
2691 security_sb_clone_mnt_opts(data->sb, s);
2693 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2697 nfs_free_server(server);
2699 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
2703 deactivate_locked_super(s);
2704 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
2708 static int nfs4_remote_referral_get_sb(struct file_system_type *fs_type,
2709 int flags, const char *dev_name, void *raw_data,
2710 struct vfsmount *mnt)
2712 struct nfs_clone_mount *data = raw_data;
2713 struct super_block *s;
2714 struct nfs_server *server;
2715 struct dentry *mntroot;
2716 struct nfs_fh mntfh;
2717 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2718 struct nfs_sb_mountdata sb_mntdata = {
2723 dprintk("--> nfs4_referral_get_sb()\n");
2725 /* create a new volume representation */
2726 server = nfs4_create_referral_server(data, &mntfh);
2727 if (IS_ERR(server)) {
2728 error = PTR_ERR(server);
2729 goto out_err_noserver;
2731 sb_mntdata.server = server;
2733 if (server->flags & NFS4_MOUNT_UNSHARED)
2734 compare_super = NULL;
2736 /* Get a superblock - note that we may end up sharing one that already exists */
2737 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2743 if (s->s_fs_info != server) {
2744 nfs_free_server(server);
2747 error = nfs_bdi_register(server);
2749 goto error_splat_super;
2753 /* initial superblock/root creation */
2757 mntroot = nfs4_get_root(s, &mntfh);
2758 if (IS_ERR(mntroot)) {
2759 error = PTR_ERR(mntroot);
2760 goto error_splat_super;
2762 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2765 goto error_splat_super;
2768 s->s_flags |= MS_ACTIVE;
2770 mnt->mnt_root = mntroot;
2772 security_sb_clone_mnt_opts(data->sb, s);
2774 dprintk("<-- nfs4_referral_get_sb() = 0\n");
2778 nfs_free_server(server);
2780 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
2784 deactivate_locked_super(s);
2785 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
2790 * Create an NFS4 server record on referral traversal
2792 static int nfs4_referral_get_sb(struct file_system_type *fs_type,
2793 int flags, const char *dev_name, void *raw_data,
2794 struct vfsmount *mnt)
2796 struct nfs_clone_mount *data = raw_data;
2798 struct vfsmount *root_mnt;
2801 dprintk("--> nfs4_referral_get_sb()\n");
2803 export_path = data->mnt_path;
2804 data->mnt_path = "/";
2806 root_mnt = nfs_do_root_mount(&nfs4_remote_referral_fs_type,
2807 flags, data, data->hostname);
2808 data->mnt_path = export_path;
2810 error = PTR_ERR(root_mnt);
2811 if (IS_ERR(root_mnt))
2814 error = nfs_follow_remote_path(root_mnt, export_path, mnt);
2816 dprintk("<-- nfs4_referral_get_sb() = %d%s\n", error,
2817 error != 0 ? " [error]" : "");
2821 #endif /* CONFIG_NFS_V4 */