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_kill_super(struct super_block
*);
245 static int nfs_remount(struct super_block
*sb
, int *flags
, char *raw_data
);
247 static struct file_system_type nfs_fs_type
= {
248 .owner
= THIS_MODULE
,
250 .get_sb
= nfs_get_sb
,
251 .kill_sb
= nfs_kill_super
,
252 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
255 struct file_system_type nfs_xdev_fs_type
= {
256 .owner
= THIS_MODULE
,
258 .get_sb
= nfs_xdev_get_sb
,
259 .kill_sb
= nfs_kill_super
,
260 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
263 static const struct super_operations nfs_sops
= {
264 .alloc_inode
= nfs_alloc_inode
,
265 .destroy_inode
= nfs_destroy_inode
,
266 .write_inode
= nfs_write_inode
,
267 .statfs
= nfs_statfs
,
268 .clear_inode
= nfs_clear_inode
,
269 .umount_begin
= nfs_umount_begin
,
270 .show_options
= nfs_show_options
,
271 .show_stats
= nfs_show_stats
,
272 .remount_fs
= nfs_remount
,
276 static int nfs4_validate_text_mount_data(void *options
,
277 struct nfs_parsed_mount_data
*args
, const char *dev_name
);
278 static int nfs4_try_mount(int flags
, const char *dev_name
,
279 struct nfs_parsed_mount_data
*data
, struct vfsmount
*mnt
);
280 static int nfs4_get_sb(struct file_system_type
*fs_type
,
281 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
282 static int nfs4_remote_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_xdev_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_referral_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_remote_referral_get_sb(struct file_system_type
*fs_type
,
289 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
290 static void nfs4_kill_super(struct super_block
*sb
);
292 static struct file_system_type nfs4_fs_type
= {
293 .owner
= THIS_MODULE
,
295 .get_sb
= nfs4_get_sb
,
296 .kill_sb
= nfs4_kill_super
,
297 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
300 static struct file_system_type nfs4_remote_fs_type
= {
301 .owner
= THIS_MODULE
,
303 .get_sb
= nfs4_remote_get_sb
,
304 .kill_sb
= nfs4_kill_super
,
305 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
308 struct file_system_type nfs4_xdev_fs_type
= {
309 .owner
= THIS_MODULE
,
311 .get_sb
= nfs4_xdev_get_sb
,
312 .kill_sb
= nfs4_kill_super
,
313 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
316 static struct file_system_type nfs4_remote_referral_fs_type
= {
317 .owner
= THIS_MODULE
,
319 .get_sb
= nfs4_remote_referral_get_sb
,
320 .kill_sb
= nfs4_kill_super
,
321 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
324 struct file_system_type nfs4_referral_fs_type
= {
325 .owner
= THIS_MODULE
,
327 .get_sb
= nfs4_referral_get_sb
,
328 .kill_sb
= nfs4_kill_super
,
329 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
332 static const struct super_operations nfs4_sops
= {
333 .alloc_inode
= nfs_alloc_inode
,
334 .destroy_inode
= nfs_destroy_inode
,
335 .write_inode
= nfs_write_inode
,
336 .statfs
= nfs_statfs
,
337 .clear_inode
= nfs4_clear_inode
,
338 .umount_begin
= nfs_umount_begin
,
339 .show_options
= nfs_show_options
,
340 .show_stats
= nfs_show_stats
,
341 .remount_fs
= nfs_remount
,
345 static struct shrinker acl_shrinker
= {
346 .shrink
= nfs_access_cache_shrinker
,
347 .seeks
= DEFAULT_SEEKS
,
351 * Register the NFS filesystems
353 int __init
register_nfs_fs(void)
357 ret
= register_filesystem(&nfs_fs_type
);
361 ret
= nfs_register_sysctl();
365 ret
= register_filesystem(&nfs4_fs_type
);
369 register_shrinker(&acl_shrinker
);
374 nfs_unregister_sysctl();
377 unregister_filesystem(&nfs_fs_type
);
383 * Unregister the NFS filesystems
385 void __exit
unregister_nfs_fs(void)
387 unregister_shrinker(&acl_shrinker
);
389 unregister_filesystem(&nfs4_fs_type
);
391 nfs_unregister_sysctl();
392 unregister_filesystem(&nfs_fs_type
);
395 void nfs_sb_active(struct super_block
*sb
)
397 struct nfs_server
*server
= NFS_SB(sb
);
399 if (atomic_inc_return(&server
->active
) == 1)
400 atomic_inc(&sb
->s_active
);
403 void nfs_sb_deactive(struct super_block
*sb
)
405 struct nfs_server
*server
= NFS_SB(sb
);
407 if (atomic_dec_and_test(&server
->active
))
408 deactivate_super(sb
);
412 * Deliver file system statistics to userspace
414 static int nfs_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
416 struct nfs_server
*server
= NFS_SB(dentry
->d_sb
);
417 unsigned char blockbits
;
418 unsigned long blockres
;
419 struct nfs_fh
*fh
= NFS_FH(dentry
->d_inode
);
420 struct nfs_fattr fattr
;
421 struct nfs_fsstat res
= {
426 error
= server
->nfs_client
->rpc_ops
->statfs(server
, fh
, &res
);
429 buf
->f_type
= NFS_SUPER_MAGIC
;
432 * Current versions of glibc do not correctly handle the
433 * case where f_frsize != f_bsize. Eventually we want to
434 * report the value of wtmult in this field.
436 buf
->f_frsize
= dentry
->d_sb
->s_blocksize
;
439 * On most *nix systems, f_blocks, f_bfree, and f_bavail
440 * are reported in units of f_frsize. Linux hasn't had
441 * an f_frsize field in its statfs struct until recently,
442 * thus historically Linux's sys_statfs reports these
443 * fields in units of f_bsize.
445 buf
->f_bsize
= dentry
->d_sb
->s_blocksize
;
446 blockbits
= dentry
->d_sb
->s_blocksize_bits
;
447 blockres
= (1 << blockbits
) - 1;
448 buf
->f_blocks
= (res
.tbytes
+ blockres
) >> blockbits
;
449 buf
->f_bfree
= (res
.fbytes
+ blockres
) >> blockbits
;
450 buf
->f_bavail
= (res
.abytes
+ blockres
) >> blockbits
;
452 buf
->f_files
= res
.tfiles
;
453 buf
->f_ffree
= res
.afiles
;
455 buf
->f_namelen
= server
->namelen
;
460 dprintk("%s: statfs error = %d\n", __func__
, -error
);
465 * Map the security flavour number to a name
467 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour
)
469 static const struct {
470 rpc_authflavor_t flavour
;
473 { RPC_AUTH_NULL
, "null" },
474 { RPC_AUTH_UNIX
, "sys" },
475 { RPC_AUTH_GSS_KRB5
, "krb5" },
476 { RPC_AUTH_GSS_KRB5I
, "krb5i" },
477 { RPC_AUTH_GSS_KRB5P
, "krb5p" },
478 { RPC_AUTH_GSS_LKEY
, "lkey" },
479 { RPC_AUTH_GSS_LKEYI
, "lkeyi" },
480 { RPC_AUTH_GSS_LKEYP
, "lkeyp" },
481 { RPC_AUTH_GSS_SPKM
, "spkm" },
482 { RPC_AUTH_GSS_SPKMI
, "spkmi" },
483 { RPC_AUTH_GSS_SPKMP
, "spkmp" },
484 { UINT_MAX
, "unknown" }
488 for (i
= 0; sec_flavours
[i
].flavour
!= UINT_MAX
; i
++) {
489 if (sec_flavours
[i
].flavour
== flavour
)
492 return sec_flavours
[i
].str
;
495 static void nfs_show_mountd_options(struct seq_file
*m
, struct nfs_server
*nfss
,
498 struct sockaddr
*sap
= (struct sockaddr
*)&nfss
->mountd_address
;
500 switch (sap
->sa_family
) {
502 struct sockaddr_in
*sin
= (struct sockaddr_in
*)sap
;
503 seq_printf(m
, ",mountaddr=%pI4", &sin
->sin_addr
.s_addr
);
507 struct sockaddr_in6
*sin6
= (struct sockaddr_in6
*)sap
;
508 seq_printf(m
, ",mountaddr=%pI6", &sin6
->sin6_addr
);
513 seq_printf(m
, ",mountaddr=unspecified");
516 if (nfss
->mountd_version
|| showdefaults
)
517 seq_printf(m
, ",mountvers=%u", nfss
->mountd_version
);
518 if (nfss
->mountd_port
|| showdefaults
)
519 seq_printf(m
, ",mountport=%u", nfss
->mountd_port
);
521 switch (nfss
->mountd_protocol
) {
523 seq_printf(m
, ",mountproto=udp");
526 seq_printf(m
, ",mountproto=tcp");
530 seq_printf(m
, ",mountproto=auto");
535 * Describe the mount options in force on this server representation
537 static void nfs_show_mount_options(struct seq_file
*m
, struct nfs_server
*nfss
,
540 static const struct proc_nfs_info
{
545 { NFS_MOUNT_SOFT
, ",soft", ",hard" },
546 { NFS_MOUNT_POSIX
, ",posix", "" },
547 { NFS_MOUNT_NOCTO
, ",nocto", "" },
548 { NFS_MOUNT_NOAC
, ",noac", "" },
549 { NFS_MOUNT_NONLM
, ",nolock", "" },
550 { NFS_MOUNT_NOACL
, ",noacl", "" },
551 { NFS_MOUNT_NORDIRPLUS
, ",nordirplus", "" },
552 { NFS_MOUNT_UNSHARED
, ",nosharecache", "" },
553 { NFS_MOUNT_NORESVPORT
, ",noresvport", "" },
556 const struct proc_nfs_info
*nfs_infop
;
557 struct nfs_client
*clp
= nfss
->nfs_client
;
558 u32 version
= clp
->rpc_ops
->version
;
560 seq_printf(m
, ",vers=%u", version
);
561 seq_printf(m
, ",rsize=%u", nfss
->rsize
);
562 seq_printf(m
, ",wsize=%u", nfss
->wsize
);
563 if (nfss
->bsize
!= 0)
564 seq_printf(m
, ",bsize=%u", nfss
->bsize
);
565 seq_printf(m
, ",namlen=%u", nfss
->namelen
);
566 if (nfss
->acregmin
!= NFS_DEF_ACREGMIN
*HZ
|| showdefaults
)
567 seq_printf(m
, ",acregmin=%u", nfss
->acregmin
/HZ
);
568 if (nfss
->acregmax
!= NFS_DEF_ACREGMAX
*HZ
|| showdefaults
)
569 seq_printf(m
, ",acregmax=%u", nfss
->acregmax
/HZ
);
570 if (nfss
->acdirmin
!= NFS_DEF_ACDIRMIN
*HZ
|| showdefaults
)
571 seq_printf(m
, ",acdirmin=%u", nfss
->acdirmin
/HZ
);
572 if (nfss
->acdirmax
!= NFS_DEF_ACDIRMAX
*HZ
|| showdefaults
)
573 seq_printf(m
, ",acdirmax=%u", nfss
->acdirmax
/HZ
);
574 for (nfs_infop
= nfs_info
; nfs_infop
->flag
; nfs_infop
++) {
575 if (nfss
->flags
& nfs_infop
->flag
)
576 seq_puts(m
, nfs_infop
->str
);
578 seq_puts(m
, nfs_infop
->nostr
);
580 seq_printf(m
, ",proto=%s",
581 rpc_peeraddr2str(nfss
->client
, RPC_DISPLAY_PROTO
));
583 if (nfss
->port
!= NFS_PORT
)
584 seq_printf(m
, ",port=%u", nfss
->port
);
587 seq_printf(m
, ",port=%u", nfss
->port
);
589 seq_printf(m
, ",timeo=%lu", 10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
);
590 seq_printf(m
, ",retrans=%u", nfss
->client
->cl_timeout
->to_retries
);
591 seq_printf(m
, ",sec=%s", nfs_pseudoflavour_to_name(nfss
->client
->cl_auth
->au_flavor
));
594 nfs_show_mountd_options(m
, nfss
, showdefaults
);
597 if (clp
->rpc_ops
->version
== 4)
598 seq_printf(m
, ",clientaddr=%s", clp
->cl_ipaddr
);
600 if (nfss
->options
& NFS_OPTION_FSCACHE
)
601 seq_printf(m
, ",fsc");
605 * Describe the mount options on this VFS mountpoint
607 static int nfs_show_options(struct seq_file
*m
, struct vfsmount
*mnt
)
609 struct nfs_server
*nfss
= NFS_SB(mnt
->mnt_sb
);
611 nfs_show_mount_options(m
, nfss
, 0);
613 seq_printf(m
, ",addr=%s",
614 rpc_peeraddr2str(nfss
->nfs_client
->cl_rpcclient
,
621 * Present statistical information for this VFS mountpoint
623 static int nfs_show_stats(struct seq_file
*m
, struct vfsmount
*mnt
)
626 struct nfs_server
*nfss
= NFS_SB(mnt
->mnt_sb
);
627 struct rpc_auth
*auth
= nfss
->client
->cl_auth
;
628 struct nfs_iostats totals
= { };
630 seq_printf(m
, "statvers=%s", NFS_IOSTAT_VERS
);
633 * Display all mount option settings
635 seq_printf(m
, "\n\topts:\t");
636 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_RDONLY
? "ro" : "rw");
637 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_SYNCHRONOUS
? ",sync" : "");
638 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_NOATIME
? ",noatime" : "");
639 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_NODIRATIME
? ",nodiratime" : "");
640 nfs_show_mount_options(m
, nfss
, 1);
642 seq_printf(m
, "\n\tage:\t%lu", (jiffies
- nfss
->mount_time
) / HZ
);
644 seq_printf(m
, "\n\tcaps:\t");
645 seq_printf(m
, "caps=0x%x", nfss
->caps
);
646 seq_printf(m
, ",wtmult=%u", nfss
->wtmult
);
647 seq_printf(m
, ",dtsize=%u", nfss
->dtsize
);
648 seq_printf(m
, ",bsize=%u", nfss
->bsize
);
649 seq_printf(m
, ",namlen=%u", nfss
->namelen
);
652 if (nfss
->nfs_client
->rpc_ops
->version
== 4) {
653 seq_printf(m
, "\n\tnfsv4:\t");
654 seq_printf(m
, "bm0=0x%x", nfss
->attr_bitmask
[0]);
655 seq_printf(m
, ",bm1=0x%x", nfss
->attr_bitmask
[1]);
656 seq_printf(m
, ",acl=0x%x", nfss
->acl_bitmask
);
661 * Display security flavor in effect for this mount
663 seq_printf(m
, "\n\tsec:\tflavor=%u", auth
->au_ops
->au_flavor
);
665 seq_printf(m
, ",pseudoflavor=%u", auth
->au_flavor
);
668 * Display superblock I/O counters
670 for_each_possible_cpu(cpu
) {
671 struct nfs_iostats
*stats
;
674 stats
= per_cpu_ptr(nfss
->io_stats
, cpu
);
676 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
677 totals
.events
[i
] += stats
->events
[i
];
678 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
679 totals
.bytes
[i
] += stats
->bytes
[i
];
680 #ifdef CONFIG_NFS_FSCACHE
681 for (i
= 0; i
< __NFSIOS_FSCACHEMAX
; i
++)
682 totals
.fscache
[i
] += stats
->fscache
[i
];
688 seq_printf(m
, "\n\tevents:\t");
689 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
690 seq_printf(m
, "%lu ", totals
.events
[i
]);
691 seq_printf(m
, "\n\tbytes:\t");
692 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
693 seq_printf(m
, "%Lu ", totals
.bytes
[i
]);
694 #ifdef CONFIG_NFS_FSCACHE
695 if (nfss
->options
& NFS_OPTION_FSCACHE
) {
696 seq_printf(m
, "\n\tfsc:\t");
697 for (i
= 0; i
< __NFSIOS_FSCACHEMAX
; i
++)
698 seq_printf(m
, "%Lu ", totals
.bytes
[i
]);
703 rpc_print_iostats(m
, nfss
->client
);
709 * Begin unmount by attempting to remove all automounted mountpoints we added
710 * in response to xdev traversals and referrals
712 static void nfs_umount_begin(struct super_block
*sb
)
714 struct nfs_server
*server
;
715 struct rpc_clnt
*rpc
;
720 /* -EIO all pending I/O */
721 rpc
= server
->client_acl
;
723 rpc_killall_tasks(rpc
);
724 rpc
= server
->client
;
726 rpc_killall_tasks(rpc
);
732 * Sanity-check a server address provided by the mount command.
734 * Address family must be initialized, and address must not be
735 * the ANY address for that family.
737 static int nfs_verify_server_address(struct sockaddr
*addr
)
739 switch (addr
->sa_family
) {
741 struct sockaddr_in
*sa
= (struct sockaddr_in
*)addr
;
742 return sa
->sin_addr
.s_addr
!= htonl(INADDR_ANY
);
745 struct in6_addr
*sa
= &((struct sockaddr_in6
*)addr
)->sin6_addr
;
746 return !ipv6_addr_any(sa
);
750 dfprintk(MOUNT
, "NFS: Invalid IP address specified\n");
755 * Select between a default port value and a user-specified port value.
756 * If a zero value is set, then autobind will be used.
758 static void nfs_set_default_port(struct sockaddr
*sap
, const int parsed_port
,
759 const unsigned short default_port
)
761 unsigned short port
= default_port
;
763 if (parsed_port
!= NFS_UNSPEC_PORT
)
766 rpc_set_port(sap
, port
);
770 * Sanity check the NFS transport protocol.
773 static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data
*mnt
)
775 switch (mnt
->nfs_server
.protocol
) {
776 case XPRT_TRANSPORT_UDP
:
777 case XPRT_TRANSPORT_TCP
:
778 case XPRT_TRANSPORT_RDMA
:
781 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
786 * For text based NFSv2/v3 mounts, the mount protocol transport default
787 * settings should depend upon the specified NFS transport.
789 static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data
*mnt
)
791 nfs_validate_transport_protocol(mnt
);
793 if (mnt
->mount_server
.protocol
== XPRT_TRANSPORT_UDP
||
794 mnt
->mount_server
.protocol
== XPRT_TRANSPORT_TCP
)
796 switch (mnt
->nfs_server
.protocol
) {
797 case XPRT_TRANSPORT_UDP
:
798 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_UDP
;
800 case XPRT_TRANSPORT_TCP
:
801 case XPRT_TRANSPORT_RDMA
:
802 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_TCP
;
807 * Parse the value of the 'sec=' option.
809 static int nfs_parse_security_flavors(char *value
,
810 struct nfs_parsed_mount_data
*mnt
)
812 substring_t args
[MAX_OPT_ARGS
];
814 dfprintk(MOUNT
, "NFS: parsing sec=%s option\n", value
);
816 switch (match_token(value
, nfs_secflavor_tokens
, args
)) {
818 mnt
->auth_flavors
[0] = RPC_AUTH_NULL
;
821 mnt
->auth_flavors
[0] = RPC_AUTH_UNIX
;
824 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5
;
827 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5I
;
830 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5P
;
833 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEY
;
836 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEYI
;
839 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEYP
;
842 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKM
;
845 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKMI
;
848 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKMP
;
854 mnt
->auth_flavor_len
= 1;
859 * Error-check and convert a string of mount options from user space into
860 * a data structure. The whole mount string is processed; bad options are
861 * skipped as they are encountered. If there were no errors, return 1;
862 * otherwise return 0 (zero).
864 static int nfs_parse_mount_options(char *raw
,
865 struct nfs_parsed_mount_data
*mnt
)
867 char *p
, *string
, *secdata
;
868 int rc
, sloppy
= 0, invalid_option
= 0;
871 dfprintk(MOUNT
, "NFS: mount options string was NULL.\n");
874 dfprintk(MOUNT
, "NFS: nfs mount opts='%s'\n", raw
);
876 secdata
= alloc_secdata();
880 rc
= security_sb_copy_data(raw
, secdata
);
882 goto out_security_failure
;
884 rc
= security_sb_parse_opts_str(secdata
, &mnt
->lsm_opts
);
886 goto out_security_failure
;
888 free_secdata(secdata
);
890 while ((p
= strsep(&raw
, ",")) != NULL
) {
891 substring_t args
[MAX_OPT_ARGS
];
892 unsigned long option
;
898 dfprintk(MOUNT
, "NFS: parsing nfs mount option '%s'\n", p
);
900 token
= match_token(p
, nfs_mount_option_tokens
, args
);
904 * boolean options: foo/nofoo
907 mnt
->flags
|= NFS_MOUNT_SOFT
;
910 mnt
->flags
&= ~NFS_MOUNT_SOFT
;
913 mnt
->flags
|= NFS_MOUNT_POSIX
;
916 mnt
->flags
&= ~NFS_MOUNT_POSIX
;
919 mnt
->flags
&= ~NFS_MOUNT_NOCTO
;
922 mnt
->flags
|= NFS_MOUNT_NOCTO
;
925 mnt
->flags
&= ~NFS_MOUNT_NOAC
;
928 mnt
->flags
|= NFS_MOUNT_NOAC
;
931 mnt
->flags
&= ~NFS_MOUNT_NONLM
;
934 mnt
->flags
|= NFS_MOUNT_NONLM
;
937 mnt
->flags
&= ~NFS_MOUNT_VER3
;
941 mnt
->flags
|= NFS_MOUNT_VER3
;
946 mnt
->flags
&= ~NFS_MOUNT_VER3
;
951 mnt
->flags
&= ~NFS_MOUNT_TCP
;
952 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
955 mnt
->flags
|= NFS_MOUNT_TCP
;
956 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
959 mnt
->flags
|= NFS_MOUNT_TCP
; /* for side protocols */
960 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_RDMA
;
961 xprt_load_transport(p
);
964 mnt
->flags
&= ~NFS_MOUNT_NOACL
;
967 mnt
->flags
|= NFS_MOUNT_NOACL
;
970 mnt
->flags
&= ~NFS_MOUNT_NORDIRPLUS
;
973 mnt
->flags
|= NFS_MOUNT_NORDIRPLUS
;
976 mnt
->flags
&= ~NFS_MOUNT_UNSHARED
;
978 case Opt_nosharecache
:
979 mnt
->flags
|= NFS_MOUNT_UNSHARED
;
982 mnt
->flags
&= ~NFS_MOUNT_NORESVPORT
;
985 mnt
->flags
|= NFS_MOUNT_NORESVPORT
;
988 mnt
->options
|= NFS_OPTION_FSCACHE
;
989 kfree(mnt
->fscache_uniq
);
990 mnt
->fscache_uniq
= NULL
;
993 mnt
->options
&= ~NFS_OPTION_FSCACHE
;
994 kfree(mnt
->fscache_uniq
);
995 mnt
->fscache_uniq
= NULL
;
997 case Opt_fscache_uniq
:
998 string
= match_strdup(args
);
1001 kfree(mnt
->fscache_uniq
);
1002 mnt
->fscache_uniq
= string
;
1003 mnt
->options
|= NFS_OPTION_FSCACHE
;
1007 * options that take numeric values
1010 string
= match_strdup(args
);
1013 rc
= strict_strtoul(string
, 10, &option
);
1015 if (rc
!= 0 || option
> USHORT_MAX
)
1016 goto out_invalid_value
;
1017 mnt
->nfs_server
.port
= option
;
1020 string
= match_strdup(args
);
1023 rc
= strict_strtoul(string
, 10, &option
);
1026 goto out_invalid_value
;
1027 mnt
->rsize
= option
;
1030 string
= match_strdup(args
);
1033 rc
= strict_strtoul(string
, 10, &option
);
1036 goto out_invalid_value
;
1037 mnt
->wsize
= option
;
1040 string
= match_strdup(args
);
1043 rc
= strict_strtoul(string
, 10, &option
);
1046 goto out_invalid_value
;
1047 mnt
->bsize
= option
;
1050 string
= match_strdup(args
);
1053 rc
= strict_strtoul(string
, 10, &option
);
1055 if (rc
!= 0 || option
== 0)
1056 goto out_invalid_value
;
1057 mnt
->timeo
= option
;
1060 string
= match_strdup(args
);
1063 rc
= strict_strtoul(string
, 10, &option
);
1065 if (rc
!= 0 || option
== 0)
1066 goto out_invalid_value
;
1067 mnt
->retrans
= option
;
1070 string
= match_strdup(args
);
1073 rc
= strict_strtoul(string
, 10, &option
);
1076 goto out_invalid_value
;
1077 mnt
->acregmin
= option
;
1080 string
= match_strdup(args
);
1083 rc
= strict_strtoul(string
, 10, &option
);
1086 goto out_invalid_value
;
1087 mnt
->acregmax
= option
;
1090 string
= match_strdup(args
);
1093 rc
= strict_strtoul(string
, 10, &option
);
1096 goto out_invalid_value
;
1097 mnt
->acdirmin
= option
;
1100 string
= match_strdup(args
);
1103 rc
= strict_strtoul(string
, 10, &option
);
1106 goto out_invalid_value
;
1107 mnt
->acdirmax
= option
;
1110 string
= match_strdup(args
);
1113 rc
= strict_strtoul(string
, 10, &option
);
1116 goto out_invalid_value
;
1117 mnt
->acregmin
= mnt
->acregmax
=
1118 mnt
->acdirmin
= mnt
->acdirmax
= option
;
1121 string
= match_strdup(args
);
1124 rc
= strict_strtoul(string
, 10, &option
);
1127 goto out_invalid_value
;
1128 mnt
->namlen
= option
;
1131 string
= match_strdup(args
);
1134 rc
= strict_strtoul(string
, 10, &option
);
1136 if (rc
!= 0 || option
> USHORT_MAX
)
1137 goto out_invalid_value
;
1138 mnt
->mount_server
.port
= option
;
1141 string
= match_strdup(args
);
1144 rc
= strict_strtoul(string
, 10, &option
);
1147 option
< NFS_MNT_VERSION
||
1148 option
> NFS_MNT3_VERSION
)
1149 goto out_invalid_value
;
1150 mnt
->mount_server
.version
= option
;
1153 string
= match_strdup(args
);
1156 rc
= strict_strtoul(string
, 10, &option
);
1159 goto out_invalid_value
;
1162 mnt
->flags
&= ~NFS_MOUNT_VER3
;
1166 mnt
->flags
|= NFS_MOUNT_VER3
;
1169 #ifdef CONFIG_NFS_V4
1171 mnt
->flags
&= ~NFS_MOUNT_VER3
;
1176 goto out_invalid_value
;
1179 case Opt_minorversion
:
1180 string
= match_strdup(args
);
1183 rc
= strict_strtoul(string
, 10, &option
);
1186 goto out_invalid_value
;
1187 if (option
> NFS4_MAX_MINOR_VERSION
)
1188 goto out_invalid_value
;
1189 mnt
->minorversion
= option
;
1193 * options that take text values
1196 string
= match_strdup(args
);
1199 rc
= nfs_parse_security_flavors(string
, mnt
);
1202 dfprintk(MOUNT
, "NFS: unrecognized "
1203 "security flavor\n");
1208 string
= match_strdup(args
);
1211 token
= match_token(string
,
1212 nfs_xprt_protocol_tokens
, args
);
1216 mnt
->flags
&= ~NFS_MOUNT_TCP
;
1217 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1221 mnt
->flags
|= NFS_MOUNT_TCP
;
1222 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1226 /* vector side protocols to TCP */
1227 mnt
->flags
|= NFS_MOUNT_TCP
;
1228 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_RDMA
;
1229 xprt_load_transport(string
);
1233 dfprintk(MOUNT
, "NFS: unrecognized "
1234 "transport protocol\n");
1238 case Opt_mountproto
:
1239 string
= match_strdup(args
);
1242 token
= match_token(string
,
1243 nfs_xprt_protocol_tokens
, args
);
1248 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_UDP
;
1251 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_TCP
;
1253 case Opt_xprt_rdma
: /* not used for side protocols */
1255 dfprintk(MOUNT
, "NFS: unrecognized "
1256 "transport protocol\n");
1261 string
= match_strdup(args
);
1264 mnt
->nfs_server
.addrlen
=
1265 rpc_pton(string
, strlen(string
),
1267 &mnt
->nfs_server
.address
,
1268 sizeof(mnt
->nfs_server
.address
));
1270 if (mnt
->nfs_server
.addrlen
== 0)
1271 goto out_invalid_address
;
1273 case Opt_clientaddr
:
1274 string
= match_strdup(args
);
1277 kfree(mnt
->client_address
);
1278 mnt
->client_address
= string
;
1281 string
= match_strdup(args
);
1284 kfree(mnt
->mount_server
.hostname
);
1285 mnt
->mount_server
.hostname
= string
;
1288 string
= match_strdup(args
);
1291 mnt
->mount_server
.addrlen
=
1292 rpc_pton(string
, strlen(string
),
1294 &mnt
->mount_server
.address
,
1295 sizeof(mnt
->mount_server
.address
));
1297 if (mnt
->mount_server
.addrlen
== 0)
1298 goto out_invalid_address
;
1300 case Opt_lookupcache
:
1301 string
= match_strdup(args
);
1304 token
= match_token(string
,
1305 nfs_lookupcache_tokens
, args
);
1308 case Opt_lookupcache_all
:
1309 mnt
->flags
&= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG
|NFS_MOUNT_LOOKUP_CACHE_NONE
);
1311 case Opt_lookupcache_positive
:
1312 mnt
->flags
&= ~NFS_MOUNT_LOOKUP_CACHE_NONE
;
1313 mnt
->flags
|= NFS_MOUNT_LOOKUP_CACHE_NONEG
;
1315 case Opt_lookupcache_none
:
1316 mnt
->flags
|= NFS_MOUNT_LOOKUP_CACHE_NONEG
|NFS_MOUNT_LOOKUP_CACHE_NONE
;
1319 dfprintk(MOUNT
, "NFS: invalid "
1320 "lookupcache argument\n");
1330 dfprintk(MOUNT
, "NFS: relaxing parsing rules\n");
1333 case Opt_deprecated
:
1334 dfprintk(MOUNT
, "NFS: ignoring mount option "
1340 dfprintk(MOUNT
, "NFS: unrecognized mount option "
1345 if (!sloppy
&& invalid_option
)
1350 out_invalid_address
:
1351 printk(KERN_INFO
"NFS: bad IP address specified: %s\n", p
);
1354 printk(KERN_INFO
"NFS: bad mount option value specified: %s\n", p
);
1357 printk(KERN_INFO
"NFS: not enough memory to parse option\n");
1359 out_security_failure
:
1360 free_secdata(secdata
);
1361 printk(KERN_INFO
"NFS: security options invalid: %d\n", rc
);
1366 * Match the requested auth flavors with the list returned by
1367 * the server. Returns zero and sets the mount's authentication
1368 * flavor on success; returns -EACCES if server does not support
1369 * the requested flavor.
1371 static int nfs_walk_authlist(struct nfs_parsed_mount_data
*args
,
1372 struct nfs_mount_request
*request
)
1374 unsigned int i
, j
, server_authlist_len
= *(request
->auth_flav_len
);
1377 * Certain releases of Linux's mountd return an empty
1378 * flavor list. To prevent behavioral regression with
1379 * these servers (ie. rejecting mounts that used to
1380 * succeed), revert to pre-2.6.32 behavior (no checking)
1381 * if the returned flavor list is empty.
1383 if (server_authlist_len
== 0)
1387 * We avoid sophisticated negotiating here, as there are
1388 * plenty of cases where we can get it wrong, providing
1389 * either too little or too much security.
1391 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1392 * flavor listed first. However, some servers list
1393 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1394 * preferred default, in args->auth_flavors[0] if user
1395 * didn't specify sec= mount option.
1397 for (i
= 0; i
< args
->auth_flavor_len
; i
++)
1398 for (j
= 0; j
< server_authlist_len
; j
++)
1399 if (args
->auth_flavors
[i
] == request
->auth_flavs
[j
]) {
1400 dfprintk(MOUNT
, "NFS: using auth flavor %d\n",
1401 request
->auth_flavs
[j
]);
1402 args
->auth_flavors
[0] = request
->auth_flavs
[j
];
1406 dfprintk(MOUNT
, "NFS: server does not support requested auth flavor\n");
1407 nfs_umount(request
);
1412 * Use the remote server's MOUNT service to request the NFS file handle
1413 * corresponding to the provided path.
1415 static int nfs_try_mount(struct nfs_parsed_mount_data
*args
,
1416 struct nfs_fh
*root_fh
)
1418 rpc_authflavor_t server_authlist
[NFS_MAX_SECFLAVORS
];
1419 unsigned int server_authlist_len
= ARRAY_SIZE(server_authlist
);
1420 struct nfs_mount_request request
= {
1421 .sap
= (struct sockaddr
*)
1422 &args
->mount_server
.address
,
1423 .dirpath
= args
->nfs_server
.export_path
,
1424 .protocol
= args
->mount_server
.protocol
,
1426 .noresvport
= args
->flags
& NFS_MOUNT_NORESVPORT
,
1427 .auth_flav_len
= &server_authlist_len
,
1428 .auth_flavs
= server_authlist
,
1432 if (args
->mount_server
.version
== 0) {
1433 switch (args
->version
) {
1435 args
->mount_server
.version
= NFS_MNT3_VERSION
;
1438 args
->mount_server
.version
= NFS_MNT_VERSION
;
1441 request
.version
= args
->mount_server
.version
;
1443 if (args
->mount_server
.hostname
)
1444 request
.hostname
= args
->mount_server
.hostname
;
1446 request
.hostname
= args
->nfs_server
.hostname
;
1449 * Construct the mount server's address.
1451 if (args
->mount_server
.address
.ss_family
== AF_UNSPEC
) {
1452 memcpy(request
.sap
, &args
->nfs_server
.address
,
1453 args
->nfs_server
.addrlen
);
1454 args
->mount_server
.addrlen
= args
->nfs_server
.addrlen
;
1456 request
.salen
= args
->mount_server
.addrlen
;
1457 nfs_set_default_port(request
.sap
, args
->mount_server
.port
, 0);
1460 * Now ask the mount server to map our export path
1463 status
= nfs_mount(&request
);
1465 dfprintk(MOUNT
, "NFS: unable to mount server %s, error %d\n",
1466 request
.hostname
, status
);
1471 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1473 if (args
->mount_server
.version
!= NFS_MNT3_VERSION
)
1475 return nfs_walk_authlist(args
, &request
);
1478 static int nfs_parse_simple_hostname(const char *dev_name
,
1479 char **hostname
, size_t maxnamlen
,
1480 char **export_path
, size_t maxpathlen
)
1483 char *colon
, *comma
;
1485 colon
= strchr(dev_name
, ':');
1487 goto out_bad_devname
;
1489 len
= colon
- dev_name
;
1490 if (len
> maxnamlen
)
1493 /* N.B. caller will free nfs_server.hostname in all cases */
1494 *hostname
= kstrndup(dev_name
, len
, GFP_KERNEL
);
1498 /* kill possible hostname list: not supported */
1499 comma
= strchr(*hostname
, ',');
1500 if (comma
!= NULL
) {
1501 if (comma
== *hostname
)
1502 goto out_bad_devname
;
1507 len
= strlen(colon
);
1508 if (len
> maxpathlen
)
1510 *export_path
= kstrndup(colon
, len
, GFP_KERNEL
);
1514 dfprintk(MOUNT
, "NFS: MNTPATH: '%s'\n", *export_path
);
1518 dfprintk(MOUNT
, "NFS: device name not in host:path format\n");
1522 dfprintk(MOUNT
, "NFS: not enough memory to parse device name\n");
1526 dfprintk(MOUNT
, "NFS: server hostname too long\n");
1527 return -ENAMETOOLONG
;
1530 dfprintk(MOUNT
, "NFS: export pathname too long\n");
1531 return -ENAMETOOLONG
;
1535 * Hostname has square brackets around it because it contains one or
1536 * more colons. We look for the first closing square bracket, and a
1537 * colon must follow it.
1539 static int nfs_parse_protected_hostname(const char *dev_name
,
1540 char **hostname
, size_t maxnamlen
,
1541 char **export_path
, size_t maxpathlen
)
1546 start
= (char *)(dev_name
+ 1);
1548 end
= strchr(start
, ']');
1550 goto out_bad_devname
;
1551 if (*(end
+ 1) != ':')
1552 goto out_bad_devname
;
1555 if (len
> maxnamlen
)
1558 /* N.B. caller will free nfs_server.hostname in all cases */
1559 *hostname
= kstrndup(start
, len
, GFP_KERNEL
);
1560 if (*hostname
== NULL
)
1565 if (len
> maxpathlen
)
1567 *export_path
= kstrndup(end
, len
, GFP_KERNEL
);
1574 dfprintk(MOUNT
, "NFS: device name not in host:path format\n");
1578 dfprintk(MOUNT
, "NFS: not enough memory to parse device name\n");
1582 dfprintk(MOUNT
, "NFS: server hostname too long\n");
1583 return -ENAMETOOLONG
;
1586 dfprintk(MOUNT
, "NFS: export pathname too long\n");
1587 return -ENAMETOOLONG
;
1591 * Split "dev_name" into "hostname:export_path".
1593 * The leftmost colon demarks the split between the server's hostname
1594 * and the export path. If the hostname starts with a left square
1595 * bracket, then it may contain colons.
1597 * Note: caller frees hostname and export path, even on error.
1599 static int nfs_parse_devname(const char *dev_name
,
1600 char **hostname
, size_t maxnamlen
,
1601 char **export_path
, size_t maxpathlen
)
1603 if (*dev_name
== '[')
1604 return nfs_parse_protected_hostname(dev_name
,
1605 hostname
, maxnamlen
,
1606 export_path
, maxpathlen
);
1608 return nfs_parse_simple_hostname(dev_name
,
1609 hostname
, maxnamlen
,
1610 export_path
, maxpathlen
);
1614 * Validate the NFS2/NFS3 mount data
1615 * - fills in the mount root filehandle
1617 * For option strings, user space handles the following behaviors:
1619 * + DNS: mapping server host name to IP address ("addr=" option)
1621 * + failure mode: how to behave if a mount request can't be handled
1622 * immediately ("fg/bg" option)
1624 * + retry: how often to retry a mount request ("retry=" option)
1626 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1627 * mountproto=tcp after mountproto=udp, and so on
1629 static int nfs_validate_mount_data(void *options
,
1630 struct nfs_parsed_mount_data
*args
,
1631 struct nfs_fh
*mntfh
,
1632 const char *dev_name
)
1634 struct nfs_mount_data
*data
= (struct nfs_mount_data
*)options
;
1635 struct sockaddr
*sap
= (struct sockaddr
*)&args
->nfs_server
.address
;
1640 args
->flags
= (NFS_MOUNT_VER3
| NFS_MOUNT_TCP
);
1641 args
->rsize
= NFS_MAX_FILE_IO_SIZE
;
1642 args
->wsize
= NFS_MAX_FILE_IO_SIZE
;
1643 args
->acregmin
= NFS_DEF_ACREGMIN
;
1644 args
->acregmax
= NFS_DEF_ACREGMAX
;
1645 args
->acdirmin
= NFS_DEF_ACDIRMIN
;
1646 args
->acdirmax
= NFS_DEF_ACDIRMAX
;
1647 args
->mount_server
.port
= NFS_UNSPEC_PORT
;
1648 args
->nfs_server
.port
= NFS_UNSPEC_PORT
;
1649 args
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1650 args
->auth_flavors
[0] = RPC_AUTH_UNIX
;
1651 args
->auth_flavor_len
= 1;
1652 args
->minorversion
= 0;
1654 switch (data
->version
) {
1660 if (data
->flags
& NFS_MOUNT_VER3
)
1662 data
->root
.size
= NFS2_FHSIZE
;
1663 memcpy(data
->root
.data
, data
->old_root
.data
, NFS2_FHSIZE
);
1665 if (data
->flags
& NFS_MOUNT_SECFLAVOUR
)
1668 memset(data
->context
, 0, sizeof(data
->context
));
1670 if (data
->flags
& NFS_MOUNT_VER3
) {
1671 if (data
->root
.size
> NFS3_FHSIZE
|| data
->root
.size
== 0)
1672 goto out_invalid_fh
;
1673 mntfh
->size
= data
->root
.size
;
1676 mntfh
->size
= NFS2_FHSIZE
;
1681 memcpy(mntfh
->data
, data
->root
.data
, mntfh
->size
);
1682 if (mntfh
->size
< sizeof(mntfh
->data
))
1683 memset(mntfh
->data
+ mntfh
->size
, 0,
1684 sizeof(mntfh
->data
) - mntfh
->size
);
1687 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1690 args
->flags
= data
->flags
& NFS_MOUNT_FLAGMASK
;
1691 args
->rsize
= data
->rsize
;
1692 args
->wsize
= data
->wsize
;
1693 args
->timeo
= data
->timeo
;
1694 args
->retrans
= data
->retrans
;
1695 args
->acregmin
= data
->acregmin
;
1696 args
->acregmax
= data
->acregmax
;
1697 args
->acdirmin
= data
->acdirmin
;
1698 args
->acdirmax
= data
->acdirmax
;
1700 memcpy(sap
, &data
->addr
, sizeof(data
->addr
));
1701 args
->nfs_server
.addrlen
= sizeof(data
->addr
);
1702 if (!nfs_verify_server_address(sap
))
1703 goto out_no_address
;
1705 if (!(data
->flags
& NFS_MOUNT_TCP
))
1706 args
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1707 /* N.B. caller will free nfs_server.hostname in all cases */
1708 args
->nfs_server
.hostname
= kstrdup(data
->hostname
, GFP_KERNEL
);
1709 args
->namlen
= data
->namlen
;
1710 args
->bsize
= data
->bsize
;
1712 if (data
->flags
& NFS_MOUNT_SECFLAVOUR
)
1713 args
->auth_flavors
[0] = data
->pseudoflavor
;
1714 if (!args
->nfs_server
.hostname
)
1718 * The legacy version 6 binary mount data from userspace has a
1719 * field used only to transport selinux information into the
1720 * the kernel. To continue to support that functionality we
1721 * have a touch of selinux knowledge here in the NFS code. The
1722 * userspace code converted context=blah to just blah so we are
1723 * converting back to the full string selinux understands.
1725 if (data
->context
[0]){
1726 #ifdef CONFIG_SECURITY_SELINUX
1728 char *opts_str
= kmalloc(sizeof(data
->context
) + 8, GFP_KERNEL
);
1731 strcpy(opts_str
, "context=");
1732 data
->context
[NFS_MAX_CONTEXT_LEN
] = '\0';
1733 strcat(opts_str
, &data
->context
[0]);
1734 rc
= security_sb_parse_opts_str(opts_str
, &args
->lsm_opts
);
1747 if (nfs_parse_mount_options((char *)options
, args
) == 0)
1750 if (!nfs_verify_server_address(sap
))
1751 goto out_no_address
;
1753 if (args
->version
== 4)
1754 #ifdef CONFIG_NFS_V4
1755 return nfs4_validate_text_mount_data(options
,
1758 goto out_v4_not_compiled
;
1761 nfs_set_default_port(sap
, args
->nfs_server
.port
, 0);
1763 nfs_set_mount_transport_protocol(args
);
1765 status
= nfs_parse_devname(dev_name
,
1766 &args
->nfs_server
.hostname
,
1768 &args
->nfs_server
.export_path
,
1771 status
= nfs_try_mount(args
, mntfh
);
1773 kfree(args
->nfs_server
.export_path
);
1774 args
->nfs_server
.export_path
= NULL
;
1783 #ifndef CONFIG_NFS_V3
1784 if (args
->version
== 3)
1785 goto out_v3_not_compiled
;
1786 #endif /* !CONFIG_NFS_V3 */
1791 dfprintk(MOUNT
, "NFS: mount program didn't pass any mount data\n");
1795 dfprintk(MOUNT
, "NFS: nfs_mount_data version %d does not support v3\n",
1800 dfprintk(MOUNT
, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1803 #ifndef CONFIG_NFS_V3
1804 out_v3_not_compiled
:
1805 dfprintk(MOUNT
, "NFS: NFSv3 is not compiled into kernel\n");
1806 return -EPROTONOSUPPORT
;
1807 #endif /* !CONFIG_NFS_V3 */
1809 #ifndef CONFIG_NFS_V4
1810 out_v4_not_compiled
:
1811 dfprintk(MOUNT
, "NFS: NFSv4 is not compiled into kernel\n");
1812 return -EPROTONOSUPPORT
;
1813 #endif /* !CONFIG_NFS_V4 */
1816 dfprintk(MOUNT
, "NFS: not enough memory to handle mount options\n");
1820 dfprintk(MOUNT
, "NFS: mount program didn't pass remote address\n");
1824 dfprintk(MOUNT
, "NFS: invalid root filehandle\n");
1829 nfs_compare_remount_data(struct nfs_server
*nfss
,
1830 struct nfs_parsed_mount_data
*data
)
1832 if (data
->flags
!= nfss
->flags
||
1833 data
->rsize
!= nfss
->rsize
||
1834 data
->wsize
!= nfss
->wsize
||
1835 data
->retrans
!= nfss
->client
->cl_timeout
->to_retries
||
1836 data
->auth_flavors
[0] != nfss
->client
->cl_auth
->au_flavor
||
1837 data
->acregmin
!= nfss
->acregmin
/ HZ
||
1838 data
->acregmax
!= nfss
->acregmax
/ HZ
||
1839 data
->acdirmin
!= nfss
->acdirmin
/ HZ
||
1840 data
->acdirmax
!= nfss
->acdirmax
/ HZ
||
1841 data
->timeo
!= (10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
) ||
1842 data
->nfs_server
.addrlen
!= nfss
->nfs_client
->cl_addrlen
||
1843 memcmp(&data
->nfs_server
.address
, &nfss
->nfs_client
->cl_addr
,
1844 data
->nfs_server
.addrlen
) != 0)
1851 nfs_remount(struct super_block
*sb
, int *flags
, char *raw_data
)
1854 struct nfs_server
*nfss
= sb
->s_fs_info
;
1855 struct nfs_parsed_mount_data
*data
;
1856 struct nfs_mount_data
*options
= (struct nfs_mount_data
*)raw_data
;
1857 struct nfs4_mount_data
*options4
= (struct nfs4_mount_data
*)raw_data
;
1858 u32 nfsvers
= nfss
->nfs_client
->rpc_ops
->version
;
1861 * Userspace mount programs that send binary options generally send
1862 * them populated with default values. We have no way to know which
1863 * ones were explicitly specified. Fall back to legacy behavior and
1864 * just return success.
1866 if ((nfsvers
== 4 && (!options4
|| options4
->version
== 1)) ||
1867 (nfsvers
<= 3 && (!options
|| (options
->version
>= 1 &&
1868 options
->version
<= 6))))
1871 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
1876 /* fill out struct with values from existing mount */
1877 data
->flags
= nfss
->flags
;
1878 data
->rsize
= nfss
->rsize
;
1879 data
->wsize
= nfss
->wsize
;
1880 data
->retrans
= nfss
->client
->cl_timeout
->to_retries
;
1881 data
->auth_flavors
[0] = nfss
->client
->cl_auth
->au_flavor
;
1882 data
->acregmin
= nfss
->acregmin
/ HZ
;
1883 data
->acregmax
= nfss
->acregmax
/ HZ
;
1884 data
->acdirmin
= nfss
->acdirmin
/ HZ
;
1885 data
->acdirmax
= nfss
->acdirmax
/ HZ
;
1886 data
->timeo
= 10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
;
1887 data
->nfs_server
.addrlen
= nfss
->nfs_client
->cl_addrlen
;
1888 memcpy(&data
->nfs_server
.address
, &nfss
->nfs_client
->cl_addr
,
1889 data
->nfs_server
.addrlen
);
1891 /* overwrite those values with any that were specified */
1892 error
= nfs_parse_mount_options((char *)options
, data
);
1896 /* compare new mount options with old ones */
1897 error
= nfs_compare_remount_data(nfss
, data
);
1905 * Initialise the common bits of the superblock
1907 static inline void nfs_initialise_sb(struct super_block
*sb
)
1909 struct nfs_server
*server
= NFS_SB(sb
);
1911 sb
->s_magic
= NFS_SUPER_MAGIC
;
1913 /* We probably want something more informative here */
1914 snprintf(sb
->s_id
, sizeof(sb
->s_id
),
1915 "%x:%x", MAJOR(sb
->s_dev
), MINOR(sb
->s_dev
));
1917 if (sb
->s_blocksize
== 0)
1918 sb
->s_blocksize
= nfs_block_bits(server
->wsize
,
1919 &sb
->s_blocksize_bits
);
1921 if (server
->flags
& NFS_MOUNT_NOAC
)
1922 sb
->s_flags
|= MS_SYNCHRONOUS
;
1924 sb
->s_bdi
= &server
->backing_dev_info
;
1926 nfs_super_set_maxbytes(sb
, server
->maxfilesize
);
1930 * Finish setting up an NFS2/3 superblock
1932 static void nfs_fill_super(struct super_block
*sb
,
1933 struct nfs_parsed_mount_data
*data
)
1935 struct nfs_server
*server
= NFS_SB(sb
);
1937 sb
->s_blocksize_bits
= 0;
1938 sb
->s_blocksize
= 0;
1940 sb
->s_blocksize
= nfs_block_size(data
->bsize
, &sb
->s_blocksize_bits
);
1942 if (server
->nfs_client
->rpc_ops
->version
== 3) {
1943 /* The VFS shouldn't apply the umask to mode bits. We will do
1944 * so ourselves when necessary.
1946 sb
->s_flags
|= MS_POSIXACL
;
1947 sb
->s_time_gran
= 1;
1950 sb
->s_op
= &nfs_sops
;
1951 nfs_initialise_sb(sb
);
1955 * Finish setting up a cloned NFS2/3 superblock
1957 static void nfs_clone_super(struct super_block
*sb
,
1958 const struct super_block
*old_sb
)
1960 struct nfs_server
*server
= NFS_SB(sb
);
1962 sb
->s_blocksize_bits
= old_sb
->s_blocksize_bits
;
1963 sb
->s_blocksize
= old_sb
->s_blocksize
;
1964 sb
->s_maxbytes
= old_sb
->s_maxbytes
;
1966 if (server
->nfs_client
->rpc_ops
->version
== 3) {
1967 /* The VFS shouldn't apply the umask to mode bits. We will do
1968 * so ourselves when necessary.
1970 sb
->s_flags
|= MS_POSIXACL
;
1971 sb
->s_time_gran
= 1;
1974 sb
->s_op
= old_sb
->s_op
;
1975 nfs_initialise_sb(sb
);
1978 static int nfs_compare_mount_options(const struct super_block
*s
, const struct nfs_server
*b
, int flags
)
1980 const struct nfs_server
*a
= s
->s_fs_info
;
1981 const struct rpc_clnt
*clnt_a
= a
->client
;
1982 const struct rpc_clnt
*clnt_b
= b
->client
;
1984 if ((s
->s_flags
& NFS_MS_MASK
) != (flags
& NFS_MS_MASK
))
1986 if (a
->nfs_client
!= b
->nfs_client
)
1988 if (a
->flags
!= b
->flags
)
1990 if (a
->wsize
!= b
->wsize
)
1992 if (a
->rsize
!= b
->rsize
)
1994 if (a
->acregmin
!= b
->acregmin
)
1996 if (a
->acregmax
!= b
->acregmax
)
1998 if (a
->acdirmin
!= b
->acdirmin
)
2000 if (a
->acdirmax
!= b
->acdirmax
)
2002 if (clnt_a
->cl_auth
->au_flavor
!= clnt_b
->cl_auth
->au_flavor
)
2009 struct nfs_sb_mountdata
{
2010 struct nfs_server
*server
;
2014 static int nfs_set_super(struct super_block
*s
, void *data
)
2016 struct nfs_sb_mountdata
*sb_mntdata
= data
;
2017 struct nfs_server
*server
= sb_mntdata
->server
;
2020 s
->s_flags
= sb_mntdata
->mntflags
;
2021 s
->s_fs_info
= server
;
2022 ret
= set_anon_super(s
, server
);
2024 server
->s_dev
= s
->s_dev
;
2028 static int nfs_compare_super_address(struct nfs_server
*server1
,
2029 struct nfs_server
*server2
)
2031 struct sockaddr
*sap1
, *sap2
;
2033 sap1
= (struct sockaddr
*)&server1
->nfs_client
->cl_addr
;
2034 sap2
= (struct sockaddr
*)&server2
->nfs_client
->cl_addr
;
2036 if (sap1
->sa_family
!= sap2
->sa_family
)
2039 switch (sap1
->sa_family
) {
2041 struct sockaddr_in
*sin1
= (struct sockaddr_in
*)sap1
;
2042 struct sockaddr_in
*sin2
= (struct sockaddr_in
*)sap2
;
2043 if (sin1
->sin_addr
.s_addr
!= sin2
->sin_addr
.s_addr
)
2045 if (sin1
->sin_port
!= sin2
->sin_port
)
2050 struct sockaddr_in6
*sin1
= (struct sockaddr_in6
*)sap1
;
2051 struct sockaddr_in6
*sin2
= (struct sockaddr_in6
*)sap2
;
2052 if (!ipv6_addr_equal(&sin1
->sin6_addr
, &sin2
->sin6_addr
))
2054 if (sin1
->sin6_port
!= sin2
->sin6_port
)
2065 static int nfs_compare_super(struct super_block
*sb
, void *data
)
2067 struct nfs_sb_mountdata
*sb_mntdata
= data
;
2068 struct nfs_server
*server
= sb_mntdata
->server
, *old
= NFS_SB(sb
);
2069 int mntflags
= sb_mntdata
->mntflags
;
2071 if (!nfs_compare_super_address(old
, server
))
2073 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2074 if (old
->flags
& NFS_MOUNT_UNSHARED
)
2076 if (memcmp(&old
->fsid
, &server
->fsid
, sizeof(old
->fsid
)) != 0)
2078 return nfs_compare_mount_options(sb
, server
, mntflags
);
2081 static int nfs_bdi_register(struct nfs_server
*server
)
2083 return bdi_register_dev(&server
->backing_dev_info
, server
->s_dev
);
2086 static int nfs_get_sb(struct file_system_type
*fs_type
,
2087 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
2089 struct nfs_server
*server
= NULL
;
2090 struct super_block
*s
;
2091 struct nfs_parsed_mount_data
*data
;
2092 struct nfs_fh
*mntfh
;
2093 struct dentry
*mntroot
;
2094 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2095 struct nfs_sb_mountdata sb_mntdata
= {
2098 int error
= -ENOMEM
;
2100 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
2101 mntfh
= kzalloc(sizeof(*mntfh
), GFP_KERNEL
);
2102 if (data
== NULL
|| mntfh
== NULL
)
2105 security_init_mnt_opts(&data
->lsm_opts
);
2107 /* Validate the mount data */
2108 error
= nfs_validate_mount_data(raw_data
, data
, mntfh
, dev_name
);
2112 #ifdef CONFIG_NFS_V4
2113 if (data
->version
== 4) {
2114 error
= nfs4_try_mount(flags
, dev_name
, data
, mnt
);
2115 kfree(data
->client_address
);
2118 #endif /* CONFIG_NFS_V4 */
2120 /* Get a volume representation */
2121 server
= nfs_create_server(data
, mntfh
);
2122 if (IS_ERR(server
)) {
2123 error
= PTR_ERR(server
);
2126 sb_mntdata
.server
= server
;
2128 if (server
->flags
& NFS_MOUNT_UNSHARED
)
2129 compare_super
= NULL
;
2131 /* Get a superblock - note that we may end up sharing one that already exists */
2132 s
= sget(fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2138 if (s
->s_fs_info
!= server
) {
2139 nfs_free_server(server
);
2142 error
= nfs_bdi_register(server
);
2144 goto error_splat_super
;
2148 /* initial superblock/root creation */
2149 nfs_fill_super(s
, data
);
2150 nfs_fscache_get_super_cookie(s
, data
);
2153 mntroot
= nfs_get_root(s
, mntfh
);
2154 if (IS_ERR(mntroot
)) {
2155 error
= PTR_ERR(mntroot
);
2156 goto error_splat_super
;
2159 error
= security_sb_set_mnt_opts(s
, &data
->lsm_opts
);
2161 goto error_splat_root
;
2163 s
->s_flags
|= MS_ACTIVE
;
2165 mnt
->mnt_root
= mntroot
;
2169 kfree(data
->nfs_server
.hostname
);
2170 kfree(data
->mount_server
.hostname
);
2171 kfree(data
->fscache_uniq
);
2172 security_free_mnt_opts(&data
->lsm_opts
);
2179 nfs_free_server(server
);
2185 deactivate_locked_super(s
);
2190 * Destroy an NFS2/3 superblock
2192 static void nfs_kill_super(struct super_block
*s
)
2194 struct nfs_server
*server
= NFS_SB(s
);
2197 bdi_unregister(&server
->backing_dev_info
);
2198 nfs_fscache_release_super_cookie(s
);
2199 nfs_free_server(server
);
2203 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2205 static int nfs_xdev_get_sb(struct file_system_type
*fs_type
, int flags
,
2206 const char *dev_name
, void *raw_data
,
2207 struct vfsmount
*mnt
)
2209 struct nfs_clone_mount
*data
= raw_data
;
2210 struct super_block
*s
;
2211 struct nfs_server
*server
;
2212 struct dentry
*mntroot
;
2213 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2214 struct nfs_sb_mountdata sb_mntdata
= {
2219 dprintk("--> nfs_xdev_get_sb()\n");
2221 /* create a new volume representation */
2222 server
= nfs_clone_server(NFS_SB(data
->sb
), data
->fh
, data
->fattr
);
2223 if (IS_ERR(server
)) {
2224 error
= PTR_ERR(server
);
2225 goto out_err_noserver
;
2227 sb_mntdata
.server
= server
;
2229 if (server
->flags
& NFS_MOUNT_UNSHARED
)
2230 compare_super
= NULL
;
2232 /* Get a superblock - note that we may end up sharing one that already exists */
2233 s
= sget(&nfs_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2239 if (s
->s_fs_info
!= server
) {
2240 nfs_free_server(server
);
2243 error
= nfs_bdi_register(server
);
2245 goto error_splat_super
;
2249 /* initial superblock/root creation */
2250 nfs_clone_super(s
, data
->sb
);
2253 mntroot
= nfs_get_root(s
, data
->fh
);
2254 if (IS_ERR(mntroot
)) {
2255 error
= PTR_ERR(mntroot
);
2256 goto error_splat_super
;
2258 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
2261 goto error_splat_super
;
2264 s
->s_flags
|= MS_ACTIVE
;
2266 mnt
->mnt_root
= mntroot
;
2268 /* clone any lsm security options from the parent to the new sb */
2269 security_sb_clone_mnt_opts(data
->sb
, s
);
2271 dprintk("<-- nfs_xdev_get_sb() = 0\n");
2275 nfs_free_server(server
);
2277 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error
);
2281 deactivate_locked_super(s
);
2282 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error
);
2286 #ifdef CONFIG_NFS_V4
2289 * Finish setting up a cloned NFS4 superblock
2291 static void nfs4_clone_super(struct super_block
*sb
,
2292 const struct super_block
*old_sb
)
2294 sb
->s_blocksize_bits
= old_sb
->s_blocksize_bits
;
2295 sb
->s_blocksize
= old_sb
->s_blocksize
;
2296 sb
->s_maxbytes
= old_sb
->s_maxbytes
;
2297 sb
->s_time_gran
= 1;
2298 sb
->s_op
= old_sb
->s_op
;
2299 nfs_initialise_sb(sb
);
2303 * Set up an NFS4 superblock
2305 static void nfs4_fill_super(struct super_block
*sb
)
2307 sb
->s_time_gran
= 1;
2308 sb
->s_op
= &nfs4_sops
;
2309 nfs_initialise_sb(sb
);
2312 static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data
*args
)
2314 args
->flags
&= ~(NFS_MOUNT_NONLM
|NFS_MOUNT_NOACL
|NFS_MOUNT_VER3
);
2317 static int nfs4_validate_text_mount_data(void *options
,
2318 struct nfs_parsed_mount_data
*args
,
2319 const char *dev_name
)
2321 struct sockaddr
*sap
= (struct sockaddr
*)&args
->nfs_server
.address
;
2323 nfs_set_default_port(sap
, args
->nfs_server
.port
, NFS_PORT
);
2325 nfs_validate_transport_protocol(args
);
2327 nfs4_validate_mount_flags(args
);
2329 if (args
->version
!= 4) {
2331 "NFS4: Illegal mount version\n");
2335 if (args
->auth_flavor_len
> 1) {
2337 "NFS4: Too many RPC auth flavours specified\n");
2341 if (args
->client_address
== NULL
) {
2343 "NFS4: mount program didn't pass callback address\n");
2347 return nfs_parse_devname(dev_name
,
2348 &args
->nfs_server
.hostname
,
2350 &args
->nfs_server
.export_path
,
2355 * Validate NFSv4 mount options
2357 static int nfs4_validate_mount_data(void *options
,
2358 struct nfs_parsed_mount_data
*args
,
2359 const char *dev_name
)
2361 struct sockaddr
*sap
= (struct sockaddr
*)&args
->nfs_server
.address
;
2362 struct nfs4_mount_data
*data
= (struct nfs4_mount_data
*)options
;
2368 args
->rsize
= NFS_MAX_FILE_IO_SIZE
;
2369 args
->wsize
= NFS_MAX_FILE_IO_SIZE
;
2370 args
->acregmin
= NFS_DEF_ACREGMIN
;
2371 args
->acregmax
= NFS_DEF_ACREGMAX
;
2372 args
->acdirmin
= NFS_DEF_ACDIRMIN
;
2373 args
->acdirmax
= NFS_DEF_ACDIRMAX
;
2374 args
->nfs_server
.port
= NFS_UNSPEC_PORT
;
2375 args
->auth_flavors
[0] = RPC_AUTH_UNIX
;
2376 args
->auth_flavor_len
= 1;
2378 args
->minorversion
= 0;
2380 switch (data
->version
) {
2382 if (data
->host_addrlen
> sizeof(args
->nfs_server
.address
))
2383 goto out_no_address
;
2384 if (data
->host_addrlen
== 0)
2385 goto out_no_address
;
2386 args
->nfs_server
.addrlen
= data
->host_addrlen
;
2387 if (copy_from_user(sap
, data
->host_addr
, data
->host_addrlen
))
2389 if (!nfs_verify_server_address(sap
))
2390 goto out_no_address
;
2392 if (data
->auth_flavourlen
) {
2393 if (data
->auth_flavourlen
> 1)
2394 goto out_inval_auth
;
2395 if (copy_from_user(&args
->auth_flavors
[0],
2396 data
->auth_flavours
,
2397 sizeof(args
->auth_flavors
[0])))
2401 c
= strndup_user(data
->hostname
.data
, NFS4_MAXNAMLEN
);
2404 args
->nfs_server
.hostname
= c
;
2406 c
= strndup_user(data
->mnt_path
.data
, NFS4_MAXPATHLEN
);
2409 args
->nfs_server
.export_path
= c
;
2410 dfprintk(MOUNT
, "NFS: MNTPATH: '%s'\n", c
);
2412 c
= strndup_user(data
->client_addr
.data
, 16);
2415 args
->client_address
= c
;
2418 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2422 args
->flags
= data
->flags
& NFS4_MOUNT_FLAGMASK
;
2423 args
->rsize
= data
->rsize
;
2424 args
->wsize
= data
->wsize
;
2425 args
->timeo
= data
->timeo
;
2426 args
->retrans
= data
->retrans
;
2427 args
->acregmin
= data
->acregmin
;
2428 args
->acregmax
= data
->acregmax
;
2429 args
->acdirmin
= data
->acdirmin
;
2430 args
->acdirmax
= data
->acdirmax
;
2431 args
->nfs_server
.protocol
= data
->proto
;
2432 nfs_validate_transport_protocol(args
);
2436 if (nfs_parse_mount_options((char *)options
, args
) == 0)
2439 if (!nfs_verify_server_address(sap
))
2442 return nfs4_validate_text_mount_data(options
, args
, dev_name
);
2448 dfprintk(MOUNT
, "NFS4: mount program didn't pass any mount data\n");
2452 dfprintk(MOUNT
, "NFS4: Invalid number of RPC auth flavours %d\n",
2453 data
->auth_flavourlen
);
2457 dfprintk(MOUNT
, "NFS4: mount program didn't pass remote address\n");
2462 * Get the superblock for the NFS4 root partition
2464 static int nfs4_remote_get_sb(struct file_system_type
*fs_type
,
2465 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
2467 struct nfs_parsed_mount_data
*data
= raw_data
;
2468 struct super_block
*s
;
2469 struct nfs_server
*server
;
2470 struct nfs_fh
*mntfh
;
2471 struct dentry
*mntroot
;
2472 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2473 struct nfs_sb_mountdata sb_mntdata
= {
2476 int error
= -ENOMEM
;
2478 mntfh
= kzalloc(sizeof(*mntfh
), GFP_KERNEL
);
2479 if (data
== NULL
|| mntfh
== NULL
)
2482 security_init_mnt_opts(&data
->lsm_opts
);
2484 /* Get a volume representation */
2485 server
= nfs4_create_server(data
, mntfh
);
2486 if (IS_ERR(server
)) {
2487 error
= PTR_ERR(server
);
2490 sb_mntdata
.server
= server
;
2492 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2493 compare_super
= NULL
;
2495 /* Get a superblock - note that we may end up sharing one that already exists */
2496 s
= sget(&nfs4_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2502 if (s
->s_fs_info
!= server
) {
2503 nfs_free_server(server
);
2506 error
= nfs_bdi_register(server
);
2508 goto error_splat_super
;
2512 /* initial superblock/root creation */
2514 nfs_fscache_get_super_cookie(s
, data
);
2517 mntroot
= nfs4_get_root(s
, mntfh
);
2518 if (IS_ERR(mntroot
)) {
2519 error
= PTR_ERR(mntroot
);
2520 goto error_splat_super
;
2523 error
= security_sb_set_mnt_opts(s
, &data
->lsm_opts
);
2525 goto error_splat_root
;
2527 s
->s_flags
|= MS_ACTIVE
;
2529 mnt
->mnt_root
= mntroot
;
2533 security_free_mnt_opts(&data
->lsm_opts
);
2539 nfs_free_server(server
);
2545 deactivate_locked_super(s
);
2549 static struct vfsmount
*nfs_do_root_mount(struct file_system_type
*fs_type
,
2550 int flags
, void *data
, const char *hostname
)
2552 struct vfsmount
*root_mnt
;
2556 len
= strlen(hostname
) + 3;
2557 root_devname
= kmalloc(len
, GFP_KERNEL
);
2558 if (root_devname
== NULL
)
2559 return ERR_PTR(-ENOMEM
);
2560 snprintf(root_devname
, len
, "%s:/", hostname
);
2561 root_mnt
= vfs_kern_mount(fs_type
, flags
, root_devname
, data
);
2562 kfree(root_devname
);
2566 static void nfs_fix_devname(const struct path
*path
, struct vfsmount
*mnt
)
2568 char *page
= (char *) __get_free_page(GFP_KERNEL
);
2569 char *devname
, *tmp
;
2573 devname
= nfs_path(path
->mnt
->mnt_devname
,
2574 path
->mnt
->mnt_root
, path
->dentry
,
2576 if (devname
== NULL
)
2578 tmp
= kstrdup(devname
, GFP_KERNEL
);
2581 kfree(mnt
->mnt_devname
);
2582 mnt
->mnt_devname
= tmp
;
2584 free_page((unsigned long)page
);
2587 static int nfs_follow_remote_path(struct vfsmount
*root_mnt
,
2588 const char *export_path
, struct vfsmount
*mnt_target
)
2590 struct mnt_namespace
*ns_private
;
2591 struct nameidata nd
;
2592 struct super_block
*s
;
2595 ns_private
= create_mnt_ns(root_mnt
);
2596 ret
= PTR_ERR(ns_private
);
2597 if (IS_ERR(ns_private
))
2600 ret
= vfs_path_lookup(root_mnt
->mnt_root
, root_mnt
,
2601 export_path
, LOOKUP_FOLLOW
, &nd
);
2603 put_mnt_ns(ns_private
);
2608 s
= nd
.path
.mnt
->mnt_sb
;
2609 atomic_inc(&s
->s_active
);
2610 mnt_target
->mnt_sb
= s
;
2611 mnt_target
->mnt_root
= dget(nd
.path
.dentry
);
2613 /* Correct the device pathname */
2614 nfs_fix_devname(&nd
.path
, mnt_target
);
2617 down_write(&s
->s_umount
);
2625 static int nfs4_try_mount(int flags
, const char *dev_name
,
2626 struct nfs_parsed_mount_data
*data
,
2627 struct vfsmount
*mnt
)
2630 struct vfsmount
*root_mnt
;
2633 dfprintk(MOUNT
, "--> nfs4_try_mount()\n");
2635 export_path
= data
->nfs_server
.export_path
;
2636 data
->nfs_server
.export_path
= "/";
2637 root_mnt
= nfs_do_root_mount(&nfs4_remote_fs_type
, flags
, data
,
2638 data
->nfs_server
.hostname
);
2639 data
->nfs_server
.export_path
= export_path
;
2641 error
= PTR_ERR(root_mnt
);
2642 if (IS_ERR(root_mnt
))
2645 error
= nfs_follow_remote_path(root_mnt
, export_path
, mnt
);
2648 dfprintk(MOUNT
, "<-- nfs4_try_mount() = %d%s\n", error
,
2649 error
!= 0 ? " [error]" : "");
2654 * Get the superblock for an NFS4 mountpoint
2656 static int nfs4_get_sb(struct file_system_type
*fs_type
,
2657 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
2659 struct nfs_parsed_mount_data
*data
;
2660 int error
= -ENOMEM
;
2662 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
2666 /* Validate the mount data */
2667 error
= nfs4_validate_mount_data(raw_data
, data
, dev_name
);
2671 error
= nfs4_try_mount(flags
, dev_name
, data
, mnt
);
2674 kfree(data
->client_address
);
2675 kfree(data
->nfs_server
.export_path
);
2676 kfree(data
->nfs_server
.hostname
);
2677 kfree(data
->fscache_uniq
);
2680 dprintk("<-- nfs4_get_sb() = %d%s\n", error
,
2681 error
!= 0 ? " [error]" : "");
2685 static void nfs4_kill_super(struct super_block
*sb
)
2687 struct nfs_server
*server
= NFS_SB(sb
);
2689 dprintk("--> %s\n", __func__
);
2690 nfs_super_return_all_delegations(sb
);
2691 kill_anon_super(sb
);
2692 nfs4_renewd_prepare_shutdown(server
);
2693 nfs_fscache_release_super_cookie(sb
);
2694 nfs_free_server(server
);
2695 dprintk("<-- %s\n", __func__
);
2699 * Clone an NFS4 server record on xdev traversal (FSID-change)
2701 static int nfs4_xdev_get_sb(struct file_system_type
*fs_type
, int flags
,
2702 const char *dev_name
, void *raw_data
,
2703 struct vfsmount
*mnt
)
2705 struct nfs_clone_mount
*data
= raw_data
;
2706 struct super_block
*s
;
2707 struct nfs_server
*server
;
2708 struct dentry
*mntroot
;
2709 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2710 struct nfs_sb_mountdata sb_mntdata
= {
2715 dprintk("--> nfs4_xdev_get_sb()\n");
2717 /* create a new volume representation */
2718 server
= nfs_clone_server(NFS_SB(data
->sb
), data
->fh
, data
->fattr
);
2719 if (IS_ERR(server
)) {
2720 error
= PTR_ERR(server
);
2721 goto out_err_noserver
;
2723 sb_mntdata
.server
= server
;
2725 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2726 compare_super
= NULL
;
2728 /* Get a superblock - note that we may end up sharing one that already exists */
2729 s
= sget(&nfs4_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2735 if (s
->s_fs_info
!= server
) {
2736 nfs_free_server(server
);
2739 error
= nfs_bdi_register(server
);
2741 goto error_splat_super
;
2745 /* initial superblock/root creation */
2746 nfs4_clone_super(s
, data
->sb
);
2749 mntroot
= nfs4_get_root(s
, data
->fh
);
2750 if (IS_ERR(mntroot
)) {
2751 error
= PTR_ERR(mntroot
);
2752 goto error_splat_super
;
2754 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
2757 goto error_splat_super
;
2760 s
->s_flags
|= MS_ACTIVE
;
2762 mnt
->mnt_root
= mntroot
;
2764 security_sb_clone_mnt_opts(data
->sb
, s
);
2766 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2770 nfs_free_server(server
);
2772 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error
);
2776 deactivate_locked_super(s
);
2777 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error
);
2781 static int nfs4_remote_referral_get_sb(struct file_system_type
*fs_type
,
2782 int flags
, const char *dev_name
, void *raw_data
,
2783 struct vfsmount
*mnt
)
2785 struct nfs_clone_mount
*data
= raw_data
;
2786 struct super_block
*s
;
2787 struct nfs_server
*server
;
2788 struct dentry
*mntroot
;
2789 struct nfs_fh mntfh
;
2790 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2791 struct nfs_sb_mountdata sb_mntdata
= {
2796 dprintk("--> nfs4_referral_get_sb()\n");
2798 /* create a new volume representation */
2799 server
= nfs4_create_referral_server(data
, &mntfh
);
2800 if (IS_ERR(server
)) {
2801 error
= PTR_ERR(server
);
2802 goto out_err_noserver
;
2804 sb_mntdata
.server
= server
;
2806 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2807 compare_super
= NULL
;
2809 /* Get a superblock - note that we may end up sharing one that already exists */
2810 s
= sget(&nfs4_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2816 if (s
->s_fs_info
!= server
) {
2817 nfs_free_server(server
);
2820 error
= nfs_bdi_register(server
);
2822 goto error_splat_super
;
2826 /* initial superblock/root creation */
2830 mntroot
= nfs4_get_root(s
, &mntfh
);
2831 if (IS_ERR(mntroot
)) {
2832 error
= PTR_ERR(mntroot
);
2833 goto error_splat_super
;
2835 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
2838 goto error_splat_super
;
2841 s
->s_flags
|= MS_ACTIVE
;
2843 mnt
->mnt_root
= mntroot
;
2845 security_sb_clone_mnt_opts(data
->sb
, s
);
2847 dprintk("<-- nfs4_referral_get_sb() = 0\n");
2851 nfs_free_server(server
);
2853 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error
);
2857 deactivate_locked_super(s
);
2858 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error
);
2863 * Create an NFS4 server record on referral traversal
2865 static int nfs4_referral_get_sb(struct file_system_type
*fs_type
,
2866 int flags
, const char *dev_name
, void *raw_data
,
2867 struct vfsmount
*mnt
)
2869 struct nfs_clone_mount
*data
= raw_data
;
2871 struct vfsmount
*root_mnt
;
2874 dprintk("--> nfs4_referral_get_sb()\n");
2876 export_path
= data
->mnt_path
;
2877 data
->mnt_path
= "/";
2879 root_mnt
= nfs_do_root_mount(&nfs4_remote_referral_fs_type
,
2880 flags
, data
, data
->hostname
);
2881 data
->mnt_path
= export_path
;
2883 error
= PTR_ERR(root_mnt
);
2884 if (IS_ERR(root_mnt
))
2887 error
= nfs_follow_remote_path(root_mnt
, export_path
, mnt
);
2889 dprintk("<-- nfs4_referral_get_sb() = %d%s\n", error
,
2890 error
!= 0 ? " [error]" : "");
2894 #endif /* CONFIG_NFS_V4 */