blob: 5fca59d73e40fd16a7c4995b0d098f4e63b6fe22 [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
Paulius Zaleckas1e657bd2010-10-31 18:21:05 +020072#ifdef CONFIG_NFS_V3
73#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};
292
David Howells54ceac42006-08-22 20:06:13 -0400293struct file_system_type nfs_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400294 .owner = THIS_MODULE,
295 .name = "nfs",
Al Viro31f43472010-10-29 03:38:12 -0400296 .mount = nfs_xdev_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400297 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700298 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400299};
300
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800301static const struct super_operations nfs_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400302 .alloc_inode = nfs_alloc_inode,
303 .destroy_inode = nfs_destroy_inode,
304 .write_inode = nfs_write_inode,
Trond Myklebust387c1492010-02-03 08:27:35 -0500305 .put_super = nfs_put_super,
David Howellsf7b422b2006-06-09 09:34:33 -0400306 .statfs = nfs_statfs,
Al Virob57922d2010-06-07 14:34:48 -0400307 .evict_inode = nfs_evict_inode,
David Howellsf7b422b2006-06-09 09:34:33 -0400308 .umount_begin = nfs_umount_begin,
309 .show_options = nfs_show_options,
Al Viroc7f404b2011-03-16 06:59:40 -0400310 .show_devname = nfs_show_devname,
311 .show_path = nfs_show_path,
David Howellsf7b422b2006-06-09 09:34:33 -0400312 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400313 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400314};
315
316#ifdef CONFIG_NFS_V4
Bryan Schumakerb72e4f42012-05-10 15:07:40 -0400317static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *);
Bryan Schumakerd72c7272012-05-10 15:07:41 -0400318static int nfs4_validate_mount_data(void *options,
319 struct nfs_parsed_mount_data *args, const char *dev_name);
David Howellsf7b422b2006-06-09 09:34:33 -0400320#endif
321
Rusty Russell8e1f9362007-07-17 04:03:17 -0700322static struct shrinker acl_shrinker = {
323 .shrink = nfs_access_cache_shrinker,
324 .seeks = DEFAULT_SEEKS,
325};
Trond Myklebust979df722006-07-25 11:28:19 -0400326
David Howellsf7b422b2006-06-09 09:34:33 -0400327/*
328 * Register the NFS filesystems
329 */
330int __init register_nfs_fs(void)
331{
332 int ret;
333
334 ret = register_filesystem(&nfs_fs_type);
335 if (ret < 0)
336 goto error_0;
337
David Howellsf7b422b2006-06-09 09:34:33 -0400338 ret = nfs_register_sysctl();
339 if (ret < 0)
340 goto error_1;
Rusty Russell8e1f9362007-07-17 04:03:17 -0700341 register_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400342 return 0;
343
David Howellsf7b422b2006-06-09 09:34:33 -0400344error_1:
345 unregister_filesystem(&nfs_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400346error_0:
347 return ret;
348}
349
350/*
351 * Unregister the NFS filesystems
352 */
353void __exit unregister_nfs_fs(void)
354{
Rusty Russell8e1f9362007-07-17 04:03:17 -0700355 unregister_shrinker(&acl_shrinker);
Alexey Dobriyan49af7ee2007-09-18 22:46:40 -0700356 nfs_unregister_sysctl();
David Howellsf7b422b2006-06-09 09:34:33 -0400357 unregister_filesystem(&nfs_fs_type);
358}
359
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400360void nfs_sb_active(struct super_block *sb)
Steve Dicksonef818a22007-11-08 04:05:04 -0500361{
362 struct nfs_server *server = NFS_SB(sb);
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400363
364 if (atomic_inc_return(&server->active) == 1)
365 atomic_inc(&sb->s_active);
366}
367
368void nfs_sb_deactive(struct super_block *sb)
369{
370 struct nfs_server *server = NFS_SB(sb);
371
372 if (atomic_dec_and_test(&server->active))
373 deactivate_super(sb);
Steve Dicksonef818a22007-11-08 04:05:04 -0500374}
375
David Howellsf7b422b2006-06-09 09:34:33 -0400376/*
377 * Deliver file system statistics to userspace
378 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -0400379int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
David Howellsf7b422b2006-06-09 09:34:33 -0400380{
David Howells0c7d90c2006-08-22 20:06:10 -0400381 struct nfs_server *server = NFS_SB(dentry->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400382 unsigned char blockbits;
383 unsigned long blockres;
David Howells0c7d90c2006-08-22 20:06:10 -0400384 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400385 struct nfs_fsstat res;
386 int error = -ENOMEM;
387
388 res.fattr = nfs_alloc_fattr();
389 if (res.fattr == NULL)
390 goto out_err;
David Howellsf7b422b2006-06-09 09:34:33 -0400391
David Howells8fa5c002006-08-22 20:06:12 -0400392 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
Menyhart Zoltanfbf3fdd2010-09-12 19:55:26 -0400393 if (unlikely(error == -ESTALE)) {
394 struct dentry *pd_dentry;
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400395
Menyhart Zoltanfbf3fdd2010-09-12 19:55:26 -0400396 pd_dentry = dget_parent(dentry);
397 if (pd_dentry != NULL) {
398 nfs_zap_caches(pd_dentry->d_inode);
399 dput(pd_dentry);
400 }
401 }
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400402 nfs_free_fattr(res.fattr);
David Howellsf7b422b2006-06-09 09:34:33 -0400403 if (error < 0)
404 goto out_err;
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400405
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700406 buf->f_type = NFS_SUPER_MAGIC;
David Howellsf7b422b2006-06-09 09:34:33 -0400407
408 /*
409 * Current versions of glibc do not correctly handle the
410 * case where f_frsize != f_bsize. Eventually we want to
411 * report the value of wtmult in this field.
412 */
David Howells0c7d90c2006-08-22 20:06:10 -0400413 buf->f_frsize = dentry->d_sb->s_blocksize;
David Howellsf7b422b2006-06-09 09:34:33 -0400414
415 /*
416 * On most *nix systems, f_blocks, f_bfree, and f_bavail
417 * are reported in units of f_frsize. Linux hasn't had
418 * an f_frsize field in its statfs struct until recently,
419 * thus historically Linux's sys_statfs reports these
420 * fields in units of f_bsize.
421 */
David Howells0c7d90c2006-08-22 20:06:10 -0400422 buf->f_bsize = dentry->d_sb->s_blocksize;
423 blockbits = dentry->d_sb->s_blocksize_bits;
David Howellsf7b422b2006-06-09 09:34:33 -0400424 blockres = (1 << blockbits) - 1;
425 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
426 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
427 buf->f_bavail = (res.abytes + blockres) >> blockbits;
428
429 buf->f_files = res.tfiles;
430 buf->f_ffree = res.afiles;
431
432 buf->f_namelen = server->namelen;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700433
David Howellsf7b422b2006-06-09 09:34:33 -0400434 return 0;
435
436 out_err:
Harvey Harrison3110ff82008-05-02 13:42:44 -0700437 dprintk("%s: statfs error = %d\n", __func__, -error);
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700438 return error;
David Howellsf7b422b2006-06-09 09:34:33 -0400439}
440
David Howells7d4e2742006-08-22 20:06:07 -0400441/*
442 * Map the security flavour number to a name
443 */
Trond Myklebust81039f12006-06-09 09:34:34 -0400444static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
445{
David Howells7d4e2742006-08-22 20:06:07 -0400446 static const struct {
Trond Myklebust81039f12006-06-09 09:34:34 -0400447 rpc_authflavor_t flavour;
448 const char *str;
449 } sec_flavours[] = {
450 { RPC_AUTH_NULL, "null" },
451 { RPC_AUTH_UNIX, "sys" },
452 { RPC_AUTH_GSS_KRB5, "krb5" },
453 { RPC_AUTH_GSS_KRB5I, "krb5i" },
454 { RPC_AUTH_GSS_KRB5P, "krb5p" },
455 { RPC_AUTH_GSS_LKEY, "lkey" },
456 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
457 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
458 { RPC_AUTH_GSS_SPKM, "spkm" },
459 { RPC_AUTH_GSS_SPKMI, "spkmi" },
460 { RPC_AUTH_GSS_SPKMP, "spkmp" },
Chuck Lever4d81cd12007-07-01 12:12:40 -0400461 { UINT_MAX, "unknown" }
Trond Myklebust81039f12006-06-09 09:34:34 -0400462 };
463 int i;
464
Chuck Lever4d81cd12007-07-01 12:12:40 -0400465 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
Trond Myklebust81039f12006-06-09 09:34:34 -0400466 if (sec_flavours[i].flavour == flavour)
467 break;
468 }
469 return sec_flavours[i].str;
470}
471
Jeff Laytonee671b02009-12-03 15:58:56 -0500472static void nfs_show_mountd_netid(struct seq_file *m, struct nfs_server *nfss,
473 int showdefaults)
474{
475 struct sockaddr *sap = (struct sockaddr *) &nfss->mountd_address;
476
477 seq_printf(m, ",mountproto=");
478 switch (sap->sa_family) {
479 case AF_INET:
480 switch (nfss->mountd_protocol) {
481 case IPPROTO_UDP:
482 seq_printf(m, RPCBIND_NETID_UDP);
483 break;
484 case IPPROTO_TCP:
485 seq_printf(m, RPCBIND_NETID_TCP);
486 break;
487 default:
488 if (showdefaults)
489 seq_printf(m, "auto");
490 }
491 break;
492 case AF_INET6:
493 switch (nfss->mountd_protocol) {
494 case IPPROTO_UDP:
495 seq_printf(m, RPCBIND_NETID_UDP6);
496 break;
497 case IPPROTO_TCP:
498 seq_printf(m, RPCBIND_NETID_TCP6);
499 break;
500 default:
501 if (showdefaults)
502 seq_printf(m, "auto");
503 }
504 break;
505 default:
506 if (showdefaults)
507 seq_printf(m, "auto");
508 }
509}
510
Chuck Lever82d101d2008-03-14 14:10:37 -0400511static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
512 int showdefaults)
513{
514 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
515
Bryan Schumakerd5eff1a2010-08-03 13:04:00 -0400516 if (nfss->flags & NFS_MOUNT_LEGACY_INTERFACE)
517 return;
518
Chuck Lever82d101d2008-03-14 14:10:37 -0400519 switch (sap->sa_family) {
520 case AF_INET: {
521 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
Harvey Harrisonbe859402008-10-31 00:56:28 -0700522 seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400523 break;
524 }
525 case AF_INET6: {
526 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
Chuck Leverd250e192009-12-03 15:58:56 -0500527 seq_printf(m, ",mountaddr=%pI6c", &sin6->sin6_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400528 break;
529 }
530 default:
531 if (showdefaults)
532 seq_printf(m, ",mountaddr=unspecified");
533 }
534
535 if (nfss->mountd_version || showdefaults)
536 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
Stanislav Kinsburskyaa699472010-12-08 12:40:13 +0300537 if ((nfss->mountd_port &&
538 nfss->mountd_port != (unsigned short)NFS_UNSPEC_PORT) ||
539 showdefaults)
Chuck Lever82d101d2008-03-14 14:10:37 -0400540 seq_printf(m, ",mountport=%u", nfss->mountd_port);
541
Jeff Laytonee671b02009-12-03 15:58:56 -0500542 nfs_show_mountd_netid(m, nfss, showdefaults);
Chuck Lever82d101d2008-03-14 14:10:37 -0400543}
544
Trond Myklebust0be81892010-06-18 12:23:58 -0400545#ifdef CONFIG_NFS_V4
546static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
547 int showdefaults)
548{
549 struct nfs_client *clp = nfss->nfs_client;
550
551 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
Trond Myklebust0be81892010-06-18 12:23:58 -0400552}
553#else
554static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
555 int showdefaults)
556{
557}
558#endif
559
Trond Myklebust7bbceb62012-03-02 14:00:20 -0500560static void nfs_show_nfs_version(struct seq_file *m,
561 unsigned int version,
562 unsigned int minorversion)
563{
564 seq_printf(m, ",vers=%u", version);
565 if (version == 4)
566 seq_printf(m, ".%u", minorversion);
567}
568
David Howellsf7b422b2006-06-09 09:34:33 -0400569/*
570 * Describe the mount options in force on this server representation
571 */
Chuck Lever82d101d2008-03-14 14:10:37 -0400572static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
573 int showdefaults)
David Howellsf7b422b2006-06-09 09:34:33 -0400574{
David Howells509de812006-08-22 20:06:11 -0400575 static const struct proc_nfs_info {
David Howellsf7b422b2006-06-09 09:34:33 -0400576 int flag;
David Howells509de812006-08-22 20:06:11 -0400577 const char *str;
578 const char *nostr;
David Howellsf7b422b2006-06-09 09:34:33 -0400579 } nfs_info[] = {
580 { NFS_MOUNT_SOFT, ",soft", ",hard" },
Chuck Lever82d101d2008-03-14 14:10:37 -0400581 { NFS_MOUNT_POSIX, ",posix", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400582 { NFS_MOUNT_NOCTO, ",nocto", "" },
583 { NFS_MOUNT_NOAC, ",noac", "" },
584 { NFS_MOUNT_NONLM, ",nolock", "" },
585 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400586 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
Chuck Leverd7403512008-12-23 15:21:37 -0500587 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
588 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400589 { 0, NULL, NULL }
590 };
David Howells509de812006-08-22 20:06:11 -0400591 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400592 struct nfs_client *clp = nfss->nfs_client;
Chuck Lever82d101d2008-03-14 14:10:37 -0400593 u32 version = clp->rpc_ops->version;
Suresh Jayaraman7c563cc2010-09-23 14:26:48 -0400594 int local_flock, local_fcntl;
David Howellsf7b422b2006-06-09 09:34:33 -0400595
Trond Myklebust7bbceb62012-03-02 14:00:20 -0500596 nfs_show_nfs_version(m, version, clp->cl_minorversion);
Chuck Lever2d767432008-03-14 14:10:08 -0400597 seq_printf(m, ",rsize=%u", nfss->rsize);
598 seq_printf(m, ",wsize=%u", nfss->wsize);
Chuck Lever82d101d2008-03-14 14:10:37 -0400599 if (nfss->bsize != 0)
600 seq_printf(m, ",bsize=%u", nfss->bsize);
601 seq_printf(m, ",namlen=%u", nfss->namelen);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400602 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400603 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400604 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400605 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400606 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400607 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400608 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400609 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
David Howellsf7b422b2006-06-09 09:34:33 -0400610 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
611 if (nfss->flags & nfs_infop->flag)
612 seq_puts(m, nfs_infop->str);
613 else
614 seq_puts(m, nfs_infop->nostr);
615 }
Trond Myklebust2446ab62012-03-01 17:00:56 -0500616 rcu_read_lock();
\"Talpey, Thomas\56928ed2007-09-10 13:48:47 -0400617 seq_printf(m, ",proto=%s",
Jeff Laytonee671b02009-12-03 15:58:56 -0500618 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
Trond Myklebust2446ab62012-03-01 17:00:56 -0500619 rcu_read_unlock();
Chuck Lever82d101d2008-03-14 14:10:37 -0400620 if (version == 4) {
621 if (nfss->port != NFS_PORT)
622 seq_printf(m, ",port=%u", nfss->port);
623 } else
624 if (nfss->port)
625 seq_printf(m, ",port=%u", nfss->port);
626
Trond Myklebust33170232007-12-20 16:03:59 -0500627 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
628 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
Trond Myklebust81039f12006-06-09 09:34:34 -0400629 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
Chuck Lever82d101d2008-03-14 14:10:37 -0400630
631 if (version != 4)
632 nfs_show_mountd_options(m, nfss, showdefaults);
Trond Myklebust0be81892010-06-18 12:23:58 -0400633 else
634 nfs_show_nfsv4_options(m, nfss, showdefaults);
Chuck Lever82d101d2008-03-14 14:10:37 -0400635
David Howellsb797cac2009-04-03 16:42:48 +0100636 if (nfss->options & NFS_OPTION_FSCACHE)
637 seq_printf(m, ",fsc");
Patrick J. LoPresti9b00c642010-08-10 17:28:01 -0400638
639 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONEG) {
640 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONE)
641 seq_printf(m, ",lookupcache=none");
642 else
643 seq_printf(m, ",lookupcache=pos");
644 }
Suresh Jayaraman7c563cc2010-09-23 14:26:48 -0400645
646 local_flock = nfss->flags & NFS_MOUNT_LOCAL_FLOCK;
647 local_fcntl = nfss->flags & NFS_MOUNT_LOCAL_FCNTL;
648
649 if (!local_flock && !local_fcntl)
650 seq_printf(m, ",local_lock=none");
651 else if (local_flock && local_fcntl)
652 seq_printf(m, ",local_lock=all");
653 else if (local_flock)
654 seq_printf(m, ",local_lock=flock");
655 else
656 seq_printf(m, ",local_lock=posix");
David Howellsf7b422b2006-06-09 09:34:33 -0400657}
658
659/*
660 * Describe the mount options on this VFS mountpoint
661 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -0400662int nfs_show_options(struct seq_file *m, struct dentry *root)
David Howellsf7b422b2006-06-09 09:34:33 -0400663{
Al Viro34c80b12011-12-08 21:32:45 -0500664 struct nfs_server *nfss = NFS_SB(root->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400665
666 nfs_show_mount_options(m, nfss, 0);
667
Trond Myklebust2446ab62012-03-01 17:00:56 -0500668 rcu_read_lock();
Chuck Lever5d8515c2007-12-10 14:57:16 -0500669 seq_printf(m, ",addr=%s",
670 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
671 RPC_DISPLAY_ADDR));
Trond Myklebust2446ab62012-03-01 17:00:56 -0500672 rcu_read_unlock();
David Howellsf7b422b2006-06-09 09:34:33 -0400673
674 return 0;
675}
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700676
677#ifdef CONFIG_NFS_V4
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300678#ifdef CONFIG_NFS_V4_1
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700679static void show_sessions(struct seq_file *m, struct nfs_server *server)
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300680{
681 if (nfs4_has_session(server->nfs_client))
682 seq_printf(m, ",sessions");
683}
684#else
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700685static void show_sessions(struct seq_file *m, struct nfs_server *server) {}
686#endif
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300687#endif
688
689#ifdef CONFIG_NFS_V4_1
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700690static void show_pnfs(struct seq_file *m, struct nfs_server *server)
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300691{
692 seq_printf(m, ",pnfs=");
693 if (server->pnfs_curr_ld)
694 seq_printf(m, "%s", server->pnfs_curr_ld->name);
695 else
696 seq_printf(m, "not configured");
697}
Trond Myklebust7e03b7c2012-03-04 18:12:57 -0500698
699static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
700{
Chuck Lever59155542012-05-21 22:44:41 -0400701 if (nfss->nfs_client && nfss->nfs_client->cl_implid) {
702 struct nfs41_impl_id *impl_id = nfss->nfs_client->cl_implid;
Trond Myklebust7e03b7c2012-03-04 18:12:57 -0500703 seq_printf(m, "\n\timpl_id:\tname='%s',domain='%s',"
704 "date='%llu,%u'",
705 impl_id->name, impl_id->domain,
706 impl_id->date.seconds, impl_id->date.nseconds);
707 }
708}
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700709#else
Trond Myklebust7e03b7c2012-03-04 18:12:57 -0500710#ifdef CONFIG_NFS_V4
711static void show_pnfs(struct seq_file *m, struct nfs_server *server)
712{
713}
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700714#endif
Trond Myklebust7e03b7c2012-03-04 18:12:57 -0500715static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
716{
717}
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700718#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400719
Bryan Schumakerfbdefd62012-07-16 16:39:20 -0400720int nfs_show_devname(struct seq_file *m, struct dentry *root)
Al Viroc7f404b2011-03-16 06:59:40 -0400721{
722 char *page = (char *) __get_free_page(GFP_KERNEL);
723 char *devname, *dummy;
724 int err = 0;
725 if (!page)
726 return -ENOMEM;
Al Virod861c632011-12-08 21:32:45 -0500727 devname = nfs_path(&dummy, root, page, PAGE_SIZE);
Al Viroc7f404b2011-03-16 06:59:40 -0400728 if (IS_ERR(devname))
729 err = PTR_ERR(devname);
730 else
731 seq_escape(m, devname, " \t\n\\");
732 free_page((unsigned long)page);
733 return err;
734}
735
Bryan Schumakerfbdefd62012-07-16 16:39:20 -0400736int nfs_show_path(struct seq_file *m, struct dentry *dentry)
Al Viroc7f404b2011-03-16 06:59:40 -0400737{
738 seq_puts(m, "/");
739 return 0;
740}
741
David Howellsf7b422b2006-06-09 09:34:33 -0400742/*
743 * Present statistical information for this VFS mountpoint
744 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -0400745int nfs_show_stats(struct seq_file *m, struct dentry *root)
David Howellsf7b422b2006-06-09 09:34:33 -0400746{
747 int i, cpu;
Al Viro64132372011-12-08 20:51:13 -0500748 struct nfs_server *nfss = NFS_SB(root->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400749 struct rpc_auth *auth = nfss->client->cl_auth;
750 struct nfs_iostats totals = { };
751
752 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
753
754 /*
755 * Display all mount option settings
756 */
757 seq_printf(m, "\n\topts:\t");
Al Viro64132372011-12-08 20:51:13 -0500758 seq_puts(m, root->d_sb->s_flags & MS_RDONLY ? "ro" : "rw");
759 seq_puts(m, root->d_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
760 seq_puts(m, root->d_sb->s_flags & MS_NOATIME ? ",noatime" : "");
761 seq_puts(m, root->d_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
David Howellsf7b422b2006-06-09 09:34:33 -0400762 nfs_show_mount_options(m, nfss, 1);
763
764 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
765
Trond Myklebust7e03b7c2012-03-04 18:12:57 -0500766 show_implementation_id(m, nfss);
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500767
David Howellsf7b422b2006-06-09 09:34:33 -0400768 seq_printf(m, "\n\tcaps:\t");
769 seq_printf(m, "caps=0x%x", nfss->caps);
Chuck Lever2d767432008-03-14 14:10:08 -0400770 seq_printf(m, ",wtmult=%u", nfss->wtmult);
771 seq_printf(m, ",dtsize=%u", nfss->dtsize);
772 seq_printf(m, ",bsize=%u", nfss->bsize);
773 seq_printf(m, ",namlen=%u", nfss->namelen);
David Howellsf7b422b2006-06-09 09:34:33 -0400774
775#ifdef CONFIG_NFS_V4
Trond Myklebust40c553192007-12-14 14:56:07 -0500776 if (nfss->nfs_client->rpc_ops->version == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400777 seq_printf(m, "\n\tnfsv4:\t");
778 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
779 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
780 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300781 show_sessions(m, nfss);
782 show_pnfs(m, nfss);
David Howellsf7b422b2006-06-09 09:34:33 -0400783 }
784#endif
785
786 /*
787 * Display security flavor in effect for this mount
788 */
Chuck Lever2d767432008-03-14 14:10:08 -0400789 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400790 if (auth->au_flavor)
Chuck Lever2d767432008-03-14 14:10:08 -0400791 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400792
793 /*
794 * Display superblock I/O counters
795 */
796 for_each_possible_cpu(cpu) {
797 struct nfs_iostats *stats;
798
799 preempt_disable();
800 stats = per_cpu_ptr(nfss->io_stats, cpu);
801
802 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
803 totals.events[i] += stats->events[i];
804 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
805 totals.bytes[i] += stats->bytes[i];
David Howells6a510912009-04-03 16:42:43 +0100806#ifdef CONFIG_NFS_FSCACHE
807 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
808 totals.fscache[i] += stats->fscache[i];
809#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400810
811 preempt_enable();
812 }
813
814 seq_printf(m, "\n\tevents:\t");
815 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
816 seq_printf(m, "%lu ", totals.events[i]);
817 seq_printf(m, "\n\tbytes:\t");
818 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
819 seq_printf(m, "%Lu ", totals.bytes[i]);
David Howells6a510912009-04-03 16:42:43 +0100820#ifdef CONFIG_NFS_FSCACHE
821 if (nfss->options & NFS_OPTION_FSCACHE) {
822 seq_printf(m, "\n\tfsc:\t");
823 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
824 seq_printf(m, "%Lu ", totals.bytes[i]);
825 }
826#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400827 seq_printf(m, "\n");
828
829 rpc_print_iostats(m, nfss->client);
830
831 return 0;
832}
833
834/*
835 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400836 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400837 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -0400838void nfs_umount_begin(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -0400839{
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200840 struct nfs_server *server;
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400841 struct rpc_clnt *rpc;
842
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200843 server = NFS_SB(sb);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400844 /* -EIO all pending I/O */
845 rpc = server->client_acl;
846 if (!IS_ERR(rpc))
847 rpc_killall_tasks(rpc);
848 rpc = server->client;
849 if (!IS_ERR(rpc))
850 rpc_killall_tasks(rpc);
David Howellsf7b422b2006-06-09 09:34:33 -0400851}
852
Bryan Schumakerdb833352012-05-10 15:07:38 -0400853static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(void)
Chuck Lever9423a082009-09-23 14:36:38 -0400854{
855 struct nfs_parsed_mount_data *data;
856
857 data = kzalloc(sizeof(*data), GFP_KERNEL);
858 if (data) {
Chuck Lever9423a082009-09-23 14:36:38 -0400859 data->acregmin = NFS_DEF_ACREGMIN;
860 data->acregmax = NFS_DEF_ACREGMAX;
861 data->acdirmin = NFS_DEF_ACDIRMIN;
862 data->acdirmax = NFS_DEF_ACDIRMAX;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400863 data->mount_server.port = NFS_UNSPEC_PORT;
Chuck Lever9423a082009-09-23 14:36:38 -0400864 data->nfs_server.port = NFS_UNSPEC_PORT;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400865 data->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Lever9423a082009-09-23 14:36:38 -0400866 data->auth_flavors[0] = RPC_AUTH_UNIX;
867 data->auth_flavor_len = 1;
868 data->minorversion = 0;
Bryan Schumakerb72e4f42012-05-10 15:07:40 -0400869 data->need_mount = true;
Trond Myklebust9937347a2012-02-19 08:44:07 +0100870 data->net = current->nsproxy->net_ns;
Jeff Layton8a0d5512011-12-20 06:57:45 -0500871 security_init_mnt_opts(&data->lsm_opts);
Chuck Lever9423a082009-09-23 14:36:38 -0400872 }
873 return data;
874}
875
Jeff Layton8a0d5512011-12-20 06:57:45 -0500876static void nfs_free_parsed_mount_data(struct nfs_parsed_mount_data *data)
877{
878 if (data) {
879 kfree(data->client_address);
880 kfree(data->mount_server.hostname);
881 kfree(data->nfs_server.export_path);
882 kfree(data->nfs_server.hostname);
883 kfree(data->fscache_uniq);
884 security_free_mnt_opts(&data->lsm_opts);
885 kfree(data);
886 }
887}
888
David Howellsf7b422b2006-06-09 09:34:33 -0400889/*
Chuck Levercdcd7f92007-12-10 14:57:45 -0500890 * Sanity-check a server address provided by the mount command.
891 *
892 * Address family must be initialized, and address must not be
893 * the ANY address for that family.
Chuck Leverfc50d582007-07-01 12:12:46 -0400894 */
895static int nfs_verify_server_address(struct sockaddr *addr)
896{
897 switch (addr->sa_family) {
898 case AF_INET: {
Chuck Levercdcd7f92007-12-10 14:57:45 -0500899 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
Al Viroe6f1ceb2008-03-17 22:44:53 -0700900 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
Chuck Levercdcd7f92007-12-10 14:57:45 -0500901 }
902 case AF_INET6: {
903 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
904 return !ipv6_addr_any(sa);
Chuck Leverfc50d582007-07-01 12:12:46 -0400905 }
906 }
907
Chuck Lever53a0b9c2009-08-09 15:09:36 -0400908 dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
Chuck Leverfc50d582007-07-01 12:12:46 -0400909 return 0;
910}
911
Chuck Lever9412b922007-12-10 14:59:21 -0500912/*
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400913 * Select between a default port value and a user-specified port value.
914 * If a zero value is set, then autobind will be used.
915 */
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400916static void nfs_set_port(struct sockaddr *sap, int *port,
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400917 const unsigned short default_port)
918{
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400919 if (*port == NFS_UNSPEC_PORT)
920 *port = default_port;
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400921
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400922 rpc_set_port(sap, *port);
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400923}
924
925/*
Trond Myklebust259875e2008-07-02 14:43:47 -0400926 * Sanity check the NFS transport protocol.
927 *
928 */
929static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
930{
931 switch (mnt->nfs_server.protocol) {
932 case XPRT_TRANSPORT_UDP:
933 case XPRT_TRANSPORT_TCP:
934 case XPRT_TRANSPORT_RDMA:
935 break;
936 default:
937 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
938 }
939}
940
941/*
942 * For text based NFSv2/v3 mounts, the mount protocol transport default
943 * settings should depend upon the specified NFS transport.
944 */
945static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
946{
947 nfs_validate_transport_protocol(mnt);
948
949 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
950 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
951 return;
952 switch (mnt->nfs_server.protocol) {
953 case XPRT_TRANSPORT_UDP:
954 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
955 break;
956 case XPRT_TRANSPORT_TCP:
957 case XPRT_TRANSPORT_RDMA:
958 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
959 }
960}
961
962/*
Chuck Lever01060c82008-06-24 16:33:38 -0400963 * Parse the value of the 'sec=' option.
Chuck Lever01060c82008-06-24 16:33:38 -0400964 */
965static int nfs_parse_security_flavors(char *value,
966 struct nfs_parsed_mount_data *mnt)
967{
968 substring_t args[MAX_OPT_ARGS];
969
970 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
971
972 switch (match_token(value, nfs_secflavor_tokens, args)) {
973 case Opt_sec_none:
Chuck Lever01060c82008-06-24 16:33:38 -0400974 mnt->auth_flavors[0] = RPC_AUTH_NULL;
975 break;
976 case Opt_sec_sys:
Chuck Lever01060c82008-06-24 16:33:38 -0400977 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
978 break;
979 case Opt_sec_krb5:
Chuck Lever01060c82008-06-24 16:33:38 -0400980 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
981 break;
982 case Opt_sec_krb5i:
Chuck Lever01060c82008-06-24 16:33:38 -0400983 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
984 break;
985 case Opt_sec_krb5p:
Chuck Lever01060c82008-06-24 16:33:38 -0400986 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
987 break;
988 case Opt_sec_lkey:
Chuck Lever01060c82008-06-24 16:33:38 -0400989 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
990 break;
991 case Opt_sec_lkeyi:
Chuck Lever01060c82008-06-24 16:33:38 -0400992 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
993 break;
994 case Opt_sec_lkeyp:
Chuck Lever01060c82008-06-24 16:33:38 -0400995 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
996 break;
997 case Opt_sec_spkm:
Chuck Lever01060c82008-06-24 16:33:38 -0400998 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
999 break;
1000 case Opt_sec_spkmi:
Chuck Lever01060c82008-06-24 16:33:38 -04001001 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
1002 break;
1003 case Opt_sec_spkmp:
Chuck Lever01060c82008-06-24 16:33:38 -04001004 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
1005 break;
1006 default:
1007 return 0;
1008 }
1009
Bryan Schumaker9b7160c2011-04-13 14:31:30 -04001010 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
Chuck Lever059f90b2009-08-09 15:09:31 -04001011 mnt->auth_flavor_len = 1;
Chuck Lever01060c82008-06-24 16:33:38 -04001012 return 1;
1013}
1014
Trond Myklebust0d71b052012-03-02 13:59:49 -05001015static int nfs_parse_version_string(char *string,
1016 struct nfs_parsed_mount_data *mnt,
1017 substring_t *args)
1018{
1019 mnt->flags &= ~NFS_MOUNT_VER3;
1020 switch (match_token(string, nfs_vers_tokens, args)) {
1021 case Opt_vers_2:
1022 mnt->version = 2;
1023 break;
1024 case Opt_vers_3:
1025 mnt->flags |= NFS_MOUNT_VER3;
1026 mnt->version = 3;
1027 break;
1028 case Opt_vers_4:
1029 /* Backward compatibility option. In future,
1030 * the mount program should always supply
1031 * a NFSv4 minor version number.
1032 */
1033 mnt->version = 4;
1034 break;
1035 case Opt_vers_4_0:
1036 mnt->version = 4;
1037 mnt->minorversion = 0;
1038 break;
1039 case Opt_vers_4_1:
1040 mnt->version = 4;
1041 mnt->minorversion = 1;
1042 break;
1043 default:
1044 return 0;
1045 }
1046 return 1;
1047}
1048
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001049static int nfs_get_option_str(substring_t args[], char **option)
1050{
1051 kfree(*option);
1052 *option = match_strdup(args);
1053 return !option;
1054}
1055
1056static int nfs_get_option_ul(substring_t args[], unsigned long *option)
1057{
1058 int rc;
1059 char *string;
1060
1061 string = match_strdup(args);
1062 if (string == NULL)
1063 return -ENOMEM;
1064 rc = strict_strtoul(string, 10, option);
1065 kfree(string);
1066
1067 return rc;
1068}
1069
Chuck Lever01060c82008-06-24 16:33:38 -04001070/*
Chuck Leverbf0fd762007-07-01 12:13:44 -04001071 * Error-check and convert a string of mount options from user space into
Chuck Leverf45663c2008-06-24 19:28:02 -04001072 * a data structure. The whole mount string is processed; bad options are
1073 * skipped as they are encountered. If there were no errors, return 1;
1074 * otherwise return 0 (zero).
Chuck Leverbf0fd762007-07-01 12:13:44 -04001075 */
1076static int nfs_parse_mount_options(char *raw,
1077 struct nfs_parsed_mount_data *mnt)
1078{
Eric Parisf9c3a382008-03-05 14:20:18 -05001079 char *p, *string, *secdata;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001080 int rc, sloppy = 0, invalid_option = 0;
Jeff Laytonee671b02009-12-03 15:58:56 -05001081 unsigned short protofamily = AF_UNSPEC;
1082 unsigned short mountfamily = AF_UNSPEC;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001083
1084 if (!raw) {
1085 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
1086 return 1;
1087 }
1088 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
1089
Eric Parisf9c3a382008-03-05 14:20:18 -05001090 secdata = alloc_secdata();
1091 if (!secdata)
1092 goto out_nomem;
1093
1094 rc = security_sb_copy_data(raw, secdata);
1095 if (rc)
1096 goto out_security_failure;
1097
1098 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
1099 if (rc)
1100 goto out_security_failure;
1101
1102 free_secdata(secdata);
1103
Chuck Leverbf0fd762007-07-01 12:13:44 -04001104 while ((p = strsep(&raw, ",")) != NULL) {
1105 substring_t args[MAX_OPT_ARGS];
Chuck Levera5a16ba2009-06-17 18:02:14 -07001106 unsigned long option;
1107 int token;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001108
1109 if (!*p)
1110 continue;
1111
1112 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
1113
1114 token = match_token(p, nfs_mount_option_tokens, args);
1115 switch (token) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001116
1117 /*
1118 * boolean options: foo/nofoo
1119 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001120 case Opt_soft:
1121 mnt->flags |= NFS_MOUNT_SOFT;
1122 break;
1123 case Opt_hard:
1124 mnt->flags &= ~NFS_MOUNT_SOFT;
1125 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001126 case Opt_posix:
1127 mnt->flags |= NFS_MOUNT_POSIX;
1128 break;
1129 case Opt_noposix:
1130 mnt->flags &= ~NFS_MOUNT_POSIX;
1131 break;
1132 case Opt_cto:
1133 mnt->flags &= ~NFS_MOUNT_NOCTO;
1134 break;
1135 case Opt_nocto:
1136 mnt->flags |= NFS_MOUNT_NOCTO;
1137 break;
1138 case Opt_ac:
1139 mnt->flags &= ~NFS_MOUNT_NOAC;
1140 break;
1141 case Opt_noac:
1142 mnt->flags |= NFS_MOUNT_NOAC;
1143 break;
1144 case Opt_lock:
1145 mnt->flags &= ~NFS_MOUNT_NONLM;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001146 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1147 NFS_MOUNT_LOCAL_FCNTL);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001148 break;
1149 case Opt_nolock:
1150 mnt->flags |= NFS_MOUNT_NONLM;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001151 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1152 NFS_MOUNT_LOCAL_FCNTL);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001153 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001154 case Opt_udp:
1155 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001156 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001157 break;
1158 case Opt_tcp:
1159 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001160 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001161 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001162 case Opt_rdma:
1163 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1164 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001165 xprt_load_transport(p);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001166 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001167 case Opt_acl:
1168 mnt->flags &= ~NFS_MOUNT_NOACL;
1169 break;
1170 case Opt_noacl:
1171 mnt->flags |= NFS_MOUNT_NOACL;
1172 break;
1173 case Opt_rdirplus:
1174 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1175 break;
1176 case Opt_nordirplus:
1177 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1178 break;
Trond Myklebust75180df2007-05-16 16:53:28 -04001179 case Opt_sharecache:
1180 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1181 break;
1182 case Opt_nosharecache:
1183 mnt->flags |= NFS_MOUNT_UNSHARED;
1184 break;
Chuck Leverd7403512008-12-23 15:21:37 -05001185 case Opt_resvport:
1186 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1187 break;
1188 case Opt_noresvport:
1189 mnt->flags |= NFS_MOUNT_NORESVPORT;
1190 break;
David Howellsb797cac2009-04-03 16:42:48 +01001191 case Opt_fscache:
1192 mnt->options |= NFS_OPTION_FSCACHE;
1193 kfree(mnt->fscache_uniq);
1194 mnt->fscache_uniq = NULL;
1195 break;
1196 case Opt_nofscache:
1197 mnt->options &= ~NFS_OPTION_FSCACHE;
1198 kfree(mnt->fscache_uniq);
1199 mnt->fscache_uniq = NULL;
1200 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001201
Chuck Leverf45663c2008-06-24 19:28:02 -04001202 /*
1203 * options that take numeric values
1204 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001205 case Opt_port:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001206 if (nfs_get_option_ul(args, &option) ||
1207 option > USHRT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001208 goto out_invalid_value;
1209 mnt->nfs_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001210 break;
1211 case Opt_rsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001212 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001213 goto out_invalid_value;
1214 mnt->rsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001215 break;
1216 case Opt_wsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001217 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001218 goto out_invalid_value;
1219 mnt->wsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001220 break;
1221 case Opt_bsize:
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->bsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001225 break;
1226 case Opt_timeo:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001227 if (nfs_get_option_ul(args, &option) || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001228 goto out_invalid_value;
1229 mnt->timeo = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001230 break;
1231 case Opt_retrans:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001232 if (nfs_get_option_ul(args, &option) || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001233 goto out_invalid_value;
1234 mnt->retrans = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001235 break;
1236 case Opt_acregmin:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001237 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001238 goto out_invalid_value;
1239 mnt->acregmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001240 break;
1241 case Opt_acregmax:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001242 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001243 goto out_invalid_value;
1244 mnt->acregmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001245 break;
1246 case Opt_acdirmin:
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->acdirmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001250 break;
1251 case Opt_acdirmax:
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->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001255 break;
1256 case Opt_actimeo:
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->acregmin = mnt->acregmax =
1260 mnt->acdirmin = mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001261 break;
1262 case Opt_namelen:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001263 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001264 goto out_invalid_value;
1265 mnt->namlen = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001266 break;
1267 case Opt_mountport:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001268 if (nfs_get_option_ul(args, &option) ||
1269 option > USHRT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001270 goto out_invalid_value;
1271 mnt->mount_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001272 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001273 case Opt_mountvers:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001274 if (nfs_get_option_ul(args, &option) ||
Chuck Leverf45663c2008-06-24 19:28:02 -04001275 option < NFS_MNT_VERSION ||
Chuck Leverd23c45f2009-06-17 18:02:13 -07001276 option > NFS_MNT3_VERSION)
1277 goto out_invalid_value;
1278 mnt->mount_server.version = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001279 break;
Mike Sager3fd5be92009-04-01 09:21:48 -04001280 case Opt_minorversion:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001281 if (nfs_get_option_ul(args, &option))
Chuck Leverf3f4f4e2009-08-09 15:09:29 -04001282 goto out_invalid_value;
1283 if (option > NFS4_MAX_MINOR_VERSION)
1284 goto out_invalid_value;
1285 mnt->minorversion = option;
Mike Sager3fd5be92009-04-01 09:21:48 -04001286 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001287
Chuck Leverf45663c2008-06-24 19:28:02 -04001288 /*
1289 * options that take text values
1290 */
Trond Myklebust0d71b052012-03-02 13:59:49 -05001291 case Opt_nfsvers:
1292 string = match_strdup(args);
1293 if (string == NULL)
1294 goto out_nomem;
1295 rc = nfs_parse_version_string(string, mnt, args);
1296 kfree(string);
1297 if (!rc)
1298 goto out_invalid_value;
1299 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001300 case Opt_sec:
1301 string = match_strdup(args);
1302 if (string == NULL)
1303 goto out_nomem;
Chuck Lever01060c82008-06-24 16:33:38 -04001304 rc = nfs_parse_security_flavors(string, mnt);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001305 kfree(string);
Chuck Leverf45663c2008-06-24 19:28:02 -04001306 if (!rc) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001307 dfprintk(MOUNT, "NFS: unrecognized "
1308 "security flavor\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001309 return 0;
Chuck Leverf45663c2008-06-24 19:28:02 -04001310 }
Chuck Leverbf0fd762007-07-01 12:13:44 -04001311 break;
1312 case Opt_proto:
1313 string = match_strdup(args);
1314 if (string == NULL)
1315 goto out_nomem;
1316 token = match_token(string,
1317 nfs_xprt_protocol_tokens, args);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001318
Jeff Laytonee671b02009-12-03 15:58:56 -05001319 protofamily = AF_INET;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001320 switch (token) {
Jeff Laytonee671b02009-12-03 15:58:56 -05001321 case Opt_xprt_udp6:
1322 protofamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001323 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001324 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001325 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001326 break;
Jeff Laytonee671b02009-12-03 15:58:56 -05001327 case Opt_xprt_tcp6:
1328 protofamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001329 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001330 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001331 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001332 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001333 case Opt_xprt_rdma:
1334 /* vector side protocols to TCP */
1335 mnt->flags |= NFS_MOUNT_TCP;
1336 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001337 xprt_load_transport(string);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001338 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001339 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001340 dfprintk(MOUNT, "NFS: unrecognized "
1341 "transport protocol\n");
Yinghai Lu4223a4a2009-10-20 14:13:46 +09001342 kfree(string);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001343 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001344 }
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001345 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001346 break;
1347 case Opt_mountproto:
1348 string = match_strdup(args);
1349 if (string == NULL)
1350 goto out_nomem;
1351 token = match_token(string,
1352 nfs_xprt_protocol_tokens, args);
Trond Myklebustd508afb2009-04-06 16:41:35 -07001353 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001354
Jeff Laytonee671b02009-12-03 15:58:56 -05001355 mountfamily = AF_INET;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001356 switch (token) {
Jeff Laytonee671b02009-12-03 15:58:56 -05001357 case Opt_xprt_udp6:
1358 mountfamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001359 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001360 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001361 break;
Jeff Laytonee671b02009-12-03 15:58:56 -05001362 case Opt_xprt_tcp6:
1363 mountfamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001364 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001365 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001366 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001367 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001368 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001369 dfprintk(MOUNT, "NFS: unrecognized "
1370 "transport protocol\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001371 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001372 }
1373 break;
1374 case Opt_addr:
1375 string = match_strdup(args);
1376 if (string == NULL)
1377 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001378 mnt->nfs_server.addrlen =
Stanislav Kinsburskyb48e1272012-01-26 15:11:57 +04001379 rpc_pton(mnt->net, string, strlen(string),
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001380 (struct sockaddr *)
1381 &mnt->nfs_server.address,
1382 sizeof(mnt->nfs_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001383 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001384 if (mnt->nfs_server.addrlen == 0)
1385 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001386 break;
1387 case Opt_clientaddr:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001388 if (nfs_get_option_str(args, &mnt->client_address))
Chuck Leverbf0fd762007-07-01 12:13:44 -04001389 goto out_nomem;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001390 break;
Chuck Lever33832032007-12-10 14:59:13 -05001391 case Opt_mounthost:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001392 if (nfs_get_option_str(args,
1393 &mnt->mount_server.hostname))
Chuck Lever33832032007-12-10 14:59:13 -05001394 goto out_nomem;
Chuck Lever33832032007-12-10 14:59:13 -05001395 break;
Chuck Lever0ac83772007-09-11 18:01:04 -04001396 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001397 string = match_strdup(args);
1398 if (string == NULL)
1399 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001400 mnt->mount_server.addrlen =
Stanislav Kinsburskyb48e1272012-01-26 15:11:57 +04001401 rpc_pton(mnt->net, string, strlen(string),
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001402 (struct sockaddr *)
1403 &mnt->mount_server.address,
1404 sizeof(mnt->mount_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001405 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001406 if (mnt->mount_server.addrlen == 0)
1407 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001408 break;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001409 case Opt_lookupcache:
1410 string = match_strdup(args);
1411 if (string == NULL)
1412 goto out_nomem;
1413 token = match_token(string,
1414 nfs_lookupcache_tokens, args);
1415 kfree(string);
1416 switch (token) {
1417 case Opt_lookupcache_all:
1418 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1419 break;
1420 case Opt_lookupcache_positive:
1421 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1422 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1423 break;
1424 case Opt_lookupcache_none:
1425 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1426 break;
1427 default:
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001428 dfprintk(MOUNT, "NFS: invalid "
1429 "lookupcache argument\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001430 return 0;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001431 };
1432 break;
Chuck Levera6d5ff62010-05-07 13:33:58 -04001433 case Opt_fscache_uniq:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001434 if (nfs_get_option_str(args, &mnt->fscache_uniq))
Chuck Levera6d5ff62010-05-07 13:33:58 -04001435 goto out_nomem;
Chuck Levera6d5ff62010-05-07 13:33:58 -04001436 mnt->options |= NFS_OPTION_FSCACHE;
1437 break;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001438 case Opt_local_lock:
1439 string = match_strdup(args);
1440 if (string == NULL)
1441 goto out_nomem;
1442 token = match_token(string, nfs_local_lock_tokens,
1443 args);
1444 kfree(string);
1445 switch (token) {
1446 case Opt_local_lock_all:
1447 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1448 NFS_MOUNT_LOCAL_FCNTL);
1449 break;
1450 case Opt_local_lock_flock:
1451 mnt->flags |= NFS_MOUNT_LOCAL_FLOCK;
1452 break;
1453 case Opt_local_lock_posix:
1454 mnt->flags |= NFS_MOUNT_LOCAL_FCNTL;
1455 break;
1456 case Opt_local_lock_none:
1457 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1458 NFS_MOUNT_LOCAL_FCNTL);
1459 break;
1460 default:
1461 dfprintk(MOUNT, "NFS: invalid "
1462 "local_lock argument\n");
1463 return 0;
1464 };
1465 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001466
Chuck Leverf45663c2008-06-24 19:28:02 -04001467 /*
1468 * Special options
1469 */
1470 case Opt_sloppy:
1471 sloppy = 1;
1472 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1473 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001474 case Opt_userspace:
1475 case Opt_deprecated:
Chuck Leverd33e4df2008-06-12 12:37:41 -04001476 dfprintk(MOUNT, "NFS: ignoring mount option "
1477 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001478 break;
1479
1480 default:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001481 invalid_option = 1;
Chuck Leverf45663c2008-06-24 19:28:02 -04001482 dfprintk(MOUNT, "NFS: unrecognized mount option "
1483 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001484 }
1485 }
1486
Chuck Leverd23c45f2009-06-17 18:02:13 -07001487 if (!sloppy && invalid_option)
1488 return 0;
1489
Weston Andros Adamson571b7552012-02-01 14:06:41 -05001490 if (mnt->minorversion && mnt->version != 4)
1491 goto out_minorversion_mismatch;
1492
Jeff Laytonee671b02009-12-03 15:58:56 -05001493 /*
1494 * verify that any proto=/mountproto= options match the address
1495 * familiies in the addr=/mountaddr= options.
1496 */
1497 if (protofamily != AF_UNSPEC &&
1498 protofamily != mnt->nfs_server.address.ss_family)
1499 goto out_proto_mismatch;
1500
1501 if (mountfamily != AF_UNSPEC) {
1502 if (mnt->mount_server.addrlen) {
1503 if (mountfamily != mnt->mount_server.address.ss_family)
1504 goto out_mountproto_mismatch;
1505 } else {
1506 if (mountfamily != mnt->nfs_server.address.ss_family)
1507 goto out_mountproto_mismatch;
1508 }
1509 }
1510
Chuck Leverbf0fd762007-07-01 12:13:44 -04001511 return 1;
1512
Jeff Laytonee671b02009-12-03 15:58:56 -05001513out_mountproto_mismatch:
1514 printk(KERN_INFO "NFS: mount server address does not match mountproto= "
1515 "option\n");
1516 return 0;
1517out_proto_mismatch:
1518 printk(KERN_INFO "NFS: server address does not match proto= option\n");
1519 return 0;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001520out_invalid_address:
1521 printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
1522 return 0;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001523out_invalid_value:
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001524 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001525 return 0;
Weston Andros Adamson571b7552012-02-01 14:06:41 -05001526out_minorversion_mismatch:
1527 printk(KERN_INFO "NFS: mount option vers=%u does not support "
1528 "minorversion=%u\n", mnt->version, mnt->minorversion);
1529 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001530out_nomem:
1531 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1532 return 0;
Eric Parisf9c3a382008-03-05 14:20:18 -05001533out_security_failure:
1534 free_secdata(secdata);
1535 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1536 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001537}
1538
1539/*
Chuck Leverec88f282009-08-09 15:09:32 -04001540 * Match the requested auth flavors with the list returned by
1541 * the server. Returns zero and sets the mount's authentication
1542 * flavor on success; returns -EACCES if server does not support
1543 * the requested flavor.
1544 */
1545static int nfs_walk_authlist(struct nfs_parsed_mount_data *args,
1546 struct nfs_mount_request *request)
1547{
1548 unsigned int i, j, server_authlist_len = *(request->auth_flav_len);
1549
1550 /*
Chuck Lever5eecfde2009-08-21 17:50:30 -04001551 * Certain releases of Linux's mountd return an empty
1552 * flavor list. To prevent behavioral regression with
1553 * these servers (ie. rejecting mounts that used to
1554 * succeed), revert to pre-2.6.32 behavior (no checking)
1555 * if the returned flavor list is empty.
1556 */
1557 if (server_authlist_len == 0)
1558 return 0;
1559
1560 /*
Chuck Leverec88f282009-08-09 15:09:32 -04001561 * We avoid sophisticated negotiating here, as there are
1562 * plenty of cases where we can get it wrong, providing
1563 * either too little or too much security.
1564 *
1565 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1566 * flavor listed first. However, some servers list
1567 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1568 * preferred default, in args->auth_flavors[0] if user
1569 * didn't specify sec= mount option.
1570 */
1571 for (i = 0; i < args->auth_flavor_len; i++)
1572 for (j = 0; j < server_authlist_len; j++)
1573 if (args->auth_flavors[i] == request->auth_flavs[j]) {
1574 dfprintk(MOUNT, "NFS: using auth flavor %d\n",
1575 request->auth_flavs[j]);
1576 args->auth_flavors[0] = request->auth_flavs[j];
1577 return 0;
1578 }
1579
1580 dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n");
1581 nfs_umount(request);
1582 return -EACCES;
1583}
1584
1585/*
Chuck Lever0076d7b2007-07-01 12:13:49 -04001586 * Use the remote server's MOUNT service to request the NFS file handle
1587 * corresponding to the provided path.
1588 */
Bryan Schumaker486aa692012-05-10 15:07:39 -04001589static int nfs_request_mount(struct nfs_parsed_mount_data *args,
1590 struct nfs_fh *root_fh)
Chuck Lever0076d7b2007-07-01 12:13:49 -04001591{
Chuck Leverec88f282009-08-09 15:09:32 -04001592 rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS];
1593 unsigned int server_authlist_len = ARRAY_SIZE(server_authlist);
Chuck Leverc5d120f2008-12-23 15:21:35 -05001594 struct nfs_mount_request request = {
1595 .sap = (struct sockaddr *)
1596 &args->mount_server.address,
1597 .dirpath = args->nfs_server.export_path,
1598 .protocol = args->mount_server.protocol,
1599 .fh = root_fh,
Chuck Lever50a737f2008-12-23 15:21:37 -05001600 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
Chuck Leverec88f282009-08-09 15:09:32 -04001601 .auth_flav_len = &server_authlist_len,
1602 .auth_flavs = server_authlist,
Stanislav Kinsbursky6d59b8d2012-01-10 16:12:54 +04001603 .net = args->net,
Chuck Leverc5d120f2008-12-23 15:21:35 -05001604 };
Chuck Lever4c568012007-12-10 14:59:28 -05001605 int status;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001606
1607 if (args->mount_server.version == 0) {
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001608 switch (args->version) {
1609 default:
1610 args->mount_server.version = NFS_MNT3_VERSION;
1611 break;
1612 case 2:
1613 args->mount_server.version = NFS_MNT_VERSION;
1614 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001615 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001616 request.version = args->mount_server.version;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001617
Chuck Lever33832032007-12-10 14:59:13 -05001618 if (args->mount_server.hostname)
Chuck Leverc5d120f2008-12-23 15:21:35 -05001619 request.hostname = args->mount_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001620 else
Chuck Leverc5d120f2008-12-23 15:21:35 -05001621 request.hostname = args->nfs_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001622
Chuck Lever0076d7b2007-07-01 12:13:49 -04001623 /*
1624 * Construct the mount server's address.
1625 */
Chuck Lever4c568012007-12-10 14:59:28 -05001626 if (args->mount_server.address.ss_family == AF_UNSPEC) {
Chuck Leverc5d120f2008-12-23 15:21:35 -05001627 memcpy(request.sap, &args->nfs_server.address,
Chuck Lever4c568012007-12-10 14:59:28 -05001628 args->nfs_server.addrlen);
1629 args->mount_server.addrlen = args->nfs_server.addrlen;
1630 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001631 request.salen = args->mount_server.addrlen;
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001632 nfs_set_port(request.sap, &args->mount_server.port, 0);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001633
1634 /*
1635 * Now ask the mount server to map our export path
1636 * to a file handle.
1637 */
Chuck Leverc5d120f2008-12-23 15:21:35 -05001638 status = nfs_mount(&request);
Chuck Leverec88f282009-08-09 15:09:32 -04001639 if (status != 0) {
1640 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1641 request.hostname, status);
1642 return status;
1643 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001644
Chuck Leverec88f282009-08-09 15:09:32 -04001645 /*
1646 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1647 */
1648 if (args->mount_server.version != NFS_MNT3_VERSION)
1649 return 0;
1650 return nfs_walk_authlist(args, &request);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001651}
1652
Bryan Schumakerff9099f22012-07-30 16:05:18 -04001653struct dentry *nfs_try_mount(int flags, const char *dev_name,
1654 struct nfs_mount_info *mount_info,
1655 struct nfs_subversion *nfs_mod)
Bryan Schumaker486aa692012-05-10 15:07:39 -04001656{
1657 int status;
1658 struct nfs_server *server;
1659
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04001660 if (mount_info->parsed->need_mount) {
Bryan Schumaker87c70832012-05-10 15:07:43 -04001661 status = nfs_request_mount(mount_info->parsed, mount_info->mntfh);
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04001662 if (status)
1663 return ERR_PTR(status);
1664 }
Bryan Schumaker486aa692012-05-10 15:07:39 -04001665
1666 /* Get a volume representation */
Bryan Schumakerab7017a2012-07-30 16:05:16 -04001667 server = nfs_create_server(mount_info->parsed, mount_info->mntfh, nfs_mod);
Bryan Schumaker486aa692012-05-10 15:07:39 -04001668 if (IS_ERR(server))
1669 return ERR_CAST(server);
1670
Bryan Schumakerab7017a2012-07-30 16:05:16 -04001671 return nfs_fs_mount_common(server, flags, dev_name, mount_info, nfs_mod);
Bryan Schumaker486aa692012-05-10 15:07:39 -04001672}
1673
Rob Landleyc12bace2011-03-09 15:54:13 -06001674/*
1675 * Split "dev_name" into "hostname:export_path".
1676 *
1677 * The leftmost colon demarks the split between the server's hostname
1678 * and the export path. If the hostname starts with a left square
1679 * bracket, then it may contain colons.
1680 *
1681 * Note: caller frees hostname and export path, even on error.
1682 */
1683static int nfs_parse_devname(const char *dev_name,
1684 char **hostname, size_t maxnamlen,
1685 char **export_path, size_t maxpathlen)
Chuck Leverdc045892008-06-23 12:36:37 -04001686{
1687 size_t len;
Rob Landleyc12bace2011-03-09 15:54:13 -06001688 char *end;
Chuck Leverdc045892008-06-23 12:36:37 -04001689
Rob Landleyc12bace2011-03-09 15:54:13 -06001690 /* Is the host name protected with square brakcets? */
1691 if (*dev_name == '[') {
1692 end = strchr(++dev_name, ']');
1693 if (end == NULL || end[1] != ':')
1694 goto out_bad_devname;
Chuck Leverdc045892008-06-23 12:36:37 -04001695
Rob Landleyc12bace2011-03-09 15:54:13 -06001696 len = end - dev_name;
1697 end++;
1698 } else {
1699 char *comma;
1700
1701 end = strchr(dev_name, ':');
1702 if (end == NULL)
1703 goto out_bad_devname;
1704 len = end - dev_name;
1705
1706 /* kill possible hostname list: not supported */
1707 comma = strchr(dev_name, ',');
1708 if (comma != NULL && comma < end)
1709 *comma = 0;
1710 }
1711
Chuck Leverdc045892008-06-23 12:36:37 -04001712 if (len > maxnamlen)
1713 goto out_hostname;
1714
1715 /* N.B. caller will free nfs_server.hostname in all cases */
1716 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
Rob Landleyc12bace2011-03-09 15:54:13 -06001717 if (*hostname == NULL)
Chuck Leverdc045892008-06-23 12:36:37 -04001718 goto out_nomem;
Rob Landleyc12bace2011-03-09 15:54:13 -06001719 len = strlen(++end);
Chuck Leverdc045892008-06-23 12:36:37 -04001720 if (len > maxpathlen)
1721 goto out_path;
Rob Landleyc12bace2011-03-09 15:54:13 -06001722 *export_path = kstrndup(end, len, GFP_KERNEL);
Chuck Leverdc045892008-06-23 12:36:37 -04001723 if (!*export_path)
1724 goto out_nomem;
1725
1726 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1727 return 0;
1728
1729out_bad_devname:
1730 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1731 return -EINVAL;
1732
1733out_nomem:
1734 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1735 return -ENOMEM;
1736
1737out_hostname:
1738 dfprintk(MOUNT, "NFS: server hostname too long\n");
1739 return -ENAMETOOLONG;
1740
1741out_path:
1742 dfprintk(MOUNT, "NFS: export pathname too long\n");
1743 return -ENAMETOOLONG;
1744}
1745
1746/*
David Howells54ceac42006-08-22 20:06:13 -04001747 * Validate the NFS2/NFS3 mount data
1748 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001749 *
1750 * For option strings, user space handles the following behaviors:
1751 *
1752 * + DNS: mapping server host name to IP address ("addr=" option)
1753 *
1754 * + failure mode: how to behave if a mount request can't be handled
1755 * immediately ("fg/bg" option)
1756 *
1757 * + retry: how often to retry a mount request ("retry=" option)
1758 *
1759 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1760 * mountproto=tcp after mountproto=udp, and so on
David Howellsf7b422b2006-06-09 09:34:33 -04001761 */
Bryan Schumakerd72c7272012-05-10 15:07:41 -04001762static int nfs23_validate_mount_data(void *options,
1763 struct nfs_parsed_mount_data *args,
1764 struct nfs_fh *mntfh,
1765 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001766{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001767 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001768 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
Chuck Lever136d5582007-07-01 12:13:54 -04001769
Chuck Lever5df36e72007-07-01 12:12:56 -04001770 if (data == NULL)
1771 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001772
Bryan Schumakerc5afc8d2012-06-08 11:32:56 -04001773 args->version = NFS_DEFAULT_VERSION;
David Howellsf7b422b2006-06-09 09:34:33 -04001774 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001775 case 1:
1776 data->namlen = 0;
1777 case 2:
1778 data->bsize = 0;
1779 case 3:
1780 if (data->flags & NFS_MOUNT_VER3)
1781 goto out_no_v3;
1782 data->root.size = NFS2_FHSIZE;
1783 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1784 case 4:
1785 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1786 goto out_no_sec;
1787 case 5:
1788 memset(data->context, 0, sizeof(data->context));
1789 case 6:
Trond Myklebustb7e24452008-06-19 15:21:11 -04001790 if (data->flags & NFS_MOUNT_VER3) {
1791 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1792 goto out_invalid_fh;
Chuck Lever5df36e72007-07-01 12:12:56 -04001793 mntfh->size = data->root.size;
Chuck Lever764302c2009-09-08 19:50:03 -04001794 args->version = 3;
1795 } else {
Chuck Lever5df36e72007-07-01 12:12:56 -04001796 mntfh->size = NFS2_FHSIZE;
Chuck Lever764302c2009-09-08 19:50:03 -04001797 args->version = 2;
1798 }
Chuck Lever5df36e72007-07-01 12:12:56 -04001799
Chuck Lever5df36e72007-07-01 12:12:56 -04001800
1801 memcpy(mntfh->data, data->root.data, mntfh->size);
1802 if (mntfh->size < sizeof(mntfh->data))
1803 memset(mntfh->data + mntfh->size, 0,
1804 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001805
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001806 /*
1807 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1808 * can deal with.
1809 */
Trond Myklebustff3525a2008-08-15 16:59:14 -04001810 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
Bryan Schumakerd5eff1a2010-08-03 13:04:00 -04001811 args->flags |= NFS_MOUNT_LEGACY_INTERFACE;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001812 args->rsize = data->rsize;
1813 args->wsize = data->wsize;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001814 args->timeo = data->timeo;
1815 args->retrans = data->retrans;
1816 args->acregmin = data->acregmin;
1817 args->acregmax = data->acregmax;
1818 args->acdirmin = data->acdirmin;
1819 args->acdirmax = data->acdirmax;
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04001820 args->need_mount = false;
Chuck Lever4c568012007-12-10 14:59:28 -05001821
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001822 memcpy(sap, &data->addr, sizeof(data->addr));
Chuck Lever4c568012007-12-10 14:59:28 -05001823 args->nfs_server.addrlen = sizeof(data->addr);
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001824 if (!nfs_verify_server_address(sap))
Chuck Lever4c568012007-12-10 14:59:28 -05001825 goto out_no_address;
1826
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001827 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001828 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001829 /* N.B. caller will free nfs_server.hostname in all cases */
1830 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1831 args->namlen = data->namlen;
1832 args->bsize = data->bsize;
Chuck Leverdd07c942008-06-24 16:33:46 -04001833
1834 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1835 args->auth_flavors[0] = data->pseudoflavor;
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001836 if (!args->nfs_server.hostname)
1837 goto out_nomem;
Eric Parisf9c3a382008-03-05 14:20:18 -05001838
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001839 if (!(data->flags & NFS_MOUNT_NONLM))
1840 args->flags &= ~(NFS_MOUNT_LOCAL_FLOCK|
1841 NFS_MOUNT_LOCAL_FCNTL);
1842 else
1843 args->flags |= (NFS_MOUNT_LOCAL_FLOCK|
1844 NFS_MOUNT_LOCAL_FCNTL);
Eric Parisf9c3a382008-03-05 14:20:18 -05001845 /*
1846 * The legacy version 6 binary mount data from userspace has a
1847 * field used only to transport selinux information into the
1848 * the kernel. To continue to support that functionality we
1849 * have a touch of selinux knowledge here in the NFS code. The
1850 * userspace code converted context=blah to just blah so we are
1851 * converting back to the full string selinux understands.
1852 */
1853 if (data->context[0]){
1854#ifdef CONFIG_SECURITY_SELINUX
1855 int rc;
1856 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1857 if (!opts_str)
1858 return -ENOMEM;
1859 strcpy(opts_str, "context=");
1860 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1861 strcat(opts_str, &data->context[0]);
1862 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1863 kfree(opts_str);
1864 if (rc)
1865 return rc;
1866#else
1867 return -EINVAL;
1868#endif
1869 }
1870
Chuck Lever5df36e72007-07-01 12:12:56 -04001871 break;
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04001872 default:
1873 return NFS_TEXT_DATA;
David Howellsf7b422b2006-06-09 09:34:33 -04001874 }
David Howells54ceac42006-08-22 20:06:13 -04001875
David Howellsf7b422b2006-06-09 09:34:33 -04001876#ifndef CONFIG_NFS_V3
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001877 if (args->version == 3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001878 goto out_v3_not_compiled;
1879#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001880
David Howells54ceac42006-08-22 20:06:13 -04001881 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001882
1883out_no_data:
1884 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1885 return -EINVAL;
1886
1887out_no_v3:
1888 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1889 data->version);
1890 return -EINVAL;
1891
1892out_no_sec:
1893 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1894 return -EINVAL;
1895
Chuck Lever5df36e72007-07-01 12:12:56 -04001896#ifndef CONFIG_NFS_V3
1897out_v3_not_compiled:
1898 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1899 return -EPROTONOSUPPORT;
1900#endif /* !CONFIG_NFS_V3 */
1901
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001902out_nomem:
1903 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
1904 return -ENOMEM;
1905
Chuck Lever5df36e72007-07-01 12:12:56 -04001906out_no_address:
1907 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1908 return -EINVAL;
1909
1910out_invalid_fh:
1911 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1912 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04001913}
1914
Bryan Schumakerd72c7272012-05-10 15:07:41 -04001915#ifdef CONFIG_NFS_V4
1916static int nfs_validate_mount_data(struct file_system_type *fs_type,
1917 void *options,
1918 struct nfs_parsed_mount_data *args,
1919 struct nfs_fh *mntfh,
1920 const char *dev_name)
1921{
1922 if (fs_type == &nfs_fs_type)
1923 return nfs23_validate_mount_data(options, args, mntfh, dev_name);
1924 return nfs4_validate_mount_data(options, args, dev_name);
1925}
1926#else
1927static 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 return nfs23_validate_mount_data(options, args, mntfh, dev_name);
1934}
1935#endif
1936
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04001937static int nfs_validate_text_mount_data(void *options,
1938 struct nfs_parsed_mount_data *args,
1939 const char *dev_name)
1940{
1941 int port = 0;
1942 int max_namelen = PAGE_SIZE;
1943 int max_pathlen = NFS_MAXPATHLEN;
1944 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
1945
1946 if (nfs_parse_mount_options((char *)options, args) == 0)
1947 return -EINVAL;
1948
1949 if (!nfs_verify_server_address(sap))
1950 goto out_no_address;
1951
1952 if (args->version == 4) {
1953#ifdef CONFIG_NFS_V4
1954 port = NFS_PORT;
1955 max_namelen = NFS4_MAXNAMLEN;
1956 max_pathlen = NFS4_MAXPATHLEN;
1957 nfs_validate_transport_protocol(args);
1958 nfs4_validate_mount_flags(args);
1959#else
1960 goto out_v4_not_compiled;
1961#endif /* CONFIG_NFS_V4 */
1962 } else
1963 nfs_set_mount_transport_protocol(args);
1964
1965 nfs_set_port(sap, &args->nfs_server.port, port);
1966
1967 if (args->auth_flavor_len > 1)
1968 goto out_bad_auth;
1969
1970 return nfs_parse_devname(dev_name,
1971 &args->nfs_server.hostname,
1972 max_namelen,
1973 &args->nfs_server.export_path,
1974 max_pathlen);
1975
1976#ifndef CONFIG_NFS_V4
1977out_v4_not_compiled:
1978 dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n");
1979 return -EPROTONOSUPPORT;
1980#endif /* !CONFIG_NFS_V4 */
1981
1982out_no_address:
1983 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1984 return -EINVAL;
1985
1986out_bad_auth:
1987 dfprintk(MOUNT, "NFS: Too many RPC auth flavours specified\n");
1988 return -EINVAL;
1989}
1990
Jeff Layton48b605f2008-06-10 15:38:39 -04001991static int
1992nfs_compare_remount_data(struct nfs_server *nfss,
1993 struct nfs_parsed_mount_data *data)
1994{
1995 if (data->flags != nfss->flags ||
1996 data->rsize != nfss->rsize ||
1997 data->wsize != nfss->wsize ||
1998 data->retrans != nfss->client->cl_timeout->to_retries ||
1999 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
2000 data->acregmin != nfss->acregmin / HZ ||
2001 data->acregmax != nfss->acregmax / HZ ||
2002 data->acdirmin != nfss->acdirmin / HZ ||
2003 data->acdirmax != nfss->acdirmax / HZ ||
2004 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
Trond Myklebustbcd2ea12009-10-06 15:41:22 -04002005 data->nfs_server.port != nfss->port ||
Jeff Layton48b605f2008-06-10 15:38:39 -04002006 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
Stefan Richtera1be9ee2009-10-12 11:26:12 -04002007 !rpc_cmp_addr((struct sockaddr *)&data->nfs_server.address,
2008 (struct sockaddr *)&nfss->nfs_client->cl_addr))
Jeff Layton48b605f2008-06-10 15:38:39 -04002009 return -EINVAL;
2010
2011 return 0;
2012}
2013
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002014int
Jeff Layton48b605f2008-06-10 15:38:39 -04002015nfs_remount(struct super_block *sb, int *flags, char *raw_data)
2016{
2017 int error;
2018 struct nfs_server *nfss = sb->s_fs_info;
2019 struct nfs_parsed_mount_data *data;
2020 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
2021 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
Trond Myklebustcd100722008-06-17 16:12:00 -04002022 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
Jeff Layton48b605f2008-06-10 15:38:39 -04002023
2024 /*
2025 * Userspace mount programs that send binary options generally send
2026 * them populated with default values. We have no way to know which
2027 * ones were explicitly specified. Fall back to legacy behavior and
2028 * just return success.
2029 */
Marc Zyngier31c94462008-07-17 13:21:55 +02002030 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
2031 (nfsvers <= 3 && (!options || (options->version >= 1 &&
2032 options->version <= 6))))
Jeff Layton48b605f2008-06-10 15:38:39 -04002033 return 0;
2034
2035 data = kzalloc(sizeof(*data), GFP_KERNEL);
2036 if (data == NULL)
2037 return -ENOMEM;
2038
2039 /* fill out struct with values from existing mount */
2040 data->flags = nfss->flags;
2041 data->rsize = nfss->rsize;
2042 data->wsize = nfss->wsize;
2043 data->retrans = nfss->client->cl_timeout->to_retries;
2044 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
2045 data->acregmin = nfss->acregmin / HZ;
2046 data->acregmax = nfss->acregmax / HZ;
2047 data->acdirmin = nfss->acdirmin / HZ;
2048 data->acdirmax = nfss->acdirmax / HZ;
2049 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
Trond Myklebustbcd2ea12009-10-06 15:41:22 -04002050 data->nfs_server.port = nfss->port;
Jeff Layton48b605f2008-06-10 15:38:39 -04002051 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
2052 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
2053 data->nfs_server.addrlen);
2054
2055 /* overwrite those values with any that were specified */
2056 error = nfs_parse_mount_options((char *)options, data);
2057 if (error < 0)
2058 goto out;
2059
Jeff Layton26c4c172011-04-27 11:49:09 -04002060 /*
2061 * noac is a special case. It implies -o sync, but that's not
2062 * necessarily reflected in the mtab options. do_remount_sb
2063 * will clear MS_SYNCHRONOUS if -o sync wasn't specified in the
2064 * remount options, so we have to explicitly reset it.
2065 */
2066 if (data->flags & NFS_MOUNT_NOAC)
2067 *flags |= MS_SYNCHRONOUS;
2068
Jeff Layton48b605f2008-06-10 15:38:39 -04002069 /* compare new mount options with old ones */
2070 error = nfs_compare_remount_data(nfss, data);
2071out:
2072 kfree(data);
2073 return error;
2074}
2075
David Howells54ceac42006-08-22 20:06:13 -04002076/*
2077 * Initialise the common bits of the superblock
2078 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002079inline void nfs_initialise_sb(struct super_block *sb)
David Howells54ceac42006-08-22 20:06:13 -04002080{
2081 struct nfs_server *server = NFS_SB(sb);
2082
2083 sb->s_magic = NFS_SUPER_MAGIC;
2084
2085 /* We probably want something more informative here */
2086 snprintf(sb->s_id, sizeof(sb->s_id),
Vivek Trivedi5a7c9ee2012-03-15 23:58:52 +05302087 "%u:%u", MAJOR(sb->s_dev), MINOR(sb->s_dev));
David Howells54ceac42006-08-22 20:06:13 -04002088
2089 if (sb->s_blocksize == 0)
2090 sb->s_blocksize = nfs_block_bits(server->wsize,
2091 &sb->s_blocksize_bits);
2092
Jens Axboe32a88aa2009-09-16 15:02:33 +02002093 sb->s_bdi = &server->backing_dev_info;
2094
David Howells54ceac42006-08-22 20:06:13 -04002095 nfs_super_set_maxbytes(sb, server->maxfilesize);
2096}
2097
2098/*
2099 * Finish setting up an NFS2/3 superblock
2100 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002101void nfs_fill_super(struct super_block *sb, struct nfs_mount_info *mount_info)
David Howells54ceac42006-08-22 20:06:13 -04002102{
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002103 struct nfs_parsed_mount_data *data = mount_info->parsed;
David Howells54ceac42006-08-22 20:06:13 -04002104 struct nfs_server *server = NFS_SB(sb);
2105
2106 sb->s_blocksize_bits = 0;
2107 sb->s_blocksize = 0;
2108 if (data->bsize)
2109 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
2110
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04002111 if (server->nfs_client->rpc_ops->version == 3) {
David Howells54ceac42006-08-22 20:06:13 -04002112 /* The VFS shouldn't apply the umask to mode bits. We will do
2113 * so ourselves when necessary.
2114 */
2115 sb->s_flags |= MS_POSIXACL;
2116 sb->s_time_gran = 1;
2117 }
2118
2119 sb->s_op = &nfs_sops;
2120 nfs_initialise_sb(sb);
2121}
2122
2123/*
Bryan Schumaker3cadf4b2012-07-16 16:39:19 -04002124 * Finish setting up a cloned NFS2/3/4 superblock
David Howells54ceac42006-08-22 20:06:13 -04002125 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002126void nfs_clone_super(struct super_block *sb, struct nfs_mount_info *mount_info)
David Howells54ceac42006-08-22 20:06:13 -04002127{
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002128 const struct super_block *old_sb = mount_info->cloned->sb;
David Howells54ceac42006-08-22 20:06:13 -04002129 struct nfs_server *server = NFS_SB(sb);
2130
2131 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2132 sb->s_blocksize = old_sb->s_blocksize;
2133 sb->s_maxbytes = old_sb->s_maxbytes;
Bryan Schumaker3cadf4b2012-07-16 16:39:19 -04002134 sb->s_xattr = old_sb->s_xattr;
2135 sb->s_op = old_sb->s_op;
2136 sb->s_time_gran = 1;
David Howells54ceac42006-08-22 20:06:13 -04002137
Bryan Schumaker3cadf4b2012-07-16 16:39:19 -04002138 if (server->nfs_client->rpc_ops->version != 2) {
David Howells54ceac42006-08-22 20:06:13 -04002139 /* The VFS shouldn't apply the umask to mode bits. We will do
2140 * so ourselves when necessary.
2141 */
2142 sb->s_flags |= MS_POSIXACL;
David Howells54ceac42006-08-22 20:06:13 -04002143 }
2144
David Howells54ceac42006-08-22 20:06:13 -04002145 nfs_initialise_sb(sb);
2146}
2147
Trond Myklebust275a5d22007-05-16 16:53:28 -04002148static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
2149{
2150 const struct nfs_server *a = s->s_fs_info;
2151 const struct rpc_clnt *clnt_a = a->client;
2152 const struct rpc_clnt *clnt_b = b->client;
2153
2154 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
2155 goto Ebusy;
2156 if (a->nfs_client != b->nfs_client)
2157 goto Ebusy;
2158 if (a->flags != b->flags)
2159 goto Ebusy;
2160 if (a->wsize != b->wsize)
2161 goto Ebusy;
2162 if (a->rsize != b->rsize)
2163 goto Ebusy;
2164 if (a->acregmin != b->acregmin)
2165 goto Ebusy;
2166 if (a->acregmax != b->acregmax)
2167 goto Ebusy;
2168 if (a->acdirmin != b->acdirmin)
2169 goto Ebusy;
2170 if (a->acdirmax != b->acdirmax)
2171 goto Ebusy;
2172 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
2173 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002174 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04002175Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002176 return 0;
2177}
2178
2179struct nfs_sb_mountdata {
2180 struct nfs_server *server;
2181 int mntflags;
2182};
2183
2184static int nfs_set_super(struct super_block *s, void *data)
2185{
2186 struct nfs_sb_mountdata *sb_mntdata = data;
2187 struct nfs_server *server = sb_mntdata->server;
2188 int ret;
2189
2190 s->s_flags = sb_mntdata->mntflags;
2191 s->s_fs_info = server;
Al Viro8b244ff2010-12-18 11:29:39 -05002192 s->s_d_op = server->nfs_client->rpc_ops->dentry_ops;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002193 ret = set_anon_super(s, server);
2194 if (ret == 0)
2195 server->s_dev = s->s_dev;
2196 return ret;
2197}
2198
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002199static int nfs_compare_super_address(struct nfs_server *server1,
2200 struct nfs_server *server2)
2201{
2202 struct sockaddr *sap1, *sap2;
2203
2204 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
2205 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
2206
2207 if (sap1->sa_family != sap2->sa_family)
2208 return 0;
2209
2210 switch (sap1->sa_family) {
2211 case AF_INET: {
2212 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
2213 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
2214 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
2215 return 0;
2216 if (sin1->sin_port != sin2->sin_port)
2217 return 0;
2218 break;
2219 }
2220 case AF_INET6: {
2221 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
2222 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
2223 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
2224 return 0;
2225 if (sin1->sin6_port != sin2->sin6_port)
2226 return 0;
2227 break;
2228 }
2229 default:
2230 return 0;
2231 }
2232
2233 return 1;
2234}
2235
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002236static int nfs_compare_super(struct super_block *sb, void *data)
2237{
2238 struct nfs_sb_mountdata *sb_mntdata = data;
2239 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2240 int mntflags = sb_mntdata->mntflags;
2241
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002242 if (!nfs_compare_super_address(old, server))
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002243 return 0;
2244 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2245 if (old->flags & NFS_MOUNT_UNSHARED)
2246 return 0;
2247 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2248 return 0;
2249 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04002250}
2251
Trond Myklebust39ffb922012-05-16 10:21:30 -07002252#ifdef CONFIG_NFS_FSCACHE
Bryan Schumaker2311b942012-05-10 15:07:32 -04002253static void nfs_get_cache_cookie(struct super_block *sb,
2254 struct nfs_parsed_mount_data *parsed,
2255 struct nfs_clone_mount *cloned)
2256{
2257 char *uniq = NULL;
2258 int ulen = 0;
2259
2260 if (parsed && parsed->fscache_uniq) {
2261 uniq = parsed->fscache_uniq;
2262 ulen = strlen(parsed->fscache_uniq);
2263 } else if (cloned) {
2264 struct nfs_server *mnt_s = NFS_SB(cloned->sb);
2265 if (mnt_s->fscache_key) {
2266 uniq = mnt_s->fscache_key->key.uniquifier;
2267 ulen = mnt_s->fscache_key->key.uniq_len;
2268 };
2269 }
2270
2271 nfs_fscache_get_super_cookie(sb, uniq, ulen);
2272}
Trond Myklebust39ffb922012-05-16 10:21:30 -07002273#else
2274static void nfs_get_cache_cookie(struct super_block *sb,
2275 struct nfs_parsed_mount_data *parsed,
2276 struct nfs_clone_mount *cloned)
2277{
2278}
2279#endif
Bryan Schumaker2311b942012-05-10 15:07:32 -04002280
Miklos Szeredifa799752008-04-30 00:54:33 -07002281static int nfs_bdi_register(struct nfs_server *server)
2282{
2283 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
2284}
2285
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002286int nfs_set_sb_security(struct super_block *s, struct dentry *mntroot,
2287 struct nfs_mount_info *mount_info)
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002288{
2289 return security_sb_set_mnt_opts(s, &mount_info->parsed->lsm_opts);
2290}
2291
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002292int nfs_clone_sb_security(struct super_block *s, struct dentry *mntroot,
2293 struct nfs_mount_info *mount_info)
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002294{
2295 /* clone any lsm security options from the parent to the new sb */
2296 security_sb_clone_mnt_opts(mount_info->cloned->sb, s);
2297 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops)
2298 return -ESTALE;
2299 return 0;
2300}
2301
Bryan Schumakerab7017a2012-07-30 16:05:16 -04002302struct dentry *nfs_fs_mount_common(struct nfs_server *server,
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002303 int flags, const char *dev_name,
Bryan Schumakerab7017a2012-07-30 16:05:16 -04002304 struct nfs_mount_info *mount_info,
2305 struct nfs_subversion *nfs_mod)
David Howells54ceac42006-08-22 20:06:13 -04002306{
David Howells54ceac42006-08-22 20:06:13 -04002307 struct super_block *s;
Al Viro01194982011-03-16 07:25:36 -04002308 struct dentry *mntroot = ERR_PTR(-ENOMEM);
Trond Myklebust75180df2007-05-16 16:53:28 -04002309 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002310 struct nfs_sb_mountdata sb_mntdata = {
2311 .mntflags = flags,
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002312 .server = server,
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002313 };
Al Viro01194982011-03-16 07:25:36 -04002314 int error;
David Howells54ceac42006-08-22 20:06:13 -04002315
Trond Myklebust75180df2007-05-16 16:53:28 -04002316 if (server->flags & NFS_MOUNT_UNSHARED)
2317 compare_super = NULL;
2318
Sachin Prabhufb2088c2011-08-01 12:10:12 +01002319 /* -o noac implies -o sync */
2320 if (server->flags & NFS_MOUNT_NOAC)
2321 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2322
David Howells54ceac42006-08-22 20:06:13 -04002323 /* Get a superblock - note that we may end up sharing one that already exists */
Bryan Schumakerab7017a2012-07-30 16:05:16 -04002324 s = sget(nfs_mod->nfs_fs, compare_super, nfs_set_super, flags, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002325 if (IS_ERR(s)) {
Al Viro01194982011-03-16 07:25:36 -04002326 mntroot = ERR_CAST(s);
David Howells54ceac42006-08-22 20:06:13 -04002327 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04002328 }
2329
David Howells54ceac42006-08-22 20:06:13 -04002330 if (s->s_fs_info != server) {
2331 nfs_free_server(server);
2332 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002333 } else {
2334 error = nfs_bdi_register(server);
Al Viro01194982011-03-16 07:25:36 -04002335 if (error) {
2336 mntroot = ERR_PTR(error);
NeilBrowncfbc0682010-03-11 11:20:17 +11002337 goto error_splat_bdi;
Al Viro01194982011-03-16 07:25:36 -04002338 }
David Howellsf7b422b2006-06-09 09:34:33 -04002339 }
David Howells54ceac42006-08-22 20:06:13 -04002340
2341 if (!s->s_root) {
2342 /* initial superblock/root creation */
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002343 mount_info->fill_super(s, mount_info);
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002344 nfs_get_cache_cookie(s, mount_info->parsed, mount_info->cloned);
David Howells54ceac42006-08-22 20:06:13 -04002345 }
2346
Bryan Schumaker87c70832012-05-10 15:07:43 -04002347 mntroot = nfs_get_root(s, mount_info->mntfh, dev_name);
Al Viro01194982011-03-16 07:25:36 -04002348 if (IS_ERR(mntroot))
David Howells54ceac42006-08-22 20:06:13 -04002349 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002350
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002351 error = mount_info->set_security(s, mntroot, mount_info);
Eric Parisf9c3a382008-03-05 14:20:18 -05002352 if (error)
2353 goto error_splat_root;
2354
David Howellsf7b422b2006-06-09 09:34:33 -04002355 s->s_flags |= MS_ACTIVE;
Chuck Lever06559602007-07-01 12:12:35 -04002356
2357out:
Al Viro01194982011-03-16 07:25:36 -04002358 return mntroot;
Trond Myklebust816724e2006-06-24 08:41:41 -04002359
David Howells54ceac42006-08-22 20:06:13 -04002360out_err_nosb:
2361 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04002362 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002363
Eric Parisf9c3a382008-03-05 14:20:18 -05002364error_splat_root:
2365 dput(mntroot);
Al Viro01194982011-03-16 07:25:36 -04002366 mntroot = ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04002367error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002368 if (server && !s->s_root)
2369 bdi_unregister(&server->backing_dev_info);
2370error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002371 deactivate_locked_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04002372 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002373}
2374
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002375struct dentry *nfs_fs_mount(struct file_system_type *fs_type,
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002376 int flags, const char *dev_name, void *raw_data)
2377{
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002378 struct nfs_mount_info mount_info = {
2379 .fill_super = nfs_fill_super,
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002380 .set_security = nfs_set_sb_security,
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002381 };
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002382 struct dentry *mntroot = ERR_PTR(-ENOMEM);
Bryan Schumakerab7017a2012-07-30 16:05:16 -04002383 struct nfs_subversion *nfs_mod;
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002384 int error;
2385
Bryan Schumaker46058d42012-05-10 15:07:42 -04002386 mount_info.parsed = nfs_alloc_parsed_mount_data();
Bryan Schumaker87c70832012-05-10 15:07:43 -04002387 mount_info.mntfh = nfs_alloc_fhandle();
2388 if (mount_info.parsed == NULL || mount_info.mntfh == NULL)
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002389 goto out;
2390
2391 /* Validate the mount data */
Bryan Schumaker87c70832012-05-10 15:07:43 -04002392 error = nfs_validate_mount_data(fs_type, raw_data, mount_info.parsed, mount_info.mntfh, dev_name);
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04002393 if (error == NFS_TEXT_DATA)
Bryan Schumaker46058d42012-05-10 15:07:42 -04002394 error = nfs_validate_text_mount_data(raw_data, mount_info.parsed, dev_name);
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002395 if (error < 0) {
2396 mntroot = ERR_PTR(error);
2397 goto out;
2398 }
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002399
Bryan Schumakerab7017a2012-07-30 16:05:16 -04002400 nfs_mod = get_nfs_version(mount_info.parsed->version);
2401 if (IS_ERR(nfs_mod)) {
2402 mntroot = ERR_CAST(nfs_mod);
2403 goto out;
2404 }
2405
Bryan Schumakerff9099f22012-07-30 16:05:18 -04002406 mntroot = nfs_mod->rpc_ops->try_mount(flags, dev_name, &mount_info, nfs_mod);
Bryan Schumakerab7017a2012-07-30 16:05:16 -04002407
2408 put_nfs_version(nfs_mod);
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002409out:
Bryan Schumaker46058d42012-05-10 15:07:42 -04002410 nfs_free_parsed_mount_data(mount_info.parsed);
Bryan Schumaker87c70832012-05-10 15:07:43 -04002411 nfs_free_fhandle(mount_info.mntfh);
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002412 return mntroot;
2413}
2414
David Howells54ceac42006-08-22 20:06:13 -04002415/*
Trond Myklebust387c1492010-02-03 08:27:35 -05002416 * Ensure that we unregister the bdi before kill_anon_super
2417 * releases the device name
2418 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002419void nfs_put_super(struct super_block *s)
Trond Myklebust387c1492010-02-03 08:27:35 -05002420{
2421 struct nfs_server *server = NFS_SB(s);
2422
2423 bdi_unregister(&server->backing_dev_info);
2424}
2425
2426/*
David Howells54ceac42006-08-22 20:06:13 -04002427 * Destroy an NFS2/3 superblock
2428 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002429void nfs_kill_super(struct super_block *s)
David Howellsf7b422b2006-06-09 09:34:33 -04002430{
2431 struct nfs_server *server = NFS_SB(s);
2432
2433 kill_anon_super(s);
David Howells08734042009-04-03 16:42:42 +01002434 nfs_fscache_release_super_cookie(s);
David Howells54ceac42006-08-22 20:06:13 -04002435 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04002436}
2437
David Howells54ceac42006-08-22 20:06:13 -04002438/*
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002439 * Clone an NFS2/3/4 server record on xdev traversal (FSID-change)
David Howells54ceac42006-08-22 20:06:13 -04002440 */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -04002441struct dentry *
Bryan Schumakere8f25e62012-07-30 16:05:17 -04002442nfs_xdev_mount(struct file_system_type *fs_type, int flags,
2443 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002444{
Bryan Schumakere8f25e62012-07-30 16:05:17 -04002445 struct nfs_clone_mount *data = raw_data;
2446 struct nfs_mount_info mount_info = {
2447 .fill_super = nfs_clone_super,
2448 .set_security = nfs_clone_sb_security,
2449 .cloned = data,
2450 };
David Howells54ceac42006-08-22 20:06:13 -04002451 struct nfs_server *server;
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002452 struct dentry *mntroot = ERR_PTR(-ENOMEM);
Bryan Schumakerab7017a2012-07-30 16:05:16 -04002453 struct nfs_subversion *nfs_mod = NFS_SB(data->sb)->nfs_client->cl_nfs_mod;
David Howells54ceac42006-08-22 20:06:13 -04002454 int error;
2455
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002456 dprintk("--> nfs_xdev_mount_common()\n");
David Howells54ceac42006-08-22 20:06:13 -04002457
Bryan Schumakere8f25e62012-07-30 16:05:17 -04002458 mount_info.mntfh = mount_info.cloned->fh;
Bryan Schumaker87c70832012-05-10 15:07:43 -04002459
David Howells54ceac42006-08-22 20:06:13 -04002460 /* create a new volume representation */
Bryan Schumaker7e6eb682012-04-27 13:27:42 -04002461 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr, data->authflavor);
David Howells54ceac42006-08-22 20:06:13 -04002462 if (IS_ERR(server)) {
2463 error = PTR_ERR(server);
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002464 goto out_err;
David Howells54ceac42006-08-22 20:06:13 -04002465 }
2466
Bryan Schumakere8f25e62012-07-30 16:05:17 -04002467 mntroot = nfs_fs_mount_common(server, flags, dev_name, &mount_info, nfs_mod);
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002468 dprintk("<-- nfs_xdev_mount_common() = 0\n");
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002469out:
Al Viro31f43472010-10-29 03:38:12 -04002470 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04002471
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002472out_err:
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002473 dprintk("<-- nfs_xdev_mount_common() = %d [error]\n", error);
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002474 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002475}
2476
2477#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04002478
Trond Myklebust01c3f052009-06-17 13:22:58 -07002479static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2480{
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04002481 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3|
2482 NFS_MOUNT_LOCAL_FLOCK|NFS_MOUNT_LOCAL_FCNTL);
Trond Myklebust01c3f052009-06-17 13:22:58 -07002483}
2484
David Howells54ceac42006-08-22 20:06:13 -04002485/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04002486 * Validate NFSv4 mount options
2487 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002488static int nfs4_validate_mount_data(void *options,
2489 struct nfs_parsed_mount_data *args,
2490 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04002491{
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002492 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002493 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002494 char *c;
2495
2496 if (data == NULL)
2497 goto out_no_data;
2498
Bryan Schumakercdf66442012-06-05 14:59:54 -04002499 args->version = 4;
2500
Chuck Leverf0768eb2007-07-01 12:13:01 -04002501 switch (data->version) {
2502 case 1:
Chuck Lever4c568012007-12-10 14:59:28 -05002503 if (data->host_addrlen > sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002504 goto out_no_address;
Chuck Lever4c568012007-12-10 14:59:28 -05002505 if (data->host_addrlen == 0)
2506 goto out_no_address;
2507 args->nfs_server.addrlen = data->host_addrlen;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002508 if (copy_from_user(sap, data->host_addr, data->host_addrlen))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002509 return -EFAULT;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002510 if (!nfs_verify_server_address(sap))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002511 goto out_no_address;
2512
Chuck Lever6738b252008-06-24 16:33:54 -04002513 if (data->auth_flavourlen) {
2514 if (data->auth_flavourlen > 1)
2515 goto out_inval_auth;
Trond Myklebust20c71f52007-09-20 20:23:51 -04002516 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002517 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04002518 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002519 return -EFAULT;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002520 }
2521
2522 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2523 if (IS_ERR(c))
2524 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002525 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002526
2527 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2528 if (IS_ERR(c))
2529 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002530 args->nfs_server.export_path = c;
2531 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002532
2533 c = strndup_user(data->client_addr.data, 16);
2534 if (IS_ERR(c))
2535 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002536 args->client_address = c;
2537
2538 /*
2539 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2540 * can deal with.
2541 */
2542
2543 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2544 args->rsize = data->rsize;
2545 args->wsize = data->wsize;
2546 args->timeo = data->timeo;
2547 args->retrans = data->retrans;
2548 args->acregmin = data->acregmin;
2549 args->acregmax = data->acregmax;
2550 args->acdirmin = data->acdirmin;
2551 args->acdirmax = data->acdirmax;
2552 args->nfs_server.protocol = data->proto;
Trond Myklebust259875e2008-07-02 14:43:47 -04002553 nfs_validate_transport_protocol(args);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002554
2555 break;
Chuck Lever7630c852009-09-08 19:49:57 -04002556 default:
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04002557 return NFS_TEXT_DATA;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002558 }
2559
2560 return 0;
2561
2562out_no_data:
2563 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2564 return -EINVAL;
2565
2566out_inval_auth:
2567 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2568 data->auth_flavourlen);
2569 return -EINVAL;
2570
2571out_no_address:
2572 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2573 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002574}
2575
David Howells54ceac42006-08-22 20:06:13 -04002576#endif /* CONFIG_NFS_V4 */