4 * Copyright (C) 1992 Rick Sladkey
6 * nfs superblock handling functions
8 * Modularised by Alan Cox <alan@lxorguk.ukuu.org.uk>, while hacking some
9 * experimental NFS changes. Modularisation taken straight from SYS5 fs.
11 * Change to nfs_read_super() to permit NFS mounts to multi-homed hosts.
12 * J.S.Peatfield@damtp.cam.ac.uk
14 * Split from inode.c by David Howells <dhowells@redhat.com>
16 * - superblocks are indexed on server only - all inodes, dentries, etc. associated with a
17 * particular server are held in the same superblock
18 * - NFS superblocks can have several effective roots to the dentry tree
19 * - directory type roots are spliced into the tree when a path from one root reaches the root
20 * of another (see nfs_lookup())
23 #include <linux/module.h>
24 #include <linux/init.h>
26 #include <linux/time.h>
27 #include <linux/kernel.h>
29 #include <linux/string.h>
30 #include <linux/stat.h>
31 #include <linux/errno.h>
32 #include <linux/unistd.h>
33 #include <linux/sunrpc/clnt.h>
34 #include <linux/sunrpc/stats.h>
35 #include <linux/sunrpc/metrics.h>
36 #include <linux/sunrpc/xprtsock.h>
37 #include <linux/sunrpc/xprtrdma.h>
38 #include <linux/nfs_fs.h>
39 #include <linux/nfs_mount.h>
40 #include <linux/nfs4_mount.h>
41 #include <linux/lockd/bind.h>
42 #include <linux/smp_lock.h>
43 #include <linux/seq_file.h>
44 #include <linux/mount.h>
45 #include <linux/nfs_idmap.h>
46 #include <linux/vfs.h>
47 #include <linux/inet.h>
48 #include <linux/in6.h>
50 #include <linux/netdevice.h>
51 #include <linux/nfs_xdr.h>
52 #include <linux/magic.h>
53 #include <linux/parser.h>
55 #include <asm/system.h>
56 #include <asm/uaccess.h>
60 #include "delegation.h"
64 #define NFSDBG_FACILITY NFSDBG_VFS
67 /* Mount options that take no arguments */
69 Opt_posix
, Opt_noposix
,
74 Opt_udp
, Opt_tcp
, Opt_rdma
,
76 Opt_rdirplus
, Opt_nordirplus
,
77 Opt_sharecache
, Opt_nosharecache
,
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
,
96 /* Special mount options */
97 Opt_userspace
, Opt_deprecated
, Opt_sloppy
,
102 static const match_table_t nfs_mount_option_tokens
= {
103 { Opt_userspace
, "bg" },
104 { Opt_userspace
, "fg" },
105 { Opt_userspace
, "retry=%s" },
107 { Opt_sloppy
, "sloppy" },
109 { Opt_soft
, "soft" },
110 { Opt_hard
, "hard" },
111 { Opt_deprecated
, "intr" },
112 { Opt_deprecated
, "nointr" },
113 { Opt_posix
, "posix" },
114 { Opt_noposix
, "noposix" },
116 { Opt_nocto
, "nocto" },
118 { Opt_noac
, "noac" },
119 { Opt_lock
, "lock" },
120 { Opt_nolock
, "nolock" },
125 { Opt_rdma
, "rdma" },
127 { Opt_noacl
, "noacl" },
128 { Opt_rdirplus
, "rdirplus" },
129 { Opt_nordirplus
, "nordirplus" },
130 { Opt_sharecache
, "sharecache" },
131 { Opt_nosharecache
, "nosharecache" },
133 { Opt_port
, "port=%u" },
134 { Opt_rsize
, "rsize=%u" },
135 { Opt_wsize
, "wsize=%u" },
136 { Opt_bsize
, "bsize=%u" },
137 { Opt_timeo
, "timeo=%u" },
138 { Opt_retrans
, "retrans=%u" },
139 { Opt_acregmin
, "acregmin=%u" },
140 { Opt_acregmax
, "acregmax=%u" },
141 { Opt_acdirmin
, "acdirmin=%u" },
142 { Opt_acdirmax
, "acdirmax=%u" },
143 { Opt_actimeo
, "actimeo=%u" },
144 { Opt_namelen
, "namlen=%u" },
145 { Opt_mountport
, "mountport=%u" },
146 { Opt_mountvers
, "mountvers=%u" },
147 { Opt_nfsvers
, "nfsvers=%u" },
148 { Opt_nfsvers
, "vers=%u" },
150 { Opt_sec
, "sec=%s" },
151 { Opt_proto
, "proto=%s" },
152 { Opt_mountproto
, "mountproto=%s" },
153 { Opt_addr
, "addr=%s" },
154 { Opt_clientaddr
, "clientaddr=%s" },
155 { Opt_mounthost
, "mounthost=%s" },
156 { Opt_mountaddr
, "mountaddr=%s" },
158 { Opt_lookupcache
, "lookupcache=%s" },
164 Opt_xprt_udp
, Opt_xprt_tcp
, Opt_xprt_rdma
,
169 static const match_table_t nfs_xprt_protocol_tokens
= {
170 { Opt_xprt_udp
, "udp" },
171 { Opt_xprt_tcp
, "tcp" },
172 { Opt_xprt_rdma
, "rdma" },
174 { Opt_xprt_err
, NULL
}
178 Opt_sec_none
, Opt_sec_sys
,
179 Opt_sec_krb5
, Opt_sec_krb5i
, Opt_sec_krb5p
,
180 Opt_sec_lkey
, Opt_sec_lkeyi
, Opt_sec_lkeyp
,
181 Opt_sec_spkm
, Opt_sec_spkmi
, Opt_sec_spkmp
,
186 static const match_table_t nfs_secflavor_tokens
= {
187 { Opt_sec_none
, "none" },
188 { Opt_sec_none
, "null" },
189 { Opt_sec_sys
, "sys" },
191 { Opt_sec_krb5
, "krb5" },
192 { Opt_sec_krb5i
, "krb5i" },
193 { Opt_sec_krb5p
, "krb5p" },
195 { Opt_sec_lkey
, "lkey" },
196 { Opt_sec_lkeyi
, "lkeyi" },
197 { Opt_sec_lkeyp
, "lkeyp" },
199 { Opt_sec_spkm
, "spkm3" },
200 { Opt_sec_spkmi
, "spkm3i" },
201 { Opt_sec_spkmp
, "spkm3p" },
203 { Opt_sec_err
, NULL
}
207 Opt_lookupcache_all
, Opt_lookupcache_positive
,
208 Opt_lookupcache_none
,
213 static match_table_t nfs_lookupcache_tokens
= {
214 { Opt_lookupcache_all
, "all" },
215 { Opt_lookupcache_positive
, "pos" },
216 { Opt_lookupcache_positive
, "positive" },
217 { Opt_lookupcache_none
, "none" },
219 { Opt_lookupcache_err
, NULL
}
223 static void nfs_umount_begin(struct super_block
*);
224 static int nfs_statfs(struct dentry
*, struct kstatfs
*);
225 static int nfs_show_options(struct seq_file
*, struct vfsmount
*);
226 static int nfs_show_stats(struct seq_file
*, struct vfsmount
*);
227 static int nfs_get_sb(struct file_system_type
*, int, const char *, void *, struct vfsmount
*);
228 static int nfs_xdev_get_sb(struct file_system_type
*fs_type
,
229 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
230 static void nfs_kill_super(struct super_block
*);
231 static int nfs_remount(struct super_block
*sb
, int *flags
, char *raw_data
);
233 static struct file_system_type nfs_fs_type
= {
234 .owner
= THIS_MODULE
,
236 .get_sb
= nfs_get_sb
,
237 .kill_sb
= nfs_kill_super
,
238 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
241 struct file_system_type nfs_xdev_fs_type
= {
242 .owner
= THIS_MODULE
,
244 .get_sb
= nfs_xdev_get_sb
,
245 .kill_sb
= nfs_kill_super
,
246 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
249 static const struct super_operations nfs_sops
= {
250 .alloc_inode
= nfs_alloc_inode
,
251 .destroy_inode
= nfs_destroy_inode
,
252 .write_inode
= nfs_write_inode
,
253 .statfs
= nfs_statfs
,
254 .clear_inode
= nfs_clear_inode
,
255 .umount_begin
= nfs_umount_begin
,
256 .show_options
= nfs_show_options
,
257 .show_stats
= nfs_show_stats
,
258 .remount_fs
= nfs_remount
,
262 static int nfs4_get_sb(struct file_system_type
*fs_type
,
263 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
264 static int nfs4_xdev_get_sb(struct file_system_type
*fs_type
,
265 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
266 static int nfs4_referral_get_sb(struct file_system_type
*fs_type
,
267 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
268 static void nfs4_kill_super(struct super_block
*sb
);
270 static struct file_system_type nfs4_fs_type
= {
271 .owner
= THIS_MODULE
,
273 .get_sb
= nfs4_get_sb
,
274 .kill_sb
= nfs4_kill_super
,
275 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
278 struct file_system_type nfs4_xdev_fs_type
= {
279 .owner
= THIS_MODULE
,
281 .get_sb
= nfs4_xdev_get_sb
,
282 .kill_sb
= nfs4_kill_super
,
283 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
286 struct file_system_type nfs4_referral_fs_type
= {
287 .owner
= THIS_MODULE
,
289 .get_sb
= nfs4_referral_get_sb
,
290 .kill_sb
= nfs4_kill_super
,
291 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
294 static const struct super_operations nfs4_sops
= {
295 .alloc_inode
= nfs_alloc_inode
,
296 .destroy_inode
= nfs_destroy_inode
,
297 .write_inode
= nfs_write_inode
,
298 .statfs
= nfs_statfs
,
299 .clear_inode
= nfs4_clear_inode
,
300 .umount_begin
= nfs_umount_begin
,
301 .show_options
= nfs_show_options
,
302 .show_stats
= nfs_show_stats
,
303 .remount_fs
= nfs_remount
,
307 static struct shrinker acl_shrinker
= {
308 .shrink
= nfs_access_cache_shrinker
,
309 .seeks
= DEFAULT_SEEKS
,
313 * Register the NFS filesystems
315 int __init
register_nfs_fs(void)
319 ret
= register_filesystem(&nfs_fs_type
);
323 ret
= nfs_register_sysctl();
327 ret
= register_filesystem(&nfs4_fs_type
);
331 register_shrinker(&acl_shrinker
);
336 nfs_unregister_sysctl();
339 unregister_filesystem(&nfs_fs_type
);
345 * Unregister the NFS filesystems
347 void __exit
unregister_nfs_fs(void)
349 unregister_shrinker(&acl_shrinker
);
351 unregister_filesystem(&nfs4_fs_type
);
353 nfs_unregister_sysctl();
354 unregister_filesystem(&nfs_fs_type
);
357 void nfs_sb_active(struct super_block
*sb
)
359 struct nfs_server
*server
= NFS_SB(sb
);
361 if (atomic_inc_return(&server
->active
) == 1)
362 atomic_inc(&sb
->s_active
);
365 void nfs_sb_deactive(struct super_block
*sb
)
367 struct nfs_server
*server
= NFS_SB(sb
);
369 if (atomic_dec_and_test(&server
->active
))
370 deactivate_super(sb
);
374 * Deliver file system statistics to userspace
376 static int nfs_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
378 struct nfs_server
*server
= NFS_SB(dentry
->d_sb
);
379 unsigned char blockbits
;
380 unsigned long blockres
;
381 struct nfs_fh
*fh
= NFS_FH(dentry
->d_inode
);
382 struct nfs_fattr fattr
;
383 struct nfs_fsstat res
= {
388 error
= server
->nfs_client
->rpc_ops
->statfs(server
, fh
, &res
);
391 buf
->f_type
= NFS_SUPER_MAGIC
;
394 * Current versions of glibc do not correctly handle the
395 * case where f_frsize != f_bsize. Eventually we want to
396 * report the value of wtmult in this field.
398 buf
->f_frsize
= dentry
->d_sb
->s_blocksize
;
401 * On most *nix systems, f_blocks, f_bfree, and f_bavail
402 * are reported in units of f_frsize. Linux hasn't had
403 * an f_frsize field in its statfs struct until recently,
404 * thus historically Linux's sys_statfs reports these
405 * fields in units of f_bsize.
407 buf
->f_bsize
= dentry
->d_sb
->s_blocksize
;
408 blockbits
= dentry
->d_sb
->s_blocksize_bits
;
409 blockres
= (1 << blockbits
) - 1;
410 buf
->f_blocks
= (res
.tbytes
+ blockres
) >> blockbits
;
411 buf
->f_bfree
= (res
.fbytes
+ blockres
) >> blockbits
;
412 buf
->f_bavail
= (res
.abytes
+ blockres
) >> blockbits
;
414 buf
->f_files
= res
.tfiles
;
415 buf
->f_ffree
= res
.afiles
;
417 buf
->f_namelen
= server
->namelen
;
422 dprintk("%s: statfs error = %d\n", __func__
, -error
);
427 * Map the security flavour number to a name
429 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour
)
431 static const struct {
432 rpc_authflavor_t flavour
;
435 { RPC_AUTH_NULL
, "null" },
436 { RPC_AUTH_UNIX
, "sys" },
437 { RPC_AUTH_GSS_KRB5
, "krb5" },
438 { RPC_AUTH_GSS_KRB5I
, "krb5i" },
439 { RPC_AUTH_GSS_KRB5P
, "krb5p" },
440 { RPC_AUTH_GSS_LKEY
, "lkey" },
441 { RPC_AUTH_GSS_LKEYI
, "lkeyi" },
442 { RPC_AUTH_GSS_LKEYP
, "lkeyp" },
443 { RPC_AUTH_GSS_SPKM
, "spkm" },
444 { RPC_AUTH_GSS_SPKMI
, "spkmi" },
445 { RPC_AUTH_GSS_SPKMP
, "spkmp" },
446 { UINT_MAX
, "unknown" }
450 for (i
= 0; sec_flavours
[i
].flavour
!= UINT_MAX
; i
++) {
451 if (sec_flavours
[i
].flavour
== flavour
)
454 return sec_flavours
[i
].str
;
457 static void nfs_show_mountd_options(struct seq_file
*m
, struct nfs_server
*nfss
,
460 struct sockaddr
*sap
= (struct sockaddr
*)&nfss
->mountd_address
;
462 switch (sap
->sa_family
) {
464 struct sockaddr_in
*sin
= (struct sockaddr_in
*)sap
;
465 seq_printf(m
, ",mountaddr=" NIPQUAD_FMT
,
466 NIPQUAD(sin
->sin_addr
.s_addr
));
470 struct sockaddr_in6
*sin6
= (struct sockaddr_in6
*)sap
;
471 seq_printf(m
, ",mountaddr=" NIP6_FMT
,
472 NIP6(sin6
->sin6_addr
));
477 seq_printf(m
, ",mountaddr=unspecified");
480 if (nfss
->mountd_version
|| showdefaults
)
481 seq_printf(m
, ",mountvers=%u", nfss
->mountd_version
);
482 if (nfss
->mountd_port
|| showdefaults
)
483 seq_printf(m
, ",mountport=%u", nfss
->mountd_port
);
485 switch (nfss
->mountd_protocol
) {
487 seq_printf(m
, ",mountproto=udp");
490 seq_printf(m
, ",mountproto=tcp");
494 seq_printf(m
, ",mountproto=auto");
499 * Describe the mount options in force on this server representation
501 static void nfs_show_mount_options(struct seq_file
*m
, struct nfs_server
*nfss
,
504 static const struct proc_nfs_info
{
509 { NFS_MOUNT_SOFT
, ",soft", ",hard" },
510 { NFS_MOUNT_INTR
, ",intr", ",nointr" },
511 { NFS_MOUNT_POSIX
, ",posix", "" },
512 { NFS_MOUNT_NOCTO
, ",nocto", "" },
513 { NFS_MOUNT_NOAC
, ",noac", "" },
514 { NFS_MOUNT_NONLM
, ",nolock", "" },
515 { NFS_MOUNT_NOACL
, ",noacl", "" },
516 { NFS_MOUNT_NORDIRPLUS
, ",nordirplus", "" },
517 { NFS_MOUNT_UNSHARED
, ",nosharecache", ""},
520 const struct proc_nfs_info
*nfs_infop
;
521 struct nfs_client
*clp
= nfss
->nfs_client
;
522 u32 version
= clp
->rpc_ops
->version
;
524 seq_printf(m
, ",vers=%u", version
);
525 seq_printf(m
, ",rsize=%u", nfss
->rsize
);
526 seq_printf(m
, ",wsize=%u", nfss
->wsize
);
527 if (nfss
->bsize
!= 0)
528 seq_printf(m
, ",bsize=%u", nfss
->bsize
);
529 seq_printf(m
, ",namlen=%u", nfss
->namelen
);
530 if (nfss
->acregmin
!= NFS_DEF_ACREGMIN
*HZ
|| showdefaults
)
531 seq_printf(m
, ",acregmin=%u", nfss
->acregmin
/HZ
);
532 if (nfss
->acregmax
!= NFS_DEF_ACREGMAX
*HZ
|| showdefaults
)
533 seq_printf(m
, ",acregmax=%u", nfss
->acregmax
/HZ
);
534 if (nfss
->acdirmin
!= NFS_DEF_ACDIRMIN
*HZ
|| showdefaults
)
535 seq_printf(m
, ",acdirmin=%u", nfss
->acdirmin
/HZ
);
536 if (nfss
->acdirmax
!= NFS_DEF_ACDIRMAX
*HZ
|| showdefaults
)
537 seq_printf(m
, ",acdirmax=%u", nfss
->acdirmax
/HZ
);
538 for (nfs_infop
= nfs_info
; nfs_infop
->flag
; nfs_infop
++) {
539 if (nfss
->flags
& nfs_infop
->flag
)
540 seq_puts(m
, nfs_infop
->str
);
542 seq_puts(m
, nfs_infop
->nostr
);
544 seq_printf(m
, ",proto=%s",
545 rpc_peeraddr2str(nfss
->client
, RPC_DISPLAY_PROTO
));
547 if (nfss
->port
!= NFS_PORT
)
548 seq_printf(m
, ",port=%u", nfss
->port
);
551 seq_printf(m
, ",port=%u", nfss
->port
);
553 seq_printf(m
, ",timeo=%lu", 10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
);
554 seq_printf(m
, ",retrans=%u", nfss
->client
->cl_timeout
->to_retries
);
555 seq_printf(m
, ",sec=%s", nfs_pseudoflavour_to_name(nfss
->client
->cl_auth
->au_flavor
));
558 nfs_show_mountd_options(m
, nfss
, showdefaults
);
561 if (clp
->rpc_ops
->version
== 4)
562 seq_printf(m
, ",clientaddr=%s", clp
->cl_ipaddr
);
567 * Describe the mount options on this VFS mountpoint
569 static int nfs_show_options(struct seq_file
*m
, struct vfsmount
*mnt
)
571 struct nfs_server
*nfss
= NFS_SB(mnt
->mnt_sb
);
573 nfs_show_mount_options(m
, nfss
, 0);
575 seq_printf(m
, ",addr=%s",
576 rpc_peeraddr2str(nfss
->nfs_client
->cl_rpcclient
,
583 * Present statistical information for this VFS mountpoint
585 static int nfs_show_stats(struct seq_file
*m
, struct vfsmount
*mnt
)
588 struct nfs_server
*nfss
= NFS_SB(mnt
->mnt_sb
);
589 struct rpc_auth
*auth
= nfss
->client
->cl_auth
;
590 struct nfs_iostats totals
= { };
592 seq_printf(m
, "statvers=%s", NFS_IOSTAT_VERS
);
595 * Display all mount option settings
597 seq_printf(m
, "\n\topts:\t");
598 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_RDONLY
? "ro" : "rw");
599 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_SYNCHRONOUS
? ",sync" : "");
600 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_NOATIME
? ",noatime" : "");
601 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_NODIRATIME
? ",nodiratime" : "");
602 nfs_show_mount_options(m
, nfss
, 1);
604 seq_printf(m
, "\n\tage:\t%lu", (jiffies
- nfss
->mount_time
) / HZ
);
606 seq_printf(m
, "\n\tcaps:\t");
607 seq_printf(m
, "caps=0x%x", nfss
->caps
);
608 seq_printf(m
, ",wtmult=%u", nfss
->wtmult
);
609 seq_printf(m
, ",dtsize=%u", nfss
->dtsize
);
610 seq_printf(m
, ",bsize=%u", nfss
->bsize
);
611 seq_printf(m
, ",namlen=%u", nfss
->namelen
);
614 if (nfss
->nfs_client
->rpc_ops
->version
== 4) {
615 seq_printf(m
, "\n\tnfsv4:\t");
616 seq_printf(m
, "bm0=0x%x", nfss
->attr_bitmask
[0]);
617 seq_printf(m
, ",bm1=0x%x", nfss
->attr_bitmask
[1]);
618 seq_printf(m
, ",acl=0x%x", nfss
->acl_bitmask
);
623 * Display security flavor in effect for this mount
625 seq_printf(m
, "\n\tsec:\tflavor=%u", auth
->au_ops
->au_flavor
);
627 seq_printf(m
, ",pseudoflavor=%u", auth
->au_flavor
);
630 * Display superblock I/O counters
632 for_each_possible_cpu(cpu
) {
633 struct nfs_iostats
*stats
;
636 stats
= per_cpu_ptr(nfss
->io_stats
, cpu
);
638 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
639 totals
.events
[i
] += stats
->events
[i
];
640 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
641 totals
.bytes
[i
] += stats
->bytes
[i
];
646 seq_printf(m
, "\n\tevents:\t");
647 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
648 seq_printf(m
, "%lu ", totals
.events
[i
]);
649 seq_printf(m
, "\n\tbytes:\t");
650 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
651 seq_printf(m
, "%Lu ", totals
.bytes
[i
]);
654 rpc_print_iostats(m
, nfss
->client
);
660 * Begin unmount by attempting to remove all automounted mountpoints we added
661 * in response to xdev traversals and referrals
663 static void nfs_umount_begin(struct super_block
*sb
)
665 struct nfs_server
*server
= NFS_SB(sb
);
666 struct rpc_clnt
*rpc
;
668 /* -EIO all pending I/O */
669 rpc
= server
->client_acl
;
671 rpc_killall_tasks(rpc
);
672 rpc
= server
->client
;
674 rpc_killall_tasks(rpc
);
678 * Sanity-check a server address provided by the mount command.
680 * Address family must be initialized, and address must not be
681 * the ANY address for that family.
683 static int nfs_verify_server_address(struct sockaddr
*addr
)
685 switch (addr
->sa_family
) {
687 struct sockaddr_in
*sa
= (struct sockaddr_in
*)addr
;
688 return sa
->sin_addr
.s_addr
!= htonl(INADDR_ANY
);
691 struct in6_addr
*sa
= &((struct sockaddr_in6
*)addr
)->sin6_addr
;
692 return !ipv6_addr_any(sa
);
699 static void nfs_parse_ipv4_address(char *string
, size_t str_len
,
700 struct sockaddr
*sap
, size_t *addr_len
)
702 struct sockaddr_in
*sin
= (struct sockaddr_in
*)sap
;
703 u8
*addr
= (u8
*)&sin
->sin_addr
.s_addr
;
705 if (str_len
<= INET_ADDRSTRLEN
) {
706 dfprintk(MOUNT
, "NFS: parsing IPv4 address %*s\n",
707 (int)str_len
, string
);
709 sin
->sin_family
= AF_INET
;
710 *addr_len
= sizeof(*sin
);
711 if (in4_pton(string
, str_len
, addr
, '\0', NULL
))
715 sap
->sa_family
= AF_UNSPEC
;
719 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
720 static int nfs_parse_ipv6_scope_id(const char *string
, const size_t str_len
,
722 struct sockaddr_in6
*sin6
)
727 if ((string
+ str_len
) == delim
)
730 if (*delim
!= IPV6_SCOPE_DELIMITER
)
733 if (!(ipv6_addr_type(&sin6
->sin6_addr
) & IPV6_ADDR_LINKLOCAL
))
736 len
= (string
+ str_len
) - delim
- 1;
737 p
= kstrndup(delim
+ 1, len
, GFP_KERNEL
);
739 unsigned long scope_id
= 0;
740 struct net_device
*dev
;
742 dev
= dev_get_by_name(&init_net
, p
);
744 scope_id
= dev
->ifindex
;
747 if (strict_strtoul(p
, 10, &scope_id
) == 0) {
755 sin6
->sin6_scope_id
= scope_id
;
756 dfprintk(MOUNT
, "NFS: IPv6 scope ID = %lu\n", scope_id
);
763 static void nfs_parse_ipv6_address(char *string
, size_t str_len
,
764 struct sockaddr
*sap
, size_t *addr_len
)
766 struct sockaddr_in6
*sin6
= (struct sockaddr_in6
*)sap
;
767 u8
*addr
= (u8
*)&sin6
->sin6_addr
.in6_u
;
770 if (str_len
<= INET6_ADDRSTRLEN
) {
771 dfprintk(MOUNT
, "NFS: parsing IPv6 address %*s\n",
772 (int)str_len
, string
);
774 sin6
->sin6_family
= AF_INET6
;
775 *addr_len
= sizeof(*sin6
);
776 if (in6_pton(string
, str_len
, addr
,
777 IPV6_SCOPE_DELIMITER
, &delim
) != 0) {
778 if (nfs_parse_ipv6_scope_id(string
, str_len
,
784 sap
->sa_family
= AF_UNSPEC
;
788 static void nfs_parse_ipv6_address(char *string
, size_t str_len
,
789 struct sockaddr
*sap
, size_t *addr_len
)
791 sap
->sa_family
= AF_UNSPEC
;
797 * Construct a sockaddr based on the contents of a string that contains
798 * an IP address in presentation format.
800 * If there is a problem constructing the new sockaddr, set the address
801 * family to AF_UNSPEC.
803 void nfs_parse_ip_address(char *string
, size_t str_len
,
804 struct sockaddr
*sap
, size_t *addr_len
)
806 unsigned int i
, colons
;
809 for (i
= 0; i
< str_len
; i
++)
810 if (string
[i
] == ':')
814 nfs_parse_ipv6_address(string
, str_len
, sap
, addr_len
);
816 nfs_parse_ipv4_address(string
, str_len
, sap
, addr_len
);
820 * Sanity check the NFS transport protocol.
823 static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data
*mnt
)
825 switch (mnt
->nfs_server
.protocol
) {
826 case XPRT_TRANSPORT_UDP
:
827 case XPRT_TRANSPORT_TCP
:
828 case XPRT_TRANSPORT_RDMA
:
831 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
836 * For text based NFSv2/v3 mounts, the mount protocol transport default
837 * settings should depend upon the specified NFS transport.
839 static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data
*mnt
)
841 nfs_validate_transport_protocol(mnt
);
843 if (mnt
->mount_server
.protocol
== XPRT_TRANSPORT_UDP
||
844 mnt
->mount_server
.protocol
== XPRT_TRANSPORT_TCP
)
846 switch (mnt
->nfs_server
.protocol
) {
847 case XPRT_TRANSPORT_UDP
:
848 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_UDP
;
850 case XPRT_TRANSPORT_TCP
:
851 case XPRT_TRANSPORT_RDMA
:
852 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_TCP
;
857 * Parse the value of the 'sec=' option.
859 * The flavor_len setting is for v4 mounts.
861 static int nfs_parse_security_flavors(char *value
,
862 struct nfs_parsed_mount_data
*mnt
)
864 substring_t args
[MAX_OPT_ARGS
];
866 dfprintk(MOUNT
, "NFS: parsing sec=%s option\n", value
);
868 switch (match_token(value
, nfs_secflavor_tokens
, args
)) {
870 mnt
->auth_flavor_len
= 0;
871 mnt
->auth_flavors
[0] = RPC_AUTH_NULL
;
874 mnt
->auth_flavor_len
= 0;
875 mnt
->auth_flavors
[0] = RPC_AUTH_UNIX
;
878 mnt
->auth_flavor_len
= 1;
879 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5
;
882 mnt
->auth_flavor_len
= 1;
883 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5I
;
886 mnt
->auth_flavor_len
= 1;
887 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5P
;
890 mnt
->auth_flavor_len
= 1;
891 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEY
;
894 mnt
->auth_flavor_len
= 1;
895 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEYI
;
898 mnt
->auth_flavor_len
= 1;
899 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEYP
;
902 mnt
->auth_flavor_len
= 1;
903 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKM
;
906 mnt
->auth_flavor_len
= 1;
907 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKMI
;
910 mnt
->auth_flavor_len
= 1;
911 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKMP
;
920 static void nfs_parse_invalid_value(const char *option
)
922 dfprintk(MOUNT
, "NFS: bad value specified for %s option\n", option
);
926 * Error-check and convert a string of mount options from user space into
927 * a data structure. The whole mount string is processed; bad options are
928 * skipped as they are encountered. If there were no errors, return 1;
929 * otherwise return 0 (zero).
931 static int nfs_parse_mount_options(char *raw
,
932 struct nfs_parsed_mount_data
*mnt
)
934 char *p
, *string
, *secdata
;
935 int rc
, sloppy
= 0, errors
= 0;
938 dfprintk(MOUNT
, "NFS: mount options string was NULL.\n");
941 dfprintk(MOUNT
, "NFS: nfs mount opts='%s'\n", raw
);
943 secdata
= alloc_secdata();
947 rc
= security_sb_copy_data(raw
, secdata
);
949 goto out_security_failure
;
951 rc
= security_sb_parse_opts_str(secdata
, &mnt
->lsm_opts
);
953 goto out_security_failure
;
955 free_secdata(secdata
);
957 while ((p
= strsep(&raw
, ",")) != NULL
) {
958 substring_t args
[MAX_OPT_ARGS
];
964 dfprintk(MOUNT
, "NFS: parsing nfs mount option '%s'\n", p
);
966 token
= match_token(p
, nfs_mount_option_tokens
, args
);
970 * boolean options: foo/nofoo
973 mnt
->flags
|= NFS_MOUNT_SOFT
;
976 mnt
->flags
&= ~NFS_MOUNT_SOFT
;
979 mnt
->flags
|= NFS_MOUNT_POSIX
;
982 mnt
->flags
&= ~NFS_MOUNT_POSIX
;
985 mnt
->flags
&= ~NFS_MOUNT_NOCTO
;
988 mnt
->flags
|= NFS_MOUNT_NOCTO
;
991 mnt
->flags
&= ~NFS_MOUNT_NOAC
;
994 mnt
->flags
|= NFS_MOUNT_NOAC
;
997 mnt
->flags
&= ~NFS_MOUNT_NONLM
;
1000 mnt
->flags
|= NFS_MOUNT_NONLM
;
1003 mnt
->flags
&= ~NFS_MOUNT_VER3
;
1006 mnt
->flags
|= NFS_MOUNT_VER3
;
1009 mnt
->flags
&= ~NFS_MOUNT_TCP
;
1010 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1013 mnt
->flags
|= NFS_MOUNT_TCP
;
1014 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1017 mnt
->flags
|= NFS_MOUNT_TCP
; /* for side protocols */
1018 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_RDMA
;
1021 mnt
->flags
&= ~NFS_MOUNT_NOACL
;
1024 mnt
->flags
|= NFS_MOUNT_NOACL
;
1027 mnt
->flags
&= ~NFS_MOUNT_NORDIRPLUS
;
1029 case Opt_nordirplus
:
1030 mnt
->flags
|= NFS_MOUNT_NORDIRPLUS
;
1032 case Opt_sharecache
:
1033 mnt
->flags
&= ~NFS_MOUNT_UNSHARED
;
1035 case Opt_nosharecache
:
1036 mnt
->flags
|= NFS_MOUNT_UNSHARED
;
1040 * options that take numeric values
1043 if (match_int(args
, &option
) ||
1044 option
< 0 || option
> USHORT_MAX
) {
1046 nfs_parse_invalid_value("port");
1048 mnt
->nfs_server
.port
= option
;
1051 if (match_int(args
, &option
) || option
< 0) {
1053 nfs_parse_invalid_value("rsize");
1055 mnt
->rsize
= option
;
1058 if (match_int(args
, &option
) || option
< 0) {
1060 nfs_parse_invalid_value("wsize");
1062 mnt
->wsize
= option
;
1065 if (match_int(args
, &option
) || option
< 0) {
1067 nfs_parse_invalid_value("bsize");
1069 mnt
->bsize
= option
;
1072 if (match_int(args
, &option
) || option
<= 0) {
1074 nfs_parse_invalid_value("timeo");
1076 mnt
->timeo
= option
;
1079 if (match_int(args
, &option
) || option
<= 0) {
1081 nfs_parse_invalid_value("retrans");
1083 mnt
->retrans
= option
;
1086 if (match_int(args
, &option
) || option
< 0) {
1088 nfs_parse_invalid_value("acregmin");
1090 mnt
->acregmin
= option
;
1093 if (match_int(args
, &option
) || option
< 0) {
1095 nfs_parse_invalid_value("acregmax");
1097 mnt
->acregmax
= option
;
1100 if (match_int(args
, &option
) || option
< 0) {
1102 nfs_parse_invalid_value("acdirmin");
1104 mnt
->acdirmin
= option
;
1107 if (match_int(args
, &option
) || option
< 0) {
1109 nfs_parse_invalid_value("acdirmax");
1111 mnt
->acdirmax
= option
;
1114 if (match_int(args
, &option
) || option
< 0) {
1116 nfs_parse_invalid_value("actimeo");
1118 mnt
->acregmin
= mnt
->acregmax
=
1119 mnt
->acdirmin
= mnt
->acdirmax
= option
;
1122 if (match_int(args
, &option
) || option
< 0) {
1124 nfs_parse_invalid_value("namlen");
1126 mnt
->namlen
= option
;
1129 if (match_int(args
, &option
) ||
1130 option
< 0 || option
> USHORT_MAX
) {
1132 nfs_parse_invalid_value("mountport");
1134 mnt
->mount_server
.port
= option
;
1137 if (match_int(args
, &option
) ||
1138 option
< NFS_MNT_VERSION
||
1139 option
> NFS_MNT3_VERSION
) {
1141 nfs_parse_invalid_value("mountvers");
1143 mnt
->mount_server
.version
= option
;
1146 if (match_int(args
, &option
)) {
1148 nfs_parse_invalid_value("nfsvers");
1153 mnt
->flags
&= ~NFS_MOUNT_VER3
;
1156 mnt
->flags
|= NFS_MOUNT_VER3
;
1160 nfs_parse_invalid_value("nfsvers");
1165 * options that take text values
1168 string
= match_strdup(args
);
1171 rc
= nfs_parse_security_flavors(string
, mnt
);
1175 dfprintk(MOUNT
, "NFS: unrecognized "
1176 "security flavor\n");
1180 string
= match_strdup(args
);
1183 token
= match_token(string
,
1184 nfs_xprt_protocol_tokens
, args
);
1189 mnt
->flags
&= ~NFS_MOUNT_TCP
;
1190 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1193 mnt
->flags
|= NFS_MOUNT_TCP
;
1194 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1197 /* vector side protocols to TCP */
1198 mnt
->flags
|= NFS_MOUNT_TCP
;
1199 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_RDMA
;
1203 dfprintk(MOUNT
, "NFS: unrecognized "
1204 "transport protocol\n");
1207 case Opt_mountproto
:
1208 string
= match_strdup(args
);
1211 token
= match_token(string
,
1212 nfs_xprt_protocol_tokens
, args
);
1217 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_UDP
;
1220 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_TCP
;
1222 case Opt_xprt_rdma
: /* not used for side protocols */
1225 dfprintk(MOUNT
, "NFS: unrecognized "
1226 "transport protocol\n");
1230 string
= match_strdup(args
);
1233 nfs_parse_ip_address(string
, strlen(string
),
1235 &mnt
->nfs_server
.address
,
1236 &mnt
->nfs_server
.addrlen
);
1239 case Opt_clientaddr
:
1240 string
= match_strdup(args
);
1243 kfree(mnt
->client_address
);
1244 mnt
->client_address
= string
;
1247 string
= match_strdup(args
);
1250 kfree(mnt
->mount_server
.hostname
);
1251 mnt
->mount_server
.hostname
= string
;
1254 string
= match_strdup(args
);
1257 nfs_parse_ip_address(string
, strlen(string
),
1259 &mnt
->mount_server
.address
,
1260 &mnt
->mount_server
.addrlen
);
1263 case Opt_lookupcache
:
1264 string
= match_strdup(args
);
1267 token
= match_token(string
,
1268 nfs_lookupcache_tokens
, args
);
1271 case Opt_lookupcache_all
:
1272 mnt
->flags
&= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG
|NFS_MOUNT_LOOKUP_CACHE_NONE
);
1274 case Opt_lookupcache_positive
:
1275 mnt
->flags
&= ~NFS_MOUNT_LOOKUP_CACHE_NONE
;
1276 mnt
->flags
|= NFS_MOUNT_LOOKUP_CACHE_NONEG
;
1278 case Opt_lookupcache_none
:
1279 mnt
->flags
|= NFS_MOUNT_LOOKUP_CACHE_NONEG
|NFS_MOUNT_LOOKUP_CACHE_NONE
;
1283 dfprintk(MOUNT
, "NFS: invalid "
1284 "lookupcache argument\n");
1293 dfprintk(MOUNT
, "NFS: relaxing parsing rules\n");
1296 case Opt_deprecated
:
1297 dfprintk(MOUNT
, "NFS: ignoring mount option "
1303 dfprintk(MOUNT
, "NFS: unrecognized mount option "
1309 dfprintk(MOUNT
, "NFS: parsing encountered %d error%s\n",
1310 errors
, (errors
== 1 ? "" : "s"));
1317 printk(KERN_INFO
"NFS: not enough memory to parse option\n");
1319 out_security_failure
:
1320 free_secdata(secdata
);
1321 printk(KERN_INFO
"NFS: security options invalid: %d\n", rc
);
1326 * Use the remote server's MOUNT service to request the NFS file handle
1327 * corresponding to the provided path.
1329 static int nfs_try_mount(struct nfs_parsed_mount_data
*args
,
1330 struct nfs_fh
*root_fh
)
1332 struct sockaddr
*sap
= (struct sockaddr
*)&args
->mount_server
.address
;
1336 if (args
->mount_server
.version
== 0) {
1337 if (args
->flags
& NFS_MOUNT_VER3
)
1338 args
->mount_server
.version
= NFS_MNT3_VERSION
;
1340 args
->mount_server
.version
= NFS_MNT_VERSION
;
1343 if (args
->mount_server
.hostname
)
1344 hostname
= args
->mount_server
.hostname
;
1346 hostname
= args
->nfs_server
.hostname
;
1349 * Construct the mount server's address.
1351 if (args
->mount_server
.address
.ss_family
== AF_UNSPEC
) {
1352 memcpy(sap
, &args
->nfs_server
.address
,
1353 args
->nfs_server
.addrlen
);
1354 args
->mount_server
.addrlen
= args
->nfs_server
.addrlen
;
1358 * autobind will be used if mount_server.port == 0
1360 nfs_set_port(sap
, args
->mount_server
.port
);
1363 * Now ask the mount server to map our export path
1366 status
= nfs_mount(sap
,
1367 args
->mount_server
.addrlen
,
1369 args
->nfs_server
.export_path
,
1370 args
->mount_server
.version
,
1371 args
->mount_server
.protocol
,
1376 dfprintk(MOUNT
, "NFS: unable to mount server %s, error %d\n",
1381 static int nfs_parse_simple_hostname(const char *dev_name
,
1382 char **hostname
, size_t maxnamlen
,
1383 char **export_path
, size_t maxpathlen
)
1386 char *colon
, *comma
;
1388 colon
= strchr(dev_name
, ':');
1390 goto out_bad_devname
;
1392 len
= colon
- dev_name
;
1393 if (len
> maxnamlen
)
1396 /* N.B. caller will free nfs_server.hostname in all cases */
1397 *hostname
= kstrndup(dev_name
, len
, GFP_KERNEL
);
1401 /* kill possible hostname list: not supported */
1402 comma
= strchr(*hostname
, ',');
1403 if (comma
!= NULL
) {
1404 if (comma
== *hostname
)
1405 goto out_bad_devname
;
1410 len
= strlen(colon
);
1411 if (len
> maxpathlen
)
1413 *export_path
= kstrndup(colon
, len
, GFP_KERNEL
);
1417 dfprintk(MOUNT
, "NFS: MNTPATH: '%s'\n", *export_path
);
1421 dfprintk(MOUNT
, "NFS: device name not in host:path format\n");
1425 dfprintk(MOUNT
, "NFS: not enough memory to parse device name\n");
1429 dfprintk(MOUNT
, "NFS: server hostname too long\n");
1430 return -ENAMETOOLONG
;
1433 dfprintk(MOUNT
, "NFS: export pathname too long\n");
1434 return -ENAMETOOLONG
;
1438 * Hostname has square brackets around it because it contains one or
1439 * more colons. We look for the first closing square bracket, and a
1440 * colon must follow it.
1442 static int nfs_parse_protected_hostname(const char *dev_name
,
1443 char **hostname
, size_t maxnamlen
,
1444 char **export_path
, size_t maxpathlen
)
1449 start
= (char *)(dev_name
+ 1);
1451 end
= strchr(start
, ']');
1453 goto out_bad_devname
;
1454 if (*(end
+ 1) != ':')
1455 goto out_bad_devname
;
1458 if (len
> maxnamlen
)
1461 /* N.B. caller will free nfs_server.hostname in all cases */
1462 *hostname
= kstrndup(start
, len
, GFP_KERNEL
);
1463 if (*hostname
== NULL
)
1468 if (len
> maxpathlen
)
1470 *export_path
= kstrndup(end
, len
, GFP_KERNEL
);
1477 dfprintk(MOUNT
, "NFS: device name not in host:path format\n");
1481 dfprintk(MOUNT
, "NFS: not enough memory to parse device name\n");
1485 dfprintk(MOUNT
, "NFS: server hostname too long\n");
1486 return -ENAMETOOLONG
;
1489 dfprintk(MOUNT
, "NFS: export pathname too long\n");
1490 return -ENAMETOOLONG
;
1494 * Split "dev_name" into "hostname:export_path".
1496 * The leftmost colon demarks the split between the server's hostname
1497 * and the export path. If the hostname starts with a left square
1498 * bracket, then it may contain colons.
1500 * Note: caller frees hostname and export path, even on error.
1502 static int nfs_parse_devname(const char *dev_name
,
1503 char **hostname
, size_t maxnamlen
,
1504 char **export_path
, size_t maxpathlen
)
1506 if (*dev_name
== '[')
1507 return nfs_parse_protected_hostname(dev_name
,
1508 hostname
, maxnamlen
,
1509 export_path
, maxpathlen
);
1511 return nfs_parse_simple_hostname(dev_name
,
1512 hostname
, maxnamlen
,
1513 export_path
, maxpathlen
);
1517 * Validate the NFS2/NFS3 mount data
1518 * - fills in the mount root filehandle
1520 * For option strings, user space handles the following behaviors:
1522 * + DNS: mapping server host name to IP address ("addr=" option)
1524 * + failure mode: how to behave if a mount request can't be handled
1525 * immediately ("fg/bg" option)
1527 * + retry: how often to retry a mount request ("retry=" option)
1529 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1530 * mountproto=tcp after mountproto=udp, and so on
1532 static int nfs_validate_mount_data(void *options
,
1533 struct nfs_parsed_mount_data
*args
,
1534 struct nfs_fh
*mntfh
,
1535 const char *dev_name
)
1537 struct nfs_mount_data
*data
= (struct nfs_mount_data
*)options
;
1542 args
->flags
= (NFS_MOUNT_VER3
| NFS_MOUNT_TCP
);
1543 args
->rsize
= NFS_MAX_FILE_IO_SIZE
;
1544 args
->wsize
= NFS_MAX_FILE_IO_SIZE
;
1545 args
->acregmin
= NFS_DEF_ACREGMIN
;
1546 args
->acregmax
= NFS_DEF_ACREGMAX
;
1547 args
->acdirmin
= NFS_DEF_ACDIRMIN
;
1548 args
->acdirmax
= NFS_DEF_ACDIRMAX
;
1549 args
->mount_server
.port
= 0; /* autobind unless user sets port */
1550 args
->nfs_server
.port
= 0; /* autobind unless user sets port */
1551 args
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1552 args
->auth_flavors
[0] = RPC_AUTH_UNIX
;
1554 switch (data
->version
) {
1560 if (data
->flags
& NFS_MOUNT_VER3
)
1562 data
->root
.size
= NFS2_FHSIZE
;
1563 memcpy(data
->root
.data
, data
->old_root
.data
, NFS2_FHSIZE
);
1565 if (data
->flags
& NFS_MOUNT_SECFLAVOUR
)
1568 memset(data
->context
, 0, sizeof(data
->context
));
1570 if (data
->flags
& NFS_MOUNT_VER3
) {
1571 if (data
->root
.size
> NFS3_FHSIZE
|| data
->root
.size
== 0)
1572 goto out_invalid_fh
;
1573 mntfh
->size
= data
->root
.size
;
1575 mntfh
->size
= NFS2_FHSIZE
;
1578 memcpy(mntfh
->data
, data
->root
.data
, mntfh
->size
);
1579 if (mntfh
->size
< sizeof(mntfh
->data
))
1580 memset(mntfh
->data
+ mntfh
->size
, 0,
1581 sizeof(mntfh
->data
) - mntfh
->size
);
1584 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1587 args
->flags
= data
->flags
& NFS_MOUNT_FLAGMASK
;
1588 args
->rsize
= data
->rsize
;
1589 args
->wsize
= data
->wsize
;
1590 args
->timeo
= data
->timeo
;
1591 args
->retrans
= data
->retrans
;
1592 args
->acregmin
= data
->acregmin
;
1593 args
->acregmax
= data
->acregmax
;
1594 args
->acdirmin
= data
->acdirmin
;
1595 args
->acdirmax
= data
->acdirmax
;
1597 memcpy(&args
->nfs_server
.address
, &data
->addr
,
1598 sizeof(data
->addr
));
1599 args
->nfs_server
.addrlen
= sizeof(data
->addr
);
1600 if (!nfs_verify_server_address((struct sockaddr
*)
1601 &args
->nfs_server
.address
))
1602 goto out_no_address
;
1604 if (!(data
->flags
& NFS_MOUNT_TCP
))
1605 args
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1606 /* N.B. caller will free nfs_server.hostname in all cases */
1607 args
->nfs_server
.hostname
= kstrdup(data
->hostname
, GFP_KERNEL
);
1608 args
->namlen
= data
->namlen
;
1609 args
->bsize
= data
->bsize
;
1611 if (data
->flags
& NFS_MOUNT_SECFLAVOUR
)
1612 args
->auth_flavors
[0] = data
->pseudoflavor
;
1613 if (!args
->nfs_server
.hostname
)
1617 * The legacy version 6 binary mount data from userspace has a
1618 * field used only to transport selinux information into the
1619 * the kernel. To continue to support that functionality we
1620 * have a touch of selinux knowledge here in the NFS code. The
1621 * userspace code converted context=blah to just blah so we are
1622 * converting back to the full string selinux understands.
1624 if (data
->context
[0]){
1625 #ifdef CONFIG_SECURITY_SELINUX
1627 char *opts_str
= kmalloc(sizeof(data
->context
) + 8, GFP_KERNEL
);
1630 strcpy(opts_str
, "context=");
1631 data
->context
[NFS_MAX_CONTEXT_LEN
] = '\0';
1632 strcat(opts_str
, &data
->context
[0]);
1633 rc
= security_sb_parse_opts_str(opts_str
, &args
->lsm_opts
);
1646 if (nfs_parse_mount_options((char *)options
, args
) == 0)
1649 if (!nfs_verify_server_address((struct sockaddr
*)
1650 &args
->nfs_server
.address
))
1651 goto out_no_address
;
1653 nfs_set_port((struct sockaddr
*)&args
->nfs_server
.address
,
1654 args
->nfs_server
.port
);
1656 nfs_set_mount_transport_protocol(args
);
1658 status
= nfs_parse_devname(dev_name
,
1659 &args
->nfs_server
.hostname
,
1661 &args
->nfs_server
.export_path
,
1664 status
= nfs_try_mount(args
, mntfh
);
1666 kfree(args
->nfs_server
.export_path
);
1667 args
->nfs_server
.export_path
= NULL
;
1676 #ifndef CONFIG_NFS_V3
1677 if (args
->flags
& NFS_MOUNT_VER3
)
1678 goto out_v3_not_compiled
;
1679 #endif /* !CONFIG_NFS_V3 */
1684 dfprintk(MOUNT
, "NFS: mount program didn't pass any mount data\n");
1688 dfprintk(MOUNT
, "NFS: nfs_mount_data version %d does not support v3\n",
1693 dfprintk(MOUNT
, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1696 #ifndef CONFIG_NFS_V3
1697 out_v3_not_compiled
:
1698 dfprintk(MOUNT
, "NFS: NFSv3 is not compiled into kernel\n");
1699 return -EPROTONOSUPPORT
;
1700 #endif /* !CONFIG_NFS_V3 */
1703 dfprintk(MOUNT
, "NFS: not enough memory to handle mount options\n");
1707 dfprintk(MOUNT
, "NFS: mount program didn't pass remote address\n");
1711 dfprintk(MOUNT
, "NFS: invalid root filehandle\n");
1716 nfs_compare_remount_data(struct nfs_server
*nfss
,
1717 struct nfs_parsed_mount_data
*data
)
1719 if (data
->flags
!= nfss
->flags
||
1720 data
->rsize
!= nfss
->rsize
||
1721 data
->wsize
!= nfss
->wsize
||
1722 data
->retrans
!= nfss
->client
->cl_timeout
->to_retries
||
1723 data
->auth_flavors
[0] != nfss
->client
->cl_auth
->au_flavor
||
1724 data
->acregmin
!= nfss
->acregmin
/ HZ
||
1725 data
->acregmax
!= nfss
->acregmax
/ HZ
||
1726 data
->acdirmin
!= nfss
->acdirmin
/ HZ
||
1727 data
->acdirmax
!= nfss
->acdirmax
/ HZ
||
1728 data
->timeo
!= (10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
) ||
1729 data
->nfs_server
.addrlen
!= nfss
->nfs_client
->cl_addrlen
||
1730 memcmp(&data
->nfs_server
.address
, &nfss
->nfs_client
->cl_addr
,
1731 data
->nfs_server
.addrlen
) != 0)
1738 nfs_remount(struct super_block
*sb
, int *flags
, char *raw_data
)
1741 struct nfs_server
*nfss
= sb
->s_fs_info
;
1742 struct nfs_parsed_mount_data
*data
;
1743 struct nfs_mount_data
*options
= (struct nfs_mount_data
*)raw_data
;
1744 struct nfs4_mount_data
*options4
= (struct nfs4_mount_data
*)raw_data
;
1745 u32 nfsvers
= nfss
->nfs_client
->rpc_ops
->version
;
1748 * Userspace mount programs that send binary options generally send
1749 * them populated with default values. We have no way to know which
1750 * ones were explicitly specified. Fall back to legacy behavior and
1751 * just return success.
1753 if ((nfsvers
== 4 && (!options4
|| options4
->version
== 1)) ||
1754 (nfsvers
<= 3 && (!options
|| (options
->version
>= 1 &&
1755 options
->version
<= 6))))
1758 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
1762 /* fill out struct with values from existing mount */
1763 data
->flags
= nfss
->flags
;
1764 data
->rsize
= nfss
->rsize
;
1765 data
->wsize
= nfss
->wsize
;
1766 data
->retrans
= nfss
->client
->cl_timeout
->to_retries
;
1767 data
->auth_flavors
[0] = nfss
->client
->cl_auth
->au_flavor
;
1768 data
->acregmin
= nfss
->acregmin
/ HZ
;
1769 data
->acregmax
= nfss
->acregmax
/ HZ
;
1770 data
->acdirmin
= nfss
->acdirmin
/ HZ
;
1771 data
->acdirmax
= nfss
->acdirmax
/ HZ
;
1772 data
->timeo
= 10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
;
1773 data
->nfs_server
.addrlen
= nfss
->nfs_client
->cl_addrlen
;
1774 memcpy(&data
->nfs_server
.address
, &nfss
->nfs_client
->cl_addr
,
1775 data
->nfs_server
.addrlen
);
1777 /* overwrite those values with any that were specified */
1778 error
= nfs_parse_mount_options((char *)options
, data
);
1782 /* compare new mount options with old ones */
1783 error
= nfs_compare_remount_data(nfss
, data
);
1790 * Initialise the common bits of the superblock
1792 static inline void nfs_initialise_sb(struct super_block
*sb
)
1794 struct nfs_server
*server
= NFS_SB(sb
);
1796 sb
->s_magic
= NFS_SUPER_MAGIC
;
1798 /* We probably want something more informative here */
1799 snprintf(sb
->s_id
, sizeof(sb
->s_id
),
1800 "%x:%x", MAJOR(sb
->s_dev
), MINOR(sb
->s_dev
));
1802 if (sb
->s_blocksize
== 0)
1803 sb
->s_blocksize
= nfs_block_bits(server
->wsize
,
1804 &sb
->s_blocksize_bits
);
1806 if (server
->flags
& NFS_MOUNT_NOAC
)
1807 sb
->s_flags
|= MS_SYNCHRONOUS
;
1809 nfs_super_set_maxbytes(sb
, server
->maxfilesize
);
1813 * Finish setting up an NFS2/3 superblock
1815 static void nfs_fill_super(struct super_block
*sb
,
1816 struct nfs_parsed_mount_data
*data
)
1818 struct nfs_server
*server
= NFS_SB(sb
);
1820 sb
->s_blocksize_bits
= 0;
1821 sb
->s_blocksize
= 0;
1823 sb
->s_blocksize
= nfs_block_size(data
->bsize
, &sb
->s_blocksize_bits
);
1825 if (server
->flags
& NFS_MOUNT_VER3
) {
1826 /* The VFS shouldn't apply the umask to mode bits. We will do
1827 * so ourselves when necessary.
1829 sb
->s_flags
|= MS_POSIXACL
;
1830 sb
->s_time_gran
= 1;
1833 sb
->s_op
= &nfs_sops
;
1834 nfs_initialise_sb(sb
);
1838 * Finish setting up a cloned NFS2/3 superblock
1840 static void nfs_clone_super(struct super_block
*sb
,
1841 const struct super_block
*old_sb
)
1843 struct nfs_server
*server
= NFS_SB(sb
);
1845 sb
->s_blocksize_bits
= old_sb
->s_blocksize_bits
;
1846 sb
->s_blocksize
= old_sb
->s_blocksize
;
1847 sb
->s_maxbytes
= old_sb
->s_maxbytes
;
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
= old_sb
->s_op
;
1858 nfs_initialise_sb(sb
);
1861 #define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
1863 static int nfs_compare_mount_options(const struct super_block
*s
, const struct nfs_server
*b
, int flags
)
1865 const struct nfs_server
*a
= s
->s_fs_info
;
1866 const struct rpc_clnt
*clnt_a
= a
->client
;
1867 const struct rpc_clnt
*clnt_b
= b
->client
;
1869 if ((s
->s_flags
& NFS_MS_MASK
) != (flags
& NFS_MS_MASK
))
1871 if (a
->nfs_client
!= b
->nfs_client
)
1873 if (a
->flags
!= b
->flags
)
1875 if (a
->wsize
!= b
->wsize
)
1877 if (a
->rsize
!= b
->rsize
)
1879 if (a
->acregmin
!= b
->acregmin
)
1881 if (a
->acregmax
!= b
->acregmax
)
1883 if (a
->acdirmin
!= b
->acdirmin
)
1885 if (a
->acdirmax
!= b
->acdirmax
)
1887 if (clnt_a
->cl_auth
->au_flavor
!= clnt_b
->cl_auth
->au_flavor
)
1894 struct nfs_sb_mountdata
{
1895 struct nfs_server
*server
;
1899 static int nfs_set_super(struct super_block
*s
, void *data
)
1901 struct nfs_sb_mountdata
*sb_mntdata
= data
;
1902 struct nfs_server
*server
= sb_mntdata
->server
;
1905 s
->s_flags
= sb_mntdata
->mntflags
;
1906 s
->s_fs_info
= server
;
1907 ret
= set_anon_super(s
, server
);
1909 server
->s_dev
= s
->s_dev
;
1913 static int nfs_compare_super_address(struct nfs_server
*server1
,
1914 struct nfs_server
*server2
)
1916 struct sockaddr
*sap1
, *sap2
;
1918 sap1
= (struct sockaddr
*)&server1
->nfs_client
->cl_addr
;
1919 sap2
= (struct sockaddr
*)&server2
->nfs_client
->cl_addr
;
1921 if (sap1
->sa_family
!= sap2
->sa_family
)
1924 switch (sap1
->sa_family
) {
1926 struct sockaddr_in
*sin1
= (struct sockaddr_in
*)sap1
;
1927 struct sockaddr_in
*sin2
= (struct sockaddr_in
*)sap2
;
1928 if (sin1
->sin_addr
.s_addr
!= sin2
->sin_addr
.s_addr
)
1930 if (sin1
->sin_port
!= sin2
->sin_port
)
1935 struct sockaddr_in6
*sin1
= (struct sockaddr_in6
*)sap1
;
1936 struct sockaddr_in6
*sin2
= (struct sockaddr_in6
*)sap2
;
1937 if (!ipv6_addr_equal(&sin1
->sin6_addr
, &sin2
->sin6_addr
))
1939 if (sin1
->sin6_port
!= sin2
->sin6_port
)
1950 static int nfs_compare_super(struct super_block
*sb
, void *data
)
1952 struct nfs_sb_mountdata
*sb_mntdata
= data
;
1953 struct nfs_server
*server
= sb_mntdata
->server
, *old
= NFS_SB(sb
);
1954 int mntflags
= sb_mntdata
->mntflags
;
1956 if (!nfs_compare_super_address(old
, server
))
1958 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1959 if (old
->flags
& NFS_MOUNT_UNSHARED
)
1961 if (memcmp(&old
->fsid
, &server
->fsid
, sizeof(old
->fsid
)) != 0)
1963 return nfs_compare_mount_options(sb
, server
, mntflags
);
1966 static int nfs_bdi_register(struct nfs_server
*server
)
1968 return bdi_register_dev(&server
->backing_dev_info
, server
->s_dev
);
1971 static int nfs_get_sb(struct file_system_type
*fs_type
,
1972 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
1974 struct nfs_server
*server
= NULL
;
1975 struct super_block
*s
;
1976 struct nfs_parsed_mount_data
*data
;
1977 struct nfs_fh
*mntfh
;
1978 struct dentry
*mntroot
;
1979 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
1980 struct nfs_sb_mountdata sb_mntdata
= {
1983 int error
= -ENOMEM
;
1985 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
1986 mntfh
= kzalloc(sizeof(*mntfh
), GFP_KERNEL
);
1987 if (data
== NULL
|| mntfh
== NULL
)
1990 security_init_mnt_opts(&data
->lsm_opts
);
1992 /* Validate the mount data */
1993 error
= nfs_validate_mount_data(raw_data
, data
, mntfh
, dev_name
);
1997 /* Get a volume representation */
1998 server
= nfs_create_server(data
, mntfh
);
1999 if (IS_ERR(server
)) {
2000 error
= PTR_ERR(server
);
2003 sb_mntdata
.server
= server
;
2005 if (server
->flags
& NFS_MOUNT_UNSHARED
)
2006 compare_super
= NULL
;
2008 /* Get a superblock - note that we may end up sharing one that already exists */
2009 s
= sget(fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2015 if (s
->s_fs_info
!= server
) {
2016 nfs_free_server(server
);
2019 error
= nfs_bdi_register(server
);
2021 goto error_splat_super
;
2025 /* initial superblock/root creation */
2026 nfs_fill_super(s
, data
);
2029 mntroot
= nfs_get_root(s
, mntfh
);
2030 if (IS_ERR(mntroot
)) {
2031 error
= PTR_ERR(mntroot
);
2032 goto error_splat_super
;
2035 error
= security_sb_set_mnt_opts(s
, &data
->lsm_opts
);
2037 goto error_splat_root
;
2039 s
->s_flags
|= MS_ACTIVE
;
2041 mnt
->mnt_root
= mntroot
;
2045 kfree(data
->nfs_server
.hostname
);
2046 kfree(data
->mount_server
.hostname
);
2047 security_free_mnt_opts(&data
->lsm_opts
);
2054 nfs_free_server(server
);
2060 up_write(&s
->s_umount
);
2061 deactivate_super(s
);
2066 * Destroy an NFS2/3 superblock
2068 static void nfs_kill_super(struct super_block
*s
)
2070 struct nfs_server
*server
= NFS_SB(s
);
2072 bdi_unregister(&server
->backing_dev_info
);
2074 nfs_free_server(server
);
2078 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2080 static int nfs_xdev_get_sb(struct file_system_type
*fs_type
, int flags
,
2081 const char *dev_name
, void *raw_data
,
2082 struct vfsmount
*mnt
)
2084 struct nfs_clone_mount
*data
= raw_data
;
2085 struct super_block
*s
;
2086 struct nfs_server
*server
;
2087 struct dentry
*mntroot
;
2088 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2089 struct nfs_sb_mountdata sb_mntdata
= {
2094 dprintk("--> nfs_xdev_get_sb()\n");
2096 /* create a new volume representation */
2097 server
= nfs_clone_server(NFS_SB(data
->sb
), data
->fh
, data
->fattr
);
2098 if (IS_ERR(server
)) {
2099 error
= PTR_ERR(server
);
2100 goto out_err_noserver
;
2102 sb_mntdata
.server
= server
;
2104 if (server
->flags
& NFS_MOUNT_UNSHARED
)
2105 compare_super
= NULL
;
2107 /* Get a superblock - note that we may end up sharing one that already exists */
2108 s
= sget(&nfs_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2114 if (s
->s_fs_info
!= server
) {
2115 nfs_free_server(server
);
2118 error
= nfs_bdi_register(server
);
2120 goto error_splat_super
;
2124 /* initial superblock/root creation */
2125 nfs_clone_super(s
, data
->sb
);
2128 mntroot
= nfs_get_root(s
, data
->fh
);
2129 if (IS_ERR(mntroot
)) {
2130 error
= PTR_ERR(mntroot
);
2131 goto error_splat_super
;
2133 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
2136 goto error_splat_super
;
2139 s
->s_flags
|= MS_ACTIVE
;
2141 mnt
->mnt_root
= mntroot
;
2143 /* clone any lsm security options from the parent to the new sb */
2144 security_sb_clone_mnt_opts(data
->sb
, s
);
2146 dprintk("<-- nfs_xdev_get_sb() = 0\n");
2150 nfs_free_server(server
);
2152 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error
);
2156 up_write(&s
->s_umount
);
2157 deactivate_super(s
);
2158 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error
);
2162 #ifdef CONFIG_NFS_V4
2165 * Finish setting up a cloned NFS4 superblock
2167 static void nfs4_clone_super(struct super_block
*sb
,
2168 const struct super_block
*old_sb
)
2170 sb
->s_blocksize_bits
= old_sb
->s_blocksize_bits
;
2171 sb
->s_blocksize
= old_sb
->s_blocksize
;
2172 sb
->s_maxbytes
= old_sb
->s_maxbytes
;
2173 sb
->s_time_gran
= 1;
2174 sb
->s_op
= old_sb
->s_op
;
2175 nfs_initialise_sb(sb
);
2179 * Set up an NFS4 superblock
2181 static void nfs4_fill_super(struct super_block
*sb
)
2183 sb
->s_time_gran
= 1;
2184 sb
->s_op
= &nfs4_sops
;
2185 nfs_initialise_sb(sb
);
2189 * Validate NFSv4 mount options
2191 static int nfs4_validate_mount_data(void *options
,
2192 struct nfs_parsed_mount_data
*args
,
2193 const char *dev_name
)
2195 struct sockaddr_in
*ap
;
2196 struct nfs4_mount_data
*data
= (struct nfs4_mount_data
*)options
;
2202 args
->rsize
= NFS_MAX_FILE_IO_SIZE
;
2203 args
->wsize
= NFS_MAX_FILE_IO_SIZE
;
2204 args
->acregmin
= NFS_DEF_ACREGMIN
;
2205 args
->acregmax
= NFS_DEF_ACREGMAX
;
2206 args
->acdirmin
= NFS_DEF_ACDIRMIN
;
2207 args
->acdirmax
= NFS_DEF_ACDIRMAX
;
2208 args
->nfs_server
.port
= NFS_PORT
; /* 2049 unless user set port= */
2209 args
->auth_flavors
[0] = RPC_AUTH_UNIX
;
2210 args
->auth_flavor_len
= 0;
2212 switch (data
->version
) {
2214 ap
= (struct sockaddr_in
*)&args
->nfs_server
.address
;
2215 if (data
->host_addrlen
> sizeof(args
->nfs_server
.address
))
2216 goto out_no_address
;
2217 if (data
->host_addrlen
== 0)
2218 goto out_no_address
;
2219 args
->nfs_server
.addrlen
= data
->host_addrlen
;
2220 if (copy_from_user(ap
, data
->host_addr
, data
->host_addrlen
))
2222 if (!nfs_verify_server_address((struct sockaddr
*)
2223 &args
->nfs_server
.address
))
2224 goto out_no_address
;
2226 if (data
->auth_flavourlen
) {
2227 if (data
->auth_flavourlen
> 1)
2228 goto out_inval_auth
;
2229 if (copy_from_user(&args
->auth_flavors
[0],
2230 data
->auth_flavours
,
2231 sizeof(args
->auth_flavors
[0])))
2235 c
= strndup_user(data
->hostname
.data
, NFS4_MAXNAMLEN
);
2238 args
->nfs_server
.hostname
= c
;
2240 c
= strndup_user(data
->mnt_path
.data
, NFS4_MAXPATHLEN
);
2243 args
->nfs_server
.export_path
= c
;
2244 dfprintk(MOUNT
, "NFS: MNTPATH: '%s'\n", c
);
2246 c
= strndup_user(data
->client_addr
.data
, 16);
2249 args
->client_address
= c
;
2252 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2256 args
->flags
= data
->flags
& NFS4_MOUNT_FLAGMASK
;
2257 args
->rsize
= data
->rsize
;
2258 args
->wsize
= data
->wsize
;
2259 args
->timeo
= data
->timeo
;
2260 args
->retrans
= data
->retrans
;
2261 args
->acregmin
= data
->acregmin
;
2262 args
->acregmax
= data
->acregmax
;
2263 args
->acdirmin
= data
->acdirmin
;
2264 args
->acdirmax
= data
->acdirmax
;
2265 args
->nfs_server
.protocol
= data
->proto
;
2266 nfs_validate_transport_protocol(args
);
2272 if (nfs_parse_mount_options((char *)options
, args
) == 0)
2275 if (!nfs_verify_server_address((struct sockaddr
*)
2276 &args
->nfs_server
.address
))
2279 nfs_set_port((struct sockaddr
*)&args
->nfs_server
.address
,
2280 args
->nfs_server
.port
);
2282 nfs_validate_transport_protocol(args
);
2284 if (args
->auth_flavor_len
> 1)
2285 goto out_inval_auth
;
2287 if (args
->client_address
== NULL
)
2288 goto out_no_client_address
;
2290 status
= nfs_parse_devname(dev_name
,
2291 &args
->nfs_server
.hostname
,
2293 &args
->nfs_server
.export_path
,
2305 dfprintk(MOUNT
, "NFS4: mount program didn't pass any mount data\n");
2309 dfprintk(MOUNT
, "NFS4: Invalid number of RPC auth flavours %d\n",
2310 data
->auth_flavourlen
);
2314 dfprintk(MOUNT
, "NFS4: mount program didn't pass remote address\n");
2317 out_no_client_address
:
2318 dfprintk(MOUNT
, "NFS4: mount program didn't pass callback address\n");
2323 * Get the superblock for an NFS4 mountpoint
2325 static int nfs4_get_sb(struct file_system_type
*fs_type
,
2326 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
2328 struct nfs_parsed_mount_data
*data
;
2329 struct super_block
*s
;
2330 struct nfs_server
*server
;
2331 struct nfs_fh
*mntfh
;
2332 struct dentry
*mntroot
;
2333 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2334 struct nfs_sb_mountdata sb_mntdata
= {
2337 int error
= -ENOMEM
;
2339 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
2340 mntfh
= kzalloc(sizeof(*mntfh
), GFP_KERNEL
);
2341 if (data
== NULL
|| mntfh
== NULL
)
2344 security_init_mnt_opts(&data
->lsm_opts
);
2346 /* Validate the mount data */
2347 error
= nfs4_validate_mount_data(raw_data
, data
, dev_name
);
2351 /* Get a volume representation */
2352 server
= nfs4_create_server(data
, mntfh
);
2353 if (IS_ERR(server
)) {
2354 error
= PTR_ERR(server
);
2357 sb_mntdata
.server
= server
;
2359 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2360 compare_super
= NULL
;
2362 /* Get a superblock - note that we may end up sharing one that already exists */
2363 s
= sget(fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2369 if (s
->s_fs_info
!= server
) {
2370 nfs_free_server(server
);
2373 error
= nfs_bdi_register(server
);
2375 goto error_splat_super
;
2379 /* initial superblock/root creation */
2383 mntroot
= nfs4_get_root(s
, mntfh
);
2384 if (IS_ERR(mntroot
)) {
2385 error
= PTR_ERR(mntroot
);
2386 goto error_splat_super
;
2389 error
= security_sb_set_mnt_opts(s
, &data
->lsm_opts
);
2391 goto error_splat_root
;
2393 s
->s_flags
|= MS_ACTIVE
;
2395 mnt
->mnt_root
= mntroot
;
2399 kfree(data
->client_address
);
2400 kfree(data
->nfs_server
.export_path
);
2401 kfree(data
->nfs_server
.hostname
);
2402 security_free_mnt_opts(&data
->lsm_opts
);
2409 nfs_free_server(server
);
2415 up_write(&s
->s_umount
);
2416 deactivate_super(s
);
2420 static void nfs4_kill_super(struct super_block
*sb
)
2422 struct nfs_server
*server
= NFS_SB(sb
);
2424 nfs_return_all_delegations(sb
);
2425 kill_anon_super(sb
);
2427 nfs4_renewd_prepare_shutdown(server
);
2428 nfs_free_server(server
);
2432 * Clone an NFS4 server record on xdev traversal (FSID-change)
2434 static int nfs4_xdev_get_sb(struct file_system_type
*fs_type
, int flags
,
2435 const char *dev_name
, void *raw_data
,
2436 struct vfsmount
*mnt
)
2438 struct nfs_clone_mount
*data
= raw_data
;
2439 struct super_block
*s
;
2440 struct nfs_server
*server
;
2441 struct dentry
*mntroot
;
2442 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2443 struct nfs_sb_mountdata sb_mntdata
= {
2448 dprintk("--> nfs4_xdev_get_sb()\n");
2450 /* create a new volume representation */
2451 server
= nfs_clone_server(NFS_SB(data
->sb
), data
->fh
, data
->fattr
);
2452 if (IS_ERR(server
)) {
2453 error
= PTR_ERR(server
);
2454 goto out_err_noserver
;
2456 sb_mntdata
.server
= server
;
2458 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2459 compare_super
= NULL
;
2461 /* Get a superblock - note that we may end up sharing one that already exists */
2462 s
= sget(&nfs4_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2468 if (s
->s_fs_info
!= server
) {
2469 nfs_free_server(server
);
2472 error
= nfs_bdi_register(server
);
2474 goto error_splat_super
;
2478 /* initial superblock/root creation */
2479 nfs4_clone_super(s
, data
->sb
);
2482 mntroot
= nfs4_get_root(s
, data
->fh
);
2483 if (IS_ERR(mntroot
)) {
2484 error
= PTR_ERR(mntroot
);
2485 goto error_splat_super
;
2487 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
2490 goto error_splat_super
;
2493 s
->s_flags
|= MS_ACTIVE
;
2495 mnt
->mnt_root
= mntroot
;
2497 security_sb_clone_mnt_opts(data
->sb
, s
);
2499 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2503 nfs_free_server(server
);
2505 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error
);
2509 up_write(&s
->s_umount
);
2510 deactivate_super(s
);
2511 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error
);
2516 * Create an NFS4 server record on referral traversal
2518 static int nfs4_referral_get_sb(struct file_system_type
*fs_type
, int flags
,
2519 const char *dev_name
, void *raw_data
,
2520 struct vfsmount
*mnt
)
2522 struct nfs_clone_mount
*data
= raw_data
;
2523 struct super_block
*s
;
2524 struct nfs_server
*server
;
2525 struct dentry
*mntroot
;
2526 struct nfs_fh mntfh
;
2527 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2528 struct nfs_sb_mountdata sb_mntdata
= {
2533 dprintk("--> nfs4_referral_get_sb()\n");
2535 /* create a new volume representation */
2536 server
= nfs4_create_referral_server(data
, &mntfh
);
2537 if (IS_ERR(server
)) {
2538 error
= PTR_ERR(server
);
2539 goto out_err_noserver
;
2541 sb_mntdata
.server
= server
;
2543 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2544 compare_super
= NULL
;
2546 /* Get a superblock - note that we may end up sharing one that already exists */
2547 s
= sget(&nfs4_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2553 if (s
->s_fs_info
!= server
) {
2554 nfs_free_server(server
);
2557 error
= nfs_bdi_register(server
);
2559 goto error_splat_super
;
2563 /* initial superblock/root creation */
2567 mntroot
= nfs4_get_root(s
, &mntfh
);
2568 if (IS_ERR(mntroot
)) {
2569 error
= PTR_ERR(mntroot
);
2570 goto error_splat_super
;
2572 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
2575 goto error_splat_super
;
2578 s
->s_flags
|= MS_ACTIVE
;
2580 mnt
->mnt_root
= mntroot
;
2582 security_sb_clone_mnt_opts(data
->sb
, s
);
2584 dprintk("<-- nfs4_referral_get_sb() = 0\n");
2588 nfs_free_server(server
);
2590 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error
);
2594 up_write(&s
->s_umount
);
2595 deactivate_super(s
);
2596 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error
);
2600 #endif /* CONFIG_NFS_V4 */