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/seq_file.h>
43 #include <linux/mount.h>
44 #include <linux/mnt_namespace.h>
45 #include <linux/namei.h>
46 #include <linux/nfs_idmap.h>
47 #include <linux/vfs.h>
48 #include <linux/inet.h>
49 #include <linux/in6.h>
50 #include <linux/slab.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 #define NFS_DEFAULT_VERSION 3
72 #define NFS_DEFAULT_VERSION 2
76 /* Mount options that take no arguments */
78 Opt_posix
, Opt_noposix
,
82 Opt_v2
, Opt_v3
, Opt_v4
,
83 Opt_udp
, Opt_tcp
, Opt_rdma
,
85 Opt_rdirplus
, Opt_nordirplus
,
86 Opt_sharecache
, Opt_nosharecache
,
87 Opt_resvport
, Opt_noresvport
,
88 Opt_fscache
, Opt_nofscache
,
90 /* Mount options that take integer arguments */
92 Opt_rsize
, Opt_wsize
, Opt_bsize
,
93 Opt_timeo
, Opt_retrans
,
94 Opt_acregmin
, Opt_acregmax
,
95 Opt_acdirmin
, Opt_acdirmax
,
103 /* Mount options that take string arguments */
104 Opt_sec
, Opt_proto
, Opt_mountproto
, Opt_mounthost
,
105 Opt_addr
, Opt_mountaddr
, Opt_clientaddr
,
110 /* Special mount options */
111 Opt_userspace
, Opt_deprecated
, Opt_sloppy
,
116 static const match_table_t nfs_mount_option_tokens
= {
117 { Opt_userspace
, "bg" },
118 { Opt_userspace
, "fg" },
119 { Opt_userspace
, "retry=%s" },
121 { Opt_sloppy
, "sloppy" },
123 { Opt_soft
, "soft" },
124 { Opt_hard
, "hard" },
125 { Opt_deprecated
, "intr" },
126 { Opt_deprecated
, "nointr" },
127 { Opt_posix
, "posix" },
128 { Opt_noposix
, "noposix" },
130 { Opt_nocto
, "nocto" },
132 { Opt_noac
, "noac" },
133 { Opt_lock
, "lock" },
134 { Opt_nolock
, "nolock" },
140 { Opt_rdma
, "rdma" },
142 { Opt_noacl
, "noacl" },
143 { Opt_rdirplus
, "rdirplus" },
144 { Opt_nordirplus
, "nordirplus" },
145 { Opt_sharecache
, "sharecache" },
146 { Opt_nosharecache
, "nosharecache" },
147 { Opt_resvport
, "resvport" },
148 { Opt_noresvport
, "noresvport" },
149 { Opt_fscache
, "fsc" },
150 { Opt_nofscache
, "nofsc" },
152 { Opt_port
, "port=%s" },
153 { Opt_rsize
, "rsize=%s" },
154 { Opt_wsize
, "wsize=%s" },
155 { Opt_bsize
, "bsize=%s" },
156 { Opt_timeo
, "timeo=%s" },
157 { Opt_retrans
, "retrans=%s" },
158 { Opt_acregmin
, "acregmin=%s" },
159 { Opt_acregmax
, "acregmax=%s" },
160 { Opt_acdirmin
, "acdirmin=%s" },
161 { Opt_acdirmax
, "acdirmax=%s" },
162 { Opt_actimeo
, "actimeo=%s" },
163 { Opt_namelen
, "namlen=%s" },
164 { Opt_mountport
, "mountport=%s" },
165 { Opt_mountvers
, "mountvers=%s" },
166 { Opt_nfsvers
, "nfsvers=%s" },
167 { Opt_nfsvers
, "vers=%s" },
168 { Opt_minorversion
, "minorversion=%s" },
170 { Opt_sec
, "sec=%s" },
171 { Opt_proto
, "proto=%s" },
172 { Opt_mountproto
, "mountproto=%s" },
173 { Opt_addr
, "addr=%s" },
174 { Opt_clientaddr
, "clientaddr=%s" },
175 { Opt_mounthost
, "mounthost=%s" },
176 { Opt_mountaddr
, "mountaddr=%s" },
178 { Opt_lookupcache
, "lookupcache=%s" },
179 { Opt_fscache_uniq
, "fsc=%s" },
180 { Opt_local_lock
, "local_lock=%s" },
186 Opt_xprt_udp
, Opt_xprt_udp6
, Opt_xprt_tcp
, Opt_xprt_tcp6
, Opt_xprt_rdma
,
191 static const match_table_t nfs_xprt_protocol_tokens
= {
192 { Opt_xprt_udp
, "udp" },
193 { Opt_xprt_udp6
, "udp6" },
194 { Opt_xprt_tcp
, "tcp" },
195 { Opt_xprt_tcp6
, "tcp6" },
196 { Opt_xprt_rdma
, "rdma" },
198 { Opt_xprt_err
, NULL
}
202 Opt_sec_none
, Opt_sec_sys
,
203 Opt_sec_krb5
, Opt_sec_krb5i
, Opt_sec_krb5p
,
204 Opt_sec_lkey
, Opt_sec_lkeyi
, Opt_sec_lkeyp
,
205 Opt_sec_spkm
, Opt_sec_spkmi
, Opt_sec_spkmp
,
210 static const match_table_t nfs_secflavor_tokens
= {
211 { Opt_sec_none
, "none" },
212 { Opt_sec_none
, "null" },
213 { Opt_sec_sys
, "sys" },
215 { Opt_sec_krb5
, "krb5" },
216 { Opt_sec_krb5i
, "krb5i" },
217 { Opt_sec_krb5p
, "krb5p" },
219 { Opt_sec_lkey
, "lkey" },
220 { Opt_sec_lkeyi
, "lkeyi" },
221 { Opt_sec_lkeyp
, "lkeyp" },
223 { Opt_sec_spkm
, "spkm3" },
224 { Opt_sec_spkmi
, "spkm3i" },
225 { Opt_sec_spkmp
, "spkm3p" },
227 { Opt_sec_err
, NULL
}
231 Opt_lookupcache_all
, Opt_lookupcache_positive
,
232 Opt_lookupcache_none
,
237 static match_table_t nfs_lookupcache_tokens
= {
238 { Opt_lookupcache_all
, "all" },
239 { Opt_lookupcache_positive
, "pos" },
240 { Opt_lookupcache_positive
, "positive" },
241 { Opt_lookupcache_none
, "none" },
243 { Opt_lookupcache_err
, NULL
}
247 Opt_local_lock_all
, Opt_local_lock_flock
, Opt_local_lock_posix
,
253 static match_table_t nfs_local_lock_tokens
= {
254 { Opt_local_lock_all
, "all" },
255 { Opt_local_lock_flock
, "flock" },
256 { Opt_local_lock_posix
, "posix" },
257 { Opt_local_lock_none
, "none" },
259 { Opt_local_lock_err
, NULL
}
263 static void nfs_umount_begin(struct super_block
*);
264 static int nfs_statfs(struct dentry
*, struct kstatfs
*);
265 static int nfs_show_options(struct seq_file
*, struct vfsmount
*);
266 static int nfs_show_stats(struct seq_file
*, struct vfsmount
*);
267 static int nfs_get_sb(struct file_system_type
*, int, const char *, void *, struct vfsmount
*);
268 static struct dentry
*nfs_xdev_mount(struct file_system_type
*fs_type
,
269 int flags
, const char *dev_name
, void *raw_data
);
270 static void nfs_put_super(struct super_block
*);
271 static void nfs_kill_super(struct super_block
*);
272 static int nfs_remount(struct super_block
*sb
, int *flags
, char *raw_data
);
274 static struct file_system_type nfs_fs_type
= {
275 .owner
= THIS_MODULE
,
277 .get_sb
= nfs_get_sb
,
278 .kill_sb
= nfs_kill_super
,
279 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
282 struct file_system_type nfs_xdev_fs_type
= {
283 .owner
= THIS_MODULE
,
285 .mount
= nfs_xdev_mount
,
286 .kill_sb
= nfs_kill_super
,
287 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
290 static const struct super_operations nfs_sops
= {
291 .alloc_inode
= nfs_alloc_inode
,
292 .destroy_inode
= nfs_destroy_inode
,
293 .write_inode
= nfs_write_inode
,
294 .put_super
= nfs_put_super
,
295 .statfs
= nfs_statfs
,
296 .evict_inode
= nfs_evict_inode
,
297 .umount_begin
= nfs_umount_begin
,
298 .show_options
= nfs_show_options
,
299 .show_stats
= nfs_show_stats
,
300 .remount_fs
= nfs_remount
,
304 static int nfs4_validate_text_mount_data(void *options
,
305 struct nfs_parsed_mount_data
*args
, const char *dev_name
);
306 static int nfs4_try_mount(int flags
, const char *dev_name
,
307 struct nfs_parsed_mount_data
*data
, struct vfsmount
*mnt
);
308 static int nfs4_get_sb(struct file_system_type
*fs_type
,
309 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
310 static struct dentry
*nfs4_remote_mount(struct file_system_type
*fs_type
,
311 int flags
, const char *dev_name
, void *raw_data
);
312 static struct dentry
*nfs4_xdev_mount(struct file_system_type
*fs_type
,
313 int flags
, const char *dev_name
, void *raw_data
);
314 static int nfs4_referral_get_sb(struct file_system_type
*fs_type
,
315 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
316 static struct dentry
*nfs4_remote_referral_mount(struct file_system_type
*fs_type
,
317 int flags
, const char *dev_name
, void *raw_data
);
318 static void nfs4_kill_super(struct super_block
*sb
);
320 static struct file_system_type nfs4_fs_type
= {
321 .owner
= THIS_MODULE
,
323 .get_sb
= nfs4_get_sb
,
324 .kill_sb
= nfs4_kill_super
,
325 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
328 static struct file_system_type nfs4_remote_fs_type
= {
329 .owner
= THIS_MODULE
,
331 .mount
= nfs4_remote_mount
,
332 .kill_sb
= nfs4_kill_super
,
333 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
336 struct file_system_type nfs4_xdev_fs_type
= {
337 .owner
= THIS_MODULE
,
339 .mount
= nfs4_xdev_mount
,
340 .kill_sb
= nfs4_kill_super
,
341 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
344 static struct file_system_type nfs4_remote_referral_fs_type
= {
345 .owner
= THIS_MODULE
,
347 .mount
= nfs4_remote_referral_mount
,
348 .kill_sb
= nfs4_kill_super
,
349 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
352 struct file_system_type nfs4_referral_fs_type
= {
353 .owner
= THIS_MODULE
,
355 .get_sb
= nfs4_referral_get_sb
,
356 .kill_sb
= nfs4_kill_super
,
357 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
360 static const struct super_operations nfs4_sops
= {
361 .alloc_inode
= nfs_alloc_inode
,
362 .destroy_inode
= nfs_destroy_inode
,
363 .write_inode
= nfs_write_inode
,
364 .put_super
= nfs_put_super
,
365 .statfs
= nfs_statfs
,
366 .evict_inode
= nfs4_evict_inode
,
367 .umount_begin
= nfs_umount_begin
,
368 .show_options
= nfs_show_options
,
369 .show_stats
= nfs_show_stats
,
370 .remount_fs
= nfs_remount
,
374 static struct shrinker acl_shrinker
= {
375 .shrink
= nfs_access_cache_shrinker
,
376 .seeks
= DEFAULT_SEEKS
,
380 * Register the NFS filesystems
382 int __init
register_nfs_fs(void)
386 ret
= register_filesystem(&nfs_fs_type
);
390 ret
= nfs_register_sysctl();
394 ret
= register_filesystem(&nfs4_fs_type
);
398 register_shrinker(&acl_shrinker
);
403 nfs_unregister_sysctl();
406 unregister_filesystem(&nfs_fs_type
);
412 * Unregister the NFS filesystems
414 void __exit
unregister_nfs_fs(void)
416 unregister_shrinker(&acl_shrinker
);
418 unregister_filesystem(&nfs4_fs_type
);
420 nfs_unregister_sysctl();
421 unregister_filesystem(&nfs_fs_type
);
424 void nfs_sb_active(struct super_block
*sb
)
426 struct nfs_server
*server
= NFS_SB(sb
);
428 if (atomic_inc_return(&server
->active
) == 1)
429 atomic_inc(&sb
->s_active
);
432 void nfs_sb_deactive(struct super_block
*sb
)
434 struct nfs_server
*server
= NFS_SB(sb
);
436 if (atomic_dec_and_test(&server
->active
))
437 deactivate_super(sb
);
441 * Deliver file system statistics to userspace
443 static int nfs_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
445 struct nfs_server
*server
= NFS_SB(dentry
->d_sb
);
446 unsigned char blockbits
;
447 unsigned long blockres
;
448 struct nfs_fh
*fh
= NFS_FH(dentry
->d_inode
);
449 struct nfs_fsstat res
;
452 res
.fattr
= nfs_alloc_fattr();
453 if (res
.fattr
== NULL
)
456 error
= server
->nfs_client
->rpc_ops
->statfs(server
, fh
, &res
);
457 if (unlikely(error
== -ESTALE
)) {
458 struct dentry
*pd_dentry
;
460 pd_dentry
= dget_parent(dentry
);
461 if (pd_dentry
!= NULL
) {
462 nfs_zap_caches(pd_dentry
->d_inode
);
466 nfs_free_fattr(res
.fattr
);
470 buf
->f_type
= NFS_SUPER_MAGIC
;
473 * Current versions of glibc do not correctly handle the
474 * case where f_frsize != f_bsize. Eventually we want to
475 * report the value of wtmult in this field.
477 buf
->f_frsize
= dentry
->d_sb
->s_blocksize
;
480 * On most *nix systems, f_blocks, f_bfree, and f_bavail
481 * are reported in units of f_frsize. Linux hasn't had
482 * an f_frsize field in its statfs struct until recently,
483 * thus historically Linux's sys_statfs reports these
484 * fields in units of f_bsize.
486 buf
->f_bsize
= dentry
->d_sb
->s_blocksize
;
487 blockbits
= dentry
->d_sb
->s_blocksize_bits
;
488 blockres
= (1 << blockbits
) - 1;
489 buf
->f_blocks
= (res
.tbytes
+ blockres
) >> blockbits
;
490 buf
->f_bfree
= (res
.fbytes
+ blockres
) >> blockbits
;
491 buf
->f_bavail
= (res
.abytes
+ blockres
) >> blockbits
;
493 buf
->f_files
= res
.tfiles
;
494 buf
->f_ffree
= res
.afiles
;
496 buf
->f_namelen
= server
->namelen
;
501 dprintk("%s: statfs error = %d\n", __func__
, -error
);
506 * Map the security flavour number to a name
508 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour
)
510 static const struct {
511 rpc_authflavor_t flavour
;
514 { RPC_AUTH_NULL
, "null" },
515 { RPC_AUTH_UNIX
, "sys" },
516 { RPC_AUTH_GSS_KRB5
, "krb5" },
517 { RPC_AUTH_GSS_KRB5I
, "krb5i" },
518 { RPC_AUTH_GSS_KRB5P
, "krb5p" },
519 { RPC_AUTH_GSS_LKEY
, "lkey" },
520 { RPC_AUTH_GSS_LKEYI
, "lkeyi" },
521 { RPC_AUTH_GSS_LKEYP
, "lkeyp" },
522 { RPC_AUTH_GSS_SPKM
, "spkm" },
523 { RPC_AUTH_GSS_SPKMI
, "spkmi" },
524 { RPC_AUTH_GSS_SPKMP
, "spkmp" },
525 { UINT_MAX
, "unknown" }
529 for (i
= 0; sec_flavours
[i
].flavour
!= UINT_MAX
; i
++) {
530 if (sec_flavours
[i
].flavour
== flavour
)
533 return sec_flavours
[i
].str
;
536 static void nfs_show_mountd_netid(struct seq_file
*m
, struct nfs_server
*nfss
,
539 struct sockaddr
*sap
= (struct sockaddr
*) &nfss
->mountd_address
;
541 seq_printf(m
, ",mountproto=");
542 switch (sap
->sa_family
) {
544 switch (nfss
->mountd_protocol
) {
546 seq_printf(m
, RPCBIND_NETID_UDP
);
549 seq_printf(m
, RPCBIND_NETID_TCP
);
553 seq_printf(m
, "auto");
557 switch (nfss
->mountd_protocol
) {
559 seq_printf(m
, RPCBIND_NETID_UDP6
);
562 seq_printf(m
, RPCBIND_NETID_TCP6
);
566 seq_printf(m
, "auto");
571 seq_printf(m
, "auto");
575 static void nfs_show_mountd_options(struct seq_file
*m
, struct nfs_server
*nfss
,
578 struct sockaddr
*sap
= (struct sockaddr
*)&nfss
->mountd_address
;
580 if (nfss
->flags
& NFS_MOUNT_LEGACY_INTERFACE
)
583 switch (sap
->sa_family
) {
585 struct sockaddr_in
*sin
= (struct sockaddr_in
*)sap
;
586 seq_printf(m
, ",mountaddr=%pI4", &sin
->sin_addr
.s_addr
);
590 struct sockaddr_in6
*sin6
= (struct sockaddr_in6
*)sap
;
591 seq_printf(m
, ",mountaddr=%pI6c", &sin6
->sin6_addr
);
596 seq_printf(m
, ",mountaddr=unspecified");
599 if (nfss
->mountd_version
|| showdefaults
)
600 seq_printf(m
, ",mountvers=%u", nfss
->mountd_version
);
601 if (nfss
->mountd_port
|| showdefaults
)
602 seq_printf(m
, ",mountport=%u", nfss
->mountd_port
);
604 nfs_show_mountd_netid(m
, nfss
, showdefaults
);
608 static void nfs_show_nfsv4_options(struct seq_file
*m
, struct nfs_server
*nfss
,
611 struct nfs_client
*clp
= nfss
->nfs_client
;
613 seq_printf(m
, ",clientaddr=%s", clp
->cl_ipaddr
);
614 seq_printf(m
, ",minorversion=%u", clp
->cl_minorversion
);
617 static void nfs_show_nfsv4_options(struct seq_file
*m
, struct nfs_server
*nfss
,
624 * Describe the mount options in force on this server representation
626 static void nfs_show_mount_options(struct seq_file
*m
, struct nfs_server
*nfss
,
629 static const struct proc_nfs_info
{
634 { NFS_MOUNT_SOFT
, ",soft", ",hard" },
635 { NFS_MOUNT_POSIX
, ",posix", "" },
636 { NFS_MOUNT_NOCTO
, ",nocto", "" },
637 { NFS_MOUNT_NOAC
, ",noac", "" },
638 { NFS_MOUNT_NONLM
, ",nolock", "" },
639 { NFS_MOUNT_NOACL
, ",noacl", "" },
640 { NFS_MOUNT_NORDIRPLUS
, ",nordirplus", "" },
641 { NFS_MOUNT_UNSHARED
, ",nosharecache", "" },
642 { NFS_MOUNT_NORESVPORT
, ",noresvport", "" },
645 const struct proc_nfs_info
*nfs_infop
;
646 struct nfs_client
*clp
= nfss
->nfs_client
;
647 u32 version
= clp
->rpc_ops
->version
;
648 int local_flock
, local_fcntl
;
650 seq_printf(m
, ",vers=%u", version
);
651 seq_printf(m
, ",rsize=%u", nfss
->rsize
);
652 seq_printf(m
, ",wsize=%u", nfss
->wsize
);
653 if (nfss
->bsize
!= 0)
654 seq_printf(m
, ",bsize=%u", nfss
->bsize
);
655 seq_printf(m
, ",namlen=%u", nfss
->namelen
);
656 if (nfss
->acregmin
!= NFS_DEF_ACREGMIN
*HZ
|| showdefaults
)
657 seq_printf(m
, ",acregmin=%u", nfss
->acregmin
/HZ
);
658 if (nfss
->acregmax
!= NFS_DEF_ACREGMAX
*HZ
|| showdefaults
)
659 seq_printf(m
, ",acregmax=%u", nfss
->acregmax
/HZ
);
660 if (nfss
->acdirmin
!= NFS_DEF_ACDIRMIN
*HZ
|| showdefaults
)
661 seq_printf(m
, ",acdirmin=%u", nfss
->acdirmin
/HZ
);
662 if (nfss
->acdirmax
!= NFS_DEF_ACDIRMAX
*HZ
|| showdefaults
)
663 seq_printf(m
, ",acdirmax=%u", nfss
->acdirmax
/HZ
);
664 for (nfs_infop
= nfs_info
; nfs_infop
->flag
; nfs_infop
++) {
665 if (nfss
->flags
& nfs_infop
->flag
)
666 seq_puts(m
, nfs_infop
->str
);
668 seq_puts(m
, nfs_infop
->nostr
);
670 seq_printf(m
, ",proto=%s",
671 rpc_peeraddr2str(nfss
->client
, RPC_DISPLAY_NETID
));
673 if (nfss
->port
!= NFS_PORT
)
674 seq_printf(m
, ",port=%u", nfss
->port
);
677 seq_printf(m
, ",port=%u", nfss
->port
);
679 seq_printf(m
, ",timeo=%lu", 10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
);
680 seq_printf(m
, ",retrans=%u", nfss
->client
->cl_timeout
->to_retries
);
681 seq_printf(m
, ",sec=%s", nfs_pseudoflavour_to_name(nfss
->client
->cl_auth
->au_flavor
));
684 nfs_show_mountd_options(m
, nfss
, showdefaults
);
686 nfs_show_nfsv4_options(m
, nfss
, showdefaults
);
688 if (nfss
->options
& NFS_OPTION_FSCACHE
)
689 seq_printf(m
, ",fsc");
691 if (nfss
->flags
& NFS_MOUNT_LOOKUP_CACHE_NONEG
) {
692 if (nfss
->flags
& NFS_MOUNT_LOOKUP_CACHE_NONE
)
693 seq_printf(m
, ",lookupcache=none");
695 seq_printf(m
, ",lookupcache=pos");
698 local_flock
= nfss
->flags
& NFS_MOUNT_LOCAL_FLOCK
;
699 local_fcntl
= nfss
->flags
& NFS_MOUNT_LOCAL_FCNTL
;
701 if (!local_flock
&& !local_fcntl
)
702 seq_printf(m
, ",local_lock=none");
703 else if (local_flock
&& local_fcntl
)
704 seq_printf(m
, ",local_lock=all");
705 else if (local_flock
)
706 seq_printf(m
, ",local_lock=flock");
708 seq_printf(m
, ",local_lock=posix");
712 * Describe the mount options on this VFS mountpoint
714 static int nfs_show_options(struct seq_file
*m
, struct vfsmount
*mnt
)
716 struct nfs_server
*nfss
= NFS_SB(mnt
->mnt_sb
);
718 nfs_show_mount_options(m
, nfss
, 0);
720 seq_printf(m
, ",addr=%s",
721 rpc_peeraddr2str(nfss
->nfs_client
->cl_rpcclient
,
728 * Present statistical information for this VFS mountpoint
730 static int nfs_show_stats(struct seq_file
*m
, struct vfsmount
*mnt
)
733 struct nfs_server
*nfss
= NFS_SB(mnt
->mnt_sb
);
734 struct rpc_auth
*auth
= nfss
->client
->cl_auth
;
735 struct nfs_iostats totals
= { };
737 seq_printf(m
, "statvers=%s", NFS_IOSTAT_VERS
);
740 * Display all mount option settings
742 seq_printf(m
, "\n\topts:\t");
743 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_RDONLY
? "ro" : "rw");
744 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_SYNCHRONOUS
? ",sync" : "");
745 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_NOATIME
? ",noatime" : "");
746 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_NODIRATIME
? ",nodiratime" : "");
747 nfs_show_mount_options(m
, nfss
, 1);
749 seq_printf(m
, "\n\tage:\t%lu", (jiffies
- nfss
->mount_time
) / HZ
);
751 seq_printf(m
, "\n\tcaps:\t");
752 seq_printf(m
, "caps=0x%x", nfss
->caps
);
753 seq_printf(m
, ",wtmult=%u", nfss
->wtmult
);
754 seq_printf(m
, ",dtsize=%u", nfss
->dtsize
);
755 seq_printf(m
, ",bsize=%u", nfss
->bsize
);
756 seq_printf(m
, ",namlen=%u", nfss
->namelen
);
759 if (nfss
->nfs_client
->rpc_ops
->version
== 4) {
760 seq_printf(m
, "\n\tnfsv4:\t");
761 seq_printf(m
, "bm0=0x%x", nfss
->attr_bitmask
[0]);
762 seq_printf(m
, ",bm1=0x%x", nfss
->attr_bitmask
[1]);
763 seq_printf(m
, ",acl=0x%x", nfss
->acl_bitmask
);
768 * Display security flavor in effect for this mount
770 seq_printf(m
, "\n\tsec:\tflavor=%u", auth
->au_ops
->au_flavor
);
772 seq_printf(m
, ",pseudoflavor=%u", auth
->au_flavor
);
775 * Display superblock I/O counters
777 for_each_possible_cpu(cpu
) {
778 struct nfs_iostats
*stats
;
781 stats
= per_cpu_ptr(nfss
->io_stats
, cpu
);
783 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
784 totals
.events
[i
] += stats
->events
[i
];
785 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
786 totals
.bytes
[i
] += stats
->bytes
[i
];
787 #ifdef CONFIG_NFS_FSCACHE
788 for (i
= 0; i
< __NFSIOS_FSCACHEMAX
; i
++)
789 totals
.fscache
[i
] += stats
->fscache
[i
];
795 seq_printf(m
, "\n\tevents:\t");
796 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
797 seq_printf(m
, "%lu ", totals
.events
[i
]);
798 seq_printf(m
, "\n\tbytes:\t");
799 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
800 seq_printf(m
, "%Lu ", totals
.bytes
[i
]);
801 #ifdef CONFIG_NFS_FSCACHE
802 if (nfss
->options
& NFS_OPTION_FSCACHE
) {
803 seq_printf(m
, "\n\tfsc:\t");
804 for (i
= 0; i
< __NFSIOS_FSCACHEMAX
; i
++)
805 seq_printf(m
, "%Lu ", totals
.bytes
[i
]);
810 rpc_print_iostats(m
, nfss
->client
);
816 * Begin unmount by attempting to remove all automounted mountpoints we added
817 * in response to xdev traversals and referrals
819 static void nfs_umount_begin(struct super_block
*sb
)
821 struct nfs_server
*server
;
822 struct rpc_clnt
*rpc
;
825 /* -EIO all pending I/O */
826 rpc
= server
->client_acl
;
828 rpc_killall_tasks(rpc
);
829 rpc
= server
->client
;
831 rpc_killall_tasks(rpc
);
834 static struct nfs_parsed_mount_data
*nfs_alloc_parsed_mount_data(unsigned int version
)
836 struct nfs_parsed_mount_data
*data
;
838 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
840 data
->acregmin
= NFS_DEF_ACREGMIN
;
841 data
->acregmax
= NFS_DEF_ACREGMAX
;
842 data
->acdirmin
= NFS_DEF_ACDIRMIN
;
843 data
->acdirmax
= NFS_DEF_ACDIRMAX
;
844 data
->mount_server
.port
= NFS_UNSPEC_PORT
;
845 data
->nfs_server
.port
= NFS_UNSPEC_PORT
;
846 data
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
847 data
->auth_flavors
[0] = RPC_AUTH_UNIX
;
848 data
->auth_flavor_len
= 1;
849 data
->version
= version
;
850 data
->minorversion
= 0;
856 * Sanity-check a server address provided by the mount command.
858 * Address family must be initialized, and address must not be
859 * the ANY address for that family.
861 static int nfs_verify_server_address(struct sockaddr
*addr
)
863 switch (addr
->sa_family
) {
865 struct sockaddr_in
*sa
= (struct sockaddr_in
*)addr
;
866 return sa
->sin_addr
.s_addr
!= htonl(INADDR_ANY
);
869 struct in6_addr
*sa
= &((struct sockaddr_in6
*)addr
)->sin6_addr
;
870 return !ipv6_addr_any(sa
);
874 dfprintk(MOUNT
, "NFS: Invalid IP address specified\n");
879 * Select between a default port value and a user-specified port value.
880 * If a zero value is set, then autobind will be used.
882 static void nfs_set_port(struct sockaddr
*sap
, int *port
,
883 const unsigned short default_port
)
885 if (*port
== NFS_UNSPEC_PORT
)
886 *port
= default_port
;
888 rpc_set_port(sap
, *port
);
892 * Sanity check the NFS transport protocol.
895 static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data
*mnt
)
897 switch (mnt
->nfs_server
.protocol
) {
898 case XPRT_TRANSPORT_UDP
:
899 case XPRT_TRANSPORT_TCP
:
900 case XPRT_TRANSPORT_RDMA
:
903 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
908 * For text based NFSv2/v3 mounts, the mount protocol transport default
909 * settings should depend upon the specified NFS transport.
911 static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data
*mnt
)
913 nfs_validate_transport_protocol(mnt
);
915 if (mnt
->mount_server
.protocol
== XPRT_TRANSPORT_UDP
||
916 mnt
->mount_server
.protocol
== XPRT_TRANSPORT_TCP
)
918 switch (mnt
->nfs_server
.protocol
) {
919 case XPRT_TRANSPORT_UDP
:
920 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_UDP
;
922 case XPRT_TRANSPORT_TCP
:
923 case XPRT_TRANSPORT_RDMA
:
924 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_TCP
;
929 * Parse the value of the 'sec=' option.
931 static int nfs_parse_security_flavors(char *value
,
932 struct nfs_parsed_mount_data
*mnt
)
934 substring_t args
[MAX_OPT_ARGS
];
936 dfprintk(MOUNT
, "NFS: parsing sec=%s option\n", value
);
938 switch (match_token(value
, nfs_secflavor_tokens
, args
)) {
940 mnt
->auth_flavors
[0] = RPC_AUTH_NULL
;
943 mnt
->auth_flavors
[0] = RPC_AUTH_UNIX
;
946 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5
;
949 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5I
;
952 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5P
;
955 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEY
;
958 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEYI
;
961 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEYP
;
964 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKM
;
967 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKMI
;
970 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKMP
;
976 mnt
->auth_flavor_len
= 1;
981 * Error-check and convert a string of mount options from user space into
982 * a data structure. The whole mount string is processed; bad options are
983 * skipped as they are encountered. If there were no errors, return 1;
984 * otherwise return 0 (zero).
986 static int nfs_parse_mount_options(char *raw
,
987 struct nfs_parsed_mount_data
*mnt
)
989 char *p
, *string
, *secdata
;
990 int rc
, sloppy
= 0, invalid_option
= 0;
991 unsigned short protofamily
= AF_UNSPEC
;
992 unsigned short mountfamily
= AF_UNSPEC
;
995 dfprintk(MOUNT
, "NFS: mount options string was NULL.\n");
998 dfprintk(MOUNT
, "NFS: nfs mount opts='%s'\n", raw
);
1000 secdata
= alloc_secdata();
1004 rc
= security_sb_copy_data(raw
, secdata
);
1006 goto out_security_failure
;
1008 rc
= security_sb_parse_opts_str(secdata
, &mnt
->lsm_opts
);
1010 goto out_security_failure
;
1012 free_secdata(secdata
);
1014 while ((p
= strsep(&raw
, ",")) != NULL
) {
1015 substring_t args
[MAX_OPT_ARGS
];
1016 unsigned long option
;
1022 dfprintk(MOUNT
, "NFS: parsing nfs mount option '%s'\n", p
);
1024 token
= match_token(p
, nfs_mount_option_tokens
, args
);
1028 * boolean options: foo/nofoo
1031 mnt
->flags
|= NFS_MOUNT_SOFT
;
1034 mnt
->flags
&= ~NFS_MOUNT_SOFT
;
1037 mnt
->flags
|= NFS_MOUNT_POSIX
;
1040 mnt
->flags
&= ~NFS_MOUNT_POSIX
;
1043 mnt
->flags
&= ~NFS_MOUNT_NOCTO
;
1046 mnt
->flags
|= NFS_MOUNT_NOCTO
;
1049 mnt
->flags
&= ~NFS_MOUNT_NOAC
;
1052 mnt
->flags
|= NFS_MOUNT_NOAC
;
1055 mnt
->flags
&= ~NFS_MOUNT_NONLM
;
1056 mnt
->flags
&= ~(NFS_MOUNT_LOCAL_FLOCK
|
1057 NFS_MOUNT_LOCAL_FCNTL
);
1060 mnt
->flags
|= NFS_MOUNT_NONLM
;
1061 mnt
->flags
|= (NFS_MOUNT_LOCAL_FLOCK
|
1062 NFS_MOUNT_LOCAL_FCNTL
);
1065 mnt
->flags
&= ~NFS_MOUNT_VER3
;
1069 mnt
->flags
|= NFS_MOUNT_VER3
;
1072 #ifdef CONFIG_NFS_V4
1074 mnt
->flags
&= ~NFS_MOUNT_VER3
;
1079 mnt
->flags
&= ~NFS_MOUNT_TCP
;
1080 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1083 mnt
->flags
|= NFS_MOUNT_TCP
;
1084 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1087 mnt
->flags
|= NFS_MOUNT_TCP
; /* for side protocols */
1088 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_RDMA
;
1089 xprt_load_transport(p
);
1092 mnt
->flags
&= ~NFS_MOUNT_NOACL
;
1095 mnt
->flags
|= NFS_MOUNT_NOACL
;
1098 mnt
->flags
&= ~NFS_MOUNT_NORDIRPLUS
;
1100 case Opt_nordirplus
:
1101 mnt
->flags
|= NFS_MOUNT_NORDIRPLUS
;
1103 case Opt_sharecache
:
1104 mnt
->flags
&= ~NFS_MOUNT_UNSHARED
;
1106 case Opt_nosharecache
:
1107 mnt
->flags
|= NFS_MOUNT_UNSHARED
;
1110 mnt
->flags
&= ~NFS_MOUNT_NORESVPORT
;
1112 case Opt_noresvport
:
1113 mnt
->flags
|= NFS_MOUNT_NORESVPORT
;
1116 mnt
->options
|= NFS_OPTION_FSCACHE
;
1117 kfree(mnt
->fscache_uniq
);
1118 mnt
->fscache_uniq
= NULL
;
1121 mnt
->options
&= ~NFS_OPTION_FSCACHE
;
1122 kfree(mnt
->fscache_uniq
);
1123 mnt
->fscache_uniq
= NULL
;
1127 * options that take numeric values
1130 string
= match_strdup(args
);
1133 rc
= strict_strtoul(string
, 10, &option
);
1135 if (rc
!= 0 || option
> USHRT_MAX
)
1136 goto out_invalid_value
;
1137 mnt
->nfs_server
.port
= option
;
1140 string
= match_strdup(args
);
1143 rc
= strict_strtoul(string
, 10, &option
);
1146 goto out_invalid_value
;
1147 mnt
->rsize
= option
;
1150 string
= match_strdup(args
);
1153 rc
= strict_strtoul(string
, 10, &option
);
1156 goto out_invalid_value
;
1157 mnt
->wsize
= option
;
1160 string
= match_strdup(args
);
1163 rc
= strict_strtoul(string
, 10, &option
);
1166 goto out_invalid_value
;
1167 mnt
->bsize
= option
;
1170 string
= match_strdup(args
);
1173 rc
= strict_strtoul(string
, 10, &option
);
1175 if (rc
!= 0 || option
== 0)
1176 goto out_invalid_value
;
1177 mnt
->timeo
= option
;
1180 string
= match_strdup(args
);
1183 rc
= strict_strtoul(string
, 10, &option
);
1185 if (rc
!= 0 || option
== 0)
1186 goto out_invalid_value
;
1187 mnt
->retrans
= option
;
1190 string
= match_strdup(args
);
1193 rc
= strict_strtoul(string
, 10, &option
);
1196 goto out_invalid_value
;
1197 mnt
->acregmin
= option
;
1200 string
= match_strdup(args
);
1203 rc
= strict_strtoul(string
, 10, &option
);
1206 goto out_invalid_value
;
1207 mnt
->acregmax
= option
;
1210 string
= match_strdup(args
);
1213 rc
= strict_strtoul(string
, 10, &option
);
1216 goto out_invalid_value
;
1217 mnt
->acdirmin
= option
;
1220 string
= match_strdup(args
);
1223 rc
= strict_strtoul(string
, 10, &option
);
1226 goto out_invalid_value
;
1227 mnt
->acdirmax
= option
;
1230 string
= match_strdup(args
);
1233 rc
= strict_strtoul(string
, 10, &option
);
1236 goto out_invalid_value
;
1237 mnt
->acregmin
= mnt
->acregmax
=
1238 mnt
->acdirmin
= mnt
->acdirmax
= option
;
1241 string
= match_strdup(args
);
1244 rc
= strict_strtoul(string
, 10, &option
);
1247 goto out_invalid_value
;
1248 mnt
->namlen
= option
;
1251 string
= match_strdup(args
);
1254 rc
= strict_strtoul(string
, 10, &option
);
1256 if (rc
!= 0 || option
> USHRT_MAX
)
1257 goto out_invalid_value
;
1258 mnt
->mount_server
.port
= option
;
1261 string
= match_strdup(args
);
1264 rc
= strict_strtoul(string
, 10, &option
);
1267 option
< NFS_MNT_VERSION
||
1268 option
> NFS_MNT3_VERSION
)
1269 goto out_invalid_value
;
1270 mnt
->mount_server
.version
= option
;
1273 string
= match_strdup(args
);
1276 rc
= strict_strtoul(string
, 10, &option
);
1279 goto out_invalid_value
;
1282 mnt
->flags
&= ~NFS_MOUNT_VER3
;
1286 mnt
->flags
|= NFS_MOUNT_VER3
;
1289 #ifdef CONFIG_NFS_V4
1291 mnt
->flags
&= ~NFS_MOUNT_VER3
;
1296 goto out_invalid_value
;
1299 case Opt_minorversion
:
1300 string
= match_strdup(args
);
1303 rc
= strict_strtoul(string
, 10, &option
);
1306 goto out_invalid_value
;
1307 if (option
> NFS4_MAX_MINOR_VERSION
)
1308 goto out_invalid_value
;
1309 mnt
->minorversion
= option
;
1313 * options that take text values
1316 string
= match_strdup(args
);
1319 rc
= nfs_parse_security_flavors(string
, mnt
);
1322 dfprintk(MOUNT
, "NFS: unrecognized "
1323 "security flavor\n");
1328 string
= match_strdup(args
);
1331 token
= match_token(string
,
1332 nfs_xprt_protocol_tokens
, args
);
1334 protofamily
= AF_INET
;
1337 protofamily
= AF_INET6
;
1339 mnt
->flags
&= ~NFS_MOUNT_TCP
;
1340 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1344 protofamily
= AF_INET6
;
1346 mnt
->flags
|= NFS_MOUNT_TCP
;
1347 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1351 /* vector side protocols to TCP */
1352 mnt
->flags
|= NFS_MOUNT_TCP
;
1353 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_RDMA
;
1354 xprt_load_transport(string
);
1358 dfprintk(MOUNT
, "NFS: unrecognized "
1359 "transport protocol\n");
1364 case Opt_mountproto
:
1365 string
= match_strdup(args
);
1368 token
= match_token(string
,
1369 nfs_xprt_protocol_tokens
, args
);
1372 mountfamily
= AF_INET
;
1375 mountfamily
= AF_INET6
;
1377 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_UDP
;
1380 mountfamily
= AF_INET6
;
1382 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_TCP
;
1384 case Opt_xprt_rdma
: /* not used for side protocols */
1386 dfprintk(MOUNT
, "NFS: unrecognized "
1387 "transport protocol\n");
1392 string
= match_strdup(args
);
1395 mnt
->nfs_server
.addrlen
=
1396 rpc_pton(string
, strlen(string
),
1398 &mnt
->nfs_server
.address
,
1399 sizeof(mnt
->nfs_server
.address
));
1401 if (mnt
->nfs_server
.addrlen
== 0)
1402 goto out_invalid_address
;
1404 case Opt_clientaddr
:
1405 string
= match_strdup(args
);
1408 kfree(mnt
->client_address
);
1409 mnt
->client_address
= string
;
1412 string
= match_strdup(args
);
1415 kfree(mnt
->mount_server
.hostname
);
1416 mnt
->mount_server
.hostname
= string
;
1419 string
= match_strdup(args
);
1422 mnt
->mount_server
.addrlen
=
1423 rpc_pton(string
, strlen(string
),
1425 &mnt
->mount_server
.address
,
1426 sizeof(mnt
->mount_server
.address
));
1428 if (mnt
->mount_server
.addrlen
== 0)
1429 goto out_invalid_address
;
1431 case Opt_lookupcache
:
1432 string
= match_strdup(args
);
1435 token
= match_token(string
,
1436 nfs_lookupcache_tokens
, args
);
1439 case Opt_lookupcache_all
:
1440 mnt
->flags
&= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG
|NFS_MOUNT_LOOKUP_CACHE_NONE
);
1442 case Opt_lookupcache_positive
:
1443 mnt
->flags
&= ~NFS_MOUNT_LOOKUP_CACHE_NONE
;
1444 mnt
->flags
|= NFS_MOUNT_LOOKUP_CACHE_NONEG
;
1446 case Opt_lookupcache_none
:
1447 mnt
->flags
|= NFS_MOUNT_LOOKUP_CACHE_NONEG
|NFS_MOUNT_LOOKUP_CACHE_NONE
;
1450 dfprintk(MOUNT
, "NFS: invalid "
1451 "lookupcache argument\n");
1455 case Opt_fscache_uniq
:
1456 string
= match_strdup(args
);
1459 kfree(mnt
->fscache_uniq
);
1460 mnt
->fscache_uniq
= string
;
1461 mnt
->options
|= NFS_OPTION_FSCACHE
;
1463 case Opt_local_lock
:
1464 string
= match_strdup(args
);
1467 token
= match_token(string
, nfs_local_lock_tokens
,
1471 case Opt_local_lock_all
:
1472 mnt
->flags
|= (NFS_MOUNT_LOCAL_FLOCK
|
1473 NFS_MOUNT_LOCAL_FCNTL
);
1475 case Opt_local_lock_flock
:
1476 mnt
->flags
|= NFS_MOUNT_LOCAL_FLOCK
;
1478 case Opt_local_lock_posix
:
1479 mnt
->flags
|= NFS_MOUNT_LOCAL_FCNTL
;
1481 case Opt_local_lock_none
:
1482 mnt
->flags
&= ~(NFS_MOUNT_LOCAL_FLOCK
|
1483 NFS_MOUNT_LOCAL_FCNTL
);
1486 dfprintk(MOUNT
, "NFS: invalid "
1487 "local_lock argument\n");
1497 dfprintk(MOUNT
, "NFS: relaxing parsing rules\n");
1500 case Opt_deprecated
:
1501 dfprintk(MOUNT
, "NFS: ignoring mount option "
1507 dfprintk(MOUNT
, "NFS: unrecognized mount option "
1512 if (!sloppy
&& invalid_option
)
1516 * verify that any proto=/mountproto= options match the address
1517 * familiies in the addr=/mountaddr= options.
1519 if (protofamily
!= AF_UNSPEC
&&
1520 protofamily
!= mnt
->nfs_server
.address
.ss_family
)
1521 goto out_proto_mismatch
;
1523 if (mountfamily
!= AF_UNSPEC
) {
1524 if (mnt
->mount_server
.addrlen
) {
1525 if (mountfamily
!= mnt
->mount_server
.address
.ss_family
)
1526 goto out_mountproto_mismatch
;
1528 if (mountfamily
!= mnt
->nfs_server
.address
.ss_family
)
1529 goto out_mountproto_mismatch
;
1535 out_mountproto_mismatch
:
1536 printk(KERN_INFO
"NFS: mount server address does not match mountproto= "
1540 printk(KERN_INFO
"NFS: server address does not match proto= option\n");
1542 out_invalid_address
:
1543 printk(KERN_INFO
"NFS: bad IP address specified: %s\n", p
);
1546 printk(KERN_INFO
"NFS: bad mount option value specified: %s\n", p
);
1549 printk(KERN_INFO
"NFS: not enough memory to parse option\n");
1551 out_security_failure
:
1552 free_secdata(secdata
);
1553 printk(KERN_INFO
"NFS: security options invalid: %d\n", rc
);
1558 * Match the requested auth flavors with the list returned by
1559 * the server. Returns zero and sets the mount's authentication
1560 * flavor on success; returns -EACCES if server does not support
1561 * the requested flavor.
1563 static int nfs_walk_authlist(struct nfs_parsed_mount_data
*args
,
1564 struct nfs_mount_request
*request
)
1566 unsigned int i
, j
, server_authlist_len
= *(request
->auth_flav_len
);
1569 * Certain releases of Linux's mountd return an empty
1570 * flavor list. To prevent behavioral regression with
1571 * these servers (ie. rejecting mounts that used to
1572 * succeed), revert to pre-2.6.32 behavior (no checking)
1573 * if the returned flavor list is empty.
1575 if (server_authlist_len
== 0)
1579 * We avoid sophisticated negotiating here, as there are
1580 * plenty of cases where we can get it wrong, providing
1581 * either too little or too much security.
1583 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1584 * flavor listed first. However, some servers list
1585 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1586 * preferred default, in args->auth_flavors[0] if user
1587 * didn't specify sec= mount option.
1589 for (i
= 0; i
< args
->auth_flavor_len
; i
++)
1590 for (j
= 0; j
< server_authlist_len
; j
++)
1591 if (args
->auth_flavors
[i
] == request
->auth_flavs
[j
]) {
1592 dfprintk(MOUNT
, "NFS: using auth flavor %d\n",
1593 request
->auth_flavs
[j
]);
1594 args
->auth_flavors
[0] = request
->auth_flavs
[j
];
1598 dfprintk(MOUNT
, "NFS: server does not support requested auth flavor\n");
1599 nfs_umount(request
);
1604 * Use the remote server's MOUNT service to request the NFS file handle
1605 * corresponding to the provided path.
1607 static int nfs_try_mount(struct nfs_parsed_mount_data
*args
,
1608 struct nfs_fh
*root_fh
)
1610 rpc_authflavor_t server_authlist
[NFS_MAX_SECFLAVORS
];
1611 unsigned int server_authlist_len
= ARRAY_SIZE(server_authlist
);
1612 struct nfs_mount_request request
= {
1613 .sap
= (struct sockaddr
*)
1614 &args
->mount_server
.address
,
1615 .dirpath
= args
->nfs_server
.export_path
,
1616 .protocol
= args
->mount_server
.protocol
,
1618 .noresvport
= args
->flags
& NFS_MOUNT_NORESVPORT
,
1619 .auth_flav_len
= &server_authlist_len
,
1620 .auth_flavs
= server_authlist
,
1624 if (args
->mount_server
.version
== 0) {
1625 switch (args
->version
) {
1627 args
->mount_server
.version
= NFS_MNT3_VERSION
;
1630 args
->mount_server
.version
= NFS_MNT_VERSION
;
1633 request
.version
= args
->mount_server
.version
;
1635 if (args
->mount_server
.hostname
)
1636 request
.hostname
= args
->mount_server
.hostname
;
1638 request
.hostname
= args
->nfs_server
.hostname
;
1641 * Construct the mount server's address.
1643 if (args
->mount_server
.address
.ss_family
== AF_UNSPEC
) {
1644 memcpy(request
.sap
, &args
->nfs_server
.address
,
1645 args
->nfs_server
.addrlen
);
1646 args
->mount_server
.addrlen
= args
->nfs_server
.addrlen
;
1648 request
.salen
= args
->mount_server
.addrlen
;
1649 nfs_set_port(request
.sap
, &args
->mount_server
.port
, 0);
1652 * Now ask the mount server to map our export path
1655 status
= nfs_mount(&request
);
1657 dfprintk(MOUNT
, "NFS: unable to mount server %s, error %d\n",
1658 request
.hostname
, status
);
1663 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1665 if (args
->mount_server
.version
!= NFS_MNT3_VERSION
)
1667 return nfs_walk_authlist(args
, &request
);
1670 static int nfs_parse_simple_hostname(const char *dev_name
,
1671 char **hostname
, size_t maxnamlen
,
1672 char **export_path
, size_t maxpathlen
)
1675 char *colon
, *comma
;
1677 colon
= strchr(dev_name
, ':');
1679 goto out_bad_devname
;
1681 len
= colon
- dev_name
;
1682 if (len
> maxnamlen
)
1685 /* N.B. caller will free nfs_server.hostname in all cases */
1686 *hostname
= kstrndup(dev_name
, len
, GFP_KERNEL
);
1690 /* kill possible hostname list: not supported */
1691 comma
= strchr(*hostname
, ',');
1692 if (comma
!= NULL
) {
1693 if (comma
== *hostname
)
1694 goto out_bad_devname
;
1699 len
= strlen(colon
);
1700 if (len
> maxpathlen
)
1702 *export_path
= kstrndup(colon
, len
, GFP_KERNEL
);
1706 dfprintk(MOUNT
, "NFS: MNTPATH: '%s'\n", *export_path
);
1710 dfprintk(MOUNT
, "NFS: device name not in host:path format\n");
1714 dfprintk(MOUNT
, "NFS: not enough memory to parse device name\n");
1718 dfprintk(MOUNT
, "NFS: server hostname too long\n");
1719 return -ENAMETOOLONG
;
1722 dfprintk(MOUNT
, "NFS: export pathname too long\n");
1723 return -ENAMETOOLONG
;
1727 * Hostname has square brackets around it because it contains one or
1728 * more colons. We look for the first closing square bracket, and a
1729 * colon must follow it.
1731 static int nfs_parse_protected_hostname(const char *dev_name
,
1732 char **hostname
, size_t maxnamlen
,
1733 char **export_path
, size_t maxpathlen
)
1738 start
= (char *)(dev_name
+ 1);
1740 end
= strchr(start
, ']');
1742 goto out_bad_devname
;
1743 if (*(end
+ 1) != ':')
1744 goto out_bad_devname
;
1747 if (len
> maxnamlen
)
1750 /* N.B. caller will free nfs_server.hostname in all cases */
1751 *hostname
= kstrndup(start
, len
, GFP_KERNEL
);
1752 if (*hostname
== NULL
)
1757 if (len
> maxpathlen
)
1759 *export_path
= kstrndup(end
, len
, GFP_KERNEL
);
1766 dfprintk(MOUNT
, "NFS: device name not in host:path format\n");
1770 dfprintk(MOUNT
, "NFS: not enough memory to parse device name\n");
1774 dfprintk(MOUNT
, "NFS: server hostname too long\n");
1775 return -ENAMETOOLONG
;
1778 dfprintk(MOUNT
, "NFS: export pathname too long\n");
1779 return -ENAMETOOLONG
;
1783 * Split "dev_name" into "hostname:export_path".
1785 * The leftmost colon demarks the split between the server's hostname
1786 * and the export path. If the hostname starts with a left square
1787 * bracket, then it may contain colons.
1789 * Note: caller frees hostname and export path, even on error.
1791 static int nfs_parse_devname(const char *dev_name
,
1792 char **hostname
, size_t maxnamlen
,
1793 char **export_path
, size_t maxpathlen
)
1795 if (*dev_name
== '[')
1796 return nfs_parse_protected_hostname(dev_name
,
1797 hostname
, maxnamlen
,
1798 export_path
, maxpathlen
);
1800 return nfs_parse_simple_hostname(dev_name
,
1801 hostname
, maxnamlen
,
1802 export_path
, maxpathlen
);
1806 * Validate the NFS2/NFS3 mount data
1807 * - fills in the mount root filehandle
1809 * For option strings, user space handles the following behaviors:
1811 * + DNS: mapping server host name to IP address ("addr=" option)
1813 * + failure mode: how to behave if a mount request can't be handled
1814 * immediately ("fg/bg" option)
1816 * + retry: how often to retry a mount request ("retry=" option)
1818 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1819 * mountproto=tcp after mountproto=udp, and so on
1821 static int nfs_validate_mount_data(void *options
,
1822 struct nfs_parsed_mount_data
*args
,
1823 struct nfs_fh
*mntfh
,
1824 const char *dev_name
)
1826 struct nfs_mount_data
*data
= (struct nfs_mount_data
*)options
;
1827 struct sockaddr
*sap
= (struct sockaddr
*)&args
->nfs_server
.address
;
1832 switch (data
->version
) {
1838 if (data
->flags
& NFS_MOUNT_VER3
)
1840 data
->root
.size
= NFS2_FHSIZE
;
1841 memcpy(data
->root
.data
, data
->old_root
.data
, NFS2_FHSIZE
);
1843 if (data
->flags
& NFS_MOUNT_SECFLAVOUR
)
1846 memset(data
->context
, 0, sizeof(data
->context
));
1848 if (data
->flags
& NFS_MOUNT_VER3
) {
1849 if (data
->root
.size
> NFS3_FHSIZE
|| data
->root
.size
== 0)
1850 goto out_invalid_fh
;
1851 mntfh
->size
= data
->root
.size
;
1854 mntfh
->size
= NFS2_FHSIZE
;
1859 memcpy(mntfh
->data
, data
->root
.data
, mntfh
->size
);
1860 if (mntfh
->size
< sizeof(mntfh
->data
))
1861 memset(mntfh
->data
+ mntfh
->size
, 0,
1862 sizeof(mntfh
->data
) - mntfh
->size
);
1865 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1868 args
->flags
= data
->flags
& NFS_MOUNT_FLAGMASK
;
1869 args
->flags
|= NFS_MOUNT_LEGACY_INTERFACE
;
1870 args
->rsize
= data
->rsize
;
1871 args
->wsize
= data
->wsize
;
1872 args
->timeo
= data
->timeo
;
1873 args
->retrans
= data
->retrans
;
1874 args
->acregmin
= data
->acregmin
;
1875 args
->acregmax
= data
->acregmax
;
1876 args
->acdirmin
= data
->acdirmin
;
1877 args
->acdirmax
= data
->acdirmax
;
1879 memcpy(sap
, &data
->addr
, sizeof(data
->addr
));
1880 args
->nfs_server
.addrlen
= sizeof(data
->addr
);
1881 if (!nfs_verify_server_address(sap
))
1882 goto out_no_address
;
1884 if (!(data
->flags
& NFS_MOUNT_TCP
))
1885 args
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1886 /* N.B. caller will free nfs_server.hostname in all cases */
1887 args
->nfs_server
.hostname
= kstrdup(data
->hostname
, GFP_KERNEL
);
1888 args
->namlen
= data
->namlen
;
1889 args
->bsize
= data
->bsize
;
1891 if (data
->flags
& NFS_MOUNT_SECFLAVOUR
)
1892 args
->auth_flavors
[0] = data
->pseudoflavor
;
1893 if (!args
->nfs_server
.hostname
)
1896 if (!(data
->flags
& NFS_MOUNT_NONLM
))
1897 args
->flags
&= ~(NFS_MOUNT_LOCAL_FLOCK
|
1898 NFS_MOUNT_LOCAL_FCNTL
);
1900 args
->flags
|= (NFS_MOUNT_LOCAL_FLOCK
|
1901 NFS_MOUNT_LOCAL_FCNTL
);
1903 * The legacy version 6 binary mount data from userspace has a
1904 * field used only to transport selinux information into the
1905 * the kernel. To continue to support that functionality we
1906 * have a touch of selinux knowledge here in the NFS code. The
1907 * userspace code converted context=blah to just blah so we are
1908 * converting back to the full string selinux understands.
1910 if (data
->context
[0]){
1911 #ifdef CONFIG_SECURITY_SELINUX
1913 char *opts_str
= kmalloc(sizeof(data
->context
) + 8, GFP_KERNEL
);
1916 strcpy(opts_str
, "context=");
1917 data
->context
[NFS_MAX_CONTEXT_LEN
] = '\0';
1918 strcat(opts_str
, &data
->context
[0]);
1919 rc
= security_sb_parse_opts_str(opts_str
, &args
->lsm_opts
);
1932 if (nfs_parse_mount_options((char *)options
, args
) == 0)
1935 if (!nfs_verify_server_address(sap
))
1936 goto out_no_address
;
1938 if (args
->version
== 4)
1939 #ifdef CONFIG_NFS_V4
1940 return nfs4_validate_text_mount_data(options
,
1943 goto out_v4_not_compiled
;
1946 nfs_set_port(sap
, &args
->nfs_server
.port
, 0);
1948 nfs_set_mount_transport_protocol(args
);
1950 status
= nfs_parse_devname(dev_name
,
1951 &args
->nfs_server
.hostname
,
1953 &args
->nfs_server
.export_path
,
1956 status
= nfs_try_mount(args
, mntfh
);
1958 kfree(args
->nfs_server
.export_path
);
1959 args
->nfs_server
.export_path
= NULL
;
1968 #ifndef CONFIG_NFS_V3
1969 if (args
->version
== 3)
1970 goto out_v3_not_compiled
;
1971 #endif /* !CONFIG_NFS_V3 */
1976 dfprintk(MOUNT
, "NFS: mount program didn't pass any mount data\n");
1980 dfprintk(MOUNT
, "NFS: nfs_mount_data version %d does not support v3\n",
1985 dfprintk(MOUNT
, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1988 #ifndef CONFIG_NFS_V3
1989 out_v3_not_compiled
:
1990 dfprintk(MOUNT
, "NFS: NFSv3 is not compiled into kernel\n");
1991 return -EPROTONOSUPPORT
;
1992 #endif /* !CONFIG_NFS_V3 */
1994 #ifndef CONFIG_NFS_V4
1995 out_v4_not_compiled
:
1996 dfprintk(MOUNT
, "NFS: NFSv4 is not compiled into kernel\n");
1997 return -EPROTONOSUPPORT
;
1998 #endif /* !CONFIG_NFS_V4 */
2001 dfprintk(MOUNT
, "NFS: not enough memory to handle mount options\n");
2005 dfprintk(MOUNT
, "NFS: mount program didn't pass remote address\n");
2009 dfprintk(MOUNT
, "NFS: invalid root filehandle\n");
2014 nfs_compare_remount_data(struct nfs_server
*nfss
,
2015 struct nfs_parsed_mount_data
*data
)
2017 if (data
->flags
!= nfss
->flags
||
2018 data
->rsize
!= nfss
->rsize
||
2019 data
->wsize
!= nfss
->wsize
||
2020 data
->retrans
!= nfss
->client
->cl_timeout
->to_retries
||
2021 data
->auth_flavors
[0] != nfss
->client
->cl_auth
->au_flavor
||
2022 data
->acregmin
!= nfss
->acregmin
/ HZ
||
2023 data
->acregmax
!= nfss
->acregmax
/ HZ
||
2024 data
->acdirmin
!= nfss
->acdirmin
/ HZ
||
2025 data
->acdirmax
!= nfss
->acdirmax
/ HZ
||
2026 data
->timeo
!= (10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
) ||
2027 data
->nfs_server
.port
!= nfss
->port
||
2028 data
->nfs_server
.addrlen
!= nfss
->nfs_client
->cl_addrlen
||
2029 !rpc_cmp_addr((struct sockaddr
*)&data
->nfs_server
.address
,
2030 (struct sockaddr
*)&nfss
->nfs_client
->cl_addr
))
2037 nfs_remount(struct super_block
*sb
, int *flags
, char *raw_data
)
2040 struct nfs_server
*nfss
= sb
->s_fs_info
;
2041 struct nfs_parsed_mount_data
*data
;
2042 struct nfs_mount_data
*options
= (struct nfs_mount_data
*)raw_data
;
2043 struct nfs4_mount_data
*options4
= (struct nfs4_mount_data
*)raw_data
;
2044 u32 nfsvers
= nfss
->nfs_client
->rpc_ops
->version
;
2047 * Userspace mount programs that send binary options generally send
2048 * them populated with default values. We have no way to know which
2049 * ones were explicitly specified. Fall back to legacy behavior and
2050 * just return success.
2052 if ((nfsvers
== 4 && (!options4
|| options4
->version
== 1)) ||
2053 (nfsvers
<= 3 && (!options
|| (options
->version
>= 1 &&
2054 options
->version
<= 6))))
2057 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
2061 /* fill out struct with values from existing mount */
2062 data
->flags
= nfss
->flags
;
2063 data
->rsize
= nfss
->rsize
;
2064 data
->wsize
= nfss
->wsize
;
2065 data
->retrans
= nfss
->client
->cl_timeout
->to_retries
;
2066 data
->auth_flavors
[0] = nfss
->client
->cl_auth
->au_flavor
;
2067 data
->acregmin
= nfss
->acregmin
/ HZ
;
2068 data
->acregmax
= nfss
->acregmax
/ HZ
;
2069 data
->acdirmin
= nfss
->acdirmin
/ HZ
;
2070 data
->acdirmax
= nfss
->acdirmax
/ HZ
;
2071 data
->timeo
= 10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
;
2072 data
->nfs_server
.port
= nfss
->port
;
2073 data
->nfs_server
.addrlen
= nfss
->nfs_client
->cl_addrlen
;
2074 memcpy(&data
->nfs_server
.address
, &nfss
->nfs_client
->cl_addr
,
2075 data
->nfs_server
.addrlen
);
2077 /* overwrite those values with any that were specified */
2078 error
= nfs_parse_mount_options((char *)options
, data
);
2082 /* compare new mount options with old ones */
2083 error
= nfs_compare_remount_data(nfss
, data
);
2090 * Initialise the common bits of the superblock
2092 static inline void nfs_initialise_sb(struct super_block
*sb
)
2094 struct nfs_server
*server
= NFS_SB(sb
);
2096 sb
->s_magic
= NFS_SUPER_MAGIC
;
2098 /* We probably want something more informative here */
2099 snprintf(sb
->s_id
, sizeof(sb
->s_id
),
2100 "%x:%x", MAJOR(sb
->s_dev
), MINOR(sb
->s_dev
));
2102 if (sb
->s_blocksize
== 0)
2103 sb
->s_blocksize
= nfs_block_bits(server
->wsize
,
2104 &sb
->s_blocksize_bits
);
2106 if (server
->flags
& NFS_MOUNT_NOAC
)
2107 sb
->s_flags
|= MS_SYNCHRONOUS
;
2109 sb
->s_bdi
= &server
->backing_dev_info
;
2111 nfs_super_set_maxbytes(sb
, server
->maxfilesize
);
2115 * Finish setting up an NFS2/3 superblock
2117 static void nfs_fill_super(struct super_block
*sb
,
2118 struct nfs_parsed_mount_data
*data
)
2120 struct nfs_server
*server
= NFS_SB(sb
);
2122 sb
->s_blocksize_bits
= 0;
2123 sb
->s_blocksize
= 0;
2125 sb
->s_blocksize
= nfs_block_size(data
->bsize
, &sb
->s_blocksize_bits
);
2127 if (server
->nfs_client
->rpc_ops
->version
== 3) {
2128 /* The VFS shouldn't apply the umask to mode bits. We will do
2129 * so ourselves when necessary.
2131 sb
->s_flags
|= MS_POSIXACL
;
2132 sb
->s_time_gran
= 1;
2135 sb
->s_op
= &nfs_sops
;
2136 nfs_initialise_sb(sb
);
2140 * Finish setting up a cloned NFS2/3 superblock
2142 static void nfs_clone_super(struct super_block
*sb
,
2143 const struct super_block
*old_sb
)
2145 struct nfs_server
*server
= NFS_SB(sb
);
2147 sb
->s_blocksize_bits
= old_sb
->s_blocksize_bits
;
2148 sb
->s_blocksize
= old_sb
->s_blocksize
;
2149 sb
->s_maxbytes
= old_sb
->s_maxbytes
;
2151 if (server
->nfs_client
->rpc_ops
->version
== 3) {
2152 /* The VFS shouldn't apply the umask to mode bits. We will do
2153 * so ourselves when necessary.
2155 sb
->s_flags
|= MS_POSIXACL
;
2156 sb
->s_time_gran
= 1;
2159 sb
->s_op
= old_sb
->s_op
;
2160 nfs_initialise_sb(sb
);
2163 static int nfs_compare_mount_options(const struct super_block
*s
, const struct nfs_server
*b
, int flags
)
2165 const struct nfs_server
*a
= s
->s_fs_info
;
2166 const struct rpc_clnt
*clnt_a
= a
->client
;
2167 const struct rpc_clnt
*clnt_b
= b
->client
;
2169 if ((s
->s_flags
& NFS_MS_MASK
) != (flags
& NFS_MS_MASK
))
2171 if (a
->nfs_client
!= b
->nfs_client
)
2173 if (a
->flags
!= b
->flags
)
2175 if (a
->wsize
!= b
->wsize
)
2177 if (a
->rsize
!= b
->rsize
)
2179 if (a
->acregmin
!= b
->acregmin
)
2181 if (a
->acregmax
!= b
->acregmax
)
2183 if (a
->acdirmin
!= b
->acdirmin
)
2185 if (a
->acdirmax
!= b
->acdirmax
)
2187 if (clnt_a
->cl_auth
->au_flavor
!= clnt_b
->cl_auth
->au_flavor
)
2194 struct nfs_sb_mountdata
{
2195 struct nfs_server
*server
;
2199 static int nfs_set_super(struct super_block
*s
, void *data
)
2201 struct nfs_sb_mountdata
*sb_mntdata
= data
;
2202 struct nfs_server
*server
= sb_mntdata
->server
;
2205 s
->s_flags
= sb_mntdata
->mntflags
;
2206 s
->s_fs_info
= server
;
2207 ret
= set_anon_super(s
, server
);
2209 server
->s_dev
= s
->s_dev
;
2213 static int nfs_compare_super_address(struct nfs_server
*server1
,
2214 struct nfs_server
*server2
)
2216 struct sockaddr
*sap1
, *sap2
;
2218 sap1
= (struct sockaddr
*)&server1
->nfs_client
->cl_addr
;
2219 sap2
= (struct sockaddr
*)&server2
->nfs_client
->cl_addr
;
2221 if (sap1
->sa_family
!= sap2
->sa_family
)
2224 switch (sap1
->sa_family
) {
2226 struct sockaddr_in
*sin1
= (struct sockaddr_in
*)sap1
;
2227 struct sockaddr_in
*sin2
= (struct sockaddr_in
*)sap2
;
2228 if (sin1
->sin_addr
.s_addr
!= sin2
->sin_addr
.s_addr
)
2230 if (sin1
->sin_port
!= sin2
->sin_port
)
2235 struct sockaddr_in6
*sin1
= (struct sockaddr_in6
*)sap1
;
2236 struct sockaddr_in6
*sin2
= (struct sockaddr_in6
*)sap2
;
2237 if (!ipv6_addr_equal(&sin1
->sin6_addr
, &sin2
->sin6_addr
))
2239 if (sin1
->sin6_port
!= sin2
->sin6_port
)
2250 static int nfs_compare_super(struct super_block
*sb
, void *data
)
2252 struct nfs_sb_mountdata
*sb_mntdata
= data
;
2253 struct nfs_server
*server
= sb_mntdata
->server
, *old
= NFS_SB(sb
);
2254 int mntflags
= sb_mntdata
->mntflags
;
2256 if (!nfs_compare_super_address(old
, server
))
2258 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2259 if (old
->flags
& NFS_MOUNT_UNSHARED
)
2261 if (memcmp(&old
->fsid
, &server
->fsid
, sizeof(old
->fsid
)) != 0)
2263 return nfs_compare_mount_options(sb
, server
, mntflags
);
2266 static int nfs_bdi_register(struct nfs_server
*server
)
2268 return bdi_register_dev(&server
->backing_dev_info
, server
->s_dev
);
2271 static int nfs_get_sb(struct file_system_type
*fs_type
,
2272 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
2274 struct nfs_server
*server
= NULL
;
2275 struct super_block
*s
;
2276 struct nfs_parsed_mount_data
*data
;
2277 struct nfs_fh
*mntfh
;
2278 struct dentry
*mntroot
;
2279 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2280 struct nfs_sb_mountdata sb_mntdata
= {
2283 int error
= -ENOMEM
;
2285 data
= nfs_alloc_parsed_mount_data(NFS_DEFAULT_VERSION
);
2286 mntfh
= nfs_alloc_fhandle();
2287 if (data
== NULL
|| mntfh
== NULL
)
2290 security_init_mnt_opts(&data
->lsm_opts
);
2292 /* Validate the mount data */
2293 error
= nfs_validate_mount_data(raw_data
, data
, mntfh
, dev_name
);
2297 #ifdef CONFIG_NFS_V4
2298 if (data
->version
== 4) {
2299 error
= nfs4_try_mount(flags
, dev_name
, data
, mnt
);
2300 kfree(data
->client_address
);
2301 kfree(data
->nfs_server
.export_path
);
2304 #endif /* CONFIG_NFS_V4 */
2306 /* Get a volume representation */
2307 server
= nfs_create_server(data
, mntfh
);
2308 if (IS_ERR(server
)) {
2309 error
= PTR_ERR(server
);
2312 sb_mntdata
.server
= server
;
2314 if (server
->flags
& NFS_MOUNT_UNSHARED
)
2315 compare_super
= NULL
;
2317 /* Get a superblock - note that we may end up sharing one that already exists */
2318 s
= sget(fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2324 if (s
->s_fs_info
!= server
) {
2325 nfs_free_server(server
);
2328 error
= nfs_bdi_register(server
);
2330 goto error_splat_bdi
;
2334 /* initial superblock/root creation */
2335 nfs_fill_super(s
, data
);
2336 nfs_fscache_get_super_cookie(
2337 s
, data
? data
->fscache_uniq
: NULL
, NULL
);
2340 mntroot
= nfs_get_root(s
, mntfh
);
2341 if (IS_ERR(mntroot
)) {
2342 error
= PTR_ERR(mntroot
);
2343 goto error_splat_super
;
2346 error
= security_sb_set_mnt_opts(s
, &data
->lsm_opts
);
2348 goto error_splat_root
;
2350 s
->s_flags
|= MS_ACTIVE
;
2352 mnt
->mnt_root
= mntroot
;
2356 kfree(data
->nfs_server
.hostname
);
2357 kfree(data
->mount_server
.hostname
);
2358 kfree(data
->fscache_uniq
);
2359 security_free_mnt_opts(&data
->lsm_opts
);
2361 nfs_free_fhandle(mntfh
);
2366 nfs_free_server(server
);
2372 if (server
&& !s
->s_root
)
2373 bdi_unregister(&server
->backing_dev_info
);
2375 deactivate_locked_super(s
);
2380 * Ensure that we unregister the bdi before kill_anon_super
2381 * releases the device name
2383 static void nfs_put_super(struct super_block
*s
)
2385 struct nfs_server
*server
= NFS_SB(s
);
2387 bdi_unregister(&server
->backing_dev_info
);
2391 * Destroy an NFS2/3 superblock
2393 static void nfs_kill_super(struct super_block
*s
)
2395 struct nfs_server
*server
= NFS_SB(s
);
2398 nfs_fscache_release_super_cookie(s
);
2399 nfs_free_server(server
);
2403 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2405 static struct dentry
*
2406 nfs_xdev_mount(struct file_system_type
*fs_type
, int flags
,
2407 const char *dev_name
, void *raw_data
)
2409 struct nfs_clone_mount
*data
= raw_data
;
2410 struct super_block
*s
;
2411 struct nfs_server
*server
;
2412 struct dentry
*mntroot
;
2413 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2414 struct nfs_sb_mountdata sb_mntdata
= {
2419 dprintk("--> nfs_xdev_mount()\n");
2421 /* create a new volume representation */
2422 server
= nfs_clone_server(NFS_SB(data
->sb
), data
->fh
, data
->fattr
);
2423 if (IS_ERR(server
)) {
2424 error
= PTR_ERR(server
);
2425 goto out_err_noserver
;
2427 sb_mntdata
.server
= server
;
2429 if (server
->flags
& NFS_MOUNT_UNSHARED
)
2430 compare_super
= NULL
;
2432 /* Get a superblock - note that we may end up sharing one that already exists */
2433 s
= sget(&nfs_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2439 if (s
->s_fs_info
!= server
) {
2440 nfs_free_server(server
);
2443 error
= nfs_bdi_register(server
);
2445 goto error_splat_bdi
;
2449 /* initial superblock/root creation */
2450 nfs_clone_super(s
, data
->sb
);
2451 nfs_fscache_get_super_cookie(s
, NULL
, data
);
2454 mntroot
= nfs_get_root(s
, data
->fh
);
2455 if (IS_ERR(mntroot
)) {
2456 error
= PTR_ERR(mntroot
);
2457 goto error_splat_super
;
2459 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
2462 goto error_splat_super
;
2465 s
->s_flags
|= MS_ACTIVE
;
2467 /* clone any lsm security options from the parent to the new sb */
2468 security_sb_clone_mnt_opts(data
->sb
, s
);
2470 dprintk("<-- nfs_xdev_mount() = 0\n");
2474 nfs_free_server(server
);
2476 dprintk("<-- nfs_xdev_mount() = %d [error]\n", error
);
2477 return ERR_PTR(error
);
2480 if (server
&& !s
->s_root
)
2481 bdi_unregister(&server
->backing_dev_info
);
2483 deactivate_locked_super(s
);
2484 dprintk("<-- nfs_xdev_mount() = %d [splat]\n", error
);
2485 return ERR_PTR(error
);
2488 #ifdef CONFIG_NFS_V4
2491 * Finish setting up a cloned NFS4 superblock
2493 static void nfs4_clone_super(struct super_block
*sb
,
2494 const struct super_block
*old_sb
)
2496 sb
->s_blocksize_bits
= old_sb
->s_blocksize_bits
;
2497 sb
->s_blocksize
= old_sb
->s_blocksize
;
2498 sb
->s_maxbytes
= old_sb
->s_maxbytes
;
2499 sb
->s_time_gran
= 1;
2500 sb
->s_op
= old_sb
->s_op
;
2501 nfs_initialise_sb(sb
);
2505 * Set up an NFS4 superblock
2507 static void nfs4_fill_super(struct super_block
*sb
)
2509 sb
->s_time_gran
= 1;
2510 sb
->s_op
= &nfs4_sops
;
2511 nfs_initialise_sb(sb
);
2514 static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data
*args
)
2516 args
->flags
&= ~(NFS_MOUNT_NONLM
|NFS_MOUNT_NOACL
|NFS_MOUNT_VER3
|
2517 NFS_MOUNT_LOCAL_FLOCK
|NFS_MOUNT_LOCAL_FCNTL
);
2520 static int nfs4_validate_text_mount_data(void *options
,
2521 struct nfs_parsed_mount_data
*args
,
2522 const char *dev_name
)
2524 struct sockaddr
*sap
= (struct sockaddr
*)&args
->nfs_server
.address
;
2526 nfs_set_port(sap
, &args
->nfs_server
.port
, NFS_PORT
);
2528 nfs_validate_transport_protocol(args
);
2530 nfs4_validate_mount_flags(args
);
2532 if (args
->version
!= 4) {
2534 "NFS4: Illegal mount version\n");
2538 if (args
->auth_flavor_len
> 1) {
2540 "NFS4: Too many RPC auth flavours specified\n");
2544 if (args
->client_address
== NULL
) {
2546 "NFS4: mount program didn't pass callback address\n");
2550 return nfs_parse_devname(dev_name
,
2551 &args
->nfs_server
.hostname
,
2553 &args
->nfs_server
.export_path
,
2558 * Validate NFSv4 mount options
2560 static int nfs4_validate_mount_data(void *options
,
2561 struct nfs_parsed_mount_data
*args
,
2562 const char *dev_name
)
2564 struct sockaddr
*sap
= (struct sockaddr
*)&args
->nfs_server
.address
;
2565 struct nfs4_mount_data
*data
= (struct nfs4_mount_data
*)options
;
2571 switch (data
->version
) {
2573 if (data
->host_addrlen
> sizeof(args
->nfs_server
.address
))
2574 goto out_no_address
;
2575 if (data
->host_addrlen
== 0)
2576 goto out_no_address
;
2577 args
->nfs_server
.addrlen
= data
->host_addrlen
;
2578 if (copy_from_user(sap
, data
->host_addr
, data
->host_addrlen
))
2580 if (!nfs_verify_server_address(sap
))
2581 goto out_no_address
;
2583 if (data
->auth_flavourlen
) {
2584 if (data
->auth_flavourlen
> 1)
2585 goto out_inval_auth
;
2586 if (copy_from_user(&args
->auth_flavors
[0],
2587 data
->auth_flavours
,
2588 sizeof(args
->auth_flavors
[0])))
2592 c
= strndup_user(data
->hostname
.data
, NFS4_MAXNAMLEN
);
2595 args
->nfs_server
.hostname
= c
;
2597 c
= strndup_user(data
->mnt_path
.data
, NFS4_MAXPATHLEN
);
2600 args
->nfs_server
.export_path
= c
;
2601 dfprintk(MOUNT
, "NFS: MNTPATH: '%s'\n", c
);
2603 c
= strndup_user(data
->client_addr
.data
, 16);
2606 args
->client_address
= c
;
2609 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2613 args
->flags
= data
->flags
& NFS4_MOUNT_FLAGMASK
;
2614 args
->rsize
= data
->rsize
;
2615 args
->wsize
= data
->wsize
;
2616 args
->timeo
= data
->timeo
;
2617 args
->retrans
= data
->retrans
;
2618 args
->acregmin
= data
->acregmin
;
2619 args
->acregmax
= data
->acregmax
;
2620 args
->acdirmin
= data
->acdirmin
;
2621 args
->acdirmax
= data
->acdirmax
;
2622 args
->nfs_server
.protocol
= data
->proto
;
2623 nfs_validate_transport_protocol(args
);
2627 if (nfs_parse_mount_options((char *)options
, args
) == 0)
2630 if (!nfs_verify_server_address(sap
))
2633 return nfs4_validate_text_mount_data(options
, args
, dev_name
);
2639 dfprintk(MOUNT
, "NFS4: mount program didn't pass any mount data\n");
2643 dfprintk(MOUNT
, "NFS4: Invalid number of RPC auth flavours %d\n",
2644 data
->auth_flavourlen
);
2648 dfprintk(MOUNT
, "NFS4: mount program didn't pass remote address\n");
2653 * Get the superblock for the NFS4 root partition
2655 static struct dentry
*
2656 nfs4_remote_mount(struct file_system_type
*fs_type
, int flags
,
2657 const char *dev_name
, void *raw_data
)
2659 struct nfs_parsed_mount_data
*data
= raw_data
;
2660 struct super_block
*s
;
2661 struct nfs_server
*server
;
2662 struct nfs_fh
*mntfh
;
2663 struct dentry
*mntroot
;
2664 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2665 struct nfs_sb_mountdata sb_mntdata
= {
2668 int error
= -ENOMEM
;
2670 mntfh
= nfs_alloc_fhandle();
2671 if (data
== NULL
|| mntfh
== NULL
)
2674 security_init_mnt_opts(&data
->lsm_opts
);
2676 /* Get a volume representation */
2677 server
= nfs4_create_server(data
, mntfh
);
2678 if (IS_ERR(server
)) {
2679 error
= PTR_ERR(server
);
2682 sb_mntdata
.server
= server
;
2684 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2685 compare_super
= NULL
;
2687 /* Get a superblock - note that we may end up sharing one that already exists */
2688 s
= sget(&nfs4_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2694 if (s
->s_fs_info
!= server
) {
2695 nfs_free_server(server
);
2698 error
= nfs_bdi_register(server
);
2700 goto error_splat_bdi
;
2704 /* initial superblock/root creation */
2706 nfs_fscache_get_super_cookie(
2707 s
, data
? data
->fscache_uniq
: NULL
, NULL
);
2710 mntroot
= nfs4_get_root(s
, mntfh
);
2711 if (IS_ERR(mntroot
)) {
2712 error
= PTR_ERR(mntroot
);
2713 goto error_splat_super
;
2716 error
= security_sb_set_mnt_opts(s
, &data
->lsm_opts
);
2718 goto error_splat_root
;
2720 s
->s_flags
|= MS_ACTIVE
;
2722 security_free_mnt_opts(&data
->lsm_opts
);
2723 nfs_free_fhandle(mntfh
);
2727 security_free_mnt_opts(&data
->lsm_opts
);
2729 nfs_free_fhandle(mntfh
);
2730 return ERR_PTR(error
);
2733 nfs_free_server(server
);
2739 if (server
&& !s
->s_root
)
2740 bdi_unregister(&server
->backing_dev_info
);
2742 deactivate_locked_super(s
);
2746 static struct vfsmount
*nfs_do_root_mount(struct file_system_type
*fs_type
,
2747 int flags
, void *data
, const char *hostname
)
2749 struct vfsmount
*root_mnt
;
2753 len
= strlen(hostname
) + 3;
2754 root_devname
= kmalloc(len
, GFP_KERNEL
);
2755 if (root_devname
== NULL
)
2756 return ERR_PTR(-ENOMEM
);
2757 snprintf(root_devname
, len
, "%s:/", hostname
);
2758 root_mnt
= vfs_kern_mount(fs_type
, flags
, root_devname
, data
);
2759 kfree(root_devname
);
2763 static void nfs_fix_devname(const struct path
*path
, struct vfsmount
*mnt
)
2765 char *page
= (char *) __get_free_page(GFP_KERNEL
);
2766 char *devname
, *tmp
;
2770 devname
= nfs_path(path
->mnt
->mnt_devname
,
2771 path
->mnt
->mnt_root
, path
->dentry
,
2773 if (IS_ERR(devname
))
2775 tmp
= kstrdup(devname
, GFP_KERNEL
);
2778 kfree(mnt
->mnt_devname
);
2779 mnt
->mnt_devname
= tmp
;
2781 free_page((unsigned long)page
);
2784 struct nfs_referral_count
{
2785 struct list_head list
;
2786 const struct task_struct
*task
;
2787 unsigned int referral_count
;
2790 static LIST_HEAD(nfs_referral_count_list
);
2791 static DEFINE_SPINLOCK(nfs_referral_count_list_lock
);
2793 static struct nfs_referral_count
*nfs_find_referral_count(void)
2795 struct nfs_referral_count
*p
;
2797 list_for_each_entry(p
, &nfs_referral_count_list
, list
) {
2798 if (p
->task
== current
)
2804 #define NFS_MAX_NESTED_REFERRALS 2
2806 static int nfs_referral_loop_protect(void)
2808 struct nfs_referral_count
*p
, *new;
2811 new = kmalloc(sizeof(*new), GFP_KERNEL
);
2814 new->task
= current
;
2815 new->referral_count
= 1;
2818 spin_lock(&nfs_referral_count_list_lock
);
2819 p
= nfs_find_referral_count();
2821 if (p
->referral_count
>= NFS_MAX_NESTED_REFERRALS
)
2824 p
->referral_count
++;
2826 list_add(&new->list
, &nfs_referral_count_list
);
2829 spin_unlock(&nfs_referral_count_list_lock
);
2835 static void nfs_referral_loop_unprotect(void)
2837 struct nfs_referral_count
*p
;
2839 spin_lock(&nfs_referral_count_list_lock
);
2840 p
= nfs_find_referral_count();
2841 p
->referral_count
--;
2842 if (p
->referral_count
== 0)
2846 spin_unlock(&nfs_referral_count_list_lock
);
2850 static int nfs_follow_remote_path(struct vfsmount
*root_mnt
,
2851 const char *export_path
, struct vfsmount
*mnt_target
)
2853 struct nameidata
*nd
= NULL
;
2854 struct mnt_namespace
*ns_private
;
2855 struct super_block
*s
;
2858 nd
= kmalloc(sizeof(*nd
), GFP_KERNEL
);
2862 ns_private
= create_mnt_ns(root_mnt
);
2863 ret
= PTR_ERR(ns_private
);
2864 if (IS_ERR(ns_private
))
2867 ret
= nfs_referral_loop_protect();
2869 goto out_put_mnt_ns
;
2871 ret
= vfs_path_lookup(root_mnt
->mnt_root
, root_mnt
,
2872 export_path
, LOOKUP_FOLLOW
, nd
);
2874 nfs_referral_loop_unprotect();
2875 put_mnt_ns(ns_private
);
2880 s
= nd
->path
.mnt
->mnt_sb
;
2881 atomic_inc(&s
->s_active
);
2882 mnt_target
->mnt_sb
= s
;
2883 mnt_target
->mnt_root
= dget(nd
->path
.dentry
);
2885 /* Correct the device pathname */
2886 nfs_fix_devname(&nd
->path
, mnt_target
);
2888 path_put(&nd
->path
);
2890 down_write(&s
->s_umount
);
2893 put_mnt_ns(ns_private
);
2901 static int nfs4_try_mount(int flags
, const char *dev_name
,
2902 struct nfs_parsed_mount_data
*data
,
2903 struct vfsmount
*mnt
)
2906 struct vfsmount
*root_mnt
;
2909 dfprintk(MOUNT
, "--> nfs4_try_mount()\n");
2911 export_path
= data
->nfs_server
.export_path
;
2912 data
->nfs_server
.export_path
= "/";
2913 root_mnt
= nfs_do_root_mount(&nfs4_remote_fs_type
, flags
, data
,
2914 data
->nfs_server
.hostname
);
2915 data
->nfs_server
.export_path
= export_path
;
2917 error
= PTR_ERR(root_mnt
);
2918 if (IS_ERR(root_mnt
))
2921 error
= nfs_follow_remote_path(root_mnt
, export_path
, mnt
);
2924 dfprintk(MOUNT
, "<-- nfs4_try_mount() = %d%s\n", error
,
2925 error
!= 0 ? " [error]" : "");
2930 * Get the superblock for an NFS4 mountpoint
2932 static int nfs4_get_sb(struct file_system_type
*fs_type
,
2933 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
2935 struct nfs_parsed_mount_data
*data
;
2936 int error
= -ENOMEM
;
2938 data
= nfs_alloc_parsed_mount_data(4);
2942 /* Validate the mount data */
2943 error
= nfs4_validate_mount_data(raw_data
, data
, dev_name
);
2947 error
= nfs4_try_mount(flags
, dev_name
, data
, mnt
);
2950 kfree(data
->client_address
);
2951 kfree(data
->nfs_server
.export_path
);
2952 kfree(data
->nfs_server
.hostname
);
2953 kfree(data
->fscache_uniq
);
2956 dprintk("<-- nfs4_get_sb() = %d%s\n", error
,
2957 error
!= 0 ? " [error]" : "");
2961 static void nfs4_kill_super(struct super_block
*sb
)
2963 struct nfs_server
*server
= NFS_SB(sb
);
2965 dprintk("--> %s\n", __func__
);
2966 nfs_super_return_all_delegations(sb
);
2967 kill_anon_super(sb
);
2968 nfs_fscache_release_super_cookie(sb
);
2969 nfs_free_server(server
);
2970 dprintk("<-- %s\n", __func__
);
2974 * Clone an NFS4 server record on xdev traversal (FSID-change)
2976 static struct dentry
*
2977 nfs4_xdev_mount(struct file_system_type
*fs_type
, int flags
,
2978 const char *dev_name
, void *raw_data
)
2980 struct nfs_clone_mount
*data
= raw_data
;
2981 struct super_block
*s
;
2982 struct nfs_server
*server
;
2983 struct dentry
*mntroot
;
2984 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2985 struct nfs_sb_mountdata sb_mntdata
= {
2990 dprintk("--> nfs4_xdev_mount()\n");
2992 /* create a new volume representation */
2993 server
= nfs_clone_server(NFS_SB(data
->sb
), data
->fh
, data
->fattr
);
2994 if (IS_ERR(server
)) {
2995 error
= PTR_ERR(server
);
2996 goto out_err_noserver
;
2998 sb_mntdata
.server
= server
;
3000 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
3001 compare_super
= NULL
;
3003 /* Get a superblock - note that we may end up sharing one that already exists */
3004 s
= sget(&nfs4_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
3010 if (s
->s_fs_info
!= server
) {
3011 nfs_free_server(server
);
3014 error
= nfs_bdi_register(server
);
3016 goto error_splat_bdi
;
3020 /* initial superblock/root creation */
3021 nfs4_clone_super(s
, data
->sb
);
3022 nfs_fscache_get_super_cookie(s
, NULL
, data
);
3025 mntroot
= nfs4_get_root(s
, data
->fh
);
3026 if (IS_ERR(mntroot
)) {
3027 error
= PTR_ERR(mntroot
);
3028 goto error_splat_super
;
3030 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
3033 goto error_splat_super
;
3036 s
->s_flags
|= MS_ACTIVE
;
3038 security_sb_clone_mnt_opts(data
->sb
, s
);
3040 dprintk("<-- nfs4_xdev_mount() = 0\n");
3044 nfs_free_server(server
);
3046 dprintk("<-- nfs4_xdev_mount() = %d [error]\n", error
);
3047 return ERR_PTR(error
);
3050 if (server
&& !s
->s_root
)
3051 bdi_unregister(&server
->backing_dev_info
);
3053 deactivate_locked_super(s
);
3054 dprintk("<-- nfs4_xdev_mount() = %d [splat]\n", error
);
3055 return ERR_PTR(error
);
3058 static struct dentry
*
3059 nfs4_remote_referral_mount(struct file_system_type
*fs_type
, int flags
,
3060 const char *dev_name
, void *raw_data
)
3062 struct nfs_clone_mount
*data
= raw_data
;
3063 struct super_block
*s
;
3064 struct nfs_server
*server
;
3065 struct dentry
*mntroot
;
3066 struct nfs_fh
*mntfh
;
3067 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
3068 struct nfs_sb_mountdata sb_mntdata
= {
3071 int error
= -ENOMEM
;
3073 dprintk("--> nfs4_referral_get_sb()\n");
3075 mntfh
= nfs_alloc_fhandle();
3079 /* create a new volume representation */
3080 server
= nfs4_create_referral_server(data
, mntfh
);
3081 if (IS_ERR(server
)) {
3082 error
= PTR_ERR(server
);
3083 goto out_err_noserver
;
3085 sb_mntdata
.server
= server
;
3087 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
3088 compare_super
= NULL
;
3090 /* Get a superblock - note that we may end up sharing one that already exists */
3091 s
= sget(&nfs4_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
3097 if (s
->s_fs_info
!= server
) {
3098 nfs_free_server(server
);
3101 error
= nfs_bdi_register(server
);
3103 goto error_splat_bdi
;
3107 /* initial superblock/root creation */
3109 nfs_fscache_get_super_cookie(s
, NULL
, data
);
3112 mntroot
= nfs4_get_root(s
, mntfh
);
3113 if (IS_ERR(mntroot
)) {
3114 error
= PTR_ERR(mntroot
);
3115 goto error_splat_super
;
3117 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
3120 goto error_splat_super
;
3123 s
->s_flags
|= MS_ACTIVE
;
3125 security_sb_clone_mnt_opts(data
->sb
, s
);
3127 nfs_free_fhandle(mntfh
);
3128 dprintk("<-- nfs4_referral_get_sb() = 0\n");
3132 nfs_free_server(server
);
3134 nfs_free_fhandle(mntfh
);
3136 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error
);
3137 return ERR_PTR(error
);
3140 if (server
&& !s
->s_root
)
3141 bdi_unregister(&server
->backing_dev_info
);
3143 deactivate_locked_super(s
);
3144 nfs_free_fhandle(mntfh
);
3145 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error
);
3146 return ERR_PTR(error
);
3150 * Create an NFS4 server record on referral traversal
3152 static int nfs4_referral_get_sb(struct file_system_type
*fs_type
,
3153 int flags
, const char *dev_name
, void *raw_data
,
3154 struct vfsmount
*mnt
)
3156 struct nfs_clone_mount
*data
= raw_data
;
3158 struct vfsmount
*root_mnt
;
3161 dprintk("--> nfs4_referral_get_sb()\n");
3163 export_path
= data
->mnt_path
;
3164 data
->mnt_path
= "/";
3166 root_mnt
= nfs_do_root_mount(&nfs4_remote_referral_fs_type
,
3167 flags
, data
, data
->hostname
);
3168 data
->mnt_path
= export_path
;
3170 error
= PTR_ERR(root_mnt
);
3171 if (IS_ERR(root_mnt
))
3174 error
= nfs_follow_remote_path(root_mnt
, export_path
, mnt
);
3176 dprintk("<-- nfs4_referral_get_sb() = %d%s\n", error
,
3177 error
!= 0 ? " [error]" : "");
3181 #endif /* CONFIG_NFS_V4 */