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
;
306 * Register the NFS filesystems
308 int __init
register_nfs_fs(void)
312 ret
= register_filesystem(&nfs_fs_type
);
316 ret
= nfs_register_sysctl();
320 ret
= register_filesystem(&nfs4_fs_type
);
324 acl_shrinker
= set_shrinker(DEFAULT_SEEKS
, nfs_access_cache_shrinker
);
329 nfs_unregister_sysctl();
332 unregister_filesystem(&nfs_fs_type
);
338 * Unregister the NFS filesystems
340 void __exit
unregister_nfs_fs(void)
342 if (acl_shrinker
!= NULL
)
343 remove_shrinker(acl_shrinker
);
345 unregister_filesystem(&nfs4_fs_type
);
347 nfs_unregister_sysctl();
348 unregister_filesystem(&nfs_fs_type
);
352 * Deliver file system statistics to userspace
354 static int nfs_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
356 struct nfs_server
*server
= NFS_SB(dentry
->d_sb
);
357 unsigned char blockbits
;
358 unsigned long blockres
;
359 struct nfs_fh
*fh
= NFS_FH(dentry
->d_inode
);
360 struct nfs_fattr fattr
;
361 struct nfs_fsstat res
= {
368 error
= server
->nfs_client
->rpc_ops
->statfs(server
, fh
, &res
);
371 buf
->f_type
= NFS_SUPER_MAGIC
;
374 * Current versions of glibc do not correctly handle the
375 * case where f_frsize != f_bsize. Eventually we want to
376 * report the value of wtmult in this field.
378 buf
->f_frsize
= dentry
->d_sb
->s_blocksize
;
381 * On most *nix systems, f_blocks, f_bfree, and f_bavail
382 * are reported in units of f_frsize. Linux hasn't had
383 * an f_frsize field in its statfs struct until recently,
384 * thus historically Linux's sys_statfs reports these
385 * fields in units of f_bsize.
387 buf
->f_bsize
= dentry
->d_sb
->s_blocksize
;
388 blockbits
= dentry
->d_sb
->s_blocksize_bits
;
389 blockres
= (1 << blockbits
) - 1;
390 buf
->f_blocks
= (res
.tbytes
+ blockres
) >> blockbits
;
391 buf
->f_bfree
= (res
.fbytes
+ blockres
) >> blockbits
;
392 buf
->f_bavail
= (res
.abytes
+ blockres
) >> blockbits
;
394 buf
->f_files
= res
.tfiles
;
395 buf
->f_ffree
= res
.afiles
;
397 buf
->f_namelen
= server
->namelen
;
403 dprintk("%s: statfs error = %d\n", __FUNCTION__
, -error
);
409 * Map the security flavour number to a name
411 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour
)
413 static const struct {
414 rpc_authflavor_t flavour
;
417 { RPC_AUTH_NULL
, "null" },
418 { RPC_AUTH_UNIX
, "sys" },
419 { RPC_AUTH_GSS_KRB5
, "krb5" },
420 { RPC_AUTH_GSS_KRB5I
, "krb5i" },
421 { RPC_AUTH_GSS_KRB5P
, "krb5p" },
422 { RPC_AUTH_GSS_LKEY
, "lkey" },
423 { RPC_AUTH_GSS_LKEYI
, "lkeyi" },
424 { RPC_AUTH_GSS_LKEYP
, "lkeyp" },
425 { RPC_AUTH_GSS_SPKM
, "spkm" },
426 { RPC_AUTH_GSS_SPKMI
, "spkmi" },
427 { RPC_AUTH_GSS_SPKMP
, "spkmp" },
428 { UINT_MAX
, "unknown" }
432 for (i
= 0; sec_flavours
[i
].flavour
!= UINT_MAX
; i
++) {
433 if (sec_flavours
[i
].flavour
== flavour
)
436 return sec_flavours
[i
].str
;
440 * Describe the mount options in force on this server representation
442 static void nfs_show_mount_options(struct seq_file
*m
, struct nfs_server
*nfss
, int showdefaults
)
444 static const struct proc_nfs_info
{
449 { NFS_MOUNT_SOFT
, ",soft", ",hard" },
450 { NFS_MOUNT_INTR
, ",intr", "" },
451 { NFS_MOUNT_NOCTO
, ",nocto", "" },
452 { NFS_MOUNT_NOAC
, ",noac", "" },
453 { NFS_MOUNT_NONLM
, ",nolock", "" },
454 { NFS_MOUNT_NOACL
, ",noacl", "" },
455 { NFS_MOUNT_NORDIRPLUS
, ",nordirplus", "" },
456 { NFS_MOUNT_UNSHARED
, ",nosharecache", ""},
459 const struct proc_nfs_info
*nfs_infop
;
460 struct nfs_client
*clp
= nfss
->nfs_client
;
464 seq_printf(m
, ",vers=%d", clp
->rpc_ops
->version
);
465 seq_printf(m
, ",rsize=%d", nfss
->rsize
);
466 seq_printf(m
, ",wsize=%d", nfss
->wsize
);
467 if (nfss
->acregmin
!= 3*HZ
|| showdefaults
)
468 seq_printf(m
, ",acregmin=%d", nfss
->acregmin
/HZ
);
469 if (nfss
->acregmax
!= 60*HZ
|| showdefaults
)
470 seq_printf(m
, ",acregmax=%d", nfss
->acregmax
/HZ
);
471 if (nfss
->acdirmin
!= 30*HZ
|| showdefaults
)
472 seq_printf(m
, ",acdirmin=%d", nfss
->acdirmin
/HZ
);
473 if (nfss
->acdirmax
!= 60*HZ
|| showdefaults
)
474 seq_printf(m
, ",acdirmax=%d", nfss
->acdirmax
/HZ
);
475 for (nfs_infop
= nfs_info
; nfs_infop
->flag
; nfs_infop
++) {
476 if (nfss
->flags
& nfs_infop
->flag
)
477 seq_puts(m
, nfs_infop
->str
);
479 seq_puts(m
, nfs_infop
->nostr
);
481 switch (nfss
->client
->cl_xprt
->prot
) {
489 snprintf(buf
, sizeof(buf
), "%u", nfss
->client
->cl_xprt
->prot
);
492 seq_printf(m
, ",proto=%s", proto
);
493 seq_printf(m
, ",timeo=%lu", 10U * clp
->retrans_timeo
/ HZ
);
494 seq_printf(m
, ",retrans=%u", clp
->retrans_count
);
495 seq_printf(m
, ",sec=%s", nfs_pseudoflavour_to_name(nfss
->client
->cl_auth
->au_flavor
));
499 * Describe the mount options on this VFS mountpoint
501 static int nfs_show_options(struct seq_file
*m
, struct vfsmount
*mnt
)
503 struct nfs_server
*nfss
= NFS_SB(mnt
->mnt_sb
);
505 nfs_show_mount_options(m
, nfss
, 0);
507 seq_puts(m
, ",addr=");
508 seq_escape(m
, nfss
->nfs_client
->cl_hostname
, " \t\n\\");
514 * Present statistical information for this VFS mountpoint
516 static int nfs_show_stats(struct seq_file
*m
, struct vfsmount
*mnt
)
519 struct nfs_server
*nfss
= NFS_SB(mnt
->mnt_sb
);
520 struct rpc_auth
*auth
= nfss
->client
->cl_auth
;
521 struct nfs_iostats totals
= { };
523 seq_printf(m
, "statvers=%s", NFS_IOSTAT_VERS
);
526 * Display all mount option settings
528 seq_printf(m
, "\n\topts:\t");
529 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_RDONLY
? "ro" : "rw");
530 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_SYNCHRONOUS
? ",sync" : "");
531 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_NOATIME
? ",noatime" : "");
532 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_NODIRATIME
? ",nodiratime" : "");
533 nfs_show_mount_options(m
, nfss
, 1);
535 seq_printf(m
, "\n\tage:\t%lu", (jiffies
- nfss
->mount_time
) / HZ
);
537 seq_printf(m
, "\n\tcaps:\t");
538 seq_printf(m
, "caps=0x%x", nfss
->caps
);
539 seq_printf(m
, ",wtmult=%d", nfss
->wtmult
);
540 seq_printf(m
, ",dtsize=%d", nfss
->dtsize
);
541 seq_printf(m
, ",bsize=%d", nfss
->bsize
);
542 seq_printf(m
, ",namelen=%d", nfss
->namelen
);
545 if (nfss
->nfs_client
->cl_nfsversion
== 4) {
546 seq_printf(m
, "\n\tnfsv4:\t");
547 seq_printf(m
, "bm0=0x%x", nfss
->attr_bitmask
[0]);
548 seq_printf(m
, ",bm1=0x%x", nfss
->attr_bitmask
[1]);
549 seq_printf(m
, ",acl=0x%x", nfss
->acl_bitmask
);
554 * Display security flavor in effect for this mount
556 seq_printf(m
, "\n\tsec:\tflavor=%d", auth
->au_ops
->au_flavor
);
558 seq_printf(m
, ",pseudoflavor=%d", auth
->au_flavor
);
561 * Display superblock I/O counters
563 for_each_possible_cpu(cpu
) {
564 struct nfs_iostats
*stats
;
567 stats
= per_cpu_ptr(nfss
->io_stats
, cpu
);
569 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
570 totals
.events
[i
] += stats
->events
[i
];
571 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
572 totals
.bytes
[i
] += stats
->bytes
[i
];
577 seq_printf(m
, "\n\tevents:\t");
578 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
579 seq_printf(m
, "%lu ", totals
.events
[i
]);
580 seq_printf(m
, "\n\tbytes:\t");
581 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
582 seq_printf(m
, "%Lu ", totals
.bytes
[i
]);
585 rpc_print_iostats(m
, nfss
->client
);
591 * Begin unmount by attempting to remove all automounted mountpoints we added
592 * in response to xdev traversals and referrals
594 static void nfs_umount_begin(struct vfsmount
*vfsmnt
, int flags
)
596 struct nfs_server
*server
= NFS_SB(vfsmnt
->mnt_sb
);
597 struct rpc_clnt
*rpc
;
599 shrink_submounts(vfsmnt
, &nfs_automount_list
);
601 if (!(flags
& MNT_FORCE
))
603 /* -EIO all pending I/O */
604 rpc
= server
->client_acl
;
606 rpc_killall_tasks(rpc
);
607 rpc
= server
->client
;
609 rpc_killall_tasks(rpc
);
613 * Sanity-check a server address provided by the mount command
615 static int nfs_verify_server_address(struct sockaddr
*addr
)
617 switch (addr
->sa_family
) {
619 struct sockaddr_in
*sa
= (struct sockaddr_in
*) addr
;
620 if (sa
->sin_addr
.s_addr
!= INADDR_ANY
)
630 * Error-check and convert a string of mount options from user space into
633 static int nfs_parse_mount_options(char *raw
,
634 struct nfs_parsed_mount_data
*mnt
)
639 dfprintk(MOUNT
, "NFS: mount options string was NULL.\n");
642 dfprintk(MOUNT
, "NFS: nfs mount opts='%s'\n", raw
);
644 while ((p
= strsep(&raw
, ",")) != NULL
) {
645 substring_t args
[MAX_OPT_ARGS
];
651 dfprintk(MOUNT
, "NFS: parsing nfs mount option '%s'\n", p
);
653 token
= match_token(p
, nfs_mount_option_tokens
, args
);
656 mnt
->flags
|= NFS_MOUNT_SOFT
;
659 mnt
->flags
&= ~NFS_MOUNT_SOFT
;
662 mnt
->flags
|= NFS_MOUNT_INTR
;
665 mnt
->flags
&= ~NFS_MOUNT_INTR
;
668 mnt
->flags
|= NFS_MOUNT_POSIX
;
671 mnt
->flags
&= ~NFS_MOUNT_POSIX
;
674 mnt
->flags
&= ~NFS_MOUNT_NOCTO
;
677 mnt
->flags
|= NFS_MOUNT_NOCTO
;
680 mnt
->flags
&= ~NFS_MOUNT_NOAC
;
683 mnt
->flags
|= NFS_MOUNT_NOAC
;
686 mnt
->flags
&= ~NFS_MOUNT_NONLM
;
689 mnt
->flags
|= NFS_MOUNT_NONLM
;
692 mnt
->flags
&= ~NFS_MOUNT_VER3
;
695 mnt
->flags
|= NFS_MOUNT_VER3
;
698 mnt
->flags
&= ~NFS_MOUNT_TCP
;
699 mnt
->nfs_server
.protocol
= IPPROTO_UDP
;
704 mnt
->flags
|= NFS_MOUNT_TCP
;
705 mnt
->nfs_server
.protocol
= IPPROTO_TCP
;
710 mnt
->flags
&= ~NFS_MOUNT_NOACL
;
713 mnt
->flags
|= NFS_MOUNT_NOACL
;
716 mnt
->flags
&= ~NFS_MOUNT_NORDIRPLUS
;
719 mnt
->flags
|= NFS_MOUNT_NORDIRPLUS
;
722 mnt
->flags
&= ~NFS_MOUNT_UNSHARED
;
724 case Opt_nosharecache
:
725 mnt
->flags
|= NFS_MOUNT_UNSHARED
;
729 if (match_int(args
, &option
))
731 if (option
< 0 || option
> 65535)
733 mnt
->nfs_server
.address
.sin_port
= htonl(option
);
736 if (match_int(args
, &mnt
->rsize
))
740 if (match_int(args
, &mnt
->wsize
))
744 if (match_int(args
, &option
))
751 if (match_int(args
, &mnt
->timeo
))
755 if (match_int(args
, &mnt
->retrans
))
759 if (match_int(args
, &mnt
->acregmin
))
763 if (match_int(args
, &mnt
->acregmax
))
767 if (match_int(args
, &mnt
->acdirmin
))
771 if (match_int(args
, &mnt
->acdirmax
))
775 if (match_int(args
, &option
))
782 mnt
->acdirmax
= option
;
785 if (match_int(args
, &mnt
->namlen
))
789 if (match_int(args
, &option
))
791 if (option
< 0 || option
> 65535)
793 mnt
->mount_server
.port
= option
;
796 if (match_int(args
, &option
))
800 mnt
->mount_server
.program
= option
;
803 if (match_int(args
, &option
))
807 mnt
->mount_server
.version
= option
;
810 if (match_int(args
, &option
))
814 mnt
->nfs_server
.program
= option
;
817 if (match_int(args
, &option
))
821 mnt
->flags
&= ~NFS_MOUNT_VER3
;
824 mnt
->flags
|= NFS_MOUNT_VER3
;
832 string
= match_strdup(args
);
835 token
= match_token(string
, nfs_secflavor_tokens
, args
);
839 * The flags setting is for v2/v3. The flavor_len
840 * setting is for v4. v2/v3 also need to know the
841 * difference between NULL and UNIX.
845 mnt
->flags
&= ~NFS_MOUNT_SECFLAVOUR
;
846 mnt
->auth_flavor_len
= 0;
847 mnt
->auth_flavors
[0] = RPC_AUTH_NULL
;
850 mnt
->flags
&= ~NFS_MOUNT_SECFLAVOUR
;
851 mnt
->auth_flavor_len
= 0;
852 mnt
->auth_flavors
[0] = RPC_AUTH_UNIX
;
855 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
856 mnt
->auth_flavor_len
= 1;
857 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5
;
860 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
861 mnt
->auth_flavor_len
= 1;
862 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5I
;
865 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
866 mnt
->auth_flavor_len
= 1;
867 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5P
;
870 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
871 mnt
->auth_flavor_len
= 1;
872 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEY
;
875 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
876 mnt
->auth_flavor_len
= 1;
877 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEYI
;
880 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
881 mnt
->auth_flavor_len
= 1;
882 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEYP
;
885 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
886 mnt
->auth_flavor_len
= 1;
887 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKM
;
890 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
891 mnt
->auth_flavor_len
= 1;
892 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKMI
;
895 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
896 mnt
->auth_flavor_len
= 1;
897 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKMP
;
904 string
= match_strdup(args
);
907 token
= match_token(string
,
908 nfs_xprt_protocol_tokens
, args
);
913 mnt
->flags
&= ~NFS_MOUNT_TCP
;
914 mnt
->nfs_server
.protocol
= IPPROTO_UDP
;
919 mnt
->flags
|= NFS_MOUNT_TCP
;
920 mnt
->nfs_server
.protocol
= IPPROTO_TCP
;
929 string
= match_strdup(args
);
932 token
= match_token(string
,
933 nfs_xprt_protocol_tokens
, args
);
938 mnt
->mount_server
.protocol
= IPPROTO_UDP
;
941 mnt
->mount_server
.protocol
= IPPROTO_TCP
;
948 string
= match_strdup(args
);
951 mnt
->nfs_server
.address
.sin_family
= AF_INET
;
952 mnt
->nfs_server
.address
.sin_addr
.s_addr
=
957 string
= match_strdup(args
);
960 mnt
->client_address
= string
;
963 string
= match_strdup(args
);
966 mnt
->mount_server
.address
.sin_family
= AF_INET
;
967 mnt
->mount_server
.address
.sin_addr
.s_addr
=
984 printk(KERN_INFO
"NFS: not enough memory to parse option\n");
988 printk(KERN_INFO
"NFS: unrecognized NFS version number\n");
992 printk(KERN_INFO
"NFS: unrecognized transport protocol\n");
996 printk(KERN_INFO
"NFS: unrecognized security flavor\n");
1000 printk(KERN_INFO
"NFS: unknown mount option: %s\n", p
);
1005 * Use the remote server's MOUNT service to request the NFS file handle
1006 * corresponding to the provided path.
1008 static int nfs_try_mount(struct nfs_parsed_mount_data
*args
,
1009 struct nfs_fh
*root_fh
)
1011 struct sockaddr_in sin
;
1014 if (args
->mount_server
.version
== 0) {
1015 if (args
->flags
& NFS_MOUNT_VER3
)
1016 args
->mount_server
.version
= NFS_MNT3_VERSION
;
1018 args
->mount_server
.version
= NFS_MNT_VERSION
;
1022 * Construct the mount server's address.
1024 if (args
->mount_server
.address
.sin_addr
.s_addr
!= INADDR_ANY
)
1025 sin
= args
->mount_server
.address
;
1027 sin
= args
->nfs_server
.address
;
1028 if (args
->mount_server
.port
== 0) {
1029 status
= rpcb_getport_sync(&sin
,
1030 args
->mount_server
.program
,
1031 args
->mount_server
.version
,
1032 args
->mount_server
.protocol
);
1035 sin
.sin_port
= htons(status
);
1037 sin
.sin_port
= htons(args
->mount_server
.port
);
1040 * Now ask the mount server to map our export path
1043 status
= nfs_mount((struct sockaddr
*) &sin
,
1045 args
->nfs_server
.hostname
,
1046 args
->nfs_server
.export_path
,
1047 args
->mount_server
.version
,
1048 args
->mount_server
.protocol
,
1056 dfprintk(MOUNT
, "NFS: unable to contact server on host "
1057 NIPQUAD_FMT
"\n", NIPQUAD(sin
.sin_addr
.s_addr
));
1062 * Validate the NFS2/NFS3 mount data
1063 * - fills in the mount root filehandle
1065 * For option strings, user space handles the following behaviors:
1067 * + DNS: mapping server host name to IP address ("addr=" option)
1069 * + failure mode: how to behave if a mount request can't be handled
1070 * immediately ("fg/bg" option)
1072 * + retry: how often to retry a mount request ("retry=" option)
1074 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1075 * mountproto=tcp after mountproto=udp, and so on
1077 * XXX: as far as I can tell, changing the NFS program number is not
1078 * supported in the NFS client.
1080 static int nfs_validate_mount_data(struct nfs_mount_data
**options
,
1081 struct nfs_fh
*mntfh
,
1082 const char *dev_name
)
1084 struct nfs_mount_data
*data
= *options
;
1089 switch (data
->version
) {
1095 if (data
->flags
& NFS_MOUNT_VER3
)
1097 data
->root
.size
= NFS2_FHSIZE
;
1098 memcpy(data
->root
.data
, data
->old_root
.data
, NFS2_FHSIZE
);
1100 if (data
->flags
& NFS_MOUNT_SECFLAVOUR
)
1103 memset(data
->context
, 0, sizeof(data
->context
));
1105 if (data
->flags
& NFS_MOUNT_VER3
)
1106 mntfh
->size
= data
->root
.size
;
1108 mntfh
->size
= NFS2_FHSIZE
;
1110 if (mntfh
->size
> sizeof(mntfh
->data
))
1111 goto out_invalid_fh
;
1113 memcpy(mntfh
->data
, data
->root
.data
, mntfh
->size
);
1114 if (mntfh
->size
< sizeof(mntfh
->data
))
1115 memset(mntfh
->data
+ mntfh
->size
, 0,
1116 sizeof(mntfh
->data
) - mntfh
->size
);
1122 struct nfs_parsed_mount_data args
= {
1123 .flags
= (NFS_MOUNT_VER3
| NFS_MOUNT_TCP
),
1124 .rsize
= NFS_MAX_FILE_IO_SIZE
,
1125 .wsize
= NFS_MAX_FILE_IO_SIZE
,
1132 .mount_server
.protocol
= IPPROTO_UDP
,
1133 .mount_server
.program
= NFS_MNT_PROGRAM
,
1134 .nfs_server
.protocol
= IPPROTO_TCP
,
1135 .nfs_server
.program
= NFS_PROGRAM
,
1138 if (nfs_parse_mount_options((char *) *options
, &args
) == 0)
1141 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
1146 * NB: after this point, caller will free "data"
1147 * if we return an error
1151 c
= strchr(dev_name
, ':');
1154 len
= c
- dev_name
- 1;
1155 if (len
> sizeof(data
->hostname
))
1157 strncpy(data
->hostname
, dev_name
, len
);
1158 args
.nfs_server
.hostname
= data
->hostname
;
1161 if (strlen(c
) > NFS_MAXPATHLEN
)
1163 args
.nfs_server
.export_path
= c
;
1165 status
= nfs_try_mount(&args
, mntfh
);
1170 * Translate to nfs_mount_data, which nfs_fill_super
1174 data
->flags
= args
.flags
;
1175 data
->rsize
= args
.rsize
;
1176 data
->wsize
= args
.wsize
;
1177 data
->timeo
= args
.timeo
;
1178 data
->retrans
= args
.retrans
;
1179 data
->acregmin
= args
.acregmin
;
1180 data
->acregmax
= args
.acregmax
;
1181 data
->acdirmin
= args
.acdirmin
;
1182 data
->acdirmax
= args
.acdirmax
;
1183 data
->addr
= args
.nfs_server
.address
;
1184 data
->namlen
= args
.namlen
;
1185 data
->bsize
= args
.bsize
;
1186 data
->pseudoflavor
= args
.auth_flavors
[0];
1192 if (!(data
->flags
& NFS_MOUNT_SECFLAVOUR
))
1193 data
->pseudoflavor
= RPC_AUTH_UNIX
;
1195 #ifndef CONFIG_NFS_V3
1196 if (data
->flags
& NFS_MOUNT_VER3
)
1197 goto out_v3_not_compiled
;
1198 #endif /* !CONFIG_NFS_V3 */
1200 if (!nfs_verify_server_address((struct sockaddr
*) &data
->addr
))
1201 goto out_no_address
;
1206 dfprintk(MOUNT
, "NFS: mount program didn't pass any mount data\n");
1210 dfprintk(MOUNT
, "NFS: nfs_mount_data version %d does not support v3\n",
1215 dfprintk(MOUNT
, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1218 #ifndef CONFIG_NFS_V3
1219 out_v3_not_compiled
:
1220 dfprintk(MOUNT
, "NFS: NFSv3 is not compiled into kernel\n");
1221 return -EPROTONOSUPPORT
;
1222 #endif /* !CONFIG_NFS_V3 */
1225 dfprintk(MOUNT
, "NFS: mount program didn't pass remote address\n");
1229 dfprintk(MOUNT
, "NFS: invalid root filehandle\n");
1234 * Initialise the common bits of the superblock
1236 static inline void nfs_initialise_sb(struct super_block
*sb
)
1238 struct nfs_server
*server
= NFS_SB(sb
);
1240 sb
->s_magic
= NFS_SUPER_MAGIC
;
1242 /* We probably want something more informative here */
1243 snprintf(sb
->s_id
, sizeof(sb
->s_id
),
1244 "%x:%x", MAJOR(sb
->s_dev
), MINOR(sb
->s_dev
));
1246 if (sb
->s_blocksize
== 0)
1247 sb
->s_blocksize
= nfs_block_bits(server
->wsize
,
1248 &sb
->s_blocksize_bits
);
1250 if (server
->flags
& NFS_MOUNT_NOAC
)
1251 sb
->s_flags
|= MS_SYNCHRONOUS
;
1253 nfs_super_set_maxbytes(sb
, server
->maxfilesize
);
1257 * Finish setting up an NFS2/3 superblock
1259 static void nfs_fill_super(struct super_block
*sb
, struct nfs_mount_data
*data
)
1261 struct nfs_server
*server
= NFS_SB(sb
);
1263 sb
->s_blocksize_bits
= 0;
1264 sb
->s_blocksize
= 0;
1266 sb
->s_blocksize
= nfs_block_size(data
->bsize
, &sb
->s_blocksize_bits
);
1268 if (server
->flags
& NFS_MOUNT_VER3
) {
1269 /* The VFS shouldn't apply the umask to mode bits. We will do
1270 * so ourselves when necessary.
1272 sb
->s_flags
|= MS_POSIXACL
;
1273 sb
->s_time_gran
= 1;
1276 sb
->s_op
= &nfs_sops
;
1277 nfs_initialise_sb(sb
);
1281 * Finish setting up a cloned NFS2/3 superblock
1283 static void nfs_clone_super(struct super_block
*sb
,
1284 const struct super_block
*old_sb
)
1286 struct nfs_server
*server
= NFS_SB(sb
);
1288 sb
->s_blocksize_bits
= old_sb
->s_blocksize_bits
;
1289 sb
->s_blocksize
= old_sb
->s_blocksize
;
1290 sb
->s_maxbytes
= old_sb
->s_maxbytes
;
1292 if (server
->flags
& NFS_MOUNT_VER3
) {
1293 /* The VFS shouldn't apply the umask to mode bits. We will do
1294 * so ourselves when necessary.
1296 sb
->s_flags
|= MS_POSIXACL
;
1297 sb
->s_time_gran
= 1;
1300 sb
->s_op
= old_sb
->s_op
;
1301 nfs_initialise_sb(sb
);
1304 static int nfs_set_super(struct super_block
*s
, void *_server
)
1306 struct nfs_server
*server
= _server
;
1309 s
->s_fs_info
= server
;
1310 ret
= set_anon_super(s
, server
);
1312 server
->s_dev
= s
->s_dev
;
1316 static int nfs_compare_super(struct super_block
*sb
, void *data
)
1318 struct nfs_server
*server
= data
, *old
= NFS_SB(sb
);
1320 if (memcmp(&old
->nfs_client
->cl_addr
,
1321 &server
->nfs_client
->cl_addr
,
1322 sizeof(old
->nfs_client
->cl_addr
)) != 0)
1324 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1325 if (old
->flags
& NFS_MOUNT_UNSHARED
)
1327 if (memcmp(&old
->fsid
, &server
->fsid
, sizeof(old
->fsid
)) != 0)
1332 #define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
1334 static int nfs_compare_mount_options(const struct super_block
*s
, const struct nfs_server
*b
, int flags
)
1336 const struct nfs_server
*a
= s
->s_fs_info
;
1337 const struct rpc_clnt
*clnt_a
= a
->client
;
1338 const struct rpc_clnt
*clnt_b
= b
->client
;
1340 if ((s
->s_flags
& NFS_MS_MASK
) != (flags
& NFS_MS_MASK
))
1342 if (a
->nfs_client
!= b
->nfs_client
)
1344 if (a
->flags
!= b
->flags
)
1346 if (a
->wsize
!= b
->wsize
)
1348 if (a
->rsize
!= b
->rsize
)
1350 if (a
->acregmin
!= b
->acregmin
)
1352 if (a
->acregmax
!= b
->acregmax
)
1354 if (a
->acdirmin
!= b
->acdirmin
)
1356 if (a
->acdirmax
!= b
->acdirmax
)
1358 if (clnt_a
->cl_auth
->au_flavor
!= clnt_b
->cl_auth
->au_flavor
)
1365 static int nfs_get_sb(struct file_system_type
*fs_type
,
1366 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
1368 struct nfs_server
*server
= NULL
;
1369 struct super_block
*s
;
1370 struct nfs_fh mntfh
;
1371 struct nfs_mount_data
*data
= raw_data
;
1372 struct dentry
*mntroot
;
1373 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
1376 /* Validate the mount data */
1377 error
= nfs_validate_mount_data(&data
, &mntfh
, dev_name
);
1381 /* Get a volume representation */
1382 server
= nfs_create_server(data
, &mntfh
);
1383 if (IS_ERR(server
)) {
1384 error
= PTR_ERR(server
);
1388 if (server
->flags
& NFS_MOUNT_UNSHARED
)
1389 compare_super
= NULL
;
1391 /* Get a superblock - note that we may end up sharing one that already exists */
1392 s
= sget(fs_type
, compare_super
, nfs_set_super
, server
);
1398 if (s
->s_fs_info
!= server
) {
1399 error
= nfs_compare_mount_options(s
, server
, flags
);
1400 nfs_free_server(server
);
1403 goto error_splat_super
;
1407 /* initial superblock/root creation */
1409 nfs_fill_super(s
, data
);
1412 mntroot
= nfs_get_root(s
, &mntfh
);
1413 if (IS_ERR(mntroot
)) {
1414 error
= PTR_ERR(mntroot
);
1415 goto error_splat_super
;
1418 s
->s_flags
|= MS_ACTIVE
;
1420 mnt
->mnt_root
= mntroot
;
1424 if (data
!= raw_data
)
1429 nfs_free_server(server
);
1433 up_write(&s
->s_umount
);
1434 deactivate_super(s
);
1439 * Destroy an NFS2/3 superblock
1441 static void nfs_kill_super(struct super_block
*s
)
1443 struct nfs_server
*server
= NFS_SB(s
);
1446 nfs_free_server(server
);
1450 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
1452 static int nfs_xdev_get_sb(struct file_system_type
*fs_type
, int flags
,
1453 const char *dev_name
, void *raw_data
,
1454 struct vfsmount
*mnt
)
1456 struct nfs_clone_mount
*data
= raw_data
;
1457 struct super_block
*s
;
1458 struct nfs_server
*server
;
1459 struct dentry
*mntroot
;
1460 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
1463 dprintk("--> nfs_xdev_get_sb()\n");
1465 /* create a new volume representation */
1466 server
= nfs_clone_server(NFS_SB(data
->sb
), data
->fh
, data
->fattr
);
1467 if (IS_ERR(server
)) {
1468 error
= PTR_ERR(server
);
1469 goto out_err_noserver
;
1472 if (server
->flags
& NFS_MOUNT_UNSHARED
)
1473 compare_super
= NULL
;
1475 /* Get a superblock - note that we may end up sharing one that already exists */
1476 s
= sget(&nfs_fs_type
, compare_super
, nfs_set_super
, server
);
1482 if (s
->s_fs_info
!= server
) {
1483 error
= nfs_compare_mount_options(s
, server
, flags
);
1484 nfs_free_server(server
);
1487 goto error_splat_super
;
1491 /* initial superblock/root creation */
1493 nfs_clone_super(s
, data
->sb
);
1496 mntroot
= nfs_get_root(s
, data
->fh
);
1497 if (IS_ERR(mntroot
)) {
1498 error
= PTR_ERR(mntroot
);
1499 goto error_splat_super
;
1502 s
->s_flags
|= MS_ACTIVE
;
1504 mnt
->mnt_root
= mntroot
;
1506 dprintk("<-- nfs_xdev_get_sb() = 0\n");
1510 nfs_free_server(server
);
1512 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error
);
1516 up_write(&s
->s_umount
);
1517 deactivate_super(s
);
1518 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error
);
1522 #ifdef CONFIG_NFS_V4
1525 * Finish setting up a cloned NFS4 superblock
1527 static void nfs4_clone_super(struct super_block
*sb
,
1528 const struct super_block
*old_sb
)
1530 sb
->s_blocksize_bits
= old_sb
->s_blocksize_bits
;
1531 sb
->s_blocksize
= old_sb
->s_blocksize
;
1532 sb
->s_maxbytes
= old_sb
->s_maxbytes
;
1533 sb
->s_time_gran
= 1;
1534 sb
->s_op
= old_sb
->s_op
;
1535 nfs_initialise_sb(sb
);
1539 * Set up an NFS4 superblock
1541 static void nfs4_fill_super(struct super_block
*sb
)
1543 sb
->s_time_gran
= 1;
1544 sb
->s_op
= &nfs4_sops
;
1545 nfs_initialise_sb(sb
);
1549 * Validate NFSv4 mount options
1551 static int nfs4_validate_mount_data(struct nfs4_mount_data
**options
,
1552 const char *dev_name
,
1553 struct sockaddr_in
*addr
,
1554 rpc_authflavor_t
*authflavour
,
1559 struct nfs4_mount_data
*data
= *options
;
1565 switch (data
->version
) {
1567 if (data
->host_addrlen
!= sizeof(*addr
))
1568 goto out_no_address
;
1569 if (copy_from_user(addr
, data
->host_addr
, sizeof(*addr
)))
1571 if (addr
->sin_port
== 0)
1572 addr
->sin_port
= htons(NFS_PORT
);
1573 if (!nfs_verify_server_address((struct sockaddr
*) addr
))
1574 goto out_no_address
;
1576 switch (data
->auth_flavourlen
) {
1578 *authflavour
= RPC_AUTH_UNIX
;
1581 if (copy_from_user(authflavour
, data
->auth_flavours
,
1582 sizeof(*authflavour
)))
1586 goto out_inval_auth
;
1589 c
= strndup_user(data
->hostname
.data
, NFS4_MAXNAMLEN
);
1594 c
= strndup_user(data
->mnt_path
.data
, NFS4_MAXPATHLEN
);
1598 dfprintk(MOUNT
, "NFS: MNTPATH: '%s'\n", *mntpath
);
1600 c
= strndup_user(data
->client_addr
.data
, 16);
1608 struct nfs_parsed_mount_data args
= {
1609 .rsize
= NFS_MAX_FILE_IO_SIZE
,
1610 .wsize
= NFS_MAX_FILE_IO_SIZE
,
1617 .nfs_server
.protocol
= IPPROTO_TCP
,
1620 if (nfs_parse_mount_options((char *) *options
, &args
) == 0)
1623 if (!nfs_verify_server_address((struct sockaddr
*)
1624 &args
.nfs_server
.address
))
1626 *addr
= args
.nfs_server
.address
;
1628 switch (args
.auth_flavor_len
) {
1630 *authflavour
= RPC_AUTH_UNIX
;
1633 *authflavour
= (rpc_authflavor_t
) args
.auth_flavors
[0];
1636 goto out_inval_auth
;
1640 * Translate to nfs4_mount_data, which nfs4_fill_super
1643 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
1649 data
->flags
= args
.flags
& NFS4_MOUNT_FLAGMASK
;
1650 data
->rsize
= args
.rsize
;
1651 data
->wsize
= args
.wsize
;
1652 data
->timeo
= args
.timeo
;
1653 data
->retrans
= args
.retrans
;
1654 data
->acregmin
= args
.acregmin
;
1655 data
->acregmax
= args
.acregmax
;
1656 data
->acdirmin
= args
.acdirmin
;
1657 data
->acdirmax
= args
.acdirmax
;
1658 data
->proto
= args
.nfs_server
.protocol
;
1661 * Split "dev_name" into "hostname:mntpath".
1663 c
= strchr(dev_name
, ':');
1666 /* while calculating len, pretend ':' is '\0' */
1668 if (len
> NFS4_MAXNAMLEN
)
1670 *hostname
= kzalloc(len
, GFP_KERNEL
);
1671 if (*hostname
== NULL
)
1673 strncpy(*hostname
, dev_name
, len
- 1);
1675 c
++; /* step over the ':' */
1677 if (len
> NFS4_MAXPATHLEN
)
1679 *mntpath
= kzalloc(len
+ 1, GFP_KERNEL
);
1680 if (*mntpath
== NULL
)
1682 strncpy(*mntpath
, c
, len
);
1684 dprintk("MNTPATH: %s\n", *mntpath
);
1686 *ip_addr
= args
.client_address
;
1695 dfprintk(MOUNT
, "NFS4: mount program didn't pass any mount data\n");
1699 dfprintk(MOUNT
, "NFS4: Invalid number of RPC auth flavours %d\n",
1700 data
->auth_flavourlen
);
1704 dfprintk(MOUNT
, "NFS4: mount program didn't pass remote address\n");
1709 * Get the superblock for an NFS4 mountpoint
1711 static int nfs4_get_sb(struct file_system_type
*fs_type
,
1712 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
1714 struct nfs4_mount_data
*data
= raw_data
;
1715 struct super_block
*s
;
1716 struct nfs_server
*server
;
1717 struct sockaddr_in addr
;
1718 rpc_authflavor_t authflavour
;
1719 struct nfs_fh mntfh
;
1720 struct dentry
*mntroot
;
1721 char *mntpath
= NULL
, *hostname
= NULL
, *ip_addr
= NULL
;
1722 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
1725 /* Validate the mount data */
1726 error
= nfs4_validate_mount_data(&data
, dev_name
, &addr
, &authflavour
,
1727 &hostname
, &mntpath
, &ip_addr
);
1731 /* Get a volume representation */
1732 server
= nfs4_create_server(data
, hostname
, &addr
, mntpath
, ip_addr
,
1733 authflavour
, &mntfh
);
1734 if (IS_ERR(server
)) {
1735 error
= PTR_ERR(server
);
1739 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
1740 compare_super
= NULL
;
1742 /* Get a superblock - note that we may end up sharing one that already exists */
1743 s
= sget(fs_type
, compare_super
, nfs_set_super
, server
);
1749 if (s
->s_fs_info
!= server
) {
1750 nfs_free_server(server
);
1755 /* initial superblock/root creation */
1760 mntroot
= nfs4_get_root(s
, &mntfh
);
1761 if (IS_ERR(mntroot
)) {
1762 error
= PTR_ERR(mntroot
);
1763 goto error_splat_super
;
1766 s
->s_flags
|= MS_ACTIVE
;
1768 mnt
->mnt_root
= mntroot
;
1778 nfs_free_server(server
);
1782 up_write(&s
->s_umount
);
1783 deactivate_super(s
);
1787 static void nfs4_kill_super(struct super_block
*sb
)
1789 struct nfs_server
*server
= NFS_SB(sb
);
1791 nfs_return_all_delegations(sb
);
1792 kill_anon_super(sb
);
1794 nfs4_renewd_prepare_shutdown(server
);
1795 nfs_free_server(server
);
1799 * Clone an NFS4 server record on xdev traversal (FSID-change)
1801 static int nfs4_xdev_get_sb(struct file_system_type
*fs_type
, int flags
,
1802 const char *dev_name
, void *raw_data
,
1803 struct vfsmount
*mnt
)
1805 struct nfs_clone_mount
*data
= raw_data
;
1806 struct super_block
*s
;
1807 struct nfs_server
*server
;
1808 struct dentry
*mntroot
;
1809 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
1812 dprintk("--> nfs4_xdev_get_sb()\n");
1814 /* create a new volume representation */
1815 server
= nfs_clone_server(NFS_SB(data
->sb
), data
->fh
, data
->fattr
);
1816 if (IS_ERR(server
)) {
1817 error
= PTR_ERR(server
);
1818 goto out_err_noserver
;
1821 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
1822 compare_super
= NULL
;
1824 /* Get a superblock - note that we may end up sharing one that already exists */
1825 s
= sget(&nfs_fs_type
, compare_super
, nfs_set_super
, server
);
1831 if (s
->s_fs_info
!= server
) {
1832 nfs_free_server(server
);
1837 /* initial superblock/root creation */
1839 nfs4_clone_super(s
, data
->sb
);
1842 mntroot
= nfs4_get_root(s
, data
->fh
);
1843 if (IS_ERR(mntroot
)) {
1844 error
= PTR_ERR(mntroot
);
1845 goto error_splat_super
;
1848 s
->s_flags
|= MS_ACTIVE
;
1850 mnt
->mnt_root
= mntroot
;
1852 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
1856 nfs_free_server(server
);
1858 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error
);
1862 up_write(&s
->s_umount
);
1863 deactivate_super(s
);
1864 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error
);
1869 * Create an NFS4 server record on referral traversal
1871 static int nfs4_referral_get_sb(struct file_system_type
*fs_type
, int flags
,
1872 const char *dev_name
, void *raw_data
,
1873 struct vfsmount
*mnt
)
1875 struct nfs_clone_mount
*data
= raw_data
;
1876 struct super_block
*s
;
1877 struct nfs_server
*server
;
1878 struct dentry
*mntroot
;
1879 struct nfs_fh mntfh
;
1880 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
1883 dprintk("--> nfs4_referral_get_sb()\n");
1885 /* create a new volume representation */
1886 server
= nfs4_create_referral_server(data
, &mntfh
);
1887 if (IS_ERR(server
)) {
1888 error
= PTR_ERR(server
);
1889 goto out_err_noserver
;
1892 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
1893 compare_super
= NULL
;
1895 /* Get a superblock - note that we may end up sharing one that already exists */
1896 s
= sget(&nfs_fs_type
, compare_super
, nfs_set_super
, server
);
1902 if (s
->s_fs_info
!= server
) {
1903 nfs_free_server(server
);
1908 /* initial superblock/root creation */
1913 mntroot
= nfs4_get_root(s
, &mntfh
);
1914 if (IS_ERR(mntroot
)) {
1915 error
= PTR_ERR(mntroot
);
1916 goto error_splat_super
;
1919 s
->s_flags
|= MS_ACTIVE
;
1921 mnt
->mnt_root
= mntroot
;
1923 dprintk("<-- nfs4_referral_get_sb() = 0\n");
1927 nfs_free_server(server
);
1929 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error
);
1933 up_write(&s
->s_umount
);
1934 deactivate_super(s
);
1935 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error
);
1939 #endif /* CONFIG_NFS_V4 */