4 * Copyright (C) 1992 Rick Sladkey
6 * nfs superblock handling functions
8 * Modularised by Alan Cox <Alan.Cox@linux.org>, while hacking some
9 * experimental NFS changes. Modularisation taken straight from SYS5 fs.
11 * Change to nfs_read_super() to permit NFS mounts to multi-homed hosts.
12 * J.S.Peatfield@damtp.cam.ac.uk
14 * Split from inode.c by David Howells <dhowells@redhat.com>
16 * - superblocks are indexed on server only - all inodes, dentries, etc. associated with a
17 * particular server are held in the same superblock
18 * - NFS superblocks can have several effective roots to the dentry tree
19 * - directory type roots are spliced into the tree when a path from one root reaches the root
20 * of another (see nfs_lookup())
23 #include <linux/module.h>
24 #include <linux/init.h>
26 #include <linux/time.h>
27 #include <linux/kernel.h>
29 #include <linux/string.h>
30 #include <linux/stat.h>
31 #include <linux/errno.h>
32 #include <linux/unistd.h>
33 #include <linux/sunrpc/clnt.h>
34 #include <linux/sunrpc/stats.h>
35 #include <linux/sunrpc/metrics.h>
36 #include <linux/sunrpc/xprtsock.h>
37 #include <linux/sunrpc/xprtrdma.h>
38 #include <linux/nfs_fs.h>
39 #include <linux/nfs_mount.h>
40 #include <linux/nfs4_mount.h>
41 #include <linux/lockd/bind.h>
42 #include <linux/smp_lock.h>
43 #include <linux/seq_file.h>
44 #include <linux/mount.h>
45 #include <linux/nfs_idmap.h>
46 #include <linux/vfs.h>
47 #include <linux/inet.h>
48 #include <linux/in6.h>
50 #include <linux/nfs_xdr.h>
51 #include <linux/magic.h>
52 #include <linux/parser.h>
54 #include <asm/system.h>
55 #include <asm/uaccess.h>
59 #include "delegation.h"
63 #define NFSDBG_FACILITY NFSDBG_VFS
66 /* Mount options that take no arguments */
69 Opt_posix
, Opt_noposix
,
74 Opt_udp
, Opt_tcp
, Opt_rdma
,
76 Opt_rdirplus
, Opt_nordirplus
,
77 Opt_sharecache
, Opt_nosharecache
,
79 /* Mount options that take integer arguments */
81 Opt_rsize
, Opt_wsize
, Opt_bsize
,
82 Opt_timeo
, Opt_retrans
,
83 Opt_acregmin
, Opt_acregmax
,
84 Opt_acdirmin
, Opt_acdirmax
,
91 /* Mount options that take string arguments */
92 Opt_sec
, Opt_proto
, Opt_mountproto
, Opt_mounthost
,
93 Opt_addr
, Opt_mountaddr
, Opt_clientaddr
,
95 /* Mount options that are ignored */
96 Opt_userspace
, Opt_deprecated
,
101 static match_table_t nfs_mount_option_tokens
= {
102 { Opt_userspace
, "bg" },
103 { Opt_userspace
, "fg" },
104 { Opt_soft
, "soft" },
105 { Opt_hard
, "hard" },
106 { Opt_intr
, "intr" },
107 { Opt_nointr
, "nointr" },
108 { Opt_posix
, "posix" },
109 { Opt_noposix
, "noposix" },
111 { Opt_nocto
, "nocto" },
113 { Opt_noac
, "noac" },
114 { Opt_lock
, "lock" },
115 { Opt_nolock
, "nolock" },
120 { Opt_rdma
, "rdma" },
122 { Opt_noacl
, "noacl" },
123 { Opt_rdirplus
, "rdirplus" },
124 { Opt_nordirplus
, "nordirplus" },
125 { Opt_sharecache
, "sharecache" },
126 { Opt_nosharecache
, "nosharecache" },
128 { Opt_port
, "port=%u" },
129 { Opt_rsize
, "rsize=%u" },
130 { Opt_wsize
, "wsize=%u" },
131 { Opt_bsize
, "bsize=%u" },
132 { Opt_timeo
, "timeo=%u" },
133 { Opt_retrans
, "retrans=%u" },
134 { Opt_acregmin
, "acregmin=%u" },
135 { Opt_acregmax
, "acregmax=%u" },
136 { Opt_acdirmin
, "acdirmin=%u" },
137 { Opt_acdirmax
, "acdirmax=%u" },
138 { Opt_actimeo
, "actimeo=%u" },
139 { Opt_userspace
, "retry=%u" },
140 { Opt_namelen
, "namlen=%u" },
141 { Opt_mountport
, "mountport=%u" },
142 { Opt_mountvers
, "mountvers=%u" },
143 { Opt_nfsvers
, "nfsvers=%u" },
144 { Opt_nfsvers
, "vers=%u" },
146 { Opt_sec
, "sec=%s" },
147 { Opt_proto
, "proto=%s" },
148 { Opt_mountproto
, "mountproto=%s" },
149 { Opt_addr
, "addr=%s" },
150 { Opt_clientaddr
, "clientaddr=%s" },
151 { Opt_mounthost
, "mounthost=%s" },
152 { Opt_mountaddr
, "mountaddr=%s" },
158 Opt_xprt_udp
, Opt_xprt_tcp
, Opt_xprt_rdma
,
163 static match_table_t nfs_xprt_protocol_tokens
= {
164 { Opt_xprt_udp
, "udp" },
165 { Opt_xprt_tcp
, "tcp" },
166 { Opt_xprt_rdma
, "rdma" },
168 { Opt_xprt_err
, NULL
}
172 Opt_sec_none
, Opt_sec_sys
,
173 Opt_sec_krb5
, Opt_sec_krb5i
, Opt_sec_krb5p
,
174 Opt_sec_lkey
, Opt_sec_lkeyi
, Opt_sec_lkeyp
,
175 Opt_sec_spkm
, Opt_sec_spkmi
, Opt_sec_spkmp
,
180 static match_table_t nfs_secflavor_tokens
= {
181 { Opt_sec_none
, "none" },
182 { Opt_sec_none
, "null" },
183 { Opt_sec_sys
, "sys" },
185 { Opt_sec_krb5
, "krb5" },
186 { Opt_sec_krb5i
, "krb5i" },
187 { Opt_sec_krb5p
, "krb5p" },
189 { Opt_sec_lkey
, "lkey" },
190 { Opt_sec_lkeyi
, "lkeyi" },
191 { Opt_sec_lkeyp
, "lkeyp" },
193 { Opt_sec_spkm
, "spkm3" },
194 { Opt_sec_spkmi
, "spkm3i" },
195 { Opt_sec_spkmp
, "spkm3p" },
197 { Opt_sec_err
, NULL
}
201 static void nfs_umount_begin(struct vfsmount
*, int);
202 static int nfs_statfs(struct dentry
*, struct kstatfs
*);
203 static int nfs_show_options(struct seq_file
*, struct vfsmount
*);
204 static int nfs_show_stats(struct seq_file
*, struct vfsmount
*);
205 static int nfs_get_sb(struct file_system_type
*, int, const char *, void *, struct vfsmount
*);
206 static int nfs_xdev_get_sb(struct file_system_type
*fs_type
,
207 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
208 static void nfs_kill_super(struct super_block
*);
209 static void nfs_put_super(struct super_block
*);
211 static struct file_system_type nfs_fs_type
= {
212 .owner
= THIS_MODULE
,
214 .get_sb
= nfs_get_sb
,
215 .kill_sb
= nfs_kill_super
,
216 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
219 struct file_system_type nfs_xdev_fs_type
= {
220 .owner
= THIS_MODULE
,
222 .get_sb
= nfs_xdev_get_sb
,
223 .kill_sb
= nfs_kill_super
,
224 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
227 static const struct super_operations nfs_sops
= {
228 .alloc_inode
= nfs_alloc_inode
,
229 .destroy_inode
= nfs_destroy_inode
,
230 .write_inode
= nfs_write_inode
,
231 .put_super
= nfs_put_super
,
232 .statfs
= nfs_statfs
,
233 .clear_inode
= nfs_clear_inode
,
234 .umount_begin
= nfs_umount_begin
,
235 .show_options
= nfs_show_options
,
236 .show_stats
= nfs_show_stats
,
240 static int nfs4_get_sb(struct file_system_type
*fs_type
,
241 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
242 static int nfs4_xdev_get_sb(struct file_system_type
*fs_type
,
243 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
244 static int nfs4_referral_get_sb(struct file_system_type
*fs_type
,
245 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
246 static void nfs4_kill_super(struct super_block
*sb
);
248 static struct file_system_type nfs4_fs_type
= {
249 .owner
= THIS_MODULE
,
251 .get_sb
= nfs4_get_sb
,
252 .kill_sb
= nfs4_kill_super
,
253 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
256 struct file_system_type nfs4_xdev_fs_type
= {
257 .owner
= THIS_MODULE
,
259 .get_sb
= nfs4_xdev_get_sb
,
260 .kill_sb
= nfs4_kill_super
,
261 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
264 struct file_system_type nfs4_referral_fs_type
= {
265 .owner
= THIS_MODULE
,
267 .get_sb
= nfs4_referral_get_sb
,
268 .kill_sb
= nfs4_kill_super
,
269 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
272 static const struct super_operations nfs4_sops
= {
273 .alloc_inode
= nfs_alloc_inode
,
274 .destroy_inode
= nfs_destroy_inode
,
275 .write_inode
= nfs_write_inode
,
276 .statfs
= nfs_statfs
,
277 .clear_inode
= nfs4_clear_inode
,
278 .umount_begin
= nfs_umount_begin
,
279 .show_options
= nfs_show_options
,
280 .show_stats
= nfs_show_stats
,
284 static struct shrinker acl_shrinker
= {
285 .shrink
= nfs_access_cache_shrinker
,
286 .seeks
= DEFAULT_SEEKS
,
290 * Register the NFS filesystems
292 int __init
register_nfs_fs(void)
296 ret
= register_filesystem(&nfs_fs_type
);
300 ret
= nfs_register_sysctl();
304 ret
= register_filesystem(&nfs4_fs_type
);
308 register_shrinker(&acl_shrinker
);
313 nfs_unregister_sysctl();
316 unregister_filesystem(&nfs_fs_type
);
322 * Unregister the NFS filesystems
324 void __exit
unregister_nfs_fs(void)
326 unregister_shrinker(&acl_shrinker
);
328 unregister_filesystem(&nfs4_fs_type
);
330 nfs_unregister_sysctl();
331 unregister_filesystem(&nfs_fs_type
);
334 void nfs_sb_active(struct nfs_server
*server
)
336 atomic_inc(&server
->active
);
339 void nfs_sb_deactive(struct nfs_server
*server
)
341 if (atomic_dec_and_test(&server
->active
))
342 wake_up(&server
->active_wq
);
345 static void nfs_put_super(struct super_block
*sb
)
347 struct nfs_server
*server
= NFS_SB(sb
);
349 * Make sure there are no outstanding ops to this server.
350 * If so, wait for them to finish before allowing the
351 * unmount to continue.
353 wait_event(server
->active_wq
, atomic_read(&server
->active
) == 0);
357 * Deliver file system statistics to userspace
359 static int nfs_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
361 struct nfs_server
*server
= NFS_SB(dentry
->d_sb
);
362 unsigned char blockbits
;
363 unsigned long blockres
;
364 struct nfs_fh
*fh
= NFS_FH(dentry
->d_inode
);
365 struct nfs_fattr fattr
;
366 struct nfs_fsstat res
= {
373 error
= server
->nfs_client
->rpc_ops
->statfs(server
, fh
, &res
);
376 buf
->f_type
= NFS_SUPER_MAGIC
;
379 * Current versions of glibc do not correctly handle the
380 * case where f_frsize != f_bsize. Eventually we want to
381 * report the value of wtmult in this field.
383 buf
->f_frsize
= dentry
->d_sb
->s_blocksize
;
386 * On most *nix systems, f_blocks, f_bfree, and f_bavail
387 * are reported in units of f_frsize. Linux hasn't had
388 * an f_frsize field in its statfs struct until recently,
389 * thus historically Linux's sys_statfs reports these
390 * fields in units of f_bsize.
392 buf
->f_bsize
= dentry
->d_sb
->s_blocksize
;
393 blockbits
= dentry
->d_sb
->s_blocksize_bits
;
394 blockres
= (1 << blockbits
) - 1;
395 buf
->f_blocks
= (res
.tbytes
+ blockres
) >> blockbits
;
396 buf
->f_bfree
= (res
.fbytes
+ blockres
) >> blockbits
;
397 buf
->f_bavail
= (res
.abytes
+ blockres
) >> blockbits
;
399 buf
->f_files
= res
.tfiles
;
400 buf
->f_ffree
= res
.afiles
;
402 buf
->f_namelen
= server
->namelen
;
408 dprintk("%s: statfs error = %d\n", __FUNCTION__
, -error
);
414 * Map the security flavour number to a name
416 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour
)
418 static const struct {
419 rpc_authflavor_t flavour
;
422 { RPC_AUTH_NULL
, "null" },
423 { RPC_AUTH_UNIX
, "sys" },
424 { RPC_AUTH_GSS_KRB5
, "krb5" },
425 { RPC_AUTH_GSS_KRB5I
, "krb5i" },
426 { RPC_AUTH_GSS_KRB5P
, "krb5p" },
427 { RPC_AUTH_GSS_LKEY
, "lkey" },
428 { RPC_AUTH_GSS_LKEYI
, "lkeyi" },
429 { RPC_AUTH_GSS_LKEYP
, "lkeyp" },
430 { RPC_AUTH_GSS_SPKM
, "spkm" },
431 { RPC_AUTH_GSS_SPKMI
, "spkmi" },
432 { RPC_AUTH_GSS_SPKMP
, "spkmp" },
433 { UINT_MAX
, "unknown" }
437 for (i
= 0; sec_flavours
[i
].flavour
!= UINT_MAX
; i
++) {
438 if (sec_flavours
[i
].flavour
== flavour
)
441 return sec_flavours
[i
].str
;
445 * Describe the mount options in force on this server representation
447 static void nfs_show_mount_options(struct seq_file
*m
, struct nfs_server
*nfss
, int showdefaults
)
449 static const struct proc_nfs_info
{
454 { NFS_MOUNT_SOFT
, ",soft", ",hard" },
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
;
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 seq_printf(m
, ",proto=%s",
484 rpc_peeraddr2str(nfss
->client
, RPC_DISPLAY_PROTO
));
485 seq_printf(m
, ",timeo=%lu", 10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
);
486 seq_printf(m
, ",retrans=%u", nfss
->client
->cl_timeout
->to_retries
);
487 seq_printf(m
, ",sec=%s", nfs_pseudoflavour_to_name(nfss
->client
->cl_auth
->au_flavor
));
491 * Describe the mount options on this VFS mountpoint
493 static int nfs_show_options(struct seq_file
*m
, struct vfsmount
*mnt
)
495 struct nfs_server
*nfss
= NFS_SB(mnt
->mnt_sb
);
497 nfs_show_mount_options(m
, nfss
, 0);
499 seq_printf(m
, ",addr=%s",
500 rpc_peeraddr2str(nfss
->nfs_client
->cl_rpcclient
,
507 * Present statistical information for this VFS mountpoint
509 static int nfs_show_stats(struct seq_file
*m
, struct vfsmount
*mnt
)
512 struct nfs_server
*nfss
= NFS_SB(mnt
->mnt_sb
);
513 struct rpc_auth
*auth
= nfss
->client
->cl_auth
;
514 struct nfs_iostats totals
= { };
516 seq_printf(m
, "statvers=%s", NFS_IOSTAT_VERS
);
519 * Display all mount option settings
521 seq_printf(m
, "\n\topts:\t");
522 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_RDONLY
? "ro" : "rw");
523 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_SYNCHRONOUS
? ",sync" : "");
524 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_NOATIME
? ",noatime" : "");
525 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_NODIRATIME
? ",nodiratime" : "");
526 nfs_show_mount_options(m
, nfss
, 1);
528 seq_printf(m
, "\n\tage:\t%lu", (jiffies
- nfss
->mount_time
) / HZ
);
530 seq_printf(m
, "\n\tcaps:\t");
531 seq_printf(m
, "caps=0x%x", nfss
->caps
);
532 seq_printf(m
, ",wtmult=%d", nfss
->wtmult
);
533 seq_printf(m
, ",dtsize=%d", nfss
->dtsize
);
534 seq_printf(m
, ",bsize=%d", nfss
->bsize
);
535 seq_printf(m
, ",namelen=%d", nfss
->namelen
);
538 if (nfss
->nfs_client
->rpc_ops
->version
== 4) {
539 seq_printf(m
, "\n\tnfsv4:\t");
540 seq_printf(m
, "bm0=0x%x", nfss
->attr_bitmask
[0]);
541 seq_printf(m
, ",bm1=0x%x", nfss
->attr_bitmask
[1]);
542 seq_printf(m
, ",acl=0x%x", nfss
->acl_bitmask
);
547 * Display security flavor in effect for this mount
549 seq_printf(m
, "\n\tsec:\tflavor=%d", auth
->au_ops
->au_flavor
);
551 seq_printf(m
, ",pseudoflavor=%d", auth
->au_flavor
);
554 * Display superblock I/O counters
556 for_each_possible_cpu(cpu
) {
557 struct nfs_iostats
*stats
;
560 stats
= per_cpu_ptr(nfss
->io_stats
, cpu
);
562 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
563 totals
.events
[i
] += stats
->events
[i
];
564 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
565 totals
.bytes
[i
] += stats
->bytes
[i
];
570 seq_printf(m
, "\n\tevents:\t");
571 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
572 seq_printf(m
, "%lu ", totals
.events
[i
]);
573 seq_printf(m
, "\n\tbytes:\t");
574 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
575 seq_printf(m
, "%Lu ", totals
.bytes
[i
]);
578 rpc_print_iostats(m
, nfss
->client
);
584 * Begin unmount by attempting to remove all automounted mountpoints we added
585 * in response to xdev traversals and referrals
587 static void nfs_umount_begin(struct vfsmount
*vfsmnt
, int flags
)
589 struct nfs_server
*server
= NFS_SB(vfsmnt
->mnt_sb
);
590 struct rpc_clnt
*rpc
;
592 shrink_submounts(vfsmnt
, &nfs_automount_list
);
594 if (!(flags
& MNT_FORCE
))
596 /* -EIO all pending I/O */
597 rpc
= server
->client_acl
;
599 rpc_killall_tasks(rpc
);
600 rpc
= server
->client
;
602 rpc_killall_tasks(rpc
);
606 * Set the port number in an address. Be agnostic about the address family.
608 static void nfs_set_port(struct sockaddr
*sap
, unsigned short port
)
610 switch (sap
->sa_family
) {
612 struct sockaddr_in
*ap
= (struct sockaddr_in
*)sap
;
613 ap
->sin_port
= htons(port
);
617 struct sockaddr_in6
*ap
= (struct sockaddr_in6
*)sap
;
618 ap
->sin6_port
= htons(port
);
625 * Sanity-check a server address provided by the mount command.
627 * Address family must be initialized, and address must not be
628 * the ANY address for that family.
630 static int nfs_verify_server_address(struct sockaddr
*addr
)
632 switch (addr
->sa_family
) {
634 struct sockaddr_in
*sa
= (struct sockaddr_in
*)addr
;
635 return sa
->sin_addr
.s_addr
!= INADDR_ANY
;
638 struct in6_addr
*sa
= &((struct sockaddr_in6
*)addr
)->sin6_addr
;
639 return !ipv6_addr_any(sa
);
647 * Parse string addresses passed in via a mount option,
648 * and construct a sockaddr based on the result.
650 * If address parsing fails, set the sockaddr's address
651 * family to AF_UNSPEC to force nfs_verify_server_address()
654 static void nfs_parse_server_address(char *value
,
655 struct sockaddr
*sap
,
658 if (strchr(value
, ':')) {
659 struct sockaddr_in6
*ap
= (struct sockaddr_in6
*)sap
;
660 u8
*addr
= (u8
*)&ap
->sin6_addr
.in6_u
;
662 ap
->sin6_family
= AF_INET6
;
664 if (in6_pton(value
, -1, addr
, '\0', NULL
))
667 struct sockaddr_in
*ap
= (struct sockaddr_in
*)sap
;
668 u8
*addr
= (u8
*)&ap
->sin_addr
.s_addr
;
670 ap
->sin_family
= AF_INET
;
672 if (in4_pton(value
, -1, addr
, '\0', NULL
))
676 sap
->sa_family
= AF_UNSPEC
;
681 * Error-check and convert a string of mount options from user space into
684 static int nfs_parse_mount_options(char *raw
,
685 struct nfs_parsed_mount_data
*mnt
)
687 <<<<<<< HEAD
:fs
/nfs
/super
.c
690 char *p
, *string
, *secdata
;
691 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:fs
/nfs
/super
.c
692 unsigned short port
= 0;
693 <<<<<<< HEAD
:fs
/nfs
/super
.c
696 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:fs
/nfs
/super
.c
699 dfprintk(MOUNT
, "NFS: mount options string was NULL.\n");
702 dfprintk(MOUNT
, "NFS: nfs mount opts='%s'\n", raw
);
704 <<<<<<< HEAD
:fs
/nfs
/super
.c
706 secdata
= alloc_secdata();
710 rc
= security_sb_copy_data(raw
, secdata
);
712 goto out_security_failure
;
714 rc
= security_sb_parse_opts_str(secdata
, &mnt
->lsm_opts
);
716 goto out_security_failure
;
718 free_secdata(secdata
);
720 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:fs
/nfs
/super
.c
721 while ((p
= strsep(&raw
, ",")) != NULL
) {
722 substring_t args
[MAX_OPT_ARGS
];
728 dfprintk(MOUNT
, "NFS: parsing nfs mount option '%s'\n", p
);
730 token
= match_token(p
, nfs_mount_option_tokens
, args
);
733 mnt
->flags
|= NFS_MOUNT_SOFT
;
736 mnt
->flags
&= ~NFS_MOUNT_SOFT
;
742 mnt
->flags
|= NFS_MOUNT_POSIX
;
745 mnt
->flags
&= ~NFS_MOUNT_POSIX
;
748 mnt
->flags
&= ~NFS_MOUNT_NOCTO
;
751 mnt
->flags
|= NFS_MOUNT_NOCTO
;
754 mnt
->flags
&= ~NFS_MOUNT_NOAC
;
757 mnt
->flags
|= NFS_MOUNT_NOAC
;
760 mnt
->flags
&= ~NFS_MOUNT_NONLM
;
763 mnt
->flags
|= NFS_MOUNT_NONLM
;
766 mnt
->flags
&= ~NFS_MOUNT_VER3
;
769 mnt
->flags
|= NFS_MOUNT_VER3
;
772 mnt
->flags
&= ~NFS_MOUNT_TCP
;
773 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
778 mnt
->flags
|= NFS_MOUNT_TCP
;
779 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
784 mnt
->flags
|= NFS_MOUNT_TCP
; /* for side protocols */
785 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_RDMA
;
790 mnt
->flags
&= ~NFS_MOUNT_NOACL
;
793 mnt
->flags
|= NFS_MOUNT_NOACL
;
796 mnt
->flags
&= ~NFS_MOUNT_NORDIRPLUS
;
799 mnt
->flags
|= NFS_MOUNT_NORDIRPLUS
;
802 mnt
->flags
&= ~NFS_MOUNT_UNSHARED
;
804 case Opt_nosharecache
:
805 mnt
->flags
|= NFS_MOUNT_UNSHARED
;
809 if (match_int(args
, &option
))
811 if (option
< 0 || option
> 65535)
816 if (match_int(args
, &mnt
->rsize
))
820 if (match_int(args
, &mnt
->wsize
))
824 if (match_int(args
, &option
))
831 if (match_int(args
, &mnt
->timeo
))
835 if (match_int(args
, &mnt
->retrans
))
839 if (match_int(args
, &mnt
->acregmin
))
843 if (match_int(args
, &mnt
->acregmax
))
847 if (match_int(args
, &mnt
->acdirmin
))
851 if (match_int(args
, &mnt
->acdirmax
))
855 if (match_int(args
, &option
))
862 mnt
->acdirmax
= option
;
865 if (match_int(args
, &mnt
->namlen
))
869 if (match_int(args
, &option
))
871 if (option
< 0 || option
> 65535)
873 mnt
->mount_server
.port
= option
;
876 if (match_int(args
, &option
))
880 mnt
->mount_server
.version
= option
;
883 if (match_int(args
, &option
))
887 mnt
->flags
&= ~NFS_MOUNT_VER3
;
890 mnt
->flags
|= NFS_MOUNT_VER3
;
898 string
= match_strdup(args
);
901 token
= match_token(string
, nfs_secflavor_tokens
, args
);
905 * The flags setting is for v2/v3. The flavor_len
906 * setting is for v4. v2/v3 also need to know the
907 * difference between NULL and UNIX.
911 mnt
->flags
&= ~NFS_MOUNT_SECFLAVOUR
;
912 mnt
->auth_flavor_len
= 0;
913 mnt
->auth_flavors
[0] = RPC_AUTH_NULL
;
916 mnt
->flags
&= ~NFS_MOUNT_SECFLAVOUR
;
917 mnt
->auth_flavor_len
= 0;
918 mnt
->auth_flavors
[0] = RPC_AUTH_UNIX
;
921 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
922 mnt
->auth_flavor_len
= 1;
923 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5
;
926 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
927 mnt
->auth_flavor_len
= 1;
928 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5I
;
931 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
932 mnt
->auth_flavor_len
= 1;
933 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5P
;
936 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
937 mnt
->auth_flavor_len
= 1;
938 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEY
;
941 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
942 mnt
->auth_flavor_len
= 1;
943 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEYI
;
946 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
947 mnt
->auth_flavor_len
= 1;
948 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEYP
;
951 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
952 mnt
->auth_flavor_len
= 1;
953 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKM
;
956 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
957 mnt
->auth_flavor_len
= 1;
958 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKMI
;
961 mnt
->flags
|= NFS_MOUNT_SECFLAVOUR
;
962 mnt
->auth_flavor_len
= 1;
963 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKMP
;
970 string
= match_strdup(args
);
973 token
= match_token(string
,
974 nfs_xprt_protocol_tokens
, args
);
979 mnt
->flags
&= ~NFS_MOUNT_TCP
;
980 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
985 mnt
->flags
|= NFS_MOUNT_TCP
;
986 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
991 /* vector side protocols to TCP */
992 mnt
->flags
|= NFS_MOUNT_TCP
;
993 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_RDMA
;
1001 case Opt_mountproto
:
1002 string
= match_strdup(args
);
1005 token
= match_token(string
,
1006 nfs_xprt_protocol_tokens
, args
);
1011 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_UDP
;
1014 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_TCP
;
1016 case Opt_xprt_rdma
: /* not used for side protocols */
1018 goto out_unrec_xprt
;
1022 string
= match_strdup(args
);
1025 nfs_parse_server_address(string
, (struct sockaddr
*)
1026 &mnt
->nfs_server
.address
,
1027 &mnt
->nfs_server
.addrlen
);
1030 case Opt_clientaddr
:
1031 string
= match_strdup(args
);
1034 kfree(mnt
->client_address
);
1035 mnt
->client_address
= string
;
1038 string
= match_strdup(args
);
1041 kfree(mnt
->mount_server
.hostname
);
1042 mnt
->mount_server
.hostname
= string
;
1045 string
= match_strdup(args
);
1048 nfs_parse_server_address(string
, (struct sockaddr
*)
1049 &mnt
->mount_server
.address
,
1050 &mnt
->mount_server
.addrlen
);
1055 case Opt_deprecated
:
1063 nfs_set_port((struct sockaddr
*)&mnt
->nfs_server
.address
, port
);
1068 printk(KERN_INFO
"NFS: not enough memory to parse option\n");
1070 <<<<<<< HEAD
:fs
/nfs
/super
.c
1073 out_security_failure
:
1074 free_secdata(secdata
);
1075 printk(KERN_INFO
"NFS: security options invalid: %d\n", rc
);
1077 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:fs
/nfs
/super
.c
1079 printk(KERN_INFO
"NFS: unrecognized NFS version number\n");
1083 printk(KERN_INFO
"NFS: unrecognized transport protocol\n");
1087 printk(KERN_INFO
"NFS: unrecognized security flavor\n");
1091 printk(KERN_INFO
"NFS: unknown mount option: %s\n", p
);
1096 * Use the remote server's MOUNT service to request the NFS file handle
1097 * corresponding to the provided path.
1099 static int nfs_try_mount(struct nfs_parsed_mount_data
*args
,
1100 struct nfs_fh
*root_fh
)
1102 struct sockaddr
*sap
= (struct sockaddr
*)&args
->mount_server
.address
;
1106 if (args
->mount_server
.version
== 0) {
1107 if (args
->flags
& NFS_MOUNT_VER3
)
1108 args
->mount_server
.version
= NFS_MNT3_VERSION
;
1110 args
->mount_server
.version
= NFS_MNT_VERSION
;
1113 if (args
->mount_server
.hostname
)
1114 hostname
= args
->mount_server
.hostname
;
1116 hostname
= args
->nfs_server
.hostname
;
1119 * Construct the mount server's address.
1121 if (args
->mount_server
.address
.ss_family
== AF_UNSPEC
) {
1122 memcpy(sap
, &args
->nfs_server
.address
,
1123 args
->nfs_server
.addrlen
);
1124 args
->mount_server
.addrlen
= args
->nfs_server
.addrlen
;
1128 * autobind will be used if mount_server.port == 0
1130 nfs_set_port(sap
, args
->mount_server
.port
);
1133 * Now ask the mount server to map our export path
1136 status
= nfs_mount(sap
,
1137 args
->mount_server
.addrlen
,
1139 args
->nfs_server
.export_path
,
1140 args
->mount_server
.version
,
1141 args
->mount_server
.protocol
,
1146 dfprintk(MOUNT
, "NFS: unable to mount server %s, error %d",
1152 * Validate the NFS2/NFS3 mount data
1153 * - fills in the mount root filehandle
1155 * For option strings, user space handles the following behaviors:
1157 * + DNS: mapping server host name to IP address ("addr=" option)
1159 * + failure mode: how to behave if a mount request can't be handled
1160 * immediately ("fg/bg" option)
1162 * + retry: how often to retry a mount request ("retry=" option)
1164 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1165 * mountproto=tcp after mountproto=udp, and so on
1167 static int nfs_validate_mount_data(void *options
,
1168 struct nfs_parsed_mount_data
*args
,
1169 struct nfs_fh
*mntfh
,
1170 const char *dev_name
)
1172 struct nfs_mount_data
*data
= (struct nfs_mount_data
*)options
;
1174 memset(args
, 0, sizeof(*args
));
1179 args
->flags
= (NFS_MOUNT_VER3
| NFS_MOUNT_TCP
);
1180 args
->rsize
= NFS_MAX_FILE_IO_SIZE
;
1181 args
->wsize
= NFS_MAX_FILE_IO_SIZE
;
1185 args
->acregmax
= 60;
1186 args
->acdirmin
= 30;
1187 args
->acdirmax
= 60;
1188 args
->mount_server
.protocol
= XPRT_TRANSPORT_UDP
;
1189 args
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1191 switch (data
->version
) {
1197 if (data
->flags
& NFS_MOUNT_VER3
)
1199 data
->root
.size
= NFS2_FHSIZE
;
1200 memcpy(data
->root
.data
, data
->old_root
.data
, NFS2_FHSIZE
);
1202 if (data
->flags
& NFS_MOUNT_SECFLAVOUR
)
1205 memset(data
->context
, 0, sizeof(data
->context
));
1207 if (data
->flags
& NFS_MOUNT_VER3
)
1208 mntfh
->size
= data
->root
.size
;
1210 mntfh
->size
= NFS2_FHSIZE
;
1212 if (mntfh
->size
> sizeof(mntfh
->data
))
1213 goto out_invalid_fh
;
1215 memcpy(mntfh
->data
, data
->root
.data
, mntfh
->size
);
1216 if (mntfh
->size
< sizeof(mntfh
->data
))
1217 memset(mntfh
->data
+ mntfh
->size
, 0,
1218 sizeof(mntfh
->data
) - mntfh
->size
);
1221 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1224 args
->flags
= data
->flags
;
1225 args
->rsize
= data
->rsize
;
1226 args
->wsize
= data
->wsize
;
1227 args
->flags
= data
->flags
;
1228 args
->timeo
= data
->timeo
;
1229 args
->retrans
= data
->retrans
;
1230 args
->acregmin
= data
->acregmin
;
1231 args
->acregmax
= data
->acregmax
;
1232 args
->acdirmin
= data
->acdirmin
;
1233 args
->acdirmax
= data
->acdirmax
;
1235 memcpy(&args
->nfs_server
.address
, &data
->addr
,
1236 sizeof(data
->addr
));
1237 args
->nfs_server
.addrlen
= sizeof(data
->addr
);
1238 if (!nfs_verify_server_address((struct sockaddr
*)
1239 &args
->nfs_server
.address
))
1240 goto out_no_address
;
1242 if (!(data
->flags
& NFS_MOUNT_TCP
))
1243 args
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1244 /* N.B. caller will free nfs_server.hostname in all cases */
1245 args
->nfs_server
.hostname
= kstrdup(data
->hostname
, GFP_KERNEL
);
1246 args
->namlen
= data
->namlen
;
1247 args
->bsize
= data
->bsize
;
1248 args
->auth_flavors
[0] = data
->pseudoflavor
;
1249 <<<<<<< HEAD
:fs
/nfs
/super
.c
1253 * The legacy version 6 binary mount data from userspace has a
1254 * field used only to transport selinux information into the
1255 * the kernel. To continue to support that functionality we
1256 * have a touch of selinux knowledge here in the NFS code. The
1257 * userspace code converted context=blah to just blah so we are
1258 * converting back to the full string selinux understands.
1260 if (data
->context
[0]){
1261 #ifdef CONFIG_SECURITY_SELINUX
1263 char *opts_str
= kmalloc(sizeof(data
->context
) + 8, GFP_KERNEL
);
1266 strcpy(opts_str
, "context=");
1267 data
->context
[NFS_MAX_CONTEXT_LEN
] = '\0';
1268 strcat(opts_str
, &data
->context
[0]);
1269 rc
= security_sb_parse_opts_str(opts_str
, &args
->lsm_opts
);
1278 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:fs
/nfs
/super
.c
1285 if (nfs_parse_mount_options((char *)options
, args
) == 0)
1288 if (!nfs_verify_server_address((struct sockaddr
*)
1289 &args
->nfs_server
.address
))
1290 goto out_no_address
;
1292 c
= strchr(dev_name
, ':');
1296 /* N.B. caller will free nfs_server.hostname in all cases */
1297 args
->nfs_server
.hostname
= kstrndup(dev_name
, len
, GFP_KERNEL
);
1300 if (strlen(c
) > NFS_MAXPATHLEN
)
1301 return -ENAMETOOLONG
;
1302 args
->nfs_server
.export_path
= c
;
1304 status
= nfs_try_mount(args
, mntfh
);
1312 if (!(args
->flags
& NFS_MOUNT_SECFLAVOUR
))
1313 args
->auth_flavors
[0] = RPC_AUTH_UNIX
;
1315 #ifndef CONFIG_NFS_V3
1316 if (args
->flags
& NFS_MOUNT_VER3
)
1317 goto out_v3_not_compiled
;
1318 #endif /* !CONFIG_NFS_V3 */
1323 dfprintk(MOUNT
, "NFS: mount program didn't pass any mount data\n");
1327 dfprintk(MOUNT
, "NFS: nfs_mount_data version %d does not support v3\n",
1332 dfprintk(MOUNT
, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1335 #ifndef CONFIG_NFS_V3
1336 out_v3_not_compiled
:
1337 dfprintk(MOUNT
, "NFS: NFSv3 is not compiled into kernel\n");
1338 return -EPROTONOSUPPORT
;
1339 #endif /* !CONFIG_NFS_V3 */
1342 dfprintk(MOUNT
, "NFS: mount program didn't pass remote address\n");
1346 dfprintk(MOUNT
, "NFS: invalid root filehandle\n");
1351 * Initialise the common bits of the superblock
1353 static inline void nfs_initialise_sb(struct super_block
*sb
)
1355 struct nfs_server
*server
= NFS_SB(sb
);
1357 sb
->s_magic
= NFS_SUPER_MAGIC
;
1359 /* We probably want something more informative here */
1360 snprintf(sb
->s_id
, sizeof(sb
->s_id
),
1361 "%x:%x", MAJOR(sb
->s_dev
), MINOR(sb
->s_dev
));
1363 if (sb
->s_blocksize
== 0)
1364 sb
->s_blocksize
= nfs_block_bits(server
->wsize
,
1365 &sb
->s_blocksize_bits
);
1367 if (server
->flags
& NFS_MOUNT_NOAC
)
1368 sb
->s_flags
|= MS_SYNCHRONOUS
;
1370 nfs_super_set_maxbytes(sb
, server
->maxfilesize
);
1374 * Finish setting up an NFS2/3 superblock
1376 static void nfs_fill_super(struct super_block
*sb
,
1377 struct nfs_parsed_mount_data
*data
)
1379 struct nfs_server
*server
= NFS_SB(sb
);
1381 sb
->s_blocksize_bits
= 0;
1382 sb
->s_blocksize
= 0;
1384 sb
->s_blocksize
= nfs_block_size(data
->bsize
, &sb
->s_blocksize_bits
);
1386 if (server
->flags
& NFS_MOUNT_VER3
) {
1387 /* The VFS shouldn't apply the umask to mode bits. We will do
1388 * so ourselves when necessary.
1390 sb
->s_flags
|= MS_POSIXACL
;
1391 sb
->s_time_gran
= 1;
1394 sb
->s_op
= &nfs_sops
;
1395 nfs_initialise_sb(sb
);
1399 * Finish setting up a cloned NFS2/3 superblock
1401 static void nfs_clone_super(struct super_block
*sb
,
1402 const struct super_block
*old_sb
)
1404 struct nfs_server
*server
= NFS_SB(sb
);
1406 sb
->s_blocksize_bits
= old_sb
->s_blocksize_bits
;
1407 sb
->s_blocksize
= old_sb
->s_blocksize
;
1408 sb
->s_maxbytes
= old_sb
->s_maxbytes
;
1410 if (server
->flags
& NFS_MOUNT_VER3
) {
1411 /* The VFS shouldn't apply the umask to mode bits. We will do
1412 * so ourselves when necessary.
1414 sb
->s_flags
|= MS_POSIXACL
;
1415 sb
->s_time_gran
= 1;
1418 sb
->s_op
= old_sb
->s_op
;
1419 nfs_initialise_sb(sb
);
1422 #define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
1424 static int nfs_compare_mount_options(const struct super_block
*s
, const struct nfs_server
*b
, int flags
)
1426 const struct nfs_server
*a
= s
->s_fs_info
;
1427 const struct rpc_clnt
*clnt_a
= a
->client
;
1428 const struct rpc_clnt
*clnt_b
= b
->client
;
1430 if ((s
->s_flags
& NFS_MS_MASK
) != (flags
& NFS_MS_MASK
))
1432 if (a
->nfs_client
!= b
->nfs_client
)
1434 if (a
->flags
!= b
->flags
)
1436 if (a
->wsize
!= b
->wsize
)
1438 if (a
->rsize
!= b
->rsize
)
1440 if (a
->acregmin
!= b
->acregmin
)
1442 if (a
->acregmax
!= b
->acregmax
)
1444 if (a
->acdirmin
!= b
->acdirmin
)
1446 if (a
->acdirmax
!= b
->acdirmax
)
1448 if (clnt_a
->cl_auth
->au_flavor
!= clnt_b
->cl_auth
->au_flavor
)
1455 struct nfs_sb_mountdata
{
1456 struct nfs_server
*server
;
1460 static int nfs_set_super(struct super_block
*s
, void *data
)
1462 struct nfs_sb_mountdata
*sb_mntdata
= data
;
1463 struct nfs_server
*server
= sb_mntdata
->server
;
1466 s
->s_flags
= sb_mntdata
->mntflags
;
1467 s
->s_fs_info
= server
;
1468 ret
= set_anon_super(s
, server
);
1470 server
->s_dev
= s
->s_dev
;
1474 static int nfs_compare_super_address(struct nfs_server
*server1
,
1475 struct nfs_server
*server2
)
1477 struct sockaddr
*sap1
, *sap2
;
1479 sap1
= (struct sockaddr
*)&server1
->nfs_client
->cl_addr
;
1480 sap2
= (struct sockaddr
*)&server2
->nfs_client
->cl_addr
;
1482 if (sap1
->sa_family
!= sap2
->sa_family
)
1485 switch (sap1
->sa_family
) {
1487 struct sockaddr_in
*sin1
= (struct sockaddr_in
*)sap1
;
1488 struct sockaddr_in
*sin2
= (struct sockaddr_in
*)sap2
;
1489 if (sin1
->sin_addr
.s_addr
!= sin2
->sin_addr
.s_addr
)
1491 if (sin1
->sin_port
!= sin2
->sin_port
)
1496 struct sockaddr_in6
*sin1
= (struct sockaddr_in6
*)sap1
;
1497 struct sockaddr_in6
*sin2
= (struct sockaddr_in6
*)sap2
;
1498 if (!ipv6_addr_equal(&sin1
->sin6_addr
, &sin2
->sin6_addr
))
1500 if (sin1
->sin6_port
!= sin2
->sin6_port
)
1511 static int nfs_compare_super(struct super_block
*sb
, void *data
)
1513 struct nfs_sb_mountdata
*sb_mntdata
= data
;
1514 struct nfs_server
*server
= sb_mntdata
->server
, *old
= NFS_SB(sb
);
1515 int mntflags
= sb_mntdata
->mntflags
;
1517 if (!nfs_compare_super_address(old
, server
))
1519 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1520 if (old
->flags
& NFS_MOUNT_UNSHARED
)
1522 if (memcmp(&old
->fsid
, &server
->fsid
, sizeof(old
->fsid
)) != 0)
1524 return nfs_compare_mount_options(sb
, server
, mntflags
);
1527 static int nfs_get_sb(struct file_system_type
*fs_type
,
1528 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
1530 struct nfs_server
*server
= NULL
;
1531 struct super_block
*s
;
1532 struct nfs_fh mntfh
;
1533 struct nfs_parsed_mount_data data
;
1534 struct dentry
*mntroot
;
1535 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
1536 struct nfs_sb_mountdata sb_mntdata
= {
1541 <<<<<<< HEAD
:fs
/nfs
/super
.c
1543 security_init_mnt_opts(&data
.lsm_opts
);
1545 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:fs
/nfs
/super
.c
1546 /* Validate the mount data */
1547 error
= nfs_validate_mount_data(raw_data
, &data
, &mntfh
, dev_name
);
1551 /* Get a volume representation */
1552 server
= nfs_create_server(&data
, &mntfh
);
1553 if (IS_ERR(server
)) {
1554 error
= PTR_ERR(server
);
1557 sb_mntdata
.server
= server
;
1559 if (server
->flags
& NFS_MOUNT_UNSHARED
)
1560 compare_super
= NULL
;
1562 /* Get a superblock - note that we may end up sharing one that already exists */
1563 s
= sget(fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
1569 if (s
->s_fs_info
!= server
) {
1570 nfs_free_server(server
);
1575 /* initial superblock/root creation */
1576 nfs_fill_super(s
, &data
);
1579 mntroot
= nfs_get_root(s
, &mntfh
);
1580 if (IS_ERR(mntroot
)) {
1581 error
= PTR_ERR(mntroot
);
1582 goto error_splat_super
;
1585 <<<<<<< HEAD
:fs
/nfs
/super
.c
1587 error
= security_sb_set_mnt_opts(s
, &data
.lsm_opts
);
1589 goto error_splat_root
;
1591 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:fs
/nfs
/super
.c
1592 s
->s_flags
|= MS_ACTIVE
;
1594 mnt
->mnt_root
= mntroot
;
1598 kfree(data
.nfs_server
.hostname
);
1599 kfree(data
.mount_server
.hostname
);
1600 <<<<<<< HEAD
:fs
/nfs
/super
.c
1602 security_free_mnt_opts(&data
.lsm_opts
);
1603 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:fs
/nfs
/super
.c
1607 nfs_free_server(server
);
1610 <<<<<<< HEAD
:fs
/nfs
/super
.c
1614 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:fs
/nfs
/super
.c
1616 up_write(&s
->s_umount
);
1617 deactivate_super(s
);
1622 * Destroy an NFS2/3 superblock
1624 static void nfs_kill_super(struct super_block
*s
)
1626 struct nfs_server
*server
= NFS_SB(s
);
1629 nfs_free_server(server
);
1633 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
1635 static int nfs_xdev_get_sb(struct file_system_type
*fs_type
, int flags
,
1636 const char *dev_name
, void *raw_data
,
1637 struct vfsmount
*mnt
)
1639 struct nfs_clone_mount
*data
= raw_data
;
1640 struct super_block
*s
;
1641 struct nfs_server
*server
;
1642 struct dentry
*mntroot
;
1643 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
1644 struct nfs_sb_mountdata sb_mntdata
= {
1649 dprintk("--> nfs_xdev_get_sb()\n");
1651 /* create a new volume representation */
1652 server
= nfs_clone_server(NFS_SB(data
->sb
), data
->fh
, data
->fattr
);
1653 if (IS_ERR(server
)) {
1654 error
= PTR_ERR(server
);
1655 goto out_err_noserver
;
1657 sb_mntdata
.server
= server
;
1659 if (server
->flags
& NFS_MOUNT_UNSHARED
)
1660 compare_super
= NULL
;
1662 /* Get a superblock - note that we may end up sharing one that already exists */
1663 s
= sget(&nfs_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
1669 if (s
->s_fs_info
!= server
) {
1670 nfs_free_server(server
);
1675 /* initial superblock/root creation */
1676 nfs_clone_super(s
, data
->sb
);
1679 mntroot
= nfs_get_root(s
, data
->fh
);
1680 if (IS_ERR(mntroot
)) {
1681 error
= PTR_ERR(mntroot
);
1682 goto error_splat_super
;
1684 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
1687 goto error_splat_super
;
1690 s
->s_flags
|= MS_ACTIVE
;
1692 mnt
->mnt_root
= mntroot
;
1694 <<<<<<< HEAD
:fs
/nfs
/super
.c
1696 /* clone any lsm security options from the parent to the new sb */
1697 security_sb_clone_mnt_opts(data
->sb
, s
);
1699 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:fs
/nfs
/super
.c
1700 dprintk("<-- nfs_xdev_get_sb() = 0\n");
1704 nfs_free_server(server
);
1706 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error
);
1710 up_write(&s
->s_umount
);
1711 deactivate_super(s
);
1712 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error
);
1716 #ifdef CONFIG_NFS_V4
1719 * Finish setting up a cloned NFS4 superblock
1721 static void nfs4_clone_super(struct super_block
*sb
,
1722 const struct super_block
*old_sb
)
1724 sb
->s_blocksize_bits
= old_sb
->s_blocksize_bits
;
1725 sb
->s_blocksize
= old_sb
->s_blocksize
;
1726 sb
->s_maxbytes
= old_sb
->s_maxbytes
;
1727 sb
->s_time_gran
= 1;
1728 sb
->s_op
= old_sb
->s_op
;
1729 nfs_initialise_sb(sb
);
1733 * Set up an NFS4 superblock
1735 static void nfs4_fill_super(struct super_block
*sb
)
1737 sb
->s_time_gran
= 1;
1738 sb
->s_op
= &nfs4_sops
;
1739 nfs_initialise_sb(sb
);
1743 * If the user didn't specify a port, set the port number to
1744 * the NFS version 4 default port.
1746 static void nfs4_default_port(struct sockaddr
*sap
)
1748 switch (sap
->sa_family
) {
1750 struct sockaddr_in
*ap
= (struct sockaddr_in
*)sap
;
1751 if (ap
->sin_port
== 0)
1752 ap
->sin_port
= htons(NFS_PORT
);
1756 struct sockaddr_in6
*ap
= (struct sockaddr_in6
*)sap
;
1757 if (ap
->sin6_port
== 0)
1758 ap
->sin6_port
= htons(NFS_PORT
);
1765 * Validate NFSv4 mount options
1767 static int nfs4_validate_mount_data(void *options
,
1768 struct nfs_parsed_mount_data
*args
,
1769 const char *dev_name
)
1771 struct sockaddr_in
*ap
;
1772 struct nfs4_mount_data
*data
= (struct nfs4_mount_data
*)options
;
1775 memset(args
, 0, sizeof(*args
));
1780 args
->rsize
= NFS_MAX_FILE_IO_SIZE
;
1781 args
->wsize
= NFS_MAX_FILE_IO_SIZE
;
1785 args
->acregmax
= 60;
1786 args
->acdirmin
= 30;
1787 args
->acdirmax
= 60;
1788 args
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1790 switch (data
->version
) {
1792 ap
= (struct sockaddr_in
*)&args
->nfs_server
.address
;
1793 if (data
->host_addrlen
> sizeof(args
->nfs_server
.address
))
1794 goto out_no_address
;
1795 if (data
->host_addrlen
== 0)
1796 goto out_no_address
;
1797 args
->nfs_server
.addrlen
= data
->host_addrlen
;
1798 if (copy_from_user(ap
, data
->host_addr
, data
->host_addrlen
))
1800 if (!nfs_verify_server_address((struct sockaddr
*)
1801 &args
->nfs_server
.address
))
1802 goto out_no_address
;
1804 nfs4_default_port((struct sockaddr
*)
1805 &args
->nfs_server
.address
);
1807 switch (data
->auth_flavourlen
) {
1809 args
->auth_flavors
[0] = RPC_AUTH_UNIX
;
1812 if (copy_from_user(&args
->auth_flavors
[0],
1813 data
->auth_flavours
,
1814 sizeof(args
->auth_flavors
[0])))
1818 goto out_inval_auth
;
1821 c
= strndup_user(data
->hostname
.data
, NFS4_MAXNAMLEN
);
1824 args
->nfs_server
.hostname
= c
;
1826 c
= strndup_user(data
->mnt_path
.data
, NFS4_MAXPATHLEN
);
1829 args
->nfs_server
.export_path
= c
;
1830 dfprintk(MOUNT
, "NFS: MNTPATH: '%s'\n", c
);
1832 c
= strndup_user(data
->client_addr
.data
, 16);
1835 args
->client_address
= c
;
1838 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
1842 args
->flags
= data
->flags
& NFS4_MOUNT_FLAGMASK
;
1843 args
->rsize
= data
->rsize
;
1844 args
->wsize
= data
->wsize
;
1845 args
->timeo
= data
->timeo
;
1846 args
->retrans
= data
->retrans
;
1847 args
->acregmin
= data
->acregmin
;
1848 args
->acregmax
= data
->acregmax
;
1849 args
->acdirmin
= data
->acdirmin
;
1850 args
->acdirmax
= data
->acdirmax
;
1851 args
->nfs_server
.protocol
= data
->proto
;
1857 if (nfs_parse_mount_options((char *)options
, args
) == 0)
1860 if (!nfs_verify_server_address((struct sockaddr
*)
1861 &args
->nfs_server
.address
))
1864 nfs4_default_port((struct sockaddr
*)
1865 &args
->nfs_server
.address
);
1867 switch (args
->auth_flavor_len
) {
1869 args
->auth_flavors
[0] = RPC_AUTH_UNIX
;
1874 goto out_inval_auth
;
1878 * Split "dev_name" into "hostname:mntpath".
1880 c
= strchr(dev_name
, ':');
1883 /* while calculating len, pretend ':' is '\0' */
1885 if (len
> NFS4_MAXNAMLEN
)
1886 return -ENAMETOOLONG
;
1887 /* N.B. caller will free nfs_server.hostname in all cases */
1888 args
->nfs_server
.hostname
= kstrndup(dev_name
, len
, GFP_KERNEL
);
1890 c
++; /* step over the ':' */
1892 if (len
> NFS4_MAXPATHLEN
)
1893 return -ENAMETOOLONG
;
1894 args
->nfs_server
.export_path
= kstrndup(c
, len
, GFP_KERNEL
);
1896 dprintk("NFS: MNTPATH: '%s'\n", args
->nfs_server
.export_path
);
1898 if (args
->client_address
== NULL
)
1899 goto out_no_client_address
;
1908 dfprintk(MOUNT
, "NFS4: mount program didn't pass any mount data\n");
1912 dfprintk(MOUNT
, "NFS4: Invalid number of RPC auth flavours %d\n",
1913 data
->auth_flavourlen
);
1917 dfprintk(MOUNT
, "NFS4: mount program didn't pass remote address\n");
1920 out_no_client_address
:
1921 dfprintk(MOUNT
, "NFS4: mount program didn't pass callback address\n");
1926 * Get the superblock for an NFS4 mountpoint
1928 static int nfs4_get_sb(struct file_system_type
*fs_type
,
1929 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
1931 struct nfs_parsed_mount_data data
;
1932 struct super_block
*s
;
1933 struct nfs_server
*server
;
1934 struct nfs_fh mntfh
;
1935 struct dentry
*mntroot
;
1936 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
1937 struct nfs_sb_mountdata sb_mntdata
= {
1942 <<<<<<< HEAD
:fs
/nfs
/super
.c
1944 security_init_mnt_opts(&data
.lsm_opts
);
1946 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:fs
/nfs
/super
.c
1947 /* Validate the mount data */
1948 error
= nfs4_validate_mount_data(raw_data
, &data
, dev_name
);
1952 /* Get a volume representation */
1953 server
= nfs4_create_server(&data
, &mntfh
);
1954 if (IS_ERR(server
)) {
1955 error
= PTR_ERR(server
);
1958 sb_mntdata
.server
= server
;
1960 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
1961 compare_super
= NULL
;
1963 /* Get a superblock - note that we may end up sharing one that already exists */
1964 s
= sget(fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
1970 if (s
->s_fs_info
!= server
) {
1971 nfs_free_server(server
);
1976 /* initial superblock/root creation */
1980 mntroot
= nfs4_get_root(s
, &mntfh
);
1981 if (IS_ERR(mntroot
)) {
1982 error
= PTR_ERR(mntroot
);
1983 goto error_splat_super
;
1986 s
->s_flags
|= MS_ACTIVE
;
1988 mnt
->mnt_root
= mntroot
;
1992 kfree(data
.client_address
);
1993 kfree(data
.nfs_server
.export_path
);
1994 kfree(data
.nfs_server
.hostname
);
1995 <<<<<<< HEAD
:fs
/nfs
/super
.c
1997 security_free_mnt_opts(&data
.lsm_opts
);
1998 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:fs
/nfs
/super
.c
2002 nfs_free_server(server
);
2006 up_write(&s
->s_umount
);
2007 deactivate_super(s
);
2011 static void nfs4_kill_super(struct super_block
*sb
)
2013 struct nfs_server
*server
= NFS_SB(sb
);
2015 nfs_return_all_delegations(sb
);
2016 kill_anon_super(sb
);
2018 nfs4_renewd_prepare_shutdown(server
);
2019 nfs_free_server(server
);
2023 * Clone an NFS4 server record on xdev traversal (FSID-change)
2025 static int nfs4_xdev_get_sb(struct file_system_type
*fs_type
, int flags
,
2026 const char *dev_name
, void *raw_data
,
2027 struct vfsmount
*mnt
)
2029 struct nfs_clone_mount
*data
= raw_data
;
2030 struct super_block
*s
;
2031 struct nfs_server
*server
;
2032 struct dentry
*mntroot
;
2033 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2034 struct nfs_sb_mountdata sb_mntdata
= {
2039 dprintk("--> nfs4_xdev_get_sb()\n");
2041 /* create a new volume representation */
2042 server
= nfs_clone_server(NFS_SB(data
->sb
), data
->fh
, data
->fattr
);
2043 if (IS_ERR(server
)) {
2044 error
= PTR_ERR(server
);
2045 goto out_err_noserver
;
2047 sb_mntdata
.server
= server
;
2049 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2050 compare_super
= NULL
;
2052 /* Get a superblock - note that we may end up sharing one that already exists */
2053 s
= sget(&nfs_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2059 if (s
->s_fs_info
!= server
) {
2060 nfs_free_server(server
);
2065 /* initial superblock/root creation */
2066 nfs4_clone_super(s
, data
->sb
);
2069 mntroot
= nfs4_get_root(s
, data
->fh
);
2070 if (IS_ERR(mntroot
)) {
2071 error
= PTR_ERR(mntroot
);
2072 goto error_splat_super
;
2074 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
2077 goto error_splat_super
;
2080 s
->s_flags
|= MS_ACTIVE
;
2082 mnt
->mnt_root
= mntroot
;
2084 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2088 nfs_free_server(server
);
2090 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error
);
2094 up_write(&s
->s_umount
);
2095 deactivate_super(s
);
2096 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error
);
2101 * Create an NFS4 server record on referral traversal
2103 static int nfs4_referral_get_sb(struct file_system_type
*fs_type
, int flags
,
2104 const char *dev_name
, void *raw_data
,
2105 struct vfsmount
*mnt
)
2107 struct nfs_clone_mount
*data
= raw_data
;
2108 struct super_block
*s
;
2109 struct nfs_server
*server
;
2110 struct dentry
*mntroot
;
2111 struct nfs_fh mntfh
;
2112 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2113 struct nfs_sb_mountdata sb_mntdata
= {
2118 dprintk("--> nfs4_referral_get_sb()\n");
2120 /* create a new volume representation */
2121 server
= nfs4_create_referral_server(data
, &mntfh
);
2122 if (IS_ERR(server
)) {
2123 error
= PTR_ERR(server
);
2124 goto out_err_noserver
;
2126 sb_mntdata
.server
= server
;
2128 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2129 compare_super
= NULL
;
2131 /* Get a superblock - note that we may end up sharing one that already exists */
2132 s
= sget(&nfs_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2138 if (s
->s_fs_info
!= server
) {
2139 nfs_free_server(server
);
2144 /* initial superblock/root creation */
2148 mntroot
= nfs4_get_root(s
, &mntfh
);
2149 if (IS_ERR(mntroot
)) {
2150 error
= PTR_ERR(mntroot
);
2151 goto error_splat_super
;
2153 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
2156 goto error_splat_super
;
2159 s
->s_flags
|= MS_ACTIVE
;
2161 mnt
->mnt_root
= mntroot
;
2163 dprintk("<-- nfs4_referral_get_sb() = 0\n");
2167 nfs_free_server(server
);
2169 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error
);
2173 up_write(&s
->s_umount
);
2174 deactivate_super(s
);
2175 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error
);
2179 #endif /* CONFIG_NFS_V4 */