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 * Use the remote server's MOUNT service to request the NFS file handle
996 * corresponding to the provided path.
998 static int nfs_try_mount(struct nfs_parsed_mount_data *args,
999 struct nfs_fh *root_fh)
1001 struct sockaddr_in sin;
1004 if (args->mount_server.version == 0) {
1005 if (args->flags & NFS_MOUNT_VER3)
1006 args->mount_server.version = NFS_MNT3_VERSION;
1008 args->mount_server.version = NFS_MNT_VERSION;
1012 * Construct the mount server's address.
1014 if (args->mount_server.address.sin_addr.s_addr != INADDR_ANY)
1015 sin = args->mount_server.address;
1017 sin = args->nfs_server.address;
1018 if (args->mount_server.port == 0) {
1019 status = rpcb_getport_sync(&sin,
1020 args->mount_server.program,
1021 args->mount_server.version,
1022 args->mount_server.protocol);
1025 sin.sin_port = htons(status);
1027 sin.sin_port = htons(args->mount_server.port);
1030 * Now ask the mount server to map our export path
1033 status = nfs_mount((struct sockaddr *) &sin,
1035 args->nfs_server.hostname,
1036 args->nfs_server.export_path,
1037 args->mount_server.version,
1038 args->mount_server.protocol,
1046 dfprintk(MOUNT, "NFS: unable to contact server on host "
1047 NIPQUAD_FMT "\n", NIPQUAD(sin.sin_addr.s_addr));
1052 * Validate the NFS2/NFS3 mount data
1053 * - fills in the mount root filehandle
1055 static int nfs_validate_mount_data(struct nfs_mount_data *data,
1056 struct nfs_fh *mntfh)
1061 switch (data->version) {
1067 if (data->flags & NFS_MOUNT_VER3)
1069 data->root.size = NFS2_FHSIZE;
1070 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1072 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1075 memset(data->context, 0, sizeof(data->context));
1077 if (data->flags & NFS_MOUNT_VER3)
1078 mntfh->size = data->root.size;
1080 mntfh->size = NFS2_FHSIZE;
1082 if (mntfh->size > sizeof(mntfh->data))
1083 goto out_invalid_fh;
1085 memcpy(mntfh->data, data->root.data, mntfh->size);
1086 if (mntfh->size < sizeof(mntfh->data))
1087 memset(mntfh->data + mntfh->size, 0,
1088 sizeof(mntfh->data) - mntfh->size);
1091 goto out_bad_version;
1094 if (!(data->flags & NFS_MOUNT_SECFLAVOUR))
1095 data->pseudoflavor = RPC_AUTH_UNIX;
1097 #ifndef CONFIG_NFS_V3
1098 if (data->flags & NFS_MOUNT_VER3)
1099 goto out_v3_not_compiled;
1100 #endif /* !CONFIG_NFS_V3 */
1102 if (!nfs_verify_server_address((struct sockaddr *) &data->addr))
1103 goto out_no_address;
1108 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1112 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1117 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1121 dfprintk(MOUNT, "NFS: bad nfs_mount_data version %d\n",
1125 #ifndef CONFIG_NFS_V3
1126 out_v3_not_compiled:
1127 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1128 return -EPROTONOSUPPORT;
1129 #endif /* !CONFIG_NFS_V3 */
1132 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1136 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1141 * Initialise the common bits of the superblock
1143 static inline void nfs_initialise_sb(struct super_block *sb)
1145 struct nfs_server *server = NFS_SB(sb);
1147 sb->s_magic = NFS_SUPER_MAGIC;
1149 /* We probably want something more informative here */
1150 snprintf(sb->s_id, sizeof(sb->s_id),
1151 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1153 if (sb->s_blocksize == 0)
1154 sb->s_blocksize = nfs_block_bits(server->wsize,
1155 &sb->s_blocksize_bits);
1157 if (server->flags & NFS_MOUNT_NOAC)
1158 sb->s_flags |= MS_SYNCHRONOUS;
1160 nfs_super_set_maxbytes(sb, server->maxfilesize);
1164 * Finish setting up an NFS2/3 superblock
1166 static void nfs_fill_super(struct super_block *sb, struct nfs_mount_data *data)
1168 struct nfs_server *server = NFS_SB(sb);
1170 sb->s_blocksize_bits = 0;
1171 sb->s_blocksize = 0;
1173 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1175 if (server->flags & NFS_MOUNT_VER3) {
1176 /* The VFS shouldn't apply the umask to mode bits. We will do
1177 * so ourselves when necessary.
1179 sb->s_flags |= MS_POSIXACL;
1180 sb->s_time_gran = 1;
1183 sb->s_op = &nfs_sops;
1184 nfs_initialise_sb(sb);
1188 * Finish setting up a cloned NFS2/3 superblock
1190 static void nfs_clone_super(struct super_block *sb,
1191 const struct super_block *old_sb)
1193 struct nfs_server *server = NFS_SB(sb);
1195 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1196 sb->s_blocksize = old_sb->s_blocksize;
1197 sb->s_maxbytes = old_sb->s_maxbytes;
1199 if (server->flags & NFS_MOUNT_VER3) {
1200 /* The VFS shouldn't apply the umask to mode bits. We will do
1201 * so ourselves when necessary.
1203 sb->s_flags |= MS_POSIXACL;
1204 sb->s_time_gran = 1;
1207 sb->s_op = old_sb->s_op;
1208 nfs_initialise_sb(sb);
1211 static int nfs_set_super(struct super_block *s, void *_server)
1213 struct nfs_server *server = _server;
1216 s->s_fs_info = server;
1217 ret = set_anon_super(s, server);
1219 server->s_dev = s->s_dev;
1223 static int nfs_compare_super(struct super_block *sb, void *data)
1225 struct nfs_server *server = data, *old = NFS_SB(sb);
1227 if (old->nfs_client != server->nfs_client)
1229 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
1234 static int nfs_get_sb(struct file_system_type *fs_type,
1235 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1237 struct nfs_server *server = NULL;
1238 struct super_block *s;
1239 struct nfs_fh mntfh;
1240 struct nfs_mount_data *data = raw_data;
1241 struct dentry *mntroot;
1244 /* Validate the mount data */
1245 error = nfs_validate_mount_data(data, &mntfh);
1249 /* Get a volume representation */
1250 server = nfs_create_server(data, &mntfh);
1251 if (IS_ERR(server)) {
1252 error = PTR_ERR(server);
1256 /* Get a superblock - note that we may end up sharing one that already exists */
1257 s = sget(fs_type, nfs_compare_super, nfs_set_super, server);
1263 if (s->s_fs_info != server) {
1264 nfs_free_server(server);
1269 /* initial superblock/root creation */
1271 nfs_fill_super(s, data);
1274 mntroot = nfs_get_root(s, &mntfh);
1275 if (IS_ERR(mntroot)) {
1276 error = PTR_ERR(mntroot);
1277 goto error_splat_super;
1280 s->s_flags |= MS_ACTIVE;
1282 mnt->mnt_root = mntroot;
1289 nfs_free_server(server);
1293 up_write(&s->s_umount);
1294 deactivate_super(s);
1299 * Destroy an NFS2/3 superblock
1301 static void nfs_kill_super(struct super_block *s)
1303 struct nfs_server *server = NFS_SB(s);
1306 nfs_free_server(server);
1310 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
1312 static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
1313 const char *dev_name, void *raw_data,
1314 struct vfsmount *mnt)
1316 struct nfs_clone_mount *data = raw_data;
1317 struct super_block *s;
1318 struct nfs_server *server;
1319 struct dentry *mntroot;
1322 dprintk("--> nfs_xdev_get_sb()\n");
1324 /* create a new volume representation */
1325 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1326 if (IS_ERR(server)) {
1327 error = PTR_ERR(server);
1328 goto out_err_noserver;
1331 /* Get a superblock - note that we may end up sharing one that already exists */
1332 s = sget(&nfs_fs_type, nfs_compare_super, nfs_set_super, server);
1338 if (s->s_fs_info != server) {
1339 nfs_free_server(server);
1344 /* initial superblock/root creation */
1346 nfs_clone_super(s, data->sb);
1349 mntroot = nfs_get_root(s, data->fh);
1350 if (IS_ERR(mntroot)) {
1351 error = PTR_ERR(mntroot);
1352 goto error_splat_super;
1355 s->s_flags |= MS_ACTIVE;
1357 mnt->mnt_root = mntroot;
1359 dprintk("<-- nfs_xdev_get_sb() = 0\n");
1363 nfs_free_server(server);
1365 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
1369 up_write(&s->s_umount);
1370 deactivate_super(s);
1371 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
1375 #ifdef CONFIG_NFS_V4
1378 * Finish setting up a cloned NFS4 superblock
1380 static void nfs4_clone_super(struct super_block *sb,
1381 const struct super_block *old_sb)
1383 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1384 sb->s_blocksize = old_sb->s_blocksize;
1385 sb->s_maxbytes = old_sb->s_maxbytes;
1386 sb->s_time_gran = 1;
1387 sb->s_op = old_sb->s_op;
1388 nfs_initialise_sb(sb);
1392 * Set up an NFS4 superblock
1394 static void nfs4_fill_super(struct super_block *sb)
1396 sb->s_time_gran = 1;
1397 sb->s_op = &nfs4_sops;
1398 nfs_initialise_sb(sb);
1402 * Validate NFSv4 mount options
1404 static int nfs4_validate_mount_data(struct nfs4_mount_data **options,
1405 const char *dev_name,
1406 struct sockaddr_in *addr,
1407 rpc_authflavor_t *authflavour,
1412 struct nfs4_mount_data *data = *options;
1418 switch (data->version) {
1420 if (data->host_addrlen != sizeof(*addr))
1421 goto out_no_address;
1422 if (copy_from_user(addr, data->host_addr, sizeof(*addr)))
1424 if (addr->sin_port == 0)
1425 addr->sin_port = htons(NFS_PORT);
1426 if (!nfs_verify_server_address((struct sockaddr *) addr))
1427 goto out_no_address;
1429 switch (data->auth_flavourlen) {
1431 *authflavour = RPC_AUTH_UNIX;
1434 if (copy_from_user(authflavour, data->auth_flavours,
1435 sizeof(*authflavour)))
1439 goto out_inval_auth;
1442 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
1447 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
1451 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *mntpath);
1453 c = strndup_user(data->client_addr.data, 16);
1460 goto out_bad_version;
1466 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
1470 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
1471 data->auth_flavourlen);
1475 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
1479 dfprintk(MOUNT, "NFS4: bad nfs_mount_data version %d\n",
1485 * Get the superblock for an NFS4 mountpoint
1487 static int nfs4_get_sb(struct file_system_type *fs_type,
1488 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1490 struct nfs4_mount_data *data = raw_data;
1491 struct super_block *s;
1492 struct nfs_server *server;
1493 struct sockaddr_in addr;
1494 rpc_authflavor_t authflavour;
1495 struct nfs_fh mntfh;
1496 struct dentry *mntroot;
1497 char *mntpath = NULL, *hostname = NULL, *ip_addr = NULL;
1500 /* Validate the mount data */
1501 error = nfs4_validate_mount_data(&data, dev_name, &addr, &authflavour,
1502 &hostname, &mntpath, &ip_addr);
1506 /* Get a volume representation */
1507 server = nfs4_create_server(data, hostname, &addr, mntpath, ip_addr,
1508 authflavour, &mntfh);
1509 if (IS_ERR(server)) {
1510 error = PTR_ERR(server);
1514 /* Get a superblock - note that we may end up sharing one that already exists */
1515 s = sget(fs_type, nfs_compare_super, nfs_set_super, server);
1521 if (s->s_fs_info != server) {
1522 nfs_free_server(server);
1527 /* initial superblock/root creation */
1532 mntroot = nfs4_get_root(s, &mntfh);
1533 if (IS_ERR(mntroot)) {
1534 error = PTR_ERR(mntroot);
1535 goto error_splat_super;
1538 s->s_flags |= MS_ACTIVE;
1540 mnt->mnt_root = mntroot;
1550 nfs_free_server(server);
1554 up_write(&s->s_umount);
1555 deactivate_super(s);
1559 static void nfs4_kill_super(struct super_block *sb)
1561 struct nfs_server *server = NFS_SB(sb);
1563 nfs_return_all_delegations(sb);
1564 kill_anon_super(sb);
1566 nfs4_renewd_prepare_shutdown(server);
1567 nfs_free_server(server);
1571 * Clone an NFS4 server record on xdev traversal (FSID-change)
1573 static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
1574 const char *dev_name, void *raw_data,
1575 struct vfsmount *mnt)
1577 struct nfs_clone_mount *data = raw_data;
1578 struct super_block *s;
1579 struct nfs_server *server;
1580 struct dentry *mntroot;
1583 dprintk("--> nfs4_xdev_get_sb()\n");
1585 /* create a new volume representation */
1586 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1587 if (IS_ERR(server)) {
1588 error = PTR_ERR(server);
1589 goto out_err_noserver;
1592 /* Get a superblock - note that we may end up sharing one that already exists */
1593 s = sget(&nfs_fs_type, nfs_compare_super, nfs_set_super, server);
1599 if (s->s_fs_info != server) {
1600 nfs_free_server(server);
1605 /* initial superblock/root creation */
1607 nfs4_clone_super(s, data->sb);
1610 mntroot = nfs4_get_root(s, data->fh);
1611 if (IS_ERR(mntroot)) {
1612 error = PTR_ERR(mntroot);
1613 goto error_splat_super;
1616 s->s_flags |= MS_ACTIVE;
1618 mnt->mnt_root = mntroot;
1620 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
1624 nfs_free_server(server);
1626 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
1630 up_write(&s->s_umount);
1631 deactivate_super(s);
1632 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
1637 * Create an NFS4 server record on referral traversal
1639 static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
1640 const char *dev_name, void *raw_data,
1641 struct vfsmount *mnt)
1643 struct nfs_clone_mount *data = raw_data;
1644 struct super_block *s;
1645 struct nfs_server *server;
1646 struct dentry *mntroot;
1647 struct nfs_fh mntfh;
1650 dprintk("--> nfs4_referral_get_sb()\n");
1652 /* create a new volume representation */
1653 server = nfs4_create_referral_server(data, &mntfh);
1654 if (IS_ERR(server)) {
1655 error = PTR_ERR(server);
1656 goto out_err_noserver;
1659 /* Get a superblock - note that we may end up sharing one that already exists */
1660 s = sget(&nfs_fs_type, nfs_compare_super, nfs_set_super, server);
1666 if (s->s_fs_info != server) {
1667 nfs_free_server(server);
1672 /* initial superblock/root creation */
1677 mntroot = nfs4_get_root(s, &mntfh);
1678 if (IS_ERR(mntroot)) {
1679 error = PTR_ERR(mntroot);
1680 goto error_splat_super;
1683 s->s_flags |= MS_ACTIVE;
1685 mnt->mnt_root = mntroot;
1687 dprintk("<-- nfs4_referral_get_sb() = 0\n");
1691 nfs_free_server(server);
1693 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
1697 up_write(&s->s_umount);
1698 deactivate_super(s);
1699 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
1703 #endif /* CONFIG_NFS_V4 */