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
,
81 /* Mount options that take integer arguments */
83 Opt_rsize
, Opt_wsize
, Opt_bsize
,
84 Opt_timeo
, Opt_retrans
,
85 Opt_acregmin
, Opt_acregmax
,
86 Opt_acdirmin
, Opt_acdirmax
,
93 /* Mount options that take string arguments */
94 Opt_sec
, Opt_proto
, Opt_mountproto
, Opt_mounthost
,
95 Opt_addr
, Opt_mountaddr
, Opt_clientaddr
,
98 /* Special mount options */
99 Opt_userspace
, Opt_deprecated
, Opt_sloppy
,
104 static const match_table_t nfs_mount_option_tokens
= {
105 { Opt_userspace
, "bg" },
106 { Opt_userspace
, "fg" },
107 { Opt_userspace
, "retry=%s" },
109 { Opt_sloppy
, "sloppy" },
111 { Opt_soft
, "soft" },
112 { Opt_hard
, "hard" },
113 { Opt_deprecated
, "intr" },
114 { Opt_deprecated
, "nointr" },
115 { Opt_posix
, "posix" },
116 { Opt_noposix
, "noposix" },
118 { Opt_nocto
, "nocto" },
120 { Opt_noac
, "noac" },
121 { Opt_lock
, "lock" },
122 { Opt_nolock
, "nolock" },
127 { Opt_rdma
, "rdma" },
129 { Opt_noacl
, "noacl" },
130 { Opt_rdirplus
, "rdirplus" },
131 { Opt_nordirplus
, "nordirplus" },
132 { Opt_sharecache
, "sharecache" },
133 { Opt_nosharecache
, "nosharecache" },
134 { Opt_resvport
, "resvport" },
135 { Opt_noresvport
, "noresvport" },
137 { Opt_port
, "port=%u" },
138 { Opt_rsize
, "rsize=%u" },
139 { Opt_wsize
, "wsize=%u" },
140 { Opt_bsize
, "bsize=%u" },
141 { Opt_timeo
, "timeo=%u" },
142 { Opt_retrans
, "retrans=%u" },
143 { Opt_acregmin
, "acregmin=%u" },
144 { Opt_acregmax
, "acregmax=%u" },
145 { Opt_acdirmin
, "acdirmin=%u" },
146 { Opt_acdirmax
, "acdirmax=%u" },
147 { Opt_actimeo
, "actimeo=%u" },
148 { Opt_namelen
, "namlen=%u" },
149 { Opt_mountport
, "mountport=%u" },
150 { Opt_mountvers
, "mountvers=%u" },
151 { Opt_nfsvers
, "nfsvers=%u" },
152 { Opt_nfsvers
, "vers=%u" },
154 { Opt_sec
, "sec=%s" },
155 { Opt_proto
, "proto=%s" },
156 { Opt_mountproto
, "mountproto=%s" },
157 { Opt_addr
, "addr=%s" },
158 { Opt_clientaddr
, "clientaddr=%s" },
159 { Opt_mounthost
, "mounthost=%s" },
160 { Opt_mountaddr
, "mountaddr=%s" },
162 { Opt_lookupcache
, "lookupcache=%s" },
168 Opt_xprt_udp
, Opt_xprt_tcp
, Opt_xprt_rdma
,
173 static const match_table_t nfs_xprt_protocol_tokens
= {
174 { Opt_xprt_udp
, "udp" },
175 { Opt_xprt_tcp
, "tcp" },
176 { Opt_xprt_rdma
, "rdma" },
178 { Opt_xprt_err
, NULL
}
182 Opt_sec_none
, Opt_sec_sys
,
183 Opt_sec_krb5
, Opt_sec_krb5i
, Opt_sec_krb5p
,
184 Opt_sec_lkey
, Opt_sec_lkeyi
, Opt_sec_lkeyp
,
185 Opt_sec_spkm
, Opt_sec_spkmi
, Opt_sec_spkmp
,
190 static const match_table_t nfs_secflavor_tokens
= {
191 { Opt_sec_none
, "none" },
192 { Opt_sec_none
, "null" },
193 { Opt_sec_sys
, "sys" },
195 { Opt_sec_krb5
, "krb5" },
196 { Opt_sec_krb5i
, "krb5i" },
197 { Opt_sec_krb5p
, "krb5p" },
199 { Opt_sec_lkey
, "lkey" },
200 { Opt_sec_lkeyi
, "lkeyi" },
201 { Opt_sec_lkeyp
, "lkeyp" },
203 { Opt_sec_spkm
, "spkm3" },
204 { Opt_sec_spkmi
, "spkm3i" },
205 { Opt_sec_spkmp
, "spkm3p" },
207 { Opt_sec_err
, NULL
}
211 Opt_lookupcache_all
, Opt_lookupcache_positive
,
212 Opt_lookupcache_none
,
217 static match_table_t nfs_lookupcache_tokens
= {
218 { Opt_lookupcache_all
, "all" },
219 { Opt_lookupcache_positive
, "pos" },
220 { Opt_lookupcache_positive
, "positive" },
221 { Opt_lookupcache_none
, "none" },
223 { Opt_lookupcache_err
, NULL
}
227 static void nfs_umount_begin(struct super_block
*);
228 static int nfs_statfs(struct dentry
*, struct kstatfs
*);
229 static int nfs_show_options(struct seq_file
*, struct vfsmount
*);
230 static int nfs_show_stats(struct seq_file
*, struct vfsmount
*);
231 static int nfs_get_sb(struct file_system_type
*, int, const char *, void *, struct vfsmount
*);
232 static int nfs_xdev_get_sb(struct file_system_type
*fs_type
,
233 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
234 static void nfs_kill_super(struct super_block
*);
235 static int nfs_remount(struct super_block
*sb
, int *flags
, char *raw_data
);
237 static struct file_system_type nfs_fs_type
= {
238 .owner
= THIS_MODULE
,
240 .get_sb
= nfs_get_sb
,
241 .kill_sb
= nfs_kill_super
,
242 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
245 struct file_system_type nfs_xdev_fs_type
= {
246 .owner
= THIS_MODULE
,
248 .get_sb
= nfs_xdev_get_sb
,
249 .kill_sb
= nfs_kill_super
,
250 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
253 static const struct super_operations nfs_sops
= {
254 .alloc_inode
= nfs_alloc_inode
,
255 .destroy_inode
= nfs_destroy_inode
,
256 .write_inode
= nfs_write_inode
,
257 .statfs
= nfs_statfs
,
258 .clear_inode
= nfs_clear_inode
,
259 .umount_begin
= nfs_umount_begin
,
260 .show_options
= nfs_show_options
,
261 .show_stats
= nfs_show_stats
,
262 .remount_fs
= nfs_remount
,
266 static int nfs4_get_sb(struct file_system_type
*fs_type
,
267 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
268 static int nfs4_xdev_get_sb(struct file_system_type
*fs_type
,
269 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
270 static int nfs4_referral_get_sb(struct file_system_type
*fs_type
,
271 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
272 static void nfs4_kill_super(struct super_block
*sb
);
274 static struct file_system_type nfs4_fs_type
= {
275 .owner
= THIS_MODULE
,
277 .get_sb
= nfs4_get_sb
,
278 .kill_sb
= nfs4_kill_super
,
279 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
282 struct file_system_type nfs4_xdev_fs_type
= {
283 .owner
= THIS_MODULE
,
285 .get_sb
= nfs4_xdev_get_sb
,
286 .kill_sb
= nfs4_kill_super
,
287 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
290 struct file_system_type nfs4_referral_fs_type
= {
291 .owner
= THIS_MODULE
,
293 .get_sb
= nfs4_referral_get_sb
,
294 .kill_sb
= nfs4_kill_super
,
295 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
298 static const struct super_operations nfs4_sops
= {
299 .alloc_inode
= nfs_alloc_inode
,
300 .destroy_inode
= nfs_destroy_inode
,
301 .write_inode
= nfs_write_inode
,
302 .statfs
= nfs_statfs
,
303 .clear_inode
= nfs4_clear_inode
,
304 .umount_begin
= nfs_umount_begin
,
305 .show_options
= nfs_show_options
,
306 .show_stats
= nfs_show_stats
,
307 .remount_fs
= nfs_remount
,
311 static struct shrinker acl_shrinker
= {
312 .shrink
= nfs_access_cache_shrinker
,
313 .seeks
= DEFAULT_SEEKS
,
317 * Register the NFS filesystems
319 int __init
register_nfs_fs(void)
323 ret
= register_filesystem(&nfs_fs_type
);
327 ret
= nfs_register_sysctl();
331 ret
= register_filesystem(&nfs4_fs_type
);
335 register_shrinker(&acl_shrinker
);
340 nfs_unregister_sysctl();
343 unregister_filesystem(&nfs_fs_type
);
349 * Unregister the NFS filesystems
351 void __exit
unregister_nfs_fs(void)
353 unregister_shrinker(&acl_shrinker
);
355 unregister_filesystem(&nfs4_fs_type
);
357 nfs_unregister_sysctl();
358 unregister_filesystem(&nfs_fs_type
);
361 void nfs_sb_active(struct super_block
*sb
)
363 struct nfs_server
*server
= NFS_SB(sb
);
365 if (atomic_inc_return(&server
->active
) == 1)
366 atomic_inc(&sb
->s_active
);
369 void nfs_sb_deactive(struct super_block
*sb
)
371 struct nfs_server
*server
= NFS_SB(sb
);
373 if (atomic_dec_and_test(&server
->active
))
374 deactivate_super(sb
);
378 * Deliver file system statistics to userspace
380 static int nfs_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
382 struct nfs_server
*server
= NFS_SB(dentry
->d_sb
);
383 unsigned char blockbits
;
384 unsigned long blockres
;
385 struct nfs_fh
*fh
= NFS_FH(dentry
->d_inode
);
386 struct nfs_fattr fattr
;
387 struct nfs_fsstat res
= {
392 error
= server
->nfs_client
->rpc_ops
->statfs(server
, fh
, &res
);
395 buf
->f_type
= NFS_SUPER_MAGIC
;
398 * Current versions of glibc do not correctly handle the
399 * case where f_frsize != f_bsize. Eventually we want to
400 * report the value of wtmult in this field.
402 buf
->f_frsize
= dentry
->d_sb
->s_blocksize
;
405 * On most *nix systems, f_blocks, f_bfree, and f_bavail
406 * are reported in units of f_frsize. Linux hasn't had
407 * an f_frsize field in its statfs struct until recently,
408 * thus historically Linux's sys_statfs reports these
409 * fields in units of f_bsize.
411 buf
->f_bsize
= dentry
->d_sb
->s_blocksize
;
412 blockbits
= dentry
->d_sb
->s_blocksize_bits
;
413 blockres
= (1 << blockbits
) - 1;
414 buf
->f_blocks
= (res
.tbytes
+ blockres
) >> blockbits
;
415 buf
->f_bfree
= (res
.fbytes
+ blockres
) >> blockbits
;
416 buf
->f_bavail
= (res
.abytes
+ blockres
) >> blockbits
;
418 buf
->f_files
= res
.tfiles
;
419 buf
->f_ffree
= res
.afiles
;
421 buf
->f_namelen
= server
->namelen
;
426 dprintk("%s: statfs error = %d\n", __func__
, -error
);
431 * Map the security flavour number to a name
433 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour
)
435 static const struct {
436 rpc_authflavor_t flavour
;
439 { RPC_AUTH_NULL
, "null" },
440 { RPC_AUTH_UNIX
, "sys" },
441 { RPC_AUTH_GSS_KRB5
, "krb5" },
442 { RPC_AUTH_GSS_KRB5I
, "krb5i" },
443 { RPC_AUTH_GSS_KRB5P
, "krb5p" },
444 { RPC_AUTH_GSS_LKEY
, "lkey" },
445 { RPC_AUTH_GSS_LKEYI
, "lkeyi" },
446 { RPC_AUTH_GSS_LKEYP
, "lkeyp" },
447 { RPC_AUTH_GSS_SPKM
, "spkm" },
448 { RPC_AUTH_GSS_SPKMI
, "spkmi" },
449 { RPC_AUTH_GSS_SPKMP
, "spkmp" },
450 { UINT_MAX
, "unknown" }
454 for (i
= 0; sec_flavours
[i
].flavour
!= UINT_MAX
; i
++) {
455 if (sec_flavours
[i
].flavour
== flavour
)
458 return sec_flavours
[i
].str
;
461 static void nfs_show_mountd_options(struct seq_file
*m
, struct nfs_server
*nfss
,
464 struct sockaddr
*sap
= (struct sockaddr
*)&nfss
->mountd_address
;
466 switch (sap
->sa_family
) {
468 struct sockaddr_in
*sin
= (struct sockaddr_in
*)sap
;
469 seq_printf(m
, ",mountaddr=%pI4", &sin
->sin_addr
.s_addr
);
473 struct sockaddr_in6
*sin6
= (struct sockaddr_in6
*)sap
;
474 seq_printf(m
, ",mountaddr=%pI6", &sin6
->sin6_addr
);
479 seq_printf(m
, ",mountaddr=unspecified");
482 if (nfss
->mountd_version
|| showdefaults
)
483 seq_printf(m
, ",mountvers=%u", nfss
->mountd_version
);
484 if (nfss
->mountd_port
|| showdefaults
)
485 seq_printf(m
, ",mountport=%u", nfss
->mountd_port
);
487 switch (nfss
->mountd_protocol
) {
489 seq_printf(m
, ",mountproto=udp");
492 seq_printf(m
, ",mountproto=tcp");
496 seq_printf(m
, ",mountproto=auto");
501 * Describe the mount options in force on this server representation
503 static void nfs_show_mount_options(struct seq_file
*m
, struct nfs_server
*nfss
,
506 static const struct proc_nfs_info
{
511 { NFS_MOUNT_SOFT
, ",soft", ",hard" },
512 { NFS_MOUNT_INTR
, ",intr", ",nointr" },
513 { NFS_MOUNT_POSIX
, ",posix", "" },
514 { NFS_MOUNT_NOCTO
, ",nocto", "" },
515 { NFS_MOUNT_NOAC
, ",noac", "" },
516 { NFS_MOUNT_NONLM
, ",nolock", "" },
517 { NFS_MOUNT_NOACL
, ",noacl", "" },
518 { NFS_MOUNT_NORDIRPLUS
, ",nordirplus", "" },
519 { NFS_MOUNT_UNSHARED
, ",nosharecache", "" },
520 { NFS_MOUNT_NORESVPORT
, ",noresvport", "" },
523 const struct proc_nfs_info
*nfs_infop
;
524 struct nfs_client
*clp
= nfss
->nfs_client
;
525 u32 version
= clp
->rpc_ops
->version
;
527 seq_printf(m
, ",vers=%u", version
);
528 seq_printf(m
, ",rsize=%u", nfss
->rsize
);
529 seq_printf(m
, ",wsize=%u", nfss
->wsize
);
530 if (nfss
->bsize
!= 0)
531 seq_printf(m
, ",bsize=%u", nfss
->bsize
);
532 seq_printf(m
, ",namlen=%u", nfss
->namelen
);
533 if (nfss
->acregmin
!= NFS_DEF_ACREGMIN
*HZ
|| showdefaults
)
534 seq_printf(m
, ",acregmin=%u", nfss
->acregmin
/HZ
);
535 if (nfss
->acregmax
!= NFS_DEF_ACREGMAX
*HZ
|| showdefaults
)
536 seq_printf(m
, ",acregmax=%u", nfss
->acregmax
/HZ
);
537 if (nfss
->acdirmin
!= NFS_DEF_ACDIRMIN
*HZ
|| showdefaults
)
538 seq_printf(m
, ",acdirmin=%u", nfss
->acdirmin
/HZ
);
539 if (nfss
->acdirmax
!= NFS_DEF_ACDIRMAX
*HZ
|| showdefaults
)
540 seq_printf(m
, ",acdirmax=%u", nfss
->acdirmax
/HZ
);
541 for (nfs_infop
= nfs_info
; nfs_infop
->flag
; nfs_infop
++) {
542 if (nfss
->flags
& nfs_infop
->flag
)
543 seq_puts(m
, nfs_infop
->str
);
545 seq_puts(m
, nfs_infop
->nostr
);
547 seq_printf(m
, ",proto=%s",
548 rpc_peeraddr2str(nfss
->client
, RPC_DISPLAY_PROTO
));
550 if (nfss
->port
!= NFS_PORT
)
551 seq_printf(m
, ",port=%u", nfss
->port
);
554 seq_printf(m
, ",port=%u", nfss
->port
);
556 seq_printf(m
, ",timeo=%lu", 10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
);
557 seq_printf(m
, ",retrans=%u", nfss
->client
->cl_timeout
->to_retries
);
558 seq_printf(m
, ",sec=%s", nfs_pseudoflavour_to_name(nfss
->client
->cl_auth
->au_flavor
));
561 nfs_show_mountd_options(m
, nfss
, showdefaults
);
564 if (clp
->rpc_ops
->version
== 4)
565 seq_printf(m
, ",clientaddr=%s", clp
->cl_ipaddr
);
570 * Describe the mount options on this VFS mountpoint
572 static int nfs_show_options(struct seq_file
*m
, struct vfsmount
*mnt
)
574 struct nfs_server
*nfss
= NFS_SB(mnt
->mnt_sb
);
576 nfs_show_mount_options(m
, nfss
, 0);
578 seq_printf(m
, ",addr=%s",
579 rpc_peeraddr2str(nfss
->nfs_client
->cl_rpcclient
,
586 * Present statistical information for this VFS mountpoint
588 static int nfs_show_stats(struct seq_file
*m
, struct vfsmount
*mnt
)
591 struct nfs_server
*nfss
= NFS_SB(mnt
->mnt_sb
);
592 struct rpc_auth
*auth
= nfss
->client
->cl_auth
;
593 struct nfs_iostats totals
= { };
595 seq_printf(m
, "statvers=%s", NFS_IOSTAT_VERS
);
598 * Display all mount option settings
600 seq_printf(m
, "\n\topts:\t");
601 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_RDONLY
? "ro" : "rw");
602 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_SYNCHRONOUS
? ",sync" : "");
603 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_NOATIME
? ",noatime" : "");
604 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_NODIRATIME
? ",nodiratime" : "");
605 nfs_show_mount_options(m
, nfss
, 1);
607 seq_printf(m
, "\n\tage:\t%lu", (jiffies
- nfss
->mount_time
) / HZ
);
609 seq_printf(m
, "\n\tcaps:\t");
610 seq_printf(m
, "caps=0x%x", nfss
->caps
);
611 seq_printf(m
, ",wtmult=%u", nfss
->wtmult
);
612 seq_printf(m
, ",dtsize=%u", nfss
->dtsize
);
613 seq_printf(m
, ",bsize=%u", nfss
->bsize
);
614 seq_printf(m
, ",namlen=%u", nfss
->namelen
);
617 if (nfss
->nfs_client
->rpc_ops
->version
== 4) {
618 seq_printf(m
, "\n\tnfsv4:\t");
619 seq_printf(m
, "bm0=0x%x", nfss
->attr_bitmask
[0]);
620 seq_printf(m
, ",bm1=0x%x", nfss
->attr_bitmask
[1]);
621 seq_printf(m
, ",acl=0x%x", nfss
->acl_bitmask
);
626 * Display security flavor in effect for this mount
628 seq_printf(m
, "\n\tsec:\tflavor=%u", auth
->au_ops
->au_flavor
);
630 seq_printf(m
, ",pseudoflavor=%u", auth
->au_flavor
);
633 * Display superblock I/O counters
635 for_each_possible_cpu(cpu
) {
636 struct nfs_iostats
*stats
;
639 stats
= per_cpu_ptr(nfss
->io_stats
, cpu
);
641 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
642 totals
.events
[i
] += stats
->events
[i
];
643 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
644 totals
.bytes
[i
] += stats
->bytes
[i
];
649 seq_printf(m
, "\n\tevents:\t");
650 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
651 seq_printf(m
, "%lu ", totals
.events
[i
]);
652 seq_printf(m
, "\n\tbytes:\t");
653 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
654 seq_printf(m
, "%Lu ", totals
.bytes
[i
]);
657 rpc_print_iostats(m
, nfss
->client
);
663 * Begin unmount by attempting to remove all automounted mountpoints we added
664 * in response to xdev traversals and referrals
666 static void nfs_umount_begin(struct super_block
*sb
)
668 struct nfs_server
*server
= NFS_SB(sb
);
669 struct rpc_clnt
*rpc
;
671 /* -EIO all pending I/O */
672 rpc
= server
->client_acl
;
674 rpc_killall_tasks(rpc
);
675 rpc
= server
->client
;
677 rpc_killall_tasks(rpc
);
681 * Sanity-check a server address provided by the mount command.
683 * Address family must be initialized, and address must not be
684 * the ANY address for that family.
686 static int nfs_verify_server_address(struct sockaddr
*addr
)
688 switch (addr
->sa_family
) {
690 struct sockaddr_in
*sa
= (struct sockaddr_in
*)addr
;
691 return sa
->sin_addr
.s_addr
!= htonl(INADDR_ANY
);
694 struct in6_addr
*sa
= &((struct sockaddr_in6
*)addr
)->sin6_addr
;
695 return !ipv6_addr_any(sa
);
702 static void nfs_parse_ipv4_address(char *string
, size_t str_len
,
703 struct sockaddr
*sap
, size_t *addr_len
)
705 struct sockaddr_in
*sin
= (struct sockaddr_in
*)sap
;
706 u8
*addr
= (u8
*)&sin
->sin_addr
.s_addr
;
708 if (str_len
<= INET_ADDRSTRLEN
) {
709 dfprintk(MOUNT
, "NFS: parsing IPv4 address %*s\n",
710 (int)str_len
, string
);
712 sin
->sin_family
= AF_INET
;
713 *addr_len
= sizeof(*sin
);
714 if (in4_pton(string
, str_len
, addr
, '\0', NULL
))
718 sap
->sa_family
= AF_UNSPEC
;
722 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
723 static int nfs_parse_ipv6_scope_id(const char *string
, const size_t str_len
,
725 struct sockaddr_in6
*sin6
)
730 if ((string
+ str_len
) == delim
)
733 if (*delim
!= IPV6_SCOPE_DELIMITER
)
736 if (!(ipv6_addr_type(&sin6
->sin6_addr
) & IPV6_ADDR_LINKLOCAL
))
739 len
= (string
+ str_len
) - delim
- 1;
740 p
= kstrndup(delim
+ 1, len
, GFP_KERNEL
);
742 unsigned long scope_id
= 0;
743 struct net_device
*dev
;
745 dev
= dev_get_by_name(&init_net
, p
);
747 scope_id
= dev
->ifindex
;
750 if (strict_strtoul(p
, 10, &scope_id
) == 0) {
758 sin6
->sin6_scope_id
= scope_id
;
759 dfprintk(MOUNT
, "NFS: IPv6 scope ID = %lu\n", scope_id
);
766 static void nfs_parse_ipv6_address(char *string
, size_t str_len
,
767 struct sockaddr
*sap
, size_t *addr_len
)
769 struct sockaddr_in6
*sin6
= (struct sockaddr_in6
*)sap
;
770 u8
*addr
= (u8
*)&sin6
->sin6_addr
.in6_u
;
773 if (str_len
<= INET6_ADDRSTRLEN
) {
774 dfprintk(MOUNT
, "NFS: parsing IPv6 address %*s\n",
775 (int)str_len
, string
);
777 sin6
->sin6_family
= AF_INET6
;
778 *addr_len
= sizeof(*sin6
);
779 if (in6_pton(string
, str_len
, addr
,
780 IPV6_SCOPE_DELIMITER
, &delim
) != 0) {
781 if (nfs_parse_ipv6_scope_id(string
, str_len
,
787 sap
->sa_family
= AF_UNSPEC
;
791 static void nfs_parse_ipv6_address(char *string
, size_t str_len
,
792 struct sockaddr
*sap
, size_t *addr_len
)
794 sap
->sa_family
= AF_UNSPEC
;
800 * Construct a sockaddr based on the contents of a string that contains
801 * an IP address in presentation format.
803 * If there is a problem constructing the new sockaddr, set the address
804 * family to AF_UNSPEC.
806 void nfs_parse_ip_address(char *string
, size_t str_len
,
807 struct sockaddr
*sap
, size_t *addr_len
)
809 unsigned int i
, colons
;
812 for (i
= 0; i
< str_len
; i
++)
813 if (string
[i
] == ':')
817 nfs_parse_ipv6_address(string
, str_len
, sap
, addr_len
);
819 nfs_parse_ipv4_address(string
, str_len
, sap
, addr_len
);
823 * Sanity check the NFS transport protocol.
826 static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data
*mnt
)
828 switch (mnt
->nfs_server
.protocol
) {
829 case XPRT_TRANSPORT_UDP
:
830 case XPRT_TRANSPORT_TCP
:
831 case XPRT_TRANSPORT_RDMA
:
834 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
839 * For text based NFSv2/v3 mounts, the mount protocol transport default
840 * settings should depend upon the specified NFS transport.
842 static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data
*mnt
)
844 nfs_validate_transport_protocol(mnt
);
846 if (mnt
->mount_server
.protocol
== XPRT_TRANSPORT_UDP
||
847 mnt
->mount_server
.protocol
== XPRT_TRANSPORT_TCP
)
849 switch (mnt
->nfs_server
.protocol
) {
850 case XPRT_TRANSPORT_UDP
:
851 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_UDP
;
853 case XPRT_TRANSPORT_TCP
:
854 case XPRT_TRANSPORT_RDMA
:
855 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_TCP
;
860 * Parse the value of the 'sec=' option.
862 * The flavor_len setting is for v4 mounts.
864 static int nfs_parse_security_flavors(char *value
,
865 struct nfs_parsed_mount_data
*mnt
)
867 substring_t args
[MAX_OPT_ARGS
];
869 dfprintk(MOUNT
, "NFS: parsing sec=%s option\n", value
);
871 switch (match_token(value
, nfs_secflavor_tokens
, args
)) {
873 mnt
->auth_flavor_len
= 0;
874 mnt
->auth_flavors
[0] = RPC_AUTH_NULL
;
877 mnt
->auth_flavor_len
= 0;
878 mnt
->auth_flavors
[0] = RPC_AUTH_UNIX
;
881 mnt
->auth_flavor_len
= 1;
882 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5
;
885 mnt
->auth_flavor_len
= 1;
886 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5I
;
889 mnt
->auth_flavor_len
= 1;
890 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5P
;
893 mnt
->auth_flavor_len
= 1;
894 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEY
;
897 mnt
->auth_flavor_len
= 1;
898 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEYI
;
901 mnt
->auth_flavor_len
= 1;
902 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEYP
;
905 mnt
->auth_flavor_len
= 1;
906 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKM
;
909 mnt
->auth_flavor_len
= 1;
910 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKMI
;
913 mnt
->auth_flavor_len
= 1;
914 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKMP
;
923 static void nfs_parse_invalid_value(const char *option
)
925 dfprintk(MOUNT
, "NFS: bad value specified for %s option\n", option
);
929 * Error-check and convert a string of mount options from user space into
930 * a data structure. The whole mount string is processed; bad options are
931 * skipped as they are encountered. If there were no errors, return 1;
932 * otherwise return 0 (zero).
934 static int nfs_parse_mount_options(char *raw
,
935 struct nfs_parsed_mount_data
*mnt
)
937 char *p
, *string
, *secdata
;
938 int rc
, sloppy
= 0, errors
= 0;
941 dfprintk(MOUNT
, "NFS: mount options string was NULL.\n");
944 dfprintk(MOUNT
, "NFS: nfs mount opts='%s'\n", raw
);
946 secdata
= alloc_secdata();
950 rc
= security_sb_copy_data(raw
, secdata
);
952 goto out_security_failure
;
954 rc
= security_sb_parse_opts_str(secdata
, &mnt
->lsm_opts
);
956 goto out_security_failure
;
958 free_secdata(secdata
);
960 while ((p
= strsep(&raw
, ",")) != NULL
) {
961 substring_t args
[MAX_OPT_ARGS
];
967 dfprintk(MOUNT
, "NFS: parsing nfs mount option '%s'\n", p
);
969 token
= match_token(p
, nfs_mount_option_tokens
, args
);
973 * boolean options: foo/nofoo
976 mnt
->flags
|= NFS_MOUNT_SOFT
;
979 mnt
->flags
&= ~NFS_MOUNT_SOFT
;
982 mnt
->flags
|= NFS_MOUNT_POSIX
;
985 mnt
->flags
&= ~NFS_MOUNT_POSIX
;
988 mnt
->flags
&= ~NFS_MOUNT_NOCTO
;
991 mnt
->flags
|= NFS_MOUNT_NOCTO
;
994 mnt
->flags
&= ~NFS_MOUNT_NOAC
;
997 mnt
->flags
|= NFS_MOUNT_NOAC
;
1000 mnt
->flags
&= ~NFS_MOUNT_NONLM
;
1003 mnt
->flags
|= NFS_MOUNT_NONLM
;
1006 mnt
->flags
&= ~NFS_MOUNT_VER3
;
1009 mnt
->flags
|= NFS_MOUNT_VER3
;
1012 mnt
->flags
&= ~NFS_MOUNT_TCP
;
1013 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1016 mnt
->flags
|= NFS_MOUNT_TCP
;
1017 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1020 mnt
->flags
|= NFS_MOUNT_TCP
; /* for side protocols */
1021 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_RDMA
;
1022 xprt_load_transport(p
);
1025 mnt
->flags
&= ~NFS_MOUNT_NOACL
;
1028 mnt
->flags
|= NFS_MOUNT_NOACL
;
1031 mnt
->flags
&= ~NFS_MOUNT_NORDIRPLUS
;
1033 case Opt_nordirplus
:
1034 mnt
->flags
|= NFS_MOUNT_NORDIRPLUS
;
1036 case Opt_sharecache
:
1037 mnt
->flags
&= ~NFS_MOUNT_UNSHARED
;
1039 case Opt_nosharecache
:
1040 mnt
->flags
|= NFS_MOUNT_UNSHARED
;
1043 mnt
->flags
&= ~NFS_MOUNT_NORESVPORT
;
1045 case Opt_noresvport
:
1046 mnt
->flags
|= NFS_MOUNT_NORESVPORT
;
1050 * options that take numeric values
1053 if (match_int(args
, &option
) ||
1054 option
< 0 || option
> USHORT_MAX
) {
1056 nfs_parse_invalid_value("port");
1058 mnt
->nfs_server
.port
= option
;
1061 if (match_int(args
, &option
) || option
< 0) {
1063 nfs_parse_invalid_value("rsize");
1065 mnt
->rsize
= option
;
1068 if (match_int(args
, &option
) || option
< 0) {
1070 nfs_parse_invalid_value("wsize");
1072 mnt
->wsize
= option
;
1075 if (match_int(args
, &option
) || option
< 0) {
1077 nfs_parse_invalid_value("bsize");
1079 mnt
->bsize
= option
;
1082 if (match_int(args
, &option
) || option
<= 0) {
1084 nfs_parse_invalid_value("timeo");
1086 mnt
->timeo
= option
;
1089 if (match_int(args
, &option
) || option
<= 0) {
1091 nfs_parse_invalid_value("retrans");
1093 mnt
->retrans
= option
;
1096 if (match_int(args
, &option
) || option
< 0) {
1098 nfs_parse_invalid_value("acregmin");
1100 mnt
->acregmin
= option
;
1103 if (match_int(args
, &option
) || option
< 0) {
1105 nfs_parse_invalid_value("acregmax");
1107 mnt
->acregmax
= option
;
1110 if (match_int(args
, &option
) || option
< 0) {
1112 nfs_parse_invalid_value("acdirmin");
1114 mnt
->acdirmin
= option
;
1117 if (match_int(args
, &option
) || option
< 0) {
1119 nfs_parse_invalid_value("acdirmax");
1121 mnt
->acdirmax
= option
;
1124 if (match_int(args
, &option
) || option
< 0) {
1126 nfs_parse_invalid_value("actimeo");
1128 mnt
->acregmin
= mnt
->acregmax
=
1129 mnt
->acdirmin
= mnt
->acdirmax
= option
;
1132 if (match_int(args
, &option
) || option
< 0) {
1134 nfs_parse_invalid_value("namlen");
1136 mnt
->namlen
= option
;
1139 if (match_int(args
, &option
) ||
1140 option
< 0 || option
> USHORT_MAX
) {
1142 nfs_parse_invalid_value("mountport");
1144 mnt
->mount_server
.port
= option
;
1147 if (match_int(args
, &option
) ||
1148 option
< NFS_MNT_VERSION
||
1149 option
> NFS_MNT3_VERSION
) {
1151 nfs_parse_invalid_value("mountvers");
1153 mnt
->mount_server
.version
= option
;
1156 if (match_int(args
, &option
)) {
1158 nfs_parse_invalid_value("nfsvers");
1163 mnt
->flags
&= ~NFS_MOUNT_VER3
;
1166 mnt
->flags
|= NFS_MOUNT_VER3
;
1170 nfs_parse_invalid_value("nfsvers");
1175 * options that take text values
1178 string
= match_strdup(args
);
1181 rc
= nfs_parse_security_flavors(string
, mnt
);
1185 dfprintk(MOUNT
, "NFS: unrecognized "
1186 "security flavor\n");
1190 string
= match_strdup(args
);
1193 token
= match_token(string
,
1194 nfs_xprt_protocol_tokens
, args
);
1199 mnt
->flags
&= ~NFS_MOUNT_TCP
;
1200 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1203 mnt
->flags
|= NFS_MOUNT_TCP
;
1204 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1207 /* vector side protocols to TCP */
1208 mnt
->flags
|= NFS_MOUNT_TCP
;
1209 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_RDMA
;
1210 xprt_load_transport(string
);
1214 dfprintk(MOUNT
, "NFS: unrecognized "
1215 "transport protocol\n");
1219 case Opt_mountproto
:
1220 string
= match_strdup(args
);
1223 token
= match_token(string
,
1224 nfs_xprt_protocol_tokens
, args
);
1228 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_UDP
;
1231 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_TCP
;
1233 case Opt_xprt_rdma
: /* not used for side protocols */
1236 dfprintk(MOUNT
, "NFS: unrecognized "
1237 "transport protocol\n");
1241 string
= match_strdup(args
);
1244 nfs_parse_ip_address(string
, strlen(string
),
1246 &mnt
->nfs_server
.address
,
1247 &mnt
->nfs_server
.addrlen
);
1250 case Opt_clientaddr
:
1251 string
= match_strdup(args
);
1254 kfree(mnt
->client_address
);
1255 mnt
->client_address
= string
;
1258 string
= match_strdup(args
);
1261 kfree(mnt
->mount_server
.hostname
);
1262 mnt
->mount_server
.hostname
= string
;
1265 string
= match_strdup(args
);
1268 nfs_parse_ip_address(string
, strlen(string
),
1270 &mnt
->mount_server
.address
,
1271 &mnt
->mount_server
.addrlen
);
1274 case Opt_lookupcache
:
1275 string
= match_strdup(args
);
1278 token
= match_token(string
,
1279 nfs_lookupcache_tokens
, args
);
1282 case Opt_lookupcache_all
:
1283 mnt
->flags
&= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG
|NFS_MOUNT_LOOKUP_CACHE_NONE
);
1285 case Opt_lookupcache_positive
:
1286 mnt
->flags
&= ~NFS_MOUNT_LOOKUP_CACHE_NONE
;
1287 mnt
->flags
|= NFS_MOUNT_LOOKUP_CACHE_NONEG
;
1289 case Opt_lookupcache_none
:
1290 mnt
->flags
|= NFS_MOUNT_LOOKUP_CACHE_NONEG
|NFS_MOUNT_LOOKUP_CACHE_NONE
;
1294 dfprintk(MOUNT
, "NFS: invalid "
1295 "lookupcache argument\n");
1304 dfprintk(MOUNT
, "NFS: relaxing parsing rules\n");
1307 case Opt_deprecated
:
1308 dfprintk(MOUNT
, "NFS: ignoring mount option "
1314 dfprintk(MOUNT
, "NFS: unrecognized mount option "
1320 dfprintk(MOUNT
, "NFS: parsing encountered %d error%s\n",
1321 errors
, (errors
== 1 ? "" : "s"));
1328 printk(KERN_INFO
"NFS: not enough memory to parse option\n");
1330 out_security_failure
:
1331 free_secdata(secdata
);
1332 printk(KERN_INFO
"NFS: security options invalid: %d\n", rc
);
1337 * Use the remote server's MOUNT service to request the NFS file handle
1338 * corresponding to the provided path.
1340 static int nfs_try_mount(struct nfs_parsed_mount_data
*args
,
1341 struct nfs_fh
*root_fh
)
1343 struct nfs_mount_request request
= {
1344 .sap
= (struct sockaddr
*)
1345 &args
->mount_server
.address
,
1346 .dirpath
= args
->nfs_server
.export_path
,
1347 .protocol
= args
->mount_server
.protocol
,
1349 .noresvport
= args
->flags
& NFS_MOUNT_NORESVPORT
,
1353 if (args
->mount_server
.version
== 0) {
1354 if (args
->flags
& NFS_MOUNT_VER3
)
1355 args
->mount_server
.version
= NFS_MNT3_VERSION
;
1357 args
->mount_server
.version
= NFS_MNT_VERSION
;
1359 request
.version
= args
->mount_server
.version
;
1361 if (args
->mount_server
.hostname
)
1362 request
.hostname
= args
->mount_server
.hostname
;
1364 request
.hostname
= args
->nfs_server
.hostname
;
1367 * Construct the mount server's address.
1369 if (args
->mount_server
.address
.ss_family
== AF_UNSPEC
) {
1370 memcpy(request
.sap
, &args
->nfs_server
.address
,
1371 args
->nfs_server
.addrlen
);
1372 args
->mount_server
.addrlen
= args
->nfs_server
.addrlen
;
1374 request
.salen
= args
->mount_server
.addrlen
;
1377 * autobind will be used if mount_server.port == 0
1379 nfs_set_port(request
.sap
, args
->mount_server
.port
);
1382 * Now ask the mount server to map our export path
1385 status
= nfs_mount(&request
);
1389 dfprintk(MOUNT
, "NFS: unable to mount server %s, error %d\n",
1390 request
.hostname
, status
);
1394 static int nfs_parse_simple_hostname(const char *dev_name
,
1395 char **hostname
, size_t maxnamlen
,
1396 char **export_path
, size_t maxpathlen
)
1399 char *colon
, *comma
;
1401 colon
= strchr(dev_name
, ':');
1403 goto out_bad_devname
;
1405 len
= colon
- dev_name
;
1406 if (len
> maxnamlen
)
1409 /* N.B. caller will free nfs_server.hostname in all cases */
1410 *hostname
= kstrndup(dev_name
, len
, GFP_KERNEL
);
1414 /* kill possible hostname list: not supported */
1415 comma
= strchr(*hostname
, ',');
1416 if (comma
!= NULL
) {
1417 if (comma
== *hostname
)
1418 goto out_bad_devname
;
1423 len
= strlen(colon
);
1424 if (len
> maxpathlen
)
1426 *export_path
= kstrndup(colon
, len
, GFP_KERNEL
);
1430 dfprintk(MOUNT
, "NFS: MNTPATH: '%s'\n", *export_path
);
1434 dfprintk(MOUNT
, "NFS: device name not in host:path format\n");
1438 dfprintk(MOUNT
, "NFS: not enough memory to parse device name\n");
1442 dfprintk(MOUNT
, "NFS: server hostname too long\n");
1443 return -ENAMETOOLONG
;
1446 dfprintk(MOUNT
, "NFS: export pathname too long\n");
1447 return -ENAMETOOLONG
;
1451 * Hostname has square brackets around it because it contains one or
1452 * more colons. We look for the first closing square bracket, and a
1453 * colon must follow it.
1455 static int nfs_parse_protected_hostname(const char *dev_name
,
1456 char **hostname
, size_t maxnamlen
,
1457 char **export_path
, size_t maxpathlen
)
1462 start
= (char *)(dev_name
+ 1);
1464 end
= strchr(start
, ']');
1466 goto out_bad_devname
;
1467 if (*(end
+ 1) != ':')
1468 goto out_bad_devname
;
1471 if (len
> maxnamlen
)
1474 /* N.B. caller will free nfs_server.hostname in all cases */
1475 *hostname
= kstrndup(start
, len
, GFP_KERNEL
);
1476 if (*hostname
== NULL
)
1481 if (len
> maxpathlen
)
1483 *export_path
= kstrndup(end
, len
, GFP_KERNEL
);
1490 dfprintk(MOUNT
, "NFS: device name not in host:path format\n");
1494 dfprintk(MOUNT
, "NFS: not enough memory to parse device name\n");
1498 dfprintk(MOUNT
, "NFS: server hostname too long\n");
1499 return -ENAMETOOLONG
;
1502 dfprintk(MOUNT
, "NFS: export pathname too long\n");
1503 return -ENAMETOOLONG
;
1507 * Split "dev_name" into "hostname:export_path".
1509 * The leftmost colon demarks the split between the server's hostname
1510 * and the export path. If the hostname starts with a left square
1511 * bracket, then it may contain colons.
1513 * Note: caller frees hostname and export path, even on error.
1515 static int nfs_parse_devname(const char *dev_name
,
1516 char **hostname
, size_t maxnamlen
,
1517 char **export_path
, size_t maxpathlen
)
1519 if (*dev_name
== '[')
1520 return nfs_parse_protected_hostname(dev_name
,
1521 hostname
, maxnamlen
,
1522 export_path
, maxpathlen
);
1524 return nfs_parse_simple_hostname(dev_name
,
1525 hostname
, maxnamlen
,
1526 export_path
, maxpathlen
);
1530 * Validate the NFS2/NFS3 mount data
1531 * - fills in the mount root filehandle
1533 * For option strings, user space handles the following behaviors:
1535 * + DNS: mapping server host name to IP address ("addr=" option)
1537 * + failure mode: how to behave if a mount request can't be handled
1538 * immediately ("fg/bg" option)
1540 * + retry: how often to retry a mount request ("retry=" option)
1542 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1543 * mountproto=tcp after mountproto=udp, and so on
1545 static int nfs_validate_mount_data(void *options
,
1546 struct nfs_parsed_mount_data
*args
,
1547 struct nfs_fh
*mntfh
,
1548 const char *dev_name
)
1550 struct nfs_mount_data
*data
= (struct nfs_mount_data
*)options
;
1555 args
->flags
= (NFS_MOUNT_VER3
| NFS_MOUNT_TCP
);
1556 args
->rsize
= NFS_MAX_FILE_IO_SIZE
;
1557 args
->wsize
= NFS_MAX_FILE_IO_SIZE
;
1558 args
->acregmin
= NFS_DEF_ACREGMIN
;
1559 args
->acregmax
= NFS_DEF_ACREGMAX
;
1560 args
->acdirmin
= NFS_DEF_ACDIRMIN
;
1561 args
->acdirmax
= NFS_DEF_ACDIRMAX
;
1562 args
->mount_server
.port
= 0; /* autobind unless user sets port */
1563 args
->nfs_server
.port
= 0; /* autobind unless user sets port */
1564 args
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1565 args
->auth_flavors
[0] = RPC_AUTH_UNIX
;
1567 switch (data
->version
) {
1573 if (data
->flags
& NFS_MOUNT_VER3
)
1575 data
->root
.size
= NFS2_FHSIZE
;
1576 memcpy(data
->root
.data
, data
->old_root
.data
, NFS2_FHSIZE
);
1578 if (data
->flags
& NFS_MOUNT_SECFLAVOUR
)
1581 memset(data
->context
, 0, sizeof(data
->context
));
1583 if (data
->flags
& NFS_MOUNT_VER3
) {
1584 if (data
->root
.size
> NFS3_FHSIZE
|| data
->root
.size
== 0)
1585 goto out_invalid_fh
;
1586 mntfh
->size
= data
->root
.size
;
1588 mntfh
->size
= NFS2_FHSIZE
;
1591 memcpy(mntfh
->data
, data
->root
.data
, mntfh
->size
);
1592 if (mntfh
->size
< sizeof(mntfh
->data
))
1593 memset(mntfh
->data
+ mntfh
->size
, 0,
1594 sizeof(mntfh
->data
) - mntfh
->size
);
1597 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1600 args
->flags
= data
->flags
& NFS_MOUNT_FLAGMASK
;
1601 args
->rsize
= data
->rsize
;
1602 args
->wsize
= data
->wsize
;
1603 args
->timeo
= data
->timeo
;
1604 args
->retrans
= data
->retrans
;
1605 args
->acregmin
= data
->acregmin
;
1606 args
->acregmax
= data
->acregmax
;
1607 args
->acdirmin
= data
->acdirmin
;
1608 args
->acdirmax
= data
->acdirmax
;
1610 memcpy(&args
->nfs_server
.address
, &data
->addr
,
1611 sizeof(data
->addr
));
1612 args
->nfs_server
.addrlen
= sizeof(data
->addr
);
1613 if (!nfs_verify_server_address((struct sockaddr
*)
1614 &args
->nfs_server
.address
))
1615 goto out_no_address
;
1617 if (!(data
->flags
& NFS_MOUNT_TCP
))
1618 args
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1619 /* N.B. caller will free nfs_server.hostname in all cases */
1620 args
->nfs_server
.hostname
= kstrdup(data
->hostname
, GFP_KERNEL
);
1621 args
->namlen
= data
->namlen
;
1622 args
->bsize
= data
->bsize
;
1624 if (data
->flags
& NFS_MOUNT_SECFLAVOUR
)
1625 args
->auth_flavors
[0] = data
->pseudoflavor
;
1626 if (!args
->nfs_server
.hostname
)
1630 * The legacy version 6 binary mount data from userspace has a
1631 * field used only to transport selinux information into the
1632 * the kernel. To continue to support that functionality we
1633 * have a touch of selinux knowledge here in the NFS code. The
1634 * userspace code converted context=blah to just blah so we are
1635 * converting back to the full string selinux understands.
1637 if (data
->context
[0]){
1638 #ifdef CONFIG_SECURITY_SELINUX
1640 char *opts_str
= kmalloc(sizeof(data
->context
) + 8, GFP_KERNEL
);
1643 strcpy(opts_str
, "context=");
1644 data
->context
[NFS_MAX_CONTEXT_LEN
] = '\0';
1645 strcat(opts_str
, &data
->context
[0]);
1646 rc
= security_sb_parse_opts_str(opts_str
, &args
->lsm_opts
);
1659 if (nfs_parse_mount_options((char *)options
, args
) == 0)
1662 if (!nfs_verify_server_address((struct sockaddr
*)
1663 &args
->nfs_server
.address
))
1664 goto out_no_address
;
1666 nfs_set_port((struct sockaddr
*)&args
->nfs_server
.address
,
1667 args
->nfs_server
.port
);
1669 nfs_set_mount_transport_protocol(args
);
1671 status
= nfs_parse_devname(dev_name
,
1672 &args
->nfs_server
.hostname
,
1674 &args
->nfs_server
.export_path
,
1677 status
= nfs_try_mount(args
, mntfh
);
1679 kfree(args
->nfs_server
.export_path
);
1680 args
->nfs_server
.export_path
= NULL
;
1689 #ifndef CONFIG_NFS_V3
1690 if (args
->flags
& NFS_MOUNT_VER3
)
1691 goto out_v3_not_compiled
;
1692 #endif /* !CONFIG_NFS_V3 */
1697 dfprintk(MOUNT
, "NFS: mount program didn't pass any mount data\n");
1701 dfprintk(MOUNT
, "NFS: nfs_mount_data version %d does not support v3\n",
1706 dfprintk(MOUNT
, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1709 #ifndef CONFIG_NFS_V3
1710 out_v3_not_compiled
:
1711 dfprintk(MOUNT
, "NFS: NFSv3 is not compiled into kernel\n");
1712 return -EPROTONOSUPPORT
;
1713 #endif /* !CONFIG_NFS_V3 */
1716 dfprintk(MOUNT
, "NFS: not enough memory to handle mount options\n");
1720 dfprintk(MOUNT
, "NFS: mount program didn't pass remote address\n");
1724 dfprintk(MOUNT
, "NFS: invalid root filehandle\n");
1729 nfs_compare_remount_data(struct nfs_server
*nfss
,
1730 struct nfs_parsed_mount_data
*data
)
1732 if (data
->flags
!= nfss
->flags
||
1733 data
->rsize
!= nfss
->rsize
||
1734 data
->wsize
!= nfss
->wsize
||
1735 data
->retrans
!= nfss
->client
->cl_timeout
->to_retries
||
1736 data
->auth_flavors
[0] != nfss
->client
->cl_auth
->au_flavor
||
1737 data
->acregmin
!= nfss
->acregmin
/ HZ
||
1738 data
->acregmax
!= nfss
->acregmax
/ HZ
||
1739 data
->acdirmin
!= nfss
->acdirmin
/ HZ
||
1740 data
->acdirmax
!= nfss
->acdirmax
/ HZ
||
1741 data
->timeo
!= (10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
) ||
1742 data
->nfs_server
.addrlen
!= nfss
->nfs_client
->cl_addrlen
||
1743 memcmp(&data
->nfs_server
.address
, &nfss
->nfs_client
->cl_addr
,
1744 data
->nfs_server
.addrlen
) != 0)
1751 nfs_remount(struct super_block
*sb
, int *flags
, char *raw_data
)
1754 struct nfs_server
*nfss
= sb
->s_fs_info
;
1755 struct nfs_parsed_mount_data
*data
;
1756 struct nfs_mount_data
*options
= (struct nfs_mount_data
*)raw_data
;
1757 struct nfs4_mount_data
*options4
= (struct nfs4_mount_data
*)raw_data
;
1758 u32 nfsvers
= nfss
->nfs_client
->rpc_ops
->version
;
1761 * Userspace mount programs that send binary options generally send
1762 * them populated with default values. We have no way to know which
1763 * ones were explicitly specified. Fall back to legacy behavior and
1764 * just return success.
1766 if ((nfsvers
== 4 && (!options4
|| options4
->version
== 1)) ||
1767 (nfsvers
<= 3 && (!options
|| (options
->version
>= 1 &&
1768 options
->version
<= 6))))
1771 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
1775 /* fill out struct with values from existing mount */
1776 data
->flags
= nfss
->flags
;
1777 data
->rsize
= nfss
->rsize
;
1778 data
->wsize
= nfss
->wsize
;
1779 data
->retrans
= nfss
->client
->cl_timeout
->to_retries
;
1780 data
->auth_flavors
[0] = nfss
->client
->cl_auth
->au_flavor
;
1781 data
->acregmin
= nfss
->acregmin
/ HZ
;
1782 data
->acregmax
= nfss
->acregmax
/ HZ
;
1783 data
->acdirmin
= nfss
->acdirmin
/ HZ
;
1784 data
->acdirmax
= nfss
->acdirmax
/ HZ
;
1785 data
->timeo
= 10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
;
1786 data
->nfs_server
.addrlen
= nfss
->nfs_client
->cl_addrlen
;
1787 memcpy(&data
->nfs_server
.address
, &nfss
->nfs_client
->cl_addr
,
1788 data
->nfs_server
.addrlen
);
1790 /* overwrite those values with any that were specified */
1791 error
= nfs_parse_mount_options((char *)options
, data
);
1795 /* compare new mount options with old ones */
1796 error
= nfs_compare_remount_data(nfss
, data
);
1803 * Initialise the common bits of the superblock
1805 static inline void nfs_initialise_sb(struct super_block
*sb
)
1807 struct nfs_server
*server
= NFS_SB(sb
);
1809 sb
->s_magic
= NFS_SUPER_MAGIC
;
1811 /* We probably want something more informative here */
1812 snprintf(sb
->s_id
, sizeof(sb
->s_id
),
1813 "%x:%x", MAJOR(sb
->s_dev
), MINOR(sb
->s_dev
));
1815 if (sb
->s_blocksize
== 0)
1816 sb
->s_blocksize
= nfs_block_bits(server
->wsize
,
1817 &sb
->s_blocksize_bits
);
1819 if (server
->flags
& NFS_MOUNT_NOAC
)
1820 sb
->s_flags
|= MS_SYNCHRONOUS
;
1822 nfs_super_set_maxbytes(sb
, server
->maxfilesize
);
1826 * Finish setting up an NFS2/3 superblock
1828 static void nfs_fill_super(struct super_block
*sb
,
1829 struct nfs_parsed_mount_data
*data
)
1831 struct nfs_server
*server
= NFS_SB(sb
);
1833 sb
->s_blocksize_bits
= 0;
1834 sb
->s_blocksize
= 0;
1836 sb
->s_blocksize
= nfs_block_size(data
->bsize
, &sb
->s_blocksize_bits
);
1838 if (server
->flags
& NFS_MOUNT_VER3
) {
1839 /* The VFS shouldn't apply the umask to mode bits. We will do
1840 * so ourselves when necessary.
1842 sb
->s_flags
|= MS_POSIXACL
;
1843 sb
->s_time_gran
= 1;
1846 sb
->s_op
= &nfs_sops
;
1847 nfs_initialise_sb(sb
);
1851 * Finish setting up a cloned NFS2/3 superblock
1853 static void nfs_clone_super(struct super_block
*sb
,
1854 const struct super_block
*old_sb
)
1856 struct nfs_server
*server
= NFS_SB(sb
);
1858 sb
->s_blocksize_bits
= old_sb
->s_blocksize_bits
;
1859 sb
->s_blocksize
= old_sb
->s_blocksize
;
1860 sb
->s_maxbytes
= old_sb
->s_maxbytes
;
1862 if (server
->flags
& NFS_MOUNT_VER3
) {
1863 /* The VFS shouldn't apply the umask to mode bits. We will do
1864 * so ourselves when necessary.
1866 sb
->s_flags
|= MS_POSIXACL
;
1867 sb
->s_time_gran
= 1;
1870 sb
->s_op
= old_sb
->s_op
;
1871 nfs_initialise_sb(sb
);
1874 static int nfs_compare_mount_options(const struct super_block
*s
, const struct nfs_server
*b
, int flags
)
1876 const struct nfs_server
*a
= s
->s_fs_info
;
1877 const struct rpc_clnt
*clnt_a
= a
->client
;
1878 const struct rpc_clnt
*clnt_b
= b
->client
;
1880 if ((s
->s_flags
& NFS_MS_MASK
) != (flags
& NFS_MS_MASK
))
1882 if (a
->nfs_client
!= b
->nfs_client
)
1884 if (a
->flags
!= b
->flags
)
1886 if (a
->wsize
!= b
->wsize
)
1888 if (a
->rsize
!= b
->rsize
)
1890 if (a
->acregmin
!= b
->acregmin
)
1892 if (a
->acregmax
!= b
->acregmax
)
1894 if (a
->acdirmin
!= b
->acdirmin
)
1896 if (a
->acdirmax
!= b
->acdirmax
)
1898 if (clnt_a
->cl_auth
->au_flavor
!= clnt_b
->cl_auth
->au_flavor
)
1905 struct nfs_sb_mountdata
{
1906 struct nfs_server
*server
;
1910 static int nfs_set_super(struct super_block
*s
, void *data
)
1912 struct nfs_sb_mountdata
*sb_mntdata
= data
;
1913 struct nfs_server
*server
= sb_mntdata
->server
;
1916 s
->s_flags
= sb_mntdata
->mntflags
;
1917 s
->s_fs_info
= server
;
1918 ret
= set_anon_super(s
, server
);
1920 server
->s_dev
= s
->s_dev
;
1924 static int nfs_compare_super_address(struct nfs_server
*server1
,
1925 struct nfs_server
*server2
)
1927 struct sockaddr
*sap1
, *sap2
;
1929 sap1
= (struct sockaddr
*)&server1
->nfs_client
->cl_addr
;
1930 sap2
= (struct sockaddr
*)&server2
->nfs_client
->cl_addr
;
1932 if (sap1
->sa_family
!= sap2
->sa_family
)
1935 switch (sap1
->sa_family
) {
1937 struct sockaddr_in
*sin1
= (struct sockaddr_in
*)sap1
;
1938 struct sockaddr_in
*sin2
= (struct sockaddr_in
*)sap2
;
1939 if (sin1
->sin_addr
.s_addr
!= sin2
->sin_addr
.s_addr
)
1941 if (sin1
->sin_port
!= sin2
->sin_port
)
1946 struct sockaddr_in6
*sin1
= (struct sockaddr_in6
*)sap1
;
1947 struct sockaddr_in6
*sin2
= (struct sockaddr_in6
*)sap2
;
1948 if (!ipv6_addr_equal(&sin1
->sin6_addr
, &sin2
->sin6_addr
))
1950 if (sin1
->sin6_port
!= sin2
->sin6_port
)
1961 static int nfs_compare_super(struct super_block
*sb
, void *data
)
1963 struct nfs_sb_mountdata
*sb_mntdata
= data
;
1964 struct nfs_server
*server
= sb_mntdata
->server
, *old
= NFS_SB(sb
);
1965 int mntflags
= sb_mntdata
->mntflags
;
1967 if (!nfs_compare_super_address(old
, server
))
1969 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1970 if (old
->flags
& NFS_MOUNT_UNSHARED
)
1972 if (memcmp(&old
->fsid
, &server
->fsid
, sizeof(old
->fsid
)) != 0)
1974 return nfs_compare_mount_options(sb
, server
, mntflags
);
1977 static int nfs_bdi_register(struct nfs_server
*server
)
1979 return bdi_register_dev(&server
->backing_dev_info
, server
->s_dev
);
1982 static int nfs_get_sb(struct file_system_type
*fs_type
,
1983 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
1985 struct nfs_server
*server
= NULL
;
1986 struct super_block
*s
;
1987 struct nfs_parsed_mount_data
*data
;
1988 struct nfs_fh
*mntfh
;
1989 struct dentry
*mntroot
;
1990 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
1991 struct nfs_sb_mountdata sb_mntdata
= {
1994 int error
= -ENOMEM
;
1996 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
1997 mntfh
= kzalloc(sizeof(*mntfh
), GFP_KERNEL
);
1998 if (data
== NULL
|| mntfh
== NULL
)
2001 security_init_mnt_opts(&data
->lsm_opts
);
2003 /* Validate the mount data */
2004 error
= nfs_validate_mount_data(raw_data
, data
, mntfh
, dev_name
);
2008 /* Get a volume representation */
2009 server
= nfs_create_server(data
, mntfh
);
2010 if (IS_ERR(server
)) {
2011 error
= PTR_ERR(server
);
2014 sb_mntdata
.server
= server
;
2016 if (server
->flags
& NFS_MOUNT_UNSHARED
)
2017 compare_super
= NULL
;
2019 /* Get a superblock - note that we may end up sharing one that already exists */
2020 s
= sget(fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2026 if (s
->s_fs_info
!= server
) {
2027 nfs_free_server(server
);
2030 error
= nfs_bdi_register(server
);
2032 goto error_splat_super
;
2036 /* initial superblock/root creation */
2037 nfs_fill_super(s
, data
);
2038 nfs_fscache_get_super_cookie(s
, data
);
2041 mntroot
= nfs_get_root(s
, mntfh
);
2042 if (IS_ERR(mntroot
)) {
2043 error
= PTR_ERR(mntroot
);
2044 goto error_splat_super
;
2047 error
= security_sb_set_mnt_opts(s
, &data
->lsm_opts
);
2049 goto error_splat_root
;
2051 s
->s_flags
|= MS_ACTIVE
;
2053 mnt
->mnt_root
= mntroot
;
2057 kfree(data
->nfs_server
.hostname
);
2058 kfree(data
->mount_server
.hostname
);
2059 kfree(data
->fscache_uniq
);
2060 security_free_mnt_opts(&data
->lsm_opts
);
2067 nfs_free_server(server
);
2073 up_write(&s
->s_umount
);
2074 deactivate_super(s
);
2079 * Destroy an NFS2/3 superblock
2081 static void nfs_kill_super(struct super_block
*s
)
2083 struct nfs_server
*server
= NFS_SB(s
);
2085 bdi_unregister(&server
->backing_dev_info
);
2087 nfs_fscache_release_super_cookie(s
);
2088 nfs_free_server(server
);
2092 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2094 static int nfs_xdev_get_sb(struct file_system_type
*fs_type
, int flags
,
2095 const char *dev_name
, void *raw_data
,
2096 struct vfsmount
*mnt
)
2098 struct nfs_clone_mount
*data
= raw_data
;
2099 struct super_block
*s
;
2100 struct nfs_server
*server
;
2101 struct dentry
*mntroot
;
2102 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2103 struct nfs_sb_mountdata sb_mntdata
= {
2108 dprintk("--> nfs_xdev_get_sb()\n");
2110 /* create a new volume representation */
2111 server
= nfs_clone_server(NFS_SB(data
->sb
), data
->fh
, data
->fattr
);
2112 if (IS_ERR(server
)) {
2113 error
= PTR_ERR(server
);
2114 goto out_err_noserver
;
2116 sb_mntdata
.server
= server
;
2118 if (server
->flags
& NFS_MOUNT_UNSHARED
)
2119 compare_super
= NULL
;
2121 /* Get a superblock - note that we may end up sharing one that already exists */
2122 s
= sget(&nfs_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2128 if (s
->s_fs_info
!= server
) {
2129 nfs_free_server(server
);
2132 error
= nfs_bdi_register(server
);
2134 goto error_splat_super
;
2138 /* initial superblock/root creation */
2139 nfs_clone_super(s
, data
->sb
);
2142 mntroot
= nfs_get_root(s
, data
->fh
);
2143 if (IS_ERR(mntroot
)) {
2144 error
= PTR_ERR(mntroot
);
2145 goto error_splat_super
;
2147 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
2150 goto error_splat_super
;
2153 s
->s_flags
|= MS_ACTIVE
;
2155 mnt
->mnt_root
= mntroot
;
2157 /* clone any lsm security options from the parent to the new sb */
2158 security_sb_clone_mnt_opts(data
->sb
, s
);
2160 dprintk("<-- nfs_xdev_get_sb() = 0\n");
2164 nfs_free_server(server
);
2166 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error
);
2170 up_write(&s
->s_umount
);
2171 deactivate_super(s
);
2172 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error
);
2176 #ifdef CONFIG_NFS_V4
2179 * Finish setting up a cloned NFS4 superblock
2181 static void nfs4_clone_super(struct super_block
*sb
,
2182 const struct super_block
*old_sb
)
2184 sb
->s_blocksize_bits
= old_sb
->s_blocksize_bits
;
2185 sb
->s_blocksize
= old_sb
->s_blocksize
;
2186 sb
->s_maxbytes
= old_sb
->s_maxbytes
;
2187 sb
->s_time_gran
= 1;
2188 sb
->s_op
= old_sb
->s_op
;
2189 nfs_initialise_sb(sb
);
2193 * Set up an NFS4 superblock
2195 static void nfs4_fill_super(struct super_block
*sb
)
2197 sb
->s_time_gran
= 1;
2198 sb
->s_op
= &nfs4_sops
;
2199 nfs_initialise_sb(sb
);
2203 * Validate NFSv4 mount options
2205 static int nfs4_validate_mount_data(void *options
,
2206 struct nfs_parsed_mount_data
*args
,
2207 const char *dev_name
)
2209 struct sockaddr_in
*ap
;
2210 struct nfs4_mount_data
*data
= (struct nfs4_mount_data
*)options
;
2216 args
->rsize
= NFS_MAX_FILE_IO_SIZE
;
2217 args
->wsize
= NFS_MAX_FILE_IO_SIZE
;
2218 args
->acregmin
= NFS_DEF_ACREGMIN
;
2219 args
->acregmax
= NFS_DEF_ACREGMAX
;
2220 args
->acdirmin
= NFS_DEF_ACDIRMIN
;
2221 args
->acdirmax
= NFS_DEF_ACDIRMAX
;
2222 args
->nfs_server
.port
= NFS_PORT
; /* 2049 unless user set port= */
2223 args
->auth_flavors
[0] = RPC_AUTH_UNIX
;
2224 args
->auth_flavor_len
= 0;
2226 switch (data
->version
) {
2228 ap
= (struct sockaddr_in
*)&args
->nfs_server
.address
;
2229 if (data
->host_addrlen
> sizeof(args
->nfs_server
.address
))
2230 goto out_no_address
;
2231 if (data
->host_addrlen
== 0)
2232 goto out_no_address
;
2233 args
->nfs_server
.addrlen
= data
->host_addrlen
;
2234 if (copy_from_user(ap
, data
->host_addr
, data
->host_addrlen
))
2236 if (!nfs_verify_server_address((struct sockaddr
*)
2237 &args
->nfs_server
.address
))
2238 goto out_no_address
;
2240 if (data
->auth_flavourlen
) {
2241 if (data
->auth_flavourlen
> 1)
2242 goto out_inval_auth
;
2243 if (copy_from_user(&args
->auth_flavors
[0],
2244 data
->auth_flavours
,
2245 sizeof(args
->auth_flavors
[0])))
2249 c
= strndup_user(data
->hostname
.data
, NFS4_MAXNAMLEN
);
2252 args
->nfs_server
.hostname
= c
;
2254 c
= strndup_user(data
->mnt_path
.data
, NFS4_MAXPATHLEN
);
2257 args
->nfs_server
.export_path
= c
;
2258 dfprintk(MOUNT
, "NFS: MNTPATH: '%s'\n", c
);
2260 c
= strndup_user(data
->client_addr
.data
, 16);
2263 args
->client_address
= c
;
2266 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2270 args
->flags
= data
->flags
& NFS4_MOUNT_FLAGMASK
;
2271 args
->rsize
= data
->rsize
;
2272 args
->wsize
= data
->wsize
;
2273 args
->timeo
= data
->timeo
;
2274 args
->retrans
= data
->retrans
;
2275 args
->acregmin
= data
->acregmin
;
2276 args
->acregmax
= data
->acregmax
;
2277 args
->acdirmin
= data
->acdirmin
;
2278 args
->acdirmax
= data
->acdirmax
;
2279 args
->nfs_server
.protocol
= data
->proto
;
2280 nfs_validate_transport_protocol(args
);
2286 if (nfs_parse_mount_options((char *)options
, args
) == 0)
2289 if (!nfs_verify_server_address((struct sockaddr
*)
2290 &args
->nfs_server
.address
))
2293 nfs_set_port((struct sockaddr
*)&args
->nfs_server
.address
,
2294 args
->nfs_server
.port
);
2296 nfs_validate_transport_protocol(args
);
2298 if (args
->auth_flavor_len
> 1)
2299 goto out_inval_auth
;
2301 if (args
->client_address
== NULL
)
2302 goto out_no_client_address
;
2304 status
= nfs_parse_devname(dev_name
,
2305 &args
->nfs_server
.hostname
,
2307 &args
->nfs_server
.export_path
,
2319 dfprintk(MOUNT
, "NFS4: mount program didn't pass any mount data\n");
2323 dfprintk(MOUNT
, "NFS4: Invalid number of RPC auth flavours %d\n",
2324 data
->auth_flavourlen
);
2328 dfprintk(MOUNT
, "NFS4: mount program didn't pass remote address\n");
2331 out_no_client_address
:
2332 dfprintk(MOUNT
, "NFS4: mount program didn't pass callback address\n");
2337 * Get the superblock for an NFS4 mountpoint
2339 static int nfs4_get_sb(struct file_system_type
*fs_type
,
2340 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
2342 struct nfs_parsed_mount_data
*data
;
2343 struct super_block
*s
;
2344 struct nfs_server
*server
;
2345 struct nfs_fh
*mntfh
;
2346 struct dentry
*mntroot
;
2347 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2348 struct nfs_sb_mountdata sb_mntdata
= {
2351 int error
= -ENOMEM
;
2353 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
2354 mntfh
= kzalloc(sizeof(*mntfh
), GFP_KERNEL
);
2355 if (data
== NULL
|| mntfh
== NULL
)
2358 security_init_mnt_opts(&data
->lsm_opts
);
2360 /* Validate the mount data */
2361 error
= nfs4_validate_mount_data(raw_data
, data
, dev_name
);
2365 /* Get a volume representation */
2366 server
= nfs4_create_server(data
, mntfh
);
2367 if (IS_ERR(server
)) {
2368 error
= PTR_ERR(server
);
2371 sb_mntdata
.server
= server
;
2373 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2374 compare_super
= NULL
;
2376 /* Get a superblock - note that we may end up sharing one that already exists */
2377 s
= sget(fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2383 if (s
->s_fs_info
!= server
) {
2384 nfs_free_server(server
);
2387 error
= nfs_bdi_register(server
);
2389 goto error_splat_super
;
2393 /* initial superblock/root creation */
2395 nfs_fscache_get_super_cookie(s
, data
);
2398 mntroot
= nfs4_get_root(s
, mntfh
);
2399 if (IS_ERR(mntroot
)) {
2400 error
= PTR_ERR(mntroot
);
2401 goto error_splat_super
;
2404 error
= security_sb_set_mnt_opts(s
, &data
->lsm_opts
);
2406 goto error_splat_root
;
2408 s
->s_flags
|= MS_ACTIVE
;
2410 mnt
->mnt_root
= mntroot
;
2414 kfree(data
->client_address
);
2415 kfree(data
->nfs_server
.export_path
);
2416 kfree(data
->nfs_server
.hostname
);
2417 kfree(data
->fscache_uniq
);
2418 security_free_mnt_opts(&data
->lsm_opts
);
2425 nfs_free_server(server
);
2431 up_write(&s
->s_umount
);
2432 deactivate_super(s
);
2436 static void nfs4_kill_super(struct super_block
*sb
)
2438 struct nfs_server
*server
= NFS_SB(sb
);
2440 nfs_super_return_all_delegations(sb
);
2441 kill_anon_super(sb
);
2443 nfs4_renewd_prepare_shutdown(server
);
2444 nfs_fscache_release_super_cookie(sb
);
2445 nfs_free_server(server
);
2449 * Clone an NFS4 server record on xdev traversal (FSID-change)
2451 static int nfs4_xdev_get_sb(struct file_system_type
*fs_type
, int flags
,
2452 const char *dev_name
, void *raw_data
,
2453 struct vfsmount
*mnt
)
2455 struct nfs_clone_mount
*data
= raw_data
;
2456 struct super_block
*s
;
2457 struct nfs_server
*server
;
2458 struct dentry
*mntroot
;
2459 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2460 struct nfs_sb_mountdata sb_mntdata
= {
2465 dprintk("--> nfs4_xdev_get_sb()\n");
2467 /* create a new volume representation */
2468 server
= nfs_clone_server(NFS_SB(data
->sb
), data
->fh
, data
->fattr
);
2469 if (IS_ERR(server
)) {
2470 error
= PTR_ERR(server
);
2471 goto out_err_noserver
;
2473 sb_mntdata
.server
= server
;
2475 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2476 compare_super
= NULL
;
2478 /* Get a superblock - note that we may end up sharing one that already exists */
2479 s
= sget(&nfs4_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2485 if (s
->s_fs_info
!= server
) {
2486 nfs_free_server(server
);
2489 error
= nfs_bdi_register(server
);
2491 goto error_splat_super
;
2495 /* initial superblock/root creation */
2496 nfs4_clone_super(s
, data
->sb
);
2499 mntroot
= nfs4_get_root(s
, data
->fh
);
2500 if (IS_ERR(mntroot
)) {
2501 error
= PTR_ERR(mntroot
);
2502 goto error_splat_super
;
2504 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
2507 goto error_splat_super
;
2510 s
->s_flags
|= MS_ACTIVE
;
2512 mnt
->mnt_root
= mntroot
;
2514 security_sb_clone_mnt_opts(data
->sb
, s
);
2516 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2520 nfs_free_server(server
);
2522 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error
);
2526 up_write(&s
->s_umount
);
2527 deactivate_super(s
);
2528 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error
);
2533 * Create an NFS4 server record on referral traversal
2535 static int nfs4_referral_get_sb(struct file_system_type
*fs_type
, int flags
,
2536 const char *dev_name
, void *raw_data
,
2537 struct vfsmount
*mnt
)
2539 struct nfs_clone_mount
*data
= raw_data
;
2540 struct super_block
*s
;
2541 struct nfs_server
*server
;
2542 struct dentry
*mntroot
;
2543 struct nfs_fh mntfh
;
2544 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2545 struct nfs_sb_mountdata sb_mntdata
= {
2550 dprintk("--> nfs4_referral_get_sb()\n");
2552 /* create a new volume representation */
2553 server
= nfs4_create_referral_server(data
, &mntfh
);
2554 if (IS_ERR(server
)) {
2555 error
= PTR_ERR(server
);
2556 goto out_err_noserver
;
2558 sb_mntdata
.server
= server
;
2560 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2561 compare_super
= NULL
;
2563 /* Get a superblock - note that we may end up sharing one that already exists */
2564 s
= sget(&nfs4_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2570 if (s
->s_fs_info
!= server
) {
2571 nfs_free_server(server
);
2574 error
= nfs_bdi_register(server
);
2576 goto error_splat_super
;
2580 /* initial superblock/root creation */
2584 mntroot
= nfs4_get_root(s
, &mntfh
);
2585 if (IS_ERR(mntroot
)) {
2586 error
= PTR_ERR(mntroot
);
2587 goto error_splat_super
;
2589 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
2592 goto error_splat_super
;
2595 s
->s_flags
|= MS_ACTIVE
;
2597 mnt
->mnt_root
= mntroot
;
2599 security_sb_clone_mnt_opts(data
->sb
, s
);
2601 dprintk("<-- nfs4_referral_get_sb() = 0\n");
2605 nfs_free_server(server
);
2607 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error
);
2611 up_write(&s
->s_umount
);
2612 deactivate_super(s
);
2613 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error
);
2617 #endif /* CONFIG_NFS_V4 */