blob: 7f0c93f8afe3d21ec4b56c4d0f3605a8d5da6f2d [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);
Trond Myklebust0be81892010-06-18 12:23:58 -0400643}
644#else
645static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
646 int showdefaults)
647{
648}
649#endif
650
Trond Myklebust7bbceb62012-03-02 14:00:20 -0500651static void nfs_show_nfs_version(struct seq_file *m,
652 unsigned int version,
653 unsigned int minorversion)
654{
655 seq_printf(m, ",vers=%u", version);
656 if (version == 4)
657 seq_printf(m, ".%u", minorversion);
658}
659
David Howellsf7b422b2006-06-09 09:34:33 -0400660/*
661 * Describe the mount options in force on this server representation
662 */
Chuck Lever82d101d2008-03-14 14:10:37 -0400663static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
664 int showdefaults)
David Howellsf7b422b2006-06-09 09:34:33 -0400665{
David Howells509de812006-08-22 20:06:11 -0400666 static const struct proc_nfs_info {
David Howellsf7b422b2006-06-09 09:34:33 -0400667 int flag;
David Howells509de812006-08-22 20:06:11 -0400668 const char *str;
669 const char *nostr;
David Howellsf7b422b2006-06-09 09:34:33 -0400670 } nfs_info[] = {
671 { NFS_MOUNT_SOFT, ",soft", ",hard" },
Chuck Lever82d101d2008-03-14 14:10:37 -0400672 { NFS_MOUNT_POSIX, ",posix", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400673 { NFS_MOUNT_NOCTO, ",nocto", "" },
674 { NFS_MOUNT_NOAC, ",noac", "" },
675 { NFS_MOUNT_NONLM, ",nolock", "" },
676 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400677 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
Chuck Leverd7403512008-12-23 15:21:37 -0500678 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
679 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400680 { 0, NULL, NULL }
681 };
David Howells509de812006-08-22 20:06:11 -0400682 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400683 struct nfs_client *clp = nfss->nfs_client;
Chuck Lever82d101d2008-03-14 14:10:37 -0400684 u32 version = clp->rpc_ops->version;
Suresh Jayaraman7c563cc2010-09-23 14:26:48 -0400685 int local_flock, local_fcntl;
David Howellsf7b422b2006-06-09 09:34:33 -0400686
Trond Myklebust7bbceb62012-03-02 14:00:20 -0500687 nfs_show_nfs_version(m, version, clp->cl_minorversion);
Chuck Lever2d767432008-03-14 14:10:08 -0400688 seq_printf(m, ",rsize=%u", nfss->rsize);
689 seq_printf(m, ",wsize=%u", nfss->wsize);
Chuck Lever82d101d2008-03-14 14:10:37 -0400690 if (nfss->bsize != 0)
691 seq_printf(m, ",bsize=%u", nfss->bsize);
692 seq_printf(m, ",namlen=%u", nfss->namelen);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400693 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400694 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400695 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400696 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400697 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400698 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400699 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400700 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
David Howellsf7b422b2006-06-09 09:34:33 -0400701 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
702 if (nfss->flags & nfs_infop->flag)
703 seq_puts(m, nfs_infop->str);
704 else
705 seq_puts(m, nfs_infop->nostr);
706 }
\"Talpey, Thomas\56928ed2007-09-10 13:48:47 -0400707 seq_printf(m, ",proto=%s",
Jeff Laytonee671b02009-12-03 15:58:56 -0500708 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
Chuck Lever82d101d2008-03-14 14:10:37 -0400709 if (version == 4) {
710 if (nfss->port != NFS_PORT)
711 seq_printf(m, ",port=%u", nfss->port);
712 } else
713 if (nfss->port)
714 seq_printf(m, ",port=%u", nfss->port);
715
Trond Myklebust33170232007-12-20 16:03:59 -0500716 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
717 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
Trond Myklebust81039f12006-06-09 09:34:34 -0400718 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
Chuck Lever82d101d2008-03-14 14:10:37 -0400719
720 if (version != 4)
721 nfs_show_mountd_options(m, nfss, showdefaults);
Trond Myklebust0be81892010-06-18 12:23:58 -0400722 else
723 nfs_show_nfsv4_options(m, nfss, showdefaults);
Chuck Lever82d101d2008-03-14 14:10:37 -0400724
David Howellsb797cac2009-04-03 16:42:48 +0100725 if (nfss->options & NFS_OPTION_FSCACHE)
726 seq_printf(m, ",fsc");
Patrick J. LoPresti9b00c642010-08-10 17:28:01 -0400727
728 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONEG) {
729 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONE)
730 seq_printf(m, ",lookupcache=none");
731 else
732 seq_printf(m, ",lookupcache=pos");
733 }
Suresh Jayaraman7c563cc2010-09-23 14:26:48 -0400734
735 local_flock = nfss->flags & NFS_MOUNT_LOCAL_FLOCK;
736 local_fcntl = nfss->flags & NFS_MOUNT_LOCAL_FCNTL;
737
738 if (!local_flock && !local_fcntl)
739 seq_printf(m, ",local_lock=none");
740 else if (local_flock && local_fcntl)
741 seq_printf(m, ",local_lock=all");
742 else if (local_flock)
743 seq_printf(m, ",local_lock=flock");
744 else
745 seq_printf(m, ",local_lock=posix");
David Howellsf7b422b2006-06-09 09:34:33 -0400746}
747
748/*
749 * Describe the mount options on this VFS mountpoint
750 */
Al Viro34c80b12011-12-08 21:32:45 -0500751static int nfs_show_options(struct seq_file *m, struct dentry *root)
David Howellsf7b422b2006-06-09 09:34:33 -0400752{
Al Viro34c80b12011-12-08 21:32:45 -0500753 struct nfs_server *nfss = NFS_SB(root->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400754
755 nfs_show_mount_options(m, nfss, 0);
756
Chuck Lever5d8515c2007-12-10 14:57:16 -0500757 seq_printf(m, ",addr=%s",
758 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
759 RPC_DISPLAY_ADDR));
David Howellsf7b422b2006-06-09 09:34:33 -0400760
761 return 0;
762}
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700763
764#ifdef CONFIG_NFS_V4
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300765#ifdef CONFIG_NFS_V4_1
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700766static void show_sessions(struct seq_file *m, struct nfs_server *server)
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300767{
768 if (nfs4_has_session(server->nfs_client))
769 seq_printf(m, ",sessions");
770}
771#else
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700772static void show_sessions(struct seq_file *m, struct nfs_server *server) {}
773#endif
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300774#endif
775
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700776#ifdef CONFIG_NFS_V4
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300777#ifdef CONFIG_NFS_V4_1
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700778static void show_pnfs(struct seq_file *m, struct nfs_server *server)
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300779{
780 seq_printf(m, ",pnfs=");
781 if (server->pnfs_curr_ld)
782 seq_printf(m, "%s", server->pnfs_curr_ld->name);
783 else
784 seq_printf(m, "not configured");
785}
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700786#else
787static void show_pnfs(struct seq_file *m, struct nfs_server *server) {}
788#endif
789#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400790
Al Virod861c632011-12-08 21:32:45 -0500791static int nfs_show_devname(struct seq_file *m, struct dentry *root)
Al Viroc7f404b2011-03-16 06:59:40 -0400792{
793 char *page = (char *) __get_free_page(GFP_KERNEL);
794 char *devname, *dummy;
795 int err = 0;
796 if (!page)
797 return -ENOMEM;
Al Virod861c632011-12-08 21:32:45 -0500798 devname = nfs_path(&dummy, root, page, PAGE_SIZE);
Al Viroc7f404b2011-03-16 06:59:40 -0400799 if (IS_ERR(devname))
800 err = PTR_ERR(devname);
801 else
802 seq_escape(m, devname, " \t\n\\");
803 free_page((unsigned long)page);
804 return err;
805}
806
Al Viroa6322de2011-12-08 21:37:57 -0500807static int nfs_show_path(struct seq_file *m, struct dentry *dentry)
Al Viroc7f404b2011-03-16 06:59:40 -0400808{
809 seq_puts(m, "/");
810 return 0;
811}
812
David Howellsf7b422b2006-06-09 09:34:33 -0400813/*
814 * Present statistical information for this VFS mountpoint
815 */
Al Viro64132372011-12-08 20:51:13 -0500816static int nfs_show_stats(struct seq_file *m, struct dentry *root)
David Howellsf7b422b2006-06-09 09:34:33 -0400817{
818 int i, cpu;
Al Viro64132372011-12-08 20:51:13 -0500819 struct nfs_server *nfss = NFS_SB(root->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400820 struct rpc_auth *auth = nfss->client->cl_auth;
821 struct nfs_iostats totals = { };
822
823 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
824
825 /*
826 * Display all mount option settings
827 */
828 seq_printf(m, "\n\topts:\t");
Al Viro64132372011-12-08 20:51:13 -0500829 seq_puts(m, root->d_sb->s_flags & MS_RDONLY ? "ro" : "rw");
830 seq_puts(m, root->d_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
831 seq_puts(m, root->d_sb->s_flags & MS_NOATIME ? ",noatime" : "");
832 seq_puts(m, root->d_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
David Howellsf7b422b2006-06-09 09:34:33 -0400833 nfs_show_mount_options(m, nfss, 1);
834
835 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
836
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500837 if (nfss->nfs_client && nfss->nfs_client->impl_id) {
838 struct nfs41_impl_id *impl_id = nfss->nfs_client->impl_id;
839 seq_printf(m, "\n\timpl_id:\tname='%s',domain='%s',"
840 "date='%llu,%u'",
841 impl_id->name, impl_id->domain,
842 impl_id->date.seconds, impl_id->date.nseconds);
843 }
844
David Howellsf7b422b2006-06-09 09:34:33 -0400845 seq_printf(m, "\n\tcaps:\t");
846 seq_printf(m, "caps=0x%x", nfss->caps);
Chuck Lever2d767432008-03-14 14:10:08 -0400847 seq_printf(m, ",wtmult=%u", nfss->wtmult);
848 seq_printf(m, ",dtsize=%u", nfss->dtsize);
849 seq_printf(m, ",bsize=%u", nfss->bsize);
850 seq_printf(m, ",namlen=%u", nfss->namelen);
David Howellsf7b422b2006-06-09 09:34:33 -0400851
852#ifdef CONFIG_NFS_V4
Trond Myklebust40c553192007-12-14 14:56:07 -0500853 if (nfss->nfs_client->rpc_ops->version == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400854 seq_printf(m, "\n\tnfsv4:\t");
855 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
856 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
857 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300858 show_sessions(m, nfss);
859 show_pnfs(m, nfss);
David Howellsf7b422b2006-06-09 09:34:33 -0400860 }
861#endif
862
863 /*
864 * Display security flavor in effect for this mount
865 */
Chuck Lever2d767432008-03-14 14:10:08 -0400866 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400867 if (auth->au_flavor)
Chuck Lever2d767432008-03-14 14:10:08 -0400868 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400869
870 /*
871 * Display superblock I/O counters
872 */
873 for_each_possible_cpu(cpu) {
874 struct nfs_iostats *stats;
875
876 preempt_disable();
877 stats = per_cpu_ptr(nfss->io_stats, cpu);
878
879 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
880 totals.events[i] += stats->events[i];
881 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
882 totals.bytes[i] += stats->bytes[i];
David Howells6a510912009-04-03 16:42:43 +0100883#ifdef CONFIG_NFS_FSCACHE
884 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
885 totals.fscache[i] += stats->fscache[i];
886#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400887
888 preempt_enable();
889 }
890
891 seq_printf(m, "\n\tevents:\t");
892 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
893 seq_printf(m, "%lu ", totals.events[i]);
894 seq_printf(m, "\n\tbytes:\t");
895 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
896 seq_printf(m, "%Lu ", totals.bytes[i]);
David Howells6a510912009-04-03 16:42:43 +0100897#ifdef CONFIG_NFS_FSCACHE
898 if (nfss->options & NFS_OPTION_FSCACHE) {
899 seq_printf(m, "\n\tfsc:\t");
900 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
901 seq_printf(m, "%Lu ", totals.bytes[i]);
902 }
903#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400904 seq_printf(m, "\n");
905
906 rpc_print_iostats(m, nfss->client);
907
908 return 0;
909}
910
911/*
912 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400913 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400914 */
Al Viro42faad92008-04-24 07:21:56 -0400915static void nfs_umount_begin(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -0400916{
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200917 struct nfs_server *server;
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400918 struct rpc_clnt *rpc;
919
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200920 server = NFS_SB(sb);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400921 /* -EIO all pending I/O */
922 rpc = server->client_acl;
923 if (!IS_ERR(rpc))
924 rpc_killall_tasks(rpc);
925 rpc = server->client;
926 if (!IS_ERR(rpc))
927 rpc_killall_tasks(rpc);
David Howellsf7b422b2006-06-09 09:34:33 -0400928}
929
Trond Myklebustc5811db2009-10-06 15:40:15 -0400930static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(unsigned int version)
Chuck Lever9423a082009-09-23 14:36:38 -0400931{
932 struct nfs_parsed_mount_data *data;
933
934 data = kzalloc(sizeof(*data), GFP_KERNEL);
935 if (data) {
Chuck Lever9423a082009-09-23 14:36:38 -0400936 data->acregmin = NFS_DEF_ACREGMIN;
937 data->acregmax = NFS_DEF_ACREGMAX;
938 data->acdirmin = NFS_DEF_ACDIRMIN;
939 data->acdirmax = NFS_DEF_ACDIRMAX;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400940 data->mount_server.port = NFS_UNSPEC_PORT;
Chuck Lever9423a082009-09-23 14:36:38 -0400941 data->nfs_server.port = NFS_UNSPEC_PORT;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400942 data->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Lever9423a082009-09-23 14:36:38 -0400943 data->auth_flavors[0] = RPC_AUTH_UNIX;
944 data->auth_flavor_len = 1;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400945 data->version = version;
Chuck Lever9423a082009-09-23 14:36:38 -0400946 data->minorversion = 0;
Trond Myklebust9937347a2012-02-19 08:44:07 +0100947 data->net = current->nsproxy->net_ns;
Jeff Layton8a0d5512011-12-20 06:57:45 -0500948 security_init_mnt_opts(&data->lsm_opts);
Chuck Lever9423a082009-09-23 14:36:38 -0400949 }
950 return data;
951}
952
Jeff Layton8a0d5512011-12-20 06:57:45 -0500953static void nfs_free_parsed_mount_data(struct nfs_parsed_mount_data *data)
954{
955 if (data) {
956 kfree(data->client_address);
957 kfree(data->mount_server.hostname);
958 kfree(data->nfs_server.export_path);
959 kfree(data->nfs_server.hostname);
960 kfree(data->fscache_uniq);
961 security_free_mnt_opts(&data->lsm_opts);
962 kfree(data);
963 }
964}
965
David Howellsf7b422b2006-06-09 09:34:33 -0400966/*
Chuck Levercdcd7f92007-12-10 14:57:45 -0500967 * Sanity-check a server address provided by the mount command.
968 *
969 * Address family must be initialized, and address must not be
970 * the ANY address for that family.
Chuck Leverfc50d582007-07-01 12:12:46 -0400971 */
972static int nfs_verify_server_address(struct sockaddr *addr)
973{
974 switch (addr->sa_family) {
975 case AF_INET: {
Chuck Levercdcd7f92007-12-10 14:57:45 -0500976 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
Al Viroe6f1ceb2008-03-17 22:44:53 -0700977 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
Chuck Levercdcd7f92007-12-10 14:57:45 -0500978 }
979 case AF_INET6: {
980 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
981 return !ipv6_addr_any(sa);
Chuck Leverfc50d582007-07-01 12:12:46 -0400982 }
983 }
984
Chuck Lever53a0b9c2009-08-09 15:09:36 -0400985 dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
Chuck Leverfc50d582007-07-01 12:12:46 -0400986 return 0;
987}
988
Chuck Lever9412b922007-12-10 14:59:21 -0500989/*
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400990 * Select between a default port value and a user-specified port value.
991 * If a zero value is set, then autobind will be used.
992 */
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400993static void nfs_set_port(struct sockaddr *sap, int *port,
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400994 const unsigned short default_port)
995{
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400996 if (*port == NFS_UNSPEC_PORT)
997 *port = default_port;
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400998
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400999 rpc_set_port(sap, *port);
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001000}
1001
1002/*
Trond Myklebust259875e2008-07-02 14:43:47 -04001003 * Sanity check the NFS transport protocol.
1004 *
1005 */
1006static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
1007{
1008 switch (mnt->nfs_server.protocol) {
1009 case XPRT_TRANSPORT_UDP:
1010 case XPRT_TRANSPORT_TCP:
1011 case XPRT_TRANSPORT_RDMA:
1012 break;
1013 default:
1014 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1015 }
1016}
1017
1018/*
1019 * For text based NFSv2/v3 mounts, the mount protocol transport default
1020 * settings should depend upon the specified NFS transport.
1021 */
1022static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
1023{
1024 nfs_validate_transport_protocol(mnt);
1025
1026 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
1027 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
1028 return;
1029 switch (mnt->nfs_server.protocol) {
1030 case XPRT_TRANSPORT_UDP:
1031 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
1032 break;
1033 case XPRT_TRANSPORT_TCP:
1034 case XPRT_TRANSPORT_RDMA:
1035 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
1036 }
1037}
1038
1039/*
Chuck Lever01060c82008-06-24 16:33:38 -04001040 * Parse the value of the 'sec=' option.
Chuck Lever01060c82008-06-24 16:33:38 -04001041 */
1042static int nfs_parse_security_flavors(char *value,
1043 struct nfs_parsed_mount_data *mnt)
1044{
1045 substring_t args[MAX_OPT_ARGS];
1046
1047 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
1048
1049 switch (match_token(value, nfs_secflavor_tokens, args)) {
1050 case Opt_sec_none:
Chuck Lever01060c82008-06-24 16:33:38 -04001051 mnt->auth_flavors[0] = RPC_AUTH_NULL;
1052 break;
1053 case Opt_sec_sys:
Chuck Lever01060c82008-06-24 16:33:38 -04001054 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
1055 break;
1056 case Opt_sec_krb5:
Chuck Lever01060c82008-06-24 16:33:38 -04001057 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
1058 break;
1059 case Opt_sec_krb5i:
Chuck Lever01060c82008-06-24 16:33:38 -04001060 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
1061 break;
1062 case Opt_sec_krb5p:
Chuck Lever01060c82008-06-24 16:33:38 -04001063 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
1064 break;
1065 case Opt_sec_lkey:
Chuck Lever01060c82008-06-24 16:33:38 -04001066 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
1067 break;
1068 case Opt_sec_lkeyi:
Chuck Lever01060c82008-06-24 16:33:38 -04001069 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
1070 break;
1071 case Opt_sec_lkeyp:
Chuck Lever01060c82008-06-24 16:33:38 -04001072 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
1073 break;
1074 case Opt_sec_spkm:
Chuck Lever01060c82008-06-24 16:33:38 -04001075 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
1076 break;
1077 case Opt_sec_spkmi:
Chuck Lever01060c82008-06-24 16:33:38 -04001078 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
1079 break;
1080 case Opt_sec_spkmp:
Chuck Lever01060c82008-06-24 16:33:38 -04001081 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
1082 break;
1083 default:
1084 return 0;
1085 }
1086
Bryan Schumaker9b7160c2011-04-13 14:31:30 -04001087 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
Chuck Lever059f90b2009-08-09 15:09:31 -04001088 mnt->auth_flavor_len = 1;
Chuck Lever01060c82008-06-24 16:33:38 -04001089 return 1;
1090}
1091
Trond Myklebust0d71b052012-03-02 13:59:49 -05001092static int nfs_parse_version_string(char *string,
1093 struct nfs_parsed_mount_data *mnt,
1094 substring_t *args)
1095{
1096 mnt->flags &= ~NFS_MOUNT_VER3;
1097 switch (match_token(string, nfs_vers_tokens, args)) {
1098 case Opt_vers_2:
1099 mnt->version = 2;
1100 break;
1101 case Opt_vers_3:
1102 mnt->flags |= NFS_MOUNT_VER3;
1103 mnt->version = 3;
1104 break;
1105 case Opt_vers_4:
1106 /* Backward compatibility option. In future,
1107 * the mount program should always supply
1108 * a NFSv4 minor version number.
1109 */
1110 mnt->version = 4;
1111 break;
1112 case Opt_vers_4_0:
1113 mnt->version = 4;
1114 mnt->minorversion = 0;
1115 break;
1116 case Opt_vers_4_1:
1117 mnt->version = 4;
1118 mnt->minorversion = 1;
1119 break;
1120 default:
1121 return 0;
1122 }
1123 return 1;
1124}
1125
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001126static int nfs_get_option_str(substring_t args[], char **option)
1127{
1128 kfree(*option);
1129 *option = match_strdup(args);
1130 return !option;
1131}
1132
1133static int nfs_get_option_ul(substring_t args[], unsigned long *option)
1134{
1135 int rc;
1136 char *string;
1137
1138 string = match_strdup(args);
1139 if (string == NULL)
1140 return -ENOMEM;
1141 rc = strict_strtoul(string, 10, option);
1142 kfree(string);
1143
1144 return rc;
1145}
1146
Chuck Lever01060c82008-06-24 16:33:38 -04001147/*
Chuck Leverbf0fd762007-07-01 12:13:44 -04001148 * Error-check and convert a string of mount options from user space into
Chuck Leverf45663c2008-06-24 19:28:02 -04001149 * a data structure. The whole mount string is processed; bad options are
1150 * skipped as they are encountered. If there were no errors, return 1;
1151 * otherwise return 0 (zero).
Chuck Leverbf0fd762007-07-01 12:13:44 -04001152 */
1153static int nfs_parse_mount_options(char *raw,
1154 struct nfs_parsed_mount_data *mnt)
1155{
Eric Parisf9c3a382008-03-05 14:20:18 -05001156 char *p, *string, *secdata;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001157 int rc, sloppy = 0, invalid_option = 0;
Jeff Laytonee671b02009-12-03 15:58:56 -05001158 unsigned short protofamily = AF_UNSPEC;
1159 unsigned short mountfamily = AF_UNSPEC;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001160
1161 if (!raw) {
1162 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
1163 return 1;
1164 }
1165 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
1166
Eric Parisf9c3a382008-03-05 14:20:18 -05001167 secdata = alloc_secdata();
1168 if (!secdata)
1169 goto out_nomem;
1170
1171 rc = security_sb_copy_data(raw, secdata);
1172 if (rc)
1173 goto out_security_failure;
1174
1175 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
1176 if (rc)
1177 goto out_security_failure;
1178
1179 free_secdata(secdata);
1180
Chuck Leverbf0fd762007-07-01 12:13:44 -04001181 while ((p = strsep(&raw, ",")) != NULL) {
1182 substring_t args[MAX_OPT_ARGS];
Chuck Levera5a16ba2009-06-17 18:02:14 -07001183 unsigned long option;
1184 int token;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001185
1186 if (!*p)
1187 continue;
1188
1189 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
1190
1191 token = match_token(p, nfs_mount_option_tokens, args);
1192 switch (token) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001193
1194 /*
1195 * boolean options: foo/nofoo
1196 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001197 case Opt_soft:
1198 mnt->flags |= NFS_MOUNT_SOFT;
1199 break;
1200 case Opt_hard:
1201 mnt->flags &= ~NFS_MOUNT_SOFT;
1202 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001203 case Opt_posix:
1204 mnt->flags |= NFS_MOUNT_POSIX;
1205 break;
1206 case Opt_noposix:
1207 mnt->flags &= ~NFS_MOUNT_POSIX;
1208 break;
1209 case Opt_cto:
1210 mnt->flags &= ~NFS_MOUNT_NOCTO;
1211 break;
1212 case Opt_nocto:
1213 mnt->flags |= NFS_MOUNT_NOCTO;
1214 break;
1215 case Opt_ac:
1216 mnt->flags &= ~NFS_MOUNT_NOAC;
1217 break;
1218 case Opt_noac:
1219 mnt->flags |= NFS_MOUNT_NOAC;
1220 break;
1221 case Opt_lock:
1222 mnt->flags &= ~NFS_MOUNT_NONLM;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001223 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1224 NFS_MOUNT_LOCAL_FCNTL);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001225 break;
1226 case Opt_nolock:
1227 mnt->flags |= NFS_MOUNT_NONLM;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001228 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1229 NFS_MOUNT_LOCAL_FCNTL);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001230 break;
1231 case Opt_v2:
1232 mnt->flags &= ~NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -04001233 mnt->version = 2;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001234 break;
1235 case Opt_v3:
1236 mnt->flags |= NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -04001237 mnt->version = 3;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001238 break;
Chuck Lever764302c2009-09-08 19:50:03 -04001239 case Opt_v4:
1240 mnt->flags &= ~NFS_MOUNT_VER3;
1241 mnt->version = 4;
1242 break;
Weston Andros Adamson7ced2862012-02-07 11:49:11 -05001243 case Opt_v4_0:
1244 mnt->flags &= ~NFS_MOUNT_VER3;
1245 mnt->version = 4;
1246 mnt->minorversion = 0;
1247 break;
1248 case Opt_v4_1:
1249 mnt->flags &= ~NFS_MOUNT_VER3;
1250 mnt->version = 4;
1251 mnt->minorversion = 1;
1252 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001253 case Opt_udp:
1254 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001255 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001256 break;
1257 case Opt_tcp:
1258 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001259 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001260 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001261 case Opt_rdma:
1262 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1263 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001264 xprt_load_transport(p);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001265 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001266 case Opt_acl:
1267 mnt->flags &= ~NFS_MOUNT_NOACL;
1268 break;
1269 case Opt_noacl:
1270 mnt->flags |= NFS_MOUNT_NOACL;
1271 break;
1272 case Opt_rdirplus:
1273 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1274 break;
1275 case Opt_nordirplus:
1276 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1277 break;
Trond Myklebust75180df2007-05-16 16:53:28 -04001278 case Opt_sharecache:
1279 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1280 break;
1281 case Opt_nosharecache:
1282 mnt->flags |= NFS_MOUNT_UNSHARED;
1283 break;
Chuck Leverd7403512008-12-23 15:21:37 -05001284 case Opt_resvport:
1285 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1286 break;
1287 case Opt_noresvport:
1288 mnt->flags |= NFS_MOUNT_NORESVPORT;
1289 break;
David Howellsb797cac2009-04-03 16:42:48 +01001290 case Opt_fscache:
1291 mnt->options |= NFS_OPTION_FSCACHE;
1292 kfree(mnt->fscache_uniq);
1293 mnt->fscache_uniq = NULL;
1294 break;
1295 case Opt_nofscache:
1296 mnt->options &= ~NFS_OPTION_FSCACHE;
1297 kfree(mnt->fscache_uniq);
1298 mnt->fscache_uniq = NULL;
1299 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001300
Chuck Leverf45663c2008-06-24 19:28:02 -04001301 /*
1302 * options that take numeric values
1303 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001304 case Opt_port:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001305 if (nfs_get_option_ul(args, &option) ||
1306 option > USHRT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001307 goto out_invalid_value;
1308 mnt->nfs_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001309 break;
1310 case Opt_rsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001311 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001312 goto out_invalid_value;
1313 mnt->rsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001314 break;
1315 case Opt_wsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001316 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001317 goto out_invalid_value;
1318 mnt->wsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001319 break;
1320 case Opt_bsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001321 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001322 goto out_invalid_value;
1323 mnt->bsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001324 break;
1325 case Opt_timeo:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001326 if (nfs_get_option_ul(args, &option) || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001327 goto out_invalid_value;
1328 mnt->timeo = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001329 break;
1330 case Opt_retrans:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001331 if (nfs_get_option_ul(args, &option) || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001332 goto out_invalid_value;
1333 mnt->retrans = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001334 break;
1335 case Opt_acregmin:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001336 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001337 goto out_invalid_value;
1338 mnt->acregmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001339 break;
1340 case Opt_acregmax:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001341 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001342 goto out_invalid_value;
1343 mnt->acregmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001344 break;
1345 case Opt_acdirmin:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001346 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001347 goto out_invalid_value;
1348 mnt->acdirmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001349 break;
1350 case Opt_acdirmax:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001351 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001352 goto out_invalid_value;
1353 mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001354 break;
1355 case Opt_actimeo:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001356 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001357 goto out_invalid_value;
1358 mnt->acregmin = mnt->acregmax =
1359 mnt->acdirmin = mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001360 break;
1361 case Opt_namelen:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001362 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001363 goto out_invalid_value;
1364 mnt->namlen = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001365 break;
1366 case Opt_mountport:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001367 if (nfs_get_option_ul(args, &option) ||
1368 option > USHRT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001369 goto out_invalid_value;
1370 mnt->mount_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001371 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001372 case Opt_mountvers:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001373 if (nfs_get_option_ul(args, &option) ||
Chuck Leverf45663c2008-06-24 19:28:02 -04001374 option < NFS_MNT_VERSION ||
Chuck Leverd23c45f2009-06-17 18:02:13 -07001375 option > NFS_MNT3_VERSION)
1376 goto out_invalid_value;
1377 mnt->mount_server.version = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001378 break;
Mike Sager3fd5be92009-04-01 09:21:48 -04001379 case Opt_minorversion:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001380 if (nfs_get_option_ul(args, &option))
Chuck Leverf3f4f4e2009-08-09 15:09:29 -04001381 goto out_invalid_value;
1382 if (option > NFS4_MAX_MINOR_VERSION)
1383 goto out_invalid_value;
1384 mnt->minorversion = option;
Mike Sager3fd5be92009-04-01 09:21:48 -04001385 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001386
Chuck Leverf45663c2008-06-24 19:28:02 -04001387 /*
1388 * options that take text values
1389 */
Trond Myklebust0d71b052012-03-02 13:59:49 -05001390 case Opt_nfsvers:
1391 string = match_strdup(args);
1392 if (string == NULL)
1393 goto out_nomem;
1394 rc = nfs_parse_version_string(string, mnt, args);
1395 kfree(string);
1396 if (!rc)
1397 goto out_invalid_value;
1398 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001399 case Opt_sec:
1400 string = match_strdup(args);
1401 if (string == NULL)
1402 goto out_nomem;
Chuck Lever01060c82008-06-24 16:33:38 -04001403 rc = nfs_parse_security_flavors(string, mnt);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001404 kfree(string);
Chuck Leverf45663c2008-06-24 19:28:02 -04001405 if (!rc) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001406 dfprintk(MOUNT, "NFS: unrecognized "
1407 "security flavor\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001408 return 0;
Chuck Leverf45663c2008-06-24 19:28:02 -04001409 }
Chuck Leverbf0fd762007-07-01 12:13:44 -04001410 break;
1411 case Opt_proto:
1412 string = match_strdup(args);
1413 if (string == NULL)
1414 goto out_nomem;
1415 token = match_token(string,
1416 nfs_xprt_protocol_tokens, args);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001417
Jeff Laytonee671b02009-12-03 15:58:56 -05001418 protofamily = AF_INET;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001419 switch (token) {
Jeff Laytonee671b02009-12-03 15:58:56 -05001420 case Opt_xprt_udp6:
1421 protofamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001422 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001423 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001424 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001425 break;
Jeff Laytonee671b02009-12-03 15:58:56 -05001426 case Opt_xprt_tcp6:
1427 protofamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001428 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001429 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001430 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001431 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001432 case Opt_xprt_rdma:
1433 /* vector side protocols to TCP */
1434 mnt->flags |= NFS_MOUNT_TCP;
1435 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001436 xprt_load_transport(string);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001437 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001438 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001439 dfprintk(MOUNT, "NFS: unrecognized "
1440 "transport protocol\n");
Yinghai Lu4223a4a2009-10-20 14:13:46 +09001441 kfree(string);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001442 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001443 }
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001444 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001445 break;
1446 case Opt_mountproto:
1447 string = match_strdup(args);
1448 if (string == NULL)
1449 goto out_nomem;
1450 token = match_token(string,
1451 nfs_xprt_protocol_tokens, args);
Trond Myklebustd508afb2009-04-06 16:41:35 -07001452 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001453
Jeff Laytonee671b02009-12-03 15:58:56 -05001454 mountfamily = AF_INET;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001455 switch (token) {
Jeff Laytonee671b02009-12-03 15:58:56 -05001456 case Opt_xprt_udp6:
1457 mountfamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001458 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001459 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001460 break;
Jeff Laytonee671b02009-12-03 15:58:56 -05001461 case Opt_xprt_tcp6:
1462 mountfamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001463 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001464 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001465 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001466 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001467 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001468 dfprintk(MOUNT, "NFS: unrecognized "
1469 "transport protocol\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001470 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001471 }
1472 break;
1473 case Opt_addr:
1474 string = match_strdup(args);
1475 if (string == NULL)
1476 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001477 mnt->nfs_server.addrlen =
Stanislav Kinsburskyb48e1272012-01-26 15:11:57 +04001478 rpc_pton(mnt->net, string, strlen(string),
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001479 (struct sockaddr *)
1480 &mnt->nfs_server.address,
1481 sizeof(mnt->nfs_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001482 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001483 if (mnt->nfs_server.addrlen == 0)
1484 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001485 break;
1486 case Opt_clientaddr:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001487 if (nfs_get_option_str(args, &mnt->client_address))
Chuck Leverbf0fd762007-07-01 12:13:44 -04001488 goto out_nomem;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001489 break;
Chuck Lever33832032007-12-10 14:59:13 -05001490 case Opt_mounthost:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001491 if (nfs_get_option_str(args,
1492 &mnt->mount_server.hostname))
Chuck Lever33832032007-12-10 14:59:13 -05001493 goto out_nomem;
Chuck Lever33832032007-12-10 14:59:13 -05001494 break;
Chuck Lever0ac83772007-09-11 18:01:04 -04001495 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001496 string = match_strdup(args);
1497 if (string == NULL)
1498 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001499 mnt->mount_server.addrlen =
Stanislav Kinsburskyb48e1272012-01-26 15:11:57 +04001500 rpc_pton(mnt->net, string, strlen(string),
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001501 (struct sockaddr *)
1502 &mnt->mount_server.address,
1503 sizeof(mnt->mount_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001504 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001505 if (mnt->mount_server.addrlen == 0)
1506 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001507 break;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001508 case Opt_lookupcache:
1509 string = match_strdup(args);
1510 if (string == NULL)
1511 goto out_nomem;
1512 token = match_token(string,
1513 nfs_lookupcache_tokens, args);
1514 kfree(string);
1515 switch (token) {
1516 case Opt_lookupcache_all:
1517 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1518 break;
1519 case Opt_lookupcache_positive:
1520 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1521 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1522 break;
1523 case Opt_lookupcache_none:
1524 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1525 break;
1526 default:
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001527 dfprintk(MOUNT, "NFS: invalid "
1528 "lookupcache argument\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001529 return 0;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001530 };
1531 break;
Chuck Levera6d5ff62010-05-07 13:33:58 -04001532 case Opt_fscache_uniq:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001533 if (nfs_get_option_str(args, &mnt->fscache_uniq))
Chuck Levera6d5ff62010-05-07 13:33:58 -04001534 goto out_nomem;
Chuck Levera6d5ff62010-05-07 13:33:58 -04001535 mnt->options |= NFS_OPTION_FSCACHE;
1536 break;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001537 case Opt_local_lock:
1538 string = match_strdup(args);
1539 if (string == NULL)
1540 goto out_nomem;
1541 token = match_token(string, nfs_local_lock_tokens,
1542 args);
1543 kfree(string);
1544 switch (token) {
1545 case Opt_local_lock_all:
1546 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1547 NFS_MOUNT_LOCAL_FCNTL);
1548 break;
1549 case Opt_local_lock_flock:
1550 mnt->flags |= NFS_MOUNT_LOCAL_FLOCK;
1551 break;
1552 case Opt_local_lock_posix:
1553 mnt->flags |= NFS_MOUNT_LOCAL_FCNTL;
1554 break;
1555 case Opt_local_lock_none:
1556 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1557 NFS_MOUNT_LOCAL_FCNTL);
1558 break;
1559 default:
1560 dfprintk(MOUNT, "NFS: invalid "
1561 "local_lock argument\n");
1562 return 0;
1563 };
1564 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001565
Chuck Leverf45663c2008-06-24 19:28:02 -04001566 /*
1567 * Special options
1568 */
1569 case Opt_sloppy:
1570 sloppy = 1;
1571 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1572 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001573 case Opt_userspace:
1574 case Opt_deprecated:
Chuck Leverd33e4df2008-06-12 12:37:41 -04001575 dfprintk(MOUNT, "NFS: ignoring mount option "
1576 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001577 break;
1578
1579 default:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001580 invalid_option = 1;
Chuck Leverf45663c2008-06-24 19:28:02 -04001581 dfprintk(MOUNT, "NFS: unrecognized mount option "
1582 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001583 }
1584 }
1585
Chuck Leverd23c45f2009-06-17 18:02:13 -07001586 if (!sloppy && invalid_option)
1587 return 0;
1588
Weston Andros Adamson571b7552012-02-01 14:06:41 -05001589 if (mnt->minorversion && mnt->version != 4)
1590 goto out_minorversion_mismatch;
1591
Jeff Laytonee671b02009-12-03 15:58:56 -05001592 /*
1593 * verify that any proto=/mountproto= options match the address
1594 * familiies in the addr=/mountaddr= options.
1595 */
1596 if (protofamily != AF_UNSPEC &&
1597 protofamily != mnt->nfs_server.address.ss_family)
1598 goto out_proto_mismatch;
1599
1600 if (mountfamily != AF_UNSPEC) {
1601 if (mnt->mount_server.addrlen) {
1602 if (mountfamily != mnt->mount_server.address.ss_family)
1603 goto out_mountproto_mismatch;
1604 } else {
1605 if (mountfamily != mnt->nfs_server.address.ss_family)
1606 goto out_mountproto_mismatch;
1607 }
1608 }
1609
Chuck Leverbf0fd762007-07-01 12:13:44 -04001610 return 1;
1611
Jeff Laytonee671b02009-12-03 15:58:56 -05001612out_mountproto_mismatch:
1613 printk(KERN_INFO "NFS: mount server address does not match mountproto= "
1614 "option\n");
1615 return 0;
1616out_proto_mismatch:
1617 printk(KERN_INFO "NFS: server address does not match proto= option\n");
1618 return 0;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001619out_invalid_address:
1620 printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
1621 return 0;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001622out_invalid_value:
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001623 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001624 return 0;
Weston Andros Adamson571b7552012-02-01 14:06:41 -05001625out_minorversion_mismatch:
1626 printk(KERN_INFO "NFS: mount option vers=%u does not support "
1627 "minorversion=%u\n", mnt->version, mnt->minorversion);
1628 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001629out_nomem:
1630 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1631 return 0;
Eric Parisf9c3a382008-03-05 14:20:18 -05001632out_security_failure:
1633 free_secdata(secdata);
1634 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1635 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001636}
1637
1638/*
Chuck Leverec88f282009-08-09 15:09:32 -04001639 * Match the requested auth flavors with the list returned by
1640 * the server. Returns zero and sets the mount's authentication
1641 * flavor on success; returns -EACCES if server does not support
1642 * the requested flavor.
1643 */
1644static int nfs_walk_authlist(struct nfs_parsed_mount_data *args,
1645 struct nfs_mount_request *request)
1646{
1647 unsigned int i, j, server_authlist_len = *(request->auth_flav_len);
1648
1649 /*
Chuck Lever5eecfde2009-08-21 17:50:30 -04001650 * Certain releases of Linux's mountd return an empty
1651 * flavor list. To prevent behavioral regression with
1652 * these servers (ie. rejecting mounts that used to
1653 * succeed), revert to pre-2.6.32 behavior (no checking)
1654 * if the returned flavor list is empty.
1655 */
1656 if (server_authlist_len == 0)
1657 return 0;
1658
1659 /*
Chuck Leverec88f282009-08-09 15:09:32 -04001660 * We avoid sophisticated negotiating here, as there are
1661 * plenty of cases where we can get it wrong, providing
1662 * either too little or too much security.
1663 *
1664 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1665 * flavor listed first. However, some servers list
1666 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1667 * preferred default, in args->auth_flavors[0] if user
1668 * didn't specify sec= mount option.
1669 */
1670 for (i = 0; i < args->auth_flavor_len; i++)
1671 for (j = 0; j < server_authlist_len; j++)
1672 if (args->auth_flavors[i] == request->auth_flavs[j]) {
1673 dfprintk(MOUNT, "NFS: using auth flavor %d\n",
1674 request->auth_flavs[j]);
1675 args->auth_flavors[0] = request->auth_flavs[j];
1676 return 0;
1677 }
1678
1679 dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n");
1680 nfs_umount(request);
1681 return -EACCES;
1682}
1683
1684/*
Chuck Lever0076d7b2007-07-01 12:13:49 -04001685 * Use the remote server's MOUNT service to request the NFS file handle
1686 * corresponding to the provided path.
1687 */
1688static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1689 struct nfs_fh *root_fh)
1690{
Chuck Leverec88f282009-08-09 15:09:32 -04001691 rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS];
1692 unsigned int server_authlist_len = ARRAY_SIZE(server_authlist);
Chuck Leverc5d120f2008-12-23 15:21:35 -05001693 struct nfs_mount_request request = {
1694 .sap = (struct sockaddr *)
1695 &args->mount_server.address,
1696 .dirpath = args->nfs_server.export_path,
1697 .protocol = args->mount_server.protocol,
1698 .fh = root_fh,
Chuck Lever50a737f2008-12-23 15:21:37 -05001699 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
Chuck Leverec88f282009-08-09 15:09:32 -04001700 .auth_flav_len = &server_authlist_len,
1701 .auth_flavs = server_authlist,
Stanislav Kinsbursky6d59b8d2012-01-10 16:12:54 +04001702 .net = args->net,
Chuck Leverc5d120f2008-12-23 15:21:35 -05001703 };
Chuck Lever4c568012007-12-10 14:59:28 -05001704 int status;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001705
1706 if (args->mount_server.version == 0) {
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001707 switch (args->version) {
1708 default:
1709 args->mount_server.version = NFS_MNT3_VERSION;
1710 break;
1711 case 2:
1712 args->mount_server.version = NFS_MNT_VERSION;
1713 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001714 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001715 request.version = args->mount_server.version;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001716
Chuck Lever33832032007-12-10 14:59:13 -05001717 if (args->mount_server.hostname)
Chuck Leverc5d120f2008-12-23 15:21:35 -05001718 request.hostname = args->mount_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001719 else
Chuck Leverc5d120f2008-12-23 15:21:35 -05001720 request.hostname = args->nfs_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001721
Chuck Lever0076d7b2007-07-01 12:13:49 -04001722 /*
1723 * Construct the mount server's address.
1724 */
Chuck Lever4c568012007-12-10 14:59:28 -05001725 if (args->mount_server.address.ss_family == AF_UNSPEC) {
Chuck Leverc5d120f2008-12-23 15:21:35 -05001726 memcpy(request.sap, &args->nfs_server.address,
Chuck Lever4c568012007-12-10 14:59:28 -05001727 args->nfs_server.addrlen);
1728 args->mount_server.addrlen = args->nfs_server.addrlen;
1729 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001730 request.salen = args->mount_server.addrlen;
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001731 nfs_set_port(request.sap, &args->mount_server.port, 0);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001732
1733 /*
1734 * Now ask the mount server to map our export path
1735 * to a file handle.
1736 */
Chuck Leverc5d120f2008-12-23 15:21:35 -05001737 status = nfs_mount(&request);
Chuck Leverec88f282009-08-09 15:09:32 -04001738 if (status != 0) {
1739 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1740 request.hostname, status);
1741 return status;
1742 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001743
Chuck Leverec88f282009-08-09 15:09:32 -04001744 /*
1745 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1746 */
1747 if (args->mount_server.version != NFS_MNT3_VERSION)
1748 return 0;
1749 return nfs_walk_authlist(args, &request);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001750}
1751
Rob Landleyc12bace2011-03-09 15:54:13 -06001752/*
1753 * Split "dev_name" into "hostname:export_path".
1754 *
1755 * The leftmost colon demarks the split between the server's hostname
1756 * and the export path. If the hostname starts with a left square
1757 * bracket, then it may contain colons.
1758 *
1759 * Note: caller frees hostname and export path, even on error.
1760 */
1761static int nfs_parse_devname(const char *dev_name,
1762 char **hostname, size_t maxnamlen,
1763 char **export_path, size_t maxpathlen)
Chuck Leverdc045892008-06-23 12:36:37 -04001764{
1765 size_t len;
Rob Landleyc12bace2011-03-09 15:54:13 -06001766 char *end;
Chuck Leverdc045892008-06-23 12:36:37 -04001767
Rob Landleyc12bace2011-03-09 15:54:13 -06001768 /* Is the host name protected with square brakcets? */
1769 if (*dev_name == '[') {
1770 end = strchr(++dev_name, ']');
1771 if (end == NULL || end[1] != ':')
1772 goto out_bad_devname;
Chuck Leverdc045892008-06-23 12:36:37 -04001773
Rob Landleyc12bace2011-03-09 15:54:13 -06001774 len = end - dev_name;
1775 end++;
1776 } else {
1777 char *comma;
1778
1779 end = strchr(dev_name, ':');
1780 if (end == NULL)
1781 goto out_bad_devname;
1782 len = end - dev_name;
1783
1784 /* kill possible hostname list: not supported */
1785 comma = strchr(dev_name, ',');
1786 if (comma != NULL && comma < end)
1787 *comma = 0;
1788 }
1789
Chuck Leverdc045892008-06-23 12:36:37 -04001790 if (len > maxnamlen)
1791 goto out_hostname;
1792
1793 /* N.B. caller will free nfs_server.hostname in all cases */
1794 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
Rob Landleyc12bace2011-03-09 15:54:13 -06001795 if (*hostname == NULL)
Chuck Leverdc045892008-06-23 12:36:37 -04001796 goto out_nomem;
Rob Landleyc12bace2011-03-09 15:54:13 -06001797 len = strlen(++end);
Chuck Leverdc045892008-06-23 12:36:37 -04001798 if (len > maxpathlen)
1799 goto out_path;
Rob Landleyc12bace2011-03-09 15:54:13 -06001800 *export_path = kstrndup(end, len, GFP_KERNEL);
Chuck Leverdc045892008-06-23 12:36:37 -04001801 if (!*export_path)
1802 goto out_nomem;
1803
1804 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1805 return 0;
1806
1807out_bad_devname:
1808 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1809 return -EINVAL;
1810
1811out_nomem:
1812 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1813 return -ENOMEM;
1814
1815out_hostname:
1816 dfprintk(MOUNT, "NFS: server hostname too long\n");
1817 return -ENAMETOOLONG;
1818
1819out_path:
1820 dfprintk(MOUNT, "NFS: export pathname too long\n");
1821 return -ENAMETOOLONG;
1822}
1823
1824/*
David Howells54ceac42006-08-22 20:06:13 -04001825 * Validate the NFS2/NFS3 mount data
1826 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001827 *
1828 * For option strings, user space handles the following behaviors:
1829 *
1830 * + DNS: mapping server host name to IP address ("addr=" option)
1831 *
1832 * + failure mode: how to behave if a mount request can't be handled
1833 * immediately ("fg/bg" option)
1834 *
1835 * + retry: how often to retry a mount request ("retry=" option)
1836 *
1837 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1838 * mountproto=tcp after mountproto=udp, and so on
David Howellsf7b422b2006-06-09 09:34:33 -04001839 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001840static int nfs_validate_mount_data(void *options,
1841 struct nfs_parsed_mount_data *args,
Chuck Lever136d5582007-07-01 12:13:54 -04001842 struct nfs_fh *mntfh,
1843 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001844{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001845 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001846 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
Chuck Lever136d5582007-07-01 12:13:54 -04001847
Chuck Lever5df36e72007-07-01 12:12:56 -04001848 if (data == NULL)
1849 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001850
David Howellsf7b422b2006-06-09 09:34:33 -04001851 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001852 case 1:
1853 data->namlen = 0;
1854 case 2:
1855 data->bsize = 0;
1856 case 3:
1857 if (data->flags & NFS_MOUNT_VER3)
1858 goto out_no_v3;
1859 data->root.size = NFS2_FHSIZE;
1860 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1861 case 4:
1862 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1863 goto out_no_sec;
1864 case 5:
1865 memset(data->context, 0, sizeof(data->context));
1866 case 6:
Trond Myklebustb7e24452008-06-19 15:21:11 -04001867 if (data->flags & NFS_MOUNT_VER3) {
1868 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1869 goto out_invalid_fh;
Chuck Lever5df36e72007-07-01 12:12:56 -04001870 mntfh->size = data->root.size;
Chuck Lever764302c2009-09-08 19:50:03 -04001871 args->version = 3;
1872 } else {
Chuck Lever5df36e72007-07-01 12:12:56 -04001873 mntfh->size = NFS2_FHSIZE;
Chuck Lever764302c2009-09-08 19:50:03 -04001874 args->version = 2;
1875 }
Chuck Lever5df36e72007-07-01 12:12:56 -04001876
Chuck Lever5df36e72007-07-01 12:12:56 -04001877
1878 memcpy(mntfh->data, data->root.data, mntfh->size);
1879 if (mntfh->size < sizeof(mntfh->data))
1880 memset(mntfh->data + mntfh->size, 0,
1881 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001882
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001883 /*
1884 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1885 * can deal with.
1886 */
Trond Myklebustff3525a2008-08-15 16:59:14 -04001887 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
Bryan Schumakerd5eff1a2010-08-03 13:04:00 -04001888 args->flags |= NFS_MOUNT_LEGACY_INTERFACE;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001889 args->rsize = data->rsize;
1890 args->wsize = data->wsize;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001891 args->timeo = data->timeo;
1892 args->retrans = data->retrans;
1893 args->acregmin = data->acregmin;
1894 args->acregmax = data->acregmax;
1895 args->acdirmin = data->acdirmin;
1896 args->acdirmax = data->acdirmax;
Chuck Lever4c568012007-12-10 14:59:28 -05001897
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001898 memcpy(sap, &data->addr, sizeof(data->addr));
Chuck Lever4c568012007-12-10 14:59:28 -05001899 args->nfs_server.addrlen = sizeof(data->addr);
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001900 if (!nfs_verify_server_address(sap))
Chuck Lever4c568012007-12-10 14:59:28 -05001901 goto out_no_address;
1902
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001903 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001904 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001905 /* N.B. caller will free nfs_server.hostname in all cases */
1906 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1907 args->namlen = data->namlen;
1908 args->bsize = data->bsize;
Chuck Leverdd07c942008-06-24 16:33:46 -04001909
1910 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1911 args->auth_flavors[0] = data->pseudoflavor;
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001912 if (!args->nfs_server.hostname)
1913 goto out_nomem;
Eric Parisf9c3a382008-03-05 14:20:18 -05001914
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001915 if (!(data->flags & NFS_MOUNT_NONLM))
1916 args->flags &= ~(NFS_MOUNT_LOCAL_FLOCK|
1917 NFS_MOUNT_LOCAL_FCNTL);
1918 else
1919 args->flags |= (NFS_MOUNT_LOCAL_FLOCK|
1920 NFS_MOUNT_LOCAL_FCNTL);
Eric Parisf9c3a382008-03-05 14:20:18 -05001921 /*
1922 * The legacy version 6 binary mount data from userspace has a
1923 * field used only to transport selinux information into the
1924 * the kernel. To continue to support that functionality we
1925 * have a touch of selinux knowledge here in the NFS code. The
1926 * userspace code converted context=blah to just blah so we are
1927 * converting back to the full string selinux understands.
1928 */
1929 if (data->context[0]){
1930#ifdef CONFIG_SECURITY_SELINUX
1931 int rc;
1932 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1933 if (!opts_str)
1934 return -ENOMEM;
1935 strcpy(opts_str, "context=");
1936 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1937 strcat(opts_str, &data->context[0]);
1938 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1939 kfree(opts_str);
1940 if (rc)
1941 return rc;
1942#else
1943 return -EINVAL;
1944#endif
1945 }
1946
Chuck Lever5df36e72007-07-01 12:12:56 -04001947 break;
Chuck Lever136d5582007-07-01 12:13:54 -04001948 default: {
Chuck Lever136d5582007-07-01 12:13:54 -04001949 int status;
Chuck Lever136d5582007-07-01 12:13:54 -04001950
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001951 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever136d5582007-07-01 12:13:54 -04001952 return -EINVAL;
1953
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001954 if (!nfs_verify_server_address(sap))
Chuck Lever6e88e062007-09-24 15:39:50 -04001955 goto out_no_address;
1956
Chuck Lever764302c2009-09-08 19:50:03 -04001957 if (args->version == 4)
1958#ifdef CONFIG_NFS_V4
1959 return nfs4_validate_text_mount_data(options,
1960 args, dev_name);
1961#else
1962 goto out_v4_not_compiled;
1963#endif
1964
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001965 nfs_set_port(sap, &args->nfs_server.port, 0);
Chuck Levered596a82008-06-26 17:47:05 -04001966
Trond Myklebust259875e2008-07-02 14:43:47 -04001967 nfs_set_mount_transport_protocol(args);
1968
Chuck Leverdc045892008-06-23 12:36:37 -04001969 status = nfs_parse_devname(dev_name,
1970 &args->nfs_server.hostname,
1971 PAGE_SIZE,
1972 &args->nfs_server.export_path,
1973 NFS_MAXPATHLEN);
1974 if (!status)
1975 status = nfs_try_mount(args, mntfh);
Chuck Lever136d5582007-07-01 12:13:54 -04001976
Chuck Leverdc045892008-06-23 12:36:37 -04001977 kfree(args->nfs_server.export_path);
1978 args->nfs_server.export_path = NULL;
Chuck Lever136d5582007-07-01 12:13:54 -04001979
Chuck Lever136d5582007-07-01 12:13:54 -04001980 if (status)
Chuck Leverfdc6e2c2007-08-29 17:58:59 -04001981 return status;
Chuck Lever136d5582007-07-01 12:13:54 -04001982
Chuck Lever136d5582007-07-01 12:13:54 -04001983 break;
1984 }
David Howellsf7b422b2006-06-09 09:34:33 -04001985 }
David Howells54ceac42006-08-22 20:06:13 -04001986
David Howellsf7b422b2006-06-09 09:34:33 -04001987#ifndef CONFIG_NFS_V3
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001988 if (args->version == 3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001989 goto out_v3_not_compiled;
1990#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001991
David Howells54ceac42006-08-22 20:06:13 -04001992 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001993
1994out_no_data:
1995 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1996 return -EINVAL;
1997
1998out_no_v3:
1999 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
2000 data->version);
2001 return -EINVAL;
2002
2003out_no_sec:
2004 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
2005 return -EINVAL;
2006
Chuck Lever5df36e72007-07-01 12:12:56 -04002007#ifndef CONFIG_NFS_V3
2008out_v3_not_compiled:
2009 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
2010 return -EPROTONOSUPPORT;
2011#endif /* !CONFIG_NFS_V3 */
2012
Chuck Lever764302c2009-09-08 19:50:03 -04002013#ifndef CONFIG_NFS_V4
2014out_v4_not_compiled:
2015 dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n");
2016 return -EPROTONOSUPPORT;
2017#endif /* !CONFIG_NFS_V4 */
2018
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04002019out_nomem:
2020 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
2021 return -ENOMEM;
2022
Chuck Lever5df36e72007-07-01 12:12:56 -04002023out_no_address:
2024 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
2025 return -EINVAL;
2026
2027out_invalid_fh:
2028 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
2029 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04002030}
2031
Jeff Layton48b605f2008-06-10 15:38:39 -04002032static int
2033nfs_compare_remount_data(struct nfs_server *nfss,
2034 struct nfs_parsed_mount_data *data)
2035{
2036 if (data->flags != nfss->flags ||
2037 data->rsize != nfss->rsize ||
2038 data->wsize != nfss->wsize ||
2039 data->retrans != nfss->client->cl_timeout->to_retries ||
2040 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
2041 data->acregmin != nfss->acregmin / HZ ||
2042 data->acregmax != nfss->acregmax / HZ ||
2043 data->acdirmin != nfss->acdirmin / HZ ||
2044 data->acdirmax != nfss->acdirmax / HZ ||
2045 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
Trond Myklebustbcd2ea12009-10-06 15:41:22 -04002046 data->nfs_server.port != nfss->port ||
Jeff Layton48b605f2008-06-10 15:38:39 -04002047 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
Stefan Richtera1be9ee2009-10-12 11:26:12 -04002048 !rpc_cmp_addr((struct sockaddr *)&data->nfs_server.address,
2049 (struct sockaddr *)&nfss->nfs_client->cl_addr))
Jeff Layton48b605f2008-06-10 15:38:39 -04002050 return -EINVAL;
2051
2052 return 0;
2053}
2054
2055static int
2056nfs_remount(struct super_block *sb, int *flags, char *raw_data)
2057{
2058 int error;
2059 struct nfs_server *nfss = sb->s_fs_info;
2060 struct nfs_parsed_mount_data *data;
2061 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
2062 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
Trond Myklebustcd100722008-06-17 16:12:00 -04002063 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
Jeff Layton48b605f2008-06-10 15:38:39 -04002064
2065 /*
2066 * Userspace mount programs that send binary options generally send
2067 * them populated with default values. We have no way to know which
2068 * ones were explicitly specified. Fall back to legacy behavior and
2069 * just return success.
2070 */
Marc Zyngier31c94462008-07-17 13:21:55 +02002071 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
2072 (nfsvers <= 3 && (!options || (options->version >= 1 &&
2073 options->version <= 6))))
Jeff Layton48b605f2008-06-10 15:38:39 -04002074 return 0;
2075
2076 data = kzalloc(sizeof(*data), GFP_KERNEL);
2077 if (data == NULL)
2078 return -ENOMEM;
2079
2080 /* fill out struct with values from existing mount */
2081 data->flags = nfss->flags;
2082 data->rsize = nfss->rsize;
2083 data->wsize = nfss->wsize;
2084 data->retrans = nfss->client->cl_timeout->to_retries;
2085 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
2086 data->acregmin = nfss->acregmin / HZ;
2087 data->acregmax = nfss->acregmax / HZ;
2088 data->acdirmin = nfss->acdirmin / HZ;
2089 data->acdirmax = nfss->acdirmax / HZ;
2090 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
Trond Myklebustbcd2ea12009-10-06 15:41:22 -04002091 data->nfs_server.port = nfss->port;
Jeff Layton48b605f2008-06-10 15:38:39 -04002092 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
2093 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
2094 data->nfs_server.addrlen);
2095
2096 /* overwrite those values with any that were specified */
2097 error = nfs_parse_mount_options((char *)options, data);
2098 if (error < 0)
2099 goto out;
2100
Jeff Layton26c4c172011-04-27 11:49:09 -04002101 /*
2102 * noac is a special case. It implies -o sync, but that's not
2103 * necessarily reflected in the mtab options. do_remount_sb
2104 * will clear MS_SYNCHRONOUS if -o sync wasn't specified in the
2105 * remount options, so we have to explicitly reset it.
2106 */
2107 if (data->flags & NFS_MOUNT_NOAC)
2108 *flags |= MS_SYNCHRONOUS;
2109
Jeff Layton48b605f2008-06-10 15:38:39 -04002110 /* compare new mount options with old ones */
2111 error = nfs_compare_remount_data(nfss, data);
2112out:
2113 kfree(data);
2114 return error;
2115}
2116
David Howells54ceac42006-08-22 20:06:13 -04002117/*
2118 * Initialise the common bits of the superblock
2119 */
2120static inline void nfs_initialise_sb(struct super_block *sb)
2121{
2122 struct nfs_server *server = NFS_SB(sb);
2123
2124 sb->s_magic = NFS_SUPER_MAGIC;
2125
2126 /* We probably want something more informative here */
2127 snprintf(sb->s_id, sizeof(sb->s_id),
2128 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
2129
2130 if (sb->s_blocksize == 0)
2131 sb->s_blocksize = nfs_block_bits(server->wsize,
2132 &sb->s_blocksize_bits);
2133
Jens Axboe32a88aa2009-09-16 15:02:33 +02002134 sb->s_bdi = &server->backing_dev_info;
2135
David Howells54ceac42006-08-22 20:06:13 -04002136 nfs_super_set_maxbytes(sb, server->maxfilesize);
2137}
2138
2139/*
2140 * Finish setting up an NFS2/3 superblock
2141 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04002142static void nfs_fill_super(struct super_block *sb,
2143 struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -04002144{
2145 struct nfs_server *server = NFS_SB(sb);
2146
2147 sb->s_blocksize_bits = 0;
2148 sb->s_blocksize = 0;
2149 if (data->bsize)
2150 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
2151
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04002152 if (server->nfs_client->rpc_ops->version == 3) {
David Howells54ceac42006-08-22 20:06:13 -04002153 /* The VFS shouldn't apply the umask to mode bits. We will do
2154 * so ourselves when necessary.
2155 */
2156 sb->s_flags |= MS_POSIXACL;
2157 sb->s_time_gran = 1;
2158 }
2159
2160 sb->s_op = &nfs_sops;
2161 nfs_initialise_sb(sb);
2162}
2163
2164/*
2165 * Finish setting up a cloned NFS2/3 superblock
2166 */
2167static void nfs_clone_super(struct super_block *sb,
2168 const struct super_block *old_sb)
2169{
2170 struct nfs_server *server = NFS_SB(sb);
2171
2172 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2173 sb->s_blocksize = old_sb->s_blocksize;
2174 sb->s_maxbytes = old_sb->s_maxbytes;
2175
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04002176 if (server->nfs_client->rpc_ops->version == 3) {
David Howells54ceac42006-08-22 20:06:13 -04002177 /* The VFS shouldn't apply the umask to mode bits. We will do
2178 * so ourselves when necessary.
2179 */
2180 sb->s_flags |= MS_POSIXACL;
2181 sb->s_time_gran = 1;
2182 }
2183
2184 sb->s_op = old_sb->s_op;
2185 nfs_initialise_sb(sb);
2186}
2187
Trond Myklebust275a5d22007-05-16 16:53:28 -04002188static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
2189{
2190 const struct nfs_server *a = s->s_fs_info;
2191 const struct rpc_clnt *clnt_a = a->client;
2192 const struct rpc_clnt *clnt_b = b->client;
2193
2194 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
2195 goto Ebusy;
2196 if (a->nfs_client != b->nfs_client)
2197 goto Ebusy;
2198 if (a->flags != b->flags)
2199 goto Ebusy;
2200 if (a->wsize != b->wsize)
2201 goto Ebusy;
2202 if (a->rsize != b->rsize)
2203 goto Ebusy;
2204 if (a->acregmin != b->acregmin)
2205 goto Ebusy;
2206 if (a->acregmax != b->acregmax)
2207 goto Ebusy;
2208 if (a->acdirmin != b->acdirmin)
2209 goto Ebusy;
2210 if (a->acdirmax != b->acdirmax)
2211 goto Ebusy;
2212 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
2213 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002214 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04002215Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002216 return 0;
2217}
2218
2219struct nfs_sb_mountdata {
2220 struct nfs_server *server;
2221 int mntflags;
2222};
2223
2224static int nfs_set_super(struct super_block *s, void *data)
2225{
2226 struct nfs_sb_mountdata *sb_mntdata = data;
2227 struct nfs_server *server = sb_mntdata->server;
2228 int ret;
2229
2230 s->s_flags = sb_mntdata->mntflags;
2231 s->s_fs_info = server;
Al Viro8b244ff2010-12-18 11:29:39 -05002232 s->s_d_op = server->nfs_client->rpc_ops->dentry_ops;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002233 ret = set_anon_super(s, server);
2234 if (ret == 0)
2235 server->s_dev = s->s_dev;
2236 return ret;
2237}
2238
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002239static int nfs_compare_super_address(struct nfs_server *server1,
2240 struct nfs_server *server2)
2241{
2242 struct sockaddr *sap1, *sap2;
2243
2244 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
2245 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
2246
2247 if (sap1->sa_family != sap2->sa_family)
2248 return 0;
2249
2250 switch (sap1->sa_family) {
2251 case AF_INET: {
2252 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
2253 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
2254 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
2255 return 0;
2256 if (sin1->sin_port != sin2->sin_port)
2257 return 0;
2258 break;
2259 }
2260 case AF_INET6: {
2261 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
2262 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
2263 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
2264 return 0;
2265 if (sin1->sin6_port != sin2->sin6_port)
2266 return 0;
2267 break;
2268 }
2269 default:
2270 return 0;
2271 }
2272
2273 return 1;
2274}
2275
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002276static int nfs_compare_super(struct super_block *sb, void *data)
2277{
2278 struct nfs_sb_mountdata *sb_mntdata = data;
2279 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2280 int mntflags = sb_mntdata->mntflags;
2281
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002282 if (!nfs_compare_super_address(old, server))
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002283 return 0;
2284 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2285 if (old->flags & NFS_MOUNT_UNSHARED)
2286 return 0;
2287 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2288 return 0;
2289 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04002290}
2291
Miklos Szeredifa799752008-04-30 00:54:33 -07002292static int nfs_bdi_register(struct nfs_server *server)
2293{
2294 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
2295}
2296
Al Viro01194982011-03-16 07:25:36 -04002297static struct dentry *nfs_fs_mount(struct file_system_type *fs_type,
2298 int flags, const char *dev_name, void *raw_data)
David Howells54ceac42006-08-22 20:06:13 -04002299{
2300 struct nfs_server *server = NULL;
2301 struct super_block *s;
Trond Myklebust33852a12008-06-19 14:20:11 -04002302 struct nfs_parsed_mount_data *data;
2303 struct nfs_fh *mntfh;
Al Viro01194982011-03-16 07:25:36 -04002304 struct dentry *mntroot = ERR_PTR(-ENOMEM);
Trond Myklebust75180df2007-05-16 16:53:28 -04002305 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002306 struct nfs_sb_mountdata sb_mntdata = {
2307 .mntflags = flags,
2308 };
Al Viro01194982011-03-16 07:25:36 -04002309 int error;
David Howells54ceac42006-08-22 20:06:13 -04002310
Paulius Zaleckas1e657bd2010-10-31 18:21:05 +02002311 data = nfs_alloc_parsed_mount_data(NFS_DEFAULT_VERSION);
Trond Myklebustb157b062010-04-19 19:05:48 -04002312 mntfh = nfs_alloc_fhandle();
Trond Myklebust33852a12008-06-19 14:20:11 -04002313 if (data == NULL || mntfh == NULL)
Jeff Layton8a0d5512011-12-20 06:57:45 -05002314 goto out;
Eric Parisf9c3a382008-03-05 14:20:18 -05002315
David Howells54ceac42006-08-22 20:06:13 -04002316 /* Validate the mount data */
Trond Myklebust33852a12008-06-19 14:20:11 -04002317 error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
Al Viro01194982011-03-16 07:25:36 -04002318 if (error < 0) {
2319 mntroot = ERR_PTR(error);
Chuck Lever06559602007-07-01 12:12:35 -04002320 goto out;
Al Viro01194982011-03-16 07:25:36 -04002321 }
David Howells54ceac42006-08-22 20:06:13 -04002322
Chuck Lever764302c2009-09-08 19:50:03 -04002323#ifdef CONFIG_NFS_V4
2324 if (data->version == 4) {
Al Viro01194982011-03-16 07:25:36 -04002325 mntroot = nfs4_try_mount(flags, dev_name, data);
Chuck Lever764302c2009-09-08 19:50:03 -04002326 goto out;
2327 }
2328#endif /* CONFIG_NFS_V4 */
2329
David Howells54ceac42006-08-22 20:06:13 -04002330 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002331 server = nfs_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002332 if (IS_ERR(server)) {
Al Viro01194982011-03-16 07:25:36 -04002333 mntroot = ERR_CAST(server);
Chuck Lever06559602007-07-01 12:12:35 -04002334 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002335 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002336 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002337
Trond Myklebust75180df2007-05-16 16:53:28 -04002338 if (server->flags & NFS_MOUNT_UNSHARED)
2339 compare_super = NULL;
2340
Sachin Prabhufb2088c2011-08-01 12:10:12 +01002341 /* -o noac implies -o sync */
2342 if (server->flags & NFS_MOUNT_NOAC)
2343 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2344
David Howells54ceac42006-08-22 20:06:13 -04002345 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002346 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002347 if (IS_ERR(s)) {
Al Viro01194982011-03-16 07:25:36 -04002348 mntroot = ERR_CAST(s);
David Howells54ceac42006-08-22 20:06:13 -04002349 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04002350 }
2351
David Howells54ceac42006-08-22 20:06:13 -04002352 if (s->s_fs_info != server) {
2353 nfs_free_server(server);
2354 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002355 } else {
2356 error = nfs_bdi_register(server);
Al Viro01194982011-03-16 07:25:36 -04002357 if (error) {
2358 mntroot = ERR_PTR(error);
NeilBrowncfbc0682010-03-11 11:20:17 +11002359 goto error_splat_bdi;
Al Viro01194982011-03-16 07:25:36 -04002360 }
David Howellsf7b422b2006-06-09 09:34:33 -04002361 }
David Howells54ceac42006-08-22 20:06:13 -04002362
2363 if (!s->s_root) {
2364 /* initial superblock/root creation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002365 nfs_fill_super(s, data);
Jesper Juhl160bc162011-04-10 17:57:07 +02002366 nfs_fscache_get_super_cookie(s, data->fscache_uniq, NULL);
David Howells54ceac42006-08-22 20:06:13 -04002367 }
2368
Al Viro0d5839a2011-03-16 05:27:27 -04002369 mntroot = nfs_get_root(s, mntfh, dev_name);
Al Viro01194982011-03-16 07:25:36 -04002370 if (IS_ERR(mntroot))
David Howells54ceac42006-08-22 20:06:13 -04002371 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002372
Trond Myklebust33852a12008-06-19 14:20:11 -04002373 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002374 if (error)
2375 goto error_splat_root;
2376
David Howellsf7b422b2006-06-09 09:34:33 -04002377 s->s_flags |= MS_ACTIVE;
Chuck Lever06559602007-07-01 12:12:35 -04002378
2379out:
Jeff Layton8a0d5512011-12-20 06:57:45 -05002380 nfs_free_parsed_mount_data(data);
Trond Myklebustb157b062010-04-19 19:05:48 -04002381 nfs_free_fhandle(mntfh);
Al Viro01194982011-03-16 07:25:36 -04002382 return mntroot;
Trond Myklebust816724e2006-06-24 08:41:41 -04002383
David Howells54ceac42006-08-22 20:06:13 -04002384out_err_nosb:
2385 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04002386 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002387
Eric Parisf9c3a382008-03-05 14:20:18 -05002388error_splat_root:
2389 dput(mntroot);
Al Viro01194982011-03-16 07:25:36 -04002390 mntroot = ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04002391error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002392 if (server && !s->s_root)
2393 bdi_unregister(&server->backing_dev_info);
2394error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002395 deactivate_locked_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04002396 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002397}
2398
David Howells54ceac42006-08-22 20:06:13 -04002399/*
Trond Myklebust387c1492010-02-03 08:27:35 -05002400 * Ensure that we unregister the bdi before kill_anon_super
2401 * releases the device name
2402 */
2403static void nfs_put_super(struct super_block *s)
2404{
2405 struct nfs_server *server = NFS_SB(s);
2406
2407 bdi_unregister(&server->backing_dev_info);
2408}
2409
2410/*
David Howells54ceac42006-08-22 20:06:13 -04002411 * Destroy an NFS2/3 superblock
2412 */
David Howellsf7b422b2006-06-09 09:34:33 -04002413static void nfs_kill_super(struct super_block *s)
2414{
2415 struct nfs_server *server = NFS_SB(s);
2416
2417 kill_anon_super(s);
David Howells08734042009-04-03 16:42:42 +01002418 nfs_fscache_release_super_cookie(s);
David Howells54ceac42006-08-22 20:06:13 -04002419 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04002420}
2421
David Howells54ceac42006-08-22 20:06:13 -04002422/*
2423 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2424 */
Al Viro31f43472010-10-29 03:38:12 -04002425static struct dentry *
2426nfs_xdev_mount(struct file_system_type *fs_type, int flags,
2427 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002428{
2429 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002430 struct super_block *s;
2431 struct nfs_server *server;
2432 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002433 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002434 struct nfs_sb_mountdata sb_mntdata = {
2435 .mntflags = flags,
2436 };
David Howells54ceac42006-08-22 20:06:13 -04002437 int error;
2438
Al Viro31f43472010-10-29 03:38:12 -04002439 dprintk("--> nfs_xdev_mount()\n");
David Howells54ceac42006-08-22 20:06:13 -04002440
2441 /* create a new volume representation */
2442 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2443 if (IS_ERR(server)) {
2444 error = PTR_ERR(server);
2445 goto out_err_noserver;
2446 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002447 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002448
Trond Myklebust75180df2007-05-16 16:53:28 -04002449 if (server->flags & NFS_MOUNT_UNSHARED)
2450 compare_super = NULL;
2451
Sachin Prabhufb2088c2011-08-01 12:10:12 +01002452 /* -o noac implies -o sync */
2453 if (server->flags & NFS_MOUNT_NOAC)
2454 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2455
David Howells54ceac42006-08-22 20:06:13 -04002456 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002457 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002458 if (IS_ERR(s)) {
2459 error = PTR_ERR(s);
2460 goto out_err_nosb;
2461 }
2462
2463 if (s->s_fs_info != server) {
2464 nfs_free_server(server);
2465 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002466 } else {
2467 error = nfs_bdi_register(server);
2468 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11002469 goto error_splat_bdi;
David Howells54ceac42006-08-22 20:06:13 -04002470 }
2471
2472 if (!s->s_root) {
2473 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002474 nfs_clone_super(s, data->sb);
David Howells2df54802009-09-23 14:36:39 -04002475 nfs_fscache_get_super_cookie(s, NULL, data);
David Howells54ceac42006-08-22 20:06:13 -04002476 }
2477
Al Viro0d5839a2011-03-16 05:27:27 -04002478 mntroot = nfs_get_root(s, data->fh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04002479 if (IS_ERR(mntroot)) {
2480 error = PTR_ERR(mntroot);
2481 goto error_splat_super;
2482 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002483 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
Neil Brown4c1fe2f2007-11-01 16:50:20 +11002484 dput(mntroot);
2485 error = -ESTALE;
2486 goto error_splat_super;
2487 }
David Howells54ceac42006-08-22 20:06:13 -04002488
2489 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002490
Eric Parisf9c3a382008-03-05 14:20:18 -05002491 /* clone any lsm security options from the parent to the new sb */
2492 security_sb_clone_mnt_opts(data->sb, s);
2493
Al Viro31f43472010-10-29 03:38:12 -04002494 dprintk("<-- nfs_xdev_mount() = 0\n");
2495 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04002496
2497out_err_nosb:
2498 nfs_free_server(server);
2499out_err_noserver:
Al Viro31f43472010-10-29 03:38:12 -04002500 dprintk("<-- nfs_xdev_mount() = %d [error]\n", error);
2501 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04002502
2503error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002504 if (server && !s->s_root)
2505 bdi_unregister(&server->backing_dev_info);
2506error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002507 deactivate_locked_super(s);
Al Viro31f43472010-10-29 03:38:12 -04002508 dprintk("<-- nfs_xdev_mount() = %d [splat]\n", error);
2509 return ERR_PTR(error);
David Howellsf7b422b2006-06-09 09:34:33 -04002510}
2511
2512#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04002513
2514/*
2515 * Finish setting up a cloned NFS4 superblock
2516 */
2517static void nfs4_clone_super(struct super_block *sb,
2518 const struct super_block *old_sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002519{
David Howells54ceac42006-08-22 20:06:13 -04002520 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2521 sb->s_blocksize = old_sb->s_blocksize;
2522 sb->s_maxbytes = old_sb->s_maxbytes;
2523 sb->s_time_gran = 1;
2524 sb->s_op = old_sb->s_op;
Aneesh Kumar K.Va8a5da92010-12-09 11:35:14 +00002525 /*
2526 * The VFS shouldn't apply the umask to mode bits. We will do
2527 * so ourselves when necessary.
2528 */
2529 sb->s_flags |= MS_POSIXACL;
Aneesh Kumar K.V64c2ce82010-12-09 11:35:25 +00002530 sb->s_xattr = old_sb->s_xattr;
2531 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002532}
2533
2534/*
2535 * Set up an NFS4 superblock
2536 */
David Howells54ceac42006-08-22 20:06:13 -04002537static void nfs4_fill_super(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002538{
David Howellsf7b422b2006-06-09 09:34:33 -04002539 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04002540 sb->s_op = &nfs4_sops;
Aneesh Kumar K.Va8a5da92010-12-09 11:35:14 +00002541 /*
2542 * The VFS shouldn't apply the umask to mode bits. We will do
2543 * so ourselves when necessary.
2544 */
2545 sb->s_flags |= MS_POSIXACL;
Aneesh Kumar K.V64c2ce82010-12-09 11:35:25 +00002546 sb->s_xattr = nfs4_xattr_handlers;
David Howells54ceac42006-08-22 20:06:13 -04002547 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002548}
2549
Trond Myklebust01c3f052009-06-17 13:22:58 -07002550static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2551{
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04002552 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3|
2553 NFS_MOUNT_LOCAL_FLOCK|NFS_MOUNT_LOCAL_FCNTL);
Trond Myklebust01c3f052009-06-17 13:22:58 -07002554}
2555
Chuck Lever7630c852009-09-08 19:49:57 -04002556static int nfs4_validate_text_mount_data(void *options,
2557 struct nfs_parsed_mount_data *args,
2558 const char *dev_name)
2559{
2560 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2561
Trond Myklebustf5855fe2009-10-06 15:40:37 -04002562 nfs_set_port(sap, &args->nfs_server.port, NFS_PORT);
Chuck Lever7630c852009-09-08 19:49:57 -04002563
2564 nfs_validate_transport_protocol(args);
2565
2566 nfs4_validate_mount_flags(args);
2567
Trond Myklebust2ecda722009-09-08 19:50:07 -04002568 if (args->version != 4) {
2569 dfprintk(MOUNT,
2570 "NFS4: Illegal mount version\n");
2571 return -EINVAL;
2572 }
2573
Chuck Lever7630c852009-09-08 19:49:57 -04002574 if (args->auth_flavor_len > 1) {
2575 dfprintk(MOUNT,
2576 "NFS4: Too many RPC auth flavours specified\n");
2577 return -EINVAL;
2578 }
2579
2580 if (args->client_address == NULL) {
2581 dfprintk(MOUNT,
2582 "NFS4: mount program didn't pass callback address\n");
2583 return -EINVAL;
2584 }
2585
2586 return nfs_parse_devname(dev_name,
2587 &args->nfs_server.hostname,
2588 NFS4_MAXNAMLEN,
2589 &args->nfs_server.export_path,
2590 NFS4_MAXPATHLEN);
2591}
2592
David Howells54ceac42006-08-22 20:06:13 -04002593/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04002594 * Validate NFSv4 mount options
2595 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002596static int nfs4_validate_mount_data(void *options,
2597 struct nfs_parsed_mount_data *args,
2598 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04002599{
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002600 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002601 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002602 char *c;
2603
2604 if (data == NULL)
2605 goto out_no_data;
2606
2607 switch (data->version) {
2608 case 1:
Chuck Lever4c568012007-12-10 14:59:28 -05002609 if (data->host_addrlen > sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002610 goto out_no_address;
Chuck Lever4c568012007-12-10 14:59:28 -05002611 if (data->host_addrlen == 0)
2612 goto out_no_address;
2613 args->nfs_server.addrlen = data->host_addrlen;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002614 if (copy_from_user(sap, data->host_addr, data->host_addrlen))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002615 return -EFAULT;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002616 if (!nfs_verify_server_address(sap))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002617 goto out_no_address;
2618
Chuck Lever6738b252008-06-24 16:33:54 -04002619 if (data->auth_flavourlen) {
2620 if (data->auth_flavourlen > 1)
2621 goto out_inval_auth;
Trond Myklebust20c71f52007-09-20 20:23:51 -04002622 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002623 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04002624 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002625 return -EFAULT;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002626 }
2627
2628 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2629 if (IS_ERR(c))
2630 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002631 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002632
2633 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2634 if (IS_ERR(c))
2635 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002636 args->nfs_server.export_path = c;
2637 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002638
2639 c = strndup_user(data->client_addr.data, 16);
2640 if (IS_ERR(c))
2641 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002642 args->client_address = c;
2643
2644 /*
2645 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2646 * can deal with.
2647 */
2648
2649 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2650 args->rsize = data->rsize;
2651 args->wsize = data->wsize;
2652 args->timeo = data->timeo;
2653 args->retrans = data->retrans;
2654 args->acregmin = data->acregmin;
2655 args->acregmax = data->acregmax;
2656 args->acdirmin = data->acdirmin;
2657 args->acdirmax = data->acdirmax;
2658 args->nfs_server.protocol = data->proto;
Trond Myklebust259875e2008-07-02 14:43:47 -04002659 nfs_validate_transport_protocol(args);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002660
2661 break;
Chuck Lever7630c852009-09-08 19:49:57 -04002662 default:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002663 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever80071222007-07-01 12:13:59 -04002664 return -EINVAL;
2665
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002666 if (!nfs_verify_server_address(sap))
Chuck Lever80071222007-07-01 12:13:59 -04002667 return -EINVAL;
Chuck Levered596a82008-06-26 17:47:05 -04002668
Chuck Lever7630c852009-09-08 19:49:57 -04002669 return nfs4_validate_text_mount_data(options, args, dev_name);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002670 }
2671
2672 return 0;
2673
2674out_no_data:
2675 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2676 return -EINVAL;
2677
2678out_inval_auth:
2679 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2680 data->auth_flavourlen);
2681 return -EINVAL;
2682
2683out_no_address:
2684 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2685 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002686}
2687
2688/*
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002689 * Get the superblock for the NFS4 root partition
David Howells54ceac42006-08-22 20:06:13 -04002690 */
Al Viro31f43472010-10-29 03:38:12 -04002691static struct dentry *
2692nfs4_remote_mount(struct file_system_type *fs_type, int flags,
2693 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002694{
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002695 struct nfs_parsed_mount_data *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002696 struct super_block *s;
2697 struct nfs_server *server;
Trond Myklebust33852a12008-06-19 14:20:11 -04002698 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04002699 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002700 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002701 struct nfs_sb_mountdata sb_mntdata = {
2702 .mntflags = flags,
2703 };
Trond Myklebust33852a12008-06-19 14:20:11 -04002704 int error = -ENOMEM;
David Howellsf7b422b2006-06-09 09:34:33 -04002705
Trond Myklebustb157b062010-04-19 19:05:48 -04002706 mntfh = nfs_alloc_fhandle();
Trond Myklebust33852a12008-06-19 14:20:11 -04002707 if (data == NULL || mntfh == NULL)
Jeff Layton8a0d5512011-12-20 06:57:45 -05002708 goto out;
Eric Parisf9c3a382008-03-05 14:20:18 -05002709
David Howells54ceac42006-08-22 20:06:13 -04002710 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002711 server = nfs4_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002712 if (IS_ERR(server)) {
2713 error = PTR_ERR(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04002714 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002715 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002716 sb_mntdata.server = server;
David Howellsf7b422b2006-06-09 09:34:33 -04002717
Trond Myklebust75180df2007-05-16 16:53:28 -04002718 if (server->flags & NFS4_MOUNT_UNSHARED)
2719 compare_super = NULL;
2720
Sachin Prabhufb2088c2011-08-01 12:10:12 +01002721 /* -o noac implies -o sync */
2722 if (server->flags & NFS_MOUNT_NOAC)
2723 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2724
David Howells54ceac42006-08-22 20:06:13 -04002725 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002726 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002727 if (IS_ERR(s)) {
2728 error = PTR_ERR(s);
David Howellsf7b422b2006-06-09 09:34:33 -04002729 goto out_free;
Trond Myklebust816724e2006-06-24 08:41:41 -04002730 }
2731
Trond Myklebust5dd31772006-08-24 01:03:05 -04002732 if (s->s_fs_info != server) {
2733 nfs_free_server(server);
2734 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002735 } else {
2736 error = nfs_bdi_register(server);
2737 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11002738 goto error_splat_bdi;
Trond Myklebust5dd31772006-08-24 01:03:05 -04002739 }
2740
David Howells54ceac42006-08-22 20:06:13 -04002741 if (!s->s_root) {
2742 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002743 nfs4_fill_super(s);
Jeff Laytonc15c9282012-01-24 16:35:00 +00002744 nfs_fscache_get_super_cookie(s, data->fscache_uniq, NULL);
Trond Myklebust816724e2006-06-24 08:41:41 -04002745 }
David Howellsf7b422b2006-06-09 09:34:33 -04002746
Al Viro0d5839a2011-03-16 05:27:27 -04002747 mntroot = nfs4_get_root(s, mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04002748 if (IS_ERR(mntroot)) {
2749 error = PTR_ERR(mntroot);
2750 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04002751 }
David Howells54ceac42006-08-22 20:06:13 -04002752
Trond Myklebust33852a12008-06-19 14:20:11 -04002753 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Paris46c8ac72008-05-02 13:42:42 -07002754 if (error)
2755 goto error_splat_root;
2756
David Howellsf7b422b2006-06-09 09:34:33 -04002757 s->s_flags |= MS_ACTIVE;
Al Viro31f43472010-10-29 03:38:12 -04002758
Al Viro31f43472010-10-29 03:38:12 -04002759 nfs_free_fhandle(mntfh);
2760 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04002761
Chuck Lever29eb9812007-07-01 12:12:30 -04002762out:
Trond Myklebustb157b062010-04-19 19:05:48 -04002763 nfs_free_fhandle(mntfh);
Al Viro31f43472010-10-29 03:38:12 -04002764 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04002765
Chuck Lever29eb9812007-07-01 12:12:30 -04002766out_free:
2767 nfs_free_server(server);
2768 goto out;
2769
Eric Paris46c8ac72008-05-02 13:42:42 -07002770error_splat_root:
2771 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04002772error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002773 if (server && !s->s_root)
2774 bdi_unregister(&server->backing_dev_info);
2775error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002776 deactivate_locked_super(s);
Chuck Lever29eb9812007-07-01 12:12:30 -04002777 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002778}
2779
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002780static struct vfsmount *nfs_do_root_mount(struct file_system_type *fs_type,
2781 int flags, void *data, const char *hostname)
2782{
2783 struct vfsmount *root_mnt;
2784 char *root_devname;
2785 size_t len;
2786
2787 len = strlen(hostname) + 3;
2788 root_devname = kmalloc(len, GFP_KERNEL);
2789 if (root_devname == NULL)
2790 return ERR_PTR(-ENOMEM);
2791 snprintf(root_devname, len, "%s:/", hostname);
2792 root_mnt = vfs_kern_mount(fs_type, flags, root_devname, data);
2793 kfree(root_devname);
2794 return root_mnt;
2795}
2796
Trond Myklebustce587e02010-04-16 16:22:52 -04002797struct nfs_referral_count {
2798 struct list_head list;
2799 const struct task_struct *task;
2800 unsigned int referral_count;
2801};
2802
2803static LIST_HEAD(nfs_referral_count_list);
2804static DEFINE_SPINLOCK(nfs_referral_count_list_lock);
2805
2806static struct nfs_referral_count *nfs_find_referral_count(void)
2807{
2808 struct nfs_referral_count *p;
2809
2810 list_for_each_entry(p, &nfs_referral_count_list, list) {
2811 if (p->task == current)
2812 return p;
2813 }
2814 return NULL;
2815}
2816
2817#define NFS_MAX_NESTED_REFERRALS 2
2818
2819static int nfs_referral_loop_protect(void)
2820{
2821 struct nfs_referral_count *p, *new;
2822 int ret = -ENOMEM;
2823
2824 new = kmalloc(sizeof(*new), GFP_KERNEL);
2825 if (!new)
2826 goto out;
2827 new->task = current;
2828 new->referral_count = 1;
2829
2830 ret = 0;
2831 spin_lock(&nfs_referral_count_list_lock);
2832 p = nfs_find_referral_count();
2833 if (p != NULL) {
2834 if (p->referral_count >= NFS_MAX_NESTED_REFERRALS)
2835 ret = -ELOOP;
2836 else
2837 p->referral_count++;
2838 } else {
2839 list_add(&new->list, &nfs_referral_count_list);
2840 new = NULL;
2841 }
2842 spin_unlock(&nfs_referral_count_list_lock);
2843 kfree(new);
2844out:
2845 return ret;
2846}
2847
2848static void nfs_referral_loop_unprotect(void)
2849{
2850 struct nfs_referral_count *p;
2851
2852 spin_lock(&nfs_referral_count_list_lock);
2853 p = nfs_find_referral_count();
2854 p->referral_count--;
2855 if (p->referral_count == 0)
2856 list_del(&p->list);
2857 else
2858 p = NULL;
2859 spin_unlock(&nfs_referral_count_list_lock);
2860 kfree(p);
2861}
2862
Al Viro01194982011-03-16 07:25:36 -04002863static struct dentry *nfs_follow_remote_path(struct vfsmount *root_mnt,
2864 const char *export_path)
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002865{
Al Viro01194982011-03-16 07:25:36 -04002866 struct dentry *dentry;
Al Viro5352d3b2011-11-16 21:52:06 -05002867 int err;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002868
Al Viro5352d3b2011-11-16 21:52:06 -05002869 if (IS_ERR(root_mnt))
2870 return ERR_CAST(root_mnt);
2871
2872 err = nfs_referral_loop_protect();
2873 if (err) {
Al Viroea441d12011-11-16 21:43:59 -05002874 mntput(root_mnt);
Al Viro5352d3b2011-11-16 21:52:06 -05002875 return ERR_PTR(err);
Al Viroc1334492011-11-16 16:12:14 -05002876 }
Trond Myklebustce587e02010-04-16 16:22:52 -04002877
Al Viroea441d12011-11-16 21:43:59 -05002878 dentry = mount_subtree(root_mnt, export_path);
2879 nfs_referral_loop_unprotect();
Linus Torvaldsa2770d82009-12-17 12:51:05 -08002880
Al Viro01194982011-03-16 07:25:36 -04002881 return dentry;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002882}
2883
Al Viro01194982011-03-16 07:25:36 -04002884static struct dentry *nfs4_try_mount(int flags, const char *dev_name,
2885 struct nfs_parsed_mount_data *data)
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002886{
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002887 char *export_path;
2888 struct vfsmount *root_mnt;
Al Viro01194982011-03-16 07:25:36 -04002889 struct dentry *res;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002890
Chuck Levera6fe23b2009-09-08 19:50:00 -04002891 dfprintk(MOUNT, "--> nfs4_try_mount()\n");
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002892
2893 export_path = data->nfs_server.export_path;
2894 data->nfs_server.export_path = "/";
2895 root_mnt = nfs_do_root_mount(&nfs4_remote_fs_type, flags, data,
2896 data->nfs_server.hostname);
2897 data->nfs_server.export_path = export_path;
2898
Al Viro5352d3b2011-11-16 21:52:06 -05002899 res = nfs_follow_remote_path(root_mnt, export_path);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002900
Al Viro01194982011-03-16 07:25:36 -04002901 dfprintk(MOUNT, "<-- nfs4_try_mount() = %ld%s\n",
2902 IS_ERR(res) ? PTR_ERR(res) : 0,
2903 IS_ERR(res) ? " [error]" : "");
2904 return res;
Chuck Levera6fe23b2009-09-08 19:50:00 -04002905}
2906
2907/*
2908 * Get the superblock for an NFS4 mountpoint
2909 */
Al Viro01194982011-03-16 07:25:36 -04002910static struct dentry *nfs4_mount(struct file_system_type *fs_type,
2911 int flags, const char *dev_name, void *raw_data)
Chuck Levera6fe23b2009-09-08 19:50:00 -04002912{
2913 struct nfs_parsed_mount_data *data;
2914 int error = -ENOMEM;
Al Viro01194982011-03-16 07:25:36 -04002915 struct dentry *res = ERR_PTR(-ENOMEM);
Chuck Levera6fe23b2009-09-08 19:50:00 -04002916
Trond Myklebustc5811db2009-10-06 15:40:15 -04002917 data = nfs_alloc_parsed_mount_data(4);
Chuck Levera6fe23b2009-09-08 19:50:00 -04002918 if (data == NULL)
Jeff Layton8a0d5512011-12-20 06:57:45 -05002919 goto out;
Chuck Levera6fe23b2009-09-08 19:50:00 -04002920
2921 /* Validate the mount data */
2922 error = nfs4_validate_mount_data(raw_data, data, dev_name);
Al Viro01194982011-03-16 07:25:36 -04002923 if (error < 0) {
2924 res = ERR_PTR(error);
Chuck Levera6fe23b2009-09-08 19:50:00 -04002925 goto out;
Al Viro01194982011-03-16 07:25:36 -04002926 }
Chuck Levera6fe23b2009-09-08 19:50:00 -04002927
Al Viro01194982011-03-16 07:25:36 -04002928 res = nfs4_try_mount(flags, dev_name, data);
2929 if (IS_ERR(res))
2930 error = PTR_ERR(res);
Chuck Levera6fe23b2009-09-08 19:50:00 -04002931
2932out:
Jeff Layton8a0d5512011-12-20 06:57:45 -05002933 nfs_free_parsed_mount_data(data);
Al Viro01194982011-03-16 07:25:36 -04002934 dprintk("<-- nfs4_mount() = %d%s\n", error,
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002935 error != 0 ? " [error]" : "");
Al Viro01194982011-03-16 07:25:36 -04002936 return res;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002937}
2938
David Howellsf7b422b2006-06-09 09:34:33 -04002939static void nfs4_kill_super(struct super_block *sb)
2940{
2941 struct nfs_server *server = NFS_SB(sb);
2942
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002943 dprintk("--> %s\n", __func__);
Trond Myklebust515d8612008-12-23 15:21:46 -05002944 nfs_super_return_all_delegations(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002945 kill_anon_super(sb);
David Howells08734042009-04-03 16:42:42 +01002946 nfs_fscache_release_super_cookie(sb);
David Howells54ceac42006-08-22 20:06:13 -04002947 nfs_free_server(server);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002948 dprintk("<-- %s\n", __func__);
David Howellsf7b422b2006-06-09 09:34:33 -04002949}
2950
2951/*
David Howells54ceac42006-08-22 20:06:13 -04002952 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -04002953 */
Al Viro31f43472010-10-29 03:38:12 -04002954static struct dentry *
2955nfs4_xdev_mount(struct file_system_type *fs_type, int flags,
2956 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002957{
2958 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002959 struct super_block *s;
2960 struct nfs_server *server;
2961 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002962 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002963 struct nfs_sb_mountdata sb_mntdata = {
2964 .mntflags = flags,
2965 };
David Howells54ceac42006-08-22 20:06:13 -04002966 int error;
2967
Al Viro31f43472010-10-29 03:38:12 -04002968 dprintk("--> nfs4_xdev_mount()\n");
David Howells54ceac42006-08-22 20:06:13 -04002969
2970 /* create a new volume representation */
2971 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2972 if (IS_ERR(server)) {
2973 error = PTR_ERR(server);
2974 goto out_err_noserver;
2975 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002976 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002977
Trond Myklebust75180df2007-05-16 16:53:28 -04002978 if (server->flags & NFS4_MOUNT_UNSHARED)
2979 compare_super = NULL;
2980
Sachin Prabhufb2088c2011-08-01 12:10:12 +01002981 /* -o noac implies -o sync */
2982 if (server->flags & NFS_MOUNT_NOAC)
2983 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2984
David Howells54ceac42006-08-22 20:06:13 -04002985 /* Get a superblock - note that we may end up sharing one that already exists */
Andy Adamsonec9a05c2008-10-17 10:44:37 -04002986 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002987 if (IS_ERR(s)) {
2988 error = PTR_ERR(s);
2989 goto out_err_nosb;
2990 }
2991
2992 if (s->s_fs_info != server) {
2993 nfs_free_server(server);
2994 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002995 } else {
2996 error = nfs_bdi_register(server);
2997 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11002998 goto error_splat_bdi;
David Howells54ceac42006-08-22 20:06:13 -04002999 }
3000
3001 if (!s->s_root) {
3002 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04003003 nfs4_clone_super(s, data->sb);
David Howells2df54802009-09-23 14:36:39 -04003004 nfs_fscache_get_super_cookie(s, NULL, data);
David Howells54ceac42006-08-22 20:06:13 -04003005 }
3006
Al Viro0d5839a2011-03-16 05:27:27 -04003007 mntroot = nfs4_get_root(s, data->fh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04003008 if (IS_ERR(mntroot)) {
3009 error = PTR_ERR(mntroot);
3010 goto error_splat_super;
3011 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05003012 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
3013 dput(mntroot);
3014 error = -ESTALE;
3015 goto error_splat_super;
3016 }
David Howells54ceac42006-08-22 20:06:13 -04003017
3018 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04003019
Eric Paris46c8ac72008-05-02 13:42:42 -07003020 security_sb_clone_mnt_opts(data->sb, s);
3021
Al Viro31f43472010-10-29 03:38:12 -04003022 dprintk("<-- nfs4_xdev_mount() = 0\n");
3023 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04003024
3025out_err_nosb:
3026 nfs_free_server(server);
3027out_err_noserver:
Al Viro31f43472010-10-29 03:38:12 -04003028 dprintk("<-- nfs4_xdev_mount() = %d [error]\n", error);
3029 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04003030
3031error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11003032 if (server && !s->s_root)
3033 bdi_unregister(&server->backing_dev_info);
3034error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04003035 deactivate_locked_super(s);
Al Viro31f43472010-10-29 03:38:12 -04003036 dprintk("<-- nfs4_xdev_mount() = %d [splat]\n", error);
3037 return ERR_PTR(error);
David Howellsf7b422b2006-06-09 09:34:33 -04003038}
3039
Al Viro31f43472010-10-29 03:38:12 -04003040static struct dentry *
3041nfs4_remote_referral_mount(struct file_system_type *fs_type, int flags,
3042 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04003043{
3044 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04003045 struct super_block *s;
3046 struct nfs_server *server;
3047 struct dentry *mntroot;
Trond Myklebust4f727292010-04-16 16:22:48 -04003048 struct nfs_fh *mntfh;
Trond Myklebust75180df2007-05-16 16:53:28 -04003049 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04003050 struct nfs_sb_mountdata sb_mntdata = {
3051 .mntflags = flags,
3052 };
Trond Myklebust4f727292010-04-16 16:22:48 -04003053 int error = -ENOMEM;
David Howells54ceac42006-08-22 20:06:13 -04003054
3055 dprintk("--> nfs4_referral_get_sb()\n");
3056
Trond Myklebust4f727292010-04-16 16:22:48 -04003057 mntfh = nfs_alloc_fhandle();
3058 if (mntfh == NULL)
3059 goto out_err_nofh;
3060
David Howells54ceac42006-08-22 20:06:13 -04003061 /* create a new volume representation */
Trond Myklebust4f727292010-04-16 16:22:48 -04003062 server = nfs4_create_referral_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04003063 if (IS_ERR(server)) {
3064 error = PTR_ERR(server);
3065 goto out_err_noserver;
3066 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04003067 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04003068
Trond Myklebust75180df2007-05-16 16:53:28 -04003069 if (server->flags & NFS4_MOUNT_UNSHARED)
3070 compare_super = NULL;
3071
Sachin Prabhufb2088c2011-08-01 12:10:12 +01003072 /* -o noac implies -o sync */
3073 if (server->flags & NFS_MOUNT_NOAC)
3074 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
3075
David Howells54ceac42006-08-22 20:06:13 -04003076 /* Get a superblock - note that we may end up sharing one that already exists */
Andy Adamsonec9a05c2008-10-17 10:44:37 -04003077 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04003078 if (IS_ERR(s)) {
3079 error = PTR_ERR(s);
3080 goto out_err_nosb;
3081 }
3082
3083 if (s->s_fs_info != server) {
3084 nfs_free_server(server);
3085 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07003086 } else {
3087 error = nfs_bdi_register(server);
3088 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11003089 goto error_splat_bdi;
David Howells54ceac42006-08-22 20:06:13 -04003090 }
3091
3092 if (!s->s_root) {
3093 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04003094 nfs4_fill_super(s);
David Howells2df54802009-09-23 14:36:39 -04003095 nfs_fscache_get_super_cookie(s, NULL, data);
David Howells54ceac42006-08-22 20:06:13 -04003096 }
3097
Al Viro0d5839a2011-03-16 05:27:27 -04003098 mntroot = nfs4_get_root(s, mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04003099 if (IS_ERR(mntroot)) {
3100 error = PTR_ERR(mntroot);
3101 goto error_splat_super;
3102 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05003103 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
3104 dput(mntroot);
3105 error = -ESTALE;
3106 goto error_splat_super;
3107 }
David Howells54ceac42006-08-22 20:06:13 -04003108
3109 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04003110
Eric Paris46c8ac72008-05-02 13:42:42 -07003111 security_sb_clone_mnt_opts(data->sb, s);
3112
Trond Myklebust4f727292010-04-16 16:22:48 -04003113 nfs_free_fhandle(mntfh);
David Howells54ceac42006-08-22 20:06:13 -04003114 dprintk("<-- nfs4_referral_get_sb() = 0\n");
Al Viro31f43472010-10-29 03:38:12 -04003115 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04003116
3117out_err_nosb:
3118 nfs_free_server(server);
3119out_err_noserver:
Trond Myklebust4f727292010-04-16 16:22:48 -04003120 nfs_free_fhandle(mntfh);
3121out_err_nofh:
David Howells54ceac42006-08-22 20:06:13 -04003122 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
Al Viro31f43472010-10-29 03:38:12 -04003123 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04003124
3125error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11003126 if (server && !s->s_root)
3127 bdi_unregister(&server->backing_dev_info);
3128error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04003129 deactivate_locked_super(s);
Trond Myklebust4f727292010-04-16 16:22:48 -04003130 nfs_free_fhandle(mntfh);
David Howells54ceac42006-08-22 20:06:13 -04003131 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
Al Viro31f43472010-10-29 03:38:12 -04003132 return ERR_PTR(error);
David Howellsf7b422b2006-06-09 09:34:33 -04003133}
3134
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04003135/*
3136 * Create an NFS4 server record on referral traversal
3137 */
Al Viro01194982011-03-16 07:25:36 -04003138static struct dentry *nfs4_referral_mount(struct file_system_type *fs_type,
3139 int flags, const char *dev_name, void *raw_data)
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04003140{
3141 struct nfs_clone_mount *data = raw_data;
3142 char *export_path;
3143 struct vfsmount *root_mnt;
Al Viro01194982011-03-16 07:25:36 -04003144 struct dentry *res;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04003145
Al Viro01194982011-03-16 07:25:36 -04003146 dprintk("--> nfs4_referral_mount()\n");
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04003147
3148 export_path = data->mnt_path;
3149 data->mnt_path = "/";
3150
3151 root_mnt = nfs_do_root_mount(&nfs4_remote_referral_fs_type,
3152 flags, data, data->hostname);
3153 data->mnt_path = export_path;
3154
Al Viro5352d3b2011-11-16 21:52:06 -05003155 res = nfs_follow_remote_path(root_mnt, export_path);
Al Viro01194982011-03-16 07:25:36 -04003156 dprintk("<-- nfs4_referral_mount() = %ld%s\n",
3157 IS_ERR(res) ? PTR_ERR(res) : 0,
3158 IS_ERR(res) ? " [error]" : "");
3159 return res;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04003160}
3161
David Howells54ceac42006-08-22 20:06:13 -04003162#endif /* CONFIG_NFS_V4 */