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/vs_tag.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 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 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);
155 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();
169 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);
207 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);
242 buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1;
248 * Map the security flavour number to a name
250 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
252 static const struct {
253 rpc_authflavor_t flavour;
256 { RPC_AUTH_NULL, "null" },
257 { RPC_AUTH_UNIX, "sys" },
258 { RPC_AUTH_GSS_KRB5, "krb5" },
259 { RPC_AUTH_GSS_KRB5I, "krb5i" },
260 { RPC_AUTH_GSS_KRB5P, "krb5p" },
261 { RPC_AUTH_GSS_LKEY, "lkey" },
262 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
263 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
264 { RPC_AUTH_GSS_SPKM, "spkm" },
265 { RPC_AUTH_GSS_SPKMI, "spkmi" },
266 { RPC_AUTH_GSS_SPKMP, "spkmp" },
271 for (i=0; sec_flavours[i].flavour != -1; i++) {
272 if (sec_flavours[i].flavour == flavour)
275 return sec_flavours[i].str;
279 * Describe the mount options in force on this server representation
281 static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss, int showdefaults)
283 static const struct proc_nfs_info {
288 { NFS_MOUNT_SOFT, ",soft", ",hard" },
289 { NFS_MOUNT_INTR, ",intr", "" },
290 { NFS_MOUNT_NOCTO, ",nocto", "" },
291 { NFS_MOUNT_NOAC, ",noac", "" },
292 { NFS_MOUNT_NONLM, ",nolock", "" },
293 { NFS_MOUNT_NOACL, ",noacl", "" },
294 { NFS_MOUNT_TAGGED, ",tag", "" },
297 const struct proc_nfs_info *nfs_infop;
298 struct nfs_client *clp = nfss->nfs_client;
302 seq_printf(m, ",vers=%d", clp->rpc_ops->version);
303 seq_printf(m, ",rsize=%d", nfss->rsize);
304 seq_printf(m, ",wsize=%d", nfss->wsize);
305 if (nfss->acregmin != 3*HZ || showdefaults)
306 seq_printf(m, ",acregmin=%d", nfss->acregmin/HZ);
307 if (nfss->acregmax != 60*HZ || showdefaults)
308 seq_printf(m, ",acregmax=%d", nfss->acregmax/HZ);
309 if (nfss->acdirmin != 30*HZ || showdefaults)
310 seq_printf(m, ",acdirmin=%d", nfss->acdirmin/HZ);
311 if (nfss->acdirmax != 60*HZ || showdefaults)
312 seq_printf(m, ",acdirmax=%d", nfss->acdirmax/HZ);
313 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
314 if (nfss->flags & nfs_infop->flag)
315 seq_puts(m, nfs_infop->str);
317 seq_puts(m, nfs_infop->nostr);
319 switch (nfss->client->cl_xprt->prot) {
327 snprintf(buf, sizeof(buf), "%u", nfss->client->cl_xprt->prot);
330 seq_printf(m, ",proto=%s", proto);
331 seq_printf(m, ",timeo=%lu", 10U * clp->retrans_timeo / HZ);
332 seq_printf(m, ",retrans=%u", clp->retrans_count);
333 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
337 * Describe the mount options on this VFS mountpoint
339 static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
341 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
343 nfs_show_mount_options(m, nfss, 0);
345 seq_puts(m, ",addr=");
346 seq_escape(m, nfss->nfs_client->cl_hostname, " \t\n\\");
352 * Present statistical information for this VFS mountpoint
354 static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
357 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
358 struct rpc_auth *auth = nfss->client->cl_auth;
359 struct nfs_iostats totals = { };
361 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
364 * Display all mount option settings
366 seq_printf(m, "\n\topts:\t");
367 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
368 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
369 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
370 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
371 nfs_show_mount_options(m, nfss, 1);
373 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
375 seq_printf(m, "\n\tcaps:\t");
376 seq_printf(m, "caps=0x%x", nfss->caps);
377 seq_printf(m, ",wtmult=%d", nfss->wtmult);
378 seq_printf(m, ",dtsize=%d", nfss->dtsize);
379 seq_printf(m, ",bsize=%d", nfss->bsize);
380 seq_printf(m, ",namelen=%d", nfss->namelen);
383 if (nfss->nfs_client->cl_nfsversion == 4) {
384 seq_printf(m, "\n\tnfsv4:\t");
385 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
386 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
387 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
392 * Display security flavor in effect for this mount
394 seq_printf(m, "\n\tsec:\tflavor=%d", auth->au_ops->au_flavor);
396 seq_printf(m, ",pseudoflavor=%d", auth->au_flavor);
399 * Display superblock I/O counters
401 for_each_possible_cpu(cpu) {
402 struct nfs_iostats *stats;
405 stats = per_cpu_ptr(nfss->io_stats, cpu);
407 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
408 totals.events[i] += stats->events[i];
409 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
410 totals.bytes[i] += stats->bytes[i];
415 seq_printf(m, "\n\tevents:\t");
416 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
417 seq_printf(m, "%lu ", totals.events[i]);
418 seq_printf(m, "\n\tbytes:\t");
419 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
420 seq_printf(m, "%Lu ", totals.bytes[i]);
423 rpc_print_iostats(m, nfss->client);
429 * Begin unmount by attempting to remove all automounted mountpoints we added
430 * in response to xdev traversals and referrals
432 static void nfs_umount_begin(struct vfsmount *vfsmnt, int flags)
434 shrink_submounts(vfsmnt, &nfs_automount_list);
438 * Validate the NFS2/NFS3 mount data
439 * - fills in the mount root filehandle
441 static int nfs_validate_mount_data(struct nfs_mount_data *data,
442 struct nfs_fh *mntfh)
445 dprintk("%s: missing data argument\n", __FUNCTION__);
449 if (data->version <= 0 || data->version > NFS_MOUNT_VERSION) {
450 dprintk("%s: bad mount version\n", __FUNCTION__);
454 switch (data->version) {
460 if (data->flags & NFS_MOUNT_VER3) {
461 dprintk("%s: mount structure version %d does not support NFSv3\n",
466 data->root.size = NFS2_FHSIZE;
467 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
469 if (data->flags & NFS_MOUNT_SECFLAVOUR) {
470 dprintk("%s: mount structure version %d does not support strong security\n",
476 memset(data->context, 0, sizeof(data->context));
479 /* Set the pseudoflavor */
480 if (!(data->flags & NFS_MOUNT_SECFLAVOUR))
481 data->pseudoflavor = RPC_AUTH_UNIX;
483 #ifndef CONFIG_NFS_V3
484 /* If NFSv3 is not compiled in, return -EPROTONOSUPPORT */
485 if (data->flags & NFS_MOUNT_VER3) {
486 dprintk("%s: NFSv3 not compiled into kernel\n", __FUNCTION__);
487 return -EPROTONOSUPPORT;
489 #endif /* CONFIG_NFS_V3 */
491 /* We now require that the mount process passes the remote address */
492 if (data->addr.sin_addr.s_addr == INADDR_ANY) {
493 dprintk("%s: mount program didn't pass remote address!\n",
498 /* Prepare the root filehandle */
499 if (data->flags & NFS_MOUNT_VER3)
500 mntfh->size = data->root.size;
502 mntfh->size = NFS2_FHSIZE;
504 if (mntfh->size > sizeof(mntfh->data)) {
505 dprintk("%s: invalid root filehandle\n", __FUNCTION__);
509 memcpy(mntfh->data, data->root.data, mntfh->size);
510 if (mntfh->size < sizeof(mntfh->data))
511 memset(mntfh->data + mntfh->size, 0,
512 sizeof(mntfh->data) - mntfh->size);
518 * Initialise the common bits of the superblock
520 static inline void nfs_initialise_sb(struct super_block *sb)
522 struct nfs_server *server = NFS_SB(sb);
524 sb->s_magic = NFS_SUPER_MAGIC;
526 /* We probably want something more informative here */
527 snprintf(sb->s_id, sizeof(sb->s_id),
528 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
530 if (sb->s_blocksize == 0)
531 sb->s_blocksize = nfs_block_bits(server->wsize,
532 &sb->s_blocksize_bits);
534 if (server->flags & NFS_MOUNT_NOAC)
535 sb->s_flags |= MS_SYNCHRONOUS;
537 nfs_super_set_maxbytes(sb, server->maxfilesize);
541 * Finish setting up an NFS2/3 superblock
543 static void nfs_fill_super(struct super_block *sb, struct nfs_mount_data *data)
545 struct nfs_server *server = NFS_SB(sb);
547 sb->s_blocksize_bits = 0;
550 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
552 if (server->flags & NFS_MOUNT_VER3) {
553 /* The VFS shouldn't apply the umask to mode bits. We will do
554 * so ourselves when necessary.
556 sb->s_flags |= MS_POSIXACL;
560 sb->s_op = &nfs_sops;
561 nfs_initialise_sb(sb);
565 * Finish setting up a cloned NFS2/3 superblock
567 static void nfs_clone_super(struct super_block *sb,
568 const struct super_block *old_sb)
570 struct nfs_server *server = NFS_SB(sb);
572 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
573 sb->s_blocksize = old_sb->s_blocksize;
574 sb->s_maxbytes = old_sb->s_maxbytes;
576 if (server->flags & NFS_MOUNT_VER3) {
577 /* The VFS shouldn't apply the umask to mode bits. We will do
578 * so ourselves when necessary.
580 sb->s_flags |= MS_POSIXACL;
584 sb->s_op = old_sb->s_op;
585 nfs_initialise_sb(sb);
588 static int nfs_set_super(struct super_block *s, void *_server)
590 struct nfs_server *server = _server;
593 s->s_fs_info = server;
594 ret = set_anon_super(s, server);
596 server->s_dev = s->s_dev;
600 static int nfs_compare_super(struct super_block *sb, void *data)
602 struct nfs_server *server = data, *old = NFS_SB(sb);
604 if (old->nfs_client != server->nfs_client)
606 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
611 static int nfs_get_sb(struct file_system_type *fs_type,
612 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
614 struct nfs_server *server = NULL;
615 struct super_block *s;
617 struct nfs_mount_data *data = raw_data;
618 struct dentry *mntroot;
621 /* Validate the mount data */
622 error = nfs_validate_mount_data(data, &mntfh);
626 /* Get a volume representation */
627 server = nfs_create_server(data, &mntfh);
628 if (IS_ERR(server)) {
629 error = PTR_ERR(server);
630 goto out_err_noserver;
633 /* Get a superblock - note that we may end up sharing one that already exists */
634 s = sget(fs_type, nfs_compare_super, nfs_set_super, server);
640 if (s->s_fs_info != server) {
641 nfs_free_server(server);
646 /* initial superblock/root creation */
648 nfs_fill_super(s, data);
651 mntroot = nfs_get_root(s, &mntfh);
652 if (IS_ERR(mntroot)) {
653 error = PTR_ERR(mntroot);
654 goto error_splat_super;
657 s->s_flags |= MS_ACTIVE;
659 mnt->mnt_root = mntroot;
663 nfs_free_server(server);
668 up_write(&s->s_umount);
674 * Destroy an NFS2/3 superblock
676 static void nfs_kill_super(struct super_block *s)
678 struct nfs_server *server = NFS_SB(s);
681 nfs_free_server(server);
685 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
687 static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
688 const char *dev_name, void *raw_data,
689 struct vfsmount *mnt)
691 struct nfs_clone_mount *data = raw_data;
692 struct super_block *s;
693 struct nfs_server *server;
694 struct dentry *mntroot;
697 dprintk("--> nfs_xdev_get_sb()\n");
699 /* create a new volume representation */
700 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
701 if (IS_ERR(server)) {
702 error = PTR_ERR(server);
703 goto out_err_noserver;
706 /* Get a superblock - note that we may end up sharing one that already exists */
707 s = sget(&nfs_fs_type, nfs_compare_super, nfs_set_super, server);
713 if (s->s_fs_info != server) {
714 nfs_free_server(server);
719 /* initial superblock/root creation */
721 nfs_clone_super(s, data->sb);
724 mntroot = nfs_get_root(s, data->fh);
725 if (IS_ERR(mntroot)) {
726 error = PTR_ERR(mntroot);
727 goto error_splat_super;
730 s->s_flags |= MS_ACTIVE;
732 mnt->mnt_root = mntroot;
734 dprintk("<-- nfs_xdev_get_sb() = 0\n");
738 nfs_free_server(server);
740 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
744 up_write(&s->s_umount);
746 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
753 * Finish setting up a cloned NFS4 superblock
755 static void nfs4_clone_super(struct super_block *sb,
756 const struct super_block *old_sb)
758 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
759 sb->s_blocksize = old_sb->s_blocksize;
760 sb->s_maxbytes = old_sb->s_maxbytes;
762 sb->s_op = old_sb->s_op;
763 nfs_initialise_sb(sb);
767 * Set up an NFS4 superblock
769 static void nfs4_fill_super(struct super_block *sb)
772 sb->s_op = &nfs4_sops;
773 nfs_initialise_sb(sb);
776 static void *nfs_copy_user_string(char *dst, struct nfs_string *src, int maxlen)
781 return ERR_PTR(-EINVAL);
782 if (src->len < maxlen)
785 p = dst = kmalloc(maxlen + 1, GFP_KERNEL);
787 return ERR_PTR(-ENOMEM);
789 if (copy_from_user(dst, src->data, maxlen)) {
791 return ERR_PTR(-EFAULT);
798 * Get the superblock for an NFS4 mountpoint
800 static int nfs4_get_sb(struct file_system_type *fs_type,
801 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
803 struct nfs4_mount_data *data = raw_data;
804 struct super_block *s;
805 struct nfs_server *server;
806 struct sockaddr_in addr;
807 rpc_authflavor_t authflavour;
809 struct dentry *mntroot;
810 char *mntpath = NULL, *hostname = NULL, ip_addr[16];
815 dprintk("%s: missing data argument\n", __FUNCTION__);
818 if (data->version <= 0 || data->version > NFS4_MOUNT_VERSION) {
819 dprintk("%s: bad mount version\n", __FUNCTION__);
823 /* We now require that the mount process passes the remote address */
824 if (data->host_addrlen != sizeof(addr))
827 if (copy_from_user(&addr, data->host_addr, sizeof(addr)))
830 if (addr.sin_family != AF_INET ||
831 addr.sin_addr.s_addr == INADDR_ANY
833 dprintk("%s: mount program didn't pass remote IP address!\n",
837 /* RFC3530: The default port for NFS is 2049 */
838 if (addr.sin_port == 0)
839 addr.sin_port = htons(NFS_PORT);
841 /* Grab the authentication type */
842 authflavour = RPC_AUTH_UNIX;
843 if (data->auth_flavourlen != 0) {
844 if (data->auth_flavourlen != 1) {
845 dprintk("%s: Invalid number of RPC auth flavours %d.\n",
846 __FUNCTION__, data->auth_flavourlen);
848 goto out_err_noserver;
851 if (copy_from_user(&authflavour, data->auth_flavours,
852 sizeof(authflavour))) {
854 goto out_err_noserver;
858 p = nfs_copy_user_string(NULL, &data->hostname, 256);
863 p = nfs_copy_user_string(NULL, &data->mnt_path, 1024);
868 dprintk("MNTPATH: %s\n", mntpath);
870 p = nfs_copy_user_string(ip_addr, &data->client_addr,
871 sizeof(ip_addr) - 1);
875 /* Get a volume representation */
876 server = nfs4_create_server(data, hostname, &addr, mntpath, ip_addr,
877 authflavour, &mntfh);
878 if (IS_ERR(server)) {
879 error = PTR_ERR(server);
880 goto out_err_noserver;
883 /* Get a superblock - note that we may end up sharing one that already exists */
884 s = sget(fs_type, nfs_compare_super, nfs_set_super, server);
890 if (s->s_fs_info != server) {
891 nfs_free_server(server);
896 /* initial superblock/root creation */
901 mntroot = nfs4_get_root(s, &mntfh);
902 if (IS_ERR(mntroot)) {
903 error = PTR_ERR(mntroot);
904 goto error_splat_super;
907 s->s_flags |= MS_ACTIVE;
909 mnt->mnt_root = mntroot;
916 goto out_err_noserver;
919 nfs_free_server(server);
926 up_write(&s->s_umount);
928 goto out_err_noserver;
931 static void nfs4_kill_super(struct super_block *sb)
933 struct nfs_server *server = NFS_SB(sb);
935 nfs_return_all_delegations(sb);
938 nfs4_renewd_prepare_shutdown(server);
939 nfs_free_server(server);
943 * Clone an NFS4 server record on xdev traversal (FSID-change)
945 static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
946 const char *dev_name, void *raw_data,
947 struct vfsmount *mnt)
949 struct nfs_clone_mount *data = raw_data;
950 struct super_block *s;
951 struct nfs_server *server;
952 struct dentry *mntroot;
955 dprintk("--> nfs4_xdev_get_sb()\n");
957 /* create a new volume representation */
958 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
959 if (IS_ERR(server)) {
960 error = PTR_ERR(server);
961 goto out_err_noserver;
964 /* Get a superblock - note that we may end up sharing one that already exists */
965 s = sget(&nfs_fs_type, nfs_compare_super, nfs_set_super, server);
971 if (s->s_fs_info != server) {
972 nfs_free_server(server);
977 /* initial superblock/root creation */
979 nfs4_clone_super(s, data->sb);
982 mntroot = nfs4_get_root(s, data->fh);
983 if (IS_ERR(mntroot)) {
984 error = PTR_ERR(mntroot);
985 goto error_splat_super;
988 s->s_flags |= MS_ACTIVE;
990 mnt->mnt_root = mntroot;
992 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
996 nfs_free_server(server);
998 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
1002 up_write(&s->s_umount);
1003 deactivate_super(s);
1004 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
1009 * Create an NFS4 server record on referral traversal
1011 static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
1012 const char *dev_name, void *raw_data,
1013 struct vfsmount *mnt)
1015 struct nfs_clone_mount *data = raw_data;
1016 struct super_block *s;
1017 struct nfs_server *server;
1018 struct dentry *mntroot;
1019 struct nfs_fh mntfh;
1022 dprintk("--> nfs4_referral_get_sb()\n");
1024 /* create a new volume representation */
1025 server = nfs4_create_referral_server(data, &mntfh);
1026 if (IS_ERR(server)) {
1027 error = PTR_ERR(server);
1028 goto out_err_noserver;
1031 /* Get a superblock - note that we may end up sharing one that already exists */
1032 s = sget(&nfs_fs_type, nfs_compare_super, nfs_set_super, server);
1038 if (s->s_fs_info != server) {
1039 nfs_free_server(server);
1044 /* initial superblock/root creation */
1049 mntroot = nfs4_get_root(s, data->fh);
1050 if (IS_ERR(mntroot)) {
1051 error = PTR_ERR(mntroot);
1052 goto error_splat_super;
1055 s->s_flags |= MS_ACTIVE;
1057 mnt->mnt_root = mntroot;
1059 dprintk("<-- nfs4_referral_get_sb() = 0\n");
1063 nfs_free_server(server);
1065 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
1069 up_write(&s->s_umount);
1070 deactivate_super(s);
1071 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
1075 #endif /* CONFIG_NFS_V4 */