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>
48 #include <linux/parser.h>
50 #include <asm/system.h>
51 #include <asm/uaccess.h>
55 #include "delegation.h"
59 #define NFSDBG_FACILITY NFSDBG_VFS
62 struct nfs_parsed_mount_data {
66 int acregmin, acregmax,
70 unsigned int auth_flavor_len;
71 rpc_authflavor_t auth_flavors[1];
75 struct sockaddr_in address;
83 struct sockaddr_in address;
92 /* Mount options that take no arguments */
95 Opt_posix, Opt_noposix,
102 Opt_rdirplus, Opt_nordirplus,
104 /* Mount options that take integer arguments */
106 Opt_rsize, Opt_wsize, Opt_bsize,
107 Opt_timeo, Opt_retrans,
108 Opt_acregmin, Opt_acregmax,
109 Opt_acdirmin, Opt_acdirmax,
113 Opt_mountprog, Opt_mountvers,
114 Opt_nfsprog, Opt_nfsvers,
116 /* Mount options that take string arguments */
117 Opt_sec, Opt_proto, Opt_mountproto,
118 Opt_addr, Opt_mounthost, Opt_clientaddr,
120 /* Mount options that are ignored */
121 Opt_userspace, Opt_deprecated,
126 static match_table_t nfs_mount_option_tokens = {
127 { Opt_userspace, "bg" },
128 { Opt_userspace, "fg" },
129 { Opt_soft, "soft" },
130 { Opt_hard, "hard" },
131 { Opt_intr, "intr" },
132 { Opt_nointr, "nointr" },
133 { Opt_posix, "posix" },
134 { Opt_noposix, "noposix" },
136 { Opt_nocto, "nocto" },
138 { Opt_noac, "noac" },
139 { Opt_lock, "lock" },
140 { Opt_nolock, "nolock" },
146 { Opt_noacl, "noacl" },
147 { Opt_rdirplus, "rdirplus" },
148 { Opt_nordirplus, "nordirplus" },
150 { Opt_port, "port=%u" },
151 { Opt_rsize, "rsize=%u" },
152 { Opt_wsize, "wsize=%u" },
153 { Opt_bsize, "bsize=%u" },
154 { Opt_timeo, "timeo=%u" },
155 { Opt_retrans, "retrans=%u" },
156 { Opt_acregmin, "acregmin=%u" },
157 { Opt_acregmax, "acregmax=%u" },
158 { Opt_acdirmin, "acdirmin=%u" },
159 { Opt_acdirmax, "acdirmax=%u" },
160 { Opt_actimeo, "actimeo=%u" },
161 { Opt_userspace, "retry=%u" },
162 { Opt_namelen, "namlen=%u" },
163 { Opt_mountport, "mountport=%u" },
164 { Opt_mountprog, "mountprog=%u" },
165 { Opt_mountvers, "mountvers=%u" },
166 { Opt_nfsprog, "nfsprog=%u" },
167 { Opt_nfsvers, "nfsvers=%u" },
168 { Opt_nfsvers, "vers=%u" },
170 { Opt_sec, "sec=%s" },
171 { Opt_proto, "proto=%s" },
172 { Opt_mountproto, "mountproto=%s" },
173 { Opt_addr, "addr=%s" },
174 { Opt_clientaddr, "clientaddr=%s" },
175 { Opt_mounthost, "mounthost=%s" },
181 Opt_xprt_udp, Opt_xprt_tcp,
186 static match_table_t nfs_xprt_protocol_tokens = {
187 { Opt_xprt_udp, "udp" },
188 { Opt_xprt_tcp, "tcp" },
190 { Opt_xprt_err, NULL }
194 Opt_sec_none, Opt_sec_sys,
195 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
196 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
197 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
202 static match_table_t nfs_secflavor_tokens = {
203 { Opt_sec_none, "none" },
204 { Opt_sec_none, "null" },
205 { Opt_sec_sys, "sys" },
207 { Opt_sec_krb5, "krb5" },
208 { Opt_sec_krb5i, "krb5i" },
209 { Opt_sec_krb5p, "krb5p" },
211 { Opt_sec_lkey, "lkey" },
212 { Opt_sec_lkeyi, "lkeyi" },
213 { Opt_sec_lkeyp, "lkeyp" },
215 { Opt_sec_err, NULL }
219 static void nfs_umount_begin(struct vfsmount *, int);
220 static int nfs_statfs(struct dentry *, struct kstatfs *);
221 static int nfs_show_options(struct seq_file *, struct vfsmount *);
222 static int nfs_show_stats(struct seq_file *, struct vfsmount *);
223 static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
224 static int nfs_xdev_get_sb(struct file_system_type *fs_type,
225 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
226 static void nfs_kill_super(struct super_block *);
228 static struct file_system_type nfs_fs_type = {
229 .owner = THIS_MODULE,
231 .get_sb = nfs_get_sb,
232 .kill_sb = nfs_kill_super,
233 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
236 struct file_system_type nfs_xdev_fs_type = {
237 .owner = THIS_MODULE,
239 .get_sb = nfs_xdev_get_sb,
240 .kill_sb = nfs_kill_super,
241 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
244 static const struct super_operations nfs_sops = {
245 .alloc_inode = nfs_alloc_inode,
246 .destroy_inode = nfs_destroy_inode,
247 .write_inode = nfs_write_inode,
248 .statfs = nfs_statfs,
249 .clear_inode = nfs_clear_inode,
250 .umount_begin = nfs_umount_begin,
251 .show_options = nfs_show_options,
252 .show_stats = nfs_show_stats,
256 static int nfs4_get_sb(struct file_system_type *fs_type,
257 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
258 static int nfs4_xdev_get_sb(struct file_system_type *fs_type,
259 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
260 static int nfs4_referral_get_sb(struct file_system_type *fs_type,
261 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
262 static void nfs4_kill_super(struct super_block *sb);
264 static struct file_system_type nfs4_fs_type = {
265 .owner = THIS_MODULE,
267 .get_sb = nfs4_get_sb,
268 .kill_sb = nfs4_kill_super,
269 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
272 struct file_system_type nfs4_xdev_fs_type = {
273 .owner = THIS_MODULE,
275 .get_sb = nfs4_xdev_get_sb,
276 .kill_sb = nfs4_kill_super,
277 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
280 struct file_system_type nfs4_referral_fs_type = {
281 .owner = THIS_MODULE,
283 .get_sb = nfs4_referral_get_sb,
284 .kill_sb = nfs4_kill_super,
285 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
288 static const struct super_operations nfs4_sops = {
289 .alloc_inode = nfs_alloc_inode,
290 .destroy_inode = nfs_destroy_inode,
291 .write_inode = nfs_write_inode,
292 .statfs = nfs_statfs,
293 .clear_inode = nfs4_clear_inode,
294 .umount_begin = nfs_umount_begin,
295 .show_options = nfs_show_options,
296 .show_stats = nfs_show_stats,
300 static struct shrinker *acl_shrinker;
303 * Register the NFS filesystems
305 int __init register_nfs_fs(void)
309 ret = register_filesystem(&nfs_fs_type);
313 ret = nfs_register_sysctl();
317 ret = register_filesystem(&nfs4_fs_type);
321 acl_shrinker = set_shrinker(DEFAULT_SEEKS, nfs_access_cache_shrinker);
326 nfs_unregister_sysctl();
329 unregister_filesystem(&nfs_fs_type);
335 * Unregister the NFS filesystems
337 void __exit unregister_nfs_fs(void)
339 if (acl_shrinker != NULL)
340 remove_shrinker(acl_shrinker);
342 unregister_filesystem(&nfs4_fs_type);
343 nfs_unregister_sysctl();
345 unregister_filesystem(&nfs_fs_type);
349 * Deliver file system statistics to userspace
351 static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
353 struct nfs_server *server = NFS_SB(dentry->d_sb);
354 unsigned char blockbits;
355 unsigned long blockres;
356 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
357 struct nfs_fattr fattr;
358 struct nfs_fsstat res = {
365 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
368 buf->f_type = NFS_SUPER_MAGIC;
371 * Current versions of glibc do not correctly handle the
372 * case where f_frsize != f_bsize. Eventually we want to
373 * report the value of wtmult in this field.
375 buf->f_frsize = dentry->d_sb->s_blocksize;
378 * On most *nix systems, f_blocks, f_bfree, and f_bavail
379 * are reported in units of f_frsize. Linux hasn't had
380 * an f_frsize field in its statfs struct until recently,
381 * thus historically Linux's sys_statfs reports these
382 * fields in units of f_bsize.
384 buf->f_bsize = dentry->d_sb->s_blocksize;
385 blockbits = dentry->d_sb->s_blocksize_bits;
386 blockres = (1 << blockbits) - 1;
387 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
388 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
389 buf->f_bavail = (res.abytes + blockres) >> blockbits;
391 buf->f_files = res.tfiles;
392 buf->f_ffree = res.afiles;
394 buf->f_namelen = server->namelen;
400 dprintk("%s: statfs error = %d\n", __FUNCTION__, -error);
406 * Map the security flavour number to a name
408 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
410 static const struct {
411 rpc_authflavor_t flavour;
414 { RPC_AUTH_NULL, "null" },
415 { RPC_AUTH_UNIX, "sys" },
416 { RPC_AUTH_GSS_KRB5, "krb5" },
417 { RPC_AUTH_GSS_KRB5I, "krb5i" },
418 { RPC_AUTH_GSS_KRB5P, "krb5p" },
419 { RPC_AUTH_GSS_LKEY, "lkey" },
420 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
421 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
422 { RPC_AUTH_GSS_SPKM, "spkm" },
423 { RPC_AUTH_GSS_SPKMI, "spkmi" },
424 { RPC_AUTH_GSS_SPKMP, "spkmp" },
425 { UINT_MAX, "unknown" }
429 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
430 if (sec_flavours[i].flavour == flavour)
433 return sec_flavours[i].str;
437 * Describe the mount options in force on this server representation
439 static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss, int showdefaults)
441 static const struct proc_nfs_info {
446 { NFS_MOUNT_SOFT, ",soft", ",hard" },
447 { NFS_MOUNT_INTR, ",intr", "" },
448 { NFS_MOUNT_NOCTO, ",nocto", "" },
449 { NFS_MOUNT_NOAC, ",noac", "" },
450 { NFS_MOUNT_NONLM, ",nolock", "" },
451 { NFS_MOUNT_NOACL, ",noacl", "" },
452 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
455 const struct proc_nfs_info *nfs_infop;
456 struct nfs_client *clp = nfss->nfs_client;
460 seq_printf(m, ",vers=%d", clp->rpc_ops->version);
461 seq_printf(m, ",rsize=%d", nfss->rsize);
462 seq_printf(m, ",wsize=%d", nfss->wsize);
463 if (nfss->acregmin != 3*HZ || showdefaults)
464 seq_printf(m, ",acregmin=%d", nfss->acregmin/HZ);
465 if (nfss->acregmax != 60*HZ || showdefaults)
466 seq_printf(m, ",acregmax=%d", nfss->acregmax/HZ);
467 if (nfss->acdirmin != 30*HZ || showdefaults)
468 seq_printf(m, ",acdirmin=%d", nfss->acdirmin/HZ);
469 if (nfss->acdirmax != 60*HZ || showdefaults)
470 seq_printf(m, ",acdirmax=%d", nfss->acdirmax/HZ);
471 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
472 if (nfss->flags & nfs_infop->flag)
473 seq_puts(m, nfs_infop->str);
475 seq_puts(m, nfs_infop->nostr);
477 switch (nfss->client->cl_xprt->prot) {
485 snprintf(buf, sizeof(buf), "%u", nfss->client->cl_xprt->prot);
488 seq_printf(m, ",proto=%s", proto);
489 seq_printf(m, ",timeo=%lu", 10U * clp->retrans_timeo / HZ);
490 seq_printf(m, ",retrans=%u", clp->retrans_count);
491 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
495 * Describe the mount options on this VFS mountpoint
497 static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
499 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
501 nfs_show_mount_options(m, nfss, 0);
503 seq_puts(m, ",addr=");
504 seq_escape(m, nfss->nfs_client->cl_hostname, " \t\n\\");
510 * Present statistical information for this VFS mountpoint
512 static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
515 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
516 struct rpc_auth *auth = nfss->client->cl_auth;
517 struct nfs_iostats totals = { };
519 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
522 * Display all mount option settings
524 seq_printf(m, "\n\topts:\t");
525 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
526 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
527 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
528 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
529 nfs_show_mount_options(m, nfss, 1);
531 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
533 seq_printf(m, "\n\tcaps:\t");
534 seq_printf(m, "caps=0x%x", nfss->caps);
535 seq_printf(m, ",wtmult=%d", nfss->wtmult);
536 seq_printf(m, ",dtsize=%d", nfss->dtsize);
537 seq_printf(m, ",bsize=%d", nfss->bsize);
538 seq_printf(m, ",namelen=%d", nfss->namelen);
541 if (nfss->nfs_client->cl_nfsversion == 4) {
542 seq_printf(m, "\n\tnfsv4:\t");
543 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
544 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
545 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
550 * Display security flavor in effect for this mount
552 seq_printf(m, "\n\tsec:\tflavor=%d", auth->au_ops->au_flavor);
554 seq_printf(m, ",pseudoflavor=%d", auth->au_flavor);
557 * Display superblock I/O counters
559 for_each_possible_cpu(cpu) {
560 struct nfs_iostats *stats;
563 stats = per_cpu_ptr(nfss->io_stats, cpu);
565 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
566 totals.events[i] += stats->events[i];
567 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
568 totals.bytes[i] += stats->bytes[i];
573 seq_printf(m, "\n\tevents:\t");
574 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
575 seq_printf(m, "%lu ", totals.events[i]);
576 seq_printf(m, "\n\tbytes:\t");
577 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
578 seq_printf(m, "%Lu ", totals.bytes[i]);
581 rpc_print_iostats(m, nfss->client);
587 * Begin unmount by attempting to remove all automounted mountpoints we added
588 * in response to xdev traversals and referrals
590 static void nfs_umount_begin(struct vfsmount *vfsmnt, int flags)
592 struct nfs_server *server = NFS_SB(vfsmnt->mnt_sb);
593 struct rpc_clnt *rpc;
595 shrink_submounts(vfsmnt, &nfs_automount_list);
597 if (!(flags & MNT_FORCE))
599 /* -EIO all pending I/O */
600 rpc = server->client_acl;
602 rpc_killall_tasks(rpc);
603 rpc = server->client;
605 rpc_killall_tasks(rpc);
609 * Sanity-check a server address provided by the mount command
611 static int nfs_verify_server_address(struct sockaddr *addr)
613 switch (addr->sa_family) {
615 struct sockaddr_in *sa = (struct sockaddr_in *) addr;
616 if (sa->sin_addr.s_addr != INADDR_ANY)
626 * Error-check and convert a string of mount options from user space into
629 static int nfs_parse_mount_options(char *raw,
630 struct nfs_parsed_mount_data *mnt)
635 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
638 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
640 while ((p = strsep(&raw, ",")) != NULL) {
641 substring_t args[MAX_OPT_ARGS];
647 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
649 token = match_token(p, nfs_mount_option_tokens, args);
652 mnt->flags |= NFS_MOUNT_SOFT;
655 mnt->flags &= ~NFS_MOUNT_SOFT;
658 mnt->flags |= NFS_MOUNT_INTR;
661 mnt->flags &= ~NFS_MOUNT_INTR;
664 mnt->flags |= NFS_MOUNT_POSIX;
667 mnt->flags &= ~NFS_MOUNT_POSIX;
670 mnt->flags &= ~NFS_MOUNT_NOCTO;
673 mnt->flags |= NFS_MOUNT_NOCTO;
676 mnt->flags &= ~NFS_MOUNT_NOAC;
679 mnt->flags |= NFS_MOUNT_NOAC;
682 mnt->flags &= ~NFS_MOUNT_NONLM;
685 mnt->flags |= NFS_MOUNT_NONLM;
688 mnt->flags &= ~NFS_MOUNT_VER3;
691 mnt->flags |= NFS_MOUNT_VER3;
694 mnt->flags &= ~NFS_MOUNT_TCP;
695 mnt->nfs_server.protocol = IPPROTO_UDP;
700 mnt->flags |= NFS_MOUNT_TCP;
701 mnt->nfs_server.protocol = IPPROTO_TCP;
706 mnt->flags &= ~NFS_MOUNT_NOACL;
709 mnt->flags |= NFS_MOUNT_NOACL;
712 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
715 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
719 if (match_int(args, &option))
721 if (option < 0 || option > 65535)
723 mnt->nfs_server.address.sin_port = htonl(option);
726 if (match_int(args, &mnt->rsize))
730 if (match_int(args, &mnt->wsize))
734 if (match_int(args, &option))
741 if (match_int(args, &mnt->timeo))
745 if (match_int(args, &mnt->retrans))
749 if (match_int(args, &mnt->acregmin))
753 if (match_int(args, &mnt->acregmax))
757 if (match_int(args, &mnt->acdirmin))
761 if (match_int(args, &mnt->acdirmax))
765 if (match_int(args, &option))
772 mnt->acdirmax = option;
775 if (match_int(args, &mnt->namlen))
779 if (match_int(args, &option))
781 if (option < 0 || option > 65535)
783 mnt->mount_server.port = option;
786 if (match_int(args, &option))
790 mnt->mount_server.program = option;
793 if (match_int(args, &option))
797 mnt->mount_server.version = option;
800 if (match_int(args, &option))
804 mnt->nfs_server.program = option;
807 if (match_int(args, &option))
811 mnt->flags &= ~NFS_MOUNT_VER3;
814 mnt->flags |= NFS_MOUNT_VER3;
822 string = match_strdup(args);
825 token = match_token(string, nfs_secflavor_tokens, args);
829 * The flags setting is for v2/v3. The flavor_len
830 * setting is for v4. v2/v3 also need to know the
831 * difference between NULL and UNIX.
835 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
836 mnt->auth_flavor_len = 0;
837 mnt->auth_flavors[0] = RPC_AUTH_NULL;
840 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
841 mnt->auth_flavor_len = 0;
842 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
845 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
846 mnt->auth_flavor_len = 1;
847 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
850 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
851 mnt->auth_flavor_len = 1;
852 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
855 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
856 mnt->auth_flavor_len = 1;
857 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
860 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
861 mnt->auth_flavor_len = 1;
862 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
865 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
866 mnt->auth_flavor_len = 1;
867 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
870 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
871 mnt->auth_flavor_len = 1;
872 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
875 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
876 mnt->auth_flavor_len = 1;
877 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
880 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
881 mnt->auth_flavor_len = 1;
882 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
885 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
886 mnt->auth_flavor_len = 1;
887 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
894 string = match_strdup(args);
897 token = match_token(string,
898 nfs_xprt_protocol_tokens, args);
903 mnt->flags &= ~NFS_MOUNT_TCP;
904 mnt->nfs_server.protocol = IPPROTO_UDP;
909 mnt->flags |= NFS_MOUNT_TCP;
910 mnt->nfs_server.protocol = IPPROTO_TCP;
919 string = match_strdup(args);
922 token = match_token(string,
923 nfs_xprt_protocol_tokens, args);
928 mnt->mount_server.protocol = IPPROTO_UDP;
931 mnt->mount_server.protocol = IPPROTO_TCP;
938 string = match_strdup(args);
941 mnt->nfs_server.address.sin_family = AF_INET;
942 mnt->nfs_server.address.sin_addr.s_addr =
947 string = match_strdup(args);
950 mnt->client_address = string;
953 string = match_strdup(args);
956 mnt->mount_server.address.sin_family = AF_INET;
957 mnt->mount_server.address.sin_addr.s_addr =
974 printk(KERN_INFO "NFS: not enough memory to parse option\n");
978 printk(KERN_INFO "NFS: unrecognized NFS version number\n");
982 printk(KERN_INFO "NFS: unrecognized transport protocol\n");
986 printk(KERN_INFO "NFS: unrecognized security flavor\n");
990 printk(KERN_INFO "NFS: unknown mount option: %s\n", p);
995 * Validate the NFS2/NFS3 mount data
996 * - fills in the mount root filehandle
998 static int nfs_validate_mount_data(struct nfs_mount_data *data,
999 struct nfs_fh *mntfh)
1004 switch (data->version) {
1010 if (data->flags & NFS_MOUNT_VER3)
1012 data->root.size = NFS2_FHSIZE;
1013 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1015 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1018 memset(data->context, 0, sizeof(data->context));
1020 if (data->flags & NFS_MOUNT_VER3)
1021 mntfh->size = data->root.size;
1023 mntfh->size = NFS2_FHSIZE;
1025 if (mntfh->size > sizeof(mntfh->data))
1026 goto out_invalid_fh;
1028 memcpy(mntfh->data, data->root.data, mntfh->size);
1029 if (mntfh->size < sizeof(mntfh->data))
1030 memset(mntfh->data + mntfh->size, 0,
1031 sizeof(mntfh->data) - mntfh->size);
1034 goto out_bad_version;
1037 if (!(data->flags & NFS_MOUNT_SECFLAVOUR))
1038 data->pseudoflavor = RPC_AUTH_UNIX;
1040 #ifndef CONFIG_NFS_V3
1041 if (data->flags & NFS_MOUNT_VER3)
1042 goto out_v3_not_compiled;
1043 #endif /* !CONFIG_NFS_V3 */
1045 if (!nfs_verify_server_address((struct sockaddr *) &data->addr))
1046 goto out_no_address;
1051 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1055 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1060 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1064 dfprintk(MOUNT, "NFS: bad nfs_mount_data version %d\n",
1068 #ifndef CONFIG_NFS_V3
1069 out_v3_not_compiled:
1070 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1071 return -EPROTONOSUPPORT;
1072 #endif /* !CONFIG_NFS_V3 */
1075 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1079 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1084 * Initialise the common bits of the superblock
1086 static inline void nfs_initialise_sb(struct super_block *sb)
1088 struct nfs_server *server = NFS_SB(sb);
1090 sb->s_magic = NFS_SUPER_MAGIC;
1092 /* We probably want something more informative here */
1093 snprintf(sb->s_id, sizeof(sb->s_id),
1094 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1096 if (sb->s_blocksize == 0)
1097 sb->s_blocksize = nfs_block_bits(server->wsize,
1098 &sb->s_blocksize_bits);
1100 if (server->flags & NFS_MOUNT_NOAC)
1101 sb->s_flags |= MS_SYNCHRONOUS;
1103 nfs_super_set_maxbytes(sb, server->maxfilesize);
1107 * Finish setting up an NFS2/3 superblock
1109 static void nfs_fill_super(struct super_block *sb, struct nfs_mount_data *data)
1111 struct nfs_server *server = NFS_SB(sb);
1113 sb->s_blocksize_bits = 0;
1114 sb->s_blocksize = 0;
1116 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1118 if (server->flags & NFS_MOUNT_VER3) {
1119 /* The VFS shouldn't apply the umask to mode bits. We will do
1120 * so ourselves when necessary.
1122 sb->s_flags |= MS_POSIXACL;
1123 sb->s_time_gran = 1;
1126 sb->s_op = &nfs_sops;
1127 nfs_initialise_sb(sb);
1131 * Finish setting up a cloned NFS2/3 superblock
1133 static void nfs_clone_super(struct super_block *sb,
1134 const struct super_block *old_sb)
1136 struct nfs_server *server = NFS_SB(sb);
1138 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1139 sb->s_blocksize = old_sb->s_blocksize;
1140 sb->s_maxbytes = old_sb->s_maxbytes;
1142 if (server->flags & NFS_MOUNT_VER3) {
1143 /* The VFS shouldn't apply the umask to mode bits. We will do
1144 * so ourselves when necessary.
1146 sb->s_flags |= MS_POSIXACL;
1147 sb->s_time_gran = 1;
1150 sb->s_op = old_sb->s_op;
1151 nfs_initialise_sb(sb);
1154 static int nfs_set_super(struct super_block *s, void *_server)
1156 struct nfs_server *server = _server;
1159 s->s_fs_info = server;
1160 ret = set_anon_super(s, server);
1162 server->s_dev = s->s_dev;
1166 static int nfs_compare_super(struct super_block *sb, void *data)
1168 struct nfs_server *server = data, *old = NFS_SB(sb);
1170 if (old->nfs_client != server->nfs_client)
1172 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
1177 static int nfs_get_sb(struct file_system_type *fs_type,
1178 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1180 struct nfs_server *server = NULL;
1181 struct super_block *s;
1182 struct nfs_fh mntfh;
1183 struct nfs_mount_data *data = raw_data;
1184 struct dentry *mntroot;
1187 /* Validate the mount data */
1188 error = nfs_validate_mount_data(data, &mntfh);
1192 /* Get a volume representation */
1193 server = nfs_create_server(data, &mntfh);
1194 if (IS_ERR(server)) {
1195 error = PTR_ERR(server);
1199 /* Get a superblock - note that we may end up sharing one that already exists */
1200 s = sget(fs_type, nfs_compare_super, nfs_set_super, server);
1206 if (s->s_fs_info != server) {
1207 nfs_free_server(server);
1212 /* initial superblock/root creation */
1214 nfs_fill_super(s, data);
1217 mntroot = nfs_get_root(s, &mntfh);
1218 if (IS_ERR(mntroot)) {
1219 error = PTR_ERR(mntroot);
1220 goto error_splat_super;
1223 s->s_flags |= MS_ACTIVE;
1225 mnt->mnt_root = mntroot;
1232 nfs_free_server(server);
1236 up_write(&s->s_umount);
1237 deactivate_super(s);
1242 * Destroy an NFS2/3 superblock
1244 static void nfs_kill_super(struct super_block *s)
1246 struct nfs_server *server = NFS_SB(s);
1249 nfs_free_server(server);
1253 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
1255 static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
1256 const char *dev_name, void *raw_data,
1257 struct vfsmount *mnt)
1259 struct nfs_clone_mount *data = raw_data;
1260 struct super_block *s;
1261 struct nfs_server *server;
1262 struct dentry *mntroot;
1265 dprintk("--> nfs_xdev_get_sb()\n");
1267 /* create a new volume representation */
1268 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1269 if (IS_ERR(server)) {
1270 error = PTR_ERR(server);
1271 goto out_err_noserver;
1274 /* Get a superblock - note that we may end up sharing one that already exists */
1275 s = sget(&nfs_fs_type, nfs_compare_super, nfs_set_super, server);
1281 if (s->s_fs_info != server) {
1282 nfs_free_server(server);
1287 /* initial superblock/root creation */
1289 nfs_clone_super(s, data->sb);
1292 mntroot = nfs_get_root(s, data->fh);
1293 if (IS_ERR(mntroot)) {
1294 error = PTR_ERR(mntroot);
1295 goto error_splat_super;
1298 s->s_flags |= MS_ACTIVE;
1300 mnt->mnt_root = mntroot;
1302 dprintk("<-- nfs_xdev_get_sb() = 0\n");
1306 nfs_free_server(server);
1308 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
1312 up_write(&s->s_umount);
1313 deactivate_super(s);
1314 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
1318 #ifdef CONFIG_NFS_V4
1321 * Finish setting up a cloned NFS4 superblock
1323 static void nfs4_clone_super(struct super_block *sb,
1324 const struct super_block *old_sb)
1326 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1327 sb->s_blocksize = old_sb->s_blocksize;
1328 sb->s_maxbytes = old_sb->s_maxbytes;
1329 sb->s_time_gran = 1;
1330 sb->s_op = old_sb->s_op;
1331 nfs_initialise_sb(sb);
1335 * Set up an NFS4 superblock
1337 static void nfs4_fill_super(struct super_block *sb)
1339 sb->s_time_gran = 1;
1340 sb->s_op = &nfs4_sops;
1341 nfs_initialise_sb(sb);
1345 * Validate NFSv4 mount options
1347 static int nfs4_validate_mount_data(struct nfs4_mount_data **options,
1348 const char *dev_name,
1349 struct sockaddr_in *addr,
1350 rpc_authflavor_t *authflavour,
1355 struct nfs4_mount_data *data = *options;
1361 switch (data->version) {
1363 if (data->host_addrlen != sizeof(*addr))
1364 goto out_no_address;
1365 if (copy_from_user(addr, data->host_addr, sizeof(*addr)))
1367 if (addr->sin_port == 0)
1368 addr->sin_port = htons(NFS_PORT);
1369 if (!nfs_verify_server_address((struct sockaddr *) addr))
1370 goto out_no_address;
1372 switch (data->auth_flavourlen) {
1374 *authflavour = RPC_AUTH_UNIX;
1377 if (copy_from_user(authflavour, data->auth_flavours,
1378 sizeof(*authflavour)))
1382 goto out_inval_auth;
1385 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
1390 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
1394 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *mntpath);
1396 c = strndup_user(data->client_addr.data, 16);
1403 goto out_bad_version;
1409 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
1413 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
1414 data->auth_flavourlen);
1418 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
1422 dfprintk(MOUNT, "NFS4: bad nfs_mount_data version %d\n",
1428 * Get the superblock for an NFS4 mountpoint
1430 static int nfs4_get_sb(struct file_system_type *fs_type,
1431 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1433 struct nfs4_mount_data *data = raw_data;
1434 struct super_block *s;
1435 struct nfs_server *server;
1436 struct sockaddr_in addr;
1437 rpc_authflavor_t authflavour;
1438 struct nfs_fh mntfh;
1439 struct dentry *mntroot;
1440 char *mntpath = NULL, *hostname = NULL, *ip_addr = NULL;
1443 /* Validate the mount data */
1444 error = nfs4_validate_mount_data(&data, dev_name, &addr, &authflavour,
1445 &hostname, &mntpath, &ip_addr);
1449 /* Get a volume representation */
1450 server = nfs4_create_server(data, hostname, &addr, mntpath, ip_addr,
1451 authflavour, &mntfh);
1452 if (IS_ERR(server)) {
1453 error = PTR_ERR(server);
1457 /* Get a superblock - note that we may end up sharing one that already exists */
1458 s = sget(fs_type, nfs_compare_super, nfs_set_super, server);
1464 if (s->s_fs_info != server) {
1465 nfs_free_server(server);
1470 /* initial superblock/root creation */
1475 mntroot = nfs4_get_root(s, &mntfh);
1476 if (IS_ERR(mntroot)) {
1477 error = PTR_ERR(mntroot);
1478 goto error_splat_super;
1481 s->s_flags |= MS_ACTIVE;
1483 mnt->mnt_root = mntroot;
1493 nfs_free_server(server);
1497 up_write(&s->s_umount);
1498 deactivate_super(s);
1502 static void nfs4_kill_super(struct super_block *sb)
1504 struct nfs_server *server = NFS_SB(sb);
1506 nfs_return_all_delegations(sb);
1507 kill_anon_super(sb);
1509 nfs4_renewd_prepare_shutdown(server);
1510 nfs_free_server(server);
1514 * Clone an NFS4 server record on xdev traversal (FSID-change)
1516 static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
1517 const char *dev_name, void *raw_data,
1518 struct vfsmount *mnt)
1520 struct nfs_clone_mount *data = raw_data;
1521 struct super_block *s;
1522 struct nfs_server *server;
1523 struct dentry *mntroot;
1526 dprintk("--> nfs4_xdev_get_sb()\n");
1528 /* create a new volume representation */
1529 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1530 if (IS_ERR(server)) {
1531 error = PTR_ERR(server);
1532 goto out_err_noserver;
1535 /* Get a superblock - note that we may end up sharing one that already exists */
1536 s = sget(&nfs_fs_type, nfs_compare_super, nfs_set_super, server);
1542 if (s->s_fs_info != server) {
1543 nfs_free_server(server);
1548 /* initial superblock/root creation */
1550 nfs4_clone_super(s, data->sb);
1553 mntroot = nfs4_get_root(s, data->fh);
1554 if (IS_ERR(mntroot)) {
1555 error = PTR_ERR(mntroot);
1556 goto error_splat_super;
1559 s->s_flags |= MS_ACTIVE;
1561 mnt->mnt_root = mntroot;
1563 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
1567 nfs_free_server(server);
1569 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
1573 up_write(&s->s_umount);
1574 deactivate_super(s);
1575 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
1580 * Create an NFS4 server record on referral traversal
1582 static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
1583 const char *dev_name, void *raw_data,
1584 struct vfsmount *mnt)
1586 struct nfs_clone_mount *data = raw_data;
1587 struct super_block *s;
1588 struct nfs_server *server;
1589 struct dentry *mntroot;
1590 struct nfs_fh mntfh;
1593 dprintk("--> nfs4_referral_get_sb()\n");
1595 /* create a new volume representation */
1596 server = nfs4_create_referral_server(data, &mntfh);
1597 if (IS_ERR(server)) {
1598 error = PTR_ERR(server);
1599 goto out_err_noserver;
1602 /* Get a superblock - note that we may end up sharing one that already exists */
1603 s = sget(&nfs_fs_type, nfs_compare_super, nfs_set_super, server);
1609 if (s->s_fs_info != server) {
1610 nfs_free_server(server);
1615 /* initial superblock/root creation */
1620 mntroot = nfs4_get_root(s, &mntfh);
1621 if (IS_ERR(mntroot)) {
1622 error = PTR_ERR(mntroot);
1623 goto error_splat_super;
1626 s->s_flags |= MS_ACTIVE;
1628 mnt->mnt_root = mntroot;
1630 dprintk("<-- nfs4_referral_get_sb() = 0\n");
1634 nfs_free_server(server);
1636 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
1640 up_write(&s->s_umount);
1641 deactivate_super(s);
1642 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
1646 #endif /* CONFIG_NFS_V4 */