blob: 79bc61fe2868388048ed309ceb2e78d0a5ba80d6 [file] [log] [blame]
David Howellsf7b422b2006-06-09 09:34:33 -04001/*
2 * linux/fs/nfs/super.c
3 *
4 * Copyright (C) 1992 Rick Sladkey
5 *
6 * nfs superblock handling functions
7 *
Alan Cox526719b2008-10-27 15:19:48 +00008 * Modularised by Alan Cox <alan@lxorguk.ukuu.org.uk>, while hacking some
David Howellsf7b422b2006-06-09 09:34:33 -04009 * experimental NFS changes. Modularisation taken straight from SYS5 fs.
10 *
11 * Change to nfs_read_super() to permit NFS mounts to multi-homed hosts.
12 * J.S.Peatfield@damtp.cam.ac.uk
13 *
14 * Split from inode.c by David Howells <dhowells@redhat.com>
15 *
David Howells54ceac42006-08-22 20:06:13 -040016 * - 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())
David Howellsf7b422b2006-06-09 09:34:33 -040021 */
22
David Howellsf7b422b2006-06-09 09:34:33 -040023#include <linux/module.h>
24#include <linux/init.h>
25
26#include <linux/time.h>
27#include <linux/kernel.h>
28#include <linux/mm.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>
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -040036#include <linux/sunrpc/xprtsock.h>
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -040037#include <linux/sunrpc/xprtrdma.h>
David Howellsf7b422b2006-06-09 09:34:33 -040038#include <linux/nfs_fs.h>
39#include <linux/nfs_mount.h>
40#include <linux/nfs4_mount.h>
41#include <linux/lockd/bind.h>
David Howellsf7b422b2006-06-09 09:34:33 -040042#include <linux/seq_file.h>
43#include <linux/mount.h>
Trond Myklebustc02d7ad2009-06-22 15:09:14 -040044#include <linux/mnt_namespace.h>
45#include <linux/namei.h>
David Howellsf7b422b2006-06-09 09:34:33 -040046#include <linux/nfs_idmap.h>
47#include <linux/vfs.h>
48#include <linux/inet.h>
Chuck Leverfd00a8f2007-12-10 14:57:38 -050049#include <linux/in6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090050#include <linux/slab.h>
Chuck Leverfd00a8f2007-12-10 14:57:38 -050051#include <net/ipv6.h>
Chuck Leverd8e77482008-06-23 12:37:01 -040052#include <linux/netdevice.h>
David Howellsf7b422b2006-06-09 09:34:33 -040053#include <linux/nfs_xdr.h>
Adrian Bunkb5d5dfb2007-02-12 00:53:40 -080054#include <linux/magic.h>
Chuck Leverbf0fd762007-07-01 12:13:44 -040055#include <linux/parser.h>
David Howellsf7b422b2006-06-09 09:34:33 -040056
57#include <asm/system.h>
58#include <asm/uaccess.h>
59
60#include "nfs4_fs.h"
61#include "callback.h"
62#include "delegation.h"
63#include "iostat.h"
64#include "internal.h"
David Howells08734042009-04-03 16:42:42 +010065#include "fscache.h"
David Howellsf7b422b2006-06-09 09:34:33 -040066
67#define NFSDBG_FACILITY NFSDBG_VFS
68
Paulius Zaleckas1e657bd2010-10-31 18:21:05 +020069#ifdef CONFIG_NFS_V3
70#define NFS_DEFAULT_VERSION 3
71#else
72#define NFS_DEFAULT_VERSION 2
73#endif
74
Chuck Leverbf0fd762007-07-01 12:13:44 -040075enum {
76 /* Mount options that take no arguments */
77 Opt_soft, Opt_hard,
Chuck Leverbf0fd762007-07-01 12:13:44 -040078 Opt_posix, Opt_noposix,
79 Opt_cto, Opt_nocto,
80 Opt_ac, Opt_noac,
81 Opt_lock, Opt_nolock,
Chuck Lever764302c2009-09-08 19:50:03 -040082 Opt_v2, Opt_v3, Opt_v4,
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -040083 Opt_udp, Opt_tcp, Opt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -040084 Opt_acl, Opt_noacl,
85 Opt_rdirplus, Opt_nordirplus,
Trond Myklebust75180df2007-05-16 16:53:28 -040086 Opt_sharecache, Opt_nosharecache,
Chuck Leverd7403512008-12-23 15:21:37 -050087 Opt_resvport, Opt_noresvport,
David Howellsb797cac2009-04-03 16:42:48 +010088 Opt_fscache, Opt_nofscache,
Chuck Leverbf0fd762007-07-01 12:13:44 -040089
90 /* Mount options that take integer arguments */
91 Opt_port,
92 Opt_rsize, Opt_wsize, Opt_bsize,
93 Opt_timeo, Opt_retrans,
94 Opt_acregmin, Opt_acregmax,
95 Opt_acdirmin, Opt_acdirmax,
96 Opt_actimeo,
97 Opt_namelen,
98 Opt_mountport,
Chuck Levere887cbc2007-10-26 13:32:29 -040099 Opt_mountvers,
Chuck Leverad879ce2007-10-26 13:32:24 -0400100 Opt_nfsvers,
Mike Sager3fd5be92009-04-01 09:21:48 -0400101 Opt_minorversion,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400102
103 /* Mount options that take string arguments */
Chuck Lever33832032007-12-10 14:59:13 -0500104 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
Chuck Lever0ac83772007-09-11 18:01:04 -0400105 Opt_addr, Opt_mountaddr, Opt_clientaddr,
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400106 Opt_lookupcache,
David Howellsb797cac2009-04-03 16:42:48 +0100107 Opt_fscache_uniq,
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400108 Opt_local_lock,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400109
Chuck Leverf45663c2008-06-24 19:28:02 -0400110 /* Special mount options */
111 Opt_userspace, Opt_deprecated, Opt_sloppy,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400112
113 Opt_err
114};
115
Steven Whitehousea447c092008-10-13 10:46:57 +0100116static const match_table_t nfs_mount_option_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400117 { Opt_userspace, "bg" },
118 { Opt_userspace, "fg" },
Chuck Leverecbb3842008-06-12 12:37:33 -0400119 { Opt_userspace, "retry=%s" },
120
Chuck Leverf45663c2008-06-24 19:28:02 -0400121 { Opt_sloppy, "sloppy" },
122
Chuck Leverbf0fd762007-07-01 12:13:44 -0400123 { Opt_soft, "soft" },
124 { Opt_hard, "hard" },
Chuck Leverd33e4df2008-06-12 12:37:41 -0400125 { Opt_deprecated, "intr" },
126 { Opt_deprecated, "nointr" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400127 { Opt_posix, "posix" },
128 { Opt_noposix, "noposix" },
129 { Opt_cto, "cto" },
130 { Opt_nocto, "nocto" },
131 { Opt_ac, "ac" },
132 { Opt_noac, "noac" },
133 { Opt_lock, "lock" },
134 { Opt_nolock, "nolock" },
135 { Opt_v2, "v2" },
136 { Opt_v3, "v3" },
Chuck Lever764302c2009-09-08 19:50:03 -0400137 { Opt_v4, "v4" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400138 { Opt_udp, "udp" },
139 { Opt_tcp, "tcp" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400140 { Opt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400141 { Opt_acl, "acl" },
142 { Opt_noacl, "noacl" },
143 { Opt_rdirplus, "rdirplus" },
144 { Opt_nordirplus, "nordirplus" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400145 { Opt_sharecache, "sharecache" },
146 { Opt_nosharecache, "nosharecache" },
Chuck Leverd7403512008-12-23 15:21:37 -0500147 { Opt_resvport, "resvport" },
148 { Opt_noresvport, "noresvport" },
David Howellsb797cac2009-04-03 16:42:48 +0100149 { Opt_fscache, "fsc" },
David Howellsb797cac2009-04-03 16:42:48 +0100150 { Opt_nofscache, "nofsc" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400151
Chuck Levera5a16ba2009-06-17 18:02:14 -0700152 { Opt_port, "port=%s" },
153 { Opt_rsize, "rsize=%s" },
154 { Opt_wsize, "wsize=%s" },
155 { Opt_bsize, "bsize=%s" },
156 { Opt_timeo, "timeo=%s" },
157 { Opt_retrans, "retrans=%s" },
158 { Opt_acregmin, "acregmin=%s" },
159 { Opt_acregmax, "acregmax=%s" },
160 { Opt_acdirmin, "acdirmin=%s" },
161 { Opt_acdirmax, "acdirmax=%s" },
162 { Opt_actimeo, "actimeo=%s" },
163 { Opt_namelen, "namlen=%s" },
164 { Opt_mountport, "mountport=%s" },
165 { Opt_mountvers, "mountvers=%s" },
166 { Opt_nfsvers, "nfsvers=%s" },
167 { Opt_nfsvers, "vers=%s" },
Chuck Leverf3f4f4e2009-08-09 15:09:29 -0400168 { Opt_minorversion, "minorversion=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400169
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" },
Chuck Lever33832032007-12-10 14:59:13 -0500175 { Opt_mounthost, "mounthost=%s" },
Chuck Lever0ac83772007-09-11 18:01:04 -0400176 { Opt_mountaddr, "mountaddr=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400177
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400178 { Opt_lookupcache, "lookupcache=%s" },
Chuck Levera6d5ff62010-05-07 13:33:58 -0400179 { Opt_fscache_uniq, "fsc=%s" },
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400180 { Opt_local_lock, "local_lock=%s" },
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400181
Chuck Leverbf0fd762007-07-01 12:13:44 -0400182 { Opt_err, NULL }
183};
184
185enum {
Jeff Laytonee671b02009-12-03 15:58:56 -0500186 Opt_xprt_udp, Opt_xprt_udp6, Opt_xprt_tcp, Opt_xprt_tcp6, Opt_xprt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400187
188 Opt_xprt_err
189};
190
Steven Whitehousea447c092008-10-13 10:46:57 +0100191static const match_table_t nfs_xprt_protocol_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400192 { Opt_xprt_udp, "udp" },
Jeff Laytonee671b02009-12-03 15:58:56 -0500193 { Opt_xprt_udp6, "udp6" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400194 { Opt_xprt_tcp, "tcp" },
Jeff Laytonee671b02009-12-03 15:58:56 -0500195 { Opt_xprt_tcp6, "tcp6" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400196 { Opt_xprt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400197
198 { Opt_xprt_err, NULL }
199};
200
201enum {
202 Opt_sec_none, Opt_sec_sys,
203 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
204 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
205 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
206
207 Opt_sec_err
208};
209
Steven Whitehousea447c092008-10-13 10:46:57 +0100210static const match_table_t nfs_secflavor_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400211 { Opt_sec_none, "none" },
212 { Opt_sec_none, "null" },
213 { Opt_sec_sys, "sys" },
214
215 { Opt_sec_krb5, "krb5" },
216 { Opt_sec_krb5i, "krb5i" },
217 { Opt_sec_krb5p, "krb5p" },
218
219 { Opt_sec_lkey, "lkey" },
220 { Opt_sec_lkeyi, "lkeyi" },
221 { Opt_sec_lkeyp, "lkeyp" },
222
Olga Kornievskaia8d042212008-02-13 16:47:06 -0500223 { Opt_sec_spkm, "spkm3" },
224 { Opt_sec_spkmi, "spkm3i" },
225 { Opt_sec_spkmp, "spkm3p" },
226
Chuck Leverbf0fd762007-07-01 12:13:44 -0400227 { Opt_sec_err, NULL }
228};
229
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400230enum {
231 Opt_lookupcache_all, Opt_lookupcache_positive,
232 Opt_lookupcache_none,
233
234 Opt_lookupcache_err
235};
236
237static match_table_t nfs_lookupcache_tokens = {
238 { Opt_lookupcache_all, "all" },
239 { Opt_lookupcache_positive, "pos" },
240 { Opt_lookupcache_positive, "positive" },
241 { Opt_lookupcache_none, "none" },
242
243 { Opt_lookupcache_err, NULL }
244};
245
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400246enum {
247 Opt_local_lock_all, Opt_local_lock_flock, Opt_local_lock_posix,
248 Opt_local_lock_none,
249
250 Opt_local_lock_err
251};
252
253static match_table_t nfs_local_lock_tokens = {
254 { Opt_local_lock_all, "all" },
255 { Opt_local_lock_flock, "flock" },
256 { Opt_local_lock_posix, "posix" },
257 { Opt_local_lock_none, "none" },
258
259 { Opt_local_lock_err, NULL }
260};
261
Chuck Leverbf0fd762007-07-01 12:13:44 -0400262
Al Viro42faad92008-04-24 07:21:56 -0400263static void nfs_umount_begin(struct super_block *);
Trond Myklebust816724e2006-06-24 08:41:41 -0400264static int nfs_statfs(struct dentry *, struct kstatfs *);
David Howellsf7b422b2006-06-09 09:34:33 -0400265static int nfs_show_options(struct seq_file *, struct vfsmount *);
Al Viroc7f404b2011-03-16 06:59:40 -0400266static int nfs_show_devname(struct seq_file *, struct vfsmount *);
267static int nfs_show_path(struct seq_file *, struct vfsmount *);
David Howellsf7b422b2006-06-09 09:34:33 -0400268static int nfs_show_stats(struct seq_file *, struct vfsmount *);
Trond Myklebust816724e2006-06-24 08:41:41 -0400269static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
Al Viro31f43472010-10-29 03:38:12 -0400270static struct dentry *nfs_xdev_mount(struct file_system_type *fs_type,
271 int flags, const char *dev_name, void *raw_data);
Trond Myklebust387c1492010-02-03 08:27:35 -0500272static void nfs_put_super(struct super_block *);
David Howellsf7b422b2006-06-09 09:34:33 -0400273static void nfs_kill_super(struct super_block *);
Jeff Layton48b605f2008-06-10 15:38:39 -0400274static int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
David Howellsf7b422b2006-06-09 09:34:33 -0400275
276static struct file_system_type nfs_fs_type = {
277 .owner = THIS_MODULE,
278 .name = "nfs",
279 .get_sb = nfs_get_sb,
280 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700281 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400282};
283
David Howells54ceac42006-08-22 20:06:13 -0400284struct file_system_type nfs_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400285 .owner = THIS_MODULE,
286 .name = "nfs",
Al Viro31f43472010-10-29 03:38:12 -0400287 .mount = nfs_xdev_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400288 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700289 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400290};
291
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800292static const struct super_operations nfs_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400293 .alloc_inode = nfs_alloc_inode,
294 .destroy_inode = nfs_destroy_inode,
295 .write_inode = nfs_write_inode,
Trond Myklebust387c1492010-02-03 08:27:35 -0500296 .put_super = nfs_put_super,
David Howellsf7b422b2006-06-09 09:34:33 -0400297 .statfs = nfs_statfs,
Al Virob57922d2010-06-07 14:34:48 -0400298 .evict_inode = nfs_evict_inode,
David Howellsf7b422b2006-06-09 09:34:33 -0400299 .umount_begin = nfs_umount_begin,
300 .show_options = nfs_show_options,
Al Viroc7f404b2011-03-16 06:59:40 -0400301 .show_devname = nfs_show_devname,
302 .show_path = nfs_show_path,
David Howellsf7b422b2006-06-09 09:34:33 -0400303 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400304 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400305};
306
307#ifdef CONFIG_NFS_V4
Chuck Lever7630c852009-09-08 19:49:57 -0400308static int nfs4_validate_text_mount_data(void *options,
309 struct nfs_parsed_mount_data *args, const char *dev_name);
Chuck Levera6fe23b2009-09-08 19:50:00 -0400310static int nfs4_try_mount(int flags, const char *dev_name,
311 struct nfs_parsed_mount_data *data, struct vfsmount *mnt);
Trond Myklebust816724e2006-06-24 08:41:41 -0400312static int nfs4_get_sb(struct file_system_type *fs_type,
313 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
Al Viro31f43472010-10-29 03:38:12 -0400314static struct dentry *nfs4_remote_mount(struct file_system_type *fs_type,
315 int flags, const char *dev_name, void *raw_data);
316static struct dentry *nfs4_xdev_mount(struct file_system_type *fs_type,
317 int flags, const char *dev_name, void *raw_data);
David Howells54ceac42006-08-22 20:06:13 -0400318static int nfs4_referral_get_sb(struct file_system_type *fs_type,
319 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
Al Viro31f43472010-10-29 03:38:12 -0400320static struct dentry *nfs4_remote_referral_mount(struct file_system_type *fs_type,
321 int flags, const char *dev_name, void *raw_data);
David Howellsf7b422b2006-06-09 09:34:33 -0400322static void nfs4_kill_super(struct super_block *sb);
323
324static struct file_system_type nfs4_fs_type = {
325 .owner = THIS_MODULE,
326 .name = "nfs4",
327 .get_sb = nfs4_get_sb,
328 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700329 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400330};
331
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400332static struct file_system_type nfs4_remote_fs_type = {
333 .owner = THIS_MODULE,
334 .name = "nfs4",
Al Viro31f43472010-10-29 03:38:12 -0400335 .mount = nfs4_remote_mount,
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400336 .kill_sb = nfs4_kill_super,
337 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
338};
339
David Howells54ceac42006-08-22 20:06:13 -0400340struct file_system_type nfs4_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400341 .owner = THIS_MODULE,
342 .name = "nfs4",
Al Viro31f43472010-10-29 03:38:12 -0400343 .mount = nfs4_xdev_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400344 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700345 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400346};
347
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400348static struct file_system_type nfs4_remote_referral_fs_type = {
349 .owner = THIS_MODULE,
350 .name = "nfs4",
Al Viro31f43472010-10-29 03:38:12 -0400351 .mount = nfs4_remote_referral_mount,
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400352 .kill_sb = nfs4_kill_super,
353 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
354};
355
David Howells54ceac42006-08-22 20:06:13 -0400356struct file_system_type nfs4_referral_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400357 .owner = THIS_MODULE,
358 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400359 .get_sb = nfs4_referral_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400360 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700361 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400362};
363
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800364static const struct super_operations nfs4_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400365 .alloc_inode = nfs_alloc_inode,
366 .destroy_inode = nfs_destroy_inode,
367 .write_inode = nfs_write_inode,
Trond Myklebust387c1492010-02-03 08:27:35 -0500368 .put_super = nfs_put_super,
David Howellsf7b422b2006-06-09 09:34:33 -0400369 .statfs = nfs_statfs,
Al Virob57922d2010-06-07 14:34:48 -0400370 .evict_inode = nfs4_evict_inode,
David Howellsf7b422b2006-06-09 09:34:33 -0400371 .umount_begin = nfs_umount_begin,
372 .show_options = nfs_show_options,
Al Viroc7f404b2011-03-16 06:59:40 -0400373 .show_devname = nfs_show_devname,
374 .show_path = nfs_show_path,
David Howellsf7b422b2006-06-09 09:34:33 -0400375 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400376 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400377};
378#endif
379
Rusty Russell8e1f9362007-07-17 04:03:17 -0700380static struct shrinker acl_shrinker = {
381 .shrink = nfs_access_cache_shrinker,
382 .seeks = DEFAULT_SEEKS,
383};
Trond Myklebust979df722006-07-25 11:28:19 -0400384
David Howellsf7b422b2006-06-09 09:34:33 -0400385/*
386 * Register the NFS filesystems
387 */
388int __init register_nfs_fs(void)
389{
390 int ret;
391
392 ret = register_filesystem(&nfs_fs_type);
393 if (ret < 0)
394 goto error_0;
395
David Howellsf7b422b2006-06-09 09:34:33 -0400396 ret = nfs_register_sysctl();
397 if (ret < 0)
398 goto error_1;
Peter Zijlstra89a09142007-03-16 13:38:26 -0800399#ifdef CONFIG_NFS_V4
David Howellsf7b422b2006-06-09 09:34:33 -0400400 ret = register_filesystem(&nfs4_fs_type);
401 if (ret < 0)
402 goto error_2;
403#endif
Rusty Russell8e1f9362007-07-17 04:03:17 -0700404 register_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400405 return 0;
406
407#ifdef CONFIG_NFS_V4
408error_2:
409 nfs_unregister_sysctl();
Peter Zijlstra89a09142007-03-16 13:38:26 -0800410#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400411error_1:
412 unregister_filesystem(&nfs_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400413error_0:
414 return ret;
415}
416
417/*
418 * Unregister the NFS filesystems
419 */
420void __exit unregister_nfs_fs(void)
421{
Rusty Russell8e1f9362007-07-17 04:03:17 -0700422 unregister_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400423#ifdef CONFIG_NFS_V4
424 unregister_filesystem(&nfs4_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400425#endif
Alexey Dobriyan49af7ee2007-09-18 22:46:40 -0700426 nfs_unregister_sysctl();
David Howellsf7b422b2006-06-09 09:34:33 -0400427 unregister_filesystem(&nfs_fs_type);
428}
429
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400430void nfs_sb_active(struct super_block *sb)
Steve Dicksonef818a22007-11-08 04:05:04 -0500431{
432 struct nfs_server *server = NFS_SB(sb);
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400433
434 if (atomic_inc_return(&server->active) == 1)
435 atomic_inc(&sb->s_active);
436}
437
438void nfs_sb_deactive(struct super_block *sb)
439{
440 struct nfs_server *server = NFS_SB(sb);
441
442 if (atomic_dec_and_test(&server->active))
443 deactivate_super(sb);
Steve Dicksonef818a22007-11-08 04:05:04 -0500444}
445
David Howellsf7b422b2006-06-09 09:34:33 -0400446/*
447 * Deliver file system statistics to userspace
448 */
Trond Myklebust816724e2006-06-24 08:41:41 -0400449static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
David Howellsf7b422b2006-06-09 09:34:33 -0400450{
David Howells0c7d90c2006-08-22 20:06:10 -0400451 struct nfs_server *server = NFS_SB(dentry->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400452 unsigned char blockbits;
453 unsigned long blockres;
David Howells0c7d90c2006-08-22 20:06:10 -0400454 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400455 struct nfs_fsstat res;
456 int error = -ENOMEM;
457
458 res.fattr = nfs_alloc_fattr();
459 if (res.fattr == NULL)
460 goto out_err;
David Howellsf7b422b2006-06-09 09:34:33 -0400461
David Howells8fa5c002006-08-22 20:06:12 -0400462 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
Menyhart Zoltanfbf3fdd2010-09-12 19:55:26 -0400463 if (unlikely(error == -ESTALE)) {
464 struct dentry *pd_dentry;
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400465
Menyhart Zoltanfbf3fdd2010-09-12 19:55:26 -0400466 pd_dentry = dget_parent(dentry);
467 if (pd_dentry != NULL) {
468 nfs_zap_caches(pd_dentry->d_inode);
469 dput(pd_dentry);
470 }
471 }
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400472 nfs_free_fattr(res.fattr);
David Howellsf7b422b2006-06-09 09:34:33 -0400473 if (error < 0)
474 goto out_err;
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400475
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700476 buf->f_type = NFS_SUPER_MAGIC;
David Howellsf7b422b2006-06-09 09:34:33 -0400477
478 /*
479 * Current versions of glibc do not correctly handle the
480 * case where f_frsize != f_bsize. Eventually we want to
481 * report the value of wtmult in this field.
482 */
David Howells0c7d90c2006-08-22 20:06:10 -0400483 buf->f_frsize = dentry->d_sb->s_blocksize;
David Howellsf7b422b2006-06-09 09:34:33 -0400484
485 /*
486 * On most *nix systems, f_blocks, f_bfree, and f_bavail
487 * are reported in units of f_frsize. Linux hasn't had
488 * an f_frsize field in its statfs struct until recently,
489 * thus historically Linux's sys_statfs reports these
490 * fields in units of f_bsize.
491 */
David Howells0c7d90c2006-08-22 20:06:10 -0400492 buf->f_bsize = dentry->d_sb->s_blocksize;
493 blockbits = dentry->d_sb->s_blocksize_bits;
David Howellsf7b422b2006-06-09 09:34:33 -0400494 blockres = (1 << blockbits) - 1;
495 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
496 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
497 buf->f_bavail = (res.abytes + blockres) >> blockbits;
498
499 buf->f_files = res.tfiles;
500 buf->f_ffree = res.afiles;
501
502 buf->f_namelen = server->namelen;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700503
David Howellsf7b422b2006-06-09 09:34:33 -0400504 return 0;
505
506 out_err:
Harvey Harrison3110ff82008-05-02 13:42:44 -0700507 dprintk("%s: statfs error = %d\n", __func__, -error);
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700508 return error;
David Howellsf7b422b2006-06-09 09:34:33 -0400509}
510
David Howells7d4e2742006-08-22 20:06:07 -0400511/*
512 * Map the security flavour number to a name
513 */
Trond Myklebust81039f12006-06-09 09:34:34 -0400514static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
515{
David Howells7d4e2742006-08-22 20:06:07 -0400516 static const struct {
Trond Myklebust81039f12006-06-09 09:34:34 -0400517 rpc_authflavor_t flavour;
518 const char *str;
519 } sec_flavours[] = {
520 { RPC_AUTH_NULL, "null" },
521 { RPC_AUTH_UNIX, "sys" },
522 { RPC_AUTH_GSS_KRB5, "krb5" },
523 { RPC_AUTH_GSS_KRB5I, "krb5i" },
524 { RPC_AUTH_GSS_KRB5P, "krb5p" },
525 { RPC_AUTH_GSS_LKEY, "lkey" },
526 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
527 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
528 { RPC_AUTH_GSS_SPKM, "spkm" },
529 { RPC_AUTH_GSS_SPKMI, "spkmi" },
530 { RPC_AUTH_GSS_SPKMP, "spkmp" },
Chuck Lever4d81cd12007-07-01 12:12:40 -0400531 { UINT_MAX, "unknown" }
Trond Myklebust81039f12006-06-09 09:34:34 -0400532 };
533 int i;
534
Chuck Lever4d81cd12007-07-01 12:12:40 -0400535 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
Trond Myklebust81039f12006-06-09 09:34:34 -0400536 if (sec_flavours[i].flavour == flavour)
537 break;
538 }
539 return sec_flavours[i].str;
540}
541
Jeff Laytonee671b02009-12-03 15:58:56 -0500542static void nfs_show_mountd_netid(struct seq_file *m, struct nfs_server *nfss,
543 int showdefaults)
544{
545 struct sockaddr *sap = (struct sockaddr *) &nfss->mountd_address;
546
547 seq_printf(m, ",mountproto=");
548 switch (sap->sa_family) {
549 case AF_INET:
550 switch (nfss->mountd_protocol) {
551 case IPPROTO_UDP:
552 seq_printf(m, RPCBIND_NETID_UDP);
553 break;
554 case IPPROTO_TCP:
555 seq_printf(m, RPCBIND_NETID_TCP);
556 break;
557 default:
558 if (showdefaults)
559 seq_printf(m, "auto");
560 }
561 break;
562 case AF_INET6:
563 switch (nfss->mountd_protocol) {
564 case IPPROTO_UDP:
565 seq_printf(m, RPCBIND_NETID_UDP6);
566 break;
567 case IPPROTO_TCP:
568 seq_printf(m, RPCBIND_NETID_TCP6);
569 break;
570 default:
571 if (showdefaults)
572 seq_printf(m, "auto");
573 }
574 break;
575 default:
576 if (showdefaults)
577 seq_printf(m, "auto");
578 }
579}
580
Chuck Lever82d101d2008-03-14 14:10:37 -0400581static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
582 int showdefaults)
583{
584 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
585
Bryan Schumakerd5eff1a2010-08-03 13:04:00 -0400586 if (nfss->flags & NFS_MOUNT_LEGACY_INTERFACE)
587 return;
588
Chuck Lever82d101d2008-03-14 14:10:37 -0400589 switch (sap->sa_family) {
590 case AF_INET: {
591 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
Harvey Harrisonbe859402008-10-31 00:56:28 -0700592 seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400593 break;
594 }
595 case AF_INET6: {
596 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
Chuck Leverd250e192009-12-03 15:58:56 -0500597 seq_printf(m, ",mountaddr=%pI6c", &sin6->sin6_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400598 break;
599 }
600 default:
601 if (showdefaults)
602 seq_printf(m, ",mountaddr=unspecified");
603 }
604
605 if (nfss->mountd_version || showdefaults)
606 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
Stanislav Kinsburskyaa699472010-12-08 12:40:13 +0300607 if ((nfss->mountd_port &&
608 nfss->mountd_port != (unsigned short)NFS_UNSPEC_PORT) ||
609 showdefaults)
Chuck Lever82d101d2008-03-14 14:10:37 -0400610 seq_printf(m, ",mountport=%u", nfss->mountd_port);
611
Jeff Laytonee671b02009-12-03 15:58:56 -0500612 nfs_show_mountd_netid(m, nfss, showdefaults);
Chuck Lever82d101d2008-03-14 14:10:37 -0400613}
614
Trond Myklebust0be81892010-06-18 12:23:58 -0400615#ifdef CONFIG_NFS_V4
616static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
617 int showdefaults)
618{
619 struct nfs_client *clp = nfss->nfs_client;
620
621 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
622 seq_printf(m, ",minorversion=%u", clp->cl_minorversion);
623}
624#else
625static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
626 int showdefaults)
627{
628}
629#endif
630
David Howellsf7b422b2006-06-09 09:34:33 -0400631/*
632 * Describe the mount options in force on this server representation
633 */
Chuck Lever82d101d2008-03-14 14:10:37 -0400634static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
635 int showdefaults)
David Howellsf7b422b2006-06-09 09:34:33 -0400636{
David Howells509de812006-08-22 20:06:11 -0400637 static const struct proc_nfs_info {
David Howellsf7b422b2006-06-09 09:34:33 -0400638 int flag;
David Howells509de812006-08-22 20:06:11 -0400639 const char *str;
640 const char *nostr;
David Howellsf7b422b2006-06-09 09:34:33 -0400641 } nfs_info[] = {
642 { NFS_MOUNT_SOFT, ",soft", ",hard" },
Chuck Lever82d101d2008-03-14 14:10:37 -0400643 { NFS_MOUNT_POSIX, ",posix", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400644 { NFS_MOUNT_NOCTO, ",nocto", "" },
645 { NFS_MOUNT_NOAC, ",noac", "" },
646 { NFS_MOUNT_NONLM, ",nolock", "" },
647 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400648 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
Chuck Leverd7403512008-12-23 15:21:37 -0500649 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
650 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400651 { 0, NULL, NULL }
652 };
David Howells509de812006-08-22 20:06:11 -0400653 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400654 struct nfs_client *clp = nfss->nfs_client;
Chuck Lever82d101d2008-03-14 14:10:37 -0400655 u32 version = clp->rpc_ops->version;
Suresh Jayaraman7c563cc2010-09-23 14:26:48 -0400656 int local_flock, local_fcntl;
David Howellsf7b422b2006-06-09 09:34:33 -0400657
Chuck Lever82d101d2008-03-14 14:10:37 -0400658 seq_printf(m, ",vers=%u", version);
Chuck Lever2d767432008-03-14 14:10:08 -0400659 seq_printf(m, ",rsize=%u", nfss->rsize);
660 seq_printf(m, ",wsize=%u", nfss->wsize);
Chuck Lever82d101d2008-03-14 14:10:37 -0400661 if (nfss->bsize != 0)
662 seq_printf(m, ",bsize=%u", nfss->bsize);
663 seq_printf(m, ",namlen=%u", nfss->namelen);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400664 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400665 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400666 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400667 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400668 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400669 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400670 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400671 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
David Howellsf7b422b2006-06-09 09:34:33 -0400672 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
673 if (nfss->flags & nfs_infop->flag)
674 seq_puts(m, nfs_infop->str);
675 else
676 seq_puts(m, nfs_infop->nostr);
677 }
\"Talpey, Thomas\56928ed2007-09-10 13:48:47 -0400678 seq_printf(m, ",proto=%s",
Jeff Laytonee671b02009-12-03 15:58:56 -0500679 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
Chuck Lever82d101d2008-03-14 14:10:37 -0400680 if (version == 4) {
681 if (nfss->port != NFS_PORT)
682 seq_printf(m, ",port=%u", nfss->port);
683 } else
684 if (nfss->port)
685 seq_printf(m, ",port=%u", nfss->port);
686
Trond Myklebust33170232007-12-20 16:03:59 -0500687 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
688 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
Trond Myklebust81039f12006-06-09 09:34:34 -0400689 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
Chuck Lever82d101d2008-03-14 14:10:37 -0400690
691 if (version != 4)
692 nfs_show_mountd_options(m, nfss, showdefaults);
Trond Myklebust0be81892010-06-18 12:23:58 -0400693 else
694 nfs_show_nfsv4_options(m, nfss, showdefaults);
Chuck Lever82d101d2008-03-14 14:10:37 -0400695
David Howellsb797cac2009-04-03 16:42:48 +0100696 if (nfss->options & NFS_OPTION_FSCACHE)
697 seq_printf(m, ",fsc");
Patrick J. LoPresti9b00c642010-08-10 17:28:01 -0400698
699 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONEG) {
700 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONE)
701 seq_printf(m, ",lookupcache=none");
702 else
703 seq_printf(m, ",lookupcache=pos");
704 }
Suresh Jayaraman7c563cc2010-09-23 14:26:48 -0400705
706 local_flock = nfss->flags & NFS_MOUNT_LOCAL_FLOCK;
707 local_fcntl = nfss->flags & NFS_MOUNT_LOCAL_FCNTL;
708
709 if (!local_flock && !local_fcntl)
710 seq_printf(m, ",local_lock=none");
711 else if (local_flock && local_fcntl)
712 seq_printf(m, ",local_lock=all");
713 else if (local_flock)
714 seq_printf(m, ",local_lock=flock");
715 else
716 seq_printf(m, ",local_lock=posix");
David Howellsf7b422b2006-06-09 09:34:33 -0400717}
718
719/*
720 * Describe the mount options on this VFS mountpoint
721 */
722static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
723{
724 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
725
726 nfs_show_mount_options(m, nfss, 0);
727
Chuck Lever5d8515c2007-12-10 14:57:16 -0500728 seq_printf(m, ",addr=%s",
729 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
730 RPC_DISPLAY_ADDR));
David Howellsf7b422b2006-06-09 09:34:33 -0400731
732 return 0;
733}
734
Al Viroc7f404b2011-03-16 06:59:40 -0400735static int nfs_show_devname(struct seq_file *m, struct vfsmount *mnt)
736{
737 char *page = (char *) __get_free_page(GFP_KERNEL);
738 char *devname, *dummy;
739 int err = 0;
740 if (!page)
741 return -ENOMEM;
742 devname = nfs_path(&dummy, mnt->mnt_root, page, PAGE_SIZE);
743 if (IS_ERR(devname))
744 err = PTR_ERR(devname);
745 else
746 seq_escape(m, devname, " \t\n\\");
747 free_page((unsigned long)page);
748 return err;
749}
750
751static int nfs_show_path(struct seq_file *m, struct vfsmount *mnt)
752{
753 seq_puts(m, "/");
754 return 0;
755}
756
David Howellsf7b422b2006-06-09 09:34:33 -0400757/*
758 * Present statistical information for this VFS mountpoint
759 */
760static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
761{
762 int i, cpu;
763 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
764 struct rpc_auth *auth = nfss->client->cl_auth;
765 struct nfs_iostats totals = { };
766
767 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
768
769 /*
770 * Display all mount option settings
771 */
772 seq_printf(m, "\n\topts:\t");
773 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
774 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
775 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
776 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
777 nfs_show_mount_options(m, nfss, 1);
778
779 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
780
781 seq_printf(m, "\n\tcaps:\t");
782 seq_printf(m, "caps=0x%x", nfss->caps);
Chuck Lever2d767432008-03-14 14:10:08 -0400783 seq_printf(m, ",wtmult=%u", nfss->wtmult);
784 seq_printf(m, ",dtsize=%u", nfss->dtsize);
785 seq_printf(m, ",bsize=%u", nfss->bsize);
786 seq_printf(m, ",namlen=%u", nfss->namelen);
David Howellsf7b422b2006-06-09 09:34:33 -0400787
788#ifdef CONFIG_NFS_V4
Trond Myklebust40c553192007-12-14 14:56:07 -0500789 if (nfss->nfs_client->rpc_ops->version == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400790 seq_printf(m, "\n\tnfsv4:\t");
791 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
792 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
793 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
794 }
795#endif
796
797 /*
798 * Display security flavor in effect for this mount
799 */
Chuck Lever2d767432008-03-14 14:10:08 -0400800 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400801 if (auth->au_flavor)
Chuck Lever2d767432008-03-14 14:10:08 -0400802 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400803
804 /*
805 * Display superblock I/O counters
806 */
807 for_each_possible_cpu(cpu) {
808 struct nfs_iostats *stats;
809
810 preempt_disable();
811 stats = per_cpu_ptr(nfss->io_stats, cpu);
812
813 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
814 totals.events[i] += stats->events[i];
815 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
816 totals.bytes[i] += stats->bytes[i];
David Howells6a510912009-04-03 16:42:43 +0100817#ifdef CONFIG_NFS_FSCACHE
818 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
819 totals.fscache[i] += stats->fscache[i];
820#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400821
822 preempt_enable();
823 }
824
825 seq_printf(m, "\n\tevents:\t");
826 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
827 seq_printf(m, "%lu ", totals.events[i]);
828 seq_printf(m, "\n\tbytes:\t");
829 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
830 seq_printf(m, "%Lu ", totals.bytes[i]);
David Howells6a510912009-04-03 16:42:43 +0100831#ifdef CONFIG_NFS_FSCACHE
832 if (nfss->options & NFS_OPTION_FSCACHE) {
833 seq_printf(m, "\n\tfsc:\t");
834 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
835 seq_printf(m, "%Lu ", totals.bytes[i]);
836 }
837#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400838 seq_printf(m, "\n");
839
840 rpc_print_iostats(m, nfss->client);
841
842 return 0;
843}
844
845/*
846 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400847 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400848 */
Al Viro42faad92008-04-24 07:21:56 -0400849static void nfs_umount_begin(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -0400850{
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200851 struct nfs_server *server;
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400852 struct rpc_clnt *rpc;
853
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200854 server = NFS_SB(sb);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400855 /* -EIO all pending I/O */
856 rpc = server->client_acl;
857 if (!IS_ERR(rpc))
858 rpc_killall_tasks(rpc);
859 rpc = server->client;
860 if (!IS_ERR(rpc))
861 rpc_killall_tasks(rpc);
David Howellsf7b422b2006-06-09 09:34:33 -0400862}
863
Trond Myklebustc5811db2009-10-06 15:40:15 -0400864static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(unsigned int version)
Chuck Lever9423a082009-09-23 14:36:38 -0400865{
866 struct nfs_parsed_mount_data *data;
867
868 data = kzalloc(sizeof(*data), GFP_KERNEL);
869 if (data) {
Chuck Lever9423a082009-09-23 14:36:38 -0400870 data->acregmin = NFS_DEF_ACREGMIN;
871 data->acregmax = NFS_DEF_ACREGMAX;
872 data->acdirmin = NFS_DEF_ACDIRMIN;
873 data->acdirmax = NFS_DEF_ACDIRMAX;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400874 data->mount_server.port = NFS_UNSPEC_PORT;
Chuck Lever9423a082009-09-23 14:36:38 -0400875 data->nfs_server.port = NFS_UNSPEC_PORT;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400876 data->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Lever9423a082009-09-23 14:36:38 -0400877 data->auth_flavors[0] = RPC_AUTH_UNIX;
878 data->auth_flavor_len = 1;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400879 data->version = version;
Chuck Lever9423a082009-09-23 14:36:38 -0400880 data->minorversion = 0;
881 }
882 return data;
883}
884
David Howellsf7b422b2006-06-09 09:34:33 -0400885/*
Chuck Levercdcd7f92007-12-10 14:57:45 -0500886 * Sanity-check a server address provided by the mount command.
887 *
888 * Address family must be initialized, and address must not be
889 * the ANY address for that family.
Chuck Leverfc50d582007-07-01 12:12:46 -0400890 */
891static int nfs_verify_server_address(struct sockaddr *addr)
892{
893 switch (addr->sa_family) {
894 case AF_INET: {
Chuck Levercdcd7f92007-12-10 14:57:45 -0500895 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
Al Viroe6f1ceb2008-03-17 22:44:53 -0700896 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
Chuck Levercdcd7f92007-12-10 14:57:45 -0500897 }
898 case AF_INET6: {
899 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
900 return !ipv6_addr_any(sa);
Chuck Leverfc50d582007-07-01 12:12:46 -0400901 }
902 }
903
Chuck Lever53a0b9c2009-08-09 15:09:36 -0400904 dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
Chuck Leverfc50d582007-07-01 12:12:46 -0400905 return 0;
906}
907
Chuck Lever9412b922007-12-10 14:59:21 -0500908/*
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400909 * Select between a default port value and a user-specified port value.
910 * If a zero value is set, then autobind will be used.
911 */
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400912static void nfs_set_port(struct sockaddr *sap, int *port,
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400913 const unsigned short default_port)
914{
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400915 if (*port == NFS_UNSPEC_PORT)
916 *port = default_port;
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400917
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400918 rpc_set_port(sap, *port);
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400919}
920
921/*
Trond Myklebust259875e2008-07-02 14:43:47 -0400922 * Sanity check the NFS transport protocol.
923 *
924 */
925static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
926{
927 switch (mnt->nfs_server.protocol) {
928 case XPRT_TRANSPORT_UDP:
929 case XPRT_TRANSPORT_TCP:
930 case XPRT_TRANSPORT_RDMA:
931 break;
932 default:
933 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
934 }
935}
936
937/*
938 * For text based NFSv2/v3 mounts, the mount protocol transport default
939 * settings should depend upon the specified NFS transport.
940 */
941static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
942{
943 nfs_validate_transport_protocol(mnt);
944
945 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
946 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
947 return;
948 switch (mnt->nfs_server.protocol) {
949 case XPRT_TRANSPORT_UDP:
950 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
951 break;
952 case XPRT_TRANSPORT_TCP:
953 case XPRT_TRANSPORT_RDMA:
954 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
955 }
956}
957
958/*
Chuck Lever01060c82008-06-24 16:33:38 -0400959 * Parse the value of the 'sec=' option.
Chuck Lever01060c82008-06-24 16:33:38 -0400960 */
961static int nfs_parse_security_flavors(char *value,
962 struct nfs_parsed_mount_data *mnt)
963{
964 substring_t args[MAX_OPT_ARGS];
965
966 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
967
968 switch (match_token(value, nfs_secflavor_tokens, args)) {
969 case Opt_sec_none:
Chuck Lever01060c82008-06-24 16:33:38 -0400970 mnt->auth_flavors[0] = RPC_AUTH_NULL;
971 break;
972 case Opt_sec_sys:
Chuck Lever01060c82008-06-24 16:33:38 -0400973 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
974 break;
975 case Opt_sec_krb5:
Chuck Lever01060c82008-06-24 16:33:38 -0400976 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
977 break;
978 case Opt_sec_krb5i:
Chuck Lever01060c82008-06-24 16:33:38 -0400979 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
980 break;
981 case Opt_sec_krb5p:
Chuck Lever01060c82008-06-24 16:33:38 -0400982 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
983 break;
984 case Opt_sec_lkey:
Chuck Lever01060c82008-06-24 16:33:38 -0400985 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
986 break;
987 case Opt_sec_lkeyi:
Chuck Lever01060c82008-06-24 16:33:38 -0400988 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
989 break;
990 case Opt_sec_lkeyp:
Chuck Lever01060c82008-06-24 16:33:38 -0400991 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
992 break;
993 case Opt_sec_spkm:
Chuck Lever01060c82008-06-24 16:33:38 -0400994 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
995 break;
996 case Opt_sec_spkmi:
Chuck Lever01060c82008-06-24 16:33:38 -0400997 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
998 break;
999 case Opt_sec_spkmp:
Chuck Lever01060c82008-06-24 16:33:38 -04001000 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
1001 break;
1002 default:
1003 return 0;
1004 }
1005
Chuck Lever059f90b2009-08-09 15:09:31 -04001006 mnt->auth_flavor_len = 1;
Chuck Lever01060c82008-06-24 16:33:38 -04001007 return 1;
1008}
1009
1010/*
Chuck Leverbf0fd762007-07-01 12:13:44 -04001011 * Error-check and convert a string of mount options from user space into
Chuck Leverf45663c2008-06-24 19:28:02 -04001012 * a data structure. The whole mount string is processed; bad options are
1013 * skipped as they are encountered. If there were no errors, return 1;
1014 * otherwise return 0 (zero).
Chuck Leverbf0fd762007-07-01 12:13:44 -04001015 */
1016static int nfs_parse_mount_options(char *raw,
1017 struct nfs_parsed_mount_data *mnt)
1018{
Eric Parisf9c3a382008-03-05 14:20:18 -05001019 char *p, *string, *secdata;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001020 int rc, sloppy = 0, invalid_option = 0;
Jeff Laytonee671b02009-12-03 15:58:56 -05001021 unsigned short protofamily = AF_UNSPEC;
1022 unsigned short mountfamily = AF_UNSPEC;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001023
1024 if (!raw) {
1025 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
1026 return 1;
1027 }
1028 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
1029
Eric Parisf9c3a382008-03-05 14:20:18 -05001030 secdata = alloc_secdata();
1031 if (!secdata)
1032 goto out_nomem;
1033
1034 rc = security_sb_copy_data(raw, secdata);
1035 if (rc)
1036 goto out_security_failure;
1037
1038 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
1039 if (rc)
1040 goto out_security_failure;
1041
1042 free_secdata(secdata);
1043
Chuck Leverbf0fd762007-07-01 12:13:44 -04001044 while ((p = strsep(&raw, ",")) != NULL) {
1045 substring_t args[MAX_OPT_ARGS];
Chuck Levera5a16ba2009-06-17 18:02:14 -07001046 unsigned long option;
1047 int token;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001048
1049 if (!*p)
1050 continue;
1051
1052 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
1053
1054 token = match_token(p, nfs_mount_option_tokens, args);
1055 switch (token) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001056
1057 /*
1058 * boolean options: foo/nofoo
1059 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001060 case Opt_soft:
1061 mnt->flags |= NFS_MOUNT_SOFT;
1062 break;
1063 case Opt_hard:
1064 mnt->flags &= ~NFS_MOUNT_SOFT;
1065 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001066 case Opt_posix:
1067 mnt->flags |= NFS_MOUNT_POSIX;
1068 break;
1069 case Opt_noposix:
1070 mnt->flags &= ~NFS_MOUNT_POSIX;
1071 break;
1072 case Opt_cto:
1073 mnt->flags &= ~NFS_MOUNT_NOCTO;
1074 break;
1075 case Opt_nocto:
1076 mnt->flags |= NFS_MOUNT_NOCTO;
1077 break;
1078 case Opt_ac:
1079 mnt->flags &= ~NFS_MOUNT_NOAC;
1080 break;
1081 case Opt_noac:
1082 mnt->flags |= NFS_MOUNT_NOAC;
1083 break;
1084 case Opt_lock:
1085 mnt->flags &= ~NFS_MOUNT_NONLM;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001086 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1087 NFS_MOUNT_LOCAL_FCNTL);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001088 break;
1089 case Opt_nolock:
1090 mnt->flags |= NFS_MOUNT_NONLM;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001091 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1092 NFS_MOUNT_LOCAL_FCNTL);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001093 break;
1094 case Opt_v2:
1095 mnt->flags &= ~NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -04001096 mnt->version = 2;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001097 break;
1098 case Opt_v3:
1099 mnt->flags |= NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -04001100 mnt->version = 3;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001101 break;
Chuck Lever764302c2009-09-08 19:50:03 -04001102 case Opt_v4:
1103 mnt->flags &= ~NFS_MOUNT_VER3;
1104 mnt->version = 4;
1105 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001106 case Opt_udp:
1107 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001108 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001109 break;
1110 case Opt_tcp:
1111 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001112 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001113 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001114 case Opt_rdma:
1115 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1116 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001117 xprt_load_transport(p);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001118 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001119 case Opt_acl:
1120 mnt->flags &= ~NFS_MOUNT_NOACL;
1121 break;
1122 case Opt_noacl:
1123 mnt->flags |= NFS_MOUNT_NOACL;
1124 break;
1125 case Opt_rdirplus:
1126 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1127 break;
1128 case Opt_nordirplus:
1129 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1130 break;
Trond Myklebust75180df2007-05-16 16:53:28 -04001131 case Opt_sharecache:
1132 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1133 break;
1134 case Opt_nosharecache:
1135 mnt->flags |= NFS_MOUNT_UNSHARED;
1136 break;
Chuck Leverd7403512008-12-23 15:21:37 -05001137 case Opt_resvport:
1138 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1139 break;
1140 case Opt_noresvport:
1141 mnt->flags |= NFS_MOUNT_NORESVPORT;
1142 break;
David Howellsb797cac2009-04-03 16:42:48 +01001143 case Opt_fscache:
1144 mnt->options |= NFS_OPTION_FSCACHE;
1145 kfree(mnt->fscache_uniq);
1146 mnt->fscache_uniq = NULL;
1147 break;
1148 case Opt_nofscache:
1149 mnt->options &= ~NFS_OPTION_FSCACHE;
1150 kfree(mnt->fscache_uniq);
1151 mnt->fscache_uniq = NULL;
1152 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001153
Chuck Leverf45663c2008-06-24 19:28:02 -04001154 /*
1155 * options that take numeric values
1156 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001157 case Opt_port:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001158 string = match_strdup(args);
1159 if (string == NULL)
1160 goto out_nomem;
1161 rc = strict_strtoul(string, 10, &option);
1162 kfree(string);
Alexey Dobriyan4be929b2010-05-24 14:33:03 -07001163 if (rc != 0 || option > USHRT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001164 goto out_invalid_value;
1165 mnt->nfs_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001166 break;
1167 case Opt_rsize:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001168 string = match_strdup(args);
1169 if (string == NULL)
1170 goto out_nomem;
1171 rc = strict_strtoul(string, 10, &option);
1172 kfree(string);
1173 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001174 goto out_invalid_value;
1175 mnt->rsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001176 break;
1177 case Opt_wsize:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001178 string = match_strdup(args);
1179 if (string == NULL)
1180 goto out_nomem;
1181 rc = strict_strtoul(string, 10, &option);
1182 kfree(string);
1183 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001184 goto out_invalid_value;
1185 mnt->wsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001186 break;
1187 case Opt_bsize:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001188 string = match_strdup(args);
1189 if (string == NULL)
1190 goto out_nomem;
1191 rc = strict_strtoul(string, 10, &option);
1192 kfree(string);
1193 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001194 goto out_invalid_value;
1195 mnt->bsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001196 break;
1197 case Opt_timeo:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001198 string = match_strdup(args);
1199 if (string == NULL)
1200 goto out_nomem;
1201 rc = strict_strtoul(string, 10, &option);
1202 kfree(string);
1203 if (rc != 0 || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001204 goto out_invalid_value;
1205 mnt->timeo = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001206 break;
1207 case Opt_retrans:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001208 string = match_strdup(args);
1209 if (string == NULL)
1210 goto out_nomem;
1211 rc = strict_strtoul(string, 10, &option);
1212 kfree(string);
1213 if (rc != 0 || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001214 goto out_invalid_value;
1215 mnt->retrans = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001216 break;
1217 case Opt_acregmin:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001218 string = match_strdup(args);
1219 if (string == NULL)
1220 goto out_nomem;
1221 rc = strict_strtoul(string, 10, &option);
1222 kfree(string);
1223 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001224 goto out_invalid_value;
1225 mnt->acregmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001226 break;
1227 case Opt_acregmax:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001228 string = match_strdup(args);
1229 if (string == NULL)
1230 goto out_nomem;
1231 rc = strict_strtoul(string, 10, &option);
1232 kfree(string);
1233 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001234 goto out_invalid_value;
1235 mnt->acregmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001236 break;
1237 case Opt_acdirmin:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001238 string = match_strdup(args);
1239 if (string == NULL)
1240 goto out_nomem;
1241 rc = strict_strtoul(string, 10, &option);
1242 kfree(string);
1243 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001244 goto out_invalid_value;
1245 mnt->acdirmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001246 break;
1247 case Opt_acdirmax:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001248 string = match_strdup(args);
1249 if (string == NULL)
1250 goto out_nomem;
1251 rc = strict_strtoul(string, 10, &option);
1252 kfree(string);
1253 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001254 goto out_invalid_value;
1255 mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001256 break;
1257 case Opt_actimeo:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001258 string = match_strdup(args);
1259 if (string == NULL)
1260 goto out_nomem;
1261 rc = strict_strtoul(string, 10, &option);
1262 kfree(string);
1263 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001264 goto out_invalid_value;
1265 mnt->acregmin = mnt->acregmax =
1266 mnt->acdirmin = mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001267 break;
1268 case Opt_namelen:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001269 string = match_strdup(args);
1270 if (string == NULL)
1271 goto out_nomem;
1272 rc = strict_strtoul(string, 10, &option);
1273 kfree(string);
1274 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001275 goto out_invalid_value;
1276 mnt->namlen = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001277 break;
1278 case Opt_mountport:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001279 string = match_strdup(args);
1280 if (string == NULL)
1281 goto out_nomem;
1282 rc = strict_strtoul(string, 10, &option);
1283 kfree(string);
Alexey Dobriyan4be929b2010-05-24 14:33:03 -07001284 if (rc != 0 || option > USHRT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001285 goto out_invalid_value;
1286 mnt->mount_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001287 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001288 case Opt_mountvers:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001289 string = match_strdup(args);
1290 if (string == NULL)
1291 goto out_nomem;
1292 rc = strict_strtoul(string, 10, &option);
1293 kfree(string);
1294 if (rc != 0 ||
Chuck Leverf45663c2008-06-24 19:28:02 -04001295 option < NFS_MNT_VERSION ||
Chuck Leverd23c45f2009-06-17 18:02:13 -07001296 option > NFS_MNT3_VERSION)
1297 goto out_invalid_value;
1298 mnt->mount_server.version = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001299 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001300 case Opt_nfsvers:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001301 string = match_strdup(args);
1302 if (string == NULL)
1303 goto out_nomem;
1304 rc = strict_strtoul(string, 10, &option);
1305 kfree(string);
1306 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001307 goto out_invalid_value;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001308 switch (option) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001309 case NFS2_VERSION:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001310 mnt->flags &= ~NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -04001311 mnt->version = 2;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001312 break;
Chuck Leverf45663c2008-06-24 19:28:02 -04001313 case NFS3_VERSION:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001314 mnt->flags |= NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -04001315 mnt->version = 3;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001316 break;
Chuck Lever764302c2009-09-08 19:50:03 -04001317 case NFS4_VERSION:
1318 mnt->flags &= ~NFS_MOUNT_VER3;
1319 mnt->version = 4;
1320 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001321 default:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001322 goto out_invalid_value;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001323 }
1324 break;
Mike Sager3fd5be92009-04-01 09:21:48 -04001325 case Opt_minorversion:
Chuck Leverf3f4f4e2009-08-09 15:09:29 -04001326 string = match_strdup(args);
1327 if (string == NULL)
1328 goto out_nomem;
1329 rc = strict_strtoul(string, 10, &option);
1330 kfree(string);
1331 if (rc != 0)
1332 goto out_invalid_value;
1333 if (option > NFS4_MAX_MINOR_VERSION)
1334 goto out_invalid_value;
1335 mnt->minorversion = option;
Mike Sager3fd5be92009-04-01 09:21:48 -04001336 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001337
Chuck Leverf45663c2008-06-24 19:28:02 -04001338 /*
1339 * options that take text values
1340 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001341 case Opt_sec:
1342 string = match_strdup(args);
1343 if (string == NULL)
1344 goto out_nomem;
Chuck Lever01060c82008-06-24 16:33:38 -04001345 rc = nfs_parse_security_flavors(string, mnt);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001346 kfree(string);
Chuck Leverf45663c2008-06-24 19:28:02 -04001347 if (!rc) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001348 dfprintk(MOUNT, "NFS: unrecognized "
1349 "security flavor\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001350 return 0;
Chuck Leverf45663c2008-06-24 19:28:02 -04001351 }
Chuck Leverbf0fd762007-07-01 12:13:44 -04001352 break;
1353 case Opt_proto:
1354 string = match_strdup(args);
1355 if (string == NULL)
1356 goto out_nomem;
1357 token = match_token(string,
1358 nfs_xprt_protocol_tokens, args);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001359
Jeff Laytonee671b02009-12-03 15:58:56 -05001360 protofamily = AF_INET;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001361 switch (token) {
Jeff Laytonee671b02009-12-03 15:58:56 -05001362 case Opt_xprt_udp6:
1363 protofamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001364 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001365 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001366 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001367 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001368 break;
Jeff Laytonee671b02009-12-03 15:58:56 -05001369 case Opt_xprt_tcp6:
1370 protofamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001371 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001372 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001373 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001374 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001375 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001376 case Opt_xprt_rdma:
1377 /* vector side protocols to TCP */
1378 mnt->flags |= NFS_MOUNT_TCP;
1379 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001380 xprt_load_transport(string);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001381 kfree(string);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001382 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001383 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001384 dfprintk(MOUNT, "NFS: unrecognized "
1385 "transport protocol\n");
Yinghai Lu4223a4a2009-10-20 14:13:46 +09001386 kfree(string);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001387 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001388 }
1389 break;
1390 case Opt_mountproto:
1391 string = match_strdup(args);
1392 if (string == NULL)
1393 goto out_nomem;
1394 token = match_token(string,
1395 nfs_xprt_protocol_tokens, args);
Trond Myklebustd508afb2009-04-06 16:41:35 -07001396 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001397
Jeff Laytonee671b02009-12-03 15:58:56 -05001398 mountfamily = AF_INET;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001399 switch (token) {
Jeff Laytonee671b02009-12-03 15:58:56 -05001400 case Opt_xprt_udp6:
1401 mountfamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001402 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001403 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001404 break;
Jeff Laytonee671b02009-12-03 15:58:56 -05001405 case Opt_xprt_tcp6:
1406 mountfamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001407 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001408 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001409 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001410 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001411 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001412 dfprintk(MOUNT, "NFS: unrecognized "
1413 "transport protocol\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001414 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001415 }
1416 break;
1417 case Opt_addr:
1418 string = match_strdup(args);
1419 if (string == NULL)
1420 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001421 mnt->nfs_server.addrlen =
1422 rpc_pton(string, strlen(string),
1423 (struct sockaddr *)
1424 &mnt->nfs_server.address,
1425 sizeof(mnt->nfs_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001426 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001427 if (mnt->nfs_server.addrlen == 0)
1428 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001429 break;
1430 case Opt_clientaddr:
1431 string = match_strdup(args);
1432 if (string == NULL)
1433 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001434 kfree(mnt->client_address);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001435 mnt->client_address = string;
1436 break;
Chuck Lever33832032007-12-10 14:59:13 -05001437 case Opt_mounthost:
1438 string = match_strdup(args);
1439 if (string == NULL)
1440 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001441 kfree(mnt->mount_server.hostname);
Chuck Lever33832032007-12-10 14:59:13 -05001442 mnt->mount_server.hostname = string;
1443 break;
Chuck Lever0ac83772007-09-11 18:01:04 -04001444 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001445 string = match_strdup(args);
1446 if (string == NULL)
1447 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001448 mnt->mount_server.addrlen =
1449 rpc_pton(string, strlen(string),
1450 (struct sockaddr *)
1451 &mnt->mount_server.address,
1452 sizeof(mnt->mount_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001453 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001454 if (mnt->mount_server.addrlen == 0)
1455 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001456 break;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001457 case Opt_lookupcache:
1458 string = match_strdup(args);
1459 if (string == NULL)
1460 goto out_nomem;
1461 token = match_token(string,
1462 nfs_lookupcache_tokens, args);
1463 kfree(string);
1464 switch (token) {
1465 case Opt_lookupcache_all:
1466 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1467 break;
1468 case Opt_lookupcache_positive:
1469 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1470 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1471 break;
1472 case Opt_lookupcache_none:
1473 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1474 break;
1475 default:
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001476 dfprintk(MOUNT, "NFS: invalid "
1477 "lookupcache argument\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001478 return 0;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001479 };
1480 break;
Chuck Levera6d5ff62010-05-07 13:33:58 -04001481 case Opt_fscache_uniq:
1482 string = match_strdup(args);
1483 if (string == NULL)
1484 goto out_nomem;
1485 kfree(mnt->fscache_uniq);
1486 mnt->fscache_uniq = string;
1487 mnt->options |= NFS_OPTION_FSCACHE;
1488 break;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001489 case Opt_local_lock:
1490 string = match_strdup(args);
1491 if (string == NULL)
1492 goto out_nomem;
1493 token = match_token(string, nfs_local_lock_tokens,
1494 args);
1495 kfree(string);
1496 switch (token) {
1497 case Opt_local_lock_all:
1498 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1499 NFS_MOUNT_LOCAL_FCNTL);
1500 break;
1501 case Opt_local_lock_flock:
1502 mnt->flags |= NFS_MOUNT_LOCAL_FLOCK;
1503 break;
1504 case Opt_local_lock_posix:
1505 mnt->flags |= NFS_MOUNT_LOCAL_FCNTL;
1506 break;
1507 case Opt_local_lock_none:
1508 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1509 NFS_MOUNT_LOCAL_FCNTL);
1510 break;
1511 default:
1512 dfprintk(MOUNT, "NFS: invalid "
1513 "local_lock argument\n");
1514 return 0;
1515 };
1516 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001517
Chuck Leverf45663c2008-06-24 19:28:02 -04001518 /*
1519 * Special options
1520 */
1521 case Opt_sloppy:
1522 sloppy = 1;
1523 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1524 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001525 case Opt_userspace:
1526 case Opt_deprecated:
Chuck Leverd33e4df2008-06-12 12:37:41 -04001527 dfprintk(MOUNT, "NFS: ignoring mount option "
1528 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001529 break;
1530
1531 default:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001532 invalid_option = 1;
Chuck Leverf45663c2008-06-24 19:28:02 -04001533 dfprintk(MOUNT, "NFS: unrecognized mount option "
1534 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001535 }
1536 }
1537
Chuck Leverd23c45f2009-06-17 18:02:13 -07001538 if (!sloppy && invalid_option)
1539 return 0;
1540
Jeff Laytonee671b02009-12-03 15:58:56 -05001541 /*
1542 * verify that any proto=/mountproto= options match the address
1543 * familiies in the addr=/mountaddr= options.
1544 */
1545 if (protofamily != AF_UNSPEC &&
1546 protofamily != mnt->nfs_server.address.ss_family)
1547 goto out_proto_mismatch;
1548
1549 if (mountfamily != AF_UNSPEC) {
1550 if (mnt->mount_server.addrlen) {
1551 if (mountfamily != mnt->mount_server.address.ss_family)
1552 goto out_mountproto_mismatch;
1553 } else {
1554 if (mountfamily != mnt->nfs_server.address.ss_family)
1555 goto out_mountproto_mismatch;
1556 }
1557 }
1558
Chuck Leverbf0fd762007-07-01 12:13:44 -04001559 return 1;
1560
Jeff Laytonee671b02009-12-03 15:58:56 -05001561out_mountproto_mismatch:
1562 printk(KERN_INFO "NFS: mount server address does not match mountproto= "
1563 "option\n");
1564 return 0;
1565out_proto_mismatch:
1566 printk(KERN_INFO "NFS: server address does not match proto= option\n");
1567 return 0;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001568out_invalid_address:
1569 printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
1570 return 0;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001571out_invalid_value:
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001572 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001573 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001574out_nomem:
1575 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1576 return 0;
Eric Parisf9c3a382008-03-05 14:20:18 -05001577out_security_failure:
1578 free_secdata(secdata);
1579 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1580 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001581}
1582
1583/*
Chuck Leverec88f282009-08-09 15:09:32 -04001584 * Match the requested auth flavors with the list returned by
1585 * the server. Returns zero and sets the mount's authentication
1586 * flavor on success; returns -EACCES if server does not support
1587 * the requested flavor.
1588 */
1589static int nfs_walk_authlist(struct nfs_parsed_mount_data *args,
1590 struct nfs_mount_request *request)
1591{
1592 unsigned int i, j, server_authlist_len = *(request->auth_flav_len);
1593
1594 /*
Chuck Lever5eecfde2009-08-21 17:50:30 -04001595 * Certain releases of Linux's mountd return an empty
1596 * flavor list. To prevent behavioral regression with
1597 * these servers (ie. rejecting mounts that used to
1598 * succeed), revert to pre-2.6.32 behavior (no checking)
1599 * if the returned flavor list is empty.
1600 */
1601 if (server_authlist_len == 0)
1602 return 0;
1603
1604 /*
Chuck Leverec88f282009-08-09 15:09:32 -04001605 * We avoid sophisticated negotiating here, as there are
1606 * plenty of cases where we can get it wrong, providing
1607 * either too little or too much security.
1608 *
1609 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1610 * flavor listed first. However, some servers list
1611 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1612 * preferred default, in args->auth_flavors[0] if user
1613 * didn't specify sec= mount option.
1614 */
1615 for (i = 0; i < args->auth_flavor_len; i++)
1616 for (j = 0; j < server_authlist_len; j++)
1617 if (args->auth_flavors[i] == request->auth_flavs[j]) {
1618 dfprintk(MOUNT, "NFS: using auth flavor %d\n",
1619 request->auth_flavs[j]);
1620 args->auth_flavors[0] = request->auth_flavs[j];
1621 return 0;
1622 }
1623
1624 dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n");
1625 nfs_umount(request);
1626 return -EACCES;
1627}
1628
1629/*
Chuck Lever0076d7b2007-07-01 12:13:49 -04001630 * Use the remote server's MOUNT service to request the NFS file handle
1631 * corresponding to the provided path.
1632 */
1633static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1634 struct nfs_fh *root_fh)
1635{
Chuck Leverec88f282009-08-09 15:09:32 -04001636 rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS];
1637 unsigned int server_authlist_len = ARRAY_SIZE(server_authlist);
Chuck Leverc5d120f2008-12-23 15:21:35 -05001638 struct nfs_mount_request request = {
1639 .sap = (struct sockaddr *)
1640 &args->mount_server.address,
1641 .dirpath = args->nfs_server.export_path,
1642 .protocol = args->mount_server.protocol,
1643 .fh = root_fh,
Chuck Lever50a737f2008-12-23 15:21:37 -05001644 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
Chuck Leverec88f282009-08-09 15:09:32 -04001645 .auth_flav_len = &server_authlist_len,
1646 .auth_flavs = server_authlist,
Chuck Leverc5d120f2008-12-23 15:21:35 -05001647 };
Chuck Lever4c568012007-12-10 14:59:28 -05001648 int status;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001649
1650 if (args->mount_server.version == 0) {
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001651 switch (args->version) {
1652 default:
1653 args->mount_server.version = NFS_MNT3_VERSION;
1654 break;
1655 case 2:
1656 args->mount_server.version = NFS_MNT_VERSION;
1657 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001658 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001659 request.version = args->mount_server.version;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001660
Chuck Lever33832032007-12-10 14:59:13 -05001661 if (args->mount_server.hostname)
Chuck Leverc5d120f2008-12-23 15:21:35 -05001662 request.hostname = args->mount_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001663 else
Chuck Leverc5d120f2008-12-23 15:21:35 -05001664 request.hostname = args->nfs_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001665
Chuck Lever0076d7b2007-07-01 12:13:49 -04001666 /*
1667 * Construct the mount server's address.
1668 */
Chuck Lever4c568012007-12-10 14:59:28 -05001669 if (args->mount_server.address.ss_family == AF_UNSPEC) {
Chuck Leverc5d120f2008-12-23 15:21:35 -05001670 memcpy(request.sap, &args->nfs_server.address,
Chuck Lever4c568012007-12-10 14:59:28 -05001671 args->nfs_server.addrlen);
1672 args->mount_server.addrlen = args->nfs_server.addrlen;
1673 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001674 request.salen = args->mount_server.addrlen;
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001675 nfs_set_port(request.sap, &args->mount_server.port, 0);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001676
1677 /*
1678 * Now ask the mount server to map our export path
1679 * to a file handle.
1680 */
Chuck Leverc5d120f2008-12-23 15:21:35 -05001681 status = nfs_mount(&request);
Chuck Leverec88f282009-08-09 15:09:32 -04001682 if (status != 0) {
1683 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1684 request.hostname, status);
1685 return status;
1686 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001687
Chuck Leverec88f282009-08-09 15:09:32 -04001688 /*
1689 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1690 */
1691 if (args->mount_server.version != NFS_MNT3_VERSION)
1692 return 0;
1693 return nfs_walk_authlist(args, &request);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001694}
1695
Chuck Leverd1aa0822008-06-23 12:36:45 -04001696static int nfs_parse_simple_hostname(const char *dev_name,
1697 char **hostname, size_t maxnamlen,
1698 char **export_path, size_t maxpathlen)
Chuck Leverdc045892008-06-23 12:36:37 -04001699{
1700 size_t len;
1701 char *colon, *comma;
1702
1703 colon = strchr(dev_name, ':');
1704 if (colon == NULL)
1705 goto out_bad_devname;
1706
1707 len = colon - dev_name;
1708 if (len > maxnamlen)
1709 goto out_hostname;
1710
1711 /* N.B. caller will free nfs_server.hostname in all cases */
1712 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
1713 if (!*hostname)
1714 goto out_nomem;
1715
1716 /* kill possible hostname list: not supported */
1717 comma = strchr(*hostname, ',');
1718 if (comma != NULL) {
1719 if (comma == *hostname)
1720 goto out_bad_devname;
1721 *comma = '\0';
1722 }
1723
1724 colon++;
1725 len = strlen(colon);
1726 if (len > maxpathlen)
1727 goto out_path;
1728 *export_path = kstrndup(colon, len, GFP_KERNEL);
1729 if (!*export_path)
1730 goto out_nomem;
1731
1732 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1733 return 0;
1734
1735out_bad_devname:
1736 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1737 return -EINVAL;
1738
1739out_nomem:
1740 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1741 return -ENOMEM;
1742
1743out_hostname:
1744 dfprintk(MOUNT, "NFS: server hostname too long\n");
1745 return -ENAMETOOLONG;
1746
1747out_path:
1748 dfprintk(MOUNT, "NFS: export pathname too long\n");
1749 return -ENAMETOOLONG;
1750}
1751
1752/*
Chuck Leverd1aa0822008-06-23 12:36:45 -04001753 * Hostname has square brackets around it because it contains one or
1754 * more colons. We look for the first closing square bracket, and a
1755 * colon must follow it.
1756 */
1757static int nfs_parse_protected_hostname(const char *dev_name,
1758 char **hostname, size_t maxnamlen,
1759 char **export_path, size_t maxpathlen)
1760{
1761 size_t len;
1762 char *start, *end;
1763
1764 start = (char *)(dev_name + 1);
1765
1766 end = strchr(start, ']');
1767 if (end == NULL)
1768 goto out_bad_devname;
1769 if (*(end + 1) != ':')
1770 goto out_bad_devname;
1771
1772 len = end - start;
1773 if (len > maxnamlen)
1774 goto out_hostname;
1775
1776 /* N.B. caller will free nfs_server.hostname in all cases */
1777 *hostname = kstrndup(start, len, GFP_KERNEL);
1778 if (*hostname == NULL)
1779 goto out_nomem;
1780
1781 end += 2;
1782 len = strlen(end);
1783 if (len > maxpathlen)
1784 goto out_path;
1785 *export_path = kstrndup(end, len, GFP_KERNEL);
1786 if (!*export_path)
1787 goto out_nomem;
1788
1789 return 0;
1790
1791out_bad_devname:
1792 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1793 return -EINVAL;
1794
1795out_nomem:
1796 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1797 return -ENOMEM;
1798
1799out_hostname:
1800 dfprintk(MOUNT, "NFS: server hostname too long\n");
1801 return -ENAMETOOLONG;
1802
1803out_path:
1804 dfprintk(MOUNT, "NFS: export pathname too long\n");
1805 return -ENAMETOOLONG;
1806}
1807
1808/*
1809 * Split "dev_name" into "hostname:export_path".
1810 *
1811 * The leftmost colon demarks the split between the server's hostname
1812 * and the export path. If the hostname starts with a left square
1813 * bracket, then it may contain colons.
1814 *
1815 * Note: caller frees hostname and export path, even on error.
1816 */
1817static int nfs_parse_devname(const char *dev_name,
1818 char **hostname, size_t maxnamlen,
1819 char **export_path, size_t maxpathlen)
1820{
1821 if (*dev_name == '[')
1822 return nfs_parse_protected_hostname(dev_name,
1823 hostname, maxnamlen,
1824 export_path, maxpathlen);
1825
1826 return nfs_parse_simple_hostname(dev_name,
1827 hostname, maxnamlen,
1828 export_path, maxpathlen);
1829}
1830
1831/*
David Howells54ceac42006-08-22 20:06:13 -04001832 * Validate the NFS2/NFS3 mount data
1833 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001834 *
1835 * For option strings, user space handles the following behaviors:
1836 *
1837 * + DNS: mapping server host name to IP address ("addr=" option)
1838 *
1839 * + failure mode: how to behave if a mount request can't be handled
1840 * immediately ("fg/bg" option)
1841 *
1842 * + retry: how often to retry a mount request ("retry=" option)
1843 *
1844 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1845 * mountproto=tcp after mountproto=udp, and so on
David Howellsf7b422b2006-06-09 09:34:33 -04001846 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001847static int nfs_validate_mount_data(void *options,
1848 struct nfs_parsed_mount_data *args,
Chuck Lever136d5582007-07-01 12:13:54 -04001849 struct nfs_fh *mntfh,
1850 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001851{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001852 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001853 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
Chuck Lever136d5582007-07-01 12:13:54 -04001854
Chuck Lever5df36e72007-07-01 12:12:56 -04001855 if (data == NULL)
1856 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001857
David Howellsf7b422b2006-06-09 09:34:33 -04001858 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001859 case 1:
1860 data->namlen = 0;
1861 case 2:
1862 data->bsize = 0;
1863 case 3:
1864 if (data->flags & NFS_MOUNT_VER3)
1865 goto out_no_v3;
1866 data->root.size = NFS2_FHSIZE;
1867 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1868 case 4:
1869 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1870 goto out_no_sec;
1871 case 5:
1872 memset(data->context, 0, sizeof(data->context));
1873 case 6:
Trond Myklebustb7e24452008-06-19 15:21:11 -04001874 if (data->flags & NFS_MOUNT_VER3) {
1875 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1876 goto out_invalid_fh;
Chuck Lever5df36e72007-07-01 12:12:56 -04001877 mntfh->size = data->root.size;
Chuck Lever764302c2009-09-08 19:50:03 -04001878 args->version = 3;
1879 } else {
Chuck Lever5df36e72007-07-01 12:12:56 -04001880 mntfh->size = NFS2_FHSIZE;
Chuck Lever764302c2009-09-08 19:50:03 -04001881 args->version = 2;
1882 }
Chuck Lever5df36e72007-07-01 12:12:56 -04001883
Chuck Lever5df36e72007-07-01 12:12:56 -04001884
1885 memcpy(mntfh->data, data->root.data, mntfh->size);
1886 if (mntfh->size < sizeof(mntfh->data))
1887 memset(mntfh->data + mntfh->size, 0,
1888 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001889
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001890 /*
1891 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1892 * can deal with.
1893 */
Trond Myklebustff3525a2008-08-15 16:59:14 -04001894 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
Bryan Schumakerd5eff1a2010-08-03 13:04:00 -04001895 args->flags |= NFS_MOUNT_LEGACY_INTERFACE;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001896 args->rsize = data->rsize;
1897 args->wsize = data->wsize;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001898 args->timeo = data->timeo;
1899 args->retrans = data->retrans;
1900 args->acregmin = data->acregmin;
1901 args->acregmax = data->acregmax;
1902 args->acdirmin = data->acdirmin;
1903 args->acdirmax = data->acdirmax;
Chuck Lever4c568012007-12-10 14:59:28 -05001904
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001905 memcpy(sap, &data->addr, sizeof(data->addr));
Chuck Lever4c568012007-12-10 14:59:28 -05001906 args->nfs_server.addrlen = sizeof(data->addr);
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001907 if (!nfs_verify_server_address(sap))
Chuck Lever4c568012007-12-10 14:59:28 -05001908 goto out_no_address;
1909
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001910 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001911 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001912 /* N.B. caller will free nfs_server.hostname in all cases */
1913 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1914 args->namlen = data->namlen;
1915 args->bsize = data->bsize;
Chuck Leverdd07c942008-06-24 16:33:46 -04001916
1917 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1918 args->auth_flavors[0] = data->pseudoflavor;
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001919 if (!args->nfs_server.hostname)
1920 goto out_nomem;
Eric Parisf9c3a382008-03-05 14:20:18 -05001921
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001922 if (!(data->flags & NFS_MOUNT_NONLM))
1923 args->flags &= ~(NFS_MOUNT_LOCAL_FLOCK|
1924 NFS_MOUNT_LOCAL_FCNTL);
1925 else
1926 args->flags |= (NFS_MOUNT_LOCAL_FLOCK|
1927 NFS_MOUNT_LOCAL_FCNTL);
Eric Parisf9c3a382008-03-05 14:20:18 -05001928 /*
1929 * The legacy version 6 binary mount data from userspace has a
1930 * field used only to transport selinux information into the
1931 * the kernel. To continue to support that functionality we
1932 * have a touch of selinux knowledge here in the NFS code. The
1933 * userspace code converted context=blah to just blah so we are
1934 * converting back to the full string selinux understands.
1935 */
1936 if (data->context[0]){
1937#ifdef CONFIG_SECURITY_SELINUX
1938 int rc;
1939 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1940 if (!opts_str)
1941 return -ENOMEM;
1942 strcpy(opts_str, "context=");
1943 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1944 strcat(opts_str, &data->context[0]);
1945 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1946 kfree(opts_str);
1947 if (rc)
1948 return rc;
1949#else
1950 return -EINVAL;
1951#endif
1952 }
1953
Chuck Lever5df36e72007-07-01 12:12:56 -04001954 break;
Chuck Lever136d5582007-07-01 12:13:54 -04001955 default: {
Chuck Lever136d5582007-07-01 12:13:54 -04001956 int status;
Chuck Lever136d5582007-07-01 12:13:54 -04001957
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001958 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever136d5582007-07-01 12:13:54 -04001959 return -EINVAL;
1960
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001961 if (!nfs_verify_server_address(sap))
Chuck Lever6e88e062007-09-24 15:39:50 -04001962 goto out_no_address;
1963
Chuck Lever764302c2009-09-08 19:50:03 -04001964 if (args->version == 4)
1965#ifdef CONFIG_NFS_V4
1966 return nfs4_validate_text_mount_data(options,
1967 args, dev_name);
1968#else
1969 goto out_v4_not_compiled;
1970#endif
1971
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001972 nfs_set_port(sap, &args->nfs_server.port, 0);
Chuck Levered596a82008-06-26 17:47:05 -04001973
Trond Myklebust259875e2008-07-02 14:43:47 -04001974 nfs_set_mount_transport_protocol(args);
1975
Chuck Leverdc045892008-06-23 12:36:37 -04001976 status = nfs_parse_devname(dev_name,
1977 &args->nfs_server.hostname,
1978 PAGE_SIZE,
1979 &args->nfs_server.export_path,
1980 NFS_MAXPATHLEN);
1981 if (!status)
1982 status = nfs_try_mount(args, mntfh);
Chuck Lever136d5582007-07-01 12:13:54 -04001983
Chuck Leverdc045892008-06-23 12:36:37 -04001984 kfree(args->nfs_server.export_path);
1985 args->nfs_server.export_path = NULL;
Chuck Lever136d5582007-07-01 12:13:54 -04001986
Chuck Lever136d5582007-07-01 12:13:54 -04001987 if (status)
Chuck Leverfdc6e2c2007-08-29 17:58:59 -04001988 return status;
Chuck Lever136d5582007-07-01 12:13:54 -04001989
Chuck Lever136d5582007-07-01 12:13:54 -04001990 break;
1991 }
David Howellsf7b422b2006-06-09 09:34:33 -04001992 }
David Howells54ceac42006-08-22 20:06:13 -04001993
David Howellsf7b422b2006-06-09 09:34:33 -04001994#ifndef CONFIG_NFS_V3
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001995 if (args->version == 3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001996 goto out_v3_not_compiled;
1997#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001998
David Howells54ceac42006-08-22 20:06:13 -04001999 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04002000
2001out_no_data:
2002 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
2003 return -EINVAL;
2004
2005out_no_v3:
2006 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
2007 data->version);
2008 return -EINVAL;
2009
2010out_no_sec:
2011 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
2012 return -EINVAL;
2013
Chuck Lever5df36e72007-07-01 12:12:56 -04002014#ifndef CONFIG_NFS_V3
2015out_v3_not_compiled:
2016 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
2017 return -EPROTONOSUPPORT;
2018#endif /* !CONFIG_NFS_V3 */
2019
Chuck Lever764302c2009-09-08 19:50:03 -04002020#ifndef CONFIG_NFS_V4
2021out_v4_not_compiled:
2022 dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n");
2023 return -EPROTONOSUPPORT;
2024#endif /* !CONFIG_NFS_V4 */
2025
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04002026out_nomem:
2027 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
2028 return -ENOMEM;
2029
Chuck Lever5df36e72007-07-01 12:12:56 -04002030out_no_address:
2031 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
2032 return -EINVAL;
2033
2034out_invalid_fh:
2035 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
2036 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04002037}
2038
Jeff Layton48b605f2008-06-10 15:38:39 -04002039static int
2040nfs_compare_remount_data(struct nfs_server *nfss,
2041 struct nfs_parsed_mount_data *data)
2042{
2043 if (data->flags != nfss->flags ||
2044 data->rsize != nfss->rsize ||
2045 data->wsize != nfss->wsize ||
2046 data->retrans != nfss->client->cl_timeout->to_retries ||
2047 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
2048 data->acregmin != nfss->acregmin / HZ ||
2049 data->acregmax != nfss->acregmax / HZ ||
2050 data->acdirmin != nfss->acdirmin / HZ ||
2051 data->acdirmax != nfss->acdirmax / HZ ||
2052 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
Trond Myklebustbcd2ea12009-10-06 15:41:22 -04002053 data->nfs_server.port != nfss->port ||
Jeff Layton48b605f2008-06-10 15:38:39 -04002054 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
Stefan Richtera1be9ee2009-10-12 11:26:12 -04002055 !rpc_cmp_addr((struct sockaddr *)&data->nfs_server.address,
2056 (struct sockaddr *)&nfss->nfs_client->cl_addr))
Jeff Layton48b605f2008-06-10 15:38:39 -04002057 return -EINVAL;
2058
2059 return 0;
2060}
2061
2062static int
2063nfs_remount(struct super_block *sb, int *flags, char *raw_data)
2064{
2065 int error;
2066 struct nfs_server *nfss = sb->s_fs_info;
2067 struct nfs_parsed_mount_data *data;
2068 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
2069 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
Trond Myklebustcd100722008-06-17 16:12:00 -04002070 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
Jeff Layton48b605f2008-06-10 15:38:39 -04002071
2072 /*
2073 * Userspace mount programs that send binary options generally send
2074 * them populated with default values. We have no way to know which
2075 * ones were explicitly specified. Fall back to legacy behavior and
2076 * just return success.
2077 */
Marc Zyngier31c94462008-07-17 13:21:55 +02002078 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
2079 (nfsvers <= 3 && (!options || (options->version >= 1 &&
2080 options->version <= 6))))
Jeff Layton48b605f2008-06-10 15:38:39 -04002081 return 0;
2082
2083 data = kzalloc(sizeof(*data), GFP_KERNEL);
2084 if (data == NULL)
2085 return -ENOMEM;
2086
2087 /* fill out struct with values from existing mount */
2088 data->flags = nfss->flags;
2089 data->rsize = nfss->rsize;
2090 data->wsize = nfss->wsize;
2091 data->retrans = nfss->client->cl_timeout->to_retries;
2092 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
2093 data->acregmin = nfss->acregmin / HZ;
2094 data->acregmax = nfss->acregmax / HZ;
2095 data->acdirmin = nfss->acdirmin / HZ;
2096 data->acdirmax = nfss->acdirmax / HZ;
2097 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
Trond Myklebustbcd2ea12009-10-06 15:41:22 -04002098 data->nfs_server.port = nfss->port;
Jeff Layton48b605f2008-06-10 15:38:39 -04002099 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
2100 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
2101 data->nfs_server.addrlen);
2102
2103 /* overwrite those values with any that were specified */
2104 error = nfs_parse_mount_options((char *)options, data);
2105 if (error < 0)
2106 goto out;
2107
2108 /* compare new mount options with old ones */
2109 error = nfs_compare_remount_data(nfss, data);
2110out:
2111 kfree(data);
2112 return error;
2113}
2114
David Howells54ceac42006-08-22 20:06:13 -04002115/*
2116 * Initialise the common bits of the superblock
2117 */
2118static inline void nfs_initialise_sb(struct super_block *sb)
2119{
2120 struct nfs_server *server = NFS_SB(sb);
2121
2122 sb->s_magic = NFS_SUPER_MAGIC;
2123
2124 /* We probably want something more informative here */
2125 snprintf(sb->s_id, sizeof(sb->s_id),
2126 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
2127
2128 if (sb->s_blocksize == 0)
2129 sb->s_blocksize = nfs_block_bits(server->wsize,
2130 &sb->s_blocksize_bits);
2131
2132 if (server->flags & NFS_MOUNT_NOAC)
2133 sb->s_flags |= MS_SYNCHRONOUS;
2134
Jens Axboe32a88aa2009-09-16 15:02:33 +02002135 sb->s_bdi = &server->backing_dev_info;
2136
David Howells54ceac42006-08-22 20:06:13 -04002137 nfs_super_set_maxbytes(sb, server->maxfilesize);
2138}
2139
2140/*
2141 * Finish setting up an NFS2/3 superblock
2142 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04002143static void nfs_fill_super(struct super_block *sb,
2144 struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -04002145{
2146 struct nfs_server *server = NFS_SB(sb);
2147
2148 sb->s_blocksize_bits = 0;
2149 sb->s_blocksize = 0;
2150 if (data->bsize)
2151 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
2152
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04002153 if (server->nfs_client->rpc_ops->version == 3) {
David Howells54ceac42006-08-22 20:06:13 -04002154 /* The VFS shouldn't apply the umask to mode bits. We will do
2155 * so ourselves when necessary.
2156 */
2157 sb->s_flags |= MS_POSIXACL;
2158 sb->s_time_gran = 1;
2159 }
2160
2161 sb->s_op = &nfs_sops;
2162 nfs_initialise_sb(sb);
2163}
2164
2165/*
2166 * Finish setting up a cloned NFS2/3 superblock
2167 */
2168static void nfs_clone_super(struct super_block *sb,
2169 const struct super_block *old_sb)
2170{
2171 struct nfs_server *server = NFS_SB(sb);
2172
2173 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2174 sb->s_blocksize = old_sb->s_blocksize;
2175 sb->s_maxbytes = old_sb->s_maxbytes;
2176
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04002177 if (server->nfs_client->rpc_ops->version == 3) {
David Howells54ceac42006-08-22 20:06:13 -04002178 /* The VFS shouldn't apply the umask to mode bits. We will do
2179 * so ourselves when necessary.
2180 */
2181 sb->s_flags |= MS_POSIXACL;
2182 sb->s_time_gran = 1;
2183 }
2184
2185 sb->s_op = old_sb->s_op;
2186 nfs_initialise_sb(sb);
2187}
2188
Trond Myklebust275a5d22007-05-16 16:53:28 -04002189static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
2190{
2191 const struct nfs_server *a = s->s_fs_info;
2192 const struct rpc_clnt *clnt_a = a->client;
2193 const struct rpc_clnt *clnt_b = b->client;
2194
2195 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
2196 goto Ebusy;
2197 if (a->nfs_client != b->nfs_client)
2198 goto Ebusy;
2199 if (a->flags != b->flags)
2200 goto Ebusy;
2201 if (a->wsize != b->wsize)
2202 goto Ebusy;
2203 if (a->rsize != b->rsize)
2204 goto Ebusy;
2205 if (a->acregmin != b->acregmin)
2206 goto Ebusy;
2207 if (a->acregmax != b->acregmax)
2208 goto Ebusy;
2209 if (a->acdirmin != b->acdirmin)
2210 goto Ebusy;
2211 if (a->acdirmax != b->acdirmax)
2212 goto Ebusy;
2213 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
2214 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002215 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04002216Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002217 return 0;
2218}
2219
2220struct nfs_sb_mountdata {
2221 struct nfs_server *server;
2222 int mntflags;
2223};
2224
2225static int nfs_set_super(struct super_block *s, void *data)
2226{
2227 struct nfs_sb_mountdata *sb_mntdata = data;
2228 struct nfs_server *server = sb_mntdata->server;
2229 int ret;
2230
2231 s->s_flags = sb_mntdata->mntflags;
2232 s->s_fs_info = server;
Al Viro8b244ff2010-12-18 11:29:39 -05002233 s->s_d_op = server->nfs_client->rpc_ops->dentry_ops;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002234 ret = set_anon_super(s, server);
2235 if (ret == 0)
2236 server->s_dev = s->s_dev;
2237 return ret;
2238}
2239
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002240static int nfs_compare_super_address(struct nfs_server *server1,
2241 struct nfs_server *server2)
2242{
2243 struct sockaddr *sap1, *sap2;
2244
2245 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
2246 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
2247
2248 if (sap1->sa_family != sap2->sa_family)
2249 return 0;
2250
2251 switch (sap1->sa_family) {
2252 case AF_INET: {
2253 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
2254 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
2255 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
2256 return 0;
2257 if (sin1->sin_port != sin2->sin_port)
2258 return 0;
2259 break;
2260 }
2261 case AF_INET6: {
2262 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
2263 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
2264 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
2265 return 0;
2266 if (sin1->sin6_port != sin2->sin6_port)
2267 return 0;
2268 break;
2269 }
2270 default:
2271 return 0;
2272 }
2273
2274 return 1;
2275}
2276
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002277static int nfs_compare_super(struct super_block *sb, void *data)
2278{
2279 struct nfs_sb_mountdata *sb_mntdata = data;
2280 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2281 int mntflags = sb_mntdata->mntflags;
2282
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002283 if (!nfs_compare_super_address(old, server))
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002284 return 0;
2285 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2286 if (old->flags & NFS_MOUNT_UNSHARED)
2287 return 0;
2288 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2289 return 0;
2290 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04002291}
2292
Miklos Szeredifa799752008-04-30 00:54:33 -07002293static int nfs_bdi_register(struct nfs_server *server)
2294{
2295 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
2296}
2297
David Howells54ceac42006-08-22 20:06:13 -04002298static int nfs_get_sb(struct file_system_type *fs_type,
2299 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2300{
2301 struct nfs_server *server = NULL;
2302 struct super_block *s;
Trond Myklebust33852a12008-06-19 14:20:11 -04002303 struct nfs_parsed_mount_data *data;
2304 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04002305 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002306 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002307 struct nfs_sb_mountdata sb_mntdata = {
2308 .mntflags = flags,
2309 };
Trond Myklebust33852a12008-06-19 14:20:11 -04002310 int error = -ENOMEM;
David Howells54ceac42006-08-22 20:06:13 -04002311
Paulius Zaleckas1e657bd2010-10-31 18:21:05 +02002312 data = nfs_alloc_parsed_mount_data(NFS_DEFAULT_VERSION);
Trond Myklebustb157b062010-04-19 19:05:48 -04002313 mntfh = nfs_alloc_fhandle();
Trond Myklebust33852a12008-06-19 14:20:11 -04002314 if (data == NULL || mntfh == NULL)
2315 goto out_free_fh;
2316
2317 security_init_mnt_opts(&data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002318
David Howells54ceac42006-08-22 20:06:13 -04002319 /* Validate the mount data */
Trond Myklebust33852a12008-06-19 14:20:11 -04002320 error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04002321 if (error < 0)
Chuck Lever06559602007-07-01 12:12:35 -04002322 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002323
Chuck Lever764302c2009-09-08 19:50:03 -04002324#ifdef CONFIG_NFS_V4
2325 if (data->version == 4) {
2326 error = nfs4_try_mount(flags, dev_name, data, mnt);
2327 kfree(data->client_address);
Xiaotian Feng9699eda2010-04-22 18:56:17 +08002328 kfree(data->nfs_server.export_path);
Chuck Lever764302c2009-09-08 19:50:03 -04002329 goto out;
2330 }
2331#endif /* CONFIG_NFS_V4 */
2332
David Howells54ceac42006-08-22 20:06:13 -04002333 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002334 server = nfs_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002335 if (IS_ERR(server)) {
2336 error = PTR_ERR(server);
Chuck Lever06559602007-07-01 12:12:35 -04002337 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002338 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002339 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002340
Trond Myklebust75180df2007-05-16 16:53:28 -04002341 if (server->flags & NFS_MOUNT_UNSHARED)
2342 compare_super = NULL;
2343
David Howells54ceac42006-08-22 20:06:13 -04002344 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002345 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002346 if (IS_ERR(s)) {
2347 error = PTR_ERR(s);
David Howells54ceac42006-08-22 20:06:13 -04002348 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04002349 }
2350
David Howells54ceac42006-08-22 20:06:13 -04002351 if (s->s_fs_info != server) {
2352 nfs_free_server(server);
2353 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002354 } else {
2355 error = nfs_bdi_register(server);
2356 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11002357 goto error_splat_bdi;
David Howellsf7b422b2006-06-09 09:34:33 -04002358 }
David Howells54ceac42006-08-22 20:06:13 -04002359
2360 if (!s->s_root) {
2361 /* initial superblock/root creation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002362 nfs_fill_super(s, data);
David Howells2df54802009-09-23 14:36:39 -04002363 nfs_fscache_get_super_cookie(
2364 s, data ? data->fscache_uniq : NULL, NULL);
David Howells54ceac42006-08-22 20:06:13 -04002365 }
2366
Al Viro0d5839a2011-03-16 05:27:27 -04002367 mntroot = nfs_get_root(s, mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04002368 if (IS_ERR(mntroot)) {
2369 error = PTR_ERR(mntroot);
2370 goto error_splat_super;
2371 }
2372
Trond Myklebust33852a12008-06-19 14:20:11 -04002373 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002374 if (error)
2375 goto error_splat_root;
2376
David Howellsf7b422b2006-06-09 09:34:33 -04002377 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002378 mnt->mnt_sb = s;
2379 mnt->mnt_root = mntroot;
Chuck Lever06559602007-07-01 12:12:35 -04002380 error = 0;
2381
2382out:
Trond Myklebust33852a12008-06-19 14:20:11 -04002383 kfree(data->nfs_server.hostname);
2384 kfree(data->mount_server.hostname);
David Howells08734042009-04-03 16:42:42 +01002385 kfree(data->fscache_uniq);
Trond Myklebust33852a12008-06-19 14:20:11 -04002386 security_free_mnt_opts(&data->lsm_opts);
2387out_free_fh:
Trond Myklebustb157b062010-04-19 19:05:48 -04002388 nfs_free_fhandle(mntfh);
Trond Myklebust33852a12008-06-19 14:20:11 -04002389 kfree(data);
Chuck Lever06559602007-07-01 12:12:35 -04002390 return error;
Trond Myklebust816724e2006-06-24 08:41:41 -04002391
David Howells54ceac42006-08-22 20:06:13 -04002392out_err_nosb:
2393 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04002394 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002395
Eric Parisf9c3a382008-03-05 14:20:18 -05002396error_splat_root:
2397 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04002398error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002399 if (server && !s->s_root)
2400 bdi_unregister(&server->backing_dev_info);
2401error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002402 deactivate_locked_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04002403 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002404}
2405
David Howells54ceac42006-08-22 20:06:13 -04002406/*
Trond Myklebust387c1492010-02-03 08:27:35 -05002407 * Ensure that we unregister the bdi before kill_anon_super
2408 * releases the device name
2409 */
2410static void nfs_put_super(struct super_block *s)
2411{
2412 struct nfs_server *server = NFS_SB(s);
2413
2414 bdi_unregister(&server->backing_dev_info);
2415}
2416
2417/*
David Howells54ceac42006-08-22 20:06:13 -04002418 * Destroy an NFS2/3 superblock
2419 */
David Howellsf7b422b2006-06-09 09:34:33 -04002420static void nfs_kill_super(struct super_block *s)
2421{
2422 struct nfs_server *server = NFS_SB(s);
2423
2424 kill_anon_super(s);
David Howells08734042009-04-03 16:42:42 +01002425 nfs_fscache_release_super_cookie(s);
David Howells54ceac42006-08-22 20:06:13 -04002426 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04002427}
2428
David Howells54ceac42006-08-22 20:06:13 -04002429/*
2430 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2431 */
Al Viro31f43472010-10-29 03:38:12 -04002432static struct dentry *
2433nfs_xdev_mount(struct file_system_type *fs_type, int flags,
2434 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002435{
2436 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002437 struct super_block *s;
2438 struct nfs_server *server;
2439 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002440 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002441 struct nfs_sb_mountdata sb_mntdata = {
2442 .mntflags = flags,
2443 };
David Howells54ceac42006-08-22 20:06:13 -04002444 int error;
2445
Al Viro31f43472010-10-29 03:38:12 -04002446 dprintk("--> nfs_xdev_mount()\n");
David Howells54ceac42006-08-22 20:06:13 -04002447
2448 /* create a new volume representation */
2449 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2450 if (IS_ERR(server)) {
2451 error = PTR_ERR(server);
2452 goto out_err_noserver;
2453 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002454 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002455
Trond Myklebust75180df2007-05-16 16:53:28 -04002456 if (server->flags & NFS_MOUNT_UNSHARED)
2457 compare_super = NULL;
2458
David Howells54ceac42006-08-22 20:06:13 -04002459 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002460 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002461 if (IS_ERR(s)) {
2462 error = PTR_ERR(s);
2463 goto out_err_nosb;
2464 }
2465
2466 if (s->s_fs_info != server) {
2467 nfs_free_server(server);
2468 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002469 } else {
2470 error = nfs_bdi_register(server);
2471 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11002472 goto error_splat_bdi;
David Howells54ceac42006-08-22 20:06:13 -04002473 }
2474
2475 if (!s->s_root) {
2476 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002477 nfs_clone_super(s, data->sb);
David Howells2df54802009-09-23 14:36:39 -04002478 nfs_fscache_get_super_cookie(s, NULL, data);
David Howells54ceac42006-08-22 20:06:13 -04002479 }
2480
Al Viro0d5839a2011-03-16 05:27:27 -04002481 mntroot = nfs_get_root(s, data->fh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04002482 if (IS_ERR(mntroot)) {
2483 error = PTR_ERR(mntroot);
2484 goto error_splat_super;
2485 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002486 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
Neil Brown4c1fe2f2007-11-01 16:50:20 +11002487 dput(mntroot);
2488 error = -ESTALE;
2489 goto error_splat_super;
2490 }
David Howells54ceac42006-08-22 20:06:13 -04002491
2492 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002493
Eric Parisf9c3a382008-03-05 14:20:18 -05002494 /* clone any lsm security options from the parent to the new sb */
2495 security_sb_clone_mnt_opts(data->sb, s);
2496
Al Viro31f43472010-10-29 03:38:12 -04002497 dprintk("<-- nfs_xdev_mount() = 0\n");
2498 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04002499
2500out_err_nosb:
2501 nfs_free_server(server);
2502out_err_noserver:
Al Viro31f43472010-10-29 03:38:12 -04002503 dprintk("<-- nfs_xdev_mount() = %d [error]\n", error);
2504 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04002505
2506error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002507 if (server && !s->s_root)
2508 bdi_unregister(&server->backing_dev_info);
2509error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002510 deactivate_locked_super(s);
Al Viro31f43472010-10-29 03:38:12 -04002511 dprintk("<-- nfs_xdev_mount() = %d [splat]\n", error);
2512 return ERR_PTR(error);
David Howellsf7b422b2006-06-09 09:34:33 -04002513}
2514
2515#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04002516
2517/*
2518 * Finish setting up a cloned NFS4 superblock
2519 */
2520static void nfs4_clone_super(struct super_block *sb,
2521 const struct super_block *old_sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002522{
David Howells54ceac42006-08-22 20:06:13 -04002523 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2524 sb->s_blocksize = old_sb->s_blocksize;
2525 sb->s_maxbytes = old_sb->s_maxbytes;
2526 sb->s_time_gran = 1;
2527 sb->s_op = old_sb->s_op;
Aneesh Kumar K.Va8a5da92010-12-09 11:35:14 +00002528 /*
2529 * The VFS shouldn't apply the umask to mode bits. We will do
2530 * so ourselves when necessary.
2531 */
2532 sb->s_flags |= MS_POSIXACL;
Aneesh Kumar K.V64c2ce82010-12-09 11:35:25 +00002533 sb->s_xattr = old_sb->s_xattr;
2534 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002535}
2536
2537/*
2538 * Set up an NFS4 superblock
2539 */
David Howells54ceac42006-08-22 20:06:13 -04002540static void nfs4_fill_super(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002541{
David Howellsf7b422b2006-06-09 09:34:33 -04002542 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04002543 sb->s_op = &nfs4_sops;
Aneesh Kumar K.Va8a5da92010-12-09 11:35:14 +00002544 /*
2545 * The VFS shouldn't apply the umask to mode bits. We will do
2546 * so ourselves when necessary.
2547 */
2548 sb->s_flags |= MS_POSIXACL;
Aneesh Kumar K.V64c2ce82010-12-09 11:35:25 +00002549 sb->s_xattr = nfs4_xattr_handlers;
David Howells54ceac42006-08-22 20:06:13 -04002550 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002551}
2552
Trond Myklebust01c3f052009-06-17 13:22:58 -07002553static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2554{
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04002555 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3|
2556 NFS_MOUNT_LOCAL_FLOCK|NFS_MOUNT_LOCAL_FCNTL);
Trond Myklebust01c3f052009-06-17 13:22:58 -07002557}
2558
Chuck Lever7630c852009-09-08 19:49:57 -04002559static int nfs4_validate_text_mount_data(void *options,
2560 struct nfs_parsed_mount_data *args,
2561 const char *dev_name)
2562{
2563 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2564
Trond Myklebustf5855fe2009-10-06 15:40:37 -04002565 nfs_set_port(sap, &args->nfs_server.port, NFS_PORT);
Chuck Lever7630c852009-09-08 19:49:57 -04002566
2567 nfs_validate_transport_protocol(args);
2568
2569 nfs4_validate_mount_flags(args);
2570
Trond Myklebust2ecda722009-09-08 19:50:07 -04002571 if (args->version != 4) {
2572 dfprintk(MOUNT,
2573 "NFS4: Illegal mount version\n");
2574 return -EINVAL;
2575 }
2576
Chuck Lever7630c852009-09-08 19:49:57 -04002577 if (args->auth_flavor_len > 1) {
2578 dfprintk(MOUNT,
2579 "NFS4: Too many RPC auth flavours specified\n");
2580 return -EINVAL;
2581 }
2582
2583 if (args->client_address == NULL) {
2584 dfprintk(MOUNT,
2585 "NFS4: mount program didn't pass callback address\n");
2586 return -EINVAL;
2587 }
2588
2589 return nfs_parse_devname(dev_name,
2590 &args->nfs_server.hostname,
2591 NFS4_MAXNAMLEN,
2592 &args->nfs_server.export_path,
2593 NFS4_MAXPATHLEN);
2594}
2595
David Howells54ceac42006-08-22 20:06:13 -04002596/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04002597 * Validate NFSv4 mount options
2598 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002599static int nfs4_validate_mount_data(void *options,
2600 struct nfs_parsed_mount_data *args,
2601 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04002602{
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002603 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002604 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002605 char *c;
2606
2607 if (data == NULL)
2608 goto out_no_data;
2609
2610 switch (data->version) {
2611 case 1:
Chuck Lever4c568012007-12-10 14:59:28 -05002612 if (data->host_addrlen > sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002613 goto out_no_address;
Chuck Lever4c568012007-12-10 14:59:28 -05002614 if (data->host_addrlen == 0)
2615 goto out_no_address;
2616 args->nfs_server.addrlen = data->host_addrlen;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002617 if (copy_from_user(sap, data->host_addr, data->host_addrlen))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002618 return -EFAULT;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002619 if (!nfs_verify_server_address(sap))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002620 goto out_no_address;
2621
Chuck Lever6738b252008-06-24 16:33:54 -04002622 if (data->auth_flavourlen) {
2623 if (data->auth_flavourlen > 1)
2624 goto out_inval_auth;
Trond Myklebust20c71f52007-09-20 20:23:51 -04002625 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002626 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04002627 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002628 return -EFAULT;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002629 }
2630
2631 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2632 if (IS_ERR(c))
2633 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002634 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002635
2636 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2637 if (IS_ERR(c))
2638 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002639 args->nfs_server.export_path = c;
2640 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002641
2642 c = strndup_user(data->client_addr.data, 16);
2643 if (IS_ERR(c))
2644 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002645 args->client_address = c;
2646
2647 /*
2648 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2649 * can deal with.
2650 */
2651
2652 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2653 args->rsize = data->rsize;
2654 args->wsize = data->wsize;
2655 args->timeo = data->timeo;
2656 args->retrans = data->retrans;
2657 args->acregmin = data->acregmin;
2658 args->acregmax = data->acregmax;
2659 args->acdirmin = data->acdirmin;
2660 args->acdirmax = data->acdirmax;
2661 args->nfs_server.protocol = data->proto;
Trond Myklebust259875e2008-07-02 14:43:47 -04002662 nfs_validate_transport_protocol(args);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002663
2664 break;
Chuck Lever7630c852009-09-08 19:49:57 -04002665 default:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002666 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever80071222007-07-01 12:13:59 -04002667 return -EINVAL;
2668
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002669 if (!nfs_verify_server_address(sap))
Chuck Lever80071222007-07-01 12:13:59 -04002670 return -EINVAL;
Chuck Levered596a82008-06-26 17:47:05 -04002671
Chuck Lever7630c852009-09-08 19:49:57 -04002672 return nfs4_validate_text_mount_data(options, args, dev_name);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002673 }
2674
2675 return 0;
2676
2677out_no_data:
2678 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2679 return -EINVAL;
2680
2681out_inval_auth:
2682 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2683 data->auth_flavourlen);
2684 return -EINVAL;
2685
2686out_no_address:
2687 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2688 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002689}
2690
2691/*
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002692 * Get the superblock for the NFS4 root partition
David Howells54ceac42006-08-22 20:06:13 -04002693 */
Al Viro31f43472010-10-29 03:38:12 -04002694static struct dentry *
2695nfs4_remote_mount(struct file_system_type *fs_type, int flags,
2696 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002697{
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002698 struct nfs_parsed_mount_data *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002699 struct super_block *s;
2700 struct nfs_server *server;
Trond Myklebust33852a12008-06-19 14:20:11 -04002701 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04002702 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002703 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002704 struct nfs_sb_mountdata sb_mntdata = {
2705 .mntflags = flags,
2706 };
Trond Myklebust33852a12008-06-19 14:20:11 -04002707 int error = -ENOMEM;
David Howellsf7b422b2006-06-09 09:34:33 -04002708
Trond Myklebustb157b062010-04-19 19:05:48 -04002709 mntfh = nfs_alloc_fhandle();
Trond Myklebust33852a12008-06-19 14:20:11 -04002710 if (data == NULL || mntfh == NULL)
2711 goto out_free_fh;
2712
2713 security_init_mnt_opts(&data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002714
David Howells54ceac42006-08-22 20:06:13 -04002715 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002716 server = nfs4_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002717 if (IS_ERR(server)) {
2718 error = PTR_ERR(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04002719 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002720 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002721 sb_mntdata.server = server;
David Howellsf7b422b2006-06-09 09:34:33 -04002722
Trond Myklebust75180df2007-05-16 16:53:28 -04002723 if (server->flags & NFS4_MOUNT_UNSHARED)
2724 compare_super = NULL;
2725
David Howells54ceac42006-08-22 20:06:13 -04002726 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002727 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002728 if (IS_ERR(s)) {
2729 error = PTR_ERR(s);
David Howellsf7b422b2006-06-09 09:34:33 -04002730 goto out_free;
Trond Myklebust816724e2006-06-24 08:41:41 -04002731 }
2732
Trond Myklebust5dd31772006-08-24 01:03:05 -04002733 if (s->s_fs_info != server) {
2734 nfs_free_server(server);
2735 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002736 } else {
2737 error = nfs_bdi_register(server);
2738 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11002739 goto error_splat_bdi;
Trond Myklebust5dd31772006-08-24 01:03:05 -04002740 }
2741
David Howells54ceac42006-08-22 20:06:13 -04002742 if (!s->s_root) {
2743 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002744 nfs4_fill_super(s);
David Howells2df54802009-09-23 14:36:39 -04002745 nfs_fscache_get_super_cookie(
2746 s, data ? data->fscache_uniq : NULL, NULL);
Trond Myklebust816724e2006-06-24 08:41:41 -04002747 }
David Howellsf7b422b2006-06-09 09:34:33 -04002748
Al Viro0d5839a2011-03-16 05:27:27 -04002749 mntroot = nfs4_get_root(s, mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04002750 if (IS_ERR(mntroot)) {
2751 error = PTR_ERR(mntroot);
2752 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04002753 }
David Howells54ceac42006-08-22 20:06:13 -04002754
Trond Myklebust33852a12008-06-19 14:20:11 -04002755 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Paris46c8ac72008-05-02 13:42:42 -07002756 if (error)
2757 goto error_splat_root;
2758
David Howellsf7b422b2006-06-09 09:34:33 -04002759 s->s_flags |= MS_ACTIVE;
Al Viro31f43472010-10-29 03:38:12 -04002760
2761 security_free_mnt_opts(&data->lsm_opts);
2762 nfs_free_fhandle(mntfh);
2763 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04002764
Chuck Lever29eb9812007-07-01 12:12:30 -04002765out:
Trond Myklebust33852a12008-06-19 14:20:11 -04002766 security_free_mnt_opts(&data->lsm_opts);
2767out_free_fh:
Trond Myklebustb157b062010-04-19 19:05:48 -04002768 nfs_free_fhandle(mntfh);
Al Viro31f43472010-10-29 03:38:12 -04002769 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04002770
Chuck Lever29eb9812007-07-01 12:12:30 -04002771out_free:
2772 nfs_free_server(server);
2773 goto out;
2774
Eric Paris46c8ac72008-05-02 13:42:42 -07002775error_splat_root:
2776 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04002777error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002778 if (server && !s->s_root)
2779 bdi_unregister(&server->backing_dev_info);
2780error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002781 deactivate_locked_super(s);
Chuck Lever29eb9812007-07-01 12:12:30 -04002782 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002783}
2784
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002785static struct vfsmount *nfs_do_root_mount(struct file_system_type *fs_type,
2786 int flags, void *data, const char *hostname)
2787{
2788 struct vfsmount *root_mnt;
2789 char *root_devname;
2790 size_t len;
2791
2792 len = strlen(hostname) + 3;
2793 root_devname = kmalloc(len, GFP_KERNEL);
2794 if (root_devname == NULL)
2795 return ERR_PTR(-ENOMEM);
2796 snprintf(root_devname, len, "%s:/", hostname);
2797 root_mnt = vfs_kern_mount(fs_type, flags, root_devname, data);
2798 kfree(root_devname);
2799 return root_mnt;
2800}
2801
Al Virob514f872011-03-16 06:26:11 -04002802static void nfs_fix_devname(struct dentry *dentry, struct vfsmount *mnt)
Trond Myklebustb88f8a52009-06-22 15:09:14 -04002803{
2804 char *page = (char *) __get_free_page(GFP_KERNEL);
2805 char *devname, *tmp;
Al Virob514f872011-03-16 06:26:11 -04002806 char *dummy;
Trond Myklebustb88f8a52009-06-22 15:09:14 -04002807
2808 if (page == NULL)
2809 return;
Al Virob514f872011-03-16 06:26:11 -04002810 devname = nfs_path(&dummy, dentry, page, PAGE_SIZE);
Dan Carpentercdd29ec2010-04-22 15:35:56 -04002811 if (IS_ERR(devname))
Trond Myklebustb88f8a52009-06-22 15:09:14 -04002812 goto out_freepage;
2813 tmp = kstrdup(devname, GFP_KERNEL);
2814 if (tmp == NULL)
2815 goto out_freepage;
2816 kfree(mnt->mnt_devname);
2817 mnt->mnt_devname = tmp;
2818out_freepage:
2819 free_page((unsigned long)page);
2820}
2821
Trond Myklebustce587e02010-04-16 16:22:52 -04002822struct nfs_referral_count {
2823 struct list_head list;
2824 const struct task_struct *task;
2825 unsigned int referral_count;
2826};
2827
2828static LIST_HEAD(nfs_referral_count_list);
2829static DEFINE_SPINLOCK(nfs_referral_count_list_lock);
2830
2831static struct nfs_referral_count *nfs_find_referral_count(void)
2832{
2833 struct nfs_referral_count *p;
2834
2835 list_for_each_entry(p, &nfs_referral_count_list, list) {
2836 if (p->task == current)
2837 return p;
2838 }
2839 return NULL;
2840}
2841
2842#define NFS_MAX_NESTED_REFERRALS 2
2843
2844static int nfs_referral_loop_protect(void)
2845{
2846 struct nfs_referral_count *p, *new;
2847 int ret = -ENOMEM;
2848
2849 new = kmalloc(sizeof(*new), GFP_KERNEL);
2850 if (!new)
2851 goto out;
2852 new->task = current;
2853 new->referral_count = 1;
2854
2855 ret = 0;
2856 spin_lock(&nfs_referral_count_list_lock);
2857 p = nfs_find_referral_count();
2858 if (p != NULL) {
2859 if (p->referral_count >= NFS_MAX_NESTED_REFERRALS)
2860 ret = -ELOOP;
2861 else
2862 p->referral_count++;
2863 } else {
2864 list_add(&new->list, &nfs_referral_count_list);
2865 new = NULL;
2866 }
2867 spin_unlock(&nfs_referral_count_list_lock);
2868 kfree(new);
2869out:
2870 return ret;
2871}
2872
2873static void nfs_referral_loop_unprotect(void)
2874{
2875 struct nfs_referral_count *p;
2876
2877 spin_lock(&nfs_referral_count_list_lock);
2878 p = nfs_find_referral_count();
2879 p->referral_count--;
2880 if (p->referral_count == 0)
2881 list_del(&p->list);
2882 else
2883 p = NULL;
2884 spin_unlock(&nfs_referral_count_list_lock);
2885 kfree(p);
2886}
2887
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002888static int nfs_follow_remote_path(struct vfsmount *root_mnt,
2889 const char *export_path, struct vfsmount *mnt_target)
2890{
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002891 struct nameidata *nd = NULL;
Linus Torvaldsa2770d82009-12-17 12:51:05 -08002892 struct mnt_namespace *ns_private;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002893 struct super_block *s;
2894 int ret;
2895
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002896 nd = kmalloc(sizeof(*nd), GFP_KERNEL);
2897 if (nd == NULL)
2898 return -ENOMEM;
2899
Linus Torvaldsa2770d82009-12-17 12:51:05 -08002900 ns_private = create_mnt_ns(root_mnt);
2901 ret = PTR_ERR(ns_private);
2902 if (IS_ERR(ns_private))
2903 goto out_mntput;
2904
Trond Myklebustce587e02010-04-16 16:22:52 -04002905 ret = nfs_referral_loop_protect();
2906 if (ret != 0)
2907 goto out_put_mnt_ns;
2908
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002909 ret = vfs_path_lookup(root_mnt->mnt_root, root_mnt,
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002910 export_path, LOOKUP_FOLLOW, nd);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002911
Trond Myklebustce587e02010-04-16 16:22:52 -04002912 nfs_referral_loop_unprotect();
Linus Torvaldsa2770d82009-12-17 12:51:05 -08002913 put_mnt_ns(ns_private);
2914
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002915 if (ret != 0)
2916 goto out_err;
2917
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002918 s = nd->path.mnt->mnt_sb;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002919 atomic_inc(&s->s_active);
2920 mnt_target->mnt_sb = s;
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002921 mnt_target->mnt_root = dget(nd->path.dentry);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002922
Trond Myklebustb88f8a52009-06-22 15:09:14 -04002923 /* Correct the device pathname */
Al Virob514f872011-03-16 06:26:11 -04002924 nfs_fix_devname(nd->path.dentry, mnt_target);
Trond Myklebustb88f8a52009-06-22 15:09:14 -04002925
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002926 path_put(&nd->path);
2927 kfree(nd);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002928 down_write(&s->s_umount);
2929 return 0;
Trond Myklebustce587e02010-04-16 16:22:52 -04002930out_put_mnt_ns:
2931 put_mnt_ns(ns_private);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002932out_mntput:
2933 mntput(root_mnt);
2934out_err:
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002935 kfree(nd);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002936 return ret;
2937}
2938
Chuck Levera6fe23b2009-09-08 19:50:00 -04002939static int nfs4_try_mount(int flags, const char *dev_name,
2940 struct nfs_parsed_mount_data *data,
2941 struct vfsmount *mnt)
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002942{
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002943 char *export_path;
2944 struct vfsmount *root_mnt;
Chuck Levera6fe23b2009-09-08 19:50:00 -04002945 int error;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002946
Chuck Levera6fe23b2009-09-08 19:50:00 -04002947 dfprintk(MOUNT, "--> nfs4_try_mount()\n");
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002948
2949 export_path = data->nfs_server.export_path;
2950 data->nfs_server.export_path = "/";
2951 root_mnt = nfs_do_root_mount(&nfs4_remote_fs_type, flags, data,
2952 data->nfs_server.hostname);
2953 data->nfs_server.export_path = export_path;
2954
2955 error = PTR_ERR(root_mnt);
2956 if (IS_ERR(root_mnt))
2957 goto out;
2958
2959 error = nfs_follow_remote_path(root_mnt, export_path, mnt);
2960
2961out:
Chuck Levera6fe23b2009-09-08 19:50:00 -04002962 dfprintk(MOUNT, "<-- nfs4_try_mount() = %d%s\n", error,
2963 error != 0 ? " [error]" : "");
2964 return error;
2965}
2966
2967/*
2968 * Get the superblock for an NFS4 mountpoint
2969 */
2970static int nfs4_get_sb(struct file_system_type *fs_type,
2971 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2972{
2973 struct nfs_parsed_mount_data *data;
2974 int error = -ENOMEM;
2975
Trond Myklebustc5811db2009-10-06 15:40:15 -04002976 data = nfs_alloc_parsed_mount_data(4);
Chuck Levera6fe23b2009-09-08 19:50:00 -04002977 if (data == NULL)
2978 goto out_free_data;
2979
2980 /* Validate the mount data */
2981 error = nfs4_validate_mount_data(raw_data, data, dev_name);
2982 if (error < 0)
2983 goto out;
2984
2985 error = nfs4_try_mount(flags, dev_name, data, mnt);
2986
2987out:
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002988 kfree(data->client_address);
2989 kfree(data->nfs_server.export_path);
2990 kfree(data->nfs_server.hostname);
2991 kfree(data->fscache_uniq);
2992out_free_data:
2993 kfree(data);
2994 dprintk("<-- nfs4_get_sb() = %d%s\n", error,
2995 error != 0 ? " [error]" : "");
2996 return error;
2997}
2998
David Howellsf7b422b2006-06-09 09:34:33 -04002999static void nfs4_kill_super(struct super_block *sb)
3000{
3001 struct nfs_server *server = NFS_SB(sb);
3002
Andy Adamson0f3e66c2009-04-01 09:22:34 -04003003 dprintk("--> %s\n", __func__);
Trond Myklebust515d8612008-12-23 15:21:46 -05003004 nfs_super_return_all_delegations(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04003005 kill_anon_super(sb);
David Howells08734042009-04-03 16:42:42 +01003006 nfs_fscache_release_super_cookie(sb);
David Howells54ceac42006-08-22 20:06:13 -04003007 nfs_free_server(server);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04003008 dprintk("<-- %s\n", __func__);
David Howellsf7b422b2006-06-09 09:34:33 -04003009}
3010
3011/*
David Howells54ceac42006-08-22 20:06:13 -04003012 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -04003013 */
Al Viro31f43472010-10-29 03:38:12 -04003014static struct dentry *
3015nfs4_xdev_mount(struct file_system_type *fs_type, int flags,
3016 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04003017{
3018 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04003019 struct super_block *s;
3020 struct nfs_server *server;
3021 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04003022 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04003023 struct nfs_sb_mountdata sb_mntdata = {
3024 .mntflags = flags,
3025 };
David Howells54ceac42006-08-22 20:06:13 -04003026 int error;
3027
Al Viro31f43472010-10-29 03:38:12 -04003028 dprintk("--> nfs4_xdev_mount()\n");
David Howells54ceac42006-08-22 20:06:13 -04003029
3030 /* create a new volume representation */
3031 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
3032 if (IS_ERR(server)) {
3033 error = PTR_ERR(server);
3034 goto out_err_noserver;
3035 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04003036 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04003037
Trond Myklebust75180df2007-05-16 16:53:28 -04003038 if (server->flags & NFS4_MOUNT_UNSHARED)
3039 compare_super = NULL;
3040
David Howells54ceac42006-08-22 20:06:13 -04003041 /* Get a superblock - note that we may end up sharing one that already exists */
Andy Adamsonec9a05c2008-10-17 10:44:37 -04003042 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04003043 if (IS_ERR(s)) {
3044 error = PTR_ERR(s);
3045 goto out_err_nosb;
3046 }
3047
3048 if (s->s_fs_info != server) {
3049 nfs_free_server(server);
3050 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07003051 } else {
3052 error = nfs_bdi_register(server);
3053 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11003054 goto error_splat_bdi;
David Howells54ceac42006-08-22 20:06:13 -04003055 }
3056
3057 if (!s->s_root) {
3058 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04003059 nfs4_clone_super(s, data->sb);
David Howells2df54802009-09-23 14:36:39 -04003060 nfs_fscache_get_super_cookie(s, NULL, data);
David Howells54ceac42006-08-22 20:06:13 -04003061 }
3062
Al Viro0d5839a2011-03-16 05:27:27 -04003063 mntroot = nfs4_get_root(s, data->fh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04003064 if (IS_ERR(mntroot)) {
3065 error = PTR_ERR(mntroot);
3066 goto error_splat_super;
3067 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05003068 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
3069 dput(mntroot);
3070 error = -ESTALE;
3071 goto error_splat_super;
3072 }
David Howells54ceac42006-08-22 20:06:13 -04003073
3074 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04003075
Eric Paris46c8ac72008-05-02 13:42:42 -07003076 security_sb_clone_mnt_opts(data->sb, s);
3077
Al Viro31f43472010-10-29 03:38:12 -04003078 dprintk("<-- nfs4_xdev_mount() = 0\n");
3079 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04003080
3081out_err_nosb:
3082 nfs_free_server(server);
3083out_err_noserver:
Al Viro31f43472010-10-29 03:38:12 -04003084 dprintk("<-- nfs4_xdev_mount() = %d [error]\n", error);
3085 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04003086
3087error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11003088 if (server && !s->s_root)
3089 bdi_unregister(&server->backing_dev_info);
3090error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04003091 deactivate_locked_super(s);
Al Viro31f43472010-10-29 03:38:12 -04003092 dprintk("<-- nfs4_xdev_mount() = %d [splat]\n", error);
3093 return ERR_PTR(error);
David Howellsf7b422b2006-06-09 09:34:33 -04003094}
3095
Al Viro31f43472010-10-29 03:38:12 -04003096static struct dentry *
3097nfs4_remote_referral_mount(struct file_system_type *fs_type, int flags,
3098 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04003099{
3100 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04003101 struct super_block *s;
3102 struct nfs_server *server;
3103 struct dentry *mntroot;
Trond Myklebust4f727292010-04-16 16:22:48 -04003104 struct nfs_fh *mntfh;
Trond Myklebust75180df2007-05-16 16:53:28 -04003105 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04003106 struct nfs_sb_mountdata sb_mntdata = {
3107 .mntflags = flags,
3108 };
Trond Myklebust4f727292010-04-16 16:22:48 -04003109 int error = -ENOMEM;
David Howells54ceac42006-08-22 20:06:13 -04003110
3111 dprintk("--> nfs4_referral_get_sb()\n");
3112
Trond Myklebust4f727292010-04-16 16:22:48 -04003113 mntfh = nfs_alloc_fhandle();
3114 if (mntfh == NULL)
3115 goto out_err_nofh;
3116
David Howells54ceac42006-08-22 20:06:13 -04003117 /* create a new volume representation */
Trond Myklebust4f727292010-04-16 16:22:48 -04003118 server = nfs4_create_referral_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04003119 if (IS_ERR(server)) {
3120 error = PTR_ERR(server);
3121 goto out_err_noserver;
3122 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04003123 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04003124
Trond Myklebust75180df2007-05-16 16:53:28 -04003125 if (server->flags & NFS4_MOUNT_UNSHARED)
3126 compare_super = NULL;
3127
David Howells54ceac42006-08-22 20:06:13 -04003128 /* Get a superblock - note that we may end up sharing one that already exists */
Andy Adamsonec9a05c2008-10-17 10:44:37 -04003129 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04003130 if (IS_ERR(s)) {
3131 error = PTR_ERR(s);
3132 goto out_err_nosb;
3133 }
3134
3135 if (s->s_fs_info != server) {
3136 nfs_free_server(server);
3137 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07003138 } else {
3139 error = nfs_bdi_register(server);
3140 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11003141 goto error_splat_bdi;
David Howells54ceac42006-08-22 20:06:13 -04003142 }
3143
3144 if (!s->s_root) {
3145 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04003146 nfs4_fill_super(s);
David Howells2df54802009-09-23 14:36:39 -04003147 nfs_fscache_get_super_cookie(s, NULL, data);
David Howells54ceac42006-08-22 20:06:13 -04003148 }
3149
Al Viro0d5839a2011-03-16 05:27:27 -04003150 mntroot = nfs4_get_root(s, mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04003151 if (IS_ERR(mntroot)) {
3152 error = PTR_ERR(mntroot);
3153 goto error_splat_super;
3154 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05003155 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
3156 dput(mntroot);
3157 error = -ESTALE;
3158 goto error_splat_super;
3159 }
David Howells54ceac42006-08-22 20:06:13 -04003160
3161 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04003162
Eric Paris46c8ac72008-05-02 13:42:42 -07003163 security_sb_clone_mnt_opts(data->sb, s);
3164
Trond Myklebust4f727292010-04-16 16:22:48 -04003165 nfs_free_fhandle(mntfh);
David Howells54ceac42006-08-22 20:06:13 -04003166 dprintk("<-- nfs4_referral_get_sb() = 0\n");
Al Viro31f43472010-10-29 03:38:12 -04003167 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04003168
3169out_err_nosb:
3170 nfs_free_server(server);
3171out_err_noserver:
Trond Myklebust4f727292010-04-16 16:22:48 -04003172 nfs_free_fhandle(mntfh);
3173out_err_nofh:
David Howells54ceac42006-08-22 20:06:13 -04003174 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
Al Viro31f43472010-10-29 03:38:12 -04003175 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04003176
3177error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11003178 if (server && !s->s_root)
3179 bdi_unregister(&server->backing_dev_info);
3180error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04003181 deactivate_locked_super(s);
Trond Myklebust4f727292010-04-16 16:22:48 -04003182 nfs_free_fhandle(mntfh);
David Howells54ceac42006-08-22 20:06:13 -04003183 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
Al Viro31f43472010-10-29 03:38:12 -04003184 return ERR_PTR(error);
David Howellsf7b422b2006-06-09 09:34:33 -04003185}
3186
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04003187/*
3188 * Create an NFS4 server record on referral traversal
3189 */
3190static int nfs4_referral_get_sb(struct file_system_type *fs_type,
3191 int flags, const char *dev_name, void *raw_data,
3192 struct vfsmount *mnt)
3193{
3194 struct nfs_clone_mount *data = raw_data;
3195 char *export_path;
3196 struct vfsmount *root_mnt;
3197 int error;
3198
3199 dprintk("--> nfs4_referral_get_sb()\n");
3200
3201 export_path = data->mnt_path;
3202 data->mnt_path = "/";
3203
3204 root_mnt = nfs_do_root_mount(&nfs4_remote_referral_fs_type,
3205 flags, data, data->hostname);
3206 data->mnt_path = export_path;
3207
3208 error = PTR_ERR(root_mnt);
3209 if (IS_ERR(root_mnt))
3210 goto out;
3211
3212 error = nfs_follow_remote_path(root_mnt, export_path, mnt);
3213out:
3214 dprintk("<-- nfs4_referral_get_sb() = %d%s\n", error,
3215 error != 0 ? " [error]" : "");
3216 return error;
3217}
3218
David Howells54ceac42006-08-22 20:06:13 -04003219#endif /* CONFIG_NFS_V4 */