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/vserver/xid.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_ODD_RENAME|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_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
85 static 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_ODD_RENAME|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_ODD_RENAME|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_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
129 static 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,
142 * Register the NFS filesystems
144 int __init register_nfs_fs(void)
148 ret = register_filesystem(&nfs_fs_type);
153 ret = nfs_register_sysctl();
156 ret = register_filesystem(&nfs4_fs_type);
164 nfs_unregister_sysctl();
166 unregister_filesystem(&nfs_fs_type);
173 * Unregister the NFS filesystems
175 void __exit unregister_nfs_fs(void)
178 unregister_filesystem(&nfs4_fs_type);
179 nfs_unregister_sysctl();
181 unregister_filesystem(&nfs_fs_type);
185 * Deliver file system statistics to userspace
187 static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
189 struct nfs_server *server = NFS_SB(dentry->d_sb);
190 unsigned char blockbits;
191 unsigned long blockres;
192 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
193 struct nfs_fattr fattr;
194 struct nfs_fsstat res = {
201 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
202 buf->f_type = NFS_SUPER_MAGIC;
207 * Current versions of glibc do not correctly handle the
208 * case where f_frsize != f_bsize. Eventually we want to
209 * report the value of wtmult in this field.
211 buf->f_frsize = dentry->d_sb->s_blocksize;
214 * On most *nix systems, f_blocks, f_bfree, and f_bavail
215 * are reported in units of f_frsize. Linux hasn't had
216 * an f_frsize field in its statfs struct until recently,
217 * thus historically Linux's sys_statfs reports these
218 * fields in units of f_bsize.
220 buf->f_bsize = dentry->d_sb->s_blocksize;
221 blockbits = dentry->d_sb->s_blocksize_bits;
222 blockres = (1 << blockbits) - 1;
223 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
224 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
225 buf->f_bavail = (res.abytes + blockres) >> blockbits;
227 buf->f_files = res.tfiles;
228 buf->f_ffree = res.afiles;
230 buf->f_namelen = server->namelen;
236 dprintk("%s: statfs error = %d\n", __FUNCTION__, -error);
237 buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1;
243 * Map the security flavour number to a name
245 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
247 static const struct {
248 rpc_authflavor_t flavour;
251 { RPC_AUTH_NULL, "null" },
252 { RPC_AUTH_UNIX, "sys" },
253 { RPC_AUTH_GSS_KRB5, "krb5" },
254 { RPC_AUTH_GSS_KRB5I, "krb5i" },
255 { RPC_AUTH_GSS_KRB5P, "krb5p" },
256 { RPC_AUTH_GSS_LKEY, "lkey" },
257 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
258 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
259 { RPC_AUTH_GSS_SPKM, "spkm" },
260 { RPC_AUTH_GSS_SPKMI, "spkmi" },
261 { RPC_AUTH_GSS_SPKMP, "spkmp" },
266 for (i=0; sec_flavours[i].flavour != -1; i++) {
267 if (sec_flavours[i].flavour == flavour)
270 return sec_flavours[i].str;
274 * Describe the mount options in force on this server representation
276 static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss, int showdefaults)
278 static const struct proc_nfs_info {
283 { NFS_MOUNT_SOFT, ",soft", ",hard" },
284 { NFS_MOUNT_INTR, ",intr", "" },
285 { NFS_MOUNT_NOCTO, ",nocto", "" },
286 { NFS_MOUNT_NOAC, ",noac", "" },
287 { NFS_MOUNT_NONLM, ",nolock", "" },
288 { NFS_MOUNT_NOACL, ",noacl", "" },
289 { NFS_MOUNT_FSCACHE, ",fsc", "" },
290 { NFS_MOUNT_TAGXID, ",tagxid", "" },
293 const struct proc_nfs_info *nfs_infop;
294 struct nfs_client *clp = nfss->nfs_client;
298 seq_printf(m, ",vers=%d", clp->rpc_ops->version);
299 seq_printf(m, ",rsize=%d", nfss->rsize);
300 seq_printf(m, ",wsize=%d", nfss->wsize);
301 if (nfss->acregmin != 3*HZ || showdefaults)
302 seq_printf(m, ",acregmin=%d", nfss->acregmin/HZ);
303 if (nfss->acregmax != 60*HZ || showdefaults)
304 seq_printf(m, ",acregmax=%d", nfss->acregmax/HZ);
305 if (nfss->acdirmin != 30*HZ || showdefaults)
306 seq_printf(m, ",acdirmin=%d", nfss->acdirmin/HZ);
307 if (nfss->acdirmax != 60*HZ || showdefaults)
308 seq_printf(m, ",acdirmax=%d", nfss->acdirmax/HZ);
309 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
310 if (nfss->flags & nfs_infop->flag)
311 seq_puts(m, nfs_infop->str);
313 seq_puts(m, nfs_infop->nostr);
315 switch (nfss->client->cl_xprt->prot) {
323 snprintf(buf, sizeof(buf), "%u", nfss->client->cl_xprt->prot);
326 seq_printf(m, ",proto=%s", proto);
327 seq_printf(m, ",timeo=%lu", 10U * clp->retrans_timeo / HZ);
328 seq_printf(m, ",retrans=%u", clp->retrans_count);
329 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
333 * Describe the mount options on this VFS mountpoint
335 static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
337 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
339 nfs_show_mount_options(m, nfss, 0);
341 seq_puts(m, ",addr=");
342 seq_escape(m, nfss->nfs_client->cl_hostname, " \t\n\\");
348 * Present statistical information for this VFS mountpoint
350 static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
353 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
354 struct rpc_auth *auth = nfss->client->cl_auth;
355 struct nfs_iostats totals = { };
357 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
360 * Display all mount option settings
362 seq_printf(m, "\n\topts:\t");
363 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
364 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
365 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
366 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
367 nfs_show_mount_options(m, nfss, 1);
369 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
371 seq_printf(m, "\n\tcaps:\t");
372 seq_printf(m, "caps=0x%x", nfss->caps);
373 seq_printf(m, ",wtmult=%d", nfss->wtmult);
374 seq_printf(m, ",dtsize=%d", nfss->dtsize);
375 seq_printf(m, ",bsize=%d", nfss->bsize);
376 seq_printf(m, ",namelen=%d", nfss->namelen);
379 if (nfss->nfs_client->cl_nfsversion == 4) {
380 seq_printf(m, "\n\tnfsv4:\t");
381 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
382 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
383 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
388 * Display security flavor in effect for this mount
390 seq_printf(m, "\n\tsec:\tflavor=%d", auth->au_ops->au_flavor);
392 seq_printf(m, ",pseudoflavor=%d", auth->au_flavor);
395 * Display superblock I/O counters
397 for_each_possible_cpu(cpu) {
398 struct nfs_iostats *stats;
401 stats = per_cpu_ptr(nfss->io_stats, cpu);
403 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
404 totals.events[i] += stats->events[i];
405 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
406 totals.bytes[i] += stats->bytes[i];
411 seq_printf(m, "\n\tevents:\t");
412 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
413 seq_printf(m, "%lu ", totals.events[i]);
414 seq_printf(m, "\n\tbytes:\t");
415 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
416 seq_printf(m, "%Lu ", totals.bytes[i]);
419 rpc_print_iostats(m, nfss->client);
425 * Begin unmount by attempting to remove all automounted mountpoints we added
426 * in response to xdev traversals and referrals
428 static void nfs_umount_begin(struct vfsmount *vfsmnt, int flags)
430 shrink_submounts(vfsmnt, &nfs_automount_list);
434 * Validate the NFS2/NFS3 mount data
435 * - fills in the mount root filehandle
437 static int nfs_validate_mount_data(struct nfs_mount_data *data,
438 struct nfs_fh *mntfh)
441 dprintk("%s: missing data argument\n", __FUNCTION__);
445 if (data->version <= 0 || data->version > NFS_MOUNT_VERSION) {
446 dprintk("%s: bad mount version\n", __FUNCTION__);
450 switch (data->version) {
456 if (data->flags & NFS_MOUNT_VER3) {
457 dprintk("%s: mount structure version %d does not support NFSv3\n",
462 data->root.size = NFS2_FHSIZE;
463 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
465 if (data->flags & NFS_MOUNT_SECFLAVOUR) {
466 dprintk("%s: mount structure version %d does not support strong security\n",
471 /* Fill in pseudoflavor for mount version < 5 */
472 data->pseudoflavor = RPC_AUTH_UNIX;
474 memset(data->context, 0, sizeof(data->context));
477 #ifndef CONFIG_NFS_V3
478 /* If NFSv3 is not compiled in, return -EPROTONOSUPPORT */
479 if (data->flags & NFS_MOUNT_VER3) {
480 dprintk("%s: NFSv3 not compiled into kernel\n", __FUNCTION__);
481 return -EPROTONOSUPPORT;
483 #endif /* CONFIG_NFS_V3 */
485 /* We now require that the mount process passes the remote address */
486 if (data->addr.sin_addr.s_addr == INADDR_ANY) {
487 dprintk("%s: mount program didn't pass remote address!\n",
492 /* Prepare the root filehandle */
493 if (data->flags & NFS_MOUNT_VER3)
494 mntfh->size = data->root.size;
496 mntfh->size = NFS2_FHSIZE;
498 if (mntfh->size > sizeof(mntfh->data)) {
499 dprintk("%s: invalid root filehandle\n", __FUNCTION__);
503 memcpy(mntfh->data, data->root.data, mntfh->size);
504 if (mntfh->size < sizeof(mntfh->data))
505 memset(mntfh->data + mntfh->size, 0,
506 sizeof(mntfh->data) - mntfh->size);
512 * Initialise the common bits of the superblock
514 static inline void nfs_initialise_sb(struct super_block *sb)
516 struct nfs_server *server = NFS_SB(sb);
518 sb->s_magic = NFS_SUPER_MAGIC;
520 /* We probably want something more informative here */
521 snprintf(sb->s_id, sizeof(sb->s_id),
522 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
524 if (sb->s_blocksize == 0)
525 sb->s_blocksize = nfs_block_bits(server->wsize,
526 &sb->s_blocksize_bits);
528 if (server->flags & NFS_MOUNT_NOAC)
529 sb->s_flags |= MS_SYNCHRONOUS;
530 if (server->flags & NFS_MOUNT_TAGXID)
531 sb->s_flags |= MS_TAGXID;
533 nfs_super_set_maxbytes(sb, server->maxfilesize);
537 * Finish setting up an NFS2/3 superblock
539 static void nfs_fill_super(struct super_block *sb, struct nfs_mount_data *data)
541 struct nfs_server *server = NFS_SB(sb);
543 sb->s_blocksize_bits = 0;
546 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
548 if (server->flags & NFS_MOUNT_VER3) {
549 /* The VFS shouldn't apply the umask to mode bits. We will do
550 * so ourselves when necessary.
552 sb->s_flags |= MS_POSIXACL;
556 sb->s_op = &nfs_sops;
557 nfs_initialise_sb(sb);
561 * Finish setting up a cloned NFS2/3 superblock
563 static void nfs_clone_super(struct super_block *sb,
564 const struct super_block *old_sb)
566 struct nfs_server *server = NFS_SB(sb);
568 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
569 sb->s_blocksize = old_sb->s_blocksize;
570 sb->s_maxbytes = old_sb->s_maxbytes;
572 if (server->flags & NFS_MOUNT_VER3) {
573 /* The VFS shouldn't apply the umask to mode bits. We will do
574 * so ourselves when necessary.
576 sb->s_flags |= MS_POSIXACL;
580 sb->s_op = old_sb->s_op;
581 nfs_initialise_sb(sb);
584 static int nfs_set_super(struct super_block *s, void *_server)
586 struct nfs_server *server = _server;
589 s->s_fs_info = server;
590 ret = set_anon_super(s, server);
592 server->s_dev = s->s_dev;
596 static int nfs_compare_super(struct super_block *sb, void *data)
598 struct nfs_server *server = data, *old = NFS_SB(sb);
600 if (old->nfs_client != server->nfs_client)
602 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
607 static int nfs_get_sb(struct file_system_type *fs_type,
608 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
610 struct nfs_server *server = NULL;
611 struct super_block *s;
613 struct nfs_mount_data *data = raw_data;
614 struct dentry *mntroot;
617 /* Validate the mount data */
618 error = nfs_validate_mount_data(data, &mntfh);
622 /* Get a volume representation */
623 server = nfs_create_server(data, &mntfh);
624 if (IS_ERR(server)) {
625 error = PTR_ERR(server);
626 goto out_err_noserver;
629 /* Get a superblock - note that we may end up sharing one that already exists */
630 s = sget(fs_type, nfs_compare_super, nfs_set_super, server);
636 if (s->s_fs_info != server) {
637 nfs_free_server(server);
642 /* initial superblock/root creation */
644 nfs_fill_super(s, data);
647 mntroot = nfs_get_root(s, &mntfh);
648 if (IS_ERR(mntroot)) {
649 error = PTR_ERR(mntroot);
650 goto error_splat_super;
653 s->s_flags |= MS_ACTIVE;
655 mnt->mnt_root = mntroot;
659 nfs_free_server(server);
664 up_write(&s->s_umount);
670 * Destroy an NFS2/3 superblock
672 static void nfs_kill_super(struct super_block *s)
674 struct nfs_server *server = NFS_SB(s);
677 nfs_free_server(server);
681 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
683 static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
684 const char *dev_name, void *raw_data,
685 struct vfsmount *mnt)
687 struct nfs_clone_mount *data = raw_data;
688 struct super_block *s;
689 struct nfs_server *server;
690 struct dentry *mntroot;
693 dprintk("--> nfs_xdev_get_sb()\n");
695 /* create a new volume representation */
696 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
697 if (IS_ERR(server)) {
698 error = PTR_ERR(server);
699 goto out_err_noserver;
702 /* Get a superblock - note that we may end up sharing one that already exists */
703 s = sget(&nfs_fs_type, nfs_compare_super, nfs_set_super, server);
709 if (s->s_fs_info != server) {
710 nfs_free_server(server);
715 /* initial superblock/root creation */
717 nfs_clone_super(s, data->sb);
720 mntroot = nfs_get_root(s, data->fh);
721 if (IS_ERR(mntroot)) {
722 error = PTR_ERR(mntroot);
723 goto error_splat_super;
726 s->s_flags |= MS_ACTIVE;
728 mnt->mnt_root = mntroot;
730 dprintk("<-- nfs_xdev_get_sb() = 0\n");
734 nfs_free_server(server);
736 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
740 up_write(&s->s_umount);
742 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
749 * Finish setting up a cloned NFS4 superblock
751 static void nfs4_clone_super(struct super_block *sb,
752 const struct super_block *old_sb)
754 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
755 sb->s_blocksize = old_sb->s_blocksize;
756 sb->s_maxbytes = old_sb->s_maxbytes;
758 sb->s_op = old_sb->s_op;
759 nfs_initialise_sb(sb);
763 * Set up an NFS4 superblock
765 static void nfs4_fill_super(struct super_block *sb)
768 sb->s_op = &nfs4_sops;
769 nfs_initialise_sb(sb);
772 static void *nfs_copy_user_string(char *dst, struct nfs_string *src, int maxlen)
777 return ERR_PTR(-EINVAL);
778 if (src->len < maxlen)
781 p = dst = kmalloc(maxlen + 1, GFP_KERNEL);
783 return ERR_PTR(-ENOMEM);
785 if (copy_from_user(dst, src->data, maxlen)) {
787 return ERR_PTR(-EFAULT);
794 * Get the superblock for an NFS4 mountpoint
796 static int nfs4_get_sb(struct file_system_type *fs_type,
797 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
799 struct nfs4_mount_data *data = raw_data;
800 struct super_block *s;
801 struct nfs_server *server;
802 struct sockaddr_in addr;
803 rpc_authflavor_t authflavour;
805 struct dentry *mntroot;
806 char *mntpath = NULL, *hostname = NULL, ip_addr[16];
811 dprintk("%s: missing data argument\n", __FUNCTION__);
814 if (data->version <= 0 || data->version > NFS4_MOUNT_VERSION) {
815 dprintk("%s: bad mount version\n", __FUNCTION__);
819 /* We now require that the mount process passes the remote address */
820 if (data->host_addrlen != sizeof(addr))
823 if (copy_from_user(&addr, data->host_addr, sizeof(addr)))
826 if (addr.sin_family != AF_INET ||
827 addr.sin_addr.s_addr == INADDR_ANY
829 dprintk("%s: mount program didn't pass remote IP address!\n",
834 /* Grab the authentication type */
835 authflavour = RPC_AUTH_UNIX;
836 if (data->auth_flavourlen != 0) {
837 if (data->auth_flavourlen != 1) {
838 dprintk("%s: Invalid number of RPC auth flavours %d.\n",
839 __FUNCTION__, data->auth_flavourlen);
841 goto out_err_noserver;
844 if (copy_from_user(&authflavour, data->auth_flavours,
845 sizeof(authflavour))) {
847 goto out_err_noserver;
851 p = nfs_copy_user_string(NULL, &data->hostname, 256);
856 p = nfs_copy_user_string(NULL, &data->mnt_path, 1024);
861 dprintk("MNTPATH: %s\n", mntpath);
863 p = nfs_copy_user_string(ip_addr, &data->client_addr,
864 sizeof(ip_addr) - 1);
868 /* Get a volume representation */
869 server = nfs4_create_server(data, hostname, &addr, mntpath, ip_addr,
870 authflavour, &mntfh);
871 if (IS_ERR(server)) {
872 error = PTR_ERR(server);
873 goto out_err_noserver;
876 /* Get a superblock - note that we may end up sharing one that already exists */
877 s = sget(fs_type, nfs_compare_super, nfs_set_super, server);
883 if (s->s_fs_info != server) {
884 nfs_free_server(server);
889 /* initial superblock/root creation */
894 mntroot = nfs4_get_root(s, &mntfh);
895 if (IS_ERR(mntroot)) {
896 error = PTR_ERR(mntroot);
897 goto error_splat_super;
900 s->s_flags |= MS_ACTIVE;
902 mnt->mnt_root = mntroot;
909 goto out_err_noserver;
912 nfs_free_server(server);
919 up_write(&s->s_umount);
921 goto out_err_noserver;
924 static void nfs4_kill_super(struct super_block *sb)
926 struct nfs_server *server = NFS_SB(sb);
928 nfs_return_all_delegations(sb);
931 nfs4_renewd_prepare_shutdown(server);
932 nfs_free_server(server);
936 * Clone an NFS4 server record on xdev traversal (FSID-change)
938 static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
939 const char *dev_name, void *raw_data,
940 struct vfsmount *mnt)
942 struct nfs_clone_mount *data = raw_data;
943 struct super_block *s;
944 struct nfs_server *server;
945 struct dentry *mntroot;
948 dprintk("--> nfs4_xdev_get_sb()\n");
950 /* create a new volume representation */
951 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
952 if (IS_ERR(server)) {
953 error = PTR_ERR(server);
954 goto out_err_noserver;
957 /* Get a superblock - note that we may end up sharing one that already exists */
958 s = sget(&nfs_fs_type, nfs_compare_super, nfs_set_super, server);
964 if (s->s_fs_info != server) {
965 nfs_free_server(server);
970 /* initial superblock/root creation */
972 nfs4_clone_super(s, data->sb);
975 mntroot = nfs4_get_root(s, data->fh);
976 if (IS_ERR(mntroot)) {
977 error = PTR_ERR(mntroot);
978 goto error_splat_super;
981 s->s_flags |= MS_ACTIVE;
983 mnt->mnt_root = mntroot;
985 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
989 nfs_free_server(server);
991 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
995 up_write(&s->s_umount);
997 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
1002 * Create an NFS4 server record on referral traversal
1004 static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
1005 const char *dev_name, void *raw_data,
1006 struct vfsmount *mnt)
1008 struct nfs_clone_mount *data = raw_data;
1009 struct super_block *s;
1010 struct nfs_server *server;
1011 struct dentry *mntroot;
1012 struct nfs_fh mntfh;
1015 dprintk("--> nfs4_referral_get_sb()\n");
1017 /* create a new volume representation */
1018 server = nfs4_create_referral_server(data, &mntfh);
1019 if (IS_ERR(server)) {
1020 error = PTR_ERR(server);
1021 goto out_err_noserver;
1024 /* Get a superblock - note that we may end up sharing one that already exists */
1025 s = sget(&nfs_fs_type, nfs_compare_super, nfs_set_super, server);
1031 if (s->s_fs_info != server) {
1032 nfs_free_server(server);
1037 /* initial superblock/root creation */
1042 mntroot = nfs4_get_root(s, data->fh);
1043 if (IS_ERR(mntroot)) {
1044 error = PTR_ERR(mntroot);
1045 goto error_splat_super;
1048 s->s_flags |= MS_ACTIVE;
1050 mnt->mnt_root = mntroot;
1052 dprintk("<-- nfs4_referral_get_sb() = 0\n");
1056 nfs_free_server(server);
1058 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
1062 up_write(&s->s_umount);
1063 deactivate_super(s);
1064 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
1068 #endif /* CONFIG_NFS_V4 */