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"
64 #define NFSDBG_FACILITY NFSDBG_VFS
67 /* Mount options that take no arguments */
69 Opt_posix
, Opt_noposix
,
74 Opt_udp
, Opt_tcp
, Opt_rdma
,
76 Opt_rdirplus
, Opt_nordirplus
,
77 Opt_sharecache
, Opt_nosharecache
,
78 Opt_resvport
, Opt_noresvport
,
80 /* Mount options that take integer arguments */
82 Opt_rsize
, Opt_wsize
, Opt_bsize
,
83 Opt_timeo
, Opt_retrans
,
84 Opt_acregmin
, Opt_acregmax
,
85 Opt_acdirmin
, Opt_acdirmax
,
92 /* Mount options that take string arguments */
93 Opt_sec
, Opt_proto
, Opt_mountproto
, Opt_mounthost
,
94 Opt_addr
, Opt_mountaddr
, Opt_clientaddr
,
97 /* Special mount options */
98 Opt_userspace
, Opt_deprecated
, Opt_sloppy
,
103 static const match_table_t nfs_mount_option_tokens
= {
104 { Opt_userspace
, "bg" },
105 { Opt_userspace
, "fg" },
106 { Opt_userspace
, "retry=%s" },
108 { Opt_sloppy
, "sloppy" },
110 { Opt_soft
, "soft" },
111 { Opt_hard
, "hard" },
112 { Opt_deprecated
, "intr" },
113 { Opt_deprecated
, "nointr" },
114 { Opt_posix
, "posix" },
115 { Opt_noposix
, "noposix" },
117 { Opt_nocto
, "nocto" },
119 { Opt_noac
, "noac" },
120 { Opt_lock
, "lock" },
121 { Opt_nolock
, "nolock" },
126 { Opt_rdma
, "rdma" },
128 { Opt_noacl
, "noacl" },
129 { Opt_rdirplus
, "rdirplus" },
130 { Opt_nordirplus
, "nordirplus" },
131 { Opt_sharecache
, "sharecache" },
132 { Opt_nosharecache
, "nosharecache" },
133 { Opt_resvport
, "resvport" },
134 { Opt_noresvport
, "noresvport" },
136 { Opt_port
, "port=%u" },
137 { Opt_rsize
, "rsize=%u" },
138 { Opt_wsize
, "wsize=%u" },
139 { Opt_bsize
, "bsize=%u" },
140 { Opt_timeo
, "timeo=%u" },
141 { Opt_retrans
, "retrans=%u" },
142 { Opt_acregmin
, "acregmin=%u" },
143 { Opt_acregmax
, "acregmax=%u" },
144 { Opt_acdirmin
, "acdirmin=%u" },
145 { Opt_acdirmax
, "acdirmax=%u" },
146 { Opt_actimeo
, "actimeo=%u" },
147 { Opt_namelen
, "namlen=%u" },
148 { Opt_mountport
, "mountport=%u" },
149 { Opt_mountvers
, "mountvers=%u" },
150 { Opt_nfsvers
, "nfsvers=%u" },
151 { Opt_nfsvers
, "vers=%u" },
153 { Opt_sec
, "sec=%s" },
154 { Opt_proto
, "proto=%s" },
155 { Opt_mountproto
, "mountproto=%s" },
156 { Opt_addr
, "addr=%s" },
157 { Opt_clientaddr
, "clientaddr=%s" },
158 { Opt_mounthost
, "mounthost=%s" },
159 { Opt_mountaddr
, "mountaddr=%s" },
161 { Opt_lookupcache
, "lookupcache=%s" },
167 Opt_xprt_udp
, Opt_xprt_tcp
, Opt_xprt_rdma
,
172 static const match_table_t nfs_xprt_protocol_tokens
= {
173 { Opt_xprt_udp
, "udp" },
174 { Opt_xprt_tcp
, "tcp" },
175 { Opt_xprt_rdma
, "rdma" },
177 { Opt_xprt_err
, NULL
}
181 Opt_sec_none
, Opt_sec_sys
,
182 Opt_sec_krb5
, Opt_sec_krb5i
, Opt_sec_krb5p
,
183 Opt_sec_lkey
, Opt_sec_lkeyi
, Opt_sec_lkeyp
,
184 Opt_sec_spkm
, Opt_sec_spkmi
, Opt_sec_spkmp
,
189 static const match_table_t nfs_secflavor_tokens
= {
190 { Opt_sec_none
, "none" },
191 { Opt_sec_none
, "null" },
192 { Opt_sec_sys
, "sys" },
194 { Opt_sec_krb5
, "krb5" },
195 { Opt_sec_krb5i
, "krb5i" },
196 { Opt_sec_krb5p
, "krb5p" },
198 { Opt_sec_lkey
, "lkey" },
199 { Opt_sec_lkeyi
, "lkeyi" },
200 { Opt_sec_lkeyp
, "lkeyp" },
202 { Opt_sec_spkm
, "spkm3" },
203 { Opt_sec_spkmi
, "spkm3i" },
204 { Opt_sec_spkmp
, "spkm3p" },
206 { Opt_sec_err
, NULL
}
210 Opt_lookupcache_all
, Opt_lookupcache_positive
,
211 Opt_lookupcache_none
,
216 static match_table_t nfs_lookupcache_tokens
= {
217 { Opt_lookupcache_all
, "all" },
218 { Opt_lookupcache_positive
, "pos" },
219 { Opt_lookupcache_positive
, "positive" },
220 { Opt_lookupcache_none
, "none" },
222 { Opt_lookupcache_err
, NULL
}
226 static void nfs_umount_begin(struct super_block
*);
227 static int nfs_statfs(struct dentry
*, struct kstatfs
*);
228 static int nfs_show_options(struct seq_file
*, struct vfsmount
*);
229 static int nfs_show_stats(struct seq_file
*, struct vfsmount
*);
230 static int nfs_get_sb(struct file_system_type
*, int, const char *, void *, struct vfsmount
*);
231 static int nfs_xdev_get_sb(struct file_system_type
*fs_type
,
232 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
233 static void nfs_kill_super(struct super_block
*);
234 static int nfs_remount(struct super_block
*sb
, int *flags
, char *raw_data
);
236 static struct file_system_type nfs_fs_type
= {
237 .owner
= THIS_MODULE
,
239 .get_sb
= nfs_get_sb
,
240 .kill_sb
= nfs_kill_super
,
241 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
244 struct file_system_type nfs_xdev_fs_type
= {
245 .owner
= THIS_MODULE
,
247 .get_sb
= nfs_xdev_get_sb
,
248 .kill_sb
= nfs_kill_super
,
249 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
252 static const struct super_operations nfs_sops
= {
253 .alloc_inode
= nfs_alloc_inode
,
254 .destroy_inode
= nfs_destroy_inode
,
255 .write_inode
= nfs_write_inode
,
256 .statfs
= nfs_statfs
,
257 .clear_inode
= nfs_clear_inode
,
258 .umount_begin
= nfs_umount_begin
,
259 .show_options
= nfs_show_options
,
260 .show_stats
= nfs_show_stats
,
261 .remount_fs
= nfs_remount
,
265 static int nfs4_get_sb(struct file_system_type
*fs_type
,
266 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
267 static int nfs4_xdev_get_sb(struct file_system_type
*fs_type
,
268 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
269 static int nfs4_referral_get_sb(struct file_system_type
*fs_type
,
270 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
271 static void nfs4_kill_super(struct super_block
*sb
);
273 static struct file_system_type nfs4_fs_type
= {
274 .owner
= THIS_MODULE
,
276 .get_sb
= nfs4_get_sb
,
277 .kill_sb
= nfs4_kill_super
,
278 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
281 struct file_system_type nfs4_xdev_fs_type
= {
282 .owner
= THIS_MODULE
,
284 .get_sb
= nfs4_xdev_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_referral_fs_type
= {
290 .owner
= THIS_MODULE
,
292 .get_sb
= nfs4_referral_get_sb
,
293 .kill_sb
= nfs4_kill_super
,
294 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
297 static const struct super_operations nfs4_sops
= {
298 .alloc_inode
= nfs_alloc_inode
,
299 .destroy_inode
= nfs_destroy_inode
,
300 .write_inode
= nfs_write_inode
,
301 .statfs
= nfs_statfs
,
302 .clear_inode
= nfs4_clear_inode
,
303 .umount_begin
= nfs_umount_begin
,
304 .show_options
= nfs_show_options
,
305 .show_stats
= nfs_show_stats
,
306 .remount_fs
= nfs_remount
,
310 static struct shrinker acl_shrinker
= {
311 .shrink
= nfs_access_cache_shrinker
,
312 .seeks
= DEFAULT_SEEKS
,
316 * Register the NFS filesystems
318 int __init
register_nfs_fs(void)
322 ret
= register_filesystem(&nfs_fs_type
);
326 ret
= nfs_register_sysctl();
330 ret
= register_filesystem(&nfs4_fs_type
);
334 register_shrinker(&acl_shrinker
);
339 nfs_unregister_sysctl();
342 unregister_filesystem(&nfs_fs_type
);
348 * Unregister the NFS filesystems
350 void __exit
unregister_nfs_fs(void)
352 unregister_shrinker(&acl_shrinker
);
354 unregister_filesystem(&nfs4_fs_type
);
356 nfs_unregister_sysctl();
357 unregister_filesystem(&nfs_fs_type
);
360 void nfs_sb_active(struct super_block
*sb
)
362 struct nfs_server
*server
= NFS_SB(sb
);
364 if (atomic_inc_return(&server
->active
) == 1)
365 atomic_inc(&sb
->s_active
);
368 void nfs_sb_deactive(struct super_block
*sb
)
370 struct nfs_server
*server
= NFS_SB(sb
);
372 if (atomic_dec_and_test(&server
->active
))
373 deactivate_super(sb
);
377 * Deliver file system statistics to userspace
379 static int nfs_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
381 struct nfs_server
*server
= NFS_SB(dentry
->d_sb
);
382 unsigned char blockbits
;
383 unsigned long blockres
;
384 struct nfs_fh
*fh
= NFS_FH(dentry
->d_inode
);
385 struct nfs_fattr fattr
;
386 struct nfs_fsstat res
= {
391 error
= server
->nfs_client
->rpc_ops
->statfs(server
, fh
, &res
);
394 buf
->f_type
= NFS_SUPER_MAGIC
;
397 * Current versions of glibc do not correctly handle the
398 * case where f_frsize != f_bsize. Eventually we want to
399 * report the value of wtmult in this field.
401 buf
->f_frsize
= dentry
->d_sb
->s_blocksize
;
404 * On most *nix systems, f_blocks, f_bfree, and f_bavail
405 * are reported in units of f_frsize. Linux hasn't had
406 * an f_frsize field in its statfs struct until recently,
407 * thus historically Linux's sys_statfs reports these
408 * fields in units of f_bsize.
410 buf
->f_bsize
= dentry
->d_sb
->s_blocksize
;
411 blockbits
= dentry
->d_sb
->s_blocksize_bits
;
412 blockres
= (1 << blockbits
) - 1;
413 buf
->f_blocks
= (res
.tbytes
+ blockres
) >> blockbits
;
414 buf
->f_bfree
= (res
.fbytes
+ blockres
) >> blockbits
;
415 buf
->f_bavail
= (res
.abytes
+ blockres
) >> blockbits
;
417 buf
->f_files
= res
.tfiles
;
418 buf
->f_ffree
= res
.afiles
;
420 buf
->f_namelen
= server
->namelen
;
425 dprintk("%s: statfs error = %d\n", __func__
, -error
);
430 * Map the security flavour number to a name
432 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour
)
434 static const struct {
435 rpc_authflavor_t flavour
;
438 { RPC_AUTH_NULL
, "null" },
439 { RPC_AUTH_UNIX
, "sys" },
440 { RPC_AUTH_GSS_KRB5
, "krb5" },
441 { RPC_AUTH_GSS_KRB5I
, "krb5i" },
442 { RPC_AUTH_GSS_KRB5P
, "krb5p" },
443 { RPC_AUTH_GSS_LKEY
, "lkey" },
444 { RPC_AUTH_GSS_LKEYI
, "lkeyi" },
445 { RPC_AUTH_GSS_LKEYP
, "lkeyp" },
446 { RPC_AUTH_GSS_SPKM
, "spkm" },
447 { RPC_AUTH_GSS_SPKMI
, "spkmi" },
448 { RPC_AUTH_GSS_SPKMP
, "spkmp" },
449 { UINT_MAX
, "unknown" }
453 for (i
= 0; sec_flavours
[i
].flavour
!= UINT_MAX
; i
++) {
454 if (sec_flavours
[i
].flavour
== flavour
)
457 return sec_flavours
[i
].str
;
460 static void nfs_show_mountd_options(struct seq_file
*m
, struct nfs_server
*nfss
,
463 struct sockaddr
*sap
= (struct sockaddr
*)&nfss
->mountd_address
;
465 switch (sap
->sa_family
) {
467 struct sockaddr_in
*sin
= (struct sockaddr_in
*)sap
;
468 seq_printf(m
, ",mountaddr=%pI4", &sin
->sin_addr
.s_addr
);
472 struct sockaddr_in6
*sin6
= (struct sockaddr_in6
*)sap
;
473 seq_printf(m
, ",mountaddr=%pI6", &sin6
->sin6_addr
);
478 seq_printf(m
, ",mountaddr=unspecified");
481 if (nfss
->mountd_version
|| showdefaults
)
482 seq_printf(m
, ",mountvers=%u", nfss
->mountd_version
);
483 if (nfss
->mountd_port
|| showdefaults
)
484 seq_printf(m
, ",mountport=%u", nfss
->mountd_port
);
486 switch (nfss
->mountd_protocol
) {
488 seq_printf(m
, ",mountproto=udp");
491 seq_printf(m
, ",mountproto=tcp");
495 seq_printf(m
, ",mountproto=auto");
500 * Describe the mount options in force on this server representation
502 static void nfs_show_mount_options(struct seq_file
*m
, struct nfs_server
*nfss
,
505 static const struct proc_nfs_info
{
510 { NFS_MOUNT_SOFT
, ",soft", ",hard" },
511 { NFS_MOUNT_INTR
, ",intr", ",nointr" },
512 { NFS_MOUNT_POSIX
, ",posix", "" },
513 { NFS_MOUNT_NOCTO
, ",nocto", "" },
514 { NFS_MOUNT_NOAC
, ",noac", "" },
515 { NFS_MOUNT_NONLM
, ",nolock", "" },
516 { NFS_MOUNT_NOACL
, ",noacl", "" },
517 { NFS_MOUNT_NORDIRPLUS
, ",nordirplus", "" },
518 { NFS_MOUNT_UNSHARED
, ",nosharecache", "" },
519 { NFS_MOUNT_NORESVPORT
, ",noresvport", "" },
522 const struct proc_nfs_info
*nfs_infop
;
523 struct nfs_client
*clp
= nfss
->nfs_client
;
524 u32 version
= clp
->rpc_ops
->version
;
526 seq_printf(m
, ",vers=%u", version
);
527 seq_printf(m
, ",rsize=%u", nfss
->rsize
);
528 seq_printf(m
, ",wsize=%u", nfss
->wsize
);
529 if (nfss
->bsize
!= 0)
530 seq_printf(m
, ",bsize=%u", nfss
->bsize
);
531 seq_printf(m
, ",namlen=%u", nfss
->namelen
);
532 if (nfss
->acregmin
!= NFS_DEF_ACREGMIN
*HZ
|| showdefaults
)
533 seq_printf(m
, ",acregmin=%u", nfss
->acregmin
/HZ
);
534 if (nfss
->acregmax
!= NFS_DEF_ACREGMAX
*HZ
|| showdefaults
)
535 seq_printf(m
, ",acregmax=%u", nfss
->acregmax
/HZ
);
536 if (nfss
->acdirmin
!= NFS_DEF_ACDIRMIN
*HZ
|| showdefaults
)
537 seq_printf(m
, ",acdirmin=%u", nfss
->acdirmin
/HZ
);
538 if (nfss
->acdirmax
!= NFS_DEF_ACDIRMAX
*HZ
|| showdefaults
)
539 seq_printf(m
, ",acdirmax=%u", nfss
->acdirmax
/HZ
);
540 for (nfs_infop
= nfs_info
; nfs_infop
->flag
; nfs_infop
++) {
541 if (nfss
->flags
& nfs_infop
->flag
)
542 seq_puts(m
, nfs_infop
->str
);
544 seq_puts(m
, nfs_infop
->nostr
);
546 seq_printf(m
, ",proto=%s",
547 rpc_peeraddr2str(nfss
->client
, RPC_DISPLAY_PROTO
));
549 if (nfss
->port
!= NFS_PORT
)
550 seq_printf(m
, ",port=%u", nfss
->port
);
553 seq_printf(m
, ",port=%u", nfss
->port
);
555 seq_printf(m
, ",timeo=%lu", 10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
);
556 seq_printf(m
, ",retrans=%u", nfss
->client
->cl_timeout
->to_retries
);
557 seq_printf(m
, ",sec=%s", nfs_pseudoflavour_to_name(nfss
->client
->cl_auth
->au_flavor
));
560 nfs_show_mountd_options(m
, nfss
, showdefaults
);
563 if (clp
->rpc_ops
->version
== 4)
564 seq_printf(m
, ",clientaddr=%s", clp
->cl_ipaddr
);
569 * Describe the mount options on this VFS mountpoint
571 static int nfs_show_options(struct seq_file
*m
, struct vfsmount
*mnt
)
573 struct nfs_server
*nfss
= NFS_SB(mnt
->mnt_sb
);
575 nfs_show_mount_options(m
, nfss
, 0);
577 seq_printf(m
, ",addr=%s",
578 rpc_peeraddr2str(nfss
->nfs_client
->cl_rpcclient
,
585 * Present statistical information for this VFS mountpoint
587 static int nfs_show_stats(struct seq_file
*m
, struct vfsmount
*mnt
)
590 struct nfs_server
*nfss
= NFS_SB(mnt
->mnt_sb
);
591 struct rpc_auth
*auth
= nfss
->client
->cl_auth
;
592 struct nfs_iostats totals
= { };
594 seq_printf(m
, "statvers=%s", NFS_IOSTAT_VERS
);
597 * Display all mount option settings
599 seq_printf(m
, "\n\topts:\t");
600 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_RDONLY
? "ro" : "rw");
601 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_SYNCHRONOUS
? ",sync" : "");
602 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_NOATIME
? ",noatime" : "");
603 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_NODIRATIME
? ",nodiratime" : "");
604 nfs_show_mount_options(m
, nfss
, 1);
606 seq_printf(m
, "\n\tage:\t%lu", (jiffies
- nfss
->mount_time
) / HZ
);
608 seq_printf(m
, "\n\tcaps:\t");
609 seq_printf(m
, "caps=0x%x", nfss
->caps
);
610 seq_printf(m
, ",wtmult=%u", nfss
->wtmult
);
611 seq_printf(m
, ",dtsize=%u", nfss
->dtsize
);
612 seq_printf(m
, ",bsize=%u", nfss
->bsize
);
613 seq_printf(m
, ",namlen=%u", nfss
->namelen
);
616 if (nfss
->nfs_client
->rpc_ops
->version
== 4) {
617 seq_printf(m
, "\n\tnfsv4:\t");
618 seq_printf(m
, "bm0=0x%x", nfss
->attr_bitmask
[0]);
619 seq_printf(m
, ",bm1=0x%x", nfss
->attr_bitmask
[1]);
620 seq_printf(m
, ",acl=0x%x", nfss
->acl_bitmask
);
625 * Display security flavor in effect for this mount
627 seq_printf(m
, "\n\tsec:\tflavor=%u", auth
->au_ops
->au_flavor
);
629 seq_printf(m
, ",pseudoflavor=%u", auth
->au_flavor
);
632 * Display superblock I/O counters
634 for_each_possible_cpu(cpu
) {
635 struct nfs_iostats
*stats
;
638 stats
= per_cpu_ptr(nfss
->io_stats
, cpu
);
640 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
641 totals
.events
[i
] += stats
->events
[i
];
642 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
643 totals
.bytes
[i
] += stats
->bytes
[i
];
648 seq_printf(m
, "\n\tevents:\t");
649 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
650 seq_printf(m
, "%lu ", totals
.events
[i
]);
651 seq_printf(m
, "\n\tbytes:\t");
652 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
653 seq_printf(m
, "%Lu ", totals
.bytes
[i
]);
656 rpc_print_iostats(m
, nfss
->client
);
662 * Begin unmount by attempting to remove all automounted mountpoints we added
663 * in response to xdev traversals and referrals
665 static void nfs_umount_begin(struct super_block
*sb
)
667 struct nfs_server
*server
= NFS_SB(sb
);
668 struct rpc_clnt
*rpc
;
670 /* -EIO all pending I/O */
671 rpc
= server
->client_acl
;
673 rpc_killall_tasks(rpc
);
674 rpc
= server
->client
;
676 rpc_killall_tasks(rpc
);
680 * Sanity-check a server address provided by the mount command.
682 * Address family must be initialized, and address must not be
683 * the ANY address for that family.
685 static int nfs_verify_server_address(struct sockaddr
*addr
)
687 switch (addr
->sa_family
) {
689 struct sockaddr_in
*sa
= (struct sockaddr_in
*)addr
;
690 return sa
->sin_addr
.s_addr
!= htonl(INADDR_ANY
);
693 struct in6_addr
*sa
= &((struct sockaddr_in6
*)addr
)->sin6_addr
;
694 return !ipv6_addr_any(sa
);
701 static void nfs_parse_ipv4_address(char *string
, size_t str_len
,
702 struct sockaddr
*sap
, size_t *addr_len
)
704 struct sockaddr_in
*sin
= (struct sockaddr_in
*)sap
;
705 u8
*addr
= (u8
*)&sin
->sin_addr
.s_addr
;
707 if (str_len
<= INET_ADDRSTRLEN
) {
708 dfprintk(MOUNT
, "NFS: parsing IPv4 address %*s\n",
709 (int)str_len
, string
);
711 sin
->sin_family
= AF_INET
;
712 *addr_len
= sizeof(*sin
);
713 if (in4_pton(string
, str_len
, addr
, '\0', NULL
))
717 sap
->sa_family
= AF_UNSPEC
;
721 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
722 static int nfs_parse_ipv6_scope_id(const char *string
, const size_t str_len
,
724 struct sockaddr_in6
*sin6
)
729 if ((string
+ str_len
) == delim
)
732 if (*delim
!= IPV6_SCOPE_DELIMITER
)
735 if (!(ipv6_addr_type(&sin6
->sin6_addr
) & IPV6_ADDR_LINKLOCAL
))
738 len
= (string
+ str_len
) - delim
- 1;
739 p
= kstrndup(delim
+ 1, len
, GFP_KERNEL
);
741 unsigned long scope_id
= 0;
742 struct net_device
*dev
;
744 dev
= dev_get_by_name(&init_net
, p
);
746 scope_id
= dev
->ifindex
;
749 if (strict_strtoul(p
, 10, &scope_id
) == 0) {
757 sin6
->sin6_scope_id
= scope_id
;
758 dfprintk(MOUNT
, "NFS: IPv6 scope ID = %lu\n", scope_id
);
765 static void nfs_parse_ipv6_address(char *string
, size_t str_len
,
766 struct sockaddr
*sap
, size_t *addr_len
)
768 struct sockaddr_in6
*sin6
= (struct sockaddr_in6
*)sap
;
769 u8
*addr
= (u8
*)&sin6
->sin6_addr
.in6_u
;
772 if (str_len
<= INET6_ADDRSTRLEN
) {
773 dfprintk(MOUNT
, "NFS: parsing IPv6 address %*s\n",
774 (int)str_len
, string
);
776 sin6
->sin6_family
= AF_INET6
;
777 *addr_len
= sizeof(*sin6
);
778 if (in6_pton(string
, str_len
, addr
,
779 IPV6_SCOPE_DELIMITER
, &delim
) != 0) {
780 if (nfs_parse_ipv6_scope_id(string
, str_len
,
786 sap
->sa_family
= AF_UNSPEC
;
790 static void nfs_parse_ipv6_address(char *string
, size_t str_len
,
791 struct sockaddr
*sap
, size_t *addr_len
)
793 sap
->sa_family
= AF_UNSPEC
;
799 * Construct a sockaddr based on the contents of a string that contains
800 * an IP address in presentation format.
802 * If there is a problem constructing the new sockaddr, set the address
803 * family to AF_UNSPEC.
805 void nfs_parse_ip_address(char *string
, size_t str_len
,
806 struct sockaddr
*sap
, size_t *addr_len
)
808 unsigned int i
, colons
;
811 for (i
= 0; i
< str_len
; i
++)
812 if (string
[i
] == ':')
816 nfs_parse_ipv6_address(string
, str_len
, sap
, addr_len
);
818 nfs_parse_ipv4_address(string
, str_len
, sap
, addr_len
);
822 * Sanity check the NFS transport protocol.
825 static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data
*mnt
)
827 switch (mnt
->nfs_server
.protocol
) {
828 case XPRT_TRANSPORT_UDP
:
829 case XPRT_TRANSPORT_TCP
:
830 case XPRT_TRANSPORT_RDMA
:
833 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
838 * For text based NFSv2/v3 mounts, the mount protocol transport default
839 * settings should depend upon the specified NFS transport.
841 static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data
*mnt
)
843 nfs_validate_transport_protocol(mnt
);
845 if (mnt
->mount_server
.protocol
== XPRT_TRANSPORT_UDP
||
846 mnt
->mount_server
.protocol
== XPRT_TRANSPORT_TCP
)
848 switch (mnt
->nfs_server
.protocol
) {
849 case XPRT_TRANSPORT_UDP
:
850 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_UDP
;
852 case XPRT_TRANSPORT_TCP
:
853 case XPRT_TRANSPORT_RDMA
:
854 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_TCP
;
859 * Parse the value of the 'sec=' option.
861 * The flavor_len setting is for v4 mounts.
863 static int nfs_parse_security_flavors(char *value
,
864 struct nfs_parsed_mount_data
*mnt
)
866 substring_t args
[MAX_OPT_ARGS
];
868 dfprintk(MOUNT
, "NFS: parsing sec=%s option\n", value
);
870 switch (match_token(value
, nfs_secflavor_tokens
, args
)) {
872 mnt
->auth_flavor_len
= 0;
873 mnt
->auth_flavors
[0] = RPC_AUTH_NULL
;
876 mnt
->auth_flavor_len
= 0;
877 mnt
->auth_flavors
[0] = RPC_AUTH_UNIX
;
880 mnt
->auth_flavor_len
= 1;
881 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5
;
884 mnt
->auth_flavor_len
= 1;
885 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5I
;
888 mnt
->auth_flavor_len
= 1;
889 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5P
;
892 mnt
->auth_flavor_len
= 1;
893 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEY
;
896 mnt
->auth_flavor_len
= 1;
897 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEYI
;
900 mnt
->auth_flavor_len
= 1;
901 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEYP
;
904 mnt
->auth_flavor_len
= 1;
905 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKM
;
908 mnt
->auth_flavor_len
= 1;
909 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKMI
;
912 mnt
->auth_flavor_len
= 1;
913 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKMP
;
922 static void nfs_parse_invalid_value(const char *option
)
924 dfprintk(MOUNT
, "NFS: bad value specified for %s option\n", option
);
928 * Error-check and convert a string of mount options from user space into
929 * a data structure. The whole mount string is processed; bad options are
930 * skipped as they are encountered. If there were no errors, return 1;
931 * otherwise return 0 (zero).
933 static int nfs_parse_mount_options(char *raw
,
934 struct nfs_parsed_mount_data
*mnt
)
936 char *p
, *string
, *secdata
;
937 int rc
, sloppy
= 0, errors
= 0;
940 dfprintk(MOUNT
, "NFS: mount options string was NULL.\n");
943 dfprintk(MOUNT
, "NFS: nfs mount opts='%s'\n", raw
);
945 secdata
= alloc_secdata();
949 rc
= security_sb_copy_data(raw
, secdata
);
951 goto out_security_failure
;
953 rc
= security_sb_parse_opts_str(secdata
, &mnt
->lsm_opts
);
955 goto out_security_failure
;
957 free_secdata(secdata
);
959 while ((p
= strsep(&raw
, ",")) != NULL
) {
960 substring_t args
[MAX_OPT_ARGS
];
966 dfprintk(MOUNT
, "NFS: parsing nfs mount option '%s'\n", p
);
968 token
= match_token(p
, nfs_mount_option_tokens
, args
);
972 * boolean options: foo/nofoo
975 mnt
->flags
|= NFS_MOUNT_SOFT
;
978 mnt
->flags
&= ~NFS_MOUNT_SOFT
;
981 mnt
->flags
|= NFS_MOUNT_POSIX
;
984 mnt
->flags
&= ~NFS_MOUNT_POSIX
;
987 mnt
->flags
&= ~NFS_MOUNT_NOCTO
;
990 mnt
->flags
|= NFS_MOUNT_NOCTO
;
993 mnt
->flags
&= ~NFS_MOUNT_NOAC
;
996 mnt
->flags
|= NFS_MOUNT_NOAC
;
999 mnt
->flags
&= ~NFS_MOUNT_NONLM
;
1002 mnt
->flags
|= NFS_MOUNT_NONLM
;
1005 mnt
->flags
&= ~NFS_MOUNT_VER3
;
1008 mnt
->flags
|= NFS_MOUNT_VER3
;
1011 mnt
->flags
&= ~NFS_MOUNT_TCP
;
1012 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1015 mnt
->flags
|= NFS_MOUNT_TCP
;
1016 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1019 mnt
->flags
|= NFS_MOUNT_TCP
; /* for side protocols */
1020 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_RDMA
;
1023 mnt
->flags
&= ~NFS_MOUNT_NOACL
;
1026 mnt
->flags
|= NFS_MOUNT_NOACL
;
1029 mnt
->flags
&= ~NFS_MOUNT_NORDIRPLUS
;
1031 case Opt_nordirplus
:
1032 mnt
->flags
|= NFS_MOUNT_NORDIRPLUS
;
1034 case Opt_sharecache
:
1035 mnt
->flags
&= ~NFS_MOUNT_UNSHARED
;
1037 case Opt_nosharecache
:
1038 mnt
->flags
|= NFS_MOUNT_UNSHARED
;
1041 mnt
->flags
&= ~NFS_MOUNT_NORESVPORT
;
1043 case Opt_noresvport
:
1044 mnt
->flags
|= NFS_MOUNT_NORESVPORT
;
1048 * options that take numeric values
1051 if (match_int(args
, &option
) ||
1052 option
< 0 || option
> USHORT_MAX
) {
1054 nfs_parse_invalid_value("port");
1056 mnt
->nfs_server
.port
= option
;
1059 if (match_int(args
, &option
) || option
< 0) {
1061 nfs_parse_invalid_value("rsize");
1063 mnt
->rsize
= option
;
1066 if (match_int(args
, &option
) || option
< 0) {
1068 nfs_parse_invalid_value("wsize");
1070 mnt
->wsize
= option
;
1073 if (match_int(args
, &option
) || option
< 0) {
1075 nfs_parse_invalid_value("bsize");
1077 mnt
->bsize
= option
;
1080 if (match_int(args
, &option
) || option
<= 0) {
1082 nfs_parse_invalid_value("timeo");
1084 mnt
->timeo
= option
;
1087 if (match_int(args
, &option
) || option
<= 0) {
1089 nfs_parse_invalid_value("retrans");
1091 mnt
->retrans
= option
;
1094 if (match_int(args
, &option
) || option
< 0) {
1096 nfs_parse_invalid_value("acregmin");
1098 mnt
->acregmin
= option
;
1101 if (match_int(args
, &option
) || option
< 0) {
1103 nfs_parse_invalid_value("acregmax");
1105 mnt
->acregmax
= option
;
1108 if (match_int(args
, &option
) || option
< 0) {
1110 nfs_parse_invalid_value("acdirmin");
1112 mnt
->acdirmin
= option
;
1115 if (match_int(args
, &option
) || option
< 0) {
1117 nfs_parse_invalid_value("acdirmax");
1119 mnt
->acdirmax
= option
;
1122 if (match_int(args
, &option
) || option
< 0) {
1124 nfs_parse_invalid_value("actimeo");
1126 mnt
->acregmin
= mnt
->acregmax
=
1127 mnt
->acdirmin
= mnt
->acdirmax
= option
;
1130 if (match_int(args
, &option
) || option
< 0) {
1132 nfs_parse_invalid_value("namlen");
1134 mnt
->namlen
= option
;
1137 if (match_int(args
, &option
) ||
1138 option
< 0 || option
> USHORT_MAX
) {
1140 nfs_parse_invalid_value("mountport");
1142 mnt
->mount_server
.port
= option
;
1145 if (match_int(args
, &option
) ||
1146 option
< NFS_MNT_VERSION
||
1147 option
> NFS_MNT3_VERSION
) {
1149 nfs_parse_invalid_value("mountvers");
1151 mnt
->mount_server
.version
= option
;
1154 if (match_int(args
, &option
)) {
1156 nfs_parse_invalid_value("nfsvers");
1161 mnt
->flags
&= ~NFS_MOUNT_VER3
;
1164 mnt
->flags
|= NFS_MOUNT_VER3
;
1168 nfs_parse_invalid_value("nfsvers");
1173 * options that take text values
1176 string
= match_strdup(args
);
1179 rc
= nfs_parse_security_flavors(string
, mnt
);
1183 dfprintk(MOUNT
, "NFS: unrecognized "
1184 "security flavor\n");
1188 string
= match_strdup(args
);
1191 token
= match_token(string
,
1192 nfs_xprt_protocol_tokens
, args
);
1197 mnt
->flags
&= ~NFS_MOUNT_TCP
;
1198 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1201 mnt
->flags
|= NFS_MOUNT_TCP
;
1202 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1205 /* vector side protocols to TCP */
1206 mnt
->flags
|= NFS_MOUNT_TCP
;
1207 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_RDMA
;
1211 dfprintk(MOUNT
, "NFS: unrecognized "
1212 "transport protocol\n");
1215 case Opt_mountproto
:
1216 string
= match_strdup(args
);
1219 token
= match_token(string
,
1220 nfs_xprt_protocol_tokens
, args
);
1225 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_UDP
;
1228 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_TCP
;
1230 case Opt_xprt_rdma
: /* not used for side protocols */
1233 dfprintk(MOUNT
, "NFS: unrecognized "
1234 "transport protocol\n");
1238 string
= match_strdup(args
);
1241 nfs_parse_ip_address(string
, strlen(string
),
1243 &mnt
->nfs_server
.address
,
1244 &mnt
->nfs_server
.addrlen
);
1247 case Opt_clientaddr
:
1248 string
= match_strdup(args
);
1251 kfree(mnt
->client_address
);
1252 mnt
->client_address
= string
;
1255 string
= match_strdup(args
);
1258 kfree(mnt
->mount_server
.hostname
);
1259 mnt
->mount_server
.hostname
= string
;
1262 string
= match_strdup(args
);
1265 nfs_parse_ip_address(string
, strlen(string
),
1267 &mnt
->mount_server
.address
,
1268 &mnt
->mount_server
.addrlen
);
1271 case Opt_lookupcache
:
1272 string
= match_strdup(args
);
1275 token
= match_token(string
,
1276 nfs_lookupcache_tokens
, args
);
1279 case Opt_lookupcache_all
:
1280 mnt
->flags
&= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG
|NFS_MOUNT_LOOKUP_CACHE_NONE
);
1282 case Opt_lookupcache_positive
:
1283 mnt
->flags
&= ~NFS_MOUNT_LOOKUP_CACHE_NONE
;
1284 mnt
->flags
|= NFS_MOUNT_LOOKUP_CACHE_NONEG
;
1286 case Opt_lookupcache_none
:
1287 mnt
->flags
|= NFS_MOUNT_LOOKUP_CACHE_NONEG
|NFS_MOUNT_LOOKUP_CACHE_NONE
;
1291 dfprintk(MOUNT
, "NFS: invalid "
1292 "lookupcache argument\n");
1301 dfprintk(MOUNT
, "NFS: relaxing parsing rules\n");
1304 case Opt_deprecated
:
1305 dfprintk(MOUNT
, "NFS: ignoring mount option "
1311 dfprintk(MOUNT
, "NFS: unrecognized mount option "
1317 dfprintk(MOUNT
, "NFS: parsing encountered %d error%s\n",
1318 errors
, (errors
== 1 ? "" : "s"));
1325 printk(KERN_INFO
"NFS: not enough memory to parse option\n");
1327 out_security_failure
:
1328 free_secdata(secdata
);
1329 printk(KERN_INFO
"NFS: security options invalid: %d\n", rc
);
1334 * Use the remote server's MOUNT service to request the NFS file handle
1335 * corresponding to the provided path.
1337 static int nfs_try_mount(struct nfs_parsed_mount_data
*args
,
1338 struct nfs_fh
*root_fh
)
1340 struct nfs_mount_request request
= {
1341 .sap
= (struct sockaddr
*)
1342 &args
->mount_server
.address
,
1343 .dirpath
= args
->nfs_server
.export_path
,
1344 .protocol
= args
->mount_server
.protocol
,
1346 .noresvport
= args
->flags
& NFS_MOUNT_NORESVPORT
,
1350 if (args
->mount_server
.version
== 0) {
1351 if (args
->flags
& NFS_MOUNT_VER3
)
1352 args
->mount_server
.version
= NFS_MNT3_VERSION
;
1354 args
->mount_server
.version
= NFS_MNT_VERSION
;
1356 request
.version
= args
->mount_server
.version
;
1358 if (args
->mount_server
.hostname
)
1359 request
.hostname
= args
->mount_server
.hostname
;
1361 request
.hostname
= args
->nfs_server
.hostname
;
1364 * Construct the mount server's address.
1366 if (args
->mount_server
.address
.ss_family
== AF_UNSPEC
) {
1367 memcpy(request
.sap
, &args
->nfs_server
.address
,
1368 args
->nfs_server
.addrlen
);
1369 args
->mount_server
.addrlen
= args
->nfs_server
.addrlen
;
1371 request
.salen
= args
->mount_server
.addrlen
;
1374 * autobind will be used if mount_server.port == 0
1376 nfs_set_port(request
.sap
, args
->mount_server
.port
);
1379 * Now ask the mount server to map our export path
1382 status
= nfs_mount(&request
);
1386 dfprintk(MOUNT
, "NFS: unable to mount server %s, error %d\n",
1387 request
.hostname
, status
);
1391 static int nfs_parse_simple_hostname(const char *dev_name
,
1392 char **hostname
, size_t maxnamlen
,
1393 char **export_path
, size_t maxpathlen
)
1396 char *colon
, *comma
;
1398 colon
= strchr(dev_name
, ':');
1400 goto out_bad_devname
;
1402 len
= colon
- dev_name
;
1403 if (len
> maxnamlen
)
1406 /* N.B. caller will free nfs_server.hostname in all cases */
1407 *hostname
= kstrndup(dev_name
, len
, GFP_KERNEL
);
1411 /* kill possible hostname list: not supported */
1412 comma
= strchr(*hostname
, ',');
1413 if (comma
!= NULL
) {
1414 if (comma
== *hostname
)
1415 goto out_bad_devname
;
1420 len
= strlen(colon
);
1421 if (len
> maxpathlen
)
1423 *export_path
= kstrndup(colon
, len
, GFP_KERNEL
);
1427 dfprintk(MOUNT
, "NFS: MNTPATH: '%s'\n", *export_path
);
1431 dfprintk(MOUNT
, "NFS: device name not in host:path format\n");
1435 dfprintk(MOUNT
, "NFS: not enough memory to parse device name\n");
1439 dfprintk(MOUNT
, "NFS: server hostname too long\n");
1440 return -ENAMETOOLONG
;
1443 dfprintk(MOUNT
, "NFS: export pathname too long\n");
1444 return -ENAMETOOLONG
;
1448 * Hostname has square brackets around it because it contains one or
1449 * more colons. We look for the first closing square bracket, and a
1450 * colon must follow it.
1452 static int nfs_parse_protected_hostname(const char *dev_name
,
1453 char **hostname
, size_t maxnamlen
,
1454 char **export_path
, size_t maxpathlen
)
1459 start
= (char *)(dev_name
+ 1);
1461 end
= strchr(start
, ']');
1463 goto out_bad_devname
;
1464 if (*(end
+ 1) != ':')
1465 goto out_bad_devname
;
1468 if (len
> maxnamlen
)
1471 /* N.B. caller will free nfs_server.hostname in all cases */
1472 *hostname
= kstrndup(start
, len
, GFP_KERNEL
);
1473 if (*hostname
== NULL
)
1478 if (len
> maxpathlen
)
1480 *export_path
= kstrndup(end
, len
, GFP_KERNEL
);
1487 dfprintk(MOUNT
, "NFS: device name not in host:path format\n");
1491 dfprintk(MOUNT
, "NFS: not enough memory to parse device name\n");
1495 dfprintk(MOUNT
, "NFS: server hostname too long\n");
1496 return -ENAMETOOLONG
;
1499 dfprintk(MOUNT
, "NFS: export pathname too long\n");
1500 return -ENAMETOOLONG
;
1504 * Split "dev_name" into "hostname:export_path".
1506 * The leftmost colon demarks the split between the server's hostname
1507 * and the export path. If the hostname starts with a left square
1508 * bracket, then it may contain colons.
1510 * Note: caller frees hostname and export path, even on error.
1512 static int nfs_parse_devname(const char *dev_name
,
1513 char **hostname
, size_t maxnamlen
,
1514 char **export_path
, size_t maxpathlen
)
1516 if (*dev_name
== '[')
1517 return nfs_parse_protected_hostname(dev_name
,
1518 hostname
, maxnamlen
,
1519 export_path
, maxpathlen
);
1521 return nfs_parse_simple_hostname(dev_name
,
1522 hostname
, maxnamlen
,
1523 export_path
, maxpathlen
);
1527 * Validate the NFS2/NFS3 mount data
1528 * - fills in the mount root filehandle
1530 * For option strings, user space handles the following behaviors:
1532 * + DNS: mapping server host name to IP address ("addr=" option)
1534 * + failure mode: how to behave if a mount request can't be handled
1535 * immediately ("fg/bg" option)
1537 * + retry: how often to retry a mount request ("retry=" option)
1539 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1540 * mountproto=tcp after mountproto=udp, and so on
1542 static int nfs_validate_mount_data(void *options
,
1543 struct nfs_parsed_mount_data
*args
,
1544 struct nfs_fh
*mntfh
,
1545 const char *dev_name
)
1547 struct nfs_mount_data
*data
= (struct nfs_mount_data
*)options
;
1552 args
->flags
= (NFS_MOUNT_VER3
| NFS_MOUNT_TCP
);
1553 args
->rsize
= NFS_MAX_FILE_IO_SIZE
;
1554 args
->wsize
= NFS_MAX_FILE_IO_SIZE
;
1555 args
->acregmin
= NFS_DEF_ACREGMIN
;
1556 args
->acregmax
= NFS_DEF_ACREGMAX
;
1557 args
->acdirmin
= NFS_DEF_ACDIRMIN
;
1558 args
->acdirmax
= NFS_DEF_ACDIRMAX
;
1559 args
->mount_server
.port
= 0; /* autobind unless user sets port */
1560 args
->nfs_server
.port
= 0; /* autobind unless user sets port */
1561 args
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1562 args
->auth_flavors
[0] = RPC_AUTH_UNIX
;
1564 switch (data
->version
) {
1570 if (data
->flags
& NFS_MOUNT_VER3
)
1572 data
->root
.size
= NFS2_FHSIZE
;
1573 memcpy(data
->root
.data
, data
->old_root
.data
, NFS2_FHSIZE
);
1575 if (data
->flags
& NFS_MOUNT_SECFLAVOUR
)
1578 memset(data
->context
, 0, sizeof(data
->context
));
1580 if (data
->flags
& NFS_MOUNT_VER3
) {
1581 if (data
->root
.size
> NFS3_FHSIZE
|| data
->root
.size
== 0)
1582 goto out_invalid_fh
;
1583 mntfh
->size
= data
->root
.size
;
1585 mntfh
->size
= NFS2_FHSIZE
;
1588 memcpy(mntfh
->data
, data
->root
.data
, mntfh
->size
);
1589 if (mntfh
->size
< sizeof(mntfh
->data
))
1590 memset(mntfh
->data
+ mntfh
->size
, 0,
1591 sizeof(mntfh
->data
) - mntfh
->size
);
1594 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1597 args
->flags
= data
->flags
& NFS_MOUNT_FLAGMASK
;
1598 args
->rsize
= data
->rsize
;
1599 args
->wsize
= data
->wsize
;
1600 args
->timeo
= data
->timeo
;
1601 args
->retrans
= data
->retrans
;
1602 args
->acregmin
= data
->acregmin
;
1603 args
->acregmax
= data
->acregmax
;
1604 args
->acdirmin
= data
->acdirmin
;
1605 args
->acdirmax
= data
->acdirmax
;
1607 memcpy(&args
->nfs_server
.address
, &data
->addr
,
1608 sizeof(data
->addr
));
1609 args
->nfs_server
.addrlen
= sizeof(data
->addr
);
1610 if (!nfs_verify_server_address((struct sockaddr
*)
1611 &args
->nfs_server
.address
))
1612 goto out_no_address
;
1614 if (!(data
->flags
& NFS_MOUNT_TCP
))
1615 args
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1616 /* N.B. caller will free nfs_server.hostname in all cases */
1617 args
->nfs_server
.hostname
= kstrdup(data
->hostname
, GFP_KERNEL
);
1618 args
->namlen
= data
->namlen
;
1619 args
->bsize
= data
->bsize
;
1621 if (data
->flags
& NFS_MOUNT_SECFLAVOUR
)
1622 args
->auth_flavors
[0] = data
->pseudoflavor
;
1623 if (!args
->nfs_server
.hostname
)
1627 * The legacy version 6 binary mount data from userspace has a
1628 * field used only to transport selinux information into the
1629 * the kernel. To continue to support that functionality we
1630 * have a touch of selinux knowledge here in the NFS code. The
1631 * userspace code converted context=blah to just blah so we are
1632 * converting back to the full string selinux understands.
1634 if (data
->context
[0]){
1635 #ifdef CONFIG_SECURITY_SELINUX
1637 char *opts_str
= kmalloc(sizeof(data
->context
) + 8, GFP_KERNEL
);
1640 strcpy(opts_str
, "context=");
1641 data
->context
[NFS_MAX_CONTEXT_LEN
] = '\0';
1642 strcat(opts_str
, &data
->context
[0]);
1643 rc
= security_sb_parse_opts_str(opts_str
, &args
->lsm_opts
);
1656 if (nfs_parse_mount_options((char *)options
, args
) == 0)
1659 if (!nfs_verify_server_address((struct sockaddr
*)
1660 &args
->nfs_server
.address
))
1661 goto out_no_address
;
1663 nfs_set_port((struct sockaddr
*)&args
->nfs_server
.address
,
1664 args
->nfs_server
.port
);
1666 nfs_set_mount_transport_protocol(args
);
1668 status
= nfs_parse_devname(dev_name
,
1669 &args
->nfs_server
.hostname
,
1671 &args
->nfs_server
.export_path
,
1674 status
= nfs_try_mount(args
, mntfh
);
1676 kfree(args
->nfs_server
.export_path
);
1677 args
->nfs_server
.export_path
= NULL
;
1686 #ifndef CONFIG_NFS_V3
1687 if (args
->flags
& NFS_MOUNT_VER3
)
1688 goto out_v3_not_compiled
;
1689 #endif /* !CONFIG_NFS_V3 */
1694 dfprintk(MOUNT
, "NFS: mount program didn't pass any mount data\n");
1698 dfprintk(MOUNT
, "NFS: nfs_mount_data version %d does not support v3\n",
1703 dfprintk(MOUNT
, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1706 #ifndef CONFIG_NFS_V3
1707 out_v3_not_compiled
:
1708 dfprintk(MOUNT
, "NFS: NFSv3 is not compiled into kernel\n");
1709 return -EPROTONOSUPPORT
;
1710 #endif /* !CONFIG_NFS_V3 */
1713 dfprintk(MOUNT
, "NFS: not enough memory to handle mount options\n");
1717 dfprintk(MOUNT
, "NFS: mount program didn't pass remote address\n");
1721 dfprintk(MOUNT
, "NFS: invalid root filehandle\n");
1726 nfs_compare_remount_data(struct nfs_server
*nfss
,
1727 struct nfs_parsed_mount_data
*data
)
1729 if (data
->flags
!= nfss
->flags
||
1730 data
->rsize
!= nfss
->rsize
||
1731 data
->wsize
!= nfss
->wsize
||
1732 data
->retrans
!= nfss
->client
->cl_timeout
->to_retries
||
1733 data
->auth_flavors
[0] != nfss
->client
->cl_auth
->au_flavor
||
1734 data
->acregmin
!= nfss
->acregmin
/ HZ
||
1735 data
->acregmax
!= nfss
->acregmax
/ HZ
||
1736 data
->acdirmin
!= nfss
->acdirmin
/ HZ
||
1737 data
->acdirmax
!= nfss
->acdirmax
/ HZ
||
1738 data
->timeo
!= (10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
) ||
1739 data
->nfs_server
.addrlen
!= nfss
->nfs_client
->cl_addrlen
||
1740 memcmp(&data
->nfs_server
.address
, &nfss
->nfs_client
->cl_addr
,
1741 data
->nfs_server
.addrlen
) != 0)
1748 nfs_remount(struct super_block
*sb
, int *flags
, char *raw_data
)
1751 struct nfs_server
*nfss
= sb
->s_fs_info
;
1752 struct nfs_parsed_mount_data
*data
;
1753 struct nfs_mount_data
*options
= (struct nfs_mount_data
*)raw_data
;
1754 struct nfs4_mount_data
*options4
= (struct nfs4_mount_data
*)raw_data
;
1755 u32 nfsvers
= nfss
->nfs_client
->rpc_ops
->version
;
1758 * Userspace mount programs that send binary options generally send
1759 * them populated with default values. We have no way to know which
1760 * ones were explicitly specified. Fall back to legacy behavior and
1761 * just return success.
1763 if ((nfsvers
== 4 && (!options4
|| options4
->version
== 1)) ||
1764 (nfsvers
<= 3 && (!options
|| (options
->version
>= 1 &&
1765 options
->version
<= 6))))
1768 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
1772 /* fill out struct with values from existing mount */
1773 data
->flags
= nfss
->flags
;
1774 data
->rsize
= nfss
->rsize
;
1775 data
->wsize
= nfss
->wsize
;
1776 data
->retrans
= nfss
->client
->cl_timeout
->to_retries
;
1777 data
->auth_flavors
[0] = nfss
->client
->cl_auth
->au_flavor
;
1778 data
->acregmin
= nfss
->acregmin
/ HZ
;
1779 data
->acregmax
= nfss
->acregmax
/ HZ
;
1780 data
->acdirmin
= nfss
->acdirmin
/ HZ
;
1781 data
->acdirmax
= nfss
->acdirmax
/ HZ
;
1782 data
->timeo
= 10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
;
1783 data
->nfs_server
.addrlen
= nfss
->nfs_client
->cl_addrlen
;
1784 memcpy(&data
->nfs_server
.address
, &nfss
->nfs_client
->cl_addr
,
1785 data
->nfs_server
.addrlen
);
1787 /* overwrite those values with any that were specified */
1788 error
= nfs_parse_mount_options((char *)options
, data
);
1792 /* compare new mount options with old ones */
1793 error
= nfs_compare_remount_data(nfss
, data
);
1800 * Initialise the common bits of the superblock
1802 static inline void nfs_initialise_sb(struct super_block
*sb
)
1804 struct nfs_server
*server
= NFS_SB(sb
);
1806 sb
->s_magic
= NFS_SUPER_MAGIC
;
1808 /* We probably want something more informative here */
1809 snprintf(sb
->s_id
, sizeof(sb
->s_id
),
1810 "%x:%x", MAJOR(sb
->s_dev
), MINOR(sb
->s_dev
));
1812 if (sb
->s_blocksize
== 0)
1813 sb
->s_blocksize
= nfs_block_bits(server
->wsize
,
1814 &sb
->s_blocksize_bits
);
1816 if (server
->flags
& NFS_MOUNT_NOAC
)
1817 sb
->s_flags
|= MS_SYNCHRONOUS
;
1819 nfs_super_set_maxbytes(sb
, server
->maxfilesize
);
1823 * Finish setting up an NFS2/3 superblock
1825 static void nfs_fill_super(struct super_block
*sb
,
1826 struct nfs_parsed_mount_data
*data
)
1828 struct nfs_server
*server
= NFS_SB(sb
);
1830 sb
->s_blocksize_bits
= 0;
1831 sb
->s_blocksize
= 0;
1833 sb
->s_blocksize
= nfs_block_size(data
->bsize
, &sb
->s_blocksize_bits
);
1835 if (server
->flags
& NFS_MOUNT_VER3
) {
1836 /* The VFS shouldn't apply the umask to mode bits. We will do
1837 * so ourselves when necessary.
1839 sb
->s_flags
|= MS_POSIXACL
;
1840 sb
->s_time_gran
= 1;
1843 sb
->s_op
= &nfs_sops
;
1844 nfs_initialise_sb(sb
);
1848 * Finish setting up a cloned NFS2/3 superblock
1850 static void nfs_clone_super(struct super_block
*sb
,
1851 const struct super_block
*old_sb
)
1853 struct nfs_server
*server
= NFS_SB(sb
);
1855 sb
->s_blocksize_bits
= old_sb
->s_blocksize_bits
;
1856 sb
->s_blocksize
= old_sb
->s_blocksize
;
1857 sb
->s_maxbytes
= old_sb
->s_maxbytes
;
1859 if (server
->flags
& NFS_MOUNT_VER3
) {
1860 /* The VFS shouldn't apply the umask to mode bits. We will do
1861 * so ourselves when necessary.
1863 sb
->s_flags
|= MS_POSIXACL
;
1864 sb
->s_time_gran
= 1;
1867 sb
->s_op
= old_sb
->s_op
;
1868 nfs_initialise_sb(sb
);
1871 #define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
1873 static int nfs_compare_mount_options(const struct super_block
*s
, const struct nfs_server
*b
, int flags
)
1875 const struct nfs_server
*a
= s
->s_fs_info
;
1876 const struct rpc_clnt
*clnt_a
= a
->client
;
1877 const struct rpc_clnt
*clnt_b
= b
->client
;
1879 if ((s
->s_flags
& NFS_MS_MASK
) != (flags
& NFS_MS_MASK
))
1881 if (a
->nfs_client
!= b
->nfs_client
)
1883 if (a
->flags
!= b
->flags
)
1885 if (a
->wsize
!= b
->wsize
)
1887 if (a
->rsize
!= b
->rsize
)
1889 if (a
->acregmin
!= b
->acregmin
)
1891 if (a
->acregmax
!= b
->acregmax
)
1893 if (a
->acdirmin
!= b
->acdirmin
)
1895 if (a
->acdirmax
!= b
->acdirmax
)
1897 if (clnt_a
->cl_auth
->au_flavor
!= clnt_b
->cl_auth
->au_flavor
)
1904 struct nfs_sb_mountdata
{
1905 struct nfs_server
*server
;
1909 static int nfs_set_super(struct super_block
*s
, void *data
)
1911 struct nfs_sb_mountdata
*sb_mntdata
= data
;
1912 struct nfs_server
*server
= sb_mntdata
->server
;
1915 s
->s_flags
= sb_mntdata
->mntflags
;
1916 s
->s_fs_info
= server
;
1917 ret
= set_anon_super(s
, server
);
1919 server
->s_dev
= s
->s_dev
;
1923 static int nfs_compare_super_address(struct nfs_server
*server1
,
1924 struct nfs_server
*server2
)
1926 struct sockaddr
*sap1
, *sap2
;
1928 sap1
= (struct sockaddr
*)&server1
->nfs_client
->cl_addr
;
1929 sap2
= (struct sockaddr
*)&server2
->nfs_client
->cl_addr
;
1931 if (sap1
->sa_family
!= sap2
->sa_family
)
1934 switch (sap1
->sa_family
) {
1936 struct sockaddr_in
*sin1
= (struct sockaddr_in
*)sap1
;
1937 struct sockaddr_in
*sin2
= (struct sockaddr_in
*)sap2
;
1938 if (sin1
->sin_addr
.s_addr
!= sin2
->sin_addr
.s_addr
)
1940 if (sin1
->sin_port
!= sin2
->sin_port
)
1945 struct sockaddr_in6
*sin1
= (struct sockaddr_in6
*)sap1
;
1946 struct sockaddr_in6
*sin2
= (struct sockaddr_in6
*)sap2
;
1947 if (!ipv6_addr_equal(&sin1
->sin6_addr
, &sin2
->sin6_addr
))
1949 if (sin1
->sin6_port
!= sin2
->sin6_port
)
1960 static int nfs_compare_super(struct super_block
*sb
, void *data
)
1962 struct nfs_sb_mountdata
*sb_mntdata
= data
;
1963 struct nfs_server
*server
= sb_mntdata
->server
, *old
= NFS_SB(sb
);
1964 int mntflags
= sb_mntdata
->mntflags
;
1966 if (!nfs_compare_super_address(old
, server
))
1968 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1969 if (old
->flags
& NFS_MOUNT_UNSHARED
)
1971 if (memcmp(&old
->fsid
, &server
->fsid
, sizeof(old
->fsid
)) != 0)
1973 return nfs_compare_mount_options(sb
, server
, mntflags
);
1976 static int nfs_bdi_register(struct nfs_server
*server
)
1978 return bdi_register_dev(&server
->backing_dev_info
, server
->s_dev
);
1981 static int nfs_get_sb(struct file_system_type
*fs_type
,
1982 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
1984 struct nfs_server
*server
= NULL
;
1985 struct super_block
*s
;
1986 struct nfs_parsed_mount_data
*data
;
1987 struct nfs_fh
*mntfh
;
1988 struct dentry
*mntroot
;
1989 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
1990 struct nfs_sb_mountdata sb_mntdata
= {
1993 int error
= -ENOMEM
;
1995 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
1996 mntfh
= kzalloc(sizeof(*mntfh
), GFP_KERNEL
);
1997 if (data
== NULL
|| mntfh
== NULL
)
2000 security_init_mnt_opts(&data
->lsm_opts
);
2002 /* Validate the mount data */
2003 error
= nfs_validate_mount_data(raw_data
, data
, mntfh
, dev_name
);
2007 /* Get a volume representation */
2008 server
= nfs_create_server(data
, mntfh
);
2009 if (IS_ERR(server
)) {
2010 error
= PTR_ERR(server
);
2013 sb_mntdata
.server
= server
;
2015 if (server
->flags
& NFS_MOUNT_UNSHARED
)
2016 compare_super
= NULL
;
2018 /* Get a superblock - note that we may end up sharing one that already exists */
2019 s
= sget(fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2025 if (s
->s_fs_info
!= server
) {
2026 nfs_free_server(server
);
2029 error
= nfs_bdi_register(server
);
2031 goto error_splat_super
;
2035 /* initial superblock/root creation */
2036 nfs_fill_super(s
, data
);
2039 mntroot
= nfs_get_root(s
, mntfh
);
2040 if (IS_ERR(mntroot
)) {
2041 error
= PTR_ERR(mntroot
);
2042 goto error_splat_super
;
2045 error
= security_sb_set_mnt_opts(s
, &data
->lsm_opts
);
2047 goto error_splat_root
;
2049 s
->s_flags
|= MS_ACTIVE
;
2051 mnt
->mnt_root
= mntroot
;
2055 kfree(data
->nfs_server
.hostname
);
2056 kfree(data
->mount_server
.hostname
);
2057 security_free_mnt_opts(&data
->lsm_opts
);
2064 nfs_free_server(server
);
2070 up_write(&s
->s_umount
);
2071 deactivate_super(s
);
2076 * Destroy an NFS2/3 superblock
2078 static void nfs_kill_super(struct super_block
*s
)
2080 struct nfs_server
*server
= NFS_SB(s
);
2082 bdi_unregister(&server
->backing_dev_info
);
2084 nfs_free_server(server
);
2088 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2090 static int nfs_xdev_get_sb(struct file_system_type
*fs_type
, int flags
,
2091 const char *dev_name
, void *raw_data
,
2092 struct vfsmount
*mnt
)
2094 struct nfs_clone_mount
*data
= raw_data
;
2095 struct super_block
*s
;
2096 struct nfs_server
*server
;
2097 struct dentry
*mntroot
;
2098 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2099 struct nfs_sb_mountdata sb_mntdata
= {
2104 dprintk("--> nfs_xdev_get_sb()\n");
2106 /* create a new volume representation */
2107 server
= nfs_clone_server(NFS_SB(data
->sb
), data
->fh
, data
->fattr
);
2108 if (IS_ERR(server
)) {
2109 error
= PTR_ERR(server
);
2110 goto out_err_noserver
;
2112 sb_mntdata
.server
= server
;
2114 if (server
->flags
& NFS_MOUNT_UNSHARED
)
2115 compare_super
= NULL
;
2117 /* Get a superblock - note that we may end up sharing one that already exists */
2118 s
= sget(&nfs_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2124 if (s
->s_fs_info
!= server
) {
2125 nfs_free_server(server
);
2128 error
= nfs_bdi_register(server
);
2130 goto error_splat_super
;
2134 /* initial superblock/root creation */
2135 nfs_clone_super(s
, data
->sb
);
2138 mntroot
= nfs_get_root(s
, data
->fh
);
2139 if (IS_ERR(mntroot
)) {
2140 error
= PTR_ERR(mntroot
);
2141 goto error_splat_super
;
2143 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
2146 goto error_splat_super
;
2149 s
->s_flags
|= MS_ACTIVE
;
2151 mnt
->mnt_root
= mntroot
;
2153 /* clone any lsm security options from the parent to the new sb */
2154 security_sb_clone_mnt_opts(data
->sb
, s
);
2156 dprintk("<-- nfs_xdev_get_sb() = 0\n");
2160 nfs_free_server(server
);
2162 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error
);
2166 up_write(&s
->s_umount
);
2167 deactivate_super(s
);
2168 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error
);
2172 #ifdef CONFIG_NFS_V4
2175 * Finish setting up a cloned NFS4 superblock
2177 static void nfs4_clone_super(struct super_block
*sb
,
2178 const struct super_block
*old_sb
)
2180 sb
->s_blocksize_bits
= old_sb
->s_blocksize_bits
;
2181 sb
->s_blocksize
= old_sb
->s_blocksize
;
2182 sb
->s_maxbytes
= old_sb
->s_maxbytes
;
2183 sb
->s_time_gran
= 1;
2184 sb
->s_op
= old_sb
->s_op
;
2185 nfs_initialise_sb(sb
);
2189 * Set up an NFS4 superblock
2191 static void nfs4_fill_super(struct super_block
*sb
)
2193 sb
->s_time_gran
= 1;
2194 sb
->s_op
= &nfs4_sops
;
2195 nfs_initialise_sb(sb
);
2199 * Validate NFSv4 mount options
2201 static int nfs4_validate_mount_data(void *options
,
2202 struct nfs_parsed_mount_data
*args
,
2203 const char *dev_name
)
2205 struct sockaddr_in
*ap
;
2206 struct nfs4_mount_data
*data
= (struct nfs4_mount_data
*)options
;
2212 args
->rsize
= NFS_MAX_FILE_IO_SIZE
;
2213 args
->wsize
= NFS_MAX_FILE_IO_SIZE
;
2214 args
->acregmin
= NFS_DEF_ACREGMIN
;
2215 args
->acregmax
= NFS_DEF_ACREGMAX
;
2216 args
->acdirmin
= NFS_DEF_ACDIRMIN
;
2217 args
->acdirmax
= NFS_DEF_ACDIRMAX
;
2218 args
->nfs_server
.port
= NFS_PORT
; /* 2049 unless user set port= */
2219 args
->auth_flavors
[0] = RPC_AUTH_UNIX
;
2220 args
->auth_flavor_len
= 0;
2222 switch (data
->version
) {
2224 ap
= (struct sockaddr_in
*)&args
->nfs_server
.address
;
2225 if (data
->host_addrlen
> sizeof(args
->nfs_server
.address
))
2226 goto out_no_address
;
2227 if (data
->host_addrlen
== 0)
2228 goto out_no_address
;
2229 args
->nfs_server
.addrlen
= data
->host_addrlen
;
2230 if (copy_from_user(ap
, data
->host_addr
, data
->host_addrlen
))
2232 if (!nfs_verify_server_address((struct sockaddr
*)
2233 &args
->nfs_server
.address
))
2234 goto out_no_address
;
2236 if (data
->auth_flavourlen
) {
2237 if (data
->auth_flavourlen
> 1)
2238 goto out_inval_auth
;
2239 if (copy_from_user(&args
->auth_flavors
[0],
2240 data
->auth_flavours
,
2241 sizeof(args
->auth_flavors
[0])))
2245 c
= strndup_user(data
->hostname
.data
, NFS4_MAXNAMLEN
);
2248 args
->nfs_server
.hostname
= c
;
2250 c
= strndup_user(data
->mnt_path
.data
, NFS4_MAXPATHLEN
);
2253 args
->nfs_server
.export_path
= c
;
2254 dfprintk(MOUNT
, "NFS: MNTPATH: '%s'\n", c
);
2256 c
= strndup_user(data
->client_addr
.data
, 16);
2259 args
->client_address
= c
;
2262 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2266 args
->flags
= data
->flags
& NFS4_MOUNT_FLAGMASK
;
2267 args
->rsize
= data
->rsize
;
2268 args
->wsize
= data
->wsize
;
2269 args
->timeo
= data
->timeo
;
2270 args
->retrans
= data
->retrans
;
2271 args
->acregmin
= data
->acregmin
;
2272 args
->acregmax
= data
->acregmax
;
2273 args
->acdirmin
= data
->acdirmin
;
2274 args
->acdirmax
= data
->acdirmax
;
2275 args
->nfs_server
.protocol
= data
->proto
;
2276 nfs_validate_transport_protocol(args
);
2282 if (nfs_parse_mount_options((char *)options
, args
) == 0)
2285 if (!nfs_verify_server_address((struct sockaddr
*)
2286 &args
->nfs_server
.address
))
2289 nfs_set_port((struct sockaddr
*)&args
->nfs_server
.address
,
2290 args
->nfs_server
.port
);
2292 nfs_validate_transport_protocol(args
);
2294 if (args
->auth_flavor_len
> 1)
2295 goto out_inval_auth
;
2297 if (args
->client_address
== NULL
)
2298 goto out_no_client_address
;
2300 status
= nfs_parse_devname(dev_name
,
2301 &args
->nfs_server
.hostname
,
2303 &args
->nfs_server
.export_path
,
2315 dfprintk(MOUNT
, "NFS4: mount program didn't pass any mount data\n");
2319 dfprintk(MOUNT
, "NFS4: Invalid number of RPC auth flavours %d\n",
2320 data
->auth_flavourlen
);
2324 dfprintk(MOUNT
, "NFS4: mount program didn't pass remote address\n");
2327 out_no_client_address
:
2328 dfprintk(MOUNT
, "NFS4: mount program didn't pass callback address\n");
2333 * Get the superblock for an NFS4 mountpoint
2335 static int nfs4_get_sb(struct file_system_type
*fs_type
,
2336 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
2338 struct nfs_parsed_mount_data
*data
;
2339 struct super_block
*s
;
2340 struct nfs_server
*server
;
2341 struct nfs_fh
*mntfh
;
2342 struct dentry
*mntroot
;
2343 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2344 struct nfs_sb_mountdata sb_mntdata
= {
2347 int error
= -ENOMEM
;
2349 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
2350 mntfh
= kzalloc(sizeof(*mntfh
), GFP_KERNEL
);
2351 if (data
== NULL
|| mntfh
== NULL
)
2354 security_init_mnt_opts(&data
->lsm_opts
);
2356 /* Validate the mount data */
2357 error
= nfs4_validate_mount_data(raw_data
, data
, dev_name
);
2361 /* Get a volume representation */
2362 server
= nfs4_create_server(data
, mntfh
);
2363 if (IS_ERR(server
)) {
2364 error
= PTR_ERR(server
);
2367 sb_mntdata
.server
= server
;
2369 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2370 compare_super
= NULL
;
2372 /* Get a superblock - note that we may end up sharing one that already exists */
2373 s
= sget(fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2379 if (s
->s_fs_info
!= server
) {
2380 nfs_free_server(server
);
2383 error
= nfs_bdi_register(server
);
2385 goto error_splat_super
;
2389 /* initial superblock/root creation */
2393 mntroot
= nfs4_get_root(s
, mntfh
);
2394 if (IS_ERR(mntroot
)) {
2395 error
= PTR_ERR(mntroot
);
2396 goto error_splat_super
;
2399 error
= security_sb_set_mnt_opts(s
, &data
->lsm_opts
);
2401 goto error_splat_root
;
2403 s
->s_flags
|= MS_ACTIVE
;
2405 mnt
->mnt_root
= mntroot
;
2409 kfree(data
->client_address
);
2410 kfree(data
->nfs_server
.export_path
);
2411 kfree(data
->nfs_server
.hostname
);
2412 security_free_mnt_opts(&data
->lsm_opts
);
2419 nfs_free_server(server
);
2425 up_write(&s
->s_umount
);
2426 deactivate_super(s
);
2430 static void nfs4_kill_super(struct super_block
*sb
)
2432 struct nfs_server
*server
= NFS_SB(sb
);
2434 nfs_super_return_all_delegations(sb
);
2435 kill_anon_super(sb
);
2437 nfs4_renewd_prepare_shutdown(server
);
2438 nfs_free_server(server
);
2442 * Clone an NFS4 server record on xdev traversal (FSID-change)
2444 static int nfs4_xdev_get_sb(struct file_system_type
*fs_type
, int flags
,
2445 const char *dev_name
, void *raw_data
,
2446 struct vfsmount
*mnt
)
2448 struct nfs_clone_mount
*data
= raw_data
;
2449 struct super_block
*s
;
2450 struct nfs_server
*server
;
2451 struct dentry
*mntroot
;
2452 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2453 struct nfs_sb_mountdata sb_mntdata
= {
2458 dprintk("--> nfs4_xdev_get_sb()\n");
2460 /* create a new volume representation */
2461 server
= nfs_clone_server(NFS_SB(data
->sb
), data
->fh
, data
->fattr
);
2462 if (IS_ERR(server
)) {
2463 error
= PTR_ERR(server
);
2464 goto out_err_noserver
;
2466 sb_mntdata
.server
= server
;
2468 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2469 compare_super
= NULL
;
2471 /* Get a superblock - note that we may end up sharing one that already exists */
2472 s
= sget(&nfs4_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2478 if (s
->s_fs_info
!= server
) {
2479 nfs_free_server(server
);
2482 error
= nfs_bdi_register(server
);
2484 goto error_splat_super
;
2488 /* initial superblock/root creation */
2489 nfs4_clone_super(s
, data
->sb
);
2492 mntroot
= nfs4_get_root(s
, data
->fh
);
2493 if (IS_ERR(mntroot
)) {
2494 error
= PTR_ERR(mntroot
);
2495 goto error_splat_super
;
2497 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
2500 goto error_splat_super
;
2503 s
->s_flags
|= MS_ACTIVE
;
2505 mnt
->mnt_root
= mntroot
;
2507 security_sb_clone_mnt_opts(data
->sb
, s
);
2509 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2513 nfs_free_server(server
);
2515 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error
);
2519 up_write(&s
->s_umount
);
2520 deactivate_super(s
);
2521 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error
);
2526 * Create an NFS4 server record on referral traversal
2528 static int nfs4_referral_get_sb(struct file_system_type
*fs_type
, int flags
,
2529 const char *dev_name
, void *raw_data
,
2530 struct vfsmount
*mnt
)
2532 struct nfs_clone_mount
*data
= raw_data
;
2533 struct super_block
*s
;
2534 struct nfs_server
*server
;
2535 struct dentry
*mntroot
;
2536 struct nfs_fh mntfh
;
2537 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2538 struct nfs_sb_mountdata sb_mntdata
= {
2543 dprintk("--> nfs4_referral_get_sb()\n");
2545 /* create a new volume representation */
2546 server
= nfs4_create_referral_server(data
, &mntfh
);
2547 if (IS_ERR(server
)) {
2548 error
= PTR_ERR(server
);
2549 goto out_err_noserver
;
2551 sb_mntdata
.server
= server
;
2553 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2554 compare_super
= NULL
;
2556 /* Get a superblock - note that we may end up sharing one that already exists */
2557 s
= sget(&nfs4_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2563 if (s
->s_fs_info
!= server
) {
2564 nfs_free_server(server
);
2567 error
= nfs_bdi_register(server
);
2569 goto error_splat_super
;
2573 /* initial superblock/root creation */
2577 mntroot
= nfs4_get_root(s
, &mntfh
);
2578 if (IS_ERR(mntroot
)) {
2579 error
= PTR_ERR(mntroot
);
2580 goto error_splat_super
;
2582 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
2585 goto error_splat_super
;
2588 s
->s_flags
|= MS_ACTIVE
;
2590 mnt
->mnt_root
= mntroot
;
2592 security_sb_clone_mnt_opts(data
->sb
, s
);
2594 dprintk("<-- nfs4_referral_get_sb() = 0\n");
2598 nfs_free_server(server
);
2600 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error
);
2604 up_write(&s
->s_umount
);
2605 deactivate_super(s
);
2606 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error
);
2610 #endif /* CONFIG_NFS_V4 */