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
];
645 #ifdef CONFIG_NFS_FSCACHE
646 for (i
= 0; i
< __NFSIOS_FSCACHEMAX
; i
++)
647 totals
.fscache
[i
] += stats
->fscache
[i
];
653 seq_printf(m
, "\n\tevents:\t");
654 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
655 seq_printf(m
, "%lu ", totals
.events
[i
]);
656 seq_printf(m
, "\n\tbytes:\t");
657 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
658 seq_printf(m
, "%Lu ", totals
.bytes
[i
]);
659 #ifdef CONFIG_NFS_FSCACHE
660 if (nfss
->options
& NFS_OPTION_FSCACHE
) {
661 seq_printf(m
, "\n\tfsc:\t");
662 for (i
= 0; i
< __NFSIOS_FSCACHEMAX
; i
++)
663 seq_printf(m
, "%Lu ", totals
.bytes
[i
]);
668 rpc_print_iostats(m
, nfss
->client
);
674 * Begin unmount by attempting to remove all automounted mountpoints we added
675 * in response to xdev traversals and referrals
677 static void nfs_umount_begin(struct super_block
*sb
)
679 struct nfs_server
*server
= NFS_SB(sb
);
680 struct rpc_clnt
*rpc
;
682 /* -EIO all pending I/O */
683 rpc
= server
->client_acl
;
685 rpc_killall_tasks(rpc
);
686 rpc
= server
->client
;
688 rpc_killall_tasks(rpc
);
692 * Sanity-check a server address provided by the mount command.
694 * Address family must be initialized, and address must not be
695 * the ANY address for that family.
697 static int nfs_verify_server_address(struct sockaddr
*addr
)
699 switch (addr
->sa_family
) {
701 struct sockaddr_in
*sa
= (struct sockaddr_in
*)addr
;
702 return sa
->sin_addr
.s_addr
!= htonl(INADDR_ANY
);
705 struct in6_addr
*sa
= &((struct sockaddr_in6
*)addr
)->sin6_addr
;
706 return !ipv6_addr_any(sa
);
713 static void nfs_parse_ipv4_address(char *string
, size_t str_len
,
714 struct sockaddr
*sap
, size_t *addr_len
)
716 struct sockaddr_in
*sin
= (struct sockaddr_in
*)sap
;
717 u8
*addr
= (u8
*)&sin
->sin_addr
.s_addr
;
719 if (str_len
<= INET_ADDRSTRLEN
) {
720 dfprintk(MOUNT
, "NFS: parsing IPv4 address %*s\n",
721 (int)str_len
, string
);
723 sin
->sin_family
= AF_INET
;
724 *addr_len
= sizeof(*sin
);
725 if (in4_pton(string
, str_len
, addr
, '\0', NULL
))
729 sap
->sa_family
= AF_UNSPEC
;
733 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
734 static int nfs_parse_ipv6_scope_id(const char *string
, const size_t str_len
,
736 struct sockaddr_in6
*sin6
)
741 if ((string
+ str_len
) == delim
)
744 if (*delim
!= IPV6_SCOPE_DELIMITER
)
747 if (!(ipv6_addr_type(&sin6
->sin6_addr
) & IPV6_ADDR_LINKLOCAL
))
750 len
= (string
+ str_len
) - delim
- 1;
751 p
= kstrndup(delim
+ 1, len
, GFP_KERNEL
);
753 unsigned long scope_id
= 0;
754 struct net_device
*dev
;
756 dev
= dev_get_by_name(&init_net
, p
);
758 scope_id
= dev
->ifindex
;
761 if (strict_strtoul(p
, 10, &scope_id
) == 0) {
769 sin6
->sin6_scope_id
= scope_id
;
770 dfprintk(MOUNT
, "NFS: IPv6 scope ID = %lu\n", scope_id
);
777 static void nfs_parse_ipv6_address(char *string
, size_t str_len
,
778 struct sockaddr
*sap
, size_t *addr_len
)
780 struct sockaddr_in6
*sin6
= (struct sockaddr_in6
*)sap
;
781 u8
*addr
= (u8
*)&sin6
->sin6_addr
.in6_u
;
784 if (str_len
<= INET6_ADDRSTRLEN
) {
785 dfprintk(MOUNT
, "NFS: parsing IPv6 address %*s\n",
786 (int)str_len
, string
);
788 sin6
->sin6_family
= AF_INET6
;
789 *addr_len
= sizeof(*sin6
);
790 if (in6_pton(string
, str_len
, addr
,
791 IPV6_SCOPE_DELIMITER
, &delim
) != 0) {
792 if (nfs_parse_ipv6_scope_id(string
, str_len
,
798 sap
->sa_family
= AF_UNSPEC
;
802 static void nfs_parse_ipv6_address(char *string
, size_t str_len
,
803 struct sockaddr
*sap
, size_t *addr_len
)
805 sap
->sa_family
= AF_UNSPEC
;
811 * Construct a sockaddr based on the contents of a string that contains
812 * an IP address in presentation format.
814 * If there is a problem constructing the new sockaddr, set the address
815 * family to AF_UNSPEC.
817 void nfs_parse_ip_address(char *string
, size_t str_len
,
818 struct sockaddr
*sap
, size_t *addr_len
)
820 unsigned int i
, colons
;
823 for (i
= 0; i
< str_len
; i
++)
824 if (string
[i
] == ':')
828 nfs_parse_ipv6_address(string
, str_len
, sap
, addr_len
);
830 nfs_parse_ipv4_address(string
, str_len
, sap
, addr_len
);
834 * Sanity check the NFS transport protocol.
837 static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data
*mnt
)
839 switch (mnt
->nfs_server
.protocol
) {
840 case XPRT_TRANSPORT_UDP
:
841 case XPRT_TRANSPORT_TCP
:
842 case XPRT_TRANSPORT_RDMA
:
845 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
850 * For text based NFSv2/v3 mounts, the mount protocol transport default
851 * settings should depend upon the specified NFS transport.
853 static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data
*mnt
)
855 nfs_validate_transport_protocol(mnt
);
857 if (mnt
->mount_server
.protocol
== XPRT_TRANSPORT_UDP
||
858 mnt
->mount_server
.protocol
== XPRT_TRANSPORT_TCP
)
860 switch (mnt
->nfs_server
.protocol
) {
861 case XPRT_TRANSPORT_UDP
:
862 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_UDP
;
864 case XPRT_TRANSPORT_TCP
:
865 case XPRT_TRANSPORT_RDMA
:
866 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_TCP
;
871 * Parse the value of the 'sec=' option.
873 * The flavor_len setting is for v4 mounts.
875 static int nfs_parse_security_flavors(char *value
,
876 struct nfs_parsed_mount_data
*mnt
)
878 substring_t args
[MAX_OPT_ARGS
];
880 dfprintk(MOUNT
, "NFS: parsing sec=%s option\n", value
);
882 switch (match_token(value
, nfs_secflavor_tokens
, args
)) {
884 mnt
->auth_flavor_len
= 0;
885 mnt
->auth_flavors
[0] = RPC_AUTH_NULL
;
888 mnt
->auth_flavor_len
= 0;
889 mnt
->auth_flavors
[0] = RPC_AUTH_UNIX
;
892 mnt
->auth_flavor_len
= 1;
893 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5
;
896 mnt
->auth_flavor_len
= 1;
897 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5I
;
900 mnt
->auth_flavor_len
= 1;
901 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5P
;
904 mnt
->auth_flavor_len
= 1;
905 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEY
;
908 mnt
->auth_flavor_len
= 1;
909 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEYI
;
912 mnt
->auth_flavor_len
= 1;
913 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEYP
;
916 mnt
->auth_flavor_len
= 1;
917 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKM
;
920 mnt
->auth_flavor_len
= 1;
921 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKMI
;
924 mnt
->auth_flavor_len
= 1;
925 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKMP
;
934 static void nfs_parse_invalid_value(const char *option
)
936 dfprintk(MOUNT
, "NFS: bad value specified for %s option\n", option
);
940 * Error-check and convert a string of mount options from user space into
941 * a data structure. The whole mount string is processed; bad options are
942 * skipped as they are encountered. If there were no errors, return 1;
943 * otherwise return 0 (zero).
945 static int nfs_parse_mount_options(char *raw
,
946 struct nfs_parsed_mount_data
*mnt
)
948 char *p
, *string
, *secdata
;
949 int rc
, sloppy
= 0, errors
= 0;
952 dfprintk(MOUNT
, "NFS: mount options string was NULL.\n");
955 dfprintk(MOUNT
, "NFS: nfs mount opts='%s'\n", raw
);
957 secdata
= alloc_secdata();
961 rc
= security_sb_copy_data(raw
, secdata
);
963 goto out_security_failure
;
965 rc
= security_sb_parse_opts_str(secdata
, &mnt
->lsm_opts
);
967 goto out_security_failure
;
969 free_secdata(secdata
);
971 while ((p
= strsep(&raw
, ",")) != NULL
) {
972 substring_t args
[MAX_OPT_ARGS
];
978 dfprintk(MOUNT
, "NFS: parsing nfs mount option '%s'\n", p
);
980 token
= match_token(p
, nfs_mount_option_tokens
, args
);
984 * boolean options: foo/nofoo
987 mnt
->flags
|= NFS_MOUNT_SOFT
;
990 mnt
->flags
&= ~NFS_MOUNT_SOFT
;
993 mnt
->flags
|= NFS_MOUNT_POSIX
;
996 mnt
->flags
&= ~NFS_MOUNT_POSIX
;
999 mnt
->flags
&= ~NFS_MOUNT_NOCTO
;
1002 mnt
->flags
|= NFS_MOUNT_NOCTO
;
1005 mnt
->flags
&= ~NFS_MOUNT_NOAC
;
1008 mnt
->flags
|= NFS_MOUNT_NOAC
;
1011 mnt
->flags
&= ~NFS_MOUNT_NONLM
;
1014 mnt
->flags
|= NFS_MOUNT_NONLM
;
1017 mnt
->flags
&= ~NFS_MOUNT_VER3
;
1020 mnt
->flags
|= NFS_MOUNT_VER3
;
1023 mnt
->flags
&= ~NFS_MOUNT_TCP
;
1024 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1027 mnt
->flags
|= NFS_MOUNT_TCP
;
1028 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1031 mnt
->flags
|= NFS_MOUNT_TCP
; /* for side protocols */
1032 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_RDMA
;
1033 xprt_load_transport(p
);
1036 mnt
->flags
&= ~NFS_MOUNT_NOACL
;
1039 mnt
->flags
|= NFS_MOUNT_NOACL
;
1042 mnt
->flags
&= ~NFS_MOUNT_NORDIRPLUS
;
1044 case Opt_nordirplus
:
1045 mnt
->flags
|= NFS_MOUNT_NORDIRPLUS
;
1047 case Opt_sharecache
:
1048 mnt
->flags
&= ~NFS_MOUNT_UNSHARED
;
1050 case Opt_nosharecache
:
1051 mnt
->flags
|= NFS_MOUNT_UNSHARED
;
1054 mnt
->flags
&= ~NFS_MOUNT_NORESVPORT
;
1056 case Opt_noresvport
:
1057 mnt
->flags
|= NFS_MOUNT_NORESVPORT
;
1061 * options that take numeric values
1064 if (match_int(args
, &option
) ||
1065 option
< 0 || option
> USHORT_MAX
) {
1067 nfs_parse_invalid_value("port");
1069 mnt
->nfs_server
.port
= option
;
1072 if (match_int(args
, &option
) || option
< 0) {
1074 nfs_parse_invalid_value("rsize");
1076 mnt
->rsize
= option
;
1079 if (match_int(args
, &option
) || option
< 0) {
1081 nfs_parse_invalid_value("wsize");
1083 mnt
->wsize
= option
;
1086 if (match_int(args
, &option
) || option
< 0) {
1088 nfs_parse_invalid_value("bsize");
1090 mnt
->bsize
= option
;
1093 if (match_int(args
, &option
) || option
<= 0) {
1095 nfs_parse_invalid_value("timeo");
1097 mnt
->timeo
= option
;
1100 if (match_int(args
, &option
) || option
<= 0) {
1102 nfs_parse_invalid_value("retrans");
1104 mnt
->retrans
= option
;
1107 if (match_int(args
, &option
) || option
< 0) {
1109 nfs_parse_invalid_value("acregmin");
1111 mnt
->acregmin
= option
;
1114 if (match_int(args
, &option
) || option
< 0) {
1116 nfs_parse_invalid_value("acregmax");
1118 mnt
->acregmax
= option
;
1121 if (match_int(args
, &option
) || option
< 0) {
1123 nfs_parse_invalid_value("acdirmin");
1125 mnt
->acdirmin
= option
;
1128 if (match_int(args
, &option
) || option
< 0) {
1130 nfs_parse_invalid_value("acdirmax");
1132 mnt
->acdirmax
= option
;
1135 if (match_int(args
, &option
) || option
< 0) {
1137 nfs_parse_invalid_value("actimeo");
1139 mnt
->acregmin
= mnt
->acregmax
=
1140 mnt
->acdirmin
= mnt
->acdirmax
= option
;
1143 if (match_int(args
, &option
) || option
< 0) {
1145 nfs_parse_invalid_value("namlen");
1147 mnt
->namlen
= option
;
1150 if (match_int(args
, &option
) ||
1151 option
< 0 || option
> USHORT_MAX
) {
1153 nfs_parse_invalid_value("mountport");
1155 mnt
->mount_server
.port
= option
;
1158 if (match_int(args
, &option
) ||
1159 option
< NFS_MNT_VERSION
||
1160 option
> NFS_MNT3_VERSION
) {
1162 nfs_parse_invalid_value("mountvers");
1164 mnt
->mount_server
.version
= option
;
1167 if (match_int(args
, &option
)) {
1169 nfs_parse_invalid_value("nfsvers");
1174 mnt
->flags
&= ~NFS_MOUNT_VER3
;
1177 mnt
->flags
|= NFS_MOUNT_VER3
;
1181 nfs_parse_invalid_value("nfsvers");
1186 * options that take text values
1189 string
= match_strdup(args
);
1192 rc
= nfs_parse_security_flavors(string
, mnt
);
1196 dfprintk(MOUNT
, "NFS: unrecognized "
1197 "security flavor\n");
1201 string
= match_strdup(args
);
1204 token
= match_token(string
,
1205 nfs_xprt_protocol_tokens
, args
);
1210 mnt
->flags
&= ~NFS_MOUNT_TCP
;
1211 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1214 mnt
->flags
|= NFS_MOUNT_TCP
;
1215 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1218 /* vector side protocols to TCP */
1219 mnt
->flags
|= NFS_MOUNT_TCP
;
1220 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_RDMA
;
1221 xprt_load_transport(string
);
1225 dfprintk(MOUNT
, "NFS: unrecognized "
1226 "transport protocol\n");
1230 case Opt_mountproto
:
1231 string
= match_strdup(args
);
1234 token
= match_token(string
,
1235 nfs_xprt_protocol_tokens
, args
);
1239 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_UDP
;
1242 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_TCP
;
1244 case Opt_xprt_rdma
: /* not used for side protocols */
1247 dfprintk(MOUNT
, "NFS: unrecognized "
1248 "transport protocol\n");
1252 string
= match_strdup(args
);
1255 nfs_parse_ip_address(string
, strlen(string
),
1257 &mnt
->nfs_server
.address
,
1258 &mnt
->nfs_server
.addrlen
);
1261 case Opt_clientaddr
:
1262 string
= match_strdup(args
);
1265 kfree(mnt
->client_address
);
1266 mnt
->client_address
= string
;
1269 string
= match_strdup(args
);
1272 kfree(mnt
->mount_server
.hostname
);
1273 mnt
->mount_server
.hostname
= string
;
1276 string
= match_strdup(args
);
1279 nfs_parse_ip_address(string
, strlen(string
),
1281 &mnt
->mount_server
.address
,
1282 &mnt
->mount_server
.addrlen
);
1285 case Opt_lookupcache
:
1286 string
= match_strdup(args
);
1289 token
= match_token(string
,
1290 nfs_lookupcache_tokens
, args
);
1293 case Opt_lookupcache_all
:
1294 mnt
->flags
&= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG
|NFS_MOUNT_LOOKUP_CACHE_NONE
);
1296 case Opt_lookupcache_positive
:
1297 mnt
->flags
&= ~NFS_MOUNT_LOOKUP_CACHE_NONE
;
1298 mnt
->flags
|= NFS_MOUNT_LOOKUP_CACHE_NONEG
;
1300 case Opt_lookupcache_none
:
1301 mnt
->flags
|= NFS_MOUNT_LOOKUP_CACHE_NONEG
|NFS_MOUNT_LOOKUP_CACHE_NONE
;
1305 dfprintk(MOUNT
, "NFS: invalid "
1306 "lookupcache argument\n");
1315 dfprintk(MOUNT
, "NFS: relaxing parsing rules\n");
1318 case Opt_deprecated
:
1319 dfprintk(MOUNT
, "NFS: ignoring mount option "
1325 dfprintk(MOUNT
, "NFS: unrecognized mount option "
1331 dfprintk(MOUNT
, "NFS: parsing encountered %d error%s\n",
1332 errors
, (errors
== 1 ? "" : "s"));
1339 printk(KERN_INFO
"NFS: not enough memory to parse option\n");
1341 out_security_failure
:
1342 free_secdata(secdata
);
1343 printk(KERN_INFO
"NFS: security options invalid: %d\n", rc
);
1348 * Use the remote server's MOUNT service to request the NFS file handle
1349 * corresponding to the provided path.
1351 static int nfs_try_mount(struct nfs_parsed_mount_data
*args
,
1352 struct nfs_fh
*root_fh
)
1354 struct nfs_mount_request request
= {
1355 .sap
= (struct sockaddr
*)
1356 &args
->mount_server
.address
,
1357 .dirpath
= args
->nfs_server
.export_path
,
1358 .protocol
= args
->mount_server
.protocol
,
1360 .noresvport
= args
->flags
& NFS_MOUNT_NORESVPORT
,
1364 if (args
->mount_server
.version
== 0) {
1365 if (args
->flags
& NFS_MOUNT_VER3
)
1366 args
->mount_server
.version
= NFS_MNT3_VERSION
;
1368 args
->mount_server
.version
= NFS_MNT_VERSION
;
1370 request
.version
= args
->mount_server
.version
;
1372 if (args
->mount_server
.hostname
)
1373 request
.hostname
= args
->mount_server
.hostname
;
1375 request
.hostname
= args
->nfs_server
.hostname
;
1378 * Construct the mount server's address.
1380 if (args
->mount_server
.address
.ss_family
== AF_UNSPEC
) {
1381 memcpy(request
.sap
, &args
->nfs_server
.address
,
1382 args
->nfs_server
.addrlen
);
1383 args
->mount_server
.addrlen
= args
->nfs_server
.addrlen
;
1385 request
.salen
= args
->mount_server
.addrlen
;
1388 * autobind will be used if mount_server.port == 0
1390 nfs_set_port(request
.sap
, args
->mount_server
.port
);
1393 * Now ask the mount server to map our export path
1396 status
= nfs_mount(&request
);
1400 dfprintk(MOUNT
, "NFS: unable to mount server %s, error %d\n",
1401 request
.hostname
, status
);
1405 static int nfs_parse_simple_hostname(const char *dev_name
,
1406 char **hostname
, size_t maxnamlen
,
1407 char **export_path
, size_t maxpathlen
)
1410 char *colon
, *comma
;
1412 colon
= strchr(dev_name
, ':');
1414 goto out_bad_devname
;
1416 len
= colon
- dev_name
;
1417 if (len
> maxnamlen
)
1420 /* N.B. caller will free nfs_server.hostname in all cases */
1421 *hostname
= kstrndup(dev_name
, len
, GFP_KERNEL
);
1425 /* kill possible hostname list: not supported */
1426 comma
= strchr(*hostname
, ',');
1427 if (comma
!= NULL
) {
1428 if (comma
== *hostname
)
1429 goto out_bad_devname
;
1434 len
= strlen(colon
);
1435 if (len
> maxpathlen
)
1437 *export_path
= kstrndup(colon
, len
, GFP_KERNEL
);
1441 dfprintk(MOUNT
, "NFS: MNTPATH: '%s'\n", *export_path
);
1445 dfprintk(MOUNT
, "NFS: device name not in host:path format\n");
1449 dfprintk(MOUNT
, "NFS: not enough memory to parse device name\n");
1453 dfprintk(MOUNT
, "NFS: server hostname too long\n");
1454 return -ENAMETOOLONG
;
1457 dfprintk(MOUNT
, "NFS: export pathname too long\n");
1458 return -ENAMETOOLONG
;
1462 * Hostname has square brackets around it because it contains one or
1463 * more colons. We look for the first closing square bracket, and a
1464 * colon must follow it.
1466 static int nfs_parse_protected_hostname(const char *dev_name
,
1467 char **hostname
, size_t maxnamlen
,
1468 char **export_path
, size_t maxpathlen
)
1473 start
= (char *)(dev_name
+ 1);
1475 end
= strchr(start
, ']');
1477 goto out_bad_devname
;
1478 if (*(end
+ 1) != ':')
1479 goto out_bad_devname
;
1482 if (len
> maxnamlen
)
1485 /* N.B. caller will free nfs_server.hostname in all cases */
1486 *hostname
= kstrndup(start
, len
, GFP_KERNEL
);
1487 if (*hostname
== NULL
)
1492 if (len
> maxpathlen
)
1494 *export_path
= kstrndup(end
, len
, GFP_KERNEL
);
1501 dfprintk(MOUNT
, "NFS: device name not in host:path format\n");
1505 dfprintk(MOUNT
, "NFS: not enough memory to parse device name\n");
1509 dfprintk(MOUNT
, "NFS: server hostname too long\n");
1510 return -ENAMETOOLONG
;
1513 dfprintk(MOUNT
, "NFS: export pathname too long\n");
1514 return -ENAMETOOLONG
;
1518 * Split "dev_name" into "hostname:export_path".
1520 * The leftmost colon demarks the split between the server's hostname
1521 * and the export path. If the hostname starts with a left square
1522 * bracket, then it may contain colons.
1524 * Note: caller frees hostname and export path, even on error.
1526 static int nfs_parse_devname(const char *dev_name
,
1527 char **hostname
, size_t maxnamlen
,
1528 char **export_path
, size_t maxpathlen
)
1530 if (*dev_name
== '[')
1531 return nfs_parse_protected_hostname(dev_name
,
1532 hostname
, maxnamlen
,
1533 export_path
, maxpathlen
);
1535 return nfs_parse_simple_hostname(dev_name
,
1536 hostname
, maxnamlen
,
1537 export_path
, maxpathlen
);
1541 * Validate the NFS2/NFS3 mount data
1542 * - fills in the mount root filehandle
1544 * For option strings, user space handles the following behaviors:
1546 * + DNS: mapping server host name to IP address ("addr=" option)
1548 * + failure mode: how to behave if a mount request can't be handled
1549 * immediately ("fg/bg" option)
1551 * + retry: how often to retry a mount request ("retry=" option)
1553 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1554 * mountproto=tcp after mountproto=udp, and so on
1556 static int nfs_validate_mount_data(void *options
,
1557 struct nfs_parsed_mount_data
*args
,
1558 struct nfs_fh
*mntfh
,
1559 const char *dev_name
)
1561 struct nfs_mount_data
*data
= (struct nfs_mount_data
*)options
;
1566 args
->flags
= (NFS_MOUNT_VER3
| NFS_MOUNT_TCP
);
1567 args
->rsize
= NFS_MAX_FILE_IO_SIZE
;
1568 args
->wsize
= NFS_MAX_FILE_IO_SIZE
;
1569 args
->acregmin
= NFS_DEF_ACREGMIN
;
1570 args
->acregmax
= NFS_DEF_ACREGMAX
;
1571 args
->acdirmin
= NFS_DEF_ACDIRMIN
;
1572 args
->acdirmax
= NFS_DEF_ACDIRMAX
;
1573 args
->mount_server
.port
= 0; /* autobind unless user sets port */
1574 args
->nfs_server
.port
= 0; /* autobind unless user sets port */
1575 args
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1576 args
->auth_flavors
[0] = RPC_AUTH_UNIX
;
1578 switch (data
->version
) {
1584 if (data
->flags
& NFS_MOUNT_VER3
)
1586 data
->root
.size
= NFS2_FHSIZE
;
1587 memcpy(data
->root
.data
, data
->old_root
.data
, NFS2_FHSIZE
);
1589 if (data
->flags
& NFS_MOUNT_SECFLAVOUR
)
1592 memset(data
->context
, 0, sizeof(data
->context
));
1594 if (data
->flags
& NFS_MOUNT_VER3
) {
1595 if (data
->root
.size
> NFS3_FHSIZE
|| data
->root
.size
== 0)
1596 goto out_invalid_fh
;
1597 mntfh
->size
= data
->root
.size
;
1599 mntfh
->size
= NFS2_FHSIZE
;
1602 memcpy(mntfh
->data
, data
->root
.data
, mntfh
->size
);
1603 if (mntfh
->size
< sizeof(mntfh
->data
))
1604 memset(mntfh
->data
+ mntfh
->size
, 0,
1605 sizeof(mntfh
->data
) - mntfh
->size
);
1608 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1611 args
->flags
= data
->flags
& NFS_MOUNT_FLAGMASK
;
1612 args
->rsize
= data
->rsize
;
1613 args
->wsize
= data
->wsize
;
1614 args
->timeo
= data
->timeo
;
1615 args
->retrans
= data
->retrans
;
1616 args
->acregmin
= data
->acregmin
;
1617 args
->acregmax
= data
->acregmax
;
1618 args
->acdirmin
= data
->acdirmin
;
1619 args
->acdirmax
= data
->acdirmax
;
1621 memcpy(&args
->nfs_server
.address
, &data
->addr
,
1622 sizeof(data
->addr
));
1623 args
->nfs_server
.addrlen
= sizeof(data
->addr
);
1624 if (!nfs_verify_server_address((struct sockaddr
*)
1625 &args
->nfs_server
.address
))
1626 goto out_no_address
;
1628 if (!(data
->flags
& NFS_MOUNT_TCP
))
1629 args
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1630 /* N.B. caller will free nfs_server.hostname in all cases */
1631 args
->nfs_server
.hostname
= kstrdup(data
->hostname
, GFP_KERNEL
);
1632 args
->namlen
= data
->namlen
;
1633 args
->bsize
= data
->bsize
;
1635 if (data
->flags
& NFS_MOUNT_SECFLAVOUR
)
1636 args
->auth_flavors
[0] = data
->pseudoflavor
;
1637 if (!args
->nfs_server
.hostname
)
1641 * The legacy version 6 binary mount data from userspace has a
1642 * field used only to transport selinux information into the
1643 * the kernel. To continue to support that functionality we
1644 * have a touch of selinux knowledge here in the NFS code. The
1645 * userspace code converted context=blah to just blah so we are
1646 * converting back to the full string selinux understands.
1648 if (data
->context
[0]){
1649 #ifdef CONFIG_SECURITY_SELINUX
1651 char *opts_str
= kmalloc(sizeof(data
->context
) + 8, GFP_KERNEL
);
1654 strcpy(opts_str
, "context=");
1655 data
->context
[NFS_MAX_CONTEXT_LEN
] = '\0';
1656 strcat(opts_str
, &data
->context
[0]);
1657 rc
= security_sb_parse_opts_str(opts_str
, &args
->lsm_opts
);
1670 if (nfs_parse_mount_options((char *)options
, args
) == 0)
1673 if (!nfs_verify_server_address((struct sockaddr
*)
1674 &args
->nfs_server
.address
))
1675 goto out_no_address
;
1677 nfs_set_port((struct sockaddr
*)&args
->nfs_server
.address
,
1678 args
->nfs_server
.port
);
1680 nfs_set_mount_transport_protocol(args
);
1682 status
= nfs_parse_devname(dev_name
,
1683 &args
->nfs_server
.hostname
,
1685 &args
->nfs_server
.export_path
,
1688 status
= nfs_try_mount(args
, mntfh
);
1690 kfree(args
->nfs_server
.export_path
);
1691 args
->nfs_server
.export_path
= NULL
;
1700 #ifndef CONFIG_NFS_V3
1701 if (args
->flags
& NFS_MOUNT_VER3
)
1702 goto out_v3_not_compiled
;
1703 #endif /* !CONFIG_NFS_V3 */
1708 dfprintk(MOUNT
, "NFS: mount program didn't pass any mount data\n");
1712 dfprintk(MOUNT
, "NFS: nfs_mount_data version %d does not support v3\n",
1717 dfprintk(MOUNT
, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1720 #ifndef CONFIG_NFS_V3
1721 out_v3_not_compiled
:
1722 dfprintk(MOUNT
, "NFS: NFSv3 is not compiled into kernel\n");
1723 return -EPROTONOSUPPORT
;
1724 #endif /* !CONFIG_NFS_V3 */
1727 dfprintk(MOUNT
, "NFS: not enough memory to handle mount options\n");
1731 dfprintk(MOUNT
, "NFS: mount program didn't pass remote address\n");
1735 dfprintk(MOUNT
, "NFS: invalid root filehandle\n");
1740 nfs_compare_remount_data(struct nfs_server
*nfss
,
1741 struct nfs_parsed_mount_data
*data
)
1743 if (data
->flags
!= nfss
->flags
||
1744 data
->rsize
!= nfss
->rsize
||
1745 data
->wsize
!= nfss
->wsize
||
1746 data
->retrans
!= nfss
->client
->cl_timeout
->to_retries
||
1747 data
->auth_flavors
[0] != nfss
->client
->cl_auth
->au_flavor
||
1748 data
->acregmin
!= nfss
->acregmin
/ HZ
||
1749 data
->acregmax
!= nfss
->acregmax
/ HZ
||
1750 data
->acdirmin
!= nfss
->acdirmin
/ HZ
||
1751 data
->acdirmax
!= nfss
->acdirmax
/ HZ
||
1752 data
->timeo
!= (10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
) ||
1753 data
->nfs_server
.addrlen
!= nfss
->nfs_client
->cl_addrlen
||
1754 memcmp(&data
->nfs_server
.address
, &nfss
->nfs_client
->cl_addr
,
1755 data
->nfs_server
.addrlen
) != 0)
1762 nfs_remount(struct super_block
*sb
, int *flags
, char *raw_data
)
1765 struct nfs_server
*nfss
= sb
->s_fs_info
;
1766 struct nfs_parsed_mount_data
*data
;
1767 struct nfs_mount_data
*options
= (struct nfs_mount_data
*)raw_data
;
1768 struct nfs4_mount_data
*options4
= (struct nfs4_mount_data
*)raw_data
;
1769 u32 nfsvers
= nfss
->nfs_client
->rpc_ops
->version
;
1772 * Userspace mount programs that send binary options generally send
1773 * them populated with default values. We have no way to know which
1774 * ones were explicitly specified. Fall back to legacy behavior and
1775 * just return success.
1777 if ((nfsvers
== 4 && (!options4
|| options4
->version
== 1)) ||
1778 (nfsvers
<= 3 && (!options
|| (options
->version
>= 1 &&
1779 options
->version
<= 6))))
1782 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
1786 /* fill out struct with values from existing mount */
1787 data
->flags
= nfss
->flags
;
1788 data
->rsize
= nfss
->rsize
;
1789 data
->wsize
= nfss
->wsize
;
1790 data
->retrans
= nfss
->client
->cl_timeout
->to_retries
;
1791 data
->auth_flavors
[0] = nfss
->client
->cl_auth
->au_flavor
;
1792 data
->acregmin
= nfss
->acregmin
/ HZ
;
1793 data
->acregmax
= nfss
->acregmax
/ HZ
;
1794 data
->acdirmin
= nfss
->acdirmin
/ HZ
;
1795 data
->acdirmax
= nfss
->acdirmax
/ HZ
;
1796 data
->timeo
= 10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
;
1797 data
->nfs_server
.addrlen
= nfss
->nfs_client
->cl_addrlen
;
1798 memcpy(&data
->nfs_server
.address
, &nfss
->nfs_client
->cl_addr
,
1799 data
->nfs_server
.addrlen
);
1801 /* overwrite those values with any that were specified */
1802 error
= nfs_parse_mount_options((char *)options
, data
);
1806 /* compare new mount options with old ones */
1807 error
= nfs_compare_remount_data(nfss
, data
);
1814 * Initialise the common bits of the superblock
1816 static inline void nfs_initialise_sb(struct super_block
*sb
)
1818 struct nfs_server
*server
= NFS_SB(sb
);
1820 sb
->s_magic
= NFS_SUPER_MAGIC
;
1822 /* We probably want something more informative here */
1823 snprintf(sb
->s_id
, sizeof(sb
->s_id
),
1824 "%x:%x", MAJOR(sb
->s_dev
), MINOR(sb
->s_dev
));
1826 if (sb
->s_blocksize
== 0)
1827 sb
->s_blocksize
= nfs_block_bits(server
->wsize
,
1828 &sb
->s_blocksize_bits
);
1830 if (server
->flags
& NFS_MOUNT_NOAC
)
1831 sb
->s_flags
|= MS_SYNCHRONOUS
;
1833 nfs_super_set_maxbytes(sb
, server
->maxfilesize
);
1837 * Finish setting up an NFS2/3 superblock
1839 static void nfs_fill_super(struct super_block
*sb
,
1840 struct nfs_parsed_mount_data
*data
)
1842 struct nfs_server
*server
= NFS_SB(sb
);
1844 sb
->s_blocksize_bits
= 0;
1845 sb
->s_blocksize
= 0;
1847 sb
->s_blocksize
= nfs_block_size(data
->bsize
, &sb
->s_blocksize_bits
);
1849 if (server
->flags
& NFS_MOUNT_VER3
) {
1850 /* The VFS shouldn't apply the umask to mode bits. We will do
1851 * so ourselves when necessary.
1853 sb
->s_flags
|= MS_POSIXACL
;
1854 sb
->s_time_gran
= 1;
1857 sb
->s_op
= &nfs_sops
;
1858 nfs_initialise_sb(sb
);
1862 * Finish setting up a cloned NFS2/3 superblock
1864 static void nfs_clone_super(struct super_block
*sb
,
1865 const struct super_block
*old_sb
)
1867 struct nfs_server
*server
= NFS_SB(sb
);
1869 sb
->s_blocksize_bits
= old_sb
->s_blocksize_bits
;
1870 sb
->s_blocksize
= old_sb
->s_blocksize
;
1871 sb
->s_maxbytes
= old_sb
->s_maxbytes
;
1873 if (server
->flags
& NFS_MOUNT_VER3
) {
1874 /* The VFS shouldn't apply the umask to mode bits. We will do
1875 * so ourselves when necessary.
1877 sb
->s_flags
|= MS_POSIXACL
;
1878 sb
->s_time_gran
= 1;
1881 sb
->s_op
= old_sb
->s_op
;
1882 nfs_initialise_sb(sb
);
1885 static int nfs_compare_mount_options(const struct super_block
*s
, const struct nfs_server
*b
, int flags
)
1887 const struct nfs_server
*a
= s
->s_fs_info
;
1888 const struct rpc_clnt
*clnt_a
= a
->client
;
1889 const struct rpc_clnt
*clnt_b
= b
->client
;
1891 if ((s
->s_flags
& NFS_MS_MASK
) != (flags
& NFS_MS_MASK
))
1893 if (a
->nfs_client
!= b
->nfs_client
)
1895 if (a
->flags
!= b
->flags
)
1897 if (a
->wsize
!= b
->wsize
)
1899 if (a
->rsize
!= b
->rsize
)
1901 if (a
->acregmin
!= b
->acregmin
)
1903 if (a
->acregmax
!= b
->acregmax
)
1905 if (a
->acdirmin
!= b
->acdirmin
)
1907 if (a
->acdirmax
!= b
->acdirmax
)
1909 if (clnt_a
->cl_auth
->au_flavor
!= clnt_b
->cl_auth
->au_flavor
)
1916 struct nfs_sb_mountdata
{
1917 struct nfs_server
*server
;
1921 static int nfs_set_super(struct super_block
*s
, void *data
)
1923 struct nfs_sb_mountdata
*sb_mntdata
= data
;
1924 struct nfs_server
*server
= sb_mntdata
->server
;
1927 s
->s_flags
= sb_mntdata
->mntflags
;
1928 s
->s_fs_info
= server
;
1929 ret
= set_anon_super(s
, server
);
1931 server
->s_dev
= s
->s_dev
;
1935 static int nfs_compare_super_address(struct nfs_server
*server1
,
1936 struct nfs_server
*server2
)
1938 struct sockaddr
*sap1
, *sap2
;
1940 sap1
= (struct sockaddr
*)&server1
->nfs_client
->cl_addr
;
1941 sap2
= (struct sockaddr
*)&server2
->nfs_client
->cl_addr
;
1943 if (sap1
->sa_family
!= sap2
->sa_family
)
1946 switch (sap1
->sa_family
) {
1948 struct sockaddr_in
*sin1
= (struct sockaddr_in
*)sap1
;
1949 struct sockaddr_in
*sin2
= (struct sockaddr_in
*)sap2
;
1950 if (sin1
->sin_addr
.s_addr
!= sin2
->sin_addr
.s_addr
)
1952 if (sin1
->sin_port
!= sin2
->sin_port
)
1957 struct sockaddr_in6
*sin1
= (struct sockaddr_in6
*)sap1
;
1958 struct sockaddr_in6
*sin2
= (struct sockaddr_in6
*)sap2
;
1959 if (!ipv6_addr_equal(&sin1
->sin6_addr
, &sin2
->sin6_addr
))
1961 if (sin1
->sin6_port
!= sin2
->sin6_port
)
1972 static int nfs_compare_super(struct super_block
*sb
, void *data
)
1974 struct nfs_sb_mountdata
*sb_mntdata
= data
;
1975 struct nfs_server
*server
= sb_mntdata
->server
, *old
= NFS_SB(sb
);
1976 int mntflags
= sb_mntdata
->mntflags
;
1978 if (!nfs_compare_super_address(old
, server
))
1980 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1981 if (old
->flags
& NFS_MOUNT_UNSHARED
)
1983 if (memcmp(&old
->fsid
, &server
->fsid
, sizeof(old
->fsid
)) != 0)
1985 return nfs_compare_mount_options(sb
, server
, mntflags
);
1988 static int nfs_bdi_register(struct nfs_server
*server
)
1990 return bdi_register_dev(&server
->backing_dev_info
, server
->s_dev
);
1993 static int nfs_get_sb(struct file_system_type
*fs_type
,
1994 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
1996 struct nfs_server
*server
= NULL
;
1997 struct super_block
*s
;
1998 struct nfs_parsed_mount_data
*data
;
1999 struct nfs_fh
*mntfh
;
2000 struct dentry
*mntroot
;
2001 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2002 struct nfs_sb_mountdata sb_mntdata
= {
2005 int error
= -ENOMEM
;
2007 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
2008 mntfh
= kzalloc(sizeof(*mntfh
), GFP_KERNEL
);
2009 if (data
== NULL
|| mntfh
== NULL
)
2012 security_init_mnt_opts(&data
->lsm_opts
);
2014 /* Validate the mount data */
2015 error
= nfs_validate_mount_data(raw_data
, data
, mntfh
, dev_name
);
2019 /* Get a volume representation */
2020 server
= nfs_create_server(data
, mntfh
);
2021 if (IS_ERR(server
)) {
2022 error
= PTR_ERR(server
);
2025 sb_mntdata
.server
= server
;
2027 if (server
->flags
& NFS_MOUNT_UNSHARED
)
2028 compare_super
= NULL
;
2030 /* Get a superblock - note that we may end up sharing one that already exists */
2031 s
= sget(fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2037 if (s
->s_fs_info
!= server
) {
2038 nfs_free_server(server
);
2041 error
= nfs_bdi_register(server
);
2043 goto error_splat_super
;
2047 /* initial superblock/root creation */
2048 nfs_fill_super(s
, data
);
2049 nfs_fscache_get_super_cookie(s
, data
);
2052 mntroot
= nfs_get_root(s
, mntfh
);
2053 if (IS_ERR(mntroot
)) {
2054 error
= PTR_ERR(mntroot
);
2055 goto error_splat_super
;
2058 error
= security_sb_set_mnt_opts(s
, &data
->lsm_opts
);
2060 goto error_splat_root
;
2062 s
->s_flags
|= MS_ACTIVE
;
2064 mnt
->mnt_root
= mntroot
;
2068 kfree(data
->nfs_server
.hostname
);
2069 kfree(data
->mount_server
.hostname
);
2070 kfree(data
->fscache_uniq
);
2071 security_free_mnt_opts(&data
->lsm_opts
);
2078 nfs_free_server(server
);
2084 up_write(&s
->s_umount
);
2085 deactivate_super(s
);
2090 * Destroy an NFS2/3 superblock
2092 static void nfs_kill_super(struct super_block
*s
)
2094 struct nfs_server
*server
= NFS_SB(s
);
2096 bdi_unregister(&server
->backing_dev_info
);
2098 nfs_fscache_release_super_cookie(s
);
2099 nfs_free_server(server
);
2103 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2105 static int nfs_xdev_get_sb(struct file_system_type
*fs_type
, int flags
,
2106 const char *dev_name
, void *raw_data
,
2107 struct vfsmount
*mnt
)
2109 struct nfs_clone_mount
*data
= raw_data
;
2110 struct super_block
*s
;
2111 struct nfs_server
*server
;
2112 struct dentry
*mntroot
;
2113 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2114 struct nfs_sb_mountdata sb_mntdata
= {
2119 dprintk("--> nfs_xdev_get_sb()\n");
2121 /* create a new volume representation */
2122 server
= nfs_clone_server(NFS_SB(data
->sb
), data
->fh
, data
->fattr
);
2123 if (IS_ERR(server
)) {
2124 error
= PTR_ERR(server
);
2125 goto out_err_noserver
;
2127 sb_mntdata
.server
= server
;
2129 if (server
->flags
& NFS_MOUNT_UNSHARED
)
2130 compare_super
= NULL
;
2132 /* Get a superblock - note that we may end up sharing one that already exists */
2133 s
= sget(&nfs_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2139 if (s
->s_fs_info
!= server
) {
2140 nfs_free_server(server
);
2143 error
= nfs_bdi_register(server
);
2145 goto error_splat_super
;
2149 /* initial superblock/root creation */
2150 nfs_clone_super(s
, data
->sb
);
2153 mntroot
= nfs_get_root(s
, data
->fh
);
2154 if (IS_ERR(mntroot
)) {
2155 error
= PTR_ERR(mntroot
);
2156 goto error_splat_super
;
2158 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
2161 goto error_splat_super
;
2164 s
->s_flags
|= MS_ACTIVE
;
2166 mnt
->mnt_root
= mntroot
;
2168 /* clone any lsm security options from the parent to the new sb */
2169 security_sb_clone_mnt_opts(data
->sb
, s
);
2171 dprintk("<-- nfs_xdev_get_sb() = 0\n");
2175 nfs_free_server(server
);
2177 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error
);
2181 up_write(&s
->s_umount
);
2182 deactivate_super(s
);
2183 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error
);
2187 #ifdef CONFIG_NFS_V4
2190 * Finish setting up a cloned NFS4 superblock
2192 static void nfs4_clone_super(struct super_block
*sb
,
2193 const struct super_block
*old_sb
)
2195 sb
->s_blocksize_bits
= old_sb
->s_blocksize_bits
;
2196 sb
->s_blocksize
= old_sb
->s_blocksize
;
2197 sb
->s_maxbytes
= old_sb
->s_maxbytes
;
2198 sb
->s_time_gran
= 1;
2199 sb
->s_op
= old_sb
->s_op
;
2200 nfs_initialise_sb(sb
);
2204 * Set up an NFS4 superblock
2206 static void nfs4_fill_super(struct super_block
*sb
)
2208 sb
->s_time_gran
= 1;
2209 sb
->s_op
= &nfs4_sops
;
2210 nfs_initialise_sb(sb
);
2214 * Validate NFSv4 mount options
2216 static int nfs4_validate_mount_data(void *options
,
2217 struct nfs_parsed_mount_data
*args
,
2218 const char *dev_name
)
2220 struct sockaddr_in
*ap
;
2221 struct nfs4_mount_data
*data
= (struct nfs4_mount_data
*)options
;
2227 args
->rsize
= NFS_MAX_FILE_IO_SIZE
;
2228 args
->wsize
= NFS_MAX_FILE_IO_SIZE
;
2229 args
->acregmin
= NFS_DEF_ACREGMIN
;
2230 args
->acregmax
= NFS_DEF_ACREGMAX
;
2231 args
->acdirmin
= NFS_DEF_ACDIRMIN
;
2232 args
->acdirmax
= NFS_DEF_ACDIRMAX
;
2233 args
->nfs_server
.port
= NFS_PORT
; /* 2049 unless user set port= */
2234 args
->auth_flavors
[0] = RPC_AUTH_UNIX
;
2235 args
->auth_flavor_len
= 0;
2237 switch (data
->version
) {
2239 ap
= (struct sockaddr_in
*)&args
->nfs_server
.address
;
2240 if (data
->host_addrlen
> sizeof(args
->nfs_server
.address
))
2241 goto out_no_address
;
2242 if (data
->host_addrlen
== 0)
2243 goto out_no_address
;
2244 args
->nfs_server
.addrlen
= data
->host_addrlen
;
2245 if (copy_from_user(ap
, data
->host_addr
, data
->host_addrlen
))
2247 if (!nfs_verify_server_address((struct sockaddr
*)
2248 &args
->nfs_server
.address
))
2249 goto out_no_address
;
2251 if (data
->auth_flavourlen
) {
2252 if (data
->auth_flavourlen
> 1)
2253 goto out_inval_auth
;
2254 if (copy_from_user(&args
->auth_flavors
[0],
2255 data
->auth_flavours
,
2256 sizeof(args
->auth_flavors
[0])))
2260 c
= strndup_user(data
->hostname
.data
, NFS4_MAXNAMLEN
);
2263 args
->nfs_server
.hostname
= c
;
2265 c
= strndup_user(data
->mnt_path
.data
, NFS4_MAXPATHLEN
);
2268 args
->nfs_server
.export_path
= c
;
2269 dfprintk(MOUNT
, "NFS: MNTPATH: '%s'\n", c
);
2271 c
= strndup_user(data
->client_addr
.data
, 16);
2274 args
->client_address
= c
;
2277 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2281 args
->flags
= data
->flags
& NFS4_MOUNT_FLAGMASK
;
2282 args
->rsize
= data
->rsize
;
2283 args
->wsize
= data
->wsize
;
2284 args
->timeo
= data
->timeo
;
2285 args
->retrans
= data
->retrans
;
2286 args
->acregmin
= data
->acregmin
;
2287 args
->acregmax
= data
->acregmax
;
2288 args
->acdirmin
= data
->acdirmin
;
2289 args
->acdirmax
= data
->acdirmax
;
2290 args
->nfs_server
.protocol
= data
->proto
;
2291 nfs_validate_transport_protocol(args
);
2297 if (nfs_parse_mount_options((char *)options
, args
) == 0)
2300 if (!nfs_verify_server_address((struct sockaddr
*)
2301 &args
->nfs_server
.address
))
2304 nfs_set_port((struct sockaddr
*)&args
->nfs_server
.address
,
2305 args
->nfs_server
.port
);
2307 nfs_validate_transport_protocol(args
);
2309 if (args
->auth_flavor_len
> 1)
2310 goto out_inval_auth
;
2312 if (args
->client_address
== NULL
)
2313 goto out_no_client_address
;
2315 status
= nfs_parse_devname(dev_name
,
2316 &args
->nfs_server
.hostname
,
2318 &args
->nfs_server
.export_path
,
2330 dfprintk(MOUNT
, "NFS4: mount program didn't pass any mount data\n");
2334 dfprintk(MOUNT
, "NFS4: Invalid number of RPC auth flavours %d\n",
2335 data
->auth_flavourlen
);
2339 dfprintk(MOUNT
, "NFS4: mount program didn't pass remote address\n");
2342 out_no_client_address
:
2343 dfprintk(MOUNT
, "NFS4: mount program didn't pass callback address\n");
2348 * Get the superblock for an NFS4 mountpoint
2350 static int nfs4_get_sb(struct file_system_type
*fs_type
,
2351 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
2353 struct nfs_parsed_mount_data
*data
;
2354 struct super_block
*s
;
2355 struct nfs_server
*server
;
2356 struct nfs_fh
*mntfh
;
2357 struct dentry
*mntroot
;
2358 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2359 struct nfs_sb_mountdata sb_mntdata
= {
2362 int error
= -ENOMEM
;
2364 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
2365 mntfh
= kzalloc(sizeof(*mntfh
), GFP_KERNEL
);
2366 if (data
== NULL
|| mntfh
== NULL
)
2369 security_init_mnt_opts(&data
->lsm_opts
);
2371 /* Validate the mount data */
2372 error
= nfs4_validate_mount_data(raw_data
, data
, dev_name
);
2376 /* Get a volume representation */
2377 server
= nfs4_create_server(data
, mntfh
);
2378 if (IS_ERR(server
)) {
2379 error
= PTR_ERR(server
);
2382 sb_mntdata
.server
= server
;
2384 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2385 compare_super
= NULL
;
2387 /* Get a superblock - note that we may end up sharing one that already exists */
2388 s
= sget(fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2394 if (s
->s_fs_info
!= server
) {
2395 nfs_free_server(server
);
2398 error
= nfs_bdi_register(server
);
2400 goto error_splat_super
;
2404 /* initial superblock/root creation */
2406 nfs_fscache_get_super_cookie(s
, data
);
2409 mntroot
= nfs4_get_root(s
, mntfh
);
2410 if (IS_ERR(mntroot
)) {
2411 error
= PTR_ERR(mntroot
);
2412 goto error_splat_super
;
2415 error
= security_sb_set_mnt_opts(s
, &data
->lsm_opts
);
2417 goto error_splat_root
;
2419 s
->s_flags
|= MS_ACTIVE
;
2421 mnt
->mnt_root
= mntroot
;
2425 kfree(data
->client_address
);
2426 kfree(data
->nfs_server
.export_path
);
2427 kfree(data
->nfs_server
.hostname
);
2428 kfree(data
->fscache_uniq
);
2429 security_free_mnt_opts(&data
->lsm_opts
);
2436 nfs_free_server(server
);
2442 up_write(&s
->s_umount
);
2443 deactivate_super(s
);
2447 static void nfs4_kill_super(struct super_block
*sb
)
2449 struct nfs_server
*server
= NFS_SB(sb
);
2451 nfs_super_return_all_delegations(sb
);
2452 kill_anon_super(sb
);
2454 nfs4_renewd_prepare_shutdown(server
);
2455 nfs_fscache_release_super_cookie(sb
);
2456 nfs_free_server(server
);
2460 * Clone an NFS4 server record on xdev traversal (FSID-change)
2462 static int nfs4_xdev_get_sb(struct file_system_type
*fs_type
, int flags
,
2463 const char *dev_name
, void *raw_data
,
2464 struct vfsmount
*mnt
)
2466 struct nfs_clone_mount
*data
= raw_data
;
2467 struct super_block
*s
;
2468 struct nfs_server
*server
;
2469 struct dentry
*mntroot
;
2470 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2471 struct nfs_sb_mountdata sb_mntdata
= {
2476 dprintk("--> nfs4_xdev_get_sb()\n");
2478 /* create a new volume representation */
2479 server
= nfs_clone_server(NFS_SB(data
->sb
), data
->fh
, data
->fattr
);
2480 if (IS_ERR(server
)) {
2481 error
= PTR_ERR(server
);
2482 goto out_err_noserver
;
2484 sb_mntdata
.server
= server
;
2486 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2487 compare_super
= NULL
;
2489 /* Get a superblock - note that we may end up sharing one that already exists */
2490 s
= sget(&nfs4_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2496 if (s
->s_fs_info
!= server
) {
2497 nfs_free_server(server
);
2500 error
= nfs_bdi_register(server
);
2502 goto error_splat_super
;
2506 /* initial superblock/root creation */
2507 nfs4_clone_super(s
, data
->sb
);
2510 mntroot
= nfs4_get_root(s
, data
->fh
);
2511 if (IS_ERR(mntroot
)) {
2512 error
= PTR_ERR(mntroot
);
2513 goto error_splat_super
;
2515 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
2518 goto error_splat_super
;
2521 s
->s_flags
|= MS_ACTIVE
;
2523 mnt
->mnt_root
= mntroot
;
2525 security_sb_clone_mnt_opts(data
->sb
, s
);
2527 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2531 nfs_free_server(server
);
2533 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error
);
2537 up_write(&s
->s_umount
);
2538 deactivate_super(s
);
2539 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error
);
2544 * Create an NFS4 server record on referral traversal
2546 static int nfs4_referral_get_sb(struct file_system_type
*fs_type
, int flags
,
2547 const char *dev_name
, void *raw_data
,
2548 struct vfsmount
*mnt
)
2550 struct nfs_clone_mount
*data
= raw_data
;
2551 struct super_block
*s
;
2552 struct nfs_server
*server
;
2553 struct dentry
*mntroot
;
2554 struct nfs_fh mntfh
;
2555 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2556 struct nfs_sb_mountdata sb_mntdata
= {
2561 dprintk("--> nfs4_referral_get_sb()\n");
2563 /* create a new volume representation */
2564 server
= nfs4_create_referral_server(data
, &mntfh
);
2565 if (IS_ERR(server
)) {
2566 error
= PTR_ERR(server
);
2567 goto out_err_noserver
;
2569 sb_mntdata
.server
= server
;
2571 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2572 compare_super
= NULL
;
2574 /* Get a superblock - note that we may end up sharing one that already exists */
2575 s
= sget(&nfs4_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2581 if (s
->s_fs_info
!= server
) {
2582 nfs_free_server(server
);
2585 error
= nfs_bdi_register(server
);
2587 goto error_splat_super
;
2591 /* initial superblock/root creation */
2595 mntroot
= nfs4_get_root(s
, &mntfh
);
2596 if (IS_ERR(mntroot
)) {
2597 error
= PTR_ERR(mntroot
);
2598 goto error_splat_super
;
2600 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
2603 goto error_splat_super
;
2606 s
->s_flags
|= MS_ACTIVE
;
2608 mnt
->mnt_root
= mntroot
;
2610 security_sb_clone_mnt_opts(data
->sb
, s
);
2612 dprintk("<-- nfs4_referral_get_sb() = 0\n");
2616 nfs_free_server(server
);
2618 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error
);
2622 up_write(&s
->s_umount
);
2623 deactivate_super(s
);
2624 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error
);
2628 #endif /* CONFIG_NFS_V4 */