blob: 13c2a5be476593eca87af812684306c87fae3ab1 [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>
Trond Myklebust2446ab62012-03-01 17:00:56 -050056#include <linux/rcupdate.h>
David Howellsf7b422b2006-06-09 09:34:33 -040057
David Howellsf7b422b2006-06-09 09:34:33 -040058#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"
Bryan Schumakerab7017a2012-07-30 16:05:16 -040067#include "nfs.h"
David Howellsf7b422b2006-06-09 09:34:33 -040068
69#define NFSDBG_FACILITY NFSDBG_VFS
Bryan Schumakerb72e4f42012-05-10 15:07:40 -040070#define NFS_TEXT_DATA 1
David Howellsf7b422b2006-06-09 09:34:33 -040071
Bryan Schumaker1c606fb2012-07-30 16:05:24 -040072#if IS_ENABLED(CONFIG_NFS_V3)
Paulius Zaleckas1e657bd2010-10-31 18:21:05 +020073#define NFS_DEFAULT_VERSION 3
74#else
75#define NFS_DEFAULT_VERSION 2
76#endif
77
Chuck Leverbf0fd762007-07-01 12:13:44 -040078enum {
79 /* Mount options that take no arguments */
80 Opt_soft, Opt_hard,
Chuck Leverbf0fd762007-07-01 12:13:44 -040081 Opt_posix, Opt_noposix,
82 Opt_cto, Opt_nocto,
83 Opt_ac, Opt_noac,
84 Opt_lock, Opt_nolock,
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -040085 Opt_udp, Opt_tcp, Opt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -040086 Opt_acl, Opt_noacl,
87 Opt_rdirplus, Opt_nordirplus,
Trond Myklebust75180df2007-05-16 16:53:28 -040088 Opt_sharecache, Opt_nosharecache,
Chuck Leverd7403512008-12-23 15:21:37 -050089 Opt_resvport, Opt_noresvport,
David Howellsb797cac2009-04-03 16:42:48 +010090 Opt_fscache, Opt_nofscache,
Chuck Lever89652612012-09-14 17:24:11 -040091 Opt_migration, Opt_nomigration,
Chuck Leverbf0fd762007-07-01 12:13:44 -040092
93 /* Mount options that take integer arguments */
94 Opt_port,
95 Opt_rsize, Opt_wsize, Opt_bsize,
96 Opt_timeo, Opt_retrans,
97 Opt_acregmin, Opt_acregmax,
98 Opt_acdirmin, Opt_acdirmax,
99 Opt_actimeo,
100 Opt_namelen,
101 Opt_mountport,
Chuck Levere887cbc2007-10-26 13:32:29 -0400102 Opt_mountvers,
Mike Sager3fd5be92009-04-01 09:21:48 -0400103 Opt_minorversion,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400104
105 /* Mount options that take string arguments */
Trond Myklebust0d71b052012-03-02 13:59:49 -0500106 Opt_nfsvers,
Chuck Lever33832032007-12-10 14:59:13 -0500107 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
Chuck Lever0ac83772007-09-11 18:01:04 -0400108 Opt_addr, Opt_mountaddr, Opt_clientaddr,
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400109 Opt_lookupcache,
David Howellsb797cac2009-04-03 16:42:48 +0100110 Opt_fscache_uniq,
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400111 Opt_local_lock,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400112
Chuck Leverf45663c2008-06-24 19:28:02 -0400113 /* Special mount options */
114 Opt_userspace, Opt_deprecated, Opt_sloppy,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400115
116 Opt_err
117};
118
Steven Whitehousea447c092008-10-13 10:46:57 +0100119static const match_table_t nfs_mount_option_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400120 { Opt_userspace, "bg" },
121 { Opt_userspace, "fg" },
Chuck Leverecbb3842008-06-12 12:37:33 -0400122 { Opt_userspace, "retry=%s" },
123
Chuck Leverf45663c2008-06-24 19:28:02 -0400124 { Opt_sloppy, "sloppy" },
125
Chuck Leverbf0fd762007-07-01 12:13:44 -0400126 { Opt_soft, "soft" },
127 { Opt_hard, "hard" },
Chuck Leverd33e4df2008-06-12 12:37:41 -0400128 { Opt_deprecated, "intr" },
129 { Opt_deprecated, "nointr" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400130 { Opt_posix, "posix" },
131 { Opt_noposix, "noposix" },
132 { Opt_cto, "cto" },
133 { Opt_nocto, "nocto" },
134 { Opt_ac, "ac" },
135 { Opt_noac, "noac" },
136 { Opt_lock, "lock" },
137 { Opt_nolock, "nolock" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400138 { Opt_udp, "udp" },
139 { Opt_tcp, "tcp" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400140 { Opt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400141 { Opt_acl, "acl" },
142 { Opt_noacl, "noacl" },
143 { Opt_rdirplus, "rdirplus" },
144 { Opt_nordirplus, "nordirplus" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400145 { Opt_sharecache, "sharecache" },
146 { Opt_nosharecache, "nosharecache" },
Chuck Leverd7403512008-12-23 15:21:37 -0500147 { Opt_resvport, "resvport" },
148 { Opt_noresvport, "noresvport" },
David Howellsb797cac2009-04-03 16:42:48 +0100149 { Opt_fscache, "fsc" },
David Howellsb797cac2009-04-03 16:42:48 +0100150 { Opt_nofscache, "nofsc" },
Chuck Lever89652612012-09-14 17:24:11 -0400151 { Opt_migration, "migration" },
152 { Opt_nomigration, "nomigration" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400153
Chuck Levera5a16ba2009-06-17 18:02:14 -0700154 { Opt_port, "port=%s" },
155 { Opt_rsize, "rsize=%s" },
156 { Opt_wsize, "wsize=%s" },
157 { Opt_bsize, "bsize=%s" },
158 { Opt_timeo, "timeo=%s" },
159 { Opt_retrans, "retrans=%s" },
160 { Opt_acregmin, "acregmin=%s" },
161 { Opt_acregmax, "acregmax=%s" },
162 { Opt_acdirmin, "acdirmin=%s" },
163 { Opt_acdirmax, "acdirmax=%s" },
164 { Opt_actimeo, "actimeo=%s" },
165 { Opt_namelen, "namlen=%s" },
166 { Opt_mountport, "mountport=%s" },
167 { Opt_mountvers, "mountvers=%s" },
Trond Myklebust0d71b052012-03-02 13:59:49 -0500168 { Opt_minorversion, "minorversion=%s" },
169
Chuck Levera5a16ba2009-06-17 18:02:14 -0700170 { Opt_nfsvers, "nfsvers=%s" },
171 { Opt_nfsvers, "vers=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400172
173 { Opt_sec, "sec=%s" },
174 { Opt_proto, "proto=%s" },
175 { Opt_mountproto, "mountproto=%s" },
176 { Opt_addr, "addr=%s" },
177 { Opt_clientaddr, "clientaddr=%s" },
Chuck Lever33832032007-12-10 14:59:13 -0500178 { Opt_mounthost, "mounthost=%s" },
Chuck Lever0ac83772007-09-11 18:01:04 -0400179 { Opt_mountaddr, "mountaddr=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400180
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400181 { Opt_lookupcache, "lookupcache=%s" },
Chuck Levera6d5ff62010-05-07 13:33:58 -0400182 { Opt_fscache_uniq, "fsc=%s" },
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400183 { Opt_local_lock, "local_lock=%s" },
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400184
Trond Myklebust38622792012-03-02 14:06:39 -0500185 /* The following needs to be listed after all other options */
186 { Opt_nfsvers, "v%s" },
187
Chuck Leverbf0fd762007-07-01 12:13:44 -0400188 { Opt_err, NULL }
189};
190
191enum {
Jeff Laytonee671b02009-12-03 15:58:56 -0500192 Opt_xprt_udp, Opt_xprt_udp6, Opt_xprt_tcp, Opt_xprt_tcp6, Opt_xprt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400193
194 Opt_xprt_err
195};
196
Steven Whitehousea447c092008-10-13 10:46:57 +0100197static const match_table_t nfs_xprt_protocol_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400198 { Opt_xprt_udp, "udp" },
Jeff Laytonee671b02009-12-03 15:58:56 -0500199 { Opt_xprt_udp6, "udp6" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400200 { Opt_xprt_tcp, "tcp" },
Jeff Laytonee671b02009-12-03 15:58:56 -0500201 { Opt_xprt_tcp6, "tcp6" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400202 { Opt_xprt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400203
204 { Opt_xprt_err, NULL }
205};
206
207enum {
208 Opt_sec_none, Opt_sec_sys,
209 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
210 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
211 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
212
213 Opt_sec_err
214};
215
Steven Whitehousea447c092008-10-13 10:46:57 +0100216static const match_table_t nfs_secflavor_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400217 { Opt_sec_none, "none" },
218 { Opt_sec_none, "null" },
219 { Opt_sec_sys, "sys" },
220
221 { Opt_sec_krb5, "krb5" },
222 { Opt_sec_krb5i, "krb5i" },
223 { Opt_sec_krb5p, "krb5p" },
224
225 { Opt_sec_lkey, "lkey" },
226 { Opt_sec_lkeyi, "lkeyi" },
227 { Opt_sec_lkeyp, "lkeyp" },
228
Olga Kornievskaia8d042212008-02-13 16:47:06 -0500229 { Opt_sec_spkm, "spkm3" },
230 { Opt_sec_spkmi, "spkm3i" },
231 { Opt_sec_spkmp, "spkm3p" },
232
Chuck Leverbf0fd762007-07-01 12:13:44 -0400233 { Opt_sec_err, NULL }
234};
235
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400236enum {
237 Opt_lookupcache_all, Opt_lookupcache_positive,
238 Opt_lookupcache_none,
239
240 Opt_lookupcache_err
241};
242
243static match_table_t nfs_lookupcache_tokens = {
244 { Opt_lookupcache_all, "all" },
245 { Opt_lookupcache_positive, "pos" },
246 { Opt_lookupcache_positive, "positive" },
247 { Opt_lookupcache_none, "none" },
248
249 { Opt_lookupcache_err, NULL }
250};
251
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400252enum {
253 Opt_local_lock_all, Opt_local_lock_flock, Opt_local_lock_posix,
254 Opt_local_lock_none,
255
256 Opt_local_lock_err
257};
258
259static match_table_t nfs_local_lock_tokens = {
260 { Opt_local_lock_all, "all" },
261 { Opt_local_lock_flock, "flock" },
262 { Opt_local_lock_posix, "posix" },
263 { Opt_local_lock_none, "none" },
264
265 { Opt_local_lock_err, NULL }
266};
267
Trond Myklebust0d71b052012-03-02 13:59:49 -0500268enum {
269 Opt_vers_2, Opt_vers_3, Opt_vers_4, Opt_vers_4_0,
270 Opt_vers_4_1,
271
272 Opt_vers_err
273};
274
275static match_table_t nfs_vers_tokens = {
276 { Opt_vers_2, "2" },
277 { Opt_vers_3, "3" },
278 { Opt_vers_4, "4" },
279 { Opt_vers_4_0, "4.0" },
280 { Opt_vers_4_1, "4.1" },
281
282 { Opt_vers_err, NULL }
283};
Chuck Leverbf0fd762007-07-01 12:13:44 -0400284
Al Viro31f43472010-10-29 03:38:12 -0400285static struct dentry *nfs_xdev_mount(struct file_system_type *fs_type,
286 int flags, const char *dev_name, void *raw_data);
David Howellsf7b422b2006-06-09 09:34:33 -0400287
Bryan Schumakerab7017a2012-07-30 16:05:16 -0400288struct file_system_type nfs_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400289 .owner = THIS_MODULE,
290 .name = "nfs",
Al Viro01194982011-03-16 07:25:36 -0400291 .mount = nfs_fs_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400292 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700293 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400294};
Bryan Schumakerddda8e02012-07-30 16:05:23 -0400295EXPORT_SYMBOL_GPL(nfs_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400296
David Howells54ceac42006-08-22 20:06:13 -0400297struct file_system_type nfs_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400298 .owner = THIS_MODULE,
299 .name = "nfs",
Al Viro31f43472010-10-29 03:38:12 -0400300 .mount = nfs_xdev_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
Bryan Schumaker6a744902012-07-30 16:05:20 -0400305const struct super_operations nfs_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400306 .alloc_inode = nfs_alloc_inode,
307 .destroy_inode = nfs_destroy_inode,
308 .write_inode = nfs_write_inode,
Trond Myklebust387c1492010-02-03 08:27:35 -0500309 .put_super = nfs_put_super,
David Howellsf7b422b2006-06-09 09:34:33 -0400310 .statfs = nfs_statfs,
Al Virob57922d2010-06-07 14:34:48 -0400311 .evict_inode = nfs_evict_inode,
David Howellsf7b422b2006-06-09 09:34:33 -0400312 .umount_begin = nfs_umount_begin,
313 .show_options = nfs_show_options,
Al Viroc7f404b2011-03-16 06:59:40 -0400314 .show_devname = nfs_show_devname,
315 .show_path = nfs_show_path,
David Howellsf7b422b2006-06-09 09:34:33 -0400316 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400317 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400318};
Bryan Schumakerddda8e02012-07-30 16:05:23 -0400319EXPORT_SYMBOL_GPL(nfs_sops);
David Howellsf7b422b2006-06-09 09:34:33 -0400320
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400321#if IS_ENABLED(CONFIG_NFS_V4)
Bryan Schumakerb72e4f42012-05-10 15:07:40 -0400322static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *);
Bryan Schumakerd72c7272012-05-10 15:07:41 -0400323static int nfs4_validate_mount_data(void *options,
324 struct nfs_parsed_mount_data *args, const char *dev_name);
bjschuma@gmail.com1ae811e2012-08-08 13:57:06 -0400325
326struct file_system_type nfs4_fs_type = {
327 .owner = THIS_MODULE,
328 .name = "nfs4",
329 .mount = nfs_fs_mount,
330 .kill_sb = nfs_kill_super,
331 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
332};
333EXPORT_SYMBOL_GPL(nfs4_fs_type);
334
335static int __init register_nfs4_fs(void)
336{
337 return register_filesystem(&nfs4_fs_type);
338}
339
340static void unregister_nfs4_fs(void)
341{
342 unregister_filesystem(&nfs4_fs_type);
343}
344#else
345static int __init register_nfs4_fs(void)
346{
347 return 0;
348}
349
350static void unregister_nfs4_fs(void)
351{
352}
David Howellsf7b422b2006-06-09 09:34:33 -0400353#endif
354
Rusty Russell8e1f9362007-07-17 04:03:17 -0700355static struct shrinker acl_shrinker = {
356 .shrink = nfs_access_cache_shrinker,
357 .seeks = DEFAULT_SEEKS,
358};
Trond Myklebust979df722006-07-25 11:28:19 -0400359
David Howellsf7b422b2006-06-09 09:34:33 -0400360/*
361 * Register the NFS filesystems
362 */
363int __init register_nfs_fs(void)
364{
365 int ret;
366
367 ret = register_filesystem(&nfs_fs_type);
368 if (ret < 0)
369 goto error_0;
370
bjschuma@gmail.com1ae811e2012-08-08 13:57:06 -0400371 ret = register_nfs4_fs();
David Howellsf7b422b2006-06-09 09:34:33 -0400372 if (ret < 0)
373 goto error_1;
bjschuma@gmail.com1ae811e2012-08-08 13:57:06 -0400374
375 ret = nfs_register_sysctl();
376 if (ret < 0)
377 goto error_2;
Rusty Russell8e1f9362007-07-17 04:03:17 -0700378 register_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400379 return 0;
380
bjschuma@gmail.com1ae811e2012-08-08 13:57:06 -0400381error_2:
382 unregister_nfs4_fs();
David Howellsf7b422b2006-06-09 09:34:33 -0400383error_1:
384 unregister_filesystem(&nfs_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400385error_0:
386 return ret;
387}
388
389/*
390 * Unregister the NFS filesystems
391 */
392void __exit unregister_nfs_fs(void)
393{
Rusty Russell8e1f9362007-07-17 04:03:17 -0700394 unregister_shrinker(&acl_shrinker);
Alexey Dobriyan49af7ee2007-09-18 22:46:40 -0700395 nfs_unregister_sysctl();
bjschuma@gmail.com1ae811e2012-08-08 13:57:06 -0400396 unregister_nfs4_fs();
David Howellsf7b422b2006-06-09 09:34:33 -0400397 unregister_filesystem(&nfs_fs_type);
398}
399
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400400void nfs_sb_active(struct super_block *sb)
Steve Dicksonef818a22007-11-08 04:05:04 -0500401{
402 struct nfs_server *server = NFS_SB(sb);
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400403
404 if (atomic_inc_return(&server->active) == 1)
405 atomic_inc(&sb->s_active);
406}
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400407EXPORT_SYMBOL_GPL(nfs_sb_active);
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400408
409void nfs_sb_deactive(struct super_block *sb)
410{
411 struct nfs_server *server = NFS_SB(sb);
412
413 if (atomic_dec_and_test(&server->active))
414 deactivate_super(sb);
Steve Dicksonef818a22007-11-08 04:05:04 -0500415}
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400416EXPORT_SYMBOL_GPL(nfs_sb_deactive);
Steve Dicksonef818a22007-11-08 04:05:04 -0500417
David Howellsf7b422b2006-06-09 09:34:33 -0400418/*
419 * Deliver file system statistics to userspace
420 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -0400421int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
David Howellsf7b422b2006-06-09 09:34:33 -0400422{
David Howells0c7d90c2006-08-22 20:06:10 -0400423 struct nfs_server *server = NFS_SB(dentry->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400424 unsigned char blockbits;
425 unsigned long blockres;
David Howells0c7d90c2006-08-22 20:06:10 -0400426 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400427 struct nfs_fsstat res;
428 int error = -ENOMEM;
429
430 res.fattr = nfs_alloc_fattr();
431 if (res.fattr == NULL)
432 goto out_err;
David Howellsf7b422b2006-06-09 09:34:33 -0400433
David Howells8fa5c002006-08-22 20:06:12 -0400434 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
Menyhart Zoltanfbf3fdd2010-09-12 19:55:26 -0400435 if (unlikely(error == -ESTALE)) {
436 struct dentry *pd_dentry;
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400437
Menyhart Zoltanfbf3fdd2010-09-12 19:55:26 -0400438 pd_dentry = dget_parent(dentry);
439 if (pd_dentry != NULL) {
440 nfs_zap_caches(pd_dentry->d_inode);
441 dput(pd_dentry);
442 }
443 }
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400444 nfs_free_fattr(res.fattr);
David Howellsf7b422b2006-06-09 09:34:33 -0400445 if (error < 0)
446 goto out_err;
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400447
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700448 buf->f_type = NFS_SUPER_MAGIC;
David Howellsf7b422b2006-06-09 09:34:33 -0400449
450 /*
451 * Current versions of glibc do not correctly handle the
452 * case where f_frsize != f_bsize. Eventually we want to
453 * report the value of wtmult in this field.
454 */
David Howells0c7d90c2006-08-22 20:06:10 -0400455 buf->f_frsize = dentry->d_sb->s_blocksize;
David Howellsf7b422b2006-06-09 09:34:33 -0400456
457 /*
458 * On most *nix systems, f_blocks, f_bfree, and f_bavail
459 * are reported in units of f_frsize. Linux hasn't had
460 * an f_frsize field in its statfs struct until recently,
461 * thus historically Linux's sys_statfs reports these
462 * fields in units of f_bsize.
463 */
David Howells0c7d90c2006-08-22 20:06:10 -0400464 buf->f_bsize = dentry->d_sb->s_blocksize;
465 blockbits = dentry->d_sb->s_blocksize_bits;
David Howellsf7b422b2006-06-09 09:34:33 -0400466 blockres = (1 << blockbits) - 1;
467 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
468 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
469 buf->f_bavail = (res.abytes + blockres) >> blockbits;
470
471 buf->f_files = res.tfiles;
472 buf->f_ffree = res.afiles;
473
474 buf->f_namelen = server->namelen;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700475
David Howellsf7b422b2006-06-09 09:34:33 -0400476 return 0;
477
478 out_err:
Harvey Harrison3110ff82008-05-02 13:42:44 -0700479 dprintk("%s: statfs error = %d\n", __func__, -error);
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700480 return error;
David Howellsf7b422b2006-06-09 09:34:33 -0400481}
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400482EXPORT_SYMBOL_GPL(nfs_statfs);
David Howellsf7b422b2006-06-09 09:34:33 -0400483
David Howells7d4e2742006-08-22 20:06:07 -0400484/*
485 * Map the security flavour number to a name
486 */
Trond Myklebust81039f12006-06-09 09:34:34 -0400487static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
488{
David Howells7d4e2742006-08-22 20:06:07 -0400489 static const struct {
Trond Myklebust81039f12006-06-09 09:34:34 -0400490 rpc_authflavor_t flavour;
491 const char *str;
492 } sec_flavours[] = {
493 { RPC_AUTH_NULL, "null" },
494 { RPC_AUTH_UNIX, "sys" },
495 { RPC_AUTH_GSS_KRB5, "krb5" },
496 { RPC_AUTH_GSS_KRB5I, "krb5i" },
497 { RPC_AUTH_GSS_KRB5P, "krb5p" },
498 { RPC_AUTH_GSS_LKEY, "lkey" },
499 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
500 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
501 { RPC_AUTH_GSS_SPKM, "spkm" },
502 { RPC_AUTH_GSS_SPKMI, "spkmi" },
503 { RPC_AUTH_GSS_SPKMP, "spkmp" },
Chuck Lever4d81cd12007-07-01 12:12:40 -0400504 { UINT_MAX, "unknown" }
Trond Myklebust81039f12006-06-09 09:34:34 -0400505 };
506 int i;
507
Chuck Lever4d81cd12007-07-01 12:12:40 -0400508 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
Trond Myklebust81039f12006-06-09 09:34:34 -0400509 if (sec_flavours[i].flavour == flavour)
510 break;
511 }
512 return sec_flavours[i].str;
513}
514
Jeff Laytonee671b02009-12-03 15:58:56 -0500515static void nfs_show_mountd_netid(struct seq_file *m, struct nfs_server *nfss,
516 int showdefaults)
517{
518 struct sockaddr *sap = (struct sockaddr *) &nfss->mountd_address;
519
520 seq_printf(m, ",mountproto=");
521 switch (sap->sa_family) {
522 case AF_INET:
523 switch (nfss->mountd_protocol) {
524 case IPPROTO_UDP:
525 seq_printf(m, RPCBIND_NETID_UDP);
526 break;
527 case IPPROTO_TCP:
528 seq_printf(m, RPCBIND_NETID_TCP);
529 break;
530 default:
531 if (showdefaults)
532 seq_printf(m, "auto");
533 }
534 break;
535 case AF_INET6:
536 switch (nfss->mountd_protocol) {
537 case IPPROTO_UDP:
538 seq_printf(m, RPCBIND_NETID_UDP6);
539 break;
540 case IPPROTO_TCP:
541 seq_printf(m, RPCBIND_NETID_TCP6);
542 break;
543 default:
544 if (showdefaults)
545 seq_printf(m, "auto");
546 }
547 break;
548 default:
549 if (showdefaults)
550 seq_printf(m, "auto");
551 }
552}
553
Chuck Lever82d101d2008-03-14 14:10:37 -0400554static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
555 int showdefaults)
556{
557 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
558
Bryan Schumakerd5eff1a2010-08-03 13:04:00 -0400559 if (nfss->flags & NFS_MOUNT_LEGACY_INTERFACE)
560 return;
561
Chuck Lever82d101d2008-03-14 14:10:37 -0400562 switch (sap->sa_family) {
563 case AF_INET: {
564 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
Harvey Harrisonbe859402008-10-31 00:56:28 -0700565 seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400566 break;
567 }
568 case AF_INET6: {
569 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
Chuck Leverd250e192009-12-03 15:58:56 -0500570 seq_printf(m, ",mountaddr=%pI6c", &sin6->sin6_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400571 break;
572 }
573 default:
574 if (showdefaults)
575 seq_printf(m, ",mountaddr=unspecified");
576 }
577
578 if (nfss->mountd_version || showdefaults)
579 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
Stanislav Kinsburskyaa699472010-12-08 12:40:13 +0300580 if ((nfss->mountd_port &&
581 nfss->mountd_port != (unsigned short)NFS_UNSPEC_PORT) ||
582 showdefaults)
Chuck Lever82d101d2008-03-14 14:10:37 -0400583 seq_printf(m, ",mountport=%u", nfss->mountd_port);
584
Jeff Laytonee671b02009-12-03 15:58:56 -0500585 nfs_show_mountd_netid(m, nfss, showdefaults);
Chuck Lever82d101d2008-03-14 14:10:37 -0400586}
587
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400588#if IS_ENABLED(CONFIG_NFS_V4)
Trond Myklebust0be81892010-06-18 12:23:58 -0400589static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
590 int showdefaults)
591{
592 struct nfs_client *clp = nfss->nfs_client;
593
594 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
Trond Myklebust0be81892010-06-18 12:23:58 -0400595}
596#else
597static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
598 int showdefaults)
599{
600}
601#endif
602
Trond Myklebust7bbceb62012-03-02 14:00:20 -0500603static void nfs_show_nfs_version(struct seq_file *m,
604 unsigned int version,
605 unsigned int minorversion)
606{
607 seq_printf(m, ",vers=%u", version);
608 if (version == 4)
609 seq_printf(m, ".%u", minorversion);
610}
611
David Howellsf7b422b2006-06-09 09:34:33 -0400612/*
613 * Describe the mount options in force on this server representation
614 */
Chuck Lever82d101d2008-03-14 14:10:37 -0400615static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
616 int showdefaults)
David Howellsf7b422b2006-06-09 09:34:33 -0400617{
David Howells509de812006-08-22 20:06:11 -0400618 static const struct proc_nfs_info {
David Howellsf7b422b2006-06-09 09:34:33 -0400619 int flag;
David Howells509de812006-08-22 20:06:11 -0400620 const char *str;
621 const char *nostr;
David Howellsf7b422b2006-06-09 09:34:33 -0400622 } nfs_info[] = {
623 { NFS_MOUNT_SOFT, ",soft", ",hard" },
Chuck Lever82d101d2008-03-14 14:10:37 -0400624 { NFS_MOUNT_POSIX, ",posix", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400625 { NFS_MOUNT_NOCTO, ",nocto", "" },
626 { NFS_MOUNT_NOAC, ",noac", "" },
627 { NFS_MOUNT_NONLM, ",nolock", "" },
628 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400629 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
Chuck Leverd7403512008-12-23 15:21:37 -0500630 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
631 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400632 { 0, NULL, NULL }
633 };
David Howells509de812006-08-22 20:06:11 -0400634 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400635 struct nfs_client *clp = nfss->nfs_client;
Chuck Lever82d101d2008-03-14 14:10:37 -0400636 u32 version = clp->rpc_ops->version;
Suresh Jayaraman7c563cc2010-09-23 14:26:48 -0400637 int local_flock, local_fcntl;
David Howellsf7b422b2006-06-09 09:34:33 -0400638
Trond Myklebust7bbceb62012-03-02 14:00:20 -0500639 nfs_show_nfs_version(m, version, clp->cl_minorversion);
Chuck Lever2d767432008-03-14 14:10:08 -0400640 seq_printf(m, ",rsize=%u", nfss->rsize);
641 seq_printf(m, ",wsize=%u", nfss->wsize);
Chuck Lever82d101d2008-03-14 14:10:37 -0400642 if (nfss->bsize != 0)
643 seq_printf(m, ",bsize=%u", nfss->bsize);
644 seq_printf(m, ",namlen=%u", nfss->namelen);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400645 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400646 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400647 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400648 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400649 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400650 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400651 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400652 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
David Howellsf7b422b2006-06-09 09:34:33 -0400653 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
654 if (nfss->flags & nfs_infop->flag)
655 seq_puts(m, nfs_infop->str);
656 else
657 seq_puts(m, nfs_infop->nostr);
658 }
Trond Myklebust2446ab62012-03-01 17:00:56 -0500659 rcu_read_lock();
\"Talpey, Thomas\56928ed2007-09-10 13:48:47 -0400660 seq_printf(m, ",proto=%s",
Jeff Laytonee671b02009-12-03 15:58:56 -0500661 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
Trond Myklebust2446ab62012-03-01 17:00:56 -0500662 rcu_read_unlock();
Chuck Lever82d101d2008-03-14 14:10:37 -0400663 if (version == 4) {
664 if (nfss->port != NFS_PORT)
665 seq_printf(m, ",port=%u", nfss->port);
666 } else
667 if (nfss->port)
668 seq_printf(m, ",port=%u", nfss->port);
669
Trond Myklebust33170232007-12-20 16:03:59 -0500670 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
671 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
Trond Myklebust81039f12006-06-09 09:34:34 -0400672 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
Chuck Lever82d101d2008-03-14 14:10:37 -0400673
674 if (version != 4)
675 nfs_show_mountd_options(m, nfss, showdefaults);
Trond Myklebust0be81892010-06-18 12:23:58 -0400676 else
677 nfs_show_nfsv4_options(m, nfss, showdefaults);
Chuck Lever82d101d2008-03-14 14:10:37 -0400678
David Howellsb797cac2009-04-03 16:42:48 +0100679 if (nfss->options & NFS_OPTION_FSCACHE)
680 seq_printf(m, ",fsc");
Patrick J. LoPresti9b00c642010-08-10 17:28:01 -0400681
Chuck Lever89652612012-09-14 17:24:11 -0400682 if (nfss->options & NFS_OPTION_MIGRATION)
683 seq_printf(m, ",migration");
684
Patrick J. LoPresti9b00c642010-08-10 17:28:01 -0400685 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONEG) {
686 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONE)
687 seq_printf(m, ",lookupcache=none");
688 else
689 seq_printf(m, ",lookupcache=pos");
690 }
Suresh Jayaraman7c563cc2010-09-23 14:26:48 -0400691
692 local_flock = nfss->flags & NFS_MOUNT_LOCAL_FLOCK;
693 local_fcntl = nfss->flags & NFS_MOUNT_LOCAL_FCNTL;
694
695 if (!local_flock && !local_fcntl)
696 seq_printf(m, ",local_lock=none");
697 else if (local_flock && local_fcntl)
698 seq_printf(m, ",local_lock=all");
699 else if (local_flock)
700 seq_printf(m, ",local_lock=flock");
701 else
702 seq_printf(m, ",local_lock=posix");
David Howellsf7b422b2006-06-09 09:34:33 -0400703}
704
705/*
706 * Describe the mount options on this VFS mountpoint
707 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -0400708int nfs_show_options(struct seq_file *m, struct dentry *root)
David Howellsf7b422b2006-06-09 09:34:33 -0400709{
Al Viro34c80b12011-12-08 21:32:45 -0500710 struct nfs_server *nfss = NFS_SB(root->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400711
712 nfs_show_mount_options(m, nfss, 0);
713
Trond Myklebust2446ab62012-03-01 17:00:56 -0500714 rcu_read_lock();
Chuck Lever5d8515c2007-12-10 14:57:16 -0500715 seq_printf(m, ",addr=%s",
716 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
717 RPC_DISPLAY_ADDR));
Trond Myklebust2446ab62012-03-01 17:00:56 -0500718 rcu_read_unlock();
David Howellsf7b422b2006-06-09 09:34:33 -0400719
720 return 0;
721}
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400722EXPORT_SYMBOL_GPL(nfs_show_options);
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700723
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400724#if IS_ENABLED(CONFIG_NFS_V4)
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300725#ifdef CONFIG_NFS_V4_1
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700726static void show_sessions(struct seq_file *m, struct nfs_server *server)
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300727{
728 if (nfs4_has_session(server->nfs_client))
729 seq_printf(m, ",sessions");
730}
731#else
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700732static void show_sessions(struct seq_file *m, struct nfs_server *server) {}
733#endif
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300734#endif
735
736#ifdef CONFIG_NFS_V4_1
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700737static void show_pnfs(struct seq_file *m, struct nfs_server *server)
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300738{
739 seq_printf(m, ",pnfs=");
740 if (server->pnfs_curr_ld)
741 seq_printf(m, "%s", server->pnfs_curr_ld->name);
742 else
743 seq_printf(m, "not configured");
744}
Trond Myklebust7e03b7c2012-03-04 18:12:57 -0500745
746static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
747{
Chuck Lever59155542012-05-21 22:44:41 -0400748 if (nfss->nfs_client && nfss->nfs_client->cl_implid) {
749 struct nfs41_impl_id *impl_id = nfss->nfs_client->cl_implid;
Trond Myklebust7e03b7c2012-03-04 18:12:57 -0500750 seq_printf(m, "\n\timpl_id:\tname='%s',domain='%s',"
751 "date='%llu,%u'",
752 impl_id->name, impl_id->domain,
753 impl_id->date.seconds, impl_id->date.nseconds);
754 }
755}
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700756#else
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400757#if IS_ENABLED(CONFIG_NFS_V4)
Trond Myklebust7e03b7c2012-03-04 18:12:57 -0500758static void show_pnfs(struct seq_file *m, struct nfs_server *server)
759{
760}
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700761#endif
Trond Myklebust7e03b7c2012-03-04 18:12:57 -0500762static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
763{
764}
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700765#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400766
Bryan Schumakerfbdefd62012-07-16 16:39:20 -0400767int nfs_show_devname(struct seq_file *m, struct dentry *root)
Al Viroc7f404b2011-03-16 06:59:40 -0400768{
769 char *page = (char *) __get_free_page(GFP_KERNEL);
770 char *devname, *dummy;
771 int err = 0;
772 if (!page)
773 return -ENOMEM;
Ben Hutchings97a54862012-10-21 19:23:52 +0100774 devname = nfs_path(&dummy, root, page, PAGE_SIZE, 0);
Al Viroc7f404b2011-03-16 06:59:40 -0400775 if (IS_ERR(devname))
776 err = PTR_ERR(devname);
777 else
778 seq_escape(m, devname, " \t\n\\");
779 free_page((unsigned long)page);
780 return err;
781}
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400782EXPORT_SYMBOL_GPL(nfs_show_devname);
Al Viroc7f404b2011-03-16 06:59:40 -0400783
Bryan Schumakerfbdefd62012-07-16 16:39:20 -0400784int nfs_show_path(struct seq_file *m, struct dentry *dentry)
Al Viroc7f404b2011-03-16 06:59:40 -0400785{
786 seq_puts(m, "/");
787 return 0;
788}
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400789EXPORT_SYMBOL_GPL(nfs_show_path);
Al Viroc7f404b2011-03-16 06:59:40 -0400790
David Howellsf7b422b2006-06-09 09:34:33 -0400791/*
792 * Present statistical information for this VFS mountpoint
793 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -0400794int nfs_show_stats(struct seq_file *m, struct dentry *root)
David Howellsf7b422b2006-06-09 09:34:33 -0400795{
796 int i, cpu;
Al Viro64132372011-12-08 20:51:13 -0500797 struct nfs_server *nfss = NFS_SB(root->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400798 struct rpc_auth *auth = nfss->client->cl_auth;
799 struct nfs_iostats totals = { };
800
801 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
802
803 /*
804 * Display all mount option settings
805 */
806 seq_printf(m, "\n\topts:\t");
Al Viro64132372011-12-08 20:51:13 -0500807 seq_puts(m, root->d_sb->s_flags & MS_RDONLY ? "ro" : "rw");
808 seq_puts(m, root->d_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
809 seq_puts(m, root->d_sb->s_flags & MS_NOATIME ? ",noatime" : "");
810 seq_puts(m, root->d_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
David Howellsf7b422b2006-06-09 09:34:33 -0400811 nfs_show_mount_options(m, nfss, 1);
812
813 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
814
Trond Myklebust7e03b7c2012-03-04 18:12:57 -0500815 show_implementation_id(m, nfss);
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500816
David Howellsf7b422b2006-06-09 09:34:33 -0400817 seq_printf(m, "\n\tcaps:\t");
818 seq_printf(m, "caps=0x%x", nfss->caps);
Chuck Lever2d767432008-03-14 14:10:08 -0400819 seq_printf(m, ",wtmult=%u", nfss->wtmult);
820 seq_printf(m, ",dtsize=%u", nfss->dtsize);
821 seq_printf(m, ",bsize=%u", nfss->bsize);
822 seq_printf(m, ",namlen=%u", nfss->namelen);
David Howellsf7b422b2006-06-09 09:34:33 -0400823
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400824#if IS_ENABLED(CONFIG_NFS_V4)
Trond Myklebust40c553192007-12-14 14:56:07 -0500825 if (nfss->nfs_client->rpc_ops->version == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400826 seq_printf(m, "\n\tnfsv4:\t");
827 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
828 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
829 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300830 show_sessions(m, nfss);
831 show_pnfs(m, nfss);
David Howellsf7b422b2006-06-09 09:34:33 -0400832 }
833#endif
834
835 /*
836 * Display security flavor in effect for this mount
837 */
Chuck Lever2d767432008-03-14 14:10:08 -0400838 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400839 if (auth->au_flavor)
Chuck Lever2d767432008-03-14 14:10:08 -0400840 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400841
842 /*
843 * Display superblock I/O counters
844 */
845 for_each_possible_cpu(cpu) {
846 struct nfs_iostats *stats;
847
848 preempt_disable();
849 stats = per_cpu_ptr(nfss->io_stats, cpu);
850
851 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
852 totals.events[i] += stats->events[i];
853 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
854 totals.bytes[i] += stats->bytes[i];
David Howells6a510912009-04-03 16:42:43 +0100855#ifdef CONFIG_NFS_FSCACHE
856 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
857 totals.fscache[i] += stats->fscache[i];
858#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400859
860 preempt_enable();
861 }
862
863 seq_printf(m, "\n\tevents:\t");
864 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
865 seq_printf(m, "%lu ", totals.events[i]);
866 seq_printf(m, "\n\tbytes:\t");
867 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
868 seq_printf(m, "%Lu ", totals.bytes[i]);
David Howells6a510912009-04-03 16:42:43 +0100869#ifdef CONFIG_NFS_FSCACHE
870 if (nfss->options & NFS_OPTION_FSCACHE) {
871 seq_printf(m, "\n\tfsc:\t");
872 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
873 seq_printf(m, "%Lu ", totals.bytes[i]);
874 }
875#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400876 seq_printf(m, "\n");
877
878 rpc_print_iostats(m, nfss->client);
879
880 return 0;
881}
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400882EXPORT_SYMBOL_GPL(nfs_show_stats);
David Howellsf7b422b2006-06-09 09:34:33 -0400883
884/*
885 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400886 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400887 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -0400888void nfs_umount_begin(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -0400889{
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200890 struct nfs_server *server;
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400891 struct rpc_clnt *rpc;
892
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200893 server = NFS_SB(sb);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400894 /* -EIO all pending I/O */
895 rpc = server->client_acl;
896 if (!IS_ERR(rpc))
897 rpc_killall_tasks(rpc);
898 rpc = server->client;
899 if (!IS_ERR(rpc))
900 rpc_killall_tasks(rpc);
David Howellsf7b422b2006-06-09 09:34:33 -0400901}
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400902EXPORT_SYMBOL_GPL(nfs_umount_begin);
David Howellsf7b422b2006-06-09 09:34:33 -0400903
Bryan Schumakerdb833352012-05-10 15:07:38 -0400904static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(void)
Chuck Lever9423a082009-09-23 14:36:38 -0400905{
906 struct nfs_parsed_mount_data *data;
907
908 data = kzalloc(sizeof(*data), GFP_KERNEL);
909 if (data) {
Chuck Lever9423a082009-09-23 14:36:38 -0400910 data->acregmin = NFS_DEF_ACREGMIN;
911 data->acregmax = NFS_DEF_ACREGMAX;
912 data->acdirmin = NFS_DEF_ACDIRMIN;
913 data->acdirmax = NFS_DEF_ACDIRMAX;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400914 data->mount_server.port = NFS_UNSPEC_PORT;
Chuck Lever9423a082009-09-23 14:36:38 -0400915 data->nfs_server.port = NFS_UNSPEC_PORT;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400916 data->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Lever9423a082009-09-23 14:36:38 -0400917 data->auth_flavors[0] = RPC_AUTH_UNIX;
918 data->auth_flavor_len = 1;
919 data->minorversion = 0;
Bryan Schumakerb72e4f42012-05-10 15:07:40 -0400920 data->need_mount = true;
Trond Myklebust9937347a2012-02-19 08:44:07 +0100921 data->net = current->nsproxy->net_ns;
Jeff Layton8a0d5512011-12-20 06:57:45 -0500922 security_init_mnt_opts(&data->lsm_opts);
Chuck Lever9423a082009-09-23 14:36:38 -0400923 }
924 return data;
925}
926
Jeff Layton8a0d5512011-12-20 06:57:45 -0500927static void nfs_free_parsed_mount_data(struct nfs_parsed_mount_data *data)
928{
929 if (data) {
930 kfree(data->client_address);
931 kfree(data->mount_server.hostname);
932 kfree(data->nfs_server.export_path);
933 kfree(data->nfs_server.hostname);
934 kfree(data->fscache_uniq);
935 security_free_mnt_opts(&data->lsm_opts);
936 kfree(data);
937 }
938}
939
David Howellsf7b422b2006-06-09 09:34:33 -0400940/*
Chuck Levercdcd7f92007-12-10 14:57:45 -0500941 * Sanity-check a server address provided by the mount command.
942 *
943 * Address family must be initialized, and address must not be
944 * the ANY address for that family.
Chuck Leverfc50d582007-07-01 12:12:46 -0400945 */
946static int nfs_verify_server_address(struct sockaddr *addr)
947{
948 switch (addr->sa_family) {
949 case AF_INET: {
Chuck Levercdcd7f92007-12-10 14:57:45 -0500950 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
Al Viroe6f1ceb2008-03-17 22:44:53 -0700951 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
Chuck Levercdcd7f92007-12-10 14:57:45 -0500952 }
953 case AF_INET6: {
954 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
955 return !ipv6_addr_any(sa);
Chuck Leverfc50d582007-07-01 12:12:46 -0400956 }
957 }
958
Chuck Lever53a0b9c2009-08-09 15:09:36 -0400959 dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
Chuck Leverfc50d582007-07-01 12:12:46 -0400960 return 0;
961}
962
Chuck Lever9412b922007-12-10 14:59:21 -0500963/*
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400964 * Select between a default port value and a user-specified port value.
965 * If a zero value is set, then autobind will be used.
966 */
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400967static void nfs_set_port(struct sockaddr *sap, int *port,
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400968 const unsigned short default_port)
969{
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400970 if (*port == NFS_UNSPEC_PORT)
971 *port = default_port;
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400972
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400973 rpc_set_port(sap, *port);
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400974}
975
976/*
Trond Myklebust259875e2008-07-02 14:43:47 -0400977 * Sanity check the NFS transport protocol.
978 *
979 */
980static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
981{
982 switch (mnt->nfs_server.protocol) {
983 case XPRT_TRANSPORT_UDP:
984 case XPRT_TRANSPORT_TCP:
985 case XPRT_TRANSPORT_RDMA:
986 break;
987 default:
988 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
989 }
990}
991
992/*
993 * For text based NFSv2/v3 mounts, the mount protocol transport default
994 * settings should depend upon the specified NFS transport.
995 */
996static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
997{
998 nfs_validate_transport_protocol(mnt);
999
1000 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
1001 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
1002 return;
1003 switch (mnt->nfs_server.protocol) {
1004 case XPRT_TRANSPORT_UDP:
1005 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
1006 break;
1007 case XPRT_TRANSPORT_TCP:
1008 case XPRT_TRANSPORT_RDMA:
1009 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
1010 }
1011}
1012
1013/*
Chuck Lever01060c82008-06-24 16:33:38 -04001014 * Parse the value of the 'sec=' option.
Chuck Lever01060c82008-06-24 16:33:38 -04001015 */
1016static int nfs_parse_security_flavors(char *value,
1017 struct nfs_parsed_mount_data *mnt)
1018{
1019 substring_t args[MAX_OPT_ARGS];
1020
1021 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
1022
1023 switch (match_token(value, nfs_secflavor_tokens, args)) {
1024 case Opt_sec_none:
Chuck Lever01060c82008-06-24 16:33:38 -04001025 mnt->auth_flavors[0] = RPC_AUTH_NULL;
1026 break;
1027 case Opt_sec_sys:
Chuck Lever01060c82008-06-24 16:33:38 -04001028 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
1029 break;
1030 case Opt_sec_krb5:
Chuck Lever01060c82008-06-24 16:33:38 -04001031 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
1032 break;
1033 case Opt_sec_krb5i:
Chuck Lever01060c82008-06-24 16:33:38 -04001034 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
1035 break;
1036 case Opt_sec_krb5p:
Chuck Lever01060c82008-06-24 16:33:38 -04001037 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
1038 break;
1039 case Opt_sec_lkey:
Chuck Lever01060c82008-06-24 16:33:38 -04001040 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
1041 break;
1042 case Opt_sec_lkeyi:
Chuck Lever01060c82008-06-24 16:33:38 -04001043 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
1044 break;
1045 case Opt_sec_lkeyp:
Chuck Lever01060c82008-06-24 16:33:38 -04001046 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
1047 break;
1048 case Opt_sec_spkm:
Chuck Lever01060c82008-06-24 16:33:38 -04001049 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
1050 break;
1051 case Opt_sec_spkmi:
Chuck Lever01060c82008-06-24 16:33:38 -04001052 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
1053 break;
1054 case Opt_sec_spkmp:
Chuck Lever01060c82008-06-24 16:33:38 -04001055 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
1056 break;
1057 default:
1058 return 0;
1059 }
1060
Bryan Schumaker9b7160c2011-04-13 14:31:30 -04001061 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
Chuck Lever059f90b2009-08-09 15:09:31 -04001062 mnt->auth_flavor_len = 1;
Chuck Lever01060c82008-06-24 16:33:38 -04001063 return 1;
1064}
1065
Trond Myklebust0d71b052012-03-02 13:59:49 -05001066static int nfs_parse_version_string(char *string,
1067 struct nfs_parsed_mount_data *mnt,
1068 substring_t *args)
1069{
1070 mnt->flags &= ~NFS_MOUNT_VER3;
1071 switch (match_token(string, nfs_vers_tokens, args)) {
1072 case Opt_vers_2:
1073 mnt->version = 2;
1074 break;
1075 case Opt_vers_3:
1076 mnt->flags |= NFS_MOUNT_VER3;
1077 mnt->version = 3;
1078 break;
1079 case Opt_vers_4:
1080 /* Backward compatibility option. In future,
1081 * the mount program should always supply
1082 * a NFSv4 minor version number.
1083 */
1084 mnt->version = 4;
1085 break;
1086 case Opt_vers_4_0:
1087 mnt->version = 4;
1088 mnt->minorversion = 0;
1089 break;
1090 case Opt_vers_4_1:
1091 mnt->version = 4;
1092 mnt->minorversion = 1;
1093 break;
1094 default:
1095 return 0;
1096 }
1097 return 1;
1098}
1099
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001100static int nfs_get_option_str(substring_t args[], char **option)
1101{
1102 kfree(*option);
1103 *option = match_strdup(args);
1104 return !option;
1105}
1106
1107static int nfs_get_option_ul(substring_t args[], unsigned long *option)
1108{
1109 int rc;
1110 char *string;
1111
1112 string = match_strdup(args);
1113 if (string == NULL)
1114 return -ENOMEM;
Daniel Walter7297cb62012-09-26 21:51:46 +02001115 rc = kstrtoul(string, 10, option);
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001116 kfree(string);
1117
1118 return rc;
1119}
1120
Chuck Lever01060c82008-06-24 16:33:38 -04001121/*
Chuck Leverbf0fd762007-07-01 12:13:44 -04001122 * Error-check and convert a string of mount options from user space into
Chuck Leverf45663c2008-06-24 19:28:02 -04001123 * a data structure. The whole mount string is processed; bad options are
1124 * skipped as they are encountered. If there were no errors, return 1;
1125 * otherwise return 0 (zero).
Chuck Leverbf0fd762007-07-01 12:13:44 -04001126 */
1127static int nfs_parse_mount_options(char *raw,
1128 struct nfs_parsed_mount_data *mnt)
1129{
Eric Parisf9c3a382008-03-05 14:20:18 -05001130 char *p, *string, *secdata;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001131 int rc, sloppy = 0, invalid_option = 0;
Jeff Laytonee671b02009-12-03 15:58:56 -05001132 unsigned short protofamily = AF_UNSPEC;
1133 unsigned short mountfamily = AF_UNSPEC;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001134
1135 if (!raw) {
1136 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
1137 return 1;
1138 }
1139 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
1140
Eric Parisf9c3a382008-03-05 14:20:18 -05001141 secdata = alloc_secdata();
1142 if (!secdata)
1143 goto out_nomem;
1144
1145 rc = security_sb_copy_data(raw, secdata);
1146 if (rc)
1147 goto out_security_failure;
1148
1149 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
1150 if (rc)
1151 goto out_security_failure;
1152
1153 free_secdata(secdata);
1154
Chuck Leverbf0fd762007-07-01 12:13:44 -04001155 while ((p = strsep(&raw, ",")) != NULL) {
1156 substring_t args[MAX_OPT_ARGS];
Chuck Levera5a16ba2009-06-17 18:02:14 -07001157 unsigned long option;
1158 int token;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001159
1160 if (!*p)
1161 continue;
1162
1163 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
1164
1165 token = match_token(p, nfs_mount_option_tokens, args);
1166 switch (token) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001167
1168 /*
1169 * boolean options: foo/nofoo
1170 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001171 case Opt_soft:
1172 mnt->flags |= NFS_MOUNT_SOFT;
1173 break;
1174 case Opt_hard:
1175 mnt->flags &= ~NFS_MOUNT_SOFT;
1176 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001177 case Opt_posix:
1178 mnt->flags |= NFS_MOUNT_POSIX;
1179 break;
1180 case Opt_noposix:
1181 mnt->flags &= ~NFS_MOUNT_POSIX;
1182 break;
1183 case Opt_cto:
1184 mnt->flags &= ~NFS_MOUNT_NOCTO;
1185 break;
1186 case Opt_nocto:
1187 mnt->flags |= NFS_MOUNT_NOCTO;
1188 break;
1189 case Opt_ac:
1190 mnt->flags &= ~NFS_MOUNT_NOAC;
1191 break;
1192 case Opt_noac:
1193 mnt->flags |= NFS_MOUNT_NOAC;
1194 break;
1195 case Opt_lock:
1196 mnt->flags &= ~NFS_MOUNT_NONLM;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001197 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1198 NFS_MOUNT_LOCAL_FCNTL);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001199 break;
1200 case Opt_nolock:
1201 mnt->flags |= NFS_MOUNT_NONLM;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001202 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1203 NFS_MOUNT_LOCAL_FCNTL);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001204 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001205 case Opt_udp:
1206 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001207 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001208 break;
1209 case Opt_tcp:
1210 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001211 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001212 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001213 case Opt_rdma:
1214 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1215 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001216 xprt_load_transport(p);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001217 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001218 case Opt_acl:
1219 mnt->flags &= ~NFS_MOUNT_NOACL;
1220 break;
1221 case Opt_noacl:
1222 mnt->flags |= NFS_MOUNT_NOACL;
1223 break;
1224 case Opt_rdirplus:
1225 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1226 break;
1227 case Opt_nordirplus:
1228 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1229 break;
Trond Myklebust75180df2007-05-16 16:53:28 -04001230 case Opt_sharecache:
1231 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1232 break;
1233 case Opt_nosharecache:
1234 mnt->flags |= NFS_MOUNT_UNSHARED;
1235 break;
Chuck Leverd7403512008-12-23 15:21:37 -05001236 case Opt_resvport:
1237 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1238 break;
1239 case Opt_noresvport:
1240 mnt->flags |= NFS_MOUNT_NORESVPORT;
1241 break;
David Howellsb797cac2009-04-03 16:42:48 +01001242 case Opt_fscache:
1243 mnt->options |= NFS_OPTION_FSCACHE;
1244 kfree(mnt->fscache_uniq);
1245 mnt->fscache_uniq = NULL;
1246 break;
1247 case Opt_nofscache:
1248 mnt->options &= ~NFS_OPTION_FSCACHE;
1249 kfree(mnt->fscache_uniq);
1250 mnt->fscache_uniq = NULL;
1251 break;
Chuck Lever89652612012-09-14 17:24:11 -04001252 case Opt_migration:
1253 mnt->options |= NFS_OPTION_MIGRATION;
1254 break;
1255 case Opt_nomigration:
1256 mnt->options &= NFS_OPTION_MIGRATION;
1257 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001258
Chuck Leverf45663c2008-06-24 19:28:02 -04001259 /*
1260 * options that take numeric values
1261 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001262 case Opt_port:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001263 if (nfs_get_option_ul(args, &option) ||
1264 option > USHRT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001265 goto out_invalid_value;
1266 mnt->nfs_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001267 break;
1268 case Opt_rsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001269 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001270 goto out_invalid_value;
1271 mnt->rsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001272 break;
1273 case Opt_wsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001274 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001275 goto out_invalid_value;
1276 mnt->wsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001277 break;
1278 case Opt_bsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001279 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001280 goto out_invalid_value;
1281 mnt->bsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001282 break;
1283 case Opt_timeo:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001284 if (nfs_get_option_ul(args, &option) || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001285 goto out_invalid_value;
1286 mnt->timeo = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001287 break;
1288 case Opt_retrans:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001289 if (nfs_get_option_ul(args, &option) || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001290 goto out_invalid_value;
1291 mnt->retrans = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001292 break;
1293 case Opt_acregmin:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001294 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001295 goto out_invalid_value;
1296 mnt->acregmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001297 break;
1298 case Opt_acregmax:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001299 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001300 goto out_invalid_value;
1301 mnt->acregmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001302 break;
1303 case Opt_acdirmin:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001304 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001305 goto out_invalid_value;
1306 mnt->acdirmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001307 break;
1308 case Opt_acdirmax:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001309 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001310 goto out_invalid_value;
1311 mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001312 break;
1313 case Opt_actimeo:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001314 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001315 goto out_invalid_value;
1316 mnt->acregmin = mnt->acregmax =
1317 mnt->acdirmin = mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001318 break;
1319 case Opt_namelen:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001320 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001321 goto out_invalid_value;
1322 mnt->namlen = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001323 break;
1324 case Opt_mountport:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001325 if (nfs_get_option_ul(args, &option) ||
1326 option > USHRT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001327 goto out_invalid_value;
1328 mnt->mount_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001329 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001330 case Opt_mountvers:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001331 if (nfs_get_option_ul(args, &option) ||
Chuck Leverf45663c2008-06-24 19:28:02 -04001332 option < NFS_MNT_VERSION ||
Chuck Leverd23c45f2009-06-17 18:02:13 -07001333 option > NFS_MNT3_VERSION)
1334 goto out_invalid_value;
1335 mnt->mount_server.version = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001336 break;
Mike Sager3fd5be92009-04-01 09:21:48 -04001337 case Opt_minorversion:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001338 if (nfs_get_option_ul(args, &option))
Chuck Leverf3f4f4e2009-08-09 15:09:29 -04001339 goto out_invalid_value;
1340 if (option > NFS4_MAX_MINOR_VERSION)
1341 goto out_invalid_value;
1342 mnt->minorversion = option;
Mike Sager3fd5be92009-04-01 09:21:48 -04001343 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001344
Chuck Leverf45663c2008-06-24 19:28:02 -04001345 /*
1346 * options that take text values
1347 */
Trond Myklebust0d71b052012-03-02 13:59:49 -05001348 case Opt_nfsvers:
1349 string = match_strdup(args);
1350 if (string == NULL)
1351 goto out_nomem;
1352 rc = nfs_parse_version_string(string, mnt, args);
1353 kfree(string);
1354 if (!rc)
1355 goto out_invalid_value;
1356 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001357 case Opt_sec:
1358 string = match_strdup(args);
1359 if (string == NULL)
1360 goto out_nomem;
Chuck Lever01060c82008-06-24 16:33:38 -04001361 rc = nfs_parse_security_flavors(string, mnt);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001362 kfree(string);
Chuck Leverf45663c2008-06-24 19:28:02 -04001363 if (!rc) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001364 dfprintk(MOUNT, "NFS: unrecognized "
1365 "security flavor\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001366 return 0;
Chuck Leverf45663c2008-06-24 19:28:02 -04001367 }
Chuck Leverbf0fd762007-07-01 12:13:44 -04001368 break;
1369 case Opt_proto:
1370 string = match_strdup(args);
1371 if (string == NULL)
1372 goto out_nomem;
1373 token = match_token(string,
1374 nfs_xprt_protocol_tokens, args);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001375
Jeff Laytonee671b02009-12-03 15:58:56 -05001376 protofamily = AF_INET;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001377 switch (token) {
Jeff Laytonee671b02009-12-03 15:58:56 -05001378 case Opt_xprt_udp6:
1379 protofamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001380 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001381 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001382 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001383 break;
Jeff Laytonee671b02009-12-03 15:58:56 -05001384 case Opt_xprt_tcp6:
1385 protofamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001386 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001387 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001388 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001389 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001390 case Opt_xprt_rdma:
1391 /* vector side protocols to TCP */
1392 mnt->flags |= NFS_MOUNT_TCP;
1393 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001394 xprt_load_transport(string);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001395 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001396 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001397 dfprintk(MOUNT, "NFS: unrecognized "
1398 "transport protocol\n");
Yinghai Lu4223a4a2009-10-20 14:13:46 +09001399 kfree(string);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001400 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001401 }
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001402 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001403 break;
1404 case Opt_mountproto:
1405 string = match_strdup(args);
1406 if (string == NULL)
1407 goto out_nomem;
1408 token = match_token(string,
1409 nfs_xprt_protocol_tokens, args);
Trond Myklebustd508afb2009-04-06 16:41:35 -07001410 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001411
Jeff Laytonee671b02009-12-03 15:58:56 -05001412 mountfamily = AF_INET;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001413 switch (token) {
Jeff Laytonee671b02009-12-03 15:58:56 -05001414 case Opt_xprt_udp6:
1415 mountfamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001416 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001417 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001418 break;
Jeff Laytonee671b02009-12-03 15:58:56 -05001419 case Opt_xprt_tcp6:
1420 mountfamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001421 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001422 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001423 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001424 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001425 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001426 dfprintk(MOUNT, "NFS: unrecognized "
1427 "transport protocol\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001428 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001429 }
1430 break;
1431 case Opt_addr:
1432 string = match_strdup(args);
1433 if (string == NULL)
1434 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001435 mnt->nfs_server.addrlen =
Stanislav Kinsburskyb48e1272012-01-26 15:11:57 +04001436 rpc_pton(mnt->net, string, strlen(string),
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001437 (struct sockaddr *)
1438 &mnt->nfs_server.address,
1439 sizeof(mnt->nfs_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001440 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001441 if (mnt->nfs_server.addrlen == 0)
1442 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001443 break;
1444 case Opt_clientaddr:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001445 if (nfs_get_option_str(args, &mnt->client_address))
Chuck Leverbf0fd762007-07-01 12:13:44 -04001446 goto out_nomem;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001447 break;
Chuck Lever33832032007-12-10 14:59:13 -05001448 case Opt_mounthost:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001449 if (nfs_get_option_str(args,
1450 &mnt->mount_server.hostname))
Chuck Lever33832032007-12-10 14:59:13 -05001451 goto out_nomem;
Chuck Lever33832032007-12-10 14:59:13 -05001452 break;
Chuck Lever0ac83772007-09-11 18:01:04 -04001453 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001454 string = match_strdup(args);
1455 if (string == NULL)
1456 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001457 mnt->mount_server.addrlen =
Stanislav Kinsburskyb48e1272012-01-26 15:11:57 +04001458 rpc_pton(mnt->net, string, strlen(string),
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001459 (struct sockaddr *)
1460 &mnt->mount_server.address,
1461 sizeof(mnt->mount_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001462 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001463 if (mnt->mount_server.addrlen == 0)
1464 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001465 break;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001466 case Opt_lookupcache:
1467 string = match_strdup(args);
1468 if (string == NULL)
1469 goto out_nomem;
1470 token = match_token(string,
1471 nfs_lookupcache_tokens, args);
1472 kfree(string);
1473 switch (token) {
1474 case Opt_lookupcache_all:
1475 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1476 break;
1477 case Opt_lookupcache_positive:
1478 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1479 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1480 break;
1481 case Opt_lookupcache_none:
1482 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1483 break;
1484 default:
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001485 dfprintk(MOUNT, "NFS: invalid "
1486 "lookupcache argument\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001487 return 0;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001488 };
1489 break;
Chuck Levera6d5ff62010-05-07 13:33:58 -04001490 case Opt_fscache_uniq:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001491 if (nfs_get_option_str(args, &mnt->fscache_uniq))
Chuck Levera6d5ff62010-05-07 13:33:58 -04001492 goto out_nomem;
Chuck Levera6d5ff62010-05-07 13:33:58 -04001493 mnt->options |= NFS_OPTION_FSCACHE;
1494 break;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001495 case Opt_local_lock:
1496 string = match_strdup(args);
1497 if (string == NULL)
1498 goto out_nomem;
1499 token = match_token(string, nfs_local_lock_tokens,
1500 args);
1501 kfree(string);
1502 switch (token) {
1503 case Opt_local_lock_all:
1504 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1505 NFS_MOUNT_LOCAL_FCNTL);
1506 break;
1507 case Opt_local_lock_flock:
1508 mnt->flags |= NFS_MOUNT_LOCAL_FLOCK;
1509 break;
1510 case Opt_local_lock_posix:
1511 mnt->flags |= NFS_MOUNT_LOCAL_FCNTL;
1512 break;
1513 case Opt_local_lock_none:
1514 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1515 NFS_MOUNT_LOCAL_FCNTL);
1516 break;
1517 default:
1518 dfprintk(MOUNT, "NFS: invalid "
1519 "local_lock argument\n");
1520 return 0;
1521 };
1522 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001523
Chuck Leverf45663c2008-06-24 19:28:02 -04001524 /*
1525 * Special options
1526 */
1527 case Opt_sloppy:
1528 sloppy = 1;
1529 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1530 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001531 case Opt_userspace:
1532 case Opt_deprecated:
Chuck Leverd33e4df2008-06-12 12:37:41 -04001533 dfprintk(MOUNT, "NFS: ignoring mount option "
1534 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001535 break;
1536
1537 default:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001538 invalid_option = 1;
Chuck Leverf45663c2008-06-24 19:28:02 -04001539 dfprintk(MOUNT, "NFS: unrecognized mount option "
1540 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001541 }
1542 }
1543
Chuck Leverd23c45f2009-06-17 18:02:13 -07001544 if (!sloppy && invalid_option)
1545 return 0;
1546
Weston Andros Adamson571b7552012-02-01 14:06:41 -05001547 if (mnt->minorversion && mnt->version != 4)
1548 goto out_minorversion_mismatch;
1549
Chuck Lever89652612012-09-14 17:24:11 -04001550 if (mnt->options & NFS_OPTION_MIGRATION &&
1551 mnt->version != 4 && mnt->minorversion != 0)
1552 goto out_migration_misuse;
1553
Jeff Laytonee671b02009-12-03 15:58:56 -05001554 /*
1555 * verify that any proto=/mountproto= options match the address
Peter Meerwald1856b222012-08-18 17:38:54 +02001556 * families in the addr=/mountaddr= options.
Jeff Laytonee671b02009-12-03 15:58:56 -05001557 */
1558 if (protofamily != AF_UNSPEC &&
1559 protofamily != mnt->nfs_server.address.ss_family)
1560 goto out_proto_mismatch;
1561
1562 if (mountfamily != AF_UNSPEC) {
1563 if (mnt->mount_server.addrlen) {
1564 if (mountfamily != mnt->mount_server.address.ss_family)
1565 goto out_mountproto_mismatch;
1566 } else {
1567 if (mountfamily != mnt->nfs_server.address.ss_family)
1568 goto out_mountproto_mismatch;
1569 }
1570 }
1571
Chuck Leverbf0fd762007-07-01 12:13:44 -04001572 return 1;
1573
Jeff Laytonee671b02009-12-03 15:58:56 -05001574out_mountproto_mismatch:
1575 printk(KERN_INFO "NFS: mount server address does not match mountproto= "
1576 "option\n");
1577 return 0;
1578out_proto_mismatch:
1579 printk(KERN_INFO "NFS: server address does not match proto= option\n");
1580 return 0;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001581out_invalid_address:
1582 printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
1583 return 0;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001584out_invalid_value:
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001585 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001586 return 0;
Weston Andros Adamson571b7552012-02-01 14:06:41 -05001587out_minorversion_mismatch:
1588 printk(KERN_INFO "NFS: mount option vers=%u does not support "
1589 "minorversion=%u\n", mnt->version, mnt->minorversion);
1590 return 0;
Chuck Lever89652612012-09-14 17:24:11 -04001591out_migration_misuse:
1592 printk(KERN_INFO
1593 "NFS: 'migration' not supported for this NFS version\n");
1594 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001595out_nomem:
1596 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1597 return 0;
Eric Parisf9c3a382008-03-05 14:20:18 -05001598out_security_failure:
1599 free_secdata(secdata);
1600 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1601 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001602}
1603
1604/*
Chuck Leverec88f282009-08-09 15:09:32 -04001605 * Match the requested auth flavors with the list returned by
1606 * the server. Returns zero and sets the mount's authentication
1607 * flavor on success; returns -EACCES if server does not support
1608 * the requested flavor.
1609 */
1610static int nfs_walk_authlist(struct nfs_parsed_mount_data *args,
1611 struct nfs_mount_request *request)
1612{
1613 unsigned int i, j, server_authlist_len = *(request->auth_flav_len);
1614
1615 /*
Chuck Lever5eecfde2009-08-21 17:50:30 -04001616 * Certain releases of Linux's mountd return an empty
1617 * flavor list. To prevent behavioral regression with
1618 * these servers (ie. rejecting mounts that used to
1619 * succeed), revert to pre-2.6.32 behavior (no checking)
1620 * if the returned flavor list is empty.
1621 */
1622 if (server_authlist_len == 0)
1623 return 0;
1624
1625 /*
Chuck Leverec88f282009-08-09 15:09:32 -04001626 * We avoid sophisticated negotiating here, as there are
1627 * plenty of cases where we can get it wrong, providing
1628 * either too little or too much security.
1629 *
1630 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1631 * flavor listed first. However, some servers list
1632 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1633 * preferred default, in args->auth_flavors[0] if user
1634 * didn't specify sec= mount option.
1635 */
1636 for (i = 0; i < args->auth_flavor_len; i++)
1637 for (j = 0; j < server_authlist_len; j++)
1638 if (args->auth_flavors[i] == request->auth_flavs[j]) {
1639 dfprintk(MOUNT, "NFS: using auth flavor %d\n",
1640 request->auth_flavs[j]);
1641 args->auth_flavors[0] = request->auth_flavs[j];
1642 return 0;
1643 }
1644
1645 dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n");
1646 nfs_umount(request);
1647 return -EACCES;
1648}
1649
1650/*
Chuck Lever0076d7b2007-07-01 12:13:49 -04001651 * Use the remote server's MOUNT service to request the NFS file handle
1652 * corresponding to the provided path.
1653 */
Bryan Schumaker486aa692012-05-10 15:07:39 -04001654static int nfs_request_mount(struct nfs_parsed_mount_data *args,
1655 struct nfs_fh *root_fh)
Chuck Lever0076d7b2007-07-01 12:13:49 -04001656{
Chuck Leverec88f282009-08-09 15:09:32 -04001657 rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS];
1658 unsigned int server_authlist_len = ARRAY_SIZE(server_authlist);
Chuck Leverc5d120f2008-12-23 15:21:35 -05001659 struct nfs_mount_request request = {
1660 .sap = (struct sockaddr *)
1661 &args->mount_server.address,
1662 .dirpath = args->nfs_server.export_path,
1663 .protocol = args->mount_server.protocol,
1664 .fh = root_fh,
Chuck Lever50a737f2008-12-23 15:21:37 -05001665 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
Chuck Leverec88f282009-08-09 15:09:32 -04001666 .auth_flav_len = &server_authlist_len,
1667 .auth_flavs = server_authlist,
Stanislav Kinsbursky6d59b8d2012-01-10 16:12:54 +04001668 .net = args->net,
Chuck Leverc5d120f2008-12-23 15:21:35 -05001669 };
Chuck Lever4c568012007-12-10 14:59:28 -05001670 int status;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001671
1672 if (args->mount_server.version == 0) {
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001673 switch (args->version) {
1674 default:
1675 args->mount_server.version = NFS_MNT3_VERSION;
1676 break;
1677 case 2:
1678 args->mount_server.version = NFS_MNT_VERSION;
1679 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001680 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001681 request.version = args->mount_server.version;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001682
Chuck Lever33832032007-12-10 14:59:13 -05001683 if (args->mount_server.hostname)
Chuck Leverc5d120f2008-12-23 15:21:35 -05001684 request.hostname = args->mount_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001685 else
Chuck Leverc5d120f2008-12-23 15:21:35 -05001686 request.hostname = args->nfs_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001687
Chuck Lever0076d7b2007-07-01 12:13:49 -04001688 /*
1689 * Construct the mount server's address.
1690 */
Chuck Lever4c568012007-12-10 14:59:28 -05001691 if (args->mount_server.address.ss_family == AF_UNSPEC) {
Chuck Leverc5d120f2008-12-23 15:21:35 -05001692 memcpy(request.sap, &args->nfs_server.address,
Chuck Lever4c568012007-12-10 14:59:28 -05001693 args->nfs_server.addrlen);
1694 args->mount_server.addrlen = args->nfs_server.addrlen;
1695 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001696 request.salen = args->mount_server.addrlen;
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001697 nfs_set_port(request.sap, &args->mount_server.port, 0);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001698
1699 /*
1700 * Now ask the mount server to map our export path
1701 * to a file handle.
1702 */
Chuck Leverc5d120f2008-12-23 15:21:35 -05001703 status = nfs_mount(&request);
Chuck Leverec88f282009-08-09 15:09:32 -04001704 if (status != 0) {
1705 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1706 request.hostname, status);
1707 return status;
1708 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001709
Chuck Leverec88f282009-08-09 15:09:32 -04001710 /*
1711 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1712 */
1713 if (args->mount_server.version != NFS_MNT3_VERSION)
1714 return 0;
1715 return nfs_walk_authlist(args, &request);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001716}
1717
Bryan Schumakerff9099f22012-07-30 16:05:18 -04001718struct dentry *nfs_try_mount(int flags, const char *dev_name,
1719 struct nfs_mount_info *mount_info,
1720 struct nfs_subversion *nfs_mod)
Bryan Schumaker486aa692012-05-10 15:07:39 -04001721{
1722 int status;
1723 struct nfs_server *server;
1724
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04001725 if (mount_info->parsed->need_mount) {
Bryan Schumaker87c70832012-05-10 15:07:43 -04001726 status = nfs_request_mount(mount_info->parsed, mount_info->mntfh);
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04001727 if (status)
1728 return ERR_PTR(status);
1729 }
Bryan Schumaker486aa692012-05-10 15:07:39 -04001730
1731 /* Get a volume representation */
Bryan Schumaker1179acc2012-07-30 16:05:19 -04001732 server = nfs_mod->rpc_ops->create_server(mount_info, nfs_mod);
Bryan Schumaker486aa692012-05-10 15:07:39 -04001733 if (IS_ERR(server))
1734 return ERR_CAST(server);
1735
Bryan Schumakerab7017a2012-07-30 16:05:16 -04001736 return nfs_fs_mount_common(server, flags, dev_name, mount_info, nfs_mod);
Bryan Schumaker486aa692012-05-10 15:07:39 -04001737}
Bryan Schumakerddda8e02012-07-30 16:05:23 -04001738EXPORT_SYMBOL_GPL(nfs_try_mount);
Bryan Schumaker486aa692012-05-10 15:07:39 -04001739
Rob Landleyc12bace2011-03-09 15:54:13 -06001740/*
1741 * Split "dev_name" into "hostname:export_path".
1742 *
1743 * The leftmost colon demarks the split between the server's hostname
1744 * and the export path. If the hostname starts with a left square
1745 * bracket, then it may contain colons.
1746 *
1747 * Note: caller frees hostname and export path, even on error.
1748 */
1749static int nfs_parse_devname(const char *dev_name,
1750 char **hostname, size_t maxnamlen,
1751 char **export_path, size_t maxpathlen)
Chuck Leverdc045892008-06-23 12:36:37 -04001752{
1753 size_t len;
Rob Landleyc12bace2011-03-09 15:54:13 -06001754 char *end;
Chuck Leverdc045892008-06-23 12:36:37 -04001755
Rob Landleyc12bace2011-03-09 15:54:13 -06001756 /* Is the host name protected with square brakcets? */
1757 if (*dev_name == '[') {
1758 end = strchr(++dev_name, ']');
1759 if (end == NULL || end[1] != ':')
1760 goto out_bad_devname;
Chuck Leverdc045892008-06-23 12:36:37 -04001761
Rob Landleyc12bace2011-03-09 15:54:13 -06001762 len = end - dev_name;
1763 end++;
1764 } else {
1765 char *comma;
1766
1767 end = strchr(dev_name, ':');
1768 if (end == NULL)
1769 goto out_bad_devname;
1770 len = end - dev_name;
1771
1772 /* kill possible hostname list: not supported */
1773 comma = strchr(dev_name, ',');
1774 if (comma != NULL && comma < end)
1775 *comma = 0;
1776 }
1777
Chuck Leverdc045892008-06-23 12:36:37 -04001778 if (len > maxnamlen)
1779 goto out_hostname;
1780
1781 /* N.B. caller will free nfs_server.hostname in all cases */
1782 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
Rob Landleyc12bace2011-03-09 15:54:13 -06001783 if (*hostname == NULL)
Chuck Leverdc045892008-06-23 12:36:37 -04001784 goto out_nomem;
Rob Landleyc12bace2011-03-09 15:54:13 -06001785 len = strlen(++end);
Chuck Leverdc045892008-06-23 12:36:37 -04001786 if (len > maxpathlen)
1787 goto out_path;
Rob Landleyc12bace2011-03-09 15:54:13 -06001788 *export_path = kstrndup(end, len, GFP_KERNEL);
Chuck Leverdc045892008-06-23 12:36:37 -04001789 if (!*export_path)
1790 goto out_nomem;
1791
1792 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1793 return 0;
1794
1795out_bad_devname:
1796 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1797 return -EINVAL;
1798
1799out_nomem:
1800 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1801 return -ENOMEM;
1802
1803out_hostname:
1804 dfprintk(MOUNT, "NFS: server hostname too long\n");
1805 return -ENAMETOOLONG;
1806
1807out_path:
1808 dfprintk(MOUNT, "NFS: export pathname too long\n");
1809 return -ENAMETOOLONG;
1810}
1811
1812/*
David Howells54ceac42006-08-22 20:06:13 -04001813 * Validate the NFS2/NFS3 mount data
1814 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001815 *
1816 * For option strings, user space handles the following behaviors:
1817 *
1818 * + DNS: mapping server host name to IP address ("addr=" option)
1819 *
1820 * + failure mode: how to behave if a mount request can't be handled
1821 * immediately ("fg/bg" option)
1822 *
1823 * + retry: how often to retry a mount request ("retry=" option)
1824 *
1825 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1826 * mountproto=tcp after mountproto=udp, and so on
David Howellsf7b422b2006-06-09 09:34:33 -04001827 */
Bryan Schumakerd72c7272012-05-10 15:07:41 -04001828static int nfs23_validate_mount_data(void *options,
1829 struct nfs_parsed_mount_data *args,
1830 struct nfs_fh *mntfh,
1831 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001832{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001833 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001834 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
Chuck Lever136d5582007-07-01 12:13:54 -04001835
Chuck Lever5df36e72007-07-01 12:12:56 -04001836 if (data == NULL)
1837 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001838
Bryan Schumakerc5afc8d2012-06-08 11:32:56 -04001839 args->version = NFS_DEFAULT_VERSION;
David Howellsf7b422b2006-06-09 09:34:33 -04001840 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001841 case 1:
1842 data->namlen = 0;
1843 case 2:
1844 data->bsize = 0;
1845 case 3:
1846 if (data->flags & NFS_MOUNT_VER3)
1847 goto out_no_v3;
1848 data->root.size = NFS2_FHSIZE;
1849 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1850 case 4:
1851 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1852 goto out_no_sec;
1853 case 5:
1854 memset(data->context, 0, sizeof(data->context));
1855 case 6:
Trond Myklebustb7e24452008-06-19 15:21:11 -04001856 if (data->flags & NFS_MOUNT_VER3) {
1857 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1858 goto out_invalid_fh;
Chuck Lever5df36e72007-07-01 12:12:56 -04001859 mntfh->size = data->root.size;
Chuck Lever764302c2009-09-08 19:50:03 -04001860 args->version = 3;
1861 } else {
Chuck Lever5df36e72007-07-01 12:12:56 -04001862 mntfh->size = NFS2_FHSIZE;
Chuck Lever764302c2009-09-08 19:50:03 -04001863 args->version = 2;
1864 }
Chuck Lever5df36e72007-07-01 12:12:56 -04001865
Chuck Lever5df36e72007-07-01 12:12:56 -04001866
1867 memcpy(mntfh->data, data->root.data, mntfh->size);
1868 if (mntfh->size < sizeof(mntfh->data))
1869 memset(mntfh->data + mntfh->size, 0,
1870 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001871
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001872 /*
1873 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1874 * can deal with.
1875 */
Trond Myklebustff3525a2008-08-15 16:59:14 -04001876 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
Bryan Schumakerd5eff1a2010-08-03 13:04:00 -04001877 args->flags |= NFS_MOUNT_LEGACY_INTERFACE;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001878 args->rsize = data->rsize;
1879 args->wsize = data->wsize;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001880 args->timeo = data->timeo;
1881 args->retrans = data->retrans;
1882 args->acregmin = data->acregmin;
1883 args->acregmax = data->acregmax;
1884 args->acdirmin = data->acdirmin;
1885 args->acdirmax = data->acdirmax;
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04001886 args->need_mount = false;
Chuck Lever4c568012007-12-10 14:59:28 -05001887
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001888 memcpy(sap, &data->addr, sizeof(data->addr));
Chuck Lever4c568012007-12-10 14:59:28 -05001889 args->nfs_server.addrlen = sizeof(data->addr);
Trond Myklebust872ece82012-09-04 11:05:07 -04001890 args->nfs_server.port = ntohs(data->addr.sin_port);
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001891 if (!nfs_verify_server_address(sap))
Chuck Lever4c568012007-12-10 14:59:28 -05001892 goto out_no_address;
1893
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001894 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001895 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001896 /* N.B. caller will free nfs_server.hostname in all cases */
1897 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1898 args->namlen = data->namlen;
1899 args->bsize = data->bsize;
Chuck Leverdd07c942008-06-24 16:33:46 -04001900
1901 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1902 args->auth_flavors[0] = data->pseudoflavor;
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001903 if (!args->nfs_server.hostname)
1904 goto out_nomem;
Eric Parisf9c3a382008-03-05 14:20:18 -05001905
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001906 if (!(data->flags & NFS_MOUNT_NONLM))
1907 args->flags &= ~(NFS_MOUNT_LOCAL_FLOCK|
1908 NFS_MOUNT_LOCAL_FCNTL);
1909 else
1910 args->flags |= (NFS_MOUNT_LOCAL_FLOCK|
1911 NFS_MOUNT_LOCAL_FCNTL);
Eric Parisf9c3a382008-03-05 14:20:18 -05001912 /*
1913 * The legacy version 6 binary mount data from userspace has a
1914 * field used only to transport selinux information into the
1915 * the kernel. To continue to support that functionality we
1916 * have a touch of selinux knowledge here in the NFS code. The
1917 * userspace code converted context=blah to just blah so we are
1918 * converting back to the full string selinux understands.
1919 */
1920 if (data->context[0]){
1921#ifdef CONFIG_SECURITY_SELINUX
1922 int rc;
1923 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1924 if (!opts_str)
1925 return -ENOMEM;
1926 strcpy(opts_str, "context=");
1927 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1928 strcat(opts_str, &data->context[0]);
1929 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1930 kfree(opts_str);
1931 if (rc)
1932 return rc;
1933#else
1934 return -EINVAL;
1935#endif
1936 }
1937
Chuck Lever5df36e72007-07-01 12:12:56 -04001938 break;
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04001939 default:
1940 return NFS_TEXT_DATA;
David Howellsf7b422b2006-06-09 09:34:33 -04001941 }
David Howells54ceac42006-08-22 20:06:13 -04001942
Bryan Schumaker1c606fb2012-07-30 16:05:24 -04001943#if !IS_ENABLED(CONFIG_NFS_V3)
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001944 if (args->version == 3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001945 goto out_v3_not_compiled;
1946#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001947
David Howells54ceac42006-08-22 20:06:13 -04001948 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001949
1950out_no_data:
1951 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1952 return -EINVAL;
1953
1954out_no_v3:
1955 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1956 data->version);
1957 return -EINVAL;
1958
1959out_no_sec:
1960 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1961 return -EINVAL;
1962
Bryan Schumaker1c606fb2012-07-30 16:05:24 -04001963#if !IS_ENABLED(CONFIG_NFS_V3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001964out_v3_not_compiled:
1965 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1966 return -EPROTONOSUPPORT;
1967#endif /* !CONFIG_NFS_V3 */
1968
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001969out_nomem:
1970 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
1971 return -ENOMEM;
1972
Chuck Lever5df36e72007-07-01 12:12:56 -04001973out_no_address:
1974 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1975 return -EINVAL;
1976
1977out_invalid_fh:
1978 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1979 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04001980}
1981
Bryan Schumaker89d77c82012-07-30 16:05:25 -04001982#if IS_ENABLED(CONFIG_NFS_V4)
Bryan Schumakerd72c7272012-05-10 15:07:41 -04001983static int nfs_validate_mount_data(struct file_system_type *fs_type,
1984 void *options,
1985 struct nfs_parsed_mount_data *args,
1986 struct nfs_fh *mntfh,
1987 const char *dev_name)
1988{
1989 if (fs_type == &nfs_fs_type)
1990 return nfs23_validate_mount_data(options, args, mntfh, dev_name);
1991 return nfs4_validate_mount_data(options, args, dev_name);
1992}
1993#else
1994static int nfs_validate_mount_data(struct file_system_type *fs_type,
1995 void *options,
1996 struct nfs_parsed_mount_data *args,
1997 struct nfs_fh *mntfh,
1998 const char *dev_name)
1999{
2000 return nfs23_validate_mount_data(options, args, mntfh, dev_name);
2001}
2002#endif
2003
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04002004static int nfs_validate_text_mount_data(void *options,
2005 struct nfs_parsed_mount_data *args,
2006 const char *dev_name)
2007{
2008 int port = 0;
2009 int max_namelen = PAGE_SIZE;
2010 int max_pathlen = NFS_MAXPATHLEN;
2011 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2012
2013 if (nfs_parse_mount_options((char *)options, args) == 0)
2014 return -EINVAL;
2015
2016 if (!nfs_verify_server_address(sap))
2017 goto out_no_address;
2018
2019 if (args->version == 4) {
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002020#if IS_ENABLED(CONFIG_NFS_V4)
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04002021 port = NFS_PORT;
2022 max_namelen = NFS4_MAXNAMLEN;
2023 max_pathlen = NFS4_MAXPATHLEN;
2024 nfs_validate_transport_protocol(args);
2025 nfs4_validate_mount_flags(args);
2026#else
2027 goto out_v4_not_compiled;
2028#endif /* CONFIG_NFS_V4 */
2029 } else
2030 nfs_set_mount_transport_protocol(args);
2031
2032 nfs_set_port(sap, &args->nfs_server.port, port);
2033
2034 if (args->auth_flavor_len > 1)
2035 goto out_bad_auth;
2036
2037 return nfs_parse_devname(dev_name,
2038 &args->nfs_server.hostname,
2039 max_namelen,
2040 &args->nfs_server.export_path,
2041 max_pathlen);
2042
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002043#if !IS_ENABLED(CONFIG_NFS_V4)
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04002044out_v4_not_compiled:
2045 dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n");
2046 return -EPROTONOSUPPORT;
2047#endif /* !CONFIG_NFS_V4 */
2048
2049out_no_address:
2050 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
2051 return -EINVAL;
2052
2053out_bad_auth:
2054 dfprintk(MOUNT, "NFS: Too many RPC auth flavours specified\n");
2055 return -EINVAL;
2056}
2057
Jeff Layton48b605f2008-06-10 15:38:39 -04002058static int
2059nfs_compare_remount_data(struct nfs_server *nfss,
2060 struct nfs_parsed_mount_data *data)
2061{
2062 if (data->flags != nfss->flags ||
2063 data->rsize != nfss->rsize ||
2064 data->wsize != nfss->wsize ||
2065 data->retrans != nfss->client->cl_timeout->to_retries ||
2066 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
2067 data->acregmin != nfss->acregmin / HZ ||
2068 data->acregmax != nfss->acregmax / HZ ||
2069 data->acdirmin != nfss->acdirmin / HZ ||
2070 data->acdirmax != nfss->acdirmax / HZ ||
2071 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
Trond Myklebustbcd2ea12009-10-06 15:41:22 -04002072 data->nfs_server.port != nfss->port ||
Jeff Layton48b605f2008-06-10 15:38:39 -04002073 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
Stefan Richtera1be9ee2009-10-12 11:26:12 -04002074 !rpc_cmp_addr((struct sockaddr *)&data->nfs_server.address,
2075 (struct sockaddr *)&nfss->nfs_client->cl_addr))
Jeff Layton48b605f2008-06-10 15:38:39 -04002076 return -EINVAL;
2077
2078 return 0;
2079}
2080
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002081int
Jeff Layton48b605f2008-06-10 15:38:39 -04002082nfs_remount(struct super_block *sb, int *flags, char *raw_data)
2083{
2084 int error;
2085 struct nfs_server *nfss = sb->s_fs_info;
2086 struct nfs_parsed_mount_data *data;
2087 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
2088 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
Trond Myklebustcd100722008-06-17 16:12:00 -04002089 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
Jeff Layton48b605f2008-06-10 15:38:39 -04002090
2091 /*
2092 * Userspace mount programs that send binary options generally send
2093 * them populated with default values. We have no way to know which
2094 * ones were explicitly specified. Fall back to legacy behavior and
2095 * just return success.
2096 */
Marc Zyngier31c94462008-07-17 13:21:55 +02002097 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
2098 (nfsvers <= 3 && (!options || (options->version >= 1 &&
2099 options->version <= 6))))
Jeff Layton48b605f2008-06-10 15:38:39 -04002100 return 0;
2101
2102 data = kzalloc(sizeof(*data), GFP_KERNEL);
2103 if (data == NULL)
2104 return -ENOMEM;
2105
2106 /* fill out struct with values from existing mount */
2107 data->flags = nfss->flags;
2108 data->rsize = nfss->rsize;
2109 data->wsize = nfss->wsize;
2110 data->retrans = nfss->client->cl_timeout->to_retries;
2111 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
2112 data->acregmin = nfss->acregmin / HZ;
2113 data->acregmax = nfss->acregmax / HZ;
2114 data->acdirmin = nfss->acdirmin / HZ;
2115 data->acdirmax = nfss->acdirmax / HZ;
2116 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
Trond Myklebustbcd2ea12009-10-06 15:41:22 -04002117 data->nfs_server.port = nfss->port;
Jeff Layton48b605f2008-06-10 15:38:39 -04002118 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
2119 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
2120 data->nfs_server.addrlen);
2121
2122 /* overwrite those values with any that were specified */
2123 error = nfs_parse_mount_options((char *)options, data);
2124 if (error < 0)
2125 goto out;
2126
Jeff Layton26c4c172011-04-27 11:49:09 -04002127 /*
2128 * noac is a special case. It implies -o sync, but that's not
2129 * necessarily reflected in the mtab options. do_remount_sb
2130 * will clear MS_SYNCHRONOUS if -o sync wasn't specified in the
2131 * remount options, so we have to explicitly reset it.
2132 */
2133 if (data->flags & NFS_MOUNT_NOAC)
2134 *flags |= MS_SYNCHRONOUS;
2135
Jeff Layton48b605f2008-06-10 15:38:39 -04002136 /* compare new mount options with old ones */
2137 error = nfs_compare_remount_data(nfss, data);
2138out:
2139 kfree(data);
2140 return error;
2141}
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002142EXPORT_SYMBOL_GPL(nfs_remount);
Jeff Layton48b605f2008-06-10 15:38:39 -04002143
David Howells54ceac42006-08-22 20:06:13 -04002144/*
2145 * Initialise the common bits of the superblock
2146 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002147inline void nfs_initialise_sb(struct super_block *sb)
David Howells54ceac42006-08-22 20:06:13 -04002148{
2149 struct nfs_server *server = NFS_SB(sb);
2150
2151 sb->s_magic = NFS_SUPER_MAGIC;
2152
2153 /* We probably want something more informative here */
2154 snprintf(sb->s_id, sizeof(sb->s_id),
Vivek Trivedi5a7c9ee2012-03-15 23:58:52 +05302155 "%u:%u", MAJOR(sb->s_dev), MINOR(sb->s_dev));
David Howells54ceac42006-08-22 20:06:13 -04002156
2157 if (sb->s_blocksize == 0)
2158 sb->s_blocksize = nfs_block_bits(server->wsize,
2159 &sb->s_blocksize_bits);
2160
Jens Axboe32a88aa2009-09-16 15:02:33 +02002161 sb->s_bdi = &server->backing_dev_info;
2162
David Howells54ceac42006-08-22 20:06:13 -04002163 nfs_super_set_maxbytes(sb, server->maxfilesize);
2164}
2165
2166/*
2167 * Finish setting up an NFS2/3 superblock
2168 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002169void nfs_fill_super(struct super_block *sb, struct nfs_mount_info *mount_info)
David Howells54ceac42006-08-22 20:06:13 -04002170{
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002171 struct nfs_parsed_mount_data *data = mount_info->parsed;
David Howells54ceac42006-08-22 20:06:13 -04002172 struct nfs_server *server = NFS_SB(sb);
2173
2174 sb->s_blocksize_bits = 0;
2175 sb->s_blocksize = 0;
Bryan Schumaker6a744902012-07-30 16:05:20 -04002176 sb->s_xattr = server->nfs_client->cl_nfs_mod->xattr;
2177 sb->s_op = server->nfs_client->cl_nfs_mod->sops;
2178 if (data && data->bsize)
David Howells54ceac42006-08-22 20:06:13 -04002179 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
2180
Bryan Schumaker6a744902012-07-30 16:05:20 -04002181 if (server->nfs_client->rpc_ops->version != 2) {
David Howells54ceac42006-08-22 20:06:13 -04002182 /* The VFS shouldn't apply the umask to mode bits. We will do
2183 * so ourselves when necessary.
2184 */
2185 sb->s_flags |= MS_POSIXACL;
2186 sb->s_time_gran = 1;
2187 }
2188
David Howells54ceac42006-08-22 20:06:13 -04002189 nfs_initialise_sb(sb);
2190}
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002191EXPORT_SYMBOL_GPL(nfs_fill_super);
David Howells54ceac42006-08-22 20:06:13 -04002192
2193/*
Bryan Schumaker3cadf4b2012-07-16 16:39:19 -04002194 * Finish setting up a cloned NFS2/3/4 superblock
David Howells54ceac42006-08-22 20:06:13 -04002195 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002196void nfs_clone_super(struct super_block *sb, struct nfs_mount_info *mount_info)
David Howells54ceac42006-08-22 20:06:13 -04002197{
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002198 const struct super_block *old_sb = mount_info->cloned->sb;
David Howells54ceac42006-08-22 20:06:13 -04002199 struct nfs_server *server = NFS_SB(sb);
2200
2201 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2202 sb->s_blocksize = old_sb->s_blocksize;
2203 sb->s_maxbytes = old_sb->s_maxbytes;
Bryan Schumaker3cadf4b2012-07-16 16:39:19 -04002204 sb->s_xattr = old_sb->s_xattr;
2205 sb->s_op = old_sb->s_op;
2206 sb->s_time_gran = 1;
David Howells54ceac42006-08-22 20:06:13 -04002207
Bryan Schumaker3cadf4b2012-07-16 16:39:19 -04002208 if (server->nfs_client->rpc_ops->version != 2) {
David Howells54ceac42006-08-22 20:06:13 -04002209 /* The VFS shouldn't apply the umask to mode bits. We will do
2210 * so ourselves when necessary.
2211 */
2212 sb->s_flags |= MS_POSIXACL;
David Howells54ceac42006-08-22 20:06:13 -04002213 }
2214
David Howells54ceac42006-08-22 20:06:13 -04002215 nfs_initialise_sb(sb);
2216}
2217
Trond Myklebust275a5d22007-05-16 16:53:28 -04002218static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
2219{
2220 const struct nfs_server *a = s->s_fs_info;
2221 const struct rpc_clnt *clnt_a = a->client;
2222 const struct rpc_clnt *clnt_b = b->client;
2223
2224 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
2225 goto Ebusy;
2226 if (a->nfs_client != b->nfs_client)
2227 goto Ebusy;
2228 if (a->flags != b->flags)
2229 goto Ebusy;
2230 if (a->wsize != b->wsize)
2231 goto Ebusy;
2232 if (a->rsize != b->rsize)
2233 goto Ebusy;
2234 if (a->acregmin != b->acregmin)
2235 goto Ebusy;
2236 if (a->acregmax != b->acregmax)
2237 goto Ebusy;
2238 if (a->acdirmin != b->acdirmin)
2239 goto Ebusy;
2240 if (a->acdirmax != b->acdirmax)
2241 goto Ebusy;
2242 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
2243 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002244 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04002245Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002246 return 0;
2247}
2248
2249struct nfs_sb_mountdata {
2250 struct nfs_server *server;
2251 int mntflags;
2252};
2253
2254static int nfs_set_super(struct super_block *s, void *data)
2255{
2256 struct nfs_sb_mountdata *sb_mntdata = data;
2257 struct nfs_server *server = sb_mntdata->server;
2258 int ret;
2259
2260 s->s_flags = sb_mntdata->mntflags;
2261 s->s_fs_info = server;
Al Viro8b244ff2010-12-18 11:29:39 -05002262 s->s_d_op = server->nfs_client->rpc_ops->dentry_ops;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002263 ret = set_anon_super(s, server);
2264 if (ret == 0)
2265 server->s_dev = s->s_dev;
2266 return ret;
2267}
2268
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002269static int nfs_compare_super_address(struct nfs_server *server1,
2270 struct nfs_server *server2)
2271{
2272 struct sockaddr *sap1, *sap2;
2273
2274 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
2275 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
2276
2277 if (sap1->sa_family != sap2->sa_family)
2278 return 0;
2279
2280 switch (sap1->sa_family) {
2281 case AF_INET: {
2282 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
2283 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
2284 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
2285 return 0;
2286 if (sin1->sin_port != sin2->sin_port)
2287 return 0;
2288 break;
2289 }
2290 case AF_INET6: {
2291 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
2292 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
2293 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
2294 return 0;
2295 if (sin1->sin6_port != sin2->sin6_port)
2296 return 0;
2297 break;
2298 }
2299 default:
2300 return 0;
2301 }
2302
2303 return 1;
2304}
2305
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002306static int nfs_compare_super(struct super_block *sb, void *data)
2307{
2308 struct nfs_sb_mountdata *sb_mntdata = data;
2309 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2310 int mntflags = sb_mntdata->mntflags;
2311
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002312 if (!nfs_compare_super_address(old, server))
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002313 return 0;
2314 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2315 if (old->flags & NFS_MOUNT_UNSHARED)
2316 return 0;
2317 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2318 return 0;
2319 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04002320}
2321
Trond Myklebust39ffb922012-05-16 10:21:30 -07002322#ifdef CONFIG_NFS_FSCACHE
Bryan Schumaker2311b942012-05-10 15:07:32 -04002323static void nfs_get_cache_cookie(struct super_block *sb,
2324 struct nfs_parsed_mount_data *parsed,
2325 struct nfs_clone_mount *cloned)
2326{
2327 char *uniq = NULL;
2328 int ulen = 0;
2329
2330 if (parsed && parsed->fscache_uniq) {
2331 uniq = parsed->fscache_uniq;
2332 ulen = strlen(parsed->fscache_uniq);
2333 } else if (cloned) {
2334 struct nfs_server *mnt_s = NFS_SB(cloned->sb);
2335 if (mnt_s->fscache_key) {
2336 uniq = mnt_s->fscache_key->key.uniquifier;
2337 ulen = mnt_s->fscache_key->key.uniq_len;
2338 };
2339 }
2340
2341 nfs_fscache_get_super_cookie(sb, uniq, ulen);
2342}
Trond Myklebust39ffb922012-05-16 10:21:30 -07002343#else
2344static void nfs_get_cache_cookie(struct super_block *sb,
2345 struct nfs_parsed_mount_data *parsed,
2346 struct nfs_clone_mount *cloned)
2347{
2348}
2349#endif
Bryan Schumaker2311b942012-05-10 15:07:32 -04002350
Miklos Szeredifa799752008-04-30 00:54:33 -07002351static int nfs_bdi_register(struct nfs_server *server)
2352{
2353 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
2354}
2355
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002356int nfs_set_sb_security(struct super_block *s, struct dentry *mntroot,
2357 struct nfs_mount_info *mount_info)
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002358{
2359 return security_sb_set_mnt_opts(s, &mount_info->parsed->lsm_opts);
2360}
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002361EXPORT_SYMBOL_GPL(nfs_set_sb_security);
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002362
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002363int nfs_clone_sb_security(struct super_block *s, struct dentry *mntroot,
2364 struct nfs_mount_info *mount_info)
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002365{
2366 /* clone any lsm security options from the parent to the new sb */
2367 security_sb_clone_mnt_opts(mount_info->cloned->sb, s);
2368 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops)
2369 return -ESTALE;
2370 return 0;
2371}
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002372EXPORT_SYMBOL_GPL(nfs_clone_sb_security);
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002373
Bryan Schumakerab7017a2012-07-30 16:05:16 -04002374struct dentry *nfs_fs_mount_common(struct nfs_server *server,
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002375 int flags, const char *dev_name,
Bryan Schumakerab7017a2012-07-30 16:05:16 -04002376 struct nfs_mount_info *mount_info,
2377 struct nfs_subversion *nfs_mod)
David Howells54ceac42006-08-22 20:06:13 -04002378{
David Howells54ceac42006-08-22 20:06:13 -04002379 struct super_block *s;
Al Viro01194982011-03-16 07:25:36 -04002380 struct dentry *mntroot = ERR_PTR(-ENOMEM);
Trond Myklebust75180df2007-05-16 16:53:28 -04002381 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002382 struct nfs_sb_mountdata sb_mntdata = {
2383 .mntflags = flags,
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002384 .server = server,
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002385 };
Al Viro01194982011-03-16 07:25:36 -04002386 int error;
David Howells54ceac42006-08-22 20:06:13 -04002387
Trond Myklebust75180df2007-05-16 16:53:28 -04002388 if (server->flags & NFS_MOUNT_UNSHARED)
2389 compare_super = NULL;
2390
Sachin Prabhufb2088c2011-08-01 12:10:12 +01002391 /* -o noac implies -o sync */
2392 if (server->flags & NFS_MOUNT_NOAC)
2393 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2394
David Howells54ceac42006-08-22 20:06:13 -04002395 /* Get a superblock - note that we may end up sharing one that already exists */
Bryan Schumakerab7017a2012-07-30 16:05:16 -04002396 s = sget(nfs_mod->nfs_fs, compare_super, nfs_set_super, flags, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002397 if (IS_ERR(s)) {
Al Viro01194982011-03-16 07:25:36 -04002398 mntroot = ERR_CAST(s);
David Howells54ceac42006-08-22 20:06:13 -04002399 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04002400 }
2401
David Howells54ceac42006-08-22 20:06:13 -04002402 if (s->s_fs_info != server) {
2403 nfs_free_server(server);
2404 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002405 } else {
2406 error = nfs_bdi_register(server);
Al Viro01194982011-03-16 07:25:36 -04002407 if (error) {
2408 mntroot = ERR_PTR(error);
NeilBrowncfbc0682010-03-11 11:20:17 +11002409 goto error_splat_bdi;
Al Viro01194982011-03-16 07:25:36 -04002410 }
David Howellsf7b422b2006-06-09 09:34:33 -04002411 }
David Howells54ceac42006-08-22 20:06:13 -04002412
2413 if (!s->s_root) {
2414 /* initial superblock/root creation */
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002415 mount_info->fill_super(s, mount_info);
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002416 nfs_get_cache_cookie(s, mount_info->parsed, mount_info->cloned);
David Howells54ceac42006-08-22 20:06:13 -04002417 }
2418
Bryan Schumaker87c70832012-05-10 15:07:43 -04002419 mntroot = nfs_get_root(s, mount_info->mntfh, dev_name);
Al Viro01194982011-03-16 07:25:36 -04002420 if (IS_ERR(mntroot))
David Howells54ceac42006-08-22 20:06:13 -04002421 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002422
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002423 error = mount_info->set_security(s, mntroot, mount_info);
Eric Parisf9c3a382008-03-05 14:20:18 -05002424 if (error)
2425 goto error_splat_root;
2426
David Howellsf7b422b2006-06-09 09:34:33 -04002427 s->s_flags |= MS_ACTIVE;
Chuck Lever06559602007-07-01 12:12:35 -04002428
2429out:
Al Viro01194982011-03-16 07:25:36 -04002430 return mntroot;
Trond Myklebust816724e2006-06-24 08:41:41 -04002431
David Howells54ceac42006-08-22 20:06:13 -04002432out_err_nosb:
2433 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04002434 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002435
Eric Parisf9c3a382008-03-05 14:20:18 -05002436error_splat_root:
2437 dput(mntroot);
Al Viro01194982011-03-16 07:25:36 -04002438 mntroot = ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04002439error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002440 if (server && !s->s_root)
2441 bdi_unregister(&server->backing_dev_info);
2442error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002443 deactivate_locked_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04002444 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002445}
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002446EXPORT_SYMBOL_GPL(nfs_fs_mount_common);
David Howellsf7b422b2006-06-09 09:34:33 -04002447
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002448struct dentry *nfs_fs_mount(struct file_system_type *fs_type,
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002449 int flags, const char *dev_name, void *raw_data)
2450{
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002451 struct nfs_mount_info mount_info = {
2452 .fill_super = nfs_fill_super,
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002453 .set_security = nfs_set_sb_security,
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002454 };
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002455 struct dentry *mntroot = ERR_PTR(-ENOMEM);
Bryan Schumakerab7017a2012-07-30 16:05:16 -04002456 struct nfs_subversion *nfs_mod;
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002457 int error;
2458
Bryan Schumaker46058d42012-05-10 15:07:42 -04002459 mount_info.parsed = nfs_alloc_parsed_mount_data();
Bryan Schumaker87c70832012-05-10 15:07:43 -04002460 mount_info.mntfh = nfs_alloc_fhandle();
2461 if (mount_info.parsed == NULL || mount_info.mntfh == NULL)
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002462 goto out;
2463
2464 /* Validate the mount data */
Bryan Schumaker87c70832012-05-10 15:07:43 -04002465 error = nfs_validate_mount_data(fs_type, raw_data, mount_info.parsed, mount_info.mntfh, dev_name);
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04002466 if (error == NFS_TEXT_DATA)
Bryan Schumaker46058d42012-05-10 15:07:42 -04002467 error = nfs_validate_text_mount_data(raw_data, mount_info.parsed, dev_name);
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002468 if (error < 0) {
2469 mntroot = ERR_PTR(error);
2470 goto out;
2471 }
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002472
Bryan Schumakerab7017a2012-07-30 16:05:16 -04002473 nfs_mod = get_nfs_version(mount_info.parsed->version);
2474 if (IS_ERR(nfs_mod)) {
2475 mntroot = ERR_CAST(nfs_mod);
2476 goto out;
2477 }
2478
Bryan Schumakerff9099f22012-07-30 16:05:18 -04002479 mntroot = nfs_mod->rpc_ops->try_mount(flags, dev_name, &mount_info, nfs_mod);
Bryan Schumakerab7017a2012-07-30 16:05:16 -04002480
2481 put_nfs_version(nfs_mod);
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002482out:
Bryan Schumaker46058d42012-05-10 15:07:42 -04002483 nfs_free_parsed_mount_data(mount_info.parsed);
Bryan Schumaker87c70832012-05-10 15:07:43 -04002484 nfs_free_fhandle(mount_info.mntfh);
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002485 return mntroot;
2486}
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002487EXPORT_SYMBOL_GPL(nfs_fs_mount);
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002488
David Howells54ceac42006-08-22 20:06:13 -04002489/*
Trond Myklebust387c1492010-02-03 08:27:35 -05002490 * Ensure that we unregister the bdi before kill_anon_super
2491 * releases the device name
2492 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002493void nfs_put_super(struct super_block *s)
Trond Myklebust387c1492010-02-03 08:27:35 -05002494{
2495 struct nfs_server *server = NFS_SB(s);
2496
2497 bdi_unregister(&server->backing_dev_info);
2498}
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002499EXPORT_SYMBOL_GPL(nfs_put_super);
Trond Myklebust387c1492010-02-03 08:27:35 -05002500
2501/*
David Howells54ceac42006-08-22 20:06:13 -04002502 * Destroy an NFS2/3 superblock
2503 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002504void nfs_kill_super(struct super_block *s)
David Howellsf7b422b2006-06-09 09:34:33 -04002505{
2506 struct nfs_server *server = NFS_SB(s);
2507
2508 kill_anon_super(s);
David Howells08734042009-04-03 16:42:42 +01002509 nfs_fscache_release_super_cookie(s);
David Howells54ceac42006-08-22 20:06:13 -04002510 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04002511}
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002512EXPORT_SYMBOL_GPL(nfs_kill_super);
David Howellsf7b422b2006-06-09 09:34:33 -04002513
David Howells54ceac42006-08-22 20:06:13 -04002514/*
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002515 * Clone an NFS2/3/4 server record on xdev traversal (FSID-change)
David Howells54ceac42006-08-22 20:06:13 -04002516 */
Stanislav Kinsbursky3dd4f8ef2012-10-02 14:19:04 +04002517static struct dentry *
Bryan Schumakere8f25e62012-07-30 16:05:17 -04002518nfs_xdev_mount(struct file_system_type *fs_type, int flags,
2519 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002520{
Bryan Schumakere8f25e62012-07-30 16:05:17 -04002521 struct nfs_clone_mount *data = raw_data;
2522 struct nfs_mount_info mount_info = {
2523 .fill_super = nfs_clone_super,
2524 .set_security = nfs_clone_sb_security,
2525 .cloned = data,
2526 };
David Howells54ceac42006-08-22 20:06:13 -04002527 struct nfs_server *server;
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002528 struct dentry *mntroot = ERR_PTR(-ENOMEM);
Bryan Schumakerab7017a2012-07-30 16:05:16 -04002529 struct nfs_subversion *nfs_mod = NFS_SB(data->sb)->nfs_client->cl_nfs_mod;
David Howells54ceac42006-08-22 20:06:13 -04002530 int error;
2531
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002532 dprintk("--> nfs_xdev_mount_common()\n");
David Howells54ceac42006-08-22 20:06:13 -04002533
Bryan Schumakere8f25e62012-07-30 16:05:17 -04002534 mount_info.mntfh = mount_info.cloned->fh;
Bryan Schumaker87c70832012-05-10 15:07:43 -04002535
David Howells54ceac42006-08-22 20:06:13 -04002536 /* create a new volume representation */
Bryan Schumaker1179acc2012-07-30 16:05:19 -04002537 server = nfs_mod->rpc_ops->clone_server(NFS_SB(data->sb), data->fh, data->fattr, data->authflavor);
David Howells54ceac42006-08-22 20:06:13 -04002538 if (IS_ERR(server)) {
2539 error = PTR_ERR(server);
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002540 goto out_err;
David Howells54ceac42006-08-22 20:06:13 -04002541 }
2542
Bryan Schumakere8f25e62012-07-30 16:05:17 -04002543 mntroot = nfs_fs_mount_common(server, flags, dev_name, &mount_info, nfs_mod);
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002544 dprintk("<-- nfs_xdev_mount_common() = 0\n");
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002545out:
Al Viro31f43472010-10-29 03:38:12 -04002546 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04002547
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002548out_err:
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002549 dprintk("<-- nfs_xdev_mount_common() = %d [error]\n", error);
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002550 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002551}
2552
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002553#if IS_ENABLED(CONFIG_NFS_V4)
David Howells54ceac42006-08-22 20:06:13 -04002554
Trond Myklebust01c3f052009-06-17 13:22:58 -07002555static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2556{
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04002557 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3|
2558 NFS_MOUNT_LOCAL_FLOCK|NFS_MOUNT_LOCAL_FCNTL);
Trond Myklebust01c3f052009-06-17 13:22:58 -07002559}
2560
David Howells54ceac42006-08-22 20:06:13 -04002561/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04002562 * Validate NFSv4 mount options
2563 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002564static int nfs4_validate_mount_data(void *options,
2565 struct nfs_parsed_mount_data *args,
2566 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04002567{
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002568 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002569 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002570 char *c;
2571
2572 if (data == NULL)
2573 goto out_no_data;
2574
Bryan Schumakercdf66442012-06-05 14:59:54 -04002575 args->version = 4;
2576
Chuck Leverf0768eb2007-07-01 12:13:01 -04002577 switch (data->version) {
2578 case 1:
Chuck Lever4c568012007-12-10 14:59:28 -05002579 if (data->host_addrlen > sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002580 goto out_no_address;
Chuck Lever4c568012007-12-10 14:59:28 -05002581 if (data->host_addrlen == 0)
2582 goto out_no_address;
2583 args->nfs_server.addrlen = data->host_addrlen;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002584 if (copy_from_user(sap, data->host_addr, data->host_addrlen))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002585 return -EFAULT;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002586 if (!nfs_verify_server_address(sap))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002587 goto out_no_address;
Trond Myklebust872ece82012-09-04 11:05:07 -04002588 args->nfs_server.port = ntohs(((struct sockaddr_in *)sap)->sin_port);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002589
Chuck Lever6738b252008-06-24 16:33:54 -04002590 if (data->auth_flavourlen) {
2591 if (data->auth_flavourlen > 1)
2592 goto out_inval_auth;
Trond Myklebust20c71f52007-09-20 20:23:51 -04002593 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002594 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04002595 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002596 return -EFAULT;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002597 }
2598
2599 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2600 if (IS_ERR(c))
2601 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002602 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002603
2604 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2605 if (IS_ERR(c))
2606 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002607 args->nfs_server.export_path = c;
2608 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002609
2610 c = strndup_user(data->client_addr.data, 16);
2611 if (IS_ERR(c))
2612 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002613 args->client_address = c;
2614
2615 /*
2616 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2617 * can deal with.
2618 */
2619
2620 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2621 args->rsize = data->rsize;
2622 args->wsize = data->wsize;
2623 args->timeo = data->timeo;
2624 args->retrans = data->retrans;
2625 args->acregmin = data->acregmin;
2626 args->acregmax = data->acregmax;
2627 args->acdirmin = data->acdirmin;
2628 args->acdirmax = data->acdirmax;
2629 args->nfs_server.protocol = data->proto;
Trond Myklebust259875e2008-07-02 14:43:47 -04002630 nfs_validate_transport_protocol(args);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002631
2632 break;
Chuck Lever7630c852009-09-08 19:49:57 -04002633 default:
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04002634 return NFS_TEXT_DATA;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002635 }
2636
2637 return 0;
2638
2639out_no_data:
2640 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2641 return -EINVAL;
2642
2643out_inval_auth:
2644 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2645 data->auth_flavourlen);
2646 return -EINVAL;
2647
2648out_no_address:
2649 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2650 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002651}
2652
Bryan Schumakerfac1e8e2012-07-30 16:05:22 -04002653/*
2654 * NFS v4 module parameters need to stay in the
2655 * NFS client for backwards compatibility
2656 */
2657unsigned int nfs_callback_set_tcpport;
2658unsigned short nfs_callback_tcpport;
2659/* Default cache timeout is 10 minutes */
2660unsigned int nfs_idmap_cache_timeout = 600;
2661/* Turn off NFSv4 uid/gid mapping when using AUTH_SYS */
2662bool nfs4_disable_idmapping = true;
2663unsigned short max_session_slots = NFS4_DEF_SLOT_TABLE_SIZE;
2664unsigned short send_implementation_id = 1;
Chuck Lever6f2ea7f2012-09-14 17:24:41 -04002665char nfs4_client_id_uniquifier[NFS4_CLIENT_ID_UNIQ_LEN] = "";
Bryan Schumakerfac1e8e2012-07-30 16:05:22 -04002666
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002667EXPORT_SYMBOL_GPL(nfs_callback_set_tcpport);
2668EXPORT_SYMBOL_GPL(nfs_callback_tcpport);
2669EXPORT_SYMBOL_GPL(nfs_idmap_cache_timeout);
2670EXPORT_SYMBOL_GPL(nfs4_disable_idmapping);
2671EXPORT_SYMBOL_GPL(max_session_slots);
2672EXPORT_SYMBOL_GPL(send_implementation_id);
Chuck Lever6f2ea7f2012-09-14 17:24:41 -04002673EXPORT_SYMBOL_GPL(nfs4_client_id_uniquifier);
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002674
Bryan Schumakerfac1e8e2012-07-30 16:05:22 -04002675#define NFS_CALLBACK_MAXPORTNR (65535U)
2676
2677static int param_set_portnr(const char *val, const struct kernel_param *kp)
2678{
2679 unsigned long num;
2680 int ret;
2681
2682 if (!val)
2683 return -EINVAL;
Daniel Walter7297cb62012-09-26 21:51:46 +02002684 ret = kstrtoul(val, 0, &num);
Bryan Schumakerfac1e8e2012-07-30 16:05:22 -04002685 if (ret == -EINVAL || num > NFS_CALLBACK_MAXPORTNR)
2686 return -EINVAL;
2687 *((unsigned int *)kp->arg) = num;
2688 return 0;
2689}
2690static struct kernel_param_ops param_ops_portnr = {
2691 .set = param_set_portnr,
2692 .get = param_get_uint,
2693};
2694#define param_check_portnr(name, p) __param_check(name, p, unsigned int);
2695
2696module_param_named(callback_tcpport, nfs_callback_set_tcpport, portnr, 0644);
2697module_param(nfs_idmap_cache_timeout, int, 0644);
2698module_param(nfs4_disable_idmapping, bool, 0644);
Chuck Lever6f2ea7f2012-09-14 17:24:41 -04002699module_param_string(nfs4_unique_id, nfs4_client_id_uniquifier,
2700 NFS4_CLIENT_ID_UNIQ_LEN, 0600);
Bryan Schumakerfac1e8e2012-07-30 16:05:22 -04002701MODULE_PARM_DESC(nfs4_disable_idmapping,
2702 "Turn off NFSv4 idmapping when using 'sec=sys'");
2703module_param(max_session_slots, ushort, 0644);
2704MODULE_PARM_DESC(max_session_slots, "Maximum number of outstanding NFSv4.1 "
2705 "requests the client will negotiate");
2706module_param(send_implementation_id, ushort, 0644);
2707MODULE_PARM_DESC(send_implementation_id,
2708 "Send implementation ID with NFSv4.1 exchange_id");
Chuck Lever6f2ea7f2012-09-14 17:24:41 -04002709MODULE_PARM_DESC(nfs4_unique_id, "nfs_client_id4 uniquifier string");
bjschuma@gmail.com425e7762012-08-08 13:57:10 -04002710MODULE_ALIAS("nfs4");
2711
David Howells54ceac42006-08-22 20:06:13 -04002712#endif /* CONFIG_NFS_V4 */