blob: e12cea4b36a53a448d57c72bcfd4298924597f79 [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"
Trond Myklebust76e697b2012-11-26 14:20:49 -050067#include "nfs4session.h"
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +030068#include "pnfs.h"
Bryan Schumakerab7017a2012-07-30 16:05:16 -040069#include "nfs.h"
David Howellsf7b422b2006-06-09 09:34:33 -040070
71#define NFSDBG_FACILITY NFSDBG_VFS
Bryan Schumakerb72e4f42012-05-10 15:07:40 -040072#define NFS_TEXT_DATA 1
David Howellsf7b422b2006-06-09 09:34:33 -040073
Bryan Schumaker1c606fb2012-07-30 16:05:24 -040074#if IS_ENABLED(CONFIG_NFS_V3)
Paulius Zaleckas1e657bd2010-10-31 18:21:05 +020075#define NFS_DEFAULT_VERSION 3
76#else
77#define NFS_DEFAULT_VERSION 2
78#endif
79
Chuck Leverbf0fd762007-07-01 12:13:44 -040080enum {
81 /* Mount options that take no arguments */
82 Opt_soft, Opt_hard,
Chuck Leverbf0fd762007-07-01 12:13:44 -040083 Opt_posix, Opt_noposix,
84 Opt_cto, Opt_nocto,
85 Opt_ac, Opt_noac,
86 Opt_lock, Opt_nolock,
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -040087 Opt_udp, Opt_tcp, Opt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -040088 Opt_acl, Opt_noacl,
89 Opt_rdirplus, Opt_nordirplus,
Trond Myklebust75180df2007-05-16 16:53:28 -040090 Opt_sharecache, Opt_nosharecache,
Chuck Leverd7403512008-12-23 15:21:37 -050091 Opt_resvport, Opt_noresvport,
David Howellsb797cac2009-04-03 16:42:48 +010092 Opt_fscache, Opt_nofscache,
Chuck Lever89652612012-09-14 17:24:11 -040093 Opt_migration, Opt_nomigration,
Chuck Leverbf0fd762007-07-01 12:13:44 -040094
95 /* Mount options that take integer arguments */
96 Opt_port,
97 Opt_rsize, Opt_wsize, Opt_bsize,
98 Opt_timeo, Opt_retrans,
99 Opt_acregmin, Opt_acregmax,
100 Opt_acdirmin, Opt_acdirmax,
101 Opt_actimeo,
102 Opt_namelen,
103 Opt_mountport,
Chuck Levere887cbc2007-10-26 13:32:29 -0400104 Opt_mountvers,
Mike Sager3fd5be92009-04-01 09:21:48 -0400105 Opt_minorversion,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400106
107 /* Mount options that take string arguments */
Trond Myklebust0d71b052012-03-02 13:59:49 -0500108 Opt_nfsvers,
Chuck Lever33832032007-12-10 14:59:13 -0500109 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
Chuck Lever0ac83772007-09-11 18:01:04 -0400110 Opt_addr, Opt_mountaddr, Opt_clientaddr,
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400111 Opt_lookupcache,
David Howellsb797cac2009-04-03 16:42:48 +0100112 Opt_fscache_uniq,
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400113 Opt_local_lock,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400114
Chuck Leverf45663c2008-06-24 19:28:02 -0400115 /* Special mount options */
116 Opt_userspace, Opt_deprecated, Opt_sloppy,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400117
118 Opt_err
119};
120
Steven Whitehousea447c092008-10-13 10:46:57 +0100121static const match_table_t nfs_mount_option_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400122 { Opt_userspace, "bg" },
123 { Opt_userspace, "fg" },
Chuck Leverecbb3842008-06-12 12:37:33 -0400124 { Opt_userspace, "retry=%s" },
125
Chuck Leverf45663c2008-06-24 19:28:02 -0400126 { Opt_sloppy, "sloppy" },
127
Chuck Leverbf0fd762007-07-01 12:13:44 -0400128 { Opt_soft, "soft" },
129 { Opt_hard, "hard" },
Chuck Leverd33e4df2008-06-12 12:37:41 -0400130 { Opt_deprecated, "intr" },
131 { Opt_deprecated, "nointr" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400132 { Opt_posix, "posix" },
133 { Opt_noposix, "noposix" },
134 { Opt_cto, "cto" },
135 { Opt_nocto, "nocto" },
136 { Opt_ac, "ac" },
137 { Opt_noac, "noac" },
138 { Opt_lock, "lock" },
139 { Opt_nolock, "nolock" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400140 { Opt_udp, "udp" },
141 { Opt_tcp, "tcp" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400142 { Opt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400143 { Opt_acl, "acl" },
144 { Opt_noacl, "noacl" },
145 { Opt_rdirplus, "rdirplus" },
146 { Opt_nordirplus, "nordirplus" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400147 { Opt_sharecache, "sharecache" },
148 { Opt_nosharecache, "nosharecache" },
Chuck Leverd7403512008-12-23 15:21:37 -0500149 { Opt_resvport, "resvport" },
150 { Opt_noresvport, "noresvport" },
David Howellsb797cac2009-04-03 16:42:48 +0100151 { Opt_fscache, "fsc" },
David Howellsb797cac2009-04-03 16:42:48 +0100152 { Opt_nofscache, "nofsc" },
Chuck Lever89652612012-09-14 17:24:11 -0400153 { Opt_migration, "migration" },
154 { Opt_nomigration, "nomigration" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400155
Chuck Levera5a16ba2009-06-17 18:02:14 -0700156 { Opt_port, "port=%s" },
157 { Opt_rsize, "rsize=%s" },
158 { Opt_wsize, "wsize=%s" },
159 { Opt_bsize, "bsize=%s" },
160 { Opt_timeo, "timeo=%s" },
161 { Opt_retrans, "retrans=%s" },
162 { Opt_acregmin, "acregmin=%s" },
163 { Opt_acregmax, "acregmax=%s" },
164 { Opt_acdirmin, "acdirmin=%s" },
165 { Opt_acdirmax, "acdirmax=%s" },
166 { Opt_actimeo, "actimeo=%s" },
167 { Opt_namelen, "namlen=%s" },
168 { Opt_mountport, "mountport=%s" },
169 { Opt_mountvers, "mountvers=%s" },
Trond Myklebust0d71b052012-03-02 13:59:49 -0500170 { Opt_minorversion, "minorversion=%s" },
171
Chuck Levera5a16ba2009-06-17 18:02:14 -0700172 { Opt_nfsvers, "nfsvers=%s" },
173 { Opt_nfsvers, "vers=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400174
175 { Opt_sec, "sec=%s" },
176 { Opt_proto, "proto=%s" },
177 { Opt_mountproto, "mountproto=%s" },
178 { Opt_addr, "addr=%s" },
179 { Opt_clientaddr, "clientaddr=%s" },
Chuck Lever33832032007-12-10 14:59:13 -0500180 { Opt_mounthost, "mounthost=%s" },
Chuck Lever0ac83772007-09-11 18:01:04 -0400181 { Opt_mountaddr, "mountaddr=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400182
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400183 { Opt_lookupcache, "lookupcache=%s" },
Chuck Levera6d5ff62010-05-07 13:33:58 -0400184 { Opt_fscache_uniq, "fsc=%s" },
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400185 { Opt_local_lock, "local_lock=%s" },
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400186
Trond Myklebust38622792012-03-02 14:06:39 -0500187 /* The following needs to be listed after all other options */
188 { Opt_nfsvers, "v%s" },
189
Chuck Leverbf0fd762007-07-01 12:13:44 -0400190 { Opt_err, NULL }
191};
192
193enum {
Jeff Laytonee671b02009-12-03 15:58:56 -0500194 Opt_xprt_udp, Opt_xprt_udp6, Opt_xprt_tcp, Opt_xprt_tcp6, Opt_xprt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400195
196 Opt_xprt_err
197};
198
Steven Whitehousea447c092008-10-13 10:46:57 +0100199static const match_table_t nfs_xprt_protocol_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400200 { Opt_xprt_udp, "udp" },
Jeff Laytonee671b02009-12-03 15:58:56 -0500201 { Opt_xprt_udp6, "udp6" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400202 { Opt_xprt_tcp, "tcp" },
Jeff Laytonee671b02009-12-03 15:58:56 -0500203 { Opt_xprt_tcp6, "tcp6" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400204 { Opt_xprt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400205
206 { Opt_xprt_err, NULL }
207};
208
209enum {
210 Opt_sec_none, Opt_sec_sys,
211 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
212 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
213 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
214
215 Opt_sec_err
216};
217
Steven Whitehousea447c092008-10-13 10:46:57 +0100218static const match_table_t nfs_secflavor_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400219 { Opt_sec_none, "none" },
220 { Opt_sec_none, "null" },
221 { Opt_sec_sys, "sys" },
222
223 { Opt_sec_krb5, "krb5" },
224 { Opt_sec_krb5i, "krb5i" },
225 { Opt_sec_krb5p, "krb5p" },
226
227 { Opt_sec_lkey, "lkey" },
228 { Opt_sec_lkeyi, "lkeyi" },
229 { Opt_sec_lkeyp, "lkeyp" },
230
Olga Kornievskaia8d042212008-02-13 16:47:06 -0500231 { Opt_sec_spkm, "spkm3" },
232 { Opt_sec_spkmi, "spkm3i" },
233 { Opt_sec_spkmp, "spkm3p" },
234
Chuck Leverbf0fd762007-07-01 12:13:44 -0400235 { Opt_sec_err, NULL }
236};
237
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400238enum {
239 Opt_lookupcache_all, Opt_lookupcache_positive,
240 Opt_lookupcache_none,
241
242 Opt_lookupcache_err
243};
244
245static match_table_t nfs_lookupcache_tokens = {
246 { Opt_lookupcache_all, "all" },
247 { Opt_lookupcache_positive, "pos" },
248 { Opt_lookupcache_positive, "positive" },
249 { Opt_lookupcache_none, "none" },
250
251 { Opt_lookupcache_err, NULL }
252};
253
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400254enum {
255 Opt_local_lock_all, Opt_local_lock_flock, Opt_local_lock_posix,
256 Opt_local_lock_none,
257
258 Opt_local_lock_err
259};
260
261static match_table_t nfs_local_lock_tokens = {
262 { Opt_local_lock_all, "all" },
263 { Opt_local_lock_flock, "flock" },
264 { Opt_local_lock_posix, "posix" },
265 { Opt_local_lock_none, "none" },
266
267 { Opt_local_lock_err, NULL }
268};
269
Trond Myklebust0d71b052012-03-02 13:59:49 -0500270enum {
271 Opt_vers_2, Opt_vers_3, Opt_vers_4, Opt_vers_4_0,
272 Opt_vers_4_1,
273
274 Opt_vers_err
275};
276
277static match_table_t nfs_vers_tokens = {
278 { Opt_vers_2, "2" },
279 { Opt_vers_3, "3" },
280 { Opt_vers_4, "4" },
281 { Opt_vers_4_0, "4.0" },
282 { Opt_vers_4_1, "4.1" },
283
284 { Opt_vers_err, NULL }
285};
Chuck Leverbf0fd762007-07-01 12:13:44 -0400286
Al Viro31f43472010-10-29 03:38:12 -0400287static struct dentry *nfs_xdev_mount(struct file_system_type *fs_type,
288 int flags, const char *dev_name, void *raw_data);
David Howellsf7b422b2006-06-09 09:34:33 -0400289
Bryan Schumakerab7017a2012-07-30 16:05:16 -0400290struct file_system_type nfs_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400291 .owner = THIS_MODULE,
292 .name = "nfs",
Al Viro01194982011-03-16 07:25:36 -0400293 .mount = nfs_fs_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400294 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700295 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400296};
Bryan Schumakerddda8e02012-07-30 16:05:23 -0400297EXPORT_SYMBOL_GPL(nfs_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400298
David Howells54ceac42006-08-22 20:06:13 -0400299struct file_system_type nfs_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400300 .owner = THIS_MODULE,
301 .name = "nfs",
Al Viro31f43472010-10-29 03:38:12 -0400302 .mount = nfs_xdev_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400303 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700304 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400305};
306
Bryan Schumaker6a744902012-07-30 16:05:20 -0400307const struct super_operations nfs_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400308 .alloc_inode = nfs_alloc_inode,
309 .destroy_inode = nfs_destroy_inode,
310 .write_inode = nfs_write_inode,
Trond Myklebust387c1492010-02-03 08:27:35 -0500311 .put_super = nfs_put_super,
David Howellsf7b422b2006-06-09 09:34:33 -0400312 .statfs = nfs_statfs,
Al Virob57922d2010-06-07 14:34:48 -0400313 .evict_inode = nfs_evict_inode,
David Howellsf7b422b2006-06-09 09:34:33 -0400314 .umount_begin = nfs_umount_begin,
315 .show_options = nfs_show_options,
Al Viroc7f404b2011-03-16 06:59:40 -0400316 .show_devname = nfs_show_devname,
317 .show_path = nfs_show_path,
David Howellsf7b422b2006-06-09 09:34:33 -0400318 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400319 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400320};
Bryan Schumakerddda8e02012-07-30 16:05:23 -0400321EXPORT_SYMBOL_GPL(nfs_sops);
David Howellsf7b422b2006-06-09 09:34:33 -0400322
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400323#if IS_ENABLED(CONFIG_NFS_V4)
Bryan Schumakerb72e4f42012-05-10 15:07:40 -0400324static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *);
Bryan Schumakerd72c7272012-05-10 15:07:41 -0400325static int nfs4_validate_mount_data(void *options,
326 struct nfs_parsed_mount_data *args, const char *dev_name);
bjschuma@gmail.com1ae811e2012-08-08 13:57:06 -0400327
328struct file_system_type nfs4_fs_type = {
329 .owner = THIS_MODULE,
330 .name = "nfs4",
331 .mount = nfs_fs_mount,
332 .kill_sb = nfs_kill_super,
333 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
334};
335EXPORT_SYMBOL_GPL(nfs4_fs_type);
336
337static int __init register_nfs4_fs(void)
338{
339 return register_filesystem(&nfs4_fs_type);
340}
341
342static void unregister_nfs4_fs(void)
343{
344 unregister_filesystem(&nfs4_fs_type);
345}
346#else
347static int __init register_nfs4_fs(void)
348{
349 return 0;
350}
351
352static void unregister_nfs4_fs(void)
353{
354}
David Howellsf7b422b2006-06-09 09:34:33 -0400355#endif
356
Rusty Russell8e1f9362007-07-17 04:03:17 -0700357static struct shrinker acl_shrinker = {
358 .shrink = nfs_access_cache_shrinker,
359 .seeks = DEFAULT_SEEKS,
360};
Trond Myklebust979df722006-07-25 11:28:19 -0400361
David Howellsf7b422b2006-06-09 09:34:33 -0400362/*
363 * Register the NFS filesystems
364 */
365int __init register_nfs_fs(void)
366{
367 int ret;
368
369 ret = register_filesystem(&nfs_fs_type);
370 if (ret < 0)
371 goto error_0;
372
bjschuma@gmail.com1ae811e2012-08-08 13:57:06 -0400373 ret = register_nfs4_fs();
David Howellsf7b422b2006-06-09 09:34:33 -0400374 if (ret < 0)
375 goto error_1;
bjschuma@gmail.com1ae811e2012-08-08 13:57:06 -0400376
377 ret = nfs_register_sysctl();
378 if (ret < 0)
379 goto error_2;
Rusty Russell8e1f9362007-07-17 04:03:17 -0700380 register_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400381 return 0;
382
bjschuma@gmail.com1ae811e2012-08-08 13:57:06 -0400383error_2:
384 unregister_nfs4_fs();
David Howellsf7b422b2006-06-09 09:34:33 -0400385error_1:
386 unregister_filesystem(&nfs_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400387error_0:
388 return ret;
389}
390
391/*
392 * Unregister the NFS filesystems
393 */
394void __exit unregister_nfs_fs(void)
395{
Rusty Russell8e1f9362007-07-17 04:03:17 -0700396 unregister_shrinker(&acl_shrinker);
Alexey Dobriyan49af7ee2007-09-18 22:46:40 -0700397 nfs_unregister_sysctl();
bjschuma@gmail.com1ae811e2012-08-08 13:57:06 -0400398 unregister_nfs4_fs();
David Howellsf7b422b2006-06-09 09:34:33 -0400399 unregister_filesystem(&nfs_fs_type);
400}
401
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400402void nfs_sb_active(struct super_block *sb)
Steve Dicksonef818a22007-11-08 04:05:04 -0500403{
404 struct nfs_server *server = NFS_SB(sb);
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400405
406 if (atomic_inc_return(&server->active) == 1)
407 atomic_inc(&sb->s_active);
408}
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400409EXPORT_SYMBOL_GPL(nfs_sb_active);
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400410
411void nfs_sb_deactive(struct super_block *sb)
412{
413 struct nfs_server *server = NFS_SB(sb);
414
415 if (atomic_dec_and_test(&server->active))
416 deactivate_super(sb);
Steve Dicksonef818a22007-11-08 04:05:04 -0500417}
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400418EXPORT_SYMBOL_GPL(nfs_sb_deactive);
Steve Dicksonef818a22007-11-08 04:05:04 -0500419
Weston Andros Adamson324d0032012-10-30 17:01:39 -0400420static int nfs_deactivate_super_async_work(void *ptr)
421{
422 struct super_block *sb = ptr;
423
424 deactivate_super(sb);
425 module_put_and_exit(0);
426 return 0;
427}
428
429/*
430 * same effect as deactivate_super, but will do final unmount in kthread
431 * context
432 */
433static void nfs_deactivate_super_async(struct super_block *sb)
434{
435 struct task_struct *task;
436 char buf[INET6_ADDRSTRLEN + 1];
437 struct nfs_server *server = NFS_SB(sb);
438 struct nfs_client *clp = server->nfs_client;
439
440 if (!atomic_add_unless(&sb->s_active, -1, 1)) {
441 rcu_read_lock();
442 snprintf(buf, sizeof(buf),
443 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR));
444 rcu_read_unlock();
445
446 __module_get(THIS_MODULE);
447 task = kthread_run(nfs_deactivate_super_async_work, sb,
448 "%s-deactivate-super", buf);
449 if (IS_ERR(task)) {
450 pr_err("%s: kthread_run: %ld\n",
451 __func__, PTR_ERR(task));
452 /* make synchronous call and hope for the best */
453 deactivate_super(sb);
454 module_put(THIS_MODULE);
455 }
456 }
457}
458
459void nfs_sb_deactive_async(struct super_block *sb)
460{
461 struct nfs_server *server = NFS_SB(sb);
462
463 if (atomic_dec_and_test(&server->active))
464 nfs_deactivate_super_async(sb);
465}
466EXPORT_SYMBOL_GPL(nfs_sb_deactive_async);
467
David Howellsf7b422b2006-06-09 09:34:33 -0400468/*
469 * Deliver file system statistics to userspace
470 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -0400471int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
David Howellsf7b422b2006-06-09 09:34:33 -0400472{
David Howells0c7d90c2006-08-22 20:06:10 -0400473 struct nfs_server *server = NFS_SB(dentry->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400474 unsigned char blockbits;
475 unsigned long blockres;
David Howells0c7d90c2006-08-22 20:06:10 -0400476 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400477 struct nfs_fsstat res;
478 int error = -ENOMEM;
479
480 res.fattr = nfs_alloc_fattr();
481 if (res.fattr == NULL)
482 goto out_err;
David Howellsf7b422b2006-06-09 09:34:33 -0400483
David Howells8fa5c002006-08-22 20:06:12 -0400484 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
Menyhart Zoltanfbf3fdd2010-09-12 19:55:26 -0400485 if (unlikely(error == -ESTALE)) {
486 struct dentry *pd_dentry;
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400487
Menyhart Zoltanfbf3fdd2010-09-12 19:55:26 -0400488 pd_dentry = dget_parent(dentry);
489 if (pd_dentry != NULL) {
490 nfs_zap_caches(pd_dentry->d_inode);
491 dput(pd_dentry);
492 }
493 }
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400494 nfs_free_fattr(res.fattr);
David Howellsf7b422b2006-06-09 09:34:33 -0400495 if (error < 0)
496 goto out_err;
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400497
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700498 buf->f_type = NFS_SUPER_MAGIC;
David Howellsf7b422b2006-06-09 09:34:33 -0400499
500 /*
501 * Current versions of glibc do not correctly handle the
502 * case where f_frsize != f_bsize. Eventually we want to
503 * report the value of wtmult in this field.
504 */
David Howells0c7d90c2006-08-22 20:06:10 -0400505 buf->f_frsize = dentry->d_sb->s_blocksize;
David Howellsf7b422b2006-06-09 09:34:33 -0400506
507 /*
508 * On most *nix systems, f_blocks, f_bfree, and f_bavail
509 * are reported in units of f_frsize. Linux hasn't had
510 * an f_frsize field in its statfs struct until recently,
511 * thus historically Linux's sys_statfs reports these
512 * fields in units of f_bsize.
513 */
David Howells0c7d90c2006-08-22 20:06:10 -0400514 buf->f_bsize = dentry->d_sb->s_blocksize;
515 blockbits = dentry->d_sb->s_blocksize_bits;
David Howellsf7b422b2006-06-09 09:34:33 -0400516 blockres = (1 << blockbits) - 1;
517 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
518 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
519 buf->f_bavail = (res.abytes + blockres) >> blockbits;
520
521 buf->f_files = res.tfiles;
522 buf->f_ffree = res.afiles;
523
524 buf->f_namelen = server->namelen;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700525
David Howellsf7b422b2006-06-09 09:34:33 -0400526 return 0;
527
528 out_err:
Harvey Harrison3110ff82008-05-02 13:42:44 -0700529 dprintk("%s: statfs error = %d\n", __func__, -error);
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700530 return error;
David Howellsf7b422b2006-06-09 09:34:33 -0400531}
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400532EXPORT_SYMBOL_GPL(nfs_statfs);
David Howellsf7b422b2006-06-09 09:34:33 -0400533
David Howells7d4e2742006-08-22 20:06:07 -0400534/*
535 * Map the security flavour number to a name
536 */
Trond Myklebust81039f12006-06-09 09:34:34 -0400537static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
538{
David Howells7d4e2742006-08-22 20:06:07 -0400539 static const struct {
Trond Myklebust81039f12006-06-09 09:34:34 -0400540 rpc_authflavor_t flavour;
541 const char *str;
542 } sec_flavours[] = {
543 { RPC_AUTH_NULL, "null" },
544 { RPC_AUTH_UNIX, "sys" },
545 { RPC_AUTH_GSS_KRB5, "krb5" },
546 { RPC_AUTH_GSS_KRB5I, "krb5i" },
547 { RPC_AUTH_GSS_KRB5P, "krb5p" },
548 { RPC_AUTH_GSS_LKEY, "lkey" },
549 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
550 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
551 { RPC_AUTH_GSS_SPKM, "spkm" },
552 { RPC_AUTH_GSS_SPKMI, "spkmi" },
553 { RPC_AUTH_GSS_SPKMP, "spkmp" },
Chuck Lever4d81cd12007-07-01 12:12:40 -0400554 { UINT_MAX, "unknown" }
Trond Myklebust81039f12006-06-09 09:34:34 -0400555 };
556 int i;
557
Chuck Lever4d81cd12007-07-01 12:12:40 -0400558 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
Trond Myklebust81039f12006-06-09 09:34:34 -0400559 if (sec_flavours[i].flavour == flavour)
560 break;
561 }
562 return sec_flavours[i].str;
563}
564
Jeff Laytonee671b02009-12-03 15:58:56 -0500565static void nfs_show_mountd_netid(struct seq_file *m, struct nfs_server *nfss,
566 int showdefaults)
567{
568 struct sockaddr *sap = (struct sockaddr *) &nfss->mountd_address;
569
570 seq_printf(m, ",mountproto=");
571 switch (sap->sa_family) {
572 case AF_INET:
573 switch (nfss->mountd_protocol) {
574 case IPPROTO_UDP:
575 seq_printf(m, RPCBIND_NETID_UDP);
576 break;
577 case IPPROTO_TCP:
578 seq_printf(m, RPCBIND_NETID_TCP);
579 break;
580 default:
581 if (showdefaults)
582 seq_printf(m, "auto");
583 }
584 break;
585 case AF_INET6:
586 switch (nfss->mountd_protocol) {
587 case IPPROTO_UDP:
588 seq_printf(m, RPCBIND_NETID_UDP6);
589 break;
590 case IPPROTO_TCP:
591 seq_printf(m, RPCBIND_NETID_TCP6);
592 break;
593 default:
594 if (showdefaults)
595 seq_printf(m, "auto");
596 }
597 break;
598 default:
599 if (showdefaults)
600 seq_printf(m, "auto");
601 }
602}
603
Chuck Lever82d101d2008-03-14 14:10:37 -0400604static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
605 int showdefaults)
606{
607 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
608
Bryan Schumakerd5eff1a2010-08-03 13:04:00 -0400609 if (nfss->flags & NFS_MOUNT_LEGACY_INTERFACE)
610 return;
611
Chuck Lever82d101d2008-03-14 14:10:37 -0400612 switch (sap->sa_family) {
613 case AF_INET: {
614 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
Harvey Harrisonbe859402008-10-31 00:56:28 -0700615 seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400616 break;
617 }
618 case AF_INET6: {
619 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
Chuck Leverd250e192009-12-03 15:58:56 -0500620 seq_printf(m, ",mountaddr=%pI6c", &sin6->sin6_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400621 break;
622 }
623 default:
624 if (showdefaults)
625 seq_printf(m, ",mountaddr=unspecified");
626 }
627
628 if (nfss->mountd_version || showdefaults)
629 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
Stanislav Kinsburskyaa699472010-12-08 12:40:13 +0300630 if ((nfss->mountd_port &&
631 nfss->mountd_port != (unsigned short)NFS_UNSPEC_PORT) ||
632 showdefaults)
Chuck Lever82d101d2008-03-14 14:10:37 -0400633 seq_printf(m, ",mountport=%u", nfss->mountd_port);
634
Jeff Laytonee671b02009-12-03 15:58:56 -0500635 nfs_show_mountd_netid(m, nfss, showdefaults);
Chuck Lever82d101d2008-03-14 14:10:37 -0400636}
637
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400638#if IS_ENABLED(CONFIG_NFS_V4)
Trond Myklebust0be81892010-06-18 12:23:58 -0400639static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
640 int showdefaults)
641{
642 struct nfs_client *clp = nfss->nfs_client;
643
644 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
Trond Myklebust0be81892010-06-18 12:23:58 -0400645}
646#else
647static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
648 int showdefaults)
649{
650}
651#endif
652
Trond Myklebust7bbceb62012-03-02 14:00:20 -0500653static void nfs_show_nfs_version(struct seq_file *m,
654 unsigned int version,
655 unsigned int minorversion)
656{
657 seq_printf(m, ",vers=%u", version);
658 if (version == 4)
659 seq_printf(m, ".%u", minorversion);
660}
661
David Howellsf7b422b2006-06-09 09:34:33 -0400662/*
663 * Describe the mount options in force on this server representation
664 */
Chuck Lever82d101d2008-03-14 14:10:37 -0400665static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
666 int showdefaults)
David Howellsf7b422b2006-06-09 09:34:33 -0400667{
David Howells509de812006-08-22 20:06:11 -0400668 static const struct proc_nfs_info {
David Howellsf7b422b2006-06-09 09:34:33 -0400669 int flag;
David Howells509de812006-08-22 20:06:11 -0400670 const char *str;
671 const char *nostr;
David Howellsf7b422b2006-06-09 09:34:33 -0400672 } nfs_info[] = {
673 { NFS_MOUNT_SOFT, ",soft", ",hard" },
Chuck Lever82d101d2008-03-14 14:10:37 -0400674 { NFS_MOUNT_POSIX, ",posix", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400675 { NFS_MOUNT_NOCTO, ",nocto", "" },
676 { NFS_MOUNT_NOAC, ",noac", "" },
677 { NFS_MOUNT_NONLM, ",nolock", "" },
678 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400679 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
Chuck Leverd7403512008-12-23 15:21:37 -0500680 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
681 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400682 { 0, NULL, NULL }
683 };
David Howells509de812006-08-22 20:06:11 -0400684 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400685 struct nfs_client *clp = nfss->nfs_client;
Chuck Lever82d101d2008-03-14 14:10:37 -0400686 u32 version = clp->rpc_ops->version;
Suresh Jayaraman7c563cc2010-09-23 14:26:48 -0400687 int local_flock, local_fcntl;
David Howellsf7b422b2006-06-09 09:34:33 -0400688
Trond Myklebust7bbceb62012-03-02 14:00:20 -0500689 nfs_show_nfs_version(m, version, clp->cl_minorversion);
Chuck Lever2d767432008-03-14 14:10:08 -0400690 seq_printf(m, ",rsize=%u", nfss->rsize);
691 seq_printf(m, ",wsize=%u", nfss->wsize);
Chuck Lever82d101d2008-03-14 14:10:37 -0400692 if (nfss->bsize != 0)
693 seq_printf(m, ",bsize=%u", nfss->bsize);
694 seq_printf(m, ",namlen=%u", nfss->namelen);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400695 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400696 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400697 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400698 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400699 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400700 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400701 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400702 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
David Howellsf7b422b2006-06-09 09:34:33 -0400703 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
704 if (nfss->flags & nfs_infop->flag)
705 seq_puts(m, nfs_infop->str);
706 else
707 seq_puts(m, nfs_infop->nostr);
708 }
Trond Myklebust2446ab62012-03-01 17:00:56 -0500709 rcu_read_lock();
\"Talpey, Thomas\56928ed2007-09-10 13:48:47 -0400710 seq_printf(m, ",proto=%s",
Jeff Laytonee671b02009-12-03 15:58:56 -0500711 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
Trond Myklebust2446ab62012-03-01 17:00:56 -0500712 rcu_read_unlock();
Chuck Lever82d101d2008-03-14 14:10:37 -0400713 if (version == 4) {
714 if (nfss->port != NFS_PORT)
715 seq_printf(m, ",port=%u", nfss->port);
716 } else
717 if (nfss->port)
718 seq_printf(m, ",port=%u", nfss->port);
719
Trond Myklebust33170232007-12-20 16:03:59 -0500720 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
721 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
Trond Myklebust81039f12006-06-09 09:34:34 -0400722 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
Chuck Lever82d101d2008-03-14 14:10:37 -0400723
724 if (version != 4)
725 nfs_show_mountd_options(m, nfss, showdefaults);
Trond Myklebust0be81892010-06-18 12:23:58 -0400726 else
727 nfs_show_nfsv4_options(m, nfss, showdefaults);
Chuck Lever82d101d2008-03-14 14:10:37 -0400728
David Howellsb797cac2009-04-03 16:42:48 +0100729 if (nfss->options & NFS_OPTION_FSCACHE)
730 seq_printf(m, ",fsc");
Patrick J. LoPresti9b00c642010-08-10 17:28:01 -0400731
Chuck Lever89652612012-09-14 17:24:11 -0400732 if (nfss->options & NFS_OPTION_MIGRATION)
733 seq_printf(m, ",migration");
734
Patrick J. LoPresti9b00c642010-08-10 17:28:01 -0400735 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONEG) {
736 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONE)
737 seq_printf(m, ",lookupcache=none");
738 else
739 seq_printf(m, ",lookupcache=pos");
740 }
Suresh Jayaraman7c563cc2010-09-23 14:26:48 -0400741
742 local_flock = nfss->flags & NFS_MOUNT_LOCAL_FLOCK;
743 local_fcntl = nfss->flags & NFS_MOUNT_LOCAL_FCNTL;
744
745 if (!local_flock && !local_fcntl)
746 seq_printf(m, ",local_lock=none");
747 else if (local_flock && local_fcntl)
748 seq_printf(m, ",local_lock=all");
749 else if (local_flock)
750 seq_printf(m, ",local_lock=flock");
751 else
752 seq_printf(m, ",local_lock=posix");
David Howellsf7b422b2006-06-09 09:34:33 -0400753}
754
755/*
756 * Describe the mount options on this VFS mountpoint
757 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -0400758int nfs_show_options(struct seq_file *m, struct dentry *root)
David Howellsf7b422b2006-06-09 09:34:33 -0400759{
Al Viro34c80b12011-12-08 21:32:45 -0500760 struct nfs_server *nfss = NFS_SB(root->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400761
762 nfs_show_mount_options(m, nfss, 0);
763
Trond Myklebust2446ab62012-03-01 17:00:56 -0500764 rcu_read_lock();
Chuck Lever5d8515c2007-12-10 14:57:16 -0500765 seq_printf(m, ",addr=%s",
766 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
767 RPC_DISPLAY_ADDR));
Trond Myklebust2446ab62012-03-01 17:00:56 -0500768 rcu_read_unlock();
David Howellsf7b422b2006-06-09 09:34:33 -0400769
770 return 0;
771}
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400772EXPORT_SYMBOL_GPL(nfs_show_options);
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700773
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400774#if IS_ENABLED(CONFIG_NFS_V4)
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300775#ifdef CONFIG_NFS_V4_1
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700776static void show_sessions(struct seq_file *m, struct nfs_server *server)
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300777{
778 if (nfs4_has_session(server->nfs_client))
779 seq_printf(m, ",sessions");
780}
781#else
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700782static void show_sessions(struct seq_file *m, struct nfs_server *server) {}
783#endif
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300784#endif
785
786#ifdef CONFIG_NFS_V4_1
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700787static void show_pnfs(struct seq_file *m, struct nfs_server *server)
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300788{
789 seq_printf(m, ",pnfs=");
790 if (server->pnfs_curr_ld)
791 seq_printf(m, "%s", server->pnfs_curr_ld->name);
792 else
793 seq_printf(m, "not configured");
794}
Trond Myklebust7e03b7c2012-03-04 18:12:57 -0500795
796static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
797{
Chuck Lever59155542012-05-21 22:44:41 -0400798 if (nfss->nfs_client && nfss->nfs_client->cl_implid) {
799 struct nfs41_impl_id *impl_id = nfss->nfs_client->cl_implid;
Trond Myklebust7e03b7c2012-03-04 18:12:57 -0500800 seq_printf(m, "\n\timpl_id:\tname='%s',domain='%s',"
801 "date='%llu,%u'",
802 impl_id->name, impl_id->domain,
803 impl_id->date.seconds, impl_id->date.nseconds);
804 }
805}
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700806#else
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400807#if IS_ENABLED(CONFIG_NFS_V4)
Trond Myklebust7e03b7c2012-03-04 18:12:57 -0500808static void show_pnfs(struct seq_file *m, struct nfs_server *server)
809{
810}
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700811#endif
Trond Myklebust7e03b7c2012-03-04 18:12:57 -0500812static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
813{
814}
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700815#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400816
Bryan Schumakerfbdefd62012-07-16 16:39:20 -0400817int nfs_show_devname(struct seq_file *m, struct dentry *root)
Al Viroc7f404b2011-03-16 06:59:40 -0400818{
819 char *page = (char *) __get_free_page(GFP_KERNEL);
820 char *devname, *dummy;
821 int err = 0;
822 if (!page)
823 return -ENOMEM;
Ben Hutchings97a54862012-10-21 19:23:52 +0100824 devname = nfs_path(&dummy, root, page, PAGE_SIZE, 0);
Al Viroc7f404b2011-03-16 06:59:40 -0400825 if (IS_ERR(devname))
826 err = PTR_ERR(devname);
827 else
828 seq_escape(m, devname, " \t\n\\");
829 free_page((unsigned long)page);
830 return err;
831}
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400832EXPORT_SYMBOL_GPL(nfs_show_devname);
Al Viroc7f404b2011-03-16 06:59:40 -0400833
Bryan Schumakerfbdefd62012-07-16 16:39:20 -0400834int nfs_show_path(struct seq_file *m, struct dentry *dentry)
Al Viroc7f404b2011-03-16 06:59:40 -0400835{
836 seq_puts(m, "/");
837 return 0;
838}
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400839EXPORT_SYMBOL_GPL(nfs_show_path);
Al Viroc7f404b2011-03-16 06:59:40 -0400840
David Howellsf7b422b2006-06-09 09:34:33 -0400841/*
842 * Present statistical information for this VFS mountpoint
843 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -0400844int nfs_show_stats(struct seq_file *m, struct dentry *root)
David Howellsf7b422b2006-06-09 09:34:33 -0400845{
846 int i, cpu;
Al Viro64132372011-12-08 20:51:13 -0500847 struct nfs_server *nfss = NFS_SB(root->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400848 struct rpc_auth *auth = nfss->client->cl_auth;
849 struct nfs_iostats totals = { };
850
851 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
852
853 /*
854 * Display all mount option settings
855 */
856 seq_printf(m, "\n\topts:\t");
Al Viro64132372011-12-08 20:51:13 -0500857 seq_puts(m, root->d_sb->s_flags & MS_RDONLY ? "ro" : "rw");
858 seq_puts(m, root->d_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
859 seq_puts(m, root->d_sb->s_flags & MS_NOATIME ? ",noatime" : "");
860 seq_puts(m, root->d_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
David Howellsf7b422b2006-06-09 09:34:33 -0400861 nfs_show_mount_options(m, nfss, 1);
862
863 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
864
Trond Myklebust7e03b7c2012-03-04 18:12:57 -0500865 show_implementation_id(m, nfss);
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500866
David Howellsf7b422b2006-06-09 09:34:33 -0400867 seq_printf(m, "\n\tcaps:\t");
868 seq_printf(m, "caps=0x%x", nfss->caps);
Chuck Lever2d767432008-03-14 14:10:08 -0400869 seq_printf(m, ",wtmult=%u", nfss->wtmult);
870 seq_printf(m, ",dtsize=%u", nfss->dtsize);
871 seq_printf(m, ",bsize=%u", nfss->bsize);
872 seq_printf(m, ",namlen=%u", nfss->namelen);
David Howellsf7b422b2006-06-09 09:34:33 -0400873
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400874#if IS_ENABLED(CONFIG_NFS_V4)
Trond Myklebust40c553192007-12-14 14:56:07 -0500875 if (nfss->nfs_client->rpc_ops->version == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400876 seq_printf(m, "\n\tnfsv4:\t");
877 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
878 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
879 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300880 show_sessions(m, nfss);
881 show_pnfs(m, nfss);
David Howellsf7b422b2006-06-09 09:34:33 -0400882 }
883#endif
884
885 /*
886 * Display security flavor in effect for this mount
887 */
Chuck Lever2d767432008-03-14 14:10:08 -0400888 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400889 if (auth->au_flavor)
Chuck Lever2d767432008-03-14 14:10:08 -0400890 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400891
892 /*
893 * Display superblock I/O counters
894 */
895 for_each_possible_cpu(cpu) {
896 struct nfs_iostats *stats;
897
898 preempt_disable();
899 stats = per_cpu_ptr(nfss->io_stats, cpu);
900
901 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
902 totals.events[i] += stats->events[i];
903 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
904 totals.bytes[i] += stats->bytes[i];
David Howells6a510912009-04-03 16:42:43 +0100905#ifdef CONFIG_NFS_FSCACHE
906 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
907 totals.fscache[i] += stats->fscache[i];
908#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400909
910 preempt_enable();
911 }
912
913 seq_printf(m, "\n\tevents:\t");
914 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
915 seq_printf(m, "%lu ", totals.events[i]);
916 seq_printf(m, "\n\tbytes:\t");
917 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
918 seq_printf(m, "%Lu ", totals.bytes[i]);
David Howells6a510912009-04-03 16:42:43 +0100919#ifdef CONFIG_NFS_FSCACHE
920 if (nfss->options & NFS_OPTION_FSCACHE) {
921 seq_printf(m, "\n\tfsc:\t");
922 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
923 seq_printf(m, "%Lu ", totals.bytes[i]);
924 }
925#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400926 seq_printf(m, "\n");
927
928 rpc_print_iostats(m, nfss->client);
929
930 return 0;
931}
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400932EXPORT_SYMBOL_GPL(nfs_show_stats);
David Howellsf7b422b2006-06-09 09:34:33 -0400933
934/*
935 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400936 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400937 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -0400938void nfs_umount_begin(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -0400939{
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200940 struct nfs_server *server;
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400941 struct rpc_clnt *rpc;
942
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200943 server = NFS_SB(sb);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400944 /* -EIO all pending I/O */
945 rpc = server->client_acl;
946 if (!IS_ERR(rpc))
947 rpc_killall_tasks(rpc);
948 rpc = server->client;
949 if (!IS_ERR(rpc))
950 rpc_killall_tasks(rpc);
David Howellsf7b422b2006-06-09 09:34:33 -0400951}
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400952EXPORT_SYMBOL_GPL(nfs_umount_begin);
David Howellsf7b422b2006-06-09 09:34:33 -0400953
Bryan Schumakerdb833352012-05-10 15:07:38 -0400954static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(void)
Chuck Lever9423a082009-09-23 14:36:38 -0400955{
956 struct nfs_parsed_mount_data *data;
957
958 data = kzalloc(sizeof(*data), GFP_KERNEL);
959 if (data) {
Chuck Lever9423a082009-09-23 14:36:38 -0400960 data->acregmin = NFS_DEF_ACREGMIN;
961 data->acregmax = NFS_DEF_ACREGMAX;
962 data->acdirmin = NFS_DEF_ACDIRMIN;
963 data->acdirmax = NFS_DEF_ACDIRMAX;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400964 data->mount_server.port = NFS_UNSPEC_PORT;
Chuck Lever9423a082009-09-23 14:36:38 -0400965 data->nfs_server.port = NFS_UNSPEC_PORT;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400966 data->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Lever9423a082009-09-23 14:36:38 -0400967 data->auth_flavors[0] = RPC_AUTH_UNIX;
968 data->auth_flavor_len = 1;
969 data->minorversion = 0;
Bryan Schumakerb72e4f42012-05-10 15:07:40 -0400970 data->need_mount = true;
Trond Myklebust9937347a2012-02-19 08:44:07 +0100971 data->net = current->nsproxy->net_ns;
Jeff Layton8a0d5512011-12-20 06:57:45 -0500972 security_init_mnt_opts(&data->lsm_opts);
Chuck Lever9423a082009-09-23 14:36:38 -0400973 }
974 return data;
975}
976
Jeff Layton8a0d5512011-12-20 06:57:45 -0500977static void nfs_free_parsed_mount_data(struct nfs_parsed_mount_data *data)
978{
979 if (data) {
980 kfree(data->client_address);
981 kfree(data->mount_server.hostname);
982 kfree(data->nfs_server.export_path);
983 kfree(data->nfs_server.hostname);
984 kfree(data->fscache_uniq);
985 security_free_mnt_opts(&data->lsm_opts);
986 kfree(data);
987 }
988}
989
David Howellsf7b422b2006-06-09 09:34:33 -0400990/*
Chuck Levercdcd7f92007-12-10 14:57:45 -0500991 * Sanity-check a server address provided by the mount command.
992 *
993 * Address family must be initialized, and address must not be
994 * the ANY address for that family.
Chuck Leverfc50d582007-07-01 12:12:46 -0400995 */
996static int nfs_verify_server_address(struct sockaddr *addr)
997{
998 switch (addr->sa_family) {
999 case AF_INET: {
Chuck Levercdcd7f92007-12-10 14:57:45 -05001000 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
Al Viroe6f1ceb2008-03-17 22:44:53 -07001001 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
Chuck Levercdcd7f92007-12-10 14:57:45 -05001002 }
1003 case AF_INET6: {
1004 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
1005 return !ipv6_addr_any(sa);
Chuck Leverfc50d582007-07-01 12:12:46 -04001006 }
1007 }
1008
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001009 dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
Chuck Leverfc50d582007-07-01 12:12:46 -04001010 return 0;
1011}
1012
Chuck Lever9412b922007-12-10 14:59:21 -05001013/*
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001014 * Select between a default port value and a user-specified port value.
1015 * If a zero value is set, then autobind will be used.
1016 */
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001017static void nfs_set_port(struct sockaddr *sap, int *port,
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001018 const unsigned short default_port)
1019{
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001020 if (*port == NFS_UNSPEC_PORT)
1021 *port = default_port;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001022
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001023 rpc_set_port(sap, *port);
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001024}
1025
1026/*
Trond Myklebust259875e2008-07-02 14:43:47 -04001027 * Sanity check the NFS transport protocol.
1028 *
1029 */
1030static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
1031{
1032 switch (mnt->nfs_server.protocol) {
1033 case XPRT_TRANSPORT_UDP:
1034 case XPRT_TRANSPORT_TCP:
1035 case XPRT_TRANSPORT_RDMA:
1036 break;
1037 default:
1038 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1039 }
1040}
1041
1042/*
1043 * For text based NFSv2/v3 mounts, the mount protocol transport default
1044 * settings should depend upon the specified NFS transport.
1045 */
1046static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
1047{
1048 nfs_validate_transport_protocol(mnt);
1049
1050 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
1051 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
1052 return;
1053 switch (mnt->nfs_server.protocol) {
1054 case XPRT_TRANSPORT_UDP:
1055 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
1056 break;
1057 case XPRT_TRANSPORT_TCP:
1058 case XPRT_TRANSPORT_RDMA:
1059 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
1060 }
1061}
1062
1063/*
Chuck Lever01060c82008-06-24 16:33:38 -04001064 * Parse the value of the 'sec=' option.
Chuck Lever01060c82008-06-24 16:33:38 -04001065 */
1066static int nfs_parse_security_flavors(char *value,
1067 struct nfs_parsed_mount_data *mnt)
1068{
1069 substring_t args[MAX_OPT_ARGS];
1070
1071 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
1072
1073 switch (match_token(value, nfs_secflavor_tokens, args)) {
1074 case Opt_sec_none:
Chuck Lever01060c82008-06-24 16:33:38 -04001075 mnt->auth_flavors[0] = RPC_AUTH_NULL;
1076 break;
1077 case Opt_sec_sys:
Chuck Lever01060c82008-06-24 16:33:38 -04001078 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
1079 break;
1080 case Opt_sec_krb5:
Chuck Lever01060c82008-06-24 16:33:38 -04001081 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
1082 break;
1083 case Opt_sec_krb5i:
Chuck Lever01060c82008-06-24 16:33:38 -04001084 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
1085 break;
1086 case Opt_sec_krb5p:
Chuck Lever01060c82008-06-24 16:33:38 -04001087 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
1088 break;
1089 case Opt_sec_lkey:
Chuck Lever01060c82008-06-24 16:33:38 -04001090 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
1091 break;
1092 case Opt_sec_lkeyi:
Chuck Lever01060c82008-06-24 16:33:38 -04001093 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
1094 break;
1095 case Opt_sec_lkeyp:
Chuck Lever01060c82008-06-24 16:33:38 -04001096 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
1097 break;
1098 case Opt_sec_spkm:
Chuck Lever01060c82008-06-24 16:33:38 -04001099 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
1100 break;
1101 case Opt_sec_spkmi:
Chuck Lever01060c82008-06-24 16:33:38 -04001102 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
1103 break;
1104 case Opt_sec_spkmp:
Chuck Lever01060c82008-06-24 16:33:38 -04001105 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
1106 break;
1107 default:
1108 return 0;
1109 }
1110
Bryan Schumaker9b7160c2011-04-13 14:31:30 -04001111 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
Chuck Lever059f90b2009-08-09 15:09:31 -04001112 mnt->auth_flavor_len = 1;
Chuck Lever01060c82008-06-24 16:33:38 -04001113 return 1;
1114}
1115
Trond Myklebust0d71b052012-03-02 13:59:49 -05001116static int nfs_parse_version_string(char *string,
1117 struct nfs_parsed_mount_data *mnt,
1118 substring_t *args)
1119{
1120 mnt->flags &= ~NFS_MOUNT_VER3;
1121 switch (match_token(string, nfs_vers_tokens, args)) {
1122 case Opt_vers_2:
1123 mnt->version = 2;
1124 break;
1125 case Opt_vers_3:
1126 mnt->flags |= NFS_MOUNT_VER3;
1127 mnt->version = 3;
1128 break;
1129 case Opt_vers_4:
1130 /* Backward compatibility option. In future,
1131 * the mount program should always supply
1132 * a NFSv4 minor version number.
1133 */
1134 mnt->version = 4;
1135 break;
1136 case Opt_vers_4_0:
1137 mnt->version = 4;
1138 mnt->minorversion = 0;
1139 break;
1140 case Opt_vers_4_1:
1141 mnt->version = 4;
1142 mnt->minorversion = 1;
1143 break;
1144 default:
1145 return 0;
1146 }
1147 return 1;
1148}
1149
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001150static int nfs_get_option_str(substring_t args[], char **option)
1151{
1152 kfree(*option);
1153 *option = match_strdup(args);
1154 return !option;
1155}
1156
1157static int nfs_get_option_ul(substring_t args[], unsigned long *option)
1158{
1159 int rc;
1160 char *string;
1161
1162 string = match_strdup(args);
1163 if (string == NULL)
1164 return -ENOMEM;
Daniel Walter7297cb62012-09-26 21:51:46 +02001165 rc = kstrtoul(string, 10, option);
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001166 kfree(string);
1167
1168 return rc;
1169}
1170
Chuck Lever01060c82008-06-24 16:33:38 -04001171/*
Chuck Leverbf0fd762007-07-01 12:13:44 -04001172 * Error-check and convert a string of mount options from user space into
Chuck Leverf45663c2008-06-24 19:28:02 -04001173 * a data structure. The whole mount string is processed; bad options are
1174 * skipped as they are encountered. If there were no errors, return 1;
1175 * otherwise return 0 (zero).
Chuck Leverbf0fd762007-07-01 12:13:44 -04001176 */
1177static int nfs_parse_mount_options(char *raw,
1178 struct nfs_parsed_mount_data *mnt)
1179{
Eric Parisf9c3a382008-03-05 14:20:18 -05001180 char *p, *string, *secdata;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001181 int rc, sloppy = 0, invalid_option = 0;
Jeff Laytonee671b02009-12-03 15:58:56 -05001182 unsigned short protofamily = AF_UNSPEC;
1183 unsigned short mountfamily = AF_UNSPEC;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001184
1185 if (!raw) {
1186 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
1187 return 1;
1188 }
1189 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
1190
Eric Parisf9c3a382008-03-05 14:20:18 -05001191 secdata = alloc_secdata();
1192 if (!secdata)
1193 goto out_nomem;
1194
1195 rc = security_sb_copy_data(raw, secdata);
1196 if (rc)
1197 goto out_security_failure;
1198
1199 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
1200 if (rc)
1201 goto out_security_failure;
1202
1203 free_secdata(secdata);
1204
Chuck Leverbf0fd762007-07-01 12:13:44 -04001205 while ((p = strsep(&raw, ",")) != NULL) {
1206 substring_t args[MAX_OPT_ARGS];
Chuck Levera5a16ba2009-06-17 18:02:14 -07001207 unsigned long option;
1208 int token;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001209
1210 if (!*p)
1211 continue;
1212
1213 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
1214
1215 token = match_token(p, nfs_mount_option_tokens, args);
1216 switch (token) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001217
1218 /*
1219 * boolean options: foo/nofoo
1220 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001221 case Opt_soft:
1222 mnt->flags |= NFS_MOUNT_SOFT;
1223 break;
1224 case Opt_hard:
1225 mnt->flags &= ~NFS_MOUNT_SOFT;
1226 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001227 case Opt_posix:
1228 mnt->flags |= NFS_MOUNT_POSIX;
1229 break;
1230 case Opt_noposix:
1231 mnt->flags &= ~NFS_MOUNT_POSIX;
1232 break;
1233 case Opt_cto:
1234 mnt->flags &= ~NFS_MOUNT_NOCTO;
1235 break;
1236 case Opt_nocto:
1237 mnt->flags |= NFS_MOUNT_NOCTO;
1238 break;
1239 case Opt_ac:
1240 mnt->flags &= ~NFS_MOUNT_NOAC;
1241 break;
1242 case Opt_noac:
1243 mnt->flags |= NFS_MOUNT_NOAC;
1244 break;
1245 case Opt_lock:
1246 mnt->flags &= ~NFS_MOUNT_NONLM;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001247 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1248 NFS_MOUNT_LOCAL_FCNTL);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001249 break;
1250 case Opt_nolock:
1251 mnt->flags |= NFS_MOUNT_NONLM;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001252 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1253 NFS_MOUNT_LOCAL_FCNTL);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001254 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001255 case Opt_udp:
1256 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001257 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001258 break;
1259 case Opt_tcp:
1260 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001261 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001262 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001263 case Opt_rdma:
1264 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1265 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001266 xprt_load_transport(p);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001267 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001268 case Opt_acl:
1269 mnt->flags &= ~NFS_MOUNT_NOACL;
1270 break;
1271 case Opt_noacl:
1272 mnt->flags |= NFS_MOUNT_NOACL;
1273 break;
1274 case Opt_rdirplus:
1275 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1276 break;
1277 case Opt_nordirplus:
1278 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1279 break;
Trond Myklebust75180df2007-05-16 16:53:28 -04001280 case Opt_sharecache:
1281 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1282 break;
1283 case Opt_nosharecache:
1284 mnt->flags |= NFS_MOUNT_UNSHARED;
1285 break;
Chuck Leverd7403512008-12-23 15:21:37 -05001286 case Opt_resvport:
1287 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1288 break;
1289 case Opt_noresvport:
1290 mnt->flags |= NFS_MOUNT_NORESVPORT;
1291 break;
David Howellsb797cac2009-04-03 16:42:48 +01001292 case Opt_fscache:
1293 mnt->options |= NFS_OPTION_FSCACHE;
1294 kfree(mnt->fscache_uniq);
1295 mnt->fscache_uniq = NULL;
1296 break;
1297 case Opt_nofscache:
1298 mnt->options &= ~NFS_OPTION_FSCACHE;
1299 kfree(mnt->fscache_uniq);
1300 mnt->fscache_uniq = NULL;
1301 break;
Chuck Lever89652612012-09-14 17:24:11 -04001302 case Opt_migration:
1303 mnt->options |= NFS_OPTION_MIGRATION;
1304 break;
1305 case Opt_nomigration:
1306 mnt->options &= NFS_OPTION_MIGRATION;
1307 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001308
Chuck Leverf45663c2008-06-24 19:28:02 -04001309 /*
1310 * options that take numeric values
1311 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001312 case Opt_port:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001313 if (nfs_get_option_ul(args, &option) ||
1314 option > USHRT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001315 goto out_invalid_value;
1316 mnt->nfs_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001317 break;
1318 case Opt_rsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001319 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001320 goto out_invalid_value;
1321 mnt->rsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001322 break;
1323 case Opt_wsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001324 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001325 goto out_invalid_value;
1326 mnt->wsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001327 break;
1328 case Opt_bsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001329 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001330 goto out_invalid_value;
1331 mnt->bsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001332 break;
1333 case Opt_timeo:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001334 if (nfs_get_option_ul(args, &option) || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001335 goto out_invalid_value;
1336 mnt->timeo = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001337 break;
1338 case Opt_retrans:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001339 if (nfs_get_option_ul(args, &option) || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001340 goto out_invalid_value;
1341 mnt->retrans = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001342 break;
1343 case Opt_acregmin:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001344 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001345 goto out_invalid_value;
1346 mnt->acregmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001347 break;
1348 case Opt_acregmax:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001349 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001350 goto out_invalid_value;
1351 mnt->acregmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001352 break;
1353 case Opt_acdirmin:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001354 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001355 goto out_invalid_value;
1356 mnt->acdirmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001357 break;
1358 case Opt_acdirmax:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001359 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001360 goto out_invalid_value;
1361 mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001362 break;
1363 case Opt_actimeo:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001364 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001365 goto out_invalid_value;
1366 mnt->acregmin = mnt->acregmax =
1367 mnt->acdirmin = mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001368 break;
1369 case Opt_namelen:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001370 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001371 goto out_invalid_value;
1372 mnt->namlen = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001373 break;
1374 case Opt_mountport:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001375 if (nfs_get_option_ul(args, &option) ||
1376 option > USHRT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001377 goto out_invalid_value;
1378 mnt->mount_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001379 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001380 case Opt_mountvers:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001381 if (nfs_get_option_ul(args, &option) ||
Chuck Leverf45663c2008-06-24 19:28:02 -04001382 option < NFS_MNT_VERSION ||
Chuck Leverd23c45f2009-06-17 18:02:13 -07001383 option > NFS_MNT3_VERSION)
1384 goto out_invalid_value;
1385 mnt->mount_server.version = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001386 break;
Mike Sager3fd5be92009-04-01 09:21:48 -04001387 case Opt_minorversion:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001388 if (nfs_get_option_ul(args, &option))
Chuck Leverf3f4f4e2009-08-09 15:09:29 -04001389 goto out_invalid_value;
1390 if (option > NFS4_MAX_MINOR_VERSION)
1391 goto out_invalid_value;
1392 mnt->minorversion = option;
Mike Sager3fd5be92009-04-01 09:21:48 -04001393 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001394
Chuck Leverf45663c2008-06-24 19:28:02 -04001395 /*
1396 * options that take text values
1397 */
Trond Myklebust0d71b052012-03-02 13:59:49 -05001398 case Opt_nfsvers:
1399 string = match_strdup(args);
1400 if (string == NULL)
1401 goto out_nomem;
1402 rc = nfs_parse_version_string(string, mnt, args);
1403 kfree(string);
1404 if (!rc)
1405 goto out_invalid_value;
1406 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001407 case Opt_sec:
1408 string = match_strdup(args);
1409 if (string == NULL)
1410 goto out_nomem;
Chuck Lever01060c82008-06-24 16:33:38 -04001411 rc = nfs_parse_security_flavors(string, mnt);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001412 kfree(string);
Chuck Leverf45663c2008-06-24 19:28:02 -04001413 if (!rc) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001414 dfprintk(MOUNT, "NFS: unrecognized "
1415 "security flavor\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001416 return 0;
Chuck Leverf45663c2008-06-24 19:28:02 -04001417 }
Chuck Leverbf0fd762007-07-01 12:13:44 -04001418 break;
1419 case Opt_proto:
1420 string = match_strdup(args);
1421 if (string == NULL)
1422 goto out_nomem;
1423 token = match_token(string,
1424 nfs_xprt_protocol_tokens, args);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001425
Jeff Laytonee671b02009-12-03 15:58:56 -05001426 protofamily = AF_INET;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001427 switch (token) {
Jeff Laytonee671b02009-12-03 15:58:56 -05001428 case Opt_xprt_udp6:
1429 protofamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001430 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001431 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001432 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001433 break;
Jeff Laytonee671b02009-12-03 15:58:56 -05001434 case Opt_xprt_tcp6:
1435 protofamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001436 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001437 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001438 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001439 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001440 case Opt_xprt_rdma:
1441 /* vector side protocols to TCP */
1442 mnt->flags |= NFS_MOUNT_TCP;
1443 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001444 xprt_load_transport(string);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001445 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001446 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001447 dfprintk(MOUNT, "NFS: unrecognized "
1448 "transport protocol\n");
Yinghai Lu4223a4a2009-10-20 14:13:46 +09001449 kfree(string);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001450 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001451 }
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001452 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001453 break;
1454 case Opt_mountproto:
1455 string = match_strdup(args);
1456 if (string == NULL)
1457 goto out_nomem;
1458 token = match_token(string,
1459 nfs_xprt_protocol_tokens, args);
Trond Myklebustd508afb2009-04-06 16:41:35 -07001460 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001461
Jeff Laytonee671b02009-12-03 15:58:56 -05001462 mountfamily = AF_INET;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001463 switch (token) {
Jeff Laytonee671b02009-12-03 15:58:56 -05001464 case Opt_xprt_udp6:
1465 mountfamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001466 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001467 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001468 break;
Jeff Laytonee671b02009-12-03 15:58:56 -05001469 case Opt_xprt_tcp6:
1470 mountfamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001471 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001472 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001473 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001474 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001475 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001476 dfprintk(MOUNT, "NFS: unrecognized "
1477 "transport protocol\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001478 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001479 }
1480 break;
1481 case Opt_addr:
1482 string = match_strdup(args);
1483 if (string == NULL)
1484 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001485 mnt->nfs_server.addrlen =
Stanislav Kinsburskyb48e1272012-01-26 15:11:57 +04001486 rpc_pton(mnt->net, string, strlen(string),
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001487 (struct sockaddr *)
1488 &mnt->nfs_server.address,
1489 sizeof(mnt->nfs_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001490 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001491 if (mnt->nfs_server.addrlen == 0)
1492 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001493 break;
1494 case Opt_clientaddr:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001495 if (nfs_get_option_str(args, &mnt->client_address))
Chuck Leverbf0fd762007-07-01 12:13:44 -04001496 goto out_nomem;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001497 break;
Chuck Lever33832032007-12-10 14:59:13 -05001498 case Opt_mounthost:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001499 if (nfs_get_option_str(args,
1500 &mnt->mount_server.hostname))
Chuck Lever33832032007-12-10 14:59:13 -05001501 goto out_nomem;
Chuck Lever33832032007-12-10 14:59:13 -05001502 break;
Chuck Lever0ac83772007-09-11 18:01:04 -04001503 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001504 string = match_strdup(args);
1505 if (string == NULL)
1506 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001507 mnt->mount_server.addrlen =
Stanislav Kinsburskyb48e1272012-01-26 15:11:57 +04001508 rpc_pton(mnt->net, string, strlen(string),
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001509 (struct sockaddr *)
1510 &mnt->mount_server.address,
1511 sizeof(mnt->mount_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001512 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001513 if (mnt->mount_server.addrlen == 0)
1514 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001515 break;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001516 case Opt_lookupcache:
1517 string = match_strdup(args);
1518 if (string == NULL)
1519 goto out_nomem;
1520 token = match_token(string,
1521 nfs_lookupcache_tokens, args);
1522 kfree(string);
1523 switch (token) {
1524 case Opt_lookupcache_all:
1525 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1526 break;
1527 case Opt_lookupcache_positive:
1528 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1529 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1530 break;
1531 case Opt_lookupcache_none:
1532 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1533 break;
1534 default:
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001535 dfprintk(MOUNT, "NFS: invalid "
1536 "lookupcache argument\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001537 return 0;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001538 };
1539 break;
Chuck Levera6d5ff62010-05-07 13:33:58 -04001540 case Opt_fscache_uniq:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001541 if (nfs_get_option_str(args, &mnt->fscache_uniq))
Chuck Levera6d5ff62010-05-07 13:33:58 -04001542 goto out_nomem;
Chuck Levera6d5ff62010-05-07 13:33:58 -04001543 mnt->options |= NFS_OPTION_FSCACHE;
1544 break;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001545 case Opt_local_lock:
1546 string = match_strdup(args);
1547 if (string == NULL)
1548 goto out_nomem;
1549 token = match_token(string, nfs_local_lock_tokens,
1550 args);
1551 kfree(string);
1552 switch (token) {
1553 case Opt_local_lock_all:
1554 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1555 NFS_MOUNT_LOCAL_FCNTL);
1556 break;
1557 case Opt_local_lock_flock:
1558 mnt->flags |= NFS_MOUNT_LOCAL_FLOCK;
1559 break;
1560 case Opt_local_lock_posix:
1561 mnt->flags |= NFS_MOUNT_LOCAL_FCNTL;
1562 break;
1563 case Opt_local_lock_none:
1564 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1565 NFS_MOUNT_LOCAL_FCNTL);
1566 break;
1567 default:
1568 dfprintk(MOUNT, "NFS: invalid "
1569 "local_lock argument\n");
1570 return 0;
1571 };
1572 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001573
Chuck Leverf45663c2008-06-24 19:28:02 -04001574 /*
1575 * Special options
1576 */
1577 case Opt_sloppy:
1578 sloppy = 1;
1579 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1580 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001581 case Opt_userspace:
1582 case Opt_deprecated:
Chuck Leverd33e4df2008-06-12 12:37:41 -04001583 dfprintk(MOUNT, "NFS: ignoring mount option "
1584 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001585 break;
1586
1587 default:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001588 invalid_option = 1;
Chuck Leverf45663c2008-06-24 19:28:02 -04001589 dfprintk(MOUNT, "NFS: unrecognized mount option "
1590 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001591 }
1592 }
1593
Chuck Leverd23c45f2009-06-17 18:02:13 -07001594 if (!sloppy && invalid_option)
1595 return 0;
1596
Weston Andros Adamson571b7552012-02-01 14:06:41 -05001597 if (mnt->minorversion && mnt->version != 4)
1598 goto out_minorversion_mismatch;
1599
Chuck Lever89652612012-09-14 17:24:11 -04001600 if (mnt->options & NFS_OPTION_MIGRATION &&
1601 mnt->version != 4 && mnt->minorversion != 0)
1602 goto out_migration_misuse;
1603
Jeff Laytonee671b02009-12-03 15:58:56 -05001604 /*
1605 * verify that any proto=/mountproto= options match the address
Peter Meerwald1856b222012-08-18 17:38:54 +02001606 * families in the addr=/mountaddr= options.
Jeff Laytonee671b02009-12-03 15:58:56 -05001607 */
1608 if (protofamily != AF_UNSPEC &&
1609 protofamily != mnt->nfs_server.address.ss_family)
1610 goto out_proto_mismatch;
1611
1612 if (mountfamily != AF_UNSPEC) {
1613 if (mnt->mount_server.addrlen) {
1614 if (mountfamily != mnt->mount_server.address.ss_family)
1615 goto out_mountproto_mismatch;
1616 } else {
1617 if (mountfamily != mnt->nfs_server.address.ss_family)
1618 goto out_mountproto_mismatch;
1619 }
1620 }
1621
Chuck Leverbf0fd762007-07-01 12:13:44 -04001622 return 1;
1623
Jeff Laytonee671b02009-12-03 15:58:56 -05001624out_mountproto_mismatch:
1625 printk(KERN_INFO "NFS: mount server address does not match mountproto= "
1626 "option\n");
1627 return 0;
1628out_proto_mismatch:
1629 printk(KERN_INFO "NFS: server address does not match proto= option\n");
1630 return 0;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001631out_invalid_address:
1632 printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
1633 return 0;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001634out_invalid_value:
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001635 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001636 return 0;
Weston Andros Adamson571b7552012-02-01 14:06:41 -05001637out_minorversion_mismatch:
1638 printk(KERN_INFO "NFS: mount option vers=%u does not support "
1639 "minorversion=%u\n", mnt->version, mnt->minorversion);
1640 return 0;
Chuck Lever89652612012-09-14 17:24:11 -04001641out_migration_misuse:
1642 printk(KERN_INFO
1643 "NFS: 'migration' not supported for this NFS version\n");
1644 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001645out_nomem:
1646 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1647 return 0;
Eric Parisf9c3a382008-03-05 14:20:18 -05001648out_security_failure:
1649 free_secdata(secdata);
1650 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1651 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001652}
1653
1654/*
Chuck Leverec88f282009-08-09 15:09:32 -04001655 * Match the requested auth flavors with the list returned by
1656 * the server. Returns zero and sets the mount's authentication
1657 * flavor on success; returns -EACCES if server does not support
1658 * the requested flavor.
1659 */
1660static int nfs_walk_authlist(struct nfs_parsed_mount_data *args,
1661 struct nfs_mount_request *request)
1662{
1663 unsigned int i, j, server_authlist_len = *(request->auth_flav_len);
1664
1665 /*
Chuck Lever5eecfde2009-08-21 17:50:30 -04001666 * Certain releases of Linux's mountd return an empty
1667 * flavor list. To prevent behavioral regression with
1668 * these servers (ie. rejecting mounts that used to
1669 * succeed), revert to pre-2.6.32 behavior (no checking)
1670 * if the returned flavor list is empty.
1671 */
1672 if (server_authlist_len == 0)
1673 return 0;
1674
1675 /*
Chuck Leverec88f282009-08-09 15:09:32 -04001676 * We avoid sophisticated negotiating here, as there are
1677 * plenty of cases where we can get it wrong, providing
1678 * either too little or too much security.
1679 *
1680 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1681 * flavor listed first. However, some servers list
1682 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1683 * preferred default, in args->auth_flavors[0] if user
1684 * didn't specify sec= mount option.
1685 */
1686 for (i = 0; i < args->auth_flavor_len; i++)
1687 for (j = 0; j < server_authlist_len; j++)
1688 if (args->auth_flavors[i] == request->auth_flavs[j]) {
1689 dfprintk(MOUNT, "NFS: using auth flavor %d\n",
1690 request->auth_flavs[j]);
1691 args->auth_flavors[0] = request->auth_flavs[j];
1692 return 0;
1693 }
1694
1695 dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n");
1696 nfs_umount(request);
1697 return -EACCES;
1698}
1699
1700/*
Chuck Lever0076d7b2007-07-01 12:13:49 -04001701 * Use the remote server's MOUNT service to request the NFS file handle
1702 * corresponding to the provided path.
1703 */
Bryan Schumaker486aa692012-05-10 15:07:39 -04001704static int nfs_request_mount(struct nfs_parsed_mount_data *args,
1705 struct nfs_fh *root_fh)
Chuck Lever0076d7b2007-07-01 12:13:49 -04001706{
Chuck Leverec88f282009-08-09 15:09:32 -04001707 rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS];
1708 unsigned int server_authlist_len = ARRAY_SIZE(server_authlist);
Chuck Leverc5d120f2008-12-23 15:21:35 -05001709 struct nfs_mount_request request = {
1710 .sap = (struct sockaddr *)
1711 &args->mount_server.address,
1712 .dirpath = args->nfs_server.export_path,
1713 .protocol = args->mount_server.protocol,
1714 .fh = root_fh,
Chuck Lever50a737f2008-12-23 15:21:37 -05001715 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
Chuck Leverec88f282009-08-09 15:09:32 -04001716 .auth_flav_len = &server_authlist_len,
1717 .auth_flavs = server_authlist,
Stanislav Kinsbursky6d59b8d2012-01-10 16:12:54 +04001718 .net = args->net,
Chuck Leverc5d120f2008-12-23 15:21:35 -05001719 };
Chuck Lever4c568012007-12-10 14:59:28 -05001720 int status;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001721
1722 if (args->mount_server.version == 0) {
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001723 switch (args->version) {
1724 default:
1725 args->mount_server.version = NFS_MNT3_VERSION;
1726 break;
1727 case 2:
1728 args->mount_server.version = NFS_MNT_VERSION;
1729 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001730 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001731 request.version = args->mount_server.version;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001732
Chuck Lever33832032007-12-10 14:59:13 -05001733 if (args->mount_server.hostname)
Chuck Leverc5d120f2008-12-23 15:21:35 -05001734 request.hostname = args->mount_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001735 else
Chuck Leverc5d120f2008-12-23 15:21:35 -05001736 request.hostname = args->nfs_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001737
Chuck Lever0076d7b2007-07-01 12:13:49 -04001738 /*
1739 * Construct the mount server's address.
1740 */
Chuck Lever4c568012007-12-10 14:59:28 -05001741 if (args->mount_server.address.ss_family == AF_UNSPEC) {
Chuck Leverc5d120f2008-12-23 15:21:35 -05001742 memcpy(request.sap, &args->nfs_server.address,
Chuck Lever4c568012007-12-10 14:59:28 -05001743 args->nfs_server.addrlen);
1744 args->mount_server.addrlen = args->nfs_server.addrlen;
1745 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001746 request.salen = args->mount_server.addrlen;
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001747 nfs_set_port(request.sap, &args->mount_server.port, 0);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001748
1749 /*
1750 * Now ask the mount server to map our export path
1751 * to a file handle.
1752 */
Chuck Leverc5d120f2008-12-23 15:21:35 -05001753 status = nfs_mount(&request);
Chuck Leverec88f282009-08-09 15:09:32 -04001754 if (status != 0) {
1755 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1756 request.hostname, status);
1757 return status;
1758 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001759
Chuck Leverec88f282009-08-09 15:09:32 -04001760 /*
1761 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1762 */
1763 if (args->mount_server.version != NFS_MNT3_VERSION)
1764 return 0;
1765 return nfs_walk_authlist(args, &request);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001766}
1767
Bryan Schumakerff9099f22012-07-30 16:05:18 -04001768struct dentry *nfs_try_mount(int flags, const char *dev_name,
1769 struct nfs_mount_info *mount_info,
1770 struct nfs_subversion *nfs_mod)
Bryan Schumaker486aa692012-05-10 15:07:39 -04001771{
1772 int status;
1773 struct nfs_server *server;
1774
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04001775 if (mount_info->parsed->need_mount) {
Bryan Schumaker87c70832012-05-10 15:07:43 -04001776 status = nfs_request_mount(mount_info->parsed, mount_info->mntfh);
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04001777 if (status)
1778 return ERR_PTR(status);
1779 }
Bryan Schumaker486aa692012-05-10 15:07:39 -04001780
1781 /* Get a volume representation */
Bryan Schumaker1179acc2012-07-30 16:05:19 -04001782 server = nfs_mod->rpc_ops->create_server(mount_info, nfs_mod);
Bryan Schumaker486aa692012-05-10 15:07:39 -04001783 if (IS_ERR(server))
1784 return ERR_CAST(server);
1785
Bryan Schumakerab7017a2012-07-30 16:05:16 -04001786 return nfs_fs_mount_common(server, flags, dev_name, mount_info, nfs_mod);
Bryan Schumaker486aa692012-05-10 15:07:39 -04001787}
Bryan Schumakerddda8e02012-07-30 16:05:23 -04001788EXPORT_SYMBOL_GPL(nfs_try_mount);
Bryan Schumaker486aa692012-05-10 15:07:39 -04001789
Rob Landleyc12bace2011-03-09 15:54:13 -06001790/*
1791 * Split "dev_name" into "hostname:export_path".
1792 *
1793 * The leftmost colon demarks the split between the server's hostname
1794 * and the export path. If the hostname starts with a left square
1795 * bracket, then it may contain colons.
1796 *
1797 * Note: caller frees hostname and export path, even on error.
1798 */
1799static int nfs_parse_devname(const char *dev_name,
1800 char **hostname, size_t maxnamlen,
1801 char **export_path, size_t maxpathlen)
Chuck Leverdc045892008-06-23 12:36:37 -04001802{
1803 size_t len;
Rob Landleyc12bace2011-03-09 15:54:13 -06001804 char *end;
Chuck Leverdc045892008-06-23 12:36:37 -04001805
Rob Landleyc12bace2011-03-09 15:54:13 -06001806 /* Is the host name protected with square brakcets? */
1807 if (*dev_name == '[') {
1808 end = strchr(++dev_name, ']');
1809 if (end == NULL || end[1] != ':')
1810 goto out_bad_devname;
Chuck Leverdc045892008-06-23 12:36:37 -04001811
Rob Landleyc12bace2011-03-09 15:54:13 -06001812 len = end - dev_name;
1813 end++;
1814 } else {
1815 char *comma;
1816
1817 end = strchr(dev_name, ':');
1818 if (end == NULL)
1819 goto out_bad_devname;
1820 len = end - dev_name;
1821
1822 /* kill possible hostname list: not supported */
1823 comma = strchr(dev_name, ',');
1824 if (comma != NULL && comma < end)
1825 *comma = 0;
1826 }
1827
Chuck Leverdc045892008-06-23 12:36:37 -04001828 if (len > maxnamlen)
1829 goto out_hostname;
1830
1831 /* N.B. caller will free nfs_server.hostname in all cases */
1832 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
Rob Landleyc12bace2011-03-09 15:54:13 -06001833 if (*hostname == NULL)
Chuck Leverdc045892008-06-23 12:36:37 -04001834 goto out_nomem;
Rob Landleyc12bace2011-03-09 15:54:13 -06001835 len = strlen(++end);
Chuck Leverdc045892008-06-23 12:36:37 -04001836 if (len > maxpathlen)
1837 goto out_path;
Rob Landleyc12bace2011-03-09 15:54:13 -06001838 *export_path = kstrndup(end, len, GFP_KERNEL);
Chuck Leverdc045892008-06-23 12:36:37 -04001839 if (!*export_path)
1840 goto out_nomem;
1841
1842 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1843 return 0;
1844
1845out_bad_devname:
1846 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1847 return -EINVAL;
1848
1849out_nomem:
1850 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1851 return -ENOMEM;
1852
1853out_hostname:
1854 dfprintk(MOUNT, "NFS: server hostname too long\n");
1855 return -ENAMETOOLONG;
1856
1857out_path:
1858 dfprintk(MOUNT, "NFS: export pathname too long\n");
1859 return -ENAMETOOLONG;
1860}
1861
1862/*
David Howells54ceac42006-08-22 20:06:13 -04001863 * Validate the NFS2/NFS3 mount data
1864 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001865 *
1866 * For option strings, user space handles the following behaviors:
1867 *
1868 * + DNS: mapping server host name to IP address ("addr=" option)
1869 *
1870 * + failure mode: how to behave if a mount request can't be handled
1871 * immediately ("fg/bg" option)
1872 *
1873 * + retry: how often to retry a mount request ("retry=" option)
1874 *
1875 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1876 * mountproto=tcp after mountproto=udp, and so on
David Howellsf7b422b2006-06-09 09:34:33 -04001877 */
Bryan Schumakerd72c7272012-05-10 15:07:41 -04001878static int nfs23_validate_mount_data(void *options,
1879 struct nfs_parsed_mount_data *args,
1880 struct nfs_fh *mntfh,
1881 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001882{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001883 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001884 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
Chuck Lever136d5582007-07-01 12:13:54 -04001885
Chuck Lever5df36e72007-07-01 12:12:56 -04001886 if (data == NULL)
1887 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001888
Bryan Schumakerc5afc8d2012-06-08 11:32:56 -04001889 args->version = NFS_DEFAULT_VERSION;
David Howellsf7b422b2006-06-09 09:34:33 -04001890 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001891 case 1:
1892 data->namlen = 0;
1893 case 2:
1894 data->bsize = 0;
1895 case 3:
1896 if (data->flags & NFS_MOUNT_VER3)
1897 goto out_no_v3;
1898 data->root.size = NFS2_FHSIZE;
1899 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1900 case 4:
1901 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1902 goto out_no_sec;
1903 case 5:
1904 memset(data->context, 0, sizeof(data->context));
1905 case 6:
Trond Myklebustb7e24452008-06-19 15:21:11 -04001906 if (data->flags & NFS_MOUNT_VER3) {
1907 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1908 goto out_invalid_fh;
Chuck Lever5df36e72007-07-01 12:12:56 -04001909 mntfh->size = data->root.size;
Chuck Lever764302c2009-09-08 19:50:03 -04001910 args->version = 3;
1911 } else {
Chuck Lever5df36e72007-07-01 12:12:56 -04001912 mntfh->size = NFS2_FHSIZE;
Chuck Lever764302c2009-09-08 19:50:03 -04001913 args->version = 2;
1914 }
Chuck Lever5df36e72007-07-01 12:12:56 -04001915
Chuck Lever5df36e72007-07-01 12:12:56 -04001916
1917 memcpy(mntfh->data, data->root.data, mntfh->size);
1918 if (mntfh->size < sizeof(mntfh->data))
1919 memset(mntfh->data + mntfh->size, 0,
1920 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001921
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001922 /*
1923 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1924 * can deal with.
1925 */
Trond Myklebustff3525a2008-08-15 16:59:14 -04001926 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
Bryan Schumakerd5eff1a2010-08-03 13:04:00 -04001927 args->flags |= NFS_MOUNT_LEGACY_INTERFACE;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001928 args->rsize = data->rsize;
1929 args->wsize = data->wsize;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001930 args->timeo = data->timeo;
1931 args->retrans = data->retrans;
1932 args->acregmin = data->acregmin;
1933 args->acregmax = data->acregmax;
1934 args->acdirmin = data->acdirmin;
1935 args->acdirmax = data->acdirmax;
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04001936 args->need_mount = false;
Chuck Lever4c568012007-12-10 14:59:28 -05001937
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001938 memcpy(sap, &data->addr, sizeof(data->addr));
Chuck Lever4c568012007-12-10 14:59:28 -05001939 args->nfs_server.addrlen = sizeof(data->addr);
Trond Myklebust872ece82012-09-04 11:05:07 -04001940 args->nfs_server.port = ntohs(data->addr.sin_port);
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001941 if (!nfs_verify_server_address(sap))
Chuck Lever4c568012007-12-10 14:59:28 -05001942 goto out_no_address;
1943
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001944 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001945 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001946 /* N.B. caller will free nfs_server.hostname in all cases */
1947 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1948 args->namlen = data->namlen;
1949 args->bsize = data->bsize;
Chuck Leverdd07c942008-06-24 16:33:46 -04001950
1951 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1952 args->auth_flavors[0] = data->pseudoflavor;
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001953 if (!args->nfs_server.hostname)
1954 goto out_nomem;
Eric Parisf9c3a382008-03-05 14:20:18 -05001955
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001956 if (!(data->flags & NFS_MOUNT_NONLM))
1957 args->flags &= ~(NFS_MOUNT_LOCAL_FLOCK|
1958 NFS_MOUNT_LOCAL_FCNTL);
1959 else
1960 args->flags |= (NFS_MOUNT_LOCAL_FLOCK|
1961 NFS_MOUNT_LOCAL_FCNTL);
Eric Parisf9c3a382008-03-05 14:20:18 -05001962 /*
1963 * The legacy version 6 binary mount data from userspace has a
1964 * field used only to transport selinux information into the
1965 * the kernel. To continue to support that functionality we
1966 * have a touch of selinux knowledge here in the NFS code. The
1967 * userspace code converted context=blah to just blah so we are
1968 * converting back to the full string selinux understands.
1969 */
1970 if (data->context[0]){
1971#ifdef CONFIG_SECURITY_SELINUX
1972 int rc;
1973 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1974 if (!opts_str)
1975 return -ENOMEM;
1976 strcpy(opts_str, "context=");
1977 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1978 strcat(opts_str, &data->context[0]);
1979 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1980 kfree(opts_str);
1981 if (rc)
1982 return rc;
1983#else
1984 return -EINVAL;
1985#endif
1986 }
1987
Chuck Lever5df36e72007-07-01 12:12:56 -04001988 break;
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04001989 default:
1990 return NFS_TEXT_DATA;
David Howellsf7b422b2006-06-09 09:34:33 -04001991 }
David Howells54ceac42006-08-22 20:06:13 -04001992
Bryan Schumaker1c606fb2012-07-30 16:05:24 -04001993#if !IS_ENABLED(CONFIG_NFS_V3)
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001994 if (args->version == 3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001995 goto out_v3_not_compiled;
1996#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001997
David Howells54ceac42006-08-22 20:06:13 -04001998 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001999
2000out_no_data:
2001 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
2002 return -EINVAL;
2003
2004out_no_v3:
2005 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
2006 data->version);
2007 return -EINVAL;
2008
2009out_no_sec:
2010 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
2011 return -EINVAL;
2012
Bryan Schumaker1c606fb2012-07-30 16:05:24 -04002013#if !IS_ENABLED(CONFIG_NFS_V3)
Chuck Lever5df36e72007-07-01 12:12:56 -04002014out_v3_not_compiled:
2015 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
2016 return -EPROTONOSUPPORT;
2017#endif /* !CONFIG_NFS_V3 */
2018
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04002019out_nomem:
2020 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
2021 return -ENOMEM;
2022
Chuck Lever5df36e72007-07-01 12:12:56 -04002023out_no_address:
2024 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
2025 return -EINVAL;
2026
2027out_invalid_fh:
2028 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
2029 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04002030}
2031
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002032#if IS_ENABLED(CONFIG_NFS_V4)
Bryan Schumakerd72c7272012-05-10 15:07:41 -04002033static int nfs_validate_mount_data(struct file_system_type *fs_type,
2034 void *options,
2035 struct nfs_parsed_mount_data *args,
2036 struct nfs_fh *mntfh,
2037 const char *dev_name)
2038{
2039 if (fs_type == &nfs_fs_type)
2040 return nfs23_validate_mount_data(options, args, mntfh, dev_name);
2041 return nfs4_validate_mount_data(options, args, dev_name);
2042}
2043#else
2044static int nfs_validate_mount_data(struct file_system_type *fs_type,
2045 void *options,
2046 struct nfs_parsed_mount_data *args,
2047 struct nfs_fh *mntfh,
2048 const char *dev_name)
2049{
2050 return nfs23_validate_mount_data(options, args, mntfh, dev_name);
2051}
2052#endif
2053
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04002054static int nfs_validate_text_mount_data(void *options,
2055 struct nfs_parsed_mount_data *args,
2056 const char *dev_name)
2057{
2058 int port = 0;
2059 int max_namelen = PAGE_SIZE;
2060 int max_pathlen = NFS_MAXPATHLEN;
2061 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2062
2063 if (nfs_parse_mount_options((char *)options, args) == 0)
2064 return -EINVAL;
2065
2066 if (!nfs_verify_server_address(sap))
2067 goto out_no_address;
2068
2069 if (args->version == 4) {
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002070#if IS_ENABLED(CONFIG_NFS_V4)
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04002071 port = NFS_PORT;
2072 max_namelen = NFS4_MAXNAMLEN;
2073 max_pathlen = NFS4_MAXPATHLEN;
2074 nfs_validate_transport_protocol(args);
2075 nfs4_validate_mount_flags(args);
2076#else
2077 goto out_v4_not_compiled;
2078#endif /* CONFIG_NFS_V4 */
2079 } else
2080 nfs_set_mount_transport_protocol(args);
2081
2082 nfs_set_port(sap, &args->nfs_server.port, port);
2083
2084 if (args->auth_flavor_len > 1)
2085 goto out_bad_auth;
2086
2087 return nfs_parse_devname(dev_name,
2088 &args->nfs_server.hostname,
2089 max_namelen,
2090 &args->nfs_server.export_path,
2091 max_pathlen);
2092
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002093#if !IS_ENABLED(CONFIG_NFS_V4)
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04002094out_v4_not_compiled:
2095 dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n");
2096 return -EPROTONOSUPPORT;
2097#endif /* !CONFIG_NFS_V4 */
2098
2099out_no_address:
2100 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
2101 return -EINVAL;
2102
2103out_bad_auth:
2104 dfprintk(MOUNT, "NFS: Too many RPC auth flavours specified\n");
2105 return -EINVAL;
2106}
2107
Jeff Layton48b605f2008-06-10 15:38:39 -04002108static int
2109nfs_compare_remount_data(struct nfs_server *nfss,
2110 struct nfs_parsed_mount_data *data)
2111{
2112 if (data->flags != nfss->flags ||
2113 data->rsize != nfss->rsize ||
2114 data->wsize != nfss->wsize ||
2115 data->retrans != nfss->client->cl_timeout->to_retries ||
2116 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
2117 data->acregmin != nfss->acregmin / HZ ||
2118 data->acregmax != nfss->acregmax / HZ ||
2119 data->acdirmin != nfss->acdirmin / HZ ||
2120 data->acdirmax != nfss->acdirmax / HZ ||
2121 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
Trond Myklebustbcd2ea12009-10-06 15:41:22 -04002122 data->nfs_server.port != nfss->port ||
Jeff Layton48b605f2008-06-10 15:38:39 -04002123 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
Stefan Richtera1be9ee2009-10-12 11:26:12 -04002124 !rpc_cmp_addr((struct sockaddr *)&data->nfs_server.address,
2125 (struct sockaddr *)&nfss->nfs_client->cl_addr))
Jeff Layton48b605f2008-06-10 15:38:39 -04002126 return -EINVAL;
2127
2128 return 0;
2129}
2130
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002131int
Jeff Layton48b605f2008-06-10 15:38:39 -04002132nfs_remount(struct super_block *sb, int *flags, char *raw_data)
2133{
2134 int error;
2135 struct nfs_server *nfss = sb->s_fs_info;
2136 struct nfs_parsed_mount_data *data;
2137 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
2138 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
Trond Myklebustcd100722008-06-17 16:12:00 -04002139 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
Jeff Layton48b605f2008-06-10 15:38:39 -04002140
2141 /*
2142 * Userspace mount programs that send binary options generally send
2143 * them populated with default values. We have no way to know which
2144 * ones were explicitly specified. Fall back to legacy behavior and
2145 * just return success.
2146 */
Marc Zyngier31c94462008-07-17 13:21:55 +02002147 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
2148 (nfsvers <= 3 && (!options || (options->version >= 1 &&
2149 options->version <= 6))))
Jeff Layton48b605f2008-06-10 15:38:39 -04002150 return 0;
2151
2152 data = kzalloc(sizeof(*data), GFP_KERNEL);
2153 if (data == NULL)
2154 return -ENOMEM;
2155
2156 /* fill out struct with values from existing mount */
2157 data->flags = nfss->flags;
2158 data->rsize = nfss->rsize;
2159 data->wsize = nfss->wsize;
2160 data->retrans = nfss->client->cl_timeout->to_retries;
2161 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
2162 data->acregmin = nfss->acregmin / HZ;
2163 data->acregmax = nfss->acregmax / HZ;
2164 data->acdirmin = nfss->acdirmin / HZ;
2165 data->acdirmax = nfss->acdirmax / HZ;
2166 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
Trond Myklebustbcd2ea12009-10-06 15:41:22 -04002167 data->nfs_server.port = nfss->port;
Jeff Layton48b605f2008-06-10 15:38:39 -04002168 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
2169 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
2170 data->nfs_server.addrlen);
2171
2172 /* overwrite those values with any that were specified */
2173 error = nfs_parse_mount_options((char *)options, data);
2174 if (error < 0)
2175 goto out;
2176
Jeff Layton26c4c172011-04-27 11:49:09 -04002177 /*
2178 * noac is a special case. It implies -o sync, but that's not
2179 * necessarily reflected in the mtab options. do_remount_sb
2180 * will clear MS_SYNCHRONOUS if -o sync wasn't specified in the
2181 * remount options, so we have to explicitly reset it.
2182 */
2183 if (data->flags & NFS_MOUNT_NOAC)
2184 *flags |= MS_SYNCHRONOUS;
2185
Jeff Layton48b605f2008-06-10 15:38:39 -04002186 /* compare new mount options with old ones */
2187 error = nfs_compare_remount_data(nfss, data);
2188out:
2189 kfree(data);
2190 return error;
2191}
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002192EXPORT_SYMBOL_GPL(nfs_remount);
Jeff Layton48b605f2008-06-10 15:38:39 -04002193
David Howells54ceac42006-08-22 20:06:13 -04002194/*
2195 * Initialise the common bits of the superblock
2196 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002197inline void nfs_initialise_sb(struct super_block *sb)
David Howells54ceac42006-08-22 20:06:13 -04002198{
2199 struct nfs_server *server = NFS_SB(sb);
2200
2201 sb->s_magic = NFS_SUPER_MAGIC;
2202
2203 /* We probably want something more informative here */
2204 snprintf(sb->s_id, sizeof(sb->s_id),
Vivek Trivedi5a7c9ee2012-03-15 23:58:52 +05302205 "%u:%u", MAJOR(sb->s_dev), MINOR(sb->s_dev));
David Howells54ceac42006-08-22 20:06:13 -04002206
2207 if (sb->s_blocksize == 0)
2208 sb->s_blocksize = nfs_block_bits(server->wsize,
2209 &sb->s_blocksize_bits);
2210
Jens Axboe32a88aa2009-09-16 15:02:33 +02002211 sb->s_bdi = &server->backing_dev_info;
2212
David Howells54ceac42006-08-22 20:06:13 -04002213 nfs_super_set_maxbytes(sb, server->maxfilesize);
2214}
2215
2216/*
2217 * Finish setting up an NFS2/3 superblock
2218 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002219void nfs_fill_super(struct super_block *sb, struct nfs_mount_info *mount_info)
David Howells54ceac42006-08-22 20:06:13 -04002220{
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002221 struct nfs_parsed_mount_data *data = mount_info->parsed;
David Howells54ceac42006-08-22 20:06:13 -04002222 struct nfs_server *server = NFS_SB(sb);
2223
2224 sb->s_blocksize_bits = 0;
2225 sb->s_blocksize = 0;
Bryan Schumaker6a744902012-07-30 16:05:20 -04002226 sb->s_xattr = server->nfs_client->cl_nfs_mod->xattr;
2227 sb->s_op = server->nfs_client->cl_nfs_mod->sops;
2228 if (data && data->bsize)
David Howells54ceac42006-08-22 20:06:13 -04002229 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
2230
Bryan Schumaker6a744902012-07-30 16:05:20 -04002231 if (server->nfs_client->rpc_ops->version != 2) {
David Howells54ceac42006-08-22 20:06:13 -04002232 /* The VFS shouldn't apply the umask to mode bits. We will do
2233 * so ourselves when necessary.
2234 */
2235 sb->s_flags |= MS_POSIXACL;
2236 sb->s_time_gran = 1;
2237 }
2238
David Howells54ceac42006-08-22 20:06:13 -04002239 nfs_initialise_sb(sb);
2240}
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002241EXPORT_SYMBOL_GPL(nfs_fill_super);
David Howells54ceac42006-08-22 20:06:13 -04002242
2243/*
Bryan Schumaker3cadf4b2012-07-16 16:39:19 -04002244 * Finish setting up a cloned NFS2/3/4 superblock
David Howells54ceac42006-08-22 20:06:13 -04002245 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002246void nfs_clone_super(struct super_block *sb, struct nfs_mount_info *mount_info)
David Howells54ceac42006-08-22 20:06:13 -04002247{
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002248 const struct super_block *old_sb = mount_info->cloned->sb;
David Howells54ceac42006-08-22 20:06:13 -04002249 struct nfs_server *server = NFS_SB(sb);
2250
2251 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2252 sb->s_blocksize = old_sb->s_blocksize;
2253 sb->s_maxbytes = old_sb->s_maxbytes;
Bryan Schumaker3cadf4b2012-07-16 16:39:19 -04002254 sb->s_xattr = old_sb->s_xattr;
2255 sb->s_op = old_sb->s_op;
2256 sb->s_time_gran = 1;
David Howells54ceac42006-08-22 20:06:13 -04002257
Bryan Schumaker3cadf4b2012-07-16 16:39:19 -04002258 if (server->nfs_client->rpc_ops->version != 2) {
David Howells54ceac42006-08-22 20:06:13 -04002259 /* The VFS shouldn't apply the umask to mode bits. We will do
2260 * so ourselves when necessary.
2261 */
2262 sb->s_flags |= MS_POSIXACL;
David Howells54ceac42006-08-22 20:06:13 -04002263 }
2264
David Howells54ceac42006-08-22 20:06:13 -04002265 nfs_initialise_sb(sb);
2266}
2267
Trond Myklebust275a5d22007-05-16 16:53:28 -04002268static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
2269{
2270 const struct nfs_server *a = s->s_fs_info;
2271 const struct rpc_clnt *clnt_a = a->client;
2272 const struct rpc_clnt *clnt_b = b->client;
2273
2274 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
2275 goto Ebusy;
2276 if (a->nfs_client != b->nfs_client)
2277 goto Ebusy;
2278 if (a->flags != b->flags)
2279 goto Ebusy;
2280 if (a->wsize != b->wsize)
2281 goto Ebusy;
2282 if (a->rsize != b->rsize)
2283 goto Ebusy;
2284 if (a->acregmin != b->acregmin)
2285 goto Ebusy;
2286 if (a->acregmax != b->acregmax)
2287 goto Ebusy;
2288 if (a->acdirmin != b->acdirmin)
2289 goto Ebusy;
2290 if (a->acdirmax != b->acdirmax)
2291 goto Ebusy;
2292 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
2293 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002294 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04002295Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002296 return 0;
2297}
2298
2299struct nfs_sb_mountdata {
2300 struct nfs_server *server;
2301 int mntflags;
2302};
2303
2304static int nfs_set_super(struct super_block *s, void *data)
2305{
2306 struct nfs_sb_mountdata *sb_mntdata = data;
2307 struct nfs_server *server = sb_mntdata->server;
2308 int ret;
2309
2310 s->s_flags = sb_mntdata->mntflags;
2311 s->s_fs_info = server;
Al Viro8b244ff2010-12-18 11:29:39 -05002312 s->s_d_op = server->nfs_client->rpc_ops->dentry_ops;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002313 ret = set_anon_super(s, server);
2314 if (ret == 0)
2315 server->s_dev = s->s_dev;
2316 return ret;
2317}
2318
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002319static int nfs_compare_super_address(struct nfs_server *server1,
2320 struct nfs_server *server2)
2321{
2322 struct sockaddr *sap1, *sap2;
2323
2324 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
2325 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
2326
2327 if (sap1->sa_family != sap2->sa_family)
2328 return 0;
2329
2330 switch (sap1->sa_family) {
2331 case AF_INET: {
2332 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
2333 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
2334 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
2335 return 0;
2336 if (sin1->sin_port != sin2->sin_port)
2337 return 0;
2338 break;
2339 }
2340 case AF_INET6: {
2341 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
2342 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
2343 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
2344 return 0;
2345 if (sin1->sin6_port != sin2->sin6_port)
2346 return 0;
2347 break;
2348 }
2349 default:
2350 return 0;
2351 }
2352
2353 return 1;
2354}
2355
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002356static int nfs_compare_super(struct super_block *sb, void *data)
2357{
2358 struct nfs_sb_mountdata *sb_mntdata = data;
2359 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2360 int mntflags = sb_mntdata->mntflags;
2361
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002362 if (!nfs_compare_super_address(old, server))
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002363 return 0;
2364 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2365 if (old->flags & NFS_MOUNT_UNSHARED)
2366 return 0;
2367 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2368 return 0;
2369 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04002370}
2371
Trond Myklebust39ffb922012-05-16 10:21:30 -07002372#ifdef CONFIG_NFS_FSCACHE
Bryan Schumaker2311b942012-05-10 15:07:32 -04002373static void nfs_get_cache_cookie(struct super_block *sb,
2374 struct nfs_parsed_mount_data *parsed,
2375 struct nfs_clone_mount *cloned)
2376{
2377 char *uniq = NULL;
2378 int ulen = 0;
2379
2380 if (parsed && parsed->fscache_uniq) {
2381 uniq = parsed->fscache_uniq;
2382 ulen = strlen(parsed->fscache_uniq);
2383 } else if (cloned) {
2384 struct nfs_server *mnt_s = NFS_SB(cloned->sb);
2385 if (mnt_s->fscache_key) {
2386 uniq = mnt_s->fscache_key->key.uniquifier;
2387 ulen = mnt_s->fscache_key->key.uniq_len;
2388 };
2389 }
2390
2391 nfs_fscache_get_super_cookie(sb, uniq, ulen);
2392}
Trond Myklebust39ffb922012-05-16 10:21:30 -07002393#else
2394static void nfs_get_cache_cookie(struct super_block *sb,
2395 struct nfs_parsed_mount_data *parsed,
2396 struct nfs_clone_mount *cloned)
2397{
2398}
2399#endif
Bryan Schumaker2311b942012-05-10 15:07:32 -04002400
Miklos Szeredifa799752008-04-30 00:54:33 -07002401static int nfs_bdi_register(struct nfs_server *server)
2402{
2403 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
2404}
2405
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002406int nfs_set_sb_security(struct super_block *s, struct dentry *mntroot,
2407 struct nfs_mount_info *mount_info)
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002408{
2409 return security_sb_set_mnt_opts(s, &mount_info->parsed->lsm_opts);
2410}
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002411EXPORT_SYMBOL_GPL(nfs_set_sb_security);
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002412
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002413int nfs_clone_sb_security(struct super_block *s, struct dentry *mntroot,
2414 struct nfs_mount_info *mount_info)
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002415{
2416 /* clone any lsm security options from the parent to the new sb */
2417 security_sb_clone_mnt_opts(mount_info->cloned->sb, s);
2418 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops)
2419 return -ESTALE;
2420 return 0;
2421}
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002422EXPORT_SYMBOL_GPL(nfs_clone_sb_security);
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002423
Bryan Schumakerab7017a2012-07-30 16:05:16 -04002424struct dentry *nfs_fs_mount_common(struct nfs_server *server,
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002425 int flags, const char *dev_name,
Bryan Schumakerab7017a2012-07-30 16:05:16 -04002426 struct nfs_mount_info *mount_info,
2427 struct nfs_subversion *nfs_mod)
David Howells54ceac42006-08-22 20:06:13 -04002428{
David Howells54ceac42006-08-22 20:06:13 -04002429 struct super_block *s;
Al Viro01194982011-03-16 07:25:36 -04002430 struct dentry *mntroot = ERR_PTR(-ENOMEM);
Trond Myklebust75180df2007-05-16 16:53:28 -04002431 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002432 struct nfs_sb_mountdata sb_mntdata = {
2433 .mntflags = flags,
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002434 .server = server,
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002435 };
Al Viro01194982011-03-16 07:25:36 -04002436 int error;
David Howells54ceac42006-08-22 20:06:13 -04002437
Trond Myklebust75180df2007-05-16 16:53:28 -04002438 if (server->flags & NFS_MOUNT_UNSHARED)
2439 compare_super = NULL;
2440
Sachin Prabhufb2088c2011-08-01 12:10:12 +01002441 /* -o noac implies -o sync */
2442 if (server->flags & NFS_MOUNT_NOAC)
2443 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2444
David Howells54ceac42006-08-22 20:06:13 -04002445 /* Get a superblock - note that we may end up sharing one that already exists */
Bryan Schumakerab7017a2012-07-30 16:05:16 -04002446 s = sget(nfs_mod->nfs_fs, compare_super, nfs_set_super, flags, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002447 if (IS_ERR(s)) {
Al Viro01194982011-03-16 07:25:36 -04002448 mntroot = ERR_CAST(s);
David Howells54ceac42006-08-22 20:06:13 -04002449 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04002450 }
2451
David Howells54ceac42006-08-22 20:06:13 -04002452 if (s->s_fs_info != server) {
2453 nfs_free_server(server);
2454 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002455 } else {
2456 error = nfs_bdi_register(server);
Al Viro01194982011-03-16 07:25:36 -04002457 if (error) {
2458 mntroot = ERR_PTR(error);
NeilBrowncfbc0682010-03-11 11:20:17 +11002459 goto error_splat_bdi;
Al Viro01194982011-03-16 07:25:36 -04002460 }
David Howellsf7b422b2006-06-09 09:34:33 -04002461 }
David Howells54ceac42006-08-22 20:06:13 -04002462
2463 if (!s->s_root) {
2464 /* initial superblock/root creation */
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002465 mount_info->fill_super(s, mount_info);
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002466 nfs_get_cache_cookie(s, mount_info->parsed, mount_info->cloned);
David Howells54ceac42006-08-22 20:06:13 -04002467 }
2468
Bryan Schumaker87c70832012-05-10 15:07:43 -04002469 mntroot = nfs_get_root(s, mount_info->mntfh, dev_name);
Al Viro01194982011-03-16 07:25:36 -04002470 if (IS_ERR(mntroot))
David Howells54ceac42006-08-22 20:06:13 -04002471 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002472
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002473 error = mount_info->set_security(s, mntroot, mount_info);
Eric Parisf9c3a382008-03-05 14:20:18 -05002474 if (error)
2475 goto error_splat_root;
2476
David Howellsf7b422b2006-06-09 09:34:33 -04002477 s->s_flags |= MS_ACTIVE;
Chuck Lever06559602007-07-01 12:12:35 -04002478
2479out:
Al Viro01194982011-03-16 07:25:36 -04002480 return mntroot;
Trond Myklebust816724e2006-06-24 08:41:41 -04002481
David Howells54ceac42006-08-22 20:06:13 -04002482out_err_nosb:
2483 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04002484 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002485
Eric Parisf9c3a382008-03-05 14:20:18 -05002486error_splat_root:
2487 dput(mntroot);
Al Viro01194982011-03-16 07:25:36 -04002488 mntroot = ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04002489error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002490 if (server && !s->s_root)
2491 bdi_unregister(&server->backing_dev_info);
2492error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002493 deactivate_locked_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04002494 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002495}
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002496EXPORT_SYMBOL_GPL(nfs_fs_mount_common);
David Howellsf7b422b2006-06-09 09:34:33 -04002497
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002498struct dentry *nfs_fs_mount(struct file_system_type *fs_type,
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002499 int flags, const char *dev_name, void *raw_data)
2500{
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002501 struct nfs_mount_info mount_info = {
2502 .fill_super = nfs_fill_super,
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002503 .set_security = nfs_set_sb_security,
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002504 };
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002505 struct dentry *mntroot = ERR_PTR(-ENOMEM);
Bryan Schumakerab7017a2012-07-30 16:05:16 -04002506 struct nfs_subversion *nfs_mod;
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002507 int error;
2508
Bryan Schumaker46058d42012-05-10 15:07:42 -04002509 mount_info.parsed = nfs_alloc_parsed_mount_data();
Bryan Schumaker87c70832012-05-10 15:07:43 -04002510 mount_info.mntfh = nfs_alloc_fhandle();
2511 if (mount_info.parsed == NULL || mount_info.mntfh == NULL)
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002512 goto out;
2513
2514 /* Validate the mount data */
Bryan Schumaker87c70832012-05-10 15:07:43 -04002515 error = nfs_validate_mount_data(fs_type, raw_data, mount_info.parsed, mount_info.mntfh, dev_name);
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04002516 if (error == NFS_TEXT_DATA)
Bryan Schumaker46058d42012-05-10 15:07:42 -04002517 error = nfs_validate_text_mount_data(raw_data, mount_info.parsed, dev_name);
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002518 if (error < 0) {
2519 mntroot = ERR_PTR(error);
2520 goto out;
2521 }
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002522
Bryan Schumakerab7017a2012-07-30 16:05:16 -04002523 nfs_mod = get_nfs_version(mount_info.parsed->version);
2524 if (IS_ERR(nfs_mod)) {
2525 mntroot = ERR_CAST(nfs_mod);
2526 goto out;
2527 }
2528
Bryan Schumakerff9099f22012-07-30 16:05:18 -04002529 mntroot = nfs_mod->rpc_ops->try_mount(flags, dev_name, &mount_info, nfs_mod);
Bryan Schumakerab7017a2012-07-30 16:05:16 -04002530
2531 put_nfs_version(nfs_mod);
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002532out:
Bryan Schumaker46058d42012-05-10 15:07:42 -04002533 nfs_free_parsed_mount_data(mount_info.parsed);
Bryan Schumaker87c70832012-05-10 15:07:43 -04002534 nfs_free_fhandle(mount_info.mntfh);
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002535 return mntroot;
2536}
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002537EXPORT_SYMBOL_GPL(nfs_fs_mount);
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002538
David Howells54ceac42006-08-22 20:06:13 -04002539/*
Trond Myklebust387c1492010-02-03 08:27:35 -05002540 * Ensure that we unregister the bdi before kill_anon_super
2541 * releases the device name
2542 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002543void nfs_put_super(struct super_block *s)
Trond Myklebust387c1492010-02-03 08:27:35 -05002544{
2545 struct nfs_server *server = NFS_SB(s);
2546
2547 bdi_unregister(&server->backing_dev_info);
2548}
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002549EXPORT_SYMBOL_GPL(nfs_put_super);
Trond Myklebust387c1492010-02-03 08:27:35 -05002550
2551/*
David Howells54ceac42006-08-22 20:06:13 -04002552 * Destroy an NFS2/3 superblock
2553 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002554void nfs_kill_super(struct super_block *s)
David Howellsf7b422b2006-06-09 09:34:33 -04002555{
2556 struct nfs_server *server = NFS_SB(s);
2557
2558 kill_anon_super(s);
David Howells08734042009-04-03 16:42:42 +01002559 nfs_fscache_release_super_cookie(s);
David Howells54ceac42006-08-22 20:06:13 -04002560 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04002561}
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002562EXPORT_SYMBOL_GPL(nfs_kill_super);
David Howellsf7b422b2006-06-09 09:34:33 -04002563
David Howells54ceac42006-08-22 20:06:13 -04002564/*
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002565 * Clone an NFS2/3/4 server record on xdev traversal (FSID-change)
David Howells54ceac42006-08-22 20:06:13 -04002566 */
Stanislav Kinsbursky3dd4f8ef2012-10-02 14:19:04 +04002567static struct dentry *
Bryan Schumakere8f25e62012-07-30 16:05:17 -04002568nfs_xdev_mount(struct file_system_type *fs_type, int flags,
2569 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002570{
Bryan Schumakere8f25e62012-07-30 16:05:17 -04002571 struct nfs_clone_mount *data = raw_data;
2572 struct nfs_mount_info mount_info = {
2573 .fill_super = nfs_clone_super,
2574 .set_security = nfs_clone_sb_security,
2575 .cloned = data,
2576 };
David Howells54ceac42006-08-22 20:06:13 -04002577 struct nfs_server *server;
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002578 struct dentry *mntroot = ERR_PTR(-ENOMEM);
Bryan Schumakerab7017a2012-07-30 16:05:16 -04002579 struct nfs_subversion *nfs_mod = NFS_SB(data->sb)->nfs_client->cl_nfs_mod;
David Howells54ceac42006-08-22 20:06:13 -04002580 int error;
2581
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002582 dprintk("--> nfs_xdev_mount_common()\n");
David Howells54ceac42006-08-22 20:06:13 -04002583
Bryan Schumakere8f25e62012-07-30 16:05:17 -04002584 mount_info.mntfh = mount_info.cloned->fh;
Bryan Schumaker87c70832012-05-10 15:07:43 -04002585
David Howells54ceac42006-08-22 20:06:13 -04002586 /* create a new volume representation */
Bryan Schumaker1179acc2012-07-30 16:05:19 -04002587 server = nfs_mod->rpc_ops->clone_server(NFS_SB(data->sb), data->fh, data->fattr, data->authflavor);
David Howells54ceac42006-08-22 20:06:13 -04002588 if (IS_ERR(server)) {
2589 error = PTR_ERR(server);
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002590 goto out_err;
David Howells54ceac42006-08-22 20:06:13 -04002591 }
2592
Bryan Schumakere8f25e62012-07-30 16:05:17 -04002593 mntroot = nfs_fs_mount_common(server, flags, dev_name, &mount_info, nfs_mod);
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002594 dprintk("<-- nfs_xdev_mount_common() = 0\n");
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002595out:
Al Viro31f43472010-10-29 03:38:12 -04002596 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04002597
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002598out_err:
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002599 dprintk("<-- nfs_xdev_mount_common() = %d [error]\n", error);
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002600 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002601}
2602
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002603#if IS_ENABLED(CONFIG_NFS_V4)
David Howells54ceac42006-08-22 20:06:13 -04002604
Trond Myklebust01c3f052009-06-17 13:22:58 -07002605static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2606{
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04002607 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3|
2608 NFS_MOUNT_LOCAL_FLOCK|NFS_MOUNT_LOCAL_FCNTL);
Trond Myklebust01c3f052009-06-17 13:22:58 -07002609}
2610
David Howells54ceac42006-08-22 20:06:13 -04002611/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04002612 * Validate NFSv4 mount options
2613 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002614static int nfs4_validate_mount_data(void *options,
2615 struct nfs_parsed_mount_data *args,
2616 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04002617{
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002618 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002619 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002620 char *c;
2621
2622 if (data == NULL)
2623 goto out_no_data;
2624
Bryan Schumakercdf66442012-06-05 14:59:54 -04002625 args->version = 4;
2626
Chuck Leverf0768eb2007-07-01 12:13:01 -04002627 switch (data->version) {
2628 case 1:
Chuck Lever4c568012007-12-10 14:59:28 -05002629 if (data->host_addrlen > sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002630 goto out_no_address;
Chuck Lever4c568012007-12-10 14:59:28 -05002631 if (data->host_addrlen == 0)
2632 goto out_no_address;
2633 args->nfs_server.addrlen = data->host_addrlen;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002634 if (copy_from_user(sap, data->host_addr, data->host_addrlen))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002635 return -EFAULT;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002636 if (!nfs_verify_server_address(sap))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002637 goto out_no_address;
Trond Myklebust872ece82012-09-04 11:05:07 -04002638 args->nfs_server.port = ntohs(((struct sockaddr_in *)sap)->sin_port);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002639
Chuck Lever6738b252008-06-24 16:33:54 -04002640 if (data->auth_flavourlen) {
2641 if (data->auth_flavourlen > 1)
2642 goto out_inval_auth;
Trond Myklebust20c71f52007-09-20 20:23:51 -04002643 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002644 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04002645 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002646 return -EFAULT;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002647 }
2648
2649 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2650 if (IS_ERR(c))
2651 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002652 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002653
2654 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2655 if (IS_ERR(c))
2656 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002657 args->nfs_server.export_path = c;
2658 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002659
2660 c = strndup_user(data->client_addr.data, 16);
2661 if (IS_ERR(c))
2662 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002663 args->client_address = c;
2664
2665 /*
2666 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2667 * can deal with.
2668 */
2669
2670 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2671 args->rsize = data->rsize;
2672 args->wsize = data->wsize;
2673 args->timeo = data->timeo;
2674 args->retrans = data->retrans;
2675 args->acregmin = data->acregmin;
2676 args->acregmax = data->acregmax;
2677 args->acdirmin = data->acdirmin;
2678 args->acdirmax = data->acdirmax;
2679 args->nfs_server.protocol = data->proto;
Trond Myklebust259875e2008-07-02 14:43:47 -04002680 nfs_validate_transport_protocol(args);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002681
2682 break;
Chuck Lever7630c852009-09-08 19:49:57 -04002683 default:
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04002684 return NFS_TEXT_DATA;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002685 }
2686
2687 return 0;
2688
2689out_no_data:
2690 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2691 return -EINVAL;
2692
2693out_inval_auth:
2694 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2695 data->auth_flavourlen);
2696 return -EINVAL;
2697
2698out_no_address:
2699 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2700 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002701}
2702
Bryan Schumakerfac1e8e2012-07-30 16:05:22 -04002703/*
2704 * NFS v4 module parameters need to stay in the
2705 * NFS client for backwards compatibility
2706 */
2707unsigned int nfs_callback_set_tcpport;
2708unsigned short nfs_callback_tcpport;
2709/* Default cache timeout is 10 minutes */
2710unsigned int nfs_idmap_cache_timeout = 600;
2711/* Turn off NFSv4 uid/gid mapping when using AUTH_SYS */
2712bool nfs4_disable_idmapping = true;
2713unsigned short max_session_slots = NFS4_DEF_SLOT_TABLE_SIZE;
2714unsigned short send_implementation_id = 1;
Chuck Lever6f2ea7f2012-09-14 17:24:41 -04002715char nfs4_client_id_uniquifier[NFS4_CLIENT_ID_UNIQ_LEN] = "";
Bryan Schumakerfac1e8e2012-07-30 16:05:22 -04002716
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002717EXPORT_SYMBOL_GPL(nfs_callback_set_tcpport);
2718EXPORT_SYMBOL_GPL(nfs_callback_tcpport);
2719EXPORT_SYMBOL_GPL(nfs_idmap_cache_timeout);
2720EXPORT_SYMBOL_GPL(nfs4_disable_idmapping);
2721EXPORT_SYMBOL_GPL(max_session_slots);
2722EXPORT_SYMBOL_GPL(send_implementation_id);
Chuck Lever6f2ea7f2012-09-14 17:24:41 -04002723EXPORT_SYMBOL_GPL(nfs4_client_id_uniquifier);
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002724
Bryan Schumakerfac1e8e2012-07-30 16:05:22 -04002725#define NFS_CALLBACK_MAXPORTNR (65535U)
2726
2727static int param_set_portnr(const char *val, const struct kernel_param *kp)
2728{
2729 unsigned long num;
2730 int ret;
2731
2732 if (!val)
2733 return -EINVAL;
Daniel Walter7297cb62012-09-26 21:51:46 +02002734 ret = kstrtoul(val, 0, &num);
Bryan Schumakerfac1e8e2012-07-30 16:05:22 -04002735 if (ret == -EINVAL || num > NFS_CALLBACK_MAXPORTNR)
2736 return -EINVAL;
2737 *((unsigned int *)kp->arg) = num;
2738 return 0;
2739}
2740static struct kernel_param_ops param_ops_portnr = {
2741 .set = param_set_portnr,
2742 .get = param_get_uint,
2743};
2744#define param_check_portnr(name, p) __param_check(name, p, unsigned int);
2745
2746module_param_named(callback_tcpport, nfs_callback_set_tcpport, portnr, 0644);
2747module_param(nfs_idmap_cache_timeout, int, 0644);
2748module_param(nfs4_disable_idmapping, bool, 0644);
Chuck Lever6f2ea7f2012-09-14 17:24:41 -04002749module_param_string(nfs4_unique_id, nfs4_client_id_uniquifier,
2750 NFS4_CLIENT_ID_UNIQ_LEN, 0600);
Bryan Schumakerfac1e8e2012-07-30 16:05:22 -04002751MODULE_PARM_DESC(nfs4_disable_idmapping,
2752 "Turn off NFSv4 idmapping when using 'sec=sys'");
2753module_param(max_session_slots, ushort, 0644);
2754MODULE_PARM_DESC(max_session_slots, "Maximum number of outstanding NFSv4.1 "
2755 "requests the client will negotiate");
2756module_param(send_implementation_id, ushort, 0644);
2757MODULE_PARM_DESC(send_implementation_id,
2758 "Send implementation ID with NFSv4.1 exchange_id");
Chuck Lever6f2ea7f2012-09-14 17:24:41 -04002759MODULE_PARM_DESC(nfs4_unique_id, "nfs_client_id4 uniquifier string");
bjschuma@gmail.com425e7762012-08-08 13:57:10 -04002760MODULE_ALIAS("nfs4");
2761
David Howells54ceac42006-08-22 20:06:13 -04002762#endif /* CONFIG_NFS_V4 */