4 * Copyright (C) 1992 Rick Sladkey
6 * nfs superblock handling functions
8 * Modularised by Alan Cox <alan@lxorguk.ukuu.org.uk>, while hacking some
9 * experimental NFS changes. Modularisation taken straight from SYS5 fs.
11 * Change to nfs_read_super() to permit NFS mounts to multi-homed hosts.
12 * J.S.Peatfield@damtp.cam.ac.uk
14 * Split from inode.c by David Howells <dhowells@redhat.com>
16 * - superblocks are indexed on server only - all inodes, dentries, etc. associated with a
17 * particular server are held in the same superblock
18 * - NFS superblocks can have several effective roots to the dentry tree
19 * - directory type roots are spliced into the tree when a path from one root reaches the root
20 * of another (see nfs_lookup())
23 #include <linux/module.h>
24 #include <linux/init.h>
26 #include <linux/time.h>
27 #include <linux/kernel.h>
29 #include <linux/string.h>
30 #include <linux/stat.h>
31 #include <linux/errno.h>
32 #include <linux/unistd.h>
33 #include <linux/sunrpc/clnt.h>
34 #include <linux/sunrpc/stats.h>
35 #include <linux/sunrpc/metrics.h>
36 #include <linux/sunrpc/xprtsock.h>
37 #include <linux/sunrpc/xprtrdma.h>
38 #include <linux/nfs_fs.h>
39 #include <linux/nfs_mount.h>
40 #include <linux/nfs4_mount.h>
41 #include <linux/lockd/bind.h>
42 #include <linux/smp_lock.h>
43 #include <linux/seq_file.h>
44 #include <linux/mount.h>
45 #include <linux/mnt_namespace.h>
46 #include <linux/namei.h>
47 #include <linux/nfs_idmap.h>
48 #include <linux/vfs.h>
49 #include <linux/inet.h>
50 #include <linux/in6.h>
52 #include <linux/netdevice.h>
53 #include <linux/nfs_xdr.h>
54 #include <linux/magic.h>
55 #include <linux/parser.h>
57 #include <asm/system.h>
58 #include <asm/uaccess.h>
62 #include "delegation.h"
67 #define NFSDBG_FACILITY NFSDBG_VFS
70 /* Mount options that take no arguments */
72 Opt_posix
, Opt_noposix
,
77 Opt_udp
, Opt_tcp
, Opt_rdma
,
79 Opt_rdirplus
, Opt_nordirplus
,
80 Opt_sharecache
, Opt_nosharecache
,
81 Opt_resvport
, Opt_noresvport
,
82 Opt_fscache
, Opt_nofscache
,
84 /* Mount options that take integer arguments */
86 Opt_rsize
, Opt_wsize
, Opt_bsize
,
87 Opt_timeo
, Opt_retrans
,
88 Opt_acregmin
, Opt_acregmax
,
89 Opt_acdirmin
, Opt_acdirmax
,
97 /* Mount options that take string arguments */
98 Opt_sec
, Opt_proto
, Opt_mountproto
, Opt_mounthost
,
99 Opt_addr
, Opt_mountaddr
, Opt_clientaddr
,
103 /* Special mount options */
104 Opt_userspace
, Opt_deprecated
, Opt_sloppy
,
109 static const match_table_t nfs_mount_option_tokens
= {
110 { Opt_userspace
, "bg" },
111 { Opt_userspace
, "fg" },
112 { Opt_userspace
, "retry=%s" },
114 { Opt_sloppy
, "sloppy" },
116 { Opt_soft
, "soft" },
117 { Opt_hard
, "hard" },
118 { Opt_deprecated
, "intr" },
119 { Opt_deprecated
, "nointr" },
120 { Opt_posix
, "posix" },
121 { Opt_noposix
, "noposix" },
123 { Opt_nocto
, "nocto" },
125 { Opt_noac
, "noac" },
126 { Opt_lock
, "lock" },
127 { Opt_nolock
, "nolock" },
132 { Opt_rdma
, "rdma" },
134 { Opt_noacl
, "noacl" },
135 { Opt_rdirplus
, "rdirplus" },
136 { Opt_nordirplus
, "nordirplus" },
137 { Opt_sharecache
, "sharecache" },
138 { Opt_nosharecache
, "nosharecache" },
139 { Opt_resvport
, "resvport" },
140 { Opt_noresvport
, "noresvport" },
141 { Opt_fscache
, "fsc" },
142 { Opt_fscache_uniq
, "fsc=%s" },
143 { Opt_nofscache
, "nofsc" },
145 { Opt_port
, "port=%s" },
146 { Opt_rsize
, "rsize=%s" },
147 { Opt_wsize
, "wsize=%s" },
148 { Opt_bsize
, "bsize=%s" },
149 { Opt_timeo
, "timeo=%s" },
150 { Opt_retrans
, "retrans=%s" },
151 { Opt_acregmin
, "acregmin=%s" },
152 { Opt_acregmax
, "acregmax=%s" },
153 { Opt_acdirmin
, "acdirmin=%s" },
154 { Opt_acdirmax
, "acdirmax=%s" },
155 { Opt_actimeo
, "actimeo=%s" },
156 { Opt_namelen
, "namlen=%s" },
157 { Opt_mountport
, "mountport=%s" },
158 { Opt_mountvers
, "mountvers=%s" },
159 { Opt_nfsvers
, "nfsvers=%s" },
160 { Opt_nfsvers
, "vers=%s" },
161 { Opt_minorversion
, "minorversion=%s" },
163 { Opt_sec
, "sec=%s" },
164 { Opt_proto
, "proto=%s" },
165 { Opt_mountproto
, "mountproto=%s" },
166 { Opt_addr
, "addr=%s" },
167 { Opt_clientaddr
, "clientaddr=%s" },
168 { Opt_mounthost
, "mounthost=%s" },
169 { Opt_mountaddr
, "mountaddr=%s" },
171 { Opt_lookupcache
, "lookupcache=%s" },
177 Opt_xprt_udp
, Opt_xprt_tcp
, Opt_xprt_rdma
,
182 static const match_table_t nfs_xprt_protocol_tokens
= {
183 { Opt_xprt_udp
, "udp" },
184 { Opt_xprt_tcp
, "tcp" },
185 { Opt_xprt_rdma
, "rdma" },
187 { Opt_xprt_err
, NULL
}
191 Opt_sec_none
, Opt_sec_sys
,
192 Opt_sec_krb5
, Opt_sec_krb5i
, Opt_sec_krb5p
,
193 Opt_sec_lkey
, Opt_sec_lkeyi
, Opt_sec_lkeyp
,
194 Opt_sec_spkm
, Opt_sec_spkmi
, Opt_sec_spkmp
,
199 static const match_table_t nfs_secflavor_tokens
= {
200 { Opt_sec_none
, "none" },
201 { Opt_sec_none
, "null" },
202 { Opt_sec_sys
, "sys" },
204 { Opt_sec_krb5
, "krb5" },
205 { Opt_sec_krb5i
, "krb5i" },
206 { Opt_sec_krb5p
, "krb5p" },
208 { Opt_sec_lkey
, "lkey" },
209 { Opt_sec_lkeyi
, "lkeyi" },
210 { Opt_sec_lkeyp
, "lkeyp" },
212 { Opt_sec_spkm
, "spkm3" },
213 { Opt_sec_spkmi
, "spkm3i" },
214 { Opt_sec_spkmp
, "spkm3p" },
216 { Opt_sec_err
, NULL
}
220 Opt_lookupcache_all
, Opt_lookupcache_positive
,
221 Opt_lookupcache_none
,
226 static match_table_t nfs_lookupcache_tokens
= {
227 { Opt_lookupcache_all
, "all" },
228 { Opt_lookupcache_positive
, "pos" },
229 { Opt_lookupcache_positive
, "positive" },
230 { Opt_lookupcache_none
, "none" },
232 { Opt_lookupcache_err
, NULL
}
236 static void nfs_umount_begin(struct super_block
*);
237 static int nfs_statfs(struct dentry
*, struct kstatfs
*);
238 static int nfs_show_options(struct seq_file
*, struct vfsmount
*);
239 static int nfs_show_stats(struct seq_file
*, struct vfsmount
*);
240 static int nfs_get_sb(struct file_system_type
*, int, const char *, void *, struct vfsmount
*);
241 static int nfs_xdev_get_sb(struct file_system_type
*fs_type
,
242 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
243 static void nfs_kill_super(struct super_block
*);
244 static int nfs_remount(struct super_block
*sb
, int *flags
, char *raw_data
);
246 static struct file_system_type nfs_fs_type
= {
247 .owner
= THIS_MODULE
,
249 .get_sb
= nfs_get_sb
,
250 .kill_sb
= nfs_kill_super
,
251 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
254 struct file_system_type nfs_xdev_fs_type
= {
255 .owner
= THIS_MODULE
,
257 .get_sb
= nfs_xdev_get_sb
,
258 .kill_sb
= nfs_kill_super
,
259 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
262 static const struct super_operations nfs_sops
= {
263 .alloc_inode
= nfs_alloc_inode
,
264 .destroy_inode
= nfs_destroy_inode
,
265 .write_inode
= nfs_write_inode
,
266 .statfs
= nfs_statfs
,
267 .clear_inode
= nfs_clear_inode
,
268 .umount_begin
= nfs_umount_begin
,
269 .show_options
= nfs_show_options
,
270 .show_stats
= nfs_show_stats
,
271 .remount_fs
= nfs_remount
,
275 static int nfs4_validate_text_mount_data(void *options
,
276 struct nfs_parsed_mount_data
*args
, const char *dev_name
);
277 static int nfs4_try_mount(int flags
, const char *dev_name
,
278 struct nfs_parsed_mount_data
*data
, struct vfsmount
*mnt
);
279 static int nfs4_get_sb(struct file_system_type
*fs_type
,
280 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
281 static int nfs4_remote_get_sb(struct file_system_type
*fs_type
,
282 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
283 static int nfs4_xdev_get_sb(struct file_system_type
*fs_type
,
284 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
285 static int nfs4_referral_get_sb(struct file_system_type
*fs_type
,
286 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
287 static int nfs4_remote_referral_get_sb(struct file_system_type
*fs_type
,
288 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
289 static void nfs4_kill_super(struct super_block
*sb
);
291 static struct file_system_type nfs4_fs_type
= {
292 .owner
= THIS_MODULE
,
294 .get_sb
= nfs4_get_sb
,
295 .kill_sb
= nfs4_kill_super
,
296 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
299 static struct file_system_type nfs4_remote_fs_type
= {
300 .owner
= THIS_MODULE
,
302 .get_sb
= nfs4_remote_get_sb
,
303 .kill_sb
= nfs4_kill_super
,
304 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
307 struct file_system_type nfs4_xdev_fs_type
= {
308 .owner
= THIS_MODULE
,
310 .get_sb
= nfs4_xdev_get_sb
,
311 .kill_sb
= nfs4_kill_super
,
312 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
315 static struct file_system_type nfs4_remote_referral_fs_type
= {
316 .owner
= THIS_MODULE
,
318 .get_sb
= nfs4_remote_referral_get_sb
,
319 .kill_sb
= nfs4_kill_super
,
320 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
323 struct file_system_type nfs4_referral_fs_type
= {
324 .owner
= THIS_MODULE
,
326 .get_sb
= nfs4_referral_get_sb
,
327 .kill_sb
= nfs4_kill_super
,
328 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
331 static const struct super_operations nfs4_sops
= {
332 .alloc_inode
= nfs_alloc_inode
,
333 .destroy_inode
= nfs_destroy_inode
,
334 .write_inode
= nfs_write_inode
,
335 .statfs
= nfs_statfs
,
336 .clear_inode
= nfs4_clear_inode
,
337 .umount_begin
= nfs_umount_begin
,
338 .show_options
= nfs_show_options
,
339 .show_stats
= nfs_show_stats
,
340 .remount_fs
= nfs_remount
,
344 static struct shrinker acl_shrinker
= {
345 .shrink
= nfs_access_cache_shrinker
,
346 .seeks
= DEFAULT_SEEKS
,
350 * Register the NFS filesystems
352 int __init
register_nfs_fs(void)
356 ret
= register_filesystem(&nfs_fs_type
);
360 ret
= nfs_register_sysctl();
364 ret
= register_filesystem(&nfs4_fs_type
);
368 register_shrinker(&acl_shrinker
);
373 nfs_unregister_sysctl();
376 unregister_filesystem(&nfs_fs_type
);
382 * Unregister the NFS filesystems
384 void __exit
unregister_nfs_fs(void)
386 unregister_shrinker(&acl_shrinker
);
388 unregister_filesystem(&nfs4_fs_type
);
390 nfs_unregister_sysctl();
391 unregister_filesystem(&nfs_fs_type
);
394 void nfs_sb_active(struct super_block
*sb
)
396 struct nfs_server
*server
= NFS_SB(sb
);
398 if (atomic_inc_return(&server
->active
) == 1)
399 atomic_inc(&sb
->s_active
);
402 void nfs_sb_deactive(struct super_block
*sb
)
404 struct nfs_server
*server
= NFS_SB(sb
);
406 if (atomic_dec_and_test(&server
->active
))
407 deactivate_super(sb
);
411 * Deliver file system statistics to userspace
413 static int nfs_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
415 struct nfs_server
*server
= NFS_SB(dentry
->d_sb
);
416 unsigned char blockbits
;
417 unsigned long blockres
;
418 struct nfs_fh
*fh
= NFS_FH(dentry
->d_inode
);
419 struct nfs_fattr fattr
;
420 struct nfs_fsstat res
= {
425 error
= server
->nfs_client
->rpc_ops
->statfs(server
, fh
, &res
);
428 buf
->f_type
= NFS_SUPER_MAGIC
;
431 * Current versions of glibc do not correctly handle the
432 * case where f_frsize != f_bsize. Eventually we want to
433 * report the value of wtmult in this field.
435 buf
->f_frsize
= dentry
->d_sb
->s_blocksize
;
438 * On most *nix systems, f_blocks, f_bfree, and f_bavail
439 * are reported in units of f_frsize. Linux hasn't had
440 * an f_frsize field in its statfs struct until recently,
441 * thus historically Linux's sys_statfs reports these
442 * fields in units of f_bsize.
444 buf
->f_bsize
= dentry
->d_sb
->s_blocksize
;
445 blockbits
= dentry
->d_sb
->s_blocksize_bits
;
446 blockres
= (1 << blockbits
) - 1;
447 buf
->f_blocks
= (res
.tbytes
+ blockres
) >> blockbits
;
448 buf
->f_bfree
= (res
.fbytes
+ blockres
) >> blockbits
;
449 buf
->f_bavail
= (res
.abytes
+ blockres
) >> blockbits
;
451 buf
->f_files
= res
.tfiles
;
452 buf
->f_ffree
= res
.afiles
;
454 buf
->f_namelen
= server
->namelen
;
459 dprintk("%s: statfs error = %d\n", __func__
, -error
);
464 * Map the security flavour number to a name
466 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour
)
468 static const struct {
469 rpc_authflavor_t flavour
;
472 { RPC_AUTH_NULL
, "null" },
473 { RPC_AUTH_UNIX
, "sys" },
474 { RPC_AUTH_GSS_KRB5
, "krb5" },
475 { RPC_AUTH_GSS_KRB5I
, "krb5i" },
476 { RPC_AUTH_GSS_KRB5P
, "krb5p" },
477 { RPC_AUTH_GSS_LKEY
, "lkey" },
478 { RPC_AUTH_GSS_LKEYI
, "lkeyi" },
479 { RPC_AUTH_GSS_LKEYP
, "lkeyp" },
480 { RPC_AUTH_GSS_SPKM
, "spkm" },
481 { RPC_AUTH_GSS_SPKMI
, "spkmi" },
482 { RPC_AUTH_GSS_SPKMP
, "spkmp" },
483 { UINT_MAX
, "unknown" }
487 for (i
= 0; sec_flavours
[i
].flavour
!= UINT_MAX
; i
++) {
488 if (sec_flavours
[i
].flavour
== flavour
)
491 return sec_flavours
[i
].str
;
494 static void nfs_show_mountd_options(struct seq_file
*m
, struct nfs_server
*nfss
,
497 struct sockaddr
*sap
= (struct sockaddr
*)&nfss
->mountd_address
;
499 switch (sap
->sa_family
) {
501 struct sockaddr_in
*sin
= (struct sockaddr_in
*)sap
;
502 seq_printf(m
, ",mountaddr=%pI4", &sin
->sin_addr
.s_addr
);
506 struct sockaddr_in6
*sin6
= (struct sockaddr_in6
*)sap
;
507 seq_printf(m
, ",mountaddr=%pI6", &sin6
->sin6_addr
);
512 seq_printf(m
, ",mountaddr=unspecified");
515 if (nfss
->mountd_version
|| showdefaults
)
516 seq_printf(m
, ",mountvers=%u", nfss
->mountd_version
);
517 if (nfss
->mountd_port
|| showdefaults
)
518 seq_printf(m
, ",mountport=%u", nfss
->mountd_port
);
520 switch (nfss
->mountd_protocol
) {
522 seq_printf(m
, ",mountproto=udp");
525 seq_printf(m
, ",mountproto=tcp");
529 seq_printf(m
, ",mountproto=auto");
534 * Describe the mount options in force on this server representation
536 static void nfs_show_mount_options(struct seq_file
*m
, struct nfs_server
*nfss
,
539 static const struct proc_nfs_info
{
544 { NFS_MOUNT_SOFT
, ",soft", ",hard" },
545 { NFS_MOUNT_POSIX
, ",posix", "" },
546 { NFS_MOUNT_NOCTO
, ",nocto", "" },
547 { NFS_MOUNT_NOAC
, ",noac", "" },
548 { NFS_MOUNT_NONLM
, ",nolock", "" },
549 { NFS_MOUNT_NOACL
, ",noacl", "" },
550 { NFS_MOUNT_NORDIRPLUS
, ",nordirplus", "" },
551 { NFS_MOUNT_UNSHARED
, ",nosharecache", "" },
552 { NFS_MOUNT_NORESVPORT
, ",noresvport", "" },
555 const struct proc_nfs_info
*nfs_infop
;
556 struct nfs_client
*clp
= nfss
->nfs_client
;
557 u32 version
= clp
->rpc_ops
->version
;
559 seq_printf(m
, ",vers=%u", version
);
560 seq_printf(m
, ",rsize=%u", nfss
->rsize
);
561 seq_printf(m
, ",wsize=%u", nfss
->wsize
);
562 if (nfss
->bsize
!= 0)
563 seq_printf(m
, ",bsize=%u", nfss
->bsize
);
564 seq_printf(m
, ",namlen=%u", nfss
->namelen
);
565 if (nfss
->acregmin
!= NFS_DEF_ACREGMIN
*HZ
|| showdefaults
)
566 seq_printf(m
, ",acregmin=%u", nfss
->acregmin
/HZ
);
567 if (nfss
->acregmax
!= NFS_DEF_ACREGMAX
*HZ
|| showdefaults
)
568 seq_printf(m
, ",acregmax=%u", nfss
->acregmax
/HZ
);
569 if (nfss
->acdirmin
!= NFS_DEF_ACDIRMIN
*HZ
|| showdefaults
)
570 seq_printf(m
, ",acdirmin=%u", nfss
->acdirmin
/HZ
);
571 if (nfss
->acdirmax
!= NFS_DEF_ACDIRMAX
*HZ
|| showdefaults
)
572 seq_printf(m
, ",acdirmax=%u", nfss
->acdirmax
/HZ
);
573 for (nfs_infop
= nfs_info
; nfs_infop
->flag
; nfs_infop
++) {
574 if (nfss
->flags
& nfs_infop
->flag
)
575 seq_puts(m
, nfs_infop
->str
);
577 seq_puts(m
, nfs_infop
->nostr
);
579 seq_printf(m
, ",proto=%s",
580 rpc_peeraddr2str(nfss
->client
, RPC_DISPLAY_PROTO
));
582 if (nfss
->port
!= NFS_PORT
)
583 seq_printf(m
, ",port=%u", nfss
->port
);
586 seq_printf(m
, ",port=%u", nfss
->port
);
588 seq_printf(m
, ",timeo=%lu", 10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
);
589 seq_printf(m
, ",retrans=%u", nfss
->client
->cl_timeout
->to_retries
);
590 seq_printf(m
, ",sec=%s", nfs_pseudoflavour_to_name(nfss
->client
->cl_auth
->au_flavor
));
593 nfs_show_mountd_options(m
, nfss
, showdefaults
);
596 if (clp
->rpc_ops
->version
== 4)
597 seq_printf(m
, ",clientaddr=%s", clp
->cl_ipaddr
);
599 if (nfss
->options
& NFS_OPTION_FSCACHE
)
600 seq_printf(m
, ",fsc");
604 * Describe the mount options on this VFS mountpoint
606 static int nfs_show_options(struct seq_file
*m
, struct vfsmount
*mnt
)
608 struct nfs_server
*nfss
= NFS_SB(mnt
->mnt_sb
);
610 nfs_show_mount_options(m
, nfss
, 0);
612 seq_printf(m
, ",addr=%s",
613 rpc_peeraddr2str(nfss
->nfs_client
->cl_rpcclient
,
620 * Present statistical information for this VFS mountpoint
622 static int nfs_show_stats(struct seq_file
*m
, struct vfsmount
*mnt
)
625 struct nfs_server
*nfss
= NFS_SB(mnt
->mnt_sb
);
626 struct rpc_auth
*auth
= nfss
->client
->cl_auth
;
627 struct nfs_iostats totals
= { };
629 seq_printf(m
, "statvers=%s", NFS_IOSTAT_VERS
);
632 * Display all mount option settings
634 seq_printf(m
, "\n\topts:\t");
635 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_RDONLY
? "ro" : "rw");
636 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_SYNCHRONOUS
? ",sync" : "");
637 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_NOATIME
? ",noatime" : "");
638 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_NODIRATIME
? ",nodiratime" : "");
639 nfs_show_mount_options(m
, nfss
, 1);
641 seq_printf(m
, "\n\tage:\t%lu", (jiffies
- nfss
->mount_time
) / HZ
);
643 seq_printf(m
, "\n\tcaps:\t");
644 seq_printf(m
, "caps=0x%x", nfss
->caps
);
645 seq_printf(m
, ",wtmult=%u", nfss
->wtmult
);
646 seq_printf(m
, ",dtsize=%u", nfss
->dtsize
);
647 seq_printf(m
, ",bsize=%u", nfss
->bsize
);
648 seq_printf(m
, ",namlen=%u", nfss
->namelen
);
651 if (nfss
->nfs_client
->rpc_ops
->version
== 4) {
652 seq_printf(m
, "\n\tnfsv4:\t");
653 seq_printf(m
, "bm0=0x%x", nfss
->attr_bitmask
[0]);
654 seq_printf(m
, ",bm1=0x%x", nfss
->attr_bitmask
[1]);
655 seq_printf(m
, ",acl=0x%x", nfss
->acl_bitmask
);
660 * Display security flavor in effect for this mount
662 seq_printf(m
, "\n\tsec:\tflavor=%u", auth
->au_ops
->au_flavor
);
664 seq_printf(m
, ",pseudoflavor=%u", auth
->au_flavor
);
667 * Display superblock I/O counters
669 for_each_possible_cpu(cpu
) {
670 struct nfs_iostats
*stats
;
673 stats
= per_cpu_ptr(nfss
->io_stats
, cpu
);
675 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
676 totals
.events
[i
] += stats
->events
[i
];
677 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
678 totals
.bytes
[i
] += stats
->bytes
[i
];
679 #ifdef CONFIG_NFS_FSCACHE
680 for (i
= 0; i
< __NFSIOS_FSCACHEMAX
; i
++)
681 totals
.fscache
[i
] += stats
->fscache
[i
];
687 seq_printf(m
, "\n\tevents:\t");
688 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
689 seq_printf(m
, "%lu ", totals
.events
[i
]);
690 seq_printf(m
, "\n\tbytes:\t");
691 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
692 seq_printf(m
, "%Lu ", totals
.bytes
[i
]);
693 #ifdef CONFIG_NFS_FSCACHE
694 if (nfss
->options
& NFS_OPTION_FSCACHE
) {
695 seq_printf(m
, "\n\tfsc:\t");
696 for (i
= 0; i
< __NFSIOS_FSCACHEMAX
; i
++)
697 seq_printf(m
, "%Lu ", totals
.bytes
[i
]);
702 rpc_print_iostats(m
, nfss
->client
);
708 * Begin unmount by attempting to remove all automounted mountpoints we added
709 * in response to xdev traversals and referrals
711 static void nfs_umount_begin(struct super_block
*sb
)
713 struct nfs_server
*server
;
714 struct rpc_clnt
*rpc
;
719 /* -EIO all pending I/O */
720 rpc
= server
->client_acl
;
722 rpc_killall_tasks(rpc
);
723 rpc
= server
->client
;
725 rpc_killall_tasks(rpc
);
731 * Sanity-check a server address provided by the mount command.
733 * Address family must be initialized, and address must not be
734 * the ANY address for that family.
736 static int nfs_verify_server_address(struct sockaddr
*addr
)
738 switch (addr
->sa_family
) {
740 struct sockaddr_in
*sa
= (struct sockaddr_in
*)addr
;
741 return sa
->sin_addr
.s_addr
!= htonl(INADDR_ANY
);
744 struct in6_addr
*sa
= &((struct sockaddr_in6
*)addr
)->sin6_addr
;
745 return !ipv6_addr_any(sa
);
749 dfprintk(MOUNT
, "NFS: Invalid IP address specified\n");
754 * Select between a default port value and a user-specified port value.
755 * If a zero value is set, then autobind will be used.
757 static void nfs_set_default_port(struct sockaddr
*sap
, const int parsed_port
,
758 const unsigned short default_port
)
760 unsigned short port
= default_port
;
762 if (parsed_port
!= NFS_UNSPEC_PORT
)
765 rpc_set_port(sap
, port
);
769 * Sanity check the NFS transport protocol.
772 static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data
*mnt
)
774 switch (mnt
->nfs_server
.protocol
) {
775 case XPRT_TRANSPORT_UDP
:
776 case XPRT_TRANSPORT_TCP
:
777 case XPRT_TRANSPORT_RDMA
:
780 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
785 * For text based NFSv2/v3 mounts, the mount protocol transport default
786 * settings should depend upon the specified NFS transport.
788 static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data
*mnt
)
790 nfs_validate_transport_protocol(mnt
);
792 if (mnt
->mount_server
.protocol
== XPRT_TRANSPORT_UDP
||
793 mnt
->mount_server
.protocol
== XPRT_TRANSPORT_TCP
)
795 switch (mnt
->nfs_server
.protocol
) {
796 case XPRT_TRANSPORT_UDP
:
797 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_UDP
;
799 case XPRT_TRANSPORT_TCP
:
800 case XPRT_TRANSPORT_RDMA
:
801 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_TCP
;
806 * Parse the value of the 'sec=' option.
808 static int nfs_parse_security_flavors(char *value
,
809 struct nfs_parsed_mount_data
*mnt
)
811 substring_t args
[MAX_OPT_ARGS
];
813 dfprintk(MOUNT
, "NFS: parsing sec=%s option\n", value
);
815 switch (match_token(value
, nfs_secflavor_tokens
, args
)) {
817 mnt
->auth_flavors
[0] = RPC_AUTH_NULL
;
820 mnt
->auth_flavors
[0] = RPC_AUTH_UNIX
;
823 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5
;
826 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5I
;
829 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5P
;
832 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEY
;
835 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEYI
;
838 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEYP
;
841 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKM
;
844 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKMI
;
847 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKMP
;
853 mnt
->auth_flavor_len
= 1;
858 * Error-check and convert a string of mount options from user space into
859 * a data structure. The whole mount string is processed; bad options are
860 * skipped as they are encountered. If there were no errors, return 1;
861 * otherwise return 0 (zero).
863 static int nfs_parse_mount_options(char *raw
,
864 struct nfs_parsed_mount_data
*mnt
)
866 char *p
, *string
, *secdata
;
867 int rc
, sloppy
= 0, invalid_option
= 0;
870 dfprintk(MOUNT
, "NFS: mount options string was NULL.\n");
873 dfprintk(MOUNT
, "NFS: nfs mount opts='%s'\n", raw
);
875 secdata
= alloc_secdata();
879 rc
= security_sb_copy_data(raw
, secdata
);
881 goto out_security_failure
;
883 rc
= security_sb_parse_opts_str(secdata
, &mnt
->lsm_opts
);
885 goto out_security_failure
;
887 free_secdata(secdata
);
889 while ((p
= strsep(&raw
, ",")) != NULL
) {
890 substring_t args
[MAX_OPT_ARGS
];
891 unsigned long option
;
897 dfprintk(MOUNT
, "NFS: parsing nfs mount option '%s'\n", p
);
899 token
= match_token(p
, nfs_mount_option_tokens
, args
);
903 * boolean options: foo/nofoo
906 mnt
->flags
|= NFS_MOUNT_SOFT
;
909 mnt
->flags
&= ~NFS_MOUNT_SOFT
;
912 mnt
->flags
|= NFS_MOUNT_POSIX
;
915 mnt
->flags
&= ~NFS_MOUNT_POSIX
;
918 mnt
->flags
&= ~NFS_MOUNT_NOCTO
;
921 mnt
->flags
|= NFS_MOUNT_NOCTO
;
924 mnt
->flags
&= ~NFS_MOUNT_NOAC
;
927 mnt
->flags
|= NFS_MOUNT_NOAC
;
930 mnt
->flags
&= ~NFS_MOUNT_NONLM
;
933 mnt
->flags
|= NFS_MOUNT_NONLM
;
936 mnt
->flags
&= ~NFS_MOUNT_VER3
;
939 mnt
->flags
|= NFS_MOUNT_VER3
;
942 mnt
->flags
&= ~NFS_MOUNT_TCP
;
943 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
946 mnt
->flags
|= NFS_MOUNT_TCP
;
947 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
950 mnt
->flags
|= NFS_MOUNT_TCP
; /* for side protocols */
951 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_RDMA
;
952 xprt_load_transport(p
);
955 mnt
->flags
&= ~NFS_MOUNT_NOACL
;
958 mnt
->flags
|= NFS_MOUNT_NOACL
;
961 mnt
->flags
&= ~NFS_MOUNT_NORDIRPLUS
;
964 mnt
->flags
|= NFS_MOUNT_NORDIRPLUS
;
967 mnt
->flags
&= ~NFS_MOUNT_UNSHARED
;
969 case Opt_nosharecache
:
970 mnt
->flags
|= NFS_MOUNT_UNSHARED
;
973 mnt
->flags
&= ~NFS_MOUNT_NORESVPORT
;
976 mnt
->flags
|= NFS_MOUNT_NORESVPORT
;
979 mnt
->options
|= NFS_OPTION_FSCACHE
;
980 kfree(mnt
->fscache_uniq
);
981 mnt
->fscache_uniq
= NULL
;
984 mnt
->options
&= ~NFS_OPTION_FSCACHE
;
985 kfree(mnt
->fscache_uniq
);
986 mnt
->fscache_uniq
= NULL
;
988 case Opt_fscache_uniq
:
989 string
= match_strdup(args
);
992 kfree(mnt
->fscache_uniq
);
993 mnt
->fscache_uniq
= string
;
994 mnt
->options
|= NFS_OPTION_FSCACHE
;
998 * options that take numeric values
1001 string
= match_strdup(args
);
1004 rc
= strict_strtoul(string
, 10, &option
);
1006 if (rc
!= 0 || option
> USHORT_MAX
)
1007 goto out_invalid_value
;
1008 mnt
->nfs_server
.port
= option
;
1011 string
= match_strdup(args
);
1014 rc
= strict_strtoul(string
, 10, &option
);
1017 goto out_invalid_value
;
1018 mnt
->rsize
= option
;
1021 string
= match_strdup(args
);
1024 rc
= strict_strtoul(string
, 10, &option
);
1027 goto out_invalid_value
;
1028 mnt
->wsize
= option
;
1031 string
= match_strdup(args
);
1034 rc
= strict_strtoul(string
, 10, &option
);
1037 goto out_invalid_value
;
1038 mnt
->bsize
= option
;
1041 string
= match_strdup(args
);
1044 rc
= strict_strtoul(string
, 10, &option
);
1046 if (rc
!= 0 || option
== 0)
1047 goto out_invalid_value
;
1048 mnt
->timeo
= option
;
1051 string
= match_strdup(args
);
1054 rc
= strict_strtoul(string
, 10, &option
);
1056 if (rc
!= 0 || option
== 0)
1057 goto out_invalid_value
;
1058 mnt
->retrans
= option
;
1061 string
= match_strdup(args
);
1064 rc
= strict_strtoul(string
, 10, &option
);
1067 goto out_invalid_value
;
1068 mnt
->acregmin
= option
;
1071 string
= match_strdup(args
);
1074 rc
= strict_strtoul(string
, 10, &option
);
1077 goto out_invalid_value
;
1078 mnt
->acregmax
= option
;
1081 string
= match_strdup(args
);
1084 rc
= strict_strtoul(string
, 10, &option
);
1087 goto out_invalid_value
;
1088 mnt
->acdirmin
= option
;
1091 string
= match_strdup(args
);
1094 rc
= strict_strtoul(string
, 10, &option
);
1097 goto out_invalid_value
;
1098 mnt
->acdirmax
= option
;
1101 string
= match_strdup(args
);
1104 rc
= strict_strtoul(string
, 10, &option
);
1107 goto out_invalid_value
;
1108 mnt
->acregmin
= mnt
->acregmax
=
1109 mnt
->acdirmin
= mnt
->acdirmax
= option
;
1112 string
= match_strdup(args
);
1115 rc
= strict_strtoul(string
, 10, &option
);
1118 goto out_invalid_value
;
1119 mnt
->namlen
= option
;
1122 string
= match_strdup(args
);
1125 rc
= strict_strtoul(string
, 10, &option
);
1127 if (rc
!= 0 || option
> USHORT_MAX
)
1128 goto out_invalid_value
;
1129 mnt
->mount_server
.port
= option
;
1132 string
= match_strdup(args
);
1135 rc
= strict_strtoul(string
, 10, &option
);
1138 option
< NFS_MNT_VERSION
||
1139 option
> NFS_MNT3_VERSION
)
1140 goto out_invalid_value
;
1141 mnt
->mount_server
.version
= option
;
1144 string
= match_strdup(args
);
1147 rc
= strict_strtoul(string
, 10, &option
);
1150 goto out_invalid_value
;
1153 mnt
->flags
&= ~NFS_MOUNT_VER3
;
1156 mnt
->flags
|= NFS_MOUNT_VER3
;
1159 goto out_invalid_value
;
1162 case Opt_minorversion
:
1163 string
= match_strdup(args
);
1166 rc
= strict_strtoul(string
, 10, &option
);
1169 goto out_invalid_value
;
1170 if (option
> NFS4_MAX_MINOR_VERSION
)
1171 goto out_invalid_value
;
1172 mnt
->minorversion
= option
;
1176 * options that take text values
1179 string
= match_strdup(args
);
1182 rc
= nfs_parse_security_flavors(string
, mnt
);
1185 dfprintk(MOUNT
, "NFS: unrecognized "
1186 "security flavor\n");
1191 string
= match_strdup(args
);
1194 token
= match_token(string
,
1195 nfs_xprt_protocol_tokens
, args
);
1199 mnt
->flags
&= ~NFS_MOUNT_TCP
;
1200 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1204 mnt
->flags
|= NFS_MOUNT_TCP
;
1205 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1209 /* vector side protocols to TCP */
1210 mnt
->flags
|= NFS_MOUNT_TCP
;
1211 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_RDMA
;
1212 xprt_load_transport(string
);
1216 dfprintk(MOUNT
, "NFS: unrecognized "
1217 "transport protocol\n");
1221 case Opt_mountproto
:
1222 string
= match_strdup(args
);
1225 token
= match_token(string
,
1226 nfs_xprt_protocol_tokens
, args
);
1231 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_UDP
;
1234 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_TCP
;
1236 case Opt_xprt_rdma
: /* not used for side protocols */
1238 dfprintk(MOUNT
, "NFS: unrecognized "
1239 "transport protocol\n");
1244 string
= match_strdup(args
);
1247 mnt
->nfs_server
.addrlen
=
1248 rpc_pton(string
, strlen(string
),
1250 &mnt
->nfs_server
.address
,
1251 sizeof(mnt
->nfs_server
.address
));
1253 if (mnt
->nfs_server
.addrlen
== 0)
1254 goto out_invalid_address
;
1256 case Opt_clientaddr
:
1257 string
= match_strdup(args
);
1260 kfree(mnt
->client_address
);
1261 mnt
->client_address
= string
;
1264 string
= match_strdup(args
);
1267 kfree(mnt
->mount_server
.hostname
);
1268 mnt
->mount_server
.hostname
= string
;
1271 string
= match_strdup(args
);
1274 mnt
->mount_server
.addrlen
=
1275 rpc_pton(string
, strlen(string
),
1277 &mnt
->mount_server
.address
,
1278 sizeof(mnt
->mount_server
.address
));
1280 if (mnt
->mount_server
.addrlen
== 0)
1281 goto out_invalid_address
;
1283 case Opt_lookupcache
:
1284 string
= match_strdup(args
);
1287 token
= match_token(string
,
1288 nfs_lookupcache_tokens
, args
);
1291 case Opt_lookupcache_all
:
1292 mnt
->flags
&= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG
|NFS_MOUNT_LOOKUP_CACHE_NONE
);
1294 case Opt_lookupcache_positive
:
1295 mnt
->flags
&= ~NFS_MOUNT_LOOKUP_CACHE_NONE
;
1296 mnt
->flags
|= NFS_MOUNT_LOOKUP_CACHE_NONEG
;
1298 case Opt_lookupcache_none
:
1299 mnt
->flags
|= NFS_MOUNT_LOOKUP_CACHE_NONEG
|NFS_MOUNT_LOOKUP_CACHE_NONE
;
1302 dfprintk(MOUNT
, "NFS: invalid "
1303 "lookupcache argument\n");
1313 dfprintk(MOUNT
, "NFS: relaxing parsing rules\n");
1316 case Opt_deprecated
:
1317 dfprintk(MOUNT
, "NFS: ignoring mount option "
1323 dfprintk(MOUNT
, "NFS: unrecognized mount option "
1328 if (!sloppy
&& invalid_option
)
1333 out_invalid_address
:
1334 printk(KERN_INFO
"NFS: bad IP address specified: %s\n", p
);
1337 printk(KERN_INFO
"NFS: bad mount option value specified: %s\n", p
);
1340 printk(KERN_INFO
"NFS: not enough memory to parse option\n");
1342 out_security_failure
:
1343 free_secdata(secdata
);
1344 printk(KERN_INFO
"NFS: security options invalid: %d\n", rc
);
1349 * Match the requested auth flavors with the list returned by
1350 * the server. Returns zero and sets the mount's authentication
1351 * flavor on success; returns -EACCES if server does not support
1352 * the requested flavor.
1354 static int nfs_walk_authlist(struct nfs_parsed_mount_data
*args
,
1355 struct nfs_mount_request
*request
)
1357 unsigned int i
, j
, server_authlist_len
= *(request
->auth_flav_len
);
1360 * Certain releases of Linux's mountd return an empty
1361 * flavor list. To prevent behavioral regression with
1362 * these servers (ie. rejecting mounts that used to
1363 * succeed), revert to pre-2.6.32 behavior (no checking)
1364 * if the returned flavor list is empty.
1366 if (server_authlist_len
== 0)
1370 * We avoid sophisticated negotiating here, as there are
1371 * plenty of cases where we can get it wrong, providing
1372 * either too little or too much security.
1374 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1375 * flavor listed first. However, some servers list
1376 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1377 * preferred default, in args->auth_flavors[0] if user
1378 * didn't specify sec= mount option.
1380 for (i
= 0; i
< args
->auth_flavor_len
; i
++)
1381 for (j
= 0; j
< server_authlist_len
; j
++)
1382 if (args
->auth_flavors
[i
] == request
->auth_flavs
[j
]) {
1383 dfprintk(MOUNT
, "NFS: using auth flavor %d\n",
1384 request
->auth_flavs
[j
]);
1385 args
->auth_flavors
[0] = request
->auth_flavs
[j
];
1389 dfprintk(MOUNT
, "NFS: server does not support requested auth flavor\n");
1390 nfs_umount(request
);
1395 * Use the remote server's MOUNT service to request the NFS file handle
1396 * corresponding to the provided path.
1398 static int nfs_try_mount(struct nfs_parsed_mount_data
*args
,
1399 struct nfs_fh
*root_fh
)
1401 rpc_authflavor_t server_authlist
[NFS_MAX_SECFLAVORS
];
1402 unsigned int server_authlist_len
= ARRAY_SIZE(server_authlist
);
1403 struct nfs_mount_request request
= {
1404 .sap
= (struct sockaddr
*)
1405 &args
->mount_server
.address
,
1406 .dirpath
= args
->nfs_server
.export_path
,
1407 .protocol
= args
->mount_server
.protocol
,
1409 .noresvport
= args
->flags
& NFS_MOUNT_NORESVPORT
,
1410 .auth_flav_len
= &server_authlist_len
,
1411 .auth_flavs
= server_authlist
,
1415 if (args
->mount_server
.version
== 0) {
1416 if (args
->flags
& NFS_MOUNT_VER3
)
1417 args
->mount_server
.version
= NFS_MNT3_VERSION
;
1419 args
->mount_server
.version
= NFS_MNT_VERSION
;
1421 request
.version
= args
->mount_server
.version
;
1423 if (args
->mount_server
.hostname
)
1424 request
.hostname
= args
->mount_server
.hostname
;
1426 request
.hostname
= args
->nfs_server
.hostname
;
1429 * Construct the mount server's address.
1431 if (args
->mount_server
.address
.ss_family
== AF_UNSPEC
) {
1432 memcpy(request
.sap
, &args
->nfs_server
.address
,
1433 args
->nfs_server
.addrlen
);
1434 args
->mount_server
.addrlen
= args
->nfs_server
.addrlen
;
1436 request
.salen
= args
->mount_server
.addrlen
;
1437 nfs_set_default_port(request
.sap
, args
->mount_server
.port
, 0);
1440 * Now ask the mount server to map our export path
1443 status
= nfs_mount(&request
);
1445 dfprintk(MOUNT
, "NFS: unable to mount server %s, error %d\n",
1446 request
.hostname
, status
);
1451 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1453 if (args
->mount_server
.version
!= NFS_MNT3_VERSION
)
1455 return nfs_walk_authlist(args
, &request
);
1458 static int nfs_parse_simple_hostname(const char *dev_name
,
1459 char **hostname
, size_t maxnamlen
,
1460 char **export_path
, size_t maxpathlen
)
1463 char *colon
, *comma
;
1465 colon
= strchr(dev_name
, ':');
1467 goto out_bad_devname
;
1469 len
= colon
- dev_name
;
1470 if (len
> maxnamlen
)
1473 /* N.B. caller will free nfs_server.hostname in all cases */
1474 *hostname
= kstrndup(dev_name
, len
, GFP_KERNEL
);
1478 /* kill possible hostname list: not supported */
1479 comma
= strchr(*hostname
, ',');
1480 if (comma
!= NULL
) {
1481 if (comma
== *hostname
)
1482 goto out_bad_devname
;
1487 len
= strlen(colon
);
1488 if (len
> maxpathlen
)
1490 *export_path
= kstrndup(colon
, len
, GFP_KERNEL
);
1494 dfprintk(MOUNT
, "NFS: MNTPATH: '%s'\n", *export_path
);
1498 dfprintk(MOUNT
, "NFS: device name not in host:path format\n");
1502 dfprintk(MOUNT
, "NFS: not enough memory to parse device name\n");
1506 dfprintk(MOUNT
, "NFS: server hostname too long\n");
1507 return -ENAMETOOLONG
;
1510 dfprintk(MOUNT
, "NFS: export pathname too long\n");
1511 return -ENAMETOOLONG
;
1515 * Hostname has square brackets around it because it contains one or
1516 * more colons. We look for the first closing square bracket, and a
1517 * colon must follow it.
1519 static int nfs_parse_protected_hostname(const char *dev_name
,
1520 char **hostname
, size_t maxnamlen
,
1521 char **export_path
, size_t maxpathlen
)
1526 start
= (char *)(dev_name
+ 1);
1528 end
= strchr(start
, ']');
1530 goto out_bad_devname
;
1531 if (*(end
+ 1) != ':')
1532 goto out_bad_devname
;
1535 if (len
> maxnamlen
)
1538 /* N.B. caller will free nfs_server.hostname in all cases */
1539 *hostname
= kstrndup(start
, len
, GFP_KERNEL
);
1540 if (*hostname
== NULL
)
1545 if (len
> maxpathlen
)
1547 *export_path
= kstrndup(end
, len
, GFP_KERNEL
);
1554 dfprintk(MOUNT
, "NFS: device name not in host:path format\n");
1558 dfprintk(MOUNT
, "NFS: not enough memory to parse device name\n");
1562 dfprintk(MOUNT
, "NFS: server hostname too long\n");
1563 return -ENAMETOOLONG
;
1566 dfprintk(MOUNT
, "NFS: export pathname too long\n");
1567 return -ENAMETOOLONG
;
1571 * Split "dev_name" into "hostname:export_path".
1573 * The leftmost colon demarks the split between the server's hostname
1574 * and the export path. If the hostname starts with a left square
1575 * bracket, then it may contain colons.
1577 * Note: caller frees hostname and export path, even on error.
1579 static int nfs_parse_devname(const char *dev_name
,
1580 char **hostname
, size_t maxnamlen
,
1581 char **export_path
, size_t maxpathlen
)
1583 if (*dev_name
== '[')
1584 return nfs_parse_protected_hostname(dev_name
,
1585 hostname
, maxnamlen
,
1586 export_path
, maxpathlen
);
1588 return nfs_parse_simple_hostname(dev_name
,
1589 hostname
, maxnamlen
,
1590 export_path
, maxpathlen
);
1594 * Validate the NFS2/NFS3 mount data
1595 * - fills in the mount root filehandle
1597 * For option strings, user space handles the following behaviors:
1599 * + DNS: mapping server host name to IP address ("addr=" option)
1601 * + failure mode: how to behave if a mount request can't be handled
1602 * immediately ("fg/bg" option)
1604 * + retry: how often to retry a mount request ("retry=" option)
1606 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1607 * mountproto=tcp after mountproto=udp, and so on
1609 static int nfs_validate_mount_data(void *options
,
1610 struct nfs_parsed_mount_data
*args
,
1611 struct nfs_fh
*mntfh
,
1612 const char *dev_name
)
1614 struct nfs_mount_data
*data
= (struct nfs_mount_data
*)options
;
1615 struct sockaddr
*sap
= (struct sockaddr
*)&args
->nfs_server
.address
;
1620 args
->flags
= (NFS_MOUNT_VER3
| NFS_MOUNT_TCP
);
1621 args
->rsize
= NFS_MAX_FILE_IO_SIZE
;
1622 args
->wsize
= NFS_MAX_FILE_IO_SIZE
;
1623 args
->acregmin
= NFS_DEF_ACREGMIN
;
1624 args
->acregmax
= NFS_DEF_ACREGMAX
;
1625 args
->acdirmin
= NFS_DEF_ACDIRMIN
;
1626 args
->acdirmax
= NFS_DEF_ACDIRMAX
;
1627 args
->mount_server
.port
= NFS_UNSPEC_PORT
;
1628 args
->nfs_server
.port
= NFS_UNSPEC_PORT
;
1629 args
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1630 args
->auth_flavors
[0] = RPC_AUTH_UNIX
;
1631 args
->auth_flavor_len
= 1;
1633 switch (data
->version
) {
1639 if (data
->flags
& NFS_MOUNT_VER3
)
1641 data
->root
.size
= NFS2_FHSIZE
;
1642 memcpy(data
->root
.data
, data
->old_root
.data
, NFS2_FHSIZE
);
1644 if (data
->flags
& NFS_MOUNT_SECFLAVOUR
)
1647 memset(data
->context
, 0, sizeof(data
->context
));
1649 if (data
->flags
& NFS_MOUNT_VER3
) {
1650 if (data
->root
.size
> NFS3_FHSIZE
|| data
->root
.size
== 0)
1651 goto out_invalid_fh
;
1652 mntfh
->size
= data
->root
.size
;
1654 mntfh
->size
= NFS2_FHSIZE
;
1657 memcpy(mntfh
->data
, data
->root
.data
, mntfh
->size
);
1658 if (mntfh
->size
< sizeof(mntfh
->data
))
1659 memset(mntfh
->data
+ mntfh
->size
, 0,
1660 sizeof(mntfh
->data
) - mntfh
->size
);
1663 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1666 args
->flags
= data
->flags
& NFS_MOUNT_FLAGMASK
;
1667 args
->rsize
= data
->rsize
;
1668 args
->wsize
= data
->wsize
;
1669 args
->timeo
= data
->timeo
;
1670 args
->retrans
= data
->retrans
;
1671 args
->acregmin
= data
->acregmin
;
1672 args
->acregmax
= data
->acregmax
;
1673 args
->acdirmin
= data
->acdirmin
;
1674 args
->acdirmax
= data
->acdirmax
;
1676 memcpy(sap
, &data
->addr
, sizeof(data
->addr
));
1677 args
->nfs_server
.addrlen
= sizeof(data
->addr
);
1678 if (!nfs_verify_server_address(sap
))
1679 goto out_no_address
;
1681 if (!(data
->flags
& NFS_MOUNT_TCP
))
1682 args
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1683 /* N.B. caller will free nfs_server.hostname in all cases */
1684 args
->nfs_server
.hostname
= kstrdup(data
->hostname
, GFP_KERNEL
);
1685 args
->namlen
= data
->namlen
;
1686 args
->bsize
= data
->bsize
;
1688 if (data
->flags
& NFS_MOUNT_SECFLAVOUR
)
1689 args
->auth_flavors
[0] = data
->pseudoflavor
;
1690 if (!args
->nfs_server
.hostname
)
1694 * The legacy version 6 binary mount data from userspace has a
1695 * field used only to transport selinux information into the
1696 * the kernel. To continue to support that functionality we
1697 * have a touch of selinux knowledge here in the NFS code. The
1698 * userspace code converted context=blah to just blah so we are
1699 * converting back to the full string selinux understands.
1701 if (data
->context
[0]){
1702 #ifdef CONFIG_SECURITY_SELINUX
1704 char *opts_str
= kmalloc(sizeof(data
->context
) + 8, GFP_KERNEL
);
1707 strcpy(opts_str
, "context=");
1708 data
->context
[NFS_MAX_CONTEXT_LEN
] = '\0';
1709 strcat(opts_str
, &data
->context
[0]);
1710 rc
= security_sb_parse_opts_str(opts_str
, &args
->lsm_opts
);
1723 if (nfs_parse_mount_options((char *)options
, args
) == 0)
1726 if (!nfs_verify_server_address(sap
))
1727 goto out_no_address
;
1729 nfs_set_default_port(sap
, args
->nfs_server
.port
, 0);
1731 nfs_set_mount_transport_protocol(args
);
1733 status
= nfs_parse_devname(dev_name
,
1734 &args
->nfs_server
.hostname
,
1736 &args
->nfs_server
.export_path
,
1739 status
= nfs_try_mount(args
, mntfh
);
1741 kfree(args
->nfs_server
.export_path
);
1742 args
->nfs_server
.export_path
= NULL
;
1751 #ifndef CONFIG_NFS_V3
1752 if (args
->flags
& NFS_MOUNT_VER3
)
1753 goto out_v3_not_compiled
;
1754 #endif /* !CONFIG_NFS_V3 */
1759 dfprintk(MOUNT
, "NFS: mount program didn't pass any mount data\n");
1763 dfprintk(MOUNT
, "NFS: nfs_mount_data version %d does not support v3\n",
1768 dfprintk(MOUNT
, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1771 #ifndef CONFIG_NFS_V3
1772 out_v3_not_compiled
:
1773 dfprintk(MOUNT
, "NFS: NFSv3 is not compiled into kernel\n");
1774 return -EPROTONOSUPPORT
;
1775 #endif /* !CONFIG_NFS_V3 */
1778 dfprintk(MOUNT
, "NFS: not enough memory to handle mount options\n");
1782 dfprintk(MOUNT
, "NFS: mount program didn't pass remote address\n");
1786 dfprintk(MOUNT
, "NFS: invalid root filehandle\n");
1791 nfs_compare_remount_data(struct nfs_server
*nfss
,
1792 struct nfs_parsed_mount_data
*data
)
1794 if (data
->flags
!= nfss
->flags
||
1795 data
->rsize
!= nfss
->rsize
||
1796 data
->wsize
!= nfss
->wsize
||
1797 data
->retrans
!= nfss
->client
->cl_timeout
->to_retries
||
1798 data
->auth_flavors
[0] != nfss
->client
->cl_auth
->au_flavor
||
1799 data
->acregmin
!= nfss
->acregmin
/ HZ
||
1800 data
->acregmax
!= nfss
->acregmax
/ HZ
||
1801 data
->acdirmin
!= nfss
->acdirmin
/ HZ
||
1802 data
->acdirmax
!= nfss
->acdirmax
/ HZ
||
1803 data
->timeo
!= (10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
) ||
1804 data
->nfs_server
.addrlen
!= nfss
->nfs_client
->cl_addrlen
||
1805 memcmp(&data
->nfs_server
.address
, &nfss
->nfs_client
->cl_addr
,
1806 data
->nfs_server
.addrlen
) != 0)
1813 nfs_remount(struct super_block
*sb
, int *flags
, char *raw_data
)
1816 struct nfs_server
*nfss
= sb
->s_fs_info
;
1817 struct nfs_parsed_mount_data
*data
;
1818 struct nfs_mount_data
*options
= (struct nfs_mount_data
*)raw_data
;
1819 struct nfs4_mount_data
*options4
= (struct nfs4_mount_data
*)raw_data
;
1820 u32 nfsvers
= nfss
->nfs_client
->rpc_ops
->version
;
1823 * Userspace mount programs that send binary options generally send
1824 * them populated with default values. We have no way to know which
1825 * ones were explicitly specified. Fall back to legacy behavior and
1826 * just return success.
1828 if ((nfsvers
== 4 && (!options4
|| options4
->version
== 1)) ||
1829 (nfsvers
<= 3 && (!options
|| (options
->version
>= 1 &&
1830 options
->version
<= 6))))
1833 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
1838 /* fill out struct with values from existing mount */
1839 data
->flags
= nfss
->flags
;
1840 data
->rsize
= nfss
->rsize
;
1841 data
->wsize
= nfss
->wsize
;
1842 data
->retrans
= nfss
->client
->cl_timeout
->to_retries
;
1843 data
->auth_flavors
[0] = nfss
->client
->cl_auth
->au_flavor
;
1844 data
->acregmin
= nfss
->acregmin
/ HZ
;
1845 data
->acregmax
= nfss
->acregmax
/ HZ
;
1846 data
->acdirmin
= nfss
->acdirmin
/ HZ
;
1847 data
->acdirmax
= nfss
->acdirmax
/ HZ
;
1848 data
->timeo
= 10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
;
1849 data
->nfs_server
.addrlen
= nfss
->nfs_client
->cl_addrlen
;
1850 memcpy(&data
->nfs_server
.address
, &nfss
->nfs_client
->cl_addr
,
1851 data
->nfs_server
.addrlen
);
1853 /* overwrite those values with any that were specified */
1854 error
= nfs_parse_mount_options((char *)options
, data
);
1858 /* compare new mount options with old ones */
1859 error
= nfs_compare_remount_data(nfss
, data
);
1867 * Initialise the common bits of the superblock
1869 static inline void nfs_initialise_sb(struct super_block
*sb
)
1871 struct nfs_server
*server
= NFS_SB(sb
);
1873 sb
->s_magic
= NFS_SUPER_MAGIC
;
1875 /* We probably want something more informative here */
1876 snprintf(sb
->s_id
, sizeof(sb
->s_id
),
1877 "%x:%x", MAJOR(sb
->s_dev
), MINOR(sb
->s_dev
));
1879 if (sb
->s_blocksize
== 0)
1880 sb
->s_blocksize
= nfs_block_bits(server
->wsize
,
1881 &sb
->s_blocksize_bits
);
1883 if (server
->flags
& NFS_MOUNT_NOAC
)
1884 sb
->s_flags
|= MS_SYNCHRONOUS
;
1886 nfs_super_set_maxbytes(sb
, server
->maxfilesize
);
1890 * Finish setting up an NFS2/3 superblock
1892 static void nfs_fill_super(struct super_block
*sb
,
1893 struct nfs_parsed_mount_data
*data
)
1895 struct nfs_server
*server
= NFS_SB(sb
);
1897 sb
->s_blocksize_bits
= 0;
1898 sb
->s_blocksize
= 0;
1900 sb
->s_blocksize
= nfs_block_size(data
->bsize
, &sb
->s_blocksize_bits
);
1902 if (server
->flags
& NFS_MOUNT_VER3
) {
1903 /* The VFS shouldn't apply the umask to mode bits. We will do
1904 * so ourselves when necessary.
1906 sb
->s_flags
|= MS_POSIXACL
;
1907 sb
->s_time_gran
= 1;
1910 sb
->s_op
= &nfs_sops
;
1911 nfs_initialise_sb(sb
);
1915 * Finish setting up a cloned NFS2/3 superblock
1917 static void nfs_clone_super(struct super_block
*sb
,
1918 const struct super_block
*old_sb
)
1920 struct nfs_server
*server
= NFS_SB(sb
);
1922 sb
->s_blocksize_bits
= old_sb
->s_blocksize_bits
;
1923 sb
->s_blocksize
= old_sb
->s_blocksize
;
1924 sb
->s_maxbytes
= old_sb
->s_maxbytes
;
1926 if (server
->flags
& NFS_MOUNT_VER3
) {
1927 /* The VFS shouldn't apply the umask to mode bits. We will do
1928 * so ourselves when necessary.
1930 sb
->s_flags
|= MS_POSIXACL
;
1931 sb
->s_time_gran
= 1;
1934 sb
->s_op
= old_sb
->s_op
;
1935 nfs_initialise_sb(sb
);
1938 static int nfs_compare_mount_options(const struct super_block
*s
, const struct nfs_server
*b
, int flags
)
1940 const struct nfs_server
*a
= s
->s_fs_info
;
1941 const struct rpc_clnt
*clnt_a
= a
->client
;
1942 const struct rpc_clnt
*clnt_b
= b
->client
;
1944 if ((s
->s_flags
& NFS_MS_MASK
) != (flags
& NFS_MS_MASK
))
1946 if (a
->nfs_client
!= b
->nfs_client
)
1948 if (a
->flags
!= b
->flags
)
1950 if (a
->wsize
!= b
->wsize
)
1952 if (a
->rsize
!= b
->rsize
)
1954 if (a
->acregmin
!= b
->acregmin
)
1956 if (a
->acregmax
!= b
->acregmax
)
1958 if (a
->acdirmin
!= b
->acdirmin
)
1960 if (a
->acdirmax
!= b
->acdirmax
)
1962 if (clnt_a
->cl_auth
->au_flavor
!= clnt_b
->cl_auth
->au_flavor
)
1969 struct nfs_sb_mountdata
{
1970 struct nfs_server
*server
;
1974 static int nfs_set_super(struct super_block
*s
, void *data
)
1976 struct nfs_sb_mountdata
*sb_mntdata
= data
;
1977 struct nfs_server
*server
= sb_mntdata
->server
;
1980 s
->s_flags
= sb_mntdata
->mntflags
;
1981 s
->s_fs_info
= server
;
1982 ret
= set_anon_super(s
, server
);
1984 server
->s_dev
= s
->s_dev
;
1988 static int nfs_compare_super_address(struct nfs_server
*server1
,
1989 struct nfs_server
*server2
)
1991 struct sockaddr
*sap1
, *sap2
;
1993 sap1
= (struct sockaddr
*)&server1
->nfs_client
->cl_addr
;
1994 sap2
= (struct sockaddr
*)&server2
->nfs_client
->cl_addr
;
1996 if (sap1
->sa_family
!= sap2
->sa_family
)
1999 switch (sap1
->sa_family
) {
2001 struct sockaddr_in
*sin1
= (struct sockaddr_in
*)sap1
;
2002 struct sockaddr_in
*sin2
= (struct sockaddr_in
*)sap2
;
2003 if (sin1
->sin_addr
.s_addr
!= sin2
->sin_addr
.s_addr
)
2005 if (sin1
->sin_port
!= sin2
->sin_port
)
2010 struct sockaddr_in6
*sin1
= (struct sockaddr_in6
*)sap1
;
2011 struct sockaddr_in6
*sin2
= (struct sockaddr_in6
*)sap2
;
2012 if (!ipv6_addr_equal(&sin1
->sin6_addr
, &sin2
->sin6_addr
))
2014 if (sin1
->sin6_port
!= sin2
->sin6_port
)
2025 static int nfs_compare_super(struct super_block
*sb
, void *data
)
2027 struct nfs_sb_mountdata
*sb_mntdata
= data
;
2028 struct nfs_server
*server
= sb_mntdata
->server
, *old
= NFS_SB(sb
);
2029 int mntflags
= sb_mntdata
->mntflags
;
2031 if (!nfs_compare_super_address(old
, server
))
2033 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2034 if (old
->flags
& NFS_MOUNT_UNSHARED
)
2036 if (memcmp(&old
->fsid
, &server
->fsid
, sizeof(old
->fsid
)) != 0)
2038 return nfs_compare_mount_options(sb
, server
, mntflags
);
2041 static int nfs_bdi_register(struct nfs_server
*server
)
2043 return bdi_register_dev(&server
->backing_dev_info
, server
->s_dev
);
2046 static int nfs_get_sb(struct file_system_type
*fs_type
,
2047 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
2049 struct nfs_server
*server
= NULL
;
2050 struct super_block
*s
;
2051 struct nfs_parsed_mount_data
*data
;
2052 struct nfs_fh
*mntfh
;
2053 struct dentry
*mntroot
;
2054 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2055 struct nfs_sb_mountdata sb_mntdata
= {
2058 int error
= -ENOMEM
;
2060 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
2061 mntfh
= kzalloc(sizeof(*mntfh
), GFP_KERNEL
);
2062 if (data
== NULL
|| mntfh
== NULL
)
2065 security_init_mnt_opts(&data
->lsm_opts
);
2067 /* Validate the mount data */
2068 error
= nfs_validate_mount_data(raw_data
, data
, mntfh
, dev_name
);
2072 /* Get a volume representation */
2073 server
= nfs_create_server(data
, mntfh
);
2074 if (IS_ERR(server
)) {
2075 error
= PTR_ERR(server
);
2078 sb_mntdata
.server
= server
;
2080 if (server
->flags
& NFS_MOUNT_UNSHARED
)
2081 compare_super
= NULL
;
2083 /* Get a superblock - note that we may end up sharing one that already exists */
2084 s
= sget(fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2090 if (s
->s_fs_info
!= server
) {
2091 nfs_free_server(server
);
2094 error
= nfs_bdi_register(server
);
2096 goto error_splat_super
;
2100 /* initial superblock/root creation */
2101 nfs_fill_super(s
, data
);
2102 nfs_fscache_get_super_cookie(s
, data
);
2105 mntroot
= nfs_get_root(s
, mntfh
);
2106 if (IS_ERR(mntroot
)) {
2107 error
= PTR_ERR(mntroot
);
2108 goto error_splat_super
;
2111 error
= security_sb_set_mnt_opts(s
, &data
->lsm_opts
);
2113 goto error_splat_root
;
2115 s
->s_flags
|= MS_ACTIVE
;
2117 mnt
->mnt_root
= mntroot
;
2121 kfree(data
->nfs_server
.hostname
);
2122 kfree(data
->mount_server
.hostname
);
2123 kfree(data
->fscache_uniq
);
2124 security_free_mnt_opts(&data
->lsm_opts
);
2131 nfs_free_server(server
);
2137 deactivate_locked_super(s
);
2142 * Destroy an NFS2/3 superblock
2144 static void nfs_kill_super(struct super_block
*s
)
2146 struct nfs_server
*server
= NFS_SB(s
);
2148 bdi_unregister(&server
->backing_dev_info
);
2150 nfs_fscache_release_super_cookie(s
);
2151 nfs_free_server(server
);
2155 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2157 static int nfs_xdev_get_sb(struct file_system_type
*fs_type
, int flags
,
2158 const char *dev_name
, void *raw_data
,
2159 struct vfsmount
*mnt
)
2161 struct nfs_clone_mount
*data
= raw_data
;
2162 struct super_block
*s
;
2163 struct nfs_server
*server
;
2164 struct dentry
*mntroot
;
2165 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2166 struct nfs_sb_mountdata sb_mntdata
= {
2171 dprintk("--> nfs_xdev_get_sb()\n");
2173 /* create a new volume representation */
2174 server
= nfs_clone_server(NFS_SB(data
->sb
), data
->fh
, data
->fattr
);
2175 if (IS_ERR(server
)) {
2176 error
= PTR_ERR(server
);
2177 goto out_err_noserver
;
2179 sb_mntdata
.server
= server
;
2181 if (server
->flags
& NFS_MOUNT_UNSHARED
)
2182 compare_super
= NULL
;
2184 /* Get a superblock - note that we may end up sharing one that already exists */
2185 s
= sget(&nfs_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2191 if (s
->s_fs_info
!= server
) {
2192 nfs_free_server(server
);
2195 error
= nfs_bdi_register(server
);
2197 goto error_splat_super
;
2201 /* initial superblock/root creation */
2202 nfs_clone_super(s
, data
->sb
);
2205 mntroot
= nfs_get_root(s
, data
->fh
);
2206 if (IS_ERR(mntroot
)) {
2207 error
= PTR_ERR(mntroot
);
2208 goto error_splat_super
;
2210 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
2213 goto error_splat_super
;
2216 s
->s_flags
|= MS_ACTIVE
;
2218 mnt
->mnt_root
= mntroot
;
2220 /* clone any lsm security options from the parent to the new sb */
2221 security_sb_clone_mnt_opts(data
->sb
, s
);
2223 dprintk("<-- nfs_xdev_get_sb() = 0\n");
2227 nfs_free_server(server
);
2229 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error
);
2233 deactivate_locked_super(s
);
2234 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error
);
2238 #ifdef CONFIG_NFS_V4
2241 * Finish setting up a cloned NFS4 superblock
2243 static void nfs4_clone_super(struct super_block
*sb
,
2244 const struct super_block
*old_sb
)
2246 sb
->s_blocksize_bits
= old_sb
->s_blocksize_bits
;
2247 sb
->s_blocksize
= old_sb
->s_blocksize
;
2248 sb
->s_maxbytes
= old_sb
->s_maxbytes
;
2249 sb
->s_time_gran
= 1;
2250 sb
->s_op
= old_sb
->s_op
;
2251 nfs_initialise_sb(sb
);
2255 * Set up an NFS4 superblock
2257 static void nfs4_fill_super(struct super_block
*sb
)
2259 sb
->s_time_gran
= 1;
2260 sb
->s_op
= &nfs4_sops
;
2261 nfs_initialise_sb(sb
);
2264 static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data
*args
)
2266 args
->flags
&= ~(NFS_MOUNT_NONLM
|NFS_MOUNT_NOACL
|NFS_MOUNT_VER3
);
2269 static int nfs4_validate_text_mount_data(void *options
,
2270 struct nfs_parsed_mount_data
*args
,
2271 const char *dev_name
)
2273 struct sockaddr
*sap
= (struct sockaddr
*)&args
->nfs_server
.address
;
2275 nfs_set_default_port(sap
, args
->nfs_server
.port
, NFS_PORT
);
2277 nfs_validate_transport_protocol(args
);
2279 nfs4_validate_mount_flags(args
);
2281 if (args
->auth_flavor_len
> 1) {
2283 "NFS4: Too many RPC auth flavours specified\n");
2287 if (args
->client_address
== NULL
) {
2289 "NFS4: mount program didn't pass callback address\n");
2293 return nfs_parse_devname(dev_name
,
2294 &args
->nfs_server
.hostname
,
2296 &args
->nfs_server
.export_path
,
2301 * Validate NFSv4 mount options
2303 static int nfs4_validate_mount_data(void *options
,
2304 struct nfs_parsed_mount_data
*args
,
2305 const char *dev_name
)
2307 struct sockaddr
*sap
= (struct sockaddr
*)&args
->nfs_server
.address
;
2308 struct nfs4_mount_data
*data
= (struct nfs4_mount_data
*)options
;
2314 args
->rsize
= NFS_MAX_FILE_IO_SIZE
;
2315 args
->wsize
= NFS_MAX_FILE_IO_SIZE
;
2316 args
->acregmin
= NFS_DEF_ACREGMIN
;
2317 args
->acregmax
= NFS_DEF_ACREGMAX
;
2318 args
->acdirmin
= NFS_DEF_ACDIRMIN
;
2319 args
->acdirmax
= NFS_DEF_ACDIRMAX
;
2320 args
->nfs_server
.port
= NFS_UNSPEC_PORT
;
2321 args
->auth_flavors
[0] = RPC_AUTH_UNIX
;
2322 args
->auth_flavor_len
= 1;
2323 args
->minorversion
= 0;
2325 switch (data
->version
) {
2327 if (data
->host_addrlen
> sizeof(args
->nfs_server
.address
))
2328 goto out_no_address
;
2329 if (data
->host_addrlen
== 0)
2330 goto out_no_address
;
2331 args
->nfs_server
.addrlen
= data
->host_addrlen
;
2332 if (copy_from_user(sap
, data
->host_addr
, data
->host_addrlen
))
2334 if (!nfs_verify_server_address(sap
))
2335 goto out_no_address
;
2337 if (data
->auth_flavourlen
) {
2338 if (data
->auth_flavourlen
> 1)
2339 goto out_inval_auth
;
2340 if (copy_from_user(&args
->auth_flavors
[0],
2341 data
->auth_flavours
,
2342 sizeof(args
->auth_flavors
[0])))
2346 c
= strndup_user(data
->hostname
.data
, NFS4_MAXNAMLEN
);
2349 args
->nfs_server
.hostname
= c
;
2351 c
= strndup_user(data
->mnt_path
.data
, NFS4_MAXPATHLEN
);
2354 args
->nfs_server
.export_path
= c
;
2355 dfprintk(MOUNT
, "NFS: MNTPATH: '%s'\n", c
);
2357 c
= strndup_user(data
->client_addr
.data
, 16);
2360 args
->client_address
= c
;
2363 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2367 args
->flags
= data
->flags
& NFS4_MOUNT_FLAGMASK
;
2368 args
->rsize
= data
->rsize
;
2369 args
->wsize
= data
->wsize
;
2370 args
->timeo
= data
->timeo
;
2371 args
->retrans
= data
->retrans
;
2372 args
->acregmin
= data
->acregmin
;
2373 args
->acregmax
= data
->acregmax
;
2374 args
->acdirmin
= data
->acdirmin
;
2375 args
->acdirmax
= data
->acdirmax
;
2376 args
->nfs_server
.protocol
= data
->proto
;
2377 nfs_validate_transport_protocol(args
);
2381 if (nfs_parse_mount_options((char *)options
, args
) == 0)
2384 if (!nfs_verify_server_address(sap
))
2387 return nfs4_validate_text_mount_data(options
, args
, dev_name
);
2393 dfprintk(MOUNT
, "NFS4: mount program didn't pass any mount data\n");
2397 dfprintk(MOUNT
, "NFS4: Invalid number of RPC auth flavours %d\n",
2398 data
->auth_flavourlen
);
2402 dfprintk(MOUNT
, "NFS4: mount program didn't pass remote address\n");
2407 * Get the superblock for the NFS4 root partition
2409 static int nfs4_remote_get_sb(struct file_system_type
*fs_type
,
2410 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
2412 struct nfs_parsed_mount_data
*data
= raw_data
;
2413 struct super_block
*s
;
2414 struct nfs_server
*server
;
2415 struct nfs_fh
*mntfh
;
2416 struct dentry
*mntroot
;
2417 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2418 struct nfs_sb_mountdata sb_mntdata
= {
2421 int error
= -ENOMEM
;
2423 mntfh
= kzalloc(sizeof(*mntfh
), GFP_KERNEL
);
2424 if (data
== NULL
|| mntfh
== NULL
)
2427 security_init_mnt_opts(&data
->lsm_opts
);
2429 /* Get a volume representation */
2430 server
= nfs4_create_server(data
, mntfh
);
2431 if (IS_ERR(server
)) {
2432 error
= PTR_ERR(server
);
2435 sb_mntdata
.server
= server
;
2437 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2438 compare_super
= NULL
;
2440 /* Get a superblock - note that we may end up sharing one that already exists */
2441 s
= sget(&nfs4_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2447 if (s
->s_fs_info
!= server
) {
2448 nfs_free_server(server
);
2451 error
= nfs_bdi_register(server
);
2453 goto error_splat_super
;
2457 /* initial superblock/root creation */
2459 nfs_fscache_get_super_cookie(s
, data
);
2462 mntroot
= nfs4_get_root(s
, mntfh
);
2463 if (IS_ERR(mntroot
)) {
2464 error
= PTR_ERR(mntroot
);
2465 goto error_splat_super
;
2468 error
= security_sb_set_mnt_opts(s
, &data
->lsm_opts
);
2470 goto error_splat_root
;
2472 s
->s_flags
|= MS_ACTIVE
;
2474 mnt
->mnt_root
= mntroot
;
2478 security_free_mnt_opts(&data
->lsm_opts
);
2484 nfs_free_server(server
);
2490 deactivate_locked_super(s
);
2494 static struct vfsmount
*nfs_do_root_mount(struct file_system_type
*fs_type
,
2495 int flags
, void *data
, const char *hostname
)
2497 struct vfsmount
*root_mnt
;
2501 len
= strlen(hostname
) + 3;
2502 root_devname
= kmalloc(len
, GFP_KERNEL
);
2503 if (root_devname
== NULL
)
2504 return ERR_PTR(-ENOMEM
);
2505 snprintf(root_devname
, len
, "%s:/", hostname
);
2506 root_mnt
= vfs_kern_mount(fs_type
, flags
, root_devname
, data
);
2507 kfree(root_devname
);
2511 static void nfs_fix_devname(const struct path
*path
, struct vfsmount
*mnt
)
2513 char *page
= (char *) __get_free_page(GFP_KERNEL
);
2514 char *devname
, *tmp
;
2518 devname
= nfs_path(path
->mnt
->mnt_devname
,
2519 path
->mnt
->mnt_root
, path
->dentry
,
2521 if (devname
== NULL
)
2523 tmp
= kstrdup(devname
, GFP_KERNEL
);
2526 kfree(mnt
->mnt_devname
);
2527 mnt
->mnt_devname
= tmp
;
2529 free_page((unsigned long)page
);
2532 static int nfs_follow_remote_path(struct vfsmount
*root_mnt
,
2533 const char *export_path
, struct vfsmount
*mnt_target
)
2535 struct mnt_namespace
*ns_private
;
2536 struct nameidata nd
;
2537 struct super_block
*s
;
2540 ns_private
= create_mnt_ns(root_mnt
);
2541 ret
= PTR_ERR(ns_private
);
2542 if (IS_ERR(ns_private
))
2545 ret
= vfs_path_lookup(root_mnt
->mnt_root
, root_mnt
,
2546 export_path
, LOOKUP_FOLLOW
, &nd
);
2548 put_mnt_ns(ns_private
);
2553 s
= nd
.path
.mnt
->mnt_sb
;
2554 atomic_inc(&s
->s_active
);
2555 mnt_target
->mnt_sb
= s
;
2556 mnt_target
->mnt_root
= dget(nd
.path
.dentry
);
2558 /* Correct the device pathname */
2559 nfs_fix_devname(&nd
.path
, mnt_target
);
2562 down_write(&s
->s_umount
);
2570 static int nfs4_try_mount(int flags
, const char *dev_name
,
2571 struct nfs_parsed_mount_data
*data
,
2572 struct vfsmount
*mnt
)
2575 struct vfsmount
*root_mnt
;
2578 dfprintk(MOUNT
, "--> nfs4_try_mount()\n");
2580 export_path
= data
->nfs_server
.export_path
;
2581 data
->nfs_server
.export_path
= "/";
2582 root_mnt
= nfs_do_root_mount(&nfs4_remote_fs_type
, flags
, data
,
2583 data
->nfs_server
.hostname
);
2584 data
->nfs_server
.export_path
= export_path
;
2586 error
= PTR_ERR(root_mnt
);
2587 if (IS_ERR(root_mnt
))
2590 error
= nfs_follow_remote_path(root_mnt
, export_path
, mnt
);
2593 dfprintk(MOUNT
, "<-- nfs4_try_mount() = %d%s\n", error
,
2594 error
!= 0 ? " [error]" : "");
2599 * Get the superblock for an NFS4 mountpoint
2601 static int nfs4_get_sb(struct file_system_type
*fs_type
,
2602 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
2604 struct nfs_parsed_mount_data
*data
;
2605 int error
= -ENOMEM
;
2607 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
2611 /* Validate the mount data */
2612 error
= nfs4_validate_mount_data(raw_data
, data
, dev_name
);
2616 error
= nfs4_try_mount(flags
, dev_name
, data
, mnt
);
2619 kfree(data
->client_address
);
2620 kfree(data
->nfs_server
.export_path
);
2621 kfree(data
->nfs_server
.hostname
);
2622 kfree(data
->fscache_uniq
);
2625 dprintk("<-- nfs4_get_sb() = %d%s\n", error
,
2626 error
!= 0 ? " [error]" : "");
2630 static void nfs4_kill_super(struct super_block
*sb
)
2632 struct nfs_server
*server
= NFS_SB(sb
);
2634 dprintk("--> %s\n", __func__
);
2635 nfs_super_return_all_delegations(sb
);
2636 kill_anon_super(sb
);
2637 nfs4_renewd_prepare_shutdown(server
);
2638 nfs_fscache_release_super_cookie(sb
);
2639 nfs_free_server(server
);
2640 dprintk("<-- %s\n", __func__
);
2644 * Clone an NFS4 server record on xdev traversal (FSID-change)
2646 static int nfs4_xdev_get_sb(struct file_system_type
*fs_type
, int flags
,
2647 const char *dev_name
, void *raw_data
,
2648 struct vfsmount
*mnt
)
2650 struct nfs_clone_mount
*data
= raw_data
;
2651 struct super_block
*s
;
2652 struct nfs_server
*server
;
2653 struct dentry
*mntroot
;
2654 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2655 struct nfs_sb_mountdata sb_mntdata
= {
2660 dprintk("--> nfs4_xdev_get_sb()\n");
2662 /* create a new volume representation */
2663 server
= nfs_clone_server(NFS_SB(data
->sb
), data
->fh
, data
->fattr
);
2664 if (IS_ERR(server
)) {
2665 error
= PTR_ERR(server
);
2666 goto out_err_noserver
;
2668 sb_mntdata
.server
= server
;
2670 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2671 compare_super
= NULL
;
2673 /* Get a superblock - note that we may end up sharing one that already exists */
2674 s
= sget(&nfs4_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2680 if (s
->s_fs_info
!= server
) {
2681 nfs_free_server(server
);
2684 error
= nfs_bdi_register(server
);
2686 goto error_splat_super
;
2690 /* initial superblock/root creation */
2691 nfs4_clone_super(s
, data
->sb
);
2694 mntroot
= nfs4_get_root(s
, data
->fh
);
2695 if (IS_ERR(mntroot
)) {
2696 error
= PTR_ERR(mntroot
);
2697 goto error_splat_super
;
2699 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
2702 goto error_splat_super
;
2705 s
->s_flags
|= MS_ACTIVE
;
2707 mnt
->mnt_root
= mntroot
;
2709 security_sb_clone_mnt_opts(data
->sb
, s
);
2711 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2715 nfs_free_server(server
);
2717 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error
);
2721 deactivate_locked_super(s
);
2722 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error
);
2726 static int nfs4_remote_referral_get_sb(struct file_system_type
*fs_type
,
2727 int flags
, const char *dev_name
, void *raw_data
,
2728 struct vfsmount
*mnt
)
2730 struct nfs_clone_mount
*data
= raw_data
;
2731 struct super_block
*s
;
2732 struct nfs_server
*server
;
2733 struct dentry
*mntroot
;
2734 struct nfs_fh mntfh
;
2735 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2736 struct nfs_sb_mountdata sb_mntdata
= {
2741 dprintk("--> nfs4_referral_get_sb()\n");
2743 /* create a new volume representation */
2744 server
= nfs4_create_referral_server(data
, &mntfh
);
2745 if (IS_ERR(server
)) {
2746 error
= PTR_ERR(server
);
2747 goto out_err_noserver
;
2749 sb_mntdata
.server
= server
;
2751 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2752 compare_super
= NULL
;
2754 /* Get a superblock - note that we may end up sharing one that already exists */
2755 s
= sget(&nfs4_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2761 if (s
->s_fs_info
!= server
) {
2762 nfs_free_server(server
);
2765 error
= nfs_bdi_register(server
);
2767 goto error_splat_super
;
2771 /* initial superblock/root creation */
2775 mntroot
= nfs4_get_root(s
, &mntfh
);
2776 if (IS_ERR(mntroot
)) {
2777 error
= PTR_ERR(mntroot
);
2778 goto error_splat_super
;
2780 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
2783 goto error_splat_super
;
2786 s
->s_flags
|= MS_ACTIVE
;
2788 mnt
->mnt_root
= mntroot
;
2790 security_sb_clone_mnt_opts(data
->sb
, s
);
2792 dprintk("<-- nfs4_referral_get_sb() = 0\n");
2796 nfs_free_server(server
);
2798 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error
);
2802 deactivate_locked_super(s
);
2803 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error
);
2808 * Create an NFS4 server record on referral traversal
2810 static int nfs4_referral_get_sb(struct file_system_type
*fs_type
,
2811 int flags
, const char *dev_name
, void *raw_data
,
2812 struct vfsmount
*mnt
)
2814 struct nfs_clone_mount
*data
= raw_data
;
2816 struct vfsmount
*root_mnt
;
2819 dprintk("--> nfs4_referral_get_sb()\n");
2821 export_path
= data
->mnt_path
;
2822 data
->mnt_path
= "/";
2824 root_mnt
= nfs_do_root_mount(&nfs4_remote_referral_fs_type
,
2825 flags
, data
, data
->hostname
);
2826 data
->mnt_path
= export_path
;
2828 error
= PTR_ERR(root_mnt
);
2829 if (IS_ERR(root_mnt
))
2832 error
= nfs_follow_remote_path(root_mnt
, export_path
, mnt
);
2834 dprintk("<-- nfs4_referral_get_sb() = %d%s\n", error
,
2835 error
!= 0 ? " [error]" : "");
2839 #endif /* CONFIG_NFS_V4 */