4 * Copyright (C) 1992 Rick Sladkey
6 * nfs superblock handling functions
8 * Modularised by Alan Cox <Alan.Cox@linux.org>, 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/nfs_xdr.h>
51 #include <linux/magic.h>
52 #include <linux/parser.h>
54 #include <asm/system.h>
55 #include <asm/uaccess.h>
59 #include "delegation.h"
63 #define NFSDBG_FACILITY NFSDBG_VFS
66 /* Mount options that take no arguments */
69 Opt_posix
, Opt_noposix
,
74 Opt_udp
, Opt_tcp
, Opt_rdma
,
76 Opt_rdirplus
, Opt_nordirplus
,
77 Opt_sharecache
, Opt_nosharecache
,
79 /* Mount options that take integer arguments */
81 Opt_rsize
, Opt_wsize
, Opt_bsize
,
82 Opt_timeo
, Opt_retrans
,
83 Opt_acregmin
, Opt_acregmax
,
84 Opt_acdirmin
, Opt_acdirmax
,
91 /* Mount options that take string arguments */
92 Opt_sec
, Opt_proto
, Opt_mountproto
, Opt_mounthost
,
93 Opt_addr
, Opt_mountaddr
, Opt_clientaddr
,
95 /* Mount options that are ignored */
96 Opt_userspace
, Opt_deprecated
,
101 static match_table_t nfs_mount_option_tokens
= {
102 { Opt_userspace
, "bg" },
103 { Opt_userspace
, "fg" },
104 { Opt_soft
, "soft" },
105 { Opt_hard
, "hard" },
106 { Opt_intr
, "intr" },
107 { Opt_nointr
, "nointr" },
108 { Opt_posix
, "posix" },
109 { Opt_noposix
, "noposix" },
111 { Opt_nocto
, "nocto" },
113 { Opt_noac
, "noac" },
114 { Opt_lock
, "lock" },
115 { Opt_nolock
, "nolock" },
120 { Opt_rdma
, "rdma" },
122 { Opt_noacl
, "noacl" },
123 { Opt_rdirplus
, "rdirplus" },
124 { Opt_nordirplus
, "nordirplus" },
125 { Opt_sharecache
, "sharecache" },
126 { Opt_nosharecache
, "nosharecache" },
128 { Opt_port
, "port=%u" },
129 { Opt_rsize
, "rsize=%u" },
130 { Opt_wsize
, "wsize=%u" },
131 { Opt_bsize
, "bsize=%u" },
132 { Opt_timeo
, "timeo=%u" },
133 { Opt_retrans
, "retrans=%u" },
134 { Opt_acregmin
, "acregmin=%u" },
135 { Opt_acregmax
, "acregmax=%u" },
136 { Opt_acdirmin
, "acdirmin=%u" },
137 { Opt_acdirmax
, "acdirmax=%u" },
138 { Opt_actimeo
, "actimeo=%u" },
139 { Opt_userspace
, "retry=%u" },
140 { Opt_namelen
, "namlen=%u" },
141 { Opt_mountport
, "mountport=%u" },
142 { Opt_mountvers
, "mountvers=%u" },
143 { Opt_nfsvers
, "nfsvers=%u" },
144 { Opt_nfsvers
, "vers=%u" },
146 { Opt_sec
, "sec=%s" },
147 { Opt_proto
, "proto=%s" },
148 { Opt_mountproto
, "mountproto=%s" },
149 { Opt_addr
, "addr=%s" },
150 { Opt_clientaddr
, "clientaddr=%s" },
151 { Opt_mounthost
, "mounthost=%s" },
152 { Opt_mountaddr
, "mountaddr=%s" },
158 Opt_xprt_udp
, Opt_xprt_tcp
, Opt_xprt_rdma
,
163 static match_table_t nfs_xprt_protocol_tokens
= {
164 { Opt_xprt_udp
, "udp" },
165 { Opt_xprt_tcp
, "tcp" },
166 { Opt_xprt_rdma
, "rdma" },
168 { Opt_xprt_err
, NULL
}
172 Opt_sec_none
, Opt_sec_sys
,
173 Opt_sec_krb5
, Opt_sec_krb5i
, Opt_sec_krb5p
,
174 Opt_sec_lkey
, Opt_sec_lkeyi
, Opt_sec_lkeyp
,
175 Opt_sec_spkm
, Opt_sec_spkmi
, Opt_sec_spkmp
,
180 static match_table_t nfs_secflavor_tokens
= {
181 { Opt_sec_none
, "none" },
182 { Opt_sec_none
, "null" },
183 { Opt_sec_sys
, "sys" },
185 { Opt_sec_krb5
, "krb5" },
186 { Opt_sec_krb5i
, "krb5i" },
187 { Opt_sec_krb5p
, "krb5p" },
189 { Opt_sec_lkey
, "lkey" },
190 { Opt_sec_lkeyi
, "lkeyi" },
191 { Opt_sec_lkeyp
, "lkeyp" },
193 { Opt_sec_spkm
, "spkm3" },
194 { Opt_sec_spkmi
, "spkm3i" },
195 { Opt_sec_spkmp
, "spkm3p" },
197 { Opt_sec_err
, NULL
}
201 static void nfs_umount_begin(struct super_block
*);
202 static int nfs_statfs(struct dentry
*, struct kstatfs
*);
203 static int nfs_show_options(struct seq_file
*, struct vfsmount
*);
204 static int nfs_show_stats(struct seq_file
*, struct vfsmount
*);
205 static int nfs_get_sb(struct file_system_type
*, int, const char *, void *, struct vfsmount
*);
206 static int nfs_xdev_get_sb(struct file_system_type
*fs_type
,
207 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
208 static void nfs_kill_super(struct super_block
*);
209 static void nfs_put_super(struct super_block
*);
210 static int nfs_remount(struct super_block
*sb
, int *flags
, char *raw_data
);
212 static struct file_system_type nfs_fs_type
= {
213 .owner
= THIS_MODULE
,
215 .get_sb
= nfs_get_sb
,
216 .kill_sb
= nfs_kill_super
,
217 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
220 struct file_system_type nfs_xdev_fs_type
= {
221 .owner
= THIS_MODULE
,
223 .get_sb
= nfs_xdev_get_sb
,
224 .kill_sb
= nfs_kill_super
,
225 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
228 static const struct super_operations nfs_sops
= {
229 .alloc_inode
= nfs_alloc_inode
,
230 .destroy_inode
= nfs_destroy_inode
,
231 .write_inode
= nfs_write_inode
,
232 .put_super
= nfs_put_super
,
233 .statfs
= nfs_statfs
,
234 .clear_inode
= nfs_clear_inode
,
235 .umount_begin
= nfs_umount_begin
,
236 .show_options
= nfs_show_options
,
237 .show_stats
= nfs_show_stats
,
238 .remount_fs
= nfs_remount
,
242 static int nfs4_get_sb(struct file_system_type
*fs_type
,
243 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
244 static int nfs4_xdev_get_sb(struct file_system_type
*fs_type
,
245 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
246 static int nfs4_referral_get_sb(struct file_system_type
*fs_type
,
247 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
248 static void nfs4_kill_super(struct super_block
*sb
);
250 static struct file_system_type nfs4_fs_type
= {
251 .owner
= THIS_MODULE
,
253 .get_sb
= nfs4_get_sb
,
254 .kill_sb
= nfs4_kill_super
,
255 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
258 struct file_system_type nfs4_xdev_fs_type
= {
259 .owner
= THIS_MODULE
,
261 .get_sb
= nfs4_xdev_get_sb
,
262 .kill_sb
= nfs4_kill_super
,
263 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
266 struct file_system_type nfs4_referral_fs_type
= {
267 .owner
= THIS_MODULE
,
269 .get_sb
= nfs4_referral_get_sb
,
270 .kill_sb
= nfs4_kill_super
,
271 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
274 static const struct super_operations nfs4_sops
= {
275 .alloc_inode
= nfs_alloc_inode
,
276 .destroy_inode
= nfs_destroy_inode
,
277 .write_inode
= nfs_write_inode
,
278 .statfs
= nfs_statfs
,
279 .clear_inode
= nfs4_clear_inode
,
280 .umount_begin
= nfs_umount_begin
,
281 .show_options
= nfs_show_options
,
282 .show_stats
= nfs_show_stats
,
283 .remount_fs
= nfs_remount
,
287 static struct shrinker acl_shrinker
= {
288 .shrink
= nfs_access_cache_shrinker
,
289 .seeks
= DEFAULT_SEEKS
,
293 * Register the NFS filesystems
295 int __init
register_nfs_fs(void)
299 ret
= register_filesystem(&nfs_fs_type
);
303 ret
= nfs_register_sysctl();
307 ret
= register_filesystem(&nfs4_fs_type
);
311 register_shrinker(&acl_shrinker
);
316 nfs_unregister_sysctl();
319 unregister_filesystem(&nfs_fs_type
);
325 * Unregister the NFS filesystems
327 void __exit
unregister_nfs_fs(void)
329 unregister_shrinker(&acl_shrinker
);
331 unregister_filesystem(&nfs4_fs_type
);
333 nfs_unregister_sysctl();
334 unregister_filesystem(&nfs_fs_type
);
337 void nfs_sb_active(struct nfs_server
*server
)
339 atomic_inc(&server
->active
);
342 void nfs_sb_deactive(struct nfs_server
*server
)
344 if (atomic_dec_and_test(&server
->active
))
345 wake_up(&server
->active_wq
);
348 static void nfs_put_super(struct super_block
*sb
)
350 struct nfs_server
*server
= NFS_SB(sb
);
352 * Make sure there are no outstanding ops to this server.
353 * If so, wait for them to finish before allowing the
354 * unmount to continue.
356 wait_event(server
->active_wq
, atomic_read(&server
->active
) == 0);
360 * Deliver file system statistics to userspace
362 static int nfs_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
364 struct nfs_server
*server
= NFS_SB(dentry
->d_sb
);
365 unsigned char blockbits
;
366 unsigned long blockres
;
367 struct nfs_fh
*fh
= NFS_FH(dentry
->d_inode
);
368 struct nfs_fattr fattr
;
369 struct nfs_fsstat res
= {
376 error
= server
->nfs_client
->rpc_ops
->statfs(server
, fh
, &res
);
379 buf
->f_type
= NFS_SUPER_MAGIC
;
382 * Current versions of glibc do not correctly handle the
383 * case where f_frsize != f_bsize. Eventually we want to
384 * report the value of wtmult in this field.
386 buf
->f_frsize
= dentry
->d_sb
->s_blocksize
;
389 * On most *nix systems, f_blocks, f_bfree, and f_bavail
390 * are reported in units of f_frsize. Linux hasn't had
391 * an f_frsize field in its statfs struct until recently,
392 * thus historically Linux's sys_statfs reports these
393 * fields in units of f_bsize.
395 buf
->f_bsize
= dentry
->d_sb
->s_blocksize
;
396 blockbits
= dentry
->d_sb
->s_blocksize_bits
;
397 blockres
= (1 << blockbits
) - 1;
398 buf
->f_blocks
= (res
.tbytes
+ blockres
) >> blockbits
;
399 buf
->f_bfree
= (res
.fbytes
+ blockres
) >> blockbits
;
400 buf
->f_bavail
= (res
.abytes
+ blockres
) >> blockbits
;
402 buf
->f_files
= res
.tfiles
;
403 buf
->f_ffree
= res
.afiles
;
405 buf
->f_namelen
= server
->namelen
;
411 dprintk("%s: statfs error = %d\n", __func__
, -error
);
417 * Map the security flavour number to a name
419 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour
)
421 static const struct {
422 rpc_authflavor_t flavour
;
425 { RPC_AUTH_NULL
, "null" },
426 { RPC_AUTH_UNIX
, "sys" },
427 { RPC_AUTH_GSS_KRB5
, "krb5" },
428 { RPC_AUTH_GSS_KRB5I
, "krb5i" },
429 { RPC_AUTH_GSS_KRB5P
, "krb5p" },
430 { RPC_AUTH_GSS_LKEY
, "lkey" },
431 { RPC_AUTH_GSS_LKEYI
, "lkeyi" },
432 { RPC_AUTH_GSS_LKEYP
, "lkeyp" },
433 { RPC_AUTH_GSS_SPKM
, "spkm" },
434 { RPC_AUTH_GSS_SPKMI
, "spkmi" },
435 { RPC_AUTH_GSS_SPKMP
, "spkmp" },
436 { UINT_MAX
, "unknown" }
440 for (i
= 0; sec_flavours
[i
].flavour
!= UINT_MAX
; i
++) {
441 if (sec_flavours
[i
].flavour
== flavour
)
444 return sec_flavours
[i
].str
;
447 static void nfs_show_mountd_options(struct seq_file
*m
, struct nfs_server
*nfss
,
450 struct sockaddr
*sap
= (struct sockaddr
*)&nfss
->mountd_address
;
452 switch (sap
->sa_family
) {
454 struct sockaddr_in
*sin
= (struct sockaddr_in
*)sap
;
455 seq_printf(m
, ",mountaddr=" NIPQUAD_FMT
,
456 NIPQUAD(sin
->sin_addr
.s_addr
));
460 struct sockaddr_in6
*sin6
= (struct sockaddr_in6
*)sap
;
461 seq_printf(m
, ",mountaddr=" NIP6_FMT
,
462 NIP6(sin6
->sin6_addr
));
467 seq_printf(m
, ",mountaddr=unspecified");
470 if (nfss
->mountd_version
|| showdefaults
)
471 seq_printf(m
, ",mountvers=%u", nfss
->mountd_version
);
472 if (nfss
->mountd_port
|| showdefaults
)
473 seq_printf(m
, ",mountport=%u", nfss
->mountd_port
);
475 switch (nfss
->mountd_protocol
) {
477 seq_printf(m
, ",mountproto=udp");
480 seq_printf(m
, ",mountproto=tcp");
484 seq_printf(m
, ",mountproto=auto");
489 * Describe the mount options in force on this server representation
491 static void nfs_show_mount_options(struct seq_file
*m
, struct nfs_server
*nfss
,
494 static const struct proc_nfs_info
{
499 { NFS_MOUNT_SOFT
, ",soft", ",hard" },
500 { NFS_MOUNT_INTR
, ",intr", ",nointr" },
501 { NFS_MOUNT_POSIX
, ",posix", "" },
502 { NFS_MOUNT_NOCTO
, ",nocto", "" },
503 { NFS_MOUNT_NOAC
, ",noac", "" },
504 { NFS_MOUNT_NONLM
, ",nolock", "" },
505 { NFS_MOUNT_NOACL
, ",noacl", "" },
506 { NFS_MOUNT_NORDIRPLUS
, ",nordirplus", "" },
507 { NFS_MOUNT_UNSHARED
, ",nosharecache", ""},
510 const struct proc_nfs_info
*nfs_infop
;
511 struct nfs_client
*clp
= nfss
->nfs_client
;
512 u32 version
= clp
->rpc_ops
->version
;
514 seq_printf(m
, ",vers=%u", version
);
515 seq_printf(m
, ",rsize=%u", nfss
->rsize
);
516 seq_printf(m
, ",wsize=%u", nfss
->wsize
);
517 if (nfss
->bsize
!= 0)
518 seq_printf(m
, ",bsize=%u", nfss
->bsize
);
519 seq_printf(m
, ",namlen=%u", nfss
->namelen
);
520 if (nfss
->acregmin
!= 3*HZ
|| showdefaults
)
521 seq_printf(m
, ",acregmin=%u", nfss
->acregmin
/HZ
);
522 if (nfss
->acregmax
!= 60*HZ
|| showdefaults
)
523 seq_printf(m
, ",acregmax=%u", nfss
->acregmax
/HZ
);
524 if (nfss
->acdirmin
!= 30*HZ
|| showdefaults
)
525 seq_printf(m
, ",acdirmin=%u", nfss
->acdirmin
/HZ
);
526 if (nfss
->acdirmax
!= 60*HZ
|| showdefaults
)
527 seq_printf(m
, ",acdirmax=%u", nfss
->acdirmax
/HZ
);
528 for (nfs_infop
= nfs_info
; nfs_infop
->flag
; nfs_infop
++) {
529 if (nfss
->flags
& nfs_infop
->flag
)
530 seq_puts(m
, nfs_infop
->str
);
532 seq_puts(m
, nfs_infop
->nostr
);
534 seq_printf(m
, ",proto=%s",
535 rpc_peeraddr2str(nfss
->client
, RPC_DISPLAY_PROTO
));
537 if (nfss
->port
!= NFS_PORT
)
538 seq_printf(m
, ",port=%u", nfss
->port
);
541 seq_printf(m
, ",port=%u", nfss
->port
);
543 seq_printf(m
, ",timeo=%lu", 10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
);
544 seq_printf(m
, ",retrans=%u", nfss
->client
->cl_timeout
->to_retries
);
545 seq_printf(m
, ",sec=%s", nfs_pseudoflavour_to_name(nfss
->client
->cl_auth
->au_flavor
));
548 nfs_show_mountd_options(m
, nfss
, showdefaults
);
551 if (clp
->rpc_ops
->version
== 4)
552 seq_printf(m
, ",clientaddr=%s", clp
->cl_ipaddr
);
557 * Describe the mount options on this VFS mountpoint
559 static int nfs_show_options(struct seq_file
*m
, struct vfsmount
*mnt
)
561 struct nfs_server
*nfss
= NFS_SB(mnt
->mnt_sb
);
563 nfs_show_mount_options(m
, nfss
, 0);
565 seq_printf(m
, ",addr=%s",
566 rpc_peeraddr2str(nfss
->nfs_client
->cl_rpcclient
,
573 * Present statistical information for this VFS mountpoint
575 static int nfs_show_stats(struct seq_file
*m
, struct vfsmount
*mnt
)
578 struct nfs_server
*nfss
= NFS_SB(mnt
->mnt_sb
);
579 struct rpc_auth
*auth
= nfss
->client
->cl_auth
;
580 struct nfs_iostats totals
= { };
582 seq_printf(m
, "statvers=%s", NFS_IOSTAT_VERS
);
585 * Display all mount option settings
587 seq_printf(m
, "\n\topts:\t");
588 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_RDONLY
? "ro" : "rw");
589 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_SYNCHRONOUS
? ",sync" : "");
590 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_NOATIME
? ",noatime" : "");
591 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_NODIRATIME
? ",nodiratime" : "");
592 nfs_show_mount_options(m
, nfss
, 1);
594 seq_printf(m
, "\n\tage:\t%lu", (jiffies
- nfss
->mount_time
) / HZ
);
596 seq_printf(m
, "\n\tcaps:\t");
597 seq_printf(m
, "caps=0x%x", nfss
->caps
);
598 seq_printf(m
, ",wtmult=%u", nfss
->wtmult
);
599 seq_printf(m
, ",dtsize=%u", nfss
->dtsize
);
600 seq_printf(m
, ",bsize=%u", nfss
->bsize
);
601 seq_printf(m
, ",namlen=%u", nfss
->namelen
);
604 if (nfss
->nfs_client
->rpc_ops
->version
== 4) {
605 seq_printf(m
, "\n\tnfsv4:\t");
606 seq_printf(m
, "bm0=0x%x", nfss
->attr_bitmask
[0]);
607 seq_printf(m
, ",bm1=0x%x", nfss
->attr_bitmask
[1]);
608 seq_printf(m
, ",acl=0x%x", nfss
->acl_bitmask
);
613 * Display security flavor in effect for this mount
615 seq_printf(m
, "\n\tsec:\tflavor=%u", auth
->au_ops
->au_flavor
);
617 seq_printf(m
, ",pseudoflavor=%u", auth
->au_flavor
);
620 * Display superblock I/O counters
622 for_each_possible_cpu(cpu
) {
623 struct nfs_iostats
*stats
;
626 stats
= per_cpu_ptr(nfss
->io_stats
, cpu
);
628 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
629 totals
.events
[i
] += stats
->events
[i
];
630 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
631 totals
.bytes
[i
] += stats
->bytes
[i
];
636 seq_printf(m
, "\n\tevents:\t");
637 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
638 seq_printf(m
, "%lu ", totals
.events
[i
]);
639 seq_printf(m
, "\n\tbytes:\t");
640 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
641 seq_printf(m
, "%Lu ", totals
.bytes
[i
]);
644 rpc_print_iostats(m
, nfss
->client
);
650 * Begin unmount by attempting to remove all automounted mountpoints we added
651 * in response to xdev traversals and referrals
653 static void nfs_umount_begin(struct super_block
*sb
)
655 struct nfs_server
*server
= NFS_SB(sb
);
656 struct rpc_clnt
*rpc
;
658 /* -EIO all pending I/O */
659 rpc
= server
->client_acl
;
661 rpc_killall_tasks(rpc
);
662 rpc
= server
->client
;
664 rpc_killall_tasks(rpc
);
668 * Set the port number in an address. Be agnostic about the address family.
670 static void nfs_set_port(struct sockaddr
*sap
, unsigned short port
)
672 switch (sap
->sa_family
) {
674 struct sockaddr_in
*ap
= (struct sockaddr_in
*)sap
;
675 ap
->sin_port
= htons(port
);
679 struct sockaddr_in6
*ap
= (struct sockaddr_in6
*)sap
;
680 ap
->sin6_port
= htons(port
);
687 * Sanity-check a server address provided by the mount command.
689 * Address family must be initialized, and address must not be
690 * the ANY address for that family.
692 static int nfs_verify_server_address(struct sockaddr
*addr
)
694 switch (addr
->sa_family
) {
696 struct sockaddr_in
*sa
= (struct sockaddr_in
*)addr
;
697 return sa
->sin_addr
.s_addr
!= htonl(INADDR_ANY
);
700 struct in6_addr
*sa
= &((struct sockaddr_in6
*)addr
)->sin6_addr
;
701 return !ipv6_addr_any(sa
);
709 * Parse string addresses passed in via a mount option,
710 * and construct a sockaddr based on the result.
712 * If address parsing fails, set the sockaddr's address
713 * family to AF_UNSPEC to force nfs_verify_server_address()
716 static void nfs_parse_server_address(char *value
,
717 struct sockaddr
*sap
,
720 if (strchr(value
, ':')) {
721 struct sockaddr_in6
*ap
= (struct sockaddr_in6
*)sap
;
722 u8
*addr
= (u8
*)&ap
->sin6_addr
.in6_u
;
724 ap
->sin6_family
= AF_INET6
;
726 if (in6_pton(value
, -1, addr
, '\0', NULL
))
729 struct sockaddr_in
*ap
= (struct sockaddr_in
*)sap
;
730 u8
*addr
= (u8
*)&ap
->sin_addr
.s_addr
;
732 ap
->sin_family
= AF_INET
;
734 if (in4_pton(value
, -1, addr
, '\0', NULL
))
738 sap
->sa_family
= AF_UNSPEC
;
743 * Error-check and convert a string of mount options from user space into
746 static int nfs_parse_mount_options(char *raw
,
747 struct nfs_parsed_mount_data
*mnt
)
749 char *p
, *string
, *secdata
;
753 dfprintk(MOUNT
, "NFS: mount options string was NULL.\n");
756 dfprintk(MOUNT
, "NFS: nfs mount opts='%s'\n", raw
);
758 secdata
= alloc_secdata();
762 rc
= security_sb_copy_data(raw
, secdata
);
764 goto out_security_failure
;
766 rc
= security_sb_parse_opts_str(secdata
, &mnt
->lsm_opts
);
768 goto out_security_failure
;
770 free_secdata(secdata
);
772 while ((p
= strsep(&raw
, ",")) != NULL
) {
773 substring_t args
[MAX_OPT_ARGS
];
779 dfprintk(MOUNT
, "NFS: parsing nfs mount option '%s'\n", p
);
781 token
= match_token(p
, nfs_mount_option_tokens
, args
);
784 mnt
->flags
|= NFS_MOUNT_SOFT
;
787 mnt
->flags
&= ~NFS_MOUNT_SOFT
;
793 mnt
->flags
|= NFS_MOUNT_POSIX
;
796 mnt
->flags
&= ~NFS_MOUNT_POSIX
;
799 mnt
->flags
&= ~NFS_MOUNT_NOCTO
;
802 mnt
->flags
|= NFS_MOUNT_NOCTO
;
805 mnt
->flags
&= ~NFS_MOUNT_NOAC
;
808 mnt
->flags
|= NFS_MOUNT_NOAC
;
811 mnt
->flags
&= ~NFS_MOUNT_NONLM
;
814 mnt
->flags
|= NFS_MOUNT_NONLM
;
817 mnt
->flags
&= ~NFS_MOUNT_VER3
;
820 mnt
->flags
|= NFS_MOUNT_VER3
;
823 mnt
->flags
&= ~NFS_MOUNT_TCP
;
824 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
829 mnt
->flags
|= NFS_MOUNT_TCP
;
830 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
835 mnt
->flags
|= NFS_MOUNT_TCP
; /* for side protocols */
836 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_RDMA
;
841 mnt
->flags
&= ~NFS_MOUNT_NOACL
;
844 mnt
->flags
|= NFS_MOUNT_NOACL
;
847 mnt
->flags
&= ~NFS_MOUNT_NORDIRPLUS
;
850 mnt
->flags
|= NFS_MOUNT_NORDIRPLUS
;
853 mnt
->flags
&= ~NFS_MOUNT_UNSHARED
;
855 case Opt_nosharecache
:
856 mnt
->flags
|= NFS_MOUNT_UNSHARED
;
860 if (match_int(args
, &option
))
862 if (option
< 0 || option
> 65535)
864 mnt
->nfs_server
.port
= option
;
867 if (match_int(args
, &mnt
->rsize
))
871 if (match_int(args
, &mnt
->wsize
))
875 if (match_int(args
, &option
))
882 if (match_int(args
, &mnt
->timeo
))
886 if (match_int(args
, &mnt
->retrans
))
890 if (match_int(args
, &mnt
->acregmin
))
894 if (match_int(args
, &mnt
->acregmax
))
898 if (match_int(args
, &mnt
->acdirmin
))
902 if (match_int(args
, &mnt
->acdirmax
))
906 if (match_int(args
, &option
))
913 mnt
->acdirmax
= option
;
916 if (match_int(args
, &mnt
->namlen
))
920 if (match_int(args
, &option
))
922 if (option
< 0 || option
> 65535)
924 mnt
->mount_server
.port
= option
;
927 if (match_int(args
, &option
))
931 mnt
->mount_server
.version
= option
;
934 if (match_int(args
, &option
))
938 mnt
->flags
&= ~NFS_MOUNT_VER3
;
941 mnt
->flags
|= NFS_MOUNT_VER3
;
949 string
= match_strdup(args
);
952 token
= match_token(string
, nfs_secflavor_tokens
, args
);
956 * The flags setting is for v2/v3. The flavor_len
957 * setting is for v4. v2/v3 also need to know the
958 * difference between NULL and UNIX.
962 mnt
->flags
&= ~NFS_MOUNT_SECFLAVOUR
;
963 mnt
->auth_flavor_len
= 0;
964 mnt
->auth_flavors
[0] = RPC_AUTH_NULL
;
967 mnt
->flags
&= ~NFS_MOUNT_SECFLAVOUR
;
968 mnt
->auth_flavor_len
= 0;
969 mnt
->auth_flavors
[0] = RPC_AUTH_UNIX
;
972 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
973 mnt
->auth_flavor_len
= 1;
974 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5
;
977 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
978 mnt
->auth_flavor_len
= 1;
979 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5I
;
982 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
983 mnt
->auth_flavor_len
= 1;
984 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5P
;
987 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
988 mnt
->auth_flavor_len
= 1;
989 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEY
;
992 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
993 mnt
->auth_flavor_len
= 1;
994 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEYI
;
997 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
998 mnt
->auth_flavor_len
= 1;
999 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEYP
;
1002 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
1003 mnt
->auth_flavor_len
= 1;
1004 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKM
;
1007 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
1008 mnt
->auth_flavor_len
= 1;
1009 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKMI
;
1012 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
1013 mnt
->auth_flavor_len
= 1;
1014 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKMP
;
1021 string
= match_strdup(args
);
1024 token
= match_token(string
,
1025 nfs_xprt_protocol_tokens
, args
);
1030 mnt
->flags
&= ~NFS_MOUNT_TCP
;
1031 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1036 mnt
->flags
|= NFS_MOUNT_TCP
;
1037 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1042 /* vector side protocols to TCP */
1043 mnt
->flags
|= NFS_MOUNT_TCP
;
1044 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_RDMA
;
1049 goto out_unrec_xprt
;
1052 case Opt_mountproto
:
1053 string
= match_strdup(args
);
1056 token
= match_token(string
,
1057 nfs_xprt_protocol_tokens
, args
);
1062 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_UDP
;
1065 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_TCP
;
1067 case Opt_xprt_rdma
: /* not used for side protocols */
1069 goto out_unrec_xprt
;
1073 string
= match_strdup(args
);
1076 nfs_parse_server_address(string
, (struct sockaddr
*)
1077 &mnt
->nfs_server
.address
,
1078 &mnt
->nfs_server
.addrlen
);
1081 case Opt_clientaddr
:
1082 string
= match_strdup(args
);
1085 kfree(mnt
->client_address
);
1086 mnt
->client_address
= string
;
1089 string
= match_strdup(args
);
1092 kfree(mnt
->mount_server
.hostname
);
1093 mnt
->mount_server
.hostname
= string
;
1096 string
= match_strdup(args
);
1099 nfs_parse_server_address(string
, (struct sockaddr
*)
1100 &mnt
->mount_server
.address
,
1101 &mnt
->mount_server
.addrlen
);
1106 case Opt_deprecated
:
1114 nfs_set_port((struct sockaddr
*)&mnt
->nfs_server
.address
,
1115 mnt
->nfs_server
.port
);
1120 printk(KERN_INFO
"NFS: not enough memory to parse option\n");
1122 out_security_failure
:
1123 free_secdata(secdata
);
1124 printk(KERN_INFO
"NFS: security options invalid: %d\n", rc
);
1127 printk(KERN_INFO
"NFS: unrecognized NFS version number\n");
1131 printk(KERN_INFO
"NFS: unrecognized transport protocol\n");
1135 printk(KERN_INFO
"NFS: unrecognized security flavor\n");
1139 printk(KERN_INFO
"NFS: unknown mount option: %s\n", p
);
1144 * Use the remote server's MOUNT service to request the NFS file handle
1145 * corresponding to the provided path.
1147 static int nfs_try_mount(struct nfs_parsed_mount_data
*args
,
1148 struct nfs_fh
*root_fh
)
1150 struct sockaddr
*sap
= (struct sockaddr
*)&args
->mount_server
.address
;
1154 if (args
->mount_server
.version
== 0) {
1155 if (args
->flags
& NFS_MOUNT_VER3
)
1156 args
->mount_server
.version
= NFS_MNT3_VERSION
;
1158 args
->mount_server
.version
= NFS_MNT_VERSION
;
1161 if (args
->mount_server
.hostname
)
1162 hostname
= args
->mount_server
.hostname
;
1164 hostname
= args
->nfs_server
.hostname
;
1167 * Construct the mount server's address.
1169 if (args
->mount_server
.address
.ss_family
== AF_UNSPEC
) {
1170 memcpy(sap
, &args
->nfs_server
.address
,
1171 args
->nfs_server
.addrlen
);
1172 args
->mount_server
.addrlen
= args
->nfs_server
.addrlen
;
1176 * autobind will be used if mount_server.port == 0
1178 nfs_set_port(sap
, args
->mount_server
.port
);
1181 * Now ask the mount server to map our export path
1184 status
= nfs_mount(sap
,
1185 args
->mount_server
.addrlen
,
1187 args
->nfs_server
.export_path
,
1188 args
->mount_server
.version
,
1189 args
->mount_server
.protocol
,
1194 dfprintk(MOUNT
, "NFS: unable to mount server %s, error %d",
1200 * Validate the NFS2/NFS3 mount data
1201 * - fills in the mount root filehandle
1203 * For option strings, user space handles the following behaviors:
1205 * + DNS: mapping server host name to IP address ("addr=" option)
1207 * + failure mode: how to behave if a mount request can't be handled
1208 * immediately ("fg/bg" option)
1210 * + retry: how often to retry a mount request ("retry=" option)
1212 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1213 * mountproto=tcp after mountproto=udp, and so on
1215 static int nfs_validate_mount_data(void *options
,
1216 struct nfs_parsed_mount_data
*args
,
1217 struct nfs_fh
*mntfh
,
1218 const char *dev_name
)
1220 struct nfs_mount_data
*data
= (struct nfs_mount_data
*)options
;
1225 args
->flags
= (NFS_MOUNT_VER3
| NFS_MOUNT_TCP
);
1226 args
->rsize
= NFS_MAX_FILE_IO_SIZE
;
1227 args
->wsize
= NFS_MAX_FILE_IO_SIZE
;
1231 args
->acregmax
= 60;
1232 args
->acdirmin
= 30;
1233 args
->acdirmax
= 60;
1234 args
->mount_server
.port
= 0; /* autobind unless user sets port */
1235 args
->mount_server
.protocol
= XPRT_TRANSPORT_UDP
;
1236 args
->nfs_server
.port
= 0; /* autobind unless user sets port */
1237 args
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1239 switch (data
->version
) {
1245 if (data
->flags
& NFS_MOUNT_VER3
)
1247 data
->root
.size
= NFS2_FHSIZE
;
1248 memcpy(data
->root
.data
, data
->old_root
.data
, NFS2_FHSIZE
);
1250 if (data
->flags
& NFS_MOUNT_SECFLAVOUR
)
1253 memset(data
->context
, 0, sizeof(data
->context
));
1255 if (data
->flags
& NFS_MOUNT_VER3
) {
1256 if (data
->root
.size
> NFS3_FHSIZE
|| data
->root
.size
== 0)
1257 goto out_invalid_fh
;
1258 mntfh
->size
= data
->root
.size
;
1260 mntfh
->size
= NFS2_FHSIZE
;
1263 memcpy(mntfh
->data
, data
->root
.data
, mntfh
->size
);
1264 if (mntfh
->size
< sizeof(mntfh
->data
))
1265 memset(mntfh
->data
+ mntfh
->size
, 0,
1266 sizeof(mntfh
->data
) - mntfh
->size
);
1269 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1272 args
->flags
= data
->flags
;
1273 args
->rsize
= data
->rsize
;
1274 args
->wsize
= data
->wsize
;
1275 args
->timeo
= data
->timeo
;
1276 args
->retrans
= data
->retrans
;
1277 args
->acregmin
= data
->acregmin
;
1278 args
->acregmax
= data
->acregmax
;
1279 args
->acdirmin
= data
->acdirmin
;
1280 args
->acdirmax
= data
->acdirmax
;
1282 memcpy(&args
->nfs_server
.address
, &data
->addr
,
1283 sizeof(data
->addr
));
1284 args
->nfs_server
.addrlen
= sizeof(data
->addr
);
1285 if (!nfs_verify_server_address((struct sockaddr
*)
1286 &args
->nfs_server
.address
))
1287 goto out_no_address
;
1289 if (!(data
->flags
& NFS_MOUNT_TCP
))
1290 args
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1291 /* N.B. caller will free nfs_server.hostname in all cases */
1292 args
->nfs_server
.hostname
= kstrdup(data
->hostname
, GFP_KERNEL
);
1293 args
->namlen
= data
->namlen
;
1294 args
->bsize
= data
->bsize
;
1295 args
->auth_flavors
[0] = data
->pseudoflavor
;
1296 if (!args
->nfs_server
.hostname
)
1300 * The legacy version 6 binary mount data from userspace has a
1301 * field used only to transport selinux information into the
1302 * the kernel. To continue to support that functionality we
1303 * have a touch of selinux knowledge here in the NFS code. The
1304 * userspace code converted context=blah to just blah so we are
1305 * converting back to the full string selinux understands.
1307 if (data
->context
[0]){
1308 #ifdef CONFIG_SECURITY_SELINUX
1310 char *opts_str
= kmalloc(sizeof(data
->context
) + 8, GFP_KERNEL
);
1313 strcpy(opts_str
, "context=");
1314 data
->context
[NFS_MAX_CONTEXT_LEN
] = '\0';
1315 strcat(opts_str
, &data
->context
[0]);
1316 rc
= security_sb_parse_opts_str(opts_str
, &args
->lsm_opts
);
1331 if (nfs_parse_mount_options((char *)options
, args
) == 0)
1334 if (!nfs_verify_server_address((struct sockaddr
*)
1335 &args
->nfs_server
.address
))
1336 goto out_no_address
;
1338 c
= strchr(dev_name
, ':');
1342 /* N.B. caller will free nfs_server.hostname in all cases */
1343 args
->nfs_server
.hostname
= kstrndup(dev_name
, len
, GFP_KERNEL
);
1344 if (!args
->nfs_server
.hostname
)
1348 if (strlen(c
) > NFS_MAXPATHLEN
)
1349 return -ENAMETOOLONG
;
1350 args
->nfs_server
.export_path
= c
;
1352 status
= nfs_try_mount(args
, mntfh
);
1360 if (!(args
->flags
& NFS_MOUNT_SECFLAVOUR
))
1361 args
->auth_flavors
[0] = RPC_AUTH_UNIX
;
1363 #ifndef CONFIG_NFS_V3
1364 if (args
->flags
& NFS_MOUNT_VER3
)
1365 goto out_v3_not_compiled
;
1366 #endif /* !CONFIG_NFS_V3 */
1371 dfprintk(MOUNT
, "NFS: mount program didn't pass any mount data\n");
1375 dfprintk(MOUNT
, "NFS: nfs_mount_data version %d does not support v3\n",
1380 dfprintk(MOUNT
, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1383 #ifndef CONFIG_NFS_V3
1384 out_v3_not_compiled
:
1385 dfprintk(MOUNT
, "NFS: NFSv3 is not compiled into kernel\n");
1386 return -EPROTONOSUPPORT
;
1387 #endif /* !CONFIG_NFS_V3 */
1390 dfprintk(MOUNT
, "NFS: not enough memory to handle mount options\n");
1394 dfprintk(MOUNT
, "NFS: mount program didn't pass remote address\n");
1398 dfprintk(MOUNT
, "NFS: invalid root filehandle\n");
1403 nfs_compare_remount_data(struct nfs_server
*nfss
,
1404 struct nfs_parsed_mount_data
*data
)
1406 if (data
->flags
!= nfss
->flags
||
1407 data
->rsize
!= nfss
->rsize
||
1408 data
->wsize
!= nfss
->wsize
||
1409 data
->retrans
!= nfss
->client
->cl_timeout
->to_retries
||
1410 data
->auth_flavors
[0] != nfss
->client
->cl_auth
->au_flavor
||
1411 data
->acregmin
!= nfss
->acregmin
/ HZ
||
1412 data
->acregmax
!= nfss
->acregmax
/ HZ
||
1413 data
->acdirmin
!= nfss
->acdirmin
/ HZ
||
1414 data
->acdirmax
!= nfss
->acdirmax
/ HZ
||
1415 data
->timeo
!= (10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
) ||
1416 data
->nfs_server
.addrlen
!= nfss
->nfs_client
->cl_addrlen
||
1417 memcmp(&data
->nfs_server
.address
, &nfss
->nfs_client
->cl_addr
,
1418 data
->nfs_server
.addrlen
) != 0)
1425 nfs_remount(struct super_block
*sb
, int *flags
, char *raw_data
)
1428 struct nfs_server
*nfss
= sb
->s_fs_info
;
1429 struct nfs_parsed_mount_data
*data
;
1430 struct nfs_mount_data
*options
= (struct nfs_mount_data
*)raw_data
;
1431 struct nfs4_mount_data
*options4
= (struct nfs4_mount_data
*)raw_data
;
1434 * Userspace mount programs that send binary options generally send
1435 * them populated with default values. We have no way to know which
1436 * ones were explicitly specified. Fall back to legacy behavior and
1437 * just return success.
1439 if ((sb
->s_type
== &nfs4_fs_type
&& options4
->version
== 1) ||
1440 (sb
->s_type
== &nfs_fs_type
&& options
->version
>= 1 &&
1441 options
->version
<= 6))
1444 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
1448 /* fill out struct with values from existing mount */
1449 data
->flags
= nfss
->flags
;
1450 data
->rsize
= nfss
->rsize
;
1451 data
->wsize
= nfss
->wsize
;
1452 data
->retrans
= nfss
->client
->cl_timeout
->to_retries
;
1453 data
->auth_flavors
[0] = nfss
->client
->cl_auth
->au_flavor
;
1454 data
->acregmin
= nfss
->acregmin
/ HZ
;
1455 data
->acregmax
= nfss
->acregmax
/ HZ
;
1456 data
->acdirmin
= nfss
->acdirmin
/ HZ
;
1457 data
->acdirmax
= nfss
->acdirmax
/ HZ
;
1458 data
->timeo
= 10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
;
1459 data
->nfs_server
.addrlen
= nfss
->nfs_client
->cl_addrlen
;
1460 memcpy(&data
->nfs_server
.address
, &nfss
->nfs_client
->cl_addr
,
1461 data
->nfs_server
.addrlen
);
1463 /* overwrite those values with any that were specified */
1464 error
= nfs_parse_mount_options((char *)options
, data
);
1468 /* compare new mount options with old ones */
1469 error
= nfs_compare_remount_data(nfss
, data
);
1476 * Initialise the common bits of the superblock
1478 static inline void nfs_initialise_sb(struct super_block
*sb
)
1480 struct nfs_server
*server
= NFS_SB(sb
);
1482 sb
->s_magic
= NFS_SUPER_MAGIC
;
1484 /* We probably want something more informative here */
1485 snprintf(sb
->s_id
, sizeof(sb
->s_id
),
1486 "%x:%x", MAJOR(sb
->s_dev
), MINOR(sb
->s_dev
));
1488 if (sb
->s_blocksize
== 0)
1489 sb
->s_blocksize
= nfs_block_bits(server
->wsize
,
1490 &sb
->s_blocksize_bits
);
1492 if (server
->flags
& NFS_MOUNT_NOAC
)
1493 sb
->s_flags
|= MS_SYNCHRONOUS
;
1495 nfs_super_set_maxbytes(sb
, server
->maxfilesize
);
1499 * Finish setting up an NFS2/3 superblock
1501 static void nfs_fill_super(struct super_block
*sb
,
1502 struct nfs_parsed_mount_data
*data
)
1504 struct nfs_server
*server
= NFS_SB(sb
);
1506 sb
->s_blocksize_bits
= 0;
1507 sb
->s_blocksize
= 0;
1509 sb
->s_blocksize
= nfs_block_size(data
->bsize
, &sb
->s_blocksize_bits
);
1511 if (server
->flags
& NFS_MOUNT_VER3
) {
1512 /* The VFS shouldn't apply the umask to mode bits. We will do
1513 * so ourselves when necessary.
1515 sb
->s_flags
|= MS_POSIXACL
;
1516 sb
->s_time_gran
= 1;
1519 sb
->s_op
= &nfs_sops
;
1520 nfs_initialise_sb(sb
);
1524 * Finish setting up a cloned NFS2/3 superblock
1526 static void nfs_clone_super(struct super_block
*sb
,
1527 const struct super_block
*old_sb
)
1529 struct nfs_server
*server
= NFS_SB(sb
);
1531 sb
->s_blocksize_bits
= old_sb
->s_blocksize_bits
;
1532 sb
->s_blocksize
= old_sb
->s_blocksize
;
1533 sb
->s_maxbytes
= old_sb
->s_maxbytes
;
1535 if (server
->flags
& NFS_MOUNT_VER3
) {
1536 /* The VFS shouldn't apply the umask to mode bits. We will do
1537 * so ourselves when necessary.
1539 sb
->s_flags
|= MS_POSIXACL
;
1540 sb
->s_time_gran
= 1;
1543 sb
->s_op
= old_sb
->s_op
;
1544 nfs_initialise_sb(sb
);
1547 #define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
1549 static int nfs_compare_mount_options(const struct super_block
*s
, const struct nfs_server
*b
, int flags
)
1551 const struct nfs_server
*a
= s
->s_fs_info
;
1552 const struct rpc_clnt
*clnt_a
= a
->client
;
1553 const struct rpc_clnt
*clnt_b
= b
->client
;
1555 if ((s
->s_flags
& NFS_MS_MASK
) != (flags
& NFS_MS_MASK
))
1557 if (a
->nfs_client
!= b
->nfs_client
)
1559 if (a
->flags
!= b
->flags
)
1561 if (a
->wsize
!= b
->wsize
)
1563 if (a
->rsize
!= b
->rsize
)
1565 if (a
->acregmin
!= b
->acregmin
)
1567 if (a
->acregmax
!= b
->acregmax
)
1569 if (a
->acdirmin
!= b
->acdirmin
)
1571 if (a
->acdirmax
!= b
->acdirmax
)
1573 if (clnt_a
->cl_auth
->au_flavor
!= clnt_b
->cl_auth
->au_flavor
)
1580 struct nfs_sb_mountdata
{
1581 struct nfs_server
*server
;
1585 static int nfs_set_super(struct super_block
*s
, void *data
)
1587 struct nfs_sb_mountdata
*sb_mntdata
= data
;
1588 struct nfs_server
*server
= sb_mntdata
->server
;
1591 s
->s_flags
= sb_mntdata
->mntflags
;
1592 s
->s_fs_info
= server
;
1593 ret
= set_anon_super(s
, server
);
1595 server
->s_dev
= s
->s_dev
;
1599 static int nfs_compare_super_address(struct nfs_server
*server1
,
1600 struct nfs_server
*server2
)
1602 struct sockaddr
*sap1
, *sap2
;
1604 sap1
= (struct sockaddr
*)&server1
->nfs_client
->cl_addr
;
1605 sap2
= (struct sockaddr
*)&server2
->nfs_client
->cl_addr
;
1607 if (sap1
->sa_family
!= sap2
->sa_family
)
1610 switch (sap1
->sa_family
) {
1612 struct sockaddr_in
*sin1
= (struct sockaddr_in
*)sap1
;
1613 struct sockaddr_in
*sin2
= (struct sockaddr_in
*)sap2
;
1614 if (sin1
->sin_addr
.s_addr
!= sin2
->sin_addr
.s_addr
)
1616 if (sin1
->sin_port
!= sin2
->sin_port
)
1621 struct sockaddr_in6
*sin1
= (struct sockaddr_in6
*)sap1
;
1622 struct sockaddr_in6
*sin2
= (struct sockaddr_in6
*)sap2
;
1623 if (!ipv6_addr_equal(&sin1
->sin6_addr
, &sin2
->sin6_addr
))
1625 if (sin1
->sin6_port
!= sin2
->sin6_port
)
1636 static int nfs_compare_super(struct super_block
*sb
, void *data
)
1638 struct nfs_sb_mountdata
*sb_mntdata
= data
;
1639 struct nfs_server
*server
= sb_mntdata
->server
, *old
= NFS_SB(sb
);
1640 int mntflags
= sb_mntdata
->mntflags
;
1642 if (!nfs_compare_super_address(old
, server
))
1644 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1645 if (old
->flags
& NFS_MOUNT_UNSHARED
)
1647 if (memcmp(&old
->fsid
, &server
->fsid
, sizeof(old
->fsid
)) != 0)
1649 return nfs_compare_mount_options(sb
, server
, mntflags
);
1652 static int nfs_bdi_register(struct nfs_server
*server
)
1654 return bdi_register_dev(&server
->backing_dev_info
, server
->s_dev
);
1657 static int nfs_get_sb(struct file_system_type
*fs_type
,
1658 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
1660 struct nfs_server
*server
= NULL
;
1661 struct super_block
*s
;
1662 struct nfs_parsed_mount_data
*data
;
1663 struct nfs_fh
*mntfh
;
1664 struct dentry
*mntroot
;
1665 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
1666 struct nfs_sb_mountdata sb_mntdata
= {
1669 int error
= -ENOMEM
;
1671 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
1672 mntfh
= kzalloc(sizeof(*mntfh
), GFP_KERNEL
);
1673 if (data
== NULL
|| mntfh
== NULL
)
1676 security_init_mnt_opts(&data
->lsm_opts
);
1678 /* Validate the mount data */
1679 error
= nfs_validate_mount_data(raw_data
, data
, mntfh
, dev_name
);
1683 /* Get a volume representation */
1684 server
= nfs_create_server(data
, mntfh
);
1685 if (IS_ERR(server
)) {
1686 error
= PTR_ERR(server
);
1689 sb_mntdata
.server
= server
;
1691 if (server
->flags
& NFS_MOUNT_UNSHARED
)
1692 compare_super
= NULL
;
1694 /* Get a superblock - note that we may end up sharing one that already exists */
1695 s
= sget(fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
1701 if (s
->s_fs_info
!= server
) {
1702 nfs_free_server(server
);
1705 error
= nfs_bdi_register(server
);
1707 goto error_splat_super
;
1711 /* initial superblock/root creation */
1712 nfs_fill_super(s
, data
);
1715 mntroot
= nfs_get_root(s
, mntfh
);
1716 if (IS_ERR(mntroot
)) {
1717 error
= PTR_ERR(mntroot
);
1718 goto error_splat_super
;
1721 error
= security_sb_set_mnt_opts(s
, &data
->lsm_opts
);
1723 goto error_splat_root
;
1725 s
->s_flags
|= MS_ACTIVE
;
1727 mnt
->mnt_root
= mntroot
;
1731 kfree(data
->nfs_server
.hostname
);
1732 kfree(data
->mount_server
.hostname
);
1733 security_free_mnt_opts(&data
->lsm_opts
);
1740 nfs_free_server(server
);
1746 up_write(&s
->s_umount
);
1747 deactivate_super(s
);
1752 * Destroy an NFS2/3 superblock
1754 static void nfs_kill_super(struct super_block
*s
)
1756 struct nfs_server
*server
= NFS_SB(s
);
1758 bdi_unregister(&server
->backing_dev_info
);
1760 nfs_free_server(server
);
1764 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
1766 static int nfs_xdev_get_sb(struct file_system_type
*fs_type
, int flags
,
1767 const char *dev_name
, void *raw_data
,
1768 struct vfsmount
*mnt
)
1770 struct nfs_clone_mount
*data
= raw_data
;
1771 struct super_block
*s
;
1772 struct nfs_server
*server
;
1773 struct dentry
*mntroot
;
1774 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
1775 struct nfs_sb_mountdata sb_mntdata
= {
1780 dprintk("--> nfs_xdev_get_sb()\n");
1782 /* create a new volume representation */
1783 server
= nfs_clone_server(NFS_SB(data
->sb
), data
->fh
, data
->fattr
);
1784 if (IS_ERR(server
)) {
1785 error
= PTR_ERR(server
);
1786 goto out_err_noserver
;
1788 sb_mntdata
.server
= server
;
1790 if (server
->flags
& NFS_MOUNT_UNSHARED
)
1791 compare_super
= NULL
;
1793 /* Get a superblock - note that we may end up sharing one that already exists */
1794 s
= sget(&nfs_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
1800 if (s
->s_fs_info
!= server
) {
1801 nfs_free_server(server
);
1804 error
= nfs_bdi_register(server
);
1806 goto error_splat_super
;
1810 /* initial superblock/root creation */
1811 nfs_clone_super(s
, data
->sb
);
1814 mntroot
= nfs_get_root(s
, data
->fh
);
1815 if (IS_ERR(mntroot
)) {
1816 error
= PTR_ERR(mntroot
);
1817 goto error_splat_super
;
1819 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
1822 goto error_splat_super
;
1825 s
->s_flags
|= MS_ACTIVE
;
1827 mnt
->mnt_root
= mntroot
;
1829 /* clone any lsm security options from the parent to the new sb */
1830 security_sb_clone_mnt_opts(data
->sb
, s
);
1832 dprintk("<-- nfs_xdev_get_sb() = 0\n");
1836 nfs_free_server(server
);
1838 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error
);
1842 up_write(&s
->s_umount
);
1843 deactivate_super(s
);
1844 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error
);
1848 #ifdef CONFIG_NFS_V4
1851 * Finish setting up a cloned NFS4 superblock
1853 static void nfs4_clone_super(struct super_block
*sb
,
1854 const struct super_block
*old_sb
)
1856 sb
->s_blocksize_bits
= old_sb
->s_blocksize_bits
;
1857 sb
->s_blocksize
= old_sb
->s_blocksize
;
1858 sb
->s_maxbytes
= old_sb
->s_maxbytes
;
1859 sb
->s_time_gran
= 1;
1860 sb
->s_op
= old_sb
->s_op
;
1861 nfs_initialise_sb(sb
);
1865 * Set up an NFS4 superblock
1867 static void nfs4_fill_super(struct super_block
*sb
)
1869 sb
->s_time_gran
= 1;
1870 sb
->s_op
= &nfs4_sops
;
1871 nfs_initialise_sb(sb
);
1875 * Validate NFSv4 mount options
1877 static int nfs4_validate_mount_data(void *options
,
1878 struct nfs_parsed_mount_data
*args
,
1879 const char *dev_name
)
1881 struct sockaddr_in
*ap
;
1882 struct nfs4_mount_data
*data
= (struct nfs4_mount_data
*)options
;
1888 args
->rsize
= NFS_MAX_FILE_IO_SIZE
;
1889 args
->wsize
= NFS_MAX_FILE_IO_SIZE
;
1893 args
->acregmax
= 60;
1894 args
->acdirmin
= 30;
1895 args
->acdirmax
= 60;
1896 args
->nfs_server
.port
= NFS_PORT
; /* 2049 unless user set port= */
1897 args
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1899 switch (data
->version
) {
1901 ap
= (struct sockaddr_in
*)&args
->nfs_server
.address
;
1902 if (data
->host_addrlen
> sizeof(args
->nfs_server
.address
))
1903 goto out_no_address
;
1904 if (data
->host_addrlen
== 0)
1905 goto out_no_address
;
1906 args
->nfs_server
.addrlen
= data
->host_addrlen
;
1907 if (copy_from_user(ap
, data
->host_addr
, data
->host_addrlen
))
1909 if (!nfs_verify_server_address((struct sockaddr
*)
1910 &args
->nfs_server
.address
))
1911 goto out_no_address
;
1913 switch (data
->auth_flavourlen
) {
1915 args
->auth_flavors
[0] = RPC_AUTH_UNIX
;
1918 if (copy_from_user(&args
->auth_flavors
[0],
1919 data
->auth_flavours
,
1920 sizeof(args
->auth_flavors
[0])))
1924 goto out_inval_auth
;
1927 c
= strndup_user(data
->hostname
.data
, NFS4_MAXNAMLEN
);
1930 args
->nfs_server
.hostname
= c
;
1932 c
= strndup_user(data
->mnt_path
.data
, NFS4_MAXPATHLEN
);
1935 args
->nfs_server
.export_path
= c
;
1936 dfprintk(MOUNT
, "NFS: MNTPATH: '%s'\n", c
);
1938 c
= strndup_user(data
->client_addr
.data
, 16);
1941 args
->client_address
= c
;
1944 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
1948 args
->flags
= data
->flags
& NFS4_MOUNT_FLAGMASK
;
1949 args
->rsize
= data
->rsize
;
1950 args
->wsize
= data
->wsize
;
1951 args
->timeo
= data
->timeo
;
1952 args
->retrans
= data
->retrans
;
1953 args
->acregmin
= data
->acregmin
;
1954 args
->acregmax
= data
->acregmax
;
1955 args
->acdirmin
= data
->acdirmin
;
1956 args
->acdirmax
= data
->acdirmax
;
1957 args
->nfs_server
.protocol
= data
->proto
;
1963 if (nfs_parse_mount_options((char *)options
, args
) == 0)
1966 if (!nfs_verify_server_address((struct sockaddr
*)
1967 &args
->nfs_server
.address
))
1970 switch (args
->auth_flavor_len
) {
1972 args
->auth_flavors
[0] = RPC_AUTH_UNIX
;
1977 goto out_inval_auth
;
1981 * Split "dev_name" into "hostname:mntpath".
1983 c
= strchr(dev_name
, ':');
1986 /* while calculating len, pretend ':' is '\0' */
1988 if (len
> NFS4_MAXNAMLEN
)
1989 return -ENAMETOOLONG
;
1990 /* N.B. caller will free nfs_server.hostname in all cases */
1991 args
->nfs_server
.hostname
= kstrndup(dev_name
, len
, GFP_KERNEL
);
1992 if (!args
->nfs_server
.hostname
)
1995 c
++; /* step over the ':' */
1997 if (len
> NFS4_MAXPATHLEN
)
1998 return -ENAMETOOLONG
;
1999 args
->nfs_server
.export_path
= kstrndup(c
, len
, GFP_KERNEL
);
2000 if (!args
->nfs_server
.export_path
)
2003 dprintk("NFS: MNTPATH: '%s'\n", args
->nfs_server
.export_path
);
2005 if (args
->client_address
== NULL
)
2006 goto out_no_client_address
;
2015 dfprintk(MOUNT
, "NFS4: mount program didn't pass any mount data\n");
2019 dfprintk(MOUNT
, "NFS4: Invalid number of RPC auth flavours %d\n",
2020 data
->auth_flavourlen
);
2024 dfprintk(MOUNT
, "NFS4: not enough memory to handle mount options\n");
2028 dfprintk(MOUNT
, "NFS4: mount program didn't pass remote address\n");
2031 out_no_client_address
:
2032 dfprintk(MOUNT
, "NFS4: mount program didn't pass callback address\n");
2037 * Get the superblock for an NFS4 mountpoint
2039 static int nfs4_get_sb(struct file_system_type
*fs_type
,
2040 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
2042 struct nfs_parsed_mount_data
*data
;
2043 struct super_block
*s
;
2044 struct nfs_server
*server
;
2045 struct nfs_fh
*mntfh
;
2046 struct dentry
*mntroot
;
2047 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2048 struct nfs_sb_mountdata sb_mntdata
= {
2051 int error
= -ENOMEM
;
2053 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
2054 mntfh
= kzalloc(sizeof(*mntfh
), GFP_KERNEL
);
2055 if (data
== NULL
|| mntfh
== NULL
)
2058 security_init_mnt_opts(&data
->lsm_opts
);
2060 /* Validate the mount data */
2061 error
= nfs4_validate_mount_data(raw_data
, data
, dev_name
);
2065 /* Get a volume representation */
2066 server
= nfs4_create_server(data
, mntfh
);
2067 if (IS_ERR(server
)) {
2068 error
= PTR_ERR(server
);
2071 sb_mntdata
.server
= server
;
2073 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2074 compare_super
= NULL
;
2076 /* Get a superblock - note that we may end up sharing one that already exists */
2077 s
= sget(fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2083 if (s
->s_fs_info
!= server
) {
2084 nfs_free_server(server
);
2087 error
= nfs_bdi_register(server
);
2089 goto error_splat_super
;
2093 /* initial superblock/root creation */
2097 mntroot
= nfs4_get_root(s
, mntfh
);
2098 if (IS_ERR(mntroot
)) {
2099 error
= PTR_ERR(mntroot
);
2100 goto error_splat_super
;
2103 error
= security_sb_set_mnt_opts(s
, &data
->lsm_opts
);
2105 goto error_splat_root
;
2107 s
->s_flags
|= MS_ACTIVE
;
2109 mnt
->mnt_root
= mntroot
;
2113 kfree(data
->client_address
);
2114 kfree(data
->nfs_server
.export_path
);
2115 kfree(data
->nfs_server
.hostname
);
2116 security_free_mnt_opts(&data
->lsm_opts
);
2123 nfs_free_server(server
);
2129 up_write(&s
->s_umount
);
2130 deactivate_super(s
);
2134 static void nfs4_kill_super(struct super_block
*sb
)
2136 struct nfs_server
*server
= NFS_SB(sb
);
2138 nfs_return_all_delegations(sb
);
2139 kill_anon_super(sb
);
2141 nfs4_renewd_prepare_shutdown(server
);
2142 nfs_free_server(server
);
2146 * Clone an NFS4 server record on xdev traversal (FSID-change)
2148 static int nfs4_xdev_get_sb(struct file_system_type
*fs_type
, int flags
,
2149 const char *dev_name
, void *raw_data
,
2150 struct vfsmount
*mnt
)
2152 struct nfs_clone_mount
*data
= raw_data
;
2153 struct super_block
*s
;
2154 struct nfs_server
*server
;
2155 struct dentry
*mntroot
;
2156 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2157 struct nfs_sb_mountdata sb_mntdata
= {
2162 dprintk("--> nfs4_xdev_get_sb()\n");
2164 /* create a new volume representation */
2165 server
= nfs_clone_server(NFS_SB(data
->sb
), data
->fh
, data
->fattr
);
2166 if (IS_ERR(server
)) {
2167 error
= PTR_ERR(server
);
2168 goto out_err_noserver
;
2170 sb_mntdata
.server
= server
;
2172 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2173 compare_super
= NULL
;
2175 /* Get a superblock - note that we may end up sharing one that already exists */
2176 s
= sget(&nfs_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2182 if (s
->s_fs_info
!= server
) {
2183 nfs_free_server(server
);
2186 error
= nfs_bdi_register(server
);
2188 goto error_splat_super
;
2192 /* initial superblock/root creation */
2193 nfs4_clone_super(s
, data
->sb
);
2196 mntroot
= nfs4_get_root(s
, data
->fh
);
2197 if (IS_ERR(mntroot
)) {
2198 error
= PTR_ERR(mntroot
);
2199 goto error_splat_super
;
2201 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
2204 goto error_splat_super
;
2207 s
->s_flags
|= MS_ACTIVE
;
2209 mnt
->mnt_root
= mntroot
;
2211 security_sb_clone_mnt_opts(data
->sb
, s
);
2213 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2217 nfs_free_server(server
);
2219 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error
);
2223 up_write(&s
->s_umount
);
2224 deactivate_super(s
);
2225 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error
);
2230 * Create an NFS4 server record on referral traversal
2232 static int nfs4_referral_get_sb(struct file_system_type
*fs_type
, int flags
,
2233 const char *dev_name
, void *raw_data
,
2234 struct vfsmount
*mnt
)
2236 struct nfs_clone_mount
*data
= raw_data
;
2237 struct super_block
*s
;
2238 struct nfs_server
*server
;
2239 struct dentry
*mntroot
;
2240 struct nfs_fh mntfh
;
2241 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2242 struct nfs_sb_mountdata sb_mntdata
= {
2247 dprintk("--> nfs4_referral_get_sb()\n");
2249 /* create a new volume representation */
2250 server
= nfs4_create_referral_server(data
, &mntfh
);
2251 if (IS_ERR(server
)) {
2252 error
= PTR_ERR(server
);
2253 goto out_err_noserver
;
2255 sb_mntdata
.server
= server
;
2257 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2258 compare_super
= NULL
;
2260 /* Get a superblock - note that we may end up sharing one that already exists */
2261 s
= sget(&nfs_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2267 if (s
->s_fs_info
!= server
) {
2268 nfs_free_server(server
);
2271 error
= nfs_bdi_register(server
);
2273 goto error_splat_super
;
2277 /* initial superblock/root creation */
2281 mntroot
= nfs4_get_root(s
, &mntfh
);
2282 if (IS_ERR(mntroot
)) {
2283 error
= PTR_ERR(mntroot
);
2284 goto error_splat_super
;
2286 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
2289 goto error_splat_super
;
2292 s
->s_flags
|= MS_ACTIVE
;
2294 mnt
->mnt_root
= mntroot
;
2296 security_sb_clone_mnt_opts(data
->sb
, s
);
2298 dprintk("<-- nfs4_referral_get_sb() = 0\n");
2302 nfs_free_server(server
);
2304 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error
);
2308 up_write(&s
->s_umount
);
2309 deactivate_super(s
);
2310 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error
);
2314 #endif /* CONFIG_NFS_V4 */