blob: db636d709f28b00febc716dad171e7f6832f24d3 [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"
David Howellsf7b422b2006-06-09 09:34:33 -040067
68#define NFSDBG_FACILITY NFSDBG_VFS
Bryan Schumakerb72e4f42012-05-10 15:07:40 -040069#define NFS_TEXT_DATA 1
David Howellsf7b422b2006-06-09 09:34:33 -040070
Paulius Zaleckas1e657bd2010-10-31 18:21:05 +020071#ifdef CONFIG_NFS_V3
72#define NFS_DEFAULT_VERSION 3
73#else
74#define NFS_DEFAULT_VERSION 2
75#endif
76
Chuck Leverbf0fd762007-07-01 12:13:44 -040077enum {
78 /* Mount options that take no arguments */
79 Opt_soft, Opt_hard,
Chuck Leverbf0fd762007-07-01 12:13:44 -040080 Opt_posix, Opt_noposix,
81 Opt_cto, Opt_nocto,
82 Opt_ac, Opt_noac,
83 Opt_lock, Opt_nolock,
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -040084 Opt_udp, Opt_tcp, Opt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -040085 Opt_acl, Opt_noacl,
86 Opt_rdirplus, Opt_nordirplus,
Trond Myklebust75180df2007-05-16 16:53:28 -040087 Opt_sharecache, Opt_nosharecache,
Chuck Leverd7403512008-12-23 15:21:37 -050088 Opt_resvport, Opt_noresvport,
David Howellsb797cac2009-04-03 16:42:48 +010089 Opt_fscache, Opt_nofscache,
Chuck Leverbf0fd762007-07-01 12:13:44 -040090
91 /* Mount options that take integer arguments */
92 Opt_port,
93 Opt_rsize, Opt_wsize, Opt_bsize,
94 Opt_timeo, Opt_retrans,
95 Opt_acregmin, Opt_acregmax,
96 Opt_acdirmin, Opt_acdirmax,
97 Opt_actimeo,
98 Opt_namelen,
99 Opt_mountport,
Chuck Levere887cbc2007-10-26 13:32:29 -0400100 Opt_mountvers,
Mike Sager3fd5be92009-04-01 09:21:48 -0400101 Opt_minorversion,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400102
103 /* Mount options that take string arguments */
Trond Myklebust0d71b052012-03-02 13:59:49 -0500104 Opt_nfsvers,
Chuck Lever33832032007-12-10 14:59:13 -0500105 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
Chuck Lever0ac83772007-09-11 18:01:04 -0400106 Opt_addr, Opt_mountaddr, Opt_clientaddr,
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400107 Opt_lookupcache,
David Howellsb797cac2009-04-03 16:42:48 +0100108 Opt_fscache_uniq,
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400109 Opt_local_lock,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400110
Chuck Leverf45663c2008-06-24 19:28:02 -0400111 /* Special mount options */
112 Opt_userspace, Opt_deprecated, Opt_sloppy,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400113
114 Opt_err
115};
116
Steven Whitehousea447c092008-10-13 10:46:57 +0100117static const match_table_t nfs_mount_option_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400118 { Opt_userspace, "bg" },
119 { Opt_userspace, "fg" },
Chuck Leverecbb3842008-06-12 12:37:33 -0400120 { Opt_userspace, "retry=%s" },
121
Chuck Leverf45663c2008-06-24 19:28:02 -0400122 { Opt_sloppy, "sloppy" },
123
Chuck Leverbf0fd762007-07-01 12:13:44 -0400124 { Opt_soft, "soft" },
125 { Opt_hard, "hard" },
Chuck Leverd33e4df2008-06-12 12:37:41 -0400126 { Opt_deprecated, "intr" },
127 { Opt_deprecated, "nointr" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400128 { Opt_posix, "posix" },
129 { Opt_noposix, "noposix" },
130 { Opt_cto, "cto" },
131 { Opt_nocto, "nocto" },
132 { Opt_ac, "ac" },
133 { Opt_noac, "noac" },
134 { Opt_lock, "lock" },
135 { Opt_nolock, "nolock" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400136 { Opt_udp, "udp" },
137 { Opt_tcp, "tcp" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400138 { Opt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400139 { Opt_acl, "acl" },
140 { Opt_noacl, "noacl" },
141 { Opt_rdirplus, "rdirplus" },
142 { Opt_nordirplus, "nordirplus" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400143 { Opt_sharecache, "sharecache" },
144 { Opt_nosharecache, "nosharecache" },
Chuck Leverd7403512008-12-23 15:21:37 -0500145 { Opt_resvport, "resvport" },
146 { Opt_noresvport, "noresvport" },
David Howellsb797cac2009-04-03 16:42:48 +0100147 { Opt_fscache, "fsc" },
David Howellsb797cac2009-04-03 16:42:48 +0100148 { Opt_nofscache, "nofsc" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400149
Chuck Levera5a16ba2009-06-17 18:02:14 -0700150 { Opt_port, "port=%s" },
151 { Opt_rsize, "rsize=%s" },
152 { Opt_wsize, "wsize=%s" },
153 { Opt_bsize, "bsize=%s" },
154 { Opt_timeo, "timeo=%s" },
155 { Opt_retrans, "retrans=%s" },
156 { Opt_acregmin, "acregmin=%s" },
157 { Opt_acregmax, "acregmax=%s" },
158 { Opt_acdirmin, "acdirmin=%s" },
159 { Opt_acdirmax, "acdirmax=%s" },
160 { Opt_actimeo, "actimeo=%s" },
161 { Opt_namelen, "namlen=%s" },
162 { Opt_mountport, "mountport=%s" },
163 { Opt_mountvers, "mountvers=%s" },
Trond Myklebust0d71b052012-03-02 13:59:49 -0500164 { Opt_minorversion, "minorversion=%s" },
165
Chuck Levera5a16ba2009-06-17 18:02:14 -0700166 { Opt_nfsvers, "nfsvers=%s" },
167 { Opt_nfsvers, "vers=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400168
169 { Opt_sec, "sec=%s" },
170 { Opt_proto, "proto=%s" },
171 { Opt_mountproto, "mountproto=%s" },
172 { Opt_addr, "addr=%s" },
173 { Opt_clientaddr, "clientaddr=%s" },
Chuck Lever33832032007-12-10 14:59:13 -0500174 { Opt_mounthost, "mounthost=%s" },
Chuck Lever0ac83772007-09-11 18:01:04 -0400175 { Opt_mountaddr, "mountaddr=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400176
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400177 { Opt_lookupcache, "lookupcache=%s" },
Chuck Levera6d5ff62010-05-07 13:33:58 -0400178 { Opt_fscache_uniq, "fsc=%s" },
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400179 { Opt_local_lock, "local_lock=%s" },
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400180
Trond Myklebust38622792012-03-02 14:06:39 -0500181 /* The following needs to be listed after all other options */
182 { Opt_nfsvers, "v%s" },
183
Chuck Leverbf0fd762007-07-01 12:13:44 -0400184 { Opt_err, NULL }
185};
186
187enum {
Jeff Laytonee671b02009-12-03 15:58:56 -0500188 Opt_xprt_udp, Opt_xprt_udp6, Opt_xprt_tcp, Opt_xprt_tcp6, Opt_xprt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400189
190 Opt_xprt_err
191};
192
Steven Whitehousea447c092008-10-13 10:46:57 +0100193static const match_table_t nfs_xprt_protocol_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400194 { Opt_xprt_udp, "udp" },
Jeff Laytonee671b02009-12-03 15:58:56 -0500195 { Opt_xprt_udp6, "udp6" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400196 { Opt_xprt_tcp, "tcp" },
Jeff Laytonee671b02009-12-03 15:58:56 -0500197 { Opt_xprt_tcp6, "tcp6" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400198 { Opt_xprt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400199
200 { Opt_xprt_err, NULL }
201};
202
203enum {
204 Opt_sec_none, Opt_sec_sys,
205 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
206 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
207 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
208
209 Opt_sec_err
210};
211
Steven Whitehousea447c092008-10-13 10:46:57 +0100212static const match_table_t nfs_secflavor_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400213 { Opt_sec_none, "none" },
214 { Opt_sec_none, "null" },
215 { Opt_sec_sys, "sys" },
216
217 { Opt_sec_krb5, "krb5" },
218 { Opt_sec_krb5i, "krb5i" },
219 { Opt_sec_krb5p, "krb5p" },
220
221 { Opt_sec_lkey, "lkey" },
222 { Opt_sec_lkeyi, "lkeyi" },
223 { Opt_sec_lkeyp, "lkeyp" },
224
Olga Kornievskaia8d042212008-02-13 16:47:06 -0500225 { Opt_sec_spkm, "spkm3" },
226 { Opt_sec_spkmi, "spkm3i" },
227 { Opt_sec_spkmp, "spkm3p" },
228
Chuck Leverbf0fd762007-07-01 12:13:44 -0400229 { Opt_sec_err, NULL }
230};
231
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400232enum {
233 Opt_lookupcache_all, Opt_lookupcache_positive,
234 Opt_lookupcache_none,
235
236 Opt_lookupcache_err
237};
238
239static match_table_t nfs_lookupcache_tokens = {
240 { Opt_lookupcache_all, "all" },
241 { Opt_lookupcache_positive, "pos" },
242 { Opt_lookupcache_positive, "positive" },
243 { Opt_lookupcache_none, "none" },
244
245 { Opt_lookupcache_err, NULL }
246};
247
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400248enum {
249 Opt_local_lock_all, Opt_local_lock_flock, Opt_local_lock_posix,
250 Opt_local_lock_none,
251
252 Opt_local_lock_err
253};
254
255static match_table_t nfs_local_lock_tokens = {
256 { Opt_local_lock_all, "all" },
257 { Opt_local_lock_flock, "flock" },
258 { Opt_local_lock_posix, "posix" },
259 { Opt_local_lock_none, "none" },
260
261 { Opt_local_lock_err, NULL }
262};
263
Trond Myklebust0d71b052012-03-02 13:59:49 -0500264enum {
265 Opt_vers_2, Opt_vers_3, Opt_vers_4, Opt_vers_4_0,
266 Opt_vers_4_1,
267
268 Opt_vers_err
269};
270
271static match_table_t nfs_vers_tokens = {
272 { Opt_vers_2, "2" },
273 { Opt_vers_3, "3" },
274 { Opt_vers_4, "4" },
275 { Opt_vers_4_0, "4.0" },
276 { Opt_vers_4_1, "4.1" },
277
278 { Opt_vers_err, NULL }
279};
Chuck Leverbf0fd762007-07-01 12:13:44 -0400280
Bryan Schumakerc40f8d12012-05-10 15:07:34 -0400281struct nfs_mount_info {
282 void (*fill_super)(struct super_block *, struct nfs_mount_info *);
Bryan Schumaker3d176e32012-05-10 15:07:36 -0400283 int (*set_security)(struct super_block *, struct dentry *, struct nfs_mount_info *);
Bryan Schumakerc40f8d12012-05-10 15:07:34 -0400284 struct nfs_parsed_mount_data *parsed;
Bryan Schumaker8c958e02012-05-10 15:07:35 -0400285 struct nfs_clone_mount *cloned;
Bryan Schumakerc40f8d12012-05-10 15:07:34 -0400286};
287
Al Viro42faad92008-04-24 07:21:56 -0400288static void nfs_umount_begin(struct super_block *);
Trond Myklebust816724e2006-06-24 08:41:41 -0400289static int nfs_statfs(struct dentry *, struct kstatfs *);
Al Viro34c80b12011-12-08 21:32:45 -0500290static int nfs_show_options(struct seq_file *, struct dentry *);
Al Virod861c632011-12-08 21:32:45 -0500291static int nfs_show_devname(struct seq_file *, struct dentry *);
Al Viroa6322de2011-12-08 21:37:57 -0500292static int nfs_show_path(struct seq_file *, struct dentry *);
Al Viro64132372011-12-08 20:51:13 -0500293static int nfs_show_stats(struct seq_file *, struct dentry *);
Bryan Schumaker486aa692012-05-10 15:07:39 -0400294static struct dentry *nfs_fs_mount_common(struct file_system_type *,
295 struct nfs_server *, int, const char *, struct nfs_fh *,
296 struct nfs_mount_info *);
Al Viro01194982011-03-16 07:25:36 -0400297static struct dentry *nfs_fs_mount(struct file_system_type *,
298 int, const char *, void *);
Al Viro31f43472010-10-29 03:38:12 -0400299static struct dentry *nfs_xdev_mount(struct file_system_type *fs_type,
300 int flags, const char *dev_name, void *raw_data);
Trond Myklebust387c1492010-02-03 08:27:35 -0500301static void nfs_put_super(struct super_block *);
David Howellsf7b422b2006-06-09 09:34:33 -0400302static void nfs_kill_super(struct super_block *);
Jeff Layton48b605f2008-06-10 15:38:39 -0400303static int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
David Howellsf7b422b2006-06-09 09:34:33 -0400304
305static struct file_system_type nfs_fs_type = {
306 .owner = THIS_MODULE,
307 .name = "nfs",
Al Viro01194982011-03-16 07:25:36 -0400308 .mount = nfs_fs_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400309 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700310 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400311};
312
David Howells54ceac42006-08-22 20:06:13 -0400313struct file_system_type nfs_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400314 .owner = THIS_MODULE,
315 .name = "nfs",
Al Viro31f43472010-10-29 03:38:12 -0400316 .mount = nfs_xdev_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400317 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700318 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400319};
320
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800321static const struct super_operations nfs_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400322 .alloc_inode = nfs_alloc_inode,
323 .destroy_inode = nfs_destroy_inode,
324 .write_inode = nfs_write_inode,
Trond Myklebust387c1492010-02-03 08:27:35 -0500325 .put_super = nfs_put_super,
David Howellsf7b422b2006-06-09 09:34:33 -0400326 .statfs = nfs_statfs,
Al Virob57922d2010-06-07 14:34:48 -0400327 .evict_inode = nfs_evict_inode,
David Howellsf7b422b2006-06-09 09:34:33 -0400328 .umount_begin = nfs_umount_begin,
329 .show_options = nfs_show_options,
Al Viroc7f404b2011-03-16 06:59:40 -0400330 .show_devname = nfs_show_devname,
331 .show_path = nfs_show_path,
David Howellsf7b422b2006-06-09 09:34:33 -0400332 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400333 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400334};
335
336#ifdef CONFIG_NFS_V4
Bryan Schumakerb72e4f42012-05-10 15:07:40 -0400337static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *);
Al Viro01194982011-03-16 07:25:36 -0400338static struct dentry *nfs4_try_mount(int flags, const char *dev_name,
339 struct nfs_parsed_mount_data *data);
340static struct dentry *nfs4_mount(struct file_system_type *fs_type,
341 int flags, const char *dev_name, void *raw_data);
Al Viro31f43472010-10-29 03:38:12 -0400342static struct dentry *nfs4_remote_mount(struct file_system_type *fs_type,
343 int flags, const char *dev_name, void *raw_data);
344static struct dentry *nfs4_xdev_mount(struct file_system_type *fs_type,
345 int flags, const char *dev_name, void *raw_data);
Al Viro01194982011-03-16 07:25:36 -0400346static struct dentry *nfs4_referral_mount(struct file_system_type *fs_type,
347 int flags, const char *dev_name, void *raw_data);
Al Viro31f43472010-10-29 03:38:12 -0400348static struct dentry *nfs4_remote_referral_mount(struct file_system_type *fs_type,
349 int flags, const char *dev_name, void *raw_data);
David Howellsf7b422b2006-06-09 09:34:33 -0400350static void nfs4_kill_super(struct super_block *sb);
351
352static struct file_system_type nfs4_fs_type = {
353 .owner = THIS_MODULE,
354 .name = "nfs4",
Al Viro01194982011-03-16 07:25:36 -0400355 .mount = nfs4_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400356 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700357 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400358};
359
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400360static struct file_system_type nfs4_remote_fs_type = {
361 .owner = THIS_MODULE,
362 .name = "nfs4",
Al Viro31f43472010-10-29 03:38:12 -0400363 .mount = nfs4_remote_mount,
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400364 .kill_sb = nfs4_kill_super,
365 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
366};
367
David Howells54ceac42006-08-22 20:06:13 -0400368struct file_system_type nfs4_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400369 .owner = THIS_MODULE,
370 .name = "nfs4",
Al Viro31f43472010-10-29 03:38:12 -0400371 .mount = nfs4_xdev_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400372 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700373 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400374};
375
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400376static struct file_system_type nfs4_remote_referral_fs_type = {
377 .owner = THIS_MODULE,
378 .name = "nfs4",
Al Viro31f43472010-10-29 03:38:12 -0400379 .mount = nfs4_remote_referral_mount,
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400380 .kill_sb = nfs4_kill_super,
381 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
382};
383
David Howells54ceac42006-08-22 20:06:13 -0400384struct file_system_type nfs4_referral_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400385 .owner = THIS_MODULE,
386 .name = "nfs4",
Al Viro01194982011-03-16 07:25:36 -0400387 .mount = nfs4_referral_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400388 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700389 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400390};
391
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800392static const struct super_operations nfs4_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400393 .alloc_inode = nfs_alloc_inode,
394 .destroy_inode = nfs_destroy_inode,
395 .write_inode = nfs_write_inode,
Trond Myklebust387c1492010-02-03 08:27:35 -0500396 .put_super = nfs_put_super,
David Howellsf7b422b2006-06-09 09:34:33 -0400397 .statfs = nfs_statfs,
Al Virob57922d2010-06-07 14:34:48 -0400398 .evict_inode = nfs4_evict_inode,
David Howellsf7b422b2006-06-09 09:34:33 -0400399 .umount_begin = nfs_umount_begin,
400 .show_options = nfs_show_options,
Al Viroc7f404b2011-03-16 06:59:40 -0400401 .show_devname = nfs_show_devname,
402 .show_path = nfs_show_path,
David Howellsf7b422b2006-06-09 09:34:33 -0400403 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400404 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400405};
406#endif
407
Rusty Russell8e1f9362007-07-17 04:03:17 -0700408static struct shrinker acl_shrinker = {
409 .shrink = nfs_access_cache_shrinker,
410 .seeks = DEFAULT_SEEKS,
411};
Trond Myklebust979df722006-07-25 11:28:19 -0400412
David Howellsf7b422b2006-06-09 09:34:33 -0400413/*
414 * Register the NFS filesystems
415 */
416int __init register_nfs_fs(void)
417{
418 int ret;
419
420 ret = register_filesystem(&nfs_fs_type);
421 if (ret < 0)
422 goto error_0;
423
David Howellsf7b422b2006-06-09 09:34:33 -0400424 ret = nfs_register_sysctl();
425 if (ret < 0)
426 goto error_1;
Peter Zijlstra89a09142007-03-16 13:38:26 -0800427#ifdef CONFIG_NFS_V4
David Howellsf7b422b2006-06-09 09:34:33 -0400428 ret = register_filesystem(&nfs4_fs_type);
429 if (ret < 0)
430 goto error_2;
431#endif
Rusty Russell8e1f9362007-07-17 04:03:17 -0700432 register_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400433 return 0;
434
435#ifdef CONFIG_NFS_V4
436error_2:
437 nfs_unregister_sysctl();
Peter Zijlstra89a09142007-03-16 13:38:26 -0800438#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400439error_1:
440 unregister_filesystem(&nfs_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400441error_0:
442 return ret;
443}
444
445/*
446 * Unregister the NFS filesystems
447 */
448void __exit unregister_nfs_fs(void)
449{
Rusty Russell8e1f9362007-07-17 04:03:17 -0700450 unregister_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400451#ifdef CONFIG_NFS_V4
452 unregister_filesystem(&nfs4_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400453#endif
Alexey Dobriyan49af7ee2007-09-18 22:46:40 -0700454 nfs_unregister_sysctl();
David Howellsf7b422b2006-06-09 09:34:33 -0400455 unregister_filesystem(&nfs_fs_type);
456}
457
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400458void nfs_sb_active(struct super_block *sb)
Steve Dicksonef818a22007-11-08 04:05:04 -0500459{
460 struct nfs_server *server = NFS_SB(sb);
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400461
462 if (atomic_inc_return(&server->active) == 1)
463 atomic_inc(&sb->s_active);
464}
465
466void nfs_sb_deactive(struct super_block *sb)
467{
468 struct nfs_server *server = NFS_SB(sb);
469
470 if (atomic_dec_and_test(&server->active))
471 deactivate_super(sb);
Steve Dicksonef818a22007-11-08 04:05:04 -0500472}
473
David Howellsf7b422b2006-06-09 09:34:33 -0400474/*
475 * Deliver file system statistics to userspace
476 */
Trond Myklebust816724e2006-06-24 08:41:41 -0400477static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
David Howellsf7b422b2006-06-09 09:34:33 -0400478{
David Howells0c7d90c2006-08-22 20:06:10 -0400479 struct nfs_server *server = NFS_SB(dentry->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400480 unsigned char blockbits;
481 unsigned long blockres;
David Howells0c7d90c2006-08-22 20:06:10 -0400482 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400483 struct nfs_fsstat res;
484 int error = -ENOMEM;
485
486 res.fattr = nfs_alloc_fattr();
487 if (res.fattr == NULL)
488 goto out_err;
David Howellsf7b422b2006-06-09 09:34:33 -0400489
David Howells8fa5c002006-08-22 20:06:12 -0400490 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
Menyhart Zoltanfbf3fdd2010-09-12 19:55:26 -0400491 if (unlikely(error == -ESTALE)) {
492 struct dentry *pd_dentry;
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400493
Menyhart Zoltanfbf3fdd2010-09-12 19:55:26 -0400494 pd_dentry = dget_parent(dentry);
495 if (pd_dentry != NULL) {
496 nfs_zap_caches(pd_dentry->d_inode);
497 dput(pd_dentry);
498 }
499 }
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400500 nfs_free_fattr(res.fattr);
David Howellsf7b422b2006-06-09 09:34:33 -0400501 if (error < 0)
502 goto out_err;
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400503
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700504 buf->f_type = NFS_SUPER_MAGIC;
David Howellsf7b422b2006-06-09 09:34:33 -0400505
506 /*
507 * Current versions of glibc do not correctly handle the
508 * case where f_frsize != f_bsize. Eventually we want to
509 * report the value of wtmult in this field.
510 */
David Howells0c7d90c2006-08-22 20:06:10 -0400511 buf->f_frsize = dentry->d_sb->s_blocksize;
David Howellsf7b422b2006-06-09 09:34:33 -0400512
513 /*
514 * On most *nix systems, f_blocks, f_bfree, and f_bavail
515 * are reported in units of f_frsize. Linux hasn't had
516 * an f_frsize field in its statfs struct until recently,
517 * thus historically Linux's sys_statfs reports these
518 * fields in units of f_bsize.
519 */
David Howells0c7d90c2006-08-22 20:06:10 -0400520 buf->f_bsize = dentry->d_sb->s_blocksize;
521 blockbits = dentry->d_sb->s_blocksize_bits;
David Howellsf7b422b2006-06-09 09:34:33 -0400522 blockres = (1 << blockbits) - 1;
523 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
524 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
525 buf->f_bavail = (res.abytes + blockres) >> blockbits;
526
527 buf->f_files = res.tfiles;
528 buf->f_ffree = res.afiles;
529
530 buf->f_namelen = server->namelen;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700531
David Howellsf7b422b2006-06-09 09:34:33 -0400532 return 0;
533
534 out_err:
Harvey Harrison3110ff82008-05-02 13:42:44 -0700535 dprintk("%s: statfs error = %d\n", __func__, -error);
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700536 return error;
David Howellsf7b422b2006-06-09 09:34:33 -0400537}
538
David Howells7d4e2742006-08-22 20:06:07 -0400539/*
540 * Map the security flavour number to a name
541 */
Trond Myklebust81039f12006-06-09 09:34:34 -0400542static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
543{
David Howells7d4e2742006-08-22 20:06:07 -0400544 static const struct {
Trond Myklebust81039f12006-06-09 09:34:34 -0400545 rpc_authflavor_t flavour;
546 const char *str;
547 } sec_flavours[] = {
548 { RPC_AUTH_NULL, "null" },
549 { RPC_AUTH_UNIX, "sys" },
550 { RPC_AUTH_GSS_KRB5, "krb5" },
551 { RPC_AUTH_GSS_KRB5I, "krb5i" },
552 { RPC_AUTH_GSS_KRB5P, "krb5p" },
553 { RPC_AUTH_GSS_LKEY, "lkey" },
554 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
555 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
556 { RPC_AUTH_GSS_SPKM, "spkm" },
557 { RPC_AUTH_GSS_SPKMI, "spkmi" },
558 { RPC_AUTH_GSS_SPKMP, "spkmp" },
Chuck Lever4d81cd12007-07-01 12:12:40 -0400559 { UINT_MAX, "unknown" }
Trond Myklebust81039f12006-06-09 09:34:34 -0400560 };
561 int i;
562
Chuck Lever4d81cd12007-07-01 12:12:40 -0400563 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
Trond Myklebust81039f12006-06-09 09:34:34 -0400564 if (sec_flavours[i].flavour == flavour)
565 break;
566 }
567 return sec_flavours[i].str;
568}
569
Jeff Laytonee671b02009-12-03 15:58:56 -0500570static void nfs_show_mountd_netid(struct seq_file *m, struct nfs_server *nfss,
571 int showdefaults)
572{
573 struct sockaddr *sap = (struct sockaddr *) &nfss->mountd_address;
574
575 seq_printf(m, ",mountproto=");
576 switch (sap->sa_family) {
577 case AF_INET:
578 switch (nfss->mountd_protocol) {
579 case IPPROTO_UDP:
580 seq_printf(m, RPCBIND_NETID_UDP);
581 break;
582 case IPPROTO_TCP:
583 seq_printf(m, RPCBIND_NETID_TCP);
584 break;
585 default:
586 if (showdefaults)
587 seq_printf(m, "auto");
588 }
589 break;
590 case AF_INET6:
591 switch (nfss->mountd_protocol) {
592 case IPPROTO_UDP:
593 seq_printf(m, RPCBIND_NETID_UDP6);
594 break;
595 case IPPROTO_TCP:
596 seq_printf(m, RPCBIND_NETID_TCP6);
597 break;
598 default:
599 if (showdefaults)
600 seq_printf(m, "auto");
601 }
602 break;
603 default:
604 if (showdefaults)
605 seq_printf(m, "auto");
606 }
607}
608
Chuck Lever82d101d2008-03-14 14:10:37 -0400609static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
610 int showdefaults)
611{
612 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
613
Bryan Schumakerd5eff1a2010-08-03 13:04:00 -0400614 if (nfss->flags & NFS_MOUNT_LEGACY_INTERFACE)
615 return;
616
Chuck Lever82d101d2008-03-14 14:10:37 -0400617 switch (sap->sa_family) {
618 case AF_INET: {
619 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
Harvey Harrisonbe859402008-10-31 00:56:28 -0700620 seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400621 break;
622 }
623 case AF_INET6: {
624 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
Chuck Leverd250e192009-12-03 15:58:56 -0500625 seq_printf(m, ",mountaddr=%pI6c", &sin6->sin6_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400626 break;
627 }
628 default:
629 if (showdefaults)
630 seq_printf(m, ",mountaddr=unspecified");
631 }
632
633 if (nfss->mountd_version || showdefaults)
634 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
Stanislav Kinsburskyaa699472010-12-08 12:40:13 +0300635 if ((nfss->mountd_port &&
636 nfss->mountd_port != (unsigned short)NFS_UNSPEC_PORT) ||
637 showdefaults)
Chuck Lever82d101d2008-03-14 14:10:37 -0400638 seq_printf(m, ",mountport=%u", nfss->mountd_port);
639
Jeff Laytonee671b02009-12-03 15:58:56 -0500640 nfs_show_mountd_netid(m, nfss, showdefaults);
Chuck Lever82d101d2008-03-14 14:10:37 -0400641}
642
Trond Myklebust0be81892010-06-18 12:23:58 -0400643#ifdef CONFIG_NFS_V4
644static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
645 int showdefaults)
646{
647 struct nfs_client *clp = nfss->nfs_client;
648
649 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
Trond Myklebust0be81892010-06-18 12:23:58 -0400650}
651#else
652static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
653 int showdefaults)
654{
655}
656#endif
657
Trond Myklebust7bbceb62012-03-02 14:00:20 -0500658static void nfs_show_nfs_version(struct seq_file *m,
659 unsigned int version,
660 unsigned int minorversion)
661{
662 seq_printf(m, ",vers=%u", version);
663 if (version == 4)
664 seq_printf(m, ".%u", minorversion);
665}
666
David Howellsf7b422b2006-06-09 09:34:33 -0400667/*
668 * Describe the mount options in force on this server representation
669 */
Chuck Lever82d101d2008-03-14 14:10:37 -0400670static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
671 int showdefaults)
David Howellsf7b422b2006-06-09 09:34:33 -0400672{
David Howells509de812006-08-22 20:06:11 -0400673 static const struct proc_nfs_info {
David Howellsf7b422b2006-06-09 09:34:33 -0400674 int flag;
David Howells509de812006-08-22 20:06:11 -0400675 const char *str;
676 const char *nostr;
David Howellsf7b422b2006-06-09 09:34:33 -0400677 } nfs_info[] = {
678 { NFS_MOUNT_SOFT, ",soft", ",hard" },
Chuck Lever82d101d2008-03-14 14:10:37 -0400679 { NFS_MOUNT_POSIX, ",posix", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400680 { NFS_MOUNT_NOCTO, ",nocto", "" },
681 { NFS_MOUNT_NOAC, ",noac", "" },
682 { NFS_MOUNT_NONLM, ",nolock", "" },
683 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400684 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
Chuck Leverd7403512008-12-23 15:21:37 -0500685 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
686 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400687 { 0, NULL, NULL }
688 };
David Howells509de812006-08-22 20:06:11 -0400689 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400690 struct nfs_client *clp = nfss->nfs_client;
Chuck Lever82d101d2008-03-14 14:10:37 -0400691 u32 version = clp->rpc_ops->version;
Suresh Jayaraman7c563cc2010-09-23 14:26:48 -0400692 int local_flock, local_fcntl;
David Howellsf7b422b2006-06-09 09:34:33 -0400693
Trond Myklebust7bbceb62012-03-02 14:00:20 -0500694 nfs_show_nfs_version(m, version, clp->cl_minorversion);
Chuck Lever2d767432008-03-14 14:10:08 -0400695 seq_printf(m, ",rsize=%u", nfss->rsize);
696 seq_printf(m, ",wsize=%u", nfss->wsize);
Chuck Lever82d101d2008-03-14 14:10:37 -0400697 if (nfss->bsize != 0)
698 seq_printf(m, ",bsize=%u", nfss->bsize);
699 seq_printf(m, ",namlen=%u", nfss->namelen);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400700 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400701 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400702 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400703 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400704 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400705 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400706 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400707 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
David Howellsf7b422b2006-06-09 09:34:33 -0400708 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
709 if (nfss->flags & nfs_infop->flag)
710 seq_puts(m, nfs_infop->str);
711 else
712 seq_puts(m, nfs_infop->nostr);
713 }
Trond Myklebust2446ab62012-03-01 17:00:56 -0500714 rcu_read_lock();
\"Talpey, Thomas\56928ed2007-09-10 13:48:47 -0400715 seq_printf(m, ",proto=%s",
Jeff Laytonee671b02009-12-03 15:58:56 -0500716 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
Trond Myklebust2446ab62012-03-01 17:00:56 -0500717 rcu_read_unlock();
Chuck Lever82d101d2008-03-14 14:10:37 -0400718 if (version == 4) {
719 if (nfss->port != NFS_PORT)
720 seq_printf(m, ",port=%u", nfss->port);
721 } else
722 if (nfss->port)
723 seq_printf(m, ",port=%u", nfss->port);
724
Trond Myklebust33170232007-12-20 16:03:59 -0500725 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
726 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
Trond Myklebust81039f12006-06-09 09:34:34 -0400727 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
Chuck Lever82d101d2008-03-14 14:10:37 -0400728
729 if (version != 4)
730 nfs_show_mountd_options(m, nfss, showdefaults);
Trond Myklebust0be81892010-06-18 12:23:58 -0400731 else
732 nfs_show_nfsv4_options(m, nfss, showdefaults);
Chuck Lever82d101d2008-03-14 14:10:37 -0400733
David Howellsb797cac2009-04-03 16:42:48 +0100734 if (nfss->options & NFS_OPTION_FSCACHE)
735 seq_printf(m, ",fsc");
Patrick J. LoPresti9b00c642010-08-10 17:28:01 -0400736
737 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONEG) {
738 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONE)
739 seq_printf(m, ",lookupcache=none");
740 else
741 seq_printf(m, ",lookupcache=pos");
742 }
Suresh Jayaraman7c563cc2010-09-23 14:26:48 -0400743
744 local_flock = nfss->flags & NFS_MOUNT_LOCAL_FLOCK;
745 local_fcntl = nfss->flags & NFS_MOUNT_LOCAL_FCNTL;
746
747 if (!local_flock && !local_fcntl)
748 seq_printf(m, ",local_lock=none");
749 else if (local_flock && local_fcntl)
750 seq_printf(m, ",local_lock=all");
751 else if (local_flock)
752 seq_printf(m, ",local_lock=flock");
753 else
754 seq_printf(m, ",local_lock=posix");
David Howellsf7b422b2006-06-09 09:34:33 -0400755}
756
757/*
758 * Describe the mount options on this VFS mountpoint
759 */
Al Viro34c80b12011-12-08 21:32:45 -0500760static int nfs_show_options(struct seq_file *m, struct dentry *root)
David Howellsf7b422b2006-06-09 09:34:33 -0400761{
Al Viro34c80b12011-12-08 21:32:45 -0500762 struct nfs_server *nfss = NFS_SB(root->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400763
764 nfs_show_mount_options(m, nfss, 0);
765
Trond Myklebust2446ab62012-03-01 17:00:56 -0500766 rcu_read_lock();
Chuck Lever5d8515c2007-12-10 14:57:16 -0500767 seq_printf(m, ",addr=%s",
768 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
769 RPC_DISPLAY_ADDR));
Trond Myklebust2446ab62012-03-01 17:00:56 -0500770 rcu_read_unlock();
David Howellsf7b422b2006-06-09 09:34:33 -0400771
772 return 0;
773}
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700774
775#ifdef CONFIG_NFS_V4
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300776#ifdef CONFIG_NFS_V4_1
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700777static void show_sessions(struct seq_file *m, struct nfs_server *server)
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300778{
779 if (nfs4_has_session(server->nfs_client))
780 seq_printf(m, ",sessions");
781}
782#else
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700783static void show_sessions(struct seq_file *m, struct nfs_server *server) {}
784#endif
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300785#endif
786
787#ifdef CONFIG_NFS_V4_1
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700788static void show_pnfs(struct seq_file *m, struct nfs_server *server)
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300789{
790 seq_printf(m, ",pnfs=");
791 if (server->pnfs_curr_ld)
792 seq_printf(m, "%s", server->pnfs_curr_ld->name);
793 else
794 seq_printf(m, "not configured");
795}
Trond Myklebust7e03b7c2012-03-04 18:12:57 -0500796
797static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
798{
799 if (nfss->nfs_client && nfss->nfs_client->impl_id) {
800 struct nfs41_impl_id *impl_id = nfss->nfs_client->impl_id;
801 seq_printf(m, "\n\timpl_id:\tname='%s',domain='%s',"
802 "date='%llu,%u'",
803 impl_id->name, impl_id->domain,
804 impl_id->date.seconds, impl_id->date.nseconds);
805 }
806}
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700807#else
Trond Myklebust7e03b7c2012-03-04 18:12:57 -0500808#ifdef CONFIG_NFS_V4
809static void show_pnfs(struct seq_file *m, struct nfs_server *server)
810{
811}
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700812#endif
Trond Myklebust7e03b7c2012-03-04 18:12:57 -0500813static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
814{
815}
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700816#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400817
Al Virod861c632011-12-08 21:32:45 -0500818static int nfs_show_devname(struct seq_file *m, struct dentry *root)
Al Viroc7f404b2011-03-16 06:59:40 -0400819{
820 char *page = (char *) __get_free_page(GFP_KERNEL);
821 char *devname, *dummy;
822 int err = 0;
823 if (!page)
824 return -ENOMEM;
Al Virod861c632011-12-08 21:32:45 -0500825 devname = nfs_path(&dummy, root, page, PAGE_SIZE);
Al Viroc7f404b2011-03-16 06:59:40 -0400826 if (IS_ERR(devname))
827 err = PTR_ERR(devname);
828 else
829 seq_escape(m, devname, " \t\n\\");
830 free_page((unsigned long)page);
831 return err;
832}
833
Al Viroa6322de2011-12-08 21:37:57 -0500834static int nfs_show_path(struct seq_file *m, struct dentry *dentry)
Al Viroc7f404b2011-03-16 06:59:40 -0400835{
836 seq_puts(m, "/");
837 return 0;
838}
839
David Howellsf7b422b2006-06-09 09:34:33 -0400840/*
841 * Present statistical information for this VFS mountpoint
842 */
Al Viro64132372011-12-08 20:51:13 -0500843static int nfs_show_stats(struct seq_file *m, struct dentry *root)
David Howellsf7b422b2006-06-09 09:34:33 -0400844{
845 int i, cpu;
Al Viro64132372011-12-08 20:51:13 -0500846 struct nfs_server *nfss = NFS_SB(root->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400847 struct rpc_auth *auth = nfss->client->cl_auth;
848 struct nfs_iostats totals = { };
849
850 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
851
852 /*
853 * Display all mount option settings
854 */
855 seq_printf(m, "\n\topts:\t");
Al Viro64132372011-12-08 20:51:13 -0500856 seq_puts(m, root->d_sb->s_flags & MS_RDONLY ? "ro" : "rw");
857 seq_puts(m, root->d_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
858 seq_puts(m, root->d_sb->s_flags & MS_NOATIME ? ",noatime" : "");
859 seq_puts(m, root->d_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
David Howellsf7b422b2006-06-09 09:34:33 -0400860 nfs_show_mount_options(m, nfss, 1);
861
862 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
863
Trond Myklebust7e03b7c2012-03-04 18:12:57 -0500864 show_implementation_id(m, nfss);
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500865
David Howellsf7b422b2006-06-09 09:34:33 -0400866 seq_printf(m, "\n\tcaps:\t");
867 seq_printf(m, "caps=0x%x", nfss->caps);
Chuck Lever2d767432008-03-14 14:10:08 -0400868 seq_printf(m, ",wtmult=%u", nfss->wtmult);
869 seq_printf(m, ",dtsize=%u", nfss->dtsize);
870 seq_printf(m, ",bsize=%u", nfss->bsize);
871 seq_printf(m, ",namlen=%u", nfss->namelen);
David Howellsf7b422b2006-06-09 09:34:33 -0400872
873#ifdef CONFIG_NFS_V4
Trond Myklebust40c553192007-12-14 14:56:07 -0500874 if (nfss->nfs_client->rpc_ops->version == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400875 seq_printf(m, "\n\tnfsv4:\t");
876 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
877 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
878 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300879 show_sessions(m, nfss);
880 show_pnfs(m, nfss);
David Howellsf7b422b2006-06-09 09:34:33 -0400881 }
882#endif
883
884 /*
885 * Display security flavor in effect for this mount
886 */
Chuck Lever2d767432008-03-14 14:10:08 -0400887 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400888 if (auth->au_flavor)
Chuck Lever2d767432008-03-14 14:10:08 -0400889 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400890
891 /*
892 * Display superblock I/O counters
893 */
894 for_each_possible_cpu(cpu) {
895 struct nfs_iostats *stats;
896
897 preempt_disable();
898 stats = per_cpu_ptr(nfss->io_stats, cpu);
899
900 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
901 totals.events[i] += stats->events[i];
902 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
903 totals.bytes[i] += stats->bytes[i];
David Howells6a510912009-04-03 16:42:43 +0100904#ifdef CONFIG_NFS_FSCACHE
905 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
906 totals.fscache[i] += stats->fscache[i];
907#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400908
909 preempt_enable();
910 }
911
912 seq_printf(m, "\n\tevents:\t");
913 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
914 seq_printf(m, "%lu ", totals.events[i]);
915 seq_printf(m, "\n\tbytes:\t");
916 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
917 seq_printf(m, "%Lu ", totals.bytes[i]);
David Howells6a510912009-04-03 16:42:43 +0100918#ifdef CONFIG_NFS_FSCACHE
919 if (nfss->options & NFS_OPTION_FSCACHE) {
920 seq_printf(m, "\n\tfsc:\t");
921 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
922 seq_printf(m, "%Lu ", totals.bytes[i]);
923 }
924#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400925 seq_printf(m, "\n");
926
927 rpc_print_iostats(m, nfss->client);
928
929 return 0;
930}
931
932/*
933 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400934 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400935 */
Al Viro42faad92008-04-24 07:21:56 -0400936static void nfs_umount_begin(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -0400937{
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200938 struct nfs_server *server;
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400939 struct rpc_clnt *rpc;
940
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200941 server = NFS_SB(sb);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400942 /* -EIO all pending I/O */
943 rpc = server->client_acl;
944 if (!IS_ERR(rpc))
945 rpc_killall_tasks(rpc);
946 rpc = server->client;
947 if (!IS_ERR(rpc))
948 rpc_killall_tasks(rpc);
David Howellsf7b422b2006-06-09 09:34:33 -0400949}
950
Bryan Schumakerdb833352012-05-10 15:07:38 -0400951static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(void)
Chuck Lever9423a082009-09-23 14:36:38 -0400952{
953 struct nfs_parsed_mount_data *data;
954
955 data = kzalloc(sizeof(*data), GFP_KERNEL);
956 if (data) {
Chuck Lever9423a082009-09-23 14:36:38 -0400957 data->acregmin = NFS_DEF_ACREGMIN;
958 data->acregmax = NFS_DEF_ACREGMAX;
959 data->acdirmin = NFS_DEF_ACDIRMIN;
960 data->acdirmax = NFS_DEF_ACDIRMAX;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400961 data->mount_server.port = NFS_UNSPEC_PORT;
Chuck Lever9423a082009-09-23 14:36:38 -0400962 data->nfs_server.port = NFS_UNSPEC_PORT;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400963 data->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Lever9423a082009-09-23 14:36:38 -0400964 data->auth_flavors[0] = RPC_AUTH_UNIX;
965 data->auth_flavor_len = 1;
966 data->minorversion = 0;
Bryan Schumakerb72e4f42012-05-10 15:07:40 -0400967 data->need_mount = true;
Trond Myklebust9937347a2012-02-19 08:44:07 +0100968 data->net = current->nsproxy->net_ns;
Jeff Layton8a0d5512011-12-20 06:57:45 -0500969 security_init_mnt_opts(&data->lsm_opts);
Chuck Lever9423a082009-09-23 14:36:38 -0400970 }
971 return data;
972}
973
Jeff Layton8a0d5512011-12-20 06:57:45 -0500974static void nfs_free_parsed_mount_data(struct nfs_parsed_mount_data *data)
975{
976 if (data) {
977 kfree(data->client_address);
978 kfree(data->mount_server.hostname);
979 kfree(data->nfs_server.export_path);
980 kfree(data->nfs_server.hostname);
981 kfree(data->fscache_uniq);
982 security_free_mnt_opts(&data->lsm_opts);
983 kfree(data);
984 }
985}
986
David Howellsf7b422b2006-06-09 09:34:33 -0400987/*
Chuck Levercdcd7f92007-12-10 14:57:45 -0500988 * Sanity-check a server address provided by the mount command.
989 *
990 * Address family must be initialized, and address must not be
991 * the ANY address for that family.
Chuck Leverfc50d582007-07-01 12:12:46 -0400992 */
993static int nfs_verify_server_address(struct sockaddr *addr)
994{
995 switch (addr->sa_family) {
996 case AF_INET: {
Chuck Levercdcd7f92007-12-10 14:57:45 -0500997 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
Al Viroe6f1ceb2008-03-17 22:44:53 -0700998 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
Chuck Levercdcd7f92007-12-10 14:57:45 -0500999 }
1000 case AF_INET6: {
1001 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
1002 return !ipv6_addr_any(sa);
Chuck Leverfc50d582007-07-01 12:12:46 -04001003 }
1004 }
1005
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001006 dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
Chuck Leverfc50d582007-07-01 12:12:46 -04001007 return 0;
1008}
1009
Chuck Lever9412b922007-12-10 14:59:21 -05001010/*
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001011 * Select between a default port value and a user-specified port value.
1012 * If a zero value is set, then autobind will be used.
1013 */
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001014static void nfs_set_port(struct sockaddr *sap, int *port,
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001015 const unsigned short default_port)
1016{
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001017 if (*port == NFS_UNSPEC_PORT)
1018 *port = default_port;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001019
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001020 rpc_set_port(sap, *port);
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001021}
1022
1023/*
Trond Myklebust259875e2008-07-02 14:43:47 -04001024 * Sanity check the NFS transport protocol.
1025 *
1026 */
1027static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
1028{
1029 switch (mnt->nfs_server.protocol) {
1030 case XPRT_TRANSPORT_UDP:
1031 case XPRT_TRANSPORT_TCP:
1032 case XPRT_TRANSPORT_RDMA:
1033 break;
1034 default:
1035 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1036 }
1037}
1038
1039/*
1040 * For text based NFSv2/v3 mounts, the mount protocol transport default
1041 * settings should depend upon the specified NFS transport.
1042 */
1043static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
1044{
1045 nfs_validate_transport_protocol(mnt);
1046
1047 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
1048 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
1049 return;
1050 switch (mnt->nfs_server.protocol) {
1051 case XPRT_TRANSPORT_UDP:
1052 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
1053 break;
1054 case XPRT_TRANSPORT_TCP:
1055 case XPRT_TRANSPORT_RDMA:
1056 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
1057 }
1058}
1059
1060/*
Chuck Lever01060c82008-06-24 16:33:38 -04001061 * Parse the value of the 'sec=' option.
Chuck Lever01060c82008-06-24 16:33:38 -04001062 */
1063static int nfs_parse_security_flavors(char *value,
1064 struct nfs_parsed_mount_data *mnt)
1065{
1066 substring_t args[MAX_OPT_ARGS];
1067
1068 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
1069
1070 switch (match_token(value, nfs_secflavor_tokens, args)) {
1071 case Opt_sec_none:
Chuck Lever01060c82008-06-24 16:33:38 -04001072 mnt->auth_flavors[0] = RPC_AUTH_NULL;
1073 break;
1074 case Opt_sec_sys:
Chuck Lever01060c82008-06-24 16:33:38 -04001075 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
1076 break;
1077 case Opt_sec_krb5:
Chuck Lever01060c82008-06-24 16:33:38 -04001078 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
1079 break;
1080 case Opt_sec_krb5i:
Chuck Lever01060c82008-06-24 16:33:38 -04001081 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
1082 break;
1083 case Opt_sec_krb5p:
Chuck Lever01060c82008-06-24 16:33:38 -04001084 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
1085 break;
1086 case Opt_sec_lkey:
Chuck Lever01060c82008-06-24 16:33:38 -04001087 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
1088 break;
1089 case Opt_sec_lkeyi:
Chuck Lever01060c82008-06-24 16:33:38 -04001090 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
1091 break;
1092 case Opt_sec_lkeyp:
Chuck Lever01060c82008-06-24 16:33:38 -04001093 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
1094 break;
1095 case Opt_sec_spkm:
Chuck Lever01060c82008-06-24 16:33:38 -04001096 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
1097 break;
1098 case Opt_sec_spkmi:
Chuck Lever01060c82008-06-24 16:33:38 -04001099 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
1100 break;
1101 case Opt_sec_spkmp:
Chuck Lever01060c82008-06-24 16:33:38 -04001102 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
1103 break;
1104 default:
1105 return 0;
1106 }
1107
Bryan Schumaker9b7160c2011-04-13 14:31:30 -04001108 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
Chuck Lever059f90b2009-08-09 15:09:31 -04001109 mnt->auth_flavor_len = 1;
Chuck Lever01060c82008-06-24 16:33:38 -04001110 return 1;
1111}
1112
Trond Myklebust0d71b052012-03-02 13:59:49 -05001113static int nfs_parse_version_string(char *string,
1114 struct nfs_parsed_mount_data *mnt,
1115 substring_t *args)
1116{
1117 mnt->flags &= ~NFS_MOUNT_VER3;
1118 switch (match_token(string, nfs_vers_tokens, args)) {
1119 case Opt_vers_2:
1120 mnt->version = 2;
1121 break;
1122 case Opt_vers_3:
1123 mnt->flags |= NFS_MOUNT_VER3;
1124 mnt->version = 3;
1125 break;
1126 case Opt_vers_4:
1127 /* Backward compatibility option. In future,
1128 * the mount program should always supply
1129 * a NFSv4 minor version number.
1130 */
1131 mnt->version = 4;
1132 break;
1133 case Opt_vers_4_0:
1134 mnt->version = 4;
1135 mnt->minorversion = 0;
1136 break;
1137 case Opt_vers_4_1:
1138 mnt->version = 4;
1139 mnt->minorversion = 1;
1140 break;
1141 default:
1142 return 0;
1143 }
1144 return 1;
1145}
1146
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001147static int nfs_get_option_str(substring_t args[], char **option)
1148{
1149 kfree(*option);
1150 *option = match_strdup(args);
1151 return !option;
1152}
1153
1154static int nfs_get_option_ul(substring_t args[], unsigned long *option)
1155{
1156 int rc;
1157 char *string;
1158
1159 string = match_strdup(args);
1160 if (string == NULL)
1161 return -ENOMEM;
1162 rc = strict_strtoul(string, 10, option);
1163 kfree(string);
1164
1165 return rc;
1166}
1167
Chuck Lever01060c82008-06-24 16:33:38 -04001168/*
Chuck Leverbf0fd762007-07-01 12:13:44 -04001169 * Error-check and convert a string of mount options from user space into
Chuck Leverf45663c2008-06-24 19:28:02 -04001170 * a data structure. The whole mount string is processed; bad options are
1171 * skipped as they are encountered. If there were no errors, return 1;
1172 * otherwise return 0 (zero).
Chuck Leverbf0fd762007-07-01 12:13:44 -04001173 */
1174static int nfs_parse_mount_options(char *raw,
1175 struct nfs_parsed_mount_data *mnt)
1176{
Eric Parisf9c3a382008-03-05 14:20:18 -05001177 char *p, *string, *secdata;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001178 int rc, sloppy = 0, invalid_option = 0;
Jeff Laytonee671b02009-12-03 15:58:56 -05001179 unsigned short protofamily = AF_UNSPEC;
1180 unsigned short mountfamily = AF_UNSPEC;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001181
1182 if (!raw) {
1183 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
1184 return 1;
1185 }
1186 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
1187
Eric Parisf9c3a382008-03-05 14:20:18 -05001188 secdata = alloc_secdata();
1189 if (!secdata)
1190 goto out_nomem;
1191
1192 rc = security_sb_copy_data(raw, secdata);
1193 if (rc)
1194 goto out_security_failure;
1195
1196 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
1197 if (rc)
1198 goto out_security_failure;
1199
1200 free_secdata(secdata);
1201
Chuck Leverbf0fd762007-07-01 12:13:44 -04001202 while ((p = strsep(&raw, ",")) != NULL) {
1203 substring_t args[MAX_OPT_ARGS];
Chuck Levera5a16ba2009-06-17 18:02:14 -07001204 unsigned long option;
1205 int token;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001206
1207 if (!*p)
1208 continue;
1209
1210 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
1211
1212 token = match_token(p, nfs_mount_option_tokens, args);
1213 switch (token) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001214
1215 /*
1216 * boolean options: foo/nofoo
1217 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001218 case Opt_soft:
1219 mnt->flags |= NFS_MOUNT_SOFT;
1220 break;
1221 case Opt_hard:
1222 mnt->flags &= ~NFS_MOUNT_SOFT;
1223 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001224 case Opt_posix:
1225 mnt->flags |= NFS_MOUNT_POSIX;
1226 break;
1227 case Opt_noposix:
1228 mnt->flags &= ~NFS_MOUNT_POSIX;
1229 break;
1230 case Opt_cto:
1231 mnt->flags &= ~NFS_MOUNT_NOCTO;
1232 break;
1233 case Opt_nocto:
1234 mnt->flags |= NFS_MOUNT_NOCTO;
1235 break;
1236 case Opt_ac:
1237 mnt->flags &= ~NFS_MOUNT_NOAC;
1238 break;
1239 case Opt_noac:
1240 mnt->flags |= NFS_MOUNT_NOAC;
1241 break;
1242 case Opt_lock:
1243 mnt->flags &= ~NFS_MOUNT_NONLM;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001244 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1245 NFS_MOUNT_LOCAL_FCNTL);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001246 break;
1247 case Opt_nolock:
1248 mnt->flags |= NFS_MOUNT_NONLM;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001249 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1250 NFS_MOUNT_LOCAL_FCNTL);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001251 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001252 case Opt_udp:
1253 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001254 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001255 break;
1256 case Opt_tcp:
1257 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001258 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001259 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001260 case Opt_rdma:
1261 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1262 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001263 xprt_load_transport(p);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001264 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001265 case Opt_acl:
1266 mnt->flags &= ~NFS_MOUNT_NOACL;
1267 break;
1268 case Opt_noacl:
1269 mnt->flags |= NFS_MOUNT_NOACL;
1270 break;
1271 case Opt_rdirplus:
1272 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1273 break;
1274 case Opt_nordirplus:
1275 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1276 break;
Trond Myklebust75180df2007-05-16 16:53:28 -04001277 case Opt_sharecache:
1278 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1279 break;
1280 case Opt_nosharecache:
1281 mnt->flags |= NFS_MOUNT_UNSHARED;
1282 break;
Chuck Leverd7403512008-12-23 15:21:37 -05001283 case Opt_resvport:
1284 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1285 break;
1286 case Opt_noresvport:
1287 mnt->flags |= NFS_MOUNT_NORESVPORT;
1288 break;
David Howellsb797cac2009-04-03 16:42:48 +01001289 case Opt_fscache:
1290 mnt->options |= NFS_OPTION_FSCACHE;
1291 kfree(mnt->fscache_uniq);
1292 mnt->fscache_uniq = NULL;
1293 break;
1294 case Opt_nofscache:
1295 mnt->options &= ~NFS_OPTION_FSCACHE;
1296 kfree(mnt->fscache_uniq);
1297 mnt->fscache_uniq = NULL;
1298 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001299
Chuck Leverf45663c2008-06-24 19:28:02 -04001300 /*
1301 * options that take numeric values
1302 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001303 case Opt_port:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001304 if (nfs_get_option_ul(args, &option) ||
1305 option > USHRT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001306 goto out_invalid_value;
1307 mnt->nfs_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001308 break;
1309 case Opt_rsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001310 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001311 goto out_invalid_value;
1312 mnt->rsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001313 break;
1314 case Opt_wsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001315 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001316 goto out_invalid_value;
1317 mnt->wsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001318 break;
1319 case Opt_bsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001320 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001321 goto out_invalid_value;
1322 mnt->bsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001323 break;
1324 case Opt_timeo:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001325 if (nfs_get_option_ul(args, &option) || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001326 goto out_invalid_value;
1327 mnt->timeo = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001328 break;
1329 case Opt_retrans:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001330 if (nfs_get_option_ul(args, &option) || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001331 goto out_invalid_value;
1332 mnt->retrans = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001333 break;
1334 case Opt_acregmin:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001335 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001336 goto out_invalid_value;
1337 mnt->acregmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001338 break;
1339 case Opt_acregmax:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001340 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001341 goto out_invalid_value;
1342 mnt->acregmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001343 break;
1344 case Opt_acdirmin:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001345 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001346 goto out_invalid_value;
1347 mnt->acdirmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001348 break;
1349 case Opt_acdirmax:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001350 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001351 goto out_invalid_value;
1352 mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001353 break;
1354 case Opt_actimeo:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001355 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001356 goto out_invalid_value;
1357 mnt->acregmin = mnt->acregmax =
1358 mnt->acdirmin = mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001359 break;
1360 case Opt_namelen:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001361 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001362 goto out_invalid_value;
1363 mnt->namlen = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001364 break;
1365 case Opt_mountport:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001366 if (nfs_get_option_ul(args, &option) ||
1367 option > USHRT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001368 goto out_invalid_value;
1369 mnt->mount_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001370 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001371 case Opt_mountvers:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001372 if (nfs_get_option_ul(args, &option) ||
Chuck Leverf45663c2008-06-24 19:28:02 -04001373 option < NFS_MNT_VERSION ||
Chuck Leverd23c45f2009-06-17 18:02:13 -07001374 option > NFS_MNT3_VERSION)
1375 goto out_invalid_value;
1376 mnt->mount_server.version = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001377 break;
Mike Sager3fd5be92009-04-01 09:21:48 -04001378 case Opt_minorversion:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001379 if (nfs_get_option_ul(args, &option))
Chuck Leverf3f4f4e2009-08-09 15:09:29 -04001380 goto out_invalid_value;
1381 if (option > NFS4_MAX_MINOR_VERSION)
1382 goto out_invalid_value;
1383 mnt->minorversion = option;
Mike Sager3fd5be92009-04-01 09:21:48 -04001384 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001385
Chuck Leverf45663c2008-06-24 19:28:02 -04001386 /*
1387 * options that take text values
1388 */
Trond Myklebust0d71b052012-03-02 13:59:49 -05001389 case Opt_nfsvers:
1390 string = match_strdup(args);
1391 if (string == NULL)
1392 goto out_nomem;
1393 rc = nfs_parse_version_string(string, mnt, args);
1394 kfree(string);
1395 if (!rc)
1396 goto out_invalid_value;
1397 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001398 case Opt_sec:
1399 string = match_strdup(args);
1400 if (string == NULL)
1401 goto out_nomem;
Chuck Lever01060c82008-06-24 16:33:38 -04001402 rc = nfs_parse_security_flavors(string, mnt);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001403 kfree(string);
Chuck Leverf45663c2008-06-24 19:28:02 -04001404 if (!rc) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001405 dfprintk(MOUNT, "NFS: unrecognized "
1406 "security flavor\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001407 return 0;
Chuck Leverf45663c2008-06-24 19:28:02 -04001408 }
Chuck Leverbf0fd762007-07-01 12:13:44 -04001409 break;
1410 case Opt_proto:
1411 string = match_strdup(args);
1412 if (string == NULL)
1413 goto out_nomem;
1414 token = match_token(string,
1415 nfs_xprt_protocol_tokens, args);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001416
Jeff Laytonee671b02009-12-03 15:58:56 -05001417 protofamily = AF_INET;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001418 switch (token) {
Jeff Laytonee671b02009-12-03 15:58:56 -05001419 case Opt_xprt_udp6:
1420 protofamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001421 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001422 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001423 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001424 break;
Jeff Laytonee671b02009-12-03 15:58:56 -05001425 case Opt_xprt_tcp6:
1426 protofamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001427 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001428 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001429 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001430 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001431 case Opt_xprt_rdma:
1432 /* vector side protocols to TCP */
1433 mnt->flags |= NFS_MOUNT_TCP;
1434 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001435 xprt_load_transport(string);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001436 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001437 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001438 dfprintk(MOUNT, "NFS: unrecognized "
1439 "transport protocol\n");
Yinghai Lu4223a4a2009-10-20 14:13:46 +09001440 kfree(string);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001441 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001442 }
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001443 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001444 break;
1445 case Opt_mountproto:
1446 string = match_strdup(args);
1447 if (string == NULL)
1448 goto out_nomem;
1449 token = match_token(string,
1450 nfs_xprt_protocol_tokens, args);
Trond Myklebustd508afb2009-04-06 16:41:35 -07001451 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001452
Jeff Laytonee671b02009-12-03 15:58:56 -05001453 mountfamily = AF_INET;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001454 switch (token) {
Jeff Laytonee671b02009-12-03 15:58:56 -05001455 case Opt_xprt_udp6:
1456 mountfamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001457 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001458 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001459 break;
Jeff Laytonee671b02009-12-03 15:58:56 -05001460 case Opt_xprt_tcp6:
1461 mountfamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001462 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001463 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001464 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001465 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001466 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001467 dfprintk(MOUNT, "NFS: unrecognized "
1468 "transport protocol\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001469 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001470 }
1471 break;
1472 case Opt_addr:
1473 string = match_strdup(args);
1474 if (string == NULL)
1475 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001476 mnt->nfs_server.addrlen =
Stanislav Kinsburskyb48e1272012-01-26 15:11:57 +04001477 rpc_pton(mnt->net, string, strlen(string),
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001478 (struct sockaddr *)
1479 &mnt->nfs_server.address,
1480 sizeof(mnt->nfs_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001481 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001482 if (mnt->nfs_server.addrlen == 0)
1483 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001484 break;
1485 case Opt_clientaddr:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001486 if (nfs_get_option_str(args, &mnt->client_address))
Chuck Leverbf0fd762007-07-01 12:13:44 -04001487 goto out_nomem;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001488 break;
Chuck Lever33832032007-12-10 14:59:13 -05001489 case Opt_mounthost:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001490 if (nfs_get_option_str(args,
1491 &mnt->mount_server.hostname))
Chuck Lever33832032007-12-10 14:59:13 -05001492 goto out_nomem;
Chuck Lever33832032007-12-10 14:59:13 -05001493 break;
Chuck Lever0ac83772007-09-11 18:01:04 -04001494 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001495 string = match_strdup(args);
1496 if (string == NULL)
1497 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001498 mnt->mount_server.addrlen =
Stanislav Kinsburskyb48e1272012-01-26 15:11:57 +04001499 rpc_pton(mnt->net, string, strlen(string),
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001500 (struct sockaddr *)
1501 &mnt->mount_server.address,
1502 sizeof(mnt->mount_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001503 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001504 if (mnt->mount_server.addrlen == 0)
1505 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001506 break;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001507 case Opt_lookupcache:
1508 string = match_strdup(args);
1509 if (string == NULL)
1510 goto out_nomem;
1511 token = match_token(string,
1512 nfs_lookupcache_tokens, args);
1513 kfree(string);
1514 switch (token) {
1515 case Opt_lookupcache_all:
1516 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1517 break;
1518 case Opt_lookupcache_positive:
1519 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1520 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1521 break;
1522 case Opt_lookupcache_none:
1523 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1524 break;
1525 default:
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001526 dfprintk(MOUNT, "NFS: invalid "
1527 "lookupcache argument\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001528 return 0;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001529 };
1530 break;
Chuck Levera6d5ff62010-05-07 13:33:58 -04001531 case Opt_fscache_uniq:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001532 if (nfs_get_option_str(args, &mnt->fscache_uniq))
Chuck Levera6d5ff62010-05-07 13:33:58 -04001533 goto out_nomem;
Chuck Levera6d5ff62010-05-07 13:33:58 -04001534 mnt->options |= NFS_OPTION_FSCACHE;
1535 break;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001536 case Opt_local_lock:
1537 string = match_strdup(args);
1538 if (string == NULL)
1539 goto out_nomem;
1540 token = match_token(string, nfs_local_lock_tokens,
1541 args);
1542 kfree(string);
1543 switch (token) {
1544 case Opt_local_lock_all:
1545 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1546 NFS_MOUNT_LOCAL_FCNTL);
1547 break;
1548 case Opt_local_lock_flock:
1549 mnt->flags |= NFS_MOUNT_LOCAL_FLOCK;
1550 break;
1551 case Opt_local_lock_posix:
1552 mnt->flags |= NFS_MOUNT_LOCAL_FCNTL;
1553 break;
1554 case Opt_local_lock_none:
1555 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1556 NFS_MOUNT_LOCAL_FCNTL);
1557 break;
1558 default:
1559 dfprintk(MOUNT, "NFS: invalid "
1560 "local_lock argument\n");
1561 return 0;
1562 };
1563 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001564
Chuck Leverf45663c2008-06-24 19:28:02 -04001565 /*
1566 * Special options
1567 */
1568 case Opt_sloppy:
1569 sloppy = 1;
1570 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1571 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001572 case Opt_userspace:
1573 case Opt_deprecated:
Chuck Leverd33e4df2008-06-12 12:37:41 -04001574 dfprintk(MOUNT, "NFS: ignoring mount option "
1575 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001576 break;
1577
1578 default:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001579 invalid_option = 1;
Chuck Leverf45663c2008-06-24 19:28:02 -04001580 dfprintk(MOUNT, "NFS: unrecognized mount option "
1581 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001582 }
1583 }
1584
Chuck Leverd23c45f2009-06-17 18:02:13 -07001585 if (!sloppy && invalid_option)
1586 return 0;
1587
Weston Andros Adamson571b7552012-02-01 14:06:41 -05001588 if (mnt->minorversion && mnt->version != 4)
1589 goto out_minorversion_mismatch;
1590
Jeff Laytonee671b02009-12-03 15:58:56 -05001591 /*
1592 * verify that any proto=/mountproto= options match the address
1593 * familiies in the addr=/mountaddr= options.
1594 */
1595 if (protofamily != AF_UNSPEC &&
1596 protofamily != mnt->nfs_server.address.ss_family)
1597 goto out_proto_mismatch;
1598
1599 if (mountfamily != AF_UNSPEC) {
1600 if (mnt->mount_server.addrlen) {
1601 if (mountfamily != mnt->mount_server.address.ss_family)
1602 goto out_mountproto_mismatch;
1603 } else {
1604 if (mountfamily != mnt->nfs_server.address.ss_family)
1605 goto out_mountproto_mismatch;
1606 }
1607 }
1608
Chuck Leverbf0fd762007-07-01 12:13:44 -04001609 return 1;
1610
Jeff Laytonee671b02009-12-03 15:58:56 -05001611out_mountproto_mismatch:
1612 printk(KERN_INFO "NFS: mount server address does not match mountproto= "
1613 "option\n");
1614 return 0;
1615out_proto_mismatch:
1616 printk(KERN_INFO "NFS: server address does not match proto= option\n");
1617 return 0;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001618out_invalid_address:
1619 printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
1620 return 0;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001621out_invalid_value:
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001622 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001623 return 0;
Weston Andros Adamson571b7552012-02-01 14:06:41 -05001624out_minorversion_mismatch:
1625 printk(KERN_INFO "NFS: mount option vers=%u does not support "
1626 "minorversion=%u\n", mnt->version, mnt->minorversion);
1627 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001628out_nomem:
1629 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1630 return 0;
Eric Parisf9c3a382008-03-05 14:20:18 -05001631out_security_failure:
1632 free_secdata(secdata);
1633 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1634 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001635}
1636
1637/*
Chuck Leverec88f282009-08-09 15:09:32 -04001638 * Match the requested auth flavors with the list returned by
1639 * the server. Returns zero and sets the mount's authentication
1640 * flavor on success; returns -EACCES if server does not support
1641 * the requested flavor.
1642 */
1643static int nfs_walk_authlist(struct nfs_parsed_mount_data *args,
1644 struct nfs_mount_request *request)
1645{
1646 unsigned int i, j, server_authlist_len = *(request->auth_flav_len);
1647
1648 /*
Chuck Lever5eecfde2009-08-21 17:50:30 -04001649 * Certain releases of Linux's mountd return an empty
1650 * flavor list. To prevent behavioral regression with
1651 * these servers (ie. rejecting mounts that used to
1652 * succeed), revert to pre-2.6.32 behavior (no checking)
1653 * if the returned flavor list is empty.
1654 */
1655 if (server_authlist_len == 0)
1656 return 0;
1657
1658 /*
Chuck Leverec88f282009-08-09 15:09:32 -04001659 * We avoid sophisticated negotiating here, as there are
1660 * plenty of cases where we can get it wrong, providing
1661 * either too little or too much security.
1662 *
1663 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1664 * flavor listed first. However, some servers list
1665 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1666 * preferred default, in args->auth_flavors[0] if user
1667 * didn't specify sec= mount option.
1668 */
1669 for (i = 0; i < args->auth_flavor_len; i++)
1670 for (j = 0; j < server_authlist_len; j++)
1671 if (args->auth_flavors[i] == request->auth_flavs[j]) {
1672 dfprintk(MOUNT, "NFS: using auth flavor %d\n",
1673 request->auth_flavs[j]);
1674 args->auth_flavors[0] = request->auth_flavs[j];
1675 return 0;
1676 }
1677
1678 dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n");
1679 nfs_umount(request);
1680 return -EACCES;
1681}
1682
1683/*
Chuck Lever0076d7b2007-07-01 12:13:49 -04001684 * Use the remote server's MOUNT service to request the NFS file handle
1685 * corresponding to the provided path.
1686 */
Bryan Schumaker486aa692012-05-10 15:07:39 -04001687static int nfs_request_mount(struct nfs_parsed_mount_data *args,
1688 struct nfs_fh *root_fh)
Chuck Lever0076d7b2007-07-01 12:13:49 -04001689{
Chuck Leverec88f282009-08-09 15:09:32 -04001690 rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS];
1691 unsigned int server_authlist_len = ARRAY_SIZE(server_authlist);
Chuck Leverc5d120f2008-12-23 15:21:35 -05001692 struct nfs_mount_request request = {
1693 .sap = (struct sockaddr *)
1694 &args->mount_server.address,
1695 .dirpath = args->nfs_server.export_path,
1696 .protocol = args->mount_server.protocol,
1697 .fh = root_fh,
Chuck Lever50a737f2008-12-23 15:21:37 -05001698 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
Chuck Leverec88f282009-08-09 15:09:32 -04001699 .auth_flav_len = &server_authlist_len,
1700 .auth_flavs = server_authlist,
Stanislav Kinsbursky6d59b8d2012-01-10 16:12:54 +04001701 .net = args->net,
Chuck Leverc5d120f2008-12-23 15:21:35 -05001702 };
Chuck Lever4c568012007-12-10 14:59:28 -05001703 int status;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001704
1705 if (args->mount_server.version == 0) {
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001706 switch (args->version) {
1707 default:
1708 args->mount_server.version = NFS_MNT3_VERSION;
1709 break;
1710 case 2:
1711 args->mount_server.version = NFS_MNT_VERSION;
1712 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001713 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001714 request.version = args->mount_server.version;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001715
Chuck Lever33832032007-12-10 14:59:13 -05001716 if (args->mount_server.hostname)
Chuck Leverc5d120f2008-12-23 15:21:35 -05001717 request.hostname = args->mount_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001718 else
Chuck Leverc5d120f2008-12-23 15:21:35 -05001719 request.hostname = args->nfs_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001720
Chuck Lever0076d7b2007-07-01 12:13:49 -04001721 /*
1722 * Construct the mount server's address.
1723 */
Chuck Lever4c568012007-12-10 14:59:28 -05001724 if (args->mount_server.address.ss_family == AF_UNSPEC) {
Chuck Leverc5d120f2008-12-23 15:21:35 -05001725 memcpy(request.sap, &args->nfs_server.address,
Chuck Lever4c568012007-12-10 14:59:28 -05001726 args->nfs_server.addrlen);
1727 args->mount_server.addrlen = args->nfs_server.addrlen;
1728 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001729 request.salen = args->mount_server.addrlen;
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001730 nfs_set_port(request.sap, &args->mount_server.port, 0);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001731
1732 /*
1733 * Now ask the mount server to map our export path
1734 * to a file handle.
1735 */
Chuck Leverc5d120f2008-12-23 15:21:35 -05001736 status = nfs_mount(&request);
Chuck Leverec88f282009-08-09 15:09:32 -04001737 if (status != 0) {
1738 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1739 request.hostname, status);
1740 return status;
1741 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001742
Chuck Leverec88f282009-08-09 15:09:32 -04001743 /*
1744 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1745 */
1746 if (args->mount_server.version != NFS_MNT3_VERSION)
1747 return 0;
1748 return nfs_walk_authlist(args, &request);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001749}
1750
Bryan Schumaker486aa692012-05-10 15:07:39 -04001751static struct dentry *nfs_try_mount(int flags, const char *dev_name,
1752 struct nfs_fh *mntfh,
1753 struct nfs_mount_info *mount_info)
1754{
1755 int status;
1756 struct nfs_server *server;
1757
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04001758 if (mount_info->parsed->need_mount) {
1759 status = nfs_request_mount(mount_info->parsed, mntfh);
1760 if (status)
1761 return ERR_PTR(status);
1762 }
Bryan Schumaker486aa692012-05-10 15:07:39 -04001763
1764 /* Get a volume representation */
1765 server = nfs_create_server(mount_info->parsed, mntfh);
1766 if (IS_ERR(server))
1767 return ERR_CAST(server);
1768
1769 return nfs_fs_mount_common(&nfs_fs_type, server, flags, dev_name, mntfh, mount_info);
1770}
1771
Rob Landleyc12bace2011-03-09 15:54:13 -06001772/*
1773 * Split "dev_name" into "hostname:export_path".
1774 *
1775 * The leftmost colon demarks the split between the server's hostname
1776 * and the export path. If the hostname starts with a left square
1777 * bracket, then it may contain colons.
1778 *
1779 * Note: caller frees hostname and export path, even on error.
1780 */
1781static int nfs_parse_devname(const char *dev_name,
1782 char **hostname, size_t maxnamlen,
1783 char **export_path, size_t maxpathlen)
Chuck Leverdc045892008-06-23 12:36:37 -04001784{
1785 size_t len;
Rob Landleyc12bace2011-03-09 15:54:13 -06001786 char *end;
Chuck Leverdc045892008-06-23 12:36:37 -04001787
Rob Landleyc12bace2011-03-09 15:54:13 -06001788 /* Is the host name protected with square brakcets? */
1789 if (*dev_name == '[') {
1790 end = strchr(++dev_name, ']');
1791 if (end == NULL || end[1] != ':')
1792 goto out_bad_devname;
Chuck Leverdc045892008-06-23 12:36:37 -04001793
Rob Landleyc12bace2011-03-09 15:54:13 -06001794 len = end - dev_name;
1795 end++;
1796 } else {
1797 char *comma;
1798
1799 end = strchr(dev_name, ':');
1800 if (end == NULL)
1801 goto out_bad_devname;
1802 len = end - dev_name;
1803
1804 /* kill possible hostname list: not supported */
1805 comma = strchr(dev_name, ',');
1806 if (comma != NULL && comma < end)
1807 *comma = 0;
1808 }
1809
Chuck Leverdc045892008-06-23 12:36:37 -04001810 if (len > maxnamlen)
1811 goto out_hostname;
1812
1813 /* N.B. caller will free nfs_server.hostname in all cases */
1814 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
Rob Landleyc12bace2011-03-09 15:54:13 -06001815 if (*hostname == NULL)
Chuck Leverdc045892008-06-23 12:36:37 -04001816 goto out_nomem;
Rob Landleyc12bace2011-03-09 15:54:13 -06001817 len = strlen(++end);
Chuck Leverdc045892008-06-23 12:36:37 -04001818 if (len > maxpathlen)
1819 goto out_path;
Rob Landleyc12bace2011-03-09 15:54:13 -06001820 *export_path = kstrndup(end, len, GFP_KERNEL);
Chuck Leverdc045892008-06-23 12:36:37 -04001821 if (!*export_path)
1822 goto out_nomem;
1823
1824 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1825 return 0;
1826
1827out_bad_devname:
1828 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1829 return -EINVAL;
1830
1831out_nomem:
1832 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1833 return -ENOMEM;
1834
1835out_hostname:
1836 dfprintk(MOUNT, "NFS: server hostname too long\n");
1837 return -ENAMETOOLONG;
1838
1839out_path:
1840 dfprintk(MOUNT, "NFS: export pathname too long\n");
1841 return -ENAMETOOLONG;
1842}
1843
1844/*
David Howells54ceac42006-08-22 20:06:13 -04001845 * Validate the NFS2/NFS3 mount data
1846 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001847 *
1848 * For option strings, user space handles the following behaviors:
1849 *
1850 * + DNS: mapping server host name to IP address ("addr=" option)
1851 *
1852 * + failure mode: how to behave if a mount request can't be handled
1853 * immediately ("fg/bg" option)
1854 *
1855 * + retry: how often to retry a mount request ("retry=" option)
1856 *
1857 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1858 * mountproto=tcp after mountproto=udp, and so on
David Howellsf7b422b2006-06-09 09:34:33 -04001859 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001860static int nfs_validate_mount_data(void *options,
1861 struct nfs_parsed_mount_data *args,
Chuck Lever136d5582007-07-01 12:13:54 -04001862 struct nfs_fh *mntfh,
1863 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001864{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001865 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001866 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
Chuck Lever136d5582007-07-01 12:13:54 -04001867
Chuck Lever5df36e72007-07-01 12:12:56 -04001868 if (data == NULL)
1869 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001870
David Howellsf7b422b2006-06-09 09:34:33 -04001871 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001872 case 1:
1873 data->namlen = 0;
1874 case 2:
1875 data->bsize = 0;
1876 case 3:
1877 if (data->flags & NFS_MOUNT_VER3)
1878 goto out_no_v3;
1879 data->root.size = NFS2_FHSIZE;
1880 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1881 case 4:
1882 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1883 goto out_no_sec;
1884 case 5:
1885 memset(data->context, 0, sizeof(data->context));
1886 case 6:
Trond Myklebustb7e24452008-06-19 15:21:11 -04001887 if (data->flags & NFS_MOUNT_VER3) {
1888 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1889 goto out_invalid_fh;
Chuck Lever5df36e72007-07-01 12:12:56 -04001890 mntfh->size = data->root.size;
Chuck Lever764302c2009-09-08 19:50:03 -04001891 args->version = 3;
1892 } else {
Chuck Lever5df36e72007-07-01 12:12:56 -04001893 mntfh->size = NFS2_FHSIZE;
Chuck Lever764302c2009-09-08 19:50:03 -04001894 args->version = 2;
1895 }
Chuck Lever5df36e72007-07-01 12:12:56 -04001896
Chuck Lever5df36e72007-07-01 12:12:56 -04001897
1898 memcpy(mntfh->data, data->root.data, mntfh->size);
1899 if (mntfh->size < sizeof(mntfh->data))
1900 memset(mntfh->data + mntfh->size, 0,
1901 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001902
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001903 /*
1904 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1905 * can deal with.
1906 */
Trond Myklebustff3525a2008-08-15 16:59:14 -04001907 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
Bryan Schumakerd5eff1a2010-08-03 13:04:00 -04001908 args->flags |= NFS_MOUNT_LEGACY_INTERFACE;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001909 args->rsize = data->rsize;
1910 args->wsize = data->wsize;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001911 args->timeo = data->timeo;
1912 args->retrans = data->retrans;
1913 args->acregmin = data->acregmin;
1914 args->acregmax = data->acregmax;
1915 args->acdirmin = data->acdirmin;
1916 args->acdirmax = data->acdirmax;
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04001917 args->need_mount = false;
Chuck Lever4c568012007-12-10 14:59:28 -05001918
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001919 memcpy(sap, &data->addr, sizeof(data->addr));
Chuck Lever4c568012007-12-10 14:59:28 -05001920 args->nfs_server.addrlen = sizeof(data->addr);
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001921 if (!nfs_verify_server_address(sap))
Chuck Lever4c568012007-12-10 14:59:28 -05001922 goto out_no_address;
1923
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001924 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001925 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001926 /* N.B. caller will free nfs_server.hostname in all cases */
1927 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1928 args->namlen = data->namlen;
1929 args->bsize = data->bsize;
Chuck Leverdd07c942008-06-24 16:33:46 -04001930
1931 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1932 args->auth_flavors[0] = data->pseudoflavor;
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001933 if (!args->nfs_server.hostname)
1934 goto out_nomem;
Eric Parisf9c3a382008-03-05 14:20:18 -05001935
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001936 if (!(data->flags & NFS_MOUNT_NONLM))
1937 args->flags &= ~(NFS_MOUNT_LOCAL_FLOCK|
1938 NFS_MOUNT_LOCAL_FCNTL);
1939 else
1940 args->flags |= (NFS_MOUNT_LOCAL_FLOCK|
1941 NFS_MOUNT_LOCAL_FCNTL);
Eric Parisf9c3a382008-03-05 14:20:18 -05001942 /*
1943 * The legacy version 6 binary mount data from userspace has a
1944 * field used only to transport selinux information into the
1945 * the kernel. To continue to support that functionality we
1946 * have a touch of selinux knowledge here in the NFS code. The
1947 * userspace code converted context=blah to just blah so we are
1948 * converting back to the full string selinux understands.
1949 */
1950 if (data->context[0]){
1951#ifdef CONFIG_SECURITY_SELINUX
1952 int rc;
1953 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1954 if (!opts_str)
1955 return -ENOMEM;
1956 strcpy(opts_str, "context=");
1957 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1958 strcat(opts_str, &data->context[0]);
1959 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1960 kfree(opts_str);
1961 if (rc)
1962 return rc;
1963#else
1964 return -EINVAL;
1965#endif
1966 }
1967
Chuck Lever5df36e72007-07-01 12:12:56 -04001968 break;
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04001969 default:
1970 return NFS_TEXT_DATA;
David Howellsf7b422b2006-06-09 09:34:33 -04001971 }
David Howells54ceac42006-08-22 20:06:13 -04001972
David Howellsf7b422b2006-06-09 09:34:33 -04001973#ifndef CONFIG_NFS_V3
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001974 if (args->version == 3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001975 goto out_v3_not_compiled;
1976#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001977
David Howells54ceac42006-08-22 20:06:13 -04001978 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001979
1980out_no_data:
1981 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1982 return -EINVAL;
1983
1984out_no_v3:
1985 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1986 data->version);
1987 return -EINVAL;
1988
1989out_no_sec:
1990 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1991 return -EINVAL;
1992
Chuck Lever5df36e72007-07-01 12:12:56 -04001993#ifndef CONFIG_NFS_V3
1994out_v3_not_compiled:
1995 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1996 return -EPROTONOSUPPORT;
1997#endif /* !CONFIG_NFS_V3 */
1998
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001999out_nomem:
2000 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
2001 return -ENOMEM;
2002
Chuck Lever5df36e72007-07-01 12:12:56 -04002003out_no_address:
2004 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
2005 return -EINVAL;
2006
2007out_invalid_fh:
2008 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
2009 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04002010}
2011
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04002012static int nfs_validate_text_mount_data(void *options,
2013 struct nfs_parsed_mount_data *args,
2014 const char *dev_name)
2015{
2016 int port = 0;
2017 int max_namelen = PAGE_SIZE;
2018 int max_pathlen = NFS_MAXPATHLEN;
2019 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2020
2021 if (nfs_parse_mount_options((char *)options, args) == 0)
2022 return -EINVAL;
2023
2024 if (!nfs_verify_server_address(sap))
2025 goto out_no_address;
2026
2027 if (args->version == 4) {
2028#ifdef CONFIG_NFS_V4
2029 port = NFS_PORT;
2030 max_namelen = NFS4_MAXNAMLEN;
2031 max_pathlen = NFS4_MAXPATHLEN;
2032 nfs_validate_transport_protocol(args);
2033 nfs4_validate_mount_flags(args);
2034#else
2035 goto out_v4_not_compiled;
2036#endif /* CONFIG_NFS_V4 */
2037 } else
2038 nfs_set_mount_transport_protocol(args);
2039
2040 nfs_set_port(sap, &args->nfs_server.port, port);
2041
2042 if (args->auth_flavor_len > 1)
2043 goto out_bad_auth;
2044
2045 return nfs_parse_devname(dev_name,
2046 &args->nfs_server.hostname,
2047 max_namelen,
2048 &args->nfs_server.export_path,
2049 max_pathlen);
2050
2051#ifndef CONFIG_NFS_V4
2052out_v4_not_compiled:
2053 dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n");
2054 return -EPROTONOSUPPORT;
2055#endif /* !CONFIG_NFS_V4 */
2056
2057out_no_address:
2058 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
2059 return -EINVAL;
2060
2061out_bad_auth:
2062 dfprintk(MOUNT, "NFS: Too many RPC auth flavours specified\n");
2063 return -EINVAL;
2064}
2065
Jeff Layton48b605f2008-06-10 15:38:39 -04002066static int
2067nfs_compare_remount_data(struct nfs_server *nfss,
2068 struct nfs_parsed_mount_data *data)
2069{
2070 if (data->flags != nfss->flags ||
2071 data->rsize != nfss->rsize ||
2072 data->wsize != nfss->wsize ||
2073 data->retrans != nfss->client->cl_timeout->to_retries ||
2074 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
2075 data->acregmin != nfss->acregmin / HZ ||
2076 data->acregmax != nfss->acregmax / HZ ||
2077 data->acdirmin != nfss->acdirmin / HZ ||
2078 data->acdirmax != nfss->acdirmax / HZ ||
2079 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
Trond Myklebustbcd2ea12009-10-06 15:41:22 -04002080 data->nfs_server.port != nfss->port ||
Jeff Layton48b605f2008-06-10 15:38:39 -04002081 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
Stefan Richtera1be9ee2009-10-12 11:26:12 -04002082 !rpc_cmp_addr((struct sockaddr *)&data->nfs_server.address,
2083 (struct sockaddr *)&nfss->nfs_client->cl_addr))
Jeff Layton48b605f2008-06-10 15:38:39 -04002084 return -EINVAL;
2085
2086 return 0;
2087}
2088
2089static int
2090nfs_remount(struct super_block *sb, int *flags, char *raw_data)
2091{
2092 int error;
2093 struct nfs_server *nfss = sb->s_fs_info;
2094 struct nfs_parsed_mount_data *data;
2095 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
2096 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
Trond Myklebustcd100722008-06-17 16:12:00 -04002097 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
Jeff Layton48b605f2008-06-10 15:38:39 -04002098
2099 /*
2100 * Userspace mount programs that send binary options generally send
2101 * them populated with default values. We have no way to know which
2102 * ones were explicitly specified. Fall back to legacy behavior and
2103 * just return success.
2104 */
Marc Zyngier31c94462008-07-17 13:21:55 +02002105 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
2106 (nfsvers <= 3 && (!options || (options->version >= 1 &&
2107 options->version <= 6))))
Jeff Layton48b605f2008-06-10 15:38:39 -04002108 return 0;
2109
2110 data = kzalloc(sizeof(*data), GFP_KERNEL);
2111 if (data == NULL)
2112 return -ENOMEM;
2113
2114 /* fill out struct with values from existing mount */
2115 data->flags = nfss->flags;
2116 data->rsize = nfss->rsize;
2117 data->wsize = nfss->wsize;
2118 data->retrans = nfss->client->cl_timeout->to_retries;
2119 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
2120 data->acregmin = nfss->acregmin / HZ;
2121 data->acregmax = nfss->acregmax / HZ;
2122 data->acdirmin = nfss->acdirmin / HZ;
2123 data->acdirmax = nfss->acdirmax / HZ;
2124 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
Trond Myklebustbcd2ea12009-10-06 15:41:22 -04002125 data->nfs_server.port = nfss->port;
Jeff Layton48b605f2008-06-10 15:38:39 -04002126 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
2127 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
2128 data->nfs_server.addrlen);
2129
2130 /* overwrite those values with any that were specified */
2131 error = nfs_parse_mount_options((char *)options, data);
2132 if (error < 0)
2133 goto out;
2134
Jeff Layton26c4c172011-04-27 11:49:09 -04002135 /*
2136 * noac is a special case. It implies -o sync, but that's not
2137 * necessarily reflected in the mtab options. do_remount_sb
2138 * will clear MS_SYNCHRONOUS if -o sync wasn't specified in the
2139 * remount options, so we have to explicitly reset it.
2140 */
2141 if (data->flags & NFS_MOUNT_NOAC)
2142 *flags |= MS_SYNCHRONOUS;
2143
Jeff Layton48b605f2008-06-10 15:38:39 -04002144 /* compare new mount options with old ones */
2145 error = nfs_compare_remount_data(nfss, data);
2146out:
2147 kfree(data);
2148 return error;
2149}
2150
David Howells54ceac42006-08-22 20:06:13 -04002151/*
2152 * Initialise the common bits of the superblock
2153 */
2154static inline void nfs_initialise_sb(struct super_block *sb)
2155{
2156 struct nfs_server *server = NFS_SB(sb);
2157
2158 sb->s_magic = NFS_SUPER_MAGIC;
2159
2160 /* We probably want something more informative here */
2161 snprintf(sb->s_id, sizeof(sb->s_id),
Vivek Trivedi5a7c9ee2012-03-15 23:58:52 +05302162 "%u:%u", MAJOR(sb->s_dev), MINOR(sb->s_dev));
David Howells54ceac42006-08-22 20:06:13 -04002163
2164 if (sb->s_blocksize == 0)
2165 sb->s_blocksize = nfs_block_bits(server->wsize,
2166 &sb->s_blocksize_bits);
2167
Jens Axboe32a88aa2009-09-16 15:02:33 +02002168 sb->s_bdi = &server->backing_dev_info;
2169
David Howells54ceac42006-08-22 20:06:13 -04002170 nfs_super_set_maxbytes(sb, server->maxfilesize);
2171}
2172
2173/*
2174 * Finish setting up an NFS2/3 superblock
2175 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04002176static void nfs_fill_super(struct super_block *sb,
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002177 struct nfs_mount_info *mount_info)
David Howells54ceac42006-08-22 20:06:13 -04002178{
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002179 struct nfs_parsed_mount_data *data = mount_info->parsed;
David Howells54ceac42006-08-22 20:06:13 -04002180 struct nfs_server *server = NFS_SB(sb);
2181
2182 sb->s_blocksize_bits = 0;
2183 sb->s_blocksize = 0;
2184 if (data->bsize)
2185 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
2186
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04002187 if (server->nfs_client->rpc_ops->version == 3) {
David Howells54ceac42006-08-22 20:06:13 -04002188 /* The VFS shouldn't apply the umask to mode bits. We will do
2189 * so ourselves when necessary.
2190 */
2191 sb->s_flags |= MS_POSIXACL;
2192 sb->s_time_gran = 1;
2193 }
2194
2195 sb->s_op = &nfs_sops;
2196 nfs_initialise_sb(sb);
2197}
2198
2199/*
2200 * Finish setting up a cloned NFS2/3 superblock
2201 */
2202static void nfs_clone_super(struct super_block *sb,
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002203 struct nfs_mount_info *mount_info)
David Howells54ceac42006-08-22 20:06:13 -04002204{
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002205 const struct super_block *old_sb = mount_info->cloned->sb;
David Howells54ceac42006-08-22 20:06:13 -04002206 struct nfs_server *server = NFS_SB(sb);
2207
2208 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2209 sb->s_blocksize = old_sb->s_blocksize;
2210 sb->s_maxbytes = old_sb->s_maxbytes;
2211
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04002212 if (server->nfs_client->rpc_ops->version == 3) {
David Howells54ceac42006-08-22 20:06:13 -04002213 /* The VFS shouldn't apply the umask to mode bits. We will do
2214 * so ourselves when necessary.
2215 */
2216 sb->s_flags |= MS_POSIXACL;
2217 sb->s_time_gran = 1;
2218 }
2219
2220 sb->s_op = old_sb->s_op;
2221 nfs_initialise_sb(sb);
2222}
2223
Trond Myklebust275a5d22007-05-16 16:53:28 -04002224static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
2225{
2226 const struct nfs_server *a = s->s_fs_info;
2227 const struct rpc_clnt *clnt_a = a->client;
2228 const struct rpc_clnt *clnt_b = b->client;
2229
2230 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
2231 goto Ebusy;
2232 if (a->nfs_client != b->nfs_client)
2233 goto Ebusy;
2234 if (a->flags != b->flags)
2235 goto Ebusy;
2236 if (a->wsize != b->wsize)
2237 goto Ebusy;
2238 if (a->rsize != b->rsize)
2239 goto Ebusy;
2240 if (a->acregmin != b->acregmin)
2241 goto Ebusy;
2242 if (a->acregmax != b->acregmax)
2243 goto Ebusy;
2244 if (a->acdirmin != b->acdirmin)
2245 goto Ebusy;
2246 if (a->acdirmax != b->acdirmax)
2247 goto Ebusy;
2248 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
2249 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002250 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04002251Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002252 return 0;
2253}
2254
2255struct nfs_sb_mountdata {
2256 struct nfs_server *server;
2257 int mntflags;
2258};
2259
2260static int nfs_set_super(struct super_block *s, void *data)
2261{
2262 struct nfs_sb_mountdata *sb_mntdata = data;
2263 struct nfs_server *server = sb_mntdata->server;
2264 int ret;
2265
2266 s->s_flags = sb_mntdata->mntflags;
2267 s->s_fs_info = server;
Al Viro8b244ff2010-12-18 11:29:39 -05002268 s->s_d_op = server->nfs_client->rpc_ops->dentry_ops;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002269 ret = set_anon_super(s, server);
2270 if (ret == 0)
2271 server->s_dev = s->s_dev;
2272 return ret;
2273}
2274
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002275static int nfs_compare_super_address(struct nfs_server *server1,
2276 struct nfs_server *server2)
2277{
2278 struct sockaddr *sap1, *sap2;
2279
2280 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
2281 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
2282
2283 if (sap1->sa_family != sap2->sa_family)
2284 return 0;
2285
2286 switch (sap1->sa_family) {
2287 case AF_INET: {
2288 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
2289 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
2290 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
2291 return 0;
2292 if (sin1->sin_port != sin2->sin_port)
2293 return 0;
2294 break;
2295 }
2296 case AF_INET6: {
2297 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
2298 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
2299 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
2300 return 0;
2301 if (sin1->sin6_port != sin2->sin6_port)
2302 return 0;
2303 break;
2304 }
2305 default:
2306 return 0;
2307 }
2308
2309 return 1;
2310}
2311
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002312static int nfs_compare_super(struct super_block *sb, void *data)
2313{
2314 struct nfs_sb_mountdata *sb_mntdata = data;
2315 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2316 int mntflags = sb_mntdata->mntflags;
2317
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002318 if (!nfs_compare_super_address(old, server))
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002319 return 0;
2320 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2321 if (old->flags & NFS_MOUNT_UNSHARED)
2322 return 0;
2323 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2324 return 0;
2325 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04002326}
2327
Bryan Schumaker2311b942012-05-10 15:07:32 -04002328static void nfs_get_cache_cookie(struct super_block *sb,
2329 struct nfs_parsed_mount_data *parsed,
2330 struct nfs_clone_mount *cloned)
2331{
2332 char *uniq = NULL;
2333 int ulen = 0;
2334
2335 if (parsed && parsed->fscache_uniq) {
2336 uniq = parsed->fscache_uniq;
2337 ulen = strlen(parsed->fscache_uniq);
2338 } else if (cloned) {
2339 struct nfs_server *mnt_s = NFS_SB(cloned->sb);
2340 if (mnt_s->fscache_key) {
2341 uniq = mnt_s->fscache_key->key.uniquifier;
2342 ulen = mnt_s->fscache_key->key.uniq_len;
2343 };
2344 }
2345
2346 nfs_fscache_get_super_cookie(sb, uniq, ulen);
2347}
2348
Miklos Szeredifa799752008-04-30 00:54:33 -07002349static int nfs_bdi_register(struct nfs_server *server)
2350{
2351 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
2352}
2353
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002354static int nfs_set_sb_security(struct super_block *s, struct dentry *mntroot,
2355 struct nfs_mount_info *mount_info)
2356{
2357 return security_sb_set_mnt_opts(s, &mount_info->parsed->lsm_opts);
2358}
2359
2360static int nfs_clone_sb_security(struct super_block *s, struct dentry *mntroot,
2361 struct nfs_mount_info *mount_info)
2362{
2363 /* clone any lsm security options from the parent to the new sb */
2364 security_sb_clone_mnt_opts(mount_info->cloned->sb, s);
2365 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops)
2366 return -ESTALE;
2367 return 0;
2368}
2369
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002370static struct dentry *nfs_fs_mount_common(struct file_system_type *fs_type,
2371 struct nfs_server *server,
2372 int flags, const char *dev_name,
2373 struct nfs_fh *mntfh,
2374 struct nfs_mount_info *mount_info)
David Howells54ceac42006-08-22 20:06:13 -04002375{
David Howells54ceac42006-08-22 20:06:13 -04002376 struct super_block *s;
Al Viro01194982011-03-16 07:25:36 -04002377 struct dentry *mntroot = ERR_PTR(-ENOMEM);
Trond Myklebust75180df2007-05-16 16:53:28 -04002378 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002379 struct nfs_sb_mountdata sb_mntdata = {
2380 .mntflags = flags,
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002381 .server = server,
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002382 };
Al Viro01194982011-03-16 07:25:36 -04002383 int error;
David Howells54ceac42006-08-22 20:06:13 -04002384
Trond Myklebust75180df2007-05-16 16:53:28 -04002385 if (server->flags & NFS_MOUNT_UNSHARED)
2386 compare_super = NULL;
2387
Sachin Prabhufb2088c2011-08-01 12:10:12 +01002388 /* -o noac implies -o sync */
2389 if (server->flags & NFS_MOUNT_NOAC)
2390 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2391
David Howells54ceac42006-08-22 20:06:13 -04002392 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002393 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002394 if (IS_ERR(s)) {
Al Viro01194982011-03-16 07:25:36 -04002395 mntroot = ERR_CAST(s);
David Howells54ceac42006-08-22 20:06:13 -04002396 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04002397 }
2398
David Howells54ceac42006-08-22 20:06:13 -04002399 if (s->s_fs_info != server) {
2400 nfs_free_server(server);
2401 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002402 } else {
2403 error = nfs_bdi_register(server);
Al Viro01194982011-03-16 07:25:36 -04002404 if (error) {
2405 mntroot = ERR_PTR(error);
NeilBrowncfbc0682010-03-11 11:20:17 +11002406 goto error_splat_bdi;
Al Viro01194982011-03-16 07:25:36 -04002407 }
David Howellsf7b422b2006-06-09 09:34:33 -04002408 }
David Howells54ceac42006-08-22 20:06:13 -04002409
2410 if (!s->s_root) {
2411 /* initial superblock/root creation */
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002412 mount_info->fill_super(s, mount_info);
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002413 nfs_get_cache_cookie(s, mount_info->parsed, mount_info->cloned);
David Howells54ceac42006-08-22 20:06:13 -04002414 }
2415
Al Viro0d5839a2011-03-16 05:27:27 -04002416 mntroot = nfs_get_root(s, mntfh, dev_name);
Al Viro01194982011-03-16 07:25:36 -04002417 if (IS_ERR(mntroot))
David Howells54ceac42006-08-22 20:06:13 -04002418 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002419
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002420 error = mount_info->set_security(s, mntroot, mount_info);
Eric Parisf9c3a382008-03-05 14:20:18 -05002421 if (error)
2422 goto error_splat_root;
2423
David Howellsf7b422b2006-06-09 09:34:33 -04002424 s->s_flags |= MS_ACTIVE;
Chuck Lever06559602007-07-01 12:12:35 -04002425
2426out:
Al Viro01194982011-03-16 07:25:36 -04002427 return mntroot;
Trond Myklebust816724e2006-06-24 08:41:41 -04002428
David Howells54ceac42006-08-22 20:06:13 -04002429out_err_nosb:
2430 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04002431 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002432
Eric Parisf9c3a382008-03-05 14:20:18 -05002433error_splat_root:
2434 dput(mntroot);
Al Viro01194982011-03-16 07:25:36 -04002435 mntroot = ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04002436error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002437 if (server && !s->s_root)
2438 bdi_unregister(&server->backing_dev_info);
2439error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002440 deactivate_locked_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04002441 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002442}
2443
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002444static struct dentry *nfs_fs_mount(struct file_system_type *fs_type,
2445 int flags, const char *dev_name, void *raw_data)
2446{
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002447 struct nfs_parsed_mount_data *data = NULL;
2448 struct nfs_mount_info mount_info = {
2449 .fill_super = nfs_fill_super,
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002450 .set_security = nfs_set_sb_security,
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002451 };
2452 struct nfs_fh *mntfh;
2453 struct dentry *mntroot = ERR_PTR(-ENOMEM);
2454 int error;
2455
Bryan Schumakerdb833352012-05-10 15:07:38 -04002456 data = nfs_alloc_parsed_mount_data();
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002457 mntfh = nfs_alloc_fhandle();
2458 if (data == NULL || mntfh == NULL)
2459 goto out;
2460
2461 /* Validate the mount data */
2462 error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04002463 if (error == NFS_TEXT_DATA)
2464 error = nfs_validate_text_mount_data(raw_data, data, dev_name);
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002465 if (error < 0) {
2466 mntroot = ERR_PTR(error);
2467 goto out;
2468 }
2469 mount_info.parsed = data;
2470
2471#ifdef CONFIG_NFS_V4
Bryan Schumaker486aa692012-05-10 15:07:39 -04002472 if (data->version == 4)
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002473 mntroot = nfs4_try_mount(flags, dev_name, data);
Bryan Schumaker486aa692012-05-10 15:07:39 -04002474 else
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002475#endif /* CONFIG_NFS_V4 */
Bryan Schumaker486aa692012-05-10 15:07:39 -04002476 mntroot = nfs_try_mount(flags, dev_name, mntfh, &mount_info);
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002477
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002478out:
2479 nfs_free_parsed_mount_data(data);
2480 nfs_free_fhandle(mntfh);
2481 return mntroot;
2482}
2483
David Howells54ceac42006-08-22 20:06:13 -04002484/*
Trond Myklebust387c1492010-02-03 08:27:35 -05002485 * Ensure that we unregister the bdi before kill_anon_super
2486 * releases the device name
2487 */
2488static void nfs_put_super(struct super_block *s)
2489{
2490 struct nfs_server *server = NFS_SB(s);
2491
2492 bdi_unregister(&server->backing_dev_info);
2493}
2494
2495/*
David Howells54ceac42006-08-22 20:06:13 -04002496 * Destroy an NFS2/3 superblock
2497 */
David Howellsf7b422b2006-06-09 09:34:33 -04002498static void nfs_kill_super(struct super_block *s)
2499{
2500 struct nfs_server *server = NFS_SB(s);
2501
2502 kill_anon_super(s);
David Howells08734042009-04-03 16:42:42 +01002503 nfs_fscache_release_super_cookie(s);
David Howells54ceac42006-08-22 20:06:13 -04002504 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04002505}
2506
David Howells54ceac42006-08-22 20:06:13 -04002507/*
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002508 * Clone an NFS2/3/4 server record on xdev traversal (FSID-change)
David Howells54ceac42006-08-22 20:06:13 -04002509 */
Al Viro31f43472010-10-29 03:38:12 -04002510static struct dentry *
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002511nfs_xdev_mount_common(struct file_system_type *fs_type, int flags,
2512 const char *dev_name, struct nfs_mount_info *mount_info)
David Howellsf7b422b2006-06-09 09:34:33 -04002513{
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002514 struct nfs_clone_mount *data = mount_info->cloned;
David Howells54ceac42006-08-22 20:06:13 -04002515 struct nfs_server *server;
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002516 struct dentry *mntroot = ERR_PTR(-ENOMEM);
David Howells54ceac42006-08-22 20:06:13 -04002517 int error;
2518
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002519 dprintk("--> nfs_xdev_mount_common()\n");
David Howells54ceac42006-08-22 20:06:13 -04002520
2521 /* create a new volume representation */
Bryan Schumaker7e6eb682012-04-27 13:27:42 -04002522 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr, data->authflavor);
David Howells54ceac42006-08-22 20:06:13 -04002523 if (IS_ERR(server)) {
2524 error = PTR_ERR(server);
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002525 goto out_err;
David Howells54ceac42006-08-22 20:06:13 -04002526 }
2527
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002528 mntroot = nfs_fs_mount_common(fs_type, server, flags, dev_name, data->fh, mount_info);
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002529 dprintk("<-- nfs_xdev_mount_common() = 0\n");
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002530out:
Al Viro31f43472010-10-29 03:38:12 -04002531 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04002532
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002533out_err:
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002534 dprintk("<-- nfs_xdev_mount_common() = %d [error]\n", error);
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002535 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002536}
2537
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002538/*
2539 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2540 */
2541static struct dentry *
2542nfs_xdev_mount(struct file_system_type *fs_type, int flags,
2543 const char *dev_name, void *raw_data)
2544{
2545 struct nfs_mount_info mount_info = {
2546 .fill_super = nfs_clone_super,
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002547 .set_security = nfs_clone_sb_security,
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002548 .cloned = raw_data,
2549 };
2550 return nfs_xdev_mount_common(&nfs_fs_type, flags, dev_name, &mount_info);
2551}
2552
David Howellsf7b422b2006-06-09 09:34:33 -04002553#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04002554
2555/*
2556 * Finish setting up a cloned NFS4 superblock
2557 */
2558static void nfs4_clone_super(struct super_block *sb,
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002559 struct nfs_mount_info *mount_info)
David Howellsf7b422b2006-06-09 09:34:33 -04002560{
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002561 const struct super_block *old_sb = mount_info->cloned->sb;
David Howells54ceac42006-08-22 20:06:13 -04002562 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2563 sb->s_blocksize = old_sb->s_blocksize;
2564 sb->s_maxbytes = old_sb->s_maxbytes;
2565 sb->s_time_gran = 1;
2566 sb->s_op = old_sb->s_op;
Aneesh Kumar K.Va8a5da92010-12-09 11:35:14 +00002567 /*
2568 * The VFS shouldn't apply the umask to mode bits. We will do
2569 * so ourselves when necessary.
2570 */
2571 sb->s_flags |= MS_POSIXACL;
Aneesh Kumar K.V64c2ce82010-12-09 11:35:25 +00002572 sb->s_xattr = old_sb->s_xattr;
2573 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002574}
2575
2576/*
2577 * Set up an NFS4 superblock
2578 */
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002579static void nfs4_fill_super(struct super_block *sb,
2580 struct nfs_mount_info *mount_info)
David Howellsf7b422b2006-06-09 09:34:33 -04002581{
David Howellsf7b422b2006-06-09 09:34:33 -04002582 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04002583 sb->s_op = &nfs4_sops;
Aneesh Kumar K.Va8a5da92010-12-09 11:35:14 +00002584 /*
2585 * The VFS shouldn't apply the umask to mode bits. We will do
2586 * so ourselves when necessary.
2587 */
2588 sb->s_flags |= MS_POSIXACL;
Aneesh Kumar K.V64c2ce82010-12-09 11:35:25 +00002589 sb->s_xattr = nfs4_xattr_handlers;
David Howells54ceac42006-08-22 20:06:13 -04002590 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002591}
2592
Trond Myklebust01c3f052009-06-17 13:22:58 -07002593static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2594{
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04002595 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3|
2596 NFS_MOUNT_LOCAL_FLOCK|NFS_MOUNT_LOCAL_FCNTL);
Trond Myklebust01c3f052009-06-17 13:22:58 -07002597}
2598
David Howells54ceac42006-08-22 20:06:13 -04002599/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04002600 * Validate NFSv4 mount options
2601 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002602static int nfs4_validate_mount_data(void *options,
2603 struct nfs_parsed_mount_data *args,
2604 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04002605{
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002606 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002607 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002608 char *c;
2609
2610 if (data == NULL)
2611 goto out_no_data;
2612
2613 switch (data->version) {
2614 case 1:
Chuck Lever4c568012007-12-10 14:59:28 -05002615 if (data->host_addrlen > sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002616 goto out_no_address;
Chuck Lever4c568012007-12-10 14:59:28 -05002617 if (data->host_addrlen == 0)
2618 goto out_no_address;
2619 args->nfs_server.addrlen = data->host_addrlen;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002620 if (copy_from_user(sap, data->host_addr, data->host_addrlen))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002621 return -EFAULT;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002622 if (!nfs_verify_server_address(sap))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002623 goto out_no_address;
2624
Chuck Lever6738b252008-06-24 16:33:54 -04002625 if (data->auth_flavourlen) {
2626 if (data->auth_flavourlen > 1)
2627 goto out_inval_auth;
Trond Myklebust20c71f52007-09-20 20:23:51 -04002628 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002629 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04002630 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002631 return -EFAULT;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002632 }
2633
2634 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2635 if (IS_ERR(c))
2636 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002637 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002638
2639 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2640 if (IS_ERR(c))
2641 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002642 args->nfs_server.export_path = c;
2643 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002644
2645 c = strndup_user(data->client_addr.data, 16);
2646 if (IS_ERR(c))
2647 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002648 args->client_address = c;
2649
2650 /*
2651 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2652 * can deal with.
2653 */
2654
2655 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2656 args->rsize = data->rsize;
2657 args->wsize = data->wsize;
2658 args->timeo = data->timeo;
2659 args->retrans = data->retrans;
2660 args->acregmin = data->acregmin;
2661 args->acregmax = data->acregmax;
2662 args->acdirmin = data->acdirmin;
2663 args->acdirmax = data->acdirmax;
2664 args->nfs_server.protocol = data->proto;
Trond Myklebust259875e2008-07-02 14:43:47 -04002665 nfs_validate_transport_protocol(args);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002666
2667 break;
Chuck Lever7630c852009-09-08 19:49:57 -04002668 default:
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04002669 return NFS_TEXT_DATA;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002670 }
2671
2672 return 0;
2673
2674out_no_data:
2675 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2676 return -EINVAL;
2677
2678out_inval_auth:
2679 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2680 data->auth_flavourlen);
2681 return -EINVAL;
2682
2683out_no_address:
2684 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2685 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002686}
2687
2688/*
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002689 * Get the superblock for the NFS4 root partition
David Howells54ceac42006-08-22 20:06:13 -04002690 */
Al Viro31f43472010-10-29 03:38:12 -04002691static struct dentry *
2692nfs4_remote_mount(struct file_system_type *fs_type, int flags,
2693 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002694{
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002695 struct nfs_mount_info mount_info = {
2696 .fill_super = nfs4_fill_super,
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002697 .set_security = nfs_set_sb_security,
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002698 .parsed = raw_data,
2699 };
David Howells54ceac42006-08-22 20:06:13 -04002700 struct nfs_server *server;
Trond Myklebust33852a12008-06-19 14:20:11 -04002701 struct nfs_fh *mntfh;
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002702 struct dentry *mntroot = ERR_PTR(-ENOMEM);
David Howellsf7b422b2006-06-09 09:34:33 -04002703
Trond Myklebustb157b062010-04-19 19:05:48 -04002704 mntfh = nfs_alloc_fhandle();
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002705 if (mount_info.parsed == NULL || mntfh == NULL)
Jeff Layton8a0d5512011-12-20 06:57:45 -05002706 goto out;
Eric Parisf9c3a382008-03-05 14:20:18 -05002707
David Howells54ceac42006-08-22 20:06:13 -04002708 /* Get a volume representation */
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002709 server = nfs4_create_server(mount_info.parsed, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002710 if (IS_ERR(server)) {
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002711 mntroot = ERR_CAST(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04002712 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002713 }
2714
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002715 mntroot = nfs_fs_mount_common(fs_type, server, flags,
2716 dev_name, mntfh, &mount_info);
David Howells54ceac42006-08-22 20:06:13 -04002717
Chuck Lever29eb9812007-07-01 12:12:30 -04002718out:
Trond Myklebustb157b062010-04-19 19:05:48 -04002719 nfs_free_fhandle(mntfh);
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002720 return mntroot;
David Howellsf7b422b2006-06-09 09:34:33 -04002721}
2722
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002723static struct vfsmount *nfs_do_root_mount(struct file_system_type *fs_type,
2724 int flags, void *data, const char *hostname)
2725{
2726 struct vfsmount *root_mnt;
2727 char *root_devname;
2728 size_t len;
2729
Jan Kara98a21392011-09-03 01:09:43 +02002730 len = strlen(hostname) + 5;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002731 root_devname = kmalloc(len, GFP_KERNEL);
2732 if (root_devname == NULL)
2733 return ERR_PTR(-ENOMEM);
Jan Kara98a21392011-09-03 01:09:43 +02002734 /* Does hostname needs to be enclosed in brackets? */
2735 if (strchr(hostname, ':'))
2736 snprintf(root_devname, len, "[%s]:/", hostname);
2737 else
2738 snprintf(root_devname, len, "%s:/", hostname);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002739 root_mnt = vfs_kern_mount(fs_type, flags, root_devname, data);
2740 kfree(root_devname);
2741 return root_mnt;
2742}
2743
Trond Myklebustce587e02010-04-16 16:22:52 -04002744struct nfs_referral_count {
2745 struct list_head list;
2746 const struct task_struct *task;
2747 unsigned int referral_count;
2748};
2749
2750static LIST_HEAD(nfs_referral_count_list);
2751static DEFINE_SPINLOCK(nfs_referral_count_list_lock);
2752
2753static struct nfs_referral_count *nfs_find_referral_count(void)
2754{
2755 struct nfs_referral_count *p;
2756
2757 list_for_each_entry(p, &nfs_referral_count_list, list) {
2758 if (p->task == current)
2759 return p;
2760 }
2761 return NULL;
2762}
2763
2764#define NFS_MAX_NESTED_REFERRALS 2
2765
2766static int nfs_referral_loop_protect(void)
2767{
2768 struct nfs_referral_count *p, *new;
2769 int ret = -ENOMEM;
2770
2771 new = kmalloc(sizeof(*new), GFP_KERNEL);
2772 if (!new)
2773 goto out;
2774 new->task = current;
2775 new->referral_count = 1;
2776
2777 ret = 0;
2778 spin_lock(&nfs_referral_count_list_lock);
2779 p = nfs_find_referral_count();
2780 if (p != NULL) {
2781 if (p->referral_count >= NFS_MAX_NESTED_REFERRALS)
2782 ret = -ELOOP;
2783 else
2784 p->referral_count++;
2785 } else {
2786 list_add(&new->list, &nfs_referral_count_list);
2787 new = NULL;
2788 }
2789 spin_unlock(&nfs_referral_count_list_lock);
2790 kfree(new);
2791out:
2792 return ret;
2793}
2794
2795static void nfs_referral_loop_unprotect(void)
2796{
2797 struct nfs_referral_count *p;
2798
2799 spin_lock(&nfs_referral_count_list_lock);
2800 p = nfs_find_referral_count();
2801 p->referral_count--;
2802 if (p->referral_count == 0)
2803 list_del(&p->list);
2804 else
2805 p = NULL;
2806 spin_unlock(&nfs_referral_count_list_lock);
2807 kfree(p);
2808}
2809
Al Viro01194982011-03-16 07:25:36 -04002810static struct dentry *nfs_follow_remote_path(struct vfsmount *root_mnt,
2811 const char *export_path)
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002812{
Al Viro01194982011-03-16 07:25:36 -04002813 struct dentry *dentry;
Al Viro5352d3b2011-11-16 21:52:06 -05002814 int err;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002815
Al Viro5352d3b2011-11-16 21:52:06 -05002816 if (IS_ERR(root_mnt))
2817 return ERR_CAST(root_mnt);
2818
2819 err = nfs_referral_loop_protect();
2820 if (err) {
Al Viroea441d12011-11-16 21:43:59 -05002821 mntput(root_mnt);
Al Viro5352d3b2011-11-16 21:52:06 -05002822 return ERR_PTR(err);
Al Viroc1334492011-11-16 16:12:14 -05002823 }
Trond Myklebustce587e02010-04-16 16:22:52 -04002824
Al Viroea441d12011-11-16 21:43:59 -05002825 dentry = mount_subtree(root_mnt, export_path);
2826 nfs_referral_loop_unprotect();
Linus Torvaldsa2770d82009-12-17 12:51:05 -08002827
Al Viro01194982011-03-16 07:25:36 -04002828 return dentry;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002829}
2830
Al Viro01194982011-03-16 07:25:36 -04002831static struct dentry *nfs4_try_mount(int flags, const char *dev_name,
2832 struct nfs_parsed_mount_data *data)
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002833{
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002834 char *export_path;
2835 struct vfsmount *root_mnt;
Al Viro01194982011-03-16 07:25:36 -04002836 struct dentry *res;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002837
Chuck Levera6fe23b2009-09-08 19:50:00 -04002838 dfprintk(MOUNT, "--> nfs4_try_mount()\n");
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002839
2840 export_path = data->nfs_server.export_path;
2841 data->nfs_server.export_path = "/";
2842 root_mnt = nfs_do_root_mount(&nfs4_remote_fs_type, flags, data,
2843 data->nfs_server.hostname);
2844 data->nfs_server.export_path = export_path;
2845
Al Viro5352d3b2011-11-16 21:52:06 -05002846 res = nfs_follow_remote_path(root_mnt, export_path);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002847
Al Viro01194982011-03-16 07:25:36 -04002848 dfprintk(MOUNT, "<-- nfs4_try_mount() = %ld%s\n",
2849 IS_ERR(res) ? PTR_ERR(res) : 0,
2850 IS_ERR(res) ? " [error]" : "");
2851 return res;
Chuck Levera6fe23b2009-09-08 19:50:00 -04002852}
2853
2854/*
2855 * Get the superblock for an NFS4 mountpoint
2856 */
Al Viro01194982011-03-16 07:25:36 -04002857static struct dentry *nfs4_mount(struct file_system_type *fs_type,
2858 int flags, const char *dev_name, void *raw_data)
Chuck Levera6fe23b2009-09-08 19:50:00 -04002859{
2860 struct nfs_parsed_mount_data *data;
2861 int error = -ENOMEM;
Al Viro01194982011-03-16 07:25:36 -04002862 struct dentry *res = ERR_PTR(-ENOMEM);
Chuck Levera6fe23b2009-09-08 19:50:00 -04002863
Bryan Schumakerdb833352012-05-10 15:07:38 -04002864 data = nfs_alloc_parsed_mount_data();
Chuck Levera6fe23b2009-09-08 19:50:00 -04002865 if (data == NULL)
Jeff Layton8a0d5512011-12-20 06:57:45 -05002866 goto out;
Chuck Levera6fe23b2009-09-08 19:50:00 -04002867
2868 /* Validate the mount data */
2869 error = nfs4_validate_mount_data(raw_data, data, dev_name);
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04002870 if (error == NFS_TEXT_DATA)
2871 error = nfs_validate_text_mount_data(raw_data, data, dev_name);
Al Viro01194982011-03-16 07:25:36 -04002872 if (error < 0) {
2873 res = ERR_PTR(error);
Chuck Levera6fe23b2009-09-08 19:50:00 -04002874 goto out;
Al Viro01194982011-03-16 07:25:36 -04002875 }
Chuck Levera6fe23b2009-09-08 19:50:00 -04002876
Al Viro01194982011-03-16 07:25:36 -04002877 res = nfs4_try_mount(flags, dev_name, data);
2878 if (IS_ERR(res))
2879 error = PTR_ERR(res);
Chuck Levera6fe23b2009-09-08 19:50:00 -04002880
2881out:
Jeff Layton8a0d5512011-12-20 06:57:45 -05002882 nfs_free_parsed_mount_data(data);
Al Viro01194982011-03-16 07:25:36 -04002883 dprintk("<-- nfs4_mount() = %d%s\n", error,
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002884 error != 0 ? " [error]" : "");
Al Viro01194982011-03-16 07:25:36 -04002885 return res;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002886}
2887
David Howellsf7b422b2006-06-09 09:34:33 -04002888static void nfs4_kill_super(struct super_block *sb)
2889{
2890 struct nfs_server *server = NFS_SB(sb);
2891
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002892 dprintk("--> %s\n", __func__);
Trond Myklebust515d8612008-12-23 15:21:46 -05002893 nfs_super_return_all_delegations(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002894 kill_anon_super(sb);
David Howells08734042009-04-03 16:42:42 +01002895 nfs_fscache_release_super_cookie(sb);
David Howells54ceac42006-08-22 20:06:13 -04002896 nfs_free_server(server);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002897 dprintk("<-- %s\n", __func__);
David Howellsf7b422b2006-06-09 09:34:33 -04002898}
2899
2900/*
David Howells54ceac42006-08-22 20:06:13 -04002901 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -04002902 */
Al Viro31f43472010-10-29 03:38:12 -04002903static struct dentry *
2904nfs4_xdev_mount(struct file_system_type *fs_type, int flags,
2905 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002906{
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002907 struct nfs_mount_info mount_info = {
2908 .fill_super = nfs4_clone_super,
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002909 .set_security = nfs_clone_sb_security,
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002910 .cloned = raw_data,
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002911 };
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002912 return nfs_xdev_mount_common(&nfs4_fs_type, flags, dev_name, &mount_info);
David Howellsf7b422b2006-06-09 09:34:33 -04002913}
2914
Al Viro31f43472010-10-29 03:38:12 -04002915static struct dentry *
2916nfs4_remote_referral_mount(struct file_system_type *fs_type, int flags,
2917 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002918{
Bryan Schumaker21e4b822012-05-10 15:07:37 -04002919 struct nfs_mount_info mount_info = {
2920 .fill_super = nfs4_fill_super,
2921 .set_security = nfs_clone_sb_security,
2922 .cloned = raw_data,
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002923 };
Bryan Schumaker21e4b822012-05-10 15:07:37 -04002924 struct nfs_server *server;
2925 struct dentry *mntroot = ERR_PTR(-ENOMEM);
2926 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04002927
2928 dprintk("--> nfs4_referral_get_sb()\n");
2929
Trond Myklebust4f727292010-04-16 16:22:48 -04002930 mntfh = nfs_alloc_fhandle();
Bryan Schumaker21e4b822012-05-10 15:07:37 -04002931 if (mount_info.cloned == NULL || mntfh == NULL)
2932 goto out;
Trond Myklebust4f727292010-04-16 16:22:48 -04002933
David Howells54ceac42006-08-22 20:06:13 -04002934 /* create a new volume representation */
Bryan Schumaker21e4b822012-05-10 15:07:37 -04002935 server = nfs4_create_referral_server(mount_info.cloned, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002936 if (IS_ERR(server)) {
Bryan Schumaker21e4b822012-05-10 15:07:37 -04002937 mntroot = ERR_CAST(server);
2938 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002939 }
2940
Bryan Schumaker21e4b822012-05-10 15:07:37 -04002941 mntroot = nfs_fs_mount_common(&nfs4_fs_type, server, flags, dev_name, mntfh, &mount_info);
2942out:
Trond Myklebust4f727292010-04-16 16:22:48 -04002943 nfs_free_fhandle(mntfh);
Al Viro31f43472010-10-29 03:38:12 -04002944 return mntroot;
David Howellsf7b422b2006-06-09 09:34:33 -04002945}
2946
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002947/*
2948 * Create an NFS4 server record on referral traversal
2949 */
Al Viro01194982011-03-16 07:25:36 -04002950static struct dentry *nfs4_referral_mount(struct file_system_type *fs_type,
2951 int flags, const char *dev_name, void *raw_data)
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002952{
2953 struct nfs_clone_mount *data = raw_data;
2954 char *export_path;
2955 struct vfsmount *root_mnt;
Al Viro01194982011-03-16 07:25:36 -04002956 struct dentry *res;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002957
Al Viro01194982011-03-16 07:25:36 -04002958 dprintk("--> nfs4_referral_mount()\n");
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002959
2960 export_path = data->mnt_path;
2961 data->mnt_path = "/";
2962
2963 root_mnt = nfs_do_root_mount(&nfs4_remote_referral_fs_type,
2964 flags, data, data->hostname);
2965 data->mnt_path = export_path;
2966
Al Viro5352d3b2011-11-16 21:52:06 -05002967 res = nfs_follow_remote_path(root_mnt, export_path);
Al Viro01194982011-03-16 07:25:36 -04002968 dprintk("<-- nfs4_referral_mount() = %ld%s\n",
2969 IS_ERR(res) ? PTR_ERR(res) : 0,
2970 IS_ERR(res) ? " [error]" : "");
2971 return res;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002972}
2973
David Howells54ceac42006-08-22 20:06:13 -04002974#endif /* CONFIG_NFS_V4 */