4 * Copyright (C) 1992 Rick Sladkey
6 * nfs superblock handling functions
8 * Modularised by Alan Cox <Alan.Cox@linux.org>, while hacking some
9 * experimental NFS changes. Modularisation taken straight from SYS5 fs.
11 * Change to nfs_read_super() to permit NFS mounts to multi-homed hosts.
12 * J.S.Peatfield@damtp.cam.ac.uk
14 * Split from inode.c by David Howells <dhowells@redhat.com>
16 * - superblocks are indexed on server only - all inodes, dentries, etc. associated with a
17 * particular server are held in the same superblock
18 * - NFS superblocks can have several effective roots to the dentry tree
19 * - directory type roots are spliced into the tree when a path from one root reaches the root
20 * of another (see nfs_lookup())
23 #include <linux/module.h>
24 #include <linux/init.h>
26 #include <linux/time.h>
27 #include <linux/kernel.h>
29 #include <linux/string.h>
30 #include <linux/stat.h>
31 #include <linux/errno.h>
32 #include <linux/unistd.h>
33 #include <linux/sunrpc/clnt.h>
34 #include <linux/sunrpc/stats.h>
35 #include <linux/sunrpc/metrics.h>
36 #include <linux/nfs_fs.h>
37 #include <linux/nfs_mount.h>
38 #include <linux/nfs4_mount.h>
39 #include <linux/lockd/bind.h>
40 #include <linux/smp_lock.h>
41 #include <linux/seq_file.h>
42 #include <linux/mount.h>
43 #include <linux/nfs_idmap.h>
44 #include <linux/vfs.h>
45 #include <linux/inet.h>
46 #include <linux/nfs_xdr.h>
47 #include <linux/magic.h>
49 #include <asm/system.h>
50 #include <asm/uaccess.h>
54 #include "delegation.h"
58 #define NFSDBG_FACILITY NFSDBG_VFS
60 static void nfs_umount_begin(struct vfsmount *, int);
61 static int nfs_statfs(struct dentry *, struct kstatfs *);
62 static int nfs_show_options(struct seq_file *, struct vfsmount *);
63 static int nfs_show_stats(struct seq_file *, struct vfsmount *);
64 static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
65 static int nfs_xdev_get_sb(struct file_system_type *fs_type,
66 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
67 static void nfs_kill_super(struct super_block *);
69 static struct file_system_type nfs_fs_type = {
73 .kill_sb = nfs_kill_super,
74 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
77 struct file_system_type nfs_xdev_fs_type = {
80 .get_sb = nfs_xdev_get_sb,
81 .kill_sb = nfs_kill_super,
82 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
85 static const struct super_operations nfs_sops = {
86 .alloc_inode = nfs_alloc_inode,
87 .destroy_inode = nfs_destroy_inode,
88 .write_inode = nfs_write_inode,
90 .clear_inode = nfs_clear_inode,
91 .umount_begin = nfs_umount_begin,
92 .show_options = nfs_show_options,
93 .show_stats = nfs_show_stats,
97 static int nfs4_get_sb(struct file_system_type *fs_type,
98 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
99 static int nfs4_xdev_get_sb(struct file_system_type *fs_type,
100 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
101 static int nfs4_referral_get_sb(struct file_system_type *fs_type,
102 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
103 static void nfs4_kill_super(struct super_block *sb);
105 static struct file_system_type nfs4_fs_type = {
106 .owner = THIS_MODULE,
108 .get_sb = nfs4_get_sb,
109 .kill_sb = nfs4_kill_super,
110 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
113 struct file_system_type nfs4_xdev_fs_type = {
114 .owner = THIS_MODULE,
116 .get_sb = nfs4_xdev_get_sb,
117 .kill_sb = nfs4_kill_super,
118 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
121 struct file_system_type nfs4_referral_fs_type = {
122 .owner = THIS_MODULE,
124 .get_sb = nfs4_referral_get_sb,
125 .kill_sb = nfs4_kill_super,
126 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
129 static const struct super_operations nfs4_sops = {
130 .alloc_inode = nfs_alloc_inode,
131 .destroy_inode = nfs_destroy_inode,
132 .write_inode = nfs_write_inode,
133 .statfs = nfs_statfs,
134 .clear_inode = nfs4_clear_inode,
135 .umount_begin = nfs_umount_begin,
136 .show_options = nfs_show_options,
137 .show_stats = nfs_show_stats,
141 static struct shrinker *acl_shrinker;
144 * Register the NFS filesystems
146 int __init register_nfs_fs(void)
150 ret = register_filesystem(&nfs_fs_type);
154 ret = nfs_register_sysctl();
158 ret = register_filesystem(&nfs4_fs_type);
162 acl_shrinker = set_shrinker(DEFAULT_SEEKS, nfs_access_cache_shrinker);
167 nfs_unregister_sysctl();
170 unregister_filesystem(&nfs_fs_type);
176 * Unregister the NFS filesystems
178 void __exit unregister_nfs_fs(void)
180 if (acl_shrinker != NULL)
181 remove_shrinker(acl_shrinker);
183 unregister_filesystem(&nfs4_fs_type);
184 nfs_unregister_sysctl();
186 unregister_filesystem(&nfs_fs_type);
190 * Deliver file system statistics to userspace
192 static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
194 struct nfs_server *server = NFS_SB(dentry->d_sb);
195 unsigned char blockbits;
196 unsigned long blockres;
197 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
198 struct nfs_fattr fattr;
199 struct nfs_fsstat res = {
206 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
209 buf->f_type = NFS_SUPER_MAGIC;
212 * Current versions of glibc do not correctly handle the
213 * case where f_frsize != f_bsize. Eventually we want to
214 * report the value of wtmult in this field.
216 buf->f_frsize = dentry->d_sb->s_blocksize;
219 * On most *nix systems, f_blocks, f_bfree, and f_bavail
220 * are reported in units of f_frsize. Linux hasn't had
221 * an f_frsize field in its statfs struct until recently,
222 * thus historically Linux's sys_statfs reports these
223 * fields in units of f_bsize.
225 buf->f_bsize = dentry->d_sb->s_blocksize;
226 blockbits = dentry->d_sb->s_blocksize_bits;
227 blockres = (1 << blockbits) - 1;
228 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
229 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
230 buf->f_bavail = (res.abytes + blockres) >> blockbits;
232 buf->f_files = res.tfiles;
233 buf->f_ffree = res.afiles;
235 buf->f_namelen = server->namelen;
241 dprintk("%s: statfs error = %d\n", __FUNCTION__, -error);
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", "" },
293 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
296 const struct proc_nfs_info *nfs_infop;
297 struct nfs_client *clp = nfss->nfs_client;
301 seq_printf(m, ",vers=%d", clp->rpc_ops->version);
302 seq_printf(m, ",rsize=%d", nfss->rsize);
303 seq_printf(m, ",wsize=%d", nfss->wsize);
304 if (nfss->acregmin != 3*HZ || showdefaults)
305 seq_printf(m, ",acregmin=%d", nfss->acregmin/HZ);
306 if (nfss->acregmax != 60*HZ || showdefaults)
307 seq_printf(m, ",acregmax=%d", nfss->acregmax/HZ);
308 if (nfss->acdirmin != 30*HZ || showdefaults)
309 seq_printf(m, ",acdirmin=%d", nfss->acdirmin/HZ);
310 if (nfss->acdirmax != 60*HZ || showdefaults)
311 seq_printf(m, ",acdirmax=%d", nfss->acdirmax/HZ);
312 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
313 if (nfss->flags & nfs_infop->flag)
314 seq_puts(m, nfs_infop->str);
316 seq_puts(m, nfs_infop->nostr);
318 switch (nfss->client->cl_xprt->prot) {
326 snprintf(buf, sizeof(buf), "%u", nfss->client->cl_xprt->prot);
329 seq_printf(m, ",proto=%s", proto);
330 seq_printf(m, ",timeo=%lu", 10U * clp->retrans_timeo / HZ);
331 seq_printf(m, ",retrans=%u", clp->retrans_count);
332 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
336 * Describe the mount options on this VFS mountpoint
338 static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
340 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
342 nfs_show_mount_options(m, nfss, 0);
344 seq_puts(m, ",addr=");
345 seq_escape(m, nfss->nfs_client->cl_hostname, " \t\n\\");
351 * Present statistical information for this VFS mountpoint
353 static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
356 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
357 struct rpc_auth *auth = nfss->client->cl_auth;
358 struct nfs_iostats totals = { };
360 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
363 * Display all mount option settings
365 seq_printf(m, "\n\topts:\t");
366 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
367 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
368 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
369 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
370 nfs_show_mount_options(m, nfss, 1);
372 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
374 seq_printf(m, "\n\tcaps:\t");
375 seq_printf(m, "caps=0x%x", nfss->caps);
376 seq_printf(m, ",wtmult=%d", nfss->wtmult);
377 seq_printf(m, ",dtsize=%d", nfss->dtsize);
378 seq_printf(m, ",bsize=%d", nfss->bsize);
379 seq_printf(m, ",namelen=%d", nfss->namelen);
382 if (nfss->nfs_client->cl_nfsversion == 4) {
383 seq_printf(m, "\n\tnfsv4:\t");
384 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
385 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
386 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
391 * Display security flavor in effect for this mount
393 seq_printf(m, "\n\tsec:\tflavor=%d", auth->au_ops->au_flavor);
395 seq_printf(m, ",pseudoflavor=%d", auth->au_flavor);
398 * Display superblock I/O counters
400 for_each_possible_cpu(cpu) {
401 struct nfs_iostats *stats;
404 stats = per_cpu_ptr(nfss->io_stats, cpu);
406 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
407 totals.events[i] += stats->events[i];
408 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
409 totals.bytes[i] += stats->bytes[i];
414 seq_printf(m, "\n\tevents:\t");
415 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
416 seq_printf(m, "%lu ", totals.events[i]);
417 seq_printf(m, "\n\tbytes:\t");
418 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
419 seq_printf(m, "%Lu ", totals.bytes[i]);
422 rpc_print_iostats(m, nfss->client);
428 * Begin unmount by attempting to remove all automounted mountpoints we added
429 * in response to xdev traversals and referrals
431 static void nfs_umount_begin(struct vfsmount *vfsmnt, int flags)
433 struct nfs_server *server = NFS_SB(vfsmnt->mnt_sb);
434 struct rpc_clnt *rpc;
436 shrink_submounts(vfsmnt, &nfs_automount_list);
438 if (!(flags & MNT_FORCE))
440 /* -EIO all pending I/O */
441 rpc = server->client_acl;
443 rpc_killall_tasks(rpc);
444 rpc = server->client;
446 rpc_killall_tasks(rpc);
450 * Validate the NFS2/NFS3 mount data
451 * - fills in the mount root filehandle
453 static int nfs_validate_mount_data(struct nfs_mount_data *data,
454 struct nfs_fh *mntfh)
457 dprintk("%s: missing data argument\n", __FUNCTION__);
461 if (data->version <= 0 || data->version > NFS_MOUNT_VERSION) {
462 dprintk("%s: bad mount version\n", __FUNCTION__);
466 switch (data->version) {
472 if (data->flags & NFS_MOUNT_VER3) {
473 dprintk("%s: mount structure version %d does not support NFSv3\n",
478 data->root.size = NFS2_FHSIZE;
479 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
481 if (data->flags & NFS_MOUNT_SECFLAVOUR) {
482 dprintk("%s: mount structure version %d does not support strong security\n",
488 memset(data->context, 0, sizeof(data->context));
491 /* Set the pseudoflavor */
492 if (!(data->flags & NFS_MOUNT_SECFLAVOUR))
493 data->pseudoflavor = RPC_AUTH_UNIX;
495 #ifndef CONFIG_NFS_V3
496 /* If NFSv3 is not compiled in, return -EPROTONOSUPPORT */
497 if (data->flags & NFS_MOUNT_VER3) {
498 dprintk("%s: NFSv3 not compiled into kernel\n", __FUNCTION__);
499 return -EPROTONOSUPPORT;
501 #endif /* CONFIG_NFS_V3 */
503 /* We now require that the mount process passes the remote address */
504 if (data->addr.sin_addr.s_addr == INADDR_ANY) {
505 dprintk("%s: mount program didn't pass remote address!\n",
510 /* Prepare the root filehandle */
511 if (data->flags & NFS_MOUNT_VER3)
512 mntfh->size = data->root.size;
514 mntfh->size = NFS2_FHSIZE;
516 if (mntfh->size > sizeof(mntfh->data)) {
517 dprintk("%s: invalid root filehandle\n", __FUNCTION__);
521 memcpy(mntfh->data, data->root.data, mntfh->size);
522 if (mntfh->size < sizeof(mntfh->data))
523 memset(mntfh->data + mntfh->size, 0,
524 sizeof(mntfh->data) - mntfh->size);
530 * Initialise the common bits of the superblock
532 static inline void nfs_initialise_sb(struct super_block *sb)
534 struct nfs_server *server = NFS_SB(sb);
536 sb->s_magic = NFS_SUPER_MAGIC;
538 /* We probably want something more informative here */
539 snprintf(sb->s_id, sizeof(sb->s_id),
540 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
542 if (sb->s_blocksize == 0)
543 sb->s_blocksize = nfs_block_bits(server->wsize,
544 &sb->s_blocksize_bits);
546 if (server->flags & NFS_MOUNT_NOAC)
547 sb->s_flags |= MS_SYNCHRONOUS;
549 nfs_super_set_maxbytes(sb, server->maxfilesize);
553 * Finish setting up an NFS2/3 superblock
555 static void nfs_fill_super(struct super_block *sb, struct nfs_mount_data *data)
557 struct nfs_server *server = NFS_SB(sb);
559 sb->s_blocksize_bits = 0;
562 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
564 if (server->flags & NFS_MOUNT_VER3) {
565 /* The VFS shouldn't apply the umask to mode bits. We will do
566 * so ourselves when necessary.
568 sb->s_flags |= MS_POSIXACL;
572 sb->s_op = &nfs_sops;
573 nfs_initialise_sb(sb);
577 * Finish setting up a cloned NFS2/3 superblock
579 static void nfs_clone_super(struct super_block *sb,
580 const struct super_block *old_sb)
582 struct nfs_server *server = NFS_SB(sb);
584 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
585 sb->s_blocksize = old_sb->s_blocksize;
586 sb->s_maxbytes = old_sb->s_maxbytes;
588 if (server->flags & NFS_MOUNT_VER3) {
589 /* The VFS shouldn't apply the umask to mode bits. We will do
590 * so ourselves when necessary.
592 sb->s_flags |= MS_POSIXACL;
596 sb->s_op = old_sb->s_op;
597 nfs_initialise_sb(sb);
600 static int nfs_set_super(struct super_block *s, void *_server)
602 struct nfs_server *server = _server;
605 s->s_fs_info = server;
606 ret = set_anon_super(s, server);
608 server->s_dev = s->s_dev;
612 static int nfs_compare_super(struct super_block *sb, void *data)
614 struct nfs_server *server = data, *old = NFS_SB(sb);
616 if (old->nfs_client != server->nfs_client)
618 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
623 static int nfs_get_sb(struct file_system_type *fs_type,
624 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
626 struct nfs_server *server = NULL;
627 struct super_block *s;
629 struct nfs_mount_data *data = raw_data;
630 struct dentry *mntroot;
633 /* Validate the mount data */
634 error = nfs_validate_mount_data(data, &mntfh);
638 /* Get a volume representation */
639 server = nfs_create_server(data, &mntfh);
640 if (IS_ERR(server)) {
641 error = PTR_ERR(server);
642 goto out_err_noserver;
645 /* Get a superblock - note that we may end up sharing one that already exists */
646 s = sget(fs_type, nfs_compare_super, nfs_set_super, server);
652 if (s->s_fs_info != server) {
653 nfs_free_server(server);
658 /* initial superblock/root creation */
660 nfs_fill_super(s, data);
663 mntroot = nfs_get_root(s, &mntfh);
664 if (IS_ERR(mntroot)) {
665 error = PTR_ERR(mntroot);
666 goto error_splat_super;
669 s->s_flags |= MS_ACTIVE;
671 mnt->mnt_root = mntroot;
675 nfs_free_server(server);
680 up_write(&s->s_umount);
686 * Destroy an NFS2/3 superblock
688 static void nfs_kill_super(struct super_block *s)
690 struct nfs_server *server = NFS_SB(s);
693 nfs_free_server(server);
697 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
699 static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
700 const char *dev_name, void *raw_data,
701 struct vfsmount *mnt)
703 struct nfs_clone_mount *data = raw_data;
704 struct super_block *s;
705 struct nfs_server *server;
706 struct dentry *mntroot;
709 dprintk("--> nfs_xdev_get_sb()\n");
711 /* create a new volume representation */
712 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
713 if (IS_ERR(server)) {
714 error = PTR_ERR(server);
715 goto out_err_noserver;
718 /* Get a superblock - note that we may end up sharing one that already exists */
719 s = sget(&nfs_fs_type, nfs_compare_super, nfs_set_super, server);
725 if (s->s_fs_info != server) {
726 nfs_free_server(server);
731 /* initial superblock/root creation */
733 nfs_clone_super(s, data->sb);
736 mntroot = nfs_get_root(s, data->fh);
737 if (IS_ERR(mntroot)) {
738 error = PTR_ERR(mntroot);
739 goto error_splat_super;
742 s->s_flags |= MS_ACTIVE;
744 mnt->mnt_root = mntroot;
746 dprintk("<-- nfs_xdev_get_sb() = 0\n");
750 nfs_free_server(server);
752 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
756 up_write(&s->s_umount);
758 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
765 * Finish setting up a cloned NFS4 superblock
767 static void nfs4_clone_super(struct super_block *sb,
768 const struct super_block *old_sb)
770 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
771 sb->s_blocksize = old_sb->s_blocksize;
772 sb->s_maxbytes = old_sb->s_maxbytes;
774 sb->s_op = old_sb->s_op;
775 nfs_initialise_sb(sb);
779 * Set up an NFS4 superblock
781 static void nfs4_fill_super(struct super_block *sb)
784 sb->s_op = &nfs4_sops;
785 nfs_initialise_sb(sb);
788 static void *nfs_copy_user_string(char *dst, struct nfs_string *src, int maxlen)
793 return ERR_PTR(-EINVAL);
794 if (src->len < maxlen)
797 p = dst = kmalloc(maxlen + 1, GFP_KERNEL);
799 return ERR_PTR(-ENOMEM);
801 if (copy_from_user(dst, src->data, maxlen)) {
803 return ERR_PTR(-EFAULT);
810 * Get the superblock for an NFS4 mountpoint
812 static int nfs4_get_sb(struct file_system_type *fs_type,
813 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
815 struct nfs4_mount_data *data = raw_data;
816 struct super_block *s;
817 struct nfs_server *server;
818 struct sockaddr_in addr;
819 rpc_authflavor_t authflavour;
821 struct dentry *mntroot;
822 char *mntpath = NULL, *hostname = NULL, ip_addr[16];
827 dprintk("%s: missing data argument\n", __FUNCTION__);
830 if (data->version <= 0 || data->version > NFS4_MOUNT_VERSION) {
831 dprintk("%s: bad mount version\n", __FUNCTION__);
835 /* We now require that the mount process passes the remote address */
836 if (data->host_addrlen != sizeof(addr))
839 if (copy_from_user(&addr, data->host_addr, sizeof(addr)))
842 if (addr.sin_family != AF_INET ||
843 addr.sin_addr.s_addr == INADDR_ANY
845 dprintk("%s: mount program didn't pass remote IP address!\n",
849 /* RFC3530: The default port for NFS is 2049 */
850 if (addr.sin_port == 0)
851 addr.sin_port = htons(NFS_PORT);
853 /* Grab the authentication type */
854 authflavour = RPC_AUTH_UNIX;
855 if (data->auth_flavourlen != 0) {
856 if (data->auth_flavourlen != 1) {
857 dprintk("%s: Invalid number of RPC auth flavours %d.\n",
858 __FUNCTION__, data->auth_flavourlen);
860 goto out_err_noserver;
863 if (copy_from_user(&authflavour, data->auth_flavours,
864 sizeof(authflavour))) {
866 goto out_err_noserver;
870 p = nfs_copy_user_string(NULL, &data->hostname, 256);
875 p = nfs_copy_user_string(NULL, &data->mnt_path, 1024);
880 dprintk("MNTPATH: %s\n", mntpath);
882 p = nfs_copy_user_string(ip_addr, &data->client_addr,
883 sizeof(ip_addr) - 1);
887 /* Get a volume representation */
888 server = nfs4_create_server(data, hostname, &addr, mntpath, ip_addr,
889 authflavour, &mntfh);
890 if (IS_ERR(server)) {
891 error = PTR_ERR(server);
892 goto out_err_noserver;
895 /* Get a superblock - note that we may end up sharing one that already exists */
896 s = sget(fs_type, nfs_compare_super, nfs_set_super, server);
902 if (s->s_fs_info != server) {
903 nfs_free_server(server);
908 /* initial superblock/root creation */
913 mntroot = nfs4_get_root(s, &mntfh);
914 if (IS_ERR(mntroot)) {
915 error = PTR_ERR(mntroot);
916 goto error_splat_super;
919 s->s_flags |= MS_ACTIVE;
921 mnt->mnt_root = mntroot;
928 goto out_err_noserver;
931 nfs_free_server(server);
938 up_write(&s->s_umount);
940 goto out_err_noserver;
943 static void nfs4_kill_super(struct super_block *sb)
945 struct nfs_server *server = NFS_SB(sb);
947 nfs_return_all_delegations(sb);
950 nfs4_renewd_prepare_shutdown(server);
951 nfs_free_server(server);
955 * Clone an NFS4 server record on xdev traversal (FSID-change)
957 static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
958 const char *dev_name, void *raw_data,
959 struct vfsmount *mnt)
961 struct nfs_clone_mount *data = raw_data;
962 struct super_block *s;
963 struct nfs_server *server;
964 struct dentry *mntroot;
967 dprintk("--> nfs4_xdev_get_sb()\n");
969 /* create a new volume representation */
970 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
971 if (IS_ERR(server)) {
972 error = PTR_ERR(server);
973 goto out_err_noserver;
976 /* Get a superblock - note that we may end up sharing one that already exists */
977 s = sget(&nfs_fs_type, nfs_compare_super, nfs_set_super, server);
983 if (s->s_fs_info != server) {
984 nfs_free_server(server);
989 /* initial superblock/root creation */
991 nfs4_clone_super(s, data->sb);
994 mntroot = nfs4_get_root(s, data->fh);
995 if (IS_ERR(mntroot)) {
996 error = PTR_ERR(mntroot);
997 goto error_splat_super;
1000 s->s_flags |= MS_ACTIVE;
1002 mnt->mnt_root = mntroot;
1004 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
1008 nfs_free_server(server);
1010 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
1014 up_write(&s->s_umount);
1015 deactivate_super(s);
1016 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
1021 * Create an NFS4 server record on referral traversal
1023 static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
1024 const char *dev_name, void *raw_data,
1025 struct vfsmount *mnt)
1027 struct nfs_clone_mount *data = raw_data;
1028 struct super_block *s;
1029 struct nfs_server *server;
1030 struct dentry *mntroot;
1031 struct nfs_fh mntfh;
1034 dprintk("--> nfs4_referral_get_sb()\n");
1036 /* create a new volume representation */
1037 server = nfs4_create_referral_server(data, &mntfh);
1038 if (IS_ERR(server)) {
1039 error = PTR_ERR(server);
1040 goto out_err_noserver;
1043 /* Get a superblock - note that we may end up sharing one that already exists */
1044 s = sget(&nfs_fs_type, nfs_compare_super, nfs_set_super, server);
1050 if (s->s_fs_info != server) {
1051 nfs_free_server(server);
1056 /* initial superblock/root creation */
1061 mntroot = nfs4_get_root(s, &mntfh);
1062 if (IS_ERR(mntroot)) {
1063 error = PTR_ERR(mntroot);
1064 goto error_splat_super;
1067 s->s_flags |= MS_ACTIVE;
1069 mnt->mnt_root = mntroot;
1071 dprintk("<-- nfs4_referral_get_sb() = 0\n");
1075 nfs_free_server(server);
1077 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
1081 up_write(&s->s_umount);
1082 deactivate_super(s);
1083 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
1087 #endif /* CONFIG_NFS_V4 */