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/nfs_idmap.h>
46 #include <linux/vfs.h>
47 #include <linux/inet.h>
48 #include <linux/in6.h>
50 #include <linux/netdevice.h>
51 #include <linux/nfs_xdr.h>
52 #include <linux/magic.h>
53 #include <linux/parser.h>
55 #include <asm/system.h>
56 #include <asm/uaccess.h>
60 #include "delegation.h"
65 #define NFSDBG_FACILITY NFSDBG_VFS
68 /* Mount options that take no arguments */
70 Opt_posix
, Opt_noposix
,
75 Opt_udp
, Opt_tcp
, Opt_rdma
,
77 Opt_rdirplus
, Opt_nordirplus
,
78 Opt_sharecache
, Opt_nosharecache
,
79 Opt_resvport
, Opt_noresvport
,
80 Opt_fscache
, Opt_nofscache
,
82 /* Mount options that take integer arguments */
84 Opt_rsize
, Opt_wsize
, Opt_bsize
,
85 Opt_timeo
, Opt_retrans
,
86 Opt_acregmin
, Opt_acregmax
,
87 Opt_acdirmin
, Opt_acdirmax
,
95 /* Mount options that take string arguments */
96 Opt_sec
, Opt_proto
, Opt_mountproto
, Opt_mounthost
,
97 Opt_addr
, Opt_mountaddr
, Opt_clientaddr
,
101 /* Special mount options */
102 Opt_userspace
, Opt_deprecated
, Opt_sloppy
,
107 static const match_table_t nfs_mount_option_tokens
= {
108 { Opt_userspace
, "bg" },
109 { Opt_userspace
, "fg" },
110 { Opt_userspace
, "retry=%s" },
112 { Opt_sloppy
, "sloppy" },
114 { Opt_soft
, "soft" },
115 { Opt_hard
, "hard" },
116 { Opt_deprecated
, "intr" },
117 { Opt_deprecated
, "nointr" },
118 { Opt_posix
, "posix" },
119 { Opt_noposix
, "noposix" },
121 { Opt_nocto
, "nocto" },
123 { Opt_noac
, "noac" },
124 { Opt_lock
, "lock" },
125 { Opt_nolock
, "nolock" },
130 { Opt_rdma
, "rdma" },
132 { Opt_noacl
, "noacl" },
133 { Opt_rdirplus
, "rdirplus" },
134 { Opt_nordirplus
, "nordirplus" },
135 { Opt_sharecache
, "sharecache" },
136 { Opt_nosharecache
, "nosharecache" },
137 { Opt_resvport
, "resvport" },
138 { Opt_noresvport
, "noresvport" },
139 { Opt_fscache
, "fsc" },
140 { Opt_fscache_uniq
, "fsc=%s" },
141 { Opt_nofscache
, "nofsc" },
143 { Opt_port
, "port=%u" },
144 { Opt_rsize
, "rsize=%u" },
145 { Opt_wsize
, "wsize=%u" },
146 { Opt_bsize
, "bsize=%u" },
147 { Opt_timeo
, "timeo=%u" },
148 { Opt_retrans
, "retrans=%u" },
149 { Opt_acregmin
, "acregmin=%u" },
150 { Opt_acregmax
, "acregmax=%u" },
151 { Opt_acdirmin
, "acdirmin=%u" },
152 { Opt_acdirmax
, "acdirmax=%u" },
153 { Opt_actimeo
, "actimeo=%u" },
154 { Opt_namelen
, "namlen=%u" },
155 { Opt_mountport
, "mountport=%u" },
156 { Opt_mountvers
, "mountvers=%u" },
157 { Opt_nfsvers
, "nfsvers=%u" },
158 { Opt_nfsvers
, "vers=%u" },
159 { Opt_minorversion
, "minorversion=%u" },
161 { Opt_sec
, "sec=%s" },
162 { Opt_proto
, "proto=%s" },
163 { Opt_mountproto
, "mountproto=%s" },
164 { Opt_addr
, "addr=%s" },
165 { Opt_clientaddr
, "clientaddr=%s" },
166 { Opt_mounthost
, "mounthost=%s" },
167 { Opt_mountaddr
, "mountaddr=%s" },
169 { Opt_lookupcache
, "lookupcache=%s" },
175 Opt_xprt_udp
, Opt_xprt_tcp
, Opt_xprt_rdma
,
180 static const match_table_t nfs_xprt_protocol_tokens
= {
181 { Opt_xprt_udp
, "udp" },
182 { Opt_xprt_tcp
, "tcp" },
183 { Opt_xprt_rdma
, "rdma" },
185 { Opt_xprt_err
, NULL
}
189 Opt_sec_none
, Opt_sec_sys
,
190 Opt_sec_krb5
, Opt_sec_krb5i
, Opt_sec_krb5p
,
191 Opt_sec_lkey
, Opt_sec_lkeyi
, Opt_sec_lkeyp
,
192 Opt_sec_spkm
, Opt_sec_spkmi
, Opt_sec_spkmp
,
197 static const match_table_t nfs_secflavor_tokens
= {
198 { Opt_sec_none
, "none" },
199 { Opt_sec_none
, "null" },
200 { Opt_sec_sys
, "sys" },
202 { Opt_sec_krb5
, "krb5" },
203 { Opt_sec_krb5i
, "krb5i" },
204 { Opt_sec_krb5p
, "krb5p" },
206 { Opt_sec_lkey
, "lkey" },
207 { Opt_sec_lkeyi
, "lkeyi" },
208 { Opt_sec_lkeyp
, "lkeyp" },
210 { Opt_sec_spkm
, "spkm3" },
211 { Opt_sec_spkmi
, "spkm3i" },
212 { Opt_sec_spkmp
, "spkm3p" },
214 { Opt_sec_err
, NULL
}
218 Opt_lookupcache_all
, Opt_lookupcache_positive
,
219 Opt_lookupcache_none
,
224 static match_table_t nfs_lookupcache_tokens
= {
225 { Opt_lookupcache_all
, "all" },
226 { Opt_lookupcache_positive
, "pos" },
227 { Opt_lookupcache_positive
, "positive" },
228 { Opt_lookupcache_none
, "none" },
230 { Opt_lookupcache_err
, NULL
}
234 static void nfs_umount_begin(struct super_block
*);
235 static int nfs_statfs(struct dentry
*, struct kstatfs
*);
236 static int nfs_show_options(struct seq_file
*, struct vfsmount
*);
237 static int nfs_show_stats(struct seq_file
*, struct vfsmount
*);
238 static int nfs_get_sb(struct file_system_type
*, int, const char *, void *, struct vfsmount
*);
239 static int nfs_xdev_get_sb(struct file_system_type
*fs_type
,
240 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
241 static void nfs_kill_super(struct super_block
*);
242 static int nfs_remount(struct super_block
*sb
, int *flags
, char *raw_data
);
244 static struct file_system_type nfs_fs_type
= {
245 .owner
= THIS_MODULE
,
247 .get_sb
= nfs_get_sb
,
248 .kill_sb
= nfs_kill_super
,
249 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
252 struct file_system_type nfs_xdev_fs_type
= {
253 .owner
= THIS_MODULE
,
255 .get_sb
= nfs_xdev_get_sb
,
256 .kill_sb
= nfs_kill_super
,
257 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
260 static const struct super_operations nfs_sops
= {
261 .alloc_inode
= nfs_alloc_inode
,
262 .destroy_inode
= nfs_destroy_inode
,
263 .write_inode
= nfs_write_inode
,
264 .statfs
= nfs_statfs
,
265 .clear_inode
= nfs_clear_inode
,
266 .umount_begin
= nfs_umount_begin
,
267 .show_options
= nfs_show_options
,
268 .show_stats
= nfs_show_stats
,
269 .remount_fs
= nfs_remount
,
273 static int nfs4_get_sb(struct file_system_type
*fs_type
,
274 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
275 static int nfs4_xdev_get_sb(struct file_system_type
*fs_type
,
276 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
277 static int nfs4_referral_get_sb(struct file_system_type
*fs_type
,
278 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
279 static void nfs4_kill_super(struct super_block
*sb
);
281 static struct file_system_type nfs4_fs_type
= {
282 .owner
= THIS_MODULE
,
284 .get_sb
= nfs4_get_sb
,
285 .kill_sb
= nfs4_kill_super
,
286 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
289 struct file_system_type nfs4_xdev_fs_type
= {
290 .owner
= THIS_MODULE
,
292 .get_sb
= nfs4_xdev_get_sb
,
293 .kill_sb
= nfs4_kill_super
,
294 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
297 struct file_system_type nfs4_referral_fs_type
= {
298 .owner
= THIS_MODULE
,
300 .get_sb
= nfs4_referral_get_sb
,
301 .kill_sb
= nfs4_kill_super
,
302 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
305 static const struct super_operations nfs4_sops
= {
306 .alloc_inode
= nfs_alloc_inode
,
307 .destroy_inode
= nfs_destroy_inode
,
308 .write_inode
= nfs_write_inode
,
309 .statfs
= nfs_statfs
,
310 .clear_inode
= nfs4_clear_inode
,
311 .umount_begin
= nfs_umount_begin
,
312 .show_options
= nfs_show_options
,
313 .show_stats
= nfs_show_stats
,
314 .remount_fs
= nfs_remount
,
318 static struct shrinker acl_shrinker
= {
319 .shrink
= nfs_access_cache_shrinker
,
320 .seeks
= DEFAULT_SEEKS
,
324 * Register the NFS filesystems
326 int __init
register_nfs_fs(void)
330 ret
= register_filesystem(&nfs_fs_type
);
334 ret
= nfs_register_sysctl();
338 ret
= register_filesystem(&nfs4_fs_type
);
342 register_shrinker(&acl_shrinker
);
347 nfs_unregister_sysctl();
350 unregister_filesystem(&nfs_fs_type
);
356 * Unregister the NFS filesystems
358 void __exit
unregister_nfs_fs(void)
360 unregister_shrinker(&acl_shrinker
);
362 unregister_filesystem(&nfs4_fs_type
);
364 nfs_unregister_sysctl();
365 unregister_filesystem(&nfs_fs_type
);
368 void nfs_sb_active(struct super_block
*sb
)
370 struct nfs_server
*server
= NFS_SB(sb
);
372 if (atomic_inc_return(&server
->active
) == 1)
373 atomic_inc(&sb
->s_active
);
376 void nfs_sb_deactive(struct super_block
*sb
)
378 struct nfs_server
*server
= NFS_SB(sb
);
380 if (atomic_dec_and_test(&server
->active
))
381 deactivate_super(sb
);
385 * Deliver file system statistics to userspace
387 static int nfs_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
389 struct nfs_server
*server
= NFS_SB(dentry
->d_sb
);
390 unsigned char blockbits
;
391 unsigned long blockres
;
392 struct nfs_fh
*fh
= NFS_FH(dentry
->d_inode
);
393 struct nfs_fattr fattr
;
394 struct nfs_fsstat res
= {
399 error
= server
->nfs_client
->rpc_ops
->statfs(server
, fh
, &res
);
402 buf
->f_type
= NFS_SUPER_MAGIC
;
405 * Current versions of glibc do not correctly handle the
406 * case where f_frsize != f_bsize. Eventually we want to
407 * report the value of wtmult in this field.
409 buf
->f_frsize
= dentry
->d_sb
->s_blocksize
;
412 * On most *nix systems, f_blocks, f_bfree, and f_bavail
413 * are reported in units of f_frsize. Linux hasn't had
414 * an f_frsize field in its statfs struct until recently,
415 * thus historically Linux's sys_statfs reports these
416 * fields in units of f_bsize.
418 buf
->f_bsize
= dentry
->d_sb
->s_blocksize
;
419 blockbits
= dentry
->d_sb
->s_blocksize_bits
;
420 blockres
= (1 << blockbits
) - 1;
421 buf
->f_blocks
= (res
.tbytes
+ blockres
) >> blockbits
;
422 buf
->f_bfree
= (res
.fbytes
+ blockres
) >> blockbits
;
423 buf
->f_bavail
= (res
.abytes
+ blockres
) >> blockbits
;
425 buf
->f_files
= res
.tfiles
;
426 buf
->f_ffree
= res
.afiles
;
428 buf
->f_namelen
= server
->namelen
;
433 dprintk("%s: statfs error = %d\n", __func__
, -error
);
438 * Map the security flavour number to a name
440 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour
)
442 static const struct {
443 rpc_authflavor_t flavour
;
446 { RPC_AUTH_NULL
, "null" },
447 { RPC_AUTH_UNIX
, "sys" },
448 { RPC_AUTH_GSS_KRB5
, "krb5" },
449 { RPC_AUTH_GSS_KRB5I
, "krb5i" },
450 { RPC_AUTH_GSS_KRB5P
, "krb5p" },
451 { RPC_AUTH_GSS_LKEY
, "lkey" },
452 { RPC_AUTH_GSS_LKEYI
, "lkeyi" },
453 { RPC_AUTH_GSS_LKEYP
, "lkeyp" },
454 { RPC_AUTH_GSS_SPKM
, "spkm" },
455 { RPC_AUTH_GSS_SPKMI
, "spkmi" },
456 { RPC_AUTH_GSS_SPKMP
, "spkmp" },
457 { UINT_MAX
, "unknown" }
461 for (i
= 0; sec_flavours
[i
].flavour
!= UINT_MAX
; i
++) {
462 if (sec_flavours
[i
].flavour
== flavour
)
465 return sec_flavours
[i
].str
;
468 static void nfs_show_mountd_options(struct seq_file
*m
, struct nfs_server
*nfss
,
471 struct sockaddr
*sap
= (struct sockaddr
*)&nfss
->mountd_address
;
473 switch (sap
->sa_family
) {
475 struct sockaddr_in
*sin
= (struct sockaddr_in
*)sap
;
476 seq_printf(m
, ",mountaddr=%pI4", &sin
->sin_addr
.s_addr
);
480 struct sockaddr_in6
*sin6
= (struct sockaddr_in6
*)sap
;
481 seq_printf(m
, ",mountaddr=%pI6", &sin6
->sin6_addr
);
486 seq_printf(m
, ",mountaddr=unspecified");
489 if (nfss
->mountd_version
|| showdefaults
)
490 seq_printf(m
, ",mountvers=%u", nfss
->mountd_version
);
491 if (nfss
->mountd_port
|| showdefaults
)
492 seq_printf(m
, ",mountport=%u", nfss
->mountd_port
);
494 switch (nfss
->mountd_protocol
) {
496 seq_printf(m
, ",mountproto=udp");
499 seq_printf(m
, ",mountproto=tcp");
503 seq_printf(m
, ",mountproto=auto");
508 * Describe the mount options in force on this server representation
510 static void nfs_show_mount_options(struct seq_file
*m
, struct nfs_server
*nfss
,
513 static const struct proc_nfs_info
{
518 { NFS_MOUNT_SOFT
, ",soft", ",hard" },
519 { NFS_MOUNT_INTR
, ",intr", ",nointr" },
520 { NFS_MOUNT_POSIX
, ",posix", "" },
521 { NFS_MOUNT_NOCTO
, ",nocto", "" },
522 { NFS_MOUNT_NOAC
, ",noac", "" },
523 { NFS_MOUNT_NONLM
, ",nolock", "" },
524 { NFS_MOUNT_NOACL
, ",noacl", "" },
525 { NFS_MOUNT_NORDIRPLUS
, ",nordirplus", "" },
526 { NFS_MOUNT_UNSHARED
, ",nosharecache", "" },
527 { NFS_MOUNT_NORESVPORT
, ",noresvport", "" },
530 const struct proc_nfs_info
*nfs_infop
;
531 struct nfs_client
*clp
= nfss
->nfs_client
;
532 u32 version
= clp
->rpc_ops
->version
;
534 seq_printf(m
, ",vers=%u", version
);
535 seq_printf(m
, ",rsize=%u", nfss
->rsize
);
536 seq_printf(m
, ",wsize=%u", nfss
->wsize
);
537 if (nfss
->bsize
!= 0)
538 seq_printf(m
, ",bsize=%u", nfss
->bsize
);
539 seq_printf(m
, ",namlen=%u", nfss
->namelen
);
540 if (nfss
->acregmin
!= NFS_DEF_ACREGMIN
*HZ
|| showdefaults
)
541 seq_printf(m
, ",acregmin=%u", nfss
->acregmin
/HZ
);
542 if (nfss
->acregmax
!= NFS_DEF_ACREGMAX
*HZ
|| showdefaults
)
543 seq_printf(m
, ",acregmax=%u", nfss
->acregmax
/HZ
);
544 if (nfss
->acdirmin
!= NFS_DEF_ACDIRMIN
*HZ
|| showdefaults
)
545 seq_printf(m
, ",acdirmin=%u", nfss
->acdirmin
/HZ
);
546 if (nfss
->acdirmax
!= NFS_DEF_ACDIRMAX
*HZ
|| showdefaults
)
547 seq_printf(m
, ",acdirmax=%u", nfss
->acdirmax
/HZ
);
548 for (nfs_infop
= nfs_info
; nfs_infop
->flag
; nfs_infop
++) {
549 if (nfss
->flags
& nfs_infop
->flag
)
550 seq_puts(m
, nfs_infop
->str
);
552 seq_puts(m
, nfs_infop
->nostr
);
554 seq_printf(m
, ",proto=%s",
555 rpc_peeraddr2str(nfss
->client
, RPC_DISPLAY_PROTO
));
557 if (nfss
->port
!= NFS_PORT
)
558 seq_printf(m
, ",port=%u", nfss
->port
);
561 seq_printf(m
, ",port=%u", nfss
->port
);
563 seq_printf(m
, ",timeo=%lu", 10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
);
564 seq_printf(m
, ",retrans=%u", nfss
->client
->cl_timeout
->to_retries
);
565 seq_printf(m
, ",sec=%s", nfs_pseudoflavour_to_name(nfss
->client
->cl_auth
->au_flavor
));
568 nfs_show_mountd_options(m
, nfss
, showdefaults
);
571 if (clp
->rpc_ops
->version
== 4)
572 seq_printf(m
, ",clientaddr=%s", clp
->cl_ipaddr
);
574 if (nfss
->options
& NFS_OPTION_FSCACHE
)
575 seq_printf(m
, ",fsc");
579 * Describe the mount options on this VFS mountpoint
581 static int nfs_show_options(struct seq_file
*m
, struct vfsmount
*mnt
)
583 struct nfs_server
*nfss
= NFS_SB(mnt
->mnt_sb
);
585 nfs_show_mount_options(m
, nfss
, 0);
587 seq_printf(m
, ",addr=%s",
588 rpc_peeraddr2str(nfss
->nfs_client
->cl_rpcclient
,
595 * Present statistical information for this VFS mountpoint
597 static int nfs_show_stats(struct seq_file
*m
, struct vfsmount
*mnt
)
600 struct nfs_server
*nfss
= NFS_SB(mnt
->mnt_sb
);
601 struct rpc_auth
*auth
= nfss
->client
->cl_auth
;
602 struct nfs_iostats totals
= { };
604 seq_printf(m
, "statvers=%s", NFS_IOSTAT_VERS
);
607 * Display all mount option settings
609 seq_printf(m
, "\n\topts:\t");
610 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_RDONLY
? "ro" : "rw");
611 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_SYNCHRONOUS
? ",sync" : "");
612 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_NOATIME
? ",noatime" : "");
613 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_NODIRATIME
? ",nodiratime" : "");
614 nfs_show_mount_options(m
, nfss
, 1);
616 seq_printf(m
, "\n\tage:\t%lu", (jiffies
- nfss
->mount_time
) / HZ
);
618 seq_printf(m
, "\n\tcaps:\t");
619 seq_printf(m
, "caps=0x%x", nfss
->caps
);
620 seq_printf(m
, ",wtmult=%u", nfss
->wtmult
);
621 seq_printf(m
, ",dtsize=%u", nfss
->dtsize
);
622 seq_printf(m
, ",bsize=%u", nfss
->bsize
);
623 seq_printf(m
, ",namlen=%u", nfss
->namelen
);
626 if (nfss
->nfs_client
->rpc_ops
->version
== 4) {
627 seq_printf(m
, "\n\tnfsv4:\t");
628 seq_printf(m
, "bm0=0x%x", nfss
->attr_bitmask
[0]);
629 seq_printf(m
, ",bm1=0x%x", nfss
->attr_bitmask
[1]);
630 seq_printf(m
, ",acl=0x%x", nfss
->acl_bitmask
);
635 * Display security flavor in effect for this mount
637 seq_printf(m
, "\n\tsec:\tflavor=%u", auth
->au_ops
->au_flavor
);
639 seq_printf(m
, ",pseudoflavor=%u", auth
->au_flavor
);
642 * Display superblock I/O counters
644 for_each_possible_cpu(cpu
) {
645 struct nfs_iostats
*stats
;
648 stats
= per_cpu_ptr(nfss
->io_stats
, cpu
);
650 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
651 totals
.events
[i
] += stats
->events
[i
];
652 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
653 totals
.bytes
[i
] += stats
->bytes
[i
];
654 #ifdef CONFIG_NFS_FSCACHE
655 for (i
= 0; i
< __NFSIOS_FSCACHEMAX
; i
++)
656 totals
.fscache
[i
] += stats
->fscache
[i
];
662 seq_printf(m
, "\n\tevents:\t");
663 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
664 seq_printf(m
, "%lu ", totals
.events
[i
]);
665 seq_printf(m
, "\n\tbytes:\t");
666 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
667 seq_printf(m
, "%Lu ", totals
.bytes
[i
]);
668 #ifdef CONFIG_NFS_FSCACHE
669 if (nfss
->options
& NFS_OPTION_FSCACHE
) {
670 seq_printf(m
, "\n\tfsc:\t");
671 for (i
= 0; i
< __NFSIOS_FSCACHEMAX
; i
++)
672 seq_printf(m
, "%Lu ", totals
.bytes
[i
]);
677 rpc_print_iostats(m
, nfss
->client
);
683 * Begin unmount by attempting to remove all automounted mountpoints we added
684 * in response to xdev traversals and referrals
686 static void nfs_umount_begin(struct super_block
*sb
)
688 struct nfs_server
*server
;
689 struct rpc_clnt
*rpc
;
694 /* -EIO all pending I/O */
695 rpc
= server
->client_acl
;
697 rpc_killall_tasks(rpc
);
698 rpc
= server
->client
;
700 rpc_killall_tasks(rpc
);
706 * Sanity-check a server address provided by the mount command.
708 * Address family must be initialized, and address must not be
709 * the ANY address for that family.
711 static int nfs_verify_server_address(struct sockaddr
*addr
)
713 switch (addr
->sa_family
) {
715 struct sockaddr_in
*sa
= (struct sockaddr_in
*)addr
;
716 return sa
->sin_addr
.s_addr
!= htonl(INADDR_ANY
);
719 struct in6_addr
*sa
= &((struct sockaddr_in6
*)addr
)->sin6_addr
;
720 return !ipv6_addr_any(sa
);
727 static void nfs_parse_ipv4_address(char *string
, size_t str_len
,
728 struct sockaddr
*sap
, size_t *addr_len
)
730 struct sockaddr_in
*sin
= (struct sockaddr_in
*)sap
;
731 u8
*addr
= (u8
*)&sin
->sin_addr
.s_addr
;
733 if (str_len
<= INET_ADDRSTRLEN
) {
734 dfprintk(MOUNT
, "NFS: parsing IPv4 address %*s\n",
735 (int)str_len
, string
);
737 sin
->sin_family
= AF_INET
;
738 *addr_len
= sizeof(*sin
);
739 if (in4_pton(string
, str_len
, addr
, '\0', NULL
))
743 sap
->sa_family
= AF_UNSPEC
;
747 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
748 static int nfs_parse_ipv6_scope_id(const char *string
, const size_t str_len
,
750 struct sockaddr_in6
*sin6
)
755 if ((string
+ str_len
) == delim
)
758 if (*delim
!= IPV6_SCOPE_DELIMITER
)
761 if (!(ipv6_addr_type(&sin6
->sin6_addr
) & IPV6_ADDR_LINKLOCAL
))
764 len
= (string
+ str_len
) - delim
- 1;
765 p
= kstrndup(delim
+ 1, len
, GFP_KERNEL
);
767 unsigned long scope_id
= 0;
768 struct net_device
*dev
;
770 dev
= dev_get_by_name(&init_net
, p
);
772 scope_id
= dev
->ifindex
;
775 if (strict_strtoul(p
, 10, &scope_id
) == 0) {
783 sin6
->sin6_scope_id
= scope_id
;
784 dfprintk(MOUNT
, "NFS: IPv6 scope ID = %lu\n", scope_id
);
791 static void nfs_parse_ipv6_address(char *string
, size_t str_len
,
792 struct sockaddr
*sap
, size_t *addr_len
)
794 struct sockaddr_in6
*sin6
= (struct sockaddr_in6
*)sap
;
795 u8
*addr
= (u8
*)&sin6
->sin6_addr
.in6_u
;
798 if (str_len
<= INET6_ADDRSTRLEN
) {
799 dfprintk(MOUNT
, "NFS: parsing IPv6 address %*s\n",
800 (int)str_len
, string
);
802 sin6
->sin6_family
= AF_INET6
;
803 *addr_len
= sizeof(*sin6
);
804 if (in6_pton(string
, str_len
, addr
,
805 IPV6_SCOPE_DELIMITER
, &delim
) != 0) {
806 if (nfs_parse_ipv6_scope_id(string
, str_len
,
812 sap
->sa_family
= AF_UNSPEC
;
816 static void nfs_parse_ipv6_address(char *string
, size_t str_len
,
817 struct sockaddr
*sap
, size_t *addr_len
)
819 sap
->sa_family
= AF_UNSPEC
;
825 * Construct a sockaddr based on the contents of a string that contains
826 * an IP address in presentation format.
828 * If there is a problem constructing the new sockaddr, set the address
829 * family to AF_UNSPEC.
831 void nfs_parse_ip_address(char *string
, size_t str_len
,
832 struct sockaddr
*sap
, size_t *addr_len
)
834 unsigned int i
, colons
;
837 for (i
= 0; i
< str_len
; i
++)
838 if (string
[i
] == ':')
842 nfs_parse_ipv6_address(string
, str_len
, sap
, addr_len
);
844 nfs_parse_ipv4_address(string
, str_len
, sap
, addr_len
);
848 * Sanity check the NFS transport protocol.
851 static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data
*mnt
)
853 switch (mnt
->nfs_server
.protocol
) {
854 case XPRT_TRANSPORT_UDP
:
855 case XPRT_TRANSPORT_TCP
:
856 case XPRT_TRANSPORT_RDMA
:
859 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
864 * For text based NFSv2/v3 mounts, the mount protocol transport default
865 * settings should depend upon the specified NFS transport.
867 static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data
*mnt
)
869 nfs_validate_transport_protocol(mnt
);
871 if (mnt
->mount_server
.protocol
== XPRT_TRANSPORT_UDP
||
872 mnt
->mount_server
.protocol
== XPRT_TRANSPORT_TCP
)
874 switch (mnt
->nfs_server
.protocol
) {
875 case XPRT_TRANSPORT_UDP
:
876 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_UDP
;
878 case XPRT_TRANSPORT_TCP
:
879 case XPRT_TRANSPORT_RDMA
:
880 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_TCP
;
885 * Parse the value of the 'sec=' option.
887 * The flavor_len setting is for v4 mounts.
889 static int nfs_parse_security_flavors(char *value
,
890 struct nfs_parsed_mount_data
*mnt
)
892 substring_t args
[MAX_OPT_ARGS
];
894 dfprintk(MOUNT
, "NFS: parsing sec=%s option\n", value
);
896 switch (match_token(value
, nfs_secflavor_tokens
, args
)) {
898 mnt
->auth_flavor_len
= 0;
899 mnt
->auth_flavors
[0] = RPC_AUTH_NULL
;
902 mnt
->auth_flavor_len
= 0;
903 mnt
->auth_flavors
[0] = RPC_AUTH_UNIX
;
906 mnt
->auth_flavor_len
= 1;
907 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5
;
910 mnt
->auth_flavor_len
= 1;
911 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5I
;
914 mnt
->auth_flavor_len
= 1;
915 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5P
;
918 mnt
->auth_flavor_len
= 1;
919 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEY
;
922 mnt
->auth_flavor_len
= 1;
923 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEYI
;
926 mnt
->auth_flavor_len
= 1;
927 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEYP
;
930 mnt
->auth_flavor_len
= 1;
931 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKM
;
934 mnt
->auth_flavor_len
= 1;
935 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKMI
;
938 mnt
->auth_flavor_len
= 1;
939 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKMP
;
948 static void nfs_parse_invalid_value(const char *option
)
950 dfprintk(MOUNT
, "NFS: bad value specified for %s option\n", option
);
954 * Error-check and convert a string of mount options from user space into
955 * a data structure. The whole mount string is processed; bad options are
956 * skipped as they are encountered. If there were no errors, return 1;
957 * otherwise return 0 (zero).
959 static int nfs_parse_mount_options(char *raw
,
960 struct nfs_parsed_mount_data
*mnt
)
962 char *p
, *string
, *secdata
;
963 int rc
, sloppy
= 0, errors
= 0;
966 dfprintk(MOUNT
, "NFS: mount options string was NULL.\n");
969 dfprintk(MOUNT
, "NFS: nfs mount opts='%s'\n", raw
);
971 secdata
= alloc_secdata();
975 rc
= security_sb_copy_data(raw
, secdata
);
977 goto out_security_failure
;
979 rc
= security_sb_parse_opts_str(secdata
, &mnt
->lsm_opts
);
981 goto out_security_failure
;
983 free_secdata(secdata
);
985 while ((p
= strsep(&raw
, ",")) != NULL
) {
986 substring_t args
[MAX_OPT_ARGS
];
992 dfprintk(MOUNT
, "NFS: parsing nfs mount option '%s'\n", p
);
994 token
= match_token(p
, nfs_mount_option_tokens
, args
);
998 * boolean options: foo/nofoo
1001 mnt
->flags
|= NFS_MOUNT_SOFT
;
1004 mnt
->flags
&= ~NFS_MOUNT_SOFT
;
1007 mnt
->flags
|= NFS_MOUNT_POSIX
;
1010 mnt
->flags
&= ~NFS_MOUNT_POSIX
;
1013 mnt
->flags
&= ~NFS_MOUNT_NOCTO
;
1016 mnt
->flags
|= NFS_MOUNT_NOCTO
;
1019 mnt
->flags
&= ~NFS_MOUNT_NOAC
;
1022 mnt
->flags
|= NFS_MOUNT_NOAC
;
1025 mnt
->flags
&= ~NFS_MOUNT_NONLM
;
1028 mnt
->flags
|= NFS_MOUNT_NONLM
;
1031 mnt
->flags
&= ~NFS_MOUNT_VER3
;
1034 mnt
->flags
|= NFS_MOUNT_VER3
;
1037 mnt
->flags
&= ~NFS_MOUNT_TCP
;
1038 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1041 mnt
->flags
|= NFS_MOUNT_TCP
;
1042 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1045 mnt
->flags
|= NFS_MOUNT_TCP
; /* for side protocols */
1046 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_RDMA
;
1047 xprt_load_transport(p
);
1050 mnt
->flags
&= ~NFS_MOUNT_NOACL
;
1053 mnt
->flags
|= NFS_MOUNT_NOACL
;
1056 mnt
->flags
&= ~NFS_MOUNT_NORDIRPLUS
;
1058 case Opt_nordirplus
:
1059 mnt
->flags
|= NFS_MOUNT_NORDIRPLUS
;
1061 case Opt_sharecache
:
1062 mnt
->flags
&= ~NFS_MOUNT_UNSHARED
;
1064 case Opt_nosharecache
:
1065 mnt
->flags
|= NFS_MOUNT_UNSHARED
;
1068 mnt
->flags
&= ~NFS_MOUNT_NORESVPORT
;
1070 case Opt_noresvport
:
1071 mnt
->flags
|= NFS_MOUNT_NORESVPORT
;
1074 mnt
->options
|= NFS_OPTION_FSCACHE
;
1075 kfree(mnt
->fscache_uniq
);
1076 mnt
->fscache_uniq
= NULL
;
1079 mnt
->options
&= ~NFS_OPTION_FSCACHE
;
1080 kfree(mnt
->fscache_uniq
);
1081 mnt
->fscache_uniq
= NULL
;
1083 case Opt_fscache_uniq
:
1084 string
= match_strdup(args
);
1087 kfree(mnt
->fscache_uniq
);
1088 mnt
->fscache_uniq
= string
;
1089 mnt
->options
|= NFS_OPTION_FSCACHE
;
1093 * options that take numeric values
1096 if (match_int(args
, &option
) ||
1097 option
< 0 || option
> USHORT_MAX
) {
1099 nfs_parse_invalid_value("port");
1101 mnt
->nfs_server
.port
= option
;
1104 if (match_int(args
, &option
) || option
< 0) {
1106 nfs_parse_invalid_value("rsize");
1108 mnt
->rsize
= option
;
1111 if (match_int(args
, &option
) || option
< 0) {
1113 nfs_parse_invalid_value("wsize");
1115 mnt
->wsize
= option
;
1118 if (match_int(args
, &option
) || option
< 0) {
1120 nfs_parse_invalid_value("bsize");
1122 mnt
->bsize
= option
;
1125 if (match_int(args
, &option
) || option
<= 0) {
1127 nfs_parse_invalid_value("timeo");
1129 mnt
->timeo
= option
;
1132 if (match_int(args
, &option
) || option
<= 0) {
1134 nfs_parse_invalid_value("retrans");
1136 mnt
->retrans
= option
;
1139 if (match_int(args
, &option
) || option
< 0) {
1141 nfs_parse_invalid_value("acregmin");
1143 mnt
->acregmin
= option
;
1146 if (match_int(args
, &option
) || option
< 0) {
1148 nfs_parse_invalid_value("acregmax");
1150 mnt
->acregmax
= option
;
1153 if (match_int(args
, &option
) || option
< 0) {
1155 nfs_parse_invalid_value("acdirmin");
1157 mnt
->acdirmin
= option
;
1160 if (match_int(args
, &option
) || option
< 0) {
1162 nfs_parse_invalid_value("acdirmax");
1164 mnt
->acdirmax
= option
;
1167 if (match_int(args
, &option
) || option
< 0) {
1169 nfs_parse_invalid_value("actimeo");
1171 mnt
->acregmin
= mnt
->acregmax
=
1172 mnt
->acdirmin
= mnt
->acdirmax
= option
;
1175 if (match_int(args
, &option
) || option
< 0) {
1177 nfs_parse_invalid_value("namlen");
1179 mnt
->namlen
= option
;
1182 if (match_int(args
, &option
) ||
1183 option
< 0 || option
> USHORT_MAX
) {
1185 nfs_parse_invalid_value("mountport");
1187 mnt
->mount_server
.port
= option
;
1190 if (match_int(args
, &option
) ||
1191 option
< NFS_MNT_VERSION
||
1192 option
> NFS_MNT3_VERSION
) {
1194 nfs_parse_invalid_value("mountvers");
1196 mnt
->mount_server
.version
= option
;
1199 if (match_int(args
, &option
)) {
1201 nfs_parse_invalid_value("nfsvers");
1206 mnt
->flags
&= ~NFS_MOUNT_VER3
;
1209 mnt
->flags
|= NFS_MOUNT_VER3
;
1213 nfs_parse_invalid_value("nfsvers");
1216 case Opt_minorversion
:
1217 if (match_int(args
, &option
))
1219 if (option
< 0 || option
> NFS4_MAX_MINOR_VERSION
)
1221 mnt
->minorversion
= option
;
1225 * options that take text values
1228 string
= match_strdup(args
);
1231 rc
= nfs_parse_security_flavors(string
, mnt
);
1235 dfprintk(MOUNT
, "NFS: unrecognized "
1236 "security flavor\n");
1240 string
= match_strdup(args
);
1243 token
= match_token(string
,
1244 nfs_xprt_protocol_tokens
, args
);
1248 mnt
->flags
&= ~NFS_MOUNT_TCP
;
1249 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1252 mnt
->flags
|= NFS_MOUNT_TCP
;
1253 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1256 /* vector side protocols to TCP */
1257 mnt
->flags
|= NFS_MOUNT_TCP
;
1258 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_RDMA
;
1259 xprt_load_transport(string
);
1263 dfprintk(MOUNT
, "NFS: unrecognized "
1264 "transport protocol\n");
1268 case Opt_mountproto
:
1269 string
= match_strdup(args
);
1272 token
= match_token(string
,
1273 nfs_xprt_protocol_tokens
, args
);
1278 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_UDP
;
1281 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_TCP
;
1283 case Opt_xprt_rdma
: /* not used for side protocols */
1286 dfprintk(MOUNT
, "NFS: unrecognized "
1287 "transport protocol\n");
1291 string
= match_strdup(args
);
1294 nfs_parse_ip_address(string
, strlen(string
),
1296 &mnt
->nfs_server
.address
,
1297 &mnt
->nfs_server
.addrlen
);
1300 case Opt_clientaddr
:
1301 string
= match_strdup(args
);
1304 kfree(mnt
->client_address
);
1305 mnt
->client_address
= string
;
1308 string
= match_strdup(args
);
1311 kfree(mnt
->mount_server
.hostname
);
1312 mnt
->mount_server
.hostname
= string
;
1315 string
= match_strdup(args
);
1318 nfs_parse_ip_address(string
, strlen(string
),
1320 &mnt
->mount_server
.address
,
1321 &mnt
->mount_server
.addrlen
);
1324 case Opt_lookupcache
:
1325 string
= match_strdup(args
);
1328 token
= match_token(string
,
1329 nfs_lookupcache_tokens
, args
);
1332 case Opt_lookupcache_all
:
1333 mnt
->flags
&= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG
|NFS_MOUNT_LOOKUP_CACHE_NONE
);
1335 case Opt_lookupcache_positive
:
1336 mnt
->flags
&= ~NFS_MOUNT_LOOKUP_CACHE_NONE
;
1337 mnt
->flags
|= NFS_MOUNT_LOOKUP_CACHE_NONEG
;
1339 case Opt_lookupcache_none
:
1340 mnt
->flags
|= NFS_MOUNT_LOOKUP_CACHE_NONEG
|NFS_MOUNT_LOOKUP_CACHE_NONE
;
1344 dfprintk(MOUNT
, "NFS: invalid "
1345 "lookupcache argument\n");
1354 dfprintk(MOUNT
, "NFS: relaxing parsing rules\n");
1357 case Opt_deprecated
:
1358 dfprintk(MOUNT
, "NFS: ignoring mount option "
1364 dfprintk(MOUNT
, "NFS: unrecognized mount option "
1370 dfprintk(MOUNT
, "NFS: parsing encountered %d error%s\n",
1371 errors
, (errors
== 1 ? "" : "s"));
1378 printk(KERN_INFO
"NFS: not enough memory to parse option\n");
1380 out_security_failure
:
1381 free_secdata(secdata
);
1382 printk(KERN_INFO
"NFS: security options invalid: %d\n", rc
);
1387 * Use the remote server's MOUNT service to request the NFS file handle
1388 * corresponding to the provided path.
1390 static int nfs_try_mount(struct nfs_parsed_mount_data
*args
,
1391 struct nfs_fh
*root_fh
)
1393 struct nfs_mount_request request
= {
1394 .sap
= (struct sockaddr
*)
1395 &args
->mount_server
.address
,
1396 .dirpath
= args
->nfs_server
.export_path
,
1397 .protocol
= args
->mount_server
.protocol
,
1399 .noresvport
= args
->flags
& NFS_MOUNT_NORESVPORT
,
1403 if (args
->mount_server
.version
== 0) {
1404 if (args
->flags
& NFS_MOUNT_VER3
)
1405 args
->mount_server
.version
= NFS_MNT3_VERSION
;
1407 args
->mount_server
.version
= NFS_MNT_VERSION
;
1409 request
.version
= args
->mount_server
.version
;
1411 if (args
->mount_server
.hostname
)
1412 request
.hostname
= args
->mount_server
.hostname
;
1414 request
.hostname
= args
->nfs_server
.hostname
;
1417 * Construct the mount server's address.
1419 if (args
->mount_server
.address
.ss_family
== AF_UNSPEC
) {
1420 memcpy(request
.sap
, &args
->nfs_server
.address
,
1421 args
->nfs_server
.addrlen
);
1422 args
->mount_server
.addrlen
= args
->nfs_server
.addrlen
;
1424 request
.salen
= args
->mount_server
.addrlen
;
1427 * autobind will be used if mount_server.port == 0
1429 nfs_set_port(request
.sap
, args
->mount_server
.port
);
1432 * Now ask the mount server to map our export path
1435 status
= nfs_mount(&request
);
1439 dfprintk(MOUNT
, "NFS: unable to mount server %s, error %d\n",
1440 request
.hostname
, status
);
1444 static int nfs_parse_simple_hostname(const char *dev_name
,
1445 char **hostname
, size_t maxnamlen
,
1446 char **export_path
, size_t maxpathlen
)
1449 char *colon
, *comma
;
1451 colon
= strchr(dev_name
, ':');
1453 goto out_bad_devname
;
1455 len
= colon
- dev_name
;
1456 if (len
> maxnamlen
)
1459 /* N.B. caller will free nfs_server.hostname in all cases */
1460 *hostname
= kstrndup(dev_name
, len
, GFP_KERNEL
);
1464 /* kill possible hostname list: not supported */
1465 comma
= strchr(*hostname
, ',');
1466 if (comma
!= NULL
) {
1467 if (comma
== *hostname
)
1468 goto out_bad_devname
;
1473 len
= strlen(colon
);
1474 if (len
> maxpathlen
)
1476 *export_path
= kstrndup(colon
, len
, GFP_KERNEL
);
1480 dfprintk(MOUNT
, "NFS: MNTPATH: '%s'\n", *export_path
);
1484 dfprintk(MOUNT
, "NFS: device name not in host:path format\n");
1488 dfprintk(MOUNT
, "NFS: not enough memory to parse device name\n");
1492 dfprintk(MOUNT
, "NFS: server hostname too long\n");
1493 return -ENAMETOOLONG
;
1496 dfprintk(MOUNT
, "NFS: export pathname too long\n");
1497 return -ENAMETOOLONG
;
1501 * Hostname has square brackets around it because it contains one or
1502 * more colons. We look for the first closing square bracket, and a
1503 * colon must follow it.
1505 static int nfs_parse_protected_hostname(const char *dev_name
,
1506 char **hostname
, size_t maxnamlen
,
1507 char **export_path
, size_t maxpathlen
)
1512 start
= (char *)(dev_name
+ 1);
1514 end
= strchr(start
, ']');
1516 goto out_bad_devname
;
1517 if (*(end
+ 1) != ':')
1518 goto out_bad_devname
;
1521 if (len
> maxnamlen
)
1524 /* N.B. caller will free nfs_server.hostname in all cases */
1525 *hostname
= kstrndup(start
, len
, GFP_KERNEL
);
1526 if (*hostname
== NULL
)
1531 if (len
> maxpathlen
)
1533 *export_path
= kstrndup(end
, len
, GFP_KERNEL
);
1540 dfprintk(MOUNT
, "NFS: device name not in host:path format\n");
1544 dfprintk(MOUNT
, "NFS: not enough memory to parse device name\n");
1548 dfprintk(MOUNT
, "NFS: server hostname too long\n");
1549 return -ENAMETOOLONG
;
1552 dfprintk(MOUNT
, "NFS: export pathname too long\n");
1553 return -ENAMETOOLONG
;
1557 * Split "dev_name" into "hostname:export_path".
1559 * The leftmost colon demarks the split between the server's hostname
1560 * and the export path. If the hostname starts with a left square
1561 * bracket, then it may contain colons.
1563 * Note: caller frees hostname and export path, even on error.
1565 static int nfs_parse_devname(const char *dev_name
,
1566 char **hostname
, size_t maxnamlen
,
1567 char **export_path
, size_t maxpathlen
)
1569 if (*dev_name
== '[')
1570 return nfs_parse_protected_hostname(dev_name
,
1571 hostname
, maxnamlen
,
1572 export_path
, maxpathlen
);
1574 return nfs_parse_simple_hostname(dev_name
,
1575 hostname
, maxnamlen
,
1576 export_path
, maxpathlen
);
1580 * Validate the NFS2/NFS3 mount data
1581 * - fills in the mount root filehandle
1583 * For option strings, user space handles the following behaviors:
1585 * + DNS: mapping server host name to IP address ("addr=" option)
1587 * + failure mode: how to behave if a mount request can't be handled
1588 * immediately ("fg/bg" option)
1590 * + retry: how often to retry a mount request ("retry=" option)
1592 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1593 * mountproto=tcp after mountproto=udp, and so on
1595 static int nfs_validate_mount_data(void *options
,
1596 struct nfs_parsed_mount_data
*args
,
1597 struct nfs_fh
*mntfh
,
1598 const char *dev_name
)
1600 struct nfs_mount_data
*data
= (struct nfs_mount_data
*)options
;
1605 args
->flags
= (NFS_MOUNT_VER3
| NFS_MOUNT_TCP
);
1606 args
->rsize
= NFS_MAX_FILE_IO_SIZE
;
1607 args
->wsize
= NFS_MAX_FILE_IO_SIZE
;
1608 args
->acregmin
= NFS_DEF_ACREGMIN
;
1609 args
->acregmax
= NFS_DEF_ACREGMAX
;
1610 args
->acdirmin
= NFS_DEF_ACDIRMIN
;
1611 args
->acdirmax
= NFS_DEF_ACDIRMAX
;
1612 args
->mount_server
.port
= 0; /* autobind unless user sets port */
1613 args
->nfs_server
.port
= 0; /* autobind unless user sets port */
1614 args
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1615 args
->auth_flavors
[0] = RPC_AUTH_UNIX
;
1617 switch (data
->version
) {
1623 if (data
->flags
& NFS_MOUNT_VER3
)
1625 data
->root
.size
= NFS2_FHSIZE
;
1626 memcpy(data
->root
.data
, data
->old_root
.data
, NFS2_FHSIZE
);
1628 if (data
->flags
& NFS_MOUNT_SECFLAVOUR
)
1631 memset(data
->context
, 0, sizeof(data
->context
));
1633 if (data
->flags
& NFS_MOUNT_VER3
) {
1634 if (data
->root
.size
> NFS3_FHSIZE
|| data
->root
.size
== 0)
1635 goto out_invalid_fh
;
1636 mntfh
->size
= data
->root
.size
;
1638 mntfh
->size
= NFS2_FHSIZE
;
1641 memcpy(mntfh
->data
, data
->root
.data
, mntfh
->size
);
1642 if (mntfh
->size
< sizeof(mntfh
->data
))
1643 memset(mntfh
->data
+ mntfh
->size
, 0,
1644 sizeof(mntfh
->data
) - mntfh
->size
);
1647 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1650 args
->flags
= data
->flags
& NFS_MOUNT_FLAGMASK
;
1651 args
->rsize
= data
->rsize
;
1652 args
->wsize
= data
->wsize
;
1653 args
->timeo
= data
->timeo
;
1654 args
->retrans
= data
->retrans
;
1655 args
->acregmin
= data
->acregmin
;
1656 args
->acregmax
= data
->acregmax
;
1657 args
->acdirmin
= data
->acdirmin
;
1658 args
->acdirmax
= data
->acdirmax
;
1660 memcpy(&args
->nfs_server
.address
, &data
->addr
,
1661 sizeof(data
->addr
));
1662 args
->nfs_server
.addrlen
= sizeof(data
->addr
);
1663 if (!nfs_verify_server_address((struct sockaddr
*)
1664 &args
->nfs_server
.address
))
1665 goto out_no_address
;
1667 if (!(data
->flags
& NFS_MOUNT_TCP
))
1668 args
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1669 /* N.B. caller will free nfs_server.hostname in all cases */
1670 args
->nfs_server
.hostname
= kstrdup(data
->hostname
, GFP_KERNEL
);
1671 args
->namlen
= data
->namlen
;
1672 args
->bsize
= data
->bsize
;
1674 if (data
->flags
& NFS_MOUNT_SECFLAVOUR
)
1675 args
->auth_flavors
[0] = data
->pseudoflavor
;
1676 if (!args
->nfs_server
.hostname
)
1680 * The legacy version 6 binary mount data from userspace has a
1681 * field used only to transport selinux information into the
1682 * the kernel. To continue to support that functionality we
1683 * have a touch of selinux knowledge here in the NFS code. The
1684 * userspace code converted context=blah to just blah so we are
1685 * converting back to the full string selinux understands.
1687 if (data
->context
[0]){
1688 #ifdef CONFIG_SECURITY_SELINUX
1690 char *opts_str
= kmalloc(sizeof(data
->context
) + 8, GFP_KERNEL
);
1693 strcpy(opts_str
, "context=");
1694 data
->context
[NFS_MAX_CONTEXT_LEN
] = '\0';
1695 strcat(opts_str
, &data
->context
[0]);
1696 rc
= security_sb_parse_opts_str(opts_str
, &args
->lsm_opts
);
1709 if (nfs_parse_mount_options((char *)options
, args
) == 0)
1712 if (!nfs_verify_server_address((struct sockaddr
*)
1713 &args
->nfs_server
.address
))
1714 goto out_no_address
;
1716 nfs_set_port((struct sockaddr
*)&args
->nfs_server
.address
,
1717 args
->nfs_server
.port
);
1719 nfs_set_mount_transport_protocol(args
);
1721 status
= nfs_parse_devname(dev_name
,
1722 &args
->nfs_server
.hostname
,
1724 &args
->nfs_server
.export_path
,
1727 status
= nfs_try_mount(args
, mntfh
);
1729 kfree(args
->nfs_server
.export_path
);
1730 args
->nfs_server
.export_path
= NULL
;
1739 #ifndef CONFIG_NFS_V3
1740 if (args
->flags
& NFS_MOUNT_VER3
)
1741 goto out_v3_not_compiled
;
1742 #endif /* !CONFIG_NFS_V3 */
1747 dfprintk(MOUNT
, "NFS: mount program didn't pass any mount data\n");
1751 dfprintk(MOUNT
, "NFS: nfs_mount_data version %d does not support v3\n",
1756 dfprintk(MOUNT
, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1759 #ifndef CONFIG_NFS_V3
1760 out_v3_not_compiled
:
1761 dfprintk(MOUNT
, "NFS: NFSv3 is not compiled into kernel\n");
1762 return -EPROTONOSUPPORT
;
1763 #endif /* !CONFIG_NFS_V3 */
1766 dfprintk(MOUNT
, "NFS: not enough memory to handle mount options\n");
1770 dfprintk(MOUNT
, "NFS: mount program didn't pass remote address\n");
1774 dfprintk(MOUNT
, "NFS: invalid root filehandle\n");
1779 nfs_compare_remount_data(struct nfs_server
*nfss
,
1780 struct nfs_parsed_mount_data
*data
)
1782 if (data
->flags
!= nfss
->flags
||
1783 data
->rsize
!= nfss
->rsize
||
1784 data
->wsize
!= nfss
->wsize
||
1785 data
->retrans
!= nfss
->client
->cl_timeout
->to_retries
||
1786 data
->auth_flavors
[0] != nfss
->client
->cl_auth
->au_flavor
||
1787 data
->acregmin
!= nfss
->acregmin
/ HZ
||
1788 data
->acregmax
!= nfss
->acregmax
/ HZ
||
1789 data
->acdirmin
!= nfss
->acdirmin
/ HZ
||
1790 data
->acdirmax
!= nfss
->acdirmax
/ HZ
||
1791 data
->timeo
!= (10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
) ||
1792 data
->nfs_server
.addrlen
!= nfss
->nfs_client
->cl_addrlen
||
1793 memcmp(&data
->nfs_server
.address
, &nfss
->nfs_client
->cl_addr
,
1794 data
->nfs_server
.addrlen
) != 0)
1801 nfs_remount(struct super_block
*sb
, int *flags
, char *raw_data
)
1804 struct nfs_server
*nfss
= sb
->s_fs_info
;
1805 struct nfs_parsed_mount_data
*data
;
1806 struct nfs_mount_data
*options
= (struct nfs_mount_data
*)raw_data
;
1807 struct nfs4_mount_data
*options4
= (struct nfs4_mount_data
*)raw_data
;
1808 u32 nfsvers
= nfss
->nfs_client
->rpc_ops
->version
;
1811 * Userspace mount programs that send binary options generally send
1812 * them populated with default values. We have no way to know which
1813 * ones were explicitly specified. Fall back to legacy behavior and
1814 * just return success.
1816 if ((nfsvers
== 4 && (!options4
|| options4
->version
== 1)) ||
1817 (nfsvers
<= 3 && (!options
|| (options
->version
>= 1 &&
1818 options
->version
<= 6))))
1821 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
1826 /* fill out struct with values from existing mount */
1827 data
->flags
= nfss
->flags
;
1828 data
->rsize
= nfss
->rsize
;
1829 data
->wsize
= nfss
->wsize
;
1830 data
->retrans
= nfss
->client
->cl_timeout
->to_retries
;
1831 data
->auth_flavors
[0] = nfss
->client
->cl_auth
->au_flavor
;
1832 data
->acregmin
= nfss
->acregmin
/ HZ
;
1833 data
->acregmax
= nfss
->acregmax
/ HZ
;
1834 data
->acdirmin
= nfss
->acdirmin
/ HZ
;
1835 data
->acdirmax
= nfss
->acdirmax
/ HZ
;
1836 data
->timeo
= 10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
;
1837 data
->nfs_server
.addrlen
= nfss
->nfs_client
->cl_addrlen
;
1838 memcpy(&data
->nfs_server
.address
, &nfss
->nfs_client
->cl_addr
,
1839 data
->nfs_server
.addrlen
);
1841 /* overwrite those values with any that were specified */
1842 error
= nfs_parse_mount_options((char *)options
, data
);
1846 /* compare new mount options with old ones */
1847 error
= nfs_compare_remount_data(nfss
, data
);
1855 * Initialise the common bits of the superblock
1857 static inline void nfs_initialise_sb(struct super_block
*sb
)
1859 struct nfs_server
*server
= NFS_SB(sb
);
1861 sb
->s_magic
= NFS_SUPER_MAGIC
;
1863 /* We probably want something more informative here */
1864 snprintf(sb
->s_id
, sizeof(sb
->s_id
),
1865 "%x:%x", MAJOR(sb
->s_dev
), MINOR(sb
->s_dev
));
1867 if (sb
->s_blocksize
== 0)
1868 sb
->s_blocksize
= nfs_block_bits(server
->wsize
,
1869 &sb
->s_blocksize_bits
);
1871 if (server
->flags
& NFS_MOUNT_NOAC
)
1872 sb
->s_flags
|= MS_SYNCHRONOUS
;
1874 nfs_super_set_maxbytes(sb
, server
->maxfilesize
);
1878 * Finish setting up an NFS2/3 superblock
1880 static void nfs_fill_super(struct super_block
*sb
,
1881 struct nfs_parsed_mount_data
*data
)
1883 struct nfs_server
*server
= NFS_SB(sb
);
1885 sb
->s_blocksize_bits
= 0;
1886 sb
->s_blocksize
= 0;
1888 sb
->s_blocksize
= nfs_block_size(data
->bsize
, &sb
->s_blocksize_bits
);
1890 if (server
->flags
& NFS_MOUNT_VER3
) {
1891 /* The VFS shouldn't apply the umask to mode bits. We will do
1892 * so ourselves when necessary.
1894 sb
->s_flags
|= MS_POSIXACL
;
1895 sb
->s_time_gran
= 1;
1898 sb
->s_op
= &nfs_sops
;
1899 nfs_initialise_sb(sb
);
1903 * Finish setting up a cloned NFS2/3 superblock
1905 static void nfs_clone_super(struct super_block
*sb
,
1906 const struct super_block
*old_sb
)
1908 struct nfs_server
*server
= NFS_SB(sb
);
1910 sb
->s_blocksize_bits
= old_sb
->s_blocksize_bits
;
1911 sb
->s_blocksize
= old_sb
->s_blocksize
;
1912 sb
->s_maxbytes
= old_sb
->s_maxbytes
;
1914 if (server
->flags
& NFS_MOUNT_VER3
) {
1915 /* The VFS shouldn't apply the umask to mode bits. We will do
1916 * so ourselves when necessary.
1918 sb
->s_flags
|= MS_POSIXACL
;
1919 sb
->s_time_gran
= 1;
1922 sb
->s_op
= old_sb
->s_op
;
1923 nfs_initialise_sb(sb
);
1926 static int nfs_compare_mount_options(const struct super_block
*s
, const struct nfs_server
*b
, int flags
)
1928 const struct nfs_server
*a
= s
->s_fs_info
;
1929 const struct rpc_clnt
*clnt_a
= a
->client
;
1930 const struct rpc_clnt
*clnt_b
= b
->client
;
1932 if ((s
->s_flags
& NFS_MS_MASK
) != (flags
& NFS_MS_MASK
))
1934 if (a
->nfs_client
!= b
->nfs_client
)
1936 if (a
->flags
!= b
->flags
)
1938 if (a
->wsize
!= b
->wsize
)
1940 if (a
->rsize
!= b
->rsize
)
1942 if (a
->acregmin
!= b
->acregmin
)
1944 if (a
->acregmax
!= b
->acregmax
)
1946 if (a
->acdirmin
!= b
->acdirmin
)
1948 if (a
->acdirmax
!= b
->acdirmax
)
1950 if (clnt_a
->cl_auth
->au_flavor
!= clnt_b
->cl_auth
->au_flavor
)
1957 struct nfs_sb_mountdata
{
1958 struct nfs_server
*server
;
1962 static int nfs_set_super(struct super_block
*s
, void *data
)
1964 struct nfs_sb_mountdata
*sb_mntdata
= data
;
1965 struct nfs_server
*server
= sb_mntdata
->server
;
1968 s
->s_flags
= sb_mntdata
->mntflags
;
1969 s
->s_fs_info
= server
;
1970 ret
= set_anon_super(s
, server
);
1972 server
->s_dev
= s
->s_dev
;
1976 static int nfs_compare_super_address(struct nfs_server
*server1
,
1977 struct nfs_server
*server2
)
1979 struct sockaddr
*sap1
, *sap2
;
1981 sap1
= (struct sockaddr
*)&server1
->nfs_client
->cl_addr
;
1982 sap2
= (struct sockaddr
*)&server2
->nfs_client
->cl_addr
;
1984 if (sap1
->sa_family
!= sap2
->sa_family
)
1987 switch (sap1
->sa_family
) {
1989 struct sockaddr_in
*sin1
= (struct sockaddr_in
*)sap1
;
1990 struct sockaddr_in
*sin2
= (struct sockaddr_in
*)sap2
;
1991 if (sin1
->sin_addr
.s_addr
!= sin2
->sin_addr
.s_addr
)
1993 if (sin1
->sin_port
!= sin2
->sin_port
)
1998 struct sockaddr_in6
*sin1
= (struct sockaddr_in6
*)sap1
;
1999 struct sockaddr_in6
*sin2
= (struct sockaddr_in6
*)sap2
;
2000 if (!ipv6_addr_equal(&sin1
->sin6_addr
, &sin2
->sin6_addr
))
2002 if (sin1
->sin6_port
!= sin2
->sin6_port
)
2013 static int nfs_compare_super(struct super_block
*sb
, void *data
)
2015 struct nfs_sb_mountdata
*sb_mntdata
= data
;
2016 struct nfs_server
*server
= sb_mntdata
->server
, *old
= NFS_SB(sb
);
2017 int mntflags
= sb_mntdata
->mntflags
;
2019 if (!nfs_compare_super_address(old
, server
))
2021 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2022 if (old
->flags
& NFS_MOUNT_UNSHARED
)
2024 if (memcmp(&old
->fsid
, &server
->fsid
, sizeof(old
->fsid
)) != 0)
2026 return nfs_compare_mount_options(sb
, server
, mntflags
);
2029 static int nfs_bdi_register(struct nfs_server
*server
)
2031 return bdi_register_dev(&server
->backing_dev_info
, server
->s_dev
);
2034 static int nfs_get_sb(struct file_system_type
*fs_type
,
2035 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
2037 struct nfs_server
*server
= NULL
;
2038 struct super_block
*s
;
2039 struct nfs_parsed_mount_data
*data
;
2040 struct nfs_fh
*mntfh
;
2041 struct dentry
*mntroot
;
2042 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2043 struct nfs_sb_mountdata sb_mntdata
= {
2046 int error
= -ENOMEM
;
2048 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
2049 mntfh
= kzalloc(sizeof(*mntfh
), GFP_KERNEL
);
2050 if (data
== NULL
|| mntfh
== NULL
)
2053 security_init_mnt_opts(&data
->lsm_opts
);
2055 /* Validate the mount data */
2056 error
= nfs_validate_mount_data(raw_data
, data
, mntfh
, dev_name
);
2060 /* Get a volume representation */
2061 server
= nfs_create_server(data
, mntfh
);
2062 if (IS_ERR(server
)) {
2063 error
= PTR_ERR(server
);
2066 sb_mntdata
.server
= server
;
2068 if (server
->flags
& NFS_MOUNT_UNSHARED
)
2069 compare_super
= NULL
;
2071 /* Get a superblock - note that we may end up sharing one that already exists */
2072 s
= sget(fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2078 if (s
->s_fs_info
!= server
) {
2079 nfs_free_server(server
);
2082 error
= nfs_bdi_register(server
);
2084 goto error_splat_super
;
2088 /* initial superblock/root creation */
2089 nfs_fill_super(s
, data
);
2090 nfs_fscache_get_super_cookie(s
, data
);
2093 mntroot
= nfs_get_root(s
, mntfh
);
2094 if (IS_ERR(mntroot
)) {
2095 error
= PTR_ERR(mntroot
);
2096 goto error_splat_super
;
2099 error
= security_sb_set_mnt_opts(s
, &data
->lsm_opts
);
2101 goto error_splat_root
;
2103 s
->s_flags
|= MS_ACTIVE
;
2105 mnt
->mnt_root
= mntroot
;
2109 kfree(data
->nfs_server
.hostname
);
2110 kfree(data
->mount_server
.hostname
);
2111 kfree(data
->fscache_uniq
);
2112 security_free_mnt_opts(&data
->lsm_opts
);
2119 nfs_free_server(server
);
2125 deactivate_locked_super(s
);
2130 * Destroy an NFS2/3 superblock
2132 static void nfs_kill_super(struct super_block
*s
)
2134 struct nfs_server
*server
= NFS_SB(s
);
2136 bdi_unregister(&server
->backing_dev_info
);
2138 nfs_fscache_release_super_cookie(s
);
2139 nfs_free_server(server
);
2143 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2145 static int nfs_xdev_get_sb(struct file_system_type
*fs_type
, int flags
,
2146 const char *dev_name
, void *raw_data
,
2147 struct vfsmount
*mnt
)
2149 struct nfs_clone_mount
*data
= raw_data
;
2150 struct super_block
*s
;
2151 struct nfs_server
*server
;
2152 struct dentry
*mntroot
;
2153 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2154 struct nfs_sb_mountdata sb_mntdata
= {
2159 dprintk("--> nfs_xdev_get_sb()\n");
2161 /* create a new volume representation */
2162 server
= nfs_clone_server(NFS_SB(data
->sb
), data
->fh
, data
->fattr
);
2163 if (IS_ERR(server
)) {
2164 error
= PTR_ERR(server
);
2165 goto out_err_noserver
;
2167 sb_mntdata
.server
= server
;
2169 if (server
->flags
& NFS_MOUNT_UNSHARED
)
2170 compare_super
= NULL
;
2172 /* Get a superblock - note that we may end up sharing one that already exists */
2173 s
= sget(&nfs_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2179 if (s
->s_fs_info
!= server
) {
2180 nfs_free_server(server
);
2183 error
= nfs_bdi_register(server
);
2185 goto error_splat_super
;
2189 /* initial superblock/root creation */
2190 nfs_clone_super(s
, data
->sb
);
2193 mntroot
= nfs_get_root(s
, data
->fh
);
2194 if (IS_ERR(mntroot
)) {
2195 error
= PTR_ERR(mntroot
);
2196 goto error_splat_super
;
2198 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
2201 goto error_splat_super
;
2204 s
->s_flags
|= MS_ACTIVE
;
2206 mnt
->mnt_root
= mntroot
;
2208 /* clone any lsm security options from the parent to the new sb */
2209 security_sb_clone_mnt_opts(data
->sb
, s
);
2211 dprintk("<-- nfs_xdev_get_sb() = 0\n");
2215 nfs_free_server(server
);
2217 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error
);
2221 deactivate_locked_super(s
);
2222 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error
);
2226 #ifdef CONFIG_NFS_V4
2229 * Finish setting up a cloned NFS4 superblock
2231 static void nfs4_clone_super(struct super_block
*sb
,
2232 const struct super_block
*old_sb
)
2234 sb
->s_blocksize_bits
= old_sb
->s_blocksize_bits
;
2235 sb
->s_blocksize
= old_sb
->s_blocksize
;
2236 sb
->s_maxbytes
= old_sb
->s_maxbytes
;
2237 sb
->s_time_gran
= 1;
2238 sb
->s_op
= old_sb
->s_op
;
2239 nfs_initialise_sb(sb
);
2243 * Set up an NFS4 superblock
2245 static void nfs4_fill_super(struct super_block
*sb
)
2247 sb
->s_time_gran
= 1;
2248 sb
->s_op
= &nfs4_sops
;
2249 nfs_initialise_sb(sb
);
2253 * Validate NFSv4 mount options
2255 static int nfs4_validate_mount_data(void *options
,
2256 struct nfs_parsed_mount_data
*args
,
2257 const char *dev_name
)
2259 struct sockaddr_in
*ap
;
2260 struct nfs4_mount_data
*data
= (struct nfs4_mount_data
*)options
;
2266 args
->rsize
= NFS_MAX_FILE_IO_SIZE
;
2267 args
->wsize
= NFS_MAX_FILE_IO_SIZE
;
2268 args
->acregmin
= NFS_DEF_ACREGMIN
;
2269 args
->acregmax
= NFS_DEF_ACREGMAX
;
2270 args
->acdirmin
= NFS_DEF_ACDIRMIN
;
2271 args
->acdirmax
= NFS_DEF_ACDIRMAX
;
2272 args
->nfs_server
.port
= NFS_PORT
; /* 2049 unless user set port= */
2273 args
->auth_flavors
[0] = RPC_AUTH_UNIX
;
2274 args
->auth_flavor_len
= 0;
2275 args
->minorversion
= 0;
2277 switch (data
->version
) {
2279 ap
= (struct sockaddr_in
*)&args
->nfs_server
.address
;
2280 if (data
->host_addrlen
> sizeof(args
->nfs_server
.address
))
2281 goto out_no_address
;
2282 if (data
->host_addrlen
== 0)
2283 goto out_no_address
;
2284 args
->nfs_server
.addrlen
= data
->host_addrlen
;
2285 if (copy_from_user(ap
, data
->host_addr
, data
->host_addrlen
))
2287 if (!nfs_verify_server_address((struct sockaddr
*)
2288 &args
->nfs_server
.address
))
2289 goto out_no_address
;
2291 if (data
->auth_flavourlen
) {
2292 if (data
->auth_flavourlen
> 1)
2293 goto out_inval_auth
;
2294 if (copy_from_user(&args
->auth_flavors
[0],
2295 data
->auth_flavours
,
2296 sizeof(args
->auth_flavors
[0])))
2300 c
= strndup_user(data
->hostname
.data
, NFS4_MAXNAMLEN
);
2303 args
->nfs_server
.hostname
= c
;
2305 c
= strndup_user(data
->mnt_path
.data
, NFS4_MAXPATHLEN
);
2308 args
->nfs_server
.export_path
= c
;
2309 dfprintk(MOUNT
, "NFS: MNTPATH: '%s'\n", c
);
2311 c
= strndup_user(data
->client_addr
.data
, 16);
2314 args
->client_address
= c
;
2317 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2321 args
->flags
= data
->flags
& NFS4_MOUNT_FLAGMASK
;
2322 args
->rsize
= data
->rsize
;
2323 args
->wsize
= data
->wsize
;
2324 args
->timeo
= data
->timeo
;
2325 args
->retrans
= data
->retrans
;
2326 args
->acregmin
= data
->acregmin
;
2327 args
->acregmax
= data
->acregmax
;
2328 args
->acdirmin
= data
->acdirmin
;
2329 args
->acdirmax
= data
->acdirmax
;
2330 args
->nfs_server
.protocol
= data
->proto
;
2331 nfs_validate_transport_protocol(args
);
2337 if (nfs_parse_mount_options((char *)options
, args
) == 0)
2340 if (!nfs_verify_server_address((struct sockaddr
*)
2341 &args
->nfs_server
.address
))
2344 nfs_set_port((struct sockaddr
*)&args
->nfs_server
.address
,
2345 args
->nfs_server
.port
);
2347 nfs_validate_transport_protocol(args
);
2349 if (args
->auth_flavor_len
> 1)
2350 goto out_inval_auth
;
2352 if (args
->client_address
== NULL
)
2353 goto out_no_client_address
;
2355 status
= nfs_parse_devname(dev_name
,
2356 &args
->nfs_server
.hostname
,
2358 &args
->nfs_server
.export_path
,
2370 dfprintk(MOUNT
, "NFS4: mount program didn't pass any mount data\n");
2374 dfprintk(MOUNT
, "NFS4: Invalid number of RPC auth flavours %d\n",
2375 data
->auth_flavourlen
);
2379 dfprintk(MOUNT
, "NFS4: mount program didn't pass remote address\n");
2382 out_no_client_address
:
2383 dfprintk(MOUNT
, "NFS4: mount program didn't pass callback address\n");
2388 * Get the superblock for an NFS4 mountpoint
2390 static int nfs4_get_sb(struct file_system_type
*fs_type
,
2391 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
2393 struct nfs_parsed_mount_data
*data
;
2394 struct super_block
*s
;
2395 struct nfs_server
*server
;
2396 struct nfs_fh
*mntfh
;
2397 struct dentry
*mntroot
;
2398 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2399 struct nfs_sb_mountdata sb_mntdata
= {
2402 int error
= -ENOMEM
;
2404 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
2405 mntfh
= kzalloc(sizeof(*mntfh
), GFP_KERNEL
);
2406 if (data
== NULL
|| mntfh
== NULL
)
2409 security_init_mnt_opts(&data
->lsm_opts
);
2411 /* Validate the mount data */
2412 error
= nfs4_validate_mount_data(raw_data
, data
, dev_name
);
2416 /* Get a volume representation */
2417 server
= nfs4_create_server(data
, mntfh
);
2418 if (IS_ERR(server
)) {
2419 error
= PTR_ERR(server
);
2422 sb_mntdata
.server
= server
;
2424 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2425 compare_super
= NULL
;
2427 /* Get a superblock - note that we may end up sharing one that already exists */
2428 s
= sget(fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2434 if (s
->s_fs_info
!= server
) {
2435 nfs_free_server(server
);
2438 error
= nfs_bdi_register(server
);
2440 goto error_splat_super
;
2444 /* initial superblock/root creation */
2446 nfs_fscache_get_super_cookie(s
, data
);
2449 mntroot
= nfs4_get_root(s
, mntfh
);
2450 if (IS_ERR(mntroot
)) {
2451 error
= PTR_ERR(mntroot
);
2452 goto error_splat_super
;
2455 error
= security_sb_set_mnt_opts(s
, &data
->lsm_opts
);
2457 goto error_splat_root
;
2459 s
->s_flags
|= MS_ACTIVE
;
2461 mnt
->mnt_root
= mntroot
;
2465 kfree(data
->client_address
);
2466 kfree(data
->nfs_server
.export_path
);
2467 kfree(data
->nfs_server
.hostname
);
2468 kfree(data
->fscache_uniq
);
2469 security_free_mnt_opts(&data
->lsm_opts
);
2476 nfs_free_server(server
);
2482 deactivate_locked_super(s
);
2486 static void nfs4_kill_super(struct super_block
*sb
)
2488 struct nfs_server
*server
= NFS_SB(sb
);
2490 dprintk("--> %s\n", __func__
);
2491 nfs_super_return_all_delegations(sb
);
2492 kill_anon_super(sb
);
2493 nfs4_renewd_prepare_shutdown(server
);
2494 nfs_fscache_release_super_cookie(sb
);
2495 nfs_free_server(server
);
2496 dprintk("<-- %s\n", __func__
);
2500 * Clone an NFS4 server record on xdev traversal (FSID-change)
2502 static int nfs4_xdev_get_sb(struct file_system_type
*fs_type
, int flags
,
2503 const char *dev_name
, void *raw_data
,
2504 struct vfsmount
*mnt
)
2506 struct nfs_clone_mount
*data
= raw_data
;
2507 struct super_block
*s
;
2508 struct nfs_server
*server
;
2509 struct dentry
*mntroot
;
2510 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2511 struct nfs_sb_mountdata sb_mntdata
= {
2516 dprintk("--> nfs4_xdev_get_sb()\n");
2518 /* create a new volume representation */
2519 server
= nfs_clone_server(NFS_SB(data
->sb
), data
->fh
, data
->fattr
);
2520 if (IS_ERR(server
)) {
2521 error
= PTR_ERR(server
);
2522 goto out_err_noserver
;
2524 sb_mntdata
.server
= server
;
2526 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2527 compare_super
= NULL
;
2529 /* Get a superblock - note that we may end up sharing one that already exists */
2530 s
= sget(&nfs4_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2536 if (s
->s_fs_info
!= server
) {
2537 nfs_free_server(server
);
2540 error
= nfs_bdi_register(server
);
2542 goto error_splat_super
;
2546 /* initial superblock/root creation */
2547 nfs4_clone_super(s
, data
->sb
);
2550 mntroot
= nfs4_get_root(s
, data
->fh
);
2551 if (IS_ERR(mntroot
)) {
2552 error
= PTR_ERR(mntroot
);
2553 goto error_splat_super
;
2555 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
2558 goto error_splat_super
;
2561 s
->s_flags
|= MS_ACTIVE
;
2563 mnt
->mnt_root
= mntroot
;
2565 security_sb_clone_mnt_opts(data
->sb
, s
);
2567 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2571 nfs_free_server(server
);
2573 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error
);
2577 deactivate_locked_super(s
);
2578 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error
);
2583 * Create an NFS4 server record on referral traversal
2585 static int nfs4_referral_get_sb(struct file_system_type
*fs_type
, int flags
,
2586 const char *dev_name
, void *raw_data
,
2587 struct vfsmount
*mnt
)
2589 struct nfs_clone_mount
*data
= raw_data
;
2590 struct super_block
*s
;
2591 struct nfs_server
*server
;
2592 struct dentry
*mntroot
;
2593 struct nfs_fh mntfh
;
2594 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2595 struct nfs_sb_mountdata sb_mntdata
= {
2600 dprintk("--> nfs4_referral_get_sb()\n");
2602 /* create a new volume representation */
2603 server
= nfs4_create_referral_server(data
, &mntfh
);
2604 if (IS_ERR(server
)) {
2605 error
= PTR_ERR(server
);
2606 goto out_err_noserver
;
2608 sb_mntdata
.server
= server
;
2610 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2611 compare_super
= NULL
;
2613 /* Get a superblock - note that we may end up sharing one that already exists */
2614 s
= sget(&nfs4_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2620 if (s
->s_fs_info
!= server
) {
2621 nfs_free_server(server
);
2624 error
= nfs_bdi_register(server
);
2626 goto error_splat_super
;
2630 /* initial superblock/root creation */
2634 mntroot
= nfs4_get_root(s
, &mntfh
);
2635 if (IS_ERR(mntroot
)) {
2636 error
= PTR_ERR(mntroot
);
2637 goto error_splat_super
;
2639 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
2642 goto error_splat_super
;
2645 s
->s_flags
|= MS_ACTIVE
;
2647 mnt
->mnt_root
= mntroot
;
2649 security_sb_clone_mnt_opts(data
->sb
, s
);
2651 dprintk("<-- nfs4_referral_get_sb() = 0\n");
2655 nfs_free_server(server
);
2657 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error
);
2661 deactivate_locked_super(s
);
2662 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error
);
2666 #endif /* CONFIG_NFS_V4 */