blob: ca3c0e8cf7740938b7f8114bbd514805e068c0c9 [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 Schumaker87c70832012-05-10 15:07:43 -0400286 struct nfs_fh *mntfh;
Bryan Schumakerc40f8d12012-05-10 15:07:34 -0400287};
288
Al Viro42faad92008-04-24 07:21:56 -0400289static void nfs_umount_begin(struct super_block *);
Trond Myklebust816724e2006-06-24 08:41:41 -0400290static int nfs_statfs(struct dentry *, struct kstatfs *);
Al Viro34c80b12011-12-08 21:32:45 -0500291static int nfs_show_options(struct seq_file *, struct dentry *);
Al Virod861c632011-12-08 21:32:45 -0500292static int nfs_show_devname(struct seq_file *, struct dentry *);
Al Viroa6322de2011-12-08 21:37:57 -0500293static int nfs_show_path(struct seq_file *, struct dentry *);
Al Viro64132372011-12-08 20:51:13 -0500294static int nfs_show_stats(struct seq_file *, struct dentry *);
Bryan Schumaker486aa692012-05-10 15:07:39 -0400295static struct dentry *nfs_fs_mount_common(struct file_system_type *,
Bryan Schumaker87c70832012-05-10 15:07:43 -0400296 struct nfs_server *, int, const char *, 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 *);
Bryan Schumakerd72c7272012-05-10 15:07:41 -0400338static int nfs4_validate_mount_data(void *options,
339 struct nfs_parsed_mount_data *args, const char *dev_name);
Al Viro01194982011-03-16 07:25:36 -0400340static struct dentry *nfs4_try_mount(int flags, const char *dev_name,
Bryan Schumaker87c70832012-05-10 15:07:43 -0400341 struct nfs_mount_info *mount_info);
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 -0400350
351static struct file_system_type nfs4_fs_type = {
352 .owner = THIS_MODULE,
353 .name = "nfs4",
Bryan Schumaker87c70832012-05-10 15:07:43 -0400354 .mount = nfs_fs_mount,
Bryan Schumakereeebf912012-06-20 15:53:41 -0400355 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700356 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400357};
358
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400359static struct file_system_type nfs4_remote_fs_type = {
360 .owner = THIS_MODULE,
361 .name = "nfs4",
Al Viro31f43472010-10-29 03:38:12 -0400362 .mount = nfs4_remote_mount,
Bryan Schumakereeebf912012-06-20 15:53:41 -0400363 .kill_sb = nfs_kill_super,
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400364 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
365};
366
David Howells54ceac42006-08-22 20:06:13 -0400367struct file_system_type nfs4_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400368 .owner = THIS_MODULE,
369 .name = "nfs4",
Al Viro31f43472010-10-29 03:38:12 -0400370 .mount = nfs4_xdev_mount,
Bryan Schumakereeebf912012-06-20 15:53:41 -0400371 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700372 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400373};
374
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400375static struct file_system_type nfs4_remote_referral_fs_type = {
376 .owner = THIS_MODULE,
377 .name = "nfs4",
Al Viro31f43472010-10-29 03:38:12 -0400378 .mount = nfs4_remote_referral_mount,
Bryan Schumakereeebf912012-06-20 15:53:41 -0400379 .kill_sb = nfs_kill_super,
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400380 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
381};
382
David Howells54ceac42006-08-22 20:06:13 -0400383struct file_system_type nfs4_referral_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400384 .owner = THIS_MODULE,
385 .name = "nfs4",
Al Viro01194982011-03-16 07:25:36 -0400386 .mount = nfs4_referral_mount,
Bryan Schumakereeebf912012-06-20 15:53:41 -0400387 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700388 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400389};
390
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800391static const struct super_operations nfs4_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400392 .alloc_inode = nfs_alloc_inode,
393 .destroy_inode = nfs_destroy_inode,
Bryan Schumakera8d8f022012-06-20 15:53:49 -0400394 .write_inode = nfs4_write_inode,
Trond Myklebust387c1492010-02-03 08:27:35 -0500395 .put_super = nfs_put_super,
David Howellsf7b422b2006-06-09 09:34:33 -0400396 .statfs = nfs_statfs,
Al Virob57922d2010-06-07 14:34:48 -0400397 .evict_inode = nfs4_evict_inode,
David Howellsf7b422b2006-06-09 09:34:33 -0400398 .umount_begin = nfs_umount_begin,
399 .show_options = nfs_show_options,
Al Viroc7f404b2011-03-16 06:59:40 -0400400 .show_devname = nfs_show_devname,
401 .show_path = nfs_show_path,
David Howellsf7b422b2006-06-09 09:34:33 -0400402 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400403 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400404};
405#endif
406
Rusty Russell8e1f9362007-07-17 04:03:17 -0700407static struct shrinker acl_shrinker = {
408 .shrink = nfs_access_cache_shrinker,
409 .seeks = DEFAULT_SEEKS,
410};
Trond Myklebust979df722006-07-25 11:28:19 -0400411
David Howellsf7b422b2006-06-09 09:34:33 -0400412/*
413 * Register the NFS filesystems
414 */
415int __init register_nfs_fs(void)
416{
417 int ret;
418
419 ret = register_filesystem(&nfs_fs_type);
420 if (ret < 0)
421 goto error_0;
422
David Howellsf7b422b2006-06-09 09:34:33 -0400423 ret = nfs_register_sysctl();
424 if (ret < 0)
425 goto error_1;
Peter Zijlstra89a09142007-03-16 13:38:26 -0800426#ifdef CONFIG_NFS_V4
David Howellsf7b422b2006-06-09 09:34:33 -0400427 ret = register_filesystem(&nfs4_fs_type);
428 if (ret < 0)
429 goto error_2;
430#endif
Rusty Russell8e1f9362007-07-17 04:03:17 -0700431 register_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400432 return 0;
433
434#ifdef CONFIG_NFS_V4
435error_2:
436 nfs_unregister_sysctl();
Peter Zijlstra89a09142007-03-16 13:38:26 -0800437#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400438error_1:
439 unregister_filesystem(&nfs_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400440error_0:
441 return ret;
442}
443
444/*
445 * Unregister the NFS filesystems
446 */
447void __exit unregister_nfs_fs(void)
448{
Rusty Russell8e1f9362007-07-17 04:03:17 -0700449 unregister_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400450#ifdef CONFIG_NFS_V4
451 unregister_filesystem(&nfs4_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400452#endif
Alexey Dobriyan49af7ee2007-09-18 22:46:40 -0700453 nfs_unregister_sysctl();
David Howellsf7b422b2006-06-09 09:34:33 -0400454 unregister_filesystem(&nfs_fs_type);
455}
456
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400457void nfs_sb_active(struct super_block *sb)
Steve Dicksonef818a22007-11-08 04:05:04 -0500458{
459 struct nfs_server *server = NFS_SB(sb);
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400460
461 if (atomic_inc_return(&server->active) == 1)
462 atomic_inc(&sb->s_active);
463}
464
465void nfs_sb_deactive(struct super_block *sb)
466{
467 struct nfs_server *server = NFS_SB(sb);
468
469 if (atomic_dec_and_test(&server->active))
470 deactivate_super(sb);
Steve Dicksonef818a22007-11-08 04:05:04 -0500471}
472
David Howellsf7b422b2006-06-09 09:34:33 -0400473/*
474 * Deliver file system statistics to userspace
475 */
Trond Myklebust816724e2006-06-24 08:41:41 -0400476static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
David Howellsf7b422b2006-06-09 09:34:33 -0400477{
David Howells0c7d90c2006-08-22 20:06:10 -0400478 struct nfs_server *server = NFS_SB(dentry->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400479 unsigned char blockbits;
480 unsigned long blockres;
David Howells0c7d90c2006-08-22 20:06:10 -0400481 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400482 struct nfs_fsstat res;
483 int error = -ENOMEM;
484
485 res.fattr = nfs_alloc_fattr();
486 if (res.fattr == NULL)
487 goto out_err;
David Howellsf7b422b2006-06-09 09:34:33 -0400488
David Howells8fa5c002006-08-22 20:06:12 -0400489 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
Menyhart Zoltanfbf3fdd2010-09-12 19:55:26 -0400490 if (unlikely(error == -ESTALE)) {
491 struct dentry *pd_dentry;
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400492
Menyhart Zoltanfbf3fdd2010-09-12 19:55:26 -0400493 pd_dentry = dget_parent(dentry);
494 if (pd_dentry != NULL) {
495 nfs_zap_caches(pd_dentry->d_inode);
496 dput(pd_dentry);
497 }
498 }
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400499 nfs_free_fattr(res.fattr);
David Howellsf7b422b2006-06-09 09:34:33 -0400500 if (error < 0)
501 goto out_err;
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400502
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700503 buf->f_type = NFS_SUPER_MAGIC;
David Howellsf7b422b2006-06-09 09:34:33 -0400504
505 /*
506 * Current versions of glibc do not correctly handle the
507 * case where f_frsize != f_bsize. Eventually we want to
508 * report the value of wtmult in this field.
509 */
David Howells0c7d90c2006-08-22 20:06:10 -0400510 buf->f_frsize = dentry->d_sb->s_blocksize;
David Howellsf7b422b2006-06-09 09:34:33 -0400511
512 /*
513 * On most *nix systems, f_blocks, f_bfree, and f_bavail
514 * are reported in units of f_frsize. Linux hasn't had
515 * an f_frsize field in its statfs struct until recently,
516 * thus historically Linux's sys_statfs reports these
517 * fields in units of f_bsize.
518 */
David Howells0c7d90c2006-08-22 20:06:10 -0400519 buf->f_bsize = dentry->d_sb->s_blocksize;
520 blockbits = dentry->d_sb->s_blocksize_bits;
David Howellsf7b422b2006-06-09 09:34:33 -0400521 blockres = (1 << blockbits) - 1;
522 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
523 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
524 buf->f_bavail = (res.abytes + blockres) >> blockbits;
525
526 buf->f_files = res.tfiles;
527 buf->f_ffree = res.afiles;
528
529 buf->f_namelen = server->namelen;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700530
David Howellsf7b422b2006-06-09 09:34:33 -0400531 return 0;
532
533 out_err:
Harvey Harrison3110ff82008-05-02 13:42:44 -0700534 dprintk("%s: statfs error = %d\n", __func__, -error);
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700535 return error;
David Howellsf7b422b2006-06-09 09:34:33 -0400536}
537
David Howells7d4e2742006-08-22 20:06:07 -0400538/*
539 * Map the security flavour number to a name
540 */
Trond Myklebust81039f12006-06-09 09:34:34 -0400541static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
542{
David Howells7d4e2742006-08-22 20:06:07 -0400543 static const struct {
Trond Myklebust81039f12006-06-09 09:34:34 -0400544 rpc_authflavor_t flavour;
545 const char *str;
546 } sec_flavours[] = {
547 { RPC_AUTH_NULL, "null" },
548 { RPC_AUTH_UNIX, "sys" },
549 { RPC_AUTH_GSS_KRB5, "krb5" },
550 { RPC_AUTH_GSS_KRB5I, "krb5i" },
551 { RPC_AUTH_GSS_KRB5P, "krb5p" },
552 { RPC_AUTH_GSS_LKEY, "lkey" },
553 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
554 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
555 { RPC_AUTH_GSS_SPKM, "spkm" },
556 { RPC_AUTH_GSS_SPKMI, "spkmi" },
557 { RPC_AUTH_GSS_SPKMP, "spkmp" },
Chuck Lever4d81cd12007-07-01 12:12:40 -0400558 { UINT_MAX, "unknown" }
Trond Myklebust81039f12006-06-09 09:34:34 -0400559 };
560 int i;
561
Chuck Lever4d81cd12007-07-01 12:12:40 -0400562 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
Trond Myklebust81039f12006-06-09 09:34:34 -0400563 if (sec_flavours[i].flavour == flavour)
564 break;
565 }
566 return sec_flavours[i].str;
567}
568
Jeff Laytonee671b02009-12-03 15:58:56 -0500569static void nfs_show_mountd_netid(struct seq_file *m, struct nfs_server *nfss,
570 int showdefaults)
571{
572 struct sockaddr *sap = (struct sockaddr *) &nfss->mountd_address;
573
574 seq_printf(m, ",mountproto=");
575 switch (sap->sa_family) {
576 case AF_INET:
577 switch (nfss->mountd_protocol) {
578 case IPPROTO_UDP:
579 seq_printf(m, RPCBIND_NETID_UDP);
580 break;
581 case IPPROTO_TCP:
582 seq_printf(m, RPCBIND_NETID_TCP);
583 break;
584 default:
585 if (showdefaults)
586 seq_printf(m, "auto");
587 }
588 break;
589 case AF_INET6:
590 switch (nfss->mountd_protocol) {
591 case IPPROTO_UDP:
592 seq_printf(m, RPCBIND_NETID_UDP6);
593 break;
594 case IPPROTO_TCP:
595 seq_printf(m, RPCBIND_NETID_TCP6);
596 break;
597 default:
598 if (showdefaults)
599 seq_printf(m, "auto");
600 }
601 break;
602 default:
603 if (showdefaults)
604 seq_printf(m, "auto");
605 }
606}
607
Chuck Lever82d101d2008-03-14 14:10:37 -0400608static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
609 int showdefaults)
610{
611 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
612
Bryan Schumakerd5eff1a2010-08-03 13:04:00 -0400613 if (nfss->flags & NFS_MOUNT_LEGACY_INTERFACE)
614 return;
615
Chuck Lever82d101d2008-03-14 14:10:37 -0400616 switch (sap->sa_family) {
617 case AF_INET: {
618 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
Harvey Harrisonbe859402008-10-31 00:56:28 -0700619 seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400620 break;
621 }
622 case AF_INET6: {
623 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
Chuck Leverd250e192009-12-03 15:58:56 -0500624 seq_printf(m, ",mountaddr=%pI6c", &sin6->sin6_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400625 break;
626 }
627 default:
628 if (showdefaults)
629 seq_printf(m, ",mountaddr=unspecified");
630 }
631
632 if (nfss->mountd_version || showdefaults)
633 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
Stanislav Kinsburskyaa699472010-12-08 12:40:13 +0300634 if ((nfss->mountd_port &&
635 nfss->mountd_port != (unsigned short)NFS_UNSPEC_PORT) ||
636 showdefaults)
Chuck Lever82d101d2008-03-14 14:10:37 -0400637 seq_printf(m, ",mountport=%u", nfss->mountd_port);
638
Jeff Laytonee671b02009-12-03 15:58:56 -0500639 nfs_show_mountd_netid(m, nfss, showdefaults);
Chuck Lever82d101d2008-03-14 14:10:37 -0400640}
641
Trond Myklebust0be81892010-06-18 12:23:58 -0400642#ifdef CONFIG_NFS_V4
643static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
644 int showdefaults)
645{
646 struct nfs_client *clp = nfss->nfs_client;
647
648 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
Trond Myklebust0be81892010-06-18 12:23:58 -0400649}
650#else
651static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
652 int showdefaults)
653{
654}
655#endif
656
Trond Myklebust7bbceb62012-03-02 14:00:20 -0500657static void nfs_show_nfs_version(struct seq_file *m,
658 unsigned int version,
659 unsigned int minorversion)
660{
661 seq_printf(m, ",vers=%u", version);
662 if (version == 4)
663 seq_printf(m, ".%u", minorversion);
664}
665
David Howellsf7b422b2006-06-09 09:34:33 -0400666/*
667 * Describe the mount options in force on this server representation
668 */
Chuck Lever82d101d2008-03-14 14:10:37 -0400669static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
670 int showdefaults)
David Howellsf7b422b2006-06-09 09:34:33 -0400671{
David Howells509de812006-08-22 20:06:11 -0400672 static const struct proc_nfs_info {
David Howellsf7b422b2006-06-09 09:34:33 -0400673 int flag;
David Howells509de812006-08-22 20:06:11 -0400674 const char *str;
675 const char *nostr;
David Howellsf7b422b2006-06-09 09:34:33 -0400676 } nfs_info[] = {
677 { NFS_MOUNT_SOFT, ",soft", ",hard" },
Chuck Lever82d101d2008-03-14 14:10:37 -0400678 { NFS_MOUNT_POSIX, ",posix", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400679 { NFS_MOUNT_NOCTO, ",nocto", "" },
680 { NFS_MOUNT_NOAC, ",noac", "" },
681 { NFS_MOUNT_NONLM, ",nolock", "" },
682 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400683 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
Chuck Leverd7403512008-12-23 15:21:37 -0500684 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
685 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400686 { 0, NULL, NULL }
687 };
David Howells509de812006-08-22 20:06:11 -0400688 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400689 struct nfs_client *clp = nfss->nfs_client;
Chuck Lever82d101d2008-03-14 14:10:37 -0400690 u32 version = clp->rpc_ops->version;
Suresh Jayaraman7c563cc2010-09-23 14:26:48 -0400691 int local_flock, local_fcntl;
David Howellsf7b422b2006-06-09 09:34:33 -0400692
Trond Myklebust7bbceb62012-03-02 14:00:20 -0500693 nfs_show_nfs_version(m, version, clp->cl_minorversion);
Chuck Lever2d767432008-03-14 14:10:08 -0400694 seq_printf(m, ",rsize=%u", nfss->rsize);
695 seq_printf(m, ",wsize=%u", nfss->wsize);
Chuck Lever82d101d2008-03-14 14:10:37 -0400696 if (nfss->bsize != 0)
697 seq_printf(m, ",bsize=%u", nfss->bsize);
698 seq_printf(m, ",namlen=%u", nfss->namelen);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400699 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400700 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400701 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400702 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400703 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400704 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400705 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400706 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
David Howellsf7b422b2006-06-09 09:34:33 -0400707 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
708 if (nfss->flags & nfs_infop->flag)
709 seq_puts(m, nfs_infop->str);
710 else
711 seq_puts(m, nfs_infop->nostr);
712 }
Trond Myklebust2446ab62012-03-01 17:00:56 -0500713 rcu_read_lock();
\"Talpey, Thomas\56928ed2007-09-10 13:48:47 -0400714 seq_printf(m, ",proto=%s",
Jeff Laytonee671b02009-12-03 15:58:56 -0500715 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
Trond Myklebust2446ab62012-03-01 17:00:56 -0500716 rcu_read_unlock();
Chuck Lever82d101d2008-03-14 14:10:37 -0400717 if (version == 4) {
718 if (nfss->port != NFS_PORT)
719 seq_printf(m, ",port=%u", nfss->port);
720 } else
721 if (nfss->port)
722 seq_printf(m, ",port=%u", nfss->port);
723
Trond Myklebust33170232007-12-20 16:03:59 -0500724 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
725 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
Trond Myklebust81039f12006-06-09 09:34:34 -0400726 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
Chuck Lever82d101d2008-03-14 14:10:37 -0400727
728 if (version != 4)
729 nfs_show_mountd_options(m, nfss, showdefaults);
Trond Myklebust0be81892010-06-18 12:23:58 -0400730 else
731 nfs_show_nfsv4_options(m, nfss, showdefaults);
Chuck Lever82d101d2008-03-14 14:10:37 -0400732
David Howellsb797cac2009-04-03 16:42:48 +0100733 if (nfss->options & NFS_OPTION_FSCACHE)
734 seq_printf(m, ",fsc");
Patrick J. LoPresti9b00c642010-08-10 17:28:01 -0400735
736 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONEG) {
737 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONE)
738 seq_printf(m, ",lookupcache=none");
739 else
740 seq_printf(m, ",lookupcache=pos");
741 }
Suresh Jayaraman7c563cc2010-09-23 14:26:48 -0400742
743 local_flock = nfss->flags & NFS_MOUNT_LOCAL_FLOCK;
744 local_fcntl = nfss->flags & NFS_MOUNT_LOCAL_FCNTL;
745
746 if (!local_flock && !local_fcntl)
747 seq_printf(m, ",local_lock=none");
748 else if (local_flock && local_fcntl)
749 seq_printf(m, ",local_lock=all");
750 else if (local_flock)
751 seq_printf(m, ",local_lock=flock");
752 else
753 seq_printf(m, ",local_lock=posix");
David Howellsf7b422b2006-06-09 09:34:33 -0400754}
755
756/*
757 * Describe the mount options on this VFS mountpoint
758 */
Al Viro34c80b12011-12-08 21:32:45 -0500759static int nfs_show_options(struct seq_file *m, struct dentry *root)
David Howellsf7b422b2006-06-09 09:34:33 -0400760{
Al Viro34c80b12011-12-08 21:32:45 -0500761 struct nfs_server *nfss = NFS_SB(root->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400762
763 nfs_show_mount_options(m, nfss, 0);
764
Trond Myklebust2446ab62012-03-01 17:00:56 -0500765 rcu_read_lock();
Chuck Lever5d8515c2007-12-10 14:57:16 -0500766 seq_printf(m, ",addr=%s",
767 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
768 RPC_DISPLAY_ADDR));
Trond Myklebust2446ab62012-03-01 17:00:56 -0500769 rcu_read_unlock();
David Howellsf7b422b2006-06-09 09:34:33 -0400770
771 return 0;
772}
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700773
774#ifdef CONFIG_NFS_V4
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300775#ifdef CONFIG_NFS_V4_1
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700776static void show_sessions(struct seq_file *m, struct nfs_server *server)
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300777{
778 if (nfs4_has_session(server->nfs_client))
779 seq_printf(m, ",sessions");
780}
781#else
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700782static void show_sessions(struct seq_file *m, struct nfs_server *server) {}
783#endif
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300784#endif
785
786#ifdef CONFIG_NFS_V4_1
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700787static void show_pnfs(struct seq_file *m, struct nfs_server *server)
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300788{
789 seq_printf(m, ",pnfs=");
790 if (server->pnfs_curr_ld)
791 seq_printf(m, "%s", server->pnfs_curr_ld->name);
792 else
793 seq_printf(m, "not configured");
794}
Trond Myklebust7e03b7c2012-03-04 18:12:57 -0500795
796static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
797{
Chuck Lever59155542012-05-21 22:44:41 -0400798 if (nfss->nfs_client && nfss->nfs_client->cl_implid) {
799 struct nfs41_impl_id *impl_id = nfss->nfs_client->cl_implid;
Trond Myklebust7e03b7c2012-03-04 18:12:57 -0500800 seq_printf(m, "\n\timpl_id:\tname='%s',domain='%s',"
801 "date='%llu,%u'",
802 impl_id->name, impl_id->domain,
803 impl_id->date.seconds, impl_id->date.nseconds);
804 }
805}
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700806#else
Trond Myklebust7e03b7c2012-03-04 18:12:57 -0500807#ifdef CONFIG_NFS_V4
808static void show_pnfs(struct seq_file *m, struct nfs_server *server)
809{
810}
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700811#endif
Trond Myklebust7e03b7c2012-03-04 18:12:57 -0500812static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
813{
814}
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700815#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400816
Al Virod861c632011-12-08 21:32:45 -0500817static int nfs_show_devname(struct seq_file *m, struct dentry *root)
Al Viroc7f404b2011-03-16 06:59:40 -0400818{
819 char *page = (char *) __get_free_page(GFP_KERNEL);
820 char *devname, *dummy;
821 int err = 0;
822 if (!page)
823 return -ENOMEM;
Al Virod861c632011-12-08 21:32:45 -0500824 devname = nfs_path(&dummy, root, page, PAGE_SIZE);
Al Viroc7f404b2011-03-16 06:59:40 -0400825 if (IS_ERR(devname))
826 err = PTR_ERR(devname);
827 else
828 seq_escape(m, devname, " \t\n\\");
829 free_page((unsigned long)page);
830 return err;
831}
832
Al Viroa6322de2011-12-08 21:37:57 -0500833static int nfs_show_path(struct seq_file *m, struct dentry *dentry)
Al Viroc7f404b2011-03-16 06:59:40 -0400834{
835 seq_puts(m, "/");
836 return 0;
837}
838
David Howellsf7b422b2006-06-09 09:34:33 -0400839/*
840 * Present statistical information for this VFS mountpoint
841 */
Al Viro64132372011-12-08 20:51:13 -0500842static int nfs_show_stats(struct seq_file *m, struct dentry *root)
David Howellsf7b422b2006-06-09 09:34:33 -0400843{
844 int i, cpu;
Al Viro64132372011-12-08 20:51:13 -0500845 struct nfs_server *nfss = NFS_SB(root->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400846 struct rpc_auth *auth = nfss->client->cl_auth;
847 struct nfs_iostats totals = { };
848
849 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
850
851 /*
852 * Display all mount option settings
853 */
854 seq_printf(m, "\n\topts:\t");
Al Viro64132372011-12-08 20:51:13 -0500855 seq_puts(m, root->d_sb->s_flags & MS_RDONLY ? "ro" : "rw");
856 seq_puts(m, root->d_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
857 seq_puts(m, root->d_sb->s_flags & MS_NOATIME ? ",noatime" : "");
858 seq_puts(m, root->d_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
David Howellsf7b422b2006-06-09 09:34:33 -0400859 nfs_show_mount_options(m, nfss, 1);
860
861 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
862
Trond Myklebust7e03b7c2012-03-04 18:12:57 -0500863 show_implementation_id(m, nfss);
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500864
David Howellsf7b422b2006-06-09 09:34:33 -0400865 seq_printf(m, "\n\tcaps:\t");
866 seq_printf(m, "caps=0x%x", nfss->caps);
Chuck Lever2d767432008-03-14 14:10:08 -0400867 seq_printf(m, ",wtmult=%u", nfss->wtmult);
868 seq_printf(m, ",dtsize=%u", nfss->dtsize);
869 seq_printf(m, ",bsize=%u", nfss->bsize);
870 seq_printf(m, ",namlen=%u", nfss->namelen);
David Howellsf7b422b2006-06-09 09:34:33 -0400871
872#ifdef CONFIG_NFS_V4
Trond Myklebust40c553192007-12-14 14:56:07 -0500873 if (nfss->nfs_client->rpc_ops->version == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400874 seq_printf(m, "\n\tnfsv4:\t");
875 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
876 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
877 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300878 show_sessions(m, nfss);
879 show_pnfs(m, nfss);
David Howellsf7b422b2006-06-09 09:34:33 -0400880 }
881#endif
882
883 /*
884 * Display security flavor in effect for this mount
885 */
Chuck Lever2d767432008-03-14 14:10:08 -0400886 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400887 if (auth->au_flavor)
Chuck Lever2d767432008-03-14 14:10:08 -0400888 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400889
890 /*
891 * Display superblock I/O counters
892 */
893 for_each_possible_cpu(cpu) {
894 struct nfs_iostats *stats;
895
896 preempt_disable();
897 stats = per_cpu_ptr(nfss->io_stats, cpu);
898
899 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
900 totals.events[i] += stats->events[i];
901 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
902 totals.bytes[i] += stats->bytes[i];
David Howells6a510912009-04-03 16:42:43 +0100903#ifdef CONFIG_NFS_FSCACHE
904 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
905 totals.fscache[i] += stats->fscache[i];
906#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400907
908 preempt_enable();
909 }
910
911 seq_printf(m, "\n\tevents:\t");
912 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
913 seq_printf(m, "%lu ", totals.events[i]);
914 seq_printf(m, "\n\tbytes:\t");
915 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
916 seq_printf(m, "%Lu ", totals.bytes[i]);
David Howells6a510912009-04-03 16:42:43 +0100917#ifdef CONFIG_NFS_FSCACHE
918 if (nfss->options & NFS_OPTION_FSCACHE) {
919 seq_printf(m, "\n\tfsc:\t");
920 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
921 seq_printf(m, "%Lu ", totals.bytes[i]);
922 }
923#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400924 seq_printf(m, "\n");
925
926 rpc_print_iostats(m, nfss->client);
927
928 return 0;
929}
930
931/*
932 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400933 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400934 */
Al Viro42faad92008-04-24 07:21:56 -0400935static void nfs_umount_begin(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -0400936{
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200937 struct nfs_server *server;
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400938 struct rpc_clnt *rpc;
939
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200940 server = NFS_SB(sb);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400941 /* -EIO all pending I/O */
942 rpc = server->client_acl;
943 if (!IS_ERR(rpc))
944 rpc_killall_tasks(rpc);
945 rpc = server->client;
946 if (!IS_ERR(rpc))
947 rpc_killall_tasks(rpc);
David Howellsf7b422b2006-06-09 09:34:33 -0400948}
949
Bryan Schumakerdb833352012-05-10 15:07:38 -0400950static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(void)
Chuck Lever9423a082009-09-23 14:36:38 -0400951{
952 struct nfs_parsed_mount_data *data;
953
954 data = kzalloc(sizeof(*data), GFP_KERNEL);
955 if (data) {
Chuck Lever9423a082009-09-23 14:36:38 -0400956 data->acregmin = NFS_DEF_ACREGMIN;
957 data->acregmax = NFS_DEF_ACREGMAX;
958 data->acdirmin = NFS_DEF_ACDIRMIN;
959 data->acdirmax = NFS_DEF_ACDIRMAX;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400960 data->mount_server.port = NFS_UNSPEC_PORT;
Chuck Lever9423a082009-09-23 14:36:38 -0400961 data->nfs_server.port = NFS_UNSPEC_PORT;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400962 data->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Lever9423a082009-09-23 14:36:38 -0400963 data->auth_flavors[0] = RPC_AUTH_UNIX;
964 data->auth_flavor_len = 1;
965 data->minorversion = 0;
Bryan Schumakerb72e4f42012-05-10 15:07:40 -0400966 data->need_mount = true;
Trond Myklebust9937347a2012-02-19 08:44:07 +0100967 data->net = current->nsproxy->net_ns;
Jeff Layton8a0d5512011-12-20 06:57:45 -0500968 security_init_mnt_opts(&data->lsm_opts);
Chuck Lever9423a082009-09-23 14:36:38 -0400969 }
970 return data;
971}
972
Jeff Layton8a0d5512011-12-20 06:57:45 -0500973static void nfs_free_parsed_mount_data(struct nfs_parsed_mount_data *data)
974{
975 if (data) {
976 kfree(data->client_address);
977 kfree(data->mount_server.hostname);
978 kfree(data->nfs_server.export_path);
979 kfree(data->nfs_server.hostname);
980 kfree(data->fscache_uniq);
981 security_free_mnt_opts(&data->lsm_opts);
982 kfree(data);
983 }
984}
985
David Howellsf7b422b2006-06-09 09:34:33 -0400986/*
Chuck Levercdcd7f92007-12-10 14:57:45 -0500987 * Sanity-check a server address provided by the mount command.
988 *
989 * Address family must be initialized, and address must not be
990 * the ANY address for that family.
Chuck Leverfc50d582007-07-01 12:12:46 -0400991 */
992static int nfs_verify_server_address(struct sockaddr *addr)
993{
994 switch (addr->sa_family) {
995 case AF_INET: {
Chuck Levercdcd7f92007-12-10 14:57:45 -0500996 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
Al Viroe6f1ceb2008-03-17 22:44:53 -0700997 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
Chuck Levercdcd7f92007-12-10 14:57:45 -0500998 }
999 case AF_INET6: {
1000 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
1001 return !ipv6_addr_any(sa);
Chuck Leverfc50d582007-07-01 12:12:46 -04001002 }
1003 }
1004
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001005 dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
Chuck Leverfc50d582007-07-01 12:12:46 -04001006 return 0;
1007}
1008
Chuck Lever9412b922007-12-10 14:59:21 -05001009/*
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001010 * Select between a default port value and a user-specified port value.
1011 * If a zero value is set, then autobind will be used.
1012 */
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001013static void nfs_set_port(struct sockaddr *sap, int *port,
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001014 const unsigned short default_port)
1015{
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001016 if (*port == NFS_UNSPEC_PORT)
1017 *port = default_port;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001018
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001019 rpc_set_port(sap, *port);
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001020}
1021
1022/*
Trond Myklebust259875e2008-07-02 14:43:47 -04001023 * Sanity check the NFS transport protocol.
1024 *
1025 */
1026static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
1027{
1028 switch (mnt->nfs_server.protocol) {
1029 case XPRT_TRANSPORT_UDP:
1030 case XPRT_TRANSPORT_TCP:
1031 case XPRT_TRANSPORT_RDMA:
1032 break;
1033 default:
1034 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1035 }
1036}
1037
1038/*
1039 * For text based NFSv2/v3 mounts, the mount protocol transport default
1040 * settings should depend upon the specified NFS transport.
1041 */
1042static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
1043{
1044 nfs_validate_transport_protocol(mnt);
1045
1046 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
1047 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
1048 return;
1049 switch (mnt->nfs_server.protocol) {
1050 case XPRT_TRANSPORT_UDP:
1051 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
1052 break;
1053 case XPRT_TRANSPORT_TCP:
1054 case XPRT_TRANSPORT_RDMA:
1055 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
1056 }
1057}
1058
1059/*
Chuck Lever01060c82008-06-24 16:33:38 -04001060 * Parse the value of the 'sec=' option.
Chuck Lever01060c82008-06-24 16:33:38 -04001061 */
1062static int nfs_parse_security_flavors(char *value,
1063 struct nfs_parsed_mount_data *mnt)
1064{
1065 substring_t args[MAX_OPT_ARGS];
1066
1067 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
1068
1069 switch (match_token(value, nfs_secflavor_tokens, args)) {
1070 case Opt_sec_none:
Chuck Lever01060c82008-06-24 16:33:38 -04001071 mnt->auth_flavors[0] = RPC_AUTH_NULL;
1072 break;
1073 case Opt_sec_sys:
Chuck Lever01060c82008-06-24 16:33:38 -04001074 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
1075 break;
1076 case Opt_sec_krb5:
Chuck Lever01060c82008-06-24 16:33:38 -04001077 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
1078 break;
1079 case Opt_sec_krb5i:
Chuck Lever01060c82008-06-24 16:33:38 -04001080 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
1081 break;
1082 case Opt_sec_krb5p:
Chuck Lever01060c82008-06-24 16:33:38 -04001083 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
1084 break;
1085 case Opt_sec_lkey:
Chuck Lever01060c82008-06-24 16:33:38 -04001086 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
1087 break;
1088 case Opt_sec_lkeyi:
Chuck Lever01060c82008-06-24 16:33:38 -04001089 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
1090 break;
1091 case Opt_sec_lkeyp:
Chuck Lever01060c82008-06-24 16:33:38 -04001092 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
1093 break;
1094 case Opt_sec_spkm:
Chuck Lever01060c82008-06-24 16:33:38 -04001095 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
1096 break;
1097 case Opt_sec_spkmi:
Chuck Lever01060c82008-06-24 16:33:38 -04001098 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
1099 break;
1100 case Opt_sec_spkmp:
Chuck Lever01060c82008-06-24 16:33:38 -04001101 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
1102 break;
1103 default:
1104 return 0;
1105 }
1106
Bryan Schumaker9b7160c2011-04-13 14:31:30 -04001107 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
Chuck Lever059f90b2009-08-09 15:09:31 -04001108 mnt->auth_flavor_len = 1;
Chuck Lever01060c82008-06-24 16:33:38 -04001109 return 1;
1110}
1111
Trond Myklebust0d71b052012-03-02 13:59:49 -05001112static int nfs_parse_version_string(char *string,
1113 struct nfs_parsed_mount_data *mnt,
1114 substring_t *args)
1115{
1116 mnt->flags &= ~NFS_MOUNT_VER3;
1117 switch (match_token(string, nfs_vers_tokens, args)) {
1118 case Opt_vers_2:
1119 mnt->version = 2;
1120 break;
1121 case Opt_vers_3:
1122 mnt->flags |= NFS_MOUNT_VER3;
1123 mnt->version = 3;
1124 break;
1125 case Opt_vers_4:
1126 /* Backward compatibility option. In future,
1127 * the mount program should always supply
1128 * a NFSv4 minor version number.
1129 */
1130 mnt->version = 4;
1131 break;
1132 case Opt_vers_4_0:
1133 mnt->version = 4;
1134 mnt->minorversion = 0;
1135 break;
1136 case Opt_vers_4_1:
1137 mnt->version = 4;
1138 mnt->minorversion = 1;
1139 break;
1140 default:
1141 return 0;
1142 }
1143 return 1;
1144}
1145
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001146static int nfs_get_option_str(substring_t args[], char **option)
1147{
1148 kfree(*option);
1149 *option = match_strdup(args);
1150 return !option;
1151}
1152
1153static int nfs_get_option_ul(substring_t args[], unsigned long *option)
1154{
1155 int rc;
1156 char *string;
1157
1158 string = match_strdup(args);
1159 if (string == NULL)
1160 return -ENOMEM;
1161 rc = strict_strtoul(string, 10, option);
1162 kfree(string);
1163
1164 return rc;
1165}
1166
Chuck Lever01060c82008-06-24 16:33:38 -04001167/*
Chuck Leverbf0fd762007-07-01 12:13:44 -04001168 * Error-check and convert a string of mount options from user space into
Chuck Leverf45663c2008-06-24 19:28:02 -04001169 * a data structure. The whole mount string is processed; bad options are
1170 * skipped as they are encountered. If there were no errors, return 1;
1171 * otherwise return 0 (zero).
Chuck Leverbf0fd762007-07-01 12:13:44 -04001172 */
1173static int nfs_parse_mount_options(char *raw,
1174 struct nfs_parsed_mount_data *mnt)
1175{
Eric Parisf9c3a382008-03-05 14:20:18 -05001176 char *p, *string, *secdata;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001177 int rc, sloppy = 0, invalid_option = 0;
Jeff Laytonee671b02009-12-03 15:58:56 -05001178 unsigned short protofamily = AF_UNSPEC;
1179 unsigned short mountfamily = AF_UNSPEC;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001180
1181 if (!raw) {
1182 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
1183 return 1;
1184 }
1185 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
1186
Eric Parisf9c3a382008-03-05 14:20:18 -05001187 secdata = alloc_secdata();
1188 if (!secdata)
1189 goto out_nomem;
1190
1191 rc = security_sb_copy_data(raw, secdata);
1192 if (rc)
1193 goto out_security_failure;
1194
1195 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
1196 if (rc)
1197 goto out_security_failure;
1198
1199 free_secdata(secdata);
1200
Chuck Leverbf0fd762007-07-01 12:13:44 -04001201 while ((p = strsep(&raw, ",")) != NULL) {
1202 substring_t args[MAX_OPT_ARGS];
Chuck Levera5a16ba2009-06-17 18:02:14 -07001203 unsigned long option;
1204 int token;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001205
1206 if (!*p)
1207 continue;
1208
1209 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
1210
1211 token = match_token(p, nfs_mount_option_tokens, args);
1212 switch (token) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001213
1214 /*
1215 * boolean options: foo/nofoo
1216 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001217 case Opt_soft:
1218 mnt->flags |= NFS_MOUNT_SOFT;
1219 break;
1220 case Opt_hard:
1221 mnt->flags &= ~NFS_MOUNT_SOFT;
1222 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001223 case Opt_posix:
1224 mnt->flags |= NFS_MOUNT_POSIX;
1225 break;
1226 case Opt_noposix:
1227 mnt->flags &= ~NFS_MOUNT_POSIX;
1228 break;
1229 case Opt_cto:
1230 mnt->flags &= ~NFS_MOUNT_NOCTO;
1231 break;
1232 case Opt_nocto:
1233 mnt->flags |= NFS_MOUNT_NOCTO;
1234 break;
1235 case Opt_ac:
1236 mnt->flags &= ~NFS_MOUNT_NOAC;
1237 break;
1238 case Opt_noac:
1239 mnt->flags |= NFS_MOUNT_NOAC;
1240 break;
1241 case Opt_lock:
1242 mnt->flags &= ~NFS_MOUNT_NONLM;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001243 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1244 NFS_MOUNT_LOCAL_FCNTL);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001245 break;
1246 case Opt_nolock:
1247 mnt->flags |= NFS_MOUNT_NONLM;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001248 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1249 NFS_MOUNT_LOCAL_FCNTL);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001250 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001251 case Opt_udp:
1252 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001253 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001254 break;
1255 case Opt_tcp:
1256 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001257 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001258 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001259 case Opt_rdma:
1260 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1261 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001262 xprt_load_transport(p);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001263 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001264 case Opt_acl:
1265 mnt->flags &= ~NFS_MOUNT_NOACL;
1266 break;
1267 case Opt_noacl:
1268 mnt->flags |= NFS_MOUNT_NOACL;
1269 break;
1270 case Opt_rdirplus:
1271 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1272 break;
1273 case Opt_nordirplus:
1274 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1275 break;
Trond Myklebust75180df2007-05-16 16:53:28 -04001276 case Opt_sharecache:
1277 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1278 break;
1279 case Opt_nosharecache:
1280 mnt->flags |= NFS_MOUNT_UNSHARED;
1281 break;
Chuck Leverd7403512008-12-23 15:21:37 -05001282 case Opt_resvport:
1283 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1284 break;
1285 case Opt_noresvport:
1286 mnt->flags |= NFS_MOUNT_NORESVPORT;
1287 break;
David Howellsb797cac2009-04-03 16:42:48 +01001288 case Opt_fscache:
1289 mnt->options |= NFS_OPTION_FSCACHE;
1290 kfree(mnt->fscache_uniq);
1291 mnt->fscache_uniq = NULL;
1292 break;
1293 case Opt_nofscache:
1294 mnt->options &= ~NFS_OPTION_FSCACHE;
1295 kfree(mnt->fscache_uniq);
1296 mnt->fscache_uniq = NULL;
1297 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001298
Chuck Leverf45663c2008-06-24 19:28:02 -04001299 /*
1300 * options that take numeric values
1301 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001302 case Opt_port:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001303 if (nfs_get_option_ul(args, &option) ||
1304 option > USHRT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001305 goto out_invalid_value;
1306 mnt->nfs_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001307 break;
1308 case Opt_rsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001309 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001310 goto out_invalid_value;
1311 mnt->rsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001312 break;
1313 case Opt_wsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001314 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001315 goto out_invalid_value;
1316 mnt->wsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001317 break;
1318 case Opt_bsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001319 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001320 goto out_invalid_value;
1321 mnt->bsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001322 break;
1323 case Opt_timeo:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001324 if (nfs_get_option_ul(args, &option) || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001325 goto out_invalid_value;
1326 mnt->timeo = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001327 break;
1328 case Opt_retrans:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001329 if (nfs_get_option_ul(args, &option) || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001330 goto out_invalid_value;
1331 mnt->retrans = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001332 break;
1333 case Opt_acregmin:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001334 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001335 goto out_invalid_value;
1336 mnt->acregmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001337 break;
1338 case Opt_acregmax:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001339 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001340 goto out_invalid_value;
1341 mnt->acregmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001342 break;
1343 case Opt_acdirmin:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001344 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001345 goto out_invalid_value;
1346 mnt->acdirmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001347 break;
1348 case Opt_acdirmax:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001349 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001350 goto out_invalid_value;
1351 mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001352 break;
1353 case Opt_actimeo:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001354 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001355 goto out_invalid_value;
1356 mnt->acregmin = mnt->acregmax =
1357 mnt->acdirmin = mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001358 break;
1359 case Opt_namelen:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001360 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001361 goto out_invalid_value;
1362 mnt->namlen = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001363 break;
1364 case Opt_mountport:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001365 if (nfs_get_option_ul(args, &option) ||
1366 option > USHRT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001367 goto out_invalid_value;
1368 mnt->mount_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001369 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001370 case Opt_mountvers:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001371 if (nfs_get_option_ul(args, &option) ||
Chuck Leverf45663c2008-06-24 19:28:02 -04001372 option < NFS_MNT_VERSION ||
Chuck Leverd23c45f2009-06-17 18:02:13 -07001373 option > NFS_MNT3_VERSION)
1374 goto out_invalid_value;
1375 mnt->mount_server.version = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001376 break;
Mike Sager3fd5be92009-04-01 09:21:48 -04001377 case Opt_minorversion:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001378 if (nfs_get_option_ul(args, &option))
Chuck Leverf3f4f4e2009-08-09 15:09:29 -04001379 goto out_invalid_value;
1380 if (option > NFS4_MAX_MINOR_VERSION)
1381 goto out_invalid_value;
1382 mnt->minorversion = option;
Mike Sager3fd5be92009-04-01 09:21:48 -04001383 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001384
Chuck Leverf45663c2008-06-24 19:28:02 -04001385 /*
1386 * options that take text values
1387 */
Trond Myklebust0d71b052012-03-02 13:59:49 -05001388 case Opt_nfsvers:
1389 string = match_strdup(args);
1390 if (string == NULL)
1391 goto out_nomem;
1392 rc = nfs_parse_version_string(string, mnt, args);
1393 kfree(string);
1394 if (!rc)
1395 goto out_invalid_value;
1396 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001397 case Opt_sec:
1398 string = match_strdup(args);
1399 if (string == NULL)
1400 goto out_nomem;
Chuck Lever01060c82008-06-24 16:33:38 -04001401 rc = nfs_parse_security_flavors(string, mnt);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001402 kfree(string);
Chuck Leverf45663c2008-06-24 19:28:02 -04001403 if (!rc) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001404 dfprintk(MOUNT, "NFS: unrecognized "
1405 "security flavor\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001406 return 0;
Chuck Leverf45663c2008-06-24 19:28:02 -04001407 }
Chuck Leverbf0fd762007-07-01 12:13:44 -04001408 break;
1409 case Opt_proto:
1410 string = match_strdup(args);
1411 if (string == NULL)
1412 goto out_nomem;
1413 token = match_token(string,
1414 nfs_xprt_protocol_tokens, args);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001415
Jeff Laytonee671b02009-12-03 15:58:56 -05001416 protofamily = AF_INET;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001417 switch (token) {
Jeff Laytonee671b02009-12-03 15:58:56 -05001418 case Opt_xprt_udp6:
1419 protofamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001420 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001421 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001422 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001423 break;
Jeff Laytonee671b02009-12-03 15:58:56 -05001424 case Opt_xprt_tcp6:
1425 protofamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001426 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001427 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001428 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001429 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001430 case Opt_xprt_rdma:
1431 /* vector side protocols to TCP */
1432 mnt->flags |= NFS_MOUNT_TCP;
1433 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001434 xprt_load_transport(string);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001435 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001436 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001437 dfprintk(MOUNT, "NFS: unrecognized "
1438 "transport protocol\n");
Yinghai Lu4223a4a2009-10-20 14:13:46 +09001439 kfree(string);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001440 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001441 }
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001442 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001443 break;
1444 case Opt_mountproto:
1445 string = match_strdup(args);
1446 if (string == NULL)
1447 goto out_nomem;
1448 token = match_token(string,
1449 nfs_xprt_protocol_tokens, args);
Trond Myklebustd508afb2009-04-06 16:41:35 -07001450 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001451
Jeff Laytonee671b02009-12-03 15:58:56 -05001452 mountfamily = AF_INET;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001453 switch (token) {
Jeff Laytonee671b02009-12-03 15:58:56 -05001454 case Opt_xprt_udp6:
1455 mountfamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001456 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001457 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001458 break;
Jeff Laytonee671b02009-12-03 15:58:56 -05001459 case Opt_xprt_tcp6:
1460 mountfamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001461 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001462 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001463 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001464 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001465 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001466 dfprintk(MOUNT, "NFS: unrecognized "
1467 "transport protocol\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001468 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001469 }
1470 break;
1471 case Opt_addr:
1472 string = match_strdup(args);
1473 if (string == NULL)
1474 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001475 mnt->nfs_server.addrlen =
Stanislav Kinsburskyb48e1272012-01-26 15:11:57 +04001476 rpc_pton(mnt->net, string, strlen(string),
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001477 (struct sockaddr *)
1478 &mnt->nfs_server.address,
1479 sizeof(mnt->nfs_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001480 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001481 if (mnt->nfs_server.addrlen == 0)
1482 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001483 break;
1484 case Opt_clientaddr:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001485 if (nfs_get_option_str(args, &mnt->client_address))
Chuck Leverbf0fd762007-07-01 12:13:44 -04001486 goto out_nomem;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001487 break;
Chuck Lever33832032007-12-10 14:59:13 -05001488 case Opt_mounthost:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001489 if (nfs_get_option_str(args,
1490 &mnt->mount_server.hostname))
Chuck Lever33832032007-12-10 14:59:13 -05001491 goto out_nomem;
Chuck Lever33832032007-12-10 14:59:13 -05001492 break;
Chuck Lever0ac83772007-09-11 18:01:04 -04001493 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001494 string = match_strdup(args);
1495 if (string == NULL)
1496 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001497 mnt->mount_server.addrlen =
Stanislav Kinsburskyb48e1272012-01-26 15:11:57 +04001498 rpc_pton(mnt->net, string, strlen(string),
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001499 (struct sockaddr *)
1500 &mnt->mount_server.address,
1501 sizeof(mnt->mount_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001502 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001503 if (mnt->mount_server.addrlen == 0)
1504 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001505 break;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001506 case Opt_lookupcache:
1507 string = match_strdup(args);
1508 if (string == NULL)
1509 goto out_nomem;
1510 token = match_token(string,
1511 nfs_lookupcache_tokens, args);
1512 kfree(string);
1513 switch (token) {
1514 case Opt_lookupcache_all:
1515 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1516 break;
1517 case Opt_lookupcache_positive:
1518 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1519 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1520 break;
1521 case Opt_lookupcache_none:
1522 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1523 break;
1524 default:
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001525 dfprintk(MOUNT, "NFS: invalid "
1526 "lookupcache argument\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001527 return 0;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001528 };
1529 break;
Chuck Levera6d5ff62010-05-07 13:33:58 -04001530 case Opt_fscache_uniq:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001531 if (nfs_get_option_str(args, &mnt->fscache_uniq))
Chuck Levera6d5ff62010-05-07 13:33:58 -04001532 goto out_nomem;
Chuck Levera6d5ff62010-05-07 13:33:58 -04001533 mnt->options |= NFS_OPTION_FSCACHE;
1534 break;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001535 case Opt_local_lock:
1536 string = match_strdup(args);
1537 if (string == NULL)
1538 goto out_nomem;
1539 token = match_token(string, nfs_local_lock_tokens,
1540 args);
1541 kfree(string);
1542 switch (token) {
1543 case Opt_local_lock_all:
1544 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1545 NFS_MOUNT_LOCAL_FCNTL);
1546 break;
1547 case Opt_local_lock_flock:
1548 mnt->flags |= NFS_MOUNT_LOCAL_FLOCK;
1549 break;
1550 case Opt_local_lock_posix:
1551 mnt->flags |= NFS_MOUNT_LOCAL_FCNTL;
1552 break;
1553 case Opt_local_lock_none:
1554 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1555 NFS_MOUNT_LOCAL_FCNTL);
1556 break;
1557 default:
1558 dfprintk(MOUNT, "NFS: invalid "
1559 "local_lock argument\n");
1560 return 0;
1561 };
1562 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001563
Chuck Leverf45663c2008-06-24 19:28:02 -04001564 /*
1565 * Special options
1566 */
1567 case Opt_sloppy:
1568 sloppy = 1;
1569 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1570 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001571 case Opt_userspace:
1572 case Opt_deprecated:
Chuck Leverd33e4df2008-06-12 12:37:41 -04001573 dfprintk(MOUNT, "NFS: ignoring mount option "
1574 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001575 break;
1576
1577 default:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001578 invalid_option = 1;
Chuck Leverf45663c2008-06-24 19:28:02 -04001579 dfprintk(MOUNT, "NFS: unrecognized mount option "
1580 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001581 }
1582 }
1583
Chuck Leverd23c45f2009-06-17 18:02:13 -07001584 if (!sloppy && invalid_option)
1585 return 0;
1586
Weston Andros Adamson571b7552012-02-01 14:06:41 -05001587 if (mnt->minorversion && mnt->version != 4)
1588 goto out_minorversion_mismatch;
1589
Jeff Laytonee671b02009-12-03 15:58:56 -05001590 /*
1591 * verify that any proto=/mountproto= options match the address
1592 * familiies in the addr=/mountaddr= options.
1593 */
1594 if (protofamily != AF_UNSPEC &&
1595 protofamily != mnt->nfs_server.address.ss_family)
1596 goto out_proto_mismatch;
1597
1598 if (mountfamily != AF_UNSPEC) {
1599 if (mnt->mount_server.addrlen) {
1600 if (mountfamily != mnt->mount_server.address.ss_family)
1601 goto out_mountproto_mismatch;
1602 } else {
1603 if (mountfamily != mnt->nfs_server.address.ss_family)
1604 goto out_mountproto_mismatch;
1605 }
1606 }
1607
Chuck Leverbf0fd762007-07-01 12:13:44 -04001608 return 1;
1609
Jeff Laytonee671b02009-12-03 15:58:56 -05001610out_mountproto_mismatch:
1611 printk(KERN_INFO "NFS: mount server address does not match mountproto= "
1612 "option\n");
1613 return 0;
1614out_proto_mismatch:
1615 printk(KERN_INFO "NFS: server address does not match proto= option\n");
1616 return 0;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001617out_invalid_address:
1618 printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
1619 return 0;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001620out_invalid_value:
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001621 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001622 return 0;
Weston Andros Adamson571b7552012-02-01 14:06:41 -05001623out_minorversion_mismatch:
1624 printk(KERN_INFO "NFS: mount option vers=%u does not support "
1625 "minorversion=%u\n", mnt->version, mnt->minorversion);
1626 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001627out_nomem:
1628 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1629 return 0;
Eric Parisf9c3a382008-03-05 14:20:18 -05001630out_security_failure:
1631 free_secdata(secdata);
1632 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1633 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001634}
1635
1636/*
Chuck Leverec88f282009-08-09 15:09:32 -04001637 * Match the requested auth flavors with the list returned by
1638 * the server. Returns zero and sets the mount's authentication
1639 * flavor on success; returns -EACCES if server does not support
1640 * the requested flavor.
1641 */
1642static int nfs_walk_authlist(struct nfs_parsed_mount_data *args,
1643 struct nfs_mount_request *request)
1644{
1645 unsigned int i, j, server_authlist_len = *(request->auth_flav_len);
1646
1647 /*
Chuck Lever5eecfde2009-08-21 17:50:30 -04001648 * Certain releases of Linux's mountd return an empty
1649 * flavor list. To prevent behavioral regression with
1650 * these servers (ie. rejecting mounts that used to
1651 * succeed), revert to pre-2.6.32 behavior (no checking)
1652 * if the returned flavor list is empty.
1653 */
1654 if (server_authlist_len == 0)
1655 return 0;
1656
1657 /*
Chuck Leverec88f282009-08-09 15:09:32 -04001658 * We avoid sophisticated negotiating here, as there are
1659 * plenty of cases where we can get it wrong, providing
1660 * either too little or too much security.
1661 *
1662 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1663 * flavor listed first. However, some servers list
1664 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1665 * preferred default, in args->auth_flavors[0] if user
1666 * didn't specify sec= mount option.
1667 */
1668 for (i = 0; i < args->auth_flavor_len; i++)
1669 for (j = 0; j < server_authlist_len; j++)
1670 if (args->auth_flavors[i] == request->auth_flavs[j]) {
1671 dfprintk(MOUNT, "NFS: using auth flavor %d\n",
1672 request->auth_flavs[j]);
1673 args->auth_flavors[0] = request->auth_flavs[j];
1674 return 0;
1675 }
1676
1677 dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n");
1678 nfs_umount(request);
1679 return -EACCES;
1680}
1681
1682/*
Chuck Lever0076d7b2007-07-01 12:13:49 -04001683 * Use the remote server's MOUNT service to request the NFS file handle
1684 * corresponding to the provided path.
1685 */
Bryan Schumaker486aa692012-05-10 15:07:39 -04001686static int nfs_request_mount(struct nfs_parsed_mount_data *args,
1687 struct nfs_fh *root_fh)
Chuck Lever0076d7b2007-07-01 12:13:49 -04001688{
Chuck Leverec88f282009-08-09 15:09:32 -04001689 rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS];
1690 unsigned int server_authlist_len = ARRAY_SIZE(server_authlist);
Chuck Leverc5d120f2008-12-23 15:21:35 -05001691 struct nfs_mount_request request = {
1692 .sap = (struct sockaddr *)
1693 &args->mount_server.address,
1694 .dirpath = args->nfs_server.export_path,
1695 .protocol = args->mount_server.protocol,
1696 .fh = root_fh,
Chuck Lever50a737f2008-12-23 15:21:37 -05001697 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
Chuck Leverec88f282009-08-09 15:09:32 -04001698 .auth_flav_len = &server_authlist_len,
1699 .auth_flavs = server_authlist,
Stanislav Kinsbursky6d59b8d2012-01-10 16:12:54 +04001700 .net = args->net,
Chuck Leverc5d120f2008-12-23 15:21:35 -05001701 };
Chuck Lever4c568012007-12-10 14:59:28 -05001702 int status;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001703
1704 if (args->mount_server.version == 0) {
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001705 switch (args->version) {
1706 default:
1707 args->mount_server.version = NFS_MNT3_VERSION;
1708 break;
1709 case 2:
1710 args->mount_server.version = NFS_MNT_VERSION;
1711 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001712 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001713 request.version = args->mount_server.version;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001714
Chuck Lever33832032007-12-10 14:59:13 -05001715 if (args->mount_server.hostname)
Chuck Leverc5d120f2008-12-23 15:21:35 -05001716 request.hostname = args->mount_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001717 else
Chuck Leverc5d120f2008-12-23 15:21:35 -05001718 request.hostname = args->nfs_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001719
Chuck Lever0076d7b2007-07-01 12:13:49 -04001720 /*
1721 * Construct the mount server's address.
1722 */
Chuck Lever4c568012007-12-10 14:59:28 -05001723 if (args->mount_server.address.ss_family == AF_UNSPEC) {
Chuck Leverc5d120f2008-12-23 15:21:35 -05001724 memcpy(request.sap, &args->nfs_server.address,
Chuck Lever4c568012007-12-10 14:59:28 -05001725 args->nfs_server.addrlen);
1726 args->mount_server.addrlen = args->nfs_server.addrlen;
1727 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001728 request.salen = args->mount_server.addrlen;
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001729 nfs_set_port(request.sap, &args->mount_server.port, 0);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001730
1731 /*
1732 * Now ask the mount server to map our export path
1733 * to a file handle.
1734 */
Chuck Leverc5d120f2008-12-23 15:21:35 -05001735 status = nfs_mount(&request);
Chuck Leverec88f282009-08-09 15:09:32 -04001736 if (status != 0) {
1737 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1738 request.hostname, status);
1739 return status;
1740 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001741
Chuck Leverec88f282009-08-09 15:09:32 -04001742 /*
1743 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1744 */
1745 if (args->mount_server.version != NFS_MNT3_VERSION)
1746 return 0;
1747 return nfs_walk_authlist(args, &request);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001748}
1749
Bryan Schumaker486aa692012-05-10 15:07:39 -04001750static struct dentry *nfs_try_mount(int flags, const char *dev_name,
Bryan Schumaker486aa692012-05-10 15:07:39 -04001751 struct nfs_mount_info *mount_info)
1752{
1753 int status;
1754 struct nfs_server *server;
1755
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04001756 if (mount_info->parsed->need_mount) {
Bryan Schumaker87c70832012-05-10 15:07:43 -04001757 status = nfs_request_mount(mount_info->parsed, mount_info->mntfh);
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04001758 if (status)
1759 return ERR_PTR(status);
1760 }
Bryan Schumaker486aa692012-05-10 15:07:39 -04001761
1762 /* Get a volume representation */
Bryan Schumaker87c70832012-05-10 15:07:43 -04001763 server = nfs_create_server(mount_info->parsed, mount_info->mntfh);
Bryan Schumaker486aa692012-05-10 15:07:39 -04001764 if (IS_ERR(server))
1765 return ERR_CAST(server);
1766
Bryan Schumaker87c70832012-05-10 15:07:43 -04001767 return nfs_fs_mount_common(&nfs_fs_type, server, flags, dev_name, mount_info);
Bryan Schumaker486aa692012-05-10 15:07:39 -04001768}
1769
Rob Landleyc12bace2011-03-09 15:54:13 -06001770/*
1771 * Split "dev_name" into "hostname:export_path".
1772 *
1773 * The leftmost colon demarks the split between the server's hostname
1774 * and the export path. If the hostname starts with a left square
1775 * bracket, then it may contain colons.
1776 *
1777 * Note: caller frees hostname and export path, even on error.
1778 */
1779static int nfs_parse_devname(const char *dev_name,
1780 char **hostname, size_t maxnamlen,
1781 char **export_path, size_t maxpathlen)
Chuck Leverdc045892008-06-23 12:36:37 -04001782{
1783 size_t len;
Rob Landleyc12bace2011-03-09 15:54:13 -06001784 char *end;
Chuck Leverdc045892008-06-23 12:36:37 -04001785
Rob Landleyc12bace2011-03-09 15:54:13 -06001786 /* Is the host name protected with square brakcets? */
1787 if (*dev_name == '[') {
1788 end = strchr(++dev_name, ']');
1789 if (end == NULL || end[1] != ':')
1790 goto out_bad_devname;
Chuck Leverdc045892008-06-23 12:36:37 -04001791
Rob Landleyc12bace2011-03-09 15:54:13 -06001792 len = end - dev_name;
1793 end++;
1794 } else {
1795 char *comma;
1796
1797 end = strchr(dev_name, ':');
1798 if (end == NULL)
1799 goto out_bad_devname;
1800 len = end - dev_name;
1801
1802 /* kill possible hostname list: not supported */
1803 comma = strchr(dev_name, ',');
1804 if (comma != NULL && comma < end)
1805 *comma = 0;
1806 }
1807
Chuck Leverdc045892008-06-23 12:36:37 -04001808 if (len > maxnamlen)
1809 goto out_hostname;
1810
1811 /* N.B. caller will free nfs_server.hostname in all cases */
1812 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
Rob Landleyc12bace2011-03-09 15:54:13 -06001813 if (*hostname == NULL)
Chuck Leverdc045892008-06-23 12:36:37 -04001814 goto out_nomem;
Rob Landleyc12bace2011-03-09 15:54:13 -06001815 len = strlen(++end);
Chuck Leverdc045892008-06-23 12:36:37 -04001816 if (len > maxpathlen)
1817 goto out_path;
Rob Landleyc12bace2011-03-09 15:54:13 -06001818 *export_path = kstrndup(end, len, GFP_KERNEL);
Chuck Leverdc045892008-06-23 12:36:37 -04001819 if (!*export_path)
1820 goto out_nomem;
1821
1822 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1823 return 0;
1824
1825out_bad_devname:
1826 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1827 return -EINVAL;
1828
1829out_nomem:
1830 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1831 return -ENOMEM;
1832
1833out_hostname:
1834 dfprintk(MOUNT, "NFS: server hostname too long\n");
1835 return -ENAMETOOLONG;
1836
1837out_path:
1838 dfprintk(MOUNT, "NFS: export pathname too long\n");
1839 return -ENAMETOOLONG;
1840}
1841
1842/*
David Howells54ceac42006-08-22 20:06:13 -04001843 * Validate the NFS2/NFS3 mount data
1844 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001845 *
1846 * For option strings, user space handles the following behaviors:
1847 *
1848 * + DNS: mapping server host name to IP address ("addr=" option)
1849 *
1850 * + failure mode: how to behave if a mount request can't be handled
1851 * immediately ("fg/bg" option)
1852 *
1853 * + retry: how often to retry a mount request ("retry=" option)
1854 *
1855 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1856 * mountproto=tcp after mountproto=udp, and so on
David Howellsf7b422b2006-06-09 09:34:33 -04001857 */
Bryan Schumakerd72c7272012-05-10 15:07:41 -04001858static int nfs23_validate_mount_data(void *options,
1859 struct nfs_parsed_mount_data *args,
1860 struct nfs_fh *mntfh,
1861 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001862{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001863 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001864 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
Chuck Lever136d5582007-07-01 12:13:54 -04001865
Chuck Lever5df36e72007-07-01 12:12:56 -04001866 if (data == NULL)
1867 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001868
Bryan Schumakerc5afc8d2012-06-08 11:32:56 -04001869 args->version = NFS_DEFAULT_VERSION;
David Howellsf7b422b2006-06-09 09:34:33 -04001870 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001871 case 1:
1872 data->namlen = 0;
1873 case 2:
1874 data->bsize = 0;
1875 case 3:
1876 if (data->flags & NFS_MOUNT_VER3)
1877 goto out_no_v3;
1878 data->root.size = NFS2_FHSIZE;
1879 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1880 case 4:
1881 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1882 goto out_no_sec;
1883 case 5:
1884 memset(data->context, 0, sizeof(data->context));
1885 case 6:
Trond Myklebustb7e24452008-06-19 15:21:11 -04001886 if (data->flags & NFS_MOUNT_VER3) {
1887 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1888 goto out_invalid_fh;
Chuck Lever5df36e72007-07-01 12:12:56 -04001889 mntfh->size = data->root.size;
Chuck Lever764302c2009-09-08 19:50:03 -04001890 args->version = 3;
1891 } else {
Chuck Lever5df36e72007-07-01 12:12:56 -04001892 mntfh->size = NFS2_FHSIZE;
Chuck Lever764302c2009-09-08 19:50:03 -04001893 args->version = 2;
1894 }
Chuck Lever5df36e72007-07-01 12:12:56 -04001895
Chuck Lever5df36e72007-07-01 12:12:56 -04001896
1897 memcpy(mntfh->data, data->root.data, mntfh->size);
1898 if (mntfh->size < sizeof(mntfh->data))
1899 memset(mntfh->data + mntfh->size, 0,
1900 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001901
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001902 /*
1903 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1904 * can deal with.
1905 */
Trond Myklebustff3525a2008-08-15 16:59:14 -04001906 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
Bryan Schumakerd5eff1a2010-08-03 13:04:00 -04001907 args->flags |= NFS_MOUNT_LEGACY_INTERFACE;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001908 args->rsize = data->rsize;
1909 args->wsize = data->wsize;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001910 args->timeo = data->timeo;
1911 args->retrans = data->retrans;
1912 args->acregmin = data->acregmin;
1913 args->acregmax = data->acregmax;
1914 args->acdirmin = data->acdirmin;
1915 args->acdirmax = data->acdirmax;
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04001916 args->need_mount = false;
Chuck Lever4c568012007-12-10 14:59:28 -05001917
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001918 memcpy(sap, &data->addr, sizeof(data->addr));
Chuck Lever4c568012007-12-10 14:59:28 -05001919 args->nfs_server.addrlen = sizeof(data->addr);
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001920 if (!nfs_verify_server_address(sap))
Chuck Lever4c568012007-12-10 14:59:28 -05001921 goto out_no_address;
1922
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001923 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001924 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001925 /* N.B. caller will free nfs_server.hostname in all cases */
1926 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1927 args->namlen = data->namlen;
1928 args->bsize = data->bsize;
Chuck Leverdd07c942008-06-24 16:33:46 -04001929
1930 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1931 args->auth_flavors[0] = data->pseudoflavor;
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001932 if (!args->nfs_server.hostname)
1933 goto out_nomem;
Eric Parisf9c3a382008-03-05 14:20:18 -05001934
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001935 if (!(data->flags & NFS_MOUNT_NONLM))
1936 args->flags &= ~(NFS_MOUNT_LOCAL_FLOCK|
1937 NFS_MOUNT_LOCAL_FCNTL);
1938 else
1939 args->flags |= (NFS_MOUNT_LOCAL_FLOCK|
1940 NFS_MOUNT_LOCAL_FCNTL);
Eric Parisf9c3a382008-03-05 14:20:18 -05001941 /*
1942 * The legacy version 6 binary mount data from userspace has a
1943 * field used only to transport selinux information into the
1944 * the kernel. To continue to support that functionality we
1945 * have a touch of selinux knowledge here in the NFS code. The
1946 * userspace code converted context=blah to just blah so we are
1947 * converting back to the full string selinux understands.
1948 */
1949 if (data->context[0]){
1950#ifdef CONFIG_SECURITY_SELINUX
1951 int rc;
1952 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1953 if (!opts_str)
1954 return -ENOMEM;
1955 strcpy(opts_str, "context=");
1956 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1957 strcat(opts_str, &data->context[0]);
1958 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1959 kfree(opts_str);
1960 if (rc)
1961 return rc;
1962#else
1963 return -EINVAL;
1964#endif
1965 }
1966
Chuck Lever5df36e72007-07-01 12:12:56 -04001967 break;
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04001968 default:
1969 return NFS_TEXT_DATA;
David Howellsf7b422b2006-06-09 09:34:33 -04001970 }
David Howells54ceac42006-08-22 20:06:13 -04001971
David Howellsf7b422b2006-06-09 09:34:33 -04001972#ifndef CONFIG_NFS_V3
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001973 if (args->version == 3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001974 goto out_v3_not_compiled;
1975#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001976
David Howells54ceac42006-08-22 20:06:13 -04001977 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001978
1979out_no_data:
1980 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1981 return -EINVAL;
1982
1983out_no_v3:
1984 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1985 data->version);
1986 return -EINVAL;
1987
1988out_no_sec:
1989 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1990 return -EINVAL;
1991
Chuck Lever5df36e72007-07-01 12:12:56 -04001992#ifndef CONFIG_NFS_V3
1993out_v3_not_compiled:
1994 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1995 return -EPROTONOSUPPORT;
1996#endif /* !CONFIG_NFS_V3 */
1997
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001998out_nomem:
1999 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
2000 return -ENOMEM;
2001
Chuck Lever5df36e72007-07-01 12:12:56 -04002002out_no_address:
2003 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
2004 return -EINVAL;
2005
2006out_invalid_fh:
2007 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
2008 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04002009}
2010
Bryan Schumakerd72c7272012-05-10 15:07:41 -04002011#ifdef CONFIG_NFS_V4
2012static int nfs_validate_mount_data(struct file_system_type *fs_type,
2013 void *options,
2014 struct nfs_parsed_mount_data *args,
2015 struct nfs_fh *mntfh,
2016 const char *dev_name)
2017{
2018 if (fs_type == &nfs_fs_type)
2019 return nfs23_validate_mount_data(options, args, mntfh, dev_name);
2020 return nfs4_validate_mount_data(options, args, dev_name);
2021}
2022#else
2023static int nfs_validate_mount_data(struct file_system_type *fs_type,
2024 void *options,
2025 struct nfs_parsed_mount_data *args,
2026 struct nfs_fh *mntfh,
2027 const char *dev_name)
2028{
2029 return nfs23_validate_mount_data(options, args, mntfh, dev_name);
2030}
2031#endif
2032
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04002033static int nfs_validate_text_mount_data(void *options,
2034 struct nfs_parsed_mount_data *args,
2035 const char *dev_name)
2036{
2037 int port = 0;
2038 int max_namelen = PAGE_SIZE;
2039 int max_pathlen = NFS_MAXPATHLEN;
2040 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2041
2042 if (nfs_parse_mount_options((char *)options, args) == 0)
2043 return -EINVAL;
2044
2045 if (!nfs_verify_server_address(sap))
2046 goto out_no_address;
2047
2048 if (args->version == 4) {
2049#ifdef CONFIG_NFS_V4
2050 port = NFS_PORT;
2051 max_namelen = NFS4_MAXNAMLEN;
2052 max_pathlen = NFS4_MAXPATHLEN;
2053 nfs_validate_transport_protocol(args);
2054 nfs4_validate_mount_flags(args);
2055#else
2056 goto out_v4_not_compiled;
2057#endif /* CONFIG_NFS_V4 */
2058 } else
2059 nfs_set_mount_transport_protocol(args);
2060
2061 nfs_set_port(sap, &args->nfs_server.port, port);
2062
2063 if (args->auth_flavor_len > 1)
2064 goto out_bad_auth;
2065
2066 return nfs_parse_devname(dev_name,
2067 &args->nfs_server.hostname,
2068 max_namelen,
2069 &args->nfs_server.export_path,
2070 max_pathlen);
2071
2072#ifndef CONFIG_NFS_V4
2073out_v4_not_compiled:
2074 dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n");
2075 return -EPROTONOSUPPORT;
2076#endif /* !CONFIG_NFS_V4 */
2077
2078out_no_address:
2079 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
2080 return -EINVAL;
2081
2082out_bad_auth:
2083 dfprintk(MOUNT, "NFS: Too many RPC auth flavours specified\n");
2084 return -EINVAL;
2085}
2086
Jeff Layton48b605f2008-06-10 15:38:39 -04002087static int
2088nfs_compare_remount_data(struct nfs_server *nfss,
2089 struct nfs_parsed_mount_data *data)
2090{
2091 if (data->flags != nfss->flags ||
2092 data->rsize != nfss->rsize ||
2093 data->wsize != nfss->wsize ||
2094 data->retrans != nfss->client->cl_timeout->to_retries ||
2095 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
2096 data->acregmin != nfss->acregmin / HZ ||
2097 data->acregmax != nfss->acregmax / HZ ||
2098 data->acdirmin != nfss->acdirmin / HZ ||
2099 data->acdirmax != nfss->acdirmax / HZ ||
2100 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
Trond Myklebustbcd2ea12009-10-06 15:41:22 -04002101 data->nfs_server.port != nfss->port ||
Jeff Layton48b605f2008-06-10 15:38:39 -04002102 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
Stefan Richtera1be9ee2009-10-12 11:26:12 -04002103 !rpc_cmp_addr((struct sockaddr *)&data->nfs_server.address,
2104 (struct sockaddr *)&nfss->nfs_client->cl_addr))
Jeff Layton48b605f2008-06-10 15:38:39 -04002105 return -EINVAL;
2106
2107 return 0;
2108}
2109
2110static int
2111nfs_remount(struct super_block *sb, int *flags, char *raw_data)
2112{
2113 int error;
2114 struct nfs_server *nfss = sb->s_fs_info;
2115 struct nfs_parsed_mount_data *data;
2116 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
2117 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
Trond Myklebustcd100722008-06-17 16:12:00 -04002118 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
Jeff Layton48b605f2008-06-10 15:38:39 -04002119
2120 /*
2121 * Userspace mount programs that send binary options generally send
2122 * them populated with default values. We have no way to know which
2123 * ones were explicitly specified. Fall back to legacy behavior and
2124 * just return success.
2125 */
Marc Zyngier31c94462008-07-17 13:21:55 +02002126 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
2127 (nfsvers <= 3 && (!options || (options->version >= 1 &&
2128 options->version <= 6))))
Jeff Layton48b605f2008-06-10 15:38:39 -04002129 return 0;
2130
2131 data = kzalloc(sizeof(*data), GFP_KERNEL);
2132 if (data == NULL)
2133 return -ENOMEM;
2134
2135 /* fill out struct with values from existing mount */
2136 data->flags = nfss->flags;
2137 data->rsize = nfss->rsize;
2138 data->wsize = nfss->wsize;
2139 data->retrans = nfss->client->cl_timeout->to_retries;
2140 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
2141 data->acregmin = nfss->acregmin / HZ;
2142 data->acregmax = nfss->acregmax / HZ;
2143 data->acdirmin = nfss->acdirmin / HZ;
2144 data->acdirmax = nfss->acdirmax / HZ;
2145 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
Trond Myklebustbcd2ea12009-10-06 15:41:22 -04002146 data->nfs_server.port = nfss->port;
Jeff Layton48b605f2008-06-10 15:38:39 -04002147 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
2148 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
2149 data->nfs_server.addrlen);
2150
2151 /* overwrite those values with any that were specified */
2152 error = nfs_parse_mount_options((char *)options, data);
2153 if (error < 0)
2154 goto out;
2155
Jeff Layton26c4c172011-04-27 11:49:09 -04002156 /*
2157 * noac is a special case. It implies -o sync, but that's not
2158 * necessarily reflected in the mtab options. do_remount_sb
2159 * will clear MS_SYNCHRONOUS if -o sync wasn't specified in the
2160 * remount options, so we have to explicitly reset it.
2161 */
2162 if (data->flags & NFS_MOUNT_NOAC)
2163 *flags |= MS_SYNCHRONOUS;
2164
Jeff Layton48b605f2008-06-10 15:38:39 -04002165 /* compare new mount options with old ones */
2166 error = nfs_compare_remount_data(nfss, data);
2167out:
2168 kfree(data);
2169 return error;
2170}
2171
David Howells54ceac42006-08-22 20:06:13 -04002172/*
2173 * Initialise the common bits of the superblock
2174 */
2175static inline void nfs_initialise_sb(struct super_block *sb)
2176{
2177 struct nfs_server *server = NFS_SB(sb);
2178
2179 sb->s_magic = NFS_SUPER_MAGIC;
2180
2181 /* We probably want something more informative here */
2182 snprintf(sb->s_id, sizeof(sb->s_id),
Vivek Trivedi5a7c9ee2012-03-15 23:58:52 +05302183 "%u:%u", MAJOR(sb->s_dev), MINOR(sb->s_dev));
David Howells54ceac42006-08-22 20:06:13 -04002184
2185 if (sb->s_blocksize == 0)
2186 sb->s_blocksize = nfs_block_bits(server->wsize,
2187 &sb->s_blocksize_bits);
2188
Jens Axboe32a88aa2009-09-16 15:02:33 +02002189 sb->s_bdi = &server->backing_dev_info;
2190
David Howells54ceac42006-08-22 20:06:13 -04002191 nfs_super_set_maxbytes(sb, server->maxfilesize);
2192}
2193
2194/*
2195 * Finish setting up an NFS2/3 superblock
2196 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04002197static void nfs_fill_super(struct super_block *sb,
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002198 struct nfs_mount_info *mount_info)
David Howells54ceac42006-08-22 20:06:13 -04002199{
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002200 struct nfs_parsed_mount_data *data = mount_info->parsed;
David Howells54ceac42006-08-22 20:06:13 -04002201 struct nfs_server *server = NFS_SB(sb);
2202
2203 sb->s_blocksize_bits = 0;
2204 sb->s_blocksize = 0;
2205 if (data->bsize)
2206 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
2207
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04002208 if (server->nfs_client->rpc_ops->version == 3) {
David Howells54ceac42006-08-22 20:06:13 -04002209 /* The VFS shouldn't apply the umask to mode bits. We will do
2210 * so ourselves when necessary.
2211 */
2212 sb->s_flags |= MS_POSIXACL;
2213 sb->s_time_gran = 1;
2214 }
2215
2216 sb->s_op = &nfs_sops;
2217 nfs_initialise_sb(sb);
2218}
2219
2220/*
Bryan Schumaker3cadf4b2012-07-16 16:39:19 -04002221 * Finish setting up a cloned NFS2/3/4 superblock
David Howells54ceac42006-08-22 20:06:13 -04002222 */
2223static void nfs_clone_super(struct super_block *sb,
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002224 struct nfs_mount_info *mount_info)
David Howells54ceac42006-08-22 20:06:13 -04002225{
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002226 const struct super_block *old_sb = mount_info->cloned->sb;
David Howells54ceac42006-08-22 20:06:13 -04002227 struct nfs_server *server = NFS_SB(sb);
2228
2229 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2230 sb->s_blocksize = old_sb->s_blocksize;
2231 sb->s_maxbytes = old_sb->s_maxbytes;
Bryan Schumaker3cadf4b2012-07-16 16:39:19 -04002232 sb->s_xattr = old_sb->s_xattr;
2233 sb->s_op = old_sb->s_op;
2234 sb->s_time_gran = 1;
David Howells54ceac42006-08-22 20:06:13 -04002235
Bryan Schumaker3cadf4b2012-07-16 16:39:19 -04002236 if (server->nfs_client->rpc_ops->version != 2) {
David Howells54ceac42006-08-22 20:06:13 -04002237 /* The VFS shouldn't apply the umask to mode bits. We will do
2238 * so ourselves when necessary.
2239 */
2240 sb->s_flags |= MS_POSIXACL;
David Howells54ceac42006-08-22 20:06:13 -04002241 }
2242
David Howells54ceac42006-08-22 20:06:13 -04002243 nfs_initialise_sb(sb);
2244}
2245
Trond Myklebust275a5d22007-05-16 16:53:28 -04002246static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
2247{
2248 const struct nfs_server *a = s->s_fs_info;
2249 const struct rpc_clnt *clnt_a = a->client;
2250 const struct rpc_clnt *clnt_b = b->client;
2251
2252 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
2253 goto Ebusy;
2254 if (a->nfs_client != b->nfs_client)
2255 goto Ebusy;
2256 if (a->flags != b->flags)
2257 goto Ebusy;
2258 if (a->wsize != b->wsize)
2259 goto Ebusy;
2260 if (a->rsize != b->rsize)
2261 goto Ebusy;
2262 if (a->acregmin != b->acregmin)
2263 goto Ebusy;
2264 if (a->acregmax != b->acregmax)
2265 goto Ebusy;
2266 if (a->acdirmin != b->acdirmin)
2267 goto Ebusy;
2268 if (a->acdirmax != b->acdirmax)
2269 goto Ebusy;
2270 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
2271 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002272 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04002273Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002274 return 0;
2275}
2276
2277struct nfs_sb_mountdata {
2278 struct nfs_server *server;
2279 int mntflags;
2280};
2281
2282static int nfs_set_super(struct super_block *s, void *data)
2283{
2284 struct nfs_sb_mountdata *sb_mntdata = data;
2285 struct nfs_server *server = sb_mntdata->server;
2286 int ret;
2287
2288 s->s_flags = sb_mntdata->mntflags;
2289 s->s_fs_info = server;
Al Viro8b244ff2010-12-18 11:29:39 -05002290 s->s_d_op = server->nfs_client->rpc_ops->dentry_ops;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002291 ret = set_anon_super(s, server);
2292 if (ret == 0)
2293 server->s_dev = s->s_dev;
2294 return ret;
2295}
2296
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002297static int nfs_compare_super_address(struct nfs_server *server1,
2298 struct nfs_server *server2)
2299{
2300 struct sockaddr *sap1, *sap2;
2301
2302 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
2303 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
2304
2305 if (sap1->sa_family != sap2->sa_family)
2306 return 0;
2307
2308 switch (sap1->sa_family) {
2309 case AF_INET: {
2310 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
2311 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
2312 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
2313 return 0;
2314 if (sin1->sin_port != sin2->sin_port)
2315 return 0;
2316 break;
2317 }
2318 case AF_INET6: {
2319 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
2320 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
2321 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
2322 return 0;
2323 if (sin1->sin6_port != sin2->sin6_port)
2324 return 0;
2325 break;
2326 }
2327 default:
2328 return 0;
2329 }
2330
2331 return 1;
2332}
2333
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002334static int nfs_compare_super(struct super_block *sb, void *data)
2335{
2336 struct nfs_sb_mountdata *sb_mntdata = data;
2337 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2338 int mntflags = sb_mntdata->mntflags;
2339
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002340 if (!nfs_compare_super_address(old, server))
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002341 return 0;
2342 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2343 if (old->flags & NFS_MOUNT_UNSHARED)
2344 return 0;
2345 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2346 return 0;
2347 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04002348}
2349
Trond Myklebust39ffb922012-05-16 10:21:30 -07002350#ifdef CONFIG_NFS_FSCACHE
Bryan Schumaker2311b942012-05-10 15:07:32 -04002351static void nfs_get_cache_cookie(struct super_block *sb,
2352 struct nfs_parsed_mount_data *parsed,
2353 struct nfs_clone_mount *cloned)
2354{
2355 char *uniq = NULL;
2356 int ulen = 0;
2357
2358 if (parsed && parsed->fscache_uniq) {
2359 uniq = parsed->fscache_uniq;
2360 ulen = strlen(parsed->fscache_uniq);
2361 } else if (cloned) {
2362 struct nfs_server *mnt_s = NFS_SB(cloned->sb);
2363 if (mnt_s->fscache_key) {
2364 uniq = mnt_s->fscache_key->key.uniquifier;
2365 ulen = mnt_s->fscache_key->key.uniq_len;
2366 };
2367 }
2368
2369 nfs_fscache_get_super_cookie(sb, uniq, ulen);
2370}
Trond Myklebust39ffb922012-05-16 10:21:30 -07002371#else
2372static void nfs_get_cache_cookie(struct super_block *sb,
2373 struct nfs_parsed_mount_data *parsed,
2374 struct nfs_clone_mount *cloned)
2375{
2376}
2377#endif
Bryan Schumaker2311b942012-05-10 15:07:32 -04002378
Miklos Szeredifa799752008-04-30 00:54:33 -07002379static int nfs_bdi_register(struct nfs_server *server)
2380{
2381 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
2382}
2383
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002384static int nfs_set_sb_security(struct super_block *s, struct dentry *mntroot,
2385 struct nfs_mount_info *mount_info)
2386{
2387 return security_sb_set_mnt_opts(s, &mount_info->parsed->lsm_opts);
2388}
2389
2390static int nfs_clone_sb_security(struct super_block *s, struct dentry *mntroot,
2391 struct nfs_mount_info *mount_info)
2392{
2393 /* clone any lsm security options from the parent to the new sb */
2394 security_sb_clone_mnt_opts(mount_info->cloned->sb, s);
2395 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops)
2396 return -ESTALE;
2397 return 0;
2398}
2399
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002400static struct dentry *nfs_fs_mount_common(struct file_system_type *fs_type,
2401 struct nfs_server *server,
2402 int flags, const char *dev_name,
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002403 struct nfs_mount_info *mount_info)
David Howells54ceac42006-08-22 20:06:13 -04002404{
David Howells54ceac42006-08-22 20:06:13 -04002405 struct super_block *s;
Al Viro01194982011-03-16 07:25:36 -04002406 struct dentry *mntroot = ERR_PTR(-ENOMEM);
Trond Myklebust75180df2007-05-16 16:53:28 -04002407 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002408 struct nfs_sb_mountdata sb_mntdata = {
2409 .mntflags = flags,
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002410 .server = server,
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002411 };
Al Viro01194982011-03-16 07:25:36 -04002412 int error;
David Howells54ceac42006-08-22 20:06:13 -04002413
Trond Myklebust75180df2007-05-16 16:53:28 -04002414 if (server->flags & NFS_MOUNT_UNSHARED)
2415 compare_super = NULL;
2416
Sachin Prabhufb2088c2011-08-01 12:10:12 +01002417 /* -o noac implies -o sync */
2418 if (server->flags & NFS_MOUNT_NOAC)
2419 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2420
David Howells54ceac42006-08-22 20:06:13 -04002421 /* Get a superblock - note that we may end up sharing one that already exists */
David Howells9249e172012-06-25 12:55:37 +01002422 s = sget(fs_type, compare_super, nfs_set_super, flags, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002423 if (IS_ERR(s)) {
Al Viro01194982011-03-16 07:25:36 -04002424 mntroot = ERR_CAST(s);
David Howells54ceac42006-08-22 20:06:13 -04002425 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04002426 }
2427
David Howells54ceac42006-08-22 20:06:13 -04002428 if (s->s_fs_info != server) {
2429 nfs_free_server(server);
2430 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002431 } else {
2432 error = nfs_bdi_register(server);
Al Viro01194982011-03-16 07:25:36 -04002433 if (error) {
2434 mntroot = ERR_PTR(error);
NeilBrowncfbc0682010-03-11 11:20:17 +11002435 goto error_splat_bdi;
Al Viro01194982011-03-16 07:25:36 -04002436 }
David Howellsf7b422b2006-06-09 09:34:33 -04002437 }
David Howells54ceac42006-08-22 20:06:13 -04002438
2439 if (!s->s_root) {
2440 /* initial superblock/root creation */
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002441 mount_info->fill_super(s, mount_info);
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002442 nfs_get_cache_cookie(s, mount_info->parsed, mount_info->cloned);
David Howells54ceac42006-08-22 20:06:13 -04002443 }
2444
Bryan Schumaker87c70832012-05-10 15:07:43 -04002445 mntroot = nfs_get_root(s, mount_info->mntfh, dev_name);
Al Viro01194982011-03-16 07:25:36 -04002446 if (IS_ERR(mntroot))
David Howells54ceac42006-08-22 20:06:13 -04002447 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002448
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002449 error = mount_info->set_security(s, mntroot, mount_info);
Eric Parisf9c3a382008-03-05 14:20:18 -05002450 if (error)
2451 goto error_splat_root;
2452
David Howellsf7b422b2006-06-09 09:34:33 -04002453 s->s_flags |= MS_ACTIVE;
Chuck Lever06559602007-07-01 12:12:35 -04002454
2455out:
Al Viro01194982011-03-16 07:25:36 -04002456 return mntroot;
Trond Myklebust816724e2006-06-24 08:41:41 -04002457
David Howells54ceac42006-08-22 20:06:13 -04002458out_err_nosb:
2459 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04002460 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002461
Eric Parisf9c3a382008-03-05 14:20:18 -05002462error_splat_root:
2463 dput(mntroot);
Al Viro01194982011-03-16 07:25:36 -04002464 mntroot = ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04002465error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002466 if (server && !s->s_root)
2467 bdi_unregister(&server->backing_dev_info);
2468error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002469 deactivate_locked_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04002470 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002471}
2472
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002473static struct dentry *nfs_fs_mount(struct file_system_type *fs_type,
2474 int flags, const char *dev_name, void *raw_data)
2475{
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002476 struct nfs_mount_info mount_info = {
2477 .fill_super = nfs_fill_super,
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002478 .set_security = nfs_set_sb_security,
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002479 };
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002480 struct dentry *mntroot = ERR_PTR(-ENOMEM);
2481 int error;
2482
Bryan Schumaker46058d42012-05-10 15:07:42 -04002483 mount_info.parsed = nfs_alloc_parsed_mount_data();
Bryan Schumaker87c70832012-05-10 15:07:43 -04002484 mount_info.mntfh = nfs_alloc_fhandle();
2485 if (mount_info.parsed == NULL || mount_info.mntfh == NULL)
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002486 goto out;
2487
2488 /* Validate the mount data */
Bryan Schumaker87c70832012-05-10 15:07:43 -04002489 error = nfs_validate_mount_data(fs_type, raw_data, mount_info.parsed, mount_info.mntfh, dev_name);
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04002490 if (error == NFS_TEXT_DATA)
Bryan Schumaker46058d42012-05-10 15:07:42 -04002491 error = nfs_validate_text_mount_data(raw_data, mount_info.parsed, dev_name);
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002492 if (error < 0) {
2493 mntroot = ERR_PTR(error);
2494 goto out;
2495 }
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002496
2497#ifdef CONFIG_NFS_V4
Bryan Schumaker46058d42012-05-10 15:07:42 -04002498 if (mount_info.parsed->version == 4)
Bryan Schumaker87c70832012-05-10 15:07:43 -04002499 mntroot = nfs4_try_mount(flags, dev_name, &mount_info);
Bryan Schumaker486aa692012-05-10 15:07:39 -04002500 else
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002501#endif /* CONFIG_NFS_V4 */
Bryan Schumaker87c70832012-05-10 15:07:43 -04002502 mntroot = nfs_try_mount(flags, dev_name, &mount_info);
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002503
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002504out:
Bryan Schumaker46058d42012-05-10 15:07:42 -04002505 nfs_free_parsed_mount_data(mount_info.parsed);
Bryan Schumaker87c70832012-05-10 15:07:43 -04002506 nfs_free_fhandle(mount_info.mntfh);
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002507 return mntroot;
2508}
2509
David Howells54ceac42006-08-22 20:06:13 -04002510/*
Trond Myklebust387c1492010-02-03 08:27:35 -05002511 * Ensure that we unregister the bdi before kill_anon_super
2512 * releases the device name
2513 */
2514static void nfs_put_super(struct super_block *s)
2515{
2516 struct nfs_server *server = NFS_SB(s);
2517
2518 bdi_unregister(&server->backing_dev_info);
2519}
2520
2521/*
David Howells54ceac42006-08-22 20:06:13 -04002522 * Destroy an NFS2/3 superblock
2523 */
David Howellsf7b422b2006-06-09 09:34:33 -04002524static void nfs_kill_super(struct super_block *s)
2525{
2526 struct nfs_server *server = NFS_SB(s);
2527
2528 kill_anon_super(s);
David Howells08734042009-04-03 16:42:42 +01002529 nfs_fscache_release_super_cookie(s);
David Howells54ceac42006-08-22 20:06:13 -04002530 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04002531}
2532
David Howells54ceac42006-08-22 20:06:13 -04002533/*
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002534 * Clone an NFS2/3/4 server record on xdev traversal (FSID-change)
David Howells54ceac42006-08-22 20:06:13 -04002535 */
Al Viro31f43472010-10-29 03:38:12 -04002536static struct dentry *
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002537nfs_xdev_mount_common(struct file_system_type *fs_type, int flags,
2538 const char *dev_name, struct nfs_mount_info *mount_info)
David Howellsf7b422b2006-06-09 09:34:33 -04002539{
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002540 struct nfs_clone_mount *data = mount_info->cloned;
David Howells54ceac42006-08-22 20:06:13 -04002541 struct nfs_server *server;
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002542 struct dentry *mntroot = ERR_PTR(-ENOMEM);
David Howells54ceac42006-08-22 20:06:13 -04002543 int error;
2544
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002545 dprintk("--> nfs_xdev_mount_common()\n");
David Howells54ceac42006-08-22 20:06:13 -04002546
Bryan Schumaker87c70832012-05-10 15:07:43 -04002547 mount_info->mntfh = data->fh;
2548
David Howells54ceac42006-08-22 20:06:13 -04002549 /* create a new volume representation */
Bryan Schumaker7e6eb682012-04-27 13:27:42 -04002550 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr, data->authflavor);
David Howells54ceac42006-08-22 20:06:13 -04002551 if (IS_ERR(server)) {
2552 error = PTR_ERR(server);
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002553 goto out_err;
David Howells54ceac42006-08-22 20:06:13 -04002554 }
2555
Bryan Schumaker87c70832012-05-10 15:07:43 -04002556 mntroot = nfs_fs_mount_common(fs_type, server, flags, dev_name, mount_info);
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002557 dprintk("<-- nfs_xdev_mount_common() = 0\n");
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002558out:
Al Viro31f43472010-10-29 03:38:12 -04002559 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04002560
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002561out_err:
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002562 dprintk("<-- nfs_xdev_mount_common() = %d [error]\n", error);
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002563 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002564}
2565
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002566/*
2567 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2568 */
2569static struct dentry *
2570nfs_xdev_mount(struct file_system_type *fs_type, int flags,
2571 const char *dev_name, void *raw_data)
2572{
2573 struct nfs_mount_info mount_info = {
2574 .fill_super = nfs_clone_super,
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002575 .set_security = nfs_clone_sb_security,
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002576 .cloned = raw_data,
2577 };
2578 return nfs_xdev_mount_common(&nfs_fs_type, flags, dev_name, &mount_info);
2579}
2580
David Howellsf7b422b2006-06-09 09:34:33 -04002581#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04002582
2583/*
David Howellsf7b422b2006-06-09 09:34:33 -04002584 * Set up an NFS4 superblock
2585 */
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002586static void nfs4_fill_super(struct super_block *sb,
2587 struct nfs_mount_info *mount_info)
David Howellsf7b422b2006-06-09 09:34:33 -04002588{
David Howellsf7b422b2006-06-09 09:34:33 -04002589 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04002590 sb->s_op = &nfs4_sops;
Aneesh Kumar K.Va8a5da92010-12-09 11:35:14 +00002591 /*
2592 * The VFS shouldn't apply the umask to mode bits. We will do
2593 * so ourselves when necessary.
2594 */
2595 sb->s_flags |= MS_POSIXACL;
Aneesh Kumar K.V64c2ce82010-12-09 11:35:25 +00002596 sb->s_xattr = nfs4_xattr_handlers;
David Howells54ceac42006-08-22 20:06:13 -04002597 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002598}
2599
Trond Myklebust01c3f052009-06-17 13:22:58 -07002600static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2601{
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04002602 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3|
2603 NFS_MOUNT_LOCAL_FLOCK|NFS_MOUNT_LOCAL_FCNTL);
Trond Myklebust01c3f052009-06-17 13:22:58 -07002604}
2605
David Howells54ceac42006-08-22 20:06:13 -04002606/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04002607 * Validate NFSv4 mount options
2608 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002609static int nfs4_validate_mount_data(void *options,
2610 struct nfs_parsed_mount_data *args,
2611 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04002612{
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002613 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002614 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002615 char *c;
2616
2617 if (data == NULL)
2618 goto out_no_data;
2619
Bryan Schumakercdf66442012-06-05 14:59:54 -04002620 args->version = 4;
2621
Chuck Leverf0768eb2007-07-01 12:13:01 -04002622 switch (data->version) {
2623 case 1:
Chuck Lever4c568012007-12-10 14:59:28 -05002624 if (data->host_addrlen > sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002625 goto out_no_address;
Chuck Lever4c568012007-12-10 14:59:28 -05002626 if (data->host_addrlen == 0)
2627 goto out_no_address;
2628 args->nfs_server.addrlen = data->host_addrlen;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002629 if (copy_from_user(sap, data->host_addr, data->host_addrlen))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002630 return -EFAULT;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002631 if (!nfs_verify_server_address(sap))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002632 goto out_no_address;
2633
Chuck Lever6738b252008-06-24 16:33:54 -04002634 if (data->auth_flavourlen) {
2635 if (data->auth_flavourlen > 1)
2636 goto out_inval_auth;
Trond Myklebust20c71f52007-09-20 20:23:51 -04002637 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002638 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04002639 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002640 return -EFAULT;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002641 }
2642
2643 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2644 if (IS_ERR(c))
2645 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002646 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002647
2648 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2649 if (IS_ERR(c))
2650 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002651 args->nfs_server.export_path = c;
2652 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002653
2654 c = strndup_user(data->client_addr.data, 16);
2655 if (IS_ERR(c))
2656 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002657 args->client_address = c;
2658
2659 /*
2660 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2661 * can deal with.
2662 */
2663
2664 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2665 args->rsize = data->rsize;
2666 args->wsize = data->wsize;
2667 args->timeo = data->timeo;
2668 args->retrans = data->retrans;
2669 args->acregmin = data->acregmin;
2670 args->acregmax = data->acregmax;
2671 args->acdirmin = data->acdirmin;
2672 args->acdirmax = data->acdirmax;
2673 args->nfs_server.protocol = data->proto;
Trond Myklebust259875e2008-07-02 14:43:47 -04002674 nfs_validate_transport_protocol(args);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002675
2676 break;
Chuck Lever7630c852009-09-08 19:49:57 -04002677 default:
Bryan Schumakerb72e4f42012-05-10 15:07:40 -04002678 return NFS_TEXT_DATA;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002679 }
2680
2681 return 0;
2682
2683out_no_data:
2684 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2685 return -EINVAL;
2686
2687out_inval_auth:
2688 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2689 data->auth_flavourlen);
2690 return -EINVAL;
2691
2692out_no_address:
2693 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2694 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002695}
2696
2697/*
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002698 * Get the superblock for the NFS4 root partition
David Howells54ceac42006-08-22 20:06:13 -04002699 */
Al Viro31f43472010-10-29 03:38:12 -04002700static struct dentry *
2701nfs4_remote_mount(struct file_system_type *fs_type, int flags,
Bryan Schumaker87c70832012-05-10 15:07:43 -04002702 const char *dev_name, void *info)
David Howellsf7b422b2006-06-09 09:34:33 -04002703{
Bryan Schumaker87c70832012-05-10 15:07:43 -04002704 struct nfs_mount_info *mount_info = info;
David Howells54ceac42006-08-22 20:06:13 -04002705 struct nfs_server *server;
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002706 struct dentry *mntroot = ERR_PTR(-ENOMEM);
David Howellsf7b422b2006-06-09 09:34:33 -04002707
Bryan Schumaker87c70832012-05-10 15:07:43 -04002708 mount_info->fill_super = nfs4_fill_super;
2709 mount_info->set_security = nfs_set_sb_security;
Eric Parisf9c3a382008-03-05 14:20:18 -05002710
David Howells54ceac42006-08-22 20:06:13 -04002711 /* Get a volume representation */
Bryan Schumaker87c70832012-05-10 15:07:43 -04002712 server = nfs4_create_server(mount_info->parsed, mount_info->mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002713 if (IS_ERR(server)) {
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002714 mntroot = ERR_CAST(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04002715 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002716 }
2717
Bryan Schumaker87c70832012-05-10 15:07:43 -04002718 mntroot = nfs_fs_mount_common(fs_type, server, flags, dev_name, mount_info);
David Howells54ceac42006-08-22 20:06:13 -04002719
Chuck Lever29eb9812007-07-01 12:12:30 -04002720out:
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002721 return mntroot;
David Howellsf7b422b2006-06-09 09:34:33 -04002722}
2723
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002724static struct vfsmount *nfs_do_root_mount(struct file_system_type *fs_type,
2725 int flags, void *data, const char *hostname)
2726{
2727 struct vfsmount *root_mnt;
2728 char *root_devname;
2729 size_t len;
2730
Jan Kara98a21392011-09-03 01:09:43 +02002731 len = strlen(hostname) + 5;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002732 root_devname = kmalloc(len, GFP_KERNEL);
2733 if (root_devname == NULL)
2734 return ERR_PTR(-ENOMEM);
Jan Kara98a21392011-09-03 01:09:43 +02002735 /* Does hostname needs to be enclosed in brackets? */
2736 if (strchr(hostname, ':'))
2737 snprintf(root_devname, len, "[%s]:/", hostname);
2738 else
2739 snprintf(root_devname, len, "%s:/", hostname);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002740 root_mnt = vfs_kern_mount(fs_type, flags, root_devname, data);
2741 kfree(root_devname);
2742 return root_mnt;
2743}
2744
Trond Myklebustce587e02010-04-16 16:22:52 -04002745struct nfs_referral_count {
2746 struct list_head list;
2747 const struct task_struct *task;
2748 unsigned int referral_count;
2749};
2750
2751static LIST_HEAD(nfs_referral_count_list);
2752static DEFINE_SPINLOCK(nfs_referral_count_list_lock);
2753
2754static struct nfs_referral_count *nfs_find_referral_count(void)
2755{
2756 struct nfs_referral_count *p;
2757
2758 list_for_each_entry(p, &nfs_referral_count_list, list) {
2759 if (p->task == current)
2760 return p;
2761 }
2762 return NULL;
2763}
2764
2765#define NFS_MAX_NESTED_REFERRALS 2
2766
2767static int nfs_referral_loop_protect(void)
2768{
2769 struct nfs_referral_count *p, *new;
2770 int ret = -ENOMEM;
2771
2772 new = kmalloc(sizeof(*new), GFP_KERNEL);
2773 if (!new)
2774 goto out;
2775 new->task = current;
2776 new->referral_count = 1;
2777
2778 ret = 0;
2779 spin_lock(&nfs_referral_count_list_lock);
2780 p = nfs_find_referral_count();
2781 if (p != NULL) {
2782 if (p->referral_count >= NFS_MAX_NESTED_REFERRALS)
2783 ret = -ELOOP;
2784 else
2785 p->referral_count++;
2786 } else {
2787 list_add(&new->list, &nfs_referral_count_list);
2788 new = NULL;
2789 }
2790 spin_unlock(&nfs_referral_count_list_lock);
2791 kfree(new);
2792out:
2793 return ret;
2794}
2795
2796static void nfs_referral_loop_unprotect(void)
2797{
2798 struct nfs_referral_count *p;
2799
2800 spin_lock(&nfs_referral_count_list_lock);
2801 p = nfs_find_referral_count();
2802 p->referral_count--;
2803 if (p->referral_count == 0)
2804 list_del(&p->list);
2805 else
2806 p = NULL;
2807 spin_unlock(&nfs_referral_count_list_lock);
2808 kfree(p);
2809}
2810
Al Viro01194982011-03-16 07:25:36 -04002811static struct dentry *nfs_follow_remote_path(struct vfsmount *root_mnt,
2812 const char *export_path)
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002813{
Al Viro01194982011-03-16 07:25:36 -04002814 struct dentry *dentry;
Al Viro5352d3b2011-11-16 21:52:06 -05002815 int err;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002816
Al Viro5352d3b2011-11-16 21:52:06 -05002817 if (IS_ERR(root_mnt))
2818 return ERR_CAST(root_mnt);
2819
2820 err = nfs_referral_loop_protect();
2821 if (err) {
Al Viroea441d12011-11-16 21:43:59 -05002822 mntput(root_mnt);
Al Viro5352d3b2011-11-16 21:52:06 -05002823 return ERR_PTR(err);
Al Viroc1334492011-11-16 16:12:14 -05002824 }
Trond Myklebustce587e02010-04-16 16:22:52 -04002825
Al Viroea441d12011-11-16 21:43:59 -05002826 dentry = mount_subtree(root_mnt, export_path);
2827 nfs_referral_loop_unprotect();
Linus Torvaldsa2770d82009-12-17 12:51:05 -08002828
Al Viro01194982011-03-16 07:25:36 -04002829 return dentry;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002830}
2831
Al Viro01194982011-03-16 07:25:36 -04002832static struct dentry *nfs4_try_mount(int flags, const char *dev_name,
Bryan Schumaker87c70832012-05-10 15:07:43 -04002833 struct nfs_mount_info *mount_info)
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002834{
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002835 char *export_path;
2836 struct vfsmount *root_mnt;
Al Viro01194982011-03-16 07:25:36 -04002837 struct dentry *res;
Bryan Schumaker87c70832012-05-10 15:07:43 -04002838 struct nfs_parsed_mount_data *data = mount_info->parsed;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002839
Chuck Levera6fe23b2009-09-08 19:50:00 -04002840 dfprintk(MOUNT, "--> nfs4_try_mount()\n");
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002841
Trond Myklebustf1daf662012-07-10 12:04:15 -04002842 mount_info->fill_super = nfs4_fill_super;
2843
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002844 export_path = data->nfs_server.export_path;
2845 data->nfs_server.export_path = "/";
Bryan Schumaker87c70832012-05-10 15:07:43 -04002846 root_mnt = nfs_do_root_mount(&nfs4_remote_fs_type, flags, mount_info,
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002847 data->nfs_server.hostname);
2848 data->nfs_server.export_path = export_path;
2849
Al Viro5352d3b2011-11-16 21:52:06 -05002850 res = nfs_follow_remote_path(root_mnt, export_path);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002851
Al Viro01194982011-03-16 07:25:36 -04002852 dfprintk(MOUNT, "<-- nfs4_try_mount() = %ld%s\n",
2853 IS_ERR(res) ? PTR_ERR(res) : 0,
2854 IS_ERR(res) ? " [error]" : "");
2855 return res;
Chuck Levera6fe23b2009-09-08 19:50:00 -04002856}
2857
David Howellsf7b422b2006-06-09 09:34:33 -04002858/*
David Howells54ceac42006-08-22 20:06:13 -04002859 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -04002860 */
Al Viro31f43472010-10-29 03:38:12 -04002861static struct dentry *
2862nfs4_xdev_mount(struct file_system_type *fs_type, int flags,
2863 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002864{
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002865 struct nfs_mount_info mount_info = {
Bryan Schumaker3cadf4b2012-07-16 16:39:19 -04002866 .fill_super = nfs_clone_super,
Bryan Schumaker3d176e32012-05-10 15:07:36 -04002867 .set_security = nfs_clone_sb_security,
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002868 .cloned = raw_data,
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002869 };
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002870 return nfs_xdev_mount_common(&nfs4_fs_type, flags, dev_name, &mount_info);
David Howellsf7b422b2006-06-09 09:34:33 -04002871}
2872
Al Viro31f43472010-10-29 03:38:12 -04002873static struct dentry *
2874nfs4_remote_referral_mount(struct file_system_type *fs_type, int flags,
2875 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002876{
Bryan Schumaker21e4b822012-05-10 15:07:37 -04002877 struct nfs_mount_info mount_info = {
2878 .fill_super = nfs4_fill_super,
2879 .set_security = nfs_clone_sb_security,
2880 .cloned = raw_data,
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002881 };
Bryan Schumaker21e4b822012-05-10 15:07:37 -04002882 struct nfs_server *server;
2883 struct dentry *mntroot = ERR_PTR(-ENOMEM);
David Howells54ceac42006-08-22 20:06:13 -04002884
2885 dprintk("--> nfs4_referral_get_sb()\n");
2886
Bryan Schumaker87c70832012-05-10 15:07:43 -04002887 mount_info.mntfh = nfs_alloc_fhandle();
2888 if (mount_info.cloned == NULL || mount_info.mntfh == NULL)
Bryan Schumaker21e4b822012-05-10 15:07:37 -04002889 goto out;
Trond Myklebust4f727292010-04-16 16:22:48 -04002890
David Howells54ceac42006-08-22 20:06:13 -04002891 /* create a new volume representation */
Bryan Schumaker87c70832012-05-10 15:07:43 -04002892 server = nfs4_create_referral_server(mount_info.cloned, mount_info.mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002893 if (IS_ERR(server)) {
Bryan Schumaker21e4b822012-05-10 15:07:37 -04002894 mntroot = ERR_CAST(server);
2895 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002896 }
2897
Bryan Schumaker87c70832012-05-10 15:07:43 -04002898 mntroot = nfs_fs_mount_common(&nfs4_fs_type, server, flags, dev_name, &mount_info);
Bryan Schumaker21e4b822012-05-10 15:07:37 -04002899out:
Bryan Schumaker87c70832012-05-10 15:07:43 -04002900 nfs_free_fhandle(mount_info.mntfh);
Al Viro31f43472010-10-29 03:38:12 -04002901 return mntroot;
David Howellsf7b422b2006-06-09 09:34:33 -04002902}
2903
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002904/*
2905 * Create an NFS4 server record on referral traversal
2906 */
Al Viro01194982011-03-16 07:25:36 -04002907static struct dentry *nfs4_referral_mount(struct file_system_type *fs_type,
2908 int flags, const char *dev_name, void *raw_data)
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002909{
2910 struct nfs_clone_mount *data = raw_data;
2911 char *export_path;
2912 struct vfsmount *root_mnt;
Al Viro01194982011-03-16 07:25:36 -04002913 struct dentry *res;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002914
Al Viro01194982011-03-16 07:25:36 -04002915 dprintk("--> nfs4_referral_mount()\n");
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002916
2917 export_path = data->mnt_path;
2918 data->mnt_path = "/";
2919
2920 root_mnt = nfs_do_root_mount(&nfs4_remote_referral_fs_type,
2921 flags, data, data->hostname);
2922 data->mnt_path = export_path;
2923
Al Viro5352d3b2011-11-16 21:52:06 -05002924 res = nfs_follow_remote_path(root_mnt, export_path);
Al Viro01194982011-03-16 07:25:36 -04002925 dprintk("<-- nfs4_referral_mount() = %ld%s\n",
2926 IS_ERR(res) ? PTR_ERR(res) : 0,
2927 IS_ERR(res) ? " [error]" : "");
2928 return res;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002929}
2930
David Howells54ceac42006-08-22 20:06:13 -04002931#endif /* CONFIG_NFS_V4 */