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
;
83 struct sockaddr_in address
;
92 /* Mount options that take no arguments */
95 Opt_posix
, Opt_noposix
,
102 Opt_rdirplus
, Opt_nordirplus
,
103 Opt_sharecache
, Opt_nosharecache
,
105 /* Mount options that take integer arguments */
107 Opt_rsize
, Opt_wsize
, Opt_bsize
,
108 Opt_timeo
, Opt_retrans
,
109 Opt_acregmin
, Opt_acregmax
,
110 Opt_acdirmin
, Opt_acdirmax
,
114 Opt_mountprog
, Opt_mountvers
,
115 Opt_nfsprog
, Opt_nfsvers
,
117 /* Mount options that take string arguments */
118 Opt_sec
, Opt_proto
, Opt_mountproto
,
119 Opt_addr
, Opt_mounthost
, Opt_clientaddr
,
121 /* Mount options that are ignored */
122 Opt_userspace
, Opt_deprecated
,
127 static match_table_t nfs_mount_option_tokens
= {
128 { Opt_userspace
, "bg" },
129 { Opt_userspace
, "fg" },
130 { Opt_soft
, "soft" },
131 { Opt_hard
, "hard" },
132 { Opt_intr
, "intr" },
133 { Opt_nointr
, "nointr" },
134 { Opt_posix
, "posix" },
135 { Opt_noposix
, "noposix" },
137 { Opt_nocto
, "nocto" },
139 { Opt_noac
, "noac" },
140 { Opt_lock
, "lock" },
141 { Opt_nolock
, "nolock" },
147 { Opt_noacl
, "noacl" },
148 { Opt_rdirplus
, "rdirplus" },
149 { Opt_nordirplus
, "nordirplus" },
150 { Opt_sharecache
, "sharecache" },
151 { Opt_nosharecache
, "nosharecache" },
153 { Opt_port
, "port=%u" },
154 { Opt_rsize
, "rsize=%u" },
155 { Opt_wsize
, "wsize=%u" },
156 { Opt_bsize
, "bsize=%u" },
157 { Opt_timeo
, "timeo=%u" },
158 { Opt_retrans
, "retrans=%u" },
159 { Opt_acregmin
, "acregmin=%u" },
160 { Opt_acregmax
, "acregmax=%u" },
161 { Opt_acdirmin
, "acdirmin=%u" },
162 { Opt_acdirmax
, "acdirmax=%u" },
163 { Opt_actimeo
, "actimeo=%u" },
164 { Opt_userspace
, "retry=%u" },
165 { Opt_namelen
, "namlen=%u" },
166 { Opt_mountport
, "mountport=%u" },
167 { Opt_mountprog
, "mountprog=%u" },
168 { Opt_mountvers
, "mountvers=%u" },
169 { Opt_nfsprog
, "nfsprog=%u" },
170 { Opt_nfsvers
, "nfsvers=%u" },
171 { Opt_nfsvers
, "vers=%u" },
173 { Opt_sec
, "sec=%s" },
174 { Opt_proto
, "proto=%s" },
175 { Opt_mountproto
, "mountproto=%s" },
176 { Opt_addr
, "addr=%s" },
177 { Opt_clientaddr
, "clientaddr=%s" },
178 { Opt_mounthost
, "mounthost=%s" },
184 Opt_xprt_udp
, Opt_xprt_tcp
,
189 static match_table_t nfs_xprt_protocol_tokens
= {
190 { Opt_xprt_udp
, "udp" },
191 { Opt_xprt_tcp
, "tcp" },
193 { Opt_xprt_err
, NULL
}
197 Opt_sec_none
, Opt_sec_sys
,
198 Opt_sec_krb5
, Opt_sec_krb5i
, Opt_sec_krb5p
,
199 Opt_sec_lkey
, Opt_sec_lkeyi
, Opt_sec_lkeyp
,
200 Opt_sec_spkm
, Opt_sec_spkmi
, Opt_sec_spkmp
,
205 static match_table_t nfs_secflavor_tokens
= {
206 { Opt_sec_none
, "none" },
207 { Opt_sec_none
, "null" },
208 { Opt_sec_sys
, "sys" },
210 { Opt_sec_krb5
, "krb5" },
211 { Opt_sec_krb5i
, "krb5i" },
212 { Opt_sec_krb5p
, "krb5p" },
214 { Opt_sec_lkey
, "lkey" },
215 { Opt_sec_lkeyi
, "lkeyi" },
216 { Opt_sec_lkeyp
, "lkeyp" },
218 { Opt_sec_err
, NULL
}
222 static void nfs_umount_begin(struct vfsmount
*, int);
223 static int nfs_statfs(struct dentry
*, struct kstatfs
*);
224 static int nfs_show_options(struct seq_file
*, struct vfsmount
*);
225 static int nfs_show_stats(struct seq_file
*, struct vfsmount
*);
226 static int nfs_get_sb(struct file_system_type
*, int, const char *, void *, struct vfsmount
*);
227 static int nfs_xdev_get_sb(struct file_system_type
*fs_type
,
228 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
229 static void nfs_kill_super(struct super_block
*);
231 static struct file_system_type nfs_fs_type
= {
232 .owner
= THIS_MODULE
,
234 .get_sb
= nfs_get_sb
,
235 .kill_sb
= nfs_kill_super
,
236 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
239 struct file_system_type nfs_xdev_fs_type
= {
240 .owner
= THIS_MODULE
,
242 .get_sb
= nfs_xdev_get_sb
,
243 .kill_sb
= nfs_kill_super
,
244 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
247 static const struct super_operations nfs_sops
= {
248 .alloc_inode
= nfs_alloc_inode
,
249 .destroy_inode
= nfs_destroy_inode
,
250 .write_inode
= nfs_write_inode
,
251 .statfs
= nfs_statfs
,
252 .clear_inode
= nfs_clear_inode
,
253 .umount_begin
= nfs_umount_begin
,
254 .show_options
= nfs_show_options
,
255 .show_stats
= nfs_show_stats
,
259 static int nfs4_get_sb(struct file_system_type
*fs_type
,
260 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
261 static int nfs4_xdev_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_referral_get_sb(struct file_system_type
*fs_type
,
264 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
265 static void nfs4_kill_super(struct super_block
*sb
);
267 static struct file_system_type nfs4_fs_type
= {
268 .owner
= THIS_MODULE
,
270 .get_sb
= nfs4_get_sb
,
271 .kill_sb
= nfs4_kill_super
,
272 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
275 struct file_system_type nfs4_xdev_fs_type
= {
276 .owner
= THIS_MODULE
,
278 .get_sb
= nfs4_xdev_get_sb
,
279 .kill_sb
= nfs4_kill_super
,
280 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
283 struct file_system_type nfs4_referral_fs_type
= {
284 .owner
= THIS_MODULE
,
286 .get_sb
= nfs4_referral_get_sb
,
287 .kill_sb
= nfs4_kill_super
,
288 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
291 static const struct super_operations nfs4_sops
= {
292 .alloc_inode
= nfs_alloc_inode
,
293 .destroy_inode
= nfs_destroy_inode
,
294 .write_inode
= nfs_write_inode
,
295 .statfs
= nfs_statfs
,
296 .clear_inode
= nfs4_clear_inode
,
297 .umount_begin
= nfs_umount_begin
,
298 .show_options
= nfs_show_options
,
299 .show_stats
= nfs_show_stats
,
303 static struct shrinker acl_shrinker
= {
304 .shrink
= nfs_access_cache_shrinker
,
305 .seeks
= DEFAULT_SEEKS
,
309 * Register the NFS filesystems
311 int __init
register_nfs_fs(void)
315 ret
= register_filesystem(&nfs_fs_type
);
319 ret
= nfs_register_sysctl();
323 ret
= register_filesystem(&nfs4_fs_type
);
327 register_shrinker(&acl_shrinker
);
332 nfs_unregister_sysctl();
335 unregister_filesystem(&nfs_fs_type
);
341 * Unregister the NFS filesystems
343 void __exit
unregister_nfs_fs(void)
345 unregister_shrinker(&acl_shrinker
);
347 unregister_filesystem(&nfs4_fs_type
);
349 nfs_unregister_sysctl();
350 unregister_filesystem(&nfs_fs_type
);
354 * Deliver file system statistics to userspace
356 static int nfs_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
358 struct nfs_server
*server
= NFS_SB(dentry
->d_sb
);
359 unsigned char blockbits
;
360 unsigned long blockres
;
361 struct nfs_fh
*fh
= NFS_FH(dentry
->d_inode
);
362 struct nfs_fattr fattr
;
363 struct nfs_fsstat res
= {
370 error
= server
->nfs_client
->rpc_ops
->statfs(server
, fh
, &res
);
373 buf
->f_type
= NFS_SUPER_MAGIC
;
376 * Current versions of glibc do not correctly handle the
377 * case where f_frsize != f_bsize. Eventually we want to
378 * report the value of wtmult in this field.
380 buf
->f_frsize
= dentry
->d_sb
->s_blocksize
;
383 * On most *nix systems, f_blocks, f_bfree, and f_bavail
384 * are reported in units of f_frsize. Linux hasn't had
385 * an f_frsize field in its statfs struct until recently,
386 * thus historically Linux's sys_statfs reports these
387 * fields in units of f_bsize.
389 buf
->f_bsize
= dentry
->d_sb
->s_blocksize
;
390 blockbits
= dentry
->d_sb
->s_blocksize_bits
;
391 blockres
= (1 << blockbits
) - 1;
392 buf
->f_blocks
= (res
.tbytes
+ blockres
) >> blockbits
;
393 buf
->f_bfree
= (res
.fbytes
+ blockres
) >> blockbits
;
394 buf
->f_bavail
= (res
.abytes
+ blockres
) >> blockbits
;
396 buf
->f_files
= res
.tfiles
;
397 buf
->f_ffree
= res
.afiles
;
399 buf
->f_namelen
= server
->namelen
;
405 dprintk("%s: statfs error = %d\n", __FUNCTION__
, -error
);
411 * Map the security flavour number to a name
413 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour
)
415 static const struct {
416 rpc_authflavor_t flavour
;
419 { RPC_AUTH_NULL
, "null" },
420 { RPC_AUTH_UNIX
, "sys" },
421 { RPC_AUTH_GSS_KRB5
, "krb5" },
422 { RPC_AUTH_GSS_KRB5I
, "krb5i" },
423 { RPC_AUTH_GSS_KRB5P
, "krb5p" },
424 { RPC_AUTH_GSS_LKEY
, "lkey" },
425 { RPC_AUTH_GSS_LKEYI
, "lkeyi" },
426 { RPC_AUTH_GSS_LKEYP
, "lkeyp" },
427 { RPC_AUTH_GSS_SPKM
, "spkm" },
428 { RPC_AUTH_GSS_SPKMI
, "spkmi" },
429 { RPC_AUTH_GSS_SPKMP
, "spkmp" },
430 { UINT_MAX
, "unknown" }
434 for (i
= 0; sec_flavours
[i
].flavour
!= UINT_MAX
; i
++) {
435 if (sec_flavours
[i
].flavour
== flavour
)
438 return sec_flavours
[i
].str
;
442 * Describe the mount options in force on this server representation
444 static void nfs_show_mount_options(struct seq_file
*m
, struct nfs_server
*nfss
, int showdefaults
)
446 static const struct proc_nfs_info
{
451 { NFS_MOUNT_SOFT
, ",soft", ",hard" },
452 { NFS_MOUNT_INTR
, ",intr", "" },
453 { NFS_MOUNT_NOCTO
, ",nocto", "" },
454 { NFS_MOUNT_NOAC
, ",noac", "" },
455 { NFS_MOUNT_NONLM
, ",nolock", "" },
456 { NFS_MOUNT_NOACL
, ",noacl", "" },
457 { NFS_MOUNT_NORDIRPLUS
, ",nordirplus", "" },
458 { NFS_MOUNT_UNSHARED
, ",nosharecache", ""},
461 const struct proc_nfs_info
*nfs_infop
;
462 struct nfs_client
*clp
= nfss
->nfs_client
;
466 seq_printf(m
, ",vers=%d", clp
->rpc_ops
->version
);
467 seq_printf(m
, ",rsize=%d", nfss
->rsize
);
468 seq_printf(m
, ",wsize=%d", nfss
->wsize
);
469 if (nfss
->acregmin
!= 3*HZ
|| showdefaults
)
470 seq_printf(m
, ",acregmin=%d", nfss
->acregmin
/HZ
);
471 if (nfss
->acregmax
!= 60*HZ
|| showdefaults
)
472 seq_printf(m
, ",acregmax=%d", nfss
->acregmax
/HZ
);
473 if (nfss
->acdirmin
!= 30*HZ
|| showdefaults
)
474 seq_printf(m
, ",acdirmin=%d", nfss
->acdirmin
/HZ
);
475 if (nfss
->acdirmax
!= 60*HZ
|| showdefaults
)
476 seq_printf(m
, ",acdirmax=%d", nfss
->acdirmax
/HZ
);
477 for (nfs_infop
= nfs_info
; nfs_infop
->flag
; nfs_infop
++) {
478 if (nfss
->flags
& nfs_infop
->flag
)
479 seq_puts(m
, nfs_infop
->str
);
481 seq_puts(m
, nfs_infop
->nostr
);
483 switch (nfss
->client
->cl_xprt
->prot
) {
491 snprintf(buf
, sizeof(buf
), "%u", nfss
->client
->cl_xprt
->prot
);
494 seq_printf(m
, ",proto=%s", proto
);
495 seq_printf(m
, ",timeo=%lu", 10U * clp
->retrans_timeo
/ HZ
);
496 seq_printf(m
, ",retrans=%u", clp
->retrans_count
);
497 seq_printf(m
, ",sec=%s", nfs_pseudoflavour_to_name(nfss
->client
->cl_auth
->au_flavor
));
501 * Describe the mount options on this VFS mountpoint
503 static int nfs_show_options(struct seq_file
*m
, struct vfsmount
*mnt
)
505 struct nfs_server
*nfss
= NFS_SB(mnt
->mnt_sb
);
507 nfs_show_mount_options(m
, nfss
, 0);
509 seq_puts(m
, ",addr=");
510 seq_escape(m
, nfss
->nfs_client
->cl_hostname
, " \t\n\\");
516 * Present statistical information for this VFS mountpoint
518 static int nfs_show_stats(struct seq_file
*m
, struct vfsmount
*mnt
)
521 struct nfs_server
*nfss
= NFS_SB(mnt
->mnt_sb
);
522 struct rpc_auth
*auth
= nfss
->client
->cl_auth
;
523 struct nfs_iostats totals
= { };
525 seq_printf(m
, "statvers=%s", NFS_IOSTAT_VERS
);
528 * Display all mount option settings
530 seq_printf(m
, "\n\topts:\t");
531 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_RDONLY
? "ro" : "rw");
532 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_SYNCHRONOUS
? ",sync" : "");
533 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_NOATIME
? ",noatime" : "");
534 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_NODIRATIME
? ",nodiratime" : "");
535 nfs_show_mount_options(m
, nfss
, 1);
537 seq_printf(m
, "\n\tage:\t%lu", (jiffies
- nfss
->mount_time
) / HZ
);
539 seq_printf(m
, "\n\tcaps:\t");
540 seq_printf(m
, "caps=0x%x", nfss
->caps
);
541 seq_printf(m
, ",wtmult=%d", nfss
->wtmult
);
542 seq_printf(m
, ",dtsize=%d", nfss
->dtsize
);
543 seq_printf(m
, ",bsize=%d", nfss
->bsize
);
544 seq_printf(m
, ",namelen=%d", nfss
->namelen
);
547 if (nfss
->nfs_client
->cl_nfsversion
== 4) {
548 seq_printf(m
, "\n\tnfsv4:\t");
549 seq_printf(m
, "bm0=0x%x", nfss
->attr_bitmask
[0]);
550 seq_printf(m
, ",bm1=0x%x", nfss
->attr_bitmask
[1]);
551 seq_printf(m
, ",acl=0x%x", nfss
->acl_bitmask
);
556 * Display security flavor in effect for this mount
558 seq_printf(m
, "\n\tsec:\tflavor=%d", auth
->au_ops
->au_flavor
);
560 seq_printf(m
, ",pseudoflavor=%d", auth
->au_flavor
);
563 * Display superblock I/O counters
565 for_each_possible_cpu(cpu
) {
566 struct nfs_iostats
*stats
;
569 stats
= per_cpu_ptr(nfss
->io_stats
, cpu
);
571 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
572 totals
.events
[i
] += stats
->events
[i
];
573 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
574 totals
.bytes
[i
] += stats
->bytes
[i
];
579 seq_printf(m
, "\n\tevents:\t");
580 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
581 seq_printf(m
, "%lu ", totals
.events
[i
]);
582 seq_printf(m
, "\n\tbytes:\t");
583 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
584 seq_printf(m
, "%Lu ", totals
.bytes
[i
]);
587 rpc_print_iostats(m
, nfss
->client
);
593 * Begin unmount by attempting to remove all automounted mountpoints we added
594 * in response to xdev traversals and referrals
596 static void nfs_umount_begin(struct vfsmount
*vfsmnt
, int flags
)
598 struct nfs_server
*server
= NFS_SB(vfsmnt
->mnt_sb
);
599 struct rpc_clnt
*rpc
;
601 shrink_submounts(vfsmnt
, &nfs_automount_list
);
603 if (!(flags
& MNT_FORCE
))
605 /* -EIO all pending I/O */
606 rpc
= server
->client_acl
;
608 rpc_killall_tasks(rpc
);
609 rpc
= server
->client
;
611 rpc_killall_tasks(rpc
);
615 * Sanity-check a server address provided by the mount command
617 static int nfs_verify_server_address(struct sockaddr
*addr
)
619 switch (addr
->sa_family
) {
621 struct sockaddr_in
*sa
= (struct sockaddr_in
*) addr
;
622 if (sa
->sin_addr
.s_addr
!= INADDR_ANY
)
632 * Error-check and convert a string of mount options from user space into
635 static int nfs_parse_mount_options(char *raw
,
636 struct nfs_parsed_mount_data
*mnt
)
641 dfprintk(MOUNT
, "NFS: mount options string was NULL.\n");
644 dfprintk(MOUNT
, "NFS: nfs mount opts='%s'\n", raw
);
646 while ((p
= strsep(&raw
, ",")) != NULL
) {
647 substring_t args
[MAX_OPT_ARGS
];
653 dfprintk(MOUNT
, "NFS: parsing nfs mount option '%s'\n", p
);
655 token
= match_token(p
, nfs_mount_option_tokens
, args
);
658 mnt
->flags
|= NFS_MOUNT_SOFT
;
661 mnt
->flags
&= ~NFS_MOUNT_SOFT
;
664 mnt
->flags
|= NFS_MOUNT_INTR
;
667 mnt
->flags
&= ~NFS_MOUNT_INTR
;
670 mnt
->flags
|= NFS_MOUNT_POSIX
;
673 mnt
->flags
&= ~NFS_MOUNT_POSIX
;
676 mnt
->flags
&= ~NFS_MOUNT_NOCTO
;
679 mnt
->flags
|= NFS_MOUNT_NOCTO
;
682 mnt
->flags
&= ~NFS_MOUNT_NOAC
;
685 mnt
->flags
|= NFS_MOUNT_NOAC
;
688 mnt
->flags
&= ~NFS_MOUNT_NONLM
;
691 mnt
->flags
|= NFS_MOUNT_NONLM
;
694 mnt
->flags
&= ~NFS_MOUNT_VER3
;
697 mnt
->flags
|= NFS_MOUNT_VER3
;
700 mnt
->flags
&= ~NFS_MOUNT_TCP
;
701 mnt
->nfs_server
.protocol
= IPPROTO_UDP
;
706 mnt
->flags
|= NFS_MOUNT_TCP
;
707 mnt
->nfs_server
.protocol
= IPPROTO_TCP
;
712 mnt
->flags
&= ~NFS_MOUNT_NOACL
;
715 mnt
->flags
|= NFS_MOUNT_NOACL
;
718 mnt
->flags
&= ~NFS_MOUNT_NORDIRPLUS
;
721 mnt
->flags
|= NFS_MOUNT_NORDIRPLUS
;
724 mnt
->flags
&= ~NFS_MOUNT_UNSHARED
;
726 case Opt_nosharecache
:
727 mnt
->flags
|= NFS_MOUNT_UNSHARED
;
731 if (match_int(args
, &option
))
733 if (option
< 0 || option
> 65535)
735 mnt
->nfs_server
.address
.sin_port
= htons(option
);
738 if (match_int(args
, &mnt
->rsize
))
742 if (match_int(args
, &mnt
->wsize
))
746 if (match_int(args
, &option
))
753 if (match_int(args
, &mnt
->timeo
))
757 if (match_int(args
, &mnt
->retrans
))
761 if (match_int(args
, &mnt
->acregmin
))
765 if (match_int(args
, &mnt
->acregmax
))
769 if (match_int(args
, &mnt
->acdirmin
))
773 if (match_int(args
, &mnt
->acdirmax
))
777 if (match_int(args
, &option
))
784 mnt
->acdirmax
= option
;
787 if (match_int(args
, &mnt
->namlen
))
791 if (match_int(args
, &option
))
793 if (option
< 0 || option
> 65535)
795 mnt
->mount_server
.port
= option
;
798 if (match_int(args
, &option
))
802 mnt
->mount_server
.program
= option
;
805 if (match_int(args
, &option
))
809 mnt
->mount_server
.version
= option
;
812 if (match_int(args
, &option
))
816 mnt
->nfs_server
.program
= option
;
819 if (match_int(args
, &option
))
823 mnt
->flags
&= ~NFS_MOUNT_VER3
;
826 mnt
->flags
|= NFS_MOUNT_VER3
;
834 string
= match_strdup(args
);
837 token
= match_token(string
, nfs_secflavor_tokens
, args
);
841 * The flags setting is for v2/v3. The flavor_len
842 * setting is for v4. v2/v3 also need to know the
843 * difference between NULL and UNIX.
847 mnt
->flags
&= ~NFS_MOUNT_SECFLAVOUR
;
848 mnt
->auth_flavor_len
= 0;
849 mnt
->auth_flavors
[0] = RPC_AUTH_NULL
;
852 mnt
->flags
&= ~NFS_MOUNT_SECFLAVOUR
;
853 mnt
->auth_flavor_len
= 0;
854 mnt
->auth_flavors
[0] = RPC_AUTH_UNIX
;
857 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
858 mnt
->auth_flavor_len
= 1;
859 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5
;
862 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
863 mnt
->auth_flavor_len
= 1;
864 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5I
;
867 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
868 mnt
->auth_flavor_len
= 1;
869 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5P
;
872 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
873 mnt
->auth_flavor_len
= 1;
874 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEY
;
877 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
878 mnt
->auth_flavor_len
= 1;
879 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEYI
;
882 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
883 mnt
->auth_flavor_len
= 1;
884 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEYP
;
887 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
888 mnt
->auth_flavor_len
= 1;
889 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKM
;
892 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
893 mnt
->auth_flavor_len
= 1;
894 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKMI
;
897 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
898 mnt
->auth_flavor_len
= 1;
899 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKMP
;
906 string
= match_strdup(args
);
909 token
= match_token(string
,
910 nfs_xprt_protocol_tokens
, args
);
915 mnt
->flags
&= ~NFS_MOUNT_TCP
;
916 mnt
->nfs_server
.protocol
= IPPROTO_UDP
;
921 mnt
->flags
|= NFS_MOUNT_TCP
;
922 mnt
->nfs_server
.protocol
= IPPROTO_TCP
;
931 string
= match_strdup(args
);
934 token
= match_token(string
,
935 nfs_xprt_protocol_tokens
, args
);
940 mnt
->mount_server
.protocol
= IPPROTO_UDP
;
943 mnt
->mount_server
.protocol
= IPPROTO_TCP
;
950 string
= match_strdup(args
);
953 mnt
->nfs_server
.address
.sin_family
= AF_INET
;
954 mnt
->nfs_server
.address
.sin_addr
.s_addr
=
959 string
= match_strdup(args
);
962 mnt
->client_address
= string
;
965 string
= match_strdup(args
);
968 mnt
->mount_server
.address
.sin_family
= AF_INET
;
969 mnt
->mount_server
.address
.sin_addr
.s_addr
=
986 printk(KERN_INFO
"NFS: not enough memory to parse option\n");
990 printk(KERN_INFO
"NFS: unrecognized NFS version number\n");
994 printk(KERN_INFO
"NFS: unrecognized transport protocol\n");
998 printk(KERN_INFO
"NFS: unrecognized security flavor\n");
1002 printk(KERN_INFO
"NFS: unknown mount option: %s\n", p
);
1007 * Use the remote server's MOUNT service to request the NFS file handle
1008 * corresponding to the provided path.
1010 static int nfs_try_mount(struct nfs_parsed_mount_data
*args
,
1011 struct nfs_fh
*root_fh
)
1013 struct sockaddr_in sin
;
1016 if (args
->mount_server
.version
== 0) {
1017 if (args
->flags
& NFS_MOUNT_VER3
)
1018 args
->mount_server
.version
= NFS_MNT3_VERSION
;
1020 args
->mount_server
.version
= NFS_MNT_VERSION
;
1024 * Construct the mount server's address.
1026 if (args
->mount_server
.address
.sin_addr
.s_addr
!= INADDR_ANY
)
1027 sin
= args
->mount_server
.address
;
1029 sin
= args
->nfs_server
.address
;
1030 if (args
->mount_server
.port
== 0) {
1031 status
= rpcb_getport_sync(&sin
,
1032 args
->mount_server
.program
,
1033 args
->mount_server
.version
,
1034 args
->mount_server
.protocol
);
1037 sin
.sin_port
= htons(status
);
1039 sin
.sin_port
= htons(args
->mount_server
.port
);
1042 * Now ask the mount server to map our export path
1045 status
= nfs_mount((struct sockaddr
*) &sin
,
1047 args
->nfs_server
.hostname
,
1048 args
->nfs_server
.export_path
,
1049 args
->mount_server
.version
,
1050 args
->mount_server
.protocol
,
1058 dfprintk(MOUNT
, "NFS: unable to contact server on host "
1059 NIPQUAD_FMT
"\n", NIPQUAD(sin
.sin_addr
.s_addr
));
1064 * Validate the NFS2/NFS3 mount data
1065 * - fills in the mount root filehandle
1067 * For option strings, user space handles the following behaviors:
1069 * + DNS: mapping server host name to IP address ("addr=" option)
1071 * + failure mode: how to behave if a mount request can't be handled
1072 * immediately ("fg/bg" option)
1074 * + retry: how often to retry a mount request ("retry=" option)
1076 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1077 * mountproto=tcp after mountproto=udp, and so on
1079 * XXX: as far as I can tell, changing the NFS program number is not
1080 * supported in the NFS client.
1082 static int nfs_validate_mount_data(struct nfs_mount_data
**options
,
1083 struct nfs_fh
*mntfh
,
1084 const char *dev_name
)
1086 struct nfs_mount_data
*data
= *options
;
1091 switch (data
->version
) {
1097 if (data
->flags
& NFS_MOUNT_VER3
)
1099 data
->root
.size
= NFS2_FHSIZE
;
1100 memcpy(data
->root
.data
, data
->old_root
.data
, NFS2_FHSIZE
);
1102 if (data
->flags
& NFS_MOUNT_SECFLAVOUR
)
1105 memset(data
->context
, 0, sizeof(data
->context
));
1107 if (data
->flags
& NFS_MOUNT_VER3
)
1108 mntfh
->size
= data
->root
.size
;
1110 mntfh
->size
= NFS2_FHSIZE
;
1112 if (mntfh
->size
> sizeof(mntfh
->data
))
1113 goto out_invalid_fh
;
1115 memcpy(mntfh
->data
, data
->root
.data
, mntfh
->size
);
1116 if (mntfh
->size
< sizeof(mntfh
->data
))
1117 memset(mntfh
->data
+ mntfh
->size
, 0,
1118 sizeof(mntfh
->data
) - mntfh
->size
);
1124 struct nfs_parsed_mount_data args
= {
1125 .flags
= (NFS_MOUNT_VER3
| NFS_MOUNT_TCP
),
1126 .rsize
= NFS_MAX_FILE_IO_SIZE
,
1127 .wsize
= NFS_MAX_FILE_IO_SIZE
,
1134 .mount_server
.protocol
= IPPROTO_UDP
,
1135 .mount_server
.program
= NFS_MNT_PROGRAM
,
1136 .nfs_server
.protocol
= IPPROTO_TCP
,
1137 .nfs_server
.program
= NFS_PROGRAM
,
1140 if (nfs_parse_mount_options((char *) *options
, &args
) == 0)
1143 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
1148 * NB: after this point, caller will free "data"
1149 * if we return an error
1153 c
= strchr(dev_name
, ':');
1157 if (len
> sizeof(data
->hostname
))
1158 return -ENAMETOOLONG
;
1159 strncpy(data
->hostname
, dev_name
, len
);
1160 args
.nfs_server
.hostname
= data
->hostname
;
1163 if (strlen(c
) > NFS_MAXPATHLEN
)
1164 return -ENAMETOOLONG
;
1165 args
.nfs_server
.export_path
= c
;
1167 status
= nfs_try_mount(&args
, mntfh
);
1172 * Translate to nfs_mount_data, which nfs_fill_super
1176 data
->flags
= args
.flags
;
1177 data
->rsize
= args
.rsize
;
1178 data
->wsize
= args
.wsize
;
1179 data
->timeo
= args
.timeo
;
1180 data
->retrans
= args
.retrans
;
1181 data
->acregmin
= args
.acregmin
;
1182 data
->acregmax
= args
.acregmax
;
1183 data
->acdirmin
= args
.acdirmin
;
1184 data
->acdirmax
= args
.acdirmax
;
1185 data
->addr
= args
.nfs_server
.address
;
1186 data
->namlen
= args
.namlen
;
1187 data
->bsize
= args
.bsize
;
1188 data
->pseudoflavor
= args
.auth_flavors
[0];
1194 if (!(data
->flags
& NFS_MOUNT_SECFLAVOUR
))
1195 data
->pseudoflavor
= RPC_AUTH_UNIX
;
1197 #ifndef CONFIG_NFS_V3
1198 if (data
->flags
& NFS_MOUNT_VER3
)
1199 goto out_v3_not_compiled
;
1200 #endif /* !CONFIG_NFS_V3 */
1202 if (!nfs_verify_server_address((struct sockaddr
*) &data
->addr
))
1203 goto out_no_address
;
1208 dfprintk(MOUNT
, "NFS: mount program didn't pass any mount data\n");
1212 dfprintk(MOUNT
, "NFS: nfs_mount_data version %d does not support v3\n",
1217 dfprintk(MOUNT
, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1220 #ifndef CONFIG_NFS_V3
1221 out_v3_not_compiled
:
1222 dfprintk(MOUNT
, "NFS: NFSv3 is not compiled into kernel\n");
1223 return -EPROTONOSUPPORT
;
1224 #endif /* !CONFIG_NFS_V3 */
1227 dfprintk(MOUNT
, "NFS: mount program didn't pass remote address\n");
1231 dfprintk(MOUNT
, "NFS: invalid root filehandle\n");
1236 * Initialise the common bits of the superblock
1238 static inline void nfs_initialise_sb(struct super_block
*sb
)
1240 struct nfs_server
*server
= NFS_SB(sb
);
1242 sb
->s_magic
= NFS_SUPER_MAGIC
;
1244 /* We probably want something more informative here */
1245 snprintf(sb
->s_id
, sizeof(sb
->s_id
),
1246 "%x:%x", MAJOR(sb
->s_dev
), MINOR(sb
->s_dev
));
1248 if (sb
->s_blocksize
== 0)
1249 sb
->s_blocksize
= nfs_block_bits(server
->wsize
,
1250 &sb
->s_blocksize_bits
);
1252 if (server
->flags
& NFS_MOUNT_NOAC
)
1253 sb
->s_flags
|= MS_SYNCHRONOUS
;
1255 nfs_super_set_maxbytes(sb
, server
->maxfilesize
);
1259 * Finish setting up an NFS2/3 superblock
1261 static void nfs_fill_super(struct super_block
*sb
, struct nfs_mount_data
*data
)
1263 struct nfs_server
*server
= NFS_SB(sb
);
1265 sb
->s_blocksize_bits
= 0;
1266 sb
->s_blocksize
= 0;
1268 sb
->s_blocksize
= nfs_block_size(data
->bsize
, &sb
->s_blocksize_bits
);
1270 if (server
->flags
& NFS_MOUNT_VER3
) {
1271 /* The VFS shouldn't apply the umask to mode bits. We will do
1272 * so ourselves when necessary.
1274 sb
->s_flags
|= MS_POSIXACL
;
1275 sb
->s_time_gran
= 1;
1278 sb
->s_op
= &nfs_sops
;
1279 nfs_initialise_sb(sb
);
1283 * Finish setting up a cloned NFS2/3 superblock
1285 static void nfs_clone_super(struct super_block
*sb
,
1286 const struct super_block
*old_sb
)
1288 struct nfs_server
*server
= NFS_SB(sb
);
1290 sb
->s_blocksize_bits
= old_sb
->s_blocksize_bits
;
1291 sb
->s_blocksize
= old_sb
->s_blocksize
;
1292 sb
->s_maxbytes
= old_sb
->s_maxbytes
;
1294 if (server
->flags
& NFS_MOUNT_VER3
) {
1295 /* The VFS shouldn't apply the umask to mode bits. We will do
1296 * so ourselves when necessary.
1298 sb
->s_flags
|= MS_POSIXACL
;
1299 sb
->s_time_gran
= 1;
1302 sb
->s_op
= old_sb
->s_op
;
1303 nfs_initialise_sb(sb
);
1306 #define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
1308 static int nfs_compare_mount_options(const struct super_block
*s
, const struct nfs_server
*b
, int flags
)
1310 const struct nfs_server
*a
= s
->s_fs_info
;
1311 const struct rpc_clnt
*clnt_a
= a
->client
;
1312 const struct rpc_clnt
*clnt_b
= b
->client
;
1314 if ((s
->s_flags
& NFS_MS_MASK
) != (flags
& NFS_MS_MASK
))
1316 if (a
->nfs_client
!= b
->nfs_client
)
1318 if (a
->flags
!= b
->flags
)
1320 if (a
->wsize
!= b
->wsize
)
1322 if (a
->rsize
!= b
->rsize
)
1324 if (a
->acregmin
!= b
->acregmin
)
1326 if (a
->acregmax
!= b
->acregmax
)
1328 if (a
->acdirmin
!= b
->acdirmin
)
1330 if (a
->acdirmax
!= b
->acdirmax
)
1332 if (clnt_a
->cl_auth
->au_flavor
!= clnt_b
->cl_auth
->au_flavor
)
1339 struct nfs_sb_mountdata
{
1340 struct nfs_server
*server
;
1344 static int nfs_set_super(struct super_block
*s
, void *data
)
1346 struct nfs_sb_mountdata
*sb_mntdata
= data
;
1347 struct nfs_server
*server
= sb_mntdata
->server
;
1350 s
->s_flags
= sb_mntdata
->mntflags
;
1351 s
->s_fs_info
= server
;
1352 ret
= set_anon_super(s
, server
);
1354 server
->s_dev
= s
->s_dev
;
1358 static int nfs_compare_super(struct super_block
*sb
, void *data
)
1360 struct nfs_sb_mountdata
*sb_mntdata
= data
;
1361 struct nfs_server
*server
= sb_mntdata
->server
, *old
= NFS_SB(sb
);
1362 int mntflags
= sb_mntdata
->mntflags
;
1364 if (memcmp(&old
->nfs_client
->cl_addr
,
1365 &server
->nfs_client
->cl_addr
,
1366 sizeof(old
->nfs_client
->cl_addr
)) != 0)
1368 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1369 if (old
->flags
& NFS_MOUNT_UNSHARED
)
1371 if (memcmp(&old
->fsid
, &server
->fsid
, sizeof(old
->fsid
)) != 0)
1373 return nfs_compare_mount_options(sb
, server
, mntflags
);
1376 static int nfs_get_sb(struct file_system_type
*fs_type
,
1377 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
1379 struct nfs_server
*server
= NULL
;
1380 struct super_block
*s
;
1381 struct nfs_fh mntfh
;
1382 struct nfs_mount_data
*data
= raw_data
;
1383 struct dentry
*mntroot
;
1384 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
1385 struct nfs_sb_mountdata sb_mntdata
= {
1390 /* Validate the mount data */
1391 error
= nfs_validate_mount_data(&data
, &mntfh
, dev_name
);
1395 /* Get a volume representation */
1396 server
= nfs_create_server(data
, &mntfh
);
1397 if (IS_ERR(server
)) {
1398 error
= PTR_ERR(server
);
1401 sb_mntdata
.server
= server
;
1403 if (server
->flags
& NFS_MOUNT_UNSHARED
)
1404 compare_super
= NULL
;
1406 /* Get a superblock - note that we may end up sharing one that already exists */
1407 s
= sget(fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
1413 if (s
->s_fs_info
!= server
) {
1414 nfs_free_server(server
);
1419 /* initial superblock/root creation */
1420 nfs_fill_super(s
, data
);
1423 mntroot
= nfs_get_root(s
, &mntfh
);
1424 if (IS_ERR(mntroot
)) {
1425 error
= PTR_ERR(mntroot
);
1426 goto error_splat_super
;
1429 s
->s_flags
|= MS_ACTIVE
;
1431 mnt
->mnt_root
= mntroot
;
1435 if (data
!= raw_data
)
1440 nfs_free_server(server
);
1444 up_write(&s
->s_umount
);
1445 deactivate_super(s
);
1450 * Destroy an NFS2/3 superblock
1452 static void nfs_kill_super(struct super_block
*s
)
1454 struct nfs_server
*server
= NFS_SB(s
);
1457 nfs_free_server(server
);
1461 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
1463 static int nfs_xdev_get_sb(struct file_system_type
*fs_type
, int flags
,
1464 const char *dev_name
, void *raw_data
,
1465 struct vfsmount
*mnt
)
1467 struct nfs_clone_mount
*data
= raw_data
;
1468 struct super_block
*s
;
1469 struct nfs_server
*server
;
1470 struct dentry
*mntroot
;
1471 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
1472 struct nfs_sb_mountdata sb_mntdata
= {
1477 dprintk("--> nfs_xdev_get_sb()\n");
1479 /* create a new volume representation */
1480 server
= nfs_clone_server(NFS_SB(data
->sb
), data
->fh
, data
->fattr
);
1481 if (IS_ERR(server
)) {
1482 error
= PTR_ERR(server
);
1483 goto out_err_noserver
;
1485 sb_mntdata
.server
= server
;
1487 if (server
->flags
& NFS_MOUNT_UNSHARED
)
1488 compare_super
= NULL
;
1490 /* Get a superblock - note that we may end up sharing one that already exists */
1491 s
= sget(&nfs_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
1497 if (s
->s_fs_info
!= server
) {
1498 nfs_free_server(server
);
1503 /* initial superblock/root creation */
1504 nfs_clone_super(s
, data
->sb
);
1507 mntroot
= nfs_get_root(s
, data
->fh
);
1508 if (IS_ERR(mntroot
)) {
1509 error
= PTR_ERR(mntroot
);
1510 goto error_splat_super
;
1513 s
->s_flags
|= MS_ACTIVE
;
1515 mnt
->mnt_root
= mntroot
;
1517 dprintk("<-- nfs_xdev_get_sb() = 0\n");
1521 nfs_free_server(server
);
1523 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error
);
1527 up_write(&s
->s_umount
);
1528 deactivate_super(s
);
1529 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error
);
1533 #ifdef CONFIG_NFS_V4
1536 * Finish setting up a cloned NFS4 superblock
1538 static void nfs4_clone_super(struct super_block
*sb
,
1539 const struct super_block
*old_sb
)
1541 sb
->s_blocksize_bits
= old_sb
->s_blocksize_bits
;
1542 sb
->s_blocksize
= old_sb
->s_blocksize
;
1543 sb
->s_maxbytes
= old_sb
->s_maxbytes
;
1544 sb
->s_time_gran
= 1;
1545 sb
->s_op
= old_sb
->s_op
;
1546 nfs_initialise_sb(sb
);
1550 * Set up an NFS4 superblock
1552 static void nfs4_fill_super(struct super_block
*sb
)
1554 sb
->s_time_gran
= 1;
1555 sb
->s_op
= &nfs4_sops
;
1556 nfs_initialise_sb(sb
);
1560 * Validate NFSv4 mount options
1562 static int nfs4_validate_mount_data(struct nfs4_mount_data
**options
,
1563 const char *dev_name
,
1564 struct sockaddr_in
*addr
,
1565 rpc_authflavor_t
*authflavour
,
1570 struct nfs4_mount_data
*data
= *options
;
1576 switch (data
->version
) {
1578 if (data
->host_addrlen
!= sizeof(*addr
))
1579 goto out_no_address
;
1580 if (copy_from_user(addr
, data
->host_addr
, sizeof(*addr
)))
1582 if (addr
->sin_port
== 0)
1583 addr
->sin_port
= htons(NFS_PORT
);
1584 if (!nfs_verify_server_address((struct sockaddr
*) addr
))
1585 goto out_no_address
;
1587 switch (data
->auth_flavourlen
) {
1589 *authflavour
= RPC_AUTH_UNIX
;
1592 if (copy_from_user(authflavour
, data
->auth_flavours
,
1593 sizeof(*authflavour
)))
1597 goto out_inval_auth
;
1600 c
= strndup_user(data
->hostname
.data
, NFS4_MAXNAMLEN
);
1605 c
= strndup_user(data
->mnt_path
.data
, NFS4_MAXPATHLEN
);
1609 dfprintk(MOUNT
, "NFS: MNTPATH: '%s'\n", *mntpath
);
1611 c
= strndup_user(data
->client_addr
.data
, 16);
1619 struct nfs_parsed_mount_data args
= {
1620 .rsize
= NFS_MAX_FILE_IO_SIZE
,
1621 .wsize
= NFS_MAX_FILE_IO_SIZE
,
1628 .nfs_server
.protocol
= IPPROTO_TCP
,
1631 if (nfs_parse_mount_options((char *) *options
, &args
) == 0)
1634 if (!nfs_verify_server_address((struct sockaddr
*)
1635 &args
.nfs_server
.address
))
1637 *addr
= args
.nfs_server
.address
;
1639 switch (args
.auth_flavor_len
) {
1641 *authflavour
= RPC_AUTH_UNIX
;
1644 *authflavour
= (rpc_authflavor_t
) args
.auth_flavors
[0];
1647 goto out_inval_auth
;
1651 * Translate to nfs4_mount_data, which nfs4_fill_super
1654 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
1660 data
->flags
= args
.flags
& NFS4_MOUNT_FLAGMASK
;
1661 data
->rsize
= args
.rsize
;
1662 data
->wsize
= args
.wsize
;
1663 data
->timeo
= args
.timeo
;
1664 data
->retrans
= args
.retrans
;
1665 data
->acregmin
= args
.acregmin
;
1666 data
->acregmax
= args
.acregmax
;
1667 data
->acdirmin
= args
.acdirmin
;
1668 data
->acdirmax
= args
.acdirmax
;
1669 data
->proto
= args
.nfs_server
.protocol
;
1672 * Split "dev_name" into "hostname:mntpath".
1674 c
= strchr(dev_name
, ':');
1677 /* while calculating len, pretend ':' is '\0' */
1679 if (len
> NFS4_MAXNAMLEN
)
1680 return -ENAMETOOLONG
;
1681 *hostname
= kzalloc(len
, GFP_KERNEL
);
1682 if (*hostname
== NULL
)
1684 strncpy(*hostname
, dev_name
, len
- 1);
1686 c
++; /* step over the ':' */
1688 if (len
> NFS4_MAXPATHLEN
)
1689 return -ENAMETOOLONG
;
1690 *mntpath
= kzalloc(len
+ 1, GFP_KERNEL
);
1691 if (*mntpath
== NULL
)
1693 strncpy(*mntpath
, c
, len
);
1695 dprintk("MNTPATH: %s\n", *mntpath
);
1697 if (args
.client_address
== NULL
)
1698 goto out_no_client_address
;
1700 *ip_addr
= args
.client_address
;
1709 dfprintk(MOUNT
, "NFS4: mount program didn't pass any mount data\n");
1713 dfprintk(MOUNT
, "NFS4: Invalid number of RPC auth flavours %d\n",
1714 data
->auth_flavourlen
);
1718 dfprintk(MOUNT
, "NFS4: mount program didn't pass remote address\n");
1721 out_no_client_address
:
1722 dfprintk(MOUNT
, "NFS4: mount program didn't pass callback address\n");
1727 * Get the superblock for an NFS4 mountpoint
1729 static int nfs4_get_sb(struct file_system_type
*fs_type
,
1730 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
1732 struct nfs4_mount_data
*data
= raw_data
;
1733 struct super_block
*s
;
1734 struct nfs_server
*server
;
1735 struct sockaddr_in addr
;
1736 rpc_authflavor_t authflavour
;
1737 struct nfs_fh mntfh
;
1738 struct dentry
*mntroot
;
1739 char *mntpath
= NULL
, *hostname
= NULL
, *ip_addr
= NULL
;
1740 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
1741 struct nfs_sb_mountdata sb_mntdata
= {
1746 /* Validate the mount data */
1747 error
= nfs4_validate_mount_data(&data
, dev_name
, &addr
, &authflavour
,
1748 &hostname
, &mntpath
, &ip_addr
);
1752 /* Get a volume representation */
1753 server
= nfs4_create_server(data
, hostname
, &addr
, mntpath
, ip_addr
,
1754 authflavour
, &mntfh
);
1755 if (IS_ERR(server
)) {
1756 error
= PTR_ERR(server
);
1759 sb_mntdata
.server
= server
;
1761 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
1762 compare_super
= NULL
;
1764 /* Get a superblock - note that we may end up sharing one that already exists */
1765 s
= sget(fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
1771 if (s
->s_fs_info
!= server
) {
1772 nfs_free_server(server
);
1777 /* initial superblock/root creation */
1781 mntroot
= nfs4_get_root(s
, &mntfh
);
1782 if (IS_ERR(mntroot
)) {
1783 error
= PTR_ERR(mntroot
);
1784 goto error_splat_super
;
1787 s
->s_flags
|= MS_ACTIVE
;
1789 mnt
->mnt_root
= mntroot
;
1799 nfs_free_server(server
);
1803 up_write(&s
->s_umount
);
1804 deactivate_super(s
);
1808 static void nfs4_kill_super(struct super_block
*sb
)
1810 struct nfs_server
*server
= NFS_SB(sb
);
1812 nfs_return_all_delegations(sb
);
1813 kill_anon_super(sb
);
1815 nfs4_renewd_prepare_shutdown(server
);
1816 nfs_free_server(server
);
1820 * Clone an NFS4 server record on xdev traversal (FSID-change)
1822 static int nfs4_xdev_get_sb(struct file_system_type
*fs_type
, int flags
,
1823 const char *dev_name
, void *raw_data
,
1824 struct vfsmount
*mnt
)
1826 struct nfs_clone_mount
*data
= raw_data
;
1827 struct super_block
*s
;
1828 struct nfs_server
*server
;
1829 struct dentry
*mntroot
;
1830 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
1831 struct nfs_sb_mountdata sb_mntdata
= {
1836 dprintk("--> nfs4_xdev_get_sb()\n");
1838 /* create a new volume representation */
1839 server
= nfs_clone_server(NFS_SB(data
->sb
), data
->fh
, data
->fattr
);
1840 if (IS_ERR(server
)) {
1841 error
= PTR_ERR(server
);
1842 goto out_err_noserver
;
1844 sb_mntdata
.server
= server
;
1846 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
1847 compare_super
= NULL
;
1849 /* Get a superblock - note that we may end up sharing one that already exists */
1850 s
= sget(&nfs_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
1856 if (s
->s_fs_info
!= server
) {
1857 nfs_free_server(server
);
1862 /* initial superblock/root creation */
1863 nfs4_clone_super(s
, data
->sb
);
1866 mntroot
= nfs4_get_root(s
, data
->fh
);
1867 if (IS_ERR(mntroot
)) {
1868 error
= PTR_ERR(mntroot
);
1869 goto error_splat_super
;
1872 s
->s_flags
|= MS_ACTIVE
;
1874 mnt
->mnt_root
= mntroot
;
1876 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
1880 nfs_free_server(server
);
1882 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error
);
1886 up_write(&s
->s_umount
);
1887 deactivate_super(s
);
1888 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error
);
1893 * Create an NFS4 server record on referral traversal
1895 static int nfs4_referral_get_sb(struct file_system_type
*fs_type
, int flags
,
1896 const char *dev_name
, void *raw_data
,
1897 struct vfsmount
*mnt
)
1899 struct nfs_clone_mount
*data
= raw_data
;
1900 struct super_block
*s
;
1901 struct nfs_server
*server
;
1902 struct dentry
*mntroot
;
1903 struct nfs_fh mntfh
;
1904 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
1905 struct nfs_sb_mountdata sb_mntdata
= {
1910 dprintk("--> nfs4_referral_get_sb()\n");
1912 /* create a new volume representation */
1913 server
= nfs4_create_referral_server(data
, &mntfh
);
1914 if (IS_ERR(server
)) {
1915 error
= PTR_ERR(server
);
1916 goto out_err_noserver
;
1918 sb_mntdata
.server
= server
;
1920 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
1921 compare_super
= NULL
;
1923 /* Get a superblock - note that we may end up sharing one that already exists */
1924 s
= sget(&nfs_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
1930 if (s
->s_fs_info
!= server
) {
1931 nfs_free_server(server
);
1936 /* initial superblock/root creation */
1940 mntroot
= nfs4_get_root(s
, &mntfh
);
1941 if (IS_ERR(mntroot
)) {
1942 error
= PTR_ERR(mntroot
);
1943 goto error_splat_super
;
1946 s
->s_flags
|= MS_ACTIVE
;
1948 mnt
->mnt_root
= mntroot
;
1950 dprintk("<-- nfs4_referral_get_sb() = 0\n");
1954 nfs_free_server(server
);
1956 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error
);
1960 up_write(&s
->s_umount
);
1961 deactivate_super(s
);
1962 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error
);
1966 #endif /* CONFIG_NFS_V4 */