blob: 652d3f7176a98fcc4e70e6f5e3d812e4b3d90b83 [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>
Weston Andros Adamson324d0032012-10-30 17:01:39 -040057#include <linux/kthread.h>
David Howellsf7b422b2006-06-09 09:34:33 -040058
David Howellsf7b422b2006-06-09 09:34:33 -040059#include <asm/uaccess.h>
60
61#include "nfs4_fs.h"
62#include "callback.h"
63#include "delegation.h"
64#include "iostat.h"
65#include "internal.h"
David Howells08734042009-04-03 16:42:42 +010066#include "fscache.h"
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +030067#include "pnfs.h"
Bryan Schumakerab7017a2012-07-30 16:05:16 -040068#include "nfs.h"
David Howellsf7b422b2006-06-09 09:34:33 -040069
70#define NFSDBG_FACILITY NFSDBG_VFS
Bryan Schumakerb72e4f42012-05-10 15:07:40 -040071#define NFS_TEXT_DATA 1
David Howellsf7b422b2006-06-09 09:34:33 -040072
Bryan Schumaker1c606fb2012-07-30 16:05:24 -040073#if IS_ENABLED(CONFIG_NFS_V3)
Paulius Zaleckas1e657bd2010-10-31 18:21:05 +020074#define NFS_DEFAULT_VERSION 3
75#else
76#define NFS_DEFAULT_VERSION 2
77#endif
78
Chuck Leverbf0fd762007-07-01 12:13:44 -040079enum {
80 /* Mount options that take no arguments */
81 Opt_soft, Opt_hard,
Chuck Leverbf0fd762007-07-01 12:13:44 -040082 Opt_posix, Opt_noposix,
83 Opt_cto, Opt_nocto,
84 Opt_ac, Opt_noac,
85 Opt_lock, Opt_nolock,
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -040086 Opt_udp, Opt_tcp, Opt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -040087 Opt_acl, Opt_noacl,
88 Opt_rdirplus, Opt_nordirplus,
Trond Myklebust75180df2007-05-16 16:53:28 -040089 Opt_sharecache, Opt_nosharecache,
Chuck Leverd7403512008-12-23 15:21:37 -050090 Opt_resvport, Opt_noresvport,
David Howellsb797cac2009-04-03 16:42:48 +010091 Opt_fscache, Opt_nofscache,
Chuck Lever89652612012-09-14 17:24:11 -040092 Opt_migration, Opt_nomigration,
Chuck Leverbf0fd762007-07-01 12:13:44 -040093
94 /* Mount options that take integer arguments */
95 Opt_port,
96 Opt_rsize, Opt_wsize, Opt_bsize,
97 Opt_timeo, Opt_retrans,
98 Opt_acregmin, Opt_acregmax,
99 Opt_acdirmin, Opt_acdirmax,
100 Opt_actimeo,
101 Opt_namelen,
102 Opt_mountport,
Chuck Levere887cbc2007-10-26 13:32:29 -0400103 Opt_mountvers,
Mike Sager3fd5be92009-04-01 09:21:48 -0400104 Opt_minorversion,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400105
106 /* Mount options that take string arguments */
Trond Myklebust0d71b052012-03-02 13:59:49 -0500107 Opt_nfsvers,
Chuck Lever33832032007-12-10 14:59:13 -0500108 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
Chuck Lever0ac83772007-09-11 18:01:04 -0400109 Opt_addr, Opt_mountaddr, Opt_clientaddr,
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400110 Opt_lookupcache,
David Howellsb797cac2009-04-03 16:42:48 +0100111 Opt_fscache_uniq,
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400112 Opt_local_lock,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400113
Chuck Leverf45663c2008-06-24 19:28:02 -0400114 /* Special mount options */
115 Opt_userspace, Opt_deprecated, Opt_sloppy,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400116
117 Opt_err
118};
119
Steven Whitehousea447c092008-10-13 10:46:57 +0100120static const match_table_t nfs_mount_option_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400121 { Opt_userspace, "bg" },
122 { Opt_userspace, "fg" },
Chuck Leverecbb3842008-06-12 12:37:33 -0400123 { Opt_userspace, "retry=%s" },
124
Chuck Leverf45663c2008-06-24 19:28:02 -0400125 { Opt_sloppy, "sloppy" },
126
Chuck Leverbf0fd762007-07-01 12:13:44 -0400127 { Opt_soft, "soft" },
128 { Opt_hard, "hard" },
Chuck Leverd33e4df2008-06-12 12:37:41 -0400129 { Opt_deprecated, "intr" },
130 { Opt_deprecated, "nointr" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400131 { Opt_posix, "posix" },
132 { Opt_noposix, "noposix" },
133 { Opt_cto, "cto" },
134 { Opt_nocto, "nocto" },
135 { Opt_ac, "ac" },
136 { Opt_noac, "noac" },
137 { Opt_lock, "lock" },
138 { Opt_nolock, "nolock" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400139 { Opt_udp, "udp" },
140 { Opt_tcp, "tcp" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400141 { Opt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400142 { Opt_acl, "acl" },
143 { Opt_noacl, "noacl" },
144 { Opt_rdirplus, "rdirplus" },
145 { Opt_nordirplus, "nordirplus" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400146 { Opt_sharecache, "sharecache" },
147 { Opt_nosharecache, "nosharecache" },
Chuck Leverd7403512008-12-23 15:21:37 -0500148 { Opt_resvport, "resvport" },
149 { Opt_noresvport, "noresvport" },
David Howellsb797cac2009-04-03 16:42:48 +0100150 { Opt_fscache, "fsc" },
David Howellsb797cac2009-04-03 16:42:48 +0100151 { Opt_nofscache, "nofsc" },
Chuck Lever89652612012-09-14 17:24:11 -0400152 { Opt_migration, "migration" },
153 { Opt_nomigration, "nomigration" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400154
Chuck Levera5a16ba2009-06-17 18:02:14 -0700155 { Opt_port, "port=%s" },
156 { Opt_rsize, "rsize=%s" },
157 { Opt_wsize, "wsize=%s" },
158 { Opt_bsize, "bsize=%s" },
159 { Opt_timeo, "timeo=%s" },
160 { Opt_retrans, "retrans=%s" },
161 { Opt_acregmin, "acregmin=%s" },
162 { Opt_acregmax, "acregmax=%s" },
163 { Opt_acdirmin, "acdirmin=%s" },
164 { Opt_acdirmax, "acdirmax=%s" },
165 { Opt_actimeo, "actimeo=%s" },
166 { Opt_namelen, "namlen=%s" },
167 { Opt_mountport, "mountport=%s" },
168 { Opt_mountvers, "mountvers=%s" },
Trond Myklebust0d71b052012-03-02 13:59:49 -0500169 { Opt_minorversion, "minorversion=%s" },
170
Chuck Levera5a16ba2009-06-17 18:02:14 -0700171 { Opt_nfsvers, "nfsvers=%s" },
172 { Opt_nfsvers, "vers=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400173
174 { Opt_sec, "sec=%s" },
175 { Opt_proto, "proto=%s" },
176 { Opt_mountproto, "mountproto=%s" },
177 { Opt_addr, "addr=%s" },
178 { Opt_clientaddr, "clientaddr=%s" },
Chuck Lever33832032007-12-10 14:59:13 -0500179 { Opt_mounthost, "mounthost=%s" },
Chuck Lever0ac83772007-09-11 18:01:04 -0400180 { Opt_mountaddr, "mountaddr=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400181
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400182 { Opt_lookupcache, "lookupcache=%s" },
Chuck Levera6d5ff62010-05-07 13:33:58 -0400183 { Opt_fscache_uniq, "fsc=%s" },
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400184 { Opt_local_lock, "local_lock=%s" },
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400185
Trond Myklebust38622792012-03-02 14:06:39 -0500186 /* The following needs to be listed after all other options */
187 { Opt_nfsvers, "v%s" },
188
Chuck Leverbf0fd762007-07-01 12:13:44 -0400189 { Opt_err, NULL }
190};
191
192enum {
Jeff Laytonee671b02009-12-03 15:58:56 -0500193 Opt_xprt_udp, Opt_xprt_udp6, Opt_xprt_tcp, Opt_xprt_tcp6, Opt_xprt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400194
195 Opt_xprt_err
196};
197
Steven Whitehousea447c092008-10-13 10:46:57 +0100198static const match_table_t nfs_xprt_protocol_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400199 { Opt_xprt_udp, "udp" },
Jeff Laytonee671b02009-12-03 15:58:56 -0500200 { Opt_xprt_udp6, "udp6" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400201 { Opt_xprt_tcp, "tcp" },
Jeff Laytonee671b02009-12-03 15:58:56 -0500202 { Opt_xprt_tcp6, "tcp6" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400203 { Opt_xprt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400204
205 { Opt_xprt_err, NULL }
206};
207
208enum {
209 Opt_sec_none, Opt_sec_sys,
210 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
211 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
212 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
213
214 Opt_sec_err
215};
216
Steven Whitehousea447c092008-10-13 10:46:57 +0100217static const match_table_t nfs_secflavor_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400218 { Opt_sec_none, "none" },
219 { Opt_sec_none, "null" },
220 { Opt_sec_sys, "sys" },
221
222 { Opt_sec_krb5, "krb5" },
223 { Opt_sec_krb5i, "krb5i" },
224 { Opt_sec_krb5p, "krb5p" },
225
226 { Opt_sec_lkey, "lkey" },
227 { Opt_sec_lkeyi, "lkeyi" },
228 { Opt_sec_lkeyp, "lkeyp" },
229
Olga Kornievskaia8d042212008-02-13 16:47:06 -0500230 { Opt_sec_spkm, "spkm3" },
231 { Opt_sec_spkmi, "spkm3i" },
232 { Opt_sec_spkmp, "spkm3p" },
233
Chuck Leverbf0fd762007-07-01 12:13:44 -0400234 { Opt_sec_err, NULL }
235};
236
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400237enum {
238 Opt_lookupcache_all, Opt_lookupcache_positive,
239 Opt_lookupcache_none,
240
241 Opt_lookupcache_err
242};
243
244static match_table_t nfs_lookupcache_tokens = {
245 { Opt_lookupcache_all, "all" },
246 { Opt_lookupcache_positive, "pos" },
247 { Opt_lookupcache_positive, "positive" },
248 { Opt_lookupcache_none, "none" },
249
250 { Opt_lookupcache_err, NULL }
251};
252
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400253enum {
254 Opt_local_lock_all, Opt_local_lock_flock, Opt_local_lock_posix,
255 Opt_local_lock_none,
256
257 Opt_local_lock_err
258};
259
260static match_table_t nfs_local_lock_tokens = {
261 { Opt_local_lock_all, "all" },
262 { Opt_local_lock_flock, "flock" },
263 { Opt_local_lock_posix, "posix" },
264 { Opt_local_lock_none, "none" },
265
266 { Opt_local_lock_err, NULL }
267};
268
Trond Myklebust0d71b052012-03-02 13:59:49 -0500269enum {
270 Opt_vers_2, Opt_vers_3, Opt_vers_4, Opt_vers_4_0,
271 Opt_vers_4_1,
272
273 Opt_vers_err
274};
275
276static match_table_t nfs_vers_tokens = {
277 { Opt_vers_2, "2" },
278 { Opt_vers_3, "3" },
279 { Opt_vers_4, "4" },
280 { Opt_vers_4_0, "4.0" },
281 { Opt_vers_4_1, "4.1" },
282
283 { Opt_vers_err, NULL }
284};
Chuck Leverbf0fd762007-07-01 12:13:44 -0400285
Al Viro31f43472010-10-29 03:38:12 -0400286static struct dentry *nfs_xdev_mount(struct file_system_type *fs_type,
287 int flags, const char *dev_name, void *raw_data);
David Howellsf7b422b2006-06-09 09:34:33 -0400288
Bryan Schumakerab7017a2012-07-30 16:05:16 -0400289struct file_system_type nfs_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400290 .owner = THIS_MODULE,
291 .name = "nfs",
Al Viro01194982011-03-16 07:25:36 -0400292 .mount = nfs_fs_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400293 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700294 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400295};
Bryan Schumakerddda8e02012-07-30 16:05:23 -0400296EXPORT_SYMBOL_GPL(nfs_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400297
David Howells54ceac42006-08-22 20:06:13 -0400298struct file_system_type nfs_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400299 .owner = THIS_MODULE,
300 .name = "nfs",
Al Viro31f43472010-10-29 03:38:12 -0400301 .mount = nfs_xdev_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400302 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700303 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400304};
305
Bryan Schumaker6a744902012-07-30 16:05:20 -0400306const struct super_operations nfs_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400307 .alloc_inode = nfs_alloc_inode,
308 .destroy_inode = nfs_destroy_inode,
309 .write_inode = nfs_write_inode,
Trond Myklebust387c1492010-02-03 08:27:35 -0500310 .put_super = nfs_put_super,
David Howellsf7b422b2006-06-09 09:34:33 -0400311 .statfs = nfs_statfs,
Al Virob57922d2010-06-07 14:34:48 -0400312 .evict_inode = nfs_evict_inode,
David Howellsf7b422b2006-06-09 09:34:33 -0400313 .umount_begin = nfs_umount_begin,
314 .show_options = nfs_show_options,
Al Viroc7f404b2011-03-16 06:59:40 -0400315 .show_devname = nfs_show_devname,
316 .show_path = nfs_show_path,
David Howellsf7b422b2006-06-09 09:34:33 -0400317 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400318 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400319};
Bryan Schumakerddda8e02012-07-30 16:05:23 -0400320EXPORT_SYMBOL_GPL(nfs_sops);
David Howellsf7b422b2006-06-09 09:34:33 -0400321
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400322#if IS_ENABLED(CONFIG_NFS_V4)
Bryan Schumakerb72e4f42012-05-10 15:07:40 -0400323static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *);
Bryan Schumakerd72c7272012-05-10 15:07:41 -0400324static int nfs4_validate_mount_data(void *options,
325 struct nfs_parsed_mount_data *args, const char *dev_name);
bjschuma@gmail.com1ae811e2012-08-08 13:57:06 -0400326
327struct file_system_type nfs4_fs_type = {
328 .owner = THIS_MODULE,
329 .name = "nfs4",
330 .mount = nfs_fs_mount,
331 .kill_sb = nfs_kill_super,
332 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
333};
334EXPORT_SYMBOL_GPL(nfs4_fs_type);
335
336static int __init register_nfs4_fs(void)
337{
338 return register_filesystem(&nfs4_fs_type);
339}
340
341static void unregister_nfs4_fs(void)
342{
343 unregister_filesystem(&nfs4_fs_type);
344}
345#else
346static int __init register_nfs4_fs(void)
347{
348 return 0;
349}
350
351static void unregister_nfs4_fs(void)
352{
353}
David Howellsf7b422b2006-06-09 09:34:33 -0400354#endif
355
Rusty Russell8e1f9362007-07-17 04:03:17 -0700356static struct shrinker acl_shrinker = {
357 .shrink = nfs_access_cache_shrinker,
358 .seeks = DEFAULT_SEEKS,
359};
Trond Myklebust979df722006-07-25 11:28:19 -0400360
David Howellsf7b422b2006-06-09 09:34:33 -0400361/*
362 * Register the NFS filesystems
363 */
364int __init register_nfs_fs(void)
365{
366 int ret;
367
368 ret = register_filesystem(&nfs_fs_type);
369 if (ret < 0)
370 goto error_0;
371
bjschuma@gmail.com1ae811e2012-08-08 13:57:06 -0400372 ret = register_nfs4_fs();
David Howellsf7b422b2006-06-09 09:34:33 -0400373 if (ret < 0)
374 goto error_1;
bjschuma@gmail.com1ae811e2012-08-08 13:57:06 -0400375
376 ret = nfs_register_sysctl();
377 if (ret < 0)
378 goto error_2;
Rusty Russell8e1f9362007-07-17 04:03:17 -0700379 register_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400380 return 0;
381
bjschuma@gmail.com1ae811e2012-08-08 13:57:06 -0400382error_2:
383 unregister_nfs4_fs();
David Howellsf7b422b2006-06-09 09:34:33 -0400384error_1:
385 unregister_filesystem(&nfs_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400386error_0:
387 return ret;
388}
389
390/*
391 * Unregister the NFS filesystems
392 */
393void __exit unregister_nfs_fs(void)
394{
Rusty Russell8e1f9362007-07-17 04:03:17 -0700395 unregister_shrinker(&acl_shrinker);
Alexey Dobriyan49af7ee2007-09-18 22:46:40 -0700396 nfs_unregister_sysctl();
bjschuma@gmail.com1ae811e2012-08-08 13:57:06 -0400397 unregister_nfs4_fs();
David Howellsf7b422b2006-06-09 09:34:33 -0400398 unregister_filesystem(&nfs_fs_type);
399}
400
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400401void nfs_sb_active(struct super_block *sb)
Steve Dicksonef818a22007-11-08 04:05:04 -0500402{
403 struct nfs_server *server = NFS_SB(sb);
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400404
405 if (atomic_inc_return(&server->active) == 1)
406 atomic_inc(&sb->s_active);
407}
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400408EXPORT_SYMBOL_GPL(nfs_sb_active);
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400409
410void nfs_sb_deactive(struct super_block *sb)
411{
412 struct nfs_server *server = NFS_SB(sb);
413
414 if (atomic_dec_and_test(&server->active))
415 deactivate_super(sb);
Steve Dicksonef818a22007-11-08 04:05:04 -0500416}
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400417EXPORT_SYMBOL_GPL(nfs_sb_deactive);
Steve Dicksonef818a22007-11-08 04:05:04 -0500418
Weston Andros Adamson324d0032012-10-30 17:01:39 -0400419static int nfs_deactivate_super_async_work(void *ptr)
420{
421 struct super_block *sb = ptr;
422
423 deactivate_super(sb);
424 module_put_and_exit(0);
425 return 0;
426}
427
428/*
429 * same effect as deactivate_super, but will do final unmount in kthread
430 * context
431 */
432static void nfs_deactivate_super_async(struct super_block *sb)
433{
434 struct task_struct *task;
435 char buf[INET6_ADDRSTRLEN + 1];
436 struct nfs_server *server = NFS_SB(sb);
437 struct nfs_client *clp = server->nfs_client;
438
439 if (!atomic_add_unless(&sb->s_active, -1, 1)) {
440 rcu_read_lock();
441 snprintf(buf, sizeof(buf),
442 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR));
443 rcu_read_unlock();
444
445 __module_get(THIS_MODULE);
446 task = kthread_run(nfs_deactivate_super_async_work, sb,
447 "%s-deactivate-super", buf);
448 if (IS_ERR(task)) {
449 pr_err("%s: kthread_run: %ld\n",
450 __func__, PTR_ERR(task));
451 /* make synchronous call and hope for the best */
452 deactivate_super(sb);
453 module_put(THIS_MODULE);
454 }
455 }
456}
457
458void nfs_sb_deactive_async(struct super_block *sb)
459{
460 struct nfs_server *server = NFS_SB(sb);
461
462 if (atomic_dec_and_test(&server->active))
463 nfs_deactivate_super_async(sb);
464}
465EXPORT_SYMBOL_GPL(nfs_sb_deactive_async);
466
David Howellsf7b422b2006-06-09 09:34:33 -0400467/*
468 * Deliver file system statistics to userspace
469 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -0400470int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
David Howellsf7b422b2006-06-09 09:34:33 -0400471{
David Howells0c7d90c2006-08-22 20:06:10 -0400472 struct nfs_server *server = NFS_SB(dentry->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400473 unsigned char blockbits;
474 unsigned long blockres;
David Howells0c7d90c2006-08-22 20:06:10 -0400475 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400476 struct nfs_fsstat res;
477 int error = -ENOMEM;
478
479 res.fattr = nfs_alloc_fattr();
480 if (res.fattr == NULL)
481 goto out_err;
David Howellsf7b422b2006-06-09 09:34:33 -0400482
David Howells8fa5c002006-08-22 20:06:12 -0400483 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
Menyhart Zoltanfbf3fdd2010-09-12 19:55:26 -0400484 if (unlikely(error == -ESTALE)) {
485 struct dentry *pd_dentry;
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400486
Menyhart Zoltanfbf3fdd2010-09-12 19:55:26 -0400487 pd_dentry = dget_parent(dentry);
488 if (pd_dentry != NULL) {
489 nfs_zap_caches(pd_dentry->d_inode);
490 dput(pd_dentry);
491 }
492 }
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400493 nfs_free_fattr(res.fattr);
David Howellsf7b422b2006-06-09 09:34:33 -0400494 if (error < 0)
495 goto out_err;
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400496
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700497 buf->f_type = NFS_SUPER_MAGIC;
David Howellsf7b422b2006-06-09 09:34:33 -0400498
499 /*
500 * Current versions of glibc do not correctly handle the
501 * case where f_frsize != f_bsize. Eventually we want to
502 * report the value of wtmult in this field.
503 */
David Howells0c7d90c2006-08-22 20:06:10 -0400504 buf->f_frsize = dentry->d_sb->s_blocksize;
David Howellsf7b422b2006-06-09 09:34:33 -0400505
506 /*
507 * On most *nix systems, f_blocks, f_bfree, and f_bavail
508 * are reported in units of f_frsize. Linux hasn't had
509 * an f_frsize field in its statfs struct until recently,
510 * thus historically Linux's sys_statfs reports these
511 * fields in units of f_bsize.
512 */
David Howells0c7d90c2006-08-22 20:06:10 -0400513 buf->f_bsize = dentry->d_sb->s_blocksize;
514 blockbits = dentry->d_sb->s_blocksize_bits;
David Howellsf7b422b2006-06-09 09:34:33 -0400515 blockres = (1 << blockbits) - 1;
516 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
517 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
518 buf->f_bavail = (res.abytes + blockres) >> blockbits;
519
520 buf->f_files = res.tfiles;
521 buf->f_ffree = res.afiles;
522
523 buf->f_namelen = server->namelen;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700524
David Howellsf7b422b2006-06-09 09:34:33 -0400525 return 0;
526
527 out_err:
Harvey Harrison3110ff82008-05-02 13:42:44 -0700528 dprintk("%s: statfs error = %d\n", __func__, -error);
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700529 return error;
David Howellsf7b422b2006-06-09 09:34:33 -0400530}
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400531EXPORT_SYMBOL_GPL(nfs_statfs);
David Howellsf7b422b2006-06-09 09:34:33 -0400532
David Howells7d4e2742006-08-22 20:06:07 -0400533/*
534 * Map the security flavour number to a name
535 */
Trond Myklebust81039f12006-06-09 09:34:34 -0400536static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
537{
David Howells7d4e2742006-08-22 20:06:07 -0400538 static const struct {
Trond Myklebust81039f12006-06-09 09:34:34 -0400539 rpc_authflavor_t flavour;
540 const char *str;
541 } sec_flavours[] = {
542 { RPC_AUTH_NULL, "null" },
543 { RPC_AUTH_UNIX, "sys" },
544 { RPC_AUTH_GSS_KRB5, "krb5" },
545 { RPC_AUTH_GSS_KRB5I, "krb5i" },
546 { RPC_AUTH_GSS_KRB5P, "krb5p" },
547 { RPC_AUTH_GSS_LKEY, "lkey" },
548 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
549 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
550 { RPC_AUTH_GSS_SPKM, "spkm" },
551 { RPC_AUTH_GSS_SPKMI, "spkmi" },
552 { RPC_AUTH_GSS_SPKMP, "spkmp" },
Chuck Lever4d81cd12007-07-01 12:12:40 -0400553 { UINT_MAX, "unknown" }
Trond Myklebust81039f12006-06-09 09:34:34 -0400554 };
555 int i;
556
Chuck Lever4d81cd12007-07-01 12:12:40 -0400557 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
Trond Myklebust81039f12006-06-09 09:34:34 -0400558 if (sec_flavours[i].flavour == flavour)
559 break;
560 }
561 return sec_flavours[i].str;
562}
563
Jeff Laytonee671b02009-12-03 15:58:56 -0500564static void nfs_show_mountd_netid(struct seq_file *m, struct nfs_server *nfss,
565 int showdefaults)
566{
567 struct sockaddr *sap = (struct sockaddr *) &nfss->mountd_address;
568
569 seq_printf(m, ",mountproto=");
570 switch (sap->sa_family) {
571 case AF_INET:
572 switch (nfss->mountd_protocol) {
573 case IPPROTO_UDP:
574 seq_printf(m, RPCBIND_NETID_UDP);
575 break;
576 case IPPROTO_TCP:
577 seq_printf(m, RPCBIND_NETID_TCP);
578 break;
579 default:
580 if (showdefaults)
581 seq_printf(m, "auto");
582 }
583 break;
584 case AF_INET6:
585 switch (nfss->mountd_protocol) {
586 case IPPROTO_UDP:
587 seq_printf(m, RPCBIND_NETID_UDP6);
588 break;
589 case IPPROTO_TCP:
590 seq_printf(m, RPCBIND_NETID_TCP6);
591 break;
592 default:
593 if (showdefaults)
594 seq_printf(m, "auto");
595 }
596 break;
597 default:
598 if (showdefaults)
599 seq_printf(m, "auto");
600 }
601}
602
Chuck Lever82d101d2008-03-14 14:10:37 -0400603static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
604 int showdefaults)
605{
606 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
607
Bryan Schumakerd5eff1a2010-08-03 13:04:00 -0400608 if (nfss->flags & NFS_MOUNT_LEGACY_INTERFACE)
609 return;
610
Chuck Lever82d101d2008-03-14 14:10:37 -0400611 switch (sap->sa_family) {
612 case AF_INET: {
613 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
Harvey Harrisonbe859402008-10-31 00:56:28 -0700614 seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400615 break;
616 }
617 case AF_INET6: {
618 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
Chuck Leverd250e192009-12-03 15:58:56 -0500619 seq_printf(m, ",mountaddr=%pI6c", &sin6->sin6_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400620 break;
621 }
622 default:
623 if (showdefaults)
624 seq_printf(m, ",mountaddr=unspecified");
625 }
626
627 if (nfss->mountd_version || showdefaults)
628 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
Stanislav Kinsburskyaa699472010-12-08 12:40:13 +0300629 if ((nfss->mountd_port &&
630 nfss->mountd_port != (unsigned short)NFS_UNSPEC_PORT) ||
631 showdefaults)
Chuck Lever82d101d2008-03-14 14:10:37 -0400632 seq_printf(m, ",mountport=%u", nfss->mountd_port);
633
Jeff Laytonee671b02009-12-03 15:58:56 -0500634 nfs_show_mountd_netid(m, nfss, showdefaults);
Chuck Lever82d101d2008-03-14 14:10:37 -0400635}
636
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400637#if IS_ENABLED(CONFIG_NFS_V4)
Trond Myklebust0be81892010-06-18 12:23:58 -0400638static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
639 int showdefaults)
640{
641 struct nfs_client *clp = nfss->nfs_client;
642
643 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
Trond Myklebust0be81892010-06-18 12:23:58 -0400644}
645#else
646static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
647 int showdefaults)
648{
649}
650#endif
651
Trond Myklebust7bbceb62012-03-02 14:00:20 -0500652static void nfs_show_nfs_version(struct seq_file *m,
653 unsigned int version,
654 unsigned int minorversion)
655{
656 seq_printf(m, ",vers=%u", version);
657 if (version == 4)
658 seq_printf(m, ".%u", minorversion);
659}
660
David Howellsf7b422b2006-06-09 09:34:33 -0400661/*
662 * Describe the mount options in force on this server representation
663 */
Chuck Lever82d101d2008-03-14 14:10:37 -0400664static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
665 int showdefaults)
David Howellsf7b422b2006-06-09 09:34:33 -0400666{
David Howells509de812006-08-22 20:06:11 -0400667 static const struct proc_nfs_info {
David Howellsf7b422b2006-06-09 09:34:33 -0400668 int flag;
David Howells509de812006-08-22 20:06:11 -0400669 const char *str;
670 const char *nostr;
David Howellsf7b422b2006-06-09 09:34:33 -0400671 } nfs_info[] = {
672 { NFS_MOUNT_SOFT, ",soft", ",hard" },
Chuck Lever82d101d2008-03-14 14:10:37 -0400673 { NFS_MOUNT_POSIX, ",posix", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400674 { NFS_MOUNT_NOCTO, ",nocto", "" },
675 { NFS_MOUNT_NOAC, ",noac", "" },
676 { NFS_MOUNT_NONLM, ",nolock", "" },
677 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400678 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
Chuck Leverd7403512008-12-23 15:21:37 -0500679 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
680 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400681 { 0, NULL, NULL }
682 };
David Howells509de812006-08-22 20:06:11 -0400683 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400684 struct nfs_client *clp = nfss->nfs_client;
Chuck Lever82d101d2008-03-14 14:10:37 -0400685 u32 version = clp->rpc_ops->version;
Suresh Jayaraman7c563cc2010-09-23 14:26:48 -0400686 int local_flock, local_fcntl;
David Howellsf7b422b2006-06-09 09:34:33 -0400687
Trond Myklebust7bbceb62012-03-02 14:00:20 -0500688 nfs_show_nfs_version(m, version, clp->cl_minorversion);
Chuck Lever2d767432008-03-14 14:10:08 -0400689 seq_printf(m, ",rsize=%u", nfss->rsize);
690 seq_printf(m, ",wsize=%u", nfss->wsize);
Chuck Lever82d101d2008-03-14 14:10:37 -0400691 if (nfss->bsize != 0)
692 seq_printf(m, ",bsize=%u", nfss->bsize);
693 seq_printf(m, ",namlen=%u", nfss->namelen);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400694 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400695 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400696 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400697 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400698 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400699 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400700 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400701 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
David Howellsf7b422b2006-06-09 09:34:33 -0400702 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
703 if (nfss->flags & nfs_infop->flag)
704 seq_puts(m, nfs_infop->str);
705 else
706 seq_puts(m, nfs_infop->nostr);
707 }
Trond Myklebust2446ab62012-03-01 17:00:56 -0500708 rcu_read_lock();
\"Talpey, Thomas\56928ed2007-09-10 13:48:47 -0400709 seq_printf(m, ",proto=%s",
Jeff Laytonee671b02009-12-03 15:58:56 -0500710 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
Trond Myklebust2446ab62012-03-01 17:00:56 -0500711 rcu_read_unlock();
Chuck Lever82d101d2008-03-14 14:10:37 -0400712 if (version == 4) {
713 if (nfss->port != NFS_PORT)
714 seq_printf(m, ",port=%u", nfss->port);
715 } else
716 if (nfss->port)
717 seq_printf(m, ",port=%u", nfss->port);
718
Trond Myklebust33170232007-12-20 16:03:59 -0500719 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
720 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
Trond Myklebust81039f12006-06-09 09:34:34 -0400721 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
Chuck Lever82d101d2008-03-14 14:10:37 -0400722
723 if (version != 4)
724 nfs_show_mountd_options(m, nfss, showdefaults);
Trond Myklebust0be81892010-06-18 12:23:58 -0400725 else
726 nfs_show_nfsv4_options(m, nfss, showdefaults);
Chuck Lever82d101d2008-03-14 14:10:37 -0400727
David Howellsb797cac2009-04-03 16:42:48 +0100728 if (nfss->options & NFS_OPTION_FSCACHE)
729 seq_printf(m, ",fsc");
Patrick J. LoPresti9b00c642010-08-10 17:28:01 -0400730
Chuck Lever89652612012-09-14 17:24:11 -0400731 if (nfss->options & NFS_OPTION_MIGRATION)
732 seq_printf(m, ",migration");
733
Patrick J. LoPresti9b00c642010-08-10 17:28:01 -0400734 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONEG) {
735 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONE)
736 seq_printf(m, ",lookupcache=none");
737 else
738 seq_printf(m, ",lookupcache=pos");
739 }
Suresh Jayaraman7c563cc2010-09-23 14:26:48 -0400740
741 local_flock = nfss->flags & NFS_MOUNT_LOCAL_FLOCK;
742 local_fcntl = nfss->flags & NFS_MOUNT_LOCAL_FCNTL;
743
744 if (!local_flock && !local_fcntl)
745 seq_printf(m, ",local_lock=none");
746 else if (local_flock && local_fcntl)
747 seq_printf(m, ",local_lock=all");
748 else if (local_flock)
749 seq_printf(m, ",local_lock=flock");
750 else
751 seq_printf(m, ",local_lock=posix");
David Howellsf7b422b2006-06-09 09:34:33 -0400752}
753
754/*
755 * Describe the mount options on this VFS mountpoint
756 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -0400757int nfs_show_options(struct seq_file *m, struct dentry *root)
David Howellsf7b422b2006-06-09 09:34:33 -0400758{
Al Viro34c80b12011-12-08 21:32:45 -0500759 struct nfs_server *nfss = NFS_SB(root->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400760
761 nfs_show_mount_options(m, nfss, 0);
762
Trond Myklebust2446ab62012-03-01 17:00:56 -0500763 rcu_read_lock();
Chuck Lever5d8515c2007-12-10 14:57:16 -0500764 seq_printf(m, ",addr=%s",
765 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
766 RPC_DISPLAY_ADDR));
Trond Myklebust2446ab62012-03-01 17:00:56 -0500767 rcu_read_unlock();
David Howellsf7b422b2006-06-09 09:34:33 -0400768
769 return 0;
770}
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400771EXPORT_SYMBOL_GPL(nfs_show_options);
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700772
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400773#if IS_ENABLED(CONFIG_NFS_V4)
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300774#ifdef CONFIG_NFS_V4_1
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700775static void show_sessions(struct seq_file *m, struct nfs_server *server)
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300776{
777 if (nfs4_has_session(server->nfs_client))
778 seq_printf(m, ",sessions");
779}
780#else
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700781static void show_sessions(struct seq_file *m, struct nfs_server *server) {}
782#endif
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300783#endif
784
785#ifdef CONFIG_NFS_V4_1
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700786static void show_pnfs(struct seq_file *m, struct nfs_server *server)
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300787{
788 seq_printf(m, ",pnfs=");
789 if (server->pnfs_curr_ld)
790 seq_printf(m, "%s", server->pnfs_curr_ld->name);
791 else
792 seq_printf(m, "not configured");
793}
Trond Myklebust7e03b7c2012-03-04 18:12:57 -0500794
795static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
796{
Chuck Lever59155542012-05-21 22:44:41 -0400797 if (nfss->nfs_client && nfss->nfs_client->cl_implid) {
798 struct nfs41_impl_id *impl_id = nfss->nfs_client->cl_implid;
Trond Myklebust7e03b7c2012-03-04 18:12:57 -0500799 seq_printf(m, "\n\timpl_id:\tname='%s',domain='%s',"
800 "date='%llu,%u'",
801 impl_id->name, impl_id->domain,
802 impl_id->date.seconds, impl_id->date.nseconds);
803 }
804}
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700805#else
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400806#if IS_ENABLED(CONFIG_NFS_V4)
Trond Myklebust7e03b7c2012-03-04 18:12:57 -0500807static void show_pnfs(struct seq_file *m, struct nfs_server *server)
808{
809}
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700810#endif
Trond Myklebust7e03b7c2012-03-04 18:12:57 -0500811static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
812{
813}
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700814#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400815
Bryan Schumakerfbdefd62012-07-16 16:39:20 -0400816int nfs_show_devname(struct seq_file *m, struct dentry *root)
Al Viroc7f404b2011-03-16 06:59:40 -0400817{
818 char *page = (char *) __get_free_page(GFP_KERNEL);
819 char *devname, *dummy;
820 int err = 0;
821 if (!page)
822 return -ENOMEM;
Ben Hutchings97a54862012-10-21 19:23:52 +0100823 devname = nfs_path(&dummy, root, page, PAGE_SIZE, 0);
Al Viroc7f404b2011-03-16 06:59:40 -0400824 if (IS_ERR(devname))
825 err = PTR_ERR(devname);
826 else
827 seq_escape(m, devname, " \t\n\\");
828 free_page((unsigned long)page);
829 return err;
830}
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400831EXPORT_SYMBOL_GPL(nfs_show_devname);
Al Viroc7f404b2011-03-16 06:59:40 -0400832
Bryan Schumakerfbdefd62012-07-16 16:39:20 -0400833int nfs_show_path(struct seq_file *m, struct dentry *dentry)
Al Viroc7f404b2011-03-16 06:59:40 -0400834{
835 seq_puts(m, "/");
836 return 0;
837}
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400838EXPORT_SYMBOL_GPL(nfs_show_path);
Al Viroc7f404b2011-03-16 06:59:40 -0400839
David Howellsf7b422b2006-06-09 09:34:33 -0400840/*
841 * Present statistical information for this VFS mountpoint
842 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -0400843int nfs_show_stats(struct seq_file *m, struct dentry *root)
David Howellsf7b422b2006-06-09 09:34:33 -0400844{
845 int i, cpu;
Al Viro64132372011-12-08 20:51:13 -0500846 struct nfs_server *nfss = NFS_SB(root->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400847 struct rpc_auth *auth = nfss->client->cl_auth;
848 struct nfs_iostats totals = { };
849
850 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
851
852 /*
853 * Display all mount option settings
854 */
855 seq_printf(m, "\n\topts:\t");
Al Viro64132372011-12-08 20:51:13 -0500856 seq_puts(m, root->d_sb->s_flags & MS_RDONLY ? "ro" : "rw");
857 seq_puts(m, root->d_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
858 seq_puts(m, root->d_sb->s_flags & MS_NOATIME ? ",noatime" : "");
859 seq_puts(m, root->d_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
David Howellsf7b422b2006-06-09 09:34:33 -0400860 nfs_show_mount_options(m, nfss, 1);
861
862 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
863
Trond Myklebust7e03b7c2012-03-04 18:12:57 -0500864 show_implementation_id(m, nfss);
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500865
David Howellsf7b422b2006-06-09 09:34:33 -0400866 seq_printf(m, "\n\tcaps:\t");
867 seq_printf(m, "caps=0x%x", nfss->caps);
Chuck Lever2d767432008-03-14 14:10:08 -0400868 seq_printf(m, ",wtmult=%u", nfss->wtmult);
869 seq_printf(m, ",dtsize=%u", nfss->dtsize);
870 seq_printf(m, ",bsize=%u", nfss->bsize);
871 seq_printf(m, ",namlen=%u", nfss->namelen);
David Howellsf7b422b2006-06-09 09:34:33 -0400872
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400873#if IS_ENABLED(CONFIG_NFS_V4)
Trond Myklebust40c553192007-12-14 14:56:07 -0500874 if (nfss->nfs_client->rpc_ops->version == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400875 seq_printf(m, "\n\tnfsv4:\t");
876 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
877 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
878 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300879 show_sessions(m, nfss);
880 show_pnfs(m, nfss);
David Howellsf7b422b2006-06-09 09:34:33 -0400881 }
882#endif
883
884 /*
885 * Display security flavor in effect for this mount
886 */
Chuck Lever2d767432008-03-14 14:10:08 -0400887 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400888 if (auth->au_flavor)
Chuck Lever2d767432008-03-14 14:10:08 -0400889 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400890
891 /*
892 * Display superblock I/O counters
893 */
894 for_each_possible_cpu(cpu) {
895 struct nfs_iostats *stats;
896
897 preempt_disable();
898 stats = per_cpu_ptr(nfss->io_stats, cpu);
899
900 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
901 totals.events[i] += stats->events[i];
902 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
903 totals.bytes[i] += stats->bytes[i];
David Howells6a510912009-04-03 16:42:43 +0100904#ifdef CONFIG_NFS_FSCACHE
905 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
906 totals.fscache[i] += stats->fscache[i];
907#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400908
909 preempt_enable();
910 }
911
912 seq_printf(m, "\n\tevents:\t");
913 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
914 seq_printf(m, "%lu ", totals.events[i]);
915 seq_printf(m, "\n\tbytes:\t");
916 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
917 seq_printf(m, "%Lu ", totals.bytes[i]);
David Howells6a510912009-04-03 16:42:43 +0100918#ifdef CONFIG_NFS_FSCACHE
919 if (nfss->options & NFS_OPTION_FSCACHE) {
920 seq_printf(m, "\n\tfsc:\t");
921 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
922 seq_printf(m, "%Lu ", totals.bytes[i]);
923 }
924#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400925 seq_printf(m, "\n");
926
927 rpc_print_iostats(m, nfss->client);
928
929 return 0;
930}
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400931EXPORT_SYMBOL_GPL(nfs_show_stats);
David Howellsf7b422b2006-06-09 09:34:33 -0400932
933/*
934 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400935 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400936 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -0400937void nfs_umount_begin(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -0400938{
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200939 struct nfs_server *server;
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400940 struct rpc_clnt *rpc;
941
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200942 server = NFS_SB(sb);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400943 /* -EIO all pending I/O */
944 rpc = server->client_acl;
945 if (!IS_ERR(rpc))
946 rpc_killall_tasks(rpc);
947 rpc = server->client;
948 if (!IS_ERR(rpc))
949 rpc_killall_tasks(rpc);
David Howellsf7b422b2006-06-09 09:34:33 -0400950}
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400951EXPORT_SYMBOL_GPL(nfs_umount_begin);
David Howellsf7b422b2006-06-09 09:34:33 -0400952
Bryan Schumakerdb833352012-05-10 15:07:38 -0400953static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(void)
Chuck Lever9423a082009-09-23 14:36:38 -0400954{
955 struct nfs_parsed_mount_data *data;
956
957 data = kzalloc(sizeof(*data), GFP_KERNEL);
958 if (data) {
Chuck Lever9423a082009-09-23 14:36:38 -0400959 data->acregmin = NFS_DEF_ACREGMIN;
960 data->acregmax = NFS_DEF_ACREGMAX;
961 data->acdirmin = NFS_DEF_ACDIRMIN;
962 data->acdirmax = NFS_DEF_ACDIRMAX;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400963 data->mount_server.port = NFS_UNSPEC_PORT;
Chuck Lever9423a082009-09-23 14:36:38 -0400964 data->nfs_server.port = NFS_UNSPEC_PORT;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400965 data->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Lever9423a082009-09-23 14:36:38 -0400966 data->auth_flavors[0] = RPC_AUTH_UNIX;
967 data->auth_flavor_len = 1;
968 data->minorversion = 0;
Bryan Schumakerb72e4f42012-05-10 15:07:40 -0400969 data->need_mount = true;
Trond Myklebust9937347a2012-02-19 08:44:07 +0100970 data->net = current->nsproxy->net_ns;
Jeff Layton8a0d5512011-12-20 06:57:45 -0500971 security_init_mnt_opts(&data->lsm_opts);
Chuck Lever9423a082009-09-23 14:36:38 -0400972 }
973 return data;
974}
975
Jeff Layton8a0d5512011-12-20 06:57:45 -0500976static void nfs_free_parsed_mount_data(struct nfs_parsed_mount_data *data)
977{
978 if (data) {
979 kfree(data->client_address);
980 kfree(data->mount_server.hostname);
981 kfree(data->nfs_server.export_path);
982 kfree(data->nfs_server.hostname);
983 kfree(data->fscache_uniq);
984 security_free_mnt_opts(&data->lsm_opts);
985 kfree(data);
986 }
987}
988
David Howellsf7b422b2006-06-09 09:34:33 -0400989/*
Chuck Levercdcd7f92007-12-10 14:57:45 -0500990 * Sanity-check a server address provided by the mount command.
991 *
992 * Address family must be initialized, and address must not be
993 * the ANY address for that family.
Chuck Leverfc50d582007-07-01 12:12:46 -0400994 */
995static int nfs_verify_server_address(struct sockaddr *addr)
996{
997 switch (addr->sa_family) {
998 case AF_INET: {
Chuck Levercdcd7f92007-12-10 14:57:45 -0500999 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
Al Viroe6f1ceb2008-03-17 22:44:53 -07001000 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
Chuck Levercdcd7f92007-12-10 14:57:45 -05001001 }
1002 case AF_INET6: {
1003 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
1004 return !ipv6_addr_any(sa);
Chuck Leverfc50d582007-07-01 12:12:46 -04001005 }
1006 }
1007
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001008 dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
Chuck Leverfc50d582007-07-01 12:12:46 -04001009 return 0;
1010}
1011
Chuck Lever9412b922007-12-10 14:59:21 -05001012/*
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001013 * Select between a default port value and a user-specified port value.
1014 * If a zero value is set, then autobind will be used.
1015 */
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001016static void nfs_set_port(struct sockaddr *sap, int *port,
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001017 const unsigned short default_port)
1018{
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001019 if (*port == NFS_UNSPEC_PORT)
1020 *port = default_port;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001021
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001022 rpc_set_port(sap, *port);
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001023}
1024
1025/*
Trond Myklebust259875e2008-07-02 14:43:47 -04001026 * Sanity check the NFS transport protocol.
1027 *
1028 */
1029static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
1030{
1031 switch (mnt->nfs_server.protocol) {
1032 case XPRT_TRANSPORT_UDP:
1033 case XPRT_TRANSPORT_TCP:
1034 case XPRT_TRANSPORT_RDMA:
1035 break;
1036 default:
1037 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1038 }
1039}
1040
1041/*
1042 * For text based NFSv2/v3 mounts, the mount protocol transport default
1043 * settings should depend upon the specified NFS transport.
1044 */
1045static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
1046{
1047 nfs_validate_transport_protocol(mnt);
1048
1049 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
1050 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
1051 return;
1052 switch (mnt->nfs_server.protocol) {
1053 case XPRT_TRANSPORT_UDP:
1054 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
1055 break;
1056 case XPRT_TRANSPORT_TCP:
1057 case XPRT_TRANSPORT_RDMA:
1058 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
1059 }
1060}
1061
1062/*
Chuck Lever01060c82008-06-24 16:33:38 -04001063 * Parse the value of the 'sec=' option.
Chuck Lever01060c82008-06-24 16:33:38 -04001064 */
1065static int nfs_parse_security_flavors(char *value,
1066 struct nfs_parsed_mount_data *mnt)
1067{
1068 substring_t args[MAX_OPT_ARGS];
1069
1070 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
1071
1072 switch (match_token(value, nfs_secflavor_tokens, args)) {
1073 case Opt_sec_none:
Chuck Lever01060c82008-06-24 16:33:38 -04001074 mnt->auth_flavors[0] = RPC_AUTH_NULL;
1075 break;
1076 case Opt_sec_sys:
Chuck Lever01060c82008-06-24 16:33:38 -04001077 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
1078 break;
1079 case Opt_sec_krb5:
Chuck Lever01060c82008-06-24 16:33:38 -04001080 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
1081 break;
1082 case Opt_sec_krb5i:
Chuck Lever01060c82008-06-24 16:33:38 -04001083 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
1084 break;
1085 case Opt_sec_krb5p:
Chuck Lever01060c82008-06-24 16:33:38 -04001086 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
1087 break;
1088 case Opt_sec_lkey:
Chuck Lever01060c82008-06-24 16:33:38 -04001089 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
1090 break;
1091 case Opt_sec_lkeyi:
Chuck Lever01060c82008-06-24 16:33:38 -04001092 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
1093 break;
1094 case Opt_sec_lkeyp:
Chuck Lever01060c82008-06-24 16:33:38 -04001095 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
1096 break;
1097 case Opt_sec_spkm:
Chuck Lever01060c82008-06-24 16:33:38 -04001098 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
1099 break;
1100 case Opt_sec_spkmi:
Chuck Lever01060c82008-06-24 16:33:38 -04001101 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
1102 break;
1103 case Opt_sec_spkmp:
Chuck Lever01060c82008-06-24 16:33:38 -04001104 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
1105 break;
1106 default:
1107 return 0;
1108 }
1109
Bryan Schumaker9b7160c2011-04-13 14:31:30 -04001110 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
Chuck Lever059f90b2009-08-09 15:09:31 -04001111 mnt->auth_flavor_len = 1;
Chuck Lever01060c82008-06-24 16:33:38 -04001112 return 1;
1113}
1114
Trond Myklebust0d71b052012-03-02 13:59:49 -05001115static int nfs_parse_version_string(char *string,
1116 struct nfs_parsed_mount_data *mnt,
1117 substring_t *args)
1118{
1119 mnt->flags &= ~NFS_MOUNT_VER3;
1120 switch (match_token(string, nfs_vers_tokens, args)) {
1121 case Opt_vers_2:
1122 mnt->version = 2;
1123 break;
1124 case Opt_vers_3:
1125 mnt->flags |= NFS_MOUNT_VER3;
1126 mnt->version = 3;
1127 break;
1128 case Opt_vers_4:
1129 /* Backward compatibility option. In future,
1130 * the mount program should always supply
1131 * a NFSv4 minor version number.
1132 */
1133 mnt->version = 4;
1134 break;
1135 case Opt_vers_4_0:
1136 mnt->version = 4;
1137 mnt->minorversion = 0;
1138 break;
1139 case Opt_vers_4_1:
1140 mnt->version = 4;
1141 mnt->minorversion = 1;
1142 break;
1143 default:
1144 return 0;
1145 }
1146 return 1;
1147}
1148
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001149static int nfs_get_option_str(substring_t args[], char **option)
1150{
1151 kfree(*option);
1152 *option = match_strdup(args);
1153 return !option;
1154}
1155
1156static int nfs_get_option_ul(substring_t args[], unsigned long *option)
1157{
1158 int rc;
1159 char *string;
1160
1161 string = match_strdup(args);
1162 if (string == NULL)
1163 return -ENOMEM;
Daniel Walter7297cb62012-09-26 21:51:46 +02001164 rc = kstrtoul(string, 10, option);
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001165 kfree(string);
1166
1167 return rc;
1168}
1169
Chuck Lever01060c82008-06-24 16:33:38 -04001170/*
Chuck Leverbf0fd762007-07-01 12:13:44 -04001171 * Error-check and convert a string of mount options from user space into
Chuck Leverf45663c2008-06-24 19:28:02 -04001172 * a data structure. The whole mount string is processed; bad options are
1173 * skipped as they are encountered. If there were no errors, return 1;
1174 * otherwise return 0 (zero).
Chuck Leverbf0fd762007-07-01 12:13:44 -04001175 */
1176static int nfs_parse_mount_options(char *raw,
1177 struct nfs_parsed_mount_data *mnt)
1178{
Eric Parisf9c3a382008-03-05 14:20:18 -05001179 char *p, *string, *secdata;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001180 int rc, sloppy = 0, invalid_option = 0;
Jeff Laytonee671b02009-12-03 15:58:56 -05001181 unsigned short protofamily = AF_UNSPEC;
1182 unsigned short mountfamily = AF_UNSPEC;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001183
1184 if (!raw) {
1185 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
1186 return 1;
1187 }
1188 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
1189
Eric Parisf9c3a382008-03-05 14:20:18 -05001190 secdata = alloc_secdata();
1191 if (!secdata)
1192 goto out_nomem;
1193
1194 rc = security_sb_copy_data(raw, secdata);
1195 if (rc)
1196 goto out_security_failure;
1197
1198 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
1199 if (rc)
1200 goto out_security_failure;
1201
1202 free_secdata(secdata);
1203
Chuck Leverbf0fd762007-07-01 12:13:44 -04001204 while ((p = strsep(&raw, ",")) != NULL) {
1205 substring_t args[MAX_OPT_ARGS];
Chuck Levera5a16ba2009-06-17 18:02:14 -07001206 unsigned long option;
1207 int token;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001208
1209 if (!*p)
1210 continue;
1211
1212 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
1213
1214 token = match_token(p, nfs_mount_option_tokens, args);
1215 switch (token) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001216
1217 /*
1218 * boolean options: foo/nofoo
1219 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001220 case Opt_soft:
1221 mnt->flags |= NFS_MOUNT_SOFT;
1222 break;
1223 case Opt_hard:
1224 mnt->flags &= ~NFS_MOUNT_SOFT;
1225 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001226 case Opt_posix:
1227 mnt->flags |= NFS_MOUNT_POSIX;
1228 break;
1229 case Opt_noposix:
1230 mnt->flags &= ~NFS_MOUNT_POSIX;
1231 break;
1232 case Opt_cto:
1233 mnt->flags &= ~NFS_MOUNT_NOCTO;
1234 break;
1235 case Opt_nocto:
1236 mnt->flags |= NFS_MOUNT_NOCTO;
1237 break;
1238 case Opt_ac:
1239 mnt->flags &= ~NFS_MOUNT_NOAC;
1240 break;
1241 case Opt_noac:
1242 mnt->flags |= NFS_MOUNT_NOAC;
1243 break;
1244 case Opt_lock:
1245 mnt->flags &= ~NFS_MOUNT_NONLM;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001246 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1247 NFS_MOUNT_LOCAL_FCNTL);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001248 break;
1249 case Opt_nolock:
1250 mnt->flags |= NFS_MOUNT_NONLM;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001251 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1252 NFS_MOUNT_LOCAL_FCNTL);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001253 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001254 case Opt_udp:
1255 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001256 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001257 break;
1258 case Opt_tcp:
1259 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001260 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001261 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001262 case Opt_rdma:
1263 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1264 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001265 xprt_load_transport(p);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001266 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001267 case Opt_acl:
1268 mnt->flags &= ~NFS_MOUNT_NOACL;
1269 break;
1270 case Opt_noacl:
1271 mnt->flags |= NFS_MOUNT_NOACL;
1272 break;
1273 case Opt_rdirplus:
1274 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1275 break;
1276 case Opt_nordirplus:
1277 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1278 break;
Trond Myklebust75180df2007-05-16 16:53:28 -04001279 case Opt_sharecache:
1280 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1281 break;
1282 case Opt_nosharecache:
1283 mnt->flags |= NFS_MOUNT_UNSHARED;
1284 break;
Chuck Leverd7403512008-12-23 15:21:37 -05001285 case Opt_resvport:
1286 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1287 break;
1288 case Opt_noresvport:
1289 mnt->flags |= NFS_MOUNT_NORESVPORT;
1290 break;
David Howellsb797cac2009-04-03 16:42:48 +01001291 case Opt_fscache:
1292 mnt->options |= NFS_OPTION_FSCACHE;
1293 kfree(mnt->fscache_uniq);
1294 mnt->fscache_uniq = NULL;
1295 break;
1296 case Opt_nofscache:
1297 mnt->options &= ~NFS_OPTION_FSCACHE;
1298 kfree(mnt->fscache_uniq);
1299 mnt->fscache_uniq = NULL;
1300 break;
Chuck Lever89652612012-09-14 17:24:11 -04001301 case Opt_migration:
1302 mnt->options |= NFS_OPTION_MIGRATION;
1303 break;
1304 case Opt_nomigration:
1305 mnt->options &= NFS_OPTION_MIGRATION;
1306 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001307
Chuck Leverf45663c2008-06-24 19:28:02 -04001308 /*
1309 * options that take numeric values
1310 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001311 case Opt_port:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001312 if (nfs_get_option_ul(args, &option) ||
1313 option > USHRT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001314 goto out_invalid_value;
1315 mnt->nfs_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001316 break;
1317 case Opt_rsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001318 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001319 goto out_invalid_value;
1320 mnt->rsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001321 break;
1322 case Opt_wsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001323 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001324 goto out_invalid_value;
1325 mnt->wsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001326 break;
1327 case Opt_bsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001328 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001329 goto out_invalid_value;
1330 mnt->bsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001331 break;
1332 case Opt_timeo:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001333 if (nfs_get_option_ul(args, &option) || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001334 goto out_invalid_value;
1335 mnt->timeo = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001336 break;
1337 case Opt_retrans:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001338 if (nfs_get_option_ul(args, &option) || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001339 goto out_invalid_value;
1340 mnt->retrans = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001341 break;
1342 case Opt_acregmin:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001343 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001344 goto out_invalid_value;
1345 mnt->acregmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001346 break;
1347 case Opt_acregmax:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001348 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001349 goto out_invalid_value;
1350 mnt->acregmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001351 break;
1352 case Opt_acdirmin:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001353 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001354 goto out_invalid_value;
1355 mnt->acdirmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001356 break;
1357 case Opt_acdirmax:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001358 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001359 goto out_invalid_value;
1360 mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001361 break;
1362 case Opt_actimeo:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001363 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001364 goto out_invalid_value;
1365 mnt->acregmin = mnt->acregmax =
1366 mnt->acdirmin = mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001367 break;
1368 case Opt_namelen:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001369 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001370 goto out_invalid_value;
1371 mnt->namlen = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001372 break;
1373 case Opt_mountport:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001374 if (nfs_get_option_ul(args, &option) ||
1375 option > USHRT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001376 goto out_invalid_value;
1377 mnt->mount_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001378 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001379 case Opt_mountvers:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001380 if (nfs_get_option_ul(args, &option) ||
Chuck Leverf45663c2008-06-24 19:28:02 -04001381 option < NFS_MNT_VERSION ||
Chuck Leverd23c45f2009-06-17 18:02:13 -07001382 option > NFS_MNT3_VERSION)
1383 goto out_invalid_value;
1384 mnt->mount_server.version = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001385 break;
Mike Sager3fd5be92009-04-01 09:21:48 -04001386 case Opt_minorversion:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001387 if (nfs_get_option_ul(args, &option))
Chuck Leverf3f4f4e2009-08-09 15:09:29 -04001388 goto out_invalid_value;
1389 if (option > NFS4_MAX_MINOR_VERSION)
1390 goto out_invalid_value;
1391 mnt->minorversion = option;
Mike Sager3fd5be92009-04-01 09:21:48 -04001392 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001393
Chuck Leverf45663c2008-06-24 19:28:02 -04001394 /*
1395 * options that take text values
1396 */
Trond Myklebust0d71b052012-03-02 13:59:49 -05001397 case Opt_nfsvers:
1398 string = match_strdup(args);
1399 if (string == NULL)
1400 goto out_nomem;
1401 rc = nfs_parse_version_string(string, mnt, args);
1402 kfree(string);
1403 if (!rc)
1404 goto out_invalid_value;
1405 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001406 case Opt_sec:
1407 string = match_strdup(args);
1408 if (string == NULL)
1409 goto out_nomem;
Chuck Lever01060c82008-06-24 16:33:38 -04001410 rc = nfs_parse_security_flavors(string, mnt);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001411 kfree(string);
Chuck Leverf45663c2008-06-24 19:28:02 -04001412 if (!rc) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001413 dfprintk(MOUNT, "NFS: unrecognized "
1414 "security flavor\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001415 return 0;
Chuck Leverf45663c2008-06-24 19:28:02 -04001416 }
Chuck Leverbf0fd762007-07-01 12:13:44 -04001417 break;
1418 case Opt_proto:
1419 string = match_strdup(args);
1420 if (string == NULL)
1421 goto out_nomem;
1422 token = match_token(string,
1423 nfs_xprt_protocol_tokens, args);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001424
Jeff Laytonee671b02009-12-03 15:58:56 -05001425 protofamily = AF_INET;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001426 switch (token) {
Jeff Laytonee671b02009-12-03 15:58:56 -05001427 case Opt_xprt_udp6:
1428 protofamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001429 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001430 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001431 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001432 break;
Jeff Laytonee671b02009-12-03 15:58:56 -05001433 case Opt_xprt_tcp6:
1434 protofamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001435 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001436 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001437 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001438 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001439 case Opt_xprt_rdma:
1440 /* vector side protocols to TCP */
1441 mnt->flags |= NFS_MOUNT_TCP;
1442 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001443 xprt_load_transport(string);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001444 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001445 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001446 dfprintk(MOUNT, "NFS: unrecognized "
1447 "transport protocol\n");
Yinghai Lu4223a4a2009-10-20 14:13:46 +09001448 kfree(string);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001449 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001450 }
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001451 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001452 break;
1453 case Opt_mountproto:
1454 string = match_strdup(args);
1455 if (string == NULL)
1456 goto out_nomem;
1457 token = match_token(string,
1458 nfs_xprt_protocol_tokens, args);
Trond Myklebustd508afb2009-04-06 16:41:35 -07001459 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001460
Jeff Laytonee671b02009-12-03 15:58:56 -05001461 mountfamily = AF_INET;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001462 switch (token) {
Jeff Laytonee671b02009-12-03 15:58:56 -05001463 case Opt_xprt_udp6:
1464 mountfamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001465 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001466 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001467 break;
Jeff Laytonee671b02009-12-03 15:58:56 -05001468 case Opt_xprt_tcp6:
1469 mountfamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001470 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001471 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001472 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001473 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001474 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001475 dfprintk(MOUNT, "NFS: unrecognized "
1476 "transport protocol\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001477 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001478 }
1479 break;
1480 case Opt_addr:
1481 string = match_strdup(args);
1482 if (string == NULL)
1483 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001484 mnt->nfs_server.addrlen =
Stanislav Kinsburskyb48e1272012-01-26 15:11:57 +04001485 rpc_pton(mnt->net, string, strlen(string),
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001486 (struct sockaddr *)
1487 &mnt->nfs_server.address,
1488 sizeof(mnt->nfs_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001489 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001490 if (mnt->nfs_server.addrlen == 0)
1491 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001492 break;
1493 case Opt_clientaddr:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001494 if (nfs_get_option_str(args, &mnt->client_address))
Chuck Leverbf0fd762007-07-01 12:13:44 -04001495 goto out_nomem;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001496 break;
Chuck Lever33832032007-12-10 14:59:13 -05001497 case Opt_mounthost:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001498 if (nfs_get_option_str(args,
1499 &mnt->mount_server.hostname))
Chuck Lever33832032007-12-10 14:59:13 -05001500 goto out_nomem;
Chuck Lever33832032007-12-10 14:59:13 -05001501 break;
Chuck Lever0ac83772007-09-11 18:01:04 -04001502 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001503 string = match_strdup(args);
1504 if (string == NULL)
1505 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001506 mnt->mount_server.addrlen =
Stanislav Kinsburskyb48e1272012-01-26 15:11:57 +04001507 rpc_pton(mnt->net, string, strlen(string),
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001508 (struct sockaddr *)
1509 &mnt->mount_server.address,
1510 sizeof(mnt->mount_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001511 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001512 if (mnt->mount_server.addrlen == 0)
1513 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001514 break;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001515 case Opt_lookupcache:
1516 string = match_strdup(args);
1517 if (string == NULL)
1518 goto out_nomem;
1519 token = match_token(string,
1520 nfs_lookupcache_tokens, args);
1521 kfree(string);
1522 switch (token) {
1523 case Opt_lookupcache_all:
1524 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1525 break;
1526 case Opt_lookupcache_positive:
1527 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1528 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1529 break;
1530 case Opt_lookupcache_none:
1531 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1532 break;
1533 default:
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001534 dfprintk(MOUNT, "NFS: invalid "
1535 "lookupcache argument\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001536 return 0;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001537 };
1538 break;
Chuck Levera6d5ff62010-05-07 13:33:58 -04001539 case Opt_fscache_uniq:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001540 if (nfs_get_option_str(args, &mnt->fscache_uniq))
Chuck Levera6d5ff62010-05-07 13:33:58 -04001541 goto out_nomem;
Chuck Levera6d5ff62010-05-07 13:33:58 -04001542 mnt->options |= NFS_OPTION_FSCACHE;
1543 break;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001544 case Opt_local_lock:
1545 string = match_strdup(args);
1546 if (string == NULL)
1547 goto out_nomem;
1548 token = match_token(string, nfs_local_lock_tokens,
1549 args);
1550 kfree(string);
1551 switch (token) {
1552 case Opt_local_lock_all:
1553 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1554 NFS_MOUNT_LOCAL_FCNTL);
1555 break;
1556 case Opt_local_lock_flock:
1557 mnt->flags |= NFS_MOUNT_LOCAL_FLOCK;
1558 break;
1559 case Opt_local_lock_posix:
1560 mnt->flags |= NFS_MOUNT_LOCAL_FCNTL;
1561 break;
1562 case Opt_local_lock_none:
1563 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1564 NFS_MOUNT_LOCAL_FCNTL);
1565 break;
1566 default:
1567 dfprintk(MOUNT, "NFS: invalid "
1568 "local_lock argument\n");
1569 return 0;
1570 };
1571 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001572
Chuck Leverf45663c2008-06-24 19:28:02 -04001573 /*
1574 * Special options
1575 */
1576 case Opt_sloppy:
1577 sloppy = 1;
1578 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1579 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001580 case Opt_userspace:
1581 case Opt_deprecated:
Chuck Leverd33e4df2008-06-12 12:37:41 -04001582 dfprintk(MOUNT, "NFS: ignoring mount option "
1583 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001584 break;
1585
1586 default:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001587 invalid_option = 1;
Chuck Leverf45663c2008-06-24 19:28:02 -04001588 dfprintk(MOUNT, "NFS: unrecognized mount option "
1589 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001590 }
1591 }
1592
Chuck Leverd23c45f2009-06-17 18:02:13 -07001593 if (!sloppy && invalid_option)
1594 return 0;
1595
Weston Andros Adamson571b7552012-02-01 14:06:41 -05001596 if (mnt->minorversion && mnt->version != 4)
1597 goto out_minorversion_mismatch;
1598
Chuck Lever89652612012-09-14 17:24:11 -04001599 if (mnt->options & NFS_OPTION_MIGRATION &&
1600 mnt->version != 4 && mnt->minorversion != 0)
1601 goto out_migration_misuse;
1602
Jeff Laytonee671b02009-12-03 15:58:56 -05001603 /*
1604 * verify that any proto=/mountproto= options match the address
Peter Meerwald1856b222012-08-18 17:38:54 +02001605 * families in the addr=/mountaddr= options.
Jeff Laytonee671b02009-12-03 15:58:56 -05001606 */
1607 if (protofamily != AF_UNSPEC &&
1608 protofamily != mnt->nfs_server.address.ss_family)
1609 goto out_proto_mismatch;
1610
1611 if (mountfamily != AF_UNSPEC) {
1612 if (mnt->mount_server.addrlen) {
1613 if (mountfamily != mnt->mount_server.address.ss_family)
1614 goto out_mountproto_mismatch;
1615 } else {
1616 if (mountfamily != mnt->nfs_server.address.ss_family)
1617 goto out_mountproto_mismatch;
1618 }
1619 }
1620
Chuck Leverbf0fd762007-07-01 12:13:44 -04001621 return 1;
1622
Jeff Laytonee671b02009-12-03 15:58:56 -05001623out_mountproto_mismatch:
1624 printk(KERN_INFO "NFS: mount server address does not match mountproto= "
1625 "option\n");
1626 return 0;
1627out_proto_mismatch:
1628 printk(KERN_INFO "NFS: server address does not match proto= option\n");
1629 return 0;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001630out_invalid_address:
1631 printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
1632 return 0;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001633out_invalid_value:
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001634 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001635 return 0;
Weston Andros Adamson571b7552012-02-01 14:06:41 -05001636out_minorversion_mismatch:
1637 printk(KERN_INFO "NFS: mount option vers=%u does not support "
1638 "minorversion=%u\n", mnt->version, mnt->minorversion);
1639 return 0;
Chuck Lever89652612012-09-14 17:24:11 -04001640out_migration_misuse:
1641 printk(KERN_INFO
1642 "NFS: 'migration' not supported for this NFS version\n");
1643 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001644out_nomem:
1645 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1646 return 0;
Eric Parisf9c3a382008-03-05 14:20:18 -05001647out_security_failure:
1648 free_secdata(secdata);
1649 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1650 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001651}
1652
1653/*
Chuck Leverec88f282009-08-09 15:09:32 -04001654 * Match the requested auth flavors with the list returned by
1655 * the server. Returns zero and sets the mount's authentication
1656 * flavor on success; returns -EACCES if server does not support
1657 * the requested flavor.
1658 */
1659static int nfs_walk_authlist(struct nfs_parsed_mount_data *args,
1660 struct nfs_mount_request *request)
1661{
1662 unsigned int i, j, server_authlist_len = *(request->auth_flav_len);
1663
1664 /*
Chuck Lever5eecfde2009-08-21 17:50:30 -04001665 * Certain releases of Linux's mountd return an empty
1666 * flavor list. To prevent behavioral regression with
1667 * these servers (ie. rejecting mounts that used to
1668 * succeed), revert to pre-2.6.32 behavior (no checking)
1669 * if the returned flavor list is empty.
1670 */
1671 if (server_authlist_len == 0)
1672 return 0;
1673
1674 /*
Chuck Leverec88f282009-08-09 15:09:32 -04001675 * We avoid sophisticated negotiating here, as there are
1676 * plenty of cases where we can get it wrong, providing
1677 * either too little or too much security.
1678 *
1679 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1680 * flavor listed first. However, some servers list
1681 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1682 * preferred default, in args->auth_flavors[0] if user
1683 * didn't specify sec= mount option.
1684 */
1685 for (i = 0; i < args->auth_flavor_len; i++)
1686 for (j = 0; j < server_authlist_len; j++)
1687 if (args->auth_flavors[i] == request->auth_flavs[j]) {
1688 dfprintk(MOUNT, "NFS: using auth flavor %d\n",
1689 request->auth_flavs[j]);
1690 args->auth_flavors[0] = request->auth_flavs[j];
1691 return 0;
1692 }
1693
1694 dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n");
1695 nfs_umount(request);
1696 return -EACCES;
1697}
1698
1699/*
Chuck Lever0076d7b2007-07-01 12:13:49 -04001700 * Use the remote server's MOUNT service to request the NFS file handle
1701 * corresponding to the provided path.
1702 */
Bryan Schumaker486aa692012-05-10 15:07:39 -04001703static int nfs_request_mount(struct nfs_parsed_mount_data *args,
1704 struct nfs_fh *root_fh)
Chuck Lever0076d7b2007-07-01 12:13:49 -04001705{
Chuck Leverec88f282009-08-09 15:09:32 -04001706 rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS];
1707 unsigned int server_authlist_len = ARRAY_SIZE(server_authlist);
Chuck Leverc5d120f2008-12-23 15:21:35 -05001708 struct nfs_mount_request request = {
1709 .sap = (struct sockaddr *)
1710 &args->mount_server.address,
1711 .dirpath = args->nfs_server.export_path,
1712 .protocol = args->mount_server.protocol,
1713 .fh = root_fh,
Chuck Lever50a737f2008-12-23 15:21:37 -05001714 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
Chuck Leverec88f282009-08-09 15:09:32 -04001715 .auth_flav_len = &server_authlist_len,
1716 .auth_flavs = server_authlist,
Stanislav Kinsbursky6d59b8d2012-01-10 16:12:54 +04001717 .net = args->net,
Chuck Leverc5d120f2008-12-23 15:21:35 -05001718 };
Chuck Lever4c568012007-12-10 14:59:28 -05001719 int status;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001720
1721 if (args->mount_server.version == 0) {
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001722 switch (args->version) {
1723 default:
1724 args->mount_server.version = NFS_MNT3_VERSION;
1725 break;
1726 case 2:
1727 args->mount_server.version = NFS_MNT_VERSION;
1728 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001729 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001730 request.version = args->mount_server.version;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001731
Chuck Lever33832032007-12-10 14:59:13 -05001732 if (args->mount_server.hostname)
Chuck Leverc5d120f2008-12-23 15:21:35 -05001733 request.hostname = args->mount_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001734 else
Chuck Leverc5d120f2008-12-23 15:21:35 -05001735 request.hostname = args->nfs_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001736
Chuck Lever0076d7b2007-07-01 12:13:49 -04001737 /*
1738 * Construct the mount server's address.
1739 */
Chuck Lever4c568012007-12-10 14:59:28 -05001740 if (args->mount_server.address.ss_family == AF_UNSPEC) {
Chuck Leverc5d120f2008-12-23 15:21:35 -05001741 memcpy(request.sap, &args->nfs_server.address,
Chuck Lever4c568012007-12-10 14:59:28 -05001742 args->nfs_server.addrlen);
1743 args->mount_server.addrlen = args->nfs_server.addrlen;
1744 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001745 request.salen = args->mount_server.addrlen;
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001746 nfs_set_port(request.sap, &args->mount_server.port, 0);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001747
1748 /*
1749 * Now ask the mount server to map our export path
1750 * to a file handle.
1751 */
Chuck Leverc5d120f2008-12-23 15:21:35 -05001752 status = nfs_mount(&request);
Chuck Leverec88f282009-08-09 15:09:32 -04001753 if (status != 0) {
1754 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1755 request.hostname, status);
1756 return status;
1757 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001758
Chuck Leverec88f282009-08-09 15:09:32 -04001759 /*
1760 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1761 */
1762 if (args->mount_server.version != NFS_MNT3_VERSION)
1763 return 0;
1764 return nfs_walk_authlist(args, &request);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001765}
1766
Bryan Schumakerff9099f22012-07-30 16:05:18 -04001767struct dentry *nfs_try_mount(int flags, const char *dev_name,
1768 struct nfs_mount_info *mount_info,
1769 struct nfs_subversion *nfs_mod)
Bryan Schumaker486aa692012-05-10 15:07:39 -04001770{
1771 int status;
1772 struct nfs_server *server;
1773
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04001774 if (mount_info->parsed->need_mount) {
Bryan Schumaker87c70832012-05-10 15:07:43 -04001775 status = nfs_request_mount(mount_info->parsed, mount_info->mntfh);
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04001776 if (status)
1777 return ERR_PTR(status);
1778 }
Bryan Schumaker486aa692012-05-10 15:07:39 -04001779
1780 /* Get a volume representation */
Bryan Schumaker1179acc2012-07-30 16:05:19 -04001781 server = nfs_mod->rpc_ops->create_server(mount_info, nfs_mod);
Bryan Schumaker486aa692012-05-10 15:07:39 -04001782 if (IS_ERR(server))
1783 return ERR_CAST(server);
1784
Bryan Schumakerab7017a2012-07-30 16:05:16 -04001785 return nfs_fs_mount_common(server, flags, dev_name, mount_info, nfs_mod);
Bryan Schumaker486aa692012-05-10 15:07:39 -04001786}
Bryan Schumakerddda8e02012-07-30 16:05:23 -04001787EXPORT_SYMBOL_GPL(nfs_try_mount);
Bryan Schumaker486aa692012-05-10 15:07:39 -04001788
Rob Landleyc12bace2011-03-09 15:54:13 -06001789/*
1790 * Split "dev_name" into "hostname:export_path".
1791 *
1792 * The leftmost colon demarks the split between the server's hostname
1793 * and the export path. If the hostname starts with a left square
1794 * bracket, then it may contain colons.
1795 *
1796 * Note: caller frees hostname and export path, even on error.
1797 */
1798static int nfs_parse_devname(const char *dev_name,
1799 char **hostname, size_t maxnamlen,
1800 char **export_path, size_t maxpathlen)
Chuck Leverdc045892008-06-23 12:36:37 -04001801{
1802 size_t len;
Rob Landleyc12bace2011-03-09 15:54:13 -06001803 char *end;
Chuck Leverdc045892008-06-23 12:36:37 -04001804
Rob Landleyc12bace2011-03-09 15:54:13 -06001805 /* Is the host name protected with square brakcets? */
1806 if (*dev_name == '[') {
1807 end = strchr(++dev_name, ']');
1808 if (end == NULL || end[1] != ':')
1809 goto out_bad_devname;
Chuck Leverdc045892008-06-23 12:36:37 -04001810
Rob Landleyc12bace2011-03-09 15:54:13 -06001811 len = end - dev_name;
1812 end++;
1813 } else {
1814 char *comma;
1815
1816 end = strchr(dev_name, ':');
1817 if (end == NULL)
1818 goto out_bad_devname;
1819 len = end - dev_name;
1820
1821 /* kill possible hostname list: not supported */
1822 comma = strchr(dev_name, ',');
1823 if (comma != NULL && comma < end)
1824 *comma = 0;
1825 }
1826
Chuck Leverdc045892008-06-23 12:36:37 -04001827 if (len > maxnamlen)
1828 goto out_hostname;
1829
1830 /* N.B. caller will free nfs_server.hostname in all cases */
1831 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
Rob Landleyc12bace2011-03-09 15:54:13 -06001832 if (*hostname == NULL)
Chuck Leverdc045892008-06-23 12:36:37 -04001833 goto out_nomem;
Rob Landleyc12bace2011-03-09 15:54:13 -06001834 len = strlen(++end);
Chuck Leverdc045892008-06-23 12:36:37 -04001835 if (len > maxpathlen)
1836 goto out_path;
Rob Landleyc12bace2011-03-09 15:54:13 -06001837 *export_path = kstrndup(end, len, GFP_KERNEL);
Chuck Leverdc045892008-06-23 12:36:37 -04001838 if (!*export_path)
1839 goto out_nomem;
1840
1841 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1842 return 0;
1843
1844out_bad_devname:
1845 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1846 return -EINVAL;
1847
1848out_nomem:
1849 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1850 return -ENOMEM;
1851
1852out_hostname:
1853 dfprintk(MOUNT, "NFS: server hostname too long\n");
1854 return -ENAMETOOLONG;
1855
1856out_path:
1857 dfprintk(MOUNT, "NFS: export pathname too long\n");
1858 return -ENAMETOOLONG;
1859}
1860
1861/*
David Howells54ceac42006-08-22 20:06:13 -04001862 * Validate the NFS2/NFS3 mount data
1863 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001864 *
1865 * For option strings, user space handles the following behaviors:
1866 *
1867 * + DNS: mapping server host name to IP address ("addr=" option)
1868 *
1869 * + failure mode: how to behave if a mount request can't be handled
1870 * immediately ("fg/bg" option)
1871 *
1872 * + retry: how often to retry a mount request ("retry=" option)
1873 *
1874 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1875 * mountproto=tcp after mountproto=udp, and so on
David Howellsf7b422b2006-06-09 09:34:33 -04001876 */
Bryan Schumakerd72c7272012-05-10 15:07:41 -04001877static int nfs23_validate_mount_data(void *options,
1878 struct nfs_parsed_mount_data *args,
1879 struct nfs_fh *mntfh,
1880 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001881{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001882 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001883 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
Chuck Lever136d5582007-07-01 12:13:54 -04001884
Chuck Lever5df36e72007-07-01 12:12:56 -04001885 if (data == NULL)
1886 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001887
Bryan Schumakerc5afc8d2012-06-08 11:32:56 -04001888 args->version = NFS_DEFAULT_VERSION;
David Howellsf7b422b2006-06-09 09:34:33 -04001889 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001890 case 1:
1891 data->namlen = 0;
1892 case 2:
1893 data->bsize = 0;
1894 case 3:
1895 if (data->flags & NFS_MOUNT_VER3)
1896 goto out_no_v3;
1897 data->root.size = NFS2_FHSIZE;
1898 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1899 case 4:
1900 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1901 goto out_no_sec;
1902 case 5:
1903 memset(data->context, 0, sizeof(data->context));
1904 case 6:
Trond Myklebustb7e24452008-06-19 15:21:11 -04001905 if (data->flags & NFS_MOUNT_VER3) {
1906 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1907 goto out_invalid_fh;
Chuck Lever5df36e72007-07-01 12:12:56 -04001908 mntfh->size = data->root.size;
Chuck Lever764302c2009-09-08 19:50:03 -04001909 args->version = 3;
1910 } else {
Chuck Lever5df36e72007-07-01 12:12:56 -04001911 mntfh->size = NFS2_FHSIZE;
Chuck Lever764302c2009-09-08 19:50:03 -04001912 args->version = 2;
1913 }
Chuck Lever5df36e72007-07-01 12:12:56 -04001914
Chuck Lever5df36e72007-07-01 12:12:56 -04001915
1916 memcpy(mntfh->data, data->root.data, mntfh->size);
1917 if (mntfh->size < sizeof(mntfh->data))
1918 memset(mntfh->data + mntfh->size, 0,
1919 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001920
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001921 /*
1922 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1923 * can deal with.
1924 */
Trond Myklebustff3525a2008-08-15 16:59:14 -04001925 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
Bryan Schumakerd5eff1a2010-08-03 13:04:00 -04001926 args->flags |= NFS_MOUNT_LEGACY_INTERFACE;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001927 args->rsize = data->rsize;
1928 args->wsize = data->wsize;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001929 args->timeo = data->timeo;
1930 args->retrans = data->retrans;
1931 args->acregmin = data->acregmin;
1932 args->acregmax = data->acregmax;
1933 args->acdirmin = data->acdirmin;
1934 args->acdirmax = data->acdirmax;
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04001935 args->need_mount = false;
Chuck Lever4c568012007-12-10 14:59:28 -05001936
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001937 memcpy(sap, &data->addr, sizeof(data->addr));
Chuck Lever4c568012007-12-10 14:59:28 -05001938 args->nfs_server.addrlen = sizeof(data->addr);
Trond Myklebust872ece82012-09-04 11:05:07 -04001939 args->nfs_server.port = ntohs(data->addr.sin_port);
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001940 if (!nfs_verify_server_address(sap))
Chuck Lever4c568012007-12-10 14:59:28 -05001941 goto out_no_address;
1942
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001943 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001944 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001945 /* N.B. caller will free nfs_server.hostname in all cases */
1946 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1947 args->namlen = data->namlen;
1948 args->bsize = data->bsize;
Chuck Leverdd07c942008-06-24 16:33:46 -04001949
1950 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1951 args->auth_flavors[0] = data->pseudoflavor;
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001952 if (!args->nfs_server.hostname)
1953 goto out_nomem;
Eric Parisf9c3a382008-03-05 14:20:18 -05001954
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001955 if (!(data->flags & NFS_MOUNT_NONLM))
1956 args->flags &= ~(NFS_MOUNT_LOCAL_FLOCK|
1957 NFS_MOUNT_LOCAL_FCNTL);
1958 else
1959 args->flags |= (NFS_MOUNT_LOCAL_FLOCK|
1960 NFS_MOUNT_LOCAL_FCNTL);
Eric Parisf9c3a382008-03-05 14:20:18 -05001961 /*
1962 * The legacy version 6 binary mount data from userspace has a
1963 * field used only to transport selinux information into the
1964 * the kernel. To continue to support that functionality we
1965 * have a touch of selinux knowledge here in the NFS code. The
1966 * userspace code converted context=blah to just blah so we are
1967 * converting back to the full string selinux understands.
1968 */
1969 if (data->context[0]){
1970#ifdef CONFIG_SECURITY_SELINUX
1971 int rc;
1972 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1973 if (!opts_str)
1974 return -ENOMEM;
1975 strcpy(opts_str, "context=");
1976 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1977 strcat(opts_str, &data->context[0]);
1978 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1979 kfree(opts_str);
1980 if (rc)
1981 return rc;
1982#else
1983 return -EINVAL;
1984#endif
1985 }
1986
Chuck Lever5df36e72007-07-01 12:12:56 -04001987 break;
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04001988 default:
1989 return NFS_TEXT_DATA;
David Howellsf7b422b2006-06-09 09:34:33 -04001990 }
David Howells54ceac42006-08-22 20:06:13 -04001991
Bryan Schumaker1c606fb2012-07-30 16:05:24 -04001992#if !IS_ENABLED(CONFIG_NFS_V3)
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001993 if (args->version == 3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001994 goto out_v3_not_compiled;
1995#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001996
David Howells54ceac42006-08-22 20:06:13 -04001997 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001998
1999out_no_data:
2000 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
2001 return -EINVAL;
2002
2003out_no_v3:
2004 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
2005 data->version);
2006 return -EINVAL;
2007
2008out_no_sec:
2009 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
2010 return -EINVAL;
2011
Bryan Schumaker1c606fb2012-07-30 16:05:24 -04002012#if !IS_ENABLED(CONFIG_NFS_V3)
Chuck Lever5df36e72007-07-01 12:12:56 -04002013out_v3_not_compiled:
2014 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
2015 return -EPROTONOSUPPORT;
2016#endif /* !CONFIG_NFS_V3 */
2017
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04002018out_nomem:
2019 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
2020 return -ENOMEM;
2021
Chuck Lever5df36e72007-07-01 12:12:56 -04002022out_no_address:
2023 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
2024 return -EINVAL;
2025
2026out_invalid_fh:
2027 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
2028 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04002029}
2030
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002031#if IS_ENABLED(CONFIG_NFS_V4)
Bryan Schumakerd72c7272012-05-10 15:07:41 -04002032static int nfs_validate_mount_data(struct file_system_type *fs_type,
2033 void *options,
2034 struct nfs_parsed_mount_data *args,
2035 struct nfs_fh *mntfh,
2036 const char *dev_name)
2037{
2038 if (fs_type == &nfs_fs_type)
2039 return nfs23_validate_mount_data(options, args, mntfh, dev_name);
2040 return nfs4_validate_mount_data(options, args, dev_name);
2041}
2042#else
2043static int nfs_validate_mount_data(struct file_system_type *fs_type,
2044 void *options,
2045 struct nfs_parsed_mount_data *args,
2046 struct nfs_fh *mntfh,
2047 const char *dev_name)
2048{
2049 return nfs23_validate_mount_data(options, args, mntfh, dev_name);
2050}
2051#endif
2052
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04002053static int nfs_validate_text_mount_data(void *options,
2054 struct nfs_parsed_mount_data *args,
2055 const char *dev_name)
2056{
2057 int port = 0;
2058 int max_namelen = PAGE_SIZE;
2059 int max_pathlen = NFS_MAXPATHLEN;
2060 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2061
2062 if (nfs_parse_mount_options((char *)options, args) == 0)
2063 return -EINVAL;
2064
2065 if (!nfs_verify_server_address(sap))
2066 goto out_no_address;
2067
2068 if (args->version == 4) {
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002069#if IS_ENABLED(CONFIG_NFS_V4)
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04002070 port = NFS_PORT;
2071 max_namelen = NFS4_MAXNAMLEN;
2072 max_pathlen = NFS4_MAXPATHLEN;
2073 nfs_validate_transport_protocol(args);
2074 nfs4_validate_mount_flags(args);
2075#else
2076 goto out_v4_not_compiled;
2077#endif /* CONFIG_NFS_V4 */
2078 } else
2079 nfs_set_mount_transport_protocol(args);
2080
2081 nfs_set_port(sap, &args->nfs_server.port, port);
2082
2083 if (args->auth_flavor_len > 1)
2084 goto out_bad_auth;
2085
2086 return nfs_parse_devname(dev_name,
2087 &args->nfs_server.hostname,
2088 max_namelen,
2089 &args->nfs_server.export_path,
2090 max_pathlen);
2091
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002092#if !IS_ENABLED(CONFIG_NFS_V4)
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04002093out_v4_not_compiled:
2094 dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n");
2095 return -EPROTONOSUPPORT;
2096#endif /* !CONFIG_NFS_V4 */
2097
2098out_no_address:
2099 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
2100 return -EINVAL;
2101
2102out_bad_auth:
2103 dfprintk(MOUNT, "NFS: Too many RPC auth flavours specified\n");
2104 return -EINVAL;
2105}
2106
Jeff Layton48b605f2008-06-10 15:38:39 -04002107static int
2108nfs_compare_remount_data(struct nfs_server *nfss,
2109 struct nfs_parsed_mount_data *data)
2110{
2111 if (data->flags != nfss->flags ||
2112 data->rsize != nfss->rsize ||
2113 data->wsize != nfss->wsize ||
2114 data->retrans != nfss->client->cl_timeout->to_retries ||
2115 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
2116 data->acregmin != nfss->acregmin / HZ ||
2117 data->acregmax != nfss->acregmax / HZ ||
2118 data->acdirmin != nfss->acdirmin / HZ ||
2119 data->acdirmax != nfss->acdirmax / HZ ||
2120 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
Trond Myklebustbcd2ea12009-10-06 15:41:22 -04002121 data->nfs_server.port != nfss->port ||
Jeff Layton48b605f2008-06-10 15:38:39 -04002122 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
Stefan Richtera1be9ee2009-10-12 11:26:12 -04002123 !rpc_cmp_addr((struct sockaddr *)&data->nfs_server.address,
2124 (struct sockaddr *)&nfss->nfs_client->cl_addr))
Jeff Layton48b605f2008-06-10 15:38:39 -04002125 return -EINVAL;
2126
2127 return 0;
2128}
2129
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002130int
Jeff Layton48b605f2008-06-10 15:38:39 -04002131nfs_remount(struct super_block *sb, int *flags, char *raw_data)
2132{
2133 int error;
2134 struct nfs_server *nfss = sb->s_fs_info;
2135 struct nfs_parsed_mount_data *data;
2136 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
2137 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
Trond Myklebustcd100722008-06-17 16:12:00 -04002138 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
Jeff Layton48b605f2008-06-10 15:38:39 -04002139
2140 /*
2141 * Userspace mount programs that send binary options generally send
2142 * them populated with default values. We have no way to know which
2143 * ones were explicitly specified. Fall back to legacy behavior and
2144 * just return success.
2145 */
Marc Zyngier31c94462008-07-17 13:21:55 +02002146 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
2147 (nfsvers <= 3 && (!options || (options->version >= 1 &&
2148 options->version <= 6))))
Jeff Layton48b605f2008-06-10 15:38:39 -04002149 return 0;
2150
2151 data = kzalloc(sizeof(*data), GFP_KERNEL);
2152 if (data == NULL)
2153 return -ENOMEM;
2154
2155 /* fill out struct with values from existing mount */
2156 data->flags = nfss->flags;
2157 data->rsize = nfss->rsize;
2158 data->wsize = nfss->wsize;
2159 data->retrans = nfss->client->cl_timeout->to_retries;
2160 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
2161 data->acregmin = nfss->acregmin / HZ;
2162 data->acregmax = nfss->acregmax / HZ;
2163 data->acdirmin = nfss->acdirmin / HZ;
2164 data->acdirmax = nfss->acdirmax / HZ;
2165 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
Trond Myklebustbcd2ea12009-10-06 15:41:22 -04002166 data->nfs_server.port = nfss->port;
Jeff Layton48b605f2008-06-10 15:38:39 -04002167 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
2168 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
2169 data->nfs_server.addrlen);
2170
2171 /* overwrite those values with any that were specified */
2172 error = nfs_parse_mount_options((char *)options, data);
2173 if (error < 0)
2174 goto out;
2175
Jeff Layton26c4c172011-04-27 11:49:09 -04002176 /*
2177 * noac is a special case. It implies -o sync, but that's not
2178 * necessarily reflected in the mtab options. do_remount_sb
2179 * will clear MS_SYNCHRONOUS if -o sync wasn't specified in the
2180 * remount options, so we have to explicitly reset it.
2181 */
2182 if (data->flags & NFS_MOUNT_NOAC)
2183 *flags |= MS_SYNCHRONOUS;
2184
Jeff Layton48b605f2008-06-10 15:38:39 -04002185 /* compare new mount options with old ones */
2186 error = nfs_compare_remount_data(nfss, data);
2187out:
2188 kfree(data);
2189 return error;
2190}
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002191EXPORT_SYMBOL_GPL(nfs_remount);
Jeff Layton48b605f2008-06-10 15:38:39 -04002192
David Howells54ceac42006-08-22 20:06:13 -04002193/*
2194 * Initialise the common bits of the superblock
2195 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002196inline void nfs_initialise_sb(struct super_block *sb)
David Howells54ceac42006-08-22 20:06:13 -04002197{
2198 struct nfs_server *server = NFS_SB(sb);
2199
2200 sb->s_magic = NFS_SUPER_MAGIC;
2201
2202 /* We probably want something more informative here */
2203 snprintf(sb->s_id, sizeof(sb->s_id),
Vivek Trivedi5a7c9ee2012-03-15 23:58:52 +05302204 "%u:%u", MAJOR(sb->s_dev), MINOR(sb->s_dev));
David Howells54ceac42006-08-22 20:06:13 -04002205
2206 if (sb->s_blocksize == 0)
2207 sb->s_blocksize = nfs_block_bits(server->wsize,
2208 &sb->s_blocksize_bits);
2209
Jens Axboe32a88aa2009-09-16 15:02:33 +02002210 sb->s_bdi = &server->backing_dev_info;
2211
David Howells54ceac42006-08-22 20:06:13 -04002212 nfs_super_set_maxbytes(sb, server->maxfilesize);
2213}
2214
2215/*
2216 * Finish setting up an NFS2/3 superblock
2217 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002218void nfs_fill_super(struct super_block *sb, struct nfs_mount_info *mount_info)
David Howells54ceac42006-08-22 20:06:13 -04002219{
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002220 struct nfs_parsed_mount_data *data = mount_info->parsed;
David Howells54ceac42006-08-22 20:06:13 -04002221 struct nfs_server *server = NFS_SB(sb);
2222
2223 sb->s_blocksize_bits = 0;
2224 sb->s_blocksize = 0;
Bryan Schumaker6a744902012-07-30 16:05:20 -04002225 sb->s_xattr = server->nfs_client->cl_nfs_mod->xattr;
2226 sb->s_op = server->nfs_client->cl_nfs_mod->sops;
2227 if (data && data->bsize)
David Howells54ceac42006-08-22 20:06:13 -04002228 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
2229
Bryan Schumaker6a744902012-07-30 16:05:20 -04002230 if (server->nfs_client->rpc_ops->version != 2) {
David Howells54ceac42006-08-22 20:06:13 -04002231 /* The VFS shouldn't apply the umask to mode bits. We will do
2232 * so ourselves when necessary.
2233 */
2234 sb->s_flags |= MS_POSIXACL;
2235 sb->s_time_gran = 1;
2236 }
2237
David Howells54ceac42006-08-22 20:06:13 -04002238 nfs_initialise_sb(sb);
2239}
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002240EXPORT_SYMBOL_GPL(nfs_fill_super);
David Howells54ceac42006-08-22 20:06:13 -04002241
2242/*
Bryan Schumaker3cadf4b2012-07-16 16:39:19 -04002243 * Finish setting up a cloned NFS2/3/4 superblock
David Howells54ceac42006-08-22 20:06:13 -04002244 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002245void nfs_clone_super(struct super_block *sb, struct nfs_mount_info *mount_info)
David Howells54ceac42006-08-22 20:06:13 -04002246{
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002247 const struct super_block *old_sb = mount_info->cloned->sb;
David Howells54ceac42006-08-22 20:06:13 -04002248 struct nfs_server *server = NFS_SB(sb);
2249
2250 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2251 sb->s_blocksize = old_sb->s_blocksize;
2252 sb->s_maxbytes = old_sb->s_maxbytes;
Bryan Schumaker3cadf4b2012-07-16 16:39:19 -04002253 sb->s_xattr = old_sb->s_xattr;
2254 sb->s_op = old_sb->s_op;
2255 sb->s_time_gran = 1;
David Howells54ceac42006-08-22 20:06:13 -04002256
Bryan Schumaker3cadf4b2012-07-16 16:39:19 -04002257 if (server->nfs_client->rpc_ops->version != 2) {
David Howells54ceac42006-08-22 20:06:13 -04002258 /* The VFS shouldn't apply the umask to mode bits. We will do
2259 * so ourselves when necessary.
2260 */
2261 sb->s_flags |= MS_POSIXACL;
David Howells54ceac42006-08-22 20:06:13 -04002262 }
2263
David Howells54ceac42006-08-22 20:06:13 -04002264 nfs_initialise_sb(sb);
2265}
2266
Trond Myklebust275a5d22007-05-16 16:53:28 -04002267static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
2268{
2269 const struct nfs_server *a = s->s_fs_info;
2270 const struct rpc_clnt *clnt_a = a->client;
2271 const struct rpc_clnt *clnt_b = b->client;
2272
2273 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
2274 goto Ebusy;
2275 if (a->nfs_client != b->nfs_client)
2276 goto Ebusy;
2277 if (a->flags != b->flags)
2278 goto Ebusy;
2279 if (a->wsize != b->wsize)
2280 goto Ebusy;
2281 if (a->rsize != b->rsize)
2282 goto Ebusy;
2283 if (a->acregmin != b->acregmin)
2284 goto Ebusy;
2285 if (a->acregmax != b->acregmax)
2286 goto Ebusy;
2287 if (a->acdirmin != b->acdirmin)
2288 goto Ebusy;
2289 if (a->acdirmax != b->acdirmax)
2290 goto Ebusy;
2291 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
2292 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002293 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04002294Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002295 return 0;
2296}
2297
2298struct nfs_sb_mountdata {
2299 struct nfs_server *server;
2300 int mntflags;
2301};
2302
2303static int nfs_set_super(struct super_block *s, void *data)
2304{
2305 struct nfs_sb_mountdata *sb_mntdata = data;
2306 struct nfs_server *server = sb_mntdata->server;
2307 int ret;
2308
2309 s->s_flags = sb_mntdata->mntflags;
2310 s->s_fs_info = server;
Al Viro8b244ff2010-12-18 11:29:39 -05002311 s->s_d_op = server->nfs_client->rpc_ops->dentry_ops;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002312 ret = set_anon_super(s, server);
2313 if (ret == 0)
2314 server->s_dev = s->s_dev;
2315 return ret;
2316}
2317
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002318static int nfs_compare_super_address(struct nfs_server *server1,
2319 struct nfs_server *server2)
2320{
2321 struct sockaddr *sap1, *sap2;
2322
2323 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
2324 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
2325
2326 if (sap1->sa_family != sap2->sa_family)
2327 return 0;
2328
2329 switch (sap1->sa_family) {
2330 case AF_INET: {
2331 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
2332 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
2333 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
2334 return 0;
2335 if (sin1->sin_port != sin2->sin_port)
2336 return 0;
2337 break;
2338 }
2339 case AF_INET6: {
2340 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
2341 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
2342 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
2343 return 0;
2344 if (sin1->sin6_port != sin2->sin6_port)
2345 return 0;
2346 break;
2347 }
2348 default:
2349 return 0;
2350 }
2351
2352 return 1;
2353}
2354
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002355static int nfs_compare_super(struct super_block *sb, void *data)
2356{
2357 struct nfs_sb_mountdata *sb_mntdata = data;
2358 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2359 int mntflags = sb_mntdata->mntflags;
2360
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002361 if (!nfs_compare_super_address(old, server))
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002362 return 0;
2363 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2364 if (old->flags & NFS_MOUNT_UNSHARED)
2365 return 0;
2366 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2367 return 0;
2368 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04002369}
2370
Trond Myklebust39ffb922012-05-16 10:21:30 -07002371#ifdef CONFIG_NFS_FSCACHE
Bryan Schumaker2311b942012-05-10 15:07:32 -04002372static void nfs_get_cache_cookie(struct super_block *sb,
2373 struct nfs_parsed_mount_data *parsed,
2374 struct nfs_clone_mount *cloned)
2375{
2376 char *uniq = NULL;
2377 int ulen = 0;
2378
2379 if (parsed && parsed->fscache_uniq) {
2380 uniq = parsed->fscache_uniq;
2381 ulen = strlen(parsed->fscache_uniq);
2382 } else if (cloned) {
2383 struct nfs_server *mnt_s = NFS_SB(cloned->sb);
2384 if (mnt_s->fscache_key) {
2385 uniq = mnt_s->fscache_key->key.uniquifier;
2386 ulen = mnt_s->fscache_key->key.uniq_len;
2387 };
2388 }
2389
2390 nfs_fscache_get_super_cookie(sb, uniq, ulen);
2391}
Trond Myklebust39ffb922012-05-16 10:21:30 -07002392#else
2393static void nfs_get_cache_cookie(struct super_block *sb,
2394 struct nfs_parsed_mount_data *parsed,
2395 struct nfs_clone_mount *cloned)
2396{
2397}
2398#endif
Bryan Schumaker2311b942012-05-10 15:07:32 -04002399
Miklos Szeredifa799752008-04-30 00:54:33 -07002400static int nfs_bdi_register(struct nfs_server *server)
2401{
2402 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
2403}
2404
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002405int nfs_set_sb_security(struct super_block *s, struct dentry *mntroot,
2406 struct nfs_mount_info *mount_info)
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002407{
2408 return security_sb_set_mnt_opts(s, &mount_info->parsed->lsm_opts);
2409}
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002410EXPORT_SYMBOL_GPL(nfs_set_sb_security);
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002411
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002412int nfs_clone_sb_security(struct super_block *s, struct dentry *mntroot,
2413 struct nfs_mount_info *mount_info)
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002414{
2415 /* clone any lsm security options from the parent to the new sb */
2416 security_sb_clone_mnt_opts(mount_info->cloned->sb, s);
2417 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops)
2418 return -ESTALE;
2419 return 0;
2420}
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002421EXPORT_SYMBOL_GPL(nfs_clone_sb_security);
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002422
Bryan Schumakerab7017a2012-07-30 16:05:16 -04002423struct dentry *nfs_fs_mount_common(struct nfs_server *server,
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002424 int flags, const char *dev_name,
Bryan Schumakerab7017a2012-07-30 16:05:16 -04002425 struct nfs_mount_info *mount_info,
2426 struct nfs_subversion *nfs_mod)
David Howells54ceac42006-08-22 20:06:13 -04002427{
David Howells54ceac42006-08-22 20:06:13 -04002428 struct super_block *s;
Al Viro01194982011-03-16 07:25:36 -04002429 struct dentry *mntroot = ERR_PTR(-ENOMEM);
Trond Myklebust75180df2007-05-16 16:53:28 -04002430 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002431 struct nfs_sb_mountdata sb_mntdata = {
2432 .mntflags = flags,
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002433 .server = server,
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002434 };
Al Viro01194982011-03-16 07:25:36 -04002435 int error;
David Howells54ceac42006-08-22 20:06:13 -04002436
Trond Myklebust75180df2007-05-16 16:53:28 -04002437 if (server->flags & NFS_MOUNT_UNSHARED)
2438 compare_super = NULL;
2439
Sachin Prabhufb2088c2011-08-01 12:10:12 +01002440 /* -o noac implies -o sync */
2441 if (server->flags & NFS_MOUNT_NOAC)
2442 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2443
David Howells54ceac42006-08-22 20:06:13 -04002444 /* Get a superblock - note that we may end up sharing one that already exists */
Bryan Schumakerab7017a2012-07-30 16:05:16 -04002445 s = sget(nfs_mod->nfs_fs, compare_super, nfs_set_super, flags, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002446 if (IS_ERR(s)) {
Al Viro01194982011-03-16 07:25:36 -04002447 mntroot = ERR_CAST(s);
David Howells54ceac42006-08-22 20:06:13 -04002448 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04002449 }
2450
David Howells54ceac42006-08-22 20:06:13 -04002451 if (s->s_fs_info != server) {
2452 nfs_free_server(server);
2453 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002454 } else {
2455 error = nfs_bdi_register(server);
Al Viro01194982011-03-16 07:25:36 -04002456 if (error) {
2457 mntroot = ERR_PTR(error);
NeilBrowncfbc0682010-03-11 11:20:17 +11002458 goto error_splat_bdi;
Al Viro01194982011-03-16 07:25:36 -04002459 }
David Howellsf7b422b2006-06-09 09:34:33 -04002460 }
David Howells54ceac42006-08-22 20:06:13 -04002461
2462 if (!s->s_root) {
2463 /* initial superblock/root creation */
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002464 mount_info->fill_super(s, mount_info);
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002465 nfs_get_cache_cookie(s, mount_info->parsed, mount_info->cloned);
David Howells54ceac42006-08-22 20:06:13 -04002466 }
2467
Bryan Schumaker87c70832012-05-10 15:07:43 -04002468 mntroot = nfs_get_root(s, mount_info->mntfh, dev_name);
Al Viro01194982011-03-16 07:25:36 -04002469 if (IS_ERR(mntroot))
David Howells54ceac42006-08-22 20:06:13 -04002470 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002471
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002472 error = mount_info->set_security(s, mntroot, mount_info);
Eric Parisf9c3a382008-03-05 14:20:18 -05002473 if (error)
2474 goto error_splat_root;
2475
David Howellsf7b422b2006-06-09 09:34:33 -04002476 s->s_flags |= MS_ACTIVE;
Chuck Lever06559602007-07-01 12:12:35 -04002477
2478out:
Al Viro01194982011-03-16 07:25:36 -04002479 return mntroot;
Trond Myklebust816724e2006-06-24 08:41:41 -04002480
David Howells54ceac42006-08-22 20:06:13 -04002481out_err_nosb:
2482 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04002483 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002484
Eric Parisf9c3a382008-03-05 14:20:18 -05002485error_splat_root:
2486 dput(mntroot);
Al Viro01194982011-03-16 07:25:36 -04002487 mntroot = ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04002488error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002489 if (server && !s->s_root)
2490 bdi_unregister(&server->backing_dev_info);
2491error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002492 deactivate_locked_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04002493 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002494}
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002495EXPORT_SYMBOL_GPL(nfs_fs_mount_common);
David Howellsf7b422b2006-06-09 09:34:33 -04002496
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002497struct dentry *nfs_fs_mount(struct file_system_type *fs_type,
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002498 int flags, const char *dev_name, void *raw_data)
2499{
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002500 struct nfs_mount_info mount_info = {
2501 .fill_super = nfs_fill_super,
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002502 .set_security = nfs_set_sb_security,
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002503 };
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002504 struct dentry *mntroot = ERR_PTR(-ENOMEM);
Bryan Schumakerab7017a2012-07-30 16:05:16 -04002505 struct nfs_subversion *nfs_mod;
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002506 int error;
2507
Bryan Schumaker46058d42012-05-10 15:07:42 -04002508 mount_info.parsed = nfs_alloc_parsed_mount_data();
Bryan Schumaker87c70832012-05-10 15:07:43 -04002509 mount_info.mntfh = nfs_alloc_fhandle();
2510 if (mount_info.parsed == NULL || mount_info.mntfh == NULL)
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002511 goto out;
2512
2513 /* Validate the mount data */
Bryan Schumaker87c70832012-05-10 15:07:43 -04002514 error = nfs_validate_mount_data(fs_type, raw_data, mount_info.parsed, mount_info.mntfh, dev_name);
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04002515 if (error == NFS_TEXT_DATA)
Bryan Schumaker46058d42012-05-10 15:07:42 -04002516 error = nfs_validate_text_mount_data(raw_data, mount_info.parsed, dev_name);
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002517 if (error < 0) {
2518 mntroot = ERR_PTR(error);
2519 goto out;
2520 }
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002521
Bryan Schumakerab7017a2012-07-30 16:05:16 -04002522 nfs_mod = get_nfs_version(mount_info.parsed->version);
2523 if (IS_ERR(nfs_mod)) {
2524 mntroot = ERR_CAST(nfs_mod);
2525 goto out;
2526 }
2527
Bryan Schumakerff9099f22012-07-30 16:05:18 -04002528 mntroot = nfs_mod->rpc_ops->try_mount(flags, dev_name, &mount_info, nfs_mod);
Bryan Schumakerab7017a2012-07-30 16:05:16 -04002529
2530 put_nfs_version(nfs_mod);
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002531out:
Bryan Schumaker46058d42012-05-10 15:07:42 -04002532 nfs_free_parsed_mount_data(mount_info.parsed);
Bryan Schumaker87c70832012-05-10 15:07:43 -04002533 nfs_free_fhandle(mount_info.mntfh);
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002534 return mntroot;
2535}
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002536EXPORT_SYMBOL_GPL(nfs_fs_mount);
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002537
David Howells54ceac42006-08-22 20:06:13 -04002538/*
Trond Myklebust387c1492010-02-03 08:27:35 -05002539 * Ensure that we unregister the bdi before kill_anon_super
2540 * releases the device name
2541 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002542void nfs_put_super(struct super_block *s)
Trond Myklebust387c1492010-02-03 08:27:35 -05002543{
2544 struct nfs_server *server = NFS_SB(s);
2545
2546 bdi_unregister(&server->backing_dev_info);
2547}
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002548EXPORT_SYMBOL_GPL(nfs_put_super);
Trond Myklebust387c1492010-02-03 08:27:35 -05002549
2550/*
David Howells54ceac42006-08-22 20:06:13 -04002551 * Destroy an NFS2/3 superblock
2552 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002553void nfs_kill_super(struct super_block *s)
David Howellsf7b422b2006-06-09 09:34:33 -04002554{
2555 struct nfs_server *server = NFS_SB(s);
2556
2557 kill_anon_super(s);
David Howells08734042009-04-03 16:42:42 +01002558 nfs_fscache_release_super_cookie(s);
David Howells54ceac42006-08-22 20:06:13 -04002559 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04002560}
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002561EXPORT_SYMBOL_GPL(nfs_kill_super);
David Howellsf7b422b2006-06-09 09:34:33 -04002562
David Howells54ceac42006-08-22 20:06:13 -04002563/*
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002564 * Clone an NFS2/3/4 server record on xdev traversal (FSID-change)
David Howells54ceac42006-08-22 20:06:13 -04002565 */
Stanislav Kinsbursky3dd4f8ef2012-10-02 14:19:04 +04002566static struct dentry *
Bryan Schumakere8f25e62012-07-30 16:05:17 -04002567nfs_xdev_mount(struct file_system_type *fs_type, int flags,
2568 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002569{
Bryan Schumakere8f25e62012-07-30 16:05:17 -04002570 struct nfs_clone_mount *data = raw_data;
2571 struct nfs_mount_info mount_info = {
2572 .fill_super = nfs_clone_super,
2573 .set_security = nfs_clone_sb_security,
2574 .cloned = data,
2575 };
David Howells54ceac42006-08-22 20:06:13 -04002576 struct nfs_server *server;
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002577 struct dentry *mntroot = ERR_PTR(-ENOMEM);
Bryan Schumakerab7017a2012-07-30 16:05:16 -04002578 struct nfs_subversion *nfs_mod = NFS_SB(data->sb)->nfs_client->cl_nfs_mod;
David Howells54ceac42006-08-22 20:06:13 -04002579 int error;
2580
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002581 dprintk("--> nfs_xdev_mount_common()\n");
David Howells54ceac42006-08-22 20:06:13 -04002582
Bryan Schumakere8f25e62012-07-30 16:05:17 -04002583 mount_info.mntfh = mount_info.cloned->fh;
Bryan Schumaker87c70832012-05-10 15:07:43 -04002584
David Howells54ceac42006-08-22 20:06:13 -04002585 /* create a new volume representation */
Bryan Schumaker1179acc2012-07-30 16:05:19 -04002586 server = nfs_mod->rpc_ops->clone_server(NFS_SB(data->sb), data->fh, data->fattr, data->authflavor);
David Howells54ceac42006-08-22 20:06:13 -04002587 if (IS_ERR(server)) {
2588 error = PTR_ERR(server);
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002589 goto out_err;
David Howells54ceac42006-08-22 20:06:13 -04002590 }
2591
Bryan Schumakere8f25e62012-07-30 16:05:17 -04002592 mntroot = nfs_fs_mount_common(server, flags, dev_name, &mount_info, nfs_mod);
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002593 dprintk("<-- nfs_xdev_mount_common() = 0\n");
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002594out:
Al Viro31f43472010-10-29 03:38:12 -04002595 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04002596
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002597out_err:
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002598 dprintk("<-- nfs_xdev_mount_common() = %d [error]\n", error);
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002599 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002600}
2601
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002602#if IS_ENABLED(CONFIG_NFS_V4)
David Howells54ceac42006-08-22 20:06:13 -04002603
Trond Myklebust01c3f052009-06-17 13:22:58 -07002604static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2605{
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04002606 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3|
2607 NFS_MOUNT_LOCAL_FLOCK|NFS_MOUNT_LOCAL_FCNTL);
Trond Myklebust01c3f052009-06-17 13:22:58 -07002608}
2609
David Howells54ceac42006-08-22 20:06:13 -04002610/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04002611 * Validate NFSv4 mount options
2612 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002613static int nfs4_validate_mount_data(void *options,
2614 struct nfs_parsed_mount_data *args,
2615 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04002616{
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002617 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002618 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002619 char *c;
2620
2621 if (data == NULL)
2622 goto out_no_data;
2623
Bryan Schumakercdf66442012-06-05 14:59:54 -04002624 args->version = 4;
2625
Chuck Leverf0768eb2007-07-01 12:13:01 -04002626 switch (data->version) {
2627 case 1:
Chuck Lever4c568012007-12-10 14:59:28 -05002628 if (data->host_addrlen > sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002629 goto out_no_address;
Chuck Lever4c568012007-12-10 14:59:28 -05002630 if (data->host_addrlen == 0)
2631 goto out_no_address;
2632 args->nfs_server.addrlen = data->host_addrlen;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002633 if (copy_from_user(sap, data->host_addr, data->host_addrlen))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002634 return -EFAULT;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002635 if (!nfs_verify_server_address(sap))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002636 goto out_no_address;
Trond Myklebust872ece82012-09-04 11:05:07 -04002637 args->nfs_server.port = ntohs(((struct sockaddr_in *)sap)->sin_port);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002638
Chuck Lever6738b252008-06-24 16:33:54 -04002639 if (data->auth_flavourlen) {
2640 if (data->auth_flavourlen > 1)
2641 goto out_inval_auth;
Trond Myklebust20c71f52007-09-20 20:23:51 -04002642 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002643 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04002644 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002645 return -EFAULT;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002646 }
2647
2648 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2649 if (IS_ERR(c))
2650 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002651 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002652
2653 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2654 if (IS_ERR(c))
2655 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002656 args->nfs_server.export_path = c;
2657 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002658
2659 c = strndup_user(data->client_addr.data, 16);
2660 if (IS_ERR(c))
2661 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002662 args->client_address = c;
2663
2664 /*
2665 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2666 * can deal with.
2667 */
2668
2669 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2670 args->rsize = data->rsize;
2671 args->wsize = data->wsize;
2672 args->timeo = data->timeo;
2673 args->retrans = data->retrans;
2674 args->acregmin = data->acregmin;
2675 args->acregmax = data->acregmax;
2676 args->acdirmin = data->acdirmin;
2677 args->acdirmax = data->acdirmax;
2678 args->nfs_server.protocol = data->proto;
Trond Myklebust259875e2008-07-02 14:43:47 -04002679 nfs_validate_transport_protocol(args);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002680
2681 break;
Chuck Lever7630c852009-09-08 19:49:57 -04002682 default:
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04002683 return NFS_TEXT_DATA;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002684 }
2685
2686 return 0;
2687
2688out_no_data:
2689 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2690 return -EINVAL;
2691
2692out_inval_auth:
2693 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2694 data->auth_flavourlen);
2695 return -EINVAL;
2696
2697out_no_address:
2698 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2699 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002700}
2701
Bryan Schumakerfac1e8e2012-07-30 16:05:22 -04002702/*
2703 * NFS v4 module parameters need to stay in the
2704 * NFS client for backwards compatibility
2705 */
2706unsigned int nfs_callback_set_tcpport;
2707unsigned short nfs_callback_tcpport;
2708/* Default cache timeout is 10 minutes */
2709unsigned int nfs_idmap_cache_timeout = 600;
2710/* Turn off NFSv4 uid/gid mapping when using AUTH_SYS */
2711bool nfs4_disable_idmapping = true;
2712unsigned short max_session_slots = NFS4_DEF_SLOT_TABLE_SIZE;
2713unsigned short send_implementation_id = 1;
Chuck Lever6f2ea7f2012-09-14 17:24:41 -04002714char nfs4_client_id_uniquifier[NFS4_CLIENT_ID_UNIQ_LEN] = "";
Bryan Schumakerfac1e8e2012-07-30 16:05:22 -04002715
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002716EXPORT_SYMBOL_GPL(nfs_callback_set_tcpport);
2717EXPORT_SYMBOL_GPL(nfs_callback_tcpport);
2718EXPORT_SYMBOL_GPL(nfs_idmap_cache_timeout);
2719EXPORT_SYMBOL_GPL(nfs4_disable_idmapping);
2720EXPORT_SYMBOL_GPL(max_session_slots);
2721EXPORT_SYMBOL_GPL(send_implementation_id);
Chuck Lever6f2ea7f2012-09-14 17:24:41 -04002722EXPORT_SYMBOL_GPL(nfs4_client_id_uniquifier);
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002723
Bryan Schumakerfac1e8e2012-07-30 16:05:22 -04002724#define NFS_CALLBACK_MAXPORTNR (65535U)
2725
2726static int param_set_portnr(const char *val, const struct kernel_param *kp)
2727{
2728 unsigned long num;
2729 int ret;
2730
2731 if (!val)
2732 return -EINVAL;
Daniel Walter7297cb62012-09-26 21:51:46 +02002733 ret = kstrtoul(val, 0, &num);
Bryan Schumakerfac1e8e2012-07-30 16:05:22 -04002734 if (ret == -EINVAL || num > NFS_CALLBACK_MAXPORTNR)
2735 return -EINVAL;
2736 *((unsigned int *)kp->arg) = num;
2737 return 0;
2738}
2739static struct kernel_param_ops param_ops_portnr = {
2740 .set = param_set_portnr,
2741 .get = param_get_uint,
2742};
2743#define param_check_portnr(name, p) __param_check(name, p, unsigned int);
2744
2745module_param_named(callback_tcpport, nfs_callback_set_tcpport, portnr, 0644);
2746module_param(nfs_idmap_cache_timeout, int, 0644);
2747module_param(nfs4_disable_idmapping, bool, 0644);
Chuck Lever6f2ea7f2012-09-14 17:24:41 -04002748module_param_string(nfs4_unique_id, nfs4_client_id_uniquifier,
2749 NFS4_CLIENT_ID_UNIQ_LEN, 0600);
Bryan Schumakerfac1e8e2012-07-30 16:05:22 -04002750MODULE_PARM_DESC(nfs4_disable_idmapping,
2751 "Turn off NFSv4 idmapping when using 'sec=sys'");
2752module_param(max_session_slots, ushort, 0644);
2753MODULE_PARM_DESC(max_session_slots, "Maximum number of outstanding NFSv4.1 "
2754 "requests the client will negotiate");
2755module_param(send_implementation_id, ushort, 0644);
2756MODULE_PARM_DESC(send_implementation_id,
2757 "Send implementation ID with NFSv4.1 exchange_id");
Chuck Lever6f2ea7f2012-09-14 17:24:41 -04002758MODULE_PARM_DESC(nfs4_unique_id, "nfs_client_id4 uniquifier string");
bjschuma@gmail.com425e7762012-08-08 13:57:10 -04002759MODULE_ALIAS("nfs4");
2760
David Howells54ceac42006-08-22 20:06:13 -04002761#endif /* CONFIG_NFS_V4 */