4 * Copyright (C) 1992 Rick Sladkey
6 * nfs superblock handling functions
8 * Modularised by Alan Cox <alan@lxorguk.ukuu.org.uk>, while hacking some
9 * experimental NFS changes. Modularisation taken straight from SYS5 fs.
11 * Change to nfs_read_super() to permit NFS mounts to multi-homed hosts.
12 * J.S.Peatfield@damtp.cam.ac.uk
14 * Split from inode.c by David Howells <dhowells@redhat.com>
16 * - superblocks are indexed on server only - all inodes, dentries, etc. associated with a
17 * particular server are held in the same superblock
18 * - NFS superblocks can have several effective roots to the dentry tree
19 * - directory type roots are spliced into the tree when a path from one root reaches the root
20 * of another (see nfs_lookup())
23 #include <linux/module.h>
24 #include <linux/init.h>
26 #include <linux/time.h>
27 #include <linux/kernel.h>
29 #include <linux/string.h>
30 #include <linux/stat.h>
31 #include <linux/errno.h>
32 #include <linux/unistd.h>
33 #include <linux/sunrpc/clnt.h>
34 #include <linux/sunrpc/stats.h>
35 #include <linux/sunrpc/metrics.h>
36 #include <linux/sunrpc/xprtsock.h>
37 #include <linux/sunrpc/xprtrdma.h>
38 #include <linux/nfs_fs.h>
39 #include <linux/nfs_mount.h>
40 #include <linux/nfs4_mount.h>
41 #include <linux/lockd/bind.h>
42 #include <linux/smp_lock.h>
43 #include <linux/seq_file.h>
44 #include <linux/mount.h>
45 #include <linux/mnt_namespace.h>
46 #include <linux/namei.h>
47 #include <linux/nfs_idmap.h>
48 #include <linux/vfs.h>
49 #include <linux/inet.h>
50 #include <linux/in6.h>
52 #include <linux/netdevice.h>
53 #include <linux/nfs_xdr.h>
54 #include <linux/magic.h>
55 #include <linux/parser.h>
57 #include <asm/system.h>
58 #include <asm/uaccess.h>
62 #include "delegation.h"
67 #define NFSDBG_FACILITY NFSDBG_VFS
70 /* Mount options that take no arguments */
72 Opt_posix
, Opt_noposix
,
76 Opt_v2
, Opt_v3
, Opt_v4
,
77 Opt_udp
, Opt_tcp
, Opt_rdma
,
79 Opt_rdirplus
, Opt_nordirplus
,
80 Opt_sharecache
, Opt_nosharecache
,
81 Opt_resvport
, Opt_noresvport
,
82 Opt_fscache
, Opt_nofscache
,
84 /* Mount options that take integer arguments */
86 Opt_rsize
, Opt_wsize
, Opt_bsize
,
87 Opt_timeo
, Opt_retrans
,
88 Opt_acregmin
, Opt_acregmax
,
89 Opt_acdirmin
, Opt_acdirmax
,
97 /* Mount options that take string arguments */
98 Opt_sec
, Opt_proto
, Opt_mountproto
, Opt_mounthost
,
99 Opt_addr
, Opt_mountaddr
, Opt_clientaddr
,
103 /* Special mount options */
104 Opt_userspace
, Opt_deprecated
, Opt_sloppy
,
109 static const match_table_t nfs_mount_option_tokens
= {
110 { Opt_userspace
, "bg" },
111 { Opt_userspace
, "fg" },
112 { Opt_userspace
, "retry=%s" },
114 { Opt_sloppy
, "sloppy" },
116 { Opt_soft
, "soft" },
117 { Opt_hard
, "hard" },
118 { Opt_deprecated
, "intr" },
119 { Opt_deprecated
, "nointr" },
120 { Opt_posix
, "posix" },
121 { Opt_noposix
, "noposix" },
123 { Opt_nocto
, "nocto" },
125 { Opt_noac
, "noac" },
126 { Opt_lock
, "lock" },
127 { Opt_nolock
, "nolock" },
133 { Opt_rdma
, "rdma" },
135 { Opt_noacl
, "noacl" },
136 { Opt_rdirplus
, "rdirplus" },
137 { Opt_nordirplus
, "nordirplus" },
138 { Opt_sharecache
, "sharecache" },
139 { Opt_nosharecache
, "nosharecache" },
140 { Opt_resvport
, "resvport" },
141 { Opt_noresvport
, "noresvport" },
142 { Opt_fscache
, "fsc" },
143 { Opt_fscache_uniq
, "fsc=%s" },
144 { Opt_nofscache
, "nofsc" },
146 { Opt_port
, "port=%s" },
147 { Opt_rsize
, "rsize=%s" },
148 { Opt_wsize
, "wsize=%s" },
149 { Opt_bsize
, "bsize=%s" },
150 { Opt_timeo
, "timeo=%s" },
151 { Opt_retrans
, "retrans=%s" },
152 { Opt_acregmin
, "acregmin=%s" },
153 { Opt_acregmax
, "acregmax=%s" },
154 { Opt_acdirmin
, "acdirmin=%s" },
155 { Opt_acdirmax
, "acdirmax=%s" },
156 { Opt_actimeo
, "actimeo=%s" },
157 { Opt_namelen
, "namlen=%s" },
158 { Opt_mountport
, "mountport=%s" },
159 { Opt_mountvers
, "mountvers=%s" },
160 { Opt_nfsvers
, "nfsvers=%s" },
161 { Opt_nfsvers
, "vers=%s" },
162 { Opt_minorversion
, "minorversion=%s" },
164 { Opt_sec
, "sec=%s" },
165 { Opt_proto
, "proto=%s" },
166 { Opt_mountproto
, "mountproto=%s" },
167 { Opt_addr
, "addr=%s" },
168 { Opt_clientaddr
, "clientaddr=%s" },
169 { Opt_mounthost
, "mounthost=%s" },
170 { Opt_mountaddr
, "mountaddr=%s" },
172 { Opt_lookupcache
, "lookupcache=%s" },
178 Opt_xprt_udp
, Opt_xprt_tcp
, Opt_xprt_rdma
,
183 static const match_table_t nfs_xprt_protocol_tokens
= {
184 { Opt_xprt_udp
, "udp" },
185 { Opt_xprt_tcp
, "tcp" },
186 { Opt_xprt_rdma
, "rdma" },
188 { Opt_xprt_err
, NULL
}
192 Opt_sec_none
, Opt_sec_sys
,
193 Opt_sec_krb5
, Opt_sec_krb5i
, Opt_sec_krb5p
,
194 Opt_sec_lkey
, Opt_sec_lkeyi
, Opt_sec_lkeyp
,
195 Opt_sec_spkm
, Opt_sec_spkmi
, Opt_sec_spkmp
,
200 static const match_table_t nfs_secflavor_tokens
= {
201 { Opt_sec_none
, "none" },
202 { Opt_sec_none
, "null" },
203 { Opt_sec_sys
, "sys" },
205 { Opt_sec_krb5
, "krb5" },
206 { Opt_sec_krb5i
, "krb5i" },
207 { Opt_sec_krb5p
, "krb5p" },
209 { Opt_sec_lkey
, "lkey" },
210 { Opt_sec_lkeyi
, "lkeyi" },
211 { Opt_sec_lkeyp
, "lkeyp" },
213 { Opt_sec_spkm
, "spkm3" },
214 { Opt_sec_spkmi
, "spkm3i" },
215 { Opt_sec_spkmp
, "spkm3p" },
217 { Opt_sec_err
, NULL
}
221 Opt_lookupcache_all
, Opt_lookupcache_positive
,
222 Opt_lookupcache_none
,
227 static match_table_t nfs_lookupcache_tokens
= {
228 { Opt_lookupcache_all
, "all" },
229 { Opt_lookupcache_positive
, "pos" },
230 { Opt_lookupcache_positive
, "positive" },
231 { Opt_lookupcache_none
, "none" },
233 { Opt_lookupcache_err
, NULL
}
237 static void nfs_umount_begin(struct super_block
*);
238 static int nfs_statfs(struct dentry
*, struct kstatfs
*);
239 static int nfs_show_options(struct seq_file
*, struct vfsmount
*);
240 static int nfs_show_stats(struct seq_file
*, struct vfsmount
*);
241 static int nfs_get_sb(struct file_system_type
*, int, const char *, void *, struct vfsmount
*);
242 static int nfs_xdev_get_sb(struct file_system_type
*fs_type
,
243 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
244 static void nfs_put_super(struct super_block
*);
245 static void nfs_kill_super(struct super_block
*);
246 static int nfs_remount(struct super_block
*sb
, int *flags
, char *raw_data
);
248 static struct file_system_type nfs_fs_type
= {
249 .owner
= THIS_MODULE
,
251 .get_sb
= nfs_get_sb
,
252 .kill_sb
= nfs_kill_super
,
253 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
256 struct file_system_type nfs_xdev_fs_type
= {
257 .owner
= THIS_MODULE
,
259 .get_sb
= nfs_xdev_get_sb
,
260 .kill_sb
= nfs_kill_super
,
261 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
264 static const struct super_operations nfs_sops
= {
265 .alloc_inode
= nfs_alloc_inode
,
266 .destroy_inode
= nfs_destroy_inode
,
267 .write_inode
= nfs_write_inode
,
268 .put_super
= nfs_put_super
,
269 .statfs
= nfs_statfs
,
270 .clear_inode
= nfs_clear_inode
,
271 .umount_begin
= nfs_umount_begin
,
272 .show_options
= nfs_show_options
,
273 .show_stats
= nfs_show_stats
,
274 .remount_fs
= nfs_remount
,
278 static int nfs4_validate_text_mount_data(void *options
,
279 struct nfs_parsed_mount_data
*args
, const char *dev_name
);
280 static int nfs4_try_mount(int flags
, const char *dev_name
,
281 struct nfs_parsed_mount_data
*data
, struct vfsmount
*mnt
);
282 static int nfs4_get_sb(struct file_system_type
*fs_type
,
283 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
284 static int nfs4_remote_get_sb(struct file_system_type
*fs_type
,
285 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
286 static int nfs4_xdev_get_sb(struct file_system_type
*fs_type
,
287 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
288 static int nfs4_referral_get_sb(struct file_system_type
*fs_type
,
289 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
290 static int nfs4_remote_referral_get_sb(struct file_system_type
*fs_type
,
291 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
292 static void nfs4_kill_super(struct super_block
*sb
);
294 static struct file_system_type nfs4_fs_type
= {
295 .owner
= THIS_MODULE
,
297 .get_sb
= nfs4_get_sb
,
298 .kill_sb
= nfs4_kill_super
,
299 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
302 static struct file_system_type nfs4_remote_fs_type
= {
303 .owner
= THIS_MODULE
,
305 .get_sb
= nfs4_remote_get_sb
,
306 .kill_sb
= nfs4_kill_super
,
307 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
310 struct file_system_type nfs4_xdev_fs_type
= {
311 .owner
= THIS_MODULE
,
313 .get_sb
= nfs4_xdev_get_sb
,
314 .kill_sb
= nfs4_kill_super
,
315 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
318 static struct file_system_type nfs4_remote_referral_fs_type
= {
319 .owner
= THIS_MODULE
,
321 .get_sb
= nfs4_remote_referral_get_sb
,
322 .kill_sb
= nfs4_kill_super
,
323 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
326 struct file_system_type nfs4_referral_fs_type
= {
327 .owner
= THIS_MODULE
,
329 .get_sb
= nfs4_referral_get_sb
,
330 .kill_sb
= nfs4_kill_super
,
331 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
334 static const struct super_operations nfs4_sops
= {
335 .alloc_inode
= nfs_alloc_inode
,
336 .destroy_inode
= nfs_destroy_inode
,
337 .write_inode
= nfs_write_inode
,
338 .put_super
= nfs_put_super
,
339 .statfs
= nfs_statfs
,
340 .clear_inode
= nfs4_clear_inode
,
341 .umount_begin
= nfs_umount_begin
,
342 .show_options
= nfs_show_options
,
343 .show_stats
= nfs_show_stats
,
344 .remount_fs
= nfs_remount
,
348 static struct shrinker acl_shrinker
= {
349 .shrink
= nfs_access_cache_shrinker
,
350 .seeks
= DEFAULT_SEEKS
,
354 * Register the NFS filesystems
356 int __init
register_nfs_fs(void)
360 ret
= register_filesystem(&nfs_fs_type
);
364 ret
= nfs_register_sysctl();
368 ret
= register_filesystem(&nfs4_fs_type
);
372 register_shrinker(&acl_shrinker
);
377 nfs_unregister_sysctl();
380 unregister_filesystem(&nfs_fs_type
);
386 * Unregister the NFS filesystems
388 void __exit
unregister_nfs_fs(void)
390 unregister_shrinker(&acl_shrinker
);
392 unregister_filesystem(&nfs4_fs_type
);
394 nfs_unregister_sysctl();
395 unregister_filesystem(&nfs_fs_type
);
398 void nfs_sb_active(struct super_block
*sb
)
400 struct nfs_server
*server
= NFS_SB(sb
);
402 if (atomic_inc_return(&server
->active
) == 1)
403 atomic_inc(&sb
->s_active
);
406 void nfs_sb_deactive(struct super_block
*sb
)
408 struct nfs_server
*server
= NFS_SB(sb
);
410 if (atomic_dec_and_test(&server
->active
))
411 deactivate_super(sb
);
415 * Deliver file system statistics to userspace
417 static int nfs_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
419 struct nfs_server
*server
= NFS_SB(dentry
->d_sb
);
420 unsigned char blockbits
;
421 unsigned long blockres
;
422 struct nfs_fh
*fh
= NFS_FH(dentry
->d_inode
);
423 struct nfs_fattr fattr
;
424 struct nfs_fsstat res
= {
429 error
= server
->nfs_client
->rpc_ops
->statfs(server
, fh
, &res
);
432 buf
->f_type
= NFS_SUPER_MAGIC
;
435 * Current versions of glibc do not correctly handle the
436 * case where f_frsize != f_bsize. Eventually we want to
437 * report the value of wtmult in this field.
439 buf
->f_frsize
= dentry
->d_sb
->s_blocksize
;
442 * On most *nix systems, f_blocks, f_bfree, and f_bavail
443 * are reported in units of f_frsize. Linux hasn't had
444 * an f_frsize field in its statfs struct until recently,
445 * thus historically Linux's sys_statfs reports these
446 * fields in units of f_bsize.
448 buf
->f_bsize
= dentry
->d_sb
->s_blocksize
;
449 blockbits
= dentry
->d_sb
->s_blocksize_bits
;
450 blockres
= (1 << blockbits
) - 1;
451 buf
->f_blocks
= (res
.tbytes
+ blockres
) >> blockbits
;
452 buf
->f_bfree
= (res
.fbytes
+ blockres
) >> blockbits
;
453 buf
->f_bavail
= (res
.abytes
+ blockres
) >> blockbits
;
455 buf
->f_files
= res
.tfiles
;
456 buf
->f_ffree
= res
.afiles
;
458 buf
->f_namelen
= server
->namelen
;
463 dprintk("%s: statfs error = %d\n", __func__
, -error
);
468 * Map the security flavour number to a name
470 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour
)
472 static const struct {
473 rpc_authflavor_t flavour
;
476 { RPC_AUTH_NULL
, "null" },
477 { RPC_AUTH_UNIX
, "sys" },
478 { RPC_AUTH_GSS_KRB5
, "krb5" },
479 { RPC_AUTH_GSS_KRB5I
, "krb5i" },
480 { RPC_AUTH_GSS_KRB5P
, "krb5p" },
481 { RPC_AUTH_GSS_LKEY
, "lkey" },
482 { RPC_AUTH_GSS_LKEYI
, "lkeyi" },
483 { RPC_AUTH_GSS_LKEYP
, "lkeyp" },
484 { RPC_AUTH_GSS_SPKM
, "spkm" },
485 { RPC_AUTH_GSS_SPKMI
, "spkmi" },
486 { RPC_AUTH_GSS_SPKMP
, "spkmp" },
487 { UINT_MAX
, "unknown" }
491 for (i
= 0; sec_flavours
[i
].flavour
!= UINT_MAX
; i
++) {
492 if (sec_flavours
[i
].flavour
== flavour
)
495 return sec_flavours
[i
].str
;
498 static void nfs_show_mountd_options(struct seq_file
*m
, struct nfs_server
*nfss
,
501 struct sockaddr
*sap
= (struct sockaddr
*)&nfss
->mountd_address
;
503 switch (sap
->sa_family
) {
505 struct sockaddr_in
*sin
= (struct sockaddr_in
*)sap
;
506 seq_printf(m
, ",mountaddr=%pI4", &sin
->sin_addr
.s_addr
);
510 struct sockaddr_in6
*sin6
= (struct sockaddr_in6
*)sap
;
511 seq_printf(m
, ",mountaddr=%pI6", &sin6
->sin6_addr
);
516 seq_printf(m
, ",mountaddr=unspecified");
519 if (nfss
->mountd_version
|| showdefaults
)
520 seq_printf(m
, ",mountvers=%u", nfss
->mountd_version
);
521 if (nfss
->mountd_port
|| showdefaults
)
522 seq_printf(m
, ",mountport=%u", nfss
->mountd_port
);
524 switch (nfss
->mountd_protocol
) {
526 seq_printf(m
, ",mountproto=udp");
529 seq_printf(m
, ",mountproto=tcp");
533 seq_printf(m
, ",mountproto=auto");
538 static void nfs_show_nfsv4_options(struct seq_file
*m
, struct nfs_server
*nfss
,
541 struct nfs_client
*clp
= nfss
->nfs_client
;
543 seq_printf(m
, ",clientaddr=%s", clp
->cl_ipaddr
);
544 seq_printf(m
, ",minorversion=%u", clp
->cl_minorversion
);
547 static void nfs_show_nfsv4_options(struct seq_file
*m
, struct nfs_server
*nfss
,
554 * Describe the mount options in force on this server representation
556 static void nfs_show_mount_options(struct seq_file
*m
, struct nfs_server
*nfss
,
559 static const struct proc_nfs_info
{
564 { NFS_MOUNT_SOFT
, ",soft", ",hard" },
565 { NFS_MOUNT_POSIX
, ",posix", "" },
566 { NFS_MOUNT_NOCTO
, ",nocto", "" },
567 { NFS_MOUNT_NOAC
, ",noac", "" },
568 { NFS_MOUNT_NONLM
, ",nolock", "" },
569 { NFS_MOUNT_NOACL
, ",noacl", "" },
570 { NFS_MOUNT_NORDIRPLUS
, ",nordirplus", "" },
571 { NFS_MOUNT_UNSHARED
, ",nosharecache", "" },
572 { NFS_MOUNT_NORESVPORT
, ",noresvport", "" },
575 const struct proc_nfs_info
*nfs_infop
;
576 struct nfs_client
*clp
= nfss
->nfs_client
;
577 u32 version
= clp
->rpc_ops
->version
;
579 seq_printf(m
, ",vers=%u", version
);
580 seq_printf(m
, ",rsize=%u", nfss
->rsize
);
581 seq_printf(m
, ",wsize=%u", nfss
->wsize
);
582 if (nfss
->bsize
!= 0)
583 seq_printf(m
, ",bsize=%u", nfss
->bsize
);
584 seq_printf(m
, ",namlen=%u", nfss
->namelen
);
585 if (nfss
->acregmin
!= NFS_DEF_ACREGMIN
*HZ
|| showdefaults
)
586 seq_printf(m
, ",acregmin=%u", nfss
->acregmin
/HZ
);
587 if (nfss
->acregmax
!= NFS_DEF_ACREGMAX
*HZ
|| showdefaults
)
588 seq_printf(m
, ",acregmax=%u", nfss
->acregmax
/HZ
);
589 if (nfss
->acdirmin
!= NFS_DEF_ACDIRMIN
*HZ
|| showdefaults
)
590 seq_printf(m
, ",acdirmin=%u", nfss
->acdirmin
/HZ
);
591 if (nfss
->acdirmax
!= NFS_DEF_ACDIRMAX
*HZ
|| showdefaults
)
592 seq_printf(m
, ",acdirmax=%u", nfss
->acdirmax
/HZ
);
593 for (nfs_infop
= nfs_info
; nfs_infop
->flag
; nfs_infop
++) {
594 if (nfss
->flags
& nfs_infop
->flag
)
595 seq_puts(m
, nfs_infop
->str
);
597 seq_puts(m
, nfs_infop
->nostr
);
599 seq_printf(m
, ",proto=%s",
600 rpc_peeraddr2str(nfss
->client
, RPC_DISPLAY_PROTO
));
602 if (nfss
->port
!= NFS_PORT
)
603 seq_printf(m
, ",port=%u", nfss
->port
);
606 seq_printf(m
, ",port=%u", nfss
->port
);
608 seq_printf(m
, ",timeo=%lu", 10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
);
609 seq_printf(m
, ",retrans=%u", nfss
->client
->cl_timeout
->to_retries
);
610 seq_printf(m
, ",sec=%s", nfs_pseudoflavour_to_name(nfss
->client
->cl_auth
->au_flavor
));
613 nfs_show_mountd_options(m
, nfss
, showdefaults
);
615 nfs_show_nfsv4_options(m
, nfss
, showdefaults
);
617 if (nfss
->options
& NFS_OPTION_FSCACHE
)
618 seq_printf(m
, ",fsc");
620 if (nfss
->flags
& NFS_MOUNT_LOOKUP_CACHE_NONEG
) {
621 if (nfss
->flags
& NFS_MOUNT_LOOKUP_CACHE_NONE
)
622 seq_printf(m
, ",lookupcache=none");
624 seq_printf(m
, ",lookupcache=pos");
629 * Describe the mount options on this VFS mountpoint
631 static int nfs_show_options(struct seq_file
*m
, struct vfsmount
*mnt
)
633 struct nfs_server
*nfss
= NFS_SB(mnt
->mnt_sb
);
635 nfs_show_mount_options(m
, nfss
, 0);
637 seq_printf(m
, ",addr=%s",
638 rpc_peeraddr2str(nfss
->nfs_client
->cl_rpcclient
,
645 * Present statistical information for this VFS mountpoint
647 static int nfs_show_stats(struct seq_file
*m
, struct vfsmount
*mnt
)
650 struct nfs_server
*nfss
= NFS_SB(mnt
->mnt_sb
);
651 struct rpc_auth
*auth
= nfss
->client
->cl_auth
;
652 struct nfs_iostats totals
= { };
654 seq_printf(m
, "statvers=%s", NFS_IOSTAT_VERS
);
657 * Display all mount option settings
659 seq_printf(m
, "\n\topts:\t");
660 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_RDONLY
? "ro" : "rw");
661 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_SYNCHRONOUS
? ",sync" : "");
662 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_NOATIME
? ",noatime" : "");
663 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_NODIRATIME
? ",nodiratime" : "");
664 nfs_show_mount_options(m
, nfss
, 1);
666 seq_printf(m
, "\n\tage:\t%lu", (jiffies
- nfss
->mount_time
) / HZ
);
668 seq_printf(m
, "\n\tcaps:\t");
669 seq_printf(m
, "caps=0x%x", nfss
->caps
);
670 seq_printf(m
, ",wtmult=%u", nfss
->wtmult
);
671 seq_printf(m
, ",dtsize=%u", nfss
->dtsize
);
672 seq_printf(m
, ",bsize=%u", nfss
->bsize
);
673 seq_printf(m
, ",namlen=%u", nfss
->namelen
);
676 if (nfss
->nfs_client
->rpc_ops
->version
== 4) {
677 seq_printf(m
, "\n\tnfsv4:\t");
678 seq_printf(m
, "bm0=0x%x", nfss
->attr_bitmask
[0]);
679 seq_printf(m
, ",bm1=0x%x", nfss
->attr_bitmask
[1]);
680 seq_printf(m
, ",acl=0x%x", nfss
->acl_bitmask
);
685 * Display security flavor in effect for this mount
687 seq_printf(m
, "\n\tsec:\tflavor=%u", auth
->au_ops
->au_flavor
);
689 seq_printf(m
, ",pseudoflavor=%u", auth
->au_flavor
);
692 * Display superblock I/O counters
694 for_each_possible_cpu(cpu
) {
695 struct nfs_iostats
*stats
;
698 stats
= per_cpu_ptr(nfss
->io_stats
, cpu
);
700 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
701 totals
.events
[i
] += stats
->events
[i
];
702 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
703 totals
.bytes
[i
] += stats
->bytes
[i
];
704 #ifdef CONFIG_NFS_FSCACHE
705 for (i
= 0; i
< __NFSIOS_FSCACHEMAX
; i
++)
706 totals
.fscache
[i
] += stats
->fscache
[i
];
712 seq_printf(m
, "\n\tevents:\t");
713 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
714 seq_printf(m
, "%lu ", totals
.events
[i
]);
715 seq_printf(m
, "\n\tbytes:\t");
716 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
717 seq_printf(m
, "%Lu ", totals
.bytes
[i
]);
718 #ifdef CONFIG_NFS_FSCACHE
719 if (nfss
->options
& NFS_OPTION_FSCACHE
) {
720 seq_printf(m
, "\n\tfsc:\t");
721 for (i
= 0; i
< __NFSIOS_FSCACHEMAX
; i
++)
722 seq_printf(m
, "%Lu ", totals
.bytes
[i
]);
727 rpc_print_iostats(m
, nfss
->client
);
733 * Begin unmount by attempting to remove all automounted mountpoints we added
734 * in response to xdev traversals and referrals
736 static void nfs_umount_begin(struct super_block
*sb
)
738 struct nfs_server
*server
;
739 struct rpc_clnt
*rpc
;
744 /* -EIO all pending I/O */
745 rpc
= server
->client_acl
;
747 rpc_killall_tasks(rpc
);
748 rpc
= server
->client
;
750 rpc_killall_tasks(rpc
);
755 static struct nfs_parsed_mount_data
*nfs_alloc_parsed_mount_data(unsigned int version
)
757 struct nfs_parsed_mount_data
*data
;
759 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
761 data
->acregmin
= NFS_DEF_ACREGMIN
;
762 data
->acregmax
= NFS_DEF_ACREGMAX
;
763 data
->acdirmin
= NFS_DEF_ACDIRMIN
;
764 data
->acdirmax
= NFS_DEF_ACDIRMAX
;
765 data
->mount_server
.port
= NFS_UNSPEC_PORT
;
766 data
->nfs_server
.port
= NFS_UNSPEC_PORT
;
767 data
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
768 data
->auth_flavors
[0] = RPC_AUTH_UNIX
;
769 data
->auth_flavor_len
= 1;
770 data
->version
= version
;
771 data
->minorversion
= 0;
777 * Sanity-check a server address provided by the mount command.
779 * Address family must be initialized, and address must not be
780 * the ANY address for that family.
782 static int nfs_verify_server_address(struct sockaddr
*addr
)
784 switch (addr
->sa_family
) {
786 struct sockaddr_in
*sa
= (struct sockaddr_in
*)addr
;
787 return sa
->sin_addr
.s_addr
!= htonl(INADDR_ANY
);
790 struct in6_addr
*sa
= &((struct sockaddr_in6
*)addr
)->sin6_addr
;
791 return !ipv6_addr_any(sa
);
795 dfprintk(MOUNT
, "NFS: Invalid IP address specified\n");
800 * Select between a default port value and a user-specified port value.
801 * If a zero value is set, then autobind will be used.
803 static void nfs_set_port(struct sockaddr
*sap
, int *port
,
804 const unsigned short default_port
)
806 if (*port
== NFS_UNSPEC_PORT
)
807 *port
= default_port
;
809 rpc_set_port(sap
, *port
);
813 * Sanity check the NFS transport protocol.
816 static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data
*mnt
)
818 switch (mnt
->nfs_server
.protocol
) {
819 case XPRT_TRANSPORT_UDP
:
820 case XPRT_TRANSPORT_TCP
:
821 case XPRT_TRANSPORT_RDMA
:
824 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
829 * For text based NFSv2/v3 mounts, the mount protocol transport default
830 * settings should depend upon the specified NFS transport.
832 static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data
*mnt
)
834 nfs_validate_transport_protocol(mnt
);
836 if (mnt
->mount_server
.protocol
== XPRT_TRANSPORT_UDP
||
837 mnt
->mount_server
.protocol
== XPRT_TRANSPORT_TCP
)
839 switch (mnt
->nfs_server
.protocol
) {
840 case XPRT_TRANSPORT_UDP
:
841 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_UDP
;
843 case XPRT_TRANSPORT_TCP
:
844 case XPRT_TRANSPORT_RDMA
:
845 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_TCP
;
850 * Parse the value of the 'sec=' option.
852 static int nfs_parse_security_flavors(char *value
,
853 struct nfs_parsed_mount_data
*mnt
)
855 substring_t args
[MAX_OPT_ARGS
];
857 dfprintk(MOUNT
, "NFS: parsing sec=%s option\n", value
);
859 switch (match_token(value
, nfs_secflavor_tokens
, args
)) {
861 mnt
->auth_flavors
[0] = RPC_AUTH_NULL
;
864 mnt
->auth_flavors
[0] = RPC_AUTH_UNIX
;
867 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5
;
870 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5I
;
873 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5P
;
876 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEY
;
879 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEYI
;
882 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEYP
;
885 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKM
;
888 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKMI
;
891 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKMP
;
897 mnt
->auth_flavor_len
= 1;
902 * Error-check and convert a string of mount options from user space into
903 * a data structure. The whole mount string is processed; bad options are
904 * skipped as they are encountered. If there were no errors, return 1;
905 * otherwise return 0 (zero).
907 static int nfs_parse_mount_options(char *raw
,
908 struct nfs_parsed_mount_data
*mnt
)
910 char *p
, *string
, *secdata
;
911 int rc
, sloppy
= 0, invalid_option
= 0;
914 dfprintk(MOUNT
, "NFS: mount options string was NULL.\n");
917 dfprintk(MOUNT
, "NFS: nfs mount opts='%s'\n", raw
);
919 secdata
= alloc_secdata();
923 rc
= security_sb_copy_data(raw
, secdata
);
925 goto out_security_failure
;
927 rc
= security_sb_parse_opts_str(secdata
, &mnt
->lsm_opts
);
929 goto out_security_failure
;
931 free_secdata(secdata
);
933 while ((p
= strsep(&raw
, ",")) != NULL
) {
934 substring_t args
[MAX_OPT_ARGS
];
935 unsigned long option
;
941 dfprintk(MOUNT
, "NFS: parsing nfs mount option '%s'\n", p
);
943 token
= match_token(p
, nfs_mount_option_tokens
, args
);
947 * boolean options: foo/nofoo
950 mnt
->flags
|= NFS_MOUNT_SOFT
;
953 mnt
->flags
&= ~NFS_MOUNT_SOFT
;
956 mnt
->flags
|= NFS_MOUNT_POSIX
;
959 mnt
->flags
&= ~NFS_MOUNT_POSIX
;
962 mnt
->flags
&= ~NFS_MOUNT_NOCTO
;
965 mnt
->flags
|= NFS_MOUNT_NOCTO
;
968 mnt
->flags
&= ~NFS_MOUNT_NOAC
;
971 mnt
->flags
|= NFS_MOUNT_NOAC
;
974 mnt
->flags
&= ~NFS_MOUNT_NONLM
;
977 mnt
->flags
|= NFS_MOUNT_NONLM
;
980 mnt
->flags
&= ~NFS_MOUNT_VER3
;
984 mnt
->flags
|= NFS_MOUNT_VER3
;
989 mnt
->flags
&= ~NFS_MOUNT_VER3
;
994 mnt
->flags
&= ~NFS_MOUNT_TCP
;
995 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
998 mnt
->flags
|= NFS_MOUNT_TCP
;
999 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1002 mnt
->flags
|= NFS_MOUNT_TCP
; /* for side protocols */
1003 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_RDMA
;
1004 xprt_load_transport(p
);
1007 mnt
->flags
&= ~NFS_MOUNT_NOACL
;
1010 mnt
->flags
|= NFS_MOUNT_NOACL
;
1013 mnt
->flags
&= ~NFS_MOUNT_NORDIRPLUS
;
1015 case Opt_nordirplus
:
1016 mnt
->flags
|= NFS_MOUNT_NORDIRPLUS
;
1018 case Opt_sharecache
:
1019 mnt
->flags
&= ~NFS_MOUNT_UNSHARED
;
1021 case Opt_nosharecache
:
1022 mnt
->flags
|= NFS_MOUNT_UNSHARED
;
1025 mnt
->flags
&= ~NFS_MOUNT_NORESVPORT
;
1027 case Opt_noresvport
:
1028 mnt
->flags
|= NFS_MOUNT_NORESVPORT
;
1031 mnt
->options
|= NFS_OPTION_FSCACHE
;
1032 kfree(mnt
->fscache_uniq
);
1033 mnt
->fscache_uniq
= NULL
;
1036 mnt
->options
&= ~NFS_OPTION_FSCACHE
;
1037 kfree(mnt
->fscache_uniq
);
1038 mnt
->fscache_uniq
= NULL
;
1040 case Opt_fscache_uniq
:
1041 string
= match_strdup(args
);
1044 kfree(mnt
->fscache_uniq
);
1045 mnt
->fscache_uniq
= string
;
1046 mnt
->options
|= NFS_OPTION_FSCACHE
;
1050 * options that take numeric values
1053 string
= match_strdup(args
);
1056 rc
= strict_strtoul(string
, 10, &option
);
1058 if (rc
!= 0 || option
> USHORT_MAX
)
1059 goto out_invalid_value
;
1060 mnt
->nfs_server
.port
= option
;
1063 string
= match_strdup(args
);
1066 rc
= strict_strtoul(string
, 10, &option
);
1069 goto out_invalid_value
;
1070 mnt
->rsize
= option
;
1073 string
= match_strdup(args
);
1076 rc
= strict_strtoul(string
, 10, &option
);
1079 goto out_invalid_value
;
1080 mnt
->wsize
= option
;
1083 string
= match_strdup(args
);
1086 rc
= strict_strtoul(string
, 10, &option
);
1089 goto out_invalid_value
;
1090 mnt
->bsize
= option
;
1093 string
= match_strdup(args
);
1096 rc
= strict_strtoul(string
, 10, &option
);
1098 if (rc
!= 0 || option
== 0)
1099 goto out_invalid_value
;
1100 mnt
->timeo
= option
;
1103 string
= match_strdup(args
);
1106 rc
= strict_strtoul(string
, 10, &option
);
1108 if (rc
!= 0 || option
== 0)
1109 goto out_invalid_value
;
1110 mnt
->retrans
= option
;
1113 string
= match_strdup(args
);
1116 rc
= strict_strtoul(string
, 10, &option
);
1119 goto out_invalid_value
;
1120 mnt
->acregmin
= option
;
1123 string
= match_strdup(args
);
1126 rc
= strict_strtoul(string
, 10, &option
);
1129 goto out_invalid_value
;
1130 mnt
->acregmax
= option
;
1133 string
= match_strdup(args
);
1136 rc
= strict_strtoul(string
, 10, &option
);
1139 goto out_invalid_value
;
1140 mnt
->acdirmin
= option
;
1143 string
= match_strdup(args
);
1146 rc
= strict_strtoul(string
, 10, &option
);
1149 goto out_invalid_value
;
1150 mnt
->acdirmax
= option
;
1153 string
= match_strdup(args
);
1156 rc
= strict_strtoul(string
, 10, &option
);
1159 goto out_invalid_value
;
1160 mnt
->acregmin
= mnt
->acregmax
=
1161 mnt
->acdirmin
= mnt
->acdirmax
= option
;
1164 string
= match_strdup(args
);
1167 rc
= strict_strtoul(string
, 10, &option
);
1170 goto out_invalid_value
;
1171 mnt
->namlen
= option
;
1174 string
= match_strdup(args
);
1177 rc
= strict_strtoul(string
, 10, &option
);
1179 if (rc
!= 0 || option
> USHORT_MAX
)
1180 goto out_invalid_value
;
1181 mnt
->mount_server
.port
= option
;
1184 string
= match_strdup(args
);
1187 rc
= strict_strtoul(string
, 10, &option
);
1190 option
< NFS_MNT_VERSION
||
1191 option
> NFS_MNT3_VERSION
)
1192 goto out_invalid_value
;
1193 mnt
->mount_server
.version
= option
;
1196 string
= match_strdup(args
);
1199 rc
= strict_strtoul(string
, 10, &option
);
1202 goto out_invalid_value
;
1205 mnt
->flags
&= ~NFS_MOUNT_VER3
;
1209 mnt
->flags
|= NFS_MOUNT_VER3
;
1212 #ifdef CONFIG_NFS_V4
1214 mnt
->flags
&= ~NFS_MOUNT_VER3
;
1219 goto out_invalid_value
;
1222 case Opt_minorversion
:
1223 string
= match_strdup(args
);
1226 rc
= strict_strtoul(string
, 10, &option
);
1229 goto out_invalid_value
;
1230 if (option
> NFS4_MAX_MINOR_VERSION
)
1231 goto out_invalid_value
;
1232 mnt
->minorversion
= option
;
1236 * options that take text values
1239 string
= match_strdup(args
);
1242 rc
= nfs_parse_security_flavors(string
, mnt
);
1245 dfprintk(MOUNT
, "NFS: unrecognized "
1246 "security flavor\n");
1251 string
= match_strdup(args
);
1254 token
= match_token(string
,
1255 nfs_xprt_protocol_tokens
, args
);
1259 mnt
->flags
&= ~NFS_MOUNT_TCP
;
1260 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1264 mnt
->flags
|= NFS_MOUNT_TCP
;
1265 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1269 /* vector side protocols to TCP */
1270 mnt
->flags
|= NFS_MOUNT_TCP
;
1271 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_RDMA
;
1272 xprt_load_transport(string
);
1276 dfprintk(MOUNT
, "NFS: unrecognized "
1277 "transport protocol\n");
1282 case Opt_mountproto
:
1283 string
= match_strdup(args
);
1286 token
= match_token(string
,
1287 nfs_xprt_protocol_tokens
, args
);
1292 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_UDP
;
1295 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_TCP
;
1297 case Opt_xprt_rdma
: /* not used for side protocols */
1299 dfprintk(MOUNT
, "NFS: unrecognized "
1300 "transport protocol\n");
1305 string
= match_strdup(args
);
1308 mnt
->nfs_server
.addrlen
=
1309 rpc_pton(string
, strlen(string
),
1311 &mnt
->nfs_server
.address
,
1312 sizeof(mnt
->nfs_server
.address
));
1314 if (mnt
->nfs_server
.addrlen
== 0)
1315 goto out_invalid_address
;
1317 case Opt_clientaddr
:
1318 string
= match_strdup(args
);
1321 kfree(mnt
->client_address
);
1322 mnt
->client_address
= string
;
1325 string
= match_strdup(args
);
1328 kfree(mnt
->mount_server
.hostname
);
1329 mnt
->mount_server
.hostname
= string
;
1332 string
= match_strdup(args
);
1335 mnt
->mount_server
.addrlen
=
1336 rpc_pton(string
, strlen(string
),
1338 &mnt
->mount_server
.address
,
1339 sizeof(mnt
->mount_server
.address
));
1341 if (mnt
->mount_server
.addrlen
== 0)
1342 goto out_invalid_address
;
1344 case Opt_lookupcache
:
1345 string
= match_strdup(args
);
1348 token
= match_token(string
,
1349 nfs_lookupcache_tokens
, args
);
1352 case Opt_lookupcache_all
:
1353 mnt
->flags
&= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG
|NFS_MOUNT_LOOKUP_CACHE_NONE
);
1355 case Opt_lookupcache_positive
:
1356 mnt
->flags
&= ~NFS_MOUNT_LOOKUP_CACHE_NONE
;
1357 mnt
->flags
|= NFS_MOUNT_LOOKUP_CACHE_NONEG
;
1359 case Opt_lookupcache_none
:
1360 mnt
->flags
|= NFS_MOUNT_LOOKUP_CACHE_NONEG
|NFS_MOUNT_LOOKUP_CACHE_NONE
;
1363 dfprintk(MOUNT
, "NFS: invalid "
1364 "lookupcache argument\n");
1374 dfprintk(MOUNT
, "NFS: relaxing parsing rules\n");
1377 case Opt_deprecated
:
1378 dfprintk(MOUNT
, "NFS: ignoring mount option "
1384 dfprintk(MOUNT
, "NFS: unrecognized mount option "
1389 if (!sloppy
&& invalid_option
)
1394 out_invalid_address
:
1395 printk(KERN_INFO
"NFS: bad IP address specified: %s\n", p
);
1398 printk(KERN_INFO
"NFS: bad mount option value specified: %s\n", p
);
1401 printk(KERN_INFO
"NFS: not enough memory to parse option\n");
1403 out_security_failure
:
1404 free_secdata(secdata
);
1405 printk(KERN_INFO
"NFS: security options invalid: %d\n", rc
);
1410 * Match the requested auth flavors with the list returned by
1411 * the server. Returns zero and sets the mount's authentication
1412 * flavor on success; returns -EACCES if server does not support
1413 * the requested flavor.
1415 static int nfs_walk_authlist(struct nfs_parsed_mount_data
*args
,
1416 struct nfs_mount_request
*request
)
1418 unsigned int i
, j
, server_authlist_len
= *(request
->auth_flav_len
);
1421 * Certain releases of Linux's mountd return an empty
1422 * flavor list. To prevent behavioral regression with
1423 * these servers (ie. rejecting mounts that used to
1424 * succeed), revert to pre-2.6.32 behavior (no checking)
1425 * if the returned flavor list is empty.
1427 if (server_authlist_len
== 0)
1431 * We avoid sophisticated negotiating here, as there are
1432 * plenty of cases where we can get it wrong, providing
1433 * either too little or too much security.
1435 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1436 * flavor listed first. However, some servers list
1437 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1438 * preferred default, in args->auth_flavors[0] if user
1439 * didn't specify sec= mount option.
1441 for (i
= 0; i
< args
->auth_flavor_len
; i
++)
1442 for (j
= 0; j
< server_authlist_len
; j
++)
1443 if (args
->auth_flavors
[i
] == request
->auth_flavs
[j
]) {
1444 dfprintk(MOUNT
, "NFS: using auth flavor %d\n",
1445 request
->auth_flavs
[j
]);
1446 args
->auth_flavors
[0] = request
->auth_flavs
[j
];
1450 dfprintk(MOUNT
, "NFS: server does not support requested auth flavor\n");
1451 nfs_umount(request
);
1456 * Use the remote server's MOUNT service to request the NFS file handle
1457 * corresponding to the provided path.
1459 static int nfs_try_mount(struct nfs_parsed_mount_data
*args
,
1460 struct nfs_fh
*root_fh
)
1462 rpc_authflavor_t server_authlist
[NFS_MAX_SECFLAVORS
];
1463 unsigned int server_authlist_len
= ARRAY_SIZE(server_authlist
);
1464 struct nfs_mount_request request
= {
1465 .sap
= (struct sockaddr
*)
1466 &args
->mount_server
.address
,
1467 .dirpath
= args
->nfs_server
.export_path
,
1468 .protocol
= args
->mount_server
.protocol
,
1470 .noresvport
= args
->flags
& NFS_MOUNT_NORESVPORT
,
1471 .auth_flav_len
= &server_authlist_len
,
1472 .auth_flavs
= server_authlist
,
1476 if (args
->mount_server
.version
== 0) {
1477 switch (args
->version
) {
1479 args
->mount_server
.version
= NFS_MNT3_VERSION
;
1482 args
->mount_server
.version
= NFS_MNT_VERSION
;
1485 request
.version
= args
->mount_server
.version
;
1487 if (args
->mount_server
.hostname
)
1488 request
.hostname
= args
->mount_server
.hostname
;
1490 request
.hostname
= args
->nfs_server
.hostname
;
1493 * Construct the mount server's address.
1495 if (args
->mount_server
.address
.ss_family
== AF_UNSPEC
) {
1496 memcpy(request
.sap
, &args
->nfs_server
.address
,
1497 args
->nfs_server
.addrlen
);
1498 args
->mount_server
.addrlen
= args
->nfs_server
.addrlen
;
1500 request
.salen
= args
->mount_server
.addrlen
;
1501 nfs_set_port(request
.sap
, &args
->mount_server
.port
, 0);
1504 * Now ask the mount server to map our export path
1507 status
= nfs_mount(&request
);
1509 dfprintk(MOUNT
, "NFS: unable to mount server %s, error %d\n",
1510 request
.hostname
, status
);
1515 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1517 if (args
->mount_server
.version
!= NFS_MNT3_VERSION
)
1519 return nfs_walk_authlist(args
, &request
);
1522 static int nfs_parse_simple_hostname(const char *dev_name
,
1523 char **hostname
, size_t maxnamlen
,
1524 char **export_path
, size_t maxpathlen
)
1527 char *colon
, *comma
;
1529 colon
= strchr(dev_name
, ':');
1531 goto out_bad_devname
;
1533 len
= colon
- dev_name
;
1534 if (len
> maxnamlen
)
1537 /* N.B. caller will free nfs_server.hostname in all cases */
1538 *hostname
= kstrndup(dev_name
, len
, GFP_KERNEL
);
1542 /* kill possible hostname list: not supported */
1543 comma
= strchr(*hostname
, ',');
1544 if (comma
!= NULL
) {
1545 if (comma
== *hostname
)
1546 goto out_bad_devname
;
1551 len
= strlen(colon
);
1552 if (len
> maxpathlen
)
1554 *export_path
= kstrndup(colon
, len
, GFP_KERNEL
);
1558 dfprintk(MOUNT
, "NFS: MNTPATH: '%s'\n", *export_path
);
1562 dfprintk(MOUNT
, "NFS: device name not in host:path format\n");
1566 dfprintk(MOUNT
, "NFS: not enough memory to parse device name\n");
1570 dfprintk(MOUNT
, "NFS: server hostname too long\n");
1571 return -ENAMETOOLONG
;
1574 dfprintk(MOUNT
, "NFS: export pathname too long\n");
1575 return -ENAMETOOLONG
;
1579 * Hostname has square brackets around it because it contains one or
1580 * more colons. We look for the first closing square bracket, and a
1581 * colon must follow it.
1583 static int nfs_parse_protected_hostname(const char *dev_name
,
1584 char **hostname
, size_t maxnamlen
,
1585 char **export_path
, size_t maxpathlen
)
1590 start
= (char *)(dev_name
+ 1);
1592 end
= strchr(start
, ']');
1594 goto out_bad_devname
;
1595 if (*(end
+ 1) != ':')
1596 goto out_bad_devname
;
1599 if (len
> maxnamlen
)
1602 /* N.B. caller will free nfs_server.hostname in all cases */
1603 *hostname
= kstrndup(start
, len
, GFP_KERNEL
);
1604 if (*hostname
== NULL
)
1609 if (len
> maxpathlen
)
1611 *export_path
= kstrndup(end
, len
, GFP_KERNEL
);
1618 dfprintk(MOUNT
, "NFS: device name not in host:path format\n");
1622 dfprintk(MOUNT
, "NFS: not enough memory to parse device name\n");
1626 dfprintk(MOUNT
, "NFS: server hostname too long\n");
1627 return -ENAMETOOLONG
;
1630 dfprintk(MOUNT
, "NFS: export pathname too long\n");
1631 return -ENAMETOOLONG
;
1635 * Split "dev_name" into "hostname:export_path".
1637 * The leftmost colon demarks the split between the server's hostname
1638 * and the export path. If the hostname starts with a left square
1639 * bracket, then it may contain colons.
1641 * Note: caller frees hostname and export path, even on error.
1643 static int nfs_parse_devname(const char *dev_name
,
1644 char **hostname
, size_t maxnamlen
,
1645 char **export_path
, size_t maxpathlen
)
1647 if (*dev_name
== '[')
1648 return nfs_parse_protected_hostname(dev_name
,
1649 hostname
, maxnamlen
,
1650 export_path
, maxpathlen
);
1652 return nfs_parse_simple_hostname(dev_name
,
1653 hostname
, maxnamlen
,
1654 export_path
, maxpathlen
);
1658 * Validate the NFS2/NFS3 mount data
1659 * - fills in the mount root filehandle
1661 * For option strings, user space handles the following behaviors:
1663 * + DNS: mapping server host name to IP address ("addr=" option)
1665 * + failure mode: how to behave if a mount request can't be handled
1666 * immediately ("fg/bg" option)
1668 * + retry: how often to retry a mount request ("retry=" option)
1670 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1671 * mountproto=tcp after mountproto=udp, and so on
1673 static int nfs_validate_mount_data(void *options
,
1674 struct nfs_parsed_mount_data
*args
,
1675 struct nfs_fh
*mntfh
,
1676 const char *dev_name
)
1678 struct nfs_mount_data
*data
= (struct nfs_mount_data
*)options
;
1679 struct sockaddr
*sap
= (struct sockaddr
*)&args
->nfs_server
.address
;
1684 switch (data
->version
) {
1690 if (data
->flags
& NFS_MOUNT_VER3
)
1692 data
->root
.size
= NFS2_FHSIZE
;
1693 memcpy(data
->root
.data
, data
->old_root
.data
, NFS2_FHSIZE
);
1695 if (data
->flags
& NFS_MOUNT_SECFLAVOUR
)
1698 memset(data
->context
, 0, sizeof(data
->context
));
1700 if (data
->flags
& NFS_MOUNT_VER3
) {
1701 if (data
->root
.size
> NFS3_FHSIZE
|| data
->root
.size
== 0)
1702 goto out_invalid_fh
;
1703 mntfh
->size
= data
->root
.size
;
1706 mntfh
->size
= NFS2_FHSIZE
;
1711 memcpy(mntfh
->data
, data
->root
.data
, mntfh
->size
);
1712 if (mntfh
->size
< sizeof(mntfh
->data
))
1713 memset(mntfh
->data
+ mntfh
->size
, 0,
1714 sizeof(mntfh
->data
) - mntfh
->size
);
1717 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1720 args
->flags
= data
->flags
& NFS_MOUNT_FLAGMASK
;
1721 args
->rsize
= data
->rsize
;
1722 args
->wsize
= data
->wsize
;
1723 args
->timeo
= data
->timeo
;
1724 args
->retrans
= data
->retrans
;
1725 args
->acregmin
= data
->acregmin
;
1726 args
->acregmax
= data
->acregmax
;
1727 args
->acdirmin
= data
->acdirmin
;
1728 args
->acdirmax
= data
->acdirmax
;
1730 memcpy(sap
, &data
->addr
, sizeof(data
->addr
));
1731 args
->nfs_server
.addrlen
= sizeof(data
->addr
);
1732 if (!nfs_verify_server_address(sap
))
1733 goto out_no_address
;
1735 if (!(data
->flags
& NFS_MOUNT_TCP
))
1736 args
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1737 /* N.B. caller will free nfs_server.hostname in all cases */
1738 args
->nfs_server
.hostname
= kstrdup(data
->hostname
, GFP_KERNEL
);
1739 args
->namlen
= data
->namlen
;
1740 args
->bsize
= data
->bsize
;
1742 if (data
->flags
& NFS_MOUNT_SECFLAVOUR
)
1743 args
->auth_flavors
[0] = data
->pseudoflavor
;
1744 if (!args
->nfs_server
.hostname
)
1748 * The legacy version 6 binary mount data from userspace has a
1749 * field used only to transport selinux information into the
1750 * the kernel. To continue to support that functionality we
1751 * have a touch of selinux knowledge here in the NFS code. The
1752 * userspace code converted context=blah to just blah so we are
1753 * converting back to the full string selinux understands.
1755 if (data
->context
[0]){
1756 #ifdef CONFIG_SECURITY_SELINUX
1758 char *opts_str
= kmalloc(sizeof(data
->context
) + 8, GFP_KERNEL
);
1761 strcpy(opts_str
, "context=");
1762 data
->context
[NFS_MAX_CONTEXT_LEN
] = '\0';
1763 strcat(opts_str
, &data
->context
[0]);
1764 rc
= security_sb_parse_opts_str(opts_str
, &args
->lsm_opts
);
1777 if (nfs_parse_mount_options((char *)options
, args
) == 0)
1780 if (!nfs_verify_server_address(sap
))
1781 goto out_no_address
;
1783 if (args
->version
== 4)
1784 #ifdef CONFIG_NFS_V4
1785 return nfs4_validate_text_mount_data(options
,
1788 goto out_v4_not_compiled
;
1791 nfs_set_port(sap
, &args
->nfs_server
.port
, 0);
1793 nfs_set_mount_transport_protocol(args
);
1795 status
= nfs_parse_devname(dev_name
,
1796 &args
->nfs_server
.hostname
,
1798 &args
->nfs_server
.export_path
,
1801 status
= nfs_try_mount(args
, mntfh
);
1803 kfree(args
->nfs_server
.export_path
);
1804 args
->nfs_server
.export_path
= NULL
;
1813 #ifndef CONFIG_NFS_V3
1814 if (args
->version
== 3)
1815 goto out_v3_not_compiled
;
1816 #endif /* !CONFIG_NFS_V3 */
1821 dfprintk(MOUNT
, "NFS: mount program didn't pass any mount data\n");
1825 dfprintk(MOUNT
, "NFS: nfs_mount_data version %d does not support v3\n",
1830 dfprintk(MOUNT
, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1833 #ifndef CONFIG_NFS_V3
1834 out_v3_not_compiled
:
1835 dfprintk(MOUNT
, "NFS: NFSv3 is not compiled into kernel\n");
1836 return -EPROTONOSUPPORT
;
1837 #endif /* !CONFIG_NFS_V3 */
1839 #ifndef CONFIG_NFS_V4
1840 out_v4_not_compiled
:
1841 dfprintk(MOUNT
, "NFS: NFSv4 is not compiled into kernel\n");
1842 return -EPROTONOSUPPORT
;
1843 #endif /* !CONFIG_NFS_V4 */
1846 dfprintk(MOUNT
, "NFS: not enough memory to handle mount options\n");
1850 dfprintk(MOUNT
, "NFS: mount program didn't pass remote address\n");
1854 dfprintk(MOUNT
, "NFS: invalid root filehandle\n");
1859 nfs_compare_remount_data(struct nfs_server
*nfss
,
1860 struct nfs_parsed_mount_data
*data
)
1862 if (data
->flags
!= nfss
->flags
||
1863 data
->rsize
!= nfss
->rsize
||
1864 data
->wsize
!= nfss
->wsize
||
1865 data
->retrans
!= nfss
->client
->cl_timeout
->to_retries
||
1866 data
->auth_flavors
[0] != nfss
->client
->cl_auth
->au_flavor
||
1867 data
->acregmin
!= nfss
->acregmin
/ HZ
||
1868 data
->acregmax
!= nfss
->acregmax
/ HZ
||
1869 data
->acdirmin
!= nfss
->acdirmin
/ HZ
||
1870 data
->acdirmax
!= nfss
->acdirmax
/ HZ
||
1871 data
->timeo
!= (10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
) ||
1872 data
->nfs_server
.port
!= nfss
->port
||
1873 data
->nfs_server
.addrlen
!= nfss
->nfs_client
->cl_addrlen
||
1874 !rpc_cmp_addr((struct sockaddr
*)&data
->nfs_server
.address
,
1875 (struct sockaddr
*)&nfss
->nfs_client
->cl_addr
))
1882 nfs_remount(struct super_block
*sb
, int *flags
, char *raw_data
)
1885 struct nfs_server
*nfss
= sb
->s_fs_info
;
1886 struct nfs_parsed_mount_data
*data
;
1887 struct nfs_mount_data
*options
= (struct nfs_mount_data
*)raw_data
;
1888 struct nfs4_mount_data
*options4
= (struct nfs4_mount_data
*)raw_data
;
1889 u32 nfsvers
= nfss
->nfs_client
->rpc_ops
->version
;
1892 * Userspace mount programs that send binary options generally send
1893 * them populated with default values. We have no way to know which
1894 * ones were explicitly specified. Fall back to legacy behavior and
1895 * just return success.
1897 if ((nfsvers
== 4 && (!options4
|| options4
->version
== 1)) ||
1898 (nfsvers
<= 3 && (!options
|| (options
->version
>= 1 &&
1899 options
->version
<= 6))))
1902 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
1907 /* fill out struct with values from existing mount */
1908 data
->flags
= nfss
->flags
;
1909 data
->rsize
= nfss
->rsize
;
1910 data
->wsize
= nfss
->wsize
;
1911 data
->retrans
= nfss
->client
->cl_timeout
->to_retries
;
1912 data
->auth_flavors
[0] = nfss
->client
->cl_auth
->au_flavor
;
1913 data
->acregmin
= nfss
->acregmin
/ HZ
;
1914 data
->acregmax
= nfss
->acregmax
/ HZ
;
1915 data
->acdirmin
= nfss
->acdirmin
/ HZ
;
1916 data
->acdirmax
= nfss
->acdirmax
/ HZ
;
1917 data
->timeo
= 10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
;
1918 data
->nfs_server
.port
= nfss
->port
;
1919 data
->nfs_server
.addrlen
= nfss
->nfs_client
->cl_addrlen
;
1920 memcpy(&data
->nfs_server
.address
, &nfss
->nfs_client
->cl_addr
,
1921 data
->nfs_server
.addrlen
);
1923 /* overwrite those values with any that were specified */
1924 error
= nfs_parse_mount_options((char *)options
, data
);
1929 * noac is a special case. It implies -o sync, but that's not
1930 * necessarily reflected in the mtab options. do_remount_sb
1931 * will clear MS_SYNCHRONOUS if -o sync wasn't specified in the
1932 * remount options, so we have to explicitly reset it.
1934 if (data
->flags
& NFS_MOUNT_NOAC
)
1935 *flags
|= MS_SYNCHRONOUS
;
1937 /* compare new mount options with old ones */
1938 error
= nfs_compare_remount_data(nfss
, data
);
1946 * Initialise the common bits of the superblock
1948 static inline void nfs_initialise_sb(struct super_block
*sb
)
1950 struct nfs_server
*server
= NFS_SB(sb
);
1952 sb
->s_magic
= NFS_SUPER_MAGIC
;
1954 /* We probably want something more informative here */
1955 snprintf(sb
->s_id
, sizeof(sb
->s_id
),
1956 "%x:%x", MAJOR(sb
->s_dev
), MINOR(sb
->s_dev
));
1958 if (sb
->s_blocksize
== 0)
1959 sb
->s_blocksize
= nfs_block_bits(server
->wsize
,
1960 &sb
->s_blocksize_bits
);
1962 if (server
->flags
& NFS_MOUNT_NOAC
)
1963 sb
->s_flags
|= MS_SYNCHRONOUS
;
1965 sb
->s_bdi
= &server
->backing_dev_info
;
1967 nfs_super_set_maxbytes(sb
, server
->maxfilesize
);
1971 * Finish setting up an NFS2/3 superblock
1973 static void nfs_fill_super(struct super_block
*sb
,
1974 struct nfs_parsed_mount_data
*data
)
1976 struct nfs_server
*server
= NFS_SB(sb
);
1978 sb
->s_blocksize_bits
= 0;
1979 sb
->s_blocksize
= 0;
1981 sb
->s_blocksize
= nfs_block_size(data
->bsize
, &sb
->s_blocksize_bits
);
1983 if (server
->nfs_client
->rpc_ops
->version
== 3) {
1984 /* The VFS shouldn't apply the umask to mode bits. We will do
1985 * so ourselves when necessary.
1987 sb
->s_flags
|= MS_POSIXACL
;
1988 sb
->s_time_gran
= 1;
1991 sb
->s_op
= &nfs_sops
;
1992 nfs_initialise_sb(sb
);
1996 * Finish setting up a cloned NFS2/3 superblock
1998 static void nfs_clone_super(struct super_block
*sb
,
1999 const struct super_block
*old_sb
)
2001 struct nfs_server
*server
= NFS_SB(sb
);
2003 sb
->s_blocksize_bits
= old_sb
->s_blocksize_bits
;
2004 sb
->s_blocksize
= old_sb
->s_blocksize
;
2005 sb
->s_maxbytes
= old_sb
->s_maxbytes
;
2007 if (server
->nfs_client
->rpc_ops
->version
== 3) {
2008 /* The VFS shouldn't apply the umask to mode bits. We will do
2009 * so ourselves when necessary.
2011 sb
->s_flags
|= MS_POSIXACL
;
2012 sb
->s_time_gran
= 1;
2015 sb
->s_op
= old_sb
->s_op
;
2016 nfs_initialise_sb(sb
);
2019 static int nfs_compare_mount_options(const struct super_block
*s
, const struct nfs_server
*b
, int flags
)
2021 const struct nfs_server
*a
= s
->s_fs_info
;
2022 const struct rpc_clnt
*clnt_a
= a
->client
;
2023 const struct rpc_clnt
*clnt_b
= b
->client
;
2025 if ((s
->s_flags
& NFS_MS_MASK
) != (flags
& NFS_MS_MASK
))
2027 if (a
->nfs_client
!= b
->nfs_client
)
2029 if (a
->flags
!= b
->flags
)
2031 if (a
->wsize
!= b
->wsize
)
2033 if (a
->rsize
!= b
->rsize
)
2035 if (a
->acregmin
!= b
->acregmin
)
2037 if (a
->acregmax
!= b
->acregmax
)
2039 if (a
->acdirmin
!= b
->acdirmin
)
2041 if (a
->acdirmax
!= b
->acdirmax
)
2043 if (clnt_a
->cl_auth
->au_flavor
!= clnt_b
->cl_auth
->au_flavor
)
2050 struct nfs_sb_mountdata
{
2051 struct nfs_server
*server
;
2055 static int nfs_set_super(struct super_block
*s
, void *data
)
2057 struct nfs_sb_mountdata
*sb_mntdata
= data
;
2058 struct nfs_server
*server
= sb_mntdata
->server
;
2061 s
->s_flags
= sb_mntdata
->mntflags
;
2062 s
->s_fs_info
= server
;
2063 ret
= set_anon_super(s
, server
);
2065 server
->s_dev
= s
->s_dev
;
2069 static int nfs_compare_super_address(struct nfs_server
*server1
,
2070 struct nfs_server
*server2
)
2072 struct sockaddr
*sap1
, *sap2
;
2074 sap1
= (struct sockaddr
*)&server1
->nfs_client
->cl_addr
;
2075 sap2
= (struct sockaddr
*)&server2
->nfs_client
->cl_addr
;
2077 if (sap1
->sa_family
!= sap2
->sa_family
)
2080 switch (sap1
->sa_family
) {
2082 struct sockaddr_in
*sin1
= (struct sockaddr_in
*)sap1
;
2083 struct sockaddr_in
*sin2
= (struct sockaddr_in
*)sap2
;
2084 if (sin1
->sin_addr
.s_addr
!= sin2
->sin_addr
.s_addr
)
2086 if (sin1
->sin_port
!= sin2
->sin_port
)
2091 struct sockaddr_in6
*sin1
= (struct sockaddr_in6
*)sap1
;
2092 struct sockaddr_in6
*sin2
= (struct sockaddr_in6
*)sap2
;
2093 if (!ipv6_addr_equal(&sin1
->sin6_addr
, &sin2
->sin6_addr
))
2095 if (sin1
->sin6_port
!= sin2
->sin6_port
)
2106 static int nfs_compare_super(struct super_block
*sb
, void *data
)
2108 struct nfs_sb_mountdata
*sb_mntdata
= data
;
2109 struct nfs_server
*server
= sb_mntdata
->server
, *old
= NFS_SB(sb
);
2110 int mntflags
= sb_mntdata
->mntflags
;
2112 if (!nfs_compare_super_address(old
, server
))
2114 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2115 if (old
->flags
& NFS_MOUNT_UNSHARED
)
2117 if (memcmp(&old
->fsid
, &server
->fsid
, sizeof(old
->fsid
)) != 0)
2119 return nfs_compare_mount_options(sb
, server
, mntflags
);
2122 static int nfs_bdi_register(struct nfs_server
*server
)
2124 return bdi_register_dev(&server
->backing_dev_info
, server
->s_dev
);
2127 static int nfs_get_sb(struct file_system_type
*fs_type
,
2128 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
2130 struct nfs_server
*server
= NULL
;
2131 struct super_block
*s
;
2132 struct nfs_parsed_mount_data
*data
;
2133 struct nfs_fh
*mntfh
;
2134 struct dentry
*mntroot
;
2135 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2136 struct nfs_sb_mountdata sb_mntdata
= {
2139 int error
= -ENOMEM
;
2141 data
= nfs_alloc_parsed_mount_data(3);
2142 mntfh
= kzalloc(sizeof(*mntfh
), GFP_KERNEL
);
2143 if (data
== NULL
|| mntfh
== NULL
)
2146 security_init_mnt_opts(&data
->lsm_opts
);
2148 /* Validate the mount data */
2149 error
= nfs_validate_mount_data(raw_data
, data
, mntfh
, dev_name
);
2153 #ifdef CONFIG_NFS_V4
2154 if (data
->version
== 4) {
2155 error
= nfs4_try_mount(flags
, dev_name
, data
, mnt
);
2156 kfree(data
->client_address
);
2159 #endif /* CONFIG_NFS_V4 */
2161 /* Get a volume representation */
2162 server
= nfs_create_server(data
, mntfh
);
2163 if (IS_ERR(server
)) {
2164 error
= PTR_ERR(server
);
2167 sb_mntdata
.server
= server
;
2169 if (server
->flags
& NFS_MOUNT_UNSHARED
)
2170 compare_super
= NULL
;
2172 /* Get a superblock - note that we may end up sharing one that already exists */
2173 s
= sget(fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2179 if (s
->s_fs_info
!= server
) {
2180 nfs_free_server(server
);
2183 error
= nfs_bdi_register(server
);
2185 goto error_splat_super
;
2189 /* initial superblock/root creation */
2190 nfs_fill_super(s
, data
);
2191 nfs_fscache_get_super_cookie(
2192 s
, data
? data
->fscache_uniq
: NULL
, NULL
);
2195 mntroot
= nfs_get_root(s
, mntfh
);
2196 if (IS_ERR(mntroot
)) {
2197 error
= PTR_ERR(mntroot
);
2198 goto error_splat_super
;
2201 error
= security_sb_set_mnt_opts(s
, &data
->lsm_opts
);
2203 goto error_splat_root
;
2205 s
->s_flags
|= MS_ACTIVE
;
2207 mnt
->mnt_root
= mntroot
;
2211 kfree(data
->nfs_server
.hostname
);
2212 kfree(data
->mount_server
.hostname
);
2213 kfree(data
->fscache_uniq
);
2214 security_free_mnt_opts(&data
->lsm_opts
);
2221 nfs_free_server(server
);
2227 deactivate_locked_super(s
);
2232 * Ensure that we unregister the bdi before kill_anon_super
2233 * releases the device name
2235 static void nfs_put_super(struct super_block
*s
)
2237 struct nfs_server
*server
= NFS_SB(s
);
2239 bdi_unregister(&server
->backing_dev_info
);
2243 * Destroy an NFS2/3 superblock
2245 static void nfs_kill_super(struct super_block
*s
)
2247 struct nfs_server
*server
= NFS_SB(s
);
2250 nfs_fscache_release_super_cookie(s
);
2251 nfs_free_server(server
);
2255 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2257 static int nfs_xdev_get_sb(struct file_system_type
*fs_type
, int flags
,
2258 const char *dev_name
, void *raw_data
,
2259 struct vfsmount
*mnt
)
2261 struct nfs_clone_mount
*data
= raw_data
;
2262 struct super_block
*s
;
2263 struct nfs_server
*server
;
2264 struct dentry
*mntroot
;
2265 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2266 struct nfs_sb_mountdata sb_mntdata
= {
2271 dprintk("--> nfs_xdev_get_sb()\n");
2273 /* create a new volume representation */
2274 server
= nfs_clone_server(NFS_SB(data
->sb
), data
->fh
, data
->fattr
);
2275 if (IS_ERR(server
)) {
2276 error
= PTR_ERR(server
);
2277 goto out_err_noserver
;
2279 sb_mntdata
.server
= server
;
2281 if (server
->flags
& NFS_MOUNT_UNSHARED
)
2282 compare_super
= NULL
;
2284 /* Get a superblock - note that we may end up sharing one that already exists */
2285 s
= sget(&nfs_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2291 if (s
->s_fs_info
!= server
) {
2292 nfs_free_server(server
);
2295 error
= nfs_bdi_register(server
);
2297 goto error_splat_super
;
2301 /* initial superblock/root creation */
2302 nfs_clone_super(s
, data
->sb
);
2303 nfs_fscache_get_super_cookie(s
, NULL
, data
);
2306 mntroot
= nfs_get_root(s
, data
->fh
);
2307 if (IS_ERR(mntroot
)) {
2308 error
= PTR_ERR(mntroot
);
2309 goto error_splat_super
;
2311 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
2314 goto error_splat_super
;
2317 s
->s_flags
|= MS_ACTIVE
;
2319 mnt
->mnt_root
= mntroot
;
2321 /* clone any lsm security options from the parent to the new sb */
2322 security_sb_clone_mnt_opts(data
->sb
, s
);
2324 dprintk("<-- nfs_xdev_get_sb() = 0\n");
2328 nfs_free_server(server
);
2330 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error
);
2334 deactivate_locked_super(s
);
2335 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error
);
2339 #ifdef CONFIG_NFS_V4
2342 * Finish setting up a cloned NFS4 superblock
2344 static void nfs4_clone_super(struct super_block
*sb
,
2345 const struct super_block
*old_sb
)
2347 sb
->s_blocksize_bits
= old_sb
->s_blocksize_bits
;
2348 sb
->s_blocksize
= old_sb
->s_blocksize
;
2349 sb
->s_maxbytes
= old_sb
->s_maxbytes
;
2350 sb
->s_time_gran
= 1;
2351 sb
->s_op
= old_sb
->s_op
;
2352 nfs_initialise_sb(sb
);
2356 * Set up an NFS4 superblock
2358 static void nfs4_fill_super(struct super_block
*sb
)
2360 sb
->s_time_gran
= 1;
2361 sb
->s_op
= &nfs4_sops
;
2362 nfs_initialise_sb(sb
);
2365 static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data
*args
)
2367 args
->flags
&= ~(NFS_MOUNT_NONLM
|NFS_MOUNT_NOACL
|NFS_MOUNT_VER3
);
2370 static int nfs4_validate_text_mount_data(void *options
,
2371 struct nfs_parsed_mount_data
*args
,
2372 const char *dev_name
)
2374 struct sockaddr
*sap
= (struct sockaddr
*)&args
->nfs_server
.address
;
2376 nfs_set_port(sap
, &args
->nfs_server
.port
, NFS_PORT
);
2378 nfs_validate_transport_protocol(args
);
2380 nfs4_validate_mount_flags(args
);
2382 if (args
->version
!= 4) {
2384 "NFS4: Illegal mount version\n");
2388 if (args
->auth_flavor_len
> 1) {
2390 "NFS4: Too many RPC auth flavours specified\n");
2394 if (args
->client_address
== NULL
) {
2396 "NFS4: mount program didn't pass callback address\n");
2400 return nfs_parse_devname(dev_name
,
2401 &args
->nfs_server
.hostname
,
2403 &args
->nfs_server
.export_path
,
2408 * Validate NFSv4 mount options
2410 static int nfs4_validate_mount_data(void *options
,
2411 struct nfs_parsed_mount_data
*args
,
2412 const char *dev_name
)
2414 struct sockaddr
*sap
= (struct sockaddr
*)&args
->nfs_server
.address
;
2415 struct nfs4_mount_data
*data
= (struct nfs4_mount_data
*)options
;
2421 switch (data
->version
) {
2423 if (data
->host_addrlen
> sizeof(args
->nfs_server
.address
))
2424 goto out_no_address
;
2425 if (data
->host_addrlen
== 0)
2426 goto out_no_address
;
2427 args
->nfs_server
.addrlen
= data
->host_addrlen
;
2428 if (copy_from_user(sap
, data
->host_addr
, data
->host_addrlen
))
2430 if (!nfs_verify_server_address(sap
))
2431 goto out_no_address
;
2433 if (data
->auth_flavourlen
) {
2434 if (data
->auth_flavourlen
> 1)
2435 goto out_inval_auth
;
2436 if (copy_from_user(&args
->auth_flavors
[0],
2437 data
->auth_flavours
,
2438 sizeof(args
->auth_flavors
[0])))
2442 c
= strndup_user(data
->hostname
.data
, NFS4_MAXNAMLEN
);
2445 args
->nfs_server
.hostname
= c
;
2447 c
= strndup_user(data
->mnt_path
.data
, NFS4_MAXPATHLEN
);
2450 args
->nfs_server
.export_path
= c
;
2451 dfprintk(MOUNT
, "NFS: MNTPATH: '%s'\n", c
);
2453 c
= strndup_user(data
->client_addr
.data
, 16);
2456 args
->client_address
= c
;
2459 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2463 args
->flags
= data
->flags
& NFS4_MOUNT_FLAGMASK
;
2464 args
->rsize
= data
->rsize
;
2465 args
->wsize
= data
->wsize
;
2466 args
->timeo
= data
->timeo
;
2467 args
->retrans
= data
->retrans
;
2468 args
->acregmin
= data
->acregmin
;
2469 args
->acregmax
= data
->acregmax
;
2470 args
->acdirmin
= data
->acdirmin
;
2471 args
->acdirmax
= data
->acdirmax
;
2472 args
->nfs_server
.protocol
= data
->proto
;
2473 nfs_validate_transport_protocol(args
);
2477 if (nfs_parse_mount_options((char *)options
, args
) == 0)
2480 if (!nfs_verify_server_address(sap
))
2483 return nfs4_validate_text_mount_data(options
, args
, dev_name
);
2489 dfprintk(MOUNT
, "NFS4: mount program didn't pass any mount data\n");
2493 dfprintk(MOUNT
, "NFS4: Invalid number of RPC auth flavours %d\n",
2494 data
->auth_flavourlen
);
2498 dfprintk(MOUNT
, "NFS4: mount program didn't pass remote address\n");
2503 * Get the superblock for the NFS4 root partition
2505 static int nfs4_remote_get_sb(struct file_system_type
*fs_type
,
2506 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
2508 struct nfs_parsed_mount_data
*data
= raw_data
;
2509 struct super_block
*s
;
2510 struct nfs_server
*server
;
2511 struct nfs_fh
*mntfh
;
2512 struct dentry
*mntroot
;
2513 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2514 struct nfs_sb_mountdata sb_mntdata
= {
2517 int error
= -ENOMEM
;
2519 mntfh
= kzalloc(sizeof(*mntfh
), GFP_KERNEL
);
2520 if (data
== NULL
|| mntfh
== NULL
)
2523 security_init_mnt_opts(&data
->lsm_opts
);
2525 /* Get a volume representation */
2526 server
= nfs4_create_server(data
, mntfh
);
2527 if (IS_ERR(server
)) {
2528 error
= PTR_ERR(server
);
2531 sb_mntdata
.server
= server
;
2533 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2534 compare_super
= NULL
;
2536 /* Get a superblock - note that we may end up sharing one that already exists */
2537 s
= sget(&nfs4_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2543 if (s
->s_fs_info
!= server
) {
2544 nfs_free_server(server
);
2547 error
= nfs_bdi_register(server
);
2549 goto error_splat_super
;
2553 /* initial superblock/root creation */
2555 nfs_fscache_get_super_cookie(
2556 s
, data
? data
->fscache_uniq
: NULL
, NULL
);
2559 mntroot
= nfs4_get_root(s
, mntfh
);
2560 if (IS_ERR(mntroot
)) {
2561 error
= PTR_ERR(mntroot
);
2562 goto error_splat_super
;
2565 error
= security_sb_set_mnt_opts(s
, &data
->lsm_opts
);
2567 goto error_splat_root
;
2569 s
->s_flags
|= MS_ACTIVE
;
2571 mnt
->mnt_root
= mntroot
;
2575 security_free_mnt_opts(&data
->lsm_opts
);
2581 nfs_free_server(server
);
2587 deactivate_locked_super(s
);
2591 static struct vfsmount
*nfs_do_root_mount(struct file_system_type
*fs_type
,
2592 int flags
, void *data
, const char *hostname
)
2594 struct vfsmount
*root_mnt
;
2598 len
= strlen(hostname
) + 3;
2599 root_devname
= kmalloc(len
, GFP_KERNEL
);
2600 if (root_devname
== NULL
)
2601 return ERR_PTR(-ENOMEM
);
2602 snprintf(root_devname
, len
, "%s:/", hostname
);
2603 root_mnt
= vfs_kern_mount(fs_type
, flags
, root_devname
, data
);
2604 kfree(root_devname
);
2608 static void nfs_fix_devname(const struct path
*path
, struct vfsmount
*mnt
)
2610 char *page
= (char *) __get_free_page(GFP_KERNEL
);
2611 char *devname
, *tmp
;
2615 devname
= nfs_path(path
->mnt
->mnt_devname
,
2616 path
->mnt
->mnt_root
, path
->dentry
,
2618 if (devname
== NULL
)
2620 tmp
= kstrdup(devname
, GFP_KERNEL
);
2623 kfree(mnt
->mnt_devname
);
2624 mnt
->mnt_devname
= tmp
;
2626 free_page((unsigned long)page
);
2629 static int nfs_follow_remote_path(struct vfsmount
*root_mnt
,
2630 const char *export_path
, struct vfsmount
*mnt_target
)
2632 struct mnt_namespace
*ns_private
;
2633 struct nameidata nd
;
2634 struct super_block
*s
;
2637 ns_private
= create_mnt_ns(root_mnt
);
2638 ret
= PTR_ERR(ns_private
);
2639 if (IS_ERR(ns_private
))
2642 ret
= vfs_path_lookup(root_mnt
->mnt_root
, root_mnt
,
2643 export_path
, LOOKUP_FOLLOW
, &nd
);
2645 put_mnt_ns(ns_private
);
2650 s
= nd
.path
.mnt
->mnt_sb
;
2651 atomic_inc(&s
->s_active
);
2652 mnt_target
->mnt_sb
= s
;
2653 mnt_target
->mnt_root
= dget(nd
.path
.dentry
);
2655 /* Correct the device pathname */
2656 nfs_fix_devname(&nd
.path
, mnt_target
);
2659 down_write(&s
->s_umount
);
2667 static int nfs4_try_mount(int flags
, const char *dev_name
,
2668 struct nfs_parsed_mount_data
*data
,
2669 struct vfsmount
*mnt
)
2672 struct vfsmount
*root_mnt
;
2675 dfprintk(MOUNT
, "--> nfs4_try_mount()\n");
2677 export_path
= data
->nfs_server
.export_path
;
2678 data
->nfs_server
.export_path
= "/";
2679 root_mnt
= nfs_do_root_mount(&nfs4_remote_fs_type
, flags
, data
,
2680 data
->nfs_server
.hostname
);
2681 data
->nfs_server
.export_path
= export_path
;
2683 error
= PTR_ERR(root_mnt
);
2684 if (IS_ERR(root_mnt
))
2687 error
= nfs_follow_remote_path(root_mnt
, export_path
, mnt
);
2690 dfprintk(MOUNT
, "<-- nfs4_try_mount() = %d%s\n", error
,
2691 error
!= 0 ? " [error]" : "");
2696 * Get the superblock for an NFS4 mountpoint
2698 static int nfs4_get_sb(struct file_system_type
*fs_type
,
2699 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
2701 struct nfs_parsed_mount_data
*data
;
2702 int error
= -ENOMEM
;
2704 data
= nfs_alloc_parsed_mount_data(4);
2708 /* Validate the mount data */
2709 error
= nfs4_validate_mount_data(raw_data
, data
, dev_name
);
2713 error
= nfs4_try_mount(flags
, dev_name
, data
, mnt
);
2716 kfree(data
->client_address
);
2717 kfree(data
->nfs_server
.export_path
);
2718 kfree(data
->nfs_server
.hostname
);
2719 kfree(data
->fscache_uniq
);
2722 dprintk("<-- nfs4_get_sb() = %d%s\n", error
,
2723 error
!= 0 ? " [error]" : "");
2727 static void nfs4_kill_super(struct super_block
*sb
)
2729 struct nfs_server
*server
= NFS_SB(sb
);
2731 dprintk("--> %s\n", __func__
);
2732 nfs_super_return_all_delegations(sb
);
2733 kill_anon_super(sb
);
2734 nfs_fscache_release_super_cookie(sb
);
2735 nfs_free_server(server
);
2736 dprintk("<-- %s\n", __func__
);
2740 * Clone an NFS4 server record on xdev traversal (FSID-change)
2742 static int nfs4_xdev_get_sb(struct file_system_type
*fs_type
, int flags
,
2743 const char *dev_name
, void *raw_data
,
2744 struct vfsmount
*mnt
)
2746 struct nfs_clone_mount
*data
= raw_data
;
2747 struct super_block
*s
;
2748 struct nfs_server
*server
;
2749 struct dentry
*mntroot
;
2750 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2751 struct nfs_sb_mountdata sb_mntdata
= {
2756 dprintk("--> nfs4_xdev_get_sb()\n");
2758 /* create a new volume representation */
2759 server
= nfs_clone_server(NFS_SB(data
->sb
), data
->fh
, data
->fattr
);
2760 if (IS_ERR(server
)) {
2761 error
= PTR_ERR(server
);
2762 goto out_err_noserver
;
2764 sb_mntdata
.server
= server
;
2766 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2767 compare_super
= NULL
;
2769 /* Get a superblock - note that we may end up sharing one that already exists */
2770 s
= sget(&nfs4_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2776 if (s
->s_fs_info
!= server
) {
2777 nfs_free_server(server
);
2780 error
= nfs_bdi_register(server
);
2782 goto error_splat_super
;
2786 /* initial superblock/root creation */
2787 nfs4_clone_super(s
, data
->sb
);
2788 nfs_fscache_get_super_cookie(s
, NULL
, data
);
2791 mntroot
= nfs4_get_root(s
, data
->fh
);
2792 if (IS_ERR(mntroot
)) {
2793 error
= PTR_ERR(mntroot
);
2794 goto error_splat_super
;
2796 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
2799 goto error_splat_super
;
2802 s
->s_flags
|= MS_ACTIVE
;
2804 mnt
->mnt_root
= mntroot
;
2806 security_sb_clone_mnt_opts(data
->sb
, s
);
2808 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2812 nfs_free_server(server
);
2814 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error
);
2818 deactivate_locked_super(s
);
2819 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error
);
2823 static int nfs4_remote_referral_get_sb(struct file_system_type
*fs_type
,
2824 int flags
, const char *dev_name
, void *raw_data
,
2825 struct vfsmount
*mnt
)
2827 struct nfs_clone_mount
*data
= raw_data
;
2828 struct super_block
*s
;
2829 struct nfs_server
*server
;
2830 struct dentry
*mntroot
;
2831 struct nfs_fh mntfh
;
2832 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2833 struct nfs_sb_mountdata sb_mntdata
= {
2838 dprintk("--> nfs4_referral_get_sb()\n");
2840 /* create a new volume representation */
2841 server
= nfs4_create_referral_server(data
, &mntfh
);
2842 if (IS_ERR(server
)) {
2843 error
= PTR_ERR(server
);
2844 goto out_err_noserver
;
2846 sb_mntdata
.server
= server
;
2848 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2849 compare_super
= NULL
;
2851 /* Get a superblock - note that we may end up sharing one that already exists */
2852 s
= sget(&nfs4_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2858 if (s
->s_fs_info
!= server
) {
2859 nfs_free_server(server
);
2862 error
= nfs_bdi_register(server
);
2864 goto error_splat_super
;
2868 /* initial superblock/root creation */
2870 nfs_fscache_get_super_cookie(s
, NULL
, data
);
2873 mntroot
= nfs4_get_root(s
, &mntfh
);
2874 if (IS_ERR(mntroot
)) {
2875 error
= PTR_ERR(mntroot
);
2876 goto error_splat_super
;
2878 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
2881 goto error_splat_super
;
2884 s
->s_flags
|= MS_ACTIVE
;
2886 mnt
->mnt_root
= mntroot
;
2888 security_sb_clone_mnt_opts(data
->sb
, s
);
2890 dprintk("<-- nfs4_referral_get_sb() = 0\n");
2894 nfs_free_server(server
);
2896 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error
);
2900 deactivate_locked_super(s
);
2901 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error
);
2906 * Create an NFS4 server record on referral traversal
2908 static int nfs4_referral_get_sb(struct file_system_type
*fs_type
,
2909 int flags
, const char *dev_name
, void *raw_data
,
2910 struct vfsmount
*mnt
)
2912 struct nfs_clone_mount
*data
= raw_data
;
2914 struct vfsmount
*root_mnt
;
2917 dprintk("--> nfs4_referral_get_sb()\n");
2919 export_path
= data
->mnt_path
;
2920 data
->mnt_path
= "/";
2922 root_mnt
= nfs_do_root_mount(&nfs4_remote_referral_fs_type
,
2923 flags
, data
, data
->hostname
);
2924 data
->mnt_path
= export_path
;
2926 error
= PTR_ERR(root_mnt
);
2927 if (IS_ERR(root_mnt
))
2930 error
= nfs_follow_remote_path(root_mnt
, export_path
, mnt
);
2932 dprintk("<-- nfs4_referral_get_sb() = %d%s\n", error
,
2933 error
!= 0 ? " [error]" : "");
2937 MODULE_ALIAS("nfs4");
2939 #endif /* CONFIG_NFS_V4 */