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/nfs_fs.h>
37 #include <linux/nfs_mount.h>
38 #include <linux/nfs4_mount.h>
39 #include <linux/lockd/bind.h>
40 #include <linux/smp_lock.h>
41 #include <linux/seq_file.h>
42 #include <linux/mount.h>
43 #include <linux/nfs_idmap.h>
44 #include <linux/vfs.h>
45 #include <linux/inet.h>
46 #include <linux/nfs_xdr.h>
47 #include <linux/magic.h>
48 #include <linux/parser.h>
50 #include <asm/system.h>
51 #include <asm/uaccess.h>
55 #include "delegation.h"
59 #define NFSDBG_FACILITY NFSDBG_VFS
62 struct nfs_parsed_mount_data
{
66 int acregmin
, acregmax
,
70 unsigned int auth_flavor_len
;
71 rpc_authflavor_t auth_flavors
[1];
75 struct sockaddr_in address
;
84 struct sockaddr_in address
;
93 /* Mount options that take no arguments */
96 Opt_posix
, Opt_noposix
,
103 Opt_rdirplus
, Opt_nordirplus
,
104 Opt_sharecache
, Opt_nosharecache
,
106 /* Mount options that take integer arguments */
108 Opt_rsize
, Opt_wsize
, Opt_bsize
,
109 Opt_timeo
, Opt_retrans
,
110 Opt_acregmin
, Opt_acregmax
,
111 Opt_acdirmin
, Opt_acdirmax
,
115 Opt_mountprog
, Opt_mountvers
,
116 Opt_nfsprog
, Opt_nfsvers
,
118 /* Mount options that take string arguments */
119 Opt_sec
, Opt_proto
, Opt_mountproto
,
120 Opt_addr
, Opt_mountaddr
, Opt_clientaddr
,
122 /* Mount options that are ignored */
123 Opt_userspace
, Opt_deprecated
,
128 static match_table_t nfs_mount_option_tokens
= {
129 { Opt_userspace
, "bg" },
130 { Opt_userspace
, "fg" },
131 { Opt_soft
, "soft" },
132 { Opt_hard
, "hard" },
133 { Opt_intr
, "intr" },
134 { Opt_nointr
, "nointr" },
135 { Opt_posix
, "posix" },
136 { Opt_noposix
, "noposix" },
138 { Opt_nocto
, "nocto" },
140 { Opt_noac
, "noac" },
141 { Opt_lock
, "lock" },
142 { Opt_nolock
, "nolock" },
148 { Opt_noacl
, "noacl" },
149 { Opt_rdirplus
, "rdirplus" },
150 { Opt_nordirplus
, "nordirplus" },
151 { Opt_sharecache
, "sharecache" },
152 { Opt_nosharecache
, "nosharecache" },
154 { Opt_port
, "port=%u" },
155 { Opt_rsize
, "rsize=%u" },
156 { Opt_wsize
, "wsize=%u" },
157 { Opt_bsize
, "bsize=%u" },
158 { Opt_timeo
, "timeo=%u" },
159 { Opt_retrans
, "retrans=%u" },
160 { Opt_acregmin
, "acregmin=%u" },
161 { Opt_acregmax
, "acregmax=%u" },
162 { Opt_acdirmin
, "acdirmin=%u" },
163 { Opt_acdirmax
, "acdirmax=%u" },
164 { Opt_actimeo
, "actimeo=%u" },
165 { Opt_userspace
, "retry=%u" },
166 { Opt_namelen
, "namlen=%u" },
167 { Opt_mountport
, "mountport=%u" },
168 { Opt_mountprog
, "mountprog=%u" },
169 { Opt_mountvers
, "mountvers=%u" },
170 { Opt_nfsprog
, "nfsprog=%u" },
171 { Opt_nfsvers
, "nfsvers=%u" },
172 { Opt_nfsvers
, "vers=%u" },
174 { Opt_sec
, "sec=%s" },
175 { Opt_proto
, "proto=%s" },
176 { Opt_mountproto
, "mountproto=%s" },
177 { Opt_addr
, "addr=%s" },
178 { Opt_clientaddr
, "clientaddr=%s" },
179 { Opt_userspace
, "mounthost=%s" },
180 { Opt_mountaddr
, "mountaddr=%s" },
186 Opt_xprt_udp
, Opt_xprt_tcp
,
191 static match_table_t nfs_xprt_protocol_tokens
= {
192 { Opt_xprt_udp
, "udp" },
193 { Opt_xprt_tcp
, "tcp" },
195 { Opt_xprt_err
, NULL
}
199 Opt_sec_none
, Opt_sec_sys
,
200 Opt_sec_krb5
, Opt_sec_krb5i
, Opt_sec_krb5p
,
201 Opt_sec_lkey
, Opt_sec_lkeyi
, Opt_sec_lkeyp
,
202 Opt_sec_spkm
, Opt_sec_spkmi
, Opt_sec_spkmp
,
207 static match_table_t nfs_secflavor_tokens
= {
208 { Opt_sec_none
, "none" },
209 { Opt_sec_none
, "null" },
210 { Opt_sec_sys
, "sys" },
212 { Opt_sec_krb5
, "krb5" },
213 { Opt_sec_krb5i
, "krb5i" },
214 { Opt_sec_krb5p
, "krb5p" },
216 { Opt_sec_lkey
, "lkey" },
217 { Opt_sec_lkeyi
, "lkeyi" },
218 { Opt_sec_lkeyp
, "lkeyp" },
220 { Opt_sec_err
, NULL
}
224 static void nfs_umount_begin(struct vfsmount
*, int);
225 static int nfs_statfs(struct dentry
*, struct kstatfs
*);
226 static int nfs_show_options(struct seq_file
*, struct vfsmount
*);
227 static int nfs_show_stats(struct seq_file
*, struct vfsmount
*);
228 static int nfs_get_sb(struct file_system_type
*, int, const char *, void *, struct vfsmount
*);
229 static int nfs_xdev_get_sb(struct file_system_type
*fs_type
,
230 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
231 static void nfs_kill_super(struct super_block
*);
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
,
261 static int nfs4_get_sb(struct file_system_type
*fs_type
,
262 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
263 static int nfs4_xdev_get_sb(struct file_system_type
*fs_type
,
264 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
265 static int nfs4_referral_get_sb(struct file_system_type
*fs_type
,
266 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
267 static void nfs4_kill_super(struct super_block
*sb
);
269 static struct file_system_type nfs4_fs_type
= {
270 .owner
= THIS_MODULE
,
272 .get_sb
= nfs4_get_sb
,
273 .kill_sb
= nfs4_kill_super
,
274 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
277 struct file_system_type nfs4_xdev_fs_type
= {
278 .owner
= THIS_MODULE
,
280 .get_sb
= nfs4_xdev_get_sb
,
281 .kill_sb
= nfs4_kill_super
,
282 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
285 struct file_system_type nfs4_referral_fs_type
= {
286 .owner
= THIS_MODULE
,
288 .get_sb
= nfs4_referral_get_sb
,
289 .kill_sb
= nfs4_kill_super
,
290 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
293 static const struct super_operations nfs4_sops
= {
294 .alloc_inode
= nfs_alloc_inode
,
295 .destroy_inode
= nfs_destroy_inode
,
296 .write_inode
= nfs_write_inode
,
297 .statfs
= nfs_statfs
,
298 .clear_inode
= nfs4_clear_inode
,
299 .umount_begin
= nfs_umount_begin
,
300 .show_options
= nfs_show_options
,
301 .show_stats
= nfs_show_stats
,
305 static struct shrinker acl_shrinker
= {
306 .shrink
= nfs_access_cache_shrinker
,
307 .seeks
= DEFAULT_SEEKS
,
311 * Register the NFS filesystems
313 int __init
register_nfs_fs(void)
317 ret
= register_filesystem(&nfs_fs_type
);
321 ret
= nfs_register_sysctl();
325 ret
= register_filesystem(&nfs4_fs_type
);
329 register_shrinker(&acl_shrinker
);
334 nfs_unregister_sysctl();
337 unregister_filesystem(&nfs_fs_type
);
343 * Unregister the NFS filesystems
345 void __exit
unregister_nfs_fs(void)
347 unregister_shrinker(&acl_shrinker
);
349 unregister_filesystem(&nfs4_fs_type
);
351 nfs_unregister_sysctl();
352 unregister_filesystem(&nfs_fs_type
);
356 * Deliver file system statistics to userspace
358 static int nfs_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
360 struct nfs_server
*server
= NFS_SB(dentry
->d_sb
);
361 unsigned char blockbits
;
362 unsigned long blockres
;
363 struct nfs_fh
*fh
= NFS_FH(dentry
->d_inode
);
364 struct nfs_fattr fattr
;
365 struct nfs_fsstat res
= {
372 error
= server
->nfs_client
->rpc_ops
->statfs(server
, fh
, &res
);
375 buf
->f_type
= NFS_SUPER_MAGIC
;
378 * Current versions of glibc do not correctly handle the
379 * case where f_frsize != f_bsize. Eventually we want to
380 * report the value of wtmult in this field.
382 buf
->f_frsize
= dentry
->d_sb
->s_blocksize
;
385 * On most *nix systems, f_blocks, f_bfree, and f_bavail
386 * are reported in units of f_frsize. Linux hasn't had
387 * an f_frsize field in its statfs struct until recently,
388 * thus historically Linux's sys_statfs reports these
389 * fields in units of f_bsize.
391 buf
->f_bsize
= dentry
->d_sb
->s_blocksize
;
392 blockbits
= dentry
->d_sb
->s_blocksize_bits
;
393 blockres
= (1 << blockbits
) - 1;
394 buf
->f_blocks
= (res
.tbytes
+ blockres
) >> blockbits
;
395 buf
->f_bfree
= (res
.fbytes
+ blockres
) >> blockbits
;
396 buf
->f_bavail
= (res
.abytes
+ blockres
) >> blockbits
;
398 buf
->f_files
= res
.tfiles
;
399 buf
->f_ffree
= res
.afiles
;
401 buf
->f_namelen
= server
->namelen
;
407 dprintk("%s: statfs error = %d\n", __FUNCTION__
, -error
);
413 * Map the security flavour number to a name
415 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour
)
417 static const struct {
418 rpc_authflavor_t flavour
;
421 { RPC_AUTH_NULL
, "null" },
422 { RPC_AUTH_UNIX
, "sys" },
423 { RPC_AUTH_GSS_KRB5
, "krb5" },
424 { RPC_AUTH_GSS_KRB5I
, "krb5i" },
425 { RPC_AUTH_GSS_KRB5P
, "krb5p" },
426 { RPC_AUTH_GSS_LKEY
, "lkey" },
427 { RPC_AUTH_GSS_LKEYI
, "lkeyi" },
428 { RPC_AUTH_GSS_LKEYP
, "lkeyp" },
429 { RPC_AUTH_GSS_SPKM
, "spkm" },
430 { RPC_AUTH_GSS_SPKMI
, "spkmi" },
431 { RPC_AUTH_GSS_SPKMP
, "spkmp" },
432 { UINT_MAX
, "unknown" }
436 for (i
= 0; sec_flavours
[i
].flavour
!= UINT_MAX
; i
++) {
437 if (sec_flavours
[i
].flavour
== flavour
)
440 return sec_flavours
[i
].str
;
444 * Describe the mount options in force on this server representation
446 static void nfs_show_mount_options(struct seq_file
*m
, struct nfs_server
*nfss
, int showdefaults
)
448 static const struct proc_nfs_info
{
453 { NFS_MOUNT_SOFT
, ",soft", ",hard" },
454 { NFS_MOUNT_INTR
, ",intr", "" },
455 { NFS_MOUNT_NOCTO
, ",nocto", "" },
456 { NFS_MOUNT_NOAC
, ",noac", "" },
457 { NFS_MOUNT_NONLM
, ",nolock", "" },
458 { NFS_MOUNT_NOACL
, ",noacl", "" },
459 { NFS_MOUNT_NORDIRPLUS
, ",nordirplus", "" },
460 { NFS_MOUNT_UNSHARED
, ",nosharecache", ""},
463 const struct proc_nfs_info
*nfs_infop
;
464 struct nfs_client
*clp
= nfss
->nfs_client
;
468 seq_printf(m
, ",vers=%d", clp
->rpc_ops
->version
);
469 seq_printf(m
, ",rsize=%d", nfss
->rsize
);
470 seq_printf(m
, ",wsize=%d", nfss
->wsize
);
471 if (nfss
->acregmin
!= 3*HZ
|| showdefaults
)
472 seq_printf(m
, ",acregmin=%d", nfss
->acregmin
/HZ
);
473 if (nfss
->acregmax
!= 60*HZ
|| showdefaults
)
474 seq_printf(m
, ",acregmax=%d", nfss
->acregmax
/HZ
);
475 if (nfss
->acdirmin
!= 30*HZ
|| showdefaults
)
476 seq_printf(m
, ",acdirmin=%d", nfss
->acdirmin
/HZ
);
477 if (nfss
->acdirmax
!= 60*HZ
|| showdefaults
)
478 seq_printf(m
, ",acdirmax=%d", nfss
->acdirmax
/HZ
);
479 for (nfs_infop
= nfs_info
; nfs_infop
->flag
; nfs_infop
++) {
480 if (nfss
->flags
& nfs_infop
->flag
)
481 seq_puts(m
, nfs_infop
->str
);
483 seq_puts(m
, nfs_infop
->nostr
);
485 switch (nfss
->client
->cl_xprt
->prot
) {
493 snprintf(buf
, sizeof(buf
), "%u", nfss
->client
->cl_xprt
->prot
);
496 seq_printf(m
, ",proto=%s", proto
);
497 seq_printf(m
, ",timeo=%lu", 10U * clp
->retrans_timeo
/ HZ
);
498 seq_printf(m
, ",retrans=%u", clp
->retrans_count
);
499 seq_printf(m
, ",sec=%s", nfs_pseudoflavour_to_name(nfss
->client
->cl_auth
->au_flavor
));
503 * Describe the mount options on this VFS mountpoint
505 static int nfs_show_options(struct seq_file
*m
, struct vfsmount
*mnt
)
507 struct nfs_server
*nfss
= NFS_SB(mnt
->mnt_sb
);
509 nfs_show_mount_options(m
, nfss
, 0);
511 seq_printf(m
, ",addr="NIPQUAD_FMT
,
512 NIPQUAD(nfss
->nfs_client
->cl_addr
.sin_addr
));
518 * Present statistical information for this VFS mountpoint
520 static int nfs_show_stats(struct seq_file
*m
, struct vfsmount
*mnt
)
523 struct nfs_server
*nfss
= NFS_SB(mnt
->mnt_sb
);
524 struct rpc_auth
*auth
= nfss
->client
->cl_auth
;
525 struct nfs_iostats totals
= { };
527 seq_printf(m
, "statvers=%s", NFS_IOSTAT_VERS
);
530 * Display all mount option settings
532 seq_printf(m
, "\n\topts:\t");
533 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_RDONLY
? "ro" : "rw");
534 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_SYNCHRONOUS
? ",sync" : "");
535 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_NOATIME
? ",noatime" : "");
536 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_NODIRATIME
? ",nodiratime" : "");
537 nfs_show_mount_options(m
, nfss
, 1);
539 seq_printf(m
, "\n\tage:\t%lu", (jiffies
- nfss
->mount_time
) / HZ
);
541 seq_printf(m
, "\n\tcaps:\t");
542 seq_printf(m
, "caps=0x%x", nfss
->caps
);
543 seq_printf(m
, ",wtmult=%d", nfss
->wtmult
);
544 seq_printf(m
, ",dtsize=%d", nfss
->dtsize
);
545 seq_printf(m
, ",bsize=%d", nfss
->bsize
);
546 seq_printf(m
, ",namelen=%d", nfss
->namelen
);
549 if (nfss
->nfs_client
->cl_nfsversion
== 4) {
550 seq_printf(m
, "\n\tnfsv4:\t");
551 seq_printf(m
, "bm0=0x%x", nfss
->attr_bitmask
[0]);
552 seq_printf(m
, ",bm1=0x%x", nfss
->attr_bitmask
[1]);
553 seq_printf(m
, ",acl=0x%x", nfss
->acl_bitmask
);
558 * Display security flavor in effect for this mount
560 seq_printf(m
, "\n\tsec:\tflavor=%d", auth
->au_ops
->au_flavor
);
562 seq_printf(m
, ",pseudoflavor=%d", auth
->au_flavor
);
565 * Display superblock I/O counters
567 for_each_possible_cpu(cpu
) {
568 struct nfs_iostats
*stats
;
571 stats
= per_cpu_ptr(nfss
->io_stats
, cpu
);
573 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
574 totals
.events
[i
] += stats
->events
[i
];
575 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
576 totals
.bytes
[i
] += stats
->bytes
[i
];
581 seq_printf(m
, "\n\tevents:\t");
582 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
583 seq_printf(m
, "%lu ", totals
.events
[i
]);
584 seq_printf(m
, "\n\tbytes:\t");
585 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
586 seq_printf(m
, "%Lu ", totals
.bytes
[i
]);
589 rpc_print_iostats(m
, nfss
->client
);
595 * Begin unmount by attempting to remove all automounted mountpoints we added
596 * in response to xdev traversals and referrals
598 static void nfs_umount_begin(struct vfsmount
*vfsmnt
, int flags
)
600 struct nfs_server
*server
= NFS_SB(vfsmnt
->mnt_sb
);
601 struct rpc_clnt
*rpc
;
603 shrink_submounts(vfsmnt
, &nfs_automount_list
);
605 if (!(flags
& MNT_FORCE
))
607 /* -EIO all pending I/O */
608 rpc
= server
->client_acl
;
610 rpc_killall_tasks(rpc
);
611 rpc
= server
->client
;
613 rpc_killall_tasks(rpc
);
617 * Sanity-check a server address provided by the mount command
619 static int nfs_verify_server_address(struct sockaddr
*addr
)
621 switch (addr
->sa_family
) {
623 struct sockaddr_in
*sa
= (struct sockaddr_in
*) addr
;
624 if (sa
->sin_addr
.s_addr
!= INADDR_ANY
)
634 * Error-check and convert a string of mount options from user space into
637 static int nfs_parse_mount_options(char *raw
,
638 struct nfs_parsed_mount_data
*mnt
)
643 dfprintk(MOUNT
, "NFS: mount options string was NULL.\n");
646 dfprintk(MOUNT
, "NFS: nfs mount opts='%s'\n", raw
);
648 while ((p
= strsep(&raw
, ",")) != NULL
) {
649 substring_t args
[MAX_OPT_ARGS
];
655 dfprintk(MOUNT
, "NFS: parsing nfs mount option '%s'\n", p
);
657 token
= match_token(p
, nfs_mount_option_tokens
, args
);
660 mnt
->flags
|= NFS_MOUNT_SOFT
;
663 mnt
->flags
&= ~NFS_MOUNT_SOFT
;
666 mnt
->flags
|= NFS_MOUNT_INTR
;
669 mnt
->flags
&= ~NFS_MOUNT_INTR
;
672 mnt
->flags
|= NFS_MOUNT_POSIX
;
675 mnt
->flags
&= ~NFS_MOUNT_POSIX
;
678 mnt
->flags
&= ~NFS_MOUNT_NOCTO
;
681 mnt
->flags
|= NFS_MOUNT_NOCTO
;
684 mnt
->flags
&= ~NFS_MOUNT_NOAC
;
687 mnt
->flags
|= NFS_MOUNT_NOAC
;
690 mnt
->flags
&= ~NFS_MOUNT_NONLM
;
693 mnt
->flags
|= NFS_MOUNT_NONLM
;
696 mnt
->flags
&= ~NFS_MOUNT_VER3
;
699 mnt
->flags
|= NFS_MOUNT_VER3
;
702 mnt
->flags
&= ~NFS_MOUNT_TCP
;
703 mnt
->nfs_server
.protocol
= IPPROTO_UDP
;
708 mnt
->flags
|= NFS_MOUNT_TCP
;
709 mnt
->nfs_server
.protocol
= IPPROTO_TCP
;
714 mnt
->flags
&= ~NFS_MOUNT_NOACL
;
717 mnt
->flags
|= NFS_MOUNT_NOACL
;
720 mnt
->flags
&= ~NFS_MOUNT_NORDIRPLUS
;
723 mnt
->flags
|= NFS_MOUNT_NORDIRPLUS
;
726 mnt
->flags
&= ~NFS_MOUNT_UNSHARED
;
728 case Opt_nosharecache
:
729 mnt
->flags
|= NFS_MOUNT_UNSHARED
;
733 if (match_int(args
, &option
))
735 if (option
< 0 || option
> 65535)
737 mnt
->nfs_server
.address
.sin_port
= htons(option
);
740 if (match_int(args
, &mnt
->rsize
))
744 if (match_int(args
, &mnt
->wsize
))
748 if (match_int(args
, &option
))
755 if (match_int(args
, &mnt
->timeo
))
759 if (match_int(args
, &mnt
->retrans
))
763 if (match_int(args
, &mnt
->acregmin
))
767 if (match_int(args
, &mnt
->acregmax
))
771 if (match_int(args
, &mnt
->acdirmin
))
775 if (match_int(args
, &mnt
->acdirmax
))
779 if (match_int(args
, &option
))
786 mnt
->acdirmax
= option
;
789 if (match_int(args
, &mnt
->namlen
))
793 if (match_int(args
, &option
))
795 if (option
< 0 || option
> 65535)
797 mnt
->mount_server
.port
= option
;
800 if (match_int(args
, &option
))
804 mnt
->mount_server
.program
= option
;
807 if (match_int(args
, &option
))
811 mnt
->mount_server
.version
= option
;
814 if (match_int(args
, &option
))
818 mnt
->nfs_server
.program
= option
;
821 if (match_int(args
, &option
))
825 mnt
->flags
&= ~NFS_MOUNT_VER3
;
828 mnt
->flags
|= NFS_MOUNT_VER3
;
836 string
= match_strdup(args
);
839 token
= match_token(string
, nfs_secflavor_tokens
, args
);
843 * The flags setting is for v2/v3. The flavor_len
844 * setting is for v4. v2/v3 also need to know the
845 * difference between NULL and UNIX.
849 mnt
->flags
&= ~NFS_MOUNT_SECFLAVOUR
;
850 mnt
->auth_flavor_len
= 0;
851 mnt
->auth_flavors
[0] = RPC_AUTH_NULL
;
854 mnt
->flags
&= ~NFS_MOUNT_SECFLAVOUR
;
855 mnt
->auth_flavor_len
= 0;
856 mnt
->auth_flavors
[0] = RPC_AUTH_UNIX
;
859 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
860 mnt
->auth_flavor_len
= 1;
861 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5
;
864 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
865 mnt
->auth_flavor_len
= 1;
866 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5I
;
869 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
870 mnt
->auth_flavor_len
= 1;
871 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5P
;
874 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
875 mnt
->auth_flavor_len
= 1;
876 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEY
;
879 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
880 mnt
->auth_flavor_len
= 1;
881 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEYI
;
884 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
885 mnt
->auth_flavor_len
= 1;
886 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEYP
;
889 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
890 mnt
->auth_flavor_len
= 1;
891 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKM
;
894 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
895 mnt
->auth_flavor_len
= 1;
896 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKMI
;
899 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
900 mnt
->auth_flavor_len
= 1;
901 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKMP
;
908 string
= match_strdup(args
);
911 token
= match_token(string
,
912 nfs_xprt_protocol_tokens
, args
);
917 mnt
->flags
&= ~NFS_MOUNT_TCP
;
918 mnt
->nfs_server
.protocol
= IPPROTO_UDP
;
923 mnt
->flags
|= NFS_MOUNT_TCP
;
924 mnt
->nfs_server
.protocol
= IPPROTO_TCP
;
933 string
= match_strdup(args
);
936 token
= match_token(string
,
937 nfs_xprt_protocol_tokens
, args
);
942 mnt
->mount_server
.protocol
= IPPROTO_UDP
;
945 mnt
->mount_server
.protocol
= IPPROTO_TCP
;
952 string
= match_strdup(args
);
955 mnt
->nfs_server
.address
.sin_family
= AF_INET
;
956 mnt
->nfs_server
.address
.sin_addr
.s_addr
=
961 string
= match_strdup(args
);
964 mnt
->client_address
= string
;
967 string
= match_strdup(args
);
970 mnt
->mount_server
.address
.sin_family
= AF_INET
;
971 mnt
->mount_server
.address
.sin_addr
.s_addr
=
988 printk(KERN_INFO
"NFS: not enough memory to parse option\n");
992 printk(KERN_INFO
"NFS: unrecognized NFS version number\n");
996 printk(KERN_INFO
"NFS: unrecognized transport protocol\n");
1000 printk(KERN_INFO
"NFS: unrecognized security flavor\n");
1004 printk(KERN_INFO
"NFS: unknown mount option: %s\n", p
);
1009 * Use the remote server's MOUNT service to request the NFS file handle
1010 * corresponding to the provided path.
1012 static int nfs_try_mount(struct nfs_parsed_mount_data
*args
,
1013 struct nfs_fh
*root_fh
)
1015 struct sockaddr_in sin
;
1018 if (args
->mount_server
.version
== 0) {
1019 if (args
->flags
& NFS_MOUNT_VER3
)
1020 args
->mount_server
.version
= NFS_MNT3_VERSION
;
1022 args
->mount_server
.version
= NFS_MNT_VERSION
;
1026 * Construct the mount server's address.
1028 if (args
->mount_server
.address
.sin_addr
.s_addr
!= INADDR_ANY
)
1029 sin
= args
->mount_server
.address
;
1031 sin
= args
->nfs_server
.address
;
1033 * autobind will be used if mount_server.port == 0
1035 sin
.sin_port
= htons(args
->mount_server
.port
);
1038 * Now ask the mount server to map our export path
1041 status
= nfs_mount((struct sockaddr
*) &sin
,
1043 args
->nfs_server
.hostname
,
1044 args
->nfs_server
.export_path
,
1045 args
->mount_server
.version
,
1046 args
->mount_server
.protocol
,
1051 dfprintk(MOUNT
, "NFS: unable to mount server " NIPQUAD_FMT
1052 ", error %d\n", NIPQUAD(sin
.sin_addr
.s_addr
), status
);
1057 * Validate the NFS2/NFS3 mount data
1058 * - fills in the mount root filehandle
1060 * For option strings, user space handles the following behaviors:
1062 * + DNS: mapping server host name to IP address ("addr=" option)
1064 * + failure mode: how to behave if a mount request can't be handled
1065 * immediately ("fg/bg" option)
1067 * + retry: how often to retry a mount request ("retry=" option)
1069 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1070 * mountproto=tcp after mountproto=udp, and so on
1072 * XXX: as far as I can tell, changing the NFS program number is not
1073 * supported in the NFS client.
1075 static int nfs_validate_mount_data(struct nfs_mount_data
**options
,
1076 struct nfs_fh
*mntfh
,
1077 const char *dev_name
)
1079 struct nfs_mount_data
*data
= *options
;
1084 switch (data
->version
) {
1090 if (data
->flags
& NFS_MOUNT_VER3
)
1092 data
->root
.size
= NFS2_FHSIZE
;
1093 memcpy(data
->root
.data
, data
->old_root
.data
, NFS2_FHSIZE
);
1095 if (data
->flags
& NFS_MOUNT_SECFLAVOUR
)
1098 memset(data
->context
, 0, sizeof(data
->context
));
1100 if (data
->flags
& NFS_MOUNT_VER3
)
1101 mntfh
->size
= data
->root
.size
;
1103 mntfh
->size
= NFS2_FHSIZE
;
1105 if (mntfh
->size
> sizeof(mntfh
->data
))
1106 goto out_invalid_fh
;
1108 memcpy(mntfh
->data
, data
->root
.data
, mntfh
->size
);
1109 if (mntfh
->size
< sizeof(mntfh
->data
))
1110 memset(mntfh
->data
+ mntfh
->size
, 0,
1111 sizeof(mntfh
->data
) - mntfh
->size
);
1117 struct nfs_parsed_mount_data args
= {
1118 .flags
= (NFS_MOUNT_VER3
| NFS_MOUNT_TCP
),
1119 .rsize
= NFS_MAX_FILE_IO_SIZE
,
1120 .wsize
= NFS_MAX_FILE_IO_SIZE
,
1127 .mount_server
.protocol
= IPPROTO_UDP
,
1128 .mount_server
.program
= NFS_MNT_PROGRAM
,
1129 .nfs_server
.protocol
= IPPROTO_TCP
,
1130 .nfs_server
.program
= NFS_PROGRAM
,
1133 if (nfs_parse_mount_options((char *) *options
, &args
) == 0)
1136 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
1141 * NB: after this point, caller will free "data"
1142 * if we return an error
1146 c
= strchr(dev_name
, ':');
1150 if (len
> sizeof(data
->hostname
))
1151 return -ENAMETOOLONG
;
1152 strncpy(data
->hostname
, dev_name
, len
);
1153 args
.nfs_server
.hostname
= data
->hostname
;
1156 if (strlen(c
) > NFS_MAXPATHLEN
)
1157 return -ENAMETOOLONG
;
1158 args
.nfs_server
.export_path
= c
;
1160 status
= nfs_try_mount(&args
, mntfh
);
1165 * Translate to nfs_mount_data, which nfs_fill_super
1169 data
->flags
= args
.flags
;
1170 data
->rsize
= args
.rsize
;
1171 data
->wsize
= args
.wsize
;
1172 data
->timeo
= args
.timeo
;
1173 data
->retrans
= args
.retrans
;
1174 data
->acregmin
= args
.acregmin
;
1175 data
->acregmax
= args
.acregmax
;
1176 data
->acdirmin
= args
.acdirmin
;
1177 data
->acdirmax
= args
.acdirmax
;
1178 data
->addr
= args
.nfs_server
.address
;
1179 data
->namlen
= args
.namlen
;
1180 data
->bsize
= args
.bsize
;
1181 data
->pseudoflavor
= args
.auth_flavors
[0];
1187 if (!(data
->flags
& NFS_MOUNT_SECFLAVOUR
))
1188 data
->pseudoflavor
= RPC_AUTH_UNIX
;
1190 #ifndef CONFIG_NFS_V3
1191 if (data
->flags
& NFS_MOUNT_VER3
)
1192 goto out_v3_not_compiled
;
1193 #endif /* !CONFIG_NFS_V3 */
1195 if (!nfs_verify_server_address((struct sockaddr
*) &data
->addr
))
1196 goto out_no_address
;
1201 dfprintk(MOUNT
, "NFS: mount program didn't pass any mount data\n");
1205 dfprintk(MOUNT
, "NFS: nfs_mount_data version %d does not support v3\n",
1210 dfprintk(MOUNT
, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1213 #ifndef CONFIG_NFS_V3
1214 out_v3_not_compiled
:
1215 dfprintk(MOUNT
, "NFS: NFSv3 is not compiled into kernel\n");
1216 return -EPROTONOSUPPORT
;
1217 #endif /* !CONFIG_NFS_V3 */
1220 dfprintk(MOUNT
, "NFS: mount program didn't pass remote address\n");
1224 dfprintk(MOUNT
, "NFS: invalid root filehandle\n");
1229 * Initialise the common bits of the superblock
1231 static inline void nfs_initialise_sb(struct super_block
*sb
)
1233 struct nfs_server
*server
= NFS_SB(sb
);
1235 sb
->s_magic
= NFS_SUPER_MAGIC
;
1237 /* We probably want something more informative here */
1238 snprintf(sb
->s_id
, sizeof(sb
->s_id
),
1239 "%x:%x", MAJOR(sb
->s_dev
), MINOR(sb
->s_dev
));
1241 if (sb
->s_blocksize
== 0)
1242 sb
->s_blocksize
= nfs_block_bits(server
->wsize
,
1243 &sb
->s_blocksize_bits
);
1245 if (server
->flags
& NFS_MOUNT_NOAC
)
1246 sb
->s_flags
|= MS_SYNCHRONOUS
;
1248 nfs_super_set_maxbytes(sb
, server
->maxfilesize
);
1252 * Finish setting up an NFS2/3 superblock
1254 static void nfs_fill_super(struct super_block
*sb
, struct nfs_mount_data
*data
)
1256 struct nfs_server
*server
= NFS_SB(sb
);
1258 sb
->s_blocksize_bits
= 0;
1259 sb
->s_blocksize
= 0;
1261 sb
->s_blocksize
= nfs_block_size(data
->bsize
, &sb
->s_blocksize_bits
);
1263 if (server
->flags
& NFS_MOUNT_VER3
) {
1264 /* The VFS shouldn't apply the umask to mode bits. We will do
1265 * so ourselves when necessary.
1267 sb
->s_flags
|= MS_POSIXACL
;
1268 sb
->s_time_gran
= 1;
1271 sb
->s_op
= &nfs_sops
;
1272 nfs_initialise_sb(sb
);
1276 * Finish setting up a cloned NFS2/3 superblock
1278 static void nfs_clone_super(struct super_block
*sb
,
1279 const struct super_block
*old_sb
)
1281 struct nfs_server
*server
= NFS_SB(sb
);
1283 sb
->s_blocksize_bits
= old_sb
->s_blocksize_bits
;
1284 sb
->s_blocksize
= old_sb
->s_blocksize
;
1285 sb
->s_maxbytes
= old_sb
->s_maxbytes
;
1287 if (server
->flags
& NFS_MOUNT_VER3
) {
1288 /* The VFS shouldn't apply the umask to mode bits. We will do
1289 * so ourselves when necessary.
1291 sb
->s_flags
|= MS_POSIXACL
;
1292 sb
->s_time_gran
= 1;
1295 sb
->s_op
= old_sb
->s_op
;
1296 nfs_initialise_sb(sb
);
1299 #define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
1301 static int nfs_compare_mount_options(const struct super_block
*s
, const struct nfs_server
*b
, int flags
)
1303 const struct nfs_server
*a
= s
->s_fs_info
;
1304 const struct rpc_clnt
*clnt_a
= a
->client
;
1305 const struct rpc_clnt
*clnt_b
= b
->client
;
1307 if ((s
->s_flags
& NFS_MS_MASK
) != (flags
& NFS_MS_MASK
))
1309 if (a
->nfs_client
!= b
->nfs_client
)
1311 if (a
->flags
!= b
->flags
)
1313 if (a
->wsize
!= b
->wsize
)
1315 if (a
->rsize
!= b
->rsize
)
1317 if (a
->acregmin
!= b
->acregmin
)
1319 if (a
->acregmax
!= b
->acregmax
)
1321 if (a
->acdirmin
!= b
->acdirmin
)
1323 if (a
->acdirmax
!= b
->acdirmax
)
1325 if (clnt_a
->cl_auth
->au_flavor
!= clnt_b
->cl_auth
->au_flavor
)
1332 struct nfs_sb_mountdata
{
1333 struct nfs_server
*server
;
1337 static int nfs_set_super(struct super_block
*s
, void *data
)
1339 struct nfs_sb_mountdata
*sb_mntdata
= data
;
1340 struct nfs_server
*server
= sb_mntdata
->server
;
1343 s
->s_flags
= sb_mntdata
->mntflags
;
1344 s
->s_fs_info
= server
;
1345 ret
= set_anon_super(s
, server
);
1347 server
->s_dev
= s
->s_dev
;
1351 static int nfs_compare_super(struct super_block
*sb
, void *data
)
1353 struct nfs_sb_mountdata
*sb_mntdata
= data
;
1354 struct nfs_server
*server
= sb_mntdata
->server
, *old
= NFS_SB(sb
);
1355 int mntflags
= sb_mntdata
->mntflags
;
1357 if (memcmp(&old
->nfs_client
->cl_addr
,
1358 &server
->nfs_client
->cl_addr
,
1359 sizeof(old
->nfs_client
->cl_addr
)) != 0)
1361 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1362 if (old
->flags
& NFS_MOUNT_UNSHARED
)
1364 if (memcmp(&old
->fsid
, &server
->fsid
, sizeof(old
->fsid
)) != 0)
1366 return nfs_compare_mount_options(sb
, server
, mntflags
);
1369 static int nfs_get_sb(struct file_system_type
*fs_type
,
1370 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
1372 struct nfs_server
*server
= NULL
;
1373 struct super_block
*s
;
1374 struct nfs_fh mntfh
;
1375 struct nfs_mount_data
*data
= raw_data
;
1376 struct dentry
*mntroot
;
1377 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
1378 struct nfs_sb_mountdata sb_mntdata
= {
1383 /* Validate the mount data */
1384 error
= nfs_validate_mount_data(&data
, &mntfh
, dev_name
);
1388 /* Get a volume representation */
1389 server
= nfs_create_server(data
, &mntfh
);
1390 if (IS_ERR(server
)) {
1391 error
= PTR_ERR(server
);
1394 sb_mntdata
.server
= server
;
1396 if (server
->flags
& NFS_MOUNT_UNSHARED
)
1397 compare_super
= NULL
;
1399 /* Get a superblock - note that we may end up sharing one that already exists */
1400 s
= sget(fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
1406 if (s
->s_fs_info
!= server
) {
1407 nfs_free_server(server
);
1412 /* initial superblock/root creation */
1413 nfs_fill_super(s
, data
);
1416 mntroot
= nfs_get_root(s
, &mntfh
);
1417 if (IS_ERR(mntroot
)) {
1418 error
= PTR_ERR(mntroot
);
1419 goto error_splat_super
;
1422 s
->s_flags
|= MS_ACTIVE
;
1424 mnt
->mnt_root
= mntroot
;
1428 if (data
!= raw_data
)
1433 nfs_free_server(server
);
1437 up_write(&s
->s_umount
);
1438 deactivate_super(s
);
1443 * Destroy an NFS2/3 superblock
1445 static void nfs_kill_super(struct super_block
*s
)
1447 struct nfs_server
*server
= NFS_SB(s
);
1450 nfs_free_server(server
);
1454 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
1456 static int nfs_xdev_get_sb(struct file_system_type
*fs_type
, int flags
,
1457 const char *dev_name
, void *raw_data
,
1458 struct vfsmount
*mnt
)
1460 struct nfs_clone_mount
*data
= raw_data
;
1461 struct super_block
*s
;
1462 struct nfs_server
*server
;
1463 struct dentry
*mntroot
;
1464 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
1465 struct nfs_sb_mountdata sb_mntdata
= {
1470 dprintk("--> nfs_xdev_get_sb()\n");
1472 /* create a new volume representation */
1473 server
= nfs_clone_server(NFS_SB(data
->sb
), data
->fh
, data
->fattr
);
1474 if (IS_ERR(server
)) {
1475 error
= PTR_ERR(server
);
1476 goto out_err_noserver
;
1478 sb_mntdata
.server
= server
;
1480 if (server
->flags
& NFS_MOUNT_UNSHARED
)
1481 compare_super
= NULL
;
1483 /* Get a superblock - note that we may end up sharing one that already exists */
1484 s
= sget(&nfs_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
1490 if (s
->s_fs_info
!= server
) {
1491 nfs_free_server(server
);
1496 /* initial superblock/root creation */
1497 nfs_clone_super(s
, data
->sb
);
1500 mntroot
= nfs_get_root(s
, data
->fh
);
1501 if (IS_ERR(mntroot
)) {
1502 error
= PTR_ERR(mntroot
);
1503 goto error_splat_super
;
1506 s
->s_flags
|= MS_ACTIVE
;
1508 mnt
->mnt_root
= mntroot
;
1510 dprintk("<-- nfs_xdev_get_sb() = 0\n");
1514 nfs_free_server(server
);
1516 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error
);
1520 up_write(&s
->s_umount
);
1521 deactivate_super(s
);
1522 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error
);
1526 #ifdef CONFIG_NFS_V4
1529 * Finish setting up a cloned NFS4 superblock
1531 static void nfs4_clone_super(struct super_block
*sb
,
1532 const struct super_block
*old_sb
)
1534 sb
->s_blocksize_bits
= old_sb
->s_blocksize_bits
;
1535 sb
->s_blocksize
= old_sb
->s_blocksize
;
1536 sb
->s_maxbytes
= old_sb
->s_maxbytes
;
1537 sb
->s_time_gran
= 1;
1538 sb
->s_op
= old_sb
->s_op
;
1539 nfs_initialise_sb(sb
);
1543 * Set up an NFS4 superblock
1545 static void nfs4_fill_super(struct super_block
*sb
)
1547 sb
->s_time_gran
= 1;
1548 sb
->s_op
= &nfs4_sops
;
1549 nfs_initialise_sb(sb
);
1553 * Validate NFSv4 mount options
1555 static int nfs4_validate_mount_data(struct nfs4_mount_data
**options
,
1556 const char *dev_name
,
1557 struct sockaddr_in
*addr
,
1558 rpc_authflavor_t
*authflavour
,
1563 struct nfs4_mount_data
*data
= *options
;
1569 switch (data
->version
) {
1571 if (data
->host_addrlen
!= sizeof(*addr
))
1572 goto out_no_address
;
1573 if (copy_from_user(addr
, data
->host_addr
, sizeof(*addr
)))
1575 if (addr
->sin_port
== 0)
1576 addr
->sin_port
= htons(NFS_PORT
);
1577 if (!nfs_verify_server_address((struct sockaddr
*) addr
))
1578 goto out_no_address
;
1580 switch (data
->auth_flavourlen
) {
1582 *authflavour
= RPC_AUTH_UNIX
;
1585 if (copy_from_user(authflavour
, data
->auth_flavours
,
1586 sizeof(*authflavour
)))
1590 goto out_inval_auth
;
1593 c
= strndup_user(data
->hostname
.data
, NFS4_MAXNAMLEN
);
1598 c
= strndup_user(data
->mnt_path
.data
, NFS4_MAXPATHLEN
);
1602 dfprintk(MOUNT
, "NFS: MNTPATH: '%s'\n", *mntpath
);
1604 c
= strndup_user(data
->client_addr
.data
, 16);
1612 struct nfs_parsed_mount_data args
= {
1613 .rsize
= NFS_MAX_FILE_IO_SIZE
,
1614 .wsize
= NFS_MAX_FILE_IO_SIZE
,
1621 .nfs_server
.protocol
= IPPROTO_TCP
,
1624 if (nfs_parse_mount_options((char *) *options
, &args
) == 0)
1627 if (!nfs_verify_server_address((struct sockaddr
*)
1628 &args
.nfs_server
.address
))
1630 *addr
= args
.nfs_server
.address
;
1632 switch (args
.auth_flavor_len
) {
1634 *authflavour
= RPC_AUTH_UNIX
;
1637 *authflavour
= (rpc_authflavor_t
) args
.auth_flavors
[0];
1640 goto out_inval_auth
;
1644 * Translate to nfs4_mount_data, which nfs4_fill_super
1647 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
1653 data
->flags
= args
.flags
& NFS4_MOUNT_FLAGMASK
;
1654 data
->rsize
= args
.rsize
;
1655 data
->wsize
= args
.wsize
;
1656 data
->timeo
= args
.timeo
;
1657 data
->retrans
= args
.retrans
;
1658 data
->acregmin
= args
.acregmin
;
1659 data
->acregmax
= args
.acregmax
;
1660 data
->acdirmin
= args
.acdirmin
;
1661 data
->acdirmax
= args
.acdirmax
;
1662 data
->proto
= args
.nfs_server
.protocol
;
1665 * Split "dev_name" into "hostname:mntpath".
1667 c
= strchr(dev_name
, ':');
1670 /* while calculating len, pretend ':' is '\0' */
1672 if (len
> NFS4_MAXNAMLEN
)
1673 return -ENAMETOOLONG
;
1674 *hostname
= kzalloc(len
, GFP_KERNEL
);
1675 if (*hostname
== NULL
)
1677 strncpy(*hostname
, dev_name
, len
- 1);
1679 c
++; /* step over the ':' */
1681 if (len
> NFS4_MAXPATHLEN
)
1682 return -ENAMETOOLONG
;
1683 *mntpath
= kzalloc(len
+ 1, GFP_KERNEL
);
1684 if (*mntpath
== NULL
)
1686 strncpy(*mntpath
, c
, len
);
1688 dprintk("MNTPATH: %s\n", *mntpath
);
1690 if (args
.client_address
== NULL
)
1691 goto out_no_client_address
;
1693 *ip_addr
= args
.client_address
;
1702 dfprintk(MOUNT
, "NFS4: mount program didn't pass any mount data\n");
1706 dfprintk(MOUNT
, "NFS4: Invalid number of RPC auth flavours %d\n",
1707 data
->auth_flavourlen
);
1711 dfprintk(MOUNT
, "NFS4: mount program didn't pass remote address\n");
1714 out_no_client_address
:
1715 dfprintk(MOUNT
, "NFS4: mount program didn't pass callback address\n");
1720 * Get the superblock for an NFS4 mountpoint
1722 static int nfs4_get_sb(struct file_system_type
*fs_type
,
1723 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
1725 struct nfs4_mount_data
*data
= raw_data
;
1726 struct super_block
*s
;
1727 struct nfs_server
*server
;
1728 struct sockaddr_in addr
;
1729 rpc_authflavor_t authflavour
;
1730 struct nfs_fh mntfh
;
1731 struct dentry
*mntroot
;
1732 char *mntpath
= NULL
, *hostname
= NULL
, *ip_addr
= NULL
;
1733 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
1734 struct nfs_sb_mountdata sb_mntdata
= {
1739 /* Validate the mount data */
1740 error
= nfs4_validate_mount_data(&data
, dev_name
, &addr
, &authflavour
,
1741 &hostname
, &mntpath
, &ip_addr
);
1745 /* Get a volume representation */
1746 server
= nfs4_create_server(data
, hostname
, &addr
, mntpath
, ip_addr
,
1747 authflavour
, &mntfh
);
1748 if (IS_ERR(server
)) {
1749 error
= PTR_ERR(server
);
1752 sb_mntdata
.server
= server
;
1754 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
1755 compare_super
= NULL
;
1757 /* Get a superblock - note that we may end up sharing one that already exists */
1758 s
= sget(fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
1764 if (s
->s_fs_info
!= server
) {
1765 nfs_free_server(server
);
1770 /* initial superblock/root creation */
1774 mntroot
= nfs4_get_root(s
, &mntfh
);
1775 if (IS_ERR(mntroot
)) {
1776 error
= PTR_ERR(mntroot
);
1777 goto error_splat_super
;
1780 s
->s_flags
|= MS_ACTIVE
;
1782 mnt
->mnt_root
= mntroot
;
1792 nfs_free_server(server
);
1796 up_write(&s
->s_umount
);
1797 deactivate_super(s
);
1801 static void nfs4_kill_super(struct super_block
*sb
)
1803 struct nfs_server
*server
= NFS_SB(sb
);
1805 nfs_return_all_delegations(sb
);
1806 kill_anon_super(sb
);
1808 nfs4_renewd_prepare_shutdown(server
);
1809 nfs_free_server(server
);
1813 * Clone an NFS4 server record on xdev traversal (FSID-change)
1815 static int nfs4_xdev_get_sb(struct file_system_type
*fs_type
, int flags
,
1816 const char *dev_name
, void *raw_data
,
1817 struct vfsmount
*mnt
)
1819 struct nfs_clone_mount
*data
= raw_data
;
1820 struct super_block
*s
;
1821 struct nfs_server
*server
;
1822 struct dentry
*mntroot
;
1823 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
1824 struct nfs_sb_mountdata sb_mntdata
= {
1829 dprintk("--> nfs4_xdev_get_sb()\n");
1831 /* create a new volume representation */
1832 server
= nfs_clone_server(NFS_SB(data
->sb
), data
->fh
, data
->fattr
);
1833 if (IS_ERR(server
)) {
1834 error
= PTR_ERR(server
);
1835 goto out_err_noserver
;
1837 sb_mntdata
.server
= server
;
1839 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
1840 compare_super
= NULL
;
1842 /* Get a superblock - note that we may end up sharing one that already exists */
1843 s
= sget(&nfs_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
1849 if (s
->s_fs_info
!= server
) {
1850 nfs_free_server(server
);
1855 /* initial superblock/root creation */
1856 nfs4_clone_super(s
, data
->sb
);
1859 mntroot
= nfs4_get_root(s
, data
->fh
);
1860 if (IS_ERR(mntroot
)) {
1861 error
= PTR_ERR(mntroot
);
1862 goto error_splat_super
;
1865 s
->s_flags
|= MS_ACTIVE
;
1867 mnt
->mnt_root
= mntroot
;
1869 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
1873 nfs_free_server(server
);
1875 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error
);
1879 up_write(&s
->s_umount
);
1880 deactivate_super(s
);
1881 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error
);
1886 * Create an NFS4 server record on referral traversal
1888 static int nfs4_referral_get_sb(struct file_system_type
*fs_type
, int flags
,
1889 const char *dev_name
, void *raw_data
,
1890 struct vfsmount
*mnt
)
1892 struct nfs_clone_mount
*data
= raw_data
;
1893 struct super_block
*s
;
1894 struct nfs_server
*server
;
1895 struct dentry
*mntroot
;
1896 struct nfs_fh mntfh
;
1897 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
1898 struct nfs_sb_mountdata sb_mntdata
= {
1903 dprintk("--> nfs4_referral_get_sb()\n");
1905 /* create a new volume representation */
1906 server
= nfs4_create_referral_server(data
, &mntfh
);
1907 if (IS_ERR(server
)) {
1908 error
= PTR_ERR(server
);
1909 goto out_err_noserver
;
1911 sb_mntdata
.server
= server
;
1913 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
1914 compare_super
= NULL
;
1916 /* Get a superblock - note that we may end up sharing one that already exists */
1917 s
= sget(&nfs_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
1923 if (s
->s_fs_info
!= server
) {
1924 nfs_free_server(server
);
1929 /* initial superblock/root creation */
1933 mntroot
= nfs4_get_root(s
, &mntfh
);
1934 if (IS_ERR(mntroot
)) {
1935 error
= PTR_ERR(mntroot
);
1936 goto error_splat_super
;
1939 s
->s_flags
|= MS_ACTIVE
;
1941 mnt
->mnt_root
= mntroot
;
1943 dprintk("<-- nfs4_referral_get_sb() = 0\n");
1947 nfs_free_server(server
);
1949 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error
);
1953 up_write(&s
->s_umount
);
1954 deactivate_super(s
);
1955 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error
);
1959 #endif /* CONFIG_NFS_V4 */