blob: ac6a3c55dce408afbd5348a2f9af42a7f78e660e [file] [log] [blame]
David Howellsf7b422b2006-06-09 09:34:33 -04001/*
2 * linux/fs/nfs/super.c
3 *
4 * Copyright (C) 1992 Rick Sladkey
5 *
6 * nfs superblock handling functions
7 *
Alan Cox526719b2008-10-27 15:19:48 +00008 * Modularised by Alan Cox <alan@lxorguk.ukuu.org.uk>, while hacking some
David Howellsf7b422b2006-06-09 09:34:33 -04009 * experimental NFS changes. Modularisation taken straight from SYS5 fs.
10 *
11 * Change to nfs_read_super() to permit NFS mounts to multi-homed hosts.
12 * J.S.Peatfield@damtp.cam.ac.uk
13 *
14 * Split from inode.c by David Howells <dhowells@redhat.com>
15 *
David Howells54ceac42006-08-22 20:06:13 -040016 * - superblocks are indexed on server only - all inodes, dentries, etc. associated with a
17 * particular server are held in the same superblock
18 * - NFS superblocks can have several effective roots to the dentry tree
19 * - directory type roots are spliced into the tree when a path from one root reaches the root
20 * of another (see nfs_lookup())
David Howellsf7b422b2006-06-09 09:34:33 -040021 */
22
David Howellsf7b422b2006-06-09 09:34:33 -040023#include <linux/module.h>
24#include <linux/init.h>
25
26#include <linux/time.h>
27#include <linux/kernel.h>
28#include <linux/mm.h>
29#include <linux/string.h>
30#include <linux/stat.h>
31#include <linux/errno.h>
32#include <linux/unistd.h>
33#include <linux/sunrpc/clnt.h>
34#include <linux/sunrpc/stats.h>
35#include <linux/sunrpc/metrics.h>
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -040036#include <linux/sunrpc/xprtsock.h>
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -040037#include <linux/sunrpc/xprtrdma.h>
David Howellsf7b422b2006-06-09 09:34:33 -040038#include <linux/nfs_fs.h>
39#include <linux/nfs_mount.h>
40#include <linux/nfs4_mount.h>
41#include <linux/lockd/bind.h>
David Howellsf7b422b2006-06-09 09:34:33 -040042#include <linux/seq_file.h>
43#include <linux/mount.h>
Trond Myklebustc02d7ad2009-06-22 15:09:14 -040044#include <linux/namei.h>
David Howellsf7b422b2006-06-09 09:34:33 -040045#include <linux/nfs_idmap.h>
46#include <linux/vfs.h>
47#include <linux/inet.h>
Chuck Leverfd00a8f2007-12-10 14:57:38 -050048#include <linux/in6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090049#include <linux/slab.h>
Chuck Leverfd00a8f2007-12-10 14:57:38 -050050#include <net/ipv6.h>
Chuck Leverd8e77482008-06-23 12:37:01 -040051#include <linux/netdevice.h>
David Howellsf7b422b2006-06-09 09:34:33 -040052#include <linux/nfs_xdr.h>
Adrian Bunkb5d5dfb2007-02-12 00:53:40 -080053#include <linux/magic.h>
Chuck Leverbf0fd762007-07-01 12:13:44 -040054#include <linux/parser.h>
Stanislav Kinsburskye50a7a12012-01-10 16:12:46 +040055#include <linux/nsproxy.h>
Trond Myklebust2446ab62012-03-01 17:00:56 -050056#include <linux/rcupdate.h>
David Howellsf7b422b2006-06-09 09:34:33 -040057
David Howellsf7b422b2006-06-09 09:34:33 -040058#include <asm/uaccess.h>
59
60#include "nfs4_fs.h"
61#include "callback.h"
62#include "delegation.h"
63#include "iostat.h"
64#include "internal.h"
David Howells08734042009-04-03 16:42:42 +010065#include "fscache.h"
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +030066#include "pnfs.h"
Bryan Schumakerab7017a2012-07-30 16:05:16 -040067#include "nfs.h"
David Howellsf7b422b2006-06-09 09:34:33 -040068
69#define NFSDBG_FACILITY NFSDBG_VFS
Bryan Schumakerb72e4f42012-05-10 15:07:40 -040070#define NFS_TEXT_DATA 1
David Howellsf7b422b2006-06-09 09:34:33 -040071
Bryan Schumaker1c606fb2012-07-30 16:05:24 -040072#if IS_ENABLED(CONFIG_NFS_V3)
Paulius Zaleckas1e657bd2010-10-31 18:21:05 +020073#define NFS_DEFAULT_VERSION 3
74#else
75#define NFS_DEFAULT_VERSION 2
76#endif
77
Chuck Leverbf0fd762007-07-01 12:13:44 -040078enum {
79 /* Mount options that take no arguments */
80 Opt_soft, Opt_hard,
Chuck Leverbf0fd762007-07-01 12:13:44 -040081 Opt_posix, Opt_noposix,
82 Opt_cto, Opt_nocto,
83 Opt_ac, Opt_noac,
84 Opt_lock, Opt_nolock,
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -040085 Opt_udp, Opt_tcp, Opt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -040086 Opt_acl, Opt_noacl,
87 Opt_rdirplus, Opt_nordirplus,
Trond Myklebust75180df2007-05-16 16:53:28 -040088 Opt_sharecache, Opt_nosharecache,
Chuck Leverd7403512008-12-23 15:21:37 -050089 Opt_resvport, Opt_noresvport,
David Howellsb797cac2009-04-03 16:42:48 +010090 Opt_fscache, Opt_nofscache,
Chuck Leverbf0fd762007-07-01 12:13:44 -040091
92 /* Mount options that take integer arguments */
93 Opt_port,
94 Opt_rsize, Opt_wsize, Opt_bsize,
95 Opt_timeo, Opt_retrans,
96 Opt_acregmin, Opt_acregmax,
97 Opt_acdirmin, Opt_acdirmax,
98 Opt_actimeo,
99 Opt_namelen,
100 Opt_mountport,
Chuck Levere887cbc2007-10-26 13:32:29 -0400101 Opt_mountvers,
Mike Sager3fd5be92009-04-01 09:21:48 -0400102 Opt_minorversion,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400103
104 /* Mount options that take string arguments */
Trond Myklebust0d71b052012-03-02 13:59:49 -0500105 Opt_nfsvers,
Chuck Lever33832032007-12-10 14:59:13 -0500106 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
Chuck Lever0ac83772007-09-11 18:01:04 -0400107 Opt_addr, Opt_mountaddr, Opt_clientaddr,
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400108 Opt_lookupcache,
David Howellsb797cac2009-04-03 16:42:48 +0100109 Opt_fscache_uniq,
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400110 Opt_local_lock,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400111
Chuck Leverf45663c2008-06-24 19:28:02 -0400112 /* Special mount options */
113 Opt_userspace, Opt_deprecated, Opt_sloppy,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400114
115 Opt_err
116};
117
Steven Whitehousea447c092008-10-13 10:46:57 +0100118static const match_table_t nfs_mount_option_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400119 { Opt_userspace, "bg" },
120 { Opt_userspace, "fg" },
Chuck Leverecbb3842008-06-12 12:37:33 -0400121 { Opt_userspace, "retry=%s" },
122
Chuck Leverf45663c2008-06-24 19:28:02 -0400123 { Opt_sloppy, "sloppy" },
124
Chuck Leverbf0fd762007-07-01 12:13:44 -0400125 { Opt_soft, "soft" },
126 { Opt_hard, "hard" },
Chuck Leverd33e4df2008-06-12 12:37:41 -0400127 { Opt_deprecated, "intr" },
128 { Opt_deprecated, "nointr" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400129 { Opt_posix, "posix" },
130 { Opt_noposix, "noposix" },
131 { Opt_cto, "cto" },
132 { Opt_nocto, "nocto" },
133 { Opt_ac, "ac" },
134 { Opt_noac, "noac" },
135 { Opt_lock, "lock" },
136 { Opt_nolock, "nolock" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400137 { Opt_udp, "udp" },
138 { Opt_tcp, "tcp" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400139 { Opt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400140 { Opt_acl, "acl" },
141 { Opt_noacl, "noacl" },
142 { Opt_rdirplus, "rdirplus" },
143 { Opt_nordirplus, "nordirplus" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400144 { Opt_sharecache, "sharecache" },
145 { Opt_nosharecache, "nosharecache" },
Chuck Leverd7403512008-12-23 15:21:37 -0500146 { Opt_resvport, "resvport" },
147 { Opt_noresvport, "noresvport" },
David Howellsb797cac2009-04-03 16:42:48 +0100148 { Opt_fscache, "fsc" },
David Howellsb797cac2009-04-03 16:42:48 +0100149 { Opt_nofscache, "nofsc" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400150
Chuck Levera5a16ba2009-06-17 18:02:14 -0700151 { Opt_port, "port=%s" },
152 { Opt_rsize, "rsize=%s" },
153 { Opt_wsize, "wsize=%s" },
154 { Opt_bsize, "bsize=%s" },
155 { Opt_timeo, "timeo=%s" },
156 { Opt_retrans, "retrans=%s" },
157 { Opt_acregmin, "acregmin=%s" },
158 { Opt_acregmax, "acregmax=%s" },
159 { Opt_acdirmin, "acdirmin=%s" },
160 { Opt_acdirmax, "acdirmax=%s" },
161 { Opt_actimeo, "actimeo=%s" },
162 { Opt_namelen, "namlen=%s" },
163 { Opt_mountport, "mountport=%s" },
164 { Opt_mountvers, "mountvers=%s" },
Trond Myklebust0d71b052012-03-02 13:59:49 -0500165 { Opt_minorversion, "minorversion=%s" },
166
Chuck Levera5a16ba2009-06-17 18:02:14 -0700167 { Opt_nfsvers, "nfsvers=%s" },
168 { Opt_nfsvers, "vers=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400169
170 { Opt_sec, "sec=%s" },
171 { Opt_proto, "proto=%s" },
172 { Opt_mountproto, "mountproto=%s" },
173 { Opt_addr, "addr=%s" },
174 { Opt_clientaddr, "clientaddr=%s" },
Chuck Lever33832032007-12-10 14:59:13 -0500175 { Opt_mounthost, "mounthost=%s" },
Chuck Lever0ac83772007-09-11 18:01:04 -0400176 { Opt_mountaddr, "mountaddr=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400177
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400178 { Opt_lookupcache, "lookupcache=%s" },
Chuck Levera6d5ff62010-05-07 13:33:58 -0400179 { Opt_fscache_uniq, "fsc=%s" },
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400180 { Opt_local_lock, "local_lock=%s" },
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400181
Trond Myklebust38622792012-03-02 14:06:39 -0500182 /* The following needs to be listed after all other options */
183 { Opt_nfsvers, "v%s" },
184
Chuck Leverbf0fd762007-07-01 12:13:44 -0400185 { Opt_err, NULL }
186};
187
188enum {
Jeff Laytonee671b02009-12-03 15:58:56 -0500189 Opt_xprt_udp, Opt_xprt_udp6, Opt_xprt_tcp, Opt_xprt_tcp6, Opt_xprt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400190
191 Opt_xprt_err
192};
193
Steven Whitehousea447c092008-10-13 10:46:57 +0100194static const match_table_t nfs_xprt_protocol_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400195 { Opt_xprt_udp, "udp" },
Jeff Laytonee671b02009-12-03 15:58:56 -0500196 { Opt_xprt_udp6, "udp6" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400197 { Opt_xprt_tcp, "tcp" },
Jeff Laytonee671b02009-12-03 15:58:56 -0500198 { Opt_xprt_tcp6, "tcp6" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400199 { Opt_xprt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400200
201 { Opt_xprt_err, NULL }
202};
203
204enum {
205 Opt_sec_none, Opt_sec_sys,
206 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
207 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
208 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
209
210 Opt_sec_err
211};
212
Steven Whitehousea447c092008-10-13 10:46:57 +0100213static const match_table_t nfs_secflavor_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400214 { Opt_sec_none, "none" },
215 { Opt_sec_none, "null" },
216 { Opt_sec_sys, "sys" },
217
218 { Opt_sec_krb5, "krb5" },
219 { Opt_sec_krb5i, "krb5i" },
220 { Opt_sec_krb5p, "krb5p" },
221
222 { Opt_sec_lkey, "lkey" },
223 { Opt_sec_lkeyi, "lkeyi" },
224 { Opt_sec_lkeyp, "lkeyp" },
225
Olga Kornievskaia8d042212008-02-13 16:47:06 -0500226 { Opt_sec_spkm, "spkm3" },
227 { Opt_sec_spkmi, "spkm3i" },
228 { Opt_sec_spkmp, "spkm3p" },
229
Chuck Leverbf0fd762007-07-01 12:13:44 -0400230 { Opt_sec_err, NULL }
231};
232
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400233enum {
234 Opt_lookupcache_all, Opt_lookupcache_positive,
235 Opt_lookupcache_none,
236
237 Opt_lookupcache_err
238};
239
240static match_table_t nfs_lookupcache_tokens = {
241 { Opt_lookupcache_all, "all" },
242 { Opt_lookupcache_positive, "pos" },
243 { Opt_lookupcache_positive, "positive" },
244 { Opt_lookupcache_none, "none" },
245
246 { Opt_lookupcache_err, NULL }
247};
248
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400249enum {
250 Opt_local_lock_all, Opt_local_lock_flock, Opt_local_lock_posix,
251 Opt_local_lock_none,
252
253 Opt_local_lock_err
254};
255
256static match_table_t nfs_local_lock_tokens = {
257 { Opt_local_lock_all, "all" },
258 { Opt_local_lock_flock, "flock" },
259 { Opt_local_lock_posix, "posix" },
260 { Opt_local_lock_none, "none" },
261
262 { Opt_local_lock_err, NULL }
263};
264
Trond Myklebust0d71b052012-03-02 13:59:49 -0500265enum {
266 Opt_vers_2, Opt_vers_3, Opt_vers_4, Opt_vers_4_0,
267 Opt_vers_4_1,
268
269 Opt_vers_err
270};
271
272static match_table_t nfs_vers_tokens = {
273 { Opt_vers_2, "2" },
274 { Opt_vers_3, "3" },
275 { Opt_vers_4, "4" },
276 { Opt_vers_4_0, "4.0" },
277 { Opt_vers_4_1, "4.1" },
278
279 { Opt_vers_err, NULL }
280};
Chuck Leverbf0fd762007-07-01 12:13:44 -0400281
Al Viro31f43472010-10-29 03:38:12 -0400282static struct dentry *nfs_xdev_mount(struct file_system_type *fs_type,
283 int flags, const char *dev_name, void *raw_data);
David Howellsf7b422b2006-06-09 09:34:33 -0400284
Bryan Schumakerab7017a2012-07-30 16:05:16 -0400285struct file_system_type nfs_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400286 .owner = THIS_MODULE,
287 .name = "nfs",
Al Viro01194982011-03-16 07:25:36 -0400288 .mount = nfs_fs_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400289 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700290 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400291};
Bryan Schumakerddda8e02012-07-30 16:05:23 -0400292EXPORT_SYMBOL_GPL(nfs_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400293
David Howells54ceac42006-08-22 20:06:13 -0400294struct file_system_type nfs_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400295 .owner = THIS_MODULE,
296 .name = "nfs",
Al Viro31f43472010-10-29 03:38:12 -0400297 .mount = nfs_xdev_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400298 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700299 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400300};
301
Bryan Schumaker6a744902012-07-30 16:05:20 -0400302const struct super_operations nfs_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400303 .alloc_inode = nfs_alloc_inode,
304 .destroy_inode = nfs_destroy_inode,
305 .write_inode = nfs_write_inode,
Trond Myklebust387c1492010-02-03 08:27:35 -0500306 .put_super = nfs_put_super,
David Howellsf7b422b2006-06-09 09:34:33 -0400307 .statfs = nfs_statfs,
Al Virob57922d2010-06-07 14:34:48 -0400308 .evict_inode = nfs_evict_inode,
David Howellsf7b422b2006-06-09 09:34:33 -0400309 .umount_begin = nfs_umount_begin,
310 .show_options = nfs_show_options,
Al Viroc7f404b2011-03-16 06:59:40 -0400311 .show_devname = nfs_show_devname,
312 .show_path = nfs_show_path,
David Howellsf7b422b2006-06-09 09:34:33 -0400313 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400314 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400315};
Bryan Schumakerddda8e02012-07-30 16:05:23 -0400316EXPORT_SYMBOL_GPL(nfs_sops);
David Howellsf7b422b2006-06-09 09:34:33 -0400317
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400318#if IS_ENABLED(CONFIG_NFS_V4)
Bryan Schumakerb72e4f42012-05-10 15:07:40 -0400319static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *);
Bryan Schumakerd72c7272012-05-10 15:07:41 -0400320static int nfs4_validate_mount_data(void *options,
321 struct nfs_parsed_mount_data *args, const char *dev_name);
David Howellsf7b422b2006-06-09 09:34:33 -0400322#endif
323
Rusty Russell8e1f9362007-07-17 04:03:17 -0700324static struct shrinker acl_shrinker = {
325 .shrink = nfs_access_cache_shrinker,
326 .seeks = DEFAULT_SEEKS,
327};
Trond Myklebust979df722006-07-25 11:28:19 -0400328
David Howellsf7b422b2006-06-09 09:34:33 -0400329/*
330 * Register the NFS filesystems
331 */
332int __init register_nfs_fs(void)
333{
334 int ret;
335
336 ret = register_filesystem(&nfs_fs_type);
337 if (ret < 0)
338 goto error_0;
339
David Howellsf7b422b2006-06-09 09:34:33 -0400340 ret = nfs_register_sysctl();
341 if (ret < 0)
342 goto error_1;
Rusty Russell8e1f9362007-07-17 04:03:17 -0700343 register_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400344 return 0;
345
David Howellsf7b422b2006-06-09 09:34:33 -0400346error_1:
347 unregister_filesystem(&nfs_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400348error_0:
349 return ret;
350}
351
352/*
353 * Unregister the NFS filesystems
354 */
355void __exit unregister_nfs_fs(void)
356{
Rusty Russell8e1f9362007-07-17 04:03:17 -0700357 unregister_shrinker(&acl_shrinker);
Alexey Dobriyan49af7ee2007-09-18 22:46:40 -0700358 nfs_unregister_sysctl();
David Howellsf7b422b2006-06-09 09:34:33 -0400359 unregister_filesystem(&nfs_fs_type);
360}
361
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400362void nfs_sb_active(struct super_block *sb)
Steve Dicksonef818a22007-11-08 04:05:04 -0500363{
364 struct nfs_server *server = NFS_SB(sb);
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400365
366 if (atomic_inc_return(&server->active) == 1)
367 atomic_inc(&sb->s_active);
368}
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400369EXPORT_SYMBOL_GPL(nfs_sb_active);
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400370
371void nfs_sb_deactive(struct super_block *sb)
372{
373 struct nfs_server *server = NFS_SB(sb);
374
375 if (atomic_dec_and_test(&server->active))
376 deactivate_super(sb);
Steve Dicksonef818a22007-11-08 04:05:04 -0500377}
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400378EXPORT_SYMBOL_GPL(nfs_sb_deactive);
Steve Dicksonef818a22007-11-08 04:05:04 -0500379
David Howellsf7b422b2006-06-09 09:34:33 -0400380/*
381 * Deliver file system statistics to userspace
382 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -0400383int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
David Howellsf7b422b2006-06-09 09:34:33 -0400384{
David Howells0c7d90c2006-08-22 20:06:10 -0400385 struct nfs_server *server = NFS_SB(dentry->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400386 unsigned char blockbits;
387 unsigned long blockres;
David Howells0c7d90c2006-08-22 20:06:10 -0400388 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400389 struct nfs_fsstat res;
390 int error = -ENOMEM;
391
392 res.fattr = nfs_alloc_fattr();
393 if (res.fattr == NULL)
394 goto out_err;
David Howellsf7b422b2006-06-09 09:34:33 -0400395
David Howells8fa5c002006-08-22 20:06:12 -0400396 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
Menyhart Zoltanfbf3fdd2010-09-12 19:55:26 -0400397 if (unlikely(error == -ESTALE)) {
398 struct dentry *pd_dentry;
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400399
Menyhart Zoltanfbf3fdd2010-09-12 19:55:26 -0400400 pd_dentry = dget_parent(dentry);
401 if (pd_dentry != NULL) {
402 nfs_zap_caches(pd_dentry->d_inode);
403 dput(pd_dentry);
404 }
405 }
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400406 nfs_free_fattr(res.fattr);
David Howellsf7b422b2006-06-09 09:34:33 -0400407 if (error < 0)
408 goto out_err;
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400409
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700410 buf->f_type = NFS_SUPER_MAGIC;
David Howellsf7b422b2006-06-09 09:34:33 -0400411
412 /*
413 * Current versions of glibc do not correctly handle the
414 * case where f_frsize != f_bsize. Eventually we want to
415 * report the value of wtmult in this field.
416 */
David Howells0c7d90c2006-08-22 20:06:10 -0400417 buf->f_frsize = dentry->d_sb->s_blocksize;
David Howellsf7b422b2006-06-09 09:34:33 -0400418
419 /*
420 * On most *nix systems, f_blocks, f_bfree, and f_bavail
421 * are reported in units of f_frsize. Linux hasn't had
422 * an f_frsize field in its statfs struct until recently,
423 * thus historically Linux's sys_statfs reports these
424 * fields in units of f_bsize.
425 */
David Howells0c7d90c2006-08-22 20:06:10 -0400426 buf->f_bsize = dentry->d_sb->s_blocksize;
427 blockbits = dentry->d_sb->s_blocksize_bits;
David Howellsf7b422b2006-06-09 09:34:33 -0400428 blockres = (1 << blockbits) - 1;
429 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
430 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
431 buf->f_bavail = (res.abytes + blockres) >> blockbits;
432
433 buf->f_files = res.tfiles;
434 buf->f_ffree = res.afiles;
435
436 buf->f_namelen = server->namelen;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700437
David Howellsf7b422b2006-06-09 09:34:33 -0400438 return 0;
439
440 out_err:
Harvey Harrison3110ff82008-05-02 13:42:44 -0700441 dprintk("%s: statfs error = %d\n", __func__, -error);
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700442 return error;
David Howellsf7b422b2006-06-09 09:34:33 -0400443}
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400444EXPORT_SYMBOL_GPL(nfs_statfs);
David Howellsf7b422b2006-06-09 09:34:33 -0400445
David Howells7d4e2742006-08-22 20:06:07 -0400446/*
447 * Map the security flavour number to a name
448 */
Trond Myklebust81039f12006-06-09 09:34:34 -0400449static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
450{
David Howells7d4e2742006-08-22 20:06:07 -0400451 static const struct {
Trond Myklebust81039f12006-06-09 09:34:34 -0400452 rpc_authflavor_t flavour;
453 const char *str;
454 } sec_flavours[] = {
455 { RPC_AUTH_NULL, "null" },
456 { RPC_AUTH_UNIX, "sys" },
457 { RPC_AUTH_GSS_KRB5, "krb5" },
458 { RPC_AUTH_GSS_KRB5I, "krb5i" },
459 { RPC_AUTH_GSS_KRB5P, "krb5p" },
460 { RPC_AUTH_GSS_LKEY, "lkey" },
461 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
462 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
463 { RPC_AUTH_GSS_SPKM, "spkm" },
464 { RPC_AUTH_GSS_SPKMI, "spkmi" },
465 { RPC_AUTH_GSS_SPKMP, "spkmp" },
Chuck Lever4d81cd12007-07-01 12:12:40 -0400466 { UINT_MAX, "unknown" }
Trond Myklebust81039f12006-06-09 09:34:34 -0400467 };
468 int i;
469
Chuck Lever4d81cd12007-07-01 12:12:40 -0400470 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
Trond Myklebust81039f12006-06-09 09:34:34 -0400471 if (sec_flavours[i].flavour == flavour)
472 break;
473 }
474 return sec_flavours[i].str;
475}
476
Jeff Laytonee671b02009-12-03 15:58:56 -0500477static void nfs_show_mountd_netid(struct seq_file *m, struct nfs_server *nfss,
478 int showdefaults)
479{
480 struct sockaddr *sap = (struct sockaddr *) &nfss->mountd_address;
481
482 seq_printf(m, ",mountproto=");
483 switch (sap->sa_family) {
484 case AF_INET:
485 switch (nfss->mountd_protocol) {
486 case IPPROTO_UDP:
487 seq_printf(m, RPCBIND_NETID_UDP);
488 break;
489 case IPPROTO_TCP:
490 seq_printf(m, RPCBIND_NETID_TCP);
491 break;
492 default:
493 if (showdefaults)
494 seq_printf(m, "auto");
495 }
496 break;
497 case AF_INET6:
498 switch (nfss->mountd_protocol) {
499 case IPPROTO_UDP:
500 seq_printf(m, RPCBIND_NETID_UDP6);
501 break;
502 case IPPROTO_TCP:
503 seq_printf(m, RPCBIND_NETID_TCP6);
504 break;
505 default:
506 if (showdefaults)
507 seq_printf(m, "auto");
508 }
509 break;
510 default:
511 if (showdefaults)
512 seq_printf(m, "auto");
513 }
514}
515
Chuck Lever82d101d2008-03-14 14:10:37 -0400516static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
517 int showdefaults)
518{
519 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
520
Bryan Schumakerd5eff1a2010-08-03 13:04:00 -0400521 if (nfss->flags & NFS_MOUNT_LEGACY_INTERFACE)
522 return;
523
Chuck Lever82d101d2008-03-14 14:10:37 -0400524 switch (sap->sa_family) {
525 case AF_INET: {
526 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
Harvey Harrisonbe859402008-10-31 00:56:28 -0700527 seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400528 break;
529 }
530 case AF_INET6: {
531 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
Chuck Leverd250e192009-12-03 15:58:56 -0500532 seq_printf(m, ",mountaddr=%pI6c", &sin6->sin6_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400533 break;
534 }
535 default:
536 if (showdefaults)
537 seq_printf(m, ",mountaddr=unspecified");
538 }
539
540 if (nfss->mountd_version || showdefaults)
541 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
Stanislav Kinsburskyaa699472010-12-08 12:40:13 +0300542 if ((nfss->mountd_port &&
543 nfss->mountd_port != (unsigned short)NFS_UNSPEC_PORT) ||
544 showdefaults)
Chuck Lever82d101d2008-03-14 14:10:37 -0400545 seq_printf(m, ",mountport=%u", nfss->mountd_port);
546
Jeff Laytonee671b02009-12-03 15:58:56 -0500547 nfs_show_mountd_netid(m, nfss, showdefaults);
Chuck Lever82d101d2008-03-14 14:10:37 -0400548}
549
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400550#if IS_ENABLED(CONFIG_NFS_V4)
Trond Myklebust0be81892010-06-18 12:23:58 -0400551static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
552 int showdefaults)
553{
554 struct nfs_client *clp = nfss->nfs_client;
555
556 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
Trond Myklebust0be81892010-06-18 12:23:58 -0400557}
558#else
559static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
560 int showdefaults)
561{
562}
563#endif
564
Trond Myklebust7bbceb62012-03-02 14:00:20 -0500565static void nfs_show_nfs_version(struct seq_file *m,
566 unsigned int version,
567 unsigned int minorversion)
568{
569 seq_printf(m, ",vers=%u", version);
570 if (version == 4)
571 seq_printf(m, ".%u", minorversion);
572}
573
David Howellsf7b422b2006-06-09 09:34:33 -0400574/*
575 * Describe the mount options in force on this server representation
576 */
Chuck Lever82d101d2008-03-14 14:10:37 -0400577static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
578 int showdefaults)
David Howellsf7b422b2006-06-09 09:34:33 -0400579{
David Howells509de812006-08-22 20:06:11 -0400580 static const struct proc_nfs_info {
David Howellsf7b422b2006-06-09 09:34:33 -0400581 int flag;
David Howells509de812006-08-22 20:06:11 -0400582 const char *str;
583 const char *nostr;
David Howellsf7b422b2006-06-09 09:34:33 -0400584 } nfs_info[] = {
585 { NFS_MOUNT_SOFT, ",soft", ",hard" },
Chuck Lever82d101d2008-03-14 14:10:37 -0400586 { NFS_MOUNT_POSIX, ",posix", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400587 { NFS_MOUNT_NOCTO, ",nocto", "" },
588 { NFS_MOUNT_NOAC, ",noac", "" },
589 { NFS_MOUNT_NONLM, ",nolock", "" },
590 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400591 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
Chuck Leverd7403512008-12-23 15:21:37 -0500592 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
593 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400594 { 0, NULL, NULL }
595 };
David Howells509de812006-08-22 20:06:11 -0400596 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400597 struct nfs_client *clp = nfss->nfs_client;
Chuck Lever82d101d2008-03-14 14:10:37 -0400598 u32 version = clp->rpc_ops->version;
Suresh Jayaraman7c563cc2010-09-23 14:26:48 -0400599 int local_flock, local_fcntl;
David Howellsf7b422b2006-06-09 09:34:33 -0400600
Trond Myklebust7bbceb62012-03-02 14:00:20 -0500601 nfs_show_nfs_version(m, version, clp->cl_minorversion);
Chuck Lever2d767432008-03-14 14:10:08 -0400602 seq_printf(m, ",rsize=%u", nfss->rsize);
603 seq_printf(m, ",wsize=%u", nfss->wsize);
Chuck Lever82d101d2008-03-14 14:10:37 -0400604 if (nfss->bsize != 0)
605 seq_printf(m, ",bsize=%u", nfss->bsize);
606 seq_printf(m, ",namlen=%u", nfss->namelen);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400607 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400608 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400609 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400610 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400611 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400612 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400613 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400614 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
David Howellsf7b422b2006-06-09 09:34:33 -0400615 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
616 if (nfss->flags & nfs_infop->flag)
617 seq_puts(m, nfs_infop->str);
618 else
619 seq_puts(m, nfs_infop->nostr);
620 }
Trond Myklebust2446ab62012-03-01 17:00:56 -0500621 rcu_read_lock();
\"Talpey, Thomas\56928ed2007-09-10 13:48:47 -0400622 seq_printf(m, ",proto=%s",
Jeff Laytonee671b02009-12-03 15:58:56 -0500623 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
Trond Myklebust2446ab62012-03-01 17:00:56 -0500624 rcu_read_unlock();
Chuck Lever82d101d2008-03-14 14:10:37 -0400625 if (version == 4) {
626 if (nfss->port != NFS_PORT)
627 seq_printf(m, ",port=%u", nfss->port);
628 } else
629 if (nfss->port)
630 seq_printf(m, ",port=%u", nfss->port);
631
Trond Myklebust33170232007-12-20 16:03:59 -0500632 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
633 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
Trond Myklebust81039f12006-06-09 09:34:34 -0400634 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
Chuck Lever82d101d2008-03-14 14:10:37 -0400635
636 if (version != 4)
637 nfs_show_mountd_options(m, nfss, showdefaults);
Trond Myklebust0be81892010-06-18 12:23:58 -0400638 else
639 nfs_show_nfsv4_options(m, nfss, showdefaults);
Chuck Lever82d101d2008-03-14 14:10:37 -0400640
David Howellsb797cac2009-04-03 16:42:48 +0100641 if (nfss->options & NFS_OPTION_FSCACHE)
642 seq_printf(m, ",fsc");
Patrick J. LoPresti9b00c642010-08-10 17:28:01 -0400643
644 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONEG) {
645 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONE)
646 seq_printf(m, ",lookupcache=none");
647 else
648 seq_printf(m, ",lookupcache=pos");
649 }
Suresh Jayaraman7c563cc2010-09-23 14:26:48 -0400650
651 local_flock = nfss->flags & NFS_MOUNT_LOCAL_FLOCK;
652 local_fcntl = nfss->flags & NFS_MOUNT_LOCAL_FCNTL;
653
654 if (!local_flock && !local_fcntl)
655 seq_printf(m, ",local_lock=none");
656 else if (local_flock && local_fcntl)
657 seq_printf(m, ",local_lock=all");
658 else if (local_flock)
659 seq_printf(m, ",local_lock=flock");
660 else
661 seq_printf(m, ",local_lock=posix");
David Howellsf7b422b2006-06-09 09:34:33 -0400662}
663
664/*
665 * Describe the mount options on this VFS mountpoint
666 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -0400667int nfs_show_options(struct seq_file *m, struct dentry *root)
David Howellsf7b422b2006-06-09 09:34:33 -0400668{
Al Viro34c80b12011-12-08 21:32:45 -0500669 struct nfs_server *nfss = NFS_SB(root->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400670
671 nfs_show_mount_options(m, nfss, 0);
672
Trond Myklebust2446ab62012-03-01 17:00:56 -0500673 rcu_read_lock();
Chuck Lever5d8515c2007-12-10 14:57:16 -0500674 seq_printf(m, ",addr=%s",
675 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
676 RPC_DISPLAY_ADDR));
Trond Myklebust2446ab62012-03-01 17:00:56 -0500677 rcu_read_unlock();
David Howellsf7b422b2006-06-09 09:34:33 -0400678
679 return 0;
680}
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400681EXPORT_SYMBOL_GPL(nfs_show_options);
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700682
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400683#if IS_ENABLED(CONFIG_NFS_V4)
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300684#ifdef CONFIG_NFS_V4_1
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700685static void show_sessions(struct seq_file *m, struct nfs_server *server)
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300686{
687 if (nfs4_has_session(server->nfs_client))
688 seq_printf(m, ",sessions");
689}
690#else
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700691static void show_sessions(struct seq_file *m, struct nfs_server *server) {}
692#endif
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300693#endif
694
695#ifdef CONFIG_NFS_V4_1
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700696static void show_pnfs(struct seq_file *m, struct nfs_server *server)
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300697{
698 seq_printf(m, ",pnfs=");
699 if (server->pnfs_curr_ld)
700 seq_printf(m, "%s", server->pnfs_curr_ld->name);
701 else
702 seq_printf(m, "not configured");
703}
Trond Myklebust7e03b7c2012-03-04 18:12:57 -0500704
705static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
706{
Chuck Lever59155542012-05-21 22:44:41 -0400707 if (nfss->nfs_client && nfss->nfs_client->cl_implid) {
708 struct nfs41_impl_id *impl_id = nfss->nfs_client->cl_implid;
Trond Myklebust7e03b7c2012-03-04 18:12:57 -0500709 seq_printf(m, "\n\timpl_id:\tname='%s',domain='%s',"
710 "date='%llu,%u'",
711 impl_id->name, impl_id->domain,
712 impl_id->date.seconds, impl_id->date.nseconds);
713 }
714}
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700715#else
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400716#if IS_ENABLED(CONFIG_NFS_V4)
Trond Myklebust7e03b7c2012-03-04 18:12:57 -0500717static void show_pnfs(struct seq_file *m, struct nfs_server *server)
718{
719}
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700720#endif
Trond Myklebust7e03b7c2012-03-04 18:12:57 -0500721static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
722{
723}
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700724#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400725
Bryan Schumakerfbdefd62012-07-16 16:39:20 -0400726int nfs_show_devname(struct seq_file *m, struct dentry *root)
Al Viroc7f404b2011-03-16 06:59:40 -0400727{
728 char *page = (char *) __get_free_page(GFP_KERNEL);
729 char *devname, *dummy;
730 int err = 0;
731 if (!page)
732 return -ENOMEM;
Al Virod861c632011-12-08 21:32:45 -0500733 devname = nfs_path(&dummy, root, page, PAGE_SIZE);
Al Viroc7f404b2011-03-16 06:59:40 -0400734 if (IS_ERR(devname))
735 err = PTR_ERR(devname);
736 else
737 seq_escape(m, devname, " \t\n\\");
738 free_page((unsigned long)page);
739 return err;
740}
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400741EXPORT_SYMBOL_GPL(nfs_show_devname);
Al Viroc7f404b2011-03-16 06:59:40 -0400742
Bryan Schumakerfbdefd62012-07-16 16:39:20 -0400743int nfs_show_path(struct seq_file *m, struct dentry *dentry)
Al Viroc7f404b2011-03-16 06:59:40 -0400744{
745 seq_puts(m, "/");
746 return 0;
747}
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400748EXPORT_SYMBOL_GPL(nfs_show_path);
Al Viroc7f404b2011-03-16 06:59:40 -0400749
David Howellsf7b422b2006-06-09 09:34:33 -0400750/*
751 * Present statistical information for this VFS mountpoint
752 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -0400753int nfs_show_stats(struct seq_file *m, struct dentry *root)
David Howellsf7b422b2006-06-09 09:34:33 -0400754{
755 int i, cpu;
Al Viro64132372011-12-08 20:51:13 -0500756 struct nfs_server *nfss = NFS_SB(root->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400757 struct rpc_auth *auth = nfss->client->cl_auth;
758 struct nfs_iostats totals = { };
759
760 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
761
762 /*
763 * Display all mount option settings
764 */
765 seq_printf(m, "\n\topts:\t");
Al Viro64132372011-12-08 20:51:13 -0500766 seq_puts(m, root->d_sb->s_flags & MS_RDONLY ? "ro" : "rw");
767 seq_puts(m, root->d_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
768 seq_puts(m, root->d_sb->s_flags & MS_NOATIME ? ",noatime" : "");
769 seq_puts(m, root->d_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
David Howellsf7b422b2006-06-09 09:34:33 -0400770 nfs_show_mount_options(m, nfss, 1);
771
772 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
773
Trond Myklebust7e03b7c2012-03-04 18:12:57 -0500774 show_implementation_id(m, nfss);
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500775
David Howellsf7b422b2006-06-09 09:34:33 -0400776 seq_printf(m, "\n\tcaps:\t");
777 seq_printf(m, "caps=0x%x", nfss->caps);
Chuck Lever2d767432008-03-14 14:10:08 -0400778 seq_printf(m, ",wtmult=%u", nfss->wtmult);
779 seq_printf(m, ",dtsize=%u", nfss->dtsize);
780 seq_printf(m, ",bsize=%u", nfss->bsize);
781 seq_printf(m, ",namlen=%u", nfss->namelen);
David Howellsf7b422b2006-06-09 09:34:33 -0400782
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400783#if IS_ENABLED(CONFIG_NFS_V4)
Trond Myklebust40c553192007-12-14 14:56:07 -0500784 if (nfss->nfs_client->rpc_ops->version == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400785 seq_printf(m, "\n\tnfsv4:\t");
786 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
787 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
788 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300789 show_sessions(m, nfss);
790 show_pnfs(m, nfss);
David Howellsf7b422b2006-06-09 09:34:33 -0400791 }
792#endif
793
794 /*
795 * Display security flavor in effect for this mount
796 */
Chuck Lever2d767432008-03-14 14:10:08 -0400797 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400798 if (auth->au_flavor)
Chuck Lever2d767432008-03-14 14:10:08 -0400799 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400800
801 /*
802 * Display superblock I/O counters
803 */
804 for_each_possible_cpu(cpu) {
805 struct nfs_iostats *stats;
806
807 preempt_disable();
808 stats = per_cpu_ptr(nfss->io_stats, cpu);
809
810 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
811 totals.events[i] += stats->events[i];
812 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
813 totals.bytes[i] += stats->bytes[i];
David Howells6a510912009-04-03 16:42:43 +0100814#ifdef CONFIG_NFS_FSCACHE
815 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
816 totals.fscache[i] += stats->fscache[i];
817#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400818
819 preempt_enable();
820 }
821
822 seq_printf(m, "\n\tevents:\t");
823 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
824 seq_printf(m, "%lu ", totals.events[i]);
825 seq_printf(m, "\n\tbytes:\t");
826 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
827 seq_printf(m, "%Lu ", totals.bytes[i]);
David Howells6a510912009-04-03 16:42:43 +0100828#ifdef CONFIG_NFS_FSCACHE
829 if (nfss->options & NFS_OPTION_FSCACHE) {
830 seq_printf(m, "\n\tfsc:\t");
831 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
832 seq_printf(m, "%Lu ", totals.bytes[i]);
833 }
834#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400835 seq_printf(m, "\n");
836
837 rpc_print_iostats(m, nfss->client);
838
839 return 0;
840}
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400841EXPORT_SYMBOL_GPL(nfs_show_stats);
David Howellsf7b422b2006-06-09 09:34:33 -0400842
843/*
844 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400845 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400846 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -0400847void nfs_umount_begin(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -0400848{
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200849 struct nfs_server *server;
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400850 struct rpc_clnt *rpc;
851
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200852 server = NFS_SB(sb);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400853 /* -EIO all pending I/O */
854 rpc = server->client_acl;
855 if (!IS_ERR(rpc))
856 rpc_killall_tasks(rpc);
857 rpc = server->client;
858 if (!IS_ERR(rpc))
859 rpc_killall_tasks(rpc);
David Howellsf7b422b2006-06-09 09:34:33 -0400860}
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400861EXPORT_SYMBOL_GPL(nfs_umount_begin);
David Howellsf7b422b2006-06-09 09:34:33 -0400862
Bryan Schumakerdb833352012-05-10 15:07:38 -0400863static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(void)
Chuck Lever9423a082009-09-23 14:36:38 -0400864{
865 struct nfs_parsed_mount_data *data;
866
867 data = kzalloc(sizeof(*data), GFP_KERNEL);
868 if (data) {
Chuck Lever9423a082009-09-23 14:36:38 -0400869 data->acregmin = NFS_DEF_ACREGMIN;
870 data->acregmax = NFS_DEF_ACREGMAX;
871 data->acdirmin = NFS_DEF_ACDIRMIN;
872 data->acdirmax = NFS_DEF_ACDIRMAX;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400873 data->mount_server.port = NFS_UNSPEC_PORT;
Chuck Lever9423a082009-09-23 14:36:38 -0400874 data->nfs_server.port = NFS_UNSPEC_PORT;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400875 data->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Lever9423a082009-09-23 14:36:38 -0400876 data->auth_flavors[0] = RPC_AUTH_UNIX;
877 data->auth_flavor_len = 1;
878 data->minorversion = 0;
Bryan Schumakerb72e4f42012-05-10 15:07:40 -0400879 data->need_mount = true;
Trond Myklebust9937347a2012-02-19 08:44:07 +0100880 data->net = current->nsproxy->net_ns;
Jeff Layton8a0d5512011-12-20 06:57:45 -0500881 security_init_mnt_opts(&data->lsm_opts);
Chuck Lever9423a082009-09-23 14:36:38 -0400882 }
883 return data;
884}
885
Jeff Layton8a0d5512011-12-20 06:57:45 -0500886static void nfs_free_parsed_mount_data(struct nfs_parsed_mount_data *data)
887{
888 if (data) {
889 kfree(data->client_address);
890 kfree(data->mount_server.hostname);
891 kfree(data->nfs_server.export_path);
892 kfree(data->nfs_server.hostname);
893 kfree(data->fscache_uniq);
894 security_free_mnt_opts(&data->lsm_opts);
895 kfree(data);
896 }
897}
898
David Howellsf7b422b2006-06-09 09:34:33 -0400899/*
Chuck Levercdcd7f92007-12-10 14:57:45 -0500900 * Sanity-check a server address provided by the mount command.
901 *
902 * Address family must be initialized, and address must not be
903 * the ANY address for that family.
Chuck Leverfc50d582007-07-01 12:12:46 -0400904 */
905static int nfs_verify_server_address(struct sockaddr *addr)
906{
907 switch (addr->sa_family) {
908 case AF_INET: {
Chuck Levercdcd7f92007-12-10 14:57:45 -0500909 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
Al Viroe6f1ceb2008-03-17 22:44:53 -0700910 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
Chuck Levercdcd7f92007-12-10 14:57:45 -0500911 }
912 case AF_INET6: {
913 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
914 return !ipv6_addr_any(sa);
Chuck Leverfc50d582007-07-01 12:12:46 -0400915 }
916 }
917
Chuck Lever53a0b9c2009-08-09 15:09:36 -0400918 dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
Chuck Leverfc50d582007-07-01 12:12:46 -0400919 return 0;
920}
921
Chuck Lever9412b922007-12-10 14:59:21 -0500922/*
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400923 * Select between a default port value and a user-specified port value.
924 * If a zero value is set, then autobind will be used.
925 */
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400926static void nfs_set_port(struct sockaddr *sap, int *port,
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400927 const unsigned short default_port)
928{
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400929 if (*port == NFS_UNSPEC_PORT)
930 *port = default_port;
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400931
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400932 rpc_set_port(sap, *port);
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400933}
934
935/*
Trond Myklebust259875e2008-07-02 14:43:47 -0400936 * Sanity check the NFS transport protocol.
937 *
938 */
939static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
940{
941 switch (mnt->nfs_server.protocol) {
942 case XPRT_TRANSPORT_UDP:
943 case XPRT_TRANSPORT_TCP:
944 case XPRT_TRANSPORT_RDMA:
945 break;
946 default:
947 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
948 }
949}
950
951/*
952 * For text based NFSv2/v3 mounts, the mount protocol transport default
953 * settings should depend upon the specified NFS transport.
954 */
955static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
956{
957 nfs_validate_transport_protocol(mnt);
958
959 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
960 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
961 return;
962 switch (mnt->nfs_server.protocol) {
963 case XPRT_TRANSPORT_UDP:
964 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
965 break;
966 case XPRT_TRANSPORT_TCP:
967 case XPRT_TRANSPORT_RDMA:
968 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
969 }
970}
971
972/*
Chuck Lever01060c82008-06-24 16:33:38 -0400973 * Parse the value of the 'sec=' option.
Chuck Lever01060c82008-06-24 16:33:38 -0400974 */
975static int nfs_parse_security_flavors(char *value,
976 struct nfs_parsed_mount_data *mnt)
977{
978 substring_t args[MAX_OPT_ARGS];
979
980 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
981
982 switch (match_token(value, nfs_secflavor_tokens, args)) {
983 case Opt_sec_none:
Chuck Lever01060c82008-06-24 16:33:38 -0400984 mnt->auth_flavors[0] = RPC_AUTH_NULL;
985 break;
986 case Opt_sec_sys:
Chuck Lever01060c82008-06-24 16:33:38 -0400987 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
988 break;
989 case Opt_sec_krb5:
Chuck Lever01060c82008-06-24 16:33:38 -0400990 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
991 break;
992 case Opt_sec_krb5i:
Chuck Lever01060c82008-06-24 16:33:38 -0400993 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
994 break;
995 case Opt_sec_krb5p:
Chuck Lever01060c82008-06-24 16:33:38 -0400996 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
997 break;
998 case Opt_sec_lkey:
Chuck Lever01060c82008-06-24 16:33:38 -0400999 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
1000 break;
1001 case Opt_sec_lkeyi:
Chuck Lever01060c82008-06-24 16:33:38 -04001002 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
1003 break;
1004 case Opt_sec_lkeyp:
Chuck Lever01060c82008-06-24 16:33:38 -04001005 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
1006 break;
1007 case Opt_sec_spkm:
Chuck Lever01060c82008-06-24 16:33:38 -04001008 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
1009 break;
1010 case Opt_sec_spkmi:
Chuck Lever01060c82008-06-24 16:33:38 -04001011 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
1012 break;
1013 case Opt_sec_spkmp:
Chuck Lever01060c82008-06-24 16:33:38 -04001014 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
1015 break;
1016 default:
1017 return 0;
1018 }
1019
Bryan Schumaker9b7160c2011-04-13 14:31:30 -04001020 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
Chuck Lever059f90b2009-08-09 15:09:31 -04001021 mnt->auth_flavor_len = 1;
Chuck Lever01060c82008-06-24 16:33:38 -04001022 return 1;
1023}
1024
Trond Myklebust0d71b052012-03-02 13:59:49 -05001025static int nfs_parse_version_string(char *string,
1026 struct nfs_parsed_mount_data *mnt,
1027 substring_t *args)
1028{
1029 mnt->flags &= ~NFS_MOUNT_VER3;
1030 switch (match_token(string, nfs_vers_tokens, args)) {
1031 case Opt_vers_2:
1032 mnt->version = 2;
1033 break;
1034 case Opt_vers_3:
1035 mnt->flags |= NFS_MOUNT_VER3;
1036 mnt->version = 3;
1037 break;
1038 case Opt_vers_4:
1039 /* Backward compatibility option. In future,
1040 * the mount program should always supply
1041 * a NFSv4 minor version number.
1042 */
1043 mnt->version = 4;
1044 break;
1045 case Opt_vers_4_0:
1046 mnt->version = 4;
1047 mnt->minorversion = 0;
1048 break;
1049 case Opt_vers_4_1:
1050 mnt->version = 4;
1051 mnt->minorversion = 1;
1052 break;
1053 default:
1054 return 0;
1055 }
1056 return 1;
1057}
1058
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001059static int nfs_get_option_str(substring_t args[], char **option)
1060{
1061 kfree(*option);
1062 *option = match_strdup(args);
1063 return !option;
1064}
1065
1066static int nfs_get_option_ul(substring_t args[], unsigned long *option)
1067{
1068 int rc;
1069 char *string;
1070
1071 string = match_strdup(args);
1072 if (string == NULL)
1073 return -ENOMEM;
1074 rc = strict_strtoul(string, 10, option);
1075 kfree(string);
1076
1077 return rc;
1078}
1079
Chuck Lever01060c82008-06-24 16:33:38 -04001080/*
Chuck Leverbf0fd762007-07-01 12:13:44 -04001081 * Error-check and convert a string of mount options from user space into
Chuck Leverf45663c2008-06-24 19:28:02 -04001082 * a data structure. The whole mount string is processed; bad options are
1083 * skipped as they are encountered. If there were no errors, return 1;
1084 * otherwise return 0 (zero).
Chuck Leverbf0fd762007-07-01 12:13:44 -04001085 */
1086static int nfs_parse_mount_options(char *raw,
1087 struct nfs_parsed_mount_data *mnt)
1088{
Eric Parisf9c3a382008-03-05 14:20:18 -05001089 char *p, *string, *secdata;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001090 int rc, sloppy = 0, invalid_option = 0;
Jeff Laytonee671b02009-12-03 15:58:56 -05001091 unsigned short protofamily = AF_UNSPEC;
1092 unsigned short mountfamily = AF_UNSPEC;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001093
1094 if (!raw) {
1095 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
1096 return 1;
1097 }
1098 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
1099
Eric Parisf9c3a382008-03-05 14:20:18 -05001100 secdata = alloc_secdata();
1101 if (!secdata)
1102 goto out_nomem;
1103
1104 rc = security_sb_copy_data(raw, secdata);
1105 if (rc)
1106 goto out_security_failure;
1107
1108 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
1109 if (rc)
1110 goto out_security_failure;
1111
1112 free_secdata(secdata);
1113
Chuck Leverbf0fd762007-07-01 12:13:44 -04001114 while ((p = strsep(&raw, ",")) != NULL) {
1115 substring_t args[MAX_OPT_ARGS];
Chuck Levera5a16ba2009-06-17 18:02:14 -07001116 unsigned long option;
1117 int token;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001118
1119 if (!*p)
1120 continue;
1121
1122 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
1123
1124 token = match_token(p, nfs_mount_option_tokens, args);
1125 switch (token) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001126
1127 /*
1128 * boolean options: foo/nofoo
1129 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001130 case Opt_soft:
1131 mnt->flags |= NFS_MOUNT_SOFT;
1132 break;
1133 case Opt_hard:
1134 mnt->flags &= ~NFS_MOUNT_SOFT;
1135 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001136 case Opt_posix:
1137 mnt->flags |= NFS_MOUNT_POSIX;
1138 break;
1139 case Opt_noposix:
1140 mnt->flags &= ~NFS_MOUNT_POSIX;
1141 break;
1142 case Opt_cto:
1143 mnt->flags &= ~NFS_MOUNT_NOCTO;
1144 break;
1145 case Opt_nocto:
1146 mnt->flags |= NFS_MOUNT_NOCTO;
1147 break;
1148 case Opt_ac:
1149 mnt->flags &= ~NFS_MOUNT_NOAC;
1150 break;
1151 case Opt_noac:
1152 mnt->flags |= NFS_MOUNT_NOAC;
1153 break;
1154 case Opt_lock:
1155 mnt->flags &= ~NFS_MOUNT_NONLM;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001156 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1157 NFS_MOUNT_LOCAL_FCNTL);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001158 break;
1159 case Opt_nolock:
1160 mnt->flags |= NFS_MOUNT_NONLM;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001161 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1162 NFS_MOUNT_LOCAL_FCNTL);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001163 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001164 case Opt_udp:
1165 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001166 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001167 break;
1168 case Opt_tcp:
1169 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001170 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001171 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001172 case Opt_rdma:
1173 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1174 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001175 xprt_load_transport(p);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001176 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001177 case Opt_acl:
1178 mnt->flags &= ~NFS_MOUNT_NOACL;
1179 break;
1180 case Opt_noacl:
1181 mnt->flags |= NFS_MOUNT_NOACL;
1182 break;
1183 case Opt_rdirplus:
1184 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1185 break;
1186 case Opt_nordirplus:
1187 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1188 break;
Trond Myklebust75180df2007-05-16 16:53:28 -04001189 case Opt_sharecache:
1190 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1191 break;
1192 case Opt_nosharecache:
1193 mnt->flags |= NFS_MOUNT_UNSHARED;
1194 break;
Chuck Leverd7403512008-12-23 15:21:37 -05001195 case Opt_resvport:
1196 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1197 break;
1198 case Opt_noresvport:
1199 mnt->flags |= NFS_MOUNT_NORESVPORT;
1200 break;
David Howellsb797cac2009-04-03 16:42:48 +01001201 case Opt_fscache:
1202 mnt->options |= NFS_OPTION_FSCACHE;
1203 kfree(mnt->fscache_uniq);
1204 mnt->fscache_uniq = NULL;
1205 break;
1206 case Opt_nofscache:
1207 mnt->options &= ~NFS_OPTION_FSCACHE;
1208 kfree(mnt->fscache_uniq);
1209 mnt->fscache_uniq = NULL;
1210 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001211
Chuck Leverf45663c2008-06-24 19:28:02 -04001212 /*
1213 * options that take numeric values
1214 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001215 case Opt_port:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001216 if (nfs_get_option_ul(args, &option) ||
1217 option > USHRT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001218 goto out_invalid_value;
1219 mnt->nfs_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001220 break;
1221 case Opt_rsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001222 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001223 goto out_invalid_value;
1224 mnt->rsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001225 break;
1226 case Opt_wsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001227 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001228 goto out_invalid_value;
1229 mnt->wsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001230 break;
1231 case Opt_bsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001232 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001233 goto out_invalid_value;
1234 mnt->bsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001235 break;
1236 case Opt_timeo:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001237 if (nfs_get_option_ul(args, &option) || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001238 goto out_invalid_value;
1239 mnt->timeo = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001240 break;
1241 case Opt_retrans:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001242 if (nfs_get_option_ul(args, &option) || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001243 goto out_invalid_value;
1244 mnt->retrans = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001245 break;
1246 case Opt_acregmin:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001247 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001248 goto out_invalid_value;
1249 mnt->acregmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001250 break;
1251 case Opt_acregmax:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001252 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001253 goto out_invalid_value;
1254 mnt->acregmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001255 break;
1256 case Opt_acdirmin:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001257 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001258 goto out_invalid_value;
1259 mnt->acdirmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001260 break;
1261 case Opt_acdirmax:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001262 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001263 goto out_invalid_value;
1264 mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001265 break;
1266 case Opt_actimeo:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001267 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001268 goto out_invalid_value;
1269 mnt->acregmin = mnt->acregmax =
1270 mnt->acdirmin = mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001271 break;
1272 case Opt_namelen:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001273 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001274 goto out_invalid_value;
1275 mnt->namlen = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001276 break;
1277 case Opt_mountport:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001278 if (nfs_get_option_ul(args, &option) ||
1279 option > USHRT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001280 goto out_invalid_value;
1281 mnt->mount_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001282 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001283 case Opt_mountvers:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001284 if (nfs_get_option_ul(args, &option) ||
Chuck Leverf45663c2008-06-24 19:28:02 -04001285 option < NFS_MNT_VERSION ||
Chuck Leverd23c45f2009-06-17 18:02:13 -07001286 option > NFS_MNT3_VERSION)
1287 goto out_invalid_value;
1288 mnt->mount_server.version = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001289 break;
Mike Sager3fd5be92009-04-01 09:21:48 -04001290 case Opt_minorversion:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001291 if (nfs_get_option_ul(args, &option))
Chuck Leverf3f4f4e2009-08-09 15:09:29 -04001292 goto out_invalid_value;
1293 if (option > NFS4_MAX_MINOR_VERSION)
1294 goto out_invalid_value;
1295 mnt->minorversion = option;
Mike Sager3fd5be92009-04-01 09:21:48 -04001296 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001297
Chuck Leverf45663c2008-06-24 19:28:02 -04001298 /*
1299 * options that take text values
1300 */
Trond Myklebust0d71b052012-03-02 13:59:49 -05001301 case Opt_nfsvers:
1302 string = match_strdup(args);
1303 if (string == NULL)
1304 goto out_nomem;
1305 rc = nfs_parse_version_string(string, mnt, args);
1306 kfree(string);
1307 if (!rc)
1308 goto out_invalid_value;
1309 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001310 case Opt_sec:
1311 string = match_strdup(args);
1312 if (string == NULL)
1313 goto out_nomem;
Chuck Lever01060c82008-06-24 16:33:38 -04001314 rc = nfs_parse_security_flavors(string, mnt);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001315 kfree(string);
Chuck Leverf45663c2008-06-24 19:28:02 -04001316 if (!rc) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001317 dfprintk(MOUNT, "NFS: unrecognized "
1318 "security flavor\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001319 return 0;
Chuck Leverf45663c2008-06-24 19:28:02 -04001320 }
Chuck Leverbf0fd762007-07-01 12:13:44 -04001321 break;
1322 case Opt_proto:
1323 string = match_strdup(args);
1324 if (string == NULL)
1325 goto out_nomem;
1326 token = match_token(string,
1327 nfs_xprt_protocol_tokens, args);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001328
Jeff Laytonee671b02009-12-03 15:58:56 -05001329 protofamily = AF_INET;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001330 switch (token) {
Jeff Laytonee671b02009-12-03 15:58:56 -05001331 case Opt_xprt_udp6:
1332 protofamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001333 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001334 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001335 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001336 break;
Jeff Laytonee671b02009-12-03 15:58:56 -05001337 case Opt_xprt_tcp6:
1338 protofamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001339 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001340 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001341 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001342 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001343 case Opt_xprt_rdma:
1344 /* vector side protocols to TCP */
1345 mnt->flags |= NFS_MOUNT_TCP;
1346 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001347 xprt_load_transport(string);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001348 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001349 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001350 dfprintk(MOUNT, "NFS: unrecognized "
1351 "transport protocol\n");
Yinghai Lu4223a4a2009-10-20 14:13:46 +09001352 kfree(string);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001353 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001354 }
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001355 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001356 break;
1357 case Opt_mountproto:
1358 string = match_strdup(args);
1359 if (string == NULL)
1360 goto out_nomem;
1361 token = match_token(string,
1362 nfs_xprt_protocol_tokens, args);
Trond Myklebustd508afb2009-04-06 16:41:35 -07001363 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001364
Jeff Laytonee671b02009-12-03 15:58:56 -05001365 mountfamily = AF_INET;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001366 switch (token) {
Jeff Laytonee671b02009-12-03 15:58:56 -05001367 case Opt_xprt_udp6:
1368 mountfamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001369 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001370 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001371 break;
Jeff Laytonee671b02009-12-03 15:58:56 -05001372 case Opt_xprt_tcp6:
1373 mountfamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001374 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001375 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001376 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001377 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001378 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001379 dfprintk(MOUNT, "NFS: unrecognized "
1380 "transport protocol\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001381 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001382 }
1383 break;
1384 case Opt_addr:
1385 string = match_strdup(args);
1386 if (string == NULL)
1387 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001388 mnt->nfs_server.addrlen =
Stanislav Kinsburskyb48e1272012-01-26 15:11:57 +04001389 rpc_pton(mnt->net, string, strlen(string),
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001390 (struct sockaddr *)
1391 &mnt->nfs_server.address,
1392 sizeof(mnt->nfs_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001393 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001394 if (mnt->nfs_server.addrlen == 0)
1395 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001396 break;
1397 case Opt_clientaddr:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001398 if (nfs_get_option_str(args, &mnt->client_address))
Chuck Leverbf0fd762007-07-01 12:13:44 -04001399 goto out_nomem;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001400 break;
Chuck Lever33832032007-12-10 14:59:13 -05001401 case Opt_mounthost:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001402 if (nfs_get_option_str(args,
1403 &mnt->mount_server.hostname))
Chuck Lever33832032007-12-10 14:59:13 -05001404 goto out_nomem;
Chuck Lever33832032007-12-10 14:59:13 -05001405 break;
Chuck Lever0ac83772007-09-11 18:01:04 -04001406 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001407 string = match_strdup(args);
1408 if (string == NULL)
1409 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001410 mnt->mount_server.addrlen =
Stanislav Kinsburskyb48e1272012-01-26 15:11:57 +04001411 rpc_pton(mnt->net, string, strlen(string),
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001412 (struct sockaddr *)
1413 &mnt->mount_server.address,
1414 sizeof(mnt->mount_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001415 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001416 if (mnt->mount_server.addrlen == 0)
1417 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001418 break;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001419 case Opt_lookupcache:
1420 string = match_strdup(args);
1421 if (string == NULL)
1422 goto out_nomem;
1423 token = match_token(string,
1424 nfs_lookupcache_tokens, args);
1425 kfree(string);
1426 switch (token) {
1427 case Opt_lookupcache_all:
1428 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1429 break;
1430 case Opt_lookupcache_positive:
1431 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1432 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1433 break;
1434 case Opt_lookupcache_none:
1435 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1436 break;
1437 default:
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001438 dfprintk(MOUNT, "NFS: invalid "
1439 "lookupcache argument\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001440 return 0;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001441 };
1442 break;
Chuck Levera6d5ff62010-05-07 13:33:58 -04001443 case Opt_fscache_uniq:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001444 if (nfs_get_option_str(args, &mnt->fscache_uniq))
Chuck Levera6d5ff62010-05-07 13:33:58 -04001445 goto out_nomem;
Chuck Levera6d5ff62010-05-07 13:33:58 -04001446 mnt->options |= NFS_OPTION_FSCACHE;
1447 break;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001448 case Opt_local_lock:
1449 string = match_strdup(args);
1450 if (string == NULL)
1451 goto out_nomem;
1452 token = match_token(string, nfs_local_lock_tokens,
1453 args);
1454 kfree(string);
1455 switch (token) {
1456 case Opt_local_lock_all:
1457 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1458 NFS_MOUNT_LOCAL_FCNTL);
1459 break;
1460 case Opt_local_lock_flock:
1461 mnt->flags |= NFS_MOUNT_LOCAL_FLOCK;
1462 break;
1463 case Opt_local_lock_posix:
1464 mnt->flags |= NFS_MOUNT_LOCAL_FCNTL;
1465 break;
1466 case Opt_local_lock_none:
1467 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1468 NFS_MOUNT_LOCAL_FCNTL);
1469 break;
1470 default:
1471 dfprintk(MOUNT, "NFS: invalid "
1472 "local_lock argument\n");
1473 return 0;
1474 };
1475 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001476
Chuck Leverf45663c2008-06-24 19:28:02 -04001477 /*
1478 * Special options
1479 */
1480 case Opt_sloppy:
1481 sloppy = 1;
1482 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1483 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001484 case Opt_userspace:
1485 case Opt_deprecated:
Chuck Leverd33e4df2008-06-12 12:37:41 -04001486 dfprintk(MOUNT, "NFS: ignoring mount option "
1487 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001488 break;
1489
1490 default:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001491 invalid_option = 1;
Chuck Leverf45663c2008-06-24 19:28:02 -04001492 dfprintk(MOUNT, "NFS: unrecognized mount option "
1493 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001494 }
1495 }
1496
Chuck Leverd23c45f2009-06-17 18:02:13 -07001497 if (!sloppy && invalid_option)
1498 return 0;
1499
Weston Andros Adamson571b7552012-02-01 14:06:41 -05001500 if (mnt->minorversion && mnt->version != 4)
1501 goto out_minorversion_mismatch;
1502
Jeff Laytonee671b02009-12-03 15:58:56 -05001503 /*
1504 * verify that any proto=/mountproto= options match the address
1505 * familiies in the addr=/mountaddr= options.
1506 */
1507 if (protofamily != AF_UNSPEC &&
1508 protofamily != mnt->nfs_server.address.ss_family)
1509 goto out_proto_mismatch;
1510
1511 if (mountfamily != AF_UNSPEC) {
1512 if (mnt->mount_server.addrlen) {
1513 if (mountfamily != mnt->mount_server.address.ss_family)
1514 goto out_mountproto_mismatch;
1515 } else {
1516 if (mountfamily != mnt->nfs_server.address.ss_family)
1517 goto out_mountproto_mismatch;
1518 }
1519 }
1520
Chuck Leverbf0fd762007-07-01 12:13:44 -04001521 return 1;
1522
Jeff Laytonee671b02009-12-03 15:58:56 -05001523out_mountproto_mismatch:
1524 printk(KERN_INFO "NFS: mount server address does not match mountproto= "
1525 "option\n");
1526 return 0;
1527out_proto_mismatch:
1528 printk(KERN_INFO "NFS: server address does not match proto= option\n");
1529 return 0;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001530out_invalid_address:
1531 printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
1532 return 0;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001533out_invalid_value:
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001534 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001535 return 0;
Weston Andros Adamson571b7552012-02-01 14:06:41 -05001536out_minorversion_mismatch:
1537 printk(KERN_INFO "NFS: mount option vers=%u does not support "
1538 "minorversion=%u\n", mnt->version, mnt->minorversion);
1539 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001540out_nomem:
1541 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1542 return 0;
Eric Parisf9c3a382008-03-05 14:20:18 -05001543out_security_failure:
1544 free_secdata(secdata);
1545 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1546 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001547}
1548
1549/*
Chuck Leverec88f282009-08-09 15:09:32 -04001550 * Match the requested auth flavors with the list returned by
1551 * the server. Returns zero and sets the mount's authentication
1552 * flavor on success; returns -EACCES if server does not support
1553 * the requested flavor.
1554 */
1555static int nfs_walk_authlist(struct nfs_parsed_mount_data *args,
1556 struct nfs_mount_request *request)
1557{
1558 unsigned int i, j, server_authlist_len = *(request->auth_flav_len);
1559
1560 /*
Chuck Lever5eecfde2009-08-21 17:50:30 -04001561 * Certain releases of Linux's mountd return an empty
1562 * flavor list. To prevent behavioral regression with
1563 * these servers (ie. rejecting mounts that used to
1564 * succeed), revert to pre-2.6.32 behavior (no checking)
1565 * if the returned flavor list is empty.
1566 */
1567 if (server_authlist_len == 0)
1568 return 0;
1569
1570 /*
Chuck Leverec88f282009-08-09 15:09:32 -04001571 * We avoid sophisticated negotiating here, as there are
1572 * plenty of cases where we can get it wrong, providing
1573 * either too little or too much security.
1574 *
1575 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1576 * flavor listed first. However, some servers list
1577 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1578 * preferred default, in args->auth_flavors[0] if user
1579 * didn't specify sec= mount option.
1580 */
1581 for (i = 0; i < args->auth_flavor_len; i++)
1582 for (j = 0; j < server_authlist_len; j++)
1583 if (args->auth_flavors[i] == request->auth_flavs[j]) {
1584 dfprintk(MOUNT, "NFS: using auth flavor %d\n",
1585 request->auth_flavs[j]);
1586 args->auth_flavors[0] = request->auth_flavs[j];
1587 return 0;
1588 }
1589
1590 dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n");
1591 nfs_umount(request);
1592 return -EACCES;
1593}
1594
1595/*
Chuck Lever0076d7b2007-07-01 12:13:49 -04001596 * Use the remote server's MOUNT service to request the NFS file handle
1597 * corresponding to the provided path.
1598 */
Bryan Schumaker486aa692012-05-10 15:07:39 -04001599static int nfs_request_mount(struct nfs_parsed_mount_data *args,
1600 struct nfs_fh *root_fh)
Chuck Lever0076d7b2007-07-01 12:13:49 -04001601{
Chuck Leverec88f282009-08-09 15:09:32 -04001602 rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS];
1603 unsigned int server_authlist_len = ARRAY_SIZE(server_authlist);
Chuck Leverc5d120f2008-12-23 15:21:35 -05001604 struct nfs_mount_request request = {
1605 .sap = (struct sockaddr *)
1606 &args->mount_server.address,
1607 .dirpath = args->nfs_server.export_path,
1608 .protocol = args->mount_server.protocol,
1609 .fh = root_fh,
Chuck Lever50a737f2008-12-23 15:21:37 -05001610 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
Chuck Leverec88f282009-08-09 15:09:32 -04001611 .auth_flav_len = &server_authlist_len,
1612 .auth_flavs = server_authlist,
Stanislav Kinsbursky6d59b8d2012-01-10 16:12:54 +04001613 .net = args->net,
Chuck Leverc5d120f2008-12-23 15:21:35 -05001614 };
Chuck Lever4c568012007-12-10 14:59:28 -05001615 int status;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001616
1617 if (args->mount_server.version == 0) {
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001618 switch (args->version) {
1619 default:
1620 args->mount_server.version = NFS_MNT3_VERSION;
1621 break;
1622 case 2:
1623 args->mount_server.version = NFS_MNT_VERSION;
1624 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001625 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001626 request.version = args->mount_server.version;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001627
Chuck Lever33832032007-12-10 14:59:13 -05001628 if (args->mount_server.hostname)
Chuck Leverc5d120f2008-12-23 15:21:35 -05001629 request.hostname = args->mount_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001630 else
Chuck Leverc5d120f2008-12-23 15:21:35 -05001631 request.hostname = args->nfs_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001632
Chuck Lever0076d7b2007-07-01 12:13:49 -04001633 /*
1634 * Construct the mount server's address.
1635 */
Chuck Lever4c568012007-12-10 14:59:28 -05001636 if (args->mount_server.address.ss_family == AF_UNSPEC) {
Chuck Leverc5d120f2008-12-23 15:21:35 -05001637 memcpy(request.sap, &args->nfs_server.address,
Chuck Lever4c568012007-12-10 14:59:28 -05001638 args->nfs_server.addrlen);
1639 args->mount_server.addrlen = args->nfs_server.addrlen;
1640 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001641 request.salen = args->mount_server.addrlen;
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001642 nfs_set_port(request.sap, &args->mount_server.port, 0);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001643
1644 /*
1645 * Now ask the mount server to map our export path
1646 * to a file handle.
1647 */
Chuck Leverc5d120f2008-12-23 15:21:35 -05001648 status = nfs_mount(&request);
Chuck Leverec88f282009-08-09 15:09:32 -04001649 if (status != 0) {
1650 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1651 request.hostname, status);
1652 return status;
1653 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001654
Chuck Leverec88f282009-08-09 15:09:32 -04001655 /*
1656 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1657 */
1658 if (args->mount_server.version != NFS_MNT3_VERSION)
1659 return 0;
1660 return nfs_walk_authlist(args, &request);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001661}
1662
Bryan Schumakerff9099f22012-07-30 16:05:18 -04001663struct dentry *nfs_try_mount(int flags, const char *dev_name,
1664 struct nfs_mount_info *mount_info,
1665 struct nfs_subversion *nfs_mod)
Bryan Schumaker486aa692012-05-10 15:07:39 -04001666{
1667 int status;
1668 struct nfs_server *server;
1669
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04001670 if (mount_info->parsed->need_mount) {
Bryan Schumaker87c70832012-05-10 15:07:43 -04001671 status = nfs_request_mount(mount_info->parsed, mount_info->mntfh);
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04001672 if (status)
1673 return ERR_PTR(status);
1674 }
Bryan Schumaker486aa692012-05-10 15:07:39 -04001675
1676 /* Get a volume representation */
Bryan Schumaker1179acc2012-07-30 16:05:19 -04001677 server = nfs_mod->rpc_ops->create_server(mount_info, nfs_mod);
Bryan Schumaker486aa692012-05-10 15:07:39 -04001678 if (IS_ERR(server))
1679 return ERR_CAST(server);
1680
Bryan Schumakerab7017a2012-07-30 16:05:16 -04001681 return nfs_fs_mount_common(server, flags, dev_name, mount_info, nfs_mod);
Bryan Schumaker486aa692012-05-10 15:07:39 -04001682}
Bryan Schumakerddda8e02012-07-30 16:05:23 -04001683EXPORT_SYMBOL_GPL(nfs_try_mount);
Bryan Schumaker486aa692012-05-10 15:07:39 -04001684
Rob Landleyc12bace2011-03-09 15:54:13 -06001685/*
1686 * Split "dev_name" into "hostname:export_path".
1687 *
1688 * The leftmost colon demarks the split between the server's hostname
1689 * and the export path. If the hostname starts with a left square
1690 * bracket, then it may contain colons.
1691 *
1692 * Note: caller frees hostname and export path, even on error.
1693 */
1694static int nfs_parse_devname(const char *dev_name,
1695 char **hostname, size_t maxnamlen,
1696 char **export_path, size_t maxpathlen)
Chuck Leverdc045892008-06-23 12:36:37 -04001697{
1698 size_t len;
Rob Landleyc12bace2011-03-09 15:54:13 -06001699 char *end;
Chuck Leverdc045892008-06-23 12:36:37 -04001700
Rob Landleyc12bace2011-03-09 15:54:13 -06001701 /* Is the host name protected with square brakcets? */
1702 if (*dev_name == '[') {
1703 end = strchr(++dev_name, ']');
1704 if (end == NULL || end[1] != ':')
1705 goto out_bad_devname;
Chuck Leverdc045892008-06-23 12:36:37 -04001706
Rob Landleyc12bace2011-03-09 15:54:13 -06001707 len = end - dev_name;
1708 end++;
1709 } else {
1710 char *comma;
1711
1712 end = strchr(dev_name, ':');
1713 if (end == NULL)
1714 goto out_bad_devname;
1715 len = end - dev_name;
1716
1717 /* kill possible hostname list: not supported */
1718 comma = strchr(dev_name, ',');
1719 if (comma != NULL && comma < end)
1720 *comma = 0;
1721 }
1722
Chuck Leverdc045892008-06-23 12:36:37 -04001723 if (len > maxnamlen)
1724 goto out_hostname;
1725
1726 /* N.B. caller will free nfs_server.hostname in all cases */
1727 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
Rob Landleyc12bace2011-03-09 15:54:13 -06001728 if (*hostname == NULL)
Chuck Leverdc045892008-06-23 12:36:37 -04001729 goto out_nomem;
Rob Landleyc12bace2011-03-09 15:54:13 -06001730 len = strlen(++end);
Chuck Leverdc045892008-06-23 12:36:37 -04001731 if (len > maxpathlen)
1732 goto out_path;
Rob Landleyc12bace2011-03-09 15:54:13 -06001733 *export_path = kstrndup(end, len, GFP_KERNEL);
Chuck Leverdc045892008-06-23 12:36:37 -04001734 if (!*export_path)
1735 goto out_nomem;
1736
1737 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1738 return 0;
1739
1740out_bad_devname:
1741 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1742 return -EINVAL;
1743
1744out_nomem:
1745 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1746 return -ENOMEM;
1747
1748out_hostname:
1749 dfprintk(MOUNT, "NFS: server hostname too long\n");
1750 return -ENAMETOOLONG;
1751
1752out_path:
1753 dfprintk(MOUNT, "NFS: export pathname too long\n");
1754 return -ENAMETOOLONG;
1755}
1756
1757/*
David Howells54ceac42006-08-22 20:06:13 -04001758 * Validate the NFS2/NFS3 mount data
1759 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001760 *
1761 * For option strings, user space handles the following behaviors:
1762 *
1763 * + DNS: mapping server host name to IP address ("addr=" option)
1764 *
1765 * + failure mode: how to behave if a mount request can't be handled
1766 * immediately ("fg/bg" option)
1767 *
1768 * + retry: how often to retry a mount request ("retry=" option)
1769 *
1770 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1771 * mountproto=tcp after mountproto=udp, and so on
David Howellsf7b422b2006-06-09 09:34:33 -04001772 */
Bryan Schumakerd72c7272012-05-10 15:07:41 -04001773static int nfs23_validate_mount_data(void *options,
1774 struct nfs_parsed_mount_data *args,
1775 struct nfs_fh *mntfh,
1776 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001777{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001778 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001779 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
Chuck Lever136d5582007-07-01 12:13:54 -04001780
Chuck Lever5df36e72007-07-01 12:12:56 -04001781 if (data == NULL)
1782 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001783
Bryan Schumakerc5afc8d2012-06-08 11:32:56 -04001784 args->version = NFS_DEFAULT_VERSION;
David Howellsf7b422b2006-06-09 09:34:33 -04001785 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001786 case 1:
1787 data->namlen = 0;
1788 case 2:
1789 data->bsize = 0;
1790 case 3:
1791 if (data->flags & NFS_MOUNT_VER3)
1792 goto out_no_v3;
1793 data->root.size = NFS2_FHSIZE;
1794 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1795 case 4:
1796 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1797 goto out_no_sec;
1798 case 5:
1799 memset(data->context, 0, sizeof(data->context));
1800 case 6:
Trond Myklebustb7e24452008-06-19 15:21:11 -04001801 if (data->flags & NFS_MOUNT_VER3) {
1802 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1803 goto out_invalid_fh;
Chuck Lever5df36e72007-07-01 12:12:56 -04001804 mntfh->size = data->root.size;
Chuck Lever764302c2009-09-08 19:50:03 -04001805 args->version = 3;
1806 } else {
Chuck Lever5df36e72007-07-01 12:12:56 -04001807 mntfh->size = NFS2_FHSIZE;
Chuck Lever764302c2009-09-08 19:50:03 -04001808 args->version = 2;
1809 }
Chuck Lever5df36e72007-07-01 12:12:56 -04001810
Chuck Lever5df36e72007-07-01 12:12:56 -04001811
1812 memcpy(mntfh->data, data->root.data, mntfh->size);
1813 if (mntfh->size < sizeof(mntfh->data))
1814 memset(mntfh->data + mntfh->size, 0,
1815 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001816
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001817 /*
1818 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1819 * can deal with.
1820 */
Trond Myklebustff3525a2008-08-15 16:59:14 -04001821 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
Bryan Schumakerd5eff1a2010-08-03 13:04:00 -04001822 args->flags |= NFS_MOUNT_LEGACY_INTERFACE;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001823 args->rsize = data->rsize;
1824 args->wsize = data->wsize;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001825 args->timeo = data->timeo;
1826 args->retrans = data->retrans;
1827 args->acregmin = data->acregmin;
1828 args->acregmax = data->acregmax;
1829 args->acdirmin = data->acdirmin;
1830 args->acdirmax = data->acdirmax;
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04001831 args->need_mount = false;
Chuck Lever4c568012007-12-10 14:59:28 -05001832
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001833 memcpy(sap, &data->addr, sizeof(data->addr));
Chuck Lever4c568012007-12-10 14:59:28 -05001834 args->nfs_server.addrlen = sizeof(data->addr);
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001835 if (!nfs_verify_server_address(sap))
Chuck Lever4c568012007-12-10 14:59:28 -05001836 goto out_no_address;
1837
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001838 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001839 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001840 /* N.B. caller will free nfs_server.hostname in all cases */
1841 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1842 args->namlen = data->namlen;
1843 args->bsize = data->bsize;
Chuck Leverdd07c942008-06-24 16:33:46 -04001844
1845 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1846 args->auth_flavors[0] = data->pseudoflavor;
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001847 if (!args->nfs_server.hostname)
1848 goto out_nomem;
Eric Parisf9c3a382008-03-05 14:20:18 -05001849
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001850 if (!(data->flags & NFS_MOUNT_NONLM))
1851 args->flags &= ~(NFS_MOUNT_LOCAL_FLOCK|
1852 NFS_MOUNT_LOCAL_FCNTL);
1853 else
1854 args->flags |= (NFS_MOUNT_LOCAL_FLOCK|
1855 NFS_MOUNT_LOCAL_FCNTL);
Eric Parisf9c3a382008-03-05 14:20:18 -05001856 /*
1857 * The legacy version 6 binary mount data from userspace has a
1858 * field used only to transport selinux information into the
1859 * the kernel. To continue to support that functionality we
1860 * have a touch of selinux knowledge here in the NFS code. The
1861 * userspace code converted context=blah to just blah so we are
1862 * converting back to the full string selinux understands.
1863 */
1864 if (data->context[0]){
1865#ifdef CONFIG_SECURITY_SELINUX
1866 int rc;
1867 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1868 if (!opts_str)
1869 return -ENOMEM;
1870 strcpy(opts_str, "context=");
1871 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1872 strcat(opts_str, &data->context[0]);
1873 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1874 kfree(opts_str);
1875 if (rc)
1876 return rc;
1877#else
1878 return -EINVAL;
1879#endif
1880 }
1881
Chuck Lever5df36e72007-07-01 12:12:56 -04001882 break;
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04001883 default:
1884 return NFS_TEXT_DATA;
David Howellsf7b422b2006-06-09 09:34:33 -04001885 }
David Howells54ceac42006-08-22 20:06:13 -04001886
Bryan Schumaker1c606fb2012-07-30 16:05:24 -04001887#if !IS_ENABLED(CONFIG_NFS_V3)
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001888 if (args->version == 3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001889 goto out_v3_not_compiled;
1890#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001891
David Howells54ceac42006-08-22 20:06:13 -04001892 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001893
1894out_no_data:
1895 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1896 return -EINVAL;
1897
1898out_no_v3:
1899 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1900 data->version);
1901 return -EINVAL;
1902
1903out_no_sec:
1904 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1905 return -EINVAL;
1906
Bryan Schumaker1c606fb2012-07-30 16:05:24 -04001907#if !IS_ENABLED(CONFIG_NFS_V3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001908out_v3_not_compiled:
1909 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1910 return -EPROTONOSUPPORT;
1911#endif /* !CONFIG_NFS_V3 */
1912
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001913out_nomem:
1914 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
1915 return -ENOMEM;
1916
Chuck Lever5df36e72007-07-01 12:12:56 -04001917out_no_address:
1918 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1919 return -EINVAL;
1920
1921out_invalid_fh:
1922 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1923 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04001924}
1925
Bryan Schumaker89d77c82012-07-30 16:05:25 -04001926#if IS_ENABLED(CONFIG_NFS_V4)
Bryan Schumakerd72c7272012-05-10 15:07:41 -04001927static int nfs_validate_mount_data(struct file_system_type *fs_type,
1928 void *options,
1929 struct nfs_parsed_mount_data *args,
1930 struct nfs_fh *mntfh,
1931 const char *dev_name)
1932{
1933 if (fs_type == &nfs_fs_type)
1934 return nfs23_validate_mount_data(options, args, mntfh, dev_name);
1935 return nfs4_validate_mount_data(options, args, dev_name);
1936}
1937#else
1938static int nfs_validate_mount_data(struct file_system_type *fs_type,
1939 void *options,
1940 struct nfs_parsed_mount_data *args,
1941 struct nfs_fh *mntfh,
1942 const char *dev_name)
1943{
1944 return nfs23_validate_mount_data(options, args, mntfh, dev_name);
1945}
1946#endif
1947
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04001948static int nfs_validate_text_mount_data(void *options,
1949 struct nfs_parsed_mount_data *args,
1950 const char *dev_name)
1951{
1952 int port = 0;
1953 int max_namelen = PAGE_SIZE;
1954 int max_pathlen = NFS_MAXPATHLEN;
1955 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
1956
1957 if (nfs_parse_mount_options((char *)options, args) == 0)
1958 return -EINVAL;
1959
1960 if (!nfs_verify_server_address(sap))
1961 goto out_no_address;
1962
1963 if (args->version == 4) {
Bryan Schumaker89d77c82012-07-30 16:05:25 -04001964#if IS_ENABLED(CONFIG_NFS_V4)
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04001965 port = NFS_PORT;
1966 max_namelen = NFS4_MAXNAMLEN;
1967 max_pathlen = NFS4_MAXPATHLEN;
1968 nfs_validate_transport_protocol(args);
1969 nfs4_validate_mount_flags(args);
1970#else
1971 goto out_v4_not_compiled;
1972#endif /* CONFIG_NFS_V4 */
1973 } else
1974 nfs_set_mount_transport_protocol(args);
1975
1976 nfs_set_port(sap, &args->nfs_server.port, port);
1977
1978 if (args->auth_flavor_len > 1)
1979 goto out_bad_auth;
1980
1981 return nfs_parse_devname(dev_name,
1982 &args->nfs_server.hostname,
1983 max_namelen,
1984 &args->nfs_server.export_path,
1985 max_pathlen);
1986
Bryan Schumaker89d77c82012-07-30 16:05:25 -04001987#if !IS_ENABLED(CONFIG_NFS_V4)
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04001988out_v4_not_compiled:
1989 dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n");
1990 return -EPROTONOSUPPORT;
1991#endif /* !CONFIG_NFS_V4 */
1992
1993out_no_address:
1994 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1995 return -EINVAL;
1996
1997out_bad_auth:
1998 dfprintk(MOUNT, "NFS: Too many RPC auth flavours specified\n");
1999 return -EINVAL;
2000}
2001
Jeff Layton48b605f2008-06-10 15:38:39 -04002002static int
2003nfs_compare_remount_data(struct nfs_server *nfss,
2004 struct nfs_parsed_mount_data *data)
2005{
2006 if (data->flags != nfss->flags ||
2007 data->rsize != nfss->rsize ||
2008 data->wsize != nfss->wsize ||
2009 data->retrans != nfss->client->cl_timeout->to_retries ||
2010 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
2011 data->acregmin != nfss->acregmin / HZ ||
2012 data->acregmax != nfss->acregmax / HZ ||
2013 data->acdirmin != nfss->acdirmin / HZ ||
2014 data->acdirmax != nfss->acdirmax / HZ ||
2015 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
Trond Myklebustbcd2ea12009-10-06 15:41:22 -04002016 data->nfs_server.port != nfss->port ||
Jeff Layton48b605f2008-06-10 15:38:39 -04002017 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
Stefan Richtera1be9ee2009-10-12 11:26:12 -04002018 !rpc_cmp_addr((struct sockaddr *)&data->nfs_server.address,
2019 (struct sockaddr *)&nfss->nfs_client->cl_addr))
Jeff Layton48b605f2008-06-10 15:38:39 -04002020 return -EINVAL;
2021
2022 return 0;
2023}
2024
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002025int
Jeff Layton48b605f2008-06-10 15:38:39 -04002026nfs_remount(struct super_block *sb, int *flags, char *raw_data)
2027{
2028 int error;
2029 struct nfs_server *nfss = sb->s_fs_info;
2030 struct nfs_parsed_mount_data *data;
2031 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
2032 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
Trond Myklebustcd100722008-06-17 16:12:00 -04002033 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
Jeff Layton48b605f2008-06-10 15:38:39 -04002034
2035 /*
2036 * Userspace mount programs that send binary options generally send
2037 * them populated with default values. We have no way to know which
2038 * ones were explicitly specified. Fall back to legacy behavior and
2039 * just return success.
2040 */
Marc Zyngier31c94462008-07-17 13:21:55 +02002041 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
2042 (nfsvers <= 3 && (!options || (options->version >= 1 &&
2043 options->version <= 6))))
Jeff Layton48b605f2008-06-10 15:38:39 -04002044 return 0;
2045
2046 data = kzalloc(sizeof(*data), GFP_KERNEL);
2047 if (data == NULL)
2048 return -ENOMEM;
2049
2050 /* fill out struct with values from existing mount */
2051 data->flags = nfss->flags;
2052 data->rsize = nfss->rsize;
2053 data->wsize = nfss->wsize;
2054 data->retrans = nfss->client->cl_timeout->to_retries;
2055 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
2056 data->acregmin = nfss->acregmin / HZ;
2057 data->acregmax = nfss->acregmax / HZ;
2058 data->acdirmin = nfss->acdirmin / HZ;
2059 data->acdirmax = nfss->acdirmax / HZ;
2060 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
Trond Myklebustbcd2ea12009-10-06 15:41:22 -04002061 data->nfs_server.port = nfss->port;
Jeff Layton48b605f2008-06-10 15:38:39 -04002062 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
2063 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
2064 data->nfs_server.addrlen);
2065
2066 /* overwrite those values with any that were specified */
2067 error = nfs_parse_mount_options((char *)options, data);
2068 if (error < 0)
2069 goto out;
2070
Jeff Layton26c4c172011-04-27 11:49:09 -04002071 /*
2072 * noac is a special case. It implies -o sync, but that's not
2073 * necessarily reflected in the mtab options. do_remount_sb
2074 * will clear MS_SYNCHRONOUS if -o sync wasn't specified in the
2075 * remount options, so we have to explicitly reset it.
2076 */
2077 if (data->flags & NFS_MOUNT_NOAC)
2078 *flags |= MS_SYNCHRONOUS;
2079
Jeff Layton48b605f2008-06-10 15:38:39 -04002080 /* compare new mount options with old ones */
2081 error = nfs_compare_remount_data(nfss, data);
2082out:
2083 kfree(data);
2084 return error;
2085}
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002086EXPORT_SYMBOL_GPL(nfs_remount);
Jeff Layton48b605f2008-06-10 15:38:39 -04002087
David Howells54ceac42006-08-22 20:06:13 -04002088/*
2089 * Initialise the common bits of the superblock
2090 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002091inline void nfs_initialise_sb(struct super_block *sb)
David Howells54ceac42006-08-22 20:06:13 -04002092{
2093 struct nfs_server *server = NFS_SB(sb);
2094
2095 sb->s_magic = NFS_SUPER_MAGIC;
2096
2097 /* We probably want something more informative here */
2098 snprintf(sb->s_id, sizeof(sb->s_id),
Vivek Trivedi5a7c9ee2012-03-15 23:58:52 +05302099 "%u:%u", MAJOR(sb->s_dev), MINOR(sb->s_dev));
David Howells54ceac42006-08-22 20:06:13 -04002100
2101 if (sb->s_blocksize == 0)
2102 sb->s_blocksize = nfs_block_bits(server->wsize,
2103 &sb->s_blocksize_bits);
2104
Jens Axboe32a88aa2009-09-16 15:02:33 +02002105 sb->s_bdi = &server->backing_dev_info;
2106
David Howells54ceac42006-08-22 20:06:13 -04002107 nfs_super_set_maxbytes(sb, server->maxfilesize);
2108}
2109
2110/*
2111 * Finish setting up an NFS2/3 superblock
2112 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002113void nfs_fill_super(struct super_block *sb, struct nfs_mount_info *mount_info)
David Howells54ceac42006-08-22 20:06:13 -04002114{
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002115 struct nfs_parsed_mount_data *data = mount_info->parsed;
David Howells54ceac42006-08-22 20:06:13 -04002116 struct nfs_server *server = NFS_SB(sb);
2117
2118 sb->s_blocksize_bits = 0;
2119 sb->s_blocksize = 0;
Bryan Schumaker6a744902012-07-30 16:05:20 -04002120 sb->s_xattr = server->nfs_client->cl_nfs_mod->xattr;
2121 sb->s_op = server->nfs_client->cl_nfs_mod->sops;
2122 if (data && data->bsize)
David Howells54ceac42006-08-22 20:06:13 -04002123 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
2124
Bryan Schumaker6a744902012-07-30 16:05:20 -04002125 if (server->nfs_client->rpc_ops->version != 2) {
David Howells54ceac42006-08-22 20:06:13 -04002126 /* The VFS shouldn't apply the umask to mode bits. We will do
2127 * so ourselves when necessary.
2128 */
2129 sb->s_flags |= MS_POSIXACL;
2130 sb->s_time_gran = 1;
2131 }
2132
David Howells54ceac42006-08-22 20:06:13 -04002133 nfs_initialise_sb(sb);
2134}
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002135EXPORT_SYMBOL_GPL(nfs_fill_super);
David Howells54ceac42006-08-22 20:06:13 -04002136
2137/*
Bryan Schumaker3cadf4b2012-07-16 16:39:19 -04002138 * Finish setting up a cloned NFS2/3/4 superblock
David Howells54ceac42006-08-22 20:06:13 -04002139 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002140void nfs_clone_super(struct super_block *sb, struct nfs_mount_info *mount_info)
David Howells54ceac42006-08-22 20:06:13 -04002141{
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002142 const struct super_block *old_sb = mount_info->cloned->sb;
David Howells54ceac42006-08-22 20:06:13 -04002143 struct nfs_server *server = NFS_SB(sb);
2144
2145 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2146 sb->s_blocksize = old_sb->s_blocksize;
2147 sb->s_maxbytes = old_sb->s_maxbytes;
Bryan Schumaker3cadf4b2012-07-16 16:39:19 -04002148 sb->s_xattr = old_sb->s_xattr;
2149 sb->s_op = old_sb->s_op;
2150 sb->s_time_gran = 1;
David Howells54ceac42006-08-22 20:06:13 -04002151
Bryan Schumaker3cadf4b2012-07-16 16:39:19 -04002152 if (server->nfs_client->rpc_ops->version != 2) {
David Howells54ceac42006-08-22 20:06:13 -04002153 /* The VFS shouldn't apply the umask to mode bits. We will do
2154 * so ourselves when necessary.
2155 */
2156 sb->s_flags |= MS_POSIXACL;
David Howells54ceac42006-08-22 20:06:13 -04002157 }
2158
David Howells54ceac42006-08-22 20:06:13 -04002159 nfs_initialise_sb(sb);
2160}
2161
Trond Myklebust275a5d22007-05-16 16:53:28 -04002162static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
2163{
2164 const struct nfs_server *a = s->s_fs_info;
2165 const struct rpc_clnt *clnt_a = a->client;
2166 const struct rpc_clnt *clnt_b = b->client;
2167
2168 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
2169 goto Ebusy;
2170 if (a->nfs_client != b->nfs_client)
2171 goto Ebusy;
2172 if (a->flags != b->flags)
2173 goto Ebusy;
2174 if (a->wsize != b->wsize)
2175 goto Ebusy;
2176 if (a->rsize != b->rsize)
2177 goto Ebusy;
2178 if (a->acregmin != b->acregmin)
2179 goto Ebusy;
2180 if (a->acregmax != b->acregmax)
2181 goto Ebusy;
2182 if (a->acdirmin != b->acdirmin)
2183 goto Ebusy;
2184 if (a->acdirmax != b->acdirmax)
2185 goto Ebusy;
2186 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
2187 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002188 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04002189Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002190 return 0;
2191}
2192
2193struct nfs_sb_mountdata {
2194 struct nfs_server *server;
2195 int mntflags;
2196};
2197
2198static int nfs_set_super(struct super_block *s, void *data)
2199{
2200 struct nfs_sb_mountdata *sb_mntdata = data;
2201 struct nfs_server *server = sb_mntdata->server;
2202 int ret;
2203
2204 s->s_flags = sb_mntdata->mntflags;
2205 s->s_fs_info = server;
Al Viro8b244ff2010-12-18 11:29:39 -05002206 s->s_d_op = server->nfs_client->rpc_ops->dentry_ops;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002207 ret = set_anon_super(s, server);
2208 if (ret == 0)
2209 server->s_dev = s->s_dev;
2210 return ret;
2211}
2212
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002213static int nfs_compare_super_address(struct nfs_server *server1,
2214 struct nfs_server *server2)
2215{
2216 struct sockaddr *sap1, *sap2;
2217
2218 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
2219 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
2220
2221 if (sap1->sa_family != sap2->sa_family)
2222 return 0;
2223
2224 switch (sap1->sa_family) {
2225 case AF_INET: {
2226 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
2227 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
2228 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
2229 return 0;
2230 if (sin1->sin_port != sin2->sin_port)
2231 return 0;
2232 break;
2233 }
2234 case AF_INET6: {
2235 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
2236 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
2237 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
2238 return 0;
2239 if (sin1->sin6_port != sin2->sin6_port)
2240 return 0;
2241 break;
2242 }
2243 default:
2244 return 0;
2245 }
2246
2247 return 1;
2248}
2249
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002250static int nfs_compare_super(struct super_block *sb, void *data)
2251{
2252 struct nfs_sb_mountdata *sb_mntdata = data;
2253 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2254 int mntflags = sb_mntdata->mntflags;
2255
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002256 if (!nfs_compare_super_address(old, server))
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002257 return 0;
2258 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2259 if (old->flags & NFS_MOUNT_UNSHARED)
2260 return 0;
2261 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2262 return 0;
2263 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04002264}
2265
Trond Myklebust39ffb922012-05-16 10:21:30 -07002266#ifdef CONFIG_NFS_FSCACHE
Bryan Schumaker2311b942012-05-10 15:07:32 -04002267static void nfs_get_cache_cookie(struct super_block *sb,
2268 struct nfs_parsed_mount_data *parsed,
2269 struct nfs_clone_mount *cloned)
2270{
2271 char *uniq = NULL;
2272 int ulen = 0;
2273
2274 if (parsed && parsed->fscache_uniq) {
2275 uniq = parsed->fscache_uniq;
2276 ulen = strlen(parsed->fscache_uniq);
2277 } else if (cloned) {
2278 struct nfs_server *mnt_s = NFS_SB(cloned->sb);
2279 if (mnt_s->fscache_key) {
2280 uniq = mnt_s->fscache_key->key.uniquifier;
2281 ulen = mnt_s->fscache_key->key.uniq_len;
2282 };
2283 }
2284
2285 nfs_fscache_get_super_cookie(sb, uniq, ulen);
2286}
Trond Myklebust39ffb922012-05-16 10:21:30 -07002287#else
2288static void nfs_get_cache_cookie(struct super_block *sb,
2289 struct nfs_parsed_mount_data *parsed,
2290 struct nfs_clone_mount *cloned)
2291{
2292}
2293#endif
Bryan Schumaker2311b942012-05-10 15:07:32 -04002294
Miklos Szeredifa799752008-04-30 00:54:33 -07002295static int nfs_bdi_register(struct nfs_server *server)
2296{
2297 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
2298}
2299
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002300int nfs_set_sb_security(struct super_block *s, struct dentry *mntroot,
2301 struct nfs_mount_info *mount_info)
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002302{
2303 return security_sb_set_mnt_opts(s, &mount_info->parsed->lsm_opts);
2304}
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002305EXPORT_SYMBOL_GPL(nfs_set_sb_security);
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002306
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002307int nfs_clone_sb_security(struct super_block *s, struct dentry *mntroot,
2308 struct nfs_mount_info *mount_info)
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002309{
2310 /* clone any lsm security options from the parent to the new sb */
2311 security_sb_clone_mnt_opts(mount_info->cloned->sb, s);
2312 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops)
2313 return -ESTALE;
2314 return 0;
2315}
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002316EXPORT_SYMBOL_GPL(nfs_clone_sb_security);
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002317
Bryan Schumakerab7017a2012-07-30 16:05:16 -04002318struct dentry *nfs_fs_mount_common(struct nfs_server *server,
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002319 int flags, const char *dev_name,
Bryan Schumakerab7017a2012-07-30 16:05:16 -04002320 struct nfs_mount_info *mount_info,
2321 struct nfs_subversion *nfs_mod)
David Howells54ceac42006-08-22 20:06:13 -04002322{
David Howells54ceac42006-08-22 20:06:13 -04002323 struct super_block *s;
Al Viro01194982011-03-16 07:25:36 -04002324 struct dentry *mntroot = ERR_PTR(-ENOMEM);
Trond Myklebust75180df2007-05-16 16:53:28 -04002325 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002326 struct nfs_sb_mountdata sb_mntdata = {
2327 .mntflags = flags,
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002328 .server = server,
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002329 };
Al Viro01194982011-03-16 07:25:36 -04002330 int error;
David Howells54ceac42006-08-22 20:06:13 -04002331
Trond Myklebust75180df2007-05-16 16:53:28 -04002332 if (server->flags & NFS_MOUNT_UNSHARED)
2333 compare_super = NULL;
2334
Sachin Prabhufb2088c2011-08-01 12:10:12 +01002335 /* -o noac implies -o sync */
2336 if (server->flags & NFS_MOUNT_NOAC)
2337 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2338
David Howells54ceac42006-08-22 20:06:13 -04002339 /* Get a superblock - note that we may end up sharing one that already exists */
Bryan Schumakerab7017a2012-07-30 16:05:16 -04002340 s = sget(nfs_mod->nfs_fs, compare_super, nfs_set_super, flags, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002341 if (IS_ERR(s)) {
Al Viro01194982011-03-16 07:25:36 -04002342 mntroot = ERR_CAST(s);
David Howells54ceac42006-08-22 20:06:13 -04002343 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04002344 }
2345
David Howells54ceac42006-08-22 20:06:13 -04002346 if (s->s_fs_info != server) {
2347 nfs_free_server(server);
2348 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002349 } else {
2350 error = nfs_bdi_register(server);
Al Viro01194982011-03-16 07:25:36 -04002351 if (error) {
2352 mntroot = ERR_PTR(error);
NeilBrowncfbc0682010-03-11 11:20:17 +11002353 goto error_splat_bdi;
Al Viro01194982011-03-16 07:25:36 -04002354 }
David Howellsf7b422b2006-06-09 09:34:33 -04002355 }
David Howells54ceac42006-08-22 20:06:13 -04002356
2357 if (!s->s_root) {
2358 /* initial superblock/root creation */
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002359 mount_info->fill_super(s, mount_info);
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002360 nfs_get_cache_cookie(s, mount_info->parsed, mount_info->cloned);
David Howells54ceac42006-08-22 20:06:13 -04002361 }
2362
Bryan Schumaker87c70832012-05-10 15:07:43 -04002363 mntroot = nfs_get_root(s, mount_info->mntfh, dev_name);
Al Viro01194982011-03-16 07:25:36 -04002364 if (IS_ERR(mntroot))
David Howells54ceac42006-08-22 20:06:13 -04002365 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002366
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002367 error = mount_info->set_security(s, mntroot, mount_info);
Eric Parisf9c3a382008-03-05 14:20:18 -05002368 if (error)
2369 goto error_splat_root;
2370
David Howellsf7b422b2006-06-09 09:34:33 -04002371 s->s_flags |= MS_ACTIVE;
Chuck Lever06559602007-07-01 12:12:35 -04002372
2373out:
Al Viro01194982011-03-16 07:25:36 -04002374 return mntroot;
Trond Myklebust816724e2006-06-24 08:41:41 -04002375
David Howells54ceac42006-08-22 20:06:13 -04002376out_err_nosb:
2377 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04002378 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002379
Eric Parisf9c3a382008-03-05 14:20:18 -05002380error_splat_root:
2381 dput(mntroot);
Al Viro01194982011-03-16 07:25:36 -04002382 mntroot = ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04002383error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002384 if (server && !s->s_root)
2385 bdi_unregister(&server->backing_dev_info);
2386error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002387 deactivate_locked_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04002388 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002389}
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002390EXPORT_SYMBOL_GPL(nfs_fs_mount_common);
David Howellsf7b422b2006-06-09 09:34:33 -04002391
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002392struct dentry *nfs_fs_mount(struct file_system_type *fs_type,
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002393 int flags, const char *dev_name, void *raw_data)
2394{
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002395 struct nfs_mount_info mount_info = {
2396 .fill_super = nfs_fill_super,
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002397 .set_security = nfs_set_sb_security,
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002398 };
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002399 struct dentry *mntroot = ERR_PTR(-ENOMEM);
Bryan Schumakerab7017a2012-07-30 16:05:16 -04002400 struct nfs_subversion *nfs_mod;
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002401 int error;
2402
Bryan Schumaker46058d42012-05-10 15:07:42 -04002403 mount_info.parsed = nfs_alloc_parsed_mount_data();
Bryan Schumaker87c70832012-05-10 15:07:43 -04002404 mount_info.mntfh = nfs_alloc_fhandle();
2405 if (mount_info.parsed == NULL || mount_info.mntfh == NULL)
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002406 goto out;
2407
2408 /* Validate the mount data */
Bryan Schumaker87c70832012-05-10 15:07:43 -04002409 error = nfs_validate_mount_data(fs_type, raw_data, mount_info.parsed, mount_info.mntfh, dev_name);
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04002410 if (error == NFS_TEXT_DATA)
Bryan Schumaker46058d42012-05-10 15:07:42 -04002411 error = nfs_validate_text_mount_data(raw_data, mount_info.parsed, dev_name);
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002412 if (error < 0) {
2413 mntroot = ERR_PTR(error);
2414 goto out;
2415 }
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002416
Bryan Schumakerab7017a2012-07-30 16:05:16 -04002417 nfs_mod = get_nfs_version(mount_info.parsed->version);
2418 if (IS_ERR(nfs_mod)) {
2419 mntroot = ERR_CAST(nfs_mod);
2420 goto out;
2421 }
2422
Bryan Schumakerff9099f22012-07-30 16:05:18 -04002423 mntroot = nfs_mod->rpc_ops->try_mount(flags, dev_name, &mount_info, nfs_mod);
Bryan Schumakerab7017a2012-07-30 16:05:16 -04002424
2425 put_nfs_version(nfs_mod);
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002426out:
Bryan Schumaker46058d42012-05-10 15:07:42 -04002427 nfs_free_parsed_mount_data(mount_info.parsed);
Bryan Schumaker87c70832012-05-10 15:07:43 -04002428 nfs_free_fhandle(mount_info.mntfh);
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002429 return mntroot;
2430}
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002431EXPORT_SYMBOL_GPL(nfs_fs_mount);
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002432
David Howells54ceac42006-08-22 20:06:13 -04002433/*
Trond Myklebust387c1492010-02-03 08:27:35 -05002434 * Ensure that we unregister the bdi before kill_anon_super
2435 * releases the device name
2436 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002437void nfs_put_super(struct super_block *s)
Trond Myklebust387c1492010-02-03 08:27:35 -05002438{
2439 struct nfs_server *server = NFS_SB(s);
2440
2441 bdi_unregister(&server->backing_dev_info);
2442}
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002443EXPORT_SYMBOL_GPL(nfs_put_super);
Trond Myklebust387c1492010-02-03 08:27:35 -05002444
2445/*
David Howells54ceac42006-08-22 20:06:13 -04002446 * Destroy an NFS2/3 superblock
2447 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002448void nfs_kill_super(struct super_block *s)
David Howellsf7b422b2006-06-09 09:34:33 -04002449{
2450 struct nfs_server *server = NFS_SB(s);
2451
2452 kill_anon_super(s);
David Howells08734042009-04-03 16:42:42 +01002453 nfs_fscache_release_super_cookie(s);
David Howells54ceac42006-08-22 20:06:13 -04002454 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04002455}
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002456EXPORT_SYMBOL_GPL(nfs_kill_super);
David Howellsf7b422b2006-06-09 09:34:33 -04002457
David Howells54ceac42006-08-22 20:06:13 -04002458/*
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002459 * Clone an NFS2/3/4 server record on xdev traversal (FSID-change)
David Howells54ceac42006-08-22 20:06:13 -04002460 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002461struct dentry *
Bryan Schumakere8f25e62012-07-30 16:05:17 -04002462nfs_xdev_mount(struct file_system_type *fs_type, int flags,
2463 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002464{
Bryan Schumakere8f25e62012-07-30 16:05:17 -04002465 struct nfs_clone_mount *data = raw_data;
2466 struct nfs_mount_info mount_info = {
2467 .fill_super = nfs_clone_super,
2468 .set_security = nfs_clone_sb_security,
2469 .cloned = data,
2470 };
David Howells54ceac42006-08-22 20:06:13 -04002471 struct nfs_server *server;
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002472 struct dentry *mntroot = ERR_PTR(-ENOMEM);
Bryan Schumakerab7017a2012-07-30 16:05:16 -04002473 struct nfs_subversion *nfs_mod = NFS_SB(data->sb)->nfs_client->cl_nfs_mod;
David Howells54ceac42006-08-22 20:06:13 -04002474 int error;
2475
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002476 dprintk("--> nfs_xdev_mount_common()\n");
David Howells54ceac42006-08-22 20:06:13 -04002477
Bryan Schumakere8f25e62012-07-30 16:05:17 -04002478 mount_info.mntfh = mount_info.cloned->fh;
Bryan Schumaker87c70832012-05-10 15:07:43 -04002479
David Howells54ceac42006-08-22 20:06:13 -04002480 /* create a new volume representation */
Bryan Schumaker1179acc2012-07-30 16:05:19 -04002481 server = nfs_mod->rpc_ops->clone_server(NFS_SB(data->sb), data->fh, data->fattr, data->authflavor);
David Howells54ceac42006-08-22 20:06:13 -04002482 if (IS_ERR(server)) {
2483 error = PTR_ERR(server);
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002484 goto out_err;
David Howells54ceac42006-08-22 20:06:13 -04002485 }
2486
Bryan Schumakere8f25e62012-07-30 16:05:17 -04002487 mntroot = nfs_fs_mount_common(server, flags, dev_name, &mount_info, nfs_mod);
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002488 dprintk("<-- nfs_xdev_mount_common() = 0\n");
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002489out:
Al Viro31f43472010-10-29 03:38:12 -04002490 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04002491
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002492out_err:
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002493 dprintk("<-- nfs_xdev_mount_common() = %d [error]\n", error);
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002494 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002495}
2496
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002497#if IS_ENABLED(CONFIG_NFS_V4)
David Howells54ceac42006-08-22 20:06:13 -04002498
Trond Myklebust01c3f052009-06-17 13:22:58 -07002499static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2500{
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04002501 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3|
2502 NFS_MOUNT_LOCAL_FLOCK|NFS_MOUNT_LOCAL_FCNTL);
Trond Myklebust01c3f052009-06-17 13:22:58 -07002503}
2504
David Howells54ceac42006-08-22 20:06:13 -04002505/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04002506 * Validate NFSv4 mount options
2507 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002508static int nfs4_validate_mount_data(void *options,
2509 struct nfs_parsed_mount_data *args,
2510 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04002511{
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002512 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002513 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002514 char *c;
2515
2516 if (data == NULL)
2517 goto out_no_data;
2518
Bryan Schumakercdf66442012-06-05 14:59:54 -04002519 args->version = 4;
2520
Chuck Leverf0768eb2007-07-01 12:13:01 -04002521 switch (data->version) {
2522 case 1:
Chuck Lever4c568012007-12-10 14:59:28 -05002523 if (data->host_addrlen > sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002524 goto out_no_address;
Chuck Lever4c568012007-12-10 14:59:28 -05002525 if (data->host_addrlen == 0)
2526 goto out_no_address;
2527 args->nfs_server.addrlen = data->host_addrlen;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002528 if (copy_from_user(sap, data->host_addr, data->host_addrlen))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002529 return -EFAULT;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002530 if (!nfs_verify_server_address(sap))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002531 goto out_no_address;
2532
Chuck Lever6738b252008-06-24 16:33:54 -04002533 if (data->auth_flavourlen) {
2534 if (data->auth_flavourlen > 1)
2535 goto out_inval_auth;
Trond Myklebust20c71f52007-09-20 20:23:51 -04002536 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002537 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04002538 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002539 return -EFAULT;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002540 }
2541
2542 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2543 if (IS_ERR(c))
2544 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002545 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002546
2547 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2548 if (IS_ERR(c))
2549 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002550 args->nfs_server.export_path = c;
2551 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002552
2553 c = strndup_user(data->client_addr.data, 16);
2554 if (IS_ERR(c))
2555 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002556 args->client_address = c;
2557
2558 /*
2559 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2560 * can deal with.
2561 */
2562
2563 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2564 args->rsize = data->rsize;
2565 args->wsize = data->wsize;
2566 args->timeo = data->timeo;
2567 args->retrans = data->retrans;
2568 args->acregmin = data->acregmin;
2569 args->acregmax = data->acregmax;
2570 args->acdirmin = data->acdirmin;
2571 args->acdirmax = data->acdirmax;
2572 args->nfs_server.protocol = data->proto;
Trond Myklebust259875e2008-07-02 14:43:47 -04002573 nfs_validate_transport_protocol(args);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002574
2575 break;
Chuck Lever7630c852009-09-08 19:49:57 -04002576 default:
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04002577 return NFS_TEXT_DATA;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002578 }
2579
2580 return 0;
2581
2582out_no_data:
2583 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2584 return -EINVAL;
2585
2586out_inval_auth:
2587 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2588 data->auth_flavourlen);
2589 return -EINVAL;
2590
2591out_no_address:
2592 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2593 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002594}
2595
Bryan Schumakerfac1e8e2012-07-30 16:05:22 -04002596/*
2597 * NFS v4 module parameters need to stay in the
2598 * NFS client for backwards compatibility
2599 */
2600unsigned int nfs_callback_set_tcpport;
2601unsigned short nfs_callback_tcpport;
2602/* Default cache timeout is 10 minutes */
2603unsigned int nfs_idmap_cache_timeout = 600;
2604/* Turn off NFSv4 uid/gid mapping when using AUTH_SYS */
2605bool nfs4_disable_idmapping = true;
2606unsigned short max_session_slots = NFS4_DEF_SLOT_TABLE_SIZE;
2607unsigned short send_implementation_id = 1;
2608
Bryan Schumaker89d77c82012-07-30 16:05:25 -04002609EXPORT_SYMBOL_GPL(nfs_callback_set_tcpport);
2610EXPORT_SYMBOL_GPL(nfs_callback_tcpport);
2611EXPORT_SYMBOL_GPL(nfs_idmap_cache_timeout);
2612EXPORT_SYMBOL_GPL(nfs4_disable_idmapping);
2613EXPORT_SYMBOL_GPL(max_session_slots);
2614EXPORT_SYMBOL_GPL(send_implementation_id);
2615
Bryan Schumakerfac1e8e2012-07-30 16:05:22 -04002616#define NFS_CALLBACK_MAXPORTNR (65535U)
2617
2618static int param_set_portnr(const char *val, const struct kernel_param *kp)
2619{
2620 unsigned long num;
2621 int ret;
2622
2623 if (!val)
2624 return -EINVAL;
2625 ret = strict_strtoul(val, 0, &num);
2626 if (ret == -EINVAL || num > NFS_CALLBACK_MAXPORTNR)
2627 return -EINVAL;
2628 *((unsigned int *)kp->arg) = num;
2629 return 0;
2630}
2631static struct kernel_param_ops param_ops_portnr = {
2632 .set = param_set_portnr,
2633 .get = param_get_uint,
2634};
2635#define param_check_portnr(name, p) __param_check(name, p, unsigned int);
2636
2637module_param_named(callback_tcpport, nfs_callback_set_tcpport, portnr, 0644);
2638module_param(nfs_idmap_cache_timeout, int, 0644);
2639module_param(nfs4_disable_idmapping, bool, 0644);
2640MODULE_PARM_DESC(nfs4_disable_idmapping,
2641 "Turn off NFSv4 idmapping when using 'sec=sys'");
2642module_param(max_session_slots, ushort, 0644);
2643MODULE_PARM_DESC(max_session_slots, "Maximum number of outstanding NFSv4.1 "
2644 "requests the client will negotiate");
2645module_param(send_implementation_id, ushort, 0644);
2646MODULE_PARM_DESC(send_implementation_id,
2647 "Send implementation ID with NFSv4.1 exchange_id");
David Howells54ceac42006-08-22 20:06:13 -04002648#endif /* CONFIG_NFS_V4 */