net: Dont use netdev_warn()
[linux-rapidio-2.6.git] / fs / nfs / super.c
blobe01637240eeb59fb4032b926e3c709c771fdcedd
1 /*
2 * linux/fs/nfs/super.c
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>
28 #include <linux/mm.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>
51 #include <linux/slab.h>
52 #include <net/ipv6.h>
53 #include <linux/netdevice.h>
54 #include <linux/nfs_xdr.h>
55 #include <linux/magic.h>
56 #include <linux/parser.h>
58 #include <asm/system.h>
59 #include <asm/uaccess.h>
61 #include "nfs4_fs.h"
62 #include "callback.h"
63 #include "delegation.h"
64 #include "iostat.h"
65 #include "internal.h"
66 #include "fscache.h"
68 #define NFSDBG_FACILITY NFSDBG_VFS
70 enum {
71 /* Mount options that take no arguments */
72 Opt_soft, Opt_hard,
73 Opt_posix, Opt_noposix,
74 Opt_cto, Opt_nocto,
75 Opt_ac, Opt_noac,
76 Opt_lock, Opt_nolock,
77 Opt_v2, Opt_v3, Opt_v4,
78 Opt_udp, Opt_tcp, Opt_rdma,
79 Opt_acl, Opt_noacl,
80 Opt_rdirplus, Opt_nordirplus,
81 Opt_sharecache, Opt_nosharecache,
82 Opt_resvport, Opt_noresvport,
83 Opt_fscache, Opt_nofscache,
85 /* Mount options that take integer arguments */
86 Opt_port,
87 Opt_rsize, Opt_wsize, Opt_bsize,
88 Opt_timeo, Opt_retrans,
89 Opt_acregmin, Opt_acregmax,
90 Opt_acdirmin, Opt_acdirmax,
91 Opt_actimeo,
92 Opt_namelen,
93 Opt_mountport,
94 Opt_mountvers,
95 Opt_nfsvers,
96 Opt_minorversion,
98 /* Mount options that take string arguments */
99 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
100 Opt_addr, Opt_mountaddr, Opt_clientaddr,
101 Opt_lookupcache,
102 Opt_fscache_uniq,
104 /* Special mount options */
105 Opt_userspace, Opt_deprecated, Opt_sloppy,
107 Opt_err
110 static const match_table_t nfs_mount_option_tokens = {
111 { Opt_userspace, "bg" },
112 { Opt_userspace, "fg" },
113 { Opt_userspace, "retry=%s" },
115 { Opt_sloppy, "sloppy" },
117 { Opt_soft, "soft" },
118 { Opt_hard, "hard" },
119 { Opt_deprecated, "intr" },
120 { Opt_deprecated, "nointr" },
121 { Opt_posix, "posix" },
122 { Opt_noposix, "noposix" },
123 { Opt_cto, "cto" },
124 { Opt_nocto, "nocto" },
125 { Opt_ac, "ac" },
126 { Opt_noac, "noac" },
127 { Opt_lock, "lock" },
128 { Opt_nolock, "nolock" },
129 { Opt_v2, "v2" },
130 { Opt_v3, "v3" },
131 { Opt_v4, "v4" },
132 { Opt_udp, "udp" },
133 { Opt_tcp, "tcp" },
134 { Opt_rdma, "rdma" },
135 { Opt_acl, "acl" },
136 { Opt_noacl, "noacl" },
137 { Opt_rdirplus, "rdirplus" },
138 { Opt_nordirplus, "nordirplus" },
139 { Opt_sharecache, "sharecache" },
140 { Opt_nosharecache, "nosharecache" },
141 { Opt_resvport, "resvport" },
142 { Opt_noresvport, "noresvport" },
143 { Opt_fscache, "fsc" },
144 { Opt_fscache_uniq, "fsc=%s" },
145 { Opt_nofscache, "nofsc" },
147 { Opt_port, "port=%s" },
148 { Opt_rsize, "rsize=%s" },
149 { Opt_wsize, "wsize=%s" },
150 { Opt_bsize, "bsize=%s" },
151 { Opt_timeo, "timeo=%s" },
152 { Opt_retrans, "retrans=%s" },
153 { Opt_acregmin, "acregmin=%s" },
154 { Opt_acregmax, "acregmax=%s" },
155 { Opt_acdirmin, "acdirmin=%s" },
156 { Opt_acdirmax, "acdirmax=%s" },
157 { Opt_actimeo, "actimeo=%s" },
158 { Opt_namelen, "namlen=%s" },
159 { Opt_mountport, "mountport=%s" },
160 { Opt_mountvers, "mountvers=%s" },
161 { Opt_nfsvers, "nfsvers=%s" },
162 { Opt_nfsvers, "vers=%s" },
163 { Opt_minorversion, "minorversion=%s" },
165 { Opt_sec, "sec=%s" },
166 { Opt_proto, "proto=%s" },
167 { Opt_mountproto, "mountproto=%s" },
168 { Opt_addr, "addr=%s" },
169 { Opt_clientaddr, "clientaddr=%s" },
170 { Opt_mounthost, "mounthost=%s" },
171 { Opt_mountaddr, "mountaddr=%s" },
173 { Opt_lookupcache, "lookupcache=%s" },
175 { Opt_err, NULL }
178 enum {
179 Opt_xprt_udp, Opt_xprt_udp6, Opt_xprt_tcp, Opt_xprt_tcp6, Opt_xprt_rdma,
181 Opt_xprt_err
184 static const match_table_t nfs_xprt_protocol_tokens = {
185 { Opt_xprt_udp, "udp" },
186 { Opt_xprt_udp6, "udp6" },
187 { Opt_xprt_tcp, "tcp" },
188 { Opt_xprt_tcp6, "tcp6" },
189 { Opt_xprt_rdma, "rdma" },
191 { Opt_xprt_err, NULL }
194 enum {
195 Opt_sec_none, Opt_sec_sys,
196 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
197 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
198 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
200 Opt_sec_err
203 static const match_table_t nfs_secflavor_tokens = {
204 { Opt_sec_none, "none" },
205 { Opt_sec_none, "null" },
206 { Opt_sec_sys, "sys" },
208 { Opt_sec_krb5, "krb5" },
209 { Opt_sec_krb5i, "krb5i" },
210 { Opt_sec_krb5p, "krb5p" },
212 { Opt_sec_lkey, "lkey" },
213 { Opt_sec_lkeyi, "lkeyi" },
214 { Opt_sec_lkeyp, "lkeyp" },
216 { Opt_sec_spkm, "spkm3" },
217 { Opt_sec_spkmi, "spkm3i" },
218 { Opt_sec_spkmp, "spkm3p" },
220 { Opt_sec_err, NULL }
223 enum {
224 Opt_lookupcache_all, Opt_lookupcache_positive,
225 Opt_lookupcache_none,
227 Opt_lookupcache_err
230 static match_table_t nfs_lookupcache_tokens = {
231 { Opt_lookupcache_all, "all" },
232 { Opt_lookupcache_positive, "pos" },
233 { Opt_lookupcache_positive, "positive" },
234 { Opt_lookupcache_none, "none" },
236 { Opt_lookupcache_err, NULL }
240 static void nfs_umount_begin(struct super_block *);
241 static int nfs_statfs(struct dentry *, struct kstatfs *);
242 static int nfs_show_options(struct seq_file *, struct vfsmount *);
243 static int nfs_show_stats(struct seq_file *, struct vfsmount *);
244 static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
245 static int nfs_xdev_get_sb(struct file_system_type *fs_type,
246 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
247 static void nfs_put_super(struct super_block *);
248 static void nfs_kill_super(struct super_block *);
249 static int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
251 static struct file_system_type nfs_fs_type = {
252 .owner = THIS_MODULE,
253 .name = "nfs",
254 .get_sb = nfs_get_sb,
255 .kill_sb = nfs_kill_super,
256 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
259 struct file_system_type nfs_xdev_fs_type = {
260 .owner = THIS_MODULE,
261 .name = "nfs",
262 .get_sb = nfs_xdev_get_sb,
263 .kill_sb = nfs_kill_super,
264 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
267 static const struct super_operations nfs_sops = {
268 .alloc_inode = nfs_alloc_inode,
269 .destroy_inode = nfs_destroy_inode,
270 .write_inode = nfs_write_inode,
271 .put_super = nfs_put_super,
272 .statfs = nfs_statfs,
273 .clear_inode = nfs_clear_inode,
274 .umount_begin = nfs_umount_begin,
275 .show_options = nfs_show_options,
276 .show_stats = nfs_show_stats,
277 .remount_fs = nfs_remount,
280 #ifdef CONFIG_NFS_V4
281 static int nfs4_validate_text_mount_data(void *options,
282 struct nfs_parsed_mount_data *args, const char *dev_name);
283 static int nfs4_try_mount(int flags, const char *dev_name,
284 struct nfs_parsed_mount_data *data, struct vfsmount *mnt);
285 static int nfs4_get_sb(struct file_system_type *fs_type,
286 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
287 static int nfs4_remote_get_sb(struct file_system_type *fs_type,
288 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
289 static int nfs4_xdev_get_sb(struct file_system_type *fs_type,
290 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
291 static int nfs4_referral_get_sb(struct file_system_type *fs_type,
292 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
293 static int nfs4_remote_referral_get_sb(struct file_system_type *fs_type,
294 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
295 static void nfs4_kill_super(struct super_block *sb);
297 static struct file_system_type nfs4_fs_type = {
298 .owner = THIS_MODULE,
299 .name = "nfs4",
300 .get_sb = nfs4_get_sb,
301 .kill_sb = nfs4_kill_super,
302 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
305 static struct file_system_type nfs4_remote_fs_type = {
306 .owner = THIS_MODULE,
307 .name = "nfs4",
308 .get_sb = nfs4_remote_get_sb,
309 .kill_sb = nfs4_kill_super,
310 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
313 struct file_system_type nfs4_xdev_fs_type = {
314 .owner = THIS_MODULE,
315 .name = "nfs4",
316 .get_sb = nfs4_xdev_get_sb,
317 .kill_sb = nfs4_kill_super,
318 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
321 static struct file_system_type nfs4_remote_referral_fs_type = {
322 .owner = THIS_MODULE,
323 .name = "nfs4",
324 .get_sb = nfs4_remote_referral_get_sb,
325 .kill_sb = nfs4_kill_super,
326 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
329 struct file_system_type nfs4_referral_fs_type = {
330 .owner = THIS_MODULE,
331 .name = "nfs4",
332 .get_sb = nfs4_referral_get_sb,
333 .kill_sb = nfs4_kill_super,
334 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
337 static const struct super_operations nfs4_sops = {
338 .alloc_inode = nfs_alloc_inode,
339 .destroy_inode = nfs_destroy_inode,
340 .write_inode = nfs_write_inode,
341 .put_super = nfs_put_super,
342 .statfs = nfs_statfs,
343 .clear_inode = nfs4_clear_inode,
344 .umount_begin = nfs_umount_begin,
345 .show_options = nfs_show_options,
346 .show_stats = nfs_show_stats,
347 .remount_fs = nfs_remount,
349 #endif
351 static struct shrinker acl_shrinker = {
352 .shrink = nfs_access_cache_shrinker,
353 .seeks = DEFAULT_SEEKS,
357 * Register the NFS filesystems
359 int __init register_nfs_fs(void)
361 int ret;
363 ret = register_filesystem(&nfs_fs_type);
364 if (ret < 0)
365 goto error_0;
367 ret = nfs_register_sysctl();
368 if (ret < 0)
369 goto error_1;
370 #ifdef CONFIG_NFS_V4
371 ret = register_filesystem(&nfs4_fs_type);
372 if (ret < 0)
373 goto error_2;
374 #endif
375 register_shrinker(&acl_shrinker);
376 return 0;
378 #ifdef CONFIG_NFS_V4
379 error_2:
380 nfs_unregister_sysctl();
381 #endif
382 error_1:
383 unregister_filesystem(&nfs_fs_type);
384 error_0:
385 return ret;
389 * Unregister the NFS filesystems
391 void __exit unregister_nfs_fs(void)
393 unregister_shrinker(&acl_shrinker);
394 #ifdef CONFIG_NFS_V4
395 unregister_filesystem(&nfs4_fs_type);
396 #endif
397 nfs_unregister_sysctl();
398 unregister_filesystem(&nfs_fs_type);
401 void nfs_sb_active(struct super_block *sb)
403 struct nfs_server *server = NFS_SB(sb);
405 if (atomic_inc_return(&server->active) == 1)
406 atomic_inc(&sb->s_active);
409 void nfs_sb_deactive(struct super_block *sb)
411 struct nfs_server *server = NFS_SB(sb);
413 if (atomic_dec_and_test(&server->active))
414 deactivate_super(sb);
418 * Deliver file system statistics to userspace
420 static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
422 struct nfs_server *server = NFS_SB(dentry->d_sb);
423 unsigned char blockbits;
424 unsigned long blockres;
425 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
426 struct nfs_fattr fattr;
427 struct nfs_fsstat res = {
428 .fattr = &fattr,
430 int error;
432 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
433 if (error < 0)
434 goto out_err;
435 buf->f_type = NFS_SUPER_MAGIC;
438 * Current versions of glibc do not correctly handle the
439 * case where f_frsize != f_bsize. Eventually we want to
440 * report the value of wtmult in this field.
442 buf->f_frsize = dentry->d_sb->s_blocksize;
445 * On most *nix systems, f_blocks, f_bfree, and f_bavail
446 * are reported in units of f_frsize. Linux hasn't had
447 * an f_frsize field in its statfs struct until recently,
448 * thus historically Linux's sys_statfs reports these
449 * fields in units of f_bsize.
451 buf->f_bsize = dentry->d_sb->s_blocksize;
452 blockbits = dentry->d_sb->s_blocksize_bits;
453 blockres = (1 << blockbits) - 1;
454 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
455 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
456 buf->f_bavail = (res.abytes + blockres) >> blockbits;
458 buf->f_files = res.tfiles;
459 buf->f_ffree = res.afiles;
461 buf->f_namelen = server->namelen;
463 return 0;
465 out_err:
466 dprintk("%s: statfs error = %d\n", __func__, -error);
467 return error;
471 * Map the security flavour number to a name
473 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
475 static const struct {
476 rpc_authflavor_t flavour;
477 const char *str;
478 } sec_flavours[] = {
479 { RPC_AUTH_NULL, "null" },
480 { RPC_AUTH_UNIX, "sys" },
481 { RPC_AUTH_GSS_KRB5, "krb5" },
482 { RPC_AUTH_GSS_KRB5I, "krb5i" },
483 { RPC_AUTH_GSS_KRB5P, "krb5p" },
484 { RPC_AUTH_GSS_LKEY, "lkey" },
485 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
486 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
487 { RPC_AUTH_GSS_SPKM, "spkm" },
488 { RPC_AUTH_GSS_SPKMI, "spkmi" },
489 { RPC_AUTH_GSS_SPKMP, "spkmp" },
490 { UINT_MAX, "unknown" }
492 int i;
494 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
495 if (sec_flavours[i].flavour == flavour)
496 break;
498 return sec_flavours[i].str;
501 static void nfs_show_mountd_netid(struct seq_file *m, struct nfs_server *nfss,
502 int showdefaults)
504 struct sockaddr *sap = (struct sockaddr *) &nfss->mountd_address;
506 seq_printf(m, ",mountproto=");
507 switch (sap->sa_family) {
508 case AF_INET:
509 switch (nfss->mountd_protocol) {
510 case IPPROTO_UDP:
511 seq_printf(m, RPCBIND_NETID_UDP);
512 break;
513 case IPPROTO_TCP:
514 seq_printf(m, RPCBIND_NETID_TCP);
515 break;
516 default:
517 if (showdefaults)
518 seq_printf(m, "auto");
520 break;
521 case AF_INET6:
522 switch (nfss->mountd_protocol) {
523 case IPPROTO_UDP:
524 seq_printf(m, RPCBIND_NETID_UDP6);
525 break;
526 case IPPROTO_TCP:
527 seq_printf(m, RPCBIND_NETID_TCP6);
528 break;
529 default:
530 if (showdefaults)
531 seq_printf(m, "auto");
533 break;
534 default:
535 if (showdefaults)
536 seq_printf(m, "auto");
540 static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
541 int showdefaults)
543 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
545 switch (sap->sa_family) {
546 case AF_INET: {
547 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
548 seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
549 break;
551 case AF_INET6: {
552 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
553 seq_printf(m, ",mountaddr=%pI6c", &sin6->sin6_addr);
554 break;
556 default:
557 if (showdefaults)
558 seq_printf(m, ",mountaddr=unspecified");
561 if (nfss->mountd_version || showdefaults)
562 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
563 if (nfss->mountd_port || showdefaults)
564 seq_printf(m, ",mountport=%u", nfss->mountd_port);
566 nfs_show_mountd_netid(m, nfss, showdefaults);
570 * Describe the mount options in force on this server representation
572 static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
573 int showdefaults)
575 static const struct proc_nfs_info {
576 int flag;
577 const char *str;
578 const char *nostr;
579 } nfs_info[] = {
580 { NFS_MOUNT_SOFT, ",soft", ",hard" },
581 { NFS_MOUNT_POSIX, ",posix", "" },
582 { NFS_MOUNT_NOCTO, ",nocto", "" },
583 { NFS_MOUNT_NOAC, ",noac", "" },
584 { NFS_MOUNT_NONLM, ",nolock", "" },
585 { NFS_MOUNT_NOACL, ",noacl", "" },
586 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
587 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
588 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
589 { 0, NULL, NULL }
591 const struct proc_nfs_info *nfs_infop;
592 struct nfs_client *clp = nfss->nfs_client;
593 u32 version = clp->rpc_ops->version;
595 seq_printf(m, ",vers=%u", version);
596 seq_printf(m, ",rsize=%u", nfss->rsize);
597 seq_printf(m, ",wsize=%u", nfss->wsize);
598 if (nfss->bsize != 0)
599 seq_printf(m, ",bsize=%u", nfss->bsize);
600 seq_printf(m, ",namlen=%u", nfss->namelen);
601 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
602 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
603 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
604 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
605 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
606 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
607 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
608 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
609 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
610 if (nfss->flags & nfs_infop->flag)
611 seq_puts(m, nfs_infop->str);
612 else
613 seq_puts(m, nfs_infop->nostr);
615 seq_printf(m, ",proto=%s",
616 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
617 if (version == 4) {
618 if (nfss->port != NFS_PORT)
619 seq_printf(m, ",port=%u", nfss->port);
620 } else
621 if (nfss->port)
622 seq_printf(m, ",port=%u", nfss->port);
624 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
625 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
626 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
628 if (version != 4)
629 nfs_show_mountd_options(m, nfss, showdefaults);
631 #ifdef CONFIG_NFS_V4
632 if (clp->rpc_ops->version == 4)
633 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
634 #endif
635 if (nfss->options & NFS_OPTION_FSCACHE)
636 seq_printf(m, ",fsc");
640 * Describe the mount options on this VFS mountpoint
642 static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
644 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
646 nfs_show_mount_options(m, nfss, 0);
648 seq_printf(m, ",addr=%s",
649 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
650 RPC_DISPLAY_ADDR));
652 return 0;
656 * Present statistical information for this VFS mountpoint
658 static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
660 int i, cpu;
661 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
662 struct rpc_auth *auth = nfss->client->cl_auth;
663 struct nfs_iostats totals = { };
665 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
668 * Display all mount option settings
670 seq_printf(m, "\n\topts:\t");
671 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
672 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
673 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
674 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
675 nfs_show_mount_options(m, nfss, 1);
677 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
679 seq_printf(m, "\n\tcaps:\t");
680 seq_printf(m, "caps=0x%x", nfss->caps);
681 seq_printf(m, ",wtmult=%u", nfss->wtmult);
682 seq_printf(m, ",dtsize=%u", nfss->dtsize);
683 seq_printf(m, ",bsize=%u", nfss->bsize);
684 seq_printf(m, ",namlen=%u", nfss->namelen);
686 #ifdef CONFIG_NFS_V4
687 if (nfss->nfs_client->rpc_ops->version == 4) {
688 seq_printf(m, "\n\tnfsv4:\t");
689 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
690 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
691 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
693 #endif
696 * Display security flavor in effect for this mount
698 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
699 if (auth->au_flavor)
700 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
703 * Display superblock I/O counters
705 for_each_possible_cpu(cpu) {
706 struct nfs_iostats *stats;
708 preempt_disable();
709 stats = per_cpu_ptr(nfss->io_stats, cpu);
711 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
712 totals.events[i] += stats->events[i];
713 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
714 totals.bytes[i] += stats->bytes[i];
715 #ifdef CONFIG_NFS_FSCACHE
716 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
717 totals.fscache[i] += stats->fscache[i];
718 #endif
720 preempt_enable();
723 seq_printf(m, "\n\tevents:\t");
724 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
725 seq_printf(m, "%lu ", totals.events[i]);
726 seq_printf(m, "\n\tbytes:\t");
727 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
728 seq_printf(m, "%Lu ", totals.bytes[i]);
729 #ifdef CONFIG_NFS_FSCACHE
730 if (nfss->options & NFS_OPTION_FSCACHE) {
731 seq_printf(m, "\n\tfsc:\t");
732 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
733 seq_printf(m, "%Lu ", totals.bytes[i]);
735 #endif
736 seq_printf(m, "\n");
738 rpc_print_iostats(m, nfss->client);
740 return 0;
744 * Begin unmount by attempting to remove all automounted mountpoints we added
745 * in response to xdev traversals and referrals
747 static void nfs_umount_begin(struct super_block *sb)
749 struct nfs_server *server;
750 struct rpc_clnt *rpc;
752 server = NFS_SB(sb);
753 /* -EIO all pending I/O */
754 rpc = server->client_acl;
755 if (!IS_ERR(rpc))
756 rpc_killall_tasks(rpc);
757 rpc = server->client;
758 if (!IS_ERR(rpc))
759 rpc_killall_tasks(rpc);
762 static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(unsigned int version)
764 struct nfs_parsed_mount_data *data;
766 data = kzalloc(sizeof(*data), GFP_KERNEL);
767 if (data) {
768 data->acregmin = NFS_DEF_ACREGMIN;
769 data->acregmax = NFS_DEF_ACREGMAX;
770 data->acdirmin = NFS_DEF_ACDIRMIN;
771 data->acdirmax = NFS_DEF_ACDIRMAX;
772 data->mount_server.port = NFS_UNSPEC_PORT;
773 data->nfs_server.port = NFS_UNSPEC_PORT;
774 data->nfs_server.protocol = XPRT_TRANSPORT_TCP;
775 data->auth_flavors[0] = RPC_AUTH_UNIX;
776 data->auth_flavor_len = 1;
777 data->version = version;
778 data->minorversion = 0;
780 return data;
784 * Sanity-check a server address provided by the mount command.
786 * Address family must be initialized, and address must not be
787 * the ANY address for that family.
789 static int nfs_verify_server_address(struct sockaddr *addr)
791 switch (addr->sa_family) {
792 case AF_INET: {
793 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
794 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
796 case AF_INET6: {
797 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
798 return !ipv6_addr_any(sa);
802 dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
803 return 0;
807 * Select between a default port value and a user-specified port value.
808 * If a zero value is set, then autobind will be used.
810 static void nfs_set_port(struct sockaddr *sap, int *port,
811 const unsigned short default_port)
813 if (*port == NFS_UNSPEC_PORT)
814 *port = default_port;
816 rpc_set_port(sap, *port);
820 * Sanity check the NFS transport protocol.
823 static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
825 switch (mnt->nfs_server.protocol) {
826 case XPRT_TRANSPORT_UDP:
827 case XPRT_TRANSPORT_TCP:
828 case XPRT_TRANSPORT_RDMA:
829 break;
830 default:
831 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
836 * For text based NFSv2/v3 mounts, the mount protocol transport default
837 * settings should depend upon the specified NFS transport.
839 static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
841 nfs_validate_transport_protocol(mnt);
843 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
844 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
845 return;
846 switch (mnt->nfs_server.protocol) {
847 case XPRT_TRANSPORT_UDP:
848 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
849 break;
850 case XPRT_TRANSPORT_TCP:
851 case XPRT_TRANSPORT_RDMA:
852 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
857 * Parse the value of the 'sec=' option.
859 static int nfs_parse_security_flavors(char *value,
860 struct nfs_parsed_mount_data *mnt)
862 substring_t args[MAX_OPT_ARGS];
864 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
866 switch (match_token(value, nfs_secflavor_tokens, args)) {
867 case Opt_sec_none:
868 mnt->auth_flavors[0] = RPC_AUTH_NULL;
869 break;
870 case Opt_sec_sys:
871 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
872 break;
873 case Opt_sec_krb5:
874 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
875 break;
876 case Opt_sec_krb5i:
877 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
878 break;
879 case Opt_sec_krb5p:
880 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
881 break;
882 case Opt_sec_lkey:
883 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
884 break;
885 case Opt_sec_lkeyi:
886 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
887 break;
888 case Opt_sec_lkeyp:
889 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
890 break;
891 case Opt_sec_spkm:
892 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
893 break;
894 case Opt_sec_spkmi:
895 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
896 break;
897 case Opt_sec_spkmp:
898 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
899 break;
900 default:
901 return 0;
904 mnt->auth_flavor_len = 1;
905 return 1;
909 * Error-check and convert a string of mount options from user space into
910 * a data structure. The whole mount string is processed; bad options are
911 * skipped as they are encountered. If there were no errors, return 1;
912 * otherwise return 0 (zero).
914 static int nfs_parse_mount_options(char *raw,
915 struct nfs_parsed_mount_data *mnt)
917 char *p, *string, *secdata;
918 int rc, sloppy = 0, invalid_option = 0;
919 unsigned short protofamily = AF_UNSPEC;
920 unsigned short mountfamily = AF_UNSPEC;
922 if (!raw) {
923 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
924 return 1;
926 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
928 secdata = alloc_secdata();
929 if (!secdata)
930 goto out_nomem;
932 rc = security_sb_copy_data(raw, secdata);
933 if (rc)
934 goto out_security_failure;
936 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
937 if (rc)
938 goto out_security_failure;
940 free_secdata(secdata);
942 while ((p = strsep(&raw, ",")) != NULL) {
943 substring_t args[MAX_OPT_ARGS];
944 unsigned long option;
945 int token;
947 if (!*p)
948 continue;
950 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
952 token = match_token(p, nfs_mount_option_tokens, args);
953 switch (token) {
956 * boolean options: foo/nofoo
958 case Opt_soft:
959 mnt->flags |= NFS_MOUNT_SOFT;
960 break;
961 case Opt_hard:
962 mnt->flags &= ~NFS_MOUNT_SOFT;
963 break;
964 case Opt_posix:
965 mnt->flags |= NFS_MOUNT_POSIX;
966 break;
967 case Opt_noposix:
968 mnt->flags &= ~NFS_MOUNT_POSIX;
969 break;
970 case Opt_cto:
971 mnt->flags &= ~NFS_MOUNT_NOCTO;
972 break;
973 case Opt_nocto:
974 mnt->flags |= NFS_MOUNT_NOCTO;
975 break;
976 case Opt_ac:
977 mnt->flags &= ~NFS_MOUNT_NOAC;
978 break;
979 case Opt_noac:
980 mnt->flags |= NFS_MOUNT_NOAC;
981 break;
982 case Opt_lock:
983 mnt->flags &= ~NFS_MOUNT_NONLM;
984 break;
985 case Opt_nolock:
986 mnt->flags |= NFS_MOUNT_NONLM;
987 break;
988 case Opt_v2:
989 mnt->flags &= ~NFS_MOUNT_VER3;
990 mnt->version = 2;
991 break;
992 case Opt_v3:
993 mnt->flags |= NFS_MOUNT_VER3;
994 mnt->version = 3;
995 break;
996 #ifdef CONFIG_NFS_V4
997 case Opt_v4:
998 mnt->flags &= ~NFS_MOUNT_VER3;
999 mnt->version = 4;
1000 break;
1001 #endif
1002 case Opt_udp:
1003 mnt->flags &= ~NFS_MOUNT_TCP;
1004 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1005 break;
1006 case Opt_tcp:
1007 mnt->flags |= NFS_MOUNT_TCP;
1008 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1009 break;
1010 case Opt_rdma:
1011 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1012 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1013 xprt_load_transport(p);
1014 break;
1015 case Opt_acl:
1016 mnt->flags &= ~NFS_MOUNT_NOACL;
1017 break;
1018 case Opt_noacl:
1019 mnt->flags |= NFS_MOUNT_NOACL;
1020 break;
1021 case Opt_rdirplus:
1022 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1023 break;
1024 case Opt_nordirplus:
1025 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1026 break;
1027 case Opt_sharecache:
1028 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1029 break;
1030 case Opt_nosharecache:
1031 mnt->flags |= NFS_MOUNT_UNSHARED;
1032 break;
1033 case Opt_resvport:
1034 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1035 break;
1036 case Opt_noresvport:
1037 mnt->flags |= NFS_MOUNT_NORESVPORT;
1038 break;
1039 case Opt_fscache:
1040 mnt->options |= NFS_OPTION_FSCACHE;
1041 kfree(mnt->fscache_uniq);
1042 mnt->fscache_uniq = NULL;
1043 break;
1044 case Opt_nofscache:
1045 mnt->options &= ~NFS_OPTION_FSCACHE;
1046 kfree(mnt->fscache_uniq);
1047 mnt->fscache_uniq = NULL;
1048 break;
1049 case Opt_fscache_uniq:
1050 string = match_strdup(args);
1051 if (!string)
1052 goto out_nomem;
1053 kfree(mnt->fscache_uniq);
1054 mnt->fscache_uniq = string;
1055 mnt->options |= NFS_OPTION_FSCACHE;
1056 break;
1059 * options that take numeric values
1061 case Opt_port:
1062 string = match_strdup(args);
1063 if (string == NULL)
1064 goto out_nomem;
1065 rc = strict_strtoul(string, 10, &option);
1066 kfree(string);
1067 if (rc != 0 || option > USHORT_MAX)
1068 goto out_invalid_value;
1069 mnt->nfs_server.port = option;
1070 break;
1071 case Opt_rsize:
1072 string = match_strdup(args);
1073 if (string == NULL)
1074 goto out_nomem;
1075 rc = strict_strtoul(string, 10, &option);
1076 kfree(string);
1077 if (rc != 0)
1078 goto out_invalid_value;
1079 mnt->rsize = option;
1080 break;
1081 case Opt_wsize:
1082 string = match_strdup(args);
1083 if (string == NULL)
1084 goto out_nomem;
1085 rc = strict_strtoul(string, 10, &option);
1086 kfree(string);
1087 if (rc != 0)
1088 goto out_invalid_value;
1089 mnt->wsize = option;
1090 break;
1091 case Opt_bsize:
1092 string = match_strdup(args);
1093 if (string == NULL)
1094 goto out_nomem;
1095 rc = strict_strtoul(string, 10, &option);
1096 kfree(string);
1097 if (rc != 0)
1098 goto out_invalid_value;
1099 mnt->bsize = option;
1100 break;
1101 case Opt_timeo:
1102 string = match_strdup(args);
1103 if (string == NULL)
1104 goto out_nomem;
1105 rc = strict_strtoul(string, 10, &option);
1106 kfree(string);
1107 if (rc != 0 || option == 0)
1108 goto out_invalid_value;
1109 mnt->timeo = option;
1110 break;
1111 case Opt_retrans:
1112 string = match_strdup(args);
1113 if (string == NULL)
1114 goto out_nomem;
1115 rc = strict_strtoul(string, 10, &option);
1116 kfree(string);
1117 if (rc != 0 || option == 0)
1118 goto out_invalid_value;
1119 mnt->retrans = option;
1120 break;
1121 case Opt_acregmin:
1122 string = match_strdup(args);
1123 if (string == NULL)
1124 goto out_nomem;
1125 rc = strict_strtoul(string, 10, &option);
1126 kfree(string);
1127 if (rc != 0)
1128 goto out_invalid_value;
1129 mnt->acregmin = option;
1130 break;
1131 case Opt_acregmax:
1132 string = match_strdup(args);
1133 if (string == NULL)
1134 goto out_nomem;
1135 rc = strict_strtoul(string, 10, &option);
1136 kfree(string);
1137 if (rc != 0)
1138 goto out_invalid_value;
1139 mnt->acregmax = option;
1140 break;
1141 case Opt_acdirmin:
1142 string = match_strdup(args);
1143 if (string == NULL)
1144 goto out_nomem;
1145 rc = strict_strtoul(string, 10, &option);
1146 kfree(string);
1147 if (rc != 0)
1148 goto out_invalid_value;
1149 mnt->acdirmin = option;
1150 break;
1151 case Opt_acdirmax:
1152 string = match_strdup(args);
1153 if (string == NULL)
1154 goto out_nomem;
1155 rc = strict_strtoul(string, 10, &option);
1156 kfree(string);
1157 if (rc != 0)
1158 goto out_invalid_value;
1159 mnt->acdirmax = option;
1160 break;
1161 case Opt_actimeo:
1162 string = match_strdup(args);
1163 if (string == NULL)
1164 goto out_nomem;
1165 rc = strict_strtoul(string, 10, &option);
1166 kfree(string);
1167 if (rc != 0)
1168 goto out_invalid_value;
1169 mnt->acregmin = mnt->acregmax =
1170 mnt->acdirmin = mnt->acdirmax = option;
1171 break;
1172 case Opt_namelen:
1173 string = match_strdup(args);
1174 if (string == NULL)
1175 goto out_nomem;
1176 rc = strict_strtoul(string, 10, &option);
1177 kfree(string);
1178 if (rc != 0)
1179 goto out_invalid_value;
1180 mnt->namlen = option;
1181 break;
1182 case Opt_mountport:
1183 string = match_strdup(args);
1184 if (string == NULL)
1185 goto out_nomem;
1186 rc = strict_strtoul(string, 10, &option);
1187 kfree(string);
1188 if (rc != 0 || option > USHORT_MAX)
1189 goto out_invalid_value;
1190 mnt->mount_server.port = option;
1191 break;
1192 case Opt_mountvers:
1193 string = match_strdup(args);
1194 if (string == NULL)
1195 goto out_nomem;
1196 rc = strict_strtoul(string, 10, &option);
1197 kfree(string);
1198 if (rc != 0 ||
1199 option < NFS_MNT_VERSION ||
1200 option > NFS_MNT3_VERSION)
1201 goto out_invalid_value;
1202 mnt->mount_server.version = option;
1203 break;
1204 case Opt_nfsvers:
1205 string = match_strdup(args);
1206 if (string == NULL)
1207 goto out_nomem;
1208 rc = strict_strtoul(string, 10, &option);
1209 kfree(string);
1210 if (rc != 0)
1211 goto out_invalid_value;
1212 switch (option) {
1213 case NFS2_VERSION:
1214 mnt->flags &= ~NFS_MOUNT_VER3;
1215 mnt->version = 2;
1216 break;
1217 case NFS3_VERSION:
1218 mnt->flags |= NFS_MOUNT_VER3;
1219 mnt->version = 3;
1220 break;
1221 #ifdef CONFIG_NFS_V4
1222 case NFS4_VERSION:
1223 mnt->flags &= ~NFS_MOUNT_VER3;
1224 mnt->version = 4;
1225 break;
1226 #endif
1227 default:
1228 goto out_invalid_value;
1230 break;
1231 case Opt_minorversion:
1232 string = match_strdup(args);
1233 if (string == NULL)
1234 goto out_nomem;
1235 rc = strict_strtoul(string, 10, &option);
1236 kfree(string);
1237 if (rc != 0)
1238 goto out_invalid_value;
1239 if (option > NFS4_MAX_MINOR_VERSION)
1240 goto out_invalid_value;
1241 mnt->minorversion = option;
1242 break;
1245 * options that take text values
1247 case Opt_sec:
1248 string = match_strdup(args);
1249 if (string == NULL)
1250 goto out_nomem;
1251 rc = nfs_parse_security_flavors(string, mnt);
1252 kfree(string);
1253 if (!rc) {
1254 dfprintk(MOUNT, "NFS: unrecognized "
1255 "security flavor\n");
1256 return 0;
1258 break;
1259 case Opt_proto:
1260 string = match_strdup(args);
1261 if (string == NULL)
1262 goto out_nomem;
1263 token = match_token(string,
1264 nfs_xprt_protocol_tokens, args);
1266 protofamily = AF_INET;
1267 switch (token) {
1268 case Opt_xprt_udp6:
1269 protofamily = AF_INET6;
1270 case Opt_xprt_udp:
1271 mnt->flags &= ~NFS_MOUNT_TCP;
1272 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1273 kfree(string);
1274 break;
1275 case Opt_xprt_tcp6:
1276 protofamily = AF_INET6;
1277 case Opt_xprt_tcp:
1278 mnt->flags |= NFS_MOUNT_TCP;
1279 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1280 kfree(string);
1281 break;
1282 case Opt_xprt_rdma:
1283 /* vector side protocols to TCP */
1284 mnt->flags |= NFS_MOUNT_TCP;
1285 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1286 xprt_load_transport(string);
1287 kfree(string);
1288 break;
1289 default:
1290 dfprintk(MOUNT, "NFS: unrecognized "
1291 "transport protocol\n");
1292 kfree(string);
1293 return 0;
1295 break;
1296 case Opt_mountproto:
1297 string = match_strdup(args);
1298 if (string == NULL)
1299 goto out_nomem;
1300 token = match_token(string,
1301 nfs_xprt_protocol_tokens, args);
1302 kfree(string);
1304 mountfamily = AF_INET;
1305 switch (token) {
1306 case Opt_xprt_udp6:
1307 mountfamily = AF_INET6;
1308 case Opt_xprt_udp:
1309 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
1310 break;
1311 case Opt_xprt_tcp6:
1312 mountfamily = AF_INET6;
1313 case Opt_xprt_tcp:
1314 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
1315 break;
1316 case Opt_xprt_rdma: /* not used for side protocols */
1317 default:
1318 dfprintk(MOUNT, "NFS: unrecognized "
1319 "transport protocol\n");
1320 return 0;
1322 break;
1323 case Opt_addr:
1324 string = match_strdup(args);
1325 if (string == NULL)
1326 goto out_nomem;
1327 mnt->nfs_server.addrlen =
1328 rpc_pton(string, strlen(string),
1329 (struct sockaddr *)
1330 &mnt->nfs_server.address,
1331 sizeof(mnt->nfs_server.address));
1332 kfree(string);
1333 if (mnt->nfs_server.addrlen == 0)
1334 goto out_invalid_address;
1335 break;
1336 case Opt_clientaddr:
1337 string = match_strdup(args);
1338 if (string == NULL)
1339 goto out_nomem;
1340 kfree(mnt->client_address);
1341 mnt->client_address = string;
1342 break;
1343 case Opt_mounthost:
1344 string = match_strdup(args);
1345 if (string == NULL)
1346 goto out_nomem;
1347 kfree(mnt->mount_server.hostname);
1348 mnt->mount_server.hostname = string;
1349 break;
1350 case Opt_mountaddr:
1351 string = match_strdup(args);
1352 if (string == NULL)
1353 goto out_nomem;
1354 mnt->mount_server.addrlen =
1355 rpc_pton(string, strlen(string),
1356 (struct sockaddr *)
1357 &mnt->mount_server.address,
1358 sizeof(mnt->mount_server.address));
1359 kfree(string);
1360 if (mnt->mount_server.addrlen == 0)
1361 goto out_invalid_address;
1362 break;
1363 case Opt_lookupcache:
1364 string = match_strdup(args);
1365 if (string == NULL)
1366 goto out_nomem;
1367 token = match_token(string,
1368 nfs_lookupcache_tokens, args);
1369 kfree(string);
1370 switch (token) {
1371 case Opt_lookupcache_all:
1372 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1373 break;
1374 case Opt_lookupcache_positive:
1375 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1376 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1377 break;
1378 case Opt_lookupcache_none:
1379 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1380 break;
1381 default:
1382 dfprintk(MOUNT, "NFS: invalid "
1383 "lookupcache argument\n");
1384 return 0;
1386 break;
1389 * Special options
1391 case Opt_sloppy:
1392 sloppy = 1;
1393 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1394 break;
1395 case Opt_userspace:
1396 case Opt_deprecated:
1397 dfprintk(MOUNT, "NFS: ignoring mount option "
1398 "'%s'\n", p);
1399 break;
1401 default:
1402 invalid_option = 1;
1403 dfprintk(MOUNT, "NFS: unrecognized mount option "
1404 "'%s'\n", p);
1408 if (!sloppy && invalid_option)
1409 return 0;
1412 * verify that any proto=/mountproto= options match the address
1413 * familiies in the addr=/mountaddr= options.
1415 if (protofamily != AF_UNSPEC &&
1416 protofamily != mnt->nfs_server.address.ss_family)
1417 goto out_proto_mismatch;
1419 if (mountfamily != AF_UNSPEC) {
1420 if (mnt->mount_server.addrlen) {
1421 if (mountfamily != mnt->mount_server.address.ss_family)
1422 goto out_mountproto_mismatch;
1423 } else {
1424 if (mountfamily != mnt->nfs_server.address.ss_family)
1425 goto out_mountproto_mismatch;
1429 return 1;
1431 out_mountproto_mismatch:
1432 printk(KERN_INFO "NFS: mount server address does not match mountproto= "
1433 "option\n");
1434 return 0;
1435 out_proto_mismatch:
1436 printk(KERN_INFO "NFS: server address does not match proto= option\n");
1437 return 0;
1438 out_invalid_address:
1439 printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
1440 return 0;
1441 out_invalid_value:
1442 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
1443 return 0;
1444 out_nomem:
1445 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1446 return 0;
1447 out_security_failure:
1448 free_secdata(secdata);
1449 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1450 return 0;
1454 * Match the requested auth flavors with the list returned by
1455 * the server. Returns zero and sets the mount's authentication
1456 * flavor on success; returns -EACCES if server does not support
1457 * the requested flavor.
1459 static int nfs_walk_authlist(struct nfs_parsed_mount_data *args,
1460 struct nfs_mount_request *request)
1462 unsigned int i, j, server_authlist_len = *(request->auth_flav_len);
1465 * Certain releases of Linux's mountd return an empty
1466 * flavor list. To prevent behavioral regression with
1467 * these servers (ie. rejecting mounts that used to
1468 * succeed), revert to pre-2.6.32 behavior (no checking)
1469 * if the returned flavor list is empty.
1471 if (server_authlist_len == 0)
1472 return 0;
1475 * We avoid sophisticated negotiating here, as there are
1476 * plenty of cases where we can get it wrong, providing
1477 * either too little or too much security.
1479 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1480 * flavor listed first. However, some servers list
1481 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1482 * preferred default, in args->auth_flavors[0] if user
1483 * didn't specify sec= mount option.
1485 for (i = 0; i < args->auth_flavor_len; i++)
1486 for (j = 0; j < server_authlist_len; j++)
1487 if (args->auth_flavors[i] == request->auth_flavs[j]) {
1488 dfprintk(MOUNT, "NFS: using auth flavor %d\n",
1489 request->auth_flavs[j]);
1490 args->auth_flavors[0] = request->auth_flavs[j];
1491 return 0;
1494 dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n");
1495 nfs_umount(request);
1496 return -EACCES;
1500 * Use the remote server's MOUNT service to request the NFS file handle
1501 * corresponding to the provided path.
1503 static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1504 struct nfs_fh *root_fh)
1506 rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS];
1507 unsigned int server_authlist_len = ARRAY_SIZE(server_authlist);
1508 struct nfs_mount_request request = {
1509 .sap = (struct sockaddr *)
1510 &args->mount_server.address,
1511 .dirpath = args->nfs_server.export_path,
1512 .protocol = args->mount_server.protocol,
1513 .fh = root_fh,
1514 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
1515 .auth_flav_len = &server_authlist_len,
1516 .auth_flavs = server_authlist,
1518 int status;
1520 if (args->mount_server.version == 0) {
1521 switch (args->version) {
1522 default:
1523 args->mount_server.version = NFS_MNT3_VERSION;
1524 break;
1525 case 2:
1526 args->mount_server.version = NFS_MNT_VERSION;
1529 request.version = args->mount_server.version;
1531 if (args->mount_server.hostname)
1532 request.hostname = args->mount_server.hostname;
1533 else
1534 request.hostname = args->nfs_server.hostname;
1537 * Construct the mount server's address.
1539 if (args->mount_server.address.ss_family == AF_UNSPEC) {
1540 memcpy(request.sap, &args->nfs_server.address,
1541 args->nfs_server.addrlen);
1542 args->mount_server.addrlen = args->nfs_server.addrlen;
1544 request.salen = args->mount_server.addrlen;
1545 nfs_set_port(request.sap, &args->mount_server.port, 0);
1548 * Now ask the mount server to map our export path
1549 * to a file handle.
1551 status = nfs_mount(&request);
1552 if (status != 0) {
1553 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1554 request.hostname, status);
1555 return status;
1559 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1561 if (args->mount_server.version != NFS_MNT3_VERSION)
1562 return 0;
1563 return nfs_walk_authlist(args, &request);
1566 static int nfs_parse_simple_hostname(const char *dev_name,
1567 char **hostname, size_t maxnamlen,
1568 char **export_path, size_t maxpathlen)
1570 size_t len;
1571 char *colon, *comma;
1573 colon = strchr(dev_name, ':');
1574 if (colon == NULL)
1575 goto out_bad_devname;
1577 len = colon - dev_name;
1578 if (len > maxnamlen)
1579 goto out_hostname;
1581 /* N.B. caller will free nfs_server.hostname in all cases */
1582 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
1583 if (!*hostname)
1584 goto out_nomem;
1586 /* kill possible hostname list: not supported */
1587 comma = strchr(*hostname, ',');
1588 if (comma != NULL) {
1589 if (comma == *hostname)
1590 goto out_bad_devname;
1591 *comma = '\0';
1594 colon++;
1595 len = strlen(colon);
1596 if (len > maxpathlen)
1597 goto out_path;
1598 *export_path = kstrndup(colon, len, GFP_KERNEL);
1599 if (!*export_path)
1600 goto out_nomem;
1602 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1603 return 0;
1605 out_bad_devname:
1606 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1607 return -EINVAL;
1609 out_nomem:
1610 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1611 return -ENOMEM;
1613 out_hostname:
1614 dfprintk(MOUNT, "NFS: server hostname too long\n");
1615 return -ENAMETOOLONG;
1617 out_path:
1618 dfprintk(MOUNT, "NFS: export pathname too long\n");
1619 return -ENAMETOOLONG;
1623 * Hostname has square brackets around it because it contains one or
1624 * more colons. We look for the first closing square bracket, and a
1625 * colon must follow it.
1627 static int nfs_parse_protected_hostname(const char *dev_name,
1628 char **hostname, size_t maxnamlen,
1629 char **export_path, size_t maxpathlen)
1631 size_t len;
1632 char *start, *end;
1634 start = (char *)(dev_name + 1);
1636 end = strchr(start, ']');
1637 if (end == NULL)
1638 goto out_bad_devname;
1639 if (*(end + 1) != ':')
1640 goto out_bad_devname;
1642 len = end - start;
1643 if (len > maxnamlen)
1644 goto out_hostname;
1646 /* N.B. caller will free nfs_server.hostname in all cases */
1647 *hostname = kstrndup(start, len, GFP_KERNEL);
1648 if (*hostname == NULL)
1649 goto out_nomem;
1651 end += 2;
1652 len = strlen(end);
1653 if (len > maxpathlen)
1654 goto out_path;
1655 *export_path = kstrndup(end, len, GFP_KERNEL);
1656 if (!*export_path)
1657 goto out_nomem;
1659 return 0;
1661 out_bad_devname:
1662 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1663 return -EINVAL;
1665 out_nomem:
1666 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1667 return -ENOMEM;
1669 out_hostname:
1670 dfprintk(MOUNT, "NFS: server hostname too long\n");
1671 return -ENAMETOOLONG;
1673 out_path:
1674 dfprintk(MOUNT, "NFS: export pathname too long\n");
1675 return -ENAMETOOLONG;
1679 * Split "dev_name" into "hostname:export_path".
1681 * The leftmost colon demarks the split between the server's hostname
1682 * and the export path. If the hostname starts with a left square
1683 * bracket, then it may contain colons.
1685 * Note: caller frees hostname and export path, even on error.
1687 static int nfs_parse_devname(const char *dev_name,
1688 char **hostname, size_t maxnamlen,
1689 char **export_path, size_t maxpathlen)
1691 if (*dev_name == '[')
1692 return nfs_parse_protected_hostname(dev_name,
1693 hostname, maxnamlen,
1694 export_path, maxpathlen);
1696 return nfs_parse_simple_hostname(dev_name,
1697 hostname, maxnamlen,
1698 export_path, maxpathlen);
1702 * Validate the NFS2/NFS3 mount data
1703 * - fills in the mount root filehandle
1705 * For option strings, user space handles the following behaviors:
1707 * + DNS: mapping server host name to IP address ("addr=" option)
1709 * + failure mode: how to behave if a mount request can't be handled
1710 * immediately ("fg/bg" option)
1712 * + retry: how often to retry a mount request ("retry=" option)
1714 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1715 * mountproto=tcp after mountproto=udp, and so on
1717 static int nfs_validate_mount_data(void *options,
1718 struct nfs_parsed_mount_data *args,
1719 struct nfs_fh *mntfh,
1720 const char *dev_name)
1722 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
1723 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
1725 if (data == NULL)
1726 goto out_no_data;
1728 switch (data->version) {
1729 case 1:
1730 data->namlen = 0;
1731 case 2:
1732 data->bsize = 0;
1733 case 3:
1734 if (data->flags & NFS_MOUNT_VER3)
1735 goto out_no_v3;
1736 data->root.size = NFS2_FHSIZE;
1737 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1738 case 4:
1739 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1740 goto out_no_sec;
1741 case 5:
1742 memset(data->context, 0, sizeof(data->context));
1743 case 6:
1744 if (data->flags & NFS_MOUNT_VER3) {
1745 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1746 goto out_invalid_fh;
1747 mntfh->size = data->root.size;
1748 args->version = 3;
1749 } else {
1750 mntfh->size = NFS2_FHSIZE;
1751 args->version = 2;
1755 memcpy(mntfh->data, data->root.data, mntfh->size);
1756 if (mntfh->size < sizeof(mntfh->data))
1757 memset(mntfh->data + mntfh->size, 0,
1758 sizeof(mntfh->data) - mntfh->size);
1761 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1762 * can deal with.
1764 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
1765 args->rsize = data->rsize;
1766 args->wsize = data->wsize;
1767 args->timeo = data->timeo;
1768 args->retrans = data->retrans;
1769 args->acregmin = data->acregmin;
1770 args->acregmax = data->acregmax;
1771 args->acdirmin = data->acdirmin;
1772 args->acdirmax = data->acdirmax;
1774 memcpy(sap, &data->addr, sizeof(data->addr));
1775 args->nfs_server.addrlen = sizeof(data->addr);
1776 if (!nfs_verify_server_address(sap))
1777 goto out_no_address;
1779 if (!(data->flags & NFS_MOUNT_TCP))
1780 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1781 /* N.B. caller will free nfs_server.hostname in all cases */
1782 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1783 args->namlen = data->namlen;
1784 args->bsize = data->bsize;
1786 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1787 args->auth_flavors[0] = data->pseudoflavor;
1788 if (!args->nfs_server.hostname)
1789 goto out_nomem;
1792 * The legacy version 6 binary mount data from userspace has a
1793 * field used only to transport selinux information into the
1794 * the kernel. To continue to support that functionality we
1795 * have a touch of selinux knowledge here in the NFS code. The
1796 * userspace code converted context=blah to just blah so we are
1797 * converting back to the full string selinux understands.
1799 if (data->context[0]){
1800 #ifdef CONFIG_SECURITY_SELINUX
1801 int rc;
1802 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1803 if (!opts_str)
1804 return -ENOMEM;
1805 strcpy(opts_str, "context=");
1806 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1807 strcat(opts_str, &data->context[0]);
1808 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1809 kfree(opts_str);
1810 if (rc)
1811 return rc;
1812 #else
1813 return -EINVAL;
1814 #endif
1817 break;
1818 default: {
1819 int status;
1821 if (nfs_parse_mount_options((char *)options, args) == 0)
1822 return -EINVAL;
1824 if (!nfs_verify_server_address(sap))
1825 goto out_no_address;
1827 if (args->version == 4)
1828 #ifdef CONFIG_NFS_V4
1829 return nfs4_validate_text_mount_data(options,
1830 args, dev_name);
1831 #else
1832 goto out_v4_not_compiled;
1833 #endif
1835 nfs_set_port(sap, &args->nfs_server.port, 0);
1837 nfs_set_mount_transport_protocol(args);
1839 status = nfs_parse_devname(dev_name,
1840 &args->nfs_server.hostname,
1841 PAGE_SIZE,
1842 &args->nfs_server.export_path,
1843 NFS_MAXPATHLEN);
1844 if (!status)
1845 status = nfs_try_mount(args, mntfh);
1847 kfree(args->nfs_server.export_path);
1848 args->nfs_server.export_path = NULL;
1850 if (status)
1851 return status;
1853 break;
1857 #ifndef CONFIG_NFS_V3
1858 if (args->version == 3)
1859 goto out_v3_not_compiled;
1860 #endif /* !CONFIG_NFS_V3 */
1862 return 0;
1864 out_no_data:
1865 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1866 return -EINVAL;
1868 out_no_v3:
1869 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1870 data->version);
1871 return -EINVAL;
1873 out_no_sec:
1874 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1875 return -EINVAL;
1877 #ifndef CONFIG_NFS_V3
1878 out_v3_not_compiled:
1879 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1880 return -EPROTONOSUPPORT;
1881 #endif /* !CONFIG_NFS_V3 */
1883 #ifndef CONFIG_NFS_V4
1884 out_v4_not_compiled:
1885 dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n");
1886 return -EPROTONOSUPPORT;
1887 #endif /* !CONFIG_NFS_V4 */
1889 out_nomem:
1890 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
1891 return -ENOMEM;
1893 out_no_address:
1894 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1895 return -EINVAL;
1897 out_invalid_fh:
1898 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1899 return -EINVAL;
1902 static int
1903 nfs_compare_remount_data(struct nfs_server *nfss,
1904 struct nfs_parsed_mount_data *data)
1906 if (data->flags != nfss->flags ||
1907 data->rsize != nfss->rsize ||
1908 data->wsize != nfss->wsize ||
1909 data->retrans != nfss->client->cl_timeout->to_retries ||
1910 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
1911 data->acregmin != nfss->acregmin / HZ ||
1912 data->acregmax != nfss->acregmax / HZ ||
1913 data->acdirmin != nfss->acdirmin / HZ ||
1914 data->acdirmax != nfss->acdirmax / HZ ||
1915 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
1916 data->nfs_server.port != nfss->port ||
1917 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
1918 !rpc_cmp_addr((struct sockaddr *)&data->nfs_server.address,
1919 (struct sockaddr *)&nfss->nfs_client->cl_addr))
1920 return -EINVAL;
1922 return 0;
1925 static int
1926 nfs_remount(struct super_block *sb, int *flags, char *raw_data)
1928 int error;
1929 struct nfs_server *nfss = sb->s_fs_info;
1930 struct nfs_parsed_mount_data *data;
1931 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
1932 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
1933 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
1936 * Userspace mount programs that send binary options generally send
1937 * them populated with default values. We have no way to know which
1938 * ones were explicitly specified. Fall back to legacy behavior and
1939 * just return success.
1941 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
1942 (nfsvers <= 3 && (!options || (options->version >= 1 &&
1943 options->version <= 6))))
1944 return 0;
1946 data = kzalloc(sizeof(*data), GFP_KERNEL);
1947 if (data == NULL)
1948 return -ENOMEM;
1950 /* fill out struct with values from existing mount */
1951 data->flags = nfss->flags;
1952 data->rsize = nfss->rsize;
1953 data->wsize = nfss->wsize;
1954 data->retrans = nfss->client->cl_timeout->to_retries;
1955 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
1956 data->acregmin = nfss->acregmin / HZ;
1957 data->acregmax = nfss->acregmax / HZ;
1958 data->acdirmin = nfss->acdirmin / HZ;
1959 data->acdirmax = nfss->acdirmax / HZ;
1960 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
1961 data->nfs_server.port = nfss->port;
1962 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
1963 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1964 data->nfs_server.addrlen);
1966 /* overwrite those values with any that were specified */
1967 error = nfs_parse_mount_options((char *)options, data);
1968 if (error < 0)
1969 goto out;
1971 /* compare new mount options with old ones */
1972 error = nfs_compare_remount_data(nfss, data);
1973 out:
1974 kfree(data);
1975 return error;
1979 * Initialise the common bits of the superblock
1981 static inline void nfs_initialise_sb(struct super_block *sb)
1983 struct nfs_server *server = NFS_SB(sb);
1985 sb->s_magic = NFS_SUPER_MAGIC;
1987 /* We probably want something more informative here */
1988 snprintf(sb->s_id, sizeof(sb->s_id),
1989 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1991 if (sb->s_blocksize == 0)
1992 sb->s_blocksize = nfs_block_bits(server->wsize,
1993 &sb->s_blocksize_bits);
1995 if (server->flags & NFS_MOUNT_NOAC)
1996 sb->s_flags |= MS_SYNCHRONOUS;
1998 sb->s_bdi = &server->backing_dev_info;
2000 nfs_super_set_maxbytes(sb, server->maxfilesize);
2004 * Finish setting up an NFS2/3 superblock
2006 static void nfs_fill_super(struct super_block *sb,
2007 struct nfs_parsed_mount_data *data)
2009 struct nfs_server *server = NFS_SB(sb);
2011 sb->s_blocksize_bits = 0;
2012 sb->s_blocksize = 0;
2013 if (data->bsize)
2014 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
2016 if (server->nfs_client->rpc_ops->version == 3) {
2017 /* The VFS shouldn't apply the umask to mode bits. We will do
2018 * so ourselves when necessary.
2020 sb->s_flags |= MS_POSIXACL;
2021 sb->s_time_gran = 1;
2024 sb->s_op = &nfs_sops;
2025 nfs_initialise_sb(sb);
2029 * Finish setting up a cloned NFS2/3 superblock
2031 static void nfs_clone_super(struct super_block *sb,
2032 const struct super_block *old_sb)
2034 struct nfs_server *server = NFS_SB(sb);
2036 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2037 sb->s_blocksize = old_sb->s_blocksize;
2038 sb->s_maxbytes = old_sb->s_maxbytes;
2040 if (server->nfs_client->rpc_ops->version == 3) {
2041 /* The VFS shouldn't apply the umask to mode bits. We will do
2042 * so ourselves when necessary.
2044 sb->s_flags |= MS_POSIXACL;
2045 sb->s_time_gran = 1;
2048 sb->s_op = old_sb->s_op;
2049 nfs_initialise_sb(sb);
2052 static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
2054 const struct nfs_server *a = s->s_fs_info;
2055 const struct rpc_clnt *clnt_a = a->client;
2056 const struct rpc_clnt *clnt_b = b->client;
2058 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
2059 goto Ebusy;
2060 if (a->nfs_client != b->nfs_client)
2061 goto Ebusy;
2062 if (a->flags != b->flags)
2063 goto Ebusy;
2064 if (a->wsize != b->wsize)
2065 goto Ebusy;
2066 if (a->rsize != b->rsize)
2067 goto Ebusy;
2068 if (a->acregmin != b->acregmin)
2069 goto Ebusy;
2070 if (a->acregmax != b->acregmax)
2071 goto Ebusy;
2072 if (a->acdirmin != b->acdirmin)
2073 goto Ebusy;
2074 if (a->acdirmax != b->acdirmax)
2075 goto Ebusy;
2076 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
2077 goto Ebusy;
2078 return 1;
2079 Ebusy:
2080 return 0;
2083 struct nfs_sb_mountdata {
2084 struct nfs_server *server;
2085 int mntflags;
2088 static int nfs_set_super(struct super_block *s, void *data)
2090 struct nfs_sb_mountdata *sb_mntdata = data;
2091 struct nfs_server *server = sb_mntdata->server;
2092 int ret;
2094 s->s_flags = sb_mntdata->mntflags;
2095 s->s_fs_info = server;
2096 ret = set_anon_super(s, server);
2097 if (ret == 0)
2098 server->s_dev = s->s_dev;
2099 return ret;
2102 static int nfs_compare_super_address(struct nfs_server *server1,
2103 struct nfs_server *server2)
2105 struct sockaddr *sap1, *sap2;
2107 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
2108 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
2110 if (sap1->sa_family != sap2->sa_family)
2111 return 0;
2113 switch (sap1->sa_family) {
2114 case AF_INET: {
2115 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
2116 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
2117 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
2118 return 0;
2119 if (sin1->sin_port != sin2->sin_port)
2120 return 0;
2121 break;
2123 case AF_INET6: {
2124 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
2125 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
2126 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
2127 return 0;
2128 if (sin1->sin6_port != sin2->sin6_port)
2129 return 0;
2130 break;
2132 default:
2133 return 0;
2136 return 1;
2139 static int nfs_compare_super(struct super_block *sb, void *data)
2141 struct nfs_sb_mountdata *sb_mntdata = data;
2142 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2143 int mntflags = sb_mntdata->mntflags;
2145 if (!nfs_compare_super_address(old, server))
2146 return 0;
2147 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2148 if (old->flags & NFS_MOUNT_UNSHARED)
2149 return 0;
2150 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2151 return 0;
2152 return nfs_compare_mount_options(sb, server, mntflags);
2155 static int nfs_bdi_register(struct nfs_server *server)
2157 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
2160 static int nfs_get_sb(struct file_system_type *fs_type,
2161 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2163 struct nfs_server *server = NULL;
2164 struct super_block *s;
2165 struct nfs_parsed_mount_data *data;
2166 struct nfs_fh *mntfh;
2167 struct dentry *mntroot;
2168 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2169 struct nfs_sb_mountdata sb_mntdata = {
2170 .mntflags = flags,
2172 int error = -ENOMEM;
2174 data = nfs_alloc_parsed_mount_data(3);
2175 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
2176 if (data == NULL || mntfh == NULL)
2177 goto out_free_fh;
2179 security_init_mnt_opts(&data->lsm_opts);
2181 /* Validate the mount data */
2182 error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
2183 if (error < 0)
2184 goto out;
2186 #ifdef CONFIG_NFS_V4
2187 if (data->version == 4) {
2188 error = nfs4_try_mount(flags, dev_name, data, mnt);
2189 kfree(data->client_address);
2190 goto out;
2192 #endif /* CONFIG_NFS_V4 */
2194 /* Get a volume representation */
2195 server = nfs_create_server(data, mntfh);
2196 if (IS_ERR(server)) {
2197 error = PTR_ERR(server);
2198 goto out;
2200 sb_mntdata.server = server;
2202 if (server->flags & NFS_MOUNT_UNSHARED)
2203 compare_super = NULL;
2205 /* Get a superblock - note that we may end up sharing one that already exists */
2206 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
2207 if (IS_ERR(s)) {
2208 error = PTR_ERR(s);
2209 goto out_err_nosb;
2212 if (s->s_fs_info != server) {
2213 nfs_free_server(server);
2214 server = NULL;
2215 } else {
2216 error = nfs_bdi_register(server);
2217 if (error)
2218 goto error_splat_bdi;
2221 if (!s->s_root) {
2222 /* initial superblock/root creation */
2223 nfs_fill_super(s, data);
2224 nfs_fscache_get_super_cookie(
2225 s, data ? data->fscache_uniq : NULL, NULL);
2228 mntroot = nfs_get_root(s, mntfh);
2229 if (IS_ERR(mntroot)) {
2230 error = PTR_ERR(mntroot);
2231 goto error_splat_super;
2234 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
2235 if (error)
2236 goto error_splat_root;
2238 s->s_flags |= MS_ACTIVE;
2239 mnt->mnt_sb = s;
2240 mnt->mnt_root = mntroot;
2241 error = 0;
2243 out:
2244 kfree(data->nfs_server.hostname);
2245 kfree(data->mount_server.hostname);
2246 kfree(data->fscache_uniq);
2247 security_free_mnt_opts(&data->lsm_opts);
2248 out_free_fh:
2249 kfree(mntfh);
2250 kfree(data);
2251 return error;
2253 out_err_nosb:
2254 nfs_free_server(server);
2255 goto out;
2257 error_splat_root:
2258 dput(mntroot);
2259 error_splat_super:
2260 if (server && !s->s_root)
2261 bdi_unregister(&server->backing_dev_info);
2262 error_splat_bdi:
2263 deactivate_locked_super(s);
2264 goto out;
2268 * Ensure that we unregister the bdi before kill_anon_super
2269 * releases the device name
2271 static void nfs_put_super(struct super_block *s)
2273 struct nfs_server *server = NFS_SB(s);
2275 bdi_unregister(&server->backing_dev_info);
2279 * Destroy an NFS2/3 superblock
2281 static void nfs_kill_super(struct super_block *s)
2283 struct nfs_server *server = NFS_SB(s);
2285 kill_anon_super(s);
2286 nfs_fscache_release_super_cookie(s);
2287 nfs_free_server(server);
2291 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2293 static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
2294 const char *dev_name, void *raw_data,
2295 struct vfsmount *mnt)
2297 struct nfs_clone_mount *data = raw_data;
2298 struct super_block *s;
2299 struct nfs_server *server;
2300 struct dentry *mntroot;
2301 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2302 struct nfs_sb_mountdata sb_mntdata = {
2303 .mntflags = flags,
2305 int error;
2307 dprintk("--> nfs_xdev_get_sb()\n");
2309 /* create a new volume representation */
2310 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2311 if (IS_ERR(server)) {
2312 error = PTR_ERR(server);
2313 goto out_err_noserver;
2315 sb_mntdata.server = server;
2317 if (server->flags & NFS_MOUNT_UNSHARED)
2318 compare_super = NULL;
2320 /* Get a superblock - note that we may end up sharing one that already exists */
2321 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2322 if (IS_ERR(s)) {
2323 error = PTR_ERR(s);
2324 goto out_err_nosb;
2327 if (s->s_fs_info != server) {
2328 nfs_free_server(server);
2329 server = NULL;
2330 } else {
2331 error = nfs_bdi_register(server);
2332 if (error)
2333 goto error_splat_bdi;
2336 if (!s->s_root) {
2337 /* initial superblock/root creation */
2338 nfs_clone_super(s, data->sb);
2339 nfs_fscache_get_super_cookie(s, NULL, data);
2342 mntroot = nfs_get_root(s, data->fh);
2343 if (IS_ERR(mntroot)) {
2344 error = PTR_ERR(mntroot);
2345 goto error_splat_super;
2347 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2348 dput(mntroot);
2349 error = -ESTALE;
2350 goto error_splat_super;
2353 s->s_flags |= MS_ACTIVE;
2354 mnt->mnt_sb = s;
2355 mnt->mnt_root = mntroot;
2357 /* clone any lsm security options from the parent to the new sb */
2358 security_sb_clone_mnt_opts(data->sb, s);
2360 dprintk("<-- nfs_xdev_get_sb() = 0\n");
2361 return 0;
2363 out_err_nosb:
2364 nfs_free_server(server);
2365 out_err_noserver:
2366 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
2367 return error;
2369 error_splat_super:
2370 if (server && !s->s_root)
2371 bdi_unregister(&server->backing_dev_info);
2372 error_splat_bdi:
2373 deactivate_locked_super(s);
2374 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
2375 return error;
2378 #ifdef CONFIG_NFS_V4
2381 * Finish setting up a cloned NFS4 superblock
2383 static void nfs4_clone_super(struct super_block *sb,
2384 const struct super_block *old_sb)
2386 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2387 sb->s_blocksize = old_sb->s_blocksize;
2388 sb->s_maxbytes = old_sb->s_maxbytes;
2389 sb->s_time_gran = 1;
2390 sb->s_op = old_sb->s_op;
2391 nfs_initialise_sb(sb);
2395 * Set up an NFS4 superblock
2397 static void nfs4_fill_super(struct super_block *sb)
2399 sb->s_time_gran = 1;
2400 sb->s_op = &nfs4_sops;
2401 nfs_initialise_sb(sb);
2404 static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2406 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3);
2409 static int nfs4_validate_text_mount_data(void *options,
2410 struct nfs_parsed_mount_data *args,
2411 const char *dev_name)
2413 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2415 nfs_set_port(sap, &args->nfs_server.port, NFS_PORT);
2417 nfs_validate_transport_protocol(args);
2419 nfs4_validate_mount_flags(args);
2421 if (args->version != 4) {
2422 dfprintk(MOUNT,
2423 "NFS4: Illegal mount version\n");
2424 return -EINVAL;
2427 if (args->auth_flavor_len > 1) {
2428 dfprintk(MOUNT,
2429 "NFS4: Too many RPC auth flavours specified\n");
2430 return -EINVAL;
2433 if (args->client_address == NULL) {
2434 dfprintk(MOUNT,
2435 "NFS4: mount program didn't pass callback address\n");
2436 return -EINVAL;
2439 return nfs_parse_devname(dev_name,
2440 &args->nfs_server.hostname,
2441 NFS4_MAXNAMLEN,
2442 &args->nfs_server.export_path,
2443 NFS4_MAXPATHLEN);
2447 * Validate NFSv4 mount options
2449 static int nfs4_validate_mount_data(void *options,
2450 struct nfs_parsed_mount_data *args,
2451 const char *dev_name)
2453 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2454 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
2455 char *c;
2457 if (data == NULL)
2458 goto out_no_data;
2460 switch (data->version) {
2461 case 1:
2462 if (data->host_addrlen > sizeof(args->nfs_server.address))
2463 goto out_no_address;
2464 if (data->host_addrlen == 0)
2465 goto out_no_address;
2466 args->nfs_server.addrlen = data->host_addrlen;
2467 if (copy_from_user(sap, data->host_addr, data->host_addrlen))
2468 return -EFAULT;
2469 if (!nfs_verify_server_address(sap))
2470 goto out_no_address;
2472 if (data->auth_flavourlen) {
2473 if (data->auth_flavourlen > 1)
2474 goto out_inval_auth;
2475 if (copy_from_user(&args->auth_flavors[0],
2476 data->auth_flavours,
2477 sizeof(args->auth_flavors[0])))
2478 return -EFAULT;
2481 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2482 if (IS_ERR(c))
2483 return PTR_ERR(c);
2484 args->nfs_server.hostname = c;
2486 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2487 if (IS_ERR(c))
2488 return PTR_ERR(c);
2489 args->nfs_server.export_path = c;
2490 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
2492 c = strndup_user(data->client_addr.data, 16);
2493 if (IS_ERR(c))
2494 return PTR_ERR(c);
2495 args->client_address = c;
2498 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2499 * can deal with.
2502 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2503 args->rsize = data->rsize;
2504 args->wsize = data->wsize;
2505 args->timeo = data->timeo;
2506 args->retrans = data->retrans;
2507 args->acregmin = data->acregmin;
2508 args->acregmax = data->acregmax;
2509 args->acdirmin = data->acdirmin;
2510 args->acdirmax = data->acdirmax;
2511 args->nfs_server.protocol = data->proto;
2512 nfs_validate_transport_protocol(args);
2514 break;
2515 default:
2516 if (nfs_parse_mount_options((char *)options, args) == 0)
2517 return -EINVAL;
2519 if (!nfs_verify_server_address(sap))
2520 return -EINVAL;
2522 return nfs4_validate_text_mount_data(options, args, dev_name);
2525 return 0;
2527 out_no_data:
2528 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2529 return -EINVAL;
2531 out_inval_auth:
2532 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2533 data->auth_flavourlen);
2534 return -EINVAL;
2536 out_no_address:
2537 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2538 return -EINVAL;
2542 * Get the superblock for the NFS4 root partition
2544 static int nfs4_remote_get_sb(struct file_system_type *fs_type,
2545 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2547 struct nfs_parsed_mount_data *data = raw_data;
2548 struct super_block *s;
2549 struct nfs_server *server;
2550 struct nfs_fh *mntfh;
2551 struct dentry *mntroot;
2552 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2553 struct nfs_sb_mountdata sb_mntdata = {
2554 .mntflags = flags,
2556 int error = -ENOMEM;
2558 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
2559 if (data == NULL || mntfh == NULL)
2560 goto out_free_fh;
2562 security_init_mnt_opts(&data->lsm_opts);
2564 /* Get a volume representation */
2565 server = nfs4_create_server(data, mntfh);
2566 if (IS_ERR(server)) {
2567 error = PTR_ERR(server);
2568 goto out;
2570 sb_mntdata.server = server;
2572 if (server->flags & NFS4_MOUNT_UNSHARED)
2573 compare_super = NULL;
2575 /* Get a superblock - note that we may end up sharing one that already exists */
2576 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2577 if (IS_ERR(s)) {
2578 error = PTR_ERR(s);
2579 goto out_free;
2582 if (s->s_fs_info != server) {
2583 nfs_free_server(server);
2584 server = NULL;
2585 } else {
2586 error = nfs_bdi_register(server);
2587 if (error)
2588 goto error_splat_bdi;
2591 if (!s->s_root) {
2592 /* initial superblock/root creation */
2593 nfs4_fill_super(s);
2594 nfs_fscache_get_super_cookie(
2595 s, data ? data->fscache_uniq : NULL, NULL);
2598 mntroot = nfs4_get_root(s, mntfh);
2599 if (IS_ERR(mntroot)) {
2600 error = PTR_ERR(mntroot);
2601 goto error_splat_super;
2604 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
2605 if (error)
2606 goto error_splat_root;
2608 s->s_flags |= MS_ACTIVE;
2609 mnt->mnt_sb = s;
2610 mnt->mnt_root = mntroot;
2611 error = 0;
2613 out:
2614 security_free_mnt_opts(&data->lsm_opts);
2615 out_free_fh:
2616 kfree(mntfh);
2617 return error;
2619 out_free:
2620 nfs_free_server(server);
2621 goto out;
2623 error_splat_root:
2624 dput(mntroot);
2625 error_splat_super:
2626 if (server && !s->s_root)
2627 bdi_unregister(&server->backing_dev_info);
2628 error_splat_bdi:
2629 deactivate_locked_super(s);
2630 goto out;
2633 static struct vfsmount *nfs_do_root_mount(struct file_system_type *fs_type,
2634 int flags, void *data, const char *hostname)
2636 struct vfsmount *root_mnt;
2637 char *root_devname;
2638 size_t len;
2640 len = strlen(hostname) + 3;
2641 root_devname = kmalloc(len, GFP_KERNEL);
2642 if (root_devname == NULL)
2643 return ERR_PTR(-ENOMEM);
2644 snprintf(root_devname, len, "%s:/", hostname);
2645 root_mnt = vfs_kern_mount(fs_type, flags, root_devname, data);
2646 kfree(root_devname);
2647 return root_mnt;
2650 static void nfs_fix_devname(const struct path *path, struct vfsmount *mnt)
2652 char *page = (char *) __get_free_page(GFP_KERNEL);
2653 char *devname, *tmp;
2655 if (page == NULL)
2656 return;
2657 devname = nfs_path(path->mnt->mnt_devname,
2658 path->mnt->mnt_root, path->dentry,
2659 page, PAGE_SIZE);
2660 if (devname == NULL)
2661 goto out_freepage;
2662 tmp = kstrdup(devname, GFP_KERNEL);
2663 if (tmp == NULL)
2664 goto out_freepage;
2665 kfree(mnt->mnt_devname);
2666 mnt->mnt_devname = tmp;
2667 out_freepage:
2668 free_page((unsigned long)page);
2671 static int nfs_follow_remote_path(struct vfsmount *root_mnt,
2672 const char *export_path, struct vfsmount *mnt_target)
2674 struct mnt_namespace *ns_private;
2675 struct nameidata nd;
2676 struct super_block *s;
2677 int ret;
2679 ns_private = create_mnt_ns(root_mnt);
2680 ret = PTR_ERR(ns_private);
2681 if (IS_ERR(ns_private))
2682 goto out_mntput;
2684 ret = vfs_path_lookup(root_mnt->mnt_root, root_mnt,
2685 export_path, LOOKUP_FOLLOW, &nd);
2687 put_mnt_ns(ns_private);
2689 if (ret != 0)
2690 goto out_err;
2692 s = nd.path.mnt->mnt_sb;
2693 atomic_inc(&s->s_active);
2694 mnt_target->mnt_sb = s;
2695 mnt_target->mnt_root = dget(nd.path.dentry);
2697 /* Correct the device pathname */
2698 nfs_fix_devname(&nd.path, mnt_target);
2700 path_put(&nd.path);
2701 down_write(&s->s_umount);
2702 return 0;
2703 out_mntput:
2704 mntput(root_mnt);
2705 out_err:
2706 return ret;
2709 static int nfs4_try_mount(int flags, const char *dev_name,
2710 struct nfs_parsed_mount_data *data,
2711 struct vfsmount *mnt)
2713 char *export_path;
2714 struct vfsmount *root_mnt;
2715 int error;
2717 dfprintk(MOUNT, "--> nfs4_try_mount()\n");
2719 export_path = data->nfs_server.export_path;
2720 data->nfs_server.export_path = "/";
2721 root_mnt = nfs_do_root_mount(&nfs4_remote_fs_type, flags, data,
2722 data->nfs_server.hostname);
2723 data->nfs_server.export_path = export_path;
2725 error = PTR_ERR(root_mnt);
2726 if (IS_ERR(root_mnt))
2727 goto out;
2729 error = nfs_follow_remote_path(root_mnt, export_path, mnt);
2731 out:
2732 dfprintk(MOUNT, "<-- nfs4_try_mount() = %d%s\n", error,
2733 error != 0 ? " [error]" : "");
2734 return error;
2738 * Get the superblock for an NFS4 mountpoint
2740 static int nfs4_get_sb(struct file_system_type *fs_type,
2741 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2743 struct nfs_parsed_mount_data *data;
2744 int error = -ENOMEM;
2746 data = nfs_alloc_parsed_mount_data(4);
2747 if (data == NULL)
2748 goto out_free_data;
2750 /* Validate the mount data */
2751 error = nfs4_validate_mount_data(raw_data, data, dev_name);
2752 if (error < 0)
2753 goto out;
2755 error = nfs4_try_mount(flags, dev_name, data, mnt);
2757 out:
2758 kfree(data->client_address);
2759 kfree(data->nfs_server.export_path);
2760 kfree(data->nfs_server.hostname);
2761 kfree(data->fscache_uniq);
2762 out_free_data:
2763 kfree(data);
2764 dprintk("<-- nfs4_get_sb() = %d%s\n", error,
2765 error != 0 ? " [error]" : "");
2766 return error;
2769 static void nfs4_kill_super(struct super_block *sb)
2771 struct nfs_server *server = NFS_SB(sb);
2773 dprintk("--> %s\n", __func__);
2774 nfs_super_return_all_delegations(sb);
2775 kill_anon_super(sb);
2776 nfs_fscache_release_super_cookie(sb);
2777 nfs_free_server(server);
2778 dprintk("<-- %s\n", __func__);
2782 * Clone an NFS4 server record on xdev traversal (FSID-change)
2784 static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
2785 const char *dev_name, void *raw_data,
2786 struct vfsmount *mnt)
2788 struct nfs_clone_mount *data = raw_data;
2789 struct super_block *s;
2790 struct nfs_server *server;
2791 struct dentry *mntroot;
2792 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2793 struct nfs_sb_mountdata sb_mntdata = {
2794 .mntflags = flags,
2796 int error;
2798 dprintk("--> nfs4_xdev_get_sb()\n");
2800 /* create a new volume representation */
2801 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2802 if (IS_ERR(server)) {
2803 error = PTR_ERR(server);
2804 goto out_err_noserver;
2806 sb_mntdata.server = server;
2808 if (server->flags & NFS4_MOUNT_UNSHARED)
2809 compare_super = NULL;
2811 /* Get a superblock - note that we may end up sharing one that already exists */
2812 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2813 if (IS_ERR(s)) {
2814 error = PTR_ERR(s);
2815 goto out_err_nosb;
2818 if (s->s_fs_info != server) {
2819 nfs_free_server(server);
2820 server = NULL;
2821 } else {
2822 error = nfs_bdi_register(server);
2823 if (error)
2824 goto error_splat_bdi;
2827 if (!s->s_root) {
2828 /* initial superblock/root creation */
2829 nfs4_clone_super(s, data->sb);
2830 nfs_fscache_get_super_cookie(s, NULL, data);
2833 mntroot = nfs4_get_root(s, data->fh);
2834 if (IS_ERR(mntroot)) {
2835 error = PTR_ERR(mntroot);
2836 goto error_splat_super;
2838 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2839 dput(mntroot);
2840 error = -ESTALE;
2841 goto error_splat_super;
2844 s->s_flags |= MS_ACTIVE;
2845 mnt->mnt_sb = s;
2846 mnt->mnt_root = mntroot;
2848 security_sb_clone_mnt_opts(data->sb, s);
2850 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2851 return 0;
2853 out_err_nosb:
2854 nfs_free_server(server);
2855 out_err_noserver:
2856 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
2857 return error;
2859 error_splat_super:
2860 if (server && !s->s_root)
2861 bdi_unregister(&server->backing_dev_info);
2862 error_splat_bdi:
2863 deactivate_locked_super(s);
2864 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
2865 return error;
2868 static int nfs4_remote_referral_get_sb(struct file_system_type *fs_type,
2869 int flags, const char *dev_name, void *raw_data,
2870 struct vfsmount *mnt)
2872 struct nfs_clone_mount *data = raw_data;
2873 struct super_block *s;
2874 struct nfs_server *server;
2875 struct dentry *mntroot;
2876 struct nfs_fh mntfh;
2877 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2878 struct nfs_sb_mountdata sb_mntdata = {
2879 .mntflags = flags,
2881 int error;
2883 dprintk("--> nfs4_referral_get_sb()\n");
2885 /* create a new volume representation */
2886 server = nfs4_create_referral_server(data, &mntfh);
2887 if (IS_ERR(server)) {
2888 error = PTR_ERR(server);
2889 goto out_err_noserver;
2891 sb_mntdata.server = server;
2893 if (server->flags & NFS4_MOUNT_UNSHARED)
2894 compare_super = NULL;
2896 /* Get a superblock - note that we may end up sharing one that already exists */
2897 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2898 if (IS_ERR(s)) {
2899 error = PTR_ERR(s);
2900 goto out_err_nosb;
2903 if (s->s_fs_info != server) {
2904 nfs_free_server(server);
2905 server = NULL;
2906 } else {
2907 error = nfs_bdi_register(server);
2908 if (error)
2909 goto error_splat_bdi;
2912 if (!s->s_root) {
2913 /* initial superblock/root creation */
2914 nfs4_fill_super(s);
2915 nfs_fscache_get_super_cookie(s, NULL, data);
2918 mntroot = nfs4_get_root(s, &mntfh);
2919 if (IS_ERR(mntroot)) {
2920 error = PTR_ERR(mntroot);
2921 goto error_splat_super;
2923 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2924 dput(mntroot);
2925 error = -ESTALE;
2926 goto error_splat_super;
2929 s->s_flags |= MS_ACTIVE;
2930 mnt->mnt_sb = s;
2931 mnt->mnt_root = mntroot;
2933 security_sb_clone_mnt_opts(data->sb, s);
2935 dprintk("<-- nfs4_referral_get_sb() = 0\n");
2936 return 0;
2938 out_err_nosb:
2939 nfs_free_server(server);
2940 out_err_noserver:
2941 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
2942 return error;
2944 error_splat_super:
2945 if (server && !s->s_root)
2946 bdi_unregister(&server->backing_dev_info);
2947 error_splat_bdi:
2948 deactivate_locked_super(s);
2949 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
2950 return error;
2954 * Create an NFS4 server record on referral traversal
2956 static int nfs4_referral_get_sb(struct file_system_type *fs_type,
2957 int flags, const char *dev_name, void *raw_data,
2958 struct vfsmount *mnt)
2960 struct nfs_clone_mount *data = raw_data;
2961 char *export_path;
2962 struct vfsmount *root_mnt;
2963 int error;
2965 dprintk("--> nfs4_referral_get_sb()\n");
2967 export_path = data->mnt_path;
2968 data->mnt_path = "/";
2970 root_mnt = nfs_do_root_mount(&nfs4_remote_referral_fs_type,
2971 flags, data, data->hostname);
2972 data->mnt_path = export_path;
2974 error = PTR_ERR(root_mnt);
2975 if (IS_ERR(root_mnt))
2976 goto out;
2978 error = nfs_follow_remote_path(root_mnt, export_path, mnt);
2979 out:
2980 dprintk("<-- nfs4_referral_get_sb() = %d%s\n", error,
2981 error != 0 ? " [error]" : "");
2982 return error;
2985 #endif /* CONFIG_NFS_V4 */