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/netdevice.h>
51 #include <linux/nfs_xdr.h>
52 #include <linux/magic.h>
53 #include <linux/parser.h>
55 #include <asm/system.h>
56 #include <asm/uaccess.h>
60 #include "delegation.h"
64 #define NFSDBG_FACILITY NFSDBG_VFS
67 /* Mount options that take no arguments */
69 Opt_posix
, Opt_noposix
,
74 Opt_udp
, Opt_tcp
, Opt_rdma
,
76 Opt_rdirplus
, Opt_nordirplus
,
77 Opt_sharecache
, Opt_nosharecache
,
79 /* Mount options that take integer arguments */
81 Opt_rsize
, Opt_wsize
, Opt_bsize
,
82 Opt_timeo
, Opt_retrans
,
83 Opt_acregmin
, Opt_acregmax
,
84 Opt_acdirmin
, Opt_acdirmax
,
91 /* Mount options that take string arguments */
92 Opt_sec
, Opt_proto
, Opt_mountproto
, Opt_mounthost
,
93 Opt_addr
, Opt_mountaddr
, Opt_clientaddr
,
95 /* Special mount options */
96 Opt_userspace
, Opt_deprecated
, Opt_sloppy
,
101 static match_table_t nfs_mount_option_tokens
= {
102 { Opt_userspace
, "bg" },
103 { Opt_userspace
, "fg" },
104 { Opt_userspace
, "retry=%s" },
106 { Opt_sloppy
, "sloppy" },
108 { Opt_soft
, "soft" },
109 { Opt_hard
, "hard" },
110 { Opt_deprecated
, "intr" },
111 { Opt_deprecated
, "nointr" },
112 { Opt_posix
, "posix" },
113 { Opt_noposix
, "noposix" },
115 { Opt_nocto
, "nocto" },
117 { Opt_noac
, "noac" },
118 { Opt_lock
, "lock" },
119 { Opt_nolock
, "nolock" },
124 { Opt_rdma
, "rdma" },
126 { Opt_noacl
, "noacl" },
127 { Opt_rdirplus
, "rdirplus" },
128 { Opt_nordirplus
, "nordirplus" },
129 { Opt_sharecache
, "sharecache" },
130 { Opt_nosharecache
, "nosharecache" },
132 { Opt_port
, "port=%u" },
133 { Opt_rsize
, "rsize=%u" },
134 { Opt_wsize
, "wsize=%u" },
135 { Opt_bsize
, "bsize=%u" },
136 { Opt_timeo
, "timeo=%u" },
137 { Opt_retrans
, "retrans=%u" },
138 { Opt_acregmin
, "acregmin=%u" },
139 { Opt_acregmax
, "acregmax=%u" },
140 { Opt_acdirmin
, "acdirmin=%u" },
141 { Opt_acdirmax
, "acdirmax=%u" },
142 { Opt_actimeo
, "actimeo=%u" },
143 { Opt_namelen
, "namlen=%u" },
144 { Opt_mountport
, "mountport=%u" },
145 { Opt_mountvers
, "mountvers=%u" },
146 { Opt_nfsvers
, "nfsvers=%u" },
147 { Opt_nfsvers
, "vers=%u" },
149 { Opt_sec
, "sec=%s" },
150 { Opt_proto
, "proto=%s" },
151 { Opt_mountproto
, "mountproto=%s" },
152 { Opt_addr
, "addr=%s" },
153 { Opt_clientaddr
, "clientaddr=%s" },
154 { Opt_mounthost
, "mounthost=%s" },
155 { Opt_mountaddr
, "mountaddr=%s" },
161 Opt_xprt_udp
, Opt_xprt_tcp
, Opt_xprt_rdma
,
166 static match_table_t nfs_xprt_protocol_tokens
= {
167 { Opt_xprt_udp
, "udp" },
168 { Opt_xprt_tcp
, "tcp" },
169 { Opt_xprt_rdma
, "rdma" },
171 { Opt_xprt_err
, NULL
}
175 Opt_sec_none
, Opt_sec_sys
,
176 Opt_sec_krb5
, Opt_sec_krb5i
, Opt_sec_krb5p
,
177 Opt_sec_lkey
, Opt_sec_lkeyi
, Opt_sec_lkeyp
,
178 Opt_sec_spkm
, Opt_sec_spkmi
, Opt_sec_spkmp
,
183 static match_table_t nfs_secflavor_tokens
= {
184 { Opt_sec_none
, "none" },
185 { Opt_sec_none
, "null" },
186 { Opt_sec_sys
, "sys" },
188 { Opt_sec_krb5
, "krb5" },
189 { Opt_sec_krb5i
, "krb5i" },
190 { Opt_sec_krb5p
, "krb5p" },
192 { Opt_sec_lkey
, "lkey" },
193 { Opt_sec_lkeyi
, "lkeyi" },
194 { Opt_sec_lkeyp
, "lkeyp" },
196 { Opt_sec_spkm
, "spkm3" },
197 { Opt_sec_spkmi
, "spkm3i" },
198 { Opt_sec_spkmp
, "spkm3p" },
200 { Opt_sec_err
, NULL
}
204 static void nfs_umount_begin(struct super_block
*);
205 static int nfs_statfs(struct dentry
*, struct kstatfs
*);
206 static int nfs_show_options(struct seq_file
*, struct vfsmount
*);
207 static int nfs_show_stats(struct seq_file
*, struct vfsmount
*);
208 static int nfs_get_sb(struct file_system_type
*, int, const char *, void *, struct vfsmount
*);
209 static int nfs_xdev_get_sb(struct file_system_type
*fs_type
,
210 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
211 static void nfs_kill_super(struct super_block
*);
212 static void nfs_put_super(struct super_block
*);
213 static int nfs_remount(struct super_block
*sb
, int *flags
, char *raw_data
);
215 static struct file_system_type nfs_fs_type
= {
216 .owner
= THIS_MODULE
,
218 .get_sb
= nfs_get_sb
,
219 .kill_sb
= nfs_kill_super
,
220 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
223 struct file_system_type nfs_xdev_fs_type
= {
224 .owner
= THIS_MODULE
,
226 .get_sb
= nfs_xdev_get_sb
,
227 .kill_sb
= nfs_kill_super
,
228 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
231 static const struct super_operations nfs_sops
= {
232 .alloc_inode
= nfs_alloc_inode
,
233 .destroy_inode
= nfs_destroy_inode
,
234 .write_inode
= nfs_write_inode
,
235 .put_super
= nfs_put_super
,
236 .statfs
= nfs_statfs
,
237 .clear_inode
= nfs_clear_inode
,
238 .umount_begin
= nfs_umount_begin
,
239 .show_options
= nfs_show_options
,
240 .show_stats
= nfs_show_stats
,
241 .remount_fs
= nfs_remount
,
245 static int nfs4_get_sb(struct file_system_type
*fs_type
,
246 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
247 static int nfs4_xdev_get_sb(struct file_system_type
*fs_type
,
248 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
249 static int nfs4_referral_get_sb(struct file_system_type
*fs_type
,
250 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
251 static void nfs4_kill_super(struct super_block
*sb
);
253 static struct file_system_type nfs4_fs_type
= {
254 .owner
= THIS_MODULE
,
256 .get_sb
= nfs4_get_sb
,
257 .kill_sb
= nfs4_kill_super
,
258 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
261 struct file_system_type nfs4_xdev_fs_type
= {
262 .owner
= THIS_MODULE
,
264 .get_sb
= nfs4_xdev_get_sb
,
265 .kill_sb
= nfs4_kill_super
,
266 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
269 struct file_system_type nfs4_referral_fs_type
= {
270 .owner
= THIS_MODULE
,
272 .get_sb
= nfs4_referral_get_sb
,
273 .kill_sb
= nfs4_kill_super
,
274 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
277 static const struct super_operations nfs4_sops
= {
278 .alloc_inode
= nfs_alloc_inode
,
279 .destroy_inode
= nfs_destroy_inode
,
280 .write_inode
= nfs_write_inode
,
281 .statfs
= nfs_statfs
,
282 .clear_inode
= nfs4_clear_inode
,
283 .umount_begin
= nfs_umount_begin
,
284 .show_options
= nfs_show_options
,
285 .show_stats
= nfs_show_stats
,
286 .remount_fs
= nfs_remount
,
290 static struct shrinker acl_shrinker
= {
291 .shrink
= nfs_access_cache_shrinker
,
292 .seeks
= DEFAULT_SEEKS
,
296 * Register the NFS filesystems
298 int __init
register_nfs_fs(void)
302 ret
= register_filesystem(&nfs_fs_type
);
306 ret
= nfs_register_sysctl();
310 ret
= register_filesystem(&nfs4_fs_type
);
314 register_shrinker(&acl_shrinker
);
319 nfs_unregister_sysctl();
322 unregister_filesystem(&nfs_fs_type
);
328 * Unregister the NFS filesystems
330 void __exit
unregister_nfs_fs(void)
332 unregister_shrinker(&acl_shrinker
);
334 unregister_filesystem(&nfs4_fs_type
);
336 nfs_unregister_sysctl();
337 unregister_filesystem(&nfs_fs_type
);
340 void nfs_sb_active(struct nfs_server
*server
)
342 atomic_inc(&server
->active
);
345 void nfs_sb_deactive(struct nfs_server
*server
)
347 if (atomic_dec_and_test(&server
->active
))
348 wake_up(&server
->active_wq
);
351 static void nfs_put_super(struct super_block
*sb
)
353 struct nfs_server
*server
= NFS_SB(sb
);
355 * Make sure there are no outstanding ops to this server.
356 * If so, wait for them to finish before allowing the
357 * unmount to continue.
359 wait_event(server
->active_wq
, atomic_read(&server
->active
) == 0);
363 * Deliver file system statistics to userspace
365 static int nfs_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
367 struct nfs_server
*server
= NFS_SB(dentry
->d_sb
);
368 unsigned char blockbits
;
369 unsigned long blockres
;
370 struct nfs_fh
*fh
= NFS_FH(dentry
->d_inode
);
371 struct nfs_fattr fattr
;
372 struct nfs_fsstat res
= {
377 error
= server
->nfs_client
->rpc_ops
->statfs(server
, fh
, &res
);
380 buf
->f_type
= NFS_SUPER_MAGIC
;
383 * Current versions of glibc do not correctly handle the
384 * case where f_frsize != f_bsize. Eventually we want to
385 * report the value of wtmult in this field.
387 buf
->f_frsize
= dentry
->d_sb
->s_blocksize
;
390 * On most *nix systems, f_blocks, f_bfree, and f_bavail
391 * are reported in units of f_frsize. Linux hasn't had
392 * an f_frsize field in its statfs struct until recently,
393 * thus historically Linux's sys_statfs reports these
394 * fields in units of f_bsize.
396 buf
->f_bsize
= dentry
->d_sb
->s_blocksize
;
397 blockbits
= dentry
->d_sb
->s_blocksize_bits
;
398 blockres
= (1 << blockbits
) - 1;
399 buf
->f_blocks
= (res
.tbytes
+ blockres
) >> blockbits
;
400 buf
->f_bfree
= (res
.fbytes
+ blockres
) >> blockbits
;
401 buf
->f_bavail
= (res
.abytes
+ blockres
) >> blockbits
;
403 buf
->f_files
= res
.tfiles
;
404 buf
->f_ffree
= res
.afiles
;
406 buf
->f_namelen
= server
->namelen
;
411 dprintk("%s: statfs error = %d\n", __func__
, -error
);
416 * Map the security flavour number to a name
418 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour
)
420 static const struct {
421 rpc_authflavor_t flavour
;
424 { RPC_AUTH_NULL
, "null" },
425 { RPC_AUTH_UNIX
, "sys" },
426 { RPC_AUTH_GSS_KRB5
, "krb5" },
427 { RPC_AUTH_GSS_KRB5I
, "krb5i" },
428 { RPC_AUTH_GSS_KRB5P
, "krb5p" },
429 { RPC_AUTH_GSS_LKEY
, "lkey" },
430 { RPC_AUTH_GSS_LKEYI
, "lkeyi" },
431 { RPC_AUTH_GSS_LKEYP
, "lkeyp" },
432 { RPC_AUTH_GSS_SPKM
, "spkm" },
433 { RPC_AUTH_GSS_SPKMI
, "spkmi" },
434 { RPC_AUTH_GSS_SPKMP
, "spkmp" },
435 { UINT_MAX
, "unknown" }
439 for (i
= 0; sec_flavours
[i
].flavour
!= UINT_MAX
; i
++) {
440 if (sec_flavours
[i
].flavour
== flavour
)
443 return sec_flavours
[i
].str
;
446 static void nfs_show_mountd_options(struct seq_file
*m
, struct nfs_server
*nfss
,
449 struct sockaddr
*sap
= (struct sockaddr
*)&nfss
->mountd_address
;
451 switch (sap
->sa_family
) {
453 struct sockaddr_in
*sin
= (struct sockaddr_in
*)sap
;
454 seq_printf(m
, ",mountaddr=" NIPQUAD_FMT
,
455 NIPQUAD(sin
->sin_addr
.s_addr
));
459 struct sockaddr_in6
*sin6
= (struct sockaddr_in6
*)sap
;
460 seq_printf(m
, ",mountaddr=" NIP6_FMT
,
461 NIP6(sin6
->sin6_addr
));
466 seq_printf(m
, ",mountaddr=unspecified");
469 if (nfss
->mountd_version
|| showdefaults
)
470 seq_printf(m
, ",mountvers=%u", nfss
->mountd_version
);
471 if (nfss
->mountd_port
|| showdefaults
)
472 seq_printf(m
, ",mountport=%u", nfss
->mountd_port
);
474 switch (nfss
->mountd_protocol
) {
476 seq_printf(m
, ",mountproto=udp");
479 seq_printf(m
, ",mountproto=tcp");
483 seq_printf(m
, ",mountproto=auto");
488 * Describe the mount options in force on this server representation
490 static void nfs_show_mount_options(struct seq_file
*m
, struct nfs_server
*nfss
,
493 static const struct proc_nfs_info
{
498 { NFS_MOUNT_SOFT
, ",soft", ",hard" },
499 { NFS_MOUNT_INTR
, ",intr", ",nointr" },
500 { NFS_MOUNT_POSIX
, ",posix", "" },
501 { NFS_MOUNT_NOCTO
, ",nocto", "" },
502 { NFS_MOUNT_NOAC
, ",noac", "" },
503 { NFS_MOUNT_NONLM
, ",nolock", "" },
504 { NFS_MOUNT_NOACL
, ",noacl", "" },
505 { NFS_MOUNT_NORDIRPLUS
, ",nordirplus", "" },
506 { NFS_MOUNT_UNSHARED
, ",nosharecache", ""},
509 const struct proc_nfs_info
*nfs_infop
;
510 struct nfs_client
*clp
= nfss
->nfs_client
;
511 u32 version
= clp
->rpc_ops
->version
;
513 seq_printf(m
, ",vers=%u", version
);
514 seq_printf(m
, ",rsize=%u", nfss
->rsize
);
515 seq_printf(m
, ",wsize=%u", nfss
->wsize
);
516 if (nfss
->bsize
!= 0)
517 seq_printf(m
, ",bsize=%u", nfss
->bsize
);
518 seq_printf(m
, ",namlen=%u", nfss
->namelen
);
519 if (nfss
->acregmin
!= NFS_DEF_ACREGMIN
*HZ
|| showdefaults
)
520 seq_printf(m
, ",acregmin=%u", nfss
->acregmin
/HZ
);
521 if (nfss
->acregmax
!= NFS_DEF_ACREGMAX
*HZ
|| showdefaults
)
522 seq_printf(m
, ",acregmax=%u", nfss
->acregmax
/HZ
);
523 if (nfss
->acdirmin
!= NFS_DEF_ACDIRMIN
*HZ
|| showdefaults
)
524 seq_printf(m
, ",acdirmin=%u", nfss
->acdirmin
/HZ
);
525 if (nfss
->acdirmax
!= NFS_DEF_ACDIRMAX
*HZ
|| showdefaults
)
526 seq_printf(m
, ",acdirmax=%u", nfss
->acdirmax
/HZ
);
527 for (nfs_infop
= nfs_info
; nfs_infop
->flag
; nfs_infop
++) {
528 if (nfss
->flags
& nfs_infop
->flag
)
529 seq_puts(m
, nfs_infop
->str
);
531 seq_puts(m
, nfs_infop
->nostr
);
533 seq_printf(m
, ",proto=%s",
534 rpc_peeraddr2str(nfss
->client
, RPC_DISPLAY_PROTO
));
536 if (nfss
->port
!= NFS_PORT
)
537 seq_printf(m
, ",port=%u", nfss
->port
);
540 seq_printf(m
, ",port=%u", nfss
->port
);
542 seq_printf(m
, ",timeo=%lu", 10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
);
543 seq_printf(m
, ",retrans=%u", nfss
->client
->cl_timeout
->to_retries
);
544 seq_printf(m
, ",sec=%s", nfs_pseudoflavour_to_name(nfss
->client
->cl_auth
->au_flavor
));
547 nfs_show_mountd_options(m
, nfss
, showdefaults
);
550 if (clp
->rpc_ops
->version
== 4)
551 seq_printf(m
, ",clientaddr=%s", clp
->cl_ipaddr
);
556 * Describe the mount options on this VFS mountpoint
558 static int nfs_show_options(struct seq_file
*m
, struct vfsmount
*mnt
)
560 struct nfs_server
*nfss
= NFS_SB(mnt
->mnt_sb
);
562 nfs_show_mount_options(m
, nfss
, 0);
564 seq_printf(m
, ",addr=%s",
565 rpc_peeraddr2str(nfss
->nfs_client
->cl_rpcclient
,
572 * Present statistical information for this VFS mountpoint
574 static int nfs_show_stats(struct seq_file
*m
, struct vfsmount
*mnt
)
577 struct nfs_server
*nfss
= NFS_SB(mnt
->mnt_sb
);
578 struct rpc_auth
*auth
= nfss
->client
->cl_auth
;
579 struct nfs_iostats totals
= { };
581 seq_printf(m
, "statvers=%s", NFS_IOSTAT_VERS
);
584 * Display all mount option settings
586 seq_printf(m
, "\n\topts:\t");
587 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_RDONLY
? "ro" : "rw");
588 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_SYNCHRONOUS
? ",sync" : "");
589 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_NOATIME
? ",noatime" : "");
590 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_NODIRATIME
? ",nodiratime" : "");
591 nfs_show_mount_options(m
, nfss
, 1);
593 seq_printf(m
, "\n\tage:\t%lu", (jiffies
- nfss
->mount_time
) / HZ
);
595 seq_printf(m
, "\n\tcaps:\t");
596 seq_printf(m
, "caps=0x%x", nfss
->caps
);
597 seq_printf(m
, ",wtmult=%u", nfss
->wtmult
);
598 seq_printf(m
, ",dtsize=%u", nfss
->dtsize
);
599 seq_printf(m
, ",bsize=%u", nfss
->bsize
);
600 seq_printf(m
, ",namlen=%u", nfss
->namelen
);
603 if (nfss
->nfs_client
->rpc_ops
->version
== 4) {
604 seq_printf(m
, "\n\tnfsv4:\t");
605 seq_printf(m
, "bm0=0x%x", nfss
->attr_bitmask
[0]);
606 seq_printf(m
, ",bm1=0x%x", nfss
->attr_bitmask
[1]);
607 seq_printf(m
, ",acl=0x%x", nfss
->acl_bitmask
);
612 * Display security flavor in effect for this mount
614 seq_printf(m
, "\n\tsec:\tflavor=%u", auth
->au_ops
->au_flavor
);
616 seq_printf(m
, ",pseudoflavor=%u", auth
->au_flavor
);
619 * Display superblock I/O counters
621 for_each_possible_cpu(cpu
) {
622 struct nfs_iostats
*stats
;
625 stats
= per_cpu_ptr(nfss
->io_stats
, cpu
);
627 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
628 totals
.events
[i
] += stats
->events
[i
];
629 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
630 totals
.bytes
[i
] += stats
->bytes
[i
];
635 seq_printf(m
, "\n\tevents:\t");
636 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
637 seq_printf(m
, "%lu ", totals
.events
[i
]);
638 seq_printf(m
, "\n\tbytes:\t");
639 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
640 seq_printf(m
, "%Lu ", totals
.bytes
[i
]);
643 rpc_print_iostats(m
, nfss
->client
);
649 * Begin unmount by attempting to remove all automounted mountpoints we added
650 * in response to xdev traversals and referrals
652 static void nfs_umount_begin(struct super_block
*sb
)
654 struct nfs_server
*server
= NFS_SB(sb
);
655 struct rpc_clnt
*rpc
;
657 /* -EIO all pending I/O */
658 rpc
= server
->client_acl
;
660 rpc_killall_tasks(rpc
);
661 rpc
= server
->client
;
663 rpc_killall_tasks(rpc
);
667 * Set the port number in an address. Be agnostic about the address family.
669 static void nfs_set_port(struct sockaddr
*sap
, unsigned short port
)
671 switch (sap
->sa_family
) {
673 struct sockaddr_in
*ap
= (struct sockaddr_in
*)sap
;
674 ap
->sin_port
= htons(port
);
678 struct sockaddr_in6
*ap
= (struct sockaddr_in6
*)sap
;
679 ap
->sin6_port
= htons(port
);
686 * Sanity-check a server address provided by the mount command.
688 * Address family must be initialized, and address must not be
689 * the ANY address for that family.
691 static int nfs_verify_server_address(struct sockaddr
*addr
)
693 switch (addr
->sa_family
) {
695 struct sockaddr_in
*sa
= (struct sockaddr_in
*)addr
;
696 return sa
->sin_addr
.s_addr
!= htonl(INADDR_ANY
);
699 struct in6_addr
*sa
= &((struct sockaddr_in6
*)addr
)->sin6_addr
;
700 return !ipv6_addr_any(sa
);
707 static void nfs_parse_ipv4_address(char *string
, size_t str_len
,
708 struct sockaddr
*sap
, size_t *addr_len
)
710 struct sockaddr_in
*sin
= (struct sockaddr_in
*)sap
;
711 u8
*addr
= (u8
*)&sin
->sin_addr
.s_addr
;
713 if (str_len
<= INET_ADDRSTRLEN
) {
714 dfprintk(MOUNT
, "NFS: parsing IPv4 address %*s\n",
715 (int)str_len
, string
);
717 sin
->sin_family
= AF_INET
;
718 *addr_len
= sizeof(*sin
);
719 if (in4_pton(string
, str_len
, addr
, '\0', NULL
))
723 sap
->sa_family
= AF_UNSPEC
;
727 #define IPV6_SCOPE_DELIMITER '%'
729 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
730 static void nfs_parse_ipv6_scope_id(const char *string
, const size_t str_len
,
732 struct sockaddr_in6
*sin6
)
737 if (!(ipv6_addr_type(&sin6
->sin6_addr
) & IPV6_ADDR_LINKLOCAL
))
739 if (*delim
!= IPV6_SCOPE_DELIMITER
)
742 len
= (string
+ str_len
) - delim
- 1;
743 p
= kstrndup(delim
+ 1, len
, GFP_KERNEL
);
745 unsigned long scope_id
= 0;
746 struct net_device
*dev
;
748 dev
= dev_get_by_name(&init_net
, p
);
750 scope_id
= dev
->ifindex
;
753 /* scope_id is set to zero on error */
754 strict_strtoul(p
, 10, &scope_id
);
758 sin6
->sin6_scope_id
= scope_id
;
759 dfprintk(MOUNT
, "NFS: IPv6 scope ID = %lu\n", scope_id
);
763 static void nfs_parse_ipv6_address(char *string
, size_t str_len
,
764 struct sockaddr
*sap
, size_t *addr_len
)
766 struct sockaddr_in6
*sin6
= (struct sockaddr_in6
*)sap
;
767 u8
*addr
= (u8
*)&sin6
->sin6_addr
.in6_u
;
770 if (str_len
<= INET6_ADDRSTRLEN
) {
771 dfprintk(MOUNT
, "NFS: parsing IPv6 address %*s\n",
772 (int)str_len
, string
);
774 sin6
->sin6_family
= AF_INET6
;
775 *addr_len
= sizeof(*sin6
);
776 if (in6_pton(string
, str_len
, addr
, IPV6_SCOPE_DELIMITER
, &delim
)) {
777 nfs_parse_ipv6_scope_id(string
, str_len
, delim
, sin6
);
782 sap
->sa_family
= AF_UNSPEC
;
786 static void nfs_parse_ipv6_address(char *string
, size_t str_len
,
787 struct sockaddr
*sap
, size_t *addr_len
)
789 sap
->sa_family
= AF_UNSPEC
;
795 * Construct a sockaddr based on the contents of a string that contains
796 * an IP address in presentation format.
798 * If there is a problem constructing the new sockaddr, set the address
799 * family to AF_UNSPEC.
801 static void nfs_parse_ip_address(char *string
, size_t str_len
,
802 struct sockaddr
*sap
, size_t *addr_len
)
804 unsigned int i
, colons
;
807 for (i
= 0; i
< str_len
; i
++)
808 if (string
[i
] == ':')
812 nfs_parse_ipv6_address(string
, str_len
, sap
, addr_len
);
814 nfs_parse_ipv4_address(string
, str_len
, sap
, addr_len
);
818 * Sanity check the NFS transport protocol.
821 static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data
*mnt
)
823 switch (mnt
->nfs_server
.protocol
) {
824 case XPRT_TRANSPORT_UDP
:
825 case XPRT_TRANSPORT_TCP
:
826 case XPRT_TRANSPORT_RDMA
:
829 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
834 * For text based NFSv2/v3 mounts, the mount protocol transport default
835 * settings should depend upon the specified NFS transport.
837 static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data
*mnt
)
839 nfs_validate_transport_protocol(mnt
);
841 if (mnt
->mount_server
.protocol
== XPRT_TRANSPORT_UDP
||
842 mnt
->mount_server
.protocol
== XPRT_TRANSPORT_TCP
)
844 switch (mnt
->nfs_server
.protocol
) {
845 case XPRT_TRANSPORT_UDP
:
846 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_UDP
;
848 case XPRT_TRANSPORT_TCP
:
849 case XPRT_TRANSPORT_RDMA
:
850 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_TCP
;
855 * Parse the value of the 'sec=' option.
857 * The flavor_len setting is for v4 mounts.
859 static int nfs_parse_security_flavors(char *value
,
860 struct nfs_parsed_mount_data
*mnt
)
862 substring_t args
[MAX_OPT_ARGS
];
864 dfprintk(MOUNT
, "NFS: parsing sec=%s option\n", value
);
866 switch (match_token(value
, nfs_secflavor_tokens
, args
)) {
868 mnt
->auth_flavor_len
= 0;
869 mnt
->auth_flavors
[0] = RPC_AUTH_NULL
;
872 mnt
->auth_flavor_len
= 0;
873 mnt
->auth_flavors
[0] = RPC_AUTH_UNIX
;
876 mnt
->auth_flavor_len
= 1;
877 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5
;
880 mnt
->auth_flavor_len
= 1;
881 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5I
;
884 mnt
->auth_flavor_len
= 1;
885 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_KRB5P
;
888 mnt
->auth_flavor_len
= 1;
889 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEY
;
892 mnt
->auth_flavor_len
= 1;
893 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEYI
;
896 mnt
->auth_flavor_len
= 1;
897 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_LKEYP
;
900 mnt
->auth_flavor_len
= 1;
901 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKM
;
904 mnt
->auth_flavor_len
= 1;
905 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKMI
;
908 mnt
->auth_flavor_len
= 1;
909 mnt
->auth_flavors
[0] = RPC_AUTH_GSS_SPKMP
;
918 static void nfs_parse_invalid_value(const char *option
)
920 dfprintk(MOUNT
, "NFS: bad value specified for %s option\n", option
);
924 * Error-check and convert a string of mount options from user space into
925 * a data structure. The whole mount string is processed; bad options are
926 * skipped as they are encountered. If there were no errors, return 1;
927 * otherwise return 0 (zero).
929 static int nfs_parse_mount_options(char *raw
,
930 struct nfs_parsed_mount_data
*mnt
)
932 char *p
, *string
, *secdata
;
933 int rc
, sloppy
= 0, errors
= 0;
936 dfprintk(MOUNT
, "NFS: mount options string was NULL.\n");
939 dfprintk(MOUNT
, "NFS: nfs mount opts='%s'\n", raw
);
941 secdata
= alloc_secdata();
945 rc
= security_sb_copy_data(raw
, secdata
);
947 goto out_security_failure
;
949 rc
= security_sb_parse_opts_str(secdata
, &mnt
->lsm_opts
);
951 goto out_security_failure
;
953 free_secdata(secdata
);
955 while ((p
= strsep(&raw
, ",")) != NULL
) {
956 substring_t args
[MAX_OPT_ARGS
];
962 dfprintk(MOUNT
, "NFS: parsing nfs mount option '%s'\n", p
);
964 token
= match_token(p
, nfs_mount_option_tokens
, args
);
968 * boolean options: foo/nofoo
971 mnt
->flags
|= NFS_MOUNT_SOFT
;
974 mnt
->flags
&= ~NFS_MOUNT_SOFT
;
977 mnt
->flags
|= NFS_MOUNT_POSIX
;
980 mnt
->flags
&= ~NFS_MOUNT_POSIX
;
983 mnt
->flags
&= ~NFS_MOUNT_NOCTO
;
986 mnt
->flags
|= NFS_MOUNT_NOCTO
;
989 mnt
->flags
&= ~NFS_MOUNT_NOAC
;
992 mnt
->flags
|= NFS_MOUNT_NOAC
;
995 mnt
->flags
&= ~NFS_MOUNT_NONLM
;
998 mnt
->flags
|= NFS_MOUNT_NONLM
;
1001 mnt
->flags
&= ~NFS_MOUNT_VER3
;
1004 mnt
->flags
|= NFS_MOUNT_VER3
;
1007 mnt
->flags
&= ~NFS_MOUNT_TCP
;
1008 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1011 mnt
->flags
|= NFS_MOUNT_TCP
;
1012 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1015 mnt
->flags
|= NFS_MOUNT_TCP
; /* for side protocols */
1016 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_RDMA
;
1019 mnt
->flags
&= ~NFS_MOUNT_NOACL
;
1022 mnt
->flags
|= NFS_MOUNT_NOACL
;
1025 mnt
->flags
&= ~NFS_MOUNT_NORDIRPLUS
;
1027 case Opt_nordirplus
:
1028 mnt
->flags
|= NFS_MOUNT_NORDIRPLUS
;
1030 case Opt_sharecache
:
1031 mnt
->flags
&= ~NFS_MOUNT_UNSHARED
;
1033 case Opt_nosharecache
:
1034 mnt
->flags
|= NFS_MOUNT_UNSHARED
;
1038 * options that take numeric values
1041 if (match_int(args
, &option
) ||
1042 option
< 0 || option
> USHORT_MAX
) {
1044 nfs_parse_invalid_value("port");
1046 mnt
->nfs_server
.port
= option
;
1049 if (match_int(args
, &option
) || option
< 0) {
1051 nfs_parse_invalid_value("rsize");
1053 mnt
->rsize
= option
;
1056 if (match_int(args
, &option
) || option
< 0) {
1058 nfs_parse_invalid_value("wsize");
1060 mnt
->wsize
= option
;
1063 if (match_int(args
, &option
) || option
< 0) {
1065 nfs_parse_invalid_value("bsize");
1067 mnt
->bsize
= option
;
1070 if (match_int(args
, &option
) || option
<= 0) {
1072 nfs_parse_invalid_value("timeo");
1074 mnt
->timeo
= option
;
1077 if (match_int(args
, &option
) || option
<= 0) {
1079 nfs_parse_invalid_value("retrans");
1081 mnt
->retrans
= option
;
1084 if (match_int(args
, &option
) || option
< 0) {
1086 nfs_parse_invalid_value("acregmin");
1088 mnt
->acregmin
= option
;
1091 if (match_int(args
, &option
) || option
< 0) {
1093 nfs_parse_invalid_value("acregmax");
1095 mnt
->acregmax
= option
;
1098 if (match_int(args
, &option
) || option
< 0) {
1100 nfs_parse_invalid_value("acdirmin");
1102 mnt
->acdirmin
= option
;
1105 if (match_int(args
, &option
) || option
< 0) {
1107 nfs_parse_invalid_value("acdirmax");
1109 mnt
->acdirmax
= option
;
1112 if (match_int(args
, &option
) || option
< 0) {
1114 nfs_parse_invalid_value("actimeo");
1116 mnt
->acregmin
= mnt
->acregmax
=
1117 mnt
->acdirmin
= mnt
->acdirmax
= option
;
1120 if (match_int(args
, &option
) || option
< 0) {
1122 nfs_parse_invalid_value("namlen");
1124 mnt
->namlen
= option
;
1127 if (match_int(args
, &option
) ||
1128 option
< 0 || option
> USHORT_MAX
) {
1130 nfs_parse_invalid_value("mountport");
1132 mnt
->mount_server
.port
= option
;
1135 if (match_int(args
, &option
) ||
1136 option
< NFS_MNT_VERSION
||
1137 option
> NFS_MNT3_VERSION
) {
1139 nfs_parse_invalid_value("mountvers");
1141 mnt
->mount_server
.version
= option
;
1144 if (match_int(args
, &option
)) {
1146 nfs_parse_invalid_value("nfsvers");
1151 mnt
->flags
&= ~NFS_MOUNT_VER3
;
1154 mnt
->flags
|= NFS_MOUNT_VER3
;
1158 nfs_parse_invalid_value("nfsvers");
1163 * options that take text values
1166 string
= match_strdup(args
);
1169 rc
= nfs_parse_security_flavors(string
, mnt
);
1173 dfprintk(MOUNT
, "NFS: unrecognized "
1174 "security flavor\n");
1178 string
= match_strdup(args
);
1181 token
= match_token(string
,
1182 nfs_xprt_protocol_tokens
, args
);
1187 mnt
->flags
&= ~NFS_MOUNT_TCP
;
1188 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1191 mnt
->flags
|= NFS_MOUNT_TCP
;
1192 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1195 /* vector side protocols to TCP */
1196 mnt
->flags
|= NFS_MOUNT_TCP
;
1197 mnt
->nfs_server
.protocol
= XPRT_TRANSPORT_RDMA
;
1201 dfprintk(MOUNT
, "NFS: unrecognized "
1202 "transport protocol\n");
1205 case Opt_mountproto
:
1206 string
= match_strdup(args
);
1209 token
= match_token(string
,
1210 nfs_xprt_protocol_tokens
, args
);
1215 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_UDP
;
1218 mnt
->mount_server
.protocol
= XPRT_TRANSPORT_TCP
;
1220 case Opt_xprt_rdma
: /* not used for side protocols */
1223 dfprintk(MOUNT
, "NFS: unrecognized "
1224 "transport protocol\n");
1228 string
= match_strdup(args
);
1231 nfs_parse_ip_address(string
, strlen(string
),
1233 &mnt
->nfs_server
.address
,
1234 &mnt
->nfs_server
.addrlen
);
1237 case Opt_clientaddr
:
1238 string
= match_strdup(args
);
1241 kfree(mnt
->client_address
);
1242 mnt
->client_address
= string
;
1245 string
= match_strdup(args
);
1248 kfree(mnt
->mount_server
.hostname
);
1249 mnt
->mount_server
.hostname
= string
;
1252 string
= match_strdup(args
);
1255 nfs_parse_ip_address(string
, strlen(string
),
1257 &mnt
->mount_server
.address
,
1258 &mnt
->mount_server
.addrlen
);
1267 dfprintk(MOUNT
, "NFS: relaxing parsing rules\n");
1270 case Opt_deprecated
:
1271 dfprintk(MOUNT
, "NFS: ignoring mount option "
1277 dfprintk(MOUNT
, "NFS: unrecognized mount option "
1285 printk(KERN_INFO
"NFS: not enough memory to parse option\n");
1287 out_security_failure
:
1288 free_secdata(secdata
);
1289 printk(KERN_INFO
"NFS: security options invalid: %d\n", rc
);
1294 * Use the remote server's MOUNT service to request the NFS file handle
1295 * corresponding to the provided path.
1297 static int nfs_try_mount(struct nfs_parsed_mount_data
*args
,
1298 struct nfs_fh
*root_fh
)
1300 struct sockaddr
*sap
= (struct sockaddr
*)&args
->mount_server
.address
;
1304 if (args
->mount_server
.version
== 0) {
1305 if (args
->flags
& NFS_MOUNT_VER3
)
1306 args
->mount_server
.version
= NFS_MNT3_VERSION
;
1308 args
->mount_server
.version
= NFS_MNT_VERSION
;
1311 if (args
->mount_server
.hostname
)
1312 hostname
= args
->mount_server
.hostname
;
1314 hostname
= args
->nfs_server
.hostname
;
1317 * Construct the mount server's address.
1319 if (args
->mount_server
.address
.ss_family
== AF_UNSPEC
) {
1320 memcpy(sap
, &args
->nfs_server
.address
,
1321 args
->nfs_server
.addrlen
);
1322 args
->mount_server
.addrlen
= args
->nfs_server
.addrlen
;
1326 * autobind will be used if mount_server.port == 0
1328 nfs_set_port(sap
, args
->mount_server
.port
);
1331 * Now ask the mount server to map our export path
1334 status
= nfs_mount(sap
,
1335 args
->mount_server
.addrlen
,
1337 args
->nfs_server
.export_path
,
1338 args
->mount_server
.version
,
1339 args
->mount_server
.protocol
,
1344 dfprintk(MOUNT
, "NFS: unable to mount server %s, error %d\n",
1349 static int nfs_parse_simple_hostname(const char *dev_name
,
1350 char **hostname
, size_t maxnamlen
,
1351 char **export_path
, size_t maxpathlen
)
1354 char *colon
, *comma
;
1356 colon
= strchr(dev_name
, ':');
1358 goto out_bad_devname
;
1360 len
= colon
- dev_name
;
1361 if (len
> maxnamlen
)
1364 /* N.B. caller will free nfs_server.hostname in all cases */
1365 *hostname
= kstrndup(dev_name
, len
, GFP_KERNEL
);
1369 /* kill possible hostname list: not supported */
1370 comma
= strchr(*hostname
, ',');
1371 if (comma
!= NULL
) {
1372 if (comma
== *hostname
)
1373 goto out_bad_devname
;
1378 len
= strlen(colon
);
1379 if (len
> maxpathlen
)
1381 *export_path
= kstrndup(colon
, len
, GFP_KERNEL
);
1385 dfprintk(MOUNT
, "NFS: MNTPATH: '%s'\n", *export_path
);
1389 dfprintk(MOUNT
, "NFS: device name not in host:path format\n");
1393 dfprintk(MOUNT
, "NFS: not enough memory to parse device name\n");
1397 dfprintk(MOUNT
, "NFS: server hostname too long\n");
1398 return -ENAMETOOLONG
;
1401 dfprintk(MOUNT
, "NFS: export pathname too long\n");
1402 return -ENAMETOOLONG
;
1406 * Hostname has square brackets around it because it contains one or
1407 * more colons. We look for the first closing square bracket, and a
1408 * colon must follow it.
1410 static int nfs_parse_protected_hostname(const char *dev_name
,
1411 char **hostname
, size_t maxnamlen
,
1412 char **export_path
, size_t maxpathlen
)
1417 start
= (char *)(dev_name
+ 1);
1419 end
= strchr(start
, ']');
1421 goto out_bad_devname
;
1422 if (*(end
+ 1) != ':')
1423 goto out_bad_devname
;
1426 if (len
> maxnamlen
)
1429 /* N.B. caller will free nfs_server.hostname in all cases */
1430 *hostname
= kstrndup(start
, len
, GFP_KERNEL
);
1431 if (*hostname
== NULL
)
1436 if (len
> maxpathlen
)
1438 *export_path
= kstrndup(end
, len
, GFP_KERNEL
);
1445 dfprintk(MOUNT
, "NFS: device name not in host:path format\n");
1449 dfprintk(MOUNT
, "NFS: not enough memory to parse device name\n");
1453 dfprintk(MOUNT
, "NFS: server hostname too long\n");
1454 return -ENAMETOOLONG
;
1457 dfprintk(MOUNT
, "NFS: export pathname too long\n");
1458 return -ENAMETOOLONG
;
1462 * Split "dev_name" into "hostname:export_path".
1464 * The leftmost colon demarks the split between the server's hostname
1465 * and the export path. If the hostname starts with a left square
1466 * bracket, then it may contain colons.
1468 * Note: caller frees hostname and export path, even on error.
1470 static int nfs_parse_devname(const char *dev_name
,
1471 char **hostname
, size_t maxnamlen
,
1472 char **export_path
, size_t maxpathlen
)
1474 if (*dev_name
== '[')
1475 return nfs_parse_protected_hostname(dev_name
,
1476 hostname
, maxnamlen
,
1477 export_path
, maxpathlen
);
1479 return nfs_parse_simple_hostname(dev_name
,
1480 hostname
, maxnamlen
,
1481 export_path
, maxpathlen
);
1485 * Validate the NFS2/NFS3 mount data
1486 * - fills in the mount root filehandle
1488 * For option strings, user space handles the following behaviors:
1490 * + DNS: mapping server host name to IP address ("addr=" option)
1492 * + failure mode: how to behave if a mount request can't be handled
1493 * immediately ("fg/bg" option)
1495 * + retry: how often to retry a mount request ("retry=" option)
1497 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1498 * mountproto=tcp after mountproto=udp, and so on
1500 static int nfs_validate_mount_data(void *options
,
1501 struct nfs_parsed_mount_data
*args
,
1502 struct nfs_fh
*mntfh
,
1503 const char *dev_name
)
1505 struct nfs_mount_data
*data
= (struct nfs_mount_data
*)options
;
1510 args
->flags
= (NFS_MOUNT_VER3
| NFS_MOUNT_TCP
);
1511 args
->rsize
= NFS_MAX_FILE_IO_SIZE
;
1512 args
->wsize
= NFS_MAX_FILE_IO_SIZE
;
1513 args
->acregmin
= NFS_DEF_ACREGMIN
;
1514 args
->acregmax
= NFS_DEF_ACREGMAX
;
1515 args
->acdirmin
= NFS_DEF_ACDIRMIN
;
1516 args
->acdirmax
= NFS_DEF_ACDIRMAX
;
1517 args
->mount_server
.port
= 0; /* autobind unless user sets port */
1518 args
->nfs_server
.port
= 0; /* autobind unless user sets port */
1519 args
->nfs_server
.protocol
= XPRT_TRANSPORT_TCP
;
1520 args
->auth_flavors
[0] = RPC_AUTH_UNIX
;
1522 switch (data
->version
) {
1528 if (data
->flags
& NFS_MOUNT_VER3
)
1530 data
->root
.size
= NFS2_FHSIZE
;
1531 memcpy(data
->root
.data
, data
->old_root
.data
, NFS2_FHSIZE
);
1533 if (data
->flags
& NFS_MOUNT_SECFLAVOUR
)
1536 memset(data
->context
, 0, sizeof(data
->context
));
1538 if (data
->flags
& NFS_MOUNT_VER3
) {
1539 if (data
->root
.size
> NFS3_FHSIZE
|| data
->root
.size
== 0)
1540 goto out_invalid_fh
;
1541 mntfh
->size
= data
->root
.size
;
1543 mntfh
->size
= NFS2_FHSIZE
;
1546 memcpy(mntfh
->data
, data
->root
.data
, mntfh
->size
);
1547 if (mntfh
->size
< sizeof(mntfh
->data
))
1548 memset(mntfh
->data
+ mntfh
->size
, 0,
1549 sizeof(mntfh
->data
) - mntfh
->size
);
1552 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1555 args
->flags
= data
->flags
;
1556 args
->rsize
= data
->rsize
;
1557 args
->wsize
= data
->wsize
;
1558 args
->timeo
= data
->timeo
;
1559 args
->retrans
= data
->retrans
;
1560 args
->acregmin
= data
->acregmin
;
1561 args
->acregmax
= data
->acregmax
;
1562 args
->acdirmin
= data
->acdirmin
;
1563 args
->acdirmax
= data
->acdirmax
;
1565 memcpy(&args
->nfs_server
.address
, &data
->addr
,
1566 sizeof(data
->addr
));
1567 args
->nfs_server
.addrlen
= sizeof(data
->addr
);
1568 if (!nfs_verify_server_address((struct sockaddr
*)
1569 &args
->nfs_server
.address
))
1570 goto out_no_address
;
1572 if (!(data
->flags
& NFS_MOUNT_TCP
))
1573 args
->nfs_server
.protocol
= XPRT_TRANSPORT_UDP
;
1574 /* N.B. caller will free nfs_server.hostname in all cases */
1575 args
->nfs_server
.hostname
= kstrdup(data
->hostname
, GFP_KERNEL
);
1576 args
->namlen
= data
->namlen
;
1577 args
->bsize
= data
->bsize
;
1579 if (data
->flags
& NFS_MOUNT_SECFLAVOUR
)
1580 args
->auth_flavors
[0] = data
->pseudoflavor
;
1581 if (!args
->nfs_server
.hostname
)
1585 * The legacy version 6 binary mount data from userspace has a
1586 * field used only to transport selinux information into the
1587 * the kernel. To continue to support that functionality we
1588 * have a touch of selinux knowledge here in the NFS code. The
1589 * userspace code converted context=blah to just blah so we are
1590 * converting back to the full string selinux understands.
1592 if (data
->context
[0]){
1593 #ifdef CONFIG_SECURITY_SELINUX
1595 char *opts_str
= kmalloc(sizeof(data
->context
) + 8, GFP_KERNEL
);
1598 strcpy(opts_str
, "context=");
1599 data
->context
[NFS_MAX_CONTEXT_LEN
] = '\0';
1600 strcat(opts_str
, &data
->context
[0]);
1601 rc
= security_sb_parse_opts_str(opts_str
, &args
->lsm_opts
);
1614 if (nfs_parse_mount_options((char *)options
, args
) == 0)
1617 if (!nfs_verify_server_address((struct sockaddr
*)
1618 &args
->nfs_server
.address
))
1619 goto out_no_address
;
1621 nfs_set_port((struct sockaddr
*)&args
->nfs_server
.address
,
1622 args
->nfs_server
.port
);
1624 nfs_set_mount_transport_protocol(args
);
1626 status
= nfs_parse_devname(dev_name
,
1627 &args
->nfs_server
.hostname
,
1629 &args
->nfs_server
.export_path
,
1632 status
= nfs_try_mount(args
, mntfh
);
1634 kfree(args
->nfs_server
.export_path
);
1635 args
->nfs_server
.export_path
= NULL
;
1644 #ifndef CONFIG_NFS_V3
1645 if (args
->flags
& NFS_MOUNT_VER3
)
1646 goto out_v3_not_compiled
;
1647 #endif /* !CONFIG_NFS_V3 */
1652 dfprintk(MOUNT
, "NFS: mount program didn't pass any mount data\n");
1656 dfprintk(MOUNT
, "NFS: nfs_mount_data version %d does not support v3\n",
1661 dfprintk(MOUNT
, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1664 #ifndef CONFIG_NFS_V3
1665 out_v3_not_compiled
:
1666 dfprintk(MOUNT
, "NFS: NFSv3 is not compiled into kernel\n");
1667 return -EPROTONOSUPPORT
;
1668 #endif /* !CONFIG_NFS_V3 */
1671 dfprintk(MOUNT
, "NFS: not enough memory to handle mount options\n");
1675 dfprintk(MOUNT
, "NFS: mount program didn't pass remote address\n");
1679 dfprintk(MOUNT
, "NFS: invalid root filehandle\n");
1684 nfs_compare_remount_data(struct nfs_server
*nfss
,
1685 struct nfs_parsed_mount_data
*data
)
1687 if (data
->flags
!= nfss
->flags
||
1688 data
->rsize
!= nfss
->rsize
||
1689 data
->wsize
!= nfss
->wsize
||
1690 data
->retrans
!= nfss
->client
->cl_timeout
->to_retries
||
1691 data
->auth_flavors
[0] != nfss
->client
->cl_auth
->au_flavor
||
1692 data
->acregmin
!= nfss
->acregmin
/ HZ
||
1693 data
->acregmax
!= nfss
->acregmax
/ HZ
||
1694 data
->acdirmin
!= nfss
->acdirmin
/ HZ
||
1695 data
->acdirmax
!= nfss
->acdirmax
/ HZ
||
1696 data
->timeo
!= (10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
) ||
1697 data
->nfs_server
.addrlen
!= nfss
->nfs_client
->cl_addrlen
||
1698 memcmp(&data
->nfs_server
.address
, &nfss
->nfs_client
->cl_addr
,
1699 data
->nfs_server
.addrlen
) != 0)
1706 nfs_remount(struct super_block
*sb
, int *flags
, char *raw_data
)
1709 struct nfs_server
*nfss
= sb
->s_fs_info
;
1710 struct nfs_parsed_mount_data
*data
;
1711 struct nfs_mount_data
*options
= (struct nfs_mount_data
*)raw_data
;
1712 struct nfs4_mount_data
*options4
= (struct nfs4_mount_data
*)raw_data
;
1713 u32 nfsvers
= nfss
->nfs_client
->rpc_ops
->version
;
1716 * Userspace mount programs that send binary options generally send
1717 * them populated with default values. We have no way to know which
1718 * ones were explicitly specified. Fall back to legacy behavior and
1719 * just return success.
1721 if ((nfsvers
== 4 && options4
->version
== 1) ||
1722 (nfsvers
<= 3 && options
->version
>= 1 &&
1723 options
->version
<= 6))
1726 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
1730 /* fill out struct with values from existing mount */
1731 data
->flags
= nfss
->flags
;
1732 data
->rsize
= nfss
->rsize
;
1733 data
->wsize
= nfss
->wsize
;
1734 data
->retrans
= nfss
->client
->cl_timeout
->to_retries
;
1735 data
->auth_flavors
[0] = nfss
->client
->cl_auth
->au_flavor
;
1736 data
->acregmin
= nfss
->acregmin
/ HZ
;
1737 data
->acregmax
= nfss
->acregmax
/ HZ
;
1738 data
->acdirmin
= nfss
->acdirmin
/ HZ
;
1739 data
->acdirmax
= nfss
->acdirmax
/ HZ
;
1740 data
->timeo
= 10U * nfss
->client
->cl_timeout
->to_initval
/ HZ
;
1741 data
->nfs_server
.addrlen
= nfss
->nfs_client
->cl_addrlen
;
1742 memcpy(&data
->nfs_server
.address
, &nfss
->nfs_client
->cl_addr
,
1743 data
->nfs_server
.addrlen
);
1745 /* overwrite those values with any that were specified */
1746 error
= nfs_parse_mount_options((char *)options
, data
);
1750 /* compare new mount options with old ones */
1751 error
= nfs_compare_remount_data(nfss
, data
);
1758 * Initialise the common bits of the superblock
1760 static inline void nfs_initialise_sb(struct super_block
*sb
)
1762 struct nfs_server
*server
= NFS_SB(sb
);
1764 sb
->s_magic
= NFS_SUPER_MAGIC
;
1766 /* We probably want something more informative here */
1767 snprintf(sb
->s_id
, sizeof(sb
->s_id
),
1768 "%x:%x", MAJOR(sb
->s_dev
), MINOR(sb
->s_dev
));
1770 if (sb
->s_blocksize
== 0)
1771 sb
->s_blocksize
= nfs_block_bits(server
->wsize
,
1772 &sb
->s_blocksize_bits
);
1774 if (server
->flags
& NFS_MOUNT_NOAC
)
1775 sb
->s_flags
|= MS_SYNCHRONOUS
;
1777 nfs_super_set_maxbytes(sb
, server
->maxfilesize
);
1781 * Finish setting up an NFS2/3 superblock
1783 static void nfs_fill_super(struct super_block
*sb
,
1784 struct nfs_parsed_mount_data
*data
)
1786 struct nfs_server
*server
= NFS_SB(sb
);
1788 sb
->s_blocksize_bits
= 0;
1789 sb
->s_blocksize
= 0;
1791 sb
->s_blocksize
= nfs_block_size(data
->bsize
, &sb
->s_blocksize_bits
);
1793 if (server
->flags
& NFS_MOUNT_VER3
) {
1794 /* The VFS shouldn't apply the umask to mode bits. We will do
1795 * so ourselves when necessary.
1797 sb
->s_flags
|= MS_POSIXACL
;
1798 sb
->s_time_gran
= 1;
1801 sb
->s_op
= &nfs_sops
;
1802 nfs_initialise_sb(sb
);
1806 * Finish setting up a cloned NFS2/3 superblock
1808 static void nfs_clone_super(struct super_block
*sb
,
1809 const struct super_block
*old_sb
)
1811 struct nfs_server
*server
= NFS_SB(sb
);
1813 sb
->s_blocksize_bits
= old_sb
->s_blocksize_bits
;
1814 sb
->s_blocksize
= old_sb
->s_blocksize
;
1815 sb
->s_maxbytes
= old_sb
->s_maxbytes
;
1817 if (server
->flags
& NFS_MOUNT_VER3
) {
1818 /* The VFS shouldn't apply the umask to mode bits. We will do
1819 * so ourselves when necessary.
1821 sb
->s_flags
|= MS_POSIXACL
;
1822 sb
->s_time_gran
= 1;
1825 sb
->s_op
= old_sb
->s_op
;
1826 nfs_initialise_sb(sb
);
1829 #define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
1831 static int nfs_compare_mount_options(const struct super_block
*s
, const struct nfs_server
*b
, int flags
)
1833 const struct nfs_server
*a
= s
->s_fs_info
;
1834 const struct rpc_clnt
*clnt_a
= a
->client
;
1835 const struct rpc_clnt
*clnt_b
= b
->client
;
1837 if ((s
->s_flags
& NFS_MS_MASK
) != (flags
& NFS_MS_MASK
))
1839 if (a
->nfs_client
!= b
->nfs_client
)
1841 if (a
->flags
!= b
->flags
)
1843 if (a
->wsize
!= b
->wsize
)
1845 if (a
->rsize
!= b
->rsize
)
1847 if (a
->acregmin
!= b
->acregmin
)
1849 if (a
->acregmax
!= b
->acregmax
)
1851 if (a
->acdirmin
!= b
->acdirmin
)
1853 if (a
->acdirmax
!= b
->acdirmax
)
1855 if (clnt_a
->cl_auth
->au_flavor
!= clnt_b
->cl_auth
->au_flavor
)
1862 struct nfs_sb_mountdata
{
1863 struct nfs_server
*server
;
1867 static int nfs_set_super(struct super_block
*s
, void *data
)
1869 struct nfs_sb_mountdata
*sb_mntdata
= data
;
1870 struct nfs_server
*server
= sb_mntdata
->server
;
1873 s
->s_flags
= sb_mntdata
->mntflags
;
1874 s
->s_fs_info
= server
;
1875 ret
= set_anon_super(s
, server
);
1877 server
->s_dev
= s
->s_dev
;
1881 static int nfs_compare_super_address(struct nfs_server
*server1
,
1882 struct nfs_server
*server2
)
1884 struct sockaddr
*sap1
, *sap2
;
1886 sap1
= (struct sockaddr
*)&server1
->nfs_client
->cl_addr
;
1887 sap2
= (struct sockaddr
*)&server2
->nfs_client
->cl_addr
;
1889 if (sap1
->sa_family
!= sap2
->sa_family
)
1892 switch (sap1
->sa_family
) {
1894 struct sockaddr_in
*sin1
= (struct sockaddr_in
*)sap1
;
1895 struct sockaddr_in
*sin2
= (struct sockaddr_in
*)sap2
;
1896 if (sin1
->sin_addr
.s_addr
!= sin2
->sin_addr
.s_addr
)
1898 if (sin1
->sin_port
!= sin2
->sin_port
)
1903 struct sockaddr_in6
*sin1
= (struct sockaddr_in6
*)sap1
;
1904 struct sockaddr_in6
*sin2
= (struct sockaddr_in6
*)sap2
;
1905 if (!ipv6_addr_equal(&sin1
->sin6_addr
, &sin2
->sin6_addr
))
1907 if (sin1
->sin6_port
!= sin2
->sin6_port
)
1918 static int nfs_compare_super(struct super_block
*sb
, void *data
)
1920 struct nfs_sb_mountdata
*sb_mntdata
= data
;
1921 struct nfs_server
*server
= sb_mntdata
->server
, *old
= NFS_SB(sb
);
1922 int mntflags
= sb_mntdata
->mntflags
;
1924 if (!nfs_compare_super_address(old
, server
))
1926 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1927 if (old
->flags
& NFS_MOUNT_UNSHARED
)
1929 if (memcmp(&old
->fsid
, &server
->fsid
, sizeof(old
->fsid
)) != 0)
1931 return nfs_compare_mount_options(sb
, server
, mntflags
);
1934 static int nfs_bdi_register(struct nfs_server
*server
)
1936 return bdi_register_dev(&server
->backing_dev_info
, server
->s_dev
);
1939 static int nfs_get_sb(struct file_system_type
*fs_type
,
1940 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
1942 struct nfs_server
*server
= NULL
;
1943 struct super_block
*s
;
1944 struct nfs_parsed_mount_data
*data
;
1945 struct nfs_fh
*mntfh
;
1946 struct dentry
*mntroot
;
1947 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
1948 struct nfs_sb_mountdata sb_mntdata
= {
1951 int error
= -ENOMEM
;
1953 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
1954 mntfh
= kzalloc(sizeof(*mntfh
), GFP_KERNEL
);
1955 if (data
== NULL
|| mntfh
== NULL
)
1958 security_init_mnt_opts(&data
->lsm_opts
);
1960 /* Validate the mount data */
1961 error
= nfs_validate_mount_data(raw_data
, data
, mntfh
, dev_name
);
1965 /* Get a volume representation */
1966 server
= nfs_create_server(data
, mntfh
);
1967 if (IS_ERR(server
)) {
1968 error
= PTR_ERR(server
);
1971 sb_mntdata
.server
= server
;
1973 if (server
->flags
& NFS_MOUNT_UNSHARED
)
1974 compare_super
= NULL
;
1976 /* Get a superblock - note that we may end up sharing one that already exists */
1977 s
= sget(fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
1983 if (s
->s_fs_info
!= server
) {
1984 nfs_free_server(server
);
1987 error
= nfs_bdi_register(server
);
1989 goto error_splat_super
;
1993 /* initial superblock/root creation */
1994 nfs_fill_super(s
, data
);
1997 mntroot
= nfs_get_root(s
, mntfh
);
1998 if (IS_ERR(mntroot
)) {
1999 error
= PTR_ERR(mntroot
);
2000 goto error_splat_super
;
2003 error
= security_sb_set_mnt_opts(s
, &data
->lsm_opts
);
2005 goto error_splat_root
;
2007 s
->s_flags
|= MS_ACTIVE
;
2009 mnt
->mnt_root
= mntroot
;
2013 kfree(data
->nfs_server
.hostname
);
2014 kfree(data
->mount_server
.hostname
);
2015 security_free_mnt_opts(&data
->lsm_opts
);
2022 nfs_free_server(server
);
2028 up_write(&s
->s_umount
);
2029 deactivate_super(s
);
2034 * Destroy an NFS2/3 superblock
2036 static void nfs_kill_super(struct super_block
*s
)
2038 struct nfs_server
*server
= NFS_SB(s
);
2040 bdi_unregister(&server
->backing_dev_info
);
2042 nfs_free_server(server
);
2046 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2048 static int nfs_xdev_get_sb(struct file_system_type
*fs_type
, int flags
,
2049 const char *dev_name
, void *raw_data
,
2050 struct vfsmount
*mnt
)
2052 struct nfs_clone_mount
*data
= raw_data
;
2053 struct super_block
*s
;
2054 struct nfs_server
*server
;
2055 struct dentry
*mntroot
;
2056 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2057 struct nfs_sb_mountdata sb_mntdata
= {
2062 dprintk("--> nfs_xdev_get_sb()\n");
2064 /* create a new volume representation */
2065 server
= nfs_clone_server(NFS_SB(data
->sb
), data
->fh
, data
->fattr
);
2066 if (IS_ERR(server
)) {
2067 error
= PTR_ERR(server
);
2068 goto out_err_noserver
;
2070 sb_mntdata
.server
= server
;
2072 if (server
->flags
& NFS_MOUNT_UNSHARED
)
2073 compare_super
= NULL
;
2075 /* Get a superblock - note that we may end up sharing one that already exists */
2076 s
= sget(&nfs_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2082 if (s
->s_fs_info
!= server
) {
2083 nfs_free_server(server
);
2086 error
= nfs_bdi_register(server
);
2088 goto error_splat_super
;
2092 /* initial superblock/root creation */
2093 nfs_clone_super(s
, data
->sb
);
2096 mntroot
= nfs_get_root(s
, data
->fh
);
2097 if (IS_ERR(mntroot
)) {
2098 error
= PTR_ERR(mntroot
);
2099 goto error_splat_super
;
2101 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
2104 goto error_splat_super
;
2107 s
->s_flags
|= MS_ACTIVE
;
2109 mnt
->mnt_root
= mntroot
;
2111 /* clone any lsm security options from the parent to the new sb */
2112 security_sb_clone_mnt_opts(data
->sb
, s
);
2114 dprintk("<-- nfs_xdev_get_sb() = 0\n");
2118 nfs_free_server(server
);
2120 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error
);
2124 up_write(&s
->s_umount
);
2125 deactivate_super(s
);
2126 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error
);
2130 #ifdef CONFIG_NFS_V4
2133 * Finish setting up a cloned NFS4 superblock
2135 static void nfs4_clone_super(struct super_block
*sb
,
2136 const struct super_block
*old_sb
)
2138 sb
->s_blocksize_bits
= old_sb
->s_blocksize_bits
;
2139 sb
->s_blocksize
= old_sb
->s_blocksize
;
2140 sb
->s_maxbytes
= old_sb
->s_maxbytes
;
2141 sb
->s_time_gran
= 1;
2142 sb
->s_op
= old_sb
->s_op
;
2143 nfs_initialise_sb(sb
);
2147 * Set up an NFS4 superblock
2149 static void nfs4_fill_super(struct super_block
*sb
)
2151 sb
->s_time_gran
= 1;
2152 sb
->s_op
= &nfs4_sops
;
2153 nfs_initialise_sb(sb
);
2157 * Validate NFSv4 mount options
2159 static int nfs4_validate_mount_data(void *options
,
2160 struct nfs_parsed_mount_data
*args
,
2161 const char *dev_name
)
2163 struct sockaddr_in
*ap
;
2164 struct nfs4_mount_data
*data
= (struct nfs4_mount_data
*)options
;
2170 args
->rsize
= NFS_MAX_FILE_IO_SIZE
;
2171 args
->wsize
= NFS_MAX_FILE_IO_SIZE
;
2172 args
->acregmin
= NFS_DEF_ACREGMIN
;
2173 args
->acregmax
= NFS_DEF_ACREGMAX
;
2174 args
->acdirmin
= NFS_DEF_ACDIRMIN
;
2175 args
->acdirmax
= NFS_DEF_ACDIRMAX
;
2176 args
->nfs_server
.port
= NFS_PORT
; /* 2049 unless user set port= */
2177 args
->auth_flavors
[0] = RPC_AUTH_UNIX
;
2178 args
->auth_flavor_len
= 0;
2180 switch (data
->version
) {
2182 ap
= (struct sockaddr_in
*)&args
->nfs_server
.address
;
2183 if (data
->host_addrlen
> sizeof(args
->nfs_server
.address
))
2184 goto out_no_address
;
2185 if (data
->host_addrlen
== 0)
2186 goto out_no_address
;
2187 args
->nfs_server
.addrlen
= data
->host_addrlen
;
2188 if (copy_from_user(ap
, data
->host_addr
, data
->host_addrlen
))
2190 if (!nfs_verify_server_address((struct sockaddr
*)
2191 &args
->nfs_server
.address
))
2192 goto out_no_address
;
2194 if (data
->auth_flavourlen
) {
2195 if (data
->auth_flavourlen
> 1)
2196 goto out_inval_auth
;
2197 if (copy_from_user(&args
->auth_flavors
[0],
2198 data
->auth_flavours
,
2199 sizeof(args
->auth_flavors
[0])))
2203 c
= strndup_user(data
->hostname
.data
, NFS4_MAXNAMLEN
);
2206 args
->nfs_server
.hostname
= c
;
2208 c
= strndup_user(data
->mnt_path
.data
, NFS4_MAXPATHLEN
);
2211 args
->nfs_server
.export_path
= c
;
2212 dfprintk(MOUNT
, "NFS: MNTPATH: '%s'\n", c
);
2214 c
= strndup_user(data
->client_addr
.data
, 16);
2217 args
->client_address
= c
;
2220 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2224 args
->flags
= data
->flags
& NFS4_MOUNT_FLAGMASK
;
2225 args
->rsize
= data
->rsize
;
2226 args
->wsize
= data
->wsize
;
2227 args
->timeo
= data
->timeo
;
2228 args
->retrans
= data
->retrans
;
2229 args
->acregmin
= data
->acregmin
;
2230 args
->acregmax
= data
->acregmax
;
2231 args
->acdirmin
= data
->acdirmin
;
2232 args
->acdirmax
= data
->acdirmax
;
2233 args
->nfs_server
.protocol
= data
->proto
;
2234 nfs_validate_transport_protocol(args
);
2240 if (nfs_parse_mount_options((char *)options
, args
) == 0)
2243 if (!nfs_verify_server_address((struct sockaddr
*)
2244 &args
->nfs_server
.address
))
2247 nfs_set_port((struct sockaddr
*)&args
->nfs_server
.address
,
2248 args
->nfs_server
.port
);
2250 nfs_validate_transport_protocol(args
);
2252 if (args
->auth_flavor_len
> 1)
2253 goto out_inval_auth
;
2255 if (args
->client_address
== NULL
)
2256 goto out_no_client_address
;
2258 status
= nfs_parse_devname(dev_name
,
2259 &args
->nfs_server
.hostname
,
2261 &args
->nfs_server
.export_path
,
2273 dfprintk(MOUNT
, "NFS4: mount program didn't pass any mount data\n");
2277 dfprintk(MOUNT
, "NFS4: Invalid number of RPC auth flavours %d\n",
2278 data
->auth_flavourlen
);
2282 dfprintk(MOUNT
, "NFS4: mount program didn't pass remote address\n");
2285 out_no_client_address
:
2286 dfprintk(MOUNT
, "NFS4: mount program didn't pass callback address\n");
2291 * Get the superblock for an NFS4 mountpoint
2293 static int nfs4_get_sb(struct file_system_type
*fs_type
,
2294 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
2296 struct nfs_parsed_mount_data
*data
;
2297 struct super_block
*s
;
2298 struct nfs_server
*server
;
2299 struct nfs_fh
*mntfh
;
2300 struct dentry
*mntroot
;
2301 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2302 struct nfs_sb_mountdata sb_mntdata
= {
2305 int error
= -ENOMEM
;
2307 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
2308 mntfh
= kzalloc(sizeof(*mntfh
), GFP_KERNEL
);
2309 if (data
== NULL
|| mntfh
== NULL
)
2312 security_init_mnt_opts(&data
->lsm_opts
);
2314 /* Validate the mount data */
2315 error
= nfs4_validate_mount_data(raw_data
, data
, dev_name
);
2319 /* Get a volume representation */
2320 server
= nfs4_create_server(data
, mntfh
);
2321 if (IS_ERR(server
)) {
2322 error
= PTR_ERR(server
);
2325 sb_mntdata
.server
= server
;
2327 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2328 compare_super
= NULL
;
2330 /* Get a superblock - note that we may end up sharing one that already exists */
2331 s
= sget(fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2337 if (s
->s_fs_info
!= server
) {
2338 nfs_free_server(server
);
2341 error
= nfs_bdi_register(server
);
2343 goto error_splat_super
;
2347 /* initial superblock/root creation */
2351 mntroot
= nfs4_get_root(s
, mntfh
);
2352 if (IS_ERR(mntroot
)) {
2353 error
= PTR_ERR(mntroot
);
2354 goto error_splat_super
;
2357 error
= security_sb_set_mnt_opts(s
, &data
->lsm_opts
);
2359 goto error_splat_root
;
2361 s
->s_flags
|= MS_ACTIVE
;
2363 mnt
->mnt_root
= mntroot
;
2367 kfree(data
->client_address
);
2368 kfree(data
->nfs_server
.export_path
);
2369 kfree(data
->nfs_server
.hostname
);
2370 security_free_mnt_opts(&data
->lsm_opts
);
2377 nfs_free_server(server
);
2383 up_write(&s
->s_umount
);
2384 deactivate_super(s
);
2388 static void nfs4_kill_super(struct super_block
*sb
)
2390 struct nfs_server
*server
= NFS_SB(sb
);
2392 nfs_return_all_delegations(sb
);
2393 kill_anon_super(sb
);
2395 nfs4_renewd_prepare_shutdown(server
);
2396 nfs_free_server(server
);
2400 * Clone an NFS4 server record on xdev traversal (FSID-change)
2402 static int nfs4_xdev_get_sb(struct file_system_type
*fs_type
, int flags
,
2403 const char *dev_name
, void *raw_data
,
2404 struct vfsmount
*mnt
)
2406 struct nfs_clone_mount
*data
= raw_data
;
2407 struct super_block
*s
;
2408 struct nfs_server
*server
;
2409 struct dentry
*mntroot
;
2410 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2411 struct nfs_sb_mountdata sb_mntdata
= {
2416 dprintk("--> nfs4_xdev_get_sb()\n");
2418 /* create a new volume representation */
2419 server
= nfs_clone_server(NFS_SB(data
->sb
), data
->fh
, data
->fattr
);
2420 if (IS_ERR(server
)) {
2421 error
= PTR_ERR(server
);
2422 goto out_err_noserver
;
2424 sb_mntdata
.server
= server
;
2426 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2427 compare_super
= NULL
;
2429 /* Get a superblock - note that we may end up sharing one that already exists */
2430 s
= sget(&nfs_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2436 if (s
->s_fs_info
!= server
) {
2437 nfs_free_server(server
);
2440 error
= nfs_bdi_register(server
);
2442 goto error_splat_super
;
2446 /* initial superblock/root creation */
2447 nfs4_clone_super(s
, data
->sb
);
2450 mntroot
= nfs4_get_root(s
, data
->fh
);
2451 if (IS_ERR(mntroot
)) {
2452 error
= PTR_ERR(mntroot
);
2453 goto error_splat_super
;
2455 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
2458 goto error_splat_super
;
2461 s
->s_flags
|= MS_ACTIVE
;
2463 mnt
->mnt_root
= mntroot
;
2465 security_sb_clone_mnt_opts(data
->sb
, s
);
2467 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2471 nfs_free_server(server
);
2473 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error
);
2477 up_write(&s
->s_umount
);
2478 deactivate_super(s
);
2479 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error
);
2484 * Create an NFS4 server record on referral traversal
2486 static int nfs4_referral_get_sb(struct file_system_type
*fs_type
, int flags
,
2487 const char *dev_name
, void *raw_data
,
2488 struct vfsmount
*mnt
)
2490 struct nfs_clone_mount
*data
= raw_data
;
2491 struct super_block
*s
;
2492 struct nfs_server
*server
;
2493 struct dentry
*mntroot
;
2494 struct nfs_fh mntfh
;
2495 int (*compare_super
)(struct super_block
*, void *) = nfs_compare_super
;
2496 struct nfs_sb_mountdata sb_mntdata
= {
2501 dprintk("--> nfs4_referral_get_sb()\n");
2503 /* create a new volume representation */
2504 server
= nfs4_create_referral_server(data
, &mntfh
);
2505 if (IS_ERR(server
)) {
2506 error
= PTR_ERR(server
);
2507 goto out_err_noserver
;
2509 sb_mntdata
.server
= server
;
2511 if (server
->flags
& NFS4_MOUNT_UNSHARED
)
2512 compare_super
= NULL
;
2514 /* Get a superblock - note that we may end up sharing one that already exists */
2515 s
= sget(&nfs_fs_type
, compare_super
, nfs_set_super
, &sb_mntdata
);
2521 if (s
->s_fs_info
!= server
) {
2522 nfs_free_server(server
);
2525 error
= nfs_bdi_register(server
);
2527 goto error_splat_super
;
2531 /* initial superblock/root creation */
2535 mntroot
= nfs4_get_root(s
, &mntfh
);
2536 if (IS_ERR(mntroot
)) {
2537 error
= PTR_ERR(mntroot
);
2538 goto error_splat_super
;
2540 if (mntroot
->d_inode
->i_op
!= NFS_SB(s
)->nfs_client
->rpc_ops
->dir_inode_ops
) {
2543 goto error_splat_super
;
2546 s
->s_flags
|= MS_ACTIVE
;
2548 mnt
->mnt_root
= mntroot
;
2550 security_sb_clone_mnt_opts(data
->sb
, s
);
2552 dprintk("<-- nfs4_referral_get_sb() = 0\n");
2556 nfs_free_server(server
);
2558 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error
);
2562 up_write(&s
->s_umount
);
2563 deactivate_super(s
);
2564 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error
);
2568 #endif /* CONFIG_NFS_V4 */