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_get_sb(struct file_system_type *fs_type,
276 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
277 static int nfs4_remote_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_xdev_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_referral_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_remote_referral_get_sb(struct file_system_type *fs_type,
284 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
285 static void nfs4_kill_super(struct super_block *sb);
287 static struct file_system_type nfs4_fs_type = {
288 .owner = THIS_MODULE,
290 .get_sb = nfs4_get_sb,
291 .kill_sb = nfs4_kill_super,
292 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
295 static struct file_system_type nfs4_remote_fs_type = {
296 .owner = THIS_MODULE,
298 .get_sb = nfs4_remote_get_sb,
299 .kill_sb = nfs4_kill_super,
300 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
303 struct file_system_type nfs4_xdev_fs_type = {
304 .owner = THIS_MODULE,
306 .get_sb = nfs4_xdev_get_sb,
307 .kill_sb = nfs4_kill_super,
308 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
311 static struct file_system_type nfs4_remote_referral_fs_type = {
312 .owner = THIS_MODULE,
314 .get_sb = nfs4_remote_referral_get_sb,
315 .kill_sb = nfs4_kill_super,
316 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
319 struct file_system_type nfs4_referral_fs_type = {
320 .owner = THIS_MODULE,
322 .get_sb = nfs4_referral_get_sb,
323 .kill_sb = nfs4_kill_super,
324 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
327 static const struct super_operations nfs4_sops = {
328 .alloc_inode = nfs_alloc_inode,
329 .destroy_inode = nfs_destroy_inode,
330 .write_inode = nfs_write_inode,
331 .statfs = nfs_statfs,
332 .clear_inode = nfs4_clear_inode,
333 .umount_begin = nfs_umount_begin,
334 .show_options = nfs_show_options,
335 .show_stats = nfs_show_stats,
336 .remount_fs = nfs_remount,
340 static struct shrinker acl_shrinker = {
341 .shrink = nfs_access_cache_shrinker,
342 .seeks = DEFAULT_SEEKS,
346 * Register the NFS filesystems
348 int __init register_nfs_fs(void)
352 ret = register_filesystem(&nfs_fs_type);
356 ret = nfs_register_sysctl();
360 ret = register_filesystem(&nfs4_fs_type);
364 register_shrinker(&acl_shrinker);
369 nfs_unregister_sysctl();
372 unregister_filesystem(&nfs_fs_type);
378 * Unregister the NFS filesystems
380 void __exit unregister_nfs_fs(void)
382 unregister_shrinker(&acl_shrinker);
384 unregister_filesystem(&nfs4_fs_type);
386 nfs_unregister_sysctl();
387 unregister_filesystem(&nfs_fs_type);
390 void nfs_sb_active(struct super_block *sb)
392 struct nfs_server *server = NFS_SB(sb);
394 if (atomic_inc_return(&server->active) == 1)
395 atomic_inc(&sb->s_active);
398 void nfs_sb_deactive(struct super_block *sb)
400 struct nfs_server *server = NFS_SB(sb);
402 if (atomic_dec_and_test(&server->active))
403 deactivate_super(sb);
407 * Deliver file system statistics to userspace
409 static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
411 struct nfs_server *server = NFS_SB(dentry->d_sb);
412 unsigned char blockbits;
413 unsigned long blockres;
414 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
415 struct nfs_fattr fattr;
416 struct nfs_fsstat res = {
421 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
424 buf->f_type = NFS_SUPER_MAGIC;
427 * Current versions of glibc do not correctly handle the
428 * case where f_frsize != f_bsize. Eventually we want to
429 * report the value of wtmult in this field.
431 buf->f_frsize = dentry->d_sb->s_blocksize;
434 * On most *nix systems, f_blocks, f_bfree, and f_bavail
435 * are reported in units of f_frsize. Linux hasn't had
436 * an f_frsize field in its statfs struct until recently,
437 * thus historically Linux's sys_statfs reports these
438 * fields in units of f_bsize.
440 buf->f_bsize = dentry->d_sb->s_blocksize;
441 blockbits = dentry->d_sb->s_blocksize_bits;
442 blockres = (1 << blockbits) - 1;
443 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
444 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
445 buf->f_bavail = (res.abytes + blockres) >> blockbits;
447 buf->f_files = res.tfiles;
448 buf->f_ffree = res.afiles;
450 buf->f_namelen = server->namelen;
455 dprintk("%s: statfs error = %d\n", __func__, -error);
460 * Map the security flavour number to a name
462 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
464 static const struct {
465 rpc_authflavor_t flavour;
468 { RPC_AUTH_NULL, "null" },
469 { RPC_AUTH_UNIX, "sys" },
470 { RPC_AUTH_GSS_KRB5, "krb5" },
471 { RPC_AUTH_GSS_KRB5I, "krb5i" },
472 { RPC_AUTH_GSS_KRB5P, "krb5p" },
473 { RPC_AUTH_GSS_LKEY, "lkey" },
474 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
475 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
476 { RPC_AUTH_GSS_SPKM, "spkm" },
477 { RPC_AUTH_GSS_SPKMI, "spkmi" },
478 { RPC_AUTH_GSS_SPKMP, "spkmp" },
479 { UINT_MAX, "unknown" }
483 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
484 if (sec_flavours[i].flavour == flavour)
487 return sec_flavours[i].str;
490 static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
493 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
495 switch (sap->sa_family) {
497 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
498 seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
502 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
503 seq_printf(m, ",mountaddr=%pI6", &sin6->sin6_addr);
508 seq_printf(m, ",mountaddr=unspecified");
511 if (nfss->mountd_version || showdefaults)
512 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
513 if (nfss->mountd_port || showdefaults)
514 seq_printf(m, ",mountport=%u", nfss->mountd_port);
516 switch (nfss->mountd_protocol) {
518 seq_printf(m, ",mountproto=udp");
521 seq_printf(m, ",mountproto=tcp");
525 seq_printf(m, ",mountproto=auto");
530 * Describe the mount options in force on this server representation
532 static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
535 static const struct proc_nfs_info {
540 { NFS_MOUNT_SOFT, ",soft", ",hard" },
541 { NFS_MOUNT_POSIX, ",posix", "" },
542 { NFS_MOUNT_NOCTO, ",nocto", "" },
543 { NFS_MOUNT_NOAC, ",noac", "" },
544 { NFS_MOUNT_NONLM, ",nolock", "" },
545 { NFS_MOUNT_NOACL, ",noacl", "" },
546 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
547 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
548 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
551 const struct proc_nfs_info *nfs_infop;
552 struct nfs_client *clp = nfss->nfs_client;
553 u32 version = clp->rpc_ops->version;
555 seq_printf(m, ",vers=%u", version);
556 seq_printf(m, ",rsize=%u", nfss->rsize);
557 seq_printf(m, ",wsize=%u", nfss->wsize);
558 if (nfss->bsize != 0)
559 seq_printf(m, ",bsize=%u", nfss->bsize);
560 seq_printf(m, ",namlen=%u", nfss->namelen);
561 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
562 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
563 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
564 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
565 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
566 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
567 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
568 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
569 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
570 if (nfss->flags & nfs_infop->flag)
571 seq_puts(m, nfs_infop->str);
573 seq_puts(m, nfs_infop->nostr);
575 seq_printf(m, ",proto=%s",
576 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_PROTO));
578 if (nfss->port != NFS_PORT)
579 seq_printf(m, ",port=%u", nfss->port);
582 seq_printf(m, ",port=%u", nfss->port);
584 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
585 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
586 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
589 nfs_show_mountd_options(m, nfss, showdefaults);
592 if (clp->rpc_ops->version == 4)
593 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
595 if (nfss->options & NFS_OPTION_FSCACHE)
596 seq_printf(m, ",fsc");
600 * Describe the mount options on this VFS mountpoint
602 static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
604 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
606 nfs_show_mount_options(m, nfss, 0);
608 seq_printf(m, ",addr=%s",
609 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
616 * Present statistical information for this VFS mountpoint
618 static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
621 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
622 struct rpc_auth *auth = nfss->client->cl_auth;
623 struct nfs_iostats totals = { };
625 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
628 * Display all mount option settings
630 seq_printf(m, "\n\topts:\t");
631 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
632 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
633 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
634 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
635 nfs_show_mount_options(m, nfss, 1);
637 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
639 seq_printf(m, "\n\tcaps:\t");
640 seq_printf(m, "caps=0x%x", nfss->caps);
641 seq_printf(m, ",wtmult=%u", nfss->wtmult);
642 seq_printf(m, ",dtsize=%u", nfss->dtsize);
643 seq_printf(m, ",bsize=%u", nfss->bsize);
644 seq_printf(m, ",namlen=%u", nfss->namelen);
647 if (nfss->nfs_client->rpc_ops->version == 4) {
648 seq_printf(m, "\n\tnfsv4:\t");
649 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
650 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
651 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
656 * Display security flavor in effect for this mount
658 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
660 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
663 * Display superblock I/O counters
665 for_each_possible_cpu(cpu) {
666 struct nfs_iostats *stats;
669 stats = per_cpu_ptr(nfss->io_stats, cpu);
671 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
672 totals.events[i] += stats->events[i];
673 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
674 totals.bytes[i] += stats->bytes[i];
675 #ifdef CONFIG_NFS_FSCACHE
676 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
677 totals.fscache[i] += stats->fscache[i];
683 seq_printf(m, "\n\tevents:\t");
684 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
685 seq_printf(m, "%lu ", totals.events[i]);
686 seq_printf(m, "\n\tbytes:\t");
687 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
688 seq_printf(m, "%Lu ", totals.bytes[i]);
689 #ifdef CONFIG_NFS_FSCACHE
690 if (nfss->options & NFS_OPTION_FSCACHE) {
691 seq_printf(m, "\n\tfsc:\t");
692 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
693 seq_printf(m, "%Lu ", totals.bytes[i]);
698 rpc_print_iostats(m, nfss->client);
704 * Begin unmount by attempting to remove all automounted mountpoints we added
705 * in response to xdev traversals and referrals
707 static void nfs_umount_begin(struct super_block *sb)
709 struct nfs_server *server;
710 struct rpc_clnt *rpc;
715 /* -EIO all pending I/O */
716 rpc = server->client_acl;
718 rpc_killall_tasks(rpc);
719 rpc = server->client;
721 rpc_killall_tasks(rpc);
727 * Sanity-check a server address provided by the mount command.
729 * Address family must be initialized, and address must not be
730 * the ANY address for that family.
732 static int nfs_verify_server_address(struct sockaddr *addr)
734 switch (addr->sa_family) {
736 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
737 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
740 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
741 return !ipv6_addr_any(sa);
745 dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
750 * Sanity check the NFS transport protocol.
753 static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
755 switch (mnt->nfs_server.protocol) {
756 case XPRT_TRANSPORT_UDP:
757 case XPRT_TRANSPORT_TCP:
758 case XPRT_TRANSPORT_RDMA:
761 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
766 * For text based NFSv2/v3 mounts, the mount protocol transport default
767 * settings should depend upon the specified NFS transport.
769 static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
771 nfs_validate_transport_protocol(mnt);
773 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
774 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
776 switch (mnt->nfs_server.protocol) {
777 case XPRT_TRANSPORT_UDP:
778 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
780 case XPRT_TRANSPORT_TCP:
781 case XPRT_TRANSPORT_RDMA:
782 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
787 * Parse the value of the 'sec=' option.
789 static int nfs_parse_security_flavors(char *value,
790 struct nfs_parsed_mount_data *mnt)
792 substring_t args[MAX_OPT_ARGS];
794 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
796 switch (match_token(value, nfs_secflavor_tokens, args)) {
798 mnt->auth_flavors[0] = RPC_AUTH_NULL;
801 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
804 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
807 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
810 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
813 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
816 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
819 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
822 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
825 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
828 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
834 mnt->auth_flavor_len = 1;
839 * Error-check and convert a string of mount options from user space into
840 * a data structure. The whole mount string is processed; bad options are
841 * skipped as they are encountered. If there were no errors, return 1;
842 * otherwise return 0 (zero).
844 static int nfs_parse_mount_options(char *raw,
845 struct nfs_parsed_mount_data *mnt)
847 char *p, *string, *secdata;
848 int rc, sloppy = 0, invalid_option = 0;
851 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
854 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
856 secdata = alloc_secdata();
860 rc = security_sb_copy_data(raw, secdata);
862 goto out_security_failure;
864 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
866 goto out_security_failure;
868 free_secdata(secdata);
870 while ((p = strsep(&raw, ",")) != NULL) {
871 substring_t args[MAX_OPT_ARGS];
872 unsigned long option;
878 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
880 token = match_token(p, nfs_mount_option_tokens, args);
884 * boolean options: foo/nofoo
887 mnt->flags |= NFS_MOUNT_SOFT;
890 mnt->flags &= ~NFS_MOUNT_SOFT;
893 mnt->flags |= NFS_MOUNT_POSIX;
896 mnt->flags &= ~NFS_MOUNT_POSIX;
899 mnt->flags &= ~NFS_MOUNT_NOCTO;
902 mnt->flags |= NFS_MOUNT_NOCTO;
905 mnt->flags &= ~NFS_MOUNT_NOAC;
908 mnt->flags |= NFS_MOUNT_NOAC;
911 mnt->flags &= ~NFS_MOUNT_NONLM;
914 mnt->flags |= NFS_MOUNT_NONLM;
917 mnt->flags &= ~NFS_MOUNT_VER3;
920 mnt->flags |= NFS_MOUNT_VER3;
923 mnt->flags &= ~NFS_MOUNT_TCP;
924 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
927 mnt->flags |= NFS_MOUNT_TCP;
928 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
931 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
932 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
933 xprt_load_transport(p);
936 mnt->flags &= ~NFS_MOUNT_NOACL;
939 mnt->flags |= NFS_MOUNT_NOACL;
942 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
945 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
948 mnt->flags &= ~NFS_MOUNT_UNSHARED;
950 case Opt_nosharecache:
951 mnt->flags |= NFS_MOUNT_UNSHARED;
954 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
957 mnt->flags |= NFS_MOUNT_NORESVPORT;
960 mnt->options |= NFS_OPTION_FSCACHE;
961 kfree(mnt->fscache_uniq);
962 mnt->fscache_uniq = NULL;
965 mnt->options &= ~NFS_OPTION_FSCACHE;
966 kfree(mnt->fscache_uniq);
967 mnt->fscache_uniq = NULL;
969 case Opt_fscache_uniq:
970 string = match_strdup(args);
973 kfree(mnt->fscache_uniq);
974 mnt->fscache_uniq = string;
975 mnt->options |= NFS_OPTION_FSCACHE;
979 * options that take numeric values
982 string = match_strdup(args);
985 rc = strict_strtoul(string, 10, &option);
987 if (rc != 0 || option > USHORT_MAX)
988 goto out_invalid_value;
989 mnt->nfs_server.port = option;
992 string = match_strdup(args);
995 rc = strict_strtoul(string, 10, &option);
998 goto out_invalid_value;
1002 string = match_strdup(args);
1005 rc = strict_strtoul(string, 10, &option);
1008 goto out_invalid_value;
1009 mnt->wsize = option;
1012 string = match_strdup(args);
1015 rc = strict_strtoul(string, 10, &option);
1018 goto out_invalid_value;
1019 mnt->bsize = option;
1022 string = match_strdup(args);
1025 rc = strict_strtoul(string, 10, &option);
1027 if (rc != 0 || option == 0)
1028 goto out_invalid_value;
1029 mnt->timeo = option;
1032 string = match_strdup(args);
1035 rc = strict_strtoul(string, 10, &option);
1037 if (rc != 0 || option == 0)
1038 goto out_invalid_value;
1039 mnt->retrans = option;
1042 string = match_strdup(args);
1045 rc = strict_strtoul(string, 10, &option);
1048 goto out_invalid_value;
1049 mnt->acregmin = option;
1052 string = match_strdup(args);
1055 rc = strict_strtoul(string, 10, &option);
1058 goto out_invalid_value;
1059 mnt->acregmax = option;
1062 string = match_strdup(args);
1065 rc = strict_strtoul(string, 10, &option);
1068 goto out_invalid_value;
1069 mnt->acdirmin = option;
1072 string = match_strdup(args);
1075 rc = strict_strtoul(string, 10, &option);
1078 goto out_invalid_value;
1079 mnt->acdirmax = option;
1082 string = match_strdup(args);
1085 rc = strict_strtoul(string, 10, &option);
1088 goto out_invalid_value;
1089 mnt->acregmin = mnt->acregmax =
1090 mnt->acdirmin = mnt->acdirmax = option;
1093 string = match_strdup(args);
1096 rc = strict_strtoul(string, 10, &option);
1099 goto out_invalid_value;
1100 mnt->namlen = option;
1103 string = match_strdup(args);
1106 rc = strict_strtoul(string, 10, &option);
1108 if (rc != 0 || option > USHORT_MAX)
1109 goto out_invalid_value;
1110 mnt->mount_server.port = option;
1113 string = match_strdup(args);
1116 rc = strict_strtoul(string, 10, &option);
1119 option < NFS_MNT_VERSION ||
1120 option > NFS_MNT3_VERSION)
1121 goto out_invalid_value;
1122 mnt->mount_server.version = option;
1125 string = match_strdup(args);
1128 rc = strict_strtoul(string, 10, &option);
1131 goto out_invalid_value;
1134 mnt->flags &= ~NFS_MOUNT_VER3;
1137 mnt->flags |= NFS_MOUNT_VER3;
1140 goto out_invalid_value;
1143 case Opt_minorversion:
1144 string = match_strdup(args);
1147 rc = strict_strtoul(string, 10, &option);
1150 goto out_invalid_value;
1151 if (option > NFS4_MAX_MINOR_VERSION)
1152 goto out_invalid_value;
1153 mnt->minorversion = option;
1157 * options that take text values
1160 string = match_strdup(args);
1163 rc = nfs_parse_security_flavors(string, mnt);
1166 dfprintk(MOUNT, "NFS: unrecognized "
1167 "security flavor\n");
1172 string = match_strdup(args);
1175 token = match_token(string,
1176 nfs_xprt_protocol_tokens, args);
1180 mnt->flags &= ~NFS_MOUNT_TCP;
1181 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1185 mnt->flags |= NFS_MOUNT_TCP;
1186 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1190 /* vector side protocols to TCP */
1191 mnt->flags |= NFS_MOUNT_TCP;
1192 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1193 xprt_load_transport(string);
1197 dfprintk(MOUNT, "NFS: unrecognized "
1198 "transport protocol\n");
1202 case Opt_mountproto:
1203 string = match_strdup(args);
1206 token = match_token(string,
1207 nfs_xprt_protocol_tokens, args);
1212 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
1215 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
1217 case Opt_xprt_rdma: /* not used for side protocols */
1219 dfprintk(MOUNT, "NFS: unrecognized "
1220 "transport protocol\n");
1225 string = match_strdup(args);
1228 mnt->nfs_server.addrlen =
1229 rpc_pton(string, strlen(string),
1231 &mnt->nfs_server.address,
1232 sizeof(mnt->nfs_server.address));
1234 if (mnt->nfs_server.addrlen == 0)
1235 goto out_invalid_address;
1237 case Opt_clientaddr:
1238 string = match_strdup(args);
1241 kfree(mnt->client_address);
1242 mnt->client_address = string;
1245 string = match_strdup(args);
1248 kfree(mnt->mount_server.hostname);
1249 mnt->mount_server.hostname = string;
1252 string = match_strdup(args);
1255 mnt->mount_server.addrlen =
1256 rpc_pton(string, strlen(string),
1258 &mnt->mount_server.address,
1259 sizeof(mnt->mount_server.address));
1261 if (mnt->mount_server.addrlen == 0)
1262 goto out_invalid_address;
1264 case Opt_lookupcache:
1265 string = match_strdup(args);
1268 token = match_token(string,
1269 nfs_lookupcache_tokens, args);
1272 case Opt_lookupcache_all:
1273 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1275 case Opt_lookupcache_positive:
1276 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1277 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1279 case Opt_lookupcache_none:
1280 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1283 dfprintk(MOUNT, "NFS: invalid "
1284 "lookupcache argument\n");
1294 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1297 case Opt_deprecated:
1298 dfprintk(MOUNT, "NFS: ignoring mount option "
1304 dfprintk(MOUNT, "NFS: unrecognized mount option "
1309 if (!sloppy && invalid_option)
1314 out_invalid_address:
1315 printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
1318 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
1321 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1323 out_security_failure:
1324 free_secdata(secdata);
1325 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1330 * Match the requested auth flavors with the list returned by
1331 * the server. Returns zero and sets the mount's authentication
1332 * flavor on success; returns -EACCES if server does not support
1333 * the requested flavor.
1335 static int nfs_walk_authlist(struct nfs_parsed_mount_data *args,
1336 struct nfs_mount_request *request)
1338 unsigned int i, j, server_authlist_len = *(request->auth_flav_len);
1341 * Certain releases of Linux's mountd return an empty
1342 * flavor list. To prevent behavioral regression with
1343 * these servers (ie. rejecting mounts that used to
1344 * succeed), revert to pre-2.6.32 behavior (no checking)
1345 * if the returned flavor list is empty.
1347 if (server_authlist_len == 0)
1351 * We avoid sophisticated negotiating here, as there are
1352 * plenty of cases where we can get it wrong, providing
1353 * either too little or too much security.
1355 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1356 * flavor listed first. However, some servers list
1357 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1358 * preferred default, in args->auth_flavors[0] if user
1359 * didn't specify sec= mount option.
1361 for (i = 0; i < args->auth_flavor_len; i++)
1362 for (j = 0; j < server_authlist_len; j++)
1363 if (args->auth_flavors[i] == request->auth_flavs[j]) {
1364 dfprintk(MOUNT, "NFS: using auth flavor %d\n",
1365 request->auth_flavs[j]);
1366 args->auth_flavors[0] = request->auth_flavs[j];
1370 dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n");
1371 nfs_umount(request);
1376 * Use the remote server's MOUNT service to request the NFS file handle
1377 * corresponding to the provided path.
1379 static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1380 struct nfs_fh *root_fh)
1382 rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS];
1383 unsigned int server_authlist_len = ARRAY_SIZE(server_authlist);
1384 struct nfs_mount_request request = {
1385 .sap = (struct sockaddr *)
1386 &args->mount_server.address,
1387 .dirpath = args->nfs_server.export_path,
1388 .protocol = args->mount_server.protocol,
1390 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
1391 .auth_flav_len = &server_authlist_len,
1392 .auth_flavs = server_authlist,
1396 if (args->mount_server.version == 0) {
1397 if (args->flags & NFS_MOUNT_VER3)
1398 args->mount_server.version = NFS_MNT3_VERSION;
1400 args->mount_server.version = NFS_MNT_VERSION;
1402 request.version = args->mount_server.version;
1404 if (args->mount_server.hostname)
1405 request.hostname = args->mount_server.hostname;
1407 request.hostname = args->nfs_server.hostname;
1410 * Construct the mount server's address.
1412 if (args->mount_server.address.ss_family == AF_UNSPEC) {
1413 memcpy(request.sap, &args->nfs_server.address,
1414 args->nfs_server.addrlen);
1415 args->mount_server.addrlen = args->nfs_server.addrlen;
1417 request.salen = args->mount_server.addrlen;
1420 * autobind will be used if mount_server.port == 0
1422 rpc_set_port(request.sap, args->mount_server.port);
1425 * Now ask the mount server to map our export path
1428 status = nfs_mount(&request);
1430 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1431 request.hostname, status);
1436 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1438 if (args->mount_server.version != NFS_MNT3_VERSION)
1440 return nfs_walk_authlist(args, &request);
1443 static int nfs_parse_simple_hostname(const char *dev_name,
1444 char **hostname, size_t maxnamlen,
1445 char **export_path, size_t maxpathlen)
1448 char *colon, *comma;
1450 colon = strchr(dev_name, ':');
1452 goto out_bad_devname;
1454 len = colon - dev_name;
1455 if (len > maxnamlen)
1458 /* N.B. caller will free nfs_server.hostname in all cases */
1459 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
1463 /* kill possible hostname list: not supported */
1464 comma = strchr(*hostname, ',');
1465 if (comma != NULL) {
1466 if (comma == *hostname)
1467 goto out_bad_devname;
1472 len = strlen(colon);
1473 if (len > maxpathlen)
1475 *export_path = kstrndup(colon, len, GFP_KERNEL);
1479 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1483 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1487 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1491 dfprintk(MOUNT, "NFS: server hostname too long\n");
1492 return -ENAMETOOLONG;
1495 dfprintk(MOUNT, "NFS: export pathname too long\n");
1496 return -ENAMETOOLONG;
1500 * Hostname has square brackets around it because it contains one or
1501 * more colons. We look for the first closing square bracket, and a
1502 * colon must follow it.
1504 static int nfs_parse_protected_hostname(const char *dev_name,
1505 char **hostname, size_t maxnamlen,
1506 char **export_path, size_t maxpathlen)
1511 start = (char *)(dev_name + 1);
1513 end = strchr(start, ']');
1515 goto out_bad_devname;
1516 if (*(end + 1) != ':')
1517 goto out_bad_devname;
1520 if (len > maxnamlen)
1523 /* N.B. caller will free nfs_server.hostname in all cases */
1524 *hostname = kstrndup(start, len, GFP_KERNEL);
1525 if (*hostname == NULL)
1530 if (len > maxpathlen)
1532 *export_path = kstrndup(end, len, GFP_KERNEL);
1539 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1543 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1547 dfprintk(MOUNT, "NFS: server hostname too long\n");
1548 return -ENAMETOOLONG;
1551 dfprintk(MOUNT, "NFS: export pathname too long\n");
1552 return -ENAMETOOLONG;
1556 * Split "dev_name" into "hostname:export_path".
1558 * The leftmost colon demarks the split between the server's hostname
1559 * and the export path. If the hostname starts with a left square
1560 * bracket, then it may contain colons.
1562 * Note: caller frees hostname and export path, even on error.
1564 static int nfs_parse_devname(const char *dev_name,
1565 char **hostname, size_t maxnamlen,
1566 char **export_path, size_t maxpathlen)
1568 if (*dev_name == '[')
1569 return nfs_parse_protected_hostname(dev_name,
1570 hostname, maxnamlen,
1571 export_path, maxpathlen);
1573 return nfs_parse_simple_hostname(dev_name,
1574 hostname, maxnamlen,
1575 export_path, maxpathlen);
1579 * Validate the NFS2/NFS3 mount data
1580 * - fills in the mount root filehandle
1582 * For option strings, user space handles the following behaviors:
1584 * + DNS: mapping server host name to IP address ("addr=" option)
1586 * + failure mode: how to behave if a mount request can't be handled
1587 * immediately ("fg/bg" option)
1589 * + retry: how often to retry a mount request ("retry=" option)
1591 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1592 * mountproto=tcp after mountproto=udp, and so on
1594 static int nfs_validate_mount_data(void *options,
1595 struct nfs_parsed_mount_data *args,
1596 struct nfs_fh *mntfh,
1597 const char *dev_name)
1599 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
1604 args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
1605 args->rsize = NFS_MAX_FILE_IO_SIZE;
1606 args->wsize = NFS_MAX_FILE_IO_SIZE;
1607 args->acregmin = NFS_DEF_ACREGMIN;
1608 args->acregmax = NFS_DEF_ACREGMAX;
1609 args->acdirmin = NFS_DEF_ACDIRMIN;
1610 args->acdirmax = NFS_DEF_ACDIRMAX;
1611 args->mount_server.port = 0; /* autobind unless user sets port */
1612 args->nfs_server.port = 0; /* autobind unless user sets port */
1613 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1614 args->auth_flavors[0] = RPC_AUTH_UNIX;
1615 args->auth_flavor_len = 1;
1617 switch (data->version) {
1623 if (data->flags & NFS_MOUNT_VER3)
1625 data->root.size = NFS2_FHSIZE;
1626 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1628 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1631 memset(data->context, 0, sizeof(data->context));
1633 if (data->flags & NFS_MOUNT_VER3) {
1634 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1635 goto out_invalid_fh;
1636 mntfh->size = data->root.size;
1638 mntfh->size = NFS2_FHSIZE;
1641 memcpy(mntfh->data, data->root.data, mntfh->size);
1642 if (mntfh->size < sizeof(mntfh->data))
1643 memset(mntfh->data + mntfh->size, 0,
1644 sizeof(mntfh->data) - mntfh->size);
1647 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1650 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
1651 args->rsize = data->rsize;
1652 args->wsize = data->wsize;
1653 args->timeo = data->timeo;
1654 args->retrans = data->retrans;
1655 args->acregmin = data->acregmin;
1656 args->acregmax = data->acregmax;
1657 args->acdirmin = data->acdirmin;
1658 args->acdirmax = data->acdirmax;
1660 memcpy(&args->nfs_server.address, &data->addr,
1661 sizeof(data->addr));
1662 args->nfs_server.addrlen = sizeof(data->addr);
1663 if (!nfs_verify_server_address((struct sockaddr *)
1664 &args->nfs_server.address))
1665 goto out_no_address;
1667 if (!(data->flags & NFS_MOUNT_TCP))
1668 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1669 /* N.B. caller will free nfs_server.hostname in all cases */
1670 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1671 args->namlen = data->namlen;
1672 args->bsize = data->bsize;
1674 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1675 args->auth_flavors[0] = data->pseudoflavor;
1676 if (!args->nfs_server.hostname)
1680 * The legacy version 6 binary mount data from userspace has a
1681 * field used only to transport selinux information into the
1682 * the kernel. To continue to support that functionality we
1683 * have a touch of selinux knowledge here in the NFS code. The
1684 * userspace code converted context=blah to just blah so we are
1685 * converting back to the full string selinux understands.
1687 if (data->context[0]){
1688 #ifdef CONFIG_SECURITY_SELINUX
1690 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1693 strcpy(opts_str, "context=");
1694 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1695 strcat(opts_str, &data->context[0]);
1696 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1709 if (nfs_parse_mount_options((char *)options, args) == 0)
1712 if (!nfs_verify_server_address((struct sockaddr *)
1713 &args->nfs_server.address))
1714 goto out_no_address;
1716 rpc_set_port((struct sockaddr *)&args->nfs_server.address,
1717 args->nfs_server.port);
1719 nfs_set_mount_transport_protocol(args);
1721 status = nfs_parse_devname(dev_name,
1722 &args->nfs_server.hostname,
1724 &args->nfs_server.export_path,
1727 status = nfs_try_mount(args, mntfh);
1729 kfree(args->nfs_server.export_path);
1730 args->nfs_server.export_path = NULL;
1739 #ifndef CONFIG_NFS_V3
1740 if (args->flags & NFS_MOUNT_VER3)
1741 goto out_v3_not_compiled;
1742 #endif /* !CONFIG_NFS_V3 */
1747 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1751 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1756 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1759 #ifndef CONFIG_NFS_V3
1760 out_v3_not_compiled:
1761 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1762 return -EPROTONOSUPPORT;
1763 #endif /* !CONFIG_NFS_V3 */
1766 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
1770 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1774 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1779 nfs_compare_remount_data(struct nfs_server *nfss,
1780 struct nfs_parsed_mount_data *data)
1782 if (data->flags != nfss->flags ||
1783 data->rsize != nfss->rsize ||
1784 data->wsize != nfss->wsize ||
1785 data->retrans != nfss->client->cl_timeout->to_retries ||
1786 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
1787 data->acregmin != nfss->acregmin / HZ ||
1788 data->acregmax != nfss->acregmax / HZ ||
1789 data->acdirmin != nfss->acdirmin / HZ ||
1790 data->acdirmax != nfss->acdirmax / HZ ||
1791 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
1792 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
1793 memcmp(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1794 data->nfs_server.addrlen) != 0)
1801 nfs_remount(struct super_block *sb, int *flags, char *raw_data)
1804 struct nfs_server *nfss = sb->s_fs_info;
1805 struct nfs_parsed_mount_data *data;
1806 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
1807 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
1808 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
1811 * Userspace mount programs that send binary options generally send
1812 * them populated with default values. We have no way to know which
1813 * ones were explicitly specified. Fall back to legacy behavior and
1814 * just return success.
1816 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
1817 (nfsvers <= 3 && (!options || (options->version >= 1 &&
1818 options->version <= 6))))
1821 data = kzalloc(sizeof(*data), GFP_KERNEL);
1826 /* fill out struct with values from existing mount */
1827 data->flags = nfss->flags;
1828 data->rsize = nfss->rsize;
1829 data->wsize = nfss->wsize;
1830 data->retrans = nfss->client->cl_timeout->to_retries;
1831 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
1832 data->acregmin = nfss->acregmin / HZ;
1833 data->acregmax = nfss->acregmax / HZ;
1834 data->acdirmin = nfss->acdirmin / HZ;
1835 data->acdirmax = nfss->acdirmax / HZ;
1836 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
1837 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
1838 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1839 data->nfs_server.addrlen);
1841 /* overwrite those values with any that were specified */
1842 error = nfs_parse_mount_options((char *)options, data);
1846 /* compare new mount options with old ones */
1847 error = nfs_compare_remount_data(nfss, data);
1855 * Initialise the common bits of the superblock
1857 static inline void nfs_initialise_sb(struct super_block *sb)
1859 struct nfs_server *server = NFS_SB(sb);
1861 sb->s_magic = NFS_SUPER_MAGIC;
1863 /* We probably want something more informative here */
1864 snprintf(sb->s_id, sizeof(sb->s_id),
1865 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1867 if (sb->s_blocksize == 0)
1868 sb->s_blocksize = nfs_block_bits(server->wsize,
1869 &sb->s_blocksize_bits);
1871 if (server->flags & NFS_MOUNT_NOAC)
1872 sb->s_flags |= MS_SYNCHRONOUS;
1874 nfs_super_set_maxbytes(sb, server->maxfilesize);
1878 * Finish setting up an NFS2/3 superblock
1880 static void nfs_fill_super(struct super_block *sb,
1881 struct nfs_parsed_mount_data *data)
1883 struct nfs_server *server = NFS_SB(sb);
1885 sb->s_blocksize_bits = 0;
1886 sb->s_blocksize = 0;
1888 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1890 if (server->flags & NFS_MOUNT_VER3) {
1891 /* The VFS shouldn't apply the umask to mode bits. We will do
1892 * so ourselves when necessary.
1894 sb->s_flags |= MS_POSIXACL;
1895 sb->s_time_gran = 1;
1898 sb->s_op = &nfs_sops;
1899 nfs_initialise_sb(sb);
1903 * Finish setting up a cloned NFS2/3 superblock
1905 static void nfs_clone_super(struct super_block *sb,
1906 const struct super_block *old_sb)
1908 struct nfs_server *server = NFS_SB(sb);
1910 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1911 sb->s_blocksize = old_sb->s_blocksize;
1912 sb->s_maxbytes = old_sb->s_maxbytes;
1914 if (server->flags & NFS_MOUNT_VER3) {
1915 /* The VFS shouldn't apply the umask to mode bits. We will do
1916 * so ourselves when necessary.
1918 sb->s_flags |= MS_POSIXACL;
1919 sb->s_time_gran = 1;
1922 sb->s_op = old_sb->s_op;
1923 nfs_initialise_sb(sb);
1926 static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
1928 const struct nfs_server *a = s->s_fs_info;
1929 const struct rpc_clnt *clnt_a = a->client;
1930 const struct rpc_clnt *clnt_b = b->client;
1932 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
1934 if (a->nfs_client != b->nfs_client)
1936 if (a->flags != b->flags)
1938 if (a->wsize != b->wsize)
1940 if (a->rsize != b->rsize)
1942 if (a->acregmin != b->acregmin)
1944 if (a->acregmax != b->acregmax)
1946 if (a->acdirmin != b->acdirmin)
1948 if (a->acdirmax != b->acdirmax)
1950 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
1957 struct nfs_sb_mountdata {
1958 struct nfs_server *server;
1962 static int nfs_set_super(struct super_block *s, void *data)
1964 struct nfs_sb_mountdata *sb_mntdata = data;
1965 struct nfs_server *server = sb_mntdata->server;
1968 s->s_flags = sb_mntdata->mntflags;
1969 s->s_fs_info = server;
1970 ret = set_anon_super(s, server);
1972 server->s_dev = s->s_dev;
1976 static int nfs_compare_super_address(struct nfs_server *server1,
1977 struct nfs_server *server2)
1979 struct sockaddr *sap1, *sap2;
1981 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
1982 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
1984 if (sap1->sa_family != sap2->sa_family)
1987 switch (sap1->sa_family) {
1989 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
1990 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
1991 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
1993 if (sin1->sin_port != sin2->sin_port)
1998 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
1999 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
2000 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
2002 if (sin1->sin6_port != sin2->sin6_port)
2013 static int nfs_compare_super(struct super_block *sb, void *data)
2015 struct nfs_sb_mountdata *sb_mntdata = data;
2016 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2017 int mntflags = sb_mntdata->mntflags;
2019 if (!nfs_compare_super_address(old, server))
2021 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2022 if (old->flags & NFS_MOUNT_UNSHARED)
2024 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2026 return nfs_compare_mount_options(sb, server, mntflags);
2029 static int nfs_bdi_register(struct nfs_server *server)
2031 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
2034 static int nfs_get_sb(struct file_system_type *fs_type,
2035 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2037 struct nfs_server *server = NULL;
2038 struct super_block *s;
2039 struct nfs_parsed_mount_data *data;
2040 struct nfs_fh *mntfh;
2041 struct dentry *mntroot;
2042 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2043 struct nfs_sb_mountdata sb_mntdata = {
2046 int error = -ENOMEM;
2048 data = kzalloc(sizeof(*data), GFP_KERNEL);
2049 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
2050 if (data == NULL || mntfh == NULL)
2053 security_init_mnt_opts(&data->lsm_opts);
2055 /* Validate the mount data */
2056 error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
2060 /* Get a volume representation */
2061 server = nfs_create_server(data, mntfh);
2062 if (IS_ERR(server)) {
2063 error = PTR_ERR(server);
2066 sb_mntdata.server = server;
2068 if (server->flags & NFS_MOUNT_UNSHARED)
2069 compare_super = NULL;
2071 /* Get a superblock - note that we may end up sharing one that already exists */
2072 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
2078 if (s->s_fs_info != server) {
2079 nfs_free_server(server);
2082 error = nfs_bdi_register(server);
2084 goto error_splat_super;
2088 /* initial superblock/root creation */
2089 nfs_fill_super(s, data);
2090 nfs_fscache_get_super_cookie(s, data);
2093 mntroot = nfs_get_root(s, mntfh);
2094 if (IS_ERR(mntroot)) {
2095 error = PTR_ERR(mntroot);
2096 goto error_splat_super;
2099 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
2101 goto error_splat_root;
2103 s->s_flags |= MS_ACTIVE;
2105 mnt->mnt_root = mntroot;
2109 kfree(data->nfs_server.hostname);
2110 kfree(data->mount_server.hostname);
2111 kfree(data->fscache_uniq);
2112 security_free_mnt_opts(&data->lsm_opts);
2119 nfs_free_server(server);
2125 deactivate_locked_super(s);
2130 * Destroy an NFS2/3 superblock
2132 static void nfs_kill_super(struct super_block *s)
2134 struct nfs_server *server = NFS_SB(s);
2136 bdi_unregister(&server->backing_dev_info);
2138 nfs_fscache_release_super_cookie(s);
2139 nfs_free_server(server);
2143 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2145 static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
2146 const char *dev_name, void *raw_data,
2147 struct vfsmount *mnt)
2149 struct nfs_clone_mount *data = raw_data;
2150 struct super_block *s;
2151 struct nfs_server *server;
2152 struct dentry *mntroot;
2153 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2154 struct nfs_sb_mountdata sb_mntdata = {
2159 dprintk("--> nfs_xdev_get_sb()\n");
2161 /* create a new volume representation */
2162 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2163 if (IS_ERR(server)) {
2164 error = PTR_ERR(server);
2165 goto out_err_noserver;
2167 sb_mntdata.server = server;
2169 if (server->flags & NFS_MOUNT_UNSHARED)
2170 compare_super = NULL;
2172 /* Get a superblock - note that we may end up sharing one that already exists */
2173 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2179 if (s->s_fs_info != server) {
2180 nfs_free_server(server);
2183 error = nfs_bdi_register(server);
2185 goto error_splat_super;
2189 /* initial superblock/root creation */
2190 nfs_clone_super(s, data->sb);
2193 mntroot = nfs_get_root(s, data->fh);
2194 if (IS_ERR(mntroot)) {
2195 error = PTR_ERR(mntroot);
2196 goto error_splat_super;
2198 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2201 goto error_splat_super;
2204 s->s_flags |= MS_ACTIVE;
2206 mnt->mnt_root = mntroot;
2208 /* clone any lsm security options from the parent to the new sb */
2209 security_sb_clone_mnt_opts(data->sb, s);
2211 dprintk("<-- nfs_xdev_get_sb() = 0\n");
2215 nfs_free_server(server);
2217 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
2221 deactivate_locked_super(s);
2222 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
2226 #ifdef CONFIG_NFS_V4
2229 * Finish setting up a cloned NFS4 superblock
2231 static void nfs4_clone_super(struct super_block *sb,
2232 const struct super_block *old_sb)
2234 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2235 sb->s_blocksize = old_sb->s_blocksize;
2236 sb->s_maxbytes = old_sb->s_maxbytes;
2237 sb->s_time_gran = 1;
2238 sb->s_op = old_sb->s_op;
2239 nfs_initialise_sb(sb);
2243 * Set up an NFS4 superblock
2245 static void nfs4_fill_super(struct super_block *sb)
2247 sb->s_time_gran = 1;
2248 sb->s_op = &nfs4_sops;
2249 nfs_initialise_sb(sb);
2252 static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2254 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3);
2258 * Validate NFSv4 mount options
2260 static int nfs4_validate_mount_data(void *options,
2261 struct nfs_parsed_mount_data *args,
2262 const char *dev_name)
2264 struct sockaddr_in *ap;
2265 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
2271 args->rsize = NFS_MAX_FILE_IO_SIZE;
2272 args->wsize = NFS_MAX_FILE_IO_SIZE;
2273 args->acregmin = NFS_DEF_ACREGMIN;
2274 args->acregmax = NFS_DEF_ACREGMAX;
2275 args->acdirmin = NFS_DEF_ACDIRMIN;
2276 args->acdirmax = NFS_DEF_ACDIRMAX;
2277 args->nfs_server.port = NFS_PORT; /* 2049 unless user set port= */
2278 args->auth_flavors[0] = RPC_AUTH_UNIX;
2279 args->auth_flavor_len = 1;
2280 args->minorversion = 0;
2282 switch (data->version) {
2284 ap = (struct sockaddr_in *)&args->nfs_server.address;
2285 if (data->host_addrlen > sizeof(args->nfs_server.address))
2286 goto out_no_address;
2287 if (data->host_addrlen == 0)
2288 goto out_no_address;
2289 args->nfs_server.addrlen = data->host_addrlen;
2290 if (copy_from_user(ap, data->host_addr, data->host_addrlen))
2292 if (!nfs_verify_server_address((struct sockaddr *)
2293 &args->nfs_server.address))
2294 goto out_no_address;
2296 if (data->auth_flavourlen) {
2297 if (data->auth_flavourlen > 1)
2298 goto out_inval_auth;
2299 if (copy_from_user(&args->auth_flavors[0],
2300 data->auth_flavours,
2301 sizeof(args->auth_flavors[0])))
2305 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2308 args->nfs_server.hostname = c;
2310 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2313 args->nfs_server.export_path = c;
2314 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
2316 c = strndup_user(data->client_addr.data, 16);
2319 args->client_address = c;
2322 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2326 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2327 args->rsize = data->rsize;
2328 args->wsize = data->wsize;
2329 args->timeo = data->timeo;
2330 args->retrans = data->retrans;
2331 args->acregmin = data->acregmin;
2332 args->acregmax = data->acregmax;
2333 args->acdirmin = data->acdirmin;
2334 args->acdirmax = data->acdirmax;
2335 args->nfs_server.protocol = data->proto;
2336 nfs_validate_transport_protocol(args);
2342 if (nfs_parse_mount_options((char *)options, args) == 0)
2345 if (!nfs_verify_server_address((struct sockaddr *)
2346 &args->nfs_server.address))
2349 rpc_set_port((struct sockaddr *)&args->nfs_server.address,
2350 args->nfs_server.port);
2352 nfs_validate_transport_protocol(args);
2354 nfs4_validate_mount_flags(args);
2356 if (args->auth_flavor_len > 1)
2357 goto out_inval_auth;
2359 if (args->client_address == NULL)
2360 goto out_no_client_address;
2362 status = nfs_parse_devname(dev_name,
2363 &args->nfs_server.hostname,
2365 &args->nfs_server.export_path,
2377 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2381 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2382 data->auth_flavourlen);
2386 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2389 out_no_client_address:
2390 dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
2395 * Get the superblock for the NFS4 root partition
2397 static int nfs4_remote_get_sb(struct file_system_type *fs_type,
2398 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2400 struct nfs_parsed_mount_data *data = raw_data;
2401 struct super_block *s;
2402 struct nfs_server *server;
2403 struct nfs_fh *mntfh;
2404 struct dentry *mntroot;
2405 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2406 struct nfs_sb_mountdata sb_mntdata = {
2409 int error = -ENOMEM;
2411 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
2412 if (data == NULL || mntfh == NULL)
2415 security_init_mnt_opts(&data->lsm_opts);
2417 /* Get a volume representation */
2418 server = nfs4_create_server(data, mntfh);
2419 if (IS_ERR(server)) {
2420 error = PTR_ERR(server);
2423 sb_mntdata.server = server;
2425 if (server->flags & NFS4_MOUNT_UNSHARED)
2426 compare_super = NULL;
2428 /* Get a superblock - note that we may end up sharing one that already exists */
2429 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2435 if (s->s_fs_info != server) {
2436 nfs_free_server(server);
2439 error = nfs_bdi_register(server);
2441 goto error_splat_super;
2445 /* initial superblock/root creation */
2447 nfs_fscache_get_super_cookie(s, data);
2450 mntroot = nfs4_get_root(s, mntfh);
2451 if (IS_ERR(mntroot)) {
2452 error = PTR_ERR(mntroot);
2453 goto error_splat_super;
2456 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
2458 goto error_splat_root;
2460 s->s_flags |= MS_ACTIVE;
2462 mnt->mnt_root = mntroot;
2466 security_free_mnt_opts(&data->lsm_opts);
2472 nfs_free_server(server);
2478 deactivate_locked_super(s);
2482 static struct vfsmount *nfs_do_root_mount(struct file_system_type *fs_type,
2483 int flags, void *data, const char *hostname)
2485 struct vfsmount *root_mnt;
2489 len = strlen(hostname) + 3;
2490 root_devname = kmalloc(len, GFP_KERNEL);
2491 if (root_devname == NULL)
2492 return ERR_PTR(-ENOMEM);
2493 snprintf(root_devname, len, "%s:/", hostname);
2494 root_mnt = vfs_kern_mount(fs_type, flags, root_devname, data);
2495 kfree(root_devname);
2499 static void nfs_fix_devname(const struct path *path, struct vfsmount *mnt)
2501 char *page = (char *) __get_free_page(GFP_KERNEL);
2502 char *devname, *tmp;
2506 devname = nfs_path(path->mnt->mnt_devname,
2507 path->mnt->mnt_root, path->dentry,
2509 if (devname == NULL)
2511 tmp = kstrdup(devname, GFP_KERNEL);
2514 kfree(mnt->mnt_devname);
2515 mnt->mnt_devname = tmp;
2517 free_page((unsigned long)page);
2520 static int nfs_follow_remote_path(struct vfsmount *root_mnt,
2521 const char *export_path, struct vfsmount *mnt_target)
2523 struct mnt_namespace *ns_private;
2524 struct nameidata nd;
2525 struct super_block *s;
2528 ns_private = create_mnt_ns(root_mnt);
2529 ret = PTR_ERR(ns_private);
2530 if (IS_ERR(ns_private))
2533 ret = vfs_path_lookup(root_mnt->mnt_root, root_mnt,
2534 export_path, LOOKUP_FOLLOW, &nd);
2536 put_mnt_ns(ns_private);
2541 s = nd.path.mnt->mnt_sb;
2542 atomic_inc(&s->s_active);
2543 mnt_target->mnt_sb = s;
2544 mnt_target->mnt_root = dget(nd.path.dentry);
2546 /* Correct the device pathname */
2547 nfs_fix_devname(&nd.path, mnt_target);
2550 down_write(&s->s_umount);
2559 * Get the superblock for an NFS4 mountpoint
2561 static int nfs4_get_sb(struct file_system_type *fs_type,
2562 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2564 struct nfs_parsed_mount_data *data;
2566 struct vfsmount *root_mnt;
2567 int error = -ENOMEM;
2569 data = kzalloc(sizeof(*data), GFP_KERNEL);
2573 /* Validate the mount data */
2574 error = nfs4_validate_mount_data(raw_data, data, dev_name);
2578 export_path = data->nfs_server.export_path;
2579 data->nfs_server.export_path = "/";
2580 root_mnt = nfs_do_root_mount(&nfs4_remote_fs_type, flags, data,
2581 data->nfs_server.hostname);
2582 data->nfs_server.export_path = export_path;
2584 error = PTR_ERR(root_mnt);
2585 if (IS_ERR(root_mnt))
2588 error = nfs_follow_remote_path(root_mnt, export_path, mnt);
2591 kfree(data->client_address);
2592 kfree(data->nfs_server.export_path);
2593 kfree(data->nfs_server.hostname);
2594 kfree(data->fscache_uniq);
2597 dprintk("<-- nfs4_get_sb() = %d%s\n", error,
2598 error != 0 ? " [error]" : "");
2602 static void nfs4_kill_super(struct super_block *sb)
2604 struct nfs_server *server = NFS_SB(sb);
2606 dprintk("--> %s\n", __func__);
2607 nfs_super_return_all_delegations(sb);
2608 kill_anon_super(sb);
2609 nfs4_renewd_prepare_shutdown(server);
2610 nfs_fscache_release_super_cookie(sb);
2611 nfs_free_server(server);
2612 dprintk("<-- %s\n", __func__);
2616 * Clone an NFS4 server record on xdev traversal (FSID-change)
2618 static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
2619 const char *dev_name, void *raw_data,
2620 struct vfsmount *mnt)
2622 struct nfs_clone_mount *data = raw_data;
2623 struct super_block *s;
2624 struct nfs_server *server;
2625 struct dentry *mntroot;
2626 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2627 struct nfs_sb_mountdata sb_mntdata = {
2632 dprintk("--> nfs4_xdev_get_sb()\n");
2634 /* create a new volume representation */
2635 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2636 if (IS_ERR(server)) {
2637 error = PTR_ERR(server);
2638 goto out_err_noserver;
2640 sb_mntdata.server = server;
2642 if (server->flags & NFS4_MOUNT_UNSHARED)
2643 compare_super = NULL;
2645 /* Get a superblock - note that we may end up sharing one that already exists */
2646 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2652 if (s->s_fs_info != server) {
2653 nfs_free_server(server);
2656 error = nfs_bdi_register(server);
2658 goto error_splat_super;
2662 /* initial superblock/root creation */
2663 nfs4_clone_super(s, data->sb);
2666 mntroot = nfs4_get_root(s, data->fh);
2667 if (IS_ERR(mntroot)) {
2668 error = PTR_ERR(mntroot);
2669 goto error_splat_super;
2671 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2674 goto error_splat_super;
2677 s->s_flags |= MS_ACTIVE;
2679 mnt->mnt_root = mntroot;
2681 security_sb_clone_mnt_opts(data->sb, s);
2683 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2687 nfs_free_server(server);
2689 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
2693 deactivate_locked_super(s);
2694 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
2698 static int nfs4_remote_referral_get_sb(struct file_system_type *fs_type,
2699 int flags, const char *dev_name, void *raw_data,
2700 struct vfsmount *mnt)
2702 struct nfs_clone_mount *data = raw_data;
2703 struct super_block *s;
2704 struct nfs_server *server;
2705 struct dentry *mntroot;
2706 struct nfs_fh mntfh;
2707 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2708 struct nfs_sb_mountdata sb_mntdata = {
2713 dprintk("--> nfs4_referral_get_sb()\n");
2715 /* create a new volume representation */
2716 server = nfs4_create_referral_server(data, &mntfh);
2717 if (IS_ERR(server)) {
2718 error = PTR_ERR(server);
2719 goto out_err_noserver;
2721 sb_mntdata.server = server;
2723 if (server->flags & NFS4_MOUNT_UNSHARED)
2724 compare_super = NULL;
2726 /* Get a superblock - note that we may end up sharing one that already exists */
2727 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2733 if (s->s_fs_info != server) {
2734 nfs_free_server(server);
2737 error = nfs_bdi_register(server);
2739 goto error_splat_super;
2743 /* initial superblock/root creation */
2747 mntroot = nfs4_get_root(s, &mntfh);
2748 if (IS_ERR(mntroot)) {
2749 error = PTR_ERR(mntroot);
2750 goto error_splat_super;
2752 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2755 goto error_splat_super;
2758 s->s_flags |= MS_ACTIVE;
2760 mnt->mnt_root = mntroot;
2762 security_sb_clone_mnt_opts(data->sb, s);
2764 dprintk("<-- nfs4_referral_get_sb() = 0\n");
2768 nfs_free_server(server);
2770 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
2774 deactivate_locked_super(s);
2775 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
2780 * Create an NFS4 server record on referral traversal
2782 static int nfs4_referral_get_sb(struct file_system_type *fs_type,
2783 int flags, const char *dev_name, void *raw_data,
2784 struct vfsmount *mnt)
2786 struct nfs_clone_mount *data = raw_data;
2788 struct vfsmount *root_mnt;
2791 dprintk("--> nfs4_referral_get_sb()\n");
2793 export_path = data->mnt_path;
2794 data->mnt_path = "/";
2796 root_mnt = nfs_do_root_mount(&nfs4_remote_referral_fs_type,
2797 flags, data, data->hostname);
2798 data->mnt_path = export_path;
2800 error = PTR_ERR(root_mnt);
2801 if (IS_ERR(root_mnt))
2804 error = nfs_follow_remote_path(root_mnt, export_path, mnt);
2806 dprintk("<-- nfs4_referral_get_sb() = %d%s\n", error,
2807 error != 0 ? " [error]" : "");
2811 #endif /* CONFIG_NFS_V4 */