blob: ab58bb9b6115d21f859b5ad9f8fc6079173c797a [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/namei.h>
David Howellsf7b422b2006-06-09 09:34:33 -040045#include <linux/nfs_idmap.h>
46#include <linux/vfs.h>
47#include <linux/inet.h>
Chuck Leverfd00a8f2007-12-10 14:57:38 -050048#include <linux/in6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090049#include <linux/slab.h>
Chuck Leverfd00a8f2007-12-10 14:57:38 -050050#include <net/ipv6.h>
Chuck Leverd8e77482008-06-23 12:37:01 -040051#include <linux/netdevice.h>
David Howellsf7b422b2006-06-09 09:34:33 -040052#include <linux/nfs_xdr.h>
Adrian Bunkb5d5dfb2007-02-12 00:53:40 -080053#include <linux/magic.h>
Chuck Leverbf0fd762007-07-01 12:13:44 -040054#include <linux/parser.h>
Stanislav Kinsburskye50a7a12012-01-10 16:12:46 +040055#include <linux/nsproxy.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"
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +030066#include "pnfs.h"
David Howellsf7b422b2006-06-09 09:34:33 -040067
68#define NFSDBG_FACILITY NFSDBG_VFS
69
Paulius Zaleckas1e657bd2010-10-31 18:21:05 +020070#ifdef CONFIG_NFS_V3
71#define NFS_DEFAULT_VERSION 3
72#else
73#define NFS_DEFAULT_VERSION 2
74#endif
75
Chuck Leverbf0fd762007-07-01 12:13:44 -040076enum {
77 /* Mount options that take no arguments */
78 Opt_soft, Opt_hard,
Chuck Leverbf0fd762007-07-01 12:13:44 -040079 Opt_posix, Opt_noposix,
80 Opt_cto, Opt_nocto,
81 Opt_ac, Opt_noac,
82 Opt_lock, Opt_nolock,
Weston Andros Adamson7ced2862012-02-07 11:49:11 -050083 Opt_v2, Opt_v3, Opt_v4, Opt_v4_0, Opt_v4_1,
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -040084 Opt_udp, Opt_tcp, Opt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -040085 Opt_acl, Opt_noacl,
86 Opt_rdirplus, Opt_nordirplus,
Trond Myklebust75180df2007-05-16 16:53:28 -040087 Opt_sharecache, Opt_nosharecache,
Chuck Leverd7403512008-12-23 15:21:37 -050088 Opt_resvport, Opt_noresvport,
David Howellsb797cac2009-04-03 16:42:48 +010089 Opt_fscache, Opt_nofscache,
Chuck Leverbf0fd762007-07-01 12:13:44 -040090
91 /* Mount options that take integer arguments */
92 Opt_port,
93 Opt_rsize, Opt_wsize, Opt_bsize,
94 Opt_timeo, Opt_retrans,
95 Opt_acregmin, Opt_acregmax,
96 Opt_acdirmin, Opt_acdirmax,
97 Opt_actimeo,
98 Opt_namelen,
99 Opt_mountport,
Chuck Levere887cbc2007-10-26 13:32:29 -0400100 Opt_mountvers,
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 */
Trond Myklebust0d71b052012-03-02 13:59:49 -0500104 Opt_nfsvers,
Chuck Lever33832032007-12-10 14:59:13 -0500105 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
Chuck Lever0ac83772007-09-11 18:01:04 -0400106 Opt_addr, Opt_mountaddr, Opt_clientaddr,
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400107 Opt_lookupcache,
David Howellsb797cac2009-04-03 16:42:48 +0100108 Opt_fscache_uniq,
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400109 Opt_local_lock,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400110
Chuck Leverf45663c2008-06-24 19:28:02 -0400111 /* Special mount options */
112 Opt_userspace, Opt_deprecated, Opt_sloppy,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400113
114 Opt_err
115};
116
Steven Whitehousea447c092008-10-13 10:46:57 +0100117static const match_table_t nfs_mount_option_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400118 { Opt_userspace, "bg" },
119 { Opt_userspace, "fg" },
Chuck Leverecbb3842008-06-12 12:37:33 -0400120 { Opt_userspace, "retry=%s" },
121
Chuck Leverf45663c2008-06-24 19:28:02 -0400122 { Opt_sloppy, "sloppy" },
123
Chuck Leverbf0fd762007-07-01 12:13:44 -0400124 { Opt_soft, "soft" },
125 { Opt_hard, "hard" },
Chuck Leverd33e4df2008-06-12 12:37:41 -0400126 { Opt_deprecated, "intr" },
127 { Opt_deprecated, "nointr" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400128 { Opt_posix, "posix" },
129 { Opt_noposix, "noposix" },
130 { Opt_cto, "cto" },
131 { Opt_nocto, "nocto" },
132 { Opt_ac, "ac" },
133 { Opt_noac, "noac" },
134 { Opt_lock, "lock" },
135 { Opt_nolock, "nolock" },
136 { Opt_v2, "v2" },
137 { Opt_v3, "v3" },
Chuck Lever764302c2009-09-08 19:50:03 -0400138 { Opt_v4, "v4" },
Weston Andros Adamson7ced2862012-02-07 11:49:11 -0500139 { Opt_v4_0, "v4.0" },
140 { Opt_v4_1, "v4.1" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400141 { Opt_udp, "udp" },
142 { Opt_tcp, "tcp" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400143 { Opt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400144 { Opt_acl, "acl" },
145 { Opt_noacl, "noacl" },
146 { Opt_rdirplus, "rdirplus" },
147 { Opt_nordirplus, "nordirplus" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400148 { Opt_sharecache, "sharecache" },
149 { Opt_nosharecache, "nosharecache" },
Chuck Leverd7403512008-12-23 15:21:37 -0500150 { Opt_resvport, "resvport" },
151 { Opt_noresvport, "noresvport" },
David Howellsb797cac2009-04-03 16:42:48 +0100152 { Opt_fscache, "fsc" },
David Howellsb797cac2009-04-03 16:42:48 +0100153 { Opt_nofscache, "nofsc" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400154
Chuck Levera5a16ba2009-06-17 18:02:14 -0700155 { Opt_port, "port=%s" },
156 { Opt_rsize, "rsize=%s" },
157 { Opt_wsize, "wsize=%s" },
158 { Opt_bsize, "bsize=%s" },
159 { Opt_timeo, "timeo=%s" },
160 { Opt_retrans, "retrans=%s" },
161 { Opt_acregmin, "acregmin=%s" },
162 { Opt_acregmax, "acregmax=%s" },
163 { Opt_acdirmin, "acdirmin=%s" },
164 { Opt_acdirmax, "acdirmax=%s" },
165 { Opt_actimeo, "actimeo=%s" },
166 { Opt_namelen, "namlen=%s" },
167 { Opt_mountport, "mountport=%s" },
168 { Opt_mountvers, "mountvers=%s" },
Trond Myklebust0d71b052012-03-02 13:59:49 -0500169 { Opt_minorversion, "minorversion=%s" },
170
Chuck Levera5a16ba2009-06-17 18:02:14 -0700171 { Opt_nfsvers, "nfsvers=%s" },
172 { Opt_nfsvers, "vers=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400173
174 { Opt_sec, "sec=%s" },
175 { Opt_proto, "proto=%s" },
176 { Opt_mountproto, "mountproto=%s" },
177 { Opt_addr, "addr=%s" },
178 { Opt_clientaddr, "clientaddr=%s" },
Chuck Lever33832032007-12-10 14:59:13 -0500179 { Opt_mounthost, "mounthost=%s" },
Chuck Lever0ac83772007-09-11 18:01:04 -0400180 { Opt_mountaddr, "mountaddr=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400181
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400182 { Opt_lookupcache, "lookupcache=%s" },
Chuck Levera6d5ff62010-05-07 13:33:58 -0400183 { Opt_fscache_uniq, "fsc=%s" },
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400184 { Opt_local_lock, "local_lock=%s" },
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400185
Chuck Leverbf0fd762007-07-01 12:13:44 -0400186 { Opt_err, NULL }
187};
188
189enum {
Jeff Laytonee671b02009-12-03 15:58:56 -0500190 Opt_xprt_udp, Opt_xprt_udp6, Opt_xprt_tcp, Opt_xprt_tcp6, Opt_xprt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400191
192 Opt_xprt_err
193};
194
Steven Whitehousea447c092008-10-13 10:46:57 +0100195static const match_table_t nfs_xprt_protocol_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400196 { Opt_xprt_udp, "udp" },
Jeff Laytonee671b02009-12-03 15:58:56 -0500197 { Opt_xprt_udp6, "udp6" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400198 { Opt_xprt_tcp, "tcp" },
Jeff Laytonee671b02009-12-03 15:58:56 -0500199 { Opt_xprt_tcp6, "tcp6" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400200 { Opt_xprt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400201
202 { Opt_xprt_err, NULL }
203};
204
205enum {
206 Opt_sec_none, Opt_sec_sys,
207 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
208 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
209 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
210
211 Opt_sec_err
212};
213
Steven Whitehousea447c092008-10-13 10:46:57 +0100214static const match_table_t nfs_secflavor_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400215 { Opt_sec_none, "none" },
216 { Opt_sec_none, "null" },
217 { Opt_sec_sys, "sys" },
218
219 { Opt_sec_krb5, "krb5" },
220 { Opt_sec_krb5i, "krb5i" },
221 { Opt_sec_krb5p, "krb5p" },
222
223 { Opt_sec_lkey, "lkey" },
224 { Opt_sec_lkeyi, "lkeyi" },
225 { Opt_sec_lkeyp, "lkeyp" },
226
Olga Kornievskaia8d042212008-02-13 16:47:06 -0500227 { Opt_sec_spkm, "spkm3" },
228 { Opt_sec_spkmi, "spkm3i" },
229 { Opt_sec_spkmp, "spkm3p" },
230
Chuck Leverbf0fd762007-07-01 12:13:44 -0400231 { Opt_sec_err, NULL }
232};
233
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400234enum {
235 Opt_lookupcache_all, Opt_lookupcache_positive,
236 Opt_lookupcache_none,
237
238 Opt_lookupcache_err
239};
240
241static match_table_t nfs_lookupcache_tokens = {
242 { Opt_lookupcache_all, "all" },
243 { Opt_lookupcache_positive, "pos" },
244 { Opt_lookupcache_positive, "positive" },
245 { Opt_lookupcache_none, "none" },
246
247 { Opt_lookupcache_err, NULL }
248};
249
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400250enum {
251 Opt_local_lock_all, Opt_local_lock_flock, Opt_local_lock_posix,
252 Opt_local_lock_none,
253
254 Opt_local_lock_err
255};
256
257static match_table_t nfs_local_lock_tokens = {
258 { Opt_local_lock_all, "all" },
259 { Opt_local_lock_flock, "flock" },
260 { Opt_local_lock_posix, "posix" },
261 { Opt_local_lock_none, "none" },
262
263 { Opt_local_lock_err, NULL }
264};
265
Trond Myklebust0d71b052012-03-02 13:59:49 -0500266enum {
267 Opt_vers_2, Opt_vers_3, Opt_vers_4, Opt_vers_4_0,
268 Opt_vers_4_1,
269
270 Opt_vers_err
271};
272
273static match_table_t nfs_vers_tokens = {
274 { Opt_vers_2, "2" },
275 { Opt_vers_3, "3" },
276 { Opt_vers_4, "4" },
277 { Opt_vers_4_0, "4.0" },
278 { Opt_vers_4_1, "4.1" },
279
280 { Opt_vers_err, NULL }
281};
Chuck Leverbf0fd762007-07-01 12:13:44 -0400282
Al Viro42faad92008-04-24 07:21:56 -0400283static void nfs_umount_begin(struct super_block *);
Trond Myklebust816724e2006-06-24 08:41:41 -0400284static int nfs_statfs(struct dentry *, struct kstatfs *);
Al Viro34c80b12011-12-08 21:32:45 -0500285static int nfs_show_options(struct seq_file *, struct dentry *);
Al Virod861c632011-12-08 21:32:45 -0500286static int nfs_show_devname(struct seq_file *, struct dentry *);
Al Viroa6322de2011-12-08 21:37:57 -0500287static int nfs_show_path(struct seq_file *, struct dentry *);
Al Viro64132372011-12-08 20:51:13 -0500288static int nfs_show_stats(struct seq_file *, struct dentry *);
Al Viro01194982011-03-16 07:25:36 -0400289static struct dentry *nfs_fs_mount(struct file_system_type *,
290 int, const char *, void *);
Al Viro31f43472010-10-29 03:38:12 -0400291static struct dentry *nfs_xdev_mount(struct file_system_type *fs_type,
292 int flags, const char *dev_name, void *raw_data);
Trond Myklebust387c1492010-02-03 08:27:35 -0500293static void nfs_put_super(struct super_block *);
David Howellsf7b422b2006-06-09 09:34:33 -0400294static void nfs_kill_super(struct super_block *);
Jeff Layton48b605f2008-06-10 15:38:39 -0400295static int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
David Howellsf7b422b2006-06-09 09:34:33 -0400296
297static struct file_system_type nfs_fs_type = {
298 .owner = THIS_MODULE,
299 .name = "nfs",
Al Viro01194982011-03-16 07:25:36 -0400300 .mount = nfs_fs_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400301 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700302 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400303};
304
David Howells54ceac42006-08-22 20:06:13 -0400305struct file_system_type nfs_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400306 .owner = THIS_MODULE,
307 .name = "nfs",
Al Viro31f43472010-10-29 03:38:12 -0400308 .mount = nfs_xdev_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400309 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700310 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400311};
312
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800313static const struct super_operations nfs_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400314 .alloc_inode = nfs_alloc_inode,
315 .destroy_inode = nfs_destroy_inode,
316 .write_inode = nfs_write_inode,
Trond Myklebust387c1492010-02-03 08:27:35 -0500317 .put_super = nfs_put_super,
David Howellsf7b422b2006-06-09 09:34:33 -0400318 .statfs = nfs_statfs,
Al Virob57922d2010-06-07 14:34:48 -0400319 .evict_inode = nfs_evict_inode,
David Howellsf7b422b2006-06-09 09:34:33 -0400320 .umount_begin = nfs_umount_begin,
321 .show_options = nfs_show_options,
Al Viroc7f404b2011-03-16 06:59:40 -0400322 .show_devname = nfs_show_devname,
323 .show_path = nfs_show_path,
David Howellsf7b422b2006-06-09 09:34:33 -0400324 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400325 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400326};
327
328#ifdef CONFIG_NFS_V4
Chuck Lever7630c852009-09-08 19:49:57 -0400329static int nfs4_validate_text_mount_data(void *options,
330 struct nfs_parsed_mount_data *args, const char *dev_name);
Al Viro01194982011-03-16 07:25:36 -0400331static struct dentry *nfs4_try_mount(int flags, const char *dev_name,
332 struct nfs_parsed_mount_data *data);
333static struct dentry *nfs4_mount(struct file_system_type *fs_type,
334 int flags, const char *dev_name, void *raw_data);
Al Viro31f43472010-10-29 03:38:12 -0400335static struct dentry *nfs4_remote_mount(struct file_system_type *fs_type,
336 int flags, const char *dev_name, void *raw_data);
337static struct dentry *nfs4_xdev_mount(struct file_system_type *fs_type,
338 int flags, const char *dev_name, void *raw_data);
Al Viro01194982011-03-16 07:25:36 -0400339static struct dentry *nfs4_referral_mount(struct file_system_type *fs_type,
340 int flags, const char *dev_name, void *raw_data);
Al Viro31f43472010-10-29 03:38:12 -0400341static struct dentry *nfs4_remote_referral_mount(struct file_system_type *fs_type,
342 int flags, const char *dev_name, void *raw_data);
David Howellsf7b422b2006-06-09 09:34:33 -0400343static void nfs4_kill_super(struct super_block *sb);
344
345static struct file_system_type nfs4_fs_type = {
346 .owner = THIS_MODULE,
347 .name = "nfs4",
Al Viro01194982011-03-16 07:25:36 -0400348 .mount = nfs4_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400349 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700350 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400351};
352
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400353static struct file_system_type nfs4_remote_fs_type = {
354 .owner = THIS_MODULE,
355 .name = "nfs4",
Al Viro31f43472010-10-29 03:38:12 -0400356 .mount = nfs4_remote_mount,
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400357 .kill_sb = nfs4_kill_super,
358 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
359};
360
David Howells54ceac42006-08-22 20:06:13 -0400361struct file_system_type nfs4_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400362 .owner = THIS_MODULE,
363 .name = "nfs4",
Al Viro31f43472010-10-29 03:38:12 -0400364 .mount = nfs4_xdev_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400365 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700366 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400367};
368
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400369static struct file_system_type nfs4_remote_referral_fs_type = {
370 .owner = THIS_MODULE,
371 .name = "nfs4",
Al Viro31f43472010-10-29 03:38:12 -0400372 .mount = nfs4_remote_referral_mount,
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400373 .kill_sb = nfs4_kill_super,
374 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
375};
376
David Howells54ceac42006-08-22 20:06:13 -0400377struct file_system_type nfs4_referral_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400378 .owner = THIS_MODULE,
379 .name = "nfs4",
Al Viro01194982011-03-16 07:25:36 -0400380 .mount = nfs4_referral_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400381 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700382 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400383};
384
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800385static const struct super_operations nfs4_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400386 .alloc_inode = nfs_alloc_inode,
387 .destroy_inode = nfs_destroy_inode,
388 .write_inode = nfs_write_inode,
Trond Myklebust387c1492010-02-03 08:27:35 -0500389 .put_super = nfs_put_super,
David Howellsf7b422b2006-06-09 09:34:33 -0400390 .statfs = nfs_statfs,
Al Virob57922d2010-06-07 14:34:48 -0400391 .evict_inode = nfs4_evict_inode,
David Howellsf7b422b2006-06-09 09:34:33 -0400392 .umount_begin = nfs_umount_begin,
393 .show_options = nfs_show_options,
Al Viroc7f404b2011-03-16 06:59:40 -0400394 .show_devname = nfs_show_devname,
395 .show_path = nfs_show_path,
David Howellsf7b422b2006-06-09 09:34:33 -0400396 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400397 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400398};
399#endif
400
Rusty Russell8e1f9362007-07-17 04:03:17 -0700401static struct shrinker acl_shrinker = {
402 .shrink = nfs_access_cache_shrinker,
403 .seeks = DEFAULT_SEEKS,
404};
Trond Myklebust979df722006-07-25 11:28:19 -0400405
David Howellsf7b422b2006-06-09 09:34:33 -0400406/*
407 * Register the NFS filesystems
408 */
409int __init register_nfs_fs(void)
410{
411 int ret;
412
413 ret = register_filesystem(&nfs_fs_type);
414 if (ret < 0)
415 goto error_0;
416
David Howellsf7b422b2006-06-09 09:34:33 -0400417 ret = nfs_register_sysctl();
418 if (ret < 0)
419 goto error_1;
Peter Zijlstra89a09142007-03-16 13:38:26 -0800420#ifdef CONFIG_NFS_V4
David Howellsf7b422b2006-06-09 09:34:33 -0400421 ret = register_filesystem(&nfs4_fs_type);
422 if (ret < 0)
423 goto error_2;
424#endif
Rusty Russell8e1f9362007-07-17 04:03:17 -0700425 register_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400426 return 0;
427
428#ifdef CONFIG_NFS_V4
429error_2:
430 nfs_unregister_sysctl();
Peter Zijlstra89a09142007-03-16 13:38:26 -0800431#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400432error_1:
433 unregister_filesystem(&nfs_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400434error_0:
435 return ret;
436}
437
438/*
439 * Unregister the NFS filesystems
440 */
441void __exit unregister_nfs_fs(void)
442{
Rusty Russell8e1f9362007-07-17 04:03:17 -0700443 unregister_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400444#ifdef CONFIG_NFS_V4
445 unregister_filesystem(&nfs4_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400446#endif
Alexey Dobriyan49af7ee2007-09-18 22:46:40 -0700447 nfs_unregister_sysctl();
David Howellsf7b422b2006-06-09 09:34:33 -0400448 unregister_filesystem(&nfs_fs_type);
449}
450
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400451void nfs_sb_active(struct super_block *sb)
Steve Dicksonef818a22007-11-08 04:05:04 -0500452{
453 struct nfs_server *server = NFS_SB(sb);
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400454
455 if (atomic_inc_return(&server->active) == 1)
456 atomic_inc(&sb->s_active);
457}
458
459void nfs_sb_deactive(struct super_block *sb)
460{
461 struct nfs_server *server = NFS_SB(sb);
462
463 if (atomic_dec_and_test(&server->active))
464 deactivate_super(sb);
Steve Dicksonef818a22007-11-08 04:05:04 -0500465}
466
David Howellsf7b422b2006-06-09 09:34:33 -0400467/*
468 * Deliver file system statistics to userspace
469 */
Trond Myklebust816724e2006-06-24 08:41:41 -0400470static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
David Howellsf7b422b2006-06-09 09:34:33 -0400471{
David Howells0c7d90c2006-08-22 20:06:10 -0400472 struct nfs_server *server = NFS_SB(dentry->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400473 unsigned char blockbits;
474 unsigned long blockres;
David Howells0c7d90c2006-08-22 20:06:10 -0400475 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400476 struct nfs_fsstat res;
477 int error = -ENOMEM;
478
479 res.fattr = nfs_alloc_fattr();
480 if (res.fattr == NULL)
481 goto out_err;
David Howellsf7b422b2006-06-09 09:34:33 -0400482
David Howells8fa5c002006-08-22 20:06:12 -0400483 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
Menyhart Zoltanfbf3fdd2010-09-12 19:55:26 -0400484 if (unlikely(error == -ESTALE)) {
485 struct dentry *pd_dentry;
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400486
Menyhart Zoltanfbf3fdd2010-09-12 19:55:26 -0400487 pd_dentry = dget_parent(dentry);
488 if (pd_dentry != NULL) {
489 nfs_zap_caches(pd_dentry->d_inode);
490 dput(pd_dentry);
491 }
492 }
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400493 nfs_free_fattr(res.fattr);
David Howellsf7b422b2006-06-09 09:34:33 -0400494 if (error < 0)
495 goto out_err;
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400496
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700497 buf->f_type = NFS_SUPER_MAGIC;
David Howellsf7b422b2006-06-09 09:34:33 -0400498
499 /*
500 * Current versions of glibc do not correctly handle the
501 * case where f_frsize != f_bsize. Eventually we want to
502 * report the value of wtmult in this field.
503 */
David Howells0c7d90c2006-08-22 20:06:10 -0400504 buf->f_frsize = dentry->d_sb->s_blocksize;
David Howellsf7b422b2006-06-09 09:34:33 -0400505
506 /*
507 * On most *nix systems, f_blocks, f_bfree, and f_bavail
508 * are reported in units of f_frsize. Linux hasn't had
509 * an f_frsize field in its statfs struct until recently,
510 * thus historically Linux's sys_statfs reports these
511 * fields in units of f_bsize.
512 */
David Howells0c7d90c2006-08-22 20:06:10 -0400513 buf->f_bsize = dentry->d_sb->s_blocksize;
514 blockbits = dentry->d_sb->s_blocksize_bits;
David Howellsf7b422b2006-06-09 09:34:33 -0400515 blockres = (1 << blockbits) - 1;
516 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
517 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
518 buf->f_bavail = (res.abytes + blockres) >> blockbits;
519
520 buf->f_files = res.tfiles;
521 buf->f_ffree = res.afiles;
522
523 buf->f_namelen = server->namelen;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700524
David Howellsf7b422b2006-06-09 09:34:33 -0400525 return 0;
526
527 out_err:
Harvey Harrison3110ff82008-05-02 13:42:44 -0700528 dprintk("%s: statfs error = %d\n", __func__, -error);
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700529 return error;
David Howellsf7b422b2006-06-09 09:34:33 -0400530}
531
David Howells7d4e2742006-08-22 20:06:07 -0400532/*
533 * Map the security flavour number to a name
534 */
Trond Myklebust81039f12006-06-09 09:34:34 -0400535static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
536{
David Howells7d4e2742006-08-22 20:06:07 -0400537 static const struct {
Trond Myklebust81039f12006-06-09 09:34:34 -0400538 rpc_authflavor_t flavour;
539 const char *str;
540 } sec_flavours[] = {
541 { RPC_AUTH_NULL, "null" },
542 { RPC_AUTH_UNIX, "sys" },
543 { RPC_AUTH_GSS_KRB5, "krb5" },
544 { RPC_AUTH_GSS_KRB5I, "krb5i" },
545 { RPC_AUTH_GSS_KRB5P, "krb5p" },
546 { RPC_AUTH_GSS_LKEY, "lkey" },
547 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
548 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
549 { RPC_AUTH_GSS_SPKM, "spkm" },
550 { RPC_AUTH_GSS_SPKMI, "spkmi" },
551 { RPC_AUTH_GSS_SPKMP, "spkmp" },
Chuck Lever4d81cd12007-07-01 12:12:40 -0400552 { UINT_MAX, "unknown" }
Trond Myklebust81039f12006-06-09 09:34:34 -0400553 };
554 int i;
555
Chuck Lever4d81cd12007-07-01 12:12:40 -0400556 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
Trond Myklebust81039f12006-06-09 09:34:34 -0400557 if (sec_flavours[i].flavour == flavour)
558 break;
559 }
560 return sec_flavours[i].str;
561}
562
Jeff Laytonee671b02009-12-03 15:58:56 -0500563static void nfs_show_mountd_netid(struct seq_file *m, struct nfs_server *nfss,
564 int showdefaults)
565{
566 struct sockaddr *sap = (struct sockaddr *) &nfss->mountd_address;
567
568 seq_printf(m, ",mountproto=");
569 switch (sap->sa_family) {
570 case AF_INET:
571 switch (nfss->mountd_protocol) {
572 case IPPROTO_UDP:
573 seq_printf(m, RPCBIND_NETID_UDP);
574 break;
575 case IPPROTO_TCP:
576 seq_printf(m, RPCBIND_NETID_TCP);
577 break;
578 default:
579 if (showdefaults)
580 seq_printf(m, "auto");
581 }
582 break;
583 case AF_INET6:
584 switch (nfss->mountd_protocol) {
585 case IPPROTO_UDP:
586 seq_printf(m, RPCBIND_NETID_UDP6);
587 break;
588 case IPPROTO_TCP:
589 seq_printf(m, RPCBIND_NETID_TCP6);
590 break;
591 default:
592 if (showdefaults)
593 seq_printf(m, "auto");
594 }
595 break;
596 default:
597 if (showdefaults)
598 seq_printf(m, "auto");
599 }
600}
601
Chuck Lever82d101d2008-03-14 14:10:37 -0400602static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
603 int showdefaults)
604{
605 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
606
Bryan Schumakerd5eff1a2010-08-03 13:04:00 -0400607 if (nfss->flags & NFS_MOUNT_LEGACY_INTERFACE)
608 return;
609
Chuck Lever82d101d2008-03-14 14:10:37 -0400610 switch (sap->sa_family) {
611 case AF_INET: {
612 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
Harvey Harrisonbe859402008-10-31 00:56:28 -0700613 seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400614 break;
615 }
616 case AF_INET6: {
617 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
Chuck Leverd250e192009-12-03 15:58:56 -0500618 seq_printf(m, ",mountaddr=%pI6c", &sin6->sin6_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400619 break;
620 }
621 default:
622 if (showdefaults)
623 seq_printf(m, ",mountaddr=unspecified");
624 }
625
626 if (nfss->mountd_version || showdefaults)
627 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
Stanislav Kinsburskyaa699472010-12-08 12:40:13 +0300628 if ((nfss->mountd_port &&
629 nfss->mountd_port != (unsigned short)NFS_UNSPEC_PORT) ||
630 showdefaults)
Chuck Lever82d101d2008-03-14 14:10:37 -0400631 seq_printf(m, ",mountport=%u", nfss->mountd_port);
632
Jeff Laytonee671b02009-12-03 15:58:56 -0500633 nfs_show_mountd_netid(m, nfss, showdefaults);
Chuck Lever82d101d2008-03-14 14:10:37 -0400634}
635
Trond Myklebust0be81892010-06-18 12:23:58 -0400636#ifdef CONFIG_NFS_V4
637static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
638 int showdefaults)
639{
640 struct nfs_client *clp = nfss->nfs_client;
641
642 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
643 seq_printf(m, ",minorversion=%u", clp->cl_minorversion);
644}
645#else
646static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
647 int showdefaults)
648{
649}
650#endif
651
David Howellsf7b422b2006-06-09 09:34:33 -0400652/*
653 * Describe the mount options in force on this server representation
654 */
Chuck Lever82d101d2008-03-14 14:10:37 -0400655static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
656 int showdefaults)
David Howellsf7b422b2006-06-09 09:34:33 -0400657{
David Howells509de812006-08-22 20:06:11 -0400658 static const struct proc_nfs_info {
David Howellsf7b422b2006-06-09 09:34:33 -0400659 int flag;
David Howells509de812006-08-22 20:06:11 -0400660 const char *str;
661 const char *nostr;
David Howellsf7b422b2006-06-09 09:34:33 -0400662 } nfs_info[] = {
663 { NFS_MOUNT_SOFT, ",soft", ",hard" },
Chuck Lever82d101d2008-03-14 14:10:37 -0400664 { NFS_MOUNT_POSIX, ",posix", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400665 { NFS_MOUNT_NOCTO, ",nocto", "" },
666 { NFS_MOUNT_NOAC, ",noac", "" },
667 { NFS_MOUNT_NONLM, ",nolock", "" },
668 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400669 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
Chuck Leverd7403512008-12-23 15:21:37 -0500670 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
671 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400672 { 0, NULL, NULL }
673 };
David Howells509de812006-08-22 20:06:11 -0400674 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400675 struct nfs_client *clp = nfss->nfs_client;
Chuck Lever82d101d2008-03-14 14:10:37 -0400676 u32 version = clp->rpc_ops->version;
Suresh Jayaraman7c563cc2010-09-23 14:26:48 -0400677 int local_flock, local_fcntl;
David Howellsf7b422b2006-06-09 09:34:33 -0400678
Chuck Lever82d101d2008-03-14 14:10:37 -0400679 seq_printf(m, ",vers=%u", version);
Chuck Lever2d767432008-03-14 14:10:08 -0400680 seq_printf(m, ",rsize=%u", nfss->rsize);
681 seq_printf(m, ",wsize=%u", nfss->wsize);
Chuck Lever82d101d2008-03-14 14:10:37 -0400682 if (nfss->bsize != 0)
683 seq_printf(m, ",bsize=%u", nfss->bsize);
684 seq_printf(m, ",namlen=%u", nfss->namelen);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400685 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400686 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400687 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400688 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400689 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400690 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400691 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400692 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
David Howellsf7b422b2006-06-09 09:34:33 -0400693 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
694 if (nfss->flags & nfs_infop->flag)
695 seq_puts(m, nfs_infop->str);
696 else
697 seq_puts(m, nfs_infop->nostr);
698 }
\"Talpey, Thomas\56928ed2007-09-10 13:48:47 -0400699 seq_printf(m, ",proto=%s",
Jeff Laytonee671b02009-12-03 15:58:56 -0500700 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
Chuck Lever82d101d2008-03-14 14:10:37 -0400701 if (version == 4) {
702 if (nfss->port != NFS_PORT)
703 seq_printf(m, ",port=%u", nfss->port);
704 } else
705 if (nfss->port)
706 seq_printf(m, ",port=%u", nfss->port);
707
Trond Myklebust33170232007-12-20 16:03:59 -0500708 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
709 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
Trond Myklebust81039f12006-06-09 09:34:34 -0400710 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
Chuck Lever82d101d2008-03-14 14:10:37 -0400711
712 if (version != 4)
713 nfs_show_mountd_options(m, nfss, showdefaults);
Trond Myklebust0be81892010-06-18 12:23:58 -0400714 else
715 nfs_show_nfsv4_options(m, nfss, showdefaults);
Chuck Lever82d101d2008-03-14 14:10:37 -0400716
David Howellsb797cac2009-04-03 16:42:48 +0100717 if (nfss->options & NFS_OPTION_FSCACHE)
718 seq_printf(m, ",fsc");
Patrick J. LoPresti9b00c642010-08-10 17:28:01 -0400719
720 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONEG) {
721 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONE)
722 seq_printf(m, ",lookupcache=none");
723 else
724 seq_printf(m, ",lookupcache=pos");
725 }
Suresh Jayaraman7c563cc2010-09-23 14:26:48 -0400726
727 local_flock = nfss->flags & NFS_MOUNT_LOCAL_FLOCK;
728 local_fcntl = nfss->flags & NFS_MOUNT_LOCAL_FCNTL;
729
730 if (!local_flock && !local_fcntl)
731 seq_printf(m, ",local_lock=none");
732 else if (local_flock && local_fcntl)
733 seq_printf(m, ",local_lock=all");
734 else if (local_flock)
735 seq_printf(m, ",local_lock=flock");
736 else
737 seq_printf(m, ",local_lock=posix");
David Howellsf7b422b2006-06-09 09:34:33 -0400738}
739
740/*
741 * Describe the mount options on this VFS mountpoint
742 */
Al Viro34c80b12011-12-08 21:32:45 -0500743static int nfs_show_options(struct seq_file *m, struct dentry *root)
David Howellsf7b422b2006-06-09 09:34:33 -0400744{
Al Viro34c80b12011-12-08 21:32:45 -0500745 struct nfs_server *nfss = NFS_SB(root->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400746
747 nfs_show_mount_options(m, nfss, 0);
748
Chuck Lever5d8515c2007-12-10 14:57:16 -0500749 seq_printf(m, ",addr=%s",
750 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
751 RPC_DISPLAY_ADDR));
David Howellsf7b422b2006-06-09 09:34:33 -0400752
753 return 0;
754}
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700755
756#ifdef CONFIG_NFS_V4
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300757#ifdef CONFIG_NFS_V4_1
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700758static void show_sessions(struct seq_file *m, struct nfs_server *server)
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300759{
760 if (nfs4_has_session(server->nfs_client))
761 seq_printf(m, ",sessions");
762}
763#else
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700764static void show_sessions(struct seq_file *m, struct nfs_server *server) {}
765#endif
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300766#endif
767
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700768#ifdef CONFIG_NFS_V4
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300769#ifdef CONFIG_NFS_V4_1
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700770static void show_pnfs(struct seq_file *m, struct nfs_server *server)
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300771{
772 seq_printf(m, ",pnfs=");
773 if (server->pnfs_curr_ld)
774 seq_printf(m, "%s", server->pnfs_curr_ld->name);
775 else
776 seq_printf(m, "not configured");
777}
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700778#else
779static void show_pnfs(struct seq_file *m, struct nfs_server *server) {}
780#endif
781#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400782
Al Virod861c632011-12-08 21:32:45 -0500783static int nfs_show_devname(struct seq_file *m, struct dentry *root)
Al Viroc7f404b2011-03-16 06:59:40 -0400784{
785 char *page = (char *) __get_free_page(GFP_KERNEL);
786 char *devname, *dummy;
787 int err = 0;
788 if (!page)
789 return -ENOMEM;
Al Virod861c632011-12-08 21:32:45 -0500790 devname = nfs_path(&dummy, root, page, PAGE_SIZE);
Al Viroc7f404b2011-03-16 06:59:40 -0400791 if (IS_ERR(devname))
792 err = PTR_ERR(devname);
793 else
794 seq_escape(m, devname, " \t\n\\");
795 free_page((unsigned long)page);
796 return err;
797}
798
Al Viroa6322de2011-12-08 21:37:57 -0500799static int nfs_show_path(struct seq_file *m, struct dentry *dentry)
Al Viroc7f404b2011-03-16 06:59:40 -0400800{
801 seq_puts(m, "/");
802 return 0;
803}
804
David Howellsf7b422b2006-06-09 09:34:33 -0400805/*
806 * Present statistical information for this VFS mountpoint
807 */
Al Viro64132372011-12-08 20:51:13 -0500808static int nfs_show_stats(struct seq_file *m, struct dentry *root)
David Howellsf7b422b2006-06-09 09:34:33 -0400809{
810 int i, cpu;
Al Viro64132372011-12-08 20:51:13 -0500811 struct nfs_server *nfss = NFS_SB(root->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400812 struct rpc_auth *auth = nfss->client->cl_auth;
813 struct nfs_iostats totals = { };
814
815 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
816
817 /*
818 * Display all mount option settings
819 */
820 seq_printf(m, "\n\topts:\t");
Al Viro64132372011-12-08 20:51:13 -0500821 seq_puts(m, root->d_sb->s_flags & MS_RDONLY ? "ro" : "rw");
822 seq_puts(m, root->d_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
823 seq_puts(m, root->d_sb->s_flags & MS_NOATIME ? ",noatime" : "");
824 seq_puts(m, root->d_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
David Howellsf7b422b2006-06-09 09:34:33 -0400825 nfs_show_mount_options(m, nfss, 1);
826
827 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
828
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500829 if (nfss->nfs_client && nfss->nfs_client->impl_id) {
830 struct nfs41_impl_id *impl_id = nfss->nfs_client->impl_id;
831 seq_printf(m, "\n\timpl_id:\tname='%s',domain='%s',"
832 "date='%llu,%u'",
833 impl_id->name, impl_id->domain,
834 impl_id->date.seconds, impl_id->date.nseconds);
835 }
836
David Howellsf7b422b2006-06-09 09:34:33 -0400837 seq_printf(m, "\n\tcaps:\t");
838 seq_printf(m, "caps=0x%x", nfss->caps);
Chuck Lever2d767432008-03-14 14:10:08 -0400839 seq_printf(m, ",wtmult=%u", nfss->wtmult);
840 seq_printf(m, ",dtsize=%u", nfss->dtsize);
841 seq_printf(m, ",bsize=%u", nfss->bsize);
842 seq_printf(m, ",namlen=%u", nfss->namelen);
David Howellsf7b422b2006-06-09 09:34:33 -0400843
844#ifdef CONFIG_NFS_V4
Trond Myklebust40c553192007-12-14 14:56:07 -0500845 if (nfss->nfs_client->rpc_ops->version == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400846 seq_printf(m, "\n\tnfsv4:\t");
847 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
848 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
849 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300850 show_sessions(m, nfss);
851 show_pnfs(m, nfss);
David Howellsf7b422b2006-06-09 09:34:33 -0400852 }
853#endif
854
855 /*
856 * Display security flavor in effect for this mount
857 */
Chuck Lever2d767432008-03-14 14:10:08 -0400858 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400859 if (auth->au_flavor)
Chuck Lever2d767432008-03-14 14:10:08 -0400860 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400861
862 /*
863 * Display superblock I/O counters
864 */
865 for_each_possible_cpu(cpu) {
866 struct nfs_iostats *stats;
867
868 preempt_disable();
869 stats = per_cpu_ptr(nfss->io_stats, cpu);
870
871 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
872 totals.events[i] += stats->events[i];
873 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
874 totals.bytes[i] += stats->bytes[i];
David Howells6a510912009-04-03 16:42:43 +0100875#ifdef CONFIG_NFS_FSCACHE
876 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
877 totals.fscache[i] += stats->fscache[i];
878#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400879
880 preempt_enable();
881 }
882
883 seq_printf(m, "\n\tevents:\t");
884 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
885 seq_printf(m, "%lu ", totals.events[i]);
886 seq_printf(m, "\n\tbytes:\t");
887 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
888 seq_printf(m, "%Lu ", totals.bytes[i]);
David Howells6a510912009-04-03 16:42:43 +0100889#ifdef CONFIG_NFS_FSCACHE
890 if (nfss->options & NFS_OPTION_FSCACHE) {
891 seq_printf(m, "\n\tfsc:\t");
892 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
893 seq_printf(m, "%Lu ", totals.bytes[i]);
894 }
895#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400896 seq_printf(m, "\n");
897
898 rpc_print_iostats(m, nfss->client);
899
900 return 0;
901}
902
903/*
904 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400905 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400906 */
Al Viro42faad92008-04-24 07:21:56 -0400907static void nfs_umount_begin(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -0400908{
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200909 struct nfs_server *server;
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400910 struct rpc_clnt *rpc;
911
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200912 server = NFS_SB(sb);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400913 /* -EIO all pending I/O */
914 rpc = server->client_acl;
915 if (!IS_ERR(rpc))
916 rpc_killall_tasks(rpc);
917 rpc = server->client;
918 if (!IS_ERR(rpc))
919 rpc_killall_tasks(rpc);
David Howellsf7b422b2006-06-09 09:34:33 -0400920}
921
Trond Myklebustc5811db2009-10-06 15:40:15 -0400922static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(unsigned int version)
Chuck Lever9423a082009-09-23 14:36:38 -0400923{
924 struct nfs_parsed_mount_data *data;
925
926 data = kzalloc(sizeof(*data), GFP_KERNEL);
927 if (data) {
Chuck Lever9423a082009-09-23 14:36:38 -0400928 data->acregmin = NFS_DEF_ACREGMIN;
929 data->acregmax = NFS_DEF_ACREGMAX;
930 data->acdirmin = NFS_DEF_ACDIRMIN;
931 data->acdirmax = NFS_DEF_ACDIRMAX;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400932 data->mount_server.port = NFS_UNSPEC_PORT;
Chuck Lever9423a082009-09-23 14:36:38 -0400933 data->nfs_server.port = NFS_UNSPEC_PORT;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400934 data->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Lever9423a082009-09-23 14:36:38 -0400935 data->auth_flavors[0] = RPC_AUTH_UNIX;
936 data->auth_flavor_len = 1;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400937 data->version = version;
Chuck Lever9423a082009-09-23 14:36:38 -0400938 data->minorversion = 0;
Trond Myklebust9937347a2012-02-19 08:44:07 +0100939 data->net = current->nsproxy->net_ns;
Jeff Layton8a0d5512011-12-20 06:57:45 -0500940 security_init_mnt_opts(&data->lsm_opts);
Chuck Lever9423a082009-09-23 14:36:38 -0400941 }
942 return data;
943}
944
Jeff Layton8a0d5512011-12-20 06:57:45 -0500945static void nfs_free_parsed_mount_data(struct nfs_parsed_mount_data *data)
946{
947 if (data) {
948 kfree(data->client_address);
949 kfree(data->mount_server.hostname);
950 kfree(data->nfs_server.export_path);
951 kfree(data->nfs_server.hostname);
952 kfree(data->fscache_uniq);
953 security_free_mnt_opts(&data->lsm_opts);
954 kfree(data);
955 }
956}
957
David Howellsf7b422b2006-06-09 09:34:33 -0400958/*
Chuck Levercdcd7f92007-12-10 14:57:45 -0500959 * Sanity-check a server address provided by the mount command.
960 *
961 * Address family must be initialized, and address must not be
962 * the ANY address for that family.
Chuck Leverfc50d582007-07-01 12:12:46 -0400963 */
964static int nfs_verify_server_address(struct sockaddr *addr)
965{
966 switch (addr->sa_family) {
967 case AF_INET: {
Chuck Levercdcd7f92007-12-10 14:57:45 -0500968 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
Al Viroe6f1ceb2008-03-17 22:44:53 -0700969 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
Chuck Levercdcd7f92007-12-10 14:57:45 -0500970 }
971 case AF_INET6: {
972 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
973 return !ipv6_addr_any(sa);
Chuck Leverfc50d582007-07-01 12:12:46 -0400974 }
975 }
976
Chuck Lever53a0b9c2009-08-09 15:09:36 -0400977 dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
Chuck Leverfc50d582007-07-01 12:12:46 -0400978 return 0;
979}
980
Chuck Lever9412b922007-12-10 14:59:21 -0500981/*
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400982 * Select between a default port value and a user-specified port value.
983 * If a zero value is set, then autobind will be used.
984 */
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400985static void nfs_set_port(struct sockaddr *sap, int *port,
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400986 const unsigned short default_port)
987{
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400988 if (*port == NFS_UNSPEC_PORT)
989 *port = default_port;
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400990
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400991 rpc_set_port(sap, *port);
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400992}
993
994/*
Trond Myklebust259875e2008-07-02 14:43:47 -0400995 * Sanity check the NFS transport protocol.
996 *
997 */
998static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
999{
1000 switch (mnt->nfs_server.protocol) {
1001 case XPRT_TRANSPORT_UDP:
1002 case XPRT_TRANSPORT_TCP:
1003 case XPRT_TRANSPORT_RDMA:
1004 break;
1005 default:
1006 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1007 }
1008}
1009
1010/*
1011 * For text based NFSv2/v3 mounts, the mount protocol transport default
1012 * settings should depend upon the specified NFS transport.
1013 */
1014static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
1015{
1016 nfs_validate_transport_protocol(mnt);
1017
1018 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
1019 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
1020 return;
1021 switch (mnt->nfs_server.protocol) {
1022 case XPRT_TRANSPORT_UDP:
1023 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
1024 break;
1025 case XPRT_TRANSPORT_TCP:
1026 case XPRT_TRANSPORT_RDMA:
1027 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
1028 }
1029}
1030
1031/*
Chuck Lever01060c82008-06-24 16:33:38 -04001032 * Parse the value of the 'sec=' option.
Chuck Lever01060c82008-06-24 16:33:38 -04001033 */
1034static int nfs_parse_security_flavors(char *value,
1035 struct nfs_parsed_mount_data *mnt)
1036{
1037 substring_t args[MAX_OPT_ARGS];
1038
1039 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
1040
1041 switch (match_token(value, nfs_secflavor_tokens, args)) {
1042 case Opt_sec_none:
Chuck Lever01060c82008-06-24 16:33:38 -04001043 mnt->auth_flavors[0] = RPC_AUTH_NULL;
1044 break;
1045 case Opt_sec_sys:
Chuck Lever01060c82008-06-24 16:33:38 -04001046 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
1047 break;
1048 case Opt_sec_krb5:
Chuck Lever01060c82008-06-24 16:33:38 -04001049 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
1050 break;
1051 case Opt_sec_krb5i:
Chuck Lever01060c82008-06-24 16:33:38 -04001052 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
1053 break;
1054 case Opt_sec_krb5p:
Chuck Lever01060c82008-06-24 16:33:38 -04001055 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
1056 break;
1057 case Opt_sec_lkey:
Chuck Lever01060c82008-06-24 16:33:38 -04001058 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
1059 break;
1060 case Opt_sec_lkeyi:
Chuck Lever01060c82008-06-24 16:33:38 -04001061 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
1062 break;
1063 case Opt_sec_lkeyp:
Chuck Lever01060c82008-06-24 16:33:38 -04001064 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
1065 break;
1066 case Opt_sec_spkm:
Chuck Lever01060c82008-06-24 16:33:38 -04001067 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
1068 break;
1069 case Opt_sec_spkmi:
Chuck Lever01060c82008-06-24 16:33:38 -04001070 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
1071 break;
1072 case Opt_sec_spkmp:
Chuck Lever01060c82008-06-24 16:33:38 -04001073 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
1074 break;
1075 default:
1076 return 0;
1077 }
1078
Bryan Schumaker9b7160c2011-04-13 14:31:30 -04001079 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
Chuck Lever059f90b2009-08-09 15:09:31 -04001080 mnt->auth_flavor_len = 1;
Chuck Lever01060c82008-06-24 16:33:38 -04001081 return 1;
1082}
1083
Trond Myklebust0d71b052012-03-02 13:59:49 -05001084static int nfs_parse_version_string(char *string,
1085 struct nfs_parsed_mount_data *mnt,
1086 substring_t *args)
1087{
1088 mnt->flags &= ~NFS_MOUNT_VER3;
1089 switch (match_token(string, nfs_vers_tokens, args)) {
1090 case Opt_vers_2:
1091 mnt->version = 2;
1092 break;
1093 case Opt_vers_3:
1094 mnt->flags |= NFS_MOUNT_VER3;
1095 mnt->version = 3;
1096 break;
1097 case Opt_vers_4:
1098 /* Backward compatibility option. In future,
1099 * the mount program should always supply
1100 * a NFSv4 minor version number.
1101 */
1102 mnt->version = 4;
1103 break;
1104 case Opt_vers_4_0:
1105 mnt->version = 4;
1106 mnt->minorversion = 0;
1107 break;
1108 case Opt_vers_4_1:
1109 mnt->version = 4;
1110 mnt->minorversion = 1;
1111 break;
1112 default:
1113 return 0;
1114 }
1115 return 1;
1116}
1117
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001118static int nfs_get_option_str(substring_t args[], char **option)
1119{
1120 kfree(*option);
1121 *option = match_strdup(args);
1122 return !option;
1123}
1124
1125static int nfs_get_option_ul(substring_t args[], unsigned long *option)
1126{
1127 int rc;
1128 char *string;
1129
1130 string = match_strdup(args);
1131 if (string == NULL)
1132 return -ENOMEM;
1133 rc = strict_strtoul(string, 10, option);
1134 kfree(string);
1135
1136 return rc;
1137}
1138
Chuck Lever01060c82008-06-24 16:33:38 -04001139/*
Chuck Leverbf0fd762007-07-01 12:13:44 -04001140 * Error-check and convert a string of mount options from user space into
Chuck Leverf45663c2008-06-24 19:28:02 -04001141 * a data structure. The whole mount string is processed; bad options are
1142 * skipped as they are encountered. If there were no errors, return 1;
1143 * otherwise return 0 (zero).
Chuck Leverbf0fd762007-07-01 12:13:44 -04001144 */
1145static int nfs_parse_mount_options(char *raw,
1146 struct nfs_parsed_mount_data *mnt)
1147{
Eric Parisf9c3a382008-03-05 14:20:18 -05001148 char *p, *string, *secdata;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001149 int rc, sloppy = 0, invalid_option = 0;
Jeff Laytonee671b02009-12-03 15:58:56 -05001150 unsigned short protofamily = AF_UNSPEC;
1151 unsigned short mountfamily = AF_UNSPEC;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001152
1153 if (!raw) {
1154 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
1155 return 1;
1156 }
1157 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
1158
Eric Parisf9c3a382008-03-05 14:20:18 -05001159 secdata = alloc_secdata();
1160 if (!secdata)
1161 goto out_nomem;
1162
1163 rc = security_sb_copy_data(raw, secdata);
1164 if (rc)
1165 goto out_security_failure;
1166
1167 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
1168 if (rc)
1169 goto out_security_failure;
1170
1171 free_secdata(secdata);
1172
Chuck Leverbf0fd762007-07-01 12:13:44 -04001173 while ((p = strsep(&raw, ",")) != NULL) {
1174 substring_t args[MAX_OPT_ARGS];
Chuck Levera5a16ba2009-06-17 18:02:14 -07001175 unsigned long option;
1176 int token;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001177
1178 if (!*p)
1179 continue;
1180
1181 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
1182
1183 token = match_token(p, nfs_mount_option_tokens, args);
1184 switch (token) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001185
1186 /*
1187 * boolean options: foo/nofoo
1188 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001189 case Opt_soft:
1190 mnt->flags |= NFS_MOUNT_SOFT;
1191 break;
1192 case Opt_hard:
1193 mnt->flags &= ~NFS_MOUNT_SOFT;
1194 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001195 case Opt_posix:
1196 mnt->flags |= NFS_MOUNT_POSIX;
1197 break;
1198 case Opt_noposix:
1199 mnt->flags &= ~NFS_MOUNT_POSIX;
1200 break;
1201 case Opt_cto:
1202 mnt->flags &= ~NFS_MOUNT_NOCTO;
1203 break;
1204 case Opt_nocto:
1205 mnt->flags |= NFS_MOUNT_NOCTO;
1206 break;
1207 case Opt_ac:
1208 mnt->flags &= ~NFS_MOUNT_NOAC;
1209 break;
1210 case Opt_noac:
1211 mnt->flags |= NFS_MOUNT_NOAC;
1212 break;
1213 case Opt_lock:
1214 mnt->flags &= ~NFS_MOUNT_NONLM;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001215 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1216 NFS_MOUNT_LOCAL_FCNTL);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001217 break;
1218 case Opt_nolock:
1219 mnt->flags |= NFS_MOUNT_NONLM;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001220 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1221 NFS_MOUNT_LOCAL_FCNTL);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001222 break;
1223 case Opt_v2:
1224 mnt->flags &= ~NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -04001225 mnt->version = 2;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001226 break;
1227 case Opt_v3:
1228 mnt->flags |= NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -04001229 mnt->version = 3;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001230 break;
Chuck Lever764302c2009-09-08 19:50:03 -04001231 case Opt_v4:
1232 mnt->flags &= ~NFS_MOUNT_VER3;
1233 mnt->version = 4;
1234 break;
Weston Andros Adamson7ced2862012-02-07 11:49:11 -05001235 case Opt_v4_0:
1236 mnt->flags &= ~NFS_MOUNT_VER3;
1237 mnt->version = 4;
1238 mnt->minorversion = 0;
1239 break;
1240 case Opt_v4_1:
1241 mnt->flags &= ~NFS_MOUNT_VER3;
1242 mnt->version = 4;
1243 mnt->minorversion = 1;
1244 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001245 case Opt_udp:
1246 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001247 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001248 break;
1249 case Opt_tcp:
1250 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001251 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001252 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001253 case Opt_rdma:
1254 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1255 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001256 xprt_load_transport(p);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001257 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001258 case Opt_acl:
1259 mnt->flags &= ~NFS_MOUNT_NOACL;
1260 break;
1261 case Opt_noacl:
1262 mnt->flags |= NFS_MOUNT_NOACL;
1263 break;
1264 case Opt_rdirplus:
1265 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1266 break;
1267 case Opt_nordirplus:
1268 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1269 break;
Trond Myklebust75180df2007-05-16 16:53:28 -04001270 case Opt_sharecache:
1271 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1272 break;
1273 case Opt_nosharecache:
1274 mnt->flags |= NFS_MOUNT_UNSHARED;
1275 break;
Chuck Leverd7403512008-12-23 15:21:37 -05001276 case Opt_resvport:
1277 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1278 break;
1279 case Opt_noresvport:
1280 mnt->flags |= NFS_MOUNT_NORESVPORT;
1281 break;
David Howellsb797cac2009-04-03 16:42:48 +01001282 case Opt_fscache:
1283 mnt->options |= NFS_OPTION_FSCACHE;
1284 kfree(mnt->fscache_uniq);
1285 mnt->fscache_uniq = NULL;
1286 break;
1287 case Opt_nofscache:
1288 mnt->options &= ~NFS_OPTION_FSCACHE;
1289 kfree(mnt->fscache_uniq);
1290 mnt->fscache_uniq = NULL;
1291 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001292
Chuck Leverf45663c2008-06-24 19:28:02 -04001293 /*
1294 * options that take numeric values
1295 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001296 case Opt_port:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001297 if (nfs_get_option_ul(args, &option) ||
1298 option > USHRT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001299 goto out_invalid_value;
1300 mnt->nfs_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001301 break;
1302 case Opt_rsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001303 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001304 goto out_invalid_value;
1305 mnt->rsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001306 break;
1307 case Opt_wsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001308 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001309 goto out_invalid_value;
1310 mnt->wsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001311 break;
1312 case Opt_bsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001313 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001314 goto out_invalid_value;
1315 mnt->bsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001316 break;
1317 case Opt_timeo:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001318 if (nfs_get_option_ul(args, &option) || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001319 goto out_invalid_value;
1320 mnt->timeo = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001321 break;
1322 case Opt_retrans:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001323 if (nfs_get_option_ul(args, &option) || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001324 goto out_invalid_value;
1325 mnt->retrans = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001326 break;
1327 case Opt_acregmin:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001328 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001329 goto out_invalid_value;
1330 mnt->acregmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001331 break;
1332 case Opt_acregmax:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001333 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001334 goto out_invalid_value;
1335 mnt->acregmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001336 break;
1337 case Opt_acdirmin:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001338 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001339 goto out_invalid_value;
1340 mnt->acdirmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001341 break;
1342 case Opt_acdirmax:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001343 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001344 goto out_invalid_value;
1345 mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001346 break;
1347 case Opt_actimeo:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001348 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001349 goto out_invalid_value;
1350 mnt->acregmin = mnt->acregmax =
1351 mnt->acdirmin = mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001352 break;
1353 case Opt_namelen:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001354 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001355 goto out_invalid_value;
1356 mnt->namlen = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001357 break;
1358 case Opt_mountport:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001359 if (nfs_get_option_ul(args, &option) ||
1360 option > USHRT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001361 goto out_invalid_value;
1362 mnt->mount_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001363 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001364 case Opt_mountvers:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001365 if (nfs_get_option_ul(args, &option) ||
Chuck Leverf45663c2008-06-24 19:28:02 -04001366 option < NFS_MNT_VERSION ||
Chuck Leverd23c45f2009-06-17 18:02:13 -07001367 option > NFS_MNT3_VERSION)
1368 goto out_invalid_value;
1369 mnt->mount_server.version = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001370 break;
Mike Sager3fd5be92009-04-01 09:21:48 -04001371 case Opt_minorversion:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001372 if (nfs_get_option_ul(args, &option))
Chuck Leverf3f4f4e2009-08-09 15:09:29 -04001373 goto out_invalid_value;
1374 if (option > NFS4_MAX_MINOR_VERSION)
1375 goto out_invalid_value;
1376 mnt->minorversion = option;
Mike Sager3fd5be92009-04-01 09:21:48 -04001377 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001378
Chuck Leverf45663c2008-06-24 19:28:02 -04001379 /*
1380 * options that take text values
1381 */
Trond Myklebust0d71b052012-03-02 13:59:49 -05001382 case Opt_nfsvers:
1383 string = match_strdup(args);
1384 if (string == NULL)
1385 goto out_nomem;
1386 rc = nfs_parse_version_string(string, mnt, args);
1387 kfree(string);
1388 if (!rc)
1389 goto out_invalid_value;
1390 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001391 case Opt_sec:
1392 string = match_strdup(args);
1393 if (string == NULL)
1394 goto out_nomem;
Chuck Lever01060c82008-06-24 16:33:38 -04001395 rc = nfs_parse_security_flavors(string, mnt);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001396 kfree(string);
Chuck Leverf45663c2008-06-24 19:28:02 -04001397 if (!rc) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001398 dfprintk(MOUNT, "NFS: unrecognized "
1399 "security flavor\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001400 return 0;
Chuck Leverf45663c2008-06-24 19:28:02 -04001401 }
Chuck Leverbf0fd762007-07-01 12:13:44 -04001402 break;
1403 case Opt_proto:
1404 string = match_strdup(args);
1405 if (string == NULL)
1406 goto out_nomem;
1407 token = match_token(string,
1408 nfs_xprt_protocol_tokens, args);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001409
Jeff Laytonee671b02009-12-03 15:58:56 -05001410 protofamily = AF_INET;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001411 switch (token) {
Jeff Laytonee671b02009-12-03 15:58:56 -05001412 case Opt_xprt_udp6:
1413 protofamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001414 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001415 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001416 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001417 break;
Jeff Laytonee671b02009-12-03 15:58:56 -05001418 case Opt_xprt_tcp6:
1419 protofamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001420 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001421 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001422 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001423 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001424 case Opt_xprt_rdma:
1425 /* vector side protocols to TCP */
1426 mnt->flags |= NFS_MOUNT_TCP;
1427 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001428 xprt_load_transport(string);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001429 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001430 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001431 dfprintk(MOUNT, "NFS: unrecognized "
1432 "transport protocol\n");
Yinghai Lu4223a4a2009-10-20 14:13:46 +09001433 kfree(string);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001434 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001435 }
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001436 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001437 break;
1438 case Opt_mountproto:
1439 string = match_strdup(args);
1440 if (string == NULL)
1441 goto out_nomem;
1442 token = match_token(string,
1443 nfs_xprt_protocol_tokens, args);
Trond Myklebustd508afb2009-04-06 16:41:35 -07001444 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001445
Jeff Laytonee671b02009-12-03 15:58:56 -05001446 mountfamily = AF_INET;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001447 switch (token) {
Jeff Laytonee671b02009-12-03 15:58:56 -05001448 case Opt_xprt_udp6:
1449 mountfamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001450 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001451 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001452 break;
Jeff Laytonee671b02009-12-03 15:58:56 -05001453 case Opt_xprt_tcp6:
1454 mountfamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001455 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001456 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001457 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001458 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001459 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001460 dfprintk(MOUNT, "NFS: unrecognized "
1461 "transport protocol\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001462 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001463 }
1464 break;
1465 case Opt_addr:
1466 string = match_strdup(args);
1467 if (string == NULL)
1468 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001469 mnt->nfs_server.addrlen =
Stanislav Kinsburskyb48e1272012-01-26 15:11:57 +04001470 rpc_pton(mnt->net, string, strlen(string),
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001471 (struct sockaddr *)
1472 &mnt->nfs_server.address,
1473 sizeof(mnt->nfs_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001474 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001475 if (mnt->nfs_server.addrlen == 0)
1476 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001477 break;
1478 case Opt_clientaddr:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001479 if (nfs_get_option_str(args, &mnt->client_address))
Chuck Leverbf0fd762007-07-01 12:13:44 -04001480 goto out_nomem;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001481 break;
Chuck Lever33832032007-12-10 14:59:13 -05001482 case Opt_mounthost:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001483 if (nfs_get_option_str(args,
1484 &mnt->mount_server.hostname))
Chuck Lever33832032007-12-10 14:59:13 -05001485 goto out_nomem;
Chuck Lever33832032007-12-10 14:59:13 -05001486 break;
Chuck Lever0ac83772007-09-11 18:01:04 -04001487 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001488 string = match_strdup(args);
1489 if (string == NULL)
1490 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001491 mnt->mount_server.addrlen =
Stanislav Kinsburskyb48e1272012-01-26 15:11:57 +04001492 rpc_pton(mnt->net, string, strlen(string),
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001493 (struct sockaddr *)
1494 &mnt->mount_server.address,
1495 sizeof(mnt->mount_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001496 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001497 if (mnt->mount_server.addrlen == 0)
1498 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001499 break;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001500 case Opt_lookupcache:
1501 string = match_strdup(args);
1502 if (string == NULL)
1503 goto out_nomem;
1504 token = match_token(string,
1505 nfs_lookupcache_tokens, args);
1506 kfree(string);
1507 switch (token) {
1508 case Opt_lookupcache_all:
1509 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1510 break;
1511 case Opt_lookupcache_positive:
1512 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1513 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1514 break;
1515 case Opt_lookupcache_none:
1516 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1517 break;
1518 default:
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001519 dfprintk(MOUNT, "NFS: invalid "
1520 "lookupcache argument\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001521 return 0;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001522 };
1523 break;
Chuck Levera6d5ff62010-05-07 13:33:58 -04001524 case Opt_fscache_uniq:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001525 if (nfs_get_option_str(args, &mnt->fscache_uniq))
Chuck Levera6d5ff62010-05-07 13:33:58 -04001526 goto out_nomem;
Chuck Levera6d5ff62010-05-07 13:33:58 -04001527 mnt->options |= NFS_OPTION_FSCACHE;
1528 break;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001529 case Opt_local_lock:
1530 string = match_strdup(args);
1531 if (string == NULL)
1532 goto out_nomem;
1533 token = match_token(string, nfs_local_lock_tokens,
1534 args);
1535 kfree(string);
1536 switch (token) {
1537 case Opt_local_lock_all:
1538 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1539 NFS_MOUNT_LOCAL_FCNTL);
1540 break;
1541 case Opt_local_lock_flock:
1542 mnt->flags |= NFS_MOUNT_LOCAL_FLOCK;
1543 break;
1544 case Opt_local_lock_posix:
1545 mnt->flags |= NFS_MOUNT_LOCAL_FCNTL;
1546 break;
1547 case Opt_local_lock_none:
1548 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1549 NFS_MOUNT_LOCAL_FCNTL);
1550 break;
1551 default:
1552 dfprintk(MOUNT, "NFS: invalid "
1553 "local_lock argument\n");
1554 return 0;
1555 };
1556 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001557
Chuck Leverf45663c2008-06-24 19:28:02 -04001558 /*
1559 * Special options
1560 */
1561 case Opt_sloppy:
1562 sloppy = 1;
1563 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1564 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001565 case Opt_userspace:
1566 case Opt_deprecated:
Chuck Leverd33e4df2008-06-12 12:37:41 -04001567 dfprintk(MOUNT, "NFS: ignoring mount option "
1568 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001569 break;
1570
1571 default:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001572 invalid_option = 1;
Chuck Leverf45663c2008-06-24 19:28:02 -04001573 dfprintk(MOUNT, "NFS: unrecognized mount option "
1574 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001575 }
1576 }
1577
Chuck Leverd23c45f2009-06-17 18:02:13 -07001578 if (!sloppy && invalid_option)
1579 return 0;
1580
Weston Andros Adamson571b7552012-02-01 14:06:41 -05001581 if (mnt->minorversion && mnt->version != 4)
1582 goto out_minorversion_mismatch;
1583
Jeff Laytonee671b02009-12-03 15:58:56 -05001584 /*
1585 * verify that any proto=/mountproto= options match the address
1586 * familiies in the addr=/mountaddr= options.
1587 */
1588 if (protofamily != AF_UNSPEC &&
1589 protofamily != mnt->nfs_server.address.ss_family)
1590 goto out_proto_mismatch;
1591
1592 if (mountfamily != AF_UNSPEC) {
1593 if (mnt->mount_server.addrlen) {
1594 if (mountfamily != mnt->mount_server.address.ss_family)
1595 goto out_mountproto_mismatch;
1596 } else {
1597 if (mountfamily != mnt->nfs_server.address.ss_family)
1598 goto out_mountproto_mismatch;
1599 }
1600 }
1601
Chuck Leverbf0fd762007-07-01 12:13:44 -04001602 return 1;
1603
Jeff Laytonee671b02009-12-03 15:58:56 -05001604out_mountproto_mismatch:
1605 printk(KERN_INFO "NFS: mount server address does not match mountproto= "
1606 "option\n");
1607 return 0;
1608out_proto_mismatch:
1609 printk(KERN_INFO "NFS: server address does not match proto= option\n");
1610 return 0;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001611out_invalid_address:
1612 printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
1613 return 0;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001614out_invalid_value:
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001615 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001616 return 0;
Weston Andros Adamson571b7552012-02-01 14:06:41 -05001617out_minorversion_mismatch:
1618 printk(KERN_INFO "NFS: mount option vers=%u does not support "
1619 "minorversion=%u\n", mnt->version, mnt->minorversion);
1620 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001621out_nomem:
1622 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1623 return 0;
Eric Parisf9c3a382008-03-05 14:20:18 -05001624out_security_failure:
1625 free_secdata(secdata);
1626 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1627 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001628}
1629
1630/*
Chuck Leverec88f282009-08-09 15:09:32 -04001631 * Match the requested auth flavors with the list returned by
1632 * the server. Returns zero and sets the mount's authentication
1633 * flavor on success; returns -EACCES if server does not support
1634 * the requested flavor.
1635 */
1636static int nfs_walk_authlist(struct nfs_parsed_mount_data *args,
1637 struct nfs_mount_request *request)
1638{
1639 unsigned int i, j, server_authlist_len = *(request->auth_flav_len);
1640
1641 /*
Chuck Lever5eecfde2009-08-21 17:50:30 -04001642 * Certain releases of Linux's mountd return an empty
1643 * flavor list. To prevent behavioral regression with
1644 * these servers (ie. rejecting mounts that used to
1645 * succeed), revert to pre-2.6.32 behavior (no checking)
1646 * if the returned flavor list is empty.
1647 */
1648 if (server_authlist_len == 0)
1649 return 0;
1650
1651 /*
Chuck Leverec88f282009-08-09 15:09:32 -04001652 * We avoid sophisticated negotiating here, as there are
1653 * plenty of cases where we can get it wrong, providing
1654 * either too little or too much security.
1655 *
1656 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1657 * flavor listed first. However, some servers list
1658 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1659 * preferred default, in args->auth_flavors[0] if user
1660 * didn't specify sec= mount option.
1661 */
1662 for (i = 0; i < args->auth_flavor_len; i++)
1663 for (j = 0; j < server_authlist_len; j++)
1664 if (args->auth_flavors[i] == request->auth_flavs[j]) {
1665 dfprintk(MOUNT, "NFS: using auth flavor %d\n",
1666 request->auth_flavs[j]);
1667 args->auth_flavors[0] = request->auth_flavs[j];
1668 return 0;
1669 }
1670
1671 dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n");
1672 nfs_umount(request);
1673 return -EACCES;
1674}
1675
1676/*
Chuck Lever0076d7b2007-07-01 12:13:49 -04001677 * Use the remote server's MOUNT service to request the NFS file handle
1678 * corresponding to the provided path.
1679 */
1680static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1681 struct nfs_fh *root_fh)
1682{
Chuck Leverec88f282009-08-09 15:09:32 -04001683 rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS];
1684 unsigned int server_authlist_len = ARRAY_SIZE(server_authlist);
Chuck Leverc5d120f2008-12-23 15:21:35 -05001685 struct nfs_mount_request request = {
1686 .sap = (struct sockaddr *)
1687 &args->mount_server.address,
1688 .dirpath = args->nfs_server.export_path,
1689 .protocol = args->mount_server.protocol,
1690 .fh = root_fh,
Chuck Lever50a737f2008-12-23 15:21:37 -05001691 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
Chuck Leverec88f282009-08-09 15:09:32 -04001692 .auth_flav_len = &server_authlist_len,
1693 .auth_flavs = server_authlist,
Stanislav Kinsbursky6d59b8d2012-01-10 16:12:54 +04001694 .net = args->net,
Chuck Leverc5d120f2008-12-23 15:21:35 -05001695 };
Chuck Lever4c568012007-12-10 14:59:28 -05001696 int status;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001697
1698 if (args->mount_server.version == 0) {
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001699 switch (args->version) {
1700 default:
1701 args->mount_server.version = NFS_MNT3_VERSION;
1702 break;
1703 case 2:
1704 args->mount_server.version = NFS_MNT_VERSION;
1705 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001706 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001707 request.version = args->mount_server.version;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001708
Chuck Lever33832032007-12-10 14:59:13 -05001709 if (args->mount_server.hostname)
Chuck Leverc5d120f2008-12-23 15:21:35 -05001710 request.hostname = args->mount_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001711 else
Chuck Leverc5d120f2008-12-23 15:21:35 -05001712 request.hostname = args->nfs_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001713
Chuck Lever0076d7b2007-07-01 12:13:49 -04001714 /*
1715 * Construct the mount server's address.
1716 */
Chuck Lever4c568012007-12-10 14:59:28 -05001717 if (args->mount_server.address.ss_family == AF_UNSPEC) {
Chuck Leverc5d120f2008-12-23 15:21:35 -05001718 memcpy(request.sap, &args->nfs_server.address,
Chuck Lever4c568012007-12-10 14:59:28 -05001719 args->nfs_server.addrlen);
1720 args->mount_server.addrlen = args->nfs_server.addrlen;
1721 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001722 request.salen = args->mount_server.addrlen;
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001723 nfs_set_port(request.sap, &args->mount_server.port, 0);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001724
1725 /*
1726 * Now ask the mount server to map our export path
1727 * to a file handle.
1728 */
Chuck Leverc5d120f2008-12-23 15:21:35 -05001729 status = nfs_mount(&request);
Chuck Leverec88f282009-08-09 15:09:32 -04001730 if (status != 0) {
1731 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1732 request.hostname, status);
1733 return status;
1734 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001735
Chuck Leverec88f282009-08-09 15:09:32 -04001736 /*
1737 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1738 */
1739 if (args->mount_server.version != NFS_MNT3_VERSION)
1740 return 0;
1741 return nfs_walk_authlist(args, &request);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001742}
1743
Rob Landleyc12bace2011-03-09 15:54:13 -06001744/*
1745 * Split "dev_name" into "hostname:export_path".
1746 *
1747 * The leftmost colon demarks the split between the server's hostname
1748 * and the export path. If the hostname starts with a left square
1749 * bracket, then it may contain colons.
1750 *
1751 * Note: caller frees hostname and export path, even on error.
1752 */
1753static int nfs_parse_devname(const char *dev_name,
1754 char **hostname, size_t maxnamlen,
1755 char **export_path, size_t maxpathlen)
Chuck Leverdc045892008-06-23 12:36:37 -04001756{
1757 size_t len;
Rob Landleyc12bace2011-03-09 15:54:13 -06001758 char *end;
Chuck Leverdc045892008-06-23 12:36:37 -04001759
Rob Landleyc12bace2011-03-09 15:54:13 -06001760 /* Is the host name protected with square brakcets? */
1761 if (*dev_name == '[') {
1762 end = strchr(++dev_name, ']');
1763 if (end == NULL || end[1] != ':')
1764 goto out_bad_devname;
Chuck Leverdc045892008-06-23 12:36:37 -04001765
Rob Landleyc12bace2011-03-09 15:54:13 -06001766 len = end - dev_name;
1767 end++;
1768 } else {
1769 char *comma;
1770
1771 end = strchr(dev_name, ':');
1772 if (end == NULL)
1773 goto out_bad_devname;
1774 len = end - dev_name;
1775
1776 /* kill possible hostname list: not supported */
1777 comma = strchr(dev_name, ',');
1778 if (comma != NULL && comma < end)
1779 *comma = 0;
1780 }
1781
Chuck Leverdc045892008-06-23 12:36:37 -04001782 if (len > maxnamlen)
1783 goto out_hostname;
1784
1785 /* N.B. caller will free nfs_server.hostname in all cases */
1786 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
Rob Landleyc12bace2011-03-09 15:54:13 -06001787 if (*hostname == NULL)
Chuck Leverdc045892008-06-23 12:36:37 -04001788 goto out_nomem;
Rob Landleyc12bace2011-03-09 15:54:13 -06001789 len = strlen(++end);
Chuck Leverdc045892008-06-23 12:36:37 -04001790 if (len > maxpathlen)
1791 goto out_path;
Rob Landleyc12bace2011-03-09 15:54:13 -06001792 *export_path = kstrndup(end, len, GFP_KERNEL);
Chuck Leverdc045892008-06-23 12:36:37 -04001793 if (!*export_path)
1794 goto out_nomem;
1795
1796 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1797 return 0;
1798
1799out_bad_devname:
1800 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1801 return -EINVAL;
1802
1803out_nomem:
1804 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1805 return -ENOMEM;
1806
1807out_hostname:
1808 dfprintk(MOUNT, "NFS: server hostname too long\n");
1809 return -ENAMETOOLONG;
1810
1811out_path:
1812 dfprintk(MOUNT, "NFS: export pathname too long\n");
1813 return -ENAMETOOLONG;
1814}
1815
1816/*
David Howells54ceac42006-08-22 20:06:13 -04001817 * Validate the NFS2/NFS3 mount data
1818 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001819 *
1820 * For option strings, user space handles the following behaviors:
1821 *
1822 * + DNS: mapping server host name to IP address ("addr=" option)
1823 *
1824 * + failure mode: how to behave if a mount request can't be handled
1825 * immediately ("fg/bg" option)
1826 *
1827 * + retry: how often to retry a mount request ("retry=" option)
1828 *
1829 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1830 * mountproto=tcp after mountproto=udp, and so on
David Howellsf7b422b2006-06-09 09:34:33 -04001831 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001832static int nfs_validate_mount_data(void *options,
1833 struct nfs_parsed_mount_data *args,
Chuck Lever136d5582007-07-01 12:13:54 -04001834 struct nfs_fh *mntfh,
1835 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001836{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001837 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001838 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
Chuck Lever136d5582007-07-01 12:13:54 -04001839
Chuck Lever5df36e72007-07-01 12:12:56 -04001840 if (data == NULL)
1841 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001842
David Howellsf7b422b2006-06-09 09:34:33 -04001843 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001844 case 1:
1845 data->namlen = 0;
1846 case 2:
1847 data->bsize = 0;
1848 case 3:
1849 if (data->flags & NFS_MOUNT_VER3)
1850 goto out_no_v3;
1851 data->root.size = NFS2_FHSIZE;
1852 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1853 case 4:
1854 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1855 goto out_no_sec;
1856 case 5:
1857 memset(data->context, 0, sizeof(data->context));
1858 case 6:
Trond Myklebustb7e24452008-06-19 15:21:11 -04001859 if (data->flags & NFS_MOUNT_VER3) {
1860 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1861 goto out_invalid_fh;
Chuck Lever5df36e72007-07-01 12:12:56 -04001862 mntfh->size = data->root.size;
Chuck Lever764302c2009-09-08 19:50:03 -04001863 args->version = 3;
1864 } else {
Chuck Lever5df36e72007-07-01 12:12:56 -04001865 mntfh->size = NFS2_FHSIZE;
Chuck Lever764302c2009-09-08 19:50:03 -04001866 args->version = 2;
1867 }
Chuck Lever5df36e72007-07-01 12:12:56 -04001868
Chuck Lever5df36e72007-07-01 12:12:56 -04001869
1870 memcpy(mntfh->data, data->root.data, mntfh->size);
1871 if (mntfh->size < sizeof(mntfh->data))
1872 memset(mntfh->data + mntfh->size, 0,
1873 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001874
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001875 /*
1876 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1877 * can deal with.
1878 */
Trond Myklebustff3525a2008-08-15 16:59:14 -04001879 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
Bryan Schumakerd5eff1a2010-08-03 13:04:00 -04001880 args->flags |= NFS_MOUNT_LEGACY_INTERFACE;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001881 args->rsize = data->rsize;
1882 args->wsize = data->wsize;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001883 args->timeo = data->timeo;
1884 args->retrans = data->retrans;
1885 args->acregmin = data->acregmin;
1886 args->acregmax = data->acregmax;
1887 args->acdirmin = data->acdirmin;
1888 args->acdirmax = data->acdirmax;
Chuck Lever4c568012007-12-10 14:59:28 -05001889
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001890 memcpy(sap, &data->addr, sizeof(data->addr));
Chuck Lever4c568012007-12-10 14:59:28 -05001891 args->nfs_server.addrlen = sizeof(data->addr);
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001892 if (!nfs_verify_server_address(sap))
Chuck Lever4c568012007-12-10 14:59:28 -05001893 goto out_no_address;
1894
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001895 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001896 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001897 /* N.B. caller will free nfs_server.hostname in all cases */
1898 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1899 args->namlen = data->namlen;
1900 args->bsize = data->bsize;
Chuck Leverdd07c942008-06-24 16:33:46 -04001901
1902 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1903 args->auth_flavors[0] = data->pseudoflavor;
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001904 if (!args->nfs_server.hostname)
1905 goto out_nomem;
Eric Parisf9c3a382008-03-05 14:20:18 -05001906
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001907 if (!(data->flags & NFS_MOUNT_NONLM))
1908 args->flags &= ~(NFS_MOUNT_LOCAL_FLOCK|
1909 NFS_MOUNT_LOCAL_FCNTL);
1910 else
1911 args->flags |= (NFS_MOUNT_LOCAL_FLOCK|
1912 NFS_MOUNT_LOCAL_FCNTL);
Eric Parisf9c3a382008-03-05 14:20:18 -05001913 /*
1914 * The legacy version 6 binary mount data from userspace has a
1915 * field used only to transport selinux information into the
1916 * the kernel. To continue to support that functionality we
1917 * have a touch of selinux knowledge here in the NFS code. The
1918 * userspace code converted context=blah to just blah so we are
1919 * converting back to the full string selinux understands.
1920 */
1921 if (data->context[0]){
1922#ifdef CONFIG_SECURITY_SELINUX
1923 int rc;
1924 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1925 if (!opts_str)
1926 return -ENOMEM;
1927 strcpy(opts_str, "context=");
1928 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1929 strcat(opts_str, &data->context[0]);
1930 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1931 kfree(opts_str);
1932 if (rc)
1933 return rc;
1934#else
1935 return -EINVAL;
1936#endif
1937 }
1938
Chuck Lever5df36e72007-07-01 12:12:56 -04001939 break;
Chuck Lever136d5582007-07-01 12:13:54 -04001940 default: {
Chuck Lever136d5582007-07-01 12:13:54 -04001941 int status;
Chuck Lever136d5582007-07-01 12:13:54 -04001942
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001943 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever136d5582007-07-01 12:13:54 -04001944 return -EINVAL;
1945
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001946 if (!nfs_verify_server_address(sap))
Chuck Lever6e88e062007-09-24 15:39:50 -04001947 goto out_no_address;
1948
Chuck Lever764302c2009-09-08 19:50:03 -04001949 if (args->version == 4)
1950#ifdef CONFIG_NFS_V4
1951 return nfs4_validate_text_mount_data(options,
1952 args, dev_name);
1953#else
1954 goto out_v4_not_compiled;
1955#endif
1956
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001957 nfs_set_port(sap, &args->nfs_server.port, 0);
Chuck Levered596a82008-06-26 17:47:05 -04001958
Trond Myklebust259875e2008-07-02 14:43:47 -04001959 nfs_set_mount_transport_protocol(args);
1960
Chuck Leverdc045892008-06-23 12:36:37 -04001961 status = nfs_parse_devname(dev_name,
1962 &args->nfs_server.hostname,
1963 PAGE_SIZE,
1964 &args->nfs_server.export_path,
1965 NFS_MAXPATHLEN);
1966 if (!status)
1967 status = nfs_try_mount(args, mntfh);
Chuck Lever136d5582007-07-01 12:13:54 -04001968
Chuck Leverdc045892008-06-23 12:36:37 -04001969 kfree(args->nfs_server.export_path);
1970 args->nfs_server.export_path = NULL;
Chuck Lever136d5582007-07-01 12:13:54 -04001971
Chuck Lever136d5582007-07-01 12:13:54 -04001972 if (status)
Chuck Leverfdc6e2c2007-08-29 17:58:59 -04001973 return status;
Chuck Lever136d5582007-07-01 12:13:54 -04001974
Chuck Lever136d5582007-07-01 12:13:54 -04001975 break;
1976 }
David Howellsf7b422b2006-06-09 09:34:33 -04001977 }
David Howells54ceac42006-08-22 20:06:13 -04001978
David Howellsf7b422b2006-06-09 09:34:33 -04001979#ifndef CONFIG_NFS_V3
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001980 if (args->version == 3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001981 goto out_v3_not_compiled;
1982#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001983
David Howells54ceac42006-08-22 20:06:13 -04001984 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001985
1986out_no_data:
1987 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1988 return -EINVAL;
1989
1990out_no_v3:
1991 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1992 data->version);
1993 return -EINVAL;
1994
1995out_no_sec:
1996 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1997 return -EINVAL;
1998
Chuck Lever5df36e72007-07-01 12:12:56 -04001999#ifndef CONFIG_NFS_V3
2000out_v3_not_compiled:
2001 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
2002 return -EPROTONOSUPPORT;
2003#endif /* !CONFIG_NFS_V3 */
2004
Chuck Lever764302c2009-09-08 19:50:03 -04002005#ifndef CONFIG_NFS_V4
2006out_v4_not_compiled:
2007 dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n");
2008 return -EPROTONOSUPPORT;
2009#endif /* !CONFIG_NFS_V4 */
2010
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04002011out_nomem:
2012 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
2013 return -ENOMEM;
2014
Chuck Lever5df36e72007-07-01 12:12:56 -04002015out_no_address:
2016 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
2017 return -EINVAL;
2018
2019out_invalid_fh:
2020 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
2021 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04002022}
2023
Jeff Layton48b605f2008-06-10 15:38:39 -04002024static int
2025nfs_compare_remount_data(struct nfs_server *nfss,
2026 struct nfs_parsed_mount_data *data)
2027{
2028 if (data->flags != nfss->flags ||
2029 data->rsize != nfss->rsize ||
2030 data->wsize != nfss->wsize ||
2031 data->retrans != nfss->client->cl_timeout->to_retries ||
2032 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
2033 data->acregmin != nfss->acregmin / HZ ||
2034 data->acregmax != nfss->acregmax / HZ ||
2035 data->acdirmin != nfss->acdirmin / HZ ||
2036 data->acdirmax != nfss->acdirmax / HZ ||
2037 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
Trond Myklebustbcd2ea12009-10-06 15:41:22 -04002038 data->nfs_server.port != nfss->port ||
Jeff Layton48b605f2008-06-10 15:38:39 -04002039 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
Stefan Richtera1be9ee2009-10-12 11:26:12 -04002040 !rpc_cmp_addr((struct sockaddr *)&data->nfs_server.address,
2041 (struct sockaddr *)&nfss->nfs_client->cl_addr))
Jeff Layton48b605f2008-06-10 15:38:39 -04002042 return -EINVAL;
2043
2044 return 0;
2045}
2046
2047static int
2048nfs_remount(struct super_block *sb, int *flags, char *raw_data)
2049{
2050 int error;
2051 struct nfs_server *nfss = sb->s_fs_info;
2052 struct nfs_parsed_mount_data *data;
2053 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
2054 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
Trond Myklebustcd100722008-06-17 16:12:00 -04002055 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
Jeff Layton48b605f2008-06-10 15:38:39 -04002056
2057 /*
2058 * Userspace mount programs that send binary options generally send
2059 * them populated with default values. We have no way to know which
2060 * ones were explicitly specified. Fall back to legacy behavior and
2061 * just return success.
2062 */
Marc Zyngier31c94462008-07-17 13:21:55 +02002063 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
2064 (nfsvers <= 3 && (!options || (options->version >= 1 &&
2065 options->version <= 6))))
Jeff Layton48b605f2008-06-10 15:38:39 -04002066 return 0;
2067
2068 data = kzalloc(sizeof(*data), GFP_KERNEL);
2069 if (data == NULL)
2070 return -ENOMEM;
2071
2072 /* fill out struct with values from existing mount */
2073 data->flags = nfss->flags;
2074 data->rsize = nfss->rsize;
2075 data->wsize = nfss->wsize;
2076 data->retrans = nfss->client->cl_timeout->to_retries;
2077 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
2078 data->acregmin = nfss->acregmin / HZ;
2079 data->acregmax = nfss->acregmax / HZ;
2080 data->acdirmin = nfss->acdirmin / HZ;
2081 data->acdirmax = nfss->acdirmax / HZ;
2082 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
Trond Myklebustbcd2ea12009-10-06 15:41:22 -04002083 data->nfs_server.port = nfss->port;
Jeff Layton48b605f2008-06-10 15:38:39 -04002084 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
2085 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
2086 data->nfs_server.addrlen);
2087
2088 /* overwrite those values with any that were specified */
2089 error = nfs_parse_mount_options((char *)options, data);
2090 if (error < 0)
2091 goto out;
2092
Jeff Layton26c4c172011-04-27 11:49:09 -04002093 /*
2094 * noac is a special case. It implies -o sync, but that's not
2095 * necessarily reflected in the mtab options. do_remount_sb
2096 * will clear MS_SYNCHRONOUS if -o sync wasn't specified in the
2097 * remount options, so we have to explicitly reset it.
2098 */
2099 if (data->flags & NFS_MOUNT_NOAC)
2100 *flags |= MS_SYNCHRONOUS;
2101
Jeff Layton48b605f2008-06-10 15:38:39 -04002102 /* compare new mount options with old ones */
2103 error = nfs_compare_remount_data(nfss, data);
2104out:
2105 kfree(data);
2106 return error;
2107}
2108
David Howells54ceac42006-08-22 20:06:13 -04002109/*
2110 * Initialise the common bits of the superblock
2111 */
2112static inline void nfs_initialise_sb(struct super_block *sb)
2113{
2114 struct nfs_server *server = NFS_SB(sb);
2115
2116 sb->s_magic = NFS_SUPER_MAGIC;
2117
2118 /* We probably want something more informative here */
2119 snprintf(sb->s_id, sizeof(sb->s_id),
2120 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
2121
2122 if (sb->s_blocksize == 0)
2123 sb->s_blocksize = nfs_block_bits(server->wsize,
2124 &sb->s_blocksize_bits);
2125
Jens Axboe32a88aa2009-09-16 15:02:33 +02002126 sb->s_bdi = &server->backing_dev_info;
2127
David Howells54ceac42006-08-22 20:06:13 -04002128 nfs_super_set_maxbytes(sb, server->maxfilesize);
2129}
2130
2131/*
2132 * Finish setting up an NFS2/3 superblock
2133 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04002134static void nfs_fill_super(struct super_block *sb,
2135 struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -04002136{
2137 struct nfs_server *server = NFS_SB(sb);
2138
2139 sb->s_blocksize_bits = 0;
2140 sb->s_blocksize = 0;
2141 if (data->bsize)
2142 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
2143
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04002144 if (server->nfs_client->rpc_ops->version == 3) {
David Howells54ceac42006-08-22 20:06:13 -04002145 /* The VFS shouldn't apply the umask to mode bits. We will do
2146 * so ourselves when necessary.
2147 */
2148 sb->s_flags |= MS_POSIXACL;
2149 sb->s_time_gran = 1;
2150 }
2151
2152 sb->s_op = &nfs_sops;
2153 nfs_initialise_sb(sb);
2154}
2155
2156/*
2157 * Finish setting up a cloned NFS2/3 superblock
2158 */
2159static void nfs_clone_super(struct super_block *sb,
2160 const struct super_block *old_sb)
2161{
2162 struct nfs_server *server = NFS_SB(sb);
2163
2164 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2165 sb->s_blocksize = old_sb->s_blocksize;
2166 sb->s_maxbytes = old_sb->s_maxbytes;
2167
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04002168 if (server->nfs_client->rpc_ops->version == 3) {
David Howells54ceac42006-08-22 20:06:13 -04002169 /* The VFS shouldn't apply the umask to mode bits. We will do
2170 * so ourselves when necessary.
2171 */
2172 sb->s_flags |= MS_POSIXACL;
2173 sb->s_time_gran = 1;
2174 }
2175
2176 sb->s_op = old_sb->s_op;
2177 nfs_initialise_sb(sb);
2178}
2179
Trond Myklebust275a5d22007-05-16 16:53:28 -04002180static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
2181{
2182 const struct nfs_server *a = s->s_fs_info;
2183 const struct rpc_clnt *clnt_a = a->client;
2184 const struct rpc_clnt *clnt_b = b->client;
2185
2186 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
2187 goto Ebusy;
2188 if (a->nfs_client != b->nfs_client)
2189 goto Ebusy;
2190 if (a->flags != b->flags)
2191 goto Ebusy;
2192 if (a->wsize != b->wsize)
2193 goto Ebusy;
2194 if (a->rsize != b->rsize)
2195 goto Ebusy;
2196 if (a->acregmin != b->acregmin)
2197 goto Ebusy;
2198 if (a->acregmax != b->acregmax)
2199 goto Ebusy;
2200 if (a->acdirmin != b->acdirmin)
2201 goto Ebusy;
2202 if (a->acdirmax != b->acdirmax)
2203 goto Ebusy;
2204 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
2205 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002206 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04002207Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002208 return 0;
2209}
2210
2211struct nfs_sb_mountdata {
2212 struct nfs_server *server;
2213 int mntflags;
2214};
2215
2216static int nfs_set_super(struct super_block *s, void *data)
2217{
2218 struct nfs_sb_mountdata *sb_mntdata = data;
2219 struct nfs_server *server = sb_mntdata->server;
2220 int ret;
2221
2222 s->s_flags = sb_mntdata->mntflags;
2223 s->s_fs_info = server;
Al Viro8b244ff2010-12-18 11:29:39 -05002224 s->s_d_op = server->nfs_client->rpc_ops->dentry_ops;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002225 ret = set_anon_super(s, server);
2226 if (ret == 0)
2227 server->s_dev = s->s_dev;
2228 return ret;
2229}
2230
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002231static int nfs_compare_super_address(struct nfs_server *server1,
2232 struct nfs_server *server2)
2233{
2234 struct sockaddr *sap1, *sap2;
2235
2236 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
2237 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
2238
2239 if (sap1->sa_family != sap2->sa_family)
2240 return 0;
2241
2242 switch (sap1->sa_family) {
2243 case AF_INET: {
2244 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
2245 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
2246 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
2247 return 0;
2248 if (sin1->sin_port != sin2->sin_port)
2249 return 0;
2250 break;
2251 }
2252 case AF_INET6: {
2253 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
2254 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
2255 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
2256 return 0;
2257 if (sin1->sin6_port != sin2->sin6_port)
2258 return 0;
2259 break;
2260 }
2261 default:
2262 return 0;
2263 }
2264
2265 return 1;
2266}
2267
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002268static int nfs_compare_super(struct super_block *sb, void *data)
2269{
2270 struct nfs_sb_mountdata *sb_mntdata = data;
2271 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2272 int mntflags = sb_mntdata->mntflags;
2273
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002274 if (!nfs_compare_super_address(old, server))
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002275 return 0;
2276 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2277 if (old->flags & NFS_MOUNT_UNSHARED)
2278 return 0;
2279 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2280 return 0;
2281 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04002282}
2283
Miklos Szeredifa799752008-04-30 00:54:33 -07002284static int nfs_bdi_register(struct nfs_server *server)
2285{
2286 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
2287}
2288
Al Viro01194982011-03-16 07:25:36 -04002289static struct dentry *nfs_fs_mount(struct file_system_type *fs_type,
2290 int flags, const char *dev_name, void *raw_data)
David Howells54ceac42006-08-22 20:06:13 -04002291{
2292 struct nfs_server *server = NULL;
2293 struct super_block *s;
Trond Myklebust33852a12008-06-19 14:20:11 -04002294 struct nfs_parsed_mount_data *data;
2295 struct nfs_fh *mntfh;
Al Viro01194982011-03-16 07:25:36 -04002296 struct dentry *mntroot = ERR_PTR(-ENOMEM);
Trond Myklebust75180df2007-05-16 16:53:28 -04002297 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002298 struct nfs_sb_mountdata sb_mntdata = {
2299 .mntflags = flags,
2300 };
Al Viro01194982011-03-16 07:25:36 -04002301 int error;
David Howells54ceac42006-08-22 20:06:13 -04002302
Paulius Zaleckas1e657bd2010-10-31 18:21:05 +02002303 data = nfs_alloc_parsed_mount_data(NFS_DEFAULT_VERSION);
Trond Myklebustb157b062010-04-19 19:05:48 -04002304 mntfh = nfs_alloc_fhandle();
Trond Myklebust33852a12008-06-19 14:20:11 -04002305 if (data == NULL || mntfh == NULL)
Jeff Layton8a0d5512011-12-20 06:57:45 -05002306 goto out;
Eric Parisf9c3a382008-03-05 14:20:18 -05002307
David Howells54ceac42006-08-22 20:06:13 -04002308 /* Validate the mount data */
Trond Myklebust33852a12008-06-19 14:20:11 -04002309 error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
Al Viro01194982011-03-16 07:25:36 -04002310 if (error < 0) {
2311 mntroot = ERR_PTR(error);
Chuck Lever06559602007-07-01 12:12:35 -04002312 goto out;
Al Viro01194982011-03-16 07:25:36 -04002313 }
David Howells54ceac42006-08-22 20:06:13 -04002314
Chuck Lever764302c2009-09-08 19:50:03 -04002315#ifdef CONFIG_NFS_V4
2316 if (data->version == 4) {
Al Viro01194982011-03-16 07:25:36 -04002317 mntroot = nfs4_try_mount(flags, dev_name, data);
Chuck Lever764302c2009-09-08 19:50:03 -04002318 goto out;
2319 }
2320#endif /* CONFIG_NFS_V4 */
2321
David Howells54ceac42006-08-22 20:06:13 -04002322 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002323 server = nfs_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002324 if (IS_ERR(server)) {
Al Viro01194982011-03-16 07:25:36 -04002325 mntroot = ERR_CAST(server);
Chuck Lever06559602007-07-01 12:12:35 -04002326 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002327 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002328 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002329
Trond Myklebust75180df2007-05-16 16:53:28 -04002330 if (server->flags & NFS_MOUNT_UNSHARED)
2331 compare_super = NULL;
2332
Sachin Prabhufb2088c2011-08-01 12:10:12 +01002333 /* -o noac implies -o sync */
2334 if (server->flags & NFS_MOUNT_NOAC)
2335 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2336
David Howells54ceac42006-08-22 20:06:13 -04002337 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002338 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002339 if (IS_ERR(s)) {
Al Viro01194982011-03-16 07:25:36 -04002340 mntroot = ERR_CAST(s);
David Howells54ceac42006-08-22 20:06:13 -04002341 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04002342 }
2343
David Howells54ceac42006-08-22 20:06:13 -04002344 if (s->s_fs_info != server) {
2345 nfs_free_server(server);
2346 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002347 } else {
2348 error = nfs_bdi_register(server);
Al Viro01194982011-03-16 07:25:36 -04002349 if (error) {
2350 mntroot = ERR_PTR(error);
NeilBrowncfbc0682010-03-11 11:20:17 +11002351 goto error_splat_bdi;
Al Viro01194982011-03-16 07:25:36 -04002352 }
David Howellsf7b422b2006-06-09 09:34:33 -04002353 }
David Howells54ceac42006-08-22 20:06:13 -04002354
2355 if (!s->s_root) {
2356 /* initial superblock/root creation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002357 nfs_fill_super(s, data);
Jesper Juhl160bc162011-04-10 17:57:07 +02002358 nfs_fscache_get_super_cookie(s, data->fscache_uniq, NULL);
David Howells54ceac42006-08-22 20:06:13 -04002359 }
2360
Al Viro0d5839a2011-03-16 05:27:27 -04002361 mntroot = nfs_get_root(s, mntfh, dev_name);
Al Viro01194982011-03-16 07:25:36 -04002362 if (IS_ERR(mntroot))
David Howells54ceac42006-08-22 20:06:13 -04002363 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002364
Trond Myklebust33852a12008-06-19 14:20:11 -04002365 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002366 if (error)
2367 goto error_splat_root;
2368
David Howellsf7b422b2006-06-09 09:34:33 -04002369 s->s_flags |= MS_ACTIVE;
Chuck Lever06559602007-07-01 12:12:35 -04002370
2371out:
Jeff Layton8a0d5512011-12-20 06:57:45 -05002372 nfs_free_parsed_mount_data(data);
Trond Myklebustb157b062010-04-19 19:05:48 -04002373 nfs_free_fhandle(mntfh);
Al Viro01194982011-03-16 07:25:36 -04002374 return mntroot;
Trond Myklebust816724e2006-06-24 08:41:41 -04002375
David Howells54ceac42006-08-22 20:06:13 -04002376out_err_nosb:
2377 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04002378 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002379
Eric Parisf9c3a382008-03-05 14:20:18 -05002380error_splat_root:
2381 dput(mntroot);
Al Viro01194982011-03-16 07:25:36 -04002382 mntroot = ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04002383error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002384 if (server && !s->s_root)
2385 bdi_unregister(&server->backing_dev_info);
2386error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002387 deactivate_locked_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04002388 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002389}
2390
David Howells54ceac42006-08-22 20:06:13 -04002391/*
Trond Myklebust387c1492010-02-03 08:27:35 -05002392 * Ensure that we unregister the bdi before kill_anon_super
2393 * releases the device name
2394 */
2395static void nfs_put_super(struct super_block *s)
2396{
2397 struct nfs_server *server = NFS_SB(s);
2398
2399 bdi_unregister(&server->backing_dev_info);
2400}
2401
2402/*
David Howells54ceac42006-08-22 20:06:13 -04002403 * Destroy an NFS2/3 superblock
2404 */
David Howellsf7b422b2006-06-09 09:34:33 -04002405static void nfs_kill_super(struct super_block *s)
2406{
2407 struct nfs_server *server = NFS_SB(s);
2408
2409 kill_anon_super(s);
David Howells08734042009-04-03 16:42:42 +01002410 nfs_fscache_release_super_cookie(s);
David Howells54ceac42006-08-22 20:06:13 -04002411 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04002412}
2413
David Howells54ceac42006-08-22 20:06:13 -04002414/*
2415 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2416 */
Al Viro31f43472010-10-29 03:38:12 -04002417static struct dentry *
2418nfs_xdev_mount(struct file_system_type *fs_type, int flags,
2419 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002420{
2421 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002422 struct super_block *s;
2423 struct nfs_server *server;
2424 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002425 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002426 struct nfs_sb_mountdata sb_mntdata = {
2427 .mntflags = flags,
2428 };
David Howells54ceac42006-08-22 20:06:13 -04002429 int error;
2430
Al Viro31f43472010-10-29 03:38:12 -04002431 dprintk("--> nfs_xdev_mount()\n");
David Howells54ceac42006-08-22 20:06:13 -04002432
2433 /* create a new volume representation */
2434 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2435 if (IS_ERR(server)) {
2436 error = PTR_ERR(server);
2437 goto out_err_noserver;
2438 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002439 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002440
Trond Myklebust75180df2007-05-16 16:53:28 -04002441 if (server->flags & NFS_MOUNT_UNSHARED)
2442 compare_super = NULL;
2443
Sachin Prabhufb2088c2011-08-01 12:10:12 +01002444 /* -o noac implies -o sync */
2445 if (server->flags & NFS_MOUNT_NOAC)
2446 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2447
David Howells54ceac42006-08-22 20:06:13 -04002448 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002449 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002450 if (IS_ERR(s)) {
2451 error = PTR_ERR(s);
2452 goto out_err_nosb;
2453 }
2454
2455 if (s->s_fs_info != server) {
2456 nfs_free_server(server);
2457 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002458 } else {
2459 error = nfs_bdi_register(server);
2460 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11002461 goto error_splat_bdi;
David Howells54ceac42006-08-22 20:06:13 -04002462 }
2463
2464 if (!s->s_root) {
2465 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002466 nfs_clone_super(s, data->sb);
David Howells2df54802009-09-23 14:36:39 -04002467 nfs_fscache_get_super_cookie(s, NULL, data);
David Howells54ceac42006-08-22 20:06:13 -04002468 }
2469
Al Viro0d5839a2011-03-16 05:27:27 -04002470 mntroot = nfs_get_root(s, data->fh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04002471 if (IS_ERR(mntroot)) {
2472 error = PTR_ERR(mntroot);
2473 goto error_splat_super;
2474 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002475 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
Neil Brown4c1fe2f2007-11-01 16:50:20 +11002476 dput(mntroot);
2477 error = -ESTALE;
2478 goto error_splat_super;
2479 }
David Howells54ceac42006-08-22 20:06:13 -04002480
2481 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002482
Eric Parisf9c3a382008-03-05 14:20:18 -05002483 /* clone any lsm security options from the parent to the new sb */
2484 security_sb_clone_mnt_opts(data->sb, s);
2485
Al Viro31f43472010-10-29 03:38:12 -04002486 dprintk("<-- nfs_xdev_mount() = 0\n");
2487 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04002488
2489out_err_nosb:
2490 nfs_free_server(server);
2491out_err_noserver:
Al Viro31f43472010-10-29 03:38:12 -04002492 dprintk("<-- nfs_xdev_mount() = %d [error]\n", error);
2493 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04002494
2495error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002496 if (server && !s->s_root)
2497 bdi_unregister(&server->backing_dev_info);
2498error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002499 deactivate_locked_super(s);
Al Viro31f43472010-10-29 03:38:12 -04002500 dprintk("<-- nfs_xdev_mount() = %d [splat]\n", error);
2501 return ERR_PTR(error);
David Howellsf7b422b2006-06-09 09:34:33 -04002502}
2503
2504#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04002505
2506/*
2507 * Finish setting up a cloned NFS4 superblock
2508 */
2509static void nfs4_clone_super(struct super_block *sb,
2510 const struct super_block *old_sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002511{
David Howells54ceac42006-08-22 20:06:13 -04002512 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2513 sb->s_blocksize = old_sb->s_blocksize;
2514 sb->s_maxbytes = old_sb->s_maxbytes;
2515 sb->s_time_gran = 1;
2516 sb->s_op = old_sb->s_op;
Aneesh Kumar K.Va8a5da92010-12-09 11:35:14 +00002517 /*
2518 * The VFS shouldn't apply the umask to mode bits. We will do
2519 * so ourselves when necessary.
2520 */
2521 sb->s_flags |= MS_POSIXACL;
Aneesh Kumar K.V64c2ce82010-12-09 11:35:25 +00002522 sb->s_xattr = old_sb->s_xattr;
2523 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002524}
2525
2526/*
2527 * Set up an NFS4 superblock
2528 */
David Howells54ceac42006-08-22 20:06:13 -04002529static void nfs4_fill_super(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002530{
David Howellsf7b422b2006-06-09 09:34:33 -04002531 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04002532 sb->s_op = &nfs4_sops;
Aneesh Kumar K.Va8a5da92010-12-09 11:35:14 +00002533 /*
2534 * The VFS shouldn't apply the umask to mode bits. We will do
2535 * so ourselves when necessary.
2536 */
2537 sb->s_flags |= MS_POSIXACL;
Aneesh Kumar K.V64c2ce82010-12-09 11:35:25 +00002538 sb->s_xattr = nfs4_xattr_handlers;
David Howells54ceac42006-08-22 20:06:13 -04002539 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002540}
2541
Trond Myklebust01c3f052009-06-17 13:22:58 -07002542static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2543{
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04002544 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3|
2545 NFS_MOUNT_LOCAL_FLOCK|NFS_MOUNT_LOCAL_FCNTL);
Trond Myklebust01c3f052009-06-17 13:22:58 -07002546}
2547
Chuck Lever7630c852009-09-08 19:49:57 -04002548static int nfs4_validate_text_mount_data(void *options,
2549 struct nfs_parsed_mount_data *args,
2550 const char *dev_name)
2551{
2552 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2553
Trond Myklebustf5855fe2009-10-06 15:40:37 -04002554 nfs_set_port(sap, &args->nfs_server.port, NFS_PORT);
Chuck Lever7630c852009-09-08 19:49:57 -04002555
2556 nfs_validate_transport_protocol(args);
2557
2558 nfs4_validate_mount_flags(args);
2559
Trond Myklebust2ecda722009-09-08 19:50:07 -04002560 if (args->version != 4) {
2561 dfprintk(MOUNT,
2562 "NFS4: Illegal mount version\n");
2563 return -EINVAL;
2564 }
2565
Chuck Lever7630c852009-09-08 19:49:57 -04002566 if (args->auth_flavor_len > 1) {
2567 dfprintk(MOUNT,
2568 "NFS4: Too many RPC auth flavours specified\n");
2569 return -EINVAL;
2570 }
2571
2572 if (args->client_address == NULL) {
2573 dfprintk(MOUNT,
2574 "NFS4: mount program didn't pass callback address\n");
2575 return -EINVAL;
2576 }
2577
2578 return nfs_parse_devname(dev_name,
2579 &args->nfs_server.hostname,
2580 NFS4_MAXNAMLEN,
2581 &args->nfs_server.export_path,
2582 NFS4_MAXPATHLEN);
2583}
2584
David Howells54ceac42006-08-22 20:06:13 -04002585/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04002586 * Validate NFSv4 mount options
2587 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002588static int nfs4_validate_mount_data(void *options,
2589 struct nfs_parsed_mount_data *args,
2590 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04002591{
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002592 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002593 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002594 char *c;
2595
2596 if (data == NULL)
2597 goto out_no_data;
2598
2599 switch (data->version) {
2600 case 1:
Chuck Lever4c568012007-12-10 14:59:28 -05002601 if (data->host_addrlen > sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002602 goto out_no_address;
Chuck Lever4c568012007-12-10 14:59:28 -05002603 if (data->host_addrlen == 0)
2604 goto out_no_address;
2605 args->nfs_server.addrlen = data->host_addrlen;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002606 if (copy_from_user(sap, data->host_addr, data->host_addrlen))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002607 return -EFAULT;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002608 if (!nfs_verify_server_address(sap))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002609 goto out_no_address;
2610
Chuck Lever6738b252008-06-24 16:33:54 -04002611 if (data->auth_flavourlen) {
2612 if (data->auth_flavourlen > 1)
2613 goto out_inval_auth;
Trond Myklebust20c71f52007-09-20 20:23:51 -04002614 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002615 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04002616 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002617 return -EFAULT;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002618 }
2619
2620 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2621 if (IS_ERR(c))
2622 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002623 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002624
2625 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2626 if (IS_ERR(c))
2627 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002628 args->nfs_server.export_path = c;
2629 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002630
2631 c = strndup_user(data->client_addr.data, 16);
2632 if (IS_ERR(c))
2633 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002634 args->client_address = c;
2635
2636 /*
2637 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2638 * can deal with.
2639 */
2640
2641 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2642 args->rsize = data->rsize;
2643 args->wsize = data->wsize;
2644 args->timeo = data->timeo;
2645 args->retrans = data->retrans;
2646 args->acregmin = data->acregmin;
2647 args->acregmax = data->acregmax;
2648 args->acdirmin = data->acdirmin;
2649 args->acdirmax = data->acdirmax;
2650 args->nfs_server.protocol = data->proto;
Trond Myklebust259875e2008-07-02 14:43:47 -04002651 nfs_validate_transport_protocol(args);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002652
2653 break;
Chuck Lever7630c852009-09-08 19:49:57 -04002654 default:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002655 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever80071222007-07-01 12:13:59 -04002656 return -EINVAL;
2657
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002658 if (!nfs_verify_server_address(sap))
Chuck Lever80071222007-07-01 12:13:59 -04002659 return -EINVAL;
Chuck Levered596a82008-06-26 17:47:05 -04002660
Chuck Lever7630c852009-09-08 19:49:57 -04002661 return nfs4_validate_text_mount_data(options, args, dev_name);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002662 }
2663
2664 return 0;
2665
2666out_no_data:
2667 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2668 return -EINVAL;
2669
2670out_inval_auth:
2671 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2672 data->auth_flavourlen);
2673 return -EINVAL;
2674
2675out_no_address:
2676 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2677 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002678}
2679
2680/*
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002681 * Get the superblock for the NFS4 root partition
David Howells54ceac42006-08-22 20:06:13 -04002682 */
Al Viro31f43472010-10-29 03:38:12 -04002683static struct dentry *
2684nfs4_remote_mount(struct file_system_type *fs_type, int flags,
2685 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002686{
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002687 struct nfs_parsed_mount_data *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002688 struct super_block *s;
2689 struct nfs_server *server;
Trond Myklebust33852a12008-06-19 14:20:11 -04002690 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04002691 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002692 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002693 struct nfs_sb_mountdata sb_mntdata = {
2694 .mntflags = flags,
2695 };
Trond Myklebust33852a12008-06-19 14:20:11 -04002696 int error = -ENOMEM;
David Howellsf7b422b2006-06-09 09:34:33 -04002697
Trond Myklebustb157b062010-04-19 19:05:48 -04002698 mntfh = nfs_alloc_fhandle();
Trond Myklebust33852a12008-06-19 14:20:11 -04002699 if (data == NULL || mntfh == NULL)
Jeff Layton8a0d5512011-12-20 06:57:45 -05002700 goto out;
Eric Parisf9c3a382008-03-05 14:20:18 -05002701
David Howells54ceac42006-08-22 20:06:13 -04002702 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002703 server = nfs4_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002704 if (IS_ERR(server)) {
2705 error = PTR_ERR(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04002706 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002707 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002708 sb_mntdata.server = server;
David Howellsf7b422b2006-06-09 09:34:33 -04002709
Trond Myklebust75180df2007-05-16 16:53:28 -04002710 if (server->flags & NFS4_MOUNT_UNSHARED)
2711 compare_super = NULL;
2712
Sachin Prabhufb2088c2011-08-01 12:10:12 +01002713 /* -o noac implies -o sync */
2714 if (server->flags & NFS_MOUNT_NOAC)
2715 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2716
David Howells54ceac42006-08-22 20:06:13 -04002717 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002718 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002719 if (IS_ERR(s)) {
2720 error = PTR_ERR(s);
David Howellsf7b422b2006-06-09 09:34:33 -04002721 goto out_free;
Trond Myklebust816724e2006-06-24 08:41:41 -04002722 }
2723
Trond Myklebust5dd31772006-08-24 01:03:05 -04002724 if (s->s_fs_info != server) {
2725 nfs_free_server(server);
2726 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002727 } else {
2728 error = nfs_bdi_register(server);
2729 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11002730 goto error_splat_bdi;
Trond Myklebust5dd31772006-08-24 01:03:05 -04002731 }
2732
David Howells54ceac42006-08-22 20:06:13 -04002733 if (!s->s_root) {
2734 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002735 nfs4_fill_super(s);
Jeff Laytonc15c9282012-01-24 16:35:00 +00002736 nfs_fscache_get_super_cookie(s, data->fscache_uniq, NULL);
Trond Myklebust816724e2006-06-24 08:41:41 -04002737 }
David Howellsf7b422b2006-06-09 09:34:33 -04002738
Al Viro0d5839a2011-03-16 05:27:27 -04002739 mntroot = nfs4_get_root(s, mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04002740 if (IS_ERR(mntroot)) {
2741 error = PTR_ERR(mntroot);
2742 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04002743 }
David Howells54ceac42006-08-22 20:06:13 -04002744
Trond Myklebust33852a12008-06-19 14:20:11 -04002745 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Paris46c8ac72008-05-02 13:42:42 -07002746 if (error)
2747 goto error_splat_root;
2748
David Howellsf7b422b2006-06-09 09:34:33 -04002749 s->s_flags |= MS_ACTIVE;
Al Viro31f43472010-10-29 03:38:12 -04002750
Al Viro31f43472010-10-29 03:38:12 -04002751 nfs_free_fhandle(mntfh);
2752 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04002753
Chuck Lever29eb9812007-07-01 12:12:30 -04002754out:
Trond Myklebustb157b062010-04-19 19:05:48 -04002755 nfs_free_fhandle(mntfh);
Al Viro31f43472010-10-29 03:38:12 -04002756 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04002757
Chuck Lever29eb9812007-07-01 12:12:30 -04002758out_free:
2759 nfs_free_server(server);
2760 goto out;
2761
Eric Paris46c8ac72008-05-02 13:42:42 -07002762error_splat_root:
2763 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04002764error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002765 if (server && !s->s_root)
2766 bdi_unregister(&server->backing_dev_info);
2767error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002768 deactivate_locked_super(s);
Chuck Lever29eb9812007-07-01 12:12:30 -04002769 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002770}
2771
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002772static struct vfsmount *nfs_do_root_mount(struct file_system_type *fs_type,
2773 int flags, void *data, const char *hostname)
2774{
2775 struct vfsmount *root_mnt;
2776 char *root_devname;
2777 size_t len;
2778
2779 len = strlen(hostname) + 3;
2780 root_devname = kmalloc(len, GFP_KERNEL);
2781 if (root_devname == NULL)
2782 return ERR_PTR(-ENOMEM);
2783 snprintf(root_devname, len, "%s:/", hostname);
2784 root_mnt = vfs_kern_mount(fs_type, flags, root_devname, data);
2785 kfree(root_devname);
2786 return root_mnt;
2787}
2788
Trond Myklebustce587e02010-04-16 16:22:52 -04002789struct nfs_referral_count {
2790 struct list_head list;
2791 const struct task_struct *task;
2792 unsigned int referral_count;
2793};
2794
2795static LIST_HEAD(nfs_referral_count_list);
2796static DEFINE_SPINLOCK(nfs_referral_count_list_lock);
2797
2798static struct nfs_referral_count *nfs_find_referral_count(void)
2799{
2800 struct nfs_referral_count *p;
2801
2802 list_for_each_entry(p, &nfs_referral_count_list, list) {
2803 if (p->task == current)
2804 return p;
2805 }
2806 return NULL;
2807}
2808
2809#define NFS_MAX_NESTED_REFERRALS 2
2810
2811static int nfs_referral_loop_protect(void)
2812{
2813 struct nfs_referral_count *p, *new;
2814 int ret = -ENOMEM;
2815
2816 new = kmalloc(sizeof(*new), GFP_KERNEL);
2817 if (!new)
2818 goto out;
2819 new->task = current;
2820 new->referral_count = 1;
2821
2822 ret = 0;
2823 spin_lock(&nfs_referral_count_list_lock);
2824 p = nfs_find_referral_count();
2825 if (p != NULL) {
2826 if (p->referral_count >= NFS_MAX_NESTED_REFERRALS)
2827 ret = -ELOOP;
2828 else
2829 p->referral_count++;
2830 } else {
2831 list_add(&new->list, &nfs_referral_count_list);
2832 new = NULL;
2833 }
2834 spin_unlock(&nfs_referral_count_list_lock);
2835 kfree(new);
2836out:
2837 return ret;
2838}
2839
2840static void nfs_referral_loop_unprotect(void)
2841{
2842 struct nfs_referral_count *p;
2843
2844 spin_lock(&nfs_referral_count_list_lock);
2845 p = nfs_find_referral_count();
2846 p->referral_count--;
2847 if (p->referral_count == 0)
2848 list_del(&p->list);
2849 else
2850 p = NULL;
2851 spin_unlock(&nfs_referral_count_list_lock);
2852 kfree(p);
2853}
2854
Al Viro01194982011-03-16 07:25:36 -04002855static struct dentry *nfs_follow_remote_path(struct vfsmount *root_mnt,
2856 const char *export_path)
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002857{
Al Viro01194982011-03-16 07:25:36 -04002858 struct dentry *dentry;
Al Viro5352d3b2011-11-16 21:52:06 -05002859 int err;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002860
Al Viro5352d3b2011-11-16 21:52:06 -05002861 if (IS_ERR(root_mnt))
2862 return ERR_CAST(root_mnt);
2863
2864 err = nfs_referral_loop_protect();
2865 if (err) {
Al Viroea441d12011-11-16 21:43:59 -05002866 mntput(root_mnt);
Al Viro5352d3b2011-11-16 21:52:06 -05002867 return ERR_PTR(err);
Al Viroc1334492011-11-16 16:12:14 -05002868 }
Trond Myklebustce587e02010-04-16 16:22:52 -04002869
Al Viroea441d12011-11-16 21:43:59 -05002870 dentry = mount_subtree(root_mnt, export_path);
2871 nfs_referral_loop_unprotect();
Linus Torvaldsa2770d82009-12-17 12:51:05 -08002872
Al Viro01194982011-03-16 07:25:36 -04002873 return dentry;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002874}
2875
Al Viro01194982011-03-16 07:25:36 -04002876static struct dentry *nfs4_try_mount(int flags, const char *dev_name,
2877 struct nfs_parsed_mount_data *data)
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002878{
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002879 char *export_path;
2880 struct vfsmount *root_mnt;
Al Viro01194982011-03-16 07:25:36 -04002881 struct dentry *res;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002882
Chuck Levera6fe23b2009-09-08 19:50:00 -04002883 dfprintk(MOUNT, "--> nfs4_try_mount()\n");
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002884
2885 export_path = data->nfs_server.export_path;
2886 data->nfs_server.export_path = "/";
2887 root_mnt = nfs_do_root_mount(&nfs4_remote_fs_type, flags, data,
2888 data->nfs_server.hostname);
2889 data->nfs_server.export_path = export_path;
2890
Al Viro5352d3b2011-11-16 21:52:06 -05002891 res = nfs_follow_remote_path(root_mnt, export_path);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002892
Al Viro01194982011-03-16 07:25:36 -04002893 dfprintk(MOUNT, "<-- nfs4_try_mount() = %ld%s\n",
2894 IS_ERR(res) ? PTR_ERR(res) : 0,
2895 IS_ERR(res) ? " [error]" : "");
2896 return res;
Chuck Levera6fe23b2009-09-08 19:50:00 -04002897}
2898
2899/*
2900 * Get the superblock for an NFS4 mountpoint
2901 */
Al Viro01194982011-03-16 07:25:36 -04002902static struct dentry *nfs4_mount(struct file_system_type *fs_type,
2903 int flags, const char *dev_name, void *raw_data)
Chuck Levera6fe23b2009-09-08 19:50:00 -04002904{
2905 struct nfs_parsed_mount_data *data;
2906 int error = -ENOMEM;
Al Viro01194982011-03-16 07:25:36 -04002907 struct dentry *res = ERR_PTR(-ENOMEM);
Chuck Levera6fe23b2009-09-08 19:50:00 -04002908
Trond Myklebustc5811db2009-10-06 15:40:15 -04002909 data = nfs_alloc_parsed_mount_data(4);
Chuck Levera6fe23b2009-09-08 19:50:00 -04002910 if (data == NULL)
Jeff Layton8a0d5512011-12-20 06:57:45 -05002911 goto out;
Chuck Levera6fe23b2009-09-08 19:50:00 -04002912
2913 /* Validate the mount data */
2914 error = nfs4_validate_mount_data(raw_data, data, dev_name);
Al Viro01194982011-03-16 07:25:36 -04002915 if (error < 0) {
2916 res = ERR_PTR(error);
Chuck Levera6fe23b2009-09-08 19:50:00 -04002917 goto out;
Al Viro01194982011-03-16 07:25:36 -04002918 }
Chuck Levera6fe23b2009-09-08 19:50:00 -04002919
Al Viro01194982011-03-16 07:25:36 -04002920 res = nfs4_try_mount(flags, dev_name, data);
2921 if (IS_ERR(res))
2922 error = PTR_ERR(res);
Chuck Levera6fe23b2009-09-08 19:50:00 -04002923
2924out:
Jeff Layton8a0d5512011-12-20 06:57:45 -05002925 nfs_free_parsed_mount_data(data);
Al Viro01194982011-03-16 07:25:36 -04002926 dprintk("<-- nfs4_mount() = %d%s\n", error,
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002927 error != 0 ? " [error]" : "");
Al Viro01194982011-03-16 07:25:36 -04002928 return res;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002929}
2930
David Howellsf7b422b2006-06-09 09:34:33 -04002931static void nfs4_kill_super(struct super_block *sb)
2932{
2933 struct nfs_server *server = NFS_SB(sb);
2934
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002935 dprintk("--> %s\n", __func__);
Trond Myklebust515d8612008-12-23 15:21:46 -05002936 nfs_super_return_all_delegations(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002937 kill_anon_super(sb);
David Howells08734042009-04-03 16:42:42 +01002938 nfs_fscache_release_super_cookie(sb);
David Howells54ceac42006-08-22 20:06:13 -04002939 nfs_free_server(server);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002940 dprintk("<-- %s\n", __func__);
David Howellsf7b422b2006-06-09 09:34:33 -04002941}
2942
2943/*
David Howells54ceac42006-08-22 20:06:13 -04002944 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -04002945 */
Al Viro31f43472010-10-29 03:38:12 -04002946static struct dentry *
2947nfs4_xdev_mount(struct file_system_type *fs_type, int flags,
2948 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002949{
2950 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002951 struct super_block *s;
2952 struct nfs_server *server;
2953 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002954 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002955 struct nfs_sb_mountdata sb_mntdata = {
2956 .mntflags = flags,
2957 };
David Howells54ceac42006-08-22 20:06:13 -04002958 int error;
2959
Al Viro31f43472010-10-29 03:38:12 -04002960 dprintk("--> nfs4_xdev_mount()\n");
David Howells54ceac42006-08-22 20:06:13 -04002961
2962 /* create a new volume representation */
2963 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2964 if (IS_ERR(server)) {
2965 error = PTR_ERR(server);
2966 goto out_err_noserver;
2967 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002968 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002969
Trond Myklebust75180df2007-05-16 16:53:28 -04002970 if (server->flags & NFS4_MOUNT_UNSHARED)
2971 compare_super = NULL;
2972
Sachin Prabhufb2088c2011-08-01 12:10:12 +01002973 /* -o noac implies -o sync */
2974 if (server->flags & NFS_MOUNT_NOAC)
2975 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2976
David Howells54ceac42006-08-22 20:06:13 -04002977 /* Get a superblock - note that we may end up sharing one that already exists */
Andy Adamsonec9a05c2008-10-17 10:44:37 -04002978 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002979 if (IS_ERR(s)) {
2980 error = PTR_ERR(s);
2981 goto out_err_nosb;
2982 }
2983
2984 if (s->s_fs_info != server) {
2985 nfs_free_server(server);
2986 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002987 } else {
2988 error = nfs_bdi_register(server);
2989 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11002990 goto error_splat_bdi;
David Howells54ceac42006-08-22 20:06:13 -04002991 }
2992
2993 if (!s->s_root) {
2994 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002995 nfs4_clone_super(s, data->sb);
David Howells2df54802009-09-23 14:36:39 -04002996 nfs_fscache_get_super_cookie(s, NULL, data);
David Howells54ceac42006-08-22 20:06:13 -04002997 }
2998
Al Viro0d5839a2011-03-16 05:27:27 -04002999 mntroot = nfs4_get_root(s, data->fh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04003000 if (IS_ERR(mntroot)) {
3001 error = PTR_ERR(mntroot);
3002 goto error_splat_super;
3003 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05003004 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
3005 dput(mntroot);
3006 error = -ESTALE;
3007 goto error_splat_super;
3008 }
David Howells54ceac42006-08-22 20:06:13 -04003009
3010 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04003011
Eric Paris46c8ac72008-05-02 13:42:42 -07003012 security_sb_clone_mnt_opts(data->sb, s);
3013
Al Viro31f43472010-10-29 03:38:12 -04003014 dprintk("<-- nfs4_xdev_mount() = 0\n");
3015 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04003016
3017out_err_nosb:
3018 nfs_free_server(server);
3019out_err_noserver:
Al Viro31f43472010-10-29 03:38:12 -04003020 dprintk("<-- nfs4_xdev_mount() = %d [error]\n", error);
3021 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04003022
3023error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11003024 if (server && !s->s_root)
3025 bdi_unregister(&server->backing_dev_info);
3026error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04003027 deactivate_locked_super(s);
Al Viro31f43472010-10-29 03:38:12 -04003028 dprintk("<-- nfs4_xdev_mount() = %d [splat]\n", error);
3029 return ERR_PTR(error);
David Howellsf7b422b2006-06-09 09:34:33 -04003030}
3031
Al Viro31f43472010-10-29 03:38:12 -04003032static struct dentry *
3033nfs4_remote_referral_mount(struct file_system_type *fs_type, int flags,
3034 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04003035{
3036 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04003037 struct super_block *s;
3038 struct nfs_server *server;
3039 struct dentry *mntroot;
Trond Myklebust4f727292010-04-16 16:22:48 -04003040 struct nfs_fh *mntfh;
Trond Myklebust75180df2007-05-16 16:53:28 -04003041 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04003042 struct nfs_sb_mountdata sb_mntdata = {
3043 .mntflags = flags,
3044 };
Trond Myklebust4f727292010-04-16 16:22:48 -04003045 int error = -ENOMEM;
David Howells54ceac42006-08-22 20:06:13 -04003046
3047 dprintk("--> nfs4_referral_get_sb()\n");
3048
Trond Myklebust4f727292010-04-16 16:22:48 -04003049 mntfh = nfs_alloc_fhandle();
3050 if (mntfh == NULL)
3051 goto out_err_nofh;
3052
David Howells54ceac42006-08-22 20:06:13 -04003053 /* create a new volume representation */
Trond Myklebust4f727292010-04-16 16:22:48 -04003054 server = nfs4_create_referral_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04003055 if (IS_ERR(server)) {
3056 error = PTR_ERR(server);
3057 goto out_err_noserver;
3058 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04003059 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04003060
Trond Myklebust75180df2007-05-16 16:53:28 -04003061 if (server->flags & NFS4_MOUNT_UNSHARED)
3062 compare_super = NULL;
3063
Sachin Prabhufb2088c2011-08-01 12:10:12 +01003064 /* -o noac implies -o sync */
3065 if (server->flags & NFS_MOUNT_NOAC)
3066 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
3067
David Howells54ceac42006-08-22 20:06:13 -04003068 /* Get a superblock - note that we may end up sharing one that already exists */
Andy Adamsonec9a05c2008-10-17 10:44:37 -04003069 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04003070 if (IS_ERR(s)) {
3071 error = PTR_ERR(s);
3072 goto out_err_nosb;
3073 }
3074
3075 if (s->s_fs_info != server) {
3076 nfs_free_server(server);
3077 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07003078 } else {
3079 error = nfs_bdi_register(server);
3080 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11003081 goto error_splat_bdi;
David Howells54ceac42006-08-22 20:06:13 -04003082 }
3083
3084 if (!s->s_root) {
3085 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04003086 nfs4_fill_super(s);
David Howells2df54802009-09-23 14:36:39 -04003087 nfs_fscache_get_super_cookie(s, NULL, data);
David Howells54ceac42006-08-22 20:06:13 -04003088 }
3089
Al Viro0d5839a2011-03-16 05:27:27 -04003090 mntroot = nfs4_get_root(s, mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04003091 if (IS_ERR(mntroot)) {
3092 error = PTR_ERR(mntroot);
3093 goto error_splat_super;
3094 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05003095 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
3096 dput(mntroot);
3097 error = -ESTALE;
3098 goto error_splat_super;
3099 }
David Howells54ceac42006-08-22 20:06:13 -04003100
3101 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04003102
Eric Paris46c8ac72008-05-02 13:42:42 -07003103 security_sb_clone_mnt_opts(data->sb, s);
3104
Trond Myklebust4f727292010-04-16 16:22:48 -04003105 nfs_free_fhandle(mntfh);
David Howells54ceac42006-08-22 20:06:13 -04003106 dprintk("<-- nfs4_referral_get_sb() = 0\n");
Al Viro31f43472010-10-29 03:38:12 -04003107 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04003108
3109out_err_nosb:
3110 nfs_free_server(server);
3111out_err_noserver:
Trond Myklebust4f727292010-04-16 16:22:48 -04003112 nfs_free_fhandle(mntfh);
3113out_err_nofh:
David Howells54ceac42006-08-22 20:06:13 -04003114 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
Al Viro31f43472010-10-29 03:38:12 -04003115 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04003116
3117error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11003118 if (server && !s->s_root)
3119 bdi_unregister(&server->backing_dev_info);
3120error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04003121 deactivate_locked_super(s);
Trond Myklebust4f727292010-04-16 16:22:48 -04003122 nfs_free_fhandle(mntfh);
David Howells54ceac42006-08-22 20:06:13 -04003123 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
Al Viro31f43472010-10-29 03:38:12 -04003124 return ERR_PTR(error);
David Howellsf7b422b2006-06-09 09:34:33 -04003125}
3126
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04003127/*
3128 * Create an NFS4 server record on referral traversal
3129 */
Al Viro01194982011-03-16 07:25:36 -04003130static struct dentry *nfs4_referral_mount(struct file_system_type *fs_type,
3131 int flags, const char *dev_name, void *raw_data)
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04003132{
3133 struct nfs_clone_mount *data = raw_data;
3134 char *export_path;
3135 struct vfsmount *root_mnt;
Al Viro01194982011-03-16 07:25:36 -04003136 struct dentry *res;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04003137
Al Viro01194982011-03-16 07:25:36 -04003138 dprintk("--> nfs4_referral_mount()\n");
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04003139
3140 export_path = data->mnt_path;
3141 data->mnt_path = "/";
3142
3143 root_mnt = nfs_do_root_mount(&nfs4_remote_referral_fs_type,
3144 flags, data, data->hostname);
3145 data->mnt_path = export_path;
3146
Al Viro5352d3b2011-11-16 21:52:06 -05003147 res = nfs_follow_remote_path(root_mnt, export_path);
Al Viro01194982011-03-16 07:25:36 -04003148 dprintk("<-- nfs4_referral_mount() = %ld%s\n",
3149 IS_ERR(res) ? PTR_ERR(res) : 0,
3150 IS_ERR(res) ? " [error]" : "");
3151 return res;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04003152}
3153
David Howells54ceac42006-08-22 20:06:13 -04003154#endif /* CONFIG_NFS_V4 */