4 * Copyright (C) 1992 Rick Sladkey
6 * nfs superblock handling functions
8 * Modularised by Alan Cox <Alan.Cox@linux.org>, while hacking some
9 * experimental NFS changes. Modularisation taken straight from SYS5 fs.
11 * Change to nfs_read_super() to permit NFS mounts to multi-homed hosts.
12 * J.S.Peatfield@damtp.cam.ac.uk
14 * Split from inode.c by David Howells <dhowells@redhat.com>
16 * - superblocks are indexed on server only - all inodes, dentries, etc. associated with a
17 * particular server are held in the same superblock
18 * - NFS superblocks can have several effective roots to the dentry tree
19 * - directory type roots are spliced into the tree when a path from one root reaches the root
20 * of another (see nfs_lookup())
23 #include <linux/module.h>
24 #include <linux/init.h>
26 #include <linux/time.h>
27 #include <linux/kernel.h>
29 #include <linux/string.h>
30 #include <linux/stat.h>
31 #include <linux/errno.h>
32 #include <linux/unistd.h>
33 #include <linux/sunrpc/clnt.h>
34 #include <linux/sunrpc/stats.h>
35 #include <linux/sunrpc/metrics.h>
36 #include <linux/nfs_fs.h>
37 #include <linux/nfs_mount.h>
38 #include <linux/nfs4_mount.h>
39 #include <linux/lockd/bind.h>
40 #include <linux/smp_lock.h>
41 #include <linux/seq_file.h>
42 #include <linux/mount.h>
43 #include <linux/nfs_idmap.h>
44 #include <linux/vfs.h>
45 #include <linux/inet.h>
46 #include <linux/nfs_xdr.h>
48 #include <asm/system.h>
49 #include <asm/uaccess.h>
53 #include "delegation.h"
57 #define NFSDBG_FACILITY NFSDBG_VFS
59 static void nfs_umount_begin(struct vfsmount
*, int);
60 static int nfs_statfs(struct dentry
*, struct kstatfs
*);
61 static int nfs_show_options(struct seq_file
*, struct vfsmount
*);
62 static int nfs_show_stats(struct seq_file
*, struct vfsmount
*);
63 static int nfs_get_sb(struct file_system_type
*, int, const char *, void *, struct vfsmount
*);
64 static int nfs_xdev_get_sb(struct file_system_type
*fs_type
,
65 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
66 static void nfs_kill_super(struct super_block
*);
68 static struct file_system_type nfs_fs_type
= {
72 .kill_sb
= nfs_kill_super
,
73 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
76 struct file_system_type nfs_xdev_fs_type
= {
79 .get_sb
= nfs_xdev_get_sb
,
80 .kill_sb
= nfs_kill_super
,
81 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
84 static struct super_operations nfs_sops
= {
85 .alloc_inode
= nfs_alloc_inode
,
86 .destroy_inode
= nfs_destroy_inode
,
87 .write_inode
= nfs_write_inode
,
89 .clear_inode
= nfs_clear_inode
,
90 .umount_begin
= nfs_umount_begin
,
91 .show_options
= nfs_show_options
,
92 .show_stats
= nfs_show_stats
,
96 static int nfs4_get_sb(struct file_system_type
*fs_type
,
97 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
98 static int nfs4_xdev_get_sb(struct file_system_type
*fs_type
,
99 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
100 static int nfs4_referral_get_sb(struct file_system_type
*fs_type
,
101 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
);
102 static void nfs4_kill_super(struct super_block
*sb
);
104 static struct file_system_type nfs4_fs_type
= {
105 .owner
= THIS_MODULE
,
107 .get_sb
= nfs4_get_sb
,
108 .kill_sb
= nfs4_kill_super
,
109 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
112 struct file_system_type nfs4_xdev_fs_type
= {
113 .owner
= THIS_MODULE
,
115 .get_sb
= nfs4_xdev_get_sb
,
116 .kill_sb
= nfs4_kill_super
,
117 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
120 struct file_system_type nfs4_referral_fs_type
= {
121 .owner
= THIS_MODULE
,
123 .get_sb
= nfs4_referral_get_sb
,
124 .kill_sb
= nfs4_kill_super
,
125 .fs_flags
= FS_RENAME_DOES_D_MOVE
|FS_REVAL_DOT
|FS_BINARY_MOUNTDATA
,
128 static struct super_operations nfs4_sops
= {
129 .alloc_inode
= nfs_alloc_inode
,
130 .destroy_inode
= nfs_destroy_inode
,
131 .write_inode
= nfs_write_inode
,
132 .statfs
= nfs_statfs
,
133 .clear_inode
= nfs4_clear_inode
,
134 .umount_begin
= nfs_umount_begin
,
135 .show_options
= nfs_show_options
,
136 .show_stats
= nfs_show_stats
,
140 static struct shrinker
*acl_shrinker
;
143 * Register the NFS filesystems
145 int __init
register_nfs_fs(void)
149 ret
= register_filesystem(&nfs_fs_type
);
154 ret
= nfs_register_sysctl();
157 ret
= register_filesystem(&nfs4_fs_type
);
161 acl_shrinker
= set_shrinker(DEFAULT_SEEKS
, nfs_access_cache_shrinker
);
166 nfs_unregister_sysctl();
168 unregister_filesystem(&nfs_fs_type
);
175 * Unregister the NFS filesystems
177 void __exit
unregister_nfs_fs(void)
179 if (acl_shrinker
!= NULL
)
180 remove_shrinker(acl_shrinker
);
182 unregister_filesystem(&nfs4_fs_type
);
183 nfs_unregister_sysctl();
185 unregister_filesystem(&nfs_fs_type
);
189 * Deliver file system statistics to userspace
191 static int nfs_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
193 struct nfs_server
*server
= NFS_SB(dentry
->d_sb
);
194 unsigned char blockbits
;
195 unsigned long blockres
;
196 struct nfs_fh
*fh
= NFS_FH(dentry
->d_inode
);
197 struct nfs_fattr fattr
;
198 struct nfs_fsstat res
= {
205 error
= server
->nfs_client
->rpc_ops
->statfs(server
, fh
, &res
);
206 buf
->f_type
= NFS_SUPER_MAGIC
;
211 * Current versions of glibc do not correctly handle the
212 * case where f_frsize != f_bsize. Eventually we want to
213 * report the value of wtmult in this field.
215 buf
->f_frsize
= dentry
->d_sb
->s_blocksize
;
218 * On most *nix systems, f_blocks, f_bfree, and f_bavail
219 * are reported in units of f_frsize. Linux hasn't had
220 * an f_frsize field in its statfs struct until recently,
221 * thus historically Linux's sys_statfs reports these
222 * fields in units of f_bsize.
224 buf
->f_bsize
= dentry
->d_sb
->s_blocksize
;
225 blockbits
= dentry
->d_sb
->s_blocksize_bits
;
226 blockres
= (1 << blockbits
) - 1;
227 buf
->f_blocks
= (res
.tbytes
+ blockres
) >> blockbits
;
228 buf
->f_bfree
= (res
.fbytes
+ blockres
) >> blockbits
;
229 buf
->f_bavail
= (res
.abytes
+ blockres
) >> blockbits
;
231 buf
->f_files
= res
.tfiles
;
232 buf
->f_ffree
= res
.afiles
;
234 buf
->f_namelen
= server
->namelen
;
240 dprintk("%s: statfs error = %d\n", __FUNCTION__
, -error
);
241 buf
->f_bsize
= buf
->f_blocks
= buf
->f_bfree
= buf
->f_bavail
= -1;
247 * Map the security flavour number to a name
249 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour
)
251 static const struct {
252 rpc_authflavor_t flavour
;
255 { RPC_AUTH_NULL
, "null" },
256 { RPC_AUTH_UNIX
, "sys" },
257 { RPC_AUTH_GSS_KRB5
, "krb5" },
258 { RPC_AUTH_GSS_KRB5I
, "krb5i" },
259 { RPC_AUTH_GSS_KRB5P
, "krb5p" },
260 { RPC_AUTH_GSS_LKEY
, "lkey" },
261 { RPC_AUTH_GSS_LKEYI
, "lkeyi" },
262 { RPC_AUTH_GSS_LKEYP
, "lkeyp" },
263 { RPC_AUTH_GSS_SPKM
, "spkm" },
264 { RPC_AUTH_GSS_SPKMI
, "spkmi" },
265 { RPC_AUTH_GSS_SPKMP
, "spkmp" },
270 for (i
=0; sec_flavours
[i
].flavour
!= -1; i
++) {
271 if (sec_flavours
[i
].flavour
== flavour
)
274 return sec_flavours
[i
].str
;
278 * Describe the mount options in force on this server representation
280 static void nfs_show_mount_options(struct seq_file
*m
, struct nfs_server
*nfss
, int showdefaults
)
282 static const struct proc_nfs_info
{
287 { NFS_MOUNT_SOFT
, ",soft", ",hard" },
288 { NFS_MOUNT_INTR
, ",intr", "" },
289 { NFS_MOUNT_NOCTO
, ",nocto", "" },
290 { NFS_MOUNT_NOAC
, ",noac", "" },
291 { NFS_MOUNT_NONLM
, ",nolock", "" },
292 { NFS_MOUNT_NOACL
, ",noacl", "" },
295 const struct proc_nfs_info
*nfs_infop
;
296 struct nfs_client
*clp
= nfss
->nfs_client
;
300 seq_printf(m
, ",vers=%d", clp
->rpc_ops
->version
);
301 seq_printf(m
, ",rsize=%d", nfss
->rsize
);
302 seq_printf(m
, ",wsize=%d", nfss
->wsize
);
303 if (nfss
->acregmin
!= 3*HZ
|| showdefaults
)
304 seq_printf(m
, ",acregmin=%d", nfss
->acregmin
/HZ
);
305 if (nfss
->acregmax
!= 60*HZ
|| showdefaults
)
306 seq_printf(m
, ",acregmax=%d", nfss
->acregmax
/HZ
);
307 if (nfss
->acdirmin
!= 30*HZ
|| showdefaults
)
308 seq_printf(m
, ",acdirmin=%d", nfss
->acdirmin
/HZ
);
309 if (nfss
->acdirmax
!= 60*HZ
|| showdefaults
)
310 seq_printf(m
, ",acdirmax=%d", nfss
->acdirmax
/HZ
);
311 for (nfs_infop
= nfs_info
; nfs_infop
->flag
; nfs_infop
++) {
312 if (nfss
->flags
& nfs_infop
->flag
)
313 seq_puts(m
, nfs_infop
->str
);
315 seq_puts(m
, nfs_infop
->nostr
);
317 switch (nfss
->client
->cl_xprt
->prot
) {
325 snprintf(buf
, sizeof(buf
), "%u", nfss
->client
->cl_xprt
->prot
);
328 seq_printf(m
, ",proto=%s", proto
);
329 seq_printf(m
, ",timeo=%lu", 10U * clp
->retrans_timeo
/ HZ
);
330 seq_printf(m
, ",retrans=%u", clp
->retrans_count
);
331 seq_printf(m
, ",sec=%s", nfs_pseudoflavour_to_name(nfss
->client
->cl_auth
->au_flavor
));
335 * Describe the mount options on this VFS mountpoint
337 static int nfs_show_options(struct seq_file
*m
, struct vfsmount
*mnt
)
339 struct nfs_server
*nfss
= NFS_SB(mnt
->mnt_sb
);
341 nfs_show_mount_options(m
, nfss
, 0);
343 seq_puts(m
, ",addr=");
344 seq_escape(m
, nfss
->nfs_client
->cl_hostname
, " \t\n\\");
350 * Present statistical information for this VFS mountpoint
352 static int nfs_show_stats(struct seq_file
*m
, struct vfsmount
*mnt
)
355 struct nfs_server
*nfss
= NFS_SB(mnt
->mnt_sb
);
356 struct rpc_auth
*auth
= nfss
->client
->cl_auth
;
357 struct nfs_iostats totals
= { };
359 seq_printf(m
, "statvers=%s", NFS_IOSTAT_VERS
);
362 * Display all mount option settings
364 seq_printf(m
, "\n\topts:\t");
365 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_RDONLY
? "ro" : "rw");
366 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_SYNCHRONOUS
? ",sync" : "");
367 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_NOATIME
? ",noatime" : "");
368 seq_puts(m
, mnt
->mnt_sb
->s_flags
& MS_NODIRATIME
? ",nodiratime" : "");
369 nfs_show_mount_options(m
, nfss
, 1);
371 seq_printf(m
, "\n\tage:\t%lu", (jiffies
- nfss
->mount_time
) / HZ
);
373 seq_printf(m
, "\n\tcaps:\t");
374 seq_printf(m
, "caps=0x%x", nfss
->caps
);
375 seq_printf(m
, ",wtmult=%d", nfss
->wtmult
);
376 seq_printf(m
, ",dtsize=%d", nfss
->dtsize
);
377 seq_printf(m
, ",bsize=%d", nfss
->bsize
);
378 seq_printf(m
, ",namelen=%d", nfss
->namelen
);
381 if (nfss
->nfs_client
->cl_nfsversion
== 4) {
382 seq_printf(m
, "\n\tnfsv4:\t");
383 seq_printf(m
, "bm0=0x%x", nfss
->attr_bitmask
[0]);
384 seq_printf(m
, ",bm1=0x%x", nfss
->attr_bitmask
[1]);
385 seq_printf(m
, ",acl=0x%x", nfss
->acl_bitmask
);
390 * Display security flavor in effect for this mount
392 seq_printf(m
, "\n\tsec:\tflavor=%d", auth
->au_ops
->au_flavor
);
394 seq_printf(m
, ",pseudoflavor=%d", auth
->au_flavor
);
397 * Display superblock I/O counters
399 for_each_possible_cpu(cpu
) {
400 struct nfs_iostats
*stats
;
403 stats
= per_cpu_ptr(nfss
->io_stats
, cpu
);
405 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
406 totals
.events
[i
] += stats
->events
[i
];
407 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
408 totals
.bytes
[i
] += stats
->bytes
[i
];
413 seq_printf(m
, "\n\tevents:\t");
414 for (i
= 0; i
< __NFSIOS_COUNTSMAX
; i
++)
415 seq_printf(m
, "%lu ", totals
.events
[i
]);
416 seq_printf(m
, "\n\tbytes:\t");
417 for (i
= 0; i
< __NFSIOS_BYTESMAX
; i
++)
418 seq_printf(m
, "%Lu ", totals
.bytes
[i
]);
421 rpc_print_iostats(m
, nfss
->client
);
427 * Begin unmount by attempting to remove all automounted mountpoints we added
428 * in response to xdev traversals and referrals
430 static void nfs_umount_begin(struct vfsmount
*vfsmnt
, int flags
)
432 shrink_submounts(vfsmnt
, &nfs_automount_list
);
436 * Validate the NFS2/NFS3 mount data
437 * - fills in the mount root filehandle
439 static int nfs_validate_mount_data(struct nfs_mount_data
*data
,
440 struct nfs_fh
*mntfh
)
443 dprintk("%s: missing data argument\n", __FUNCTION__
);
447 if (data
->version
<= 0 || data
->version
> NFS_MOUNT_VERSION
) {
448 dprintk("%s: bad mount version\n", __FUNCTION__
);
452 switch (data
->version
) {
458 if (data
->flags
& NFS_MOUNT_VER3
) {
459 dprintk("%s: mount structure version %d does not support NFSv3\n",
464 data
->root
.size
= NFS2_FHSIZE
;
465 memcpy(data
->root
.data
, data
->old_root
.data
, NFS2_FHSIZE
);
467 if (data
->flags
& NFS_MOUNT_SECFLAVOUR
) {
468 dprintk("%s: mount structure version %d does not support strong security\n",
474 memset(data
->context
, 0, sizeof(data
->context
));
477 /* Set the pseudoflavor */
478 if (!(data
->flags
& NFS_MOUNT_SECFLAVOUR
))
479 data
->pseudoflavor
= RPC_AUTH_UNIX
;
481 #ifndef CONFIG_NFS_V3
482 /* If NFSv3 is not compiled in, return -EPROTONOSUPPORT */
483 if (data
->flags
& NFS_MOUNT_VER3
) {
484 dprintk("%s: NFSv3 not compiled into kernel\n", __FUNCTION__
);
485 return -EPROTONOSUPPORT
;
487 #endif /* CONFIG_NFS_V3 */
489 /* We now require that the mount process passes the remote address */
490 if (data
->addr
.sin_addr
.s_addr
== INADDR_ANY
) {
491 dprintk("%s: mount program didn't pass remote address!\n",
496 /* Prepare the root filehandle */
497 if (data
->flags
& NFS_MOUNT_VER3
)
498 mntfh
->size
= data
->root
.size
;
500 mntfh
->size
= NFS2_FHSIZE
;
502 if (mntfh
->size
> sizeof(mntfh
->data
)) {
503 dprintk("%s: invalid root filehandle\n", __FUNCTION__
);
507 memcpy(mntfh
->data
, data
->root
.data
, mntfh
->size
);
508 if (mntfh
->size
< sizeof(mntfh
->data
))
509 memset(mntfh
->data
+ mntfh
->size
, 0,
510 sizeof(mntfh
->data
) - mntfh
->size
);
516 * Initialise the common bits of the superblock
518 static inline void nfs_initialise_sb(struct super_block
*sb
)
520 struct nfs_server
*server
= NFS_SB(sb
);
522 sb
->s_magic
= NFS_SUPER_MAGIC
;
524 /* We probably want something more informative here */
525 snprintf(sb
->s_id
, sizeof(sb
->s_id
),
526 "%x:%x", MAJOR(sb
->s_dev
), MINOR(sb
->s_dev
));
528 if (sb
->s_blocksize
== 0)
529 sb
->s_blocksize
= nfs_block_bits(server
->wsize
,
530 &sb
->s_blocksize_bits
);
532 if (server
->flags
& NFS_MOUNT_NOAC
)
533 sb
->s_flags
|= MS_SYNCHRONOUS
;
535 nfs_super_set_maxbytes(sb
, server
->maxfilesize
);
539 * Finish setting up an NFS2/3 superblock
541 static void nfs_fill_super(struct super_block
*sb
, struct nfs_mount_data
*data
)
543 struct nfs_server
*server
= NFS_SB(sb
);
545 sb
->s_blocksize_bits
= 0;
548 sb
->s_blocksize
= nfs_block_size(data
->bsize
, &sb
->s_blocksize_bits
);
550 if (server
->flags
& NFS_MOUNT_VER3
) {
551 /* The VFS shouldn't apply the umask to mode bits. We will do
552 * so ourselves when necessary.
554 sb
->s_flags
|= MS_POSIXACL
;
558 sb
->s_op
= &nfs_sops
;
559 nfs_initialise_sb(sb
);
563 * Finish setting up a cloned NFS2/3 superblock
565 static void nfs_clone_super(struct super_block
*sb
,
566 const struct super_block
*old_sb
)
568 struct nfs_server
*server
= NFS_SB(sb
);
570 sb
->s_blocksize_bits
= old_sb
->s_blocksize_bits
;
571 sb
->s_blocksize
= old_sb
->s_blocksize
;
572 sb
->s_maxbytes
= old_sb
->s_maxbytes
;
574 if (server
->flags
& NFS_MOUNT_VER3
) {
575 /* The VFS shouldn't apply the umask to mode bits. We will do
576 * so ourselves when necessary.
578 sb
->s_flags
|= MS_POSIXACL
;
582 sb
->s_op
= old_sb
->s_op
;
583 nfs_initialise_sb(sb
);
586 static int nfs_set_super(struct super_block
*s
, void *_server
)
588 struct nfs_server
*server
= _server
;
591 s
->s_fs_info
= server
;
592 ret
= set_anon_super(s
, server
);
594 server
->s_dev
= s
->s_dev
;
598 static int nfs_compare_super(struct super_block
*sb
, void *data
)
600 struct nfs_server
*server
= data
, *old
= NFS_SB(sb
);
602 if (old
->nfs_client
!= server
->nfs_client
)
604 if (memcmp(&old
->fsid
, &server
->fsid
, sizeof(old
->fsid
)) != 0)
609 static int nfs_get_sb(struct file_system_type
*fs_type
,
610 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
612 struct nfs_server
*server
= NULL
;
613 struct super_block
*s
;
615 struct nfs_mount_data
*data
= raw_data
;
616 struct dentry
*mntroot
;
619 /* Validate the mount data */
620 error
= nfs_validate_mount_data(data
, &mntfh
);
624 /* Get a volume representation */
625 server
= nfs_create_server(data
, &mntfh
);
626 if (IS_ERR(server
)) {
627 error
= PTR_ERR(server
);
628 goto out_err_noserver
;
631 /* Get a superblock - note that we may end up sharing one that already exists */
632 s
= sget(fs_type
, nfs_compare_super
, nfs_set_super
, server
);
638 if (s
->s_fs_info
!= server
) {
639 nfs_free_server(server
);
644 /* initial superblock/root creation */
646 nfs_fill_super(s
, data
);
649 mntroot
= nfs_get_root(s
, &mntfh
);
650 if (IS_ERR(mntroot
)) {
651 error
= PTR_ERR(mntroot
);
652 goto error_splat_super
;
655 s
->s_flags
|= MS_ACTIVE
;
657 mnt
->mnt_root
= mntroot
;
661 nfs_free_server(server
);
666 up_write(&s
->s_umount
);
672 * Destroy an NFS2/3 superblock
674 static void nfs_kill_super(struct super_block
*s
)
676 struct nfs_server
*server
= NFS_SB(s
);
679 nfs_free_server(server
);
683 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
685 static int nfs_xdev_get_sb(struct file_system_type
*fs_type
, int flags
,
686 const char *dev_name
, void *raw_data
,
687 struct vfsmount
*mnt
)
689 struct nfs_clone_mount
*data
= raw_data
;
690 struct super_block
*s
;
691 struct nfs_server
*server
;
692 struct dentry
*mntroot
;
695 dprintk("--> nfs_xdev_get_sb()\n");
697 /* create a new volume representation */
698 server
= nfs_clone_server(NFS_SB(data
->sb
), data
->fh
, data
->fattr
);
699 if (IS_ERR(server
)) {
700 error
= PTR_ERR(server
);
701 goto out_err_noserver
;
704 /* Get a superblock - note that we may end up sharing one that already exists */
705 s
= sget(&nfs_fs_type
, nfs_compare_super
, nfs_set_super
, server
);
711 if (s
->s_fs_info
!= server
) {
712 nfs_free_server(server
);
717 /* initial superblock/root creation */
719 nfs_clone_super(s
, data
->sb
);
722 mntroot
= nfs_get_root(s
, data
->fh
);
723 if (IS_ERR(mntroot
)) {
724 error
= PTR_ERR(mntroot
);
725 goto error_splat_super
;
728 s
->s_flags
|= MS_ACTIVE
;
730 mnt
->mnt_root
= mntroot
;
732 dprintk("<-- nfs_xdev_get_sb() = 0\n");
736 nfs_free_server(server
);
738 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error
);
742 up_write(&s
->s_umount
);
744 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error
);
751 * Finish setting up a cloned NFS4 superblock
753 static void nfs4_clone_super(struct super_block
*sb
,
754 const struct super_block
*old_sb
)
756 sb
->s_blocksize_bits
= old_sb
->s_blocksize_bits
;
757 sb
->s_blocksize
= old_sb
->s_blocksize
;
758 sb
->s_maxbytes
= old_sb
->s_maxbytes
;
760 sb
->s_op
= old_sb
->s_op
;
761 nfs_initialise_sb(sb
);
765 * Set up an NFS4 superblock
767 static void nfs4_fill_super(struct super_block
*sb
)
770 sb
->s_op
= &nfs4_sops
;
771 nfs_initialise_sb(sb
);
774 static void *nfs_copy_user_string(char *dst
, struct nfs_string
*src
, int maxlen
)
779 return ERR_PTR(-EINVAL
);
780 if (src
->len
< maxlen
)
783 p
= dst
= kmalloc(maxlen
+ 1, GFP_KERNEL
);
785 return ERR_PTR(-ENOMEM
);
787 if (copy_from_user(dst
, src
->data
, maxlen
)) {
789 return ERR_PTR(-EFAULT
);
796 * Get the superblock for an NFS4 mountpoint
798 static int nfs4_get_sb(struct file_system_type
*fs_type
,
799 int flags
, const char *dev_name
, void *raw_data
, struct vfsmount
*mnt
)
801 struct nfs4_mount_data
*data
= raw_data
;
802 struct super_block
*s
;
803 struct nfs_server
*server
;
804 struct sockaddr_in addr
;
805 rpc_authflavor_t authflavour
;
807 struct dentry
*mntroot
;
808 char *mntpath
= NULL
, *hostname
= NULL
, ip_addr
[16];
813 dprintk("%s: missing data argument\n", __FUNCTION__
);
816 if (data
->version
<= 0 || data
->version
> NFS4_MOUNT_VERSION
) {
817 dprintk("%s: bad mount version\n", __FUNCTION__
);
821 /* We now require that the mount process passes the remote address */
822 if (data
->host_addrlen
!= sizeof(addr
))
825 if (copy_from_user(&addr
, data
->host_addr
, sizeof(addr
)))
828 if (addr
.sin_family
!= AF_INET
||
829 addr
.sin_addr
.s_addr
== INADDR_ANY
831 dprintk("%s: mount program didn't pass remote IP address!\n",
835 /* RFC3530: The default port for NFS is 2049 */
836 if (addr
.sin_port
== 0)
837 addr
.sin_port
= NFS_PORT
;
839 /* Grab the authentication type */
840 authflavour
= RPC_AUTH_UNIX
;
841 if (data
->auth_flavourlen
!= 0) {
842 if (data
->auth_flavourlen
!= 1) {
843 dprintk("%s: Invalid number of RPC auth flavours %d.\n",
844 __FUNCTION__
, data
->auth_flavourlen
);
846 goto out_err_noserver
;
849 if (copy_from_user(&authflavour
, data
->auth_flavours
,
850 sizeof(authflavour
))) {
852 goto out_err_noserver
;
856 p
= nfs_copy_user_string(NULL
, &data
->hostname
, 256);
861 p
= nfs_copy_user_string(NULL
, &data
->mnt_path
, 1024);
866 dprintk("MNTPATH: %s\n", mntpath
);
868 p
= nfs_copy_user_string(ip_addr
, &data
->client_addr
,
869 sizeof(ip_addr
) - 1);
873 /* Get a volume representation */
874 server
= nfs4_create_server(data
, hostname
, &addr
, mntpath
, ip_addr
,
875 authflavour
, &mntfh
);
876 if (IS_ERR(server
)) {
877 error
= PTR_ERR(server
);
878 goto out_err_noserver
;
881 /* Get a superblock - note that we may end up sharing one that already exists */
882 s
= sget(fs_type
, nfs_compare_super
, nfs_set_super
, server
);
888 if (s
->s_fs_info
!= server
) {
889 nfs_free_server(server
);
894 /* initial superblock/root creation */
899 mntroot
= nfs4_get_root(s
, &mntfh
);
900 if (IS_ERR(mntroot
)) {
901 error
= PTR_ERR(mntroot
);
902 goto error_splat_super
;
905 s
->s_flags
|= MS_ACTIVE
;
907 mnt
->mnt_root
= mntroot
;
914 goto out_err_noserver
;
917 nfs_free_server(server
);
924 up_write(&s
->s_umount
);
926 goto out_err_noserver
;
929 static void nfs4_kill_super(struct super_block
*sb
)
931 struct nfs_server
*server
= NFS_SB(sb
);
933 nfs_return_all_delegations(sb
);
936 nfs4_renewd_prepare_shutdown(server
);
937 nfs_free_server(server
);
941 * Clone an NFS4 server record on xdev traversal (FSID-change)
943 static int nfs4_xdev_get_sb(struct file_system_type
*fs_type
, int flags
,
944 const char *dev_name
, void *raw_data
,
945 struct vfsmount
*mnt
)
947 struct nfs_clone_mount
*data
= raw_data
;
948 struct super_block
*s
;
949 struct nfs_server
*server
;
950 struct dentry
*mntroot
;
953 dprintk("--> nfs4_xdev_get_sb()\n");
955 /* create a new volume representation */
956 server
= nfs_clone_server(NFS_SB(data
->sb
), data
->fh
, data
->fattr
);
957 if (IS_ERR(server
)) {
958 error
= PTR_ERR(server
);
959 goto out_err_noserver
;
962 /* Get a superblock - note that we may end up sharing one that already exists */
963 s
= sget(&nfs_fs_type
, nfs_compare_super
, nfs_set_super
, server
);
969 if (s
->s_fs_info
!= server
) {
970 nfs_free_server(server
);
975 /* initial superblock/root creation */
977 nfs4_clone_super(s
, data
->sb
);
980 mntroot
= nfs4_get_root(s
, data
->fh
);
981 if (IS_ERR(mntroot
)) {
982 error
= PTR_ERR(mntroot
);
983 goto error_splat_super
;
986 s
->s_flags
|= MS_ACTIVE
;
988 mnt
->mnt_root
= mntroot
;
990 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
994 nfs_free_server(server
);
996 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error
);
1000 up_write(&s
->s_umount
);
1001 deactivate_super(s
);
1002 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error
);
1007 * Create an NFS4 server record on referral traversal
1009 static int nfs4_referral_get_sb(struct file_system_type
*fs_type
, int flags
,
1010 const char *dev_name
, void *raw_data
,
1011 struct vfsmount
*mnt
)
1013 struct nfs_clone_mount
*data
= raw_data
;
1014 struct super_block
*s
;
1015 struct nfs_server
*server
;
1016 struct dentry
*mntroot
;
1017 struct nfs_fh mntfh
;
1020 dprintk("--> nfs4_referral_get_sb()\n");
1022 /* create a new volume representation */
1023 server
= nfs4_create_referral_server(data
, &mntfh
);
1024 if (IS_ERR(server
)) {
1025 error
= PTR_ERR(server
);
1026 goto out_err_noserver
;
1029 /* Get a superblock - note that we may end up sharing one that already exists */
1030 s
= sget(&nfs_fs_type
, nfs_compare_super
, nfs_set_super
, server
);
1036 if (s
->s_fs_info
!= server
) {
1037 nfs_free_server(server
);
1042 /* initial superblock/root creation */
1047 mntroot
= nfs4_get_root(s
, data
->fh
);
1048 if (IS_ERR(mntroot
)) {
1049 error
= PTR_ERR(mntroot
);
1050 goto error_splat_super
;
1053 s
->s_flags
|= MS_ACTIVE
;
1055 mnt
->mnt_root
= mntroot
;
1057 dprintk("<-- nfs4_referral_get_sb() = 0\n");
1061 nfs_free_server(server
);
1063 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error
);
1067 up_write(&s
->s_umount
);
1068 deactivate_super(s
);
1069 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error
);
1073 #endif /* CONFIG_NFS_V4 */