blob: 707d1f67fb32a28a4093911fbce9c79dd838b63b [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
69
Paulius Zaleckas1e657bd2010-10-31 18:21:05 +020070#ifdef CONFIG_NFS_V3
71#define NFS_DEFAULT_VERSION 3
72#else
73#define NFS_DEFAULT_VERSION 2
74#endif
75
Chuck Leverbf0fd762007-07-01 12:13:44 -040076enum {
77 /* Mount options that take no arguments */
78 Opt_soft, Opt_hard,
Chuck Leverbf0fd762007-07-01 12:13:44 -040079 Opt_posix, Opt_noposix,
80 Opt_cto, Opt_nocto,
81 Opt_ac, Opt_noac,
82 Opt_lock, Opt_nolock,
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -040083 Opt_udp, Opt_tcp, Opt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -040084 Opt_acl, Opt_noacl,
85 Opt_rdirplus, Opt_nordirplus,
Trond Myklebust75180df2007-05-16 16:53:28 -040086 Opt_sharecache, Opt_nosharecache,
Chuck Leverd7403512008-12-23 15:21:37 -050087 Opt_resvport, Opt_noresvport,
David Howellsb797cac2009-04-03 16:42:48 +010088 Opt_fscache, Opt_nofscache,
Chuck Leverbf0fd762007-07-01 12:13:44 -040089
90 /* Mount options that take integer arguments */
91 Opt_port,
92 Opt_rsize, Opt_wsize, Opt_bsize,
93 Opt_timeo, Opt_retrans,
94 Opt_acregmin, Opt_acregmax,
95 Opt_acdirmin, Opt_acdirmax,
96 Opt_actimeo,
97 Opt_namelen,
98 Opt_mountport,
Chuck Levere887cbc2007-10-26 13:32:29 -040099 Opt_mountvers,
Mike Sager3fd5be92009-04-01 09:21:48 -0400100 Opt_minorversion,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400101
102 /* Mount options that take string arguments */
Trond Myklebust0d71b052012-03-02 13:59:49 -0500103 Opt_nfsvers,
Chuck Lever33832032007-12-10 14:59:13 -0500104 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
Chuck Lever0ac83772007-09-11 18:01:04 -0400105 Opt_addr, Opt_mountaddr, Opt_clientaddr,
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400106 Opt_lookupcache,
David Howellsb797cac2009-04-03 16:42:48 +0100107 Opt_fscache_uniq,
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400108 Opt_local_lock,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400109
Chuck Leverf45663c2008-06-24 19:28:02 -0400110 /* Special mount options */
111 Opt_userspace, Opt_deprecated, Opt_sloppy,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400112
113 Opt_err
114};
115
Steven Whitehousea447c092008-10-13 10:46:57 +0100116static const match_table_t nfs_mount_option_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400117 { Opt_userspace, "bg" },
118 { Opt_userspace, "fg" },
Chuck Leverecbb3842008-06-12 12:37:33 -0400119 { Opt_userspace, "retry=%s" },
120
Chuck Leverf45663c2008-06-24 19:28:02 -0400121 { Opt_sloppy, "sloppy" },
122
Chuck Leverbf0fd762007-07-01 12:13:44 -0400123 { Opt_soft, "soft" },
124 { Opt_hard, "hard" },
Chuck Leverd33e4df2008-06-12 12:37:41 -0400125 { Opt_deprecated, "intr" },
126 { Opt_deprecated, "nointr" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400127 { Opt_posix, "posix" },
128 { Opt_noposix, "noposix" },
129 { Opt_cto, "cto" },
130 { Opt_nocto, "nocto" },
131 { Opt_ac, "ac" },
132 { Opt_noac, "noac" },
133 { Opt_lock, "lock" },
134 { Opt_nolock, "nolock" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400135 { Opt_udp, "udp" },
136 { Opt_tcp, "tcp" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400137 { Opt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400138 { Opt_acl, "acl" },
139 { Opt_noacl, "noacl" },
140 { Opt_rdirplus, "rdirplus" },
141 { Opt_nordirplus, "nordirplus" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400142 { Opt_sharecache, "sharecache" },
143 { Opt_nosharecache, "nosharecache" },
Chuck Leverd7403512008-12-23 15:21:37 -0500144 { Opt_resvport, "resvport" },
145 { Opt_noresvport, "noresvport" },
David Howellsb797cac2009-04-03 16:42:48 +0100146 { Opt_fscache, "fsc" },
David Howellsb797cac2009-04-03 16:42:48 +0100147 { Opt_nofscache, "nofsc" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400148
Chuck Levera5a16ba2009-06-17 18:02:14 -0700149 { Opt_port, "port=%s" },
150 { Opt_rsize, "rsize=%s" },
151 { Opt_wsize, "wsize=%s" },
152 { Opt_bsize, "bsize=%s" },
153 { Opt_timeo, "timeo=%s" },
154 { Opt_retrans, "retrans=%s" },
155 { Opt_acregmin, "acregmin=%s" },
156 { Opt_acregmax, "acregmax=%s" },
157 { Opt_acdirmin, "acdirmin=%s" },
158 { Opt_acdirmax, "acdirmax=%s" },
159 { Opt_actimeo, "actimeo=%s" },
160 { Opt_namelen, "namlen=%s" },
161 { Opt_mountport, "mountport=%s" },
162 { Opt_mountvers, "mountvers=%s" },
Trond Myklebust0d71b052012-03-02 13:59:49 -0500163 { Opt_minorversion, "minorversion=%s" },
164
Chuck Levera5a16ba2009-06-17 18:02:14 -0700165 { Opt_nfsvers, "nfsvers=%s" },
166 { Opt_nfsvers, "vers=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400167
168 { Opt_sec, "sec=%s" },
169 { Opt_proto, "proto=%s" },
170 { Opt_mountproto, "mountproto=%s" },
171 { Opt_addr, "addr=%s" },
172 { Opt_clientaddr, "clientaddr=%s" },
Chuck Lever33832032007-12-10 14:59:13 -0500173 { Opt_mounthost, "mounthost=%s" },
Chuck Lever0ac83772007-09-11 18:01:04 -0400174 { Opt_mountaddr, "mountaddr=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400175
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400176 { Opt_lookupcache, "lookupcache=%s" },
Chuck Levera6d5ff62010-05-07 13:33:58 -0400177 { Opt_fscache_uniq, "fsc=%s" },
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400178 { Opt_local_lock, "local_lock=%s" },
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400179
Trond Myklebust38622792012-03-02 14:06:39 -0500180 /* The following needs to be listed after all other options */
181 { Opt_nfsvers, "v%s" },
182
Chuck Leverbf0fd762007-07-01 12:13:44 -0400183 { Opt_err, NULL }
184};
185
186enum {
Jeff Laytonee671b02009-12-03 15:58:56 -0500187 Opt_xprt_udp, Opt_xprt_udp6, Opt_xprt_tcp, Opt_xprt_tcp6, Opt_xprt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400188
189 Opt_xprt_err
190};
191
Steven Whitehousea447c092008-10-13 10:46:57 +0100192static const match_table_t nfs_xprt_protocol_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400193 { Opt_xprt_udp, "udp" },
Jeff Laytonee671b02009-12-03 15:58:56 -0500194 { Opt_xprt_udp6, "udp6" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400195 { Opt_xprt_tcp, "tcp" },
Jeff Laytonee671b02009-12-03 15:58:56 -0500196 { Opt_xprt_tcp6, "tcp6" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400197 { Opt_xprt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400198
199 { Opt_xprt_err, NULL }
200};
201
202enum {
203 Opt_sec_none, Opt_sec_sys,
204 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
205 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
206 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
207
208 Opt_sec_err
209};
210
Steven Whitehousea447c092008-10-13 10:46:57 +0100211static const match_table_t nfs_secflavor_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400212 { Opt_sec_none, "none" },
213 { Opt_sec_none, "null" },
214 { Opt_sec_sys, "sys" },
215
216 { Opt_sec_krb5, "krb5" },
217 { Opt_sec_krb5i, "krb5i" },
218 { Opt_sec_krb5p, "krb5p" },
219
220 { Opt_sec_lkey, "lkey" },
221 { Opt_sec_lkeyi, "lkeyi" },
222 { Opt_sec_lkeyp, "lkeyp" },
223
Olga Kornievskaia8d042212008-02-13 16:47:06 -0500224 { Opt_sec_spkm, "spkm3" },
225 { Opt_sec_spkmi, "spkm3i" },
226 { Opt_sec_spkmp, "spkm3p" },
227
Chuck Leverbf0fd762007-07-01 12:13:44 -0400228 { Opt_sec_err, NULL }
229};
230
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400231enum {
232 Opt_lookupcache_all, Opt_lookupcache_positive,
233 Opt_lookupcache_none,
234
235 Opt_lookupcache_err
236};
237
238static match_table_t nfs_lookupcache_tokens = {
239 { Opt_lookupcache_all, "all" },
240 { Opt_lookupcache_positive, "pos" },
241 { Opt_lookupcache_positive, "positive" },
242 { Opt_lookupcache_none, "none" },
243
244 { Opt_lookupcache_err, NULL }
245};
246
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400247enum {
248 Opt_local_lock_all, Opt_local_lock_flock, Opt_local_lock_posix,
249 Opt_local_lock_none,
250
251 Opt_local_lock_err
252};
253
254static match_table_t nfs_local_lock_tokens = {
255 { Opt_local_lock_all, "all" },
256 { Opt_local_lock_flock, "flock" },
257 { Opt_local_lock_posix, "posix" },
258 { Opt_local_lock_none, "none" },
259
260 { Opt_local_lock_err, NULL }
261};
262
Trond Myklebust0d71b052012-03-02 13:59:49 -0500263enum {
264 Opt_vers_2, Opt_vers_3, Opt_vers_4, Opt_vers_4_0,
265 Opt_vers_4_1,
266
267 Opt_vers_err
268};
269
270static match_table_t nfs_vers_tokens = {
271 { Opt_vers_2, "2" },
272 { Opt_vers_3, "3" },
273 { Opt_vers_4, "4" },
274 { Opt_vers_4_0, "4.0" },
275 { Opt_vers_4_1, "4.1" },
276
277 { Opt_vers_err, NULL }
278};
Chuck Leverbf0fd762007-07-01 12:13:44 -0400279
Bryan Schumakerc40f8d12012-05-10 15:07:34 -0400280struct nfs_mount_info {
281 void (*fill_super)(struct super_block *, struct nfs_mount_info *);
282 struct nfs_parsed_mount_data *parsed;
Bryan Schumaker8c958e02012-05-10 15:07:35 -0400283 struct nfs_clone_mount *cloned;
Bryan Schumakerc40f8d12012-05-10 15:07:34 -0400284};
285
Al Viro42faad92008-04-24 07:21:56 -0400286static void nfs_umount_begin(struct super_block *);
Trond Myklebust816724e2006-06-24 08:41:41 -0400287static int nfs_statfs(struct dentry *, struct kstatfs *);
Al Viro34c80b12011-12-08 21:32:45 -0500288static int nfs_show_options(struct seq_file *, struct dentry *);
Al Virod861c632011-12-08 21:32:45 -0500289static int nfs_show_devname(struct seq_file *, struct dentry *);
Al Viroa6322de2011-12-08 21:37:57 -0500290static int nfs_show_path(struct seq_file *, struct dentry *);
Al Viro64132372011-12-08 20:51:13 -0500291static int nfs_show_stats(struct seq_file *, struct dentry *);
Al Viro01194982011-03-16 07:25:36 -0400292static struct dentry *nfs_fs_mount(struct file_system_type *,
293 int, const char *, void *);
Al Viro31f43472010-10-29 03:38:12 -0400294static struct dentry *nfs_xdev_mount(struct file_system_type *fs_type,
295 int flags, const char *dev_name, void *raw_data);
Trond Myklebust387c1492010-02-03 08:27:35 -0500296static void nfs_put_super(struct super_block *);
David Howellsf7b422b2006-06-09 09:34:33 -0400297static void nfs_kill_super(struct super_block *);
Jeff Layton48b605f2008-06-10 15:38:39 -0400298static int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
David Howellsf7b422b2006-06-09 09:34:33 -0400299
300static struct file_system_type nfs_fs_type = {
301 .owner = THIS_MODULE,
302 .name = "nfs",
Al Viro01194982011-03-16 07:25:36 -0400303 .mount = nfs_fs_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400304 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700305 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400306};
307
David Howells54ceac42006-08-22 20:06:13 -0400308struct file_system_type nfs_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400309 .owner = THIS_MODULE,
310 .name = "nfs",
Al Viro31f43472010-10-29 03:38:12 -0400311 .mount = nfs_xdev_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400312 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700313 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400314};
315
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800316static const struct super_operations nfs_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400317 .alloc_inode = nfs_alloc_inode,
318 .destroy_inode = nfs_destroy_inode,
319 .write_inode = nfs_write_inode,
Trond Myklebust387c1492010-02-03 08:27:35 -0500320 .put_super = nfs_put_super,
David Howellsf7b422b2006-06-09 09:34:33 -0400321 .statfs = nfs_statfs,
Al Virob57922d2010-06-07 14:34:48 -0400322 .evict_inode = nfs_evict_inode,
David Howellsf7b422b2006-06-09 09:34:33 -0400323 .umount_begin = nfs_umount_begin,
324 .show_options = nfs_show_options,
Al Viroc7f404b2011-03-16 06:59:40 -0400325 .show_devname = nfs_show_devname,
326 .show_path = nfs_show_path,
David Howellsf7b422b2006-06-09 09:34:33 -0400327 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400328 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400329};
330
331#ifdef CONFIG_NFS_V4
Chuck Lever7630c852009-09-08 19:49:57 -0400332static int nfs4_validate_text_mount_data(void *options,
333 struct nfs_parsed_mount_data *args, const char *dev_name);
Al Viro01194982011-03-16 07:25:36 -0400334static struct dentry *nfs4_try_mount(int flags, const char *dev_name,
335 struct nfs_parsed_mount_data *data);
336static struct dentry *nfs4_mount(struct file_system_type *fs_type,
337 int flags, const char *dev_name, void *raw_data);
Al Viro31f43472010-10-29 03:38:12 -0400338static struct dentry *nfs4_remote_mount(struct file_system_type *fs_type,
339 int flags, const char *dev_name, void *raw_data);
340static struct dentry *nfs4_xdev_mount(struct file_system_type *fs_type,
341 int flags, const char *dev_name, void *raw_data);
Al Viro01194982011-03-16 07:25:36 -0400342static struct dentry *nfs4_referral_mount(struct file_system_type *fs_type,
343 int flags, const char *dev_name, void *raw_data);
Al Viro31f43472010-10-29 03:38:12 -0400344static struct dentry *nfs4_remote_referral_mount(struct file_system_type *fs_type,
345 int flags, const char *dev_name, void *raw_data);
David Howellsf7b422b2006-06-09 09:34:33 -0400346static void nfs4_kill_super(struct super_block *sb);
347
348static struct file_system_type nfs4_fs_type = {
349 .owner = THIS_MODULE,
350 .name = "nfs4",
Al Viro01194982011-03-16 07:25:36 -0400351 .mount = nfs4_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400352 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700353 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400354};
355
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400356static struct file_system_type nfs4_remote_fs_type = {
357 .owner = THIS_MODULE,
358 .name = "nfs4",
Al Viro31f43472010-10-29 03:38:12 -0400359 .mount = nfs4_remote_mount,
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400360 .kill_sb = nfs4_kill_super,
361 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
362};
363
David Howells54ceac42006-08-22 20:06:13 -0400364struct file_system_type nfs4_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400365 .owner = THIS_MODULE,
366 .name = "nfs4",
Al Viro31f43472010-10-29 03:38:12 -0400367 .mount = nfs4_xdev_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400368 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700369 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400370};
371
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400372static struct file_system_type nfs4_remote_referral_fs_type = {
373 .owner = THIS_MODULE,
374 .name = "nfs4",
Al Viro31f43472010-10-29 03:38:12 -0400375 .mount = nfs4_remote_referral_mount,
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400376 .kill_sb = nfs4_kill_super,
377 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
378};
379
David Howells54ceac42006-08-22 20:06:13 -0400380struct file_system_type nfs4_referral_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400381 .owner = THIS_MODULE,
382 .name = "nfs4",
Al Viro01194982011-03-16 07:25:36 -0400383 .mount = nfs4_referral_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400384 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700385 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400386};
387
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800388static const struct super_operations nfs4_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400389 .alloc_inode = nfs_alloc_inode,
390 .destroy_inode = nfs_destroy_inode,
391 .write_inode = nfs_write_inode,
Trond Myklebust387c1492010-02-03 08:27:35 -0500392 .put_super = nfs_put_super,
David Howellsf7b422b2006-06-09 09:34:33 -0400393 .statfs = nfs_statfs,
Al Virob57922d2010-06-07 14:34:48 -0400394 .evict_inode = nfs4_evict_inode,
David Howellsf7b422b2006-06-09 09:34:33 -0400395 .umount_begin = nfs_umount_begin,
396 .show_options = nfs_show_options,
Al Viroc7f404b2011-03-16 06:59:40 -0400397 .show_devname = nfs_show_devname,
398 .show_path = nfs_show_path,
David Howellsf7b422b2006-06-09 09:34:33 -0400399 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400400 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400401};
402#endif
403
Rusty Russell8e1f9362007-07-17 04:03:17 -0700404static struct shrinker acl_shrinker = {
405 .shrink = nfs_access_cache_shrinker,
406 .seeks = DEFAULT_SEEKS,
407};
Trond Myklebust979df722006-07-25 11:28:19 -0400408
David Howellsf7b422b2006-06-09 09:34:33 -0400409/*
410 * Register the NFS filesystems
411 */
412int __init register_nfs_fs(void)
413{
414 int ret;
415
416 ret = register_filesystem(&nfs_fs_type);
417 if (ret < 0)
418 goto error_0;
419
David Howellsf7b422b2006-06-09 09:34:33 -0400420 ret = nfs_register_sysctl();
421 if (ret < 0)
422 goto error_1;
Peter Zijlstra89a09142007-03-16 13:38:26 -0800423#ifdef CONFIG_NFS_V4
David Howellsf7b422b2006-06-09 09:34:33 -0400424 ret = register_filesystem(&nfs4_fs_type);
425 if (ret < 0)
426 goto error_2;
427#endif
Rusty Russell8e1f9362007-07-17 04:03:17 -0700428 register_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400429 return 0;
430
431#ifdef CONFIG_NFS_V4
432error_2:
433 nfs_unregister_sysctl();
Peter Zijlstra89a09142007-03-16 13:38:26 -0800434#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400435error_1:
436 unregister_filesystem(&nfs_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400437error_0:
438 return ret;
439}
440
441/*
442 * Unregister the NFS filesystems
443 */
444void __exit unregister_nfs_fs(void)
445{
Rusty Russell8e1f9362007-07-17 04:03:17 -0700446 unregister_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400447#ifdef CONFIG_NFS_V4
448 unregister_filesystem(&nfs4_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400449#endif
Alexey Dobriyan49af7ee2007-09-18 22:46:40 -0700450 nfs_unregister_sysctl();
David Howellsf7b422b2006-06-09 09:34:33 -0400451 unregister_filesystem(&nfs_fs_type);
452}
453
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400454void nfs_sb_active(struct super_block *sb)
Steve Dicksonef818a22007-11-08 04:05:04 -0500455{
456 struct nfs_server *server = NFS_SB(sb);
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400457
458 if (atomic_inc_return(&server->active) == 1)
459 atomic_inc(&sb->s_active);
460}
461
462void nfs_sb_deactive(struct super_block *sb)
463{
464 struct nfs_server *server = NFS_SB(sb);
465
466 if (atomic_dec_and_test(&server->active))
467 deactivate_super(sb);
Steve Dicksonef818a22007-11-08 04:05:04 -0500468}
469
David Howellsf7b422b2006-06-09 09:34:33 -0400470/*
471 * Deliver file system statistics to userspace
472 */
Trond Myklebust816724e2006-06-24 08:41:41 -0400473static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
David Howellsf7b422b2006-06-09 09:34:33 -0400474{
David Howells0c7d90c2006-08-22 20:06:10 -0400475 struct nfs_server *server = NFS_SB(dentry->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400476 unsigned char blockbits;
477 unsigned long blockres;
David Howells0c7d90c2006-08-22 20:06:10 -0400478 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400479 struct nfs_fsstat res;
480 int error = -ENOMEM;
481
482 res.fattr = nfs_alloc_fattr();
483 if (res.fattr == NULL)
484 goto out_err;
David Howellsf7b422b2006-06-09 09:34:33 -0400485
David Howells8fa5c002006-08-22 20:06:12 -0400486 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
Menyhart Zoltanfbf3fdd2010-09-12 19:55:26 -0400487 if (unlikely(error == -ESTALE)) {
488 struct dentry *pd_dentry;
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400489
Menyhart Zoltanfbf3fdd2010-09-12 19:55:26 -0400490 pd_dentry = dget_parent(dentry);
491 if (pd_dentry != NULL) {
492 nfs_zap_caches(pd_dentry->d_inode);
493 dput(pd_dentry);
494 }
495 }
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400496 nfs_free_fattr(res.fattr);
David Howellsf7b422b2006-06-09 09:34:33 -0400497 if (error < 0)
498 goto out_err;
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400499
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700500 buf->f_type = NFS_SUPER_MAGIC;
David Howellsf7b422b2006-06-09 09:34:33 -0400501
502 /*
503 * Current versions of glibc do not correctly handle the
504 * case where f_frsize != f_bsize. Eventually we want to
505 * report the value of wtmult in this field.
506 */
David Howells0c7d90c2006-08-22 20:06:10 -0400507 buf->f_frsize = dentry->d_sb->s_blocksize;
David Howellsf7b422b2006-06-09 09:34:33 -0400508
509 /*
510 * On most *nix systems, f_blocks, f_bfree, and f_bavail
511 * are reported in units of f_frsize. Linux hasn't had
512 * an f_frsize field in its statfs struct until recently,
513 * thus historically Linux's sys_statfs reports these
514 * fields in units of f_bsize.
515 */
David Howells0c7d90c2006-08-22 20:06:10 -0400516 buf->f_bsize = dentry->d_sb->s_blocksize;
517 blockbits = dentry->d_sb->s_blocksize_bits;
David Howellsf7b422b2006-06-09 09:34:33 -0400518 blockres = (1 << blockbits) - 1;
519 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
520 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
521 buf->f_bavail = (res.abytes + blockres) >> blockbits;
522
523 buf->f_files = res.tfiles;
524 buf->f_ffree = res.afiles;
525
526 buf->f_namelen = server->namelen;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700527
David Howellsf7b422b2006-06-09 09:34:33 -0400528 return 0;
529
530 out_err:
Harvey Harrison3110ff82008-05-02 13:42:44 -0700531 dprintk("%s: statfs error = %d\n", __func__, -error);
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700532 return error;
David Howellsf7b422b2006-06-09 09:34:33 -0400533}
534
David Howells7d4e2742006-08-22 20:06:07 -0400535/*
536 * Map the security flavour number to a name
537 */
Trond Myklebust81039f12006-06-09 09:34:34 -0400538static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
539{
David Howells7d4e2742006-08-22 20:06:07 -0400540 static const struct {
Trond Myklebust81039f12006-06-09 09:34:34 -0400541 rpc_authflavor_t flavour;
542 const char *str;
543 } sec_flavours[] = {
544 { RPC_AUTH_NULL, "null" },
545 { RPC_AUTH_UNIX, "sys" },
546 { RPC_AUTH_GSS_KRB5, "krb5" },
547 { RPC_AUTH_GSS_KRB5I, "krb5i" },
548 { RPC_AUTH_GSS_KRB5P, "krb5p" },
549 { RPC_AUTH_GSS_LKEY, "lkey" },
550 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
551 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
552 { RPC_AUTH_GSS_SPKM, "spkm" },
553 { RPC_AUTH_GSS_SPKMI, "spkmi" },
554 { RPC_AUTH_GSS_SPKMP, "spkmp" },
Chuck Lever4d81cd12007-07-01 12:12:40 -0400555 { UINT_MAX, "unknown" }
Trond Myklebust81039f12006-06-09 09:34:34 -0400556 };
557 int i;
558
Chuck Lever4d81cd12007-07-01 12:12:40 -0400559 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
Trond Myklebust81039f12006-06-09 09:34:34 -0400560 if (sec_flavours[i].flavour == flavour)
561 break;
562 }
563 return sec_flavours[i].str;
564}
565
Jeff Laytonee671b02009-12-03 15:58:56 -0500566static void nfs_show_mountd_netid(struct seq_file *m, struct nfs_server *nfss,
567 int showdefaults)
568{
569 struct sockaddr *sap = (struct sockaddr *) &nfss->mountd_address;
570
571 seq_printf(m, ",mountproto=");
572 switch (sap->sa_family) {
573 case AF_INET:
574 switch (nfss->mountd_protocol) {
575 case IPPROTO_UDP:
576 seq_printf(m, RPCBIND_NETID_UDP);
577 break;
578 case IPPROTO_TCP:
579 seq_printf(m, RPCBIND_NETID_TCP);
580 break;
581 default:
582 if (showdefaults)
583 seq_printf(m, "auto");
584 }
585 break;
586 case AF_INET6:
587 switch (nfss->mountd_protocol) {
588 case IPPROTO_UDP:
589 seq_printf(m, RPCBIND_NETID_UDP6);
590 break;
591 case IPPROTO_TCP:
592 seq_printf(m, RPCBIND_NETID_TCP6);
593 break;
594 default:
595 if (showdefaults)
596 seq_printf(m, "auto");
597 }
598 break;
599 default:
600 if (showdefaults)
601 seq_printf(m, "auto");
602 }
603}
604
Chuck Lever82d101d2008-03-14 14:10:37 -0400605static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
606 int showdefaults)
607{
608 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
609
Bryan Schumakerd5eff1a2010-08-03 13:04:00 -0400610 if (nfss->flags & NFS_MOUNT_LEGACY_INTERFACE)
611 return;
612
Chuck Lever82d101d2008-03-14 14:10:37 -0400613 switch (sap->sa_family) {
614 case AF_INET: {
615 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
Harvey Harrisonbe859402008-10-31 00:56:28 -0700616 seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400617 break;
618 }
619 case AF_INET6: {
620 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
Chuck Leverd250e192009-12-03 15:58:56 -0500621 seq_printf(m, ",mountaddr=%pI6c", &sin6->sin6_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400622 break;
623 }
624 default:
625 if (showdefaults)
626 seq_printf(m, ",mountaddr=unspecified");
627 }
628
629 if (nfss->mountd_version || showdefaults)
630 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
Stanislav Kinsburskyaa699472010-12-08 12:40:13 +0300631 if ((nfss->mountd_port &&
632 nfss->mountd_port != (unsigned short)NFS_UNSPEC_PORT) ||
633 showdefaults)
Chuck Lever82d101d2008-03-14 14:10:37 -0400634 seq_printf(m, ",mountport=%u", nfss->mountd_port);
635
Jeff Laytonee671b02009-12-03 15:58:56 -0500636 nfs_show_mountd_netid(m, nfss, showdefaults);
Chuck Lever82d101d2008-03-14 14:10:37 -0400637}
638
Trond Myklebust0be81892010-06-18 12:23:58 -0400639#ifdef CONFIG_NFS_V4
640static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
641 int showdefaults)
642{
643 struct nfs_client *clp = nfss->nfs_client;
644
645 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
Trond Myklebust0be81892010-06-18 12:23:58 -0400646}
647#else
648static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
649 int showdefaults)
650{
651}
652#endif
653
Trond Myklebust7bbceb62012-03-02 14:00:20 -0500654static void nfs_show_nfs_version(struct seq_file *m,
655 unsigned int version,
656 unsigned int minorversion)
657{
658 seq_printf(m, ",vers=%u", version);
659 if (version == 4)
660 seq_printf(m, ".%u", minorversion);
661}
662
David Howellsf7b422b2006-06-09 09:34:33 -0400663/*
664 * Describe the mount options in force on this server representation
665 */
Chuck Lever82d101d2008-03-14 14:10:37 -0400666static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
667 int showdefaults)
David Howellsf7b422b2006-06-09 09:34:33 -0400668{
David Howells509de812006-08-22 20:06:11 -0400669 static const struct proc_nfs_info {
David Howellsf7b422b2006-06-09 09:34:33 -0400670 int flag;
David Howells509de812006-08-22 20:06:11 -0400671 const char *str;
672 const char *nostr;
David Howellsf7b422b2006-06-09 09:34:33 -0400673 } nfs_info[] = {
674 { NFS_MOUNT_SOFT, ",soft", ",hard" },
Chuck Lever82d101d2008-03-14 14:10:37 -0400675 { NFS_MOUNT_POSIX, ",posix", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400676 { NFS_MOUNT_NOCTO, ",nocto", "" },
677 { NFS_MOUNT_NOAC, ",noac", "" },
678 { NFS_MOUNT_NONLM, ",nolock", "" },
679 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400680 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
Chuck Leverd7403512008-12-23 15:21:37 -0500681 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
682 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400683 { 0, NULL, NULL }
684 };
David Howells509de812006-08-22 20:06:11 -0400685 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400686 struct nfs_client *clp = nfss->nfs_client;
Chuck Lever82d101d2008-03-14 14:10:37 -0400687 u32 version = clp->rpc_ops->version;
Suresh Jayaraman7c563cc2010-09-23 14:26:48 -0400688 int local_flock, local_fcntl;
David Howellsf7b422b2006-06-09 09:34:33 -0400689
Trond Myklebust7bbceb62012-03-02 14:00:20 -0500690 nfs_show_nfs_version(m, version, clp->cl_minorversion);
Chuck Lever2d767432008-03-14 14:10:08 -0400691 seq_printf(m, ",rsize=%u", nfss->rsize);
692 seq_printf(m, ",wsize=%u", nfss->wsize);
Chuck Lever82d101d2008-03-14 14:10:37 -0400693 if (nfss->bsize != 0)
694 seq_printf(m, ",bsize=%u", nfss->bsize);
695 seq_printf(m, ",namlen=%u", nfss->namelen);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400696 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400697 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400698 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400699 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400700 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400701 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400702 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400703 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
David Howellsf7b422b2006-06-09 09:34:33 -0400704 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
705 if (nfss->flags & nfs_infop->flag)
706 seq_puts(m, nfs_infop->str);
707 else
708 seq_puts(m, nfs_infop->nostr);
709 }
Trond Myklebust2446ab62012-03-01 17:00:56 -0500710 rcu_read_lock();
\"Talpey, Thomas\56928ed2007-09-10 13:48:47 -0400711 seq_printf(m, ",proto=%s",
Jeff Laytonee671b02009-12-03 15:58:56 -0500712 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
Trond Myklebust2446ab62012-03-01 17:00:56 -0500713 rcu_read_unlock();
Chuck Lever82d101d2008-03-14 14:10:37 -0400714 if (version == 4) {
715 if (nfss->port != NFS_PORT)
716 seq_printf(m, ",port=%u", nfss->port);
717 } else
718 if (nfss->port)
719 seq_printf(m, ",port=%u", nfss->port);
720
Trond Myklebust33170232007-12-20 16:03:59 -0500721 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
722 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
Trond Myklebust81039f12006-06-09 09:34:34 -0400723 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
Chuck Lever82d101d2008-03-14 14:10:37 -0400724
725 if (version != 4)
726 nfs_show_mountd_options(m, nfss, showdefaults);
Trond Myklebust0be81892010-06-18 12:23:58 -0400727 else
728 nfs_show_nfsv4_options(m, nfss, showdefaults);
Chuck Lever82d101d2008-03-14 14:10:37 -0400729
David Howellsb797cac2009-04-03 16:42:48 +0100730 if (nfss->options & NFS_OPTION_FSCACHE)
731 seq_printf(m, ",fsc");
Patrick J. LoPresti9b00c642010-08-10 17:28:01 -0400732
733 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONEG) {
734 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONE)
735 seq_printf(m, ",lookupcache=none");
736 else
737 seq_printf(m, ",lookupcache=pos");
738 }
Suresh Jayaraman7c563cc2010-09-23 14:26:48 -0400739
740 local_flock = nfss->flags & NFS_MOUNT_LOCAL_FLOCK;
741 local_fcntl = nfss->flags & NFS_MOUNT_LOCAL_FCNTL;
742
743 if (!local_flock && !local_fcntl)
744 seq_printf(m, ",local_lock=none");
745 else if (local_flock && local_fcntl)
746 seq_printf(m, ",local_lock=all");
747 else if (local_flock)
748 seq_printf(m, ",local_lock=flock");
749 else
750 seq_printf(m, ",local_lock=posix");
David Howellsf7b422b2006-06-09 09:34:33 -0400751}
752
753/*
754 * Describe the mount options on this VFS mountpoint
755 */
Al Viro34c80b12011-12-08 21:32:45 -0500756static int nfs_show_options(struct seq_file *m, struct dentry *root)
David Howellsf7b422b2006-06-09 09:34:33 -0400757{
Al Viro34c80b12011-12-08 21:32:45 -0500758 struct nfs_server *nfss = NFS_SB(root->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400759
760 nfs_show_mount_options(m, nfss, 0);
761
Trond Myklebust2446ab62012-03-01 17:00:56 -0500762 rcu_read_lock();
Chuck Lever5d8515c2007-12-10 14:57:16 -0500763 seq_printf(m, ",addr=%s",
764 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
765 RPC_DISPLAY_ADDR));
Trond Myklebust2446ab62012-03-01 17:00:56 -0500766 rcu_read_unlock();
David Howellsf7b422b2006-06-09 09:34:33 -0400767
768 return 0;
769}
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700770
771#ifdef CONFIG_NFS_V4
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300772#ifdef CONFIG_NFS_V4_1
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700773static void show_sessions(struct seq_file *m, struct nfs_server *server)
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300774{
775 if (nfs4_has_session(server->nfs_client))
776 seq_printf(m, ",sessions");
777}
778#else
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700779static void show_sessions(struct seq_file *m, struct nfs_server *server) {}
780#endif
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300781#endif
782
783#ifdef CONFIG_NFS_V4_1
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700784static void show_pnfs(struct seq_file *m, struct nfs_server *server)
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300785{
786 seq_printf(m, ",pnfs=");
787 if (server->pnfs_curr_ld)
788 seq_printf(m, "%s", server->pnfs_curr_ld->name);
789 else
790 seq_printf(m, "not configured");
791}
Trond Myklebust7e03b7c2012-03-04 18:12:57 -0500792
793static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
794{
795 if (nfss->nfs_client && nfss->nfs_client->impl_id) {
796 struct nfs41_impl_id *impl_id = nfss->nfs_client->impl_id;
797 seq_printf(m, "\n\timpl_id:\tname='%s',domain='%s',"
798 "date='%llu,%u'",
799 impl_id->name, impl_id->domain,
800 impl_id->date.seconds, impl_id->date.nseconds);
801 }
802}
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700803#else
Trond Myklebust7e03b7c2012-03-04 18:12:57 -0500804#ifdef CONFIG_NFS_V4
805static void show_pnfs(struct seq_file *m, struct nfs_server *server)
806{
807}
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700808#endif
Trond Myklebust7e03b7c2012-03-04 18:12:57 -0500809static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
810{
811}
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700812#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400813
Al Virod861c632011-12-08 21:32:45 -0500814static int nfs_show_devname(struct seq_file *m, struct dentry *root)
Al Viroc7f404b2011-03-16 06:59:40 -0400815{
816 char *page = (char *) __get_free_page(GFP_KERNEL);
817 char *devname, *dummy;
818 int err = 0;
819 if (!page)
820 return -ENOMEM;
Al Virod861c632011-12-08 21:32:45 -0500821 devname = nfs_path(&dummy, root, page, PAGE_SIZE);
Al Viroc7f404b2011-03-16 06:59:40 -0400822 if (IS_ERR(devname))
823 err = PTR_ERR(devname);
824 else
825 seq_escape(m, devname, " \t\n\\");
826 free_page((unsigned long)page);
827 return err;
828}
829
Al Viroa6322de2011-12-08 21:37:57 -0500830static int nfs_show_path(struct seq_file *m, struct dentry *dentry)
Al Viroc7f404b2011-03-16 06:59:40 -0400831{
832 seq_puts(m, "/");
833 return 0;
834}
835
David Howellsf7b422b2006-06-09 09:34:33 -0400836/*
837 * Present statistical information for this VFS mountpoint
838 */
Al Viro64132372011-12-08 20:51:13 -0500839static int nfs_show_stats(struct seq_file *m, struct dentry *root)
David Howellsf7b422b2006-06-09 09:34:33 -0400840{
841 int i, cpu;
Al Viro64132372011-12-08 20:51:13 -0500842 struct nfs_server *nfss = NFS_SB(root->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400843 struct rpc_auth *auth = nfss->client->cl_auth;
844 struct nfs_iostats totals = { };
845
846 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
847
848 /*
849 * Display all mount option settings
850 */
851 seq_printf(m, "\n\topts:\t");
Al Viro64132372011-12-08 20:51:13 -0500852 seq_puts(m, root->d_sb->s_flags & MS_RDONLY ? "ro" : "rw");
853 seq_puts(m, root->d_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
854 seq_puts(m, root->d_sb->s_flags & MS_NOATIME ? ",noatime" : "");
855 seq_puts(m, root->d_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
David Howellsf7b422b2006-06-09 09:34:33 -0400856 nfs_show_mount_options(m, nfss, 1);
857
858 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
859
Trond Myklebust7e03b7c2012-03-04 18:12:57 -0500860 show_implementation_id(m, nfss);
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500861
David Howellsf7b422b2006-06-09 09:34:33 -0400862 seq_printf(m, "\n\tcaps:\t");
863 seq_printf(m, "caps=0x%x", nfss->caps);
Chuck Lever2d767432008-03-14 14:10:08 -0400864 seq_printf(m, ",wtmult=%u", nfss->wtmult);
865 seq_printf(m, ",dtsize=%u", nfss->dtsize);
866 seq_printf(m, ",bsize=%u", nfss->bsize);
867 seq_printf(m, ",namlen=%u", nfss->namelen);
David Howellsf7b422b2006-06-09 09:34:33 -0400868
869#ifdef CONFIG_NFS_V4
Trond Myklebust40c553192007-12-14 14:56:07 -0500870 if (nfss->nfs_client->rpc_ops->version == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400871 seq_printf(m, "\n\tnfsv4:\t");
872 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
873 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
874 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300875 show_sessions(m, nfss);
876 show_pnfs(m, nfss);
David Howellsf7b422b2006-06-09 09:34:33 -0400877 }
878#endif
879
880 /*
881 * Display security flavor in effect for this mount
882 */
Chuck Lever2d767432008-03-14 14:10:08 -0400883 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400884 if (auth->au_flavor)
Chuck Lever2d767432008-03-14 14:10:08 -0400885 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400886
887 /*
888 * Display superblock I/O counters
889 */
890 for_each_possible_cpu(cpu) {
891 struct nfs_iostats *stats;
892
893 preempt_disable();
894 stats = per_cpu_ptr(nfss->io_stats, cpu);
895
896 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
897 totals.events[i] += stats->events[i];
898 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
899 totals.bytes[i] += stats->bytes[i];
David Howells6a510912009-04-03 16:42:43 +0100900#ifdef CONFIG_NFS_FSCACHE
901 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
902 totals.fscache[i] += stats->fscache[i];
903#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400904
905 preempt_enable();
906 }
907
908 seq_printf(m, "\n\tevents:\t");
909 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
910 seq_printf(m, "%lu ", totals.events[i]);
911 seq_printf(m, "\n\tbytes:\t");
912 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
913 seq_printf(m, "%Lu ", totals.bytes[i]);
David Howells6a510912009-04-03 16:42:43 +0100914#ifdef CONFIG_NFS_FSCACHE
915 if (nfss->options & NFS_OPTION_FSCACHE) {
916 seq_printf(m, "\n\tfsc:\t");
917 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
918 seq_printf(m, "%Lu ", totals.bytes[i]);
919 }
920#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400921 seq_printf(m, "\n");
922
923 rpc_print_iostats(m, nfss->client);
924
925 return 0;
926}
927
928/*
929 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400930 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400931 */
Al Viro42faad92008-04-24 07:21:56 -0400932static void nfs_umount_begin(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -0400933{
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200934 struct nfs_server *server;
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400935 struct rpc_clnt *rpc;
936
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200937 server = NFS_SB(sb);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400938 /* -EIO all pending I/O */
939 rpc = server->client_acl;
940 if (!IS_ERR(rpc))
941 rpc_killall_tasks(rpc);
942 rpc = server->client;
943 if (!IS_ERR(rpc))
944 rpc_killall_tasks(rpc);
David Howellsf7b422b2006-06-09 09:34:33 -0400945}
946
Trond Myklebustc5811db2009-10-06 15:40:15 -0400947static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(unsigned int version)
Chuck Lever9423a082009-09-23 14:36:38 -0400948{
949 struct nfs_parsed_mount_data *data;
950
951 data = kzalloc(sizeof(*data), GFP_KERNEL);
952 if (data) {
Chuck Lever9423a082009-09-23 14:36:38 -0400953 data->acregmin = NFS_DEF_ACREGMIN;
954 data->acregmax = NFS_DEF_ACREGMAX;
955 data->acdirmin = NFS_DEF_ACDIRMIN;
956 data->acdirmax = NFS_DEF_ACDIRMAX;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400957 data->mount_server.port = NFS_UNSPEC_PORT;
Chuck Lever9423a082009-09-23 14:36:38 -0400958 data->nfs_server.port = NFS_UNSPEC_PORT;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400959 data->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Lever9423a082009-09-23 14:36:38 -0400960 data->auth_flavors[0] = RPC_AUTH_UNIX;
961 data->auth_flavor_len = 1;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400962 data->version = version;
Chuck Lever9423a082009-09-23 14:36:38 -0400963 data->minorversion = 0;
Trond Myklebust9937347a2012-02-19 08:44:07 +0100964 data->net = current->nsproxy->net_ns;
Jeff Layton8a0d5512011-12-20 06:57:45 -0500965 security_init_mnt_opts(&data->lsm_opts);
Chuck Lever9423a082009-09-23 14:36:38 -0400966 }
967 return data;
968}
969
Jeff Layton8a0d5512011-12-20 06:57:45 -0500970static void nfs_free_parsed_mount_data(struct nfs_parsed_mount_data *data)
971{
972 if (data) {
973 kfree(data->client_address);
974 kfree(data->mount_server.hostname);
975 kfree(data->nfs_server.export_path);
976 kfree(data->nfs_server.hostname);
977 kfree(data->fscache_uniq);
978 security_free_mnt_opts(&data->lsm_opts);
979 kfree(data);
980 }
981}
982
David Howellsf7b422b2006-06-09 09:34:33 -0400983/*
Chuck Levercdcd7f92007-12-10 14:57:45 -0500984 * Sanity-check a server address provided by the mount command.
985 *
986 * Address family must be initialized, and address must not be
987 * the ANY address for that family.
Chuck Leverfc50d582007-07-01 12:12:46 -0400988 */
989static int nfs_verify_server_address(struct sockaddr *addr)
990{
991 switch (addr->sa_family) {
992 case AF_INET: {
Chuck Levercdcd7f92007-12-10 14:57:45 -0500993 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
Al Viroe6f1ceb2008-03-17 22:44:53 -0700994 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
Chuck Levercdcd7f92007-12-10 14:57:45 -0500995 }
996 case AF_INET6: {
997 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
998 return !ipv6_addr_any(sa);
Chuck Leverfc50d582007-07-01 12:12:46 -0400999 }
1000 }
1001
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001002 dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
Chuck Leverfc50d582007-07-01 12:12:46 -04001003 return 0;
1004}
1005
Chuck Lever9412b922007-12-10 14:59:21 -05001006/*
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001007 * Select between a default port value and a user-specified port value.
1008 * If a zero value is set, then autobind will be used.
1009 */
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001010static void nfs_set_port(struct sockaddr *sap, int *port,
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001011 const unsigned short default_port)
1012{
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001013 if (*port == NFS_UNSPEC_PORT)
1014 *port = default_port;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001015
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001016 rpc_set_port(sap, *port);
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001017}
1018
1019/*
Trond Myklebust259875e2008-07-02 14:43:47 -04001020 * Sanity check the NFS transport protocol.
1021 *
1022 */
1023static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
1024{
1025 switch (mnt->nfs_server.protocol) {
1026 case XPRT_TRANSPORT_UDP:
1027 case XPRT_TRANSPORT_TCP:
1028 case XPRT_TRANSPORT_RDMA:
1029 break;
1030 default:
1031 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1032 }
1033}
1034
1035/*
1036 * For text based NFSv2/v3 mounts, the mount protocol transport default
1037 * settings should depend upon the specified NFS transport.
1038 */
1039static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
1040{
1041 nfs_validate_transport_protocol(mnt);
1042
1043 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
1044 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
1045 return;
1046 switch (mnt->nfs_server.protocol) {
1047 case XPRT_TRANSPORT_UDP:
1048 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
1049 break;
1050 case XPRT_TRANSPORT_TCP:
1051 case XPRT_TRANSPORT_RDMA:
1052 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
1053 }
1054}
1055
1056/*
Chuck Lever01060c82008-06-24 16:33:38 -04001057 * Parse the value of the 'sec=' option.
Chuck Lever01060c82008-06-24 16:33:38 -04001058 */
1059static int nfs_parse_security_flavors(char *value,
1060 struct nfs_parsed_mount_data *mnt)
1061{
1062 substring_t args[MAX_OPT_ARGS];
1063
1064 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
1065
1066 switch (match_token(value, nfs_secflavor_tokens, args)) {
1067 case Opt_sec_none:
Chuck Lever01060c82008-06-24 16:33:38 -04001068 mnt->auth_flavors[0] = RPC_AUTH_NULL;
1069 break;
1070 case Opt_sec_sys:
Chuck Lever01060c82008-06-24 16:33:38 -04001071 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
1072 break;
1073 case Opt_sec_krb5:
Chuck Lever01060c82008-06-24 16:33:38 -04001074 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
1075 break;
1076 case Opt_sec_krb5i:
Chuck Lever01060c82008-06-24 16:33:38 -04001077 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
1078 break;
1079 case Opt_sec_krb5p:
Chuck Lever01060c82008-06-24 16:33:38 -04001080 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
1081 break;
1082 case Opt_sec_lkey:
Chuck Lever01060c82008-06-24 16:33:38 -04001083 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
1084 break;
1085 case Opt_sec_lkeyi:
Chuck Lever01060c82008-06-24 16:33:38 -04001086 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
1087 break;
1088 case Opt_sec_lkeyp:
Chuck Lever01060c82008-06-24 16:33:38 -04001089 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
1090 break;
1091 case Opt_sec_spkm:
Chuck Lever01060c82008-06-24 16:33:38 -04001092 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
1093 break;
1094 case Opt_sec_spkmi:
Chuck Lever01060c82008-06-24 16:33:38 -04001095 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
1096 break;
1097 case Opt_sec_spkmp:
Chuck Lever01060c82008-06-24 16:33:38 -04001098 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
1099 break;
1100 default:
1101 return 0;
1102 }
1103
Bryan Schumaker9b7160c2011-04-13 14:31:30 -04001104 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
Chuck Lever059f90b2009-08-09 15:09:31 -04001105 mnt->auth_flavor_len = 1;
Chuck Lever01060c82008-06-24 16:33:38 -04001106 return 1;
1107}
1108
Trond Myklebust0d71b052012-03-02 13:59:49 -05001109static int nfs_parse_version_string(char *string,
1110 struct nfs_parsed_mount_data *mnt,
1111 substring_t *args)
1112{
1113 mnt->flags &= ~NFS_MOUNT_VER3;
1114 switch (match_token(string, nfs_vers_tokens, args)) {
1115 case Opt_vers_2:
1116 mnt->version = 2;
1117 break;
1118 case Opt_vers_3:
1119 mnt->flags |= NFS_MOUNT_VER3;
1120 mnt->version = 3;
1121 break;
1122 case Opt_vers_4:
1123 /* Backward compatibility option. In future,
1124 * the mount program should always supply
1125 * a NFSv4 minor version number.
1126 */
1127 mnt->version = 4;
1128 break;
1129 case Opt_vers_4_0:
1130 mnt->version = 4;
1131 mnt->minorversion = 0;
1132 break;
1133 case Opt_vers_4_1:
1134 mnt->version = 4;
1135 mnt->minorversion = 1;
1136 break;
1137 default:
1138 return 0;
1139 }
1140 return 1;
1141}
1142
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001143static int nfs_get_option_str(substring_t args[], char **option)
1144{
1145 kfree(*option);
1146 *option = match_strdup(args);
1147 return !option;
1148}
1149
1150static int nfs_get_option_ul(substring_t args[], unsigned long *option)
1151{
1152 int rc;
1153 char *string;
1154
1155 string = match_strdup(args);
1156 if (string == NULL)
1157 return -ENOMEM;
1158 rc = strict_strtoul(string, 10, option);
1159 kfree(string);
1160
1161 return rc;
1162}
1163
Chuck Lever01060c82008-06-24 16:33:38 -04001164/*
Chuck Leverbf0fd762007-07-01 12:13:44 -04001165 * Error-check and convert a string of mount options from user space into
Chuck Leverf45663c2008-06-24 19:28:02 -04001166 * a data structure. The whole mount string is processed; bad options are
1167 * skipped as they are encountered. If there were no errors, return 1;
1168 * otherwise return 0 (zero).
Chuck Leverbf0fd762007-07-01 12:13:44 -04001169 */
1170static int nfs_parse_mount_options(char *raw,
1171 struct nfs_parsed_mount_data *mnt)
1172{
Eric Parisf9c3a382008-03-05 14:20:18 -05001173 char *p, *string, *secdata;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001174 int rc, sloppy = 0, invalid_option = 0;
Jeff Laytonee671b02009-12-03 15:58:56 -05001175 unsigned short protofamily = AF_UNSPEC;
1176 unsigned short mountfamily = AF_UNSPEC;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001177
1178 if (!raw) {
1179 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
1180 return 1;
1181 }
1182 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
1183
Eric Parisf9c3a382008-03-05 14:20:18 -05001184 secdata = alloc_secdata();
1185 if (!secdata)
1186 goto out_nomem;
1187
1188 rc = security_sb_copy_data(raw, secdata);
1189 if (rc)
1190 goto out_security_failure;
1191
1192 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
1193 if (rc)
1194 goto out_security_failure;
1195
1196 free_secdata(secdata);
1197
Chuck Leverbf0fd762007-07-01 12:13:44 -04001198 while ((p = strsep(&raw, ",")) != NULL) {
1199 substring_t args[MAX_OPT_ARGS];
Chuck Levera5a16ba2009-06-17 18:02:14 -07001200 unsigned long option;
1201 int token;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001202
1203 if (!*p)
1204 continue;
1205
1206 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
1207
1208 token = match_token(p, nfs_mount_option_tokens, args);
1209 switch (token) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001210
1211 /*
1212 * boolean options: foo/nofoo
1213 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001214 case Opt_soft:
1215 mnt->flags |= NFS_MOUNT_SOFT;
1216 break;
1217 case Opt_hard:
1218 mnt->flags &= ~NFS_MOUNT_SOFT;
1219 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001220 case Opt_posix:
1221 mnt->flags |= NFS_MOUNT_POSIX;
1222 break;
1223 case Opt_noposix:
1224 mnt->flags &= ~NFS_MOUNT_POSIX;
1225 break;
1226 case Opt_cto:
1227 mnt->flags &= ~NFS_MOUNT_NOCTO;
1228 break;
1229 case Opt_nocto:
1230 mnt->flags |= NFS_MOUNT_NOCTO;
1231 break;
1232 case Opt_ac:
1233 mnt->flags &= ~NFS_MOUNT_NOAC;
1234 break;
1235 case Opt_noac:
1236 mnt->flags |= NFS_MOUNT_NOAC;
1237 break;
1238 case Opt_lock:
1239 mnt->flags &= ~NFS_MOUNT_NONLM;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001240 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1241 NFS_MOUNT_LOCAL_FCNTL);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001242 break;
1243 case Opt_nolock:
1244 mnt->flags |= NFS_MOUNT_NONLM;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001245 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1246 NFS_MOUNT_LOCAL_FCNTL);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001247 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001248 case Opt_udp:
1249 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001250 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001251 break;
1252 case Opt_tcp:
1253 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001254 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001255 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001256 case Opt_rdma:
1257 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1258 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001259 xprt_load_transport(p);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001260 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001261 case Opt_acl:
1262 mnt->flags &= ~NFS_MOUNT_NOACL;
1263 break;
1264 case Opt_noacl:
1265 mnt->flags |= NFS_MOUNT_NOACL;
1266 break;
1267 case Opt_rdirplus:
1268 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1269 break;
1270 case Opt_nordirplus:
1271 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1272 break;
Trond Myklebust75180df2007-05-16 16:53:28 -04001273 case Opt_sharecache:
1274 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1275 break;
1276 case Opt_nosharecache:
1277 mnt->flags |= NFS_MOUNT_UNSHARED;
1278 break;
Chuck Leverd7403512008-12-23 15:21:37 -05001279 case Opt_resvport:
1280 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1281 break;
1282 case Opt_noresvport:
1283 mnt->flags |= NFS_MOUNT_NORESVPORT;
1284 break;
David Howellsb797cac2009-04-03 16:42:48 +01001285 case Opt_fscache:
1286 mnt->options |= NFS_OPTION_FSCACHE;
1287 kfree(mnt->fscache_uniq);
1288 mnt->fscache_uniq = NULL;
1289 break;
1290 case Opt_nofscache:
1291 mnt->options &= ~NFS_OPTION_FSCACHE;
1292 kfree(mnt->fscache_uniq);
1293 mnt->fscache_uniq = NULL;
1294 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001295
Chuck Leverf45663c2008-06-24 19:28:02 -04001296 /*
1297 * options that take numeric values
1298 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001299 case Opt_port:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001300 if (nfs_get_option_ul(args, &option) ||
1301 option > USHRT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001302 goto out_invalid_value;
1303 mnt->nfs_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001304 break;
1305 case Opt_rsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001306 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001307 goto out_invalid_value;
1308 mnt->rsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001309 break;
1310 case Opt_wsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001311 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001312 goto out_invalid_value;
1313 mnt->wsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001314 break;
1315 case Opt_bsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001316 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001317 goto out_invalid_value;
1318 mnt->bsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001319 break;
1320 case Opt_timeo:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001321 if (nfs_get_option_ul(args, &option) || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001322 goto out_invalid_value;
1323 mnt->timeo = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001324 break;
1325 case Opt_retrans:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001326 if (nfs_get_option_ul(args, &option) || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001327 goto out_invalid_value;
1328 mnt->retrans = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001329 break;
1330 case Opt_acregmin:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001331 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001332 goto out_invalid_value;
1333 mnt->acregmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001334 break;
1335 case Opt_acregmax:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001336 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001337 goto out_invalid_value;
1338 mnt->acregmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001339 break;
1340 case Opt_acdirmin:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001341 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001342 goto out_invalid_value;
1343 mnt->acdirmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001344 break;
1345 case Opt_acdirmax:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001346 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001347 goto out_invalid_value;
1348 mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001349 break;
1350 case Opt_actimeo:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001351 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001352 goto out_invalid_value;
1353 mnt->acregmin = mnt->acregmax =
1354 mnt->acdirmin = mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001355 break;
1356 case Opt_namelen:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001357 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001358 goto out_invalid_value;
1359 mnt->namlen = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001360 break;
1361 case Opt_mountport:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001362 if (nfs_get_option_ul(args, &option) ||
1363 option > USHRT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001364 goto out_invalid_value;
1365 mnt->mount_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001366 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001367 case Opt_mountvers:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001368 if (nfs_get_option_ul(args, &option) ||
Chuck Leverf45663c2008-06-24 19:28:02 -04001369 option < NFS_MNT_VERSION ||
Chuck Leverd23c45f2009-06-17 18:02:13 -07001370 option > NFS_MNT3_VERSION)
1371 goto out_invalid_value;
1372 mnt->mount_server.version = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001373 break;
Mike Sager3fd5be92009-04-01 09:21:48 -04001374 case Opt_minorversion:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001375 if (nfs_get_option_ul(args, &option))
Chuck Leverf3f4f4e2009-08-09 15:09:29 -04001376 goto out_invalid_value;
1377 if (option > NFS4_MAX_MINOR_VERSION)
1378 goto out_invalid_value;
1379 mnt->minorversion = option;
Mike Sager3fd5be92009-04-01 09:21:48 -04001380 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001381
Chuck Leverf45663c2008-06-24 19:28:02 -04001382 /*
1383 * options that take text values
1384 */
Trond Myklebust0d71b052012-03-02 13:59:49 -05001385 case Opt_nfsvers:
1386 string = match_strdup(args);
1387 if (string == NULL)
1388 goto out_nomem;
1389 rc = nfs_parse_version_string(string, mnt, args);
1390 kfree(string);
1391 if (!rc)
1392 goto out_invalid_value;
1393 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001394 case Opt_sec:
1395 string = match_strdup(args);
1396 if (string == NULL)
1397 goto out_nomem;
Chuck Lever01060c82008-06-24 16:33:38 -04001398 rc = nfs_parse_security_flavors(string, mnt);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001399 kfree(string);
Chuck Leverf45663c2008-06-24 19:28:02 -04001400 if (!rc) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001401 dfprintk(MOUNT, "NFS: unrecognized "
1402 "security flavor\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001403 return 0;
Chuck Leverf45663c2008-06-24 19:28:02 -04001404 }
Chuck Leverbf0fd762007-07-01 12:13:44 -04001405 break;
1406 case Opt_proto:
1407 string = match_strdup(args);
1408 if (string == NULL)
1409 goto out_nomem;
1410 token = match_token(string,
1411 nfs_xprt_protocol_tokens, args);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001412
Jeff Laytonee671b02009-12-03 15:58:56 -05001413 protofamily = AF_INET;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001414 switch (token) {
Jeff Laytonee671b02009-12-03 15:58:56 -05001415 case Opt_xprt_udp6:
1416 protofamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001417 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001418 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001419 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001420 break;
Jeff Laytonee671b02009-12-03 15:58:56 -05001421 case Opt_xprt_tcp6:
1422 protofamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001423 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001424 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001425 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001426 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001427 case Opt_xprt_rdma:
1428 /* vector side protocols to TCP */
1429 mnt->flags |= NFS_MOUNT_TCP;
1430 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001431 xprt_load_transport(string);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001432 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001433 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001434 dfprintk(MOUNT, "NFS: unrecognized "
1435 "transport protocol\n");
Yinghai Lu4223a4a2009-10-20 14:13:46 +09001436 kfree(string);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001437 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001438 }
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001439 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001440 break;
1441 case Opt_mountproto:
1442 string = match_strdup(args);
1443 if (string == NULL)
1444 goto out_nomem;
1445 token = match_token(string,
1446 nfs_xprt_protocol_tokens, args);
Trond Myklebustd508afb2009-04-06 16:41:35 -07001447 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001448
Jeff Laytonee671b02009-12-03 15:58:56 -05001449 mountfamily = AF_INET;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001450 switch (token) {
Jeff Laytonee671b02009-12-03 15:58:56 -05001451 case Opt_xprt_udp6:
1452 mountfamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001453 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001454 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001455 break;
Jeff Laytonee671b02009-12-03 15:58:56 -05001456 case Opt_xprt_tcp6:
1457 mountfamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001458 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001459 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001460 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001461 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001462 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001463 dfprintk(MOUNT, "NFS: unrecognized "
1464 "transport protocol\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001465 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001466 }
1467 break;
1468 case Opt_addr:
1469 string = match_strdup(args);
1470 if (string == NULL)
1471 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001472 mnt->nfs_server.addrlen =
Stanislav Kinsburskyb48e1272012-01-26 15:11:57 +04001473 rpc_pton(mnt->net, string, strlen(string),
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001474 (struct sockaddr *)
1475 &mnt->nfs_server.address,
1476 sizeof(mnt->nfs_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001477 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001478 if (mnt->nfs_server.addrlen == 0)
1479 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001480 break;
1481 case Opt_clientaddr:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001482 if (nfs_get_option_str(args, &mnt->client_address))
Chuck Leverbf0fd762007-07-01 12:13:44 -04001483 goto out_nomem;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001484 break;
Chuck Lever33832032007-12-10 14:59:13 -05001485 case Opt_mounthost:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001486 if (nfs_get_option_str(args,
1487 &mnt->mount_server.hostname))
Chuck Lever33832032007-12-10 14:59:13 -05001488 goto out_nomem;
Chuck Lever33832032007-12-10 14:59:13 -05001489 break;
Chuck Lever0ac83772007-09-11 18:01:04 -04001490 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001491 string = match_strdup(args);
1492 if (string == NULL)
1493 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001494 mnt->mount_server.addrlen =
Stanislav Kinsburskyb48e1272012-01-26 15:11:57 +04001495 rpc_pton(mnt->net, string, strlen(string),
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001496 (struct sockaddr *)
1497 &mnt->mount_server.address,
1498 sizeof(mnt->mount_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001499 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001500 if (mnt->mount_server.addrlen == 0)
1501 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001502 break;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001503 case Opt_lookupcache:
1504 string = match_strdup(args);
1505 if (string == NULL)
1506 goto out_nomem;
1507 token = match_token(string,
1508 nfs_lookupcache_tokens, args);
1509 kfree(string);
1510 switch (token) {
1511 case Opt_lookupcache_all:
1512 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1513 break;
1514 case Opt_lookupcache_positive:
1515 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1516 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1517 break;
1518 case Opt_lookupcache_none:
1519 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1520 break;
1521 default:
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001522 dfprintk(MOUNT, "NFS: invalid "
1523 "lookupcache argument\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001524 return 0;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001525 };
1526 break;
Chuck Levera6d5ff62010-05-07 13:33:58 -04001527 case Opt_fscache_uniq:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001528 if (nfs_get_option_str(args, &mnt->fscache_uniq))
Chuck Levera6d5ff62010-05-07 13:33:58 -04001529 goto out_nomem;
Chuck Levera6d5ff62010-05-07 13:33:58 -04001530 mnt->options |= NFS_OPTION_FSCACHE;
1531 break;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001532 case Opt_local_lock:
1533 string = match_strdup(args);
1534 if (string == NULL)
1535 goto out_nomem;
1536 token = match_token(string, nfs_local_lock_tokens,
1537 args);
1538 kfree(string);
1539 switch (token) {
1540 case Opt_local_lock_all:
1541 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1542 NFS_MOUNT_LOCAL_FCNTL);
1543 break;
1544 case Opt_local_lock_flock:
1545 mnt->flags |= NFS_MOUNT_LOCAL_FLOCK;
1546 break;
1547 case Opt_local_lock_posix:
1548 mnt->flags |= NFS_MOUNT_LOCAL_FCNTL;
1549 break;
1550 case Opt_local_lock_none:
1551 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1552 NFS_MOUNT_LOCAL_FCNTL);
1553 break;
1554 default:
1555 dfprintk(MOUNT, "NFS: invalid "
1556 "local_lock argument\n");
1557 return 0;
1558 };
1559 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001560
Chuck Leverf45663c2008-06-24 19:28:02 -04001561 /*
1562 * Special options
1563 */
1564 case Opt_sloppy:
1565 sloppy = 1;
1566 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1567 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001568 case Opt_userspace:
1569 case Opt_deprecated:
Chuck Leverd33e4df2008-06-12 12:37:41 -04001570 dfprintk(MOUNT, "NFS: ignoring mount option "
1571 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001572 break;
1573
1574 default:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001575 invalid_option = 1;
Chuck Leverf45663c2008-06-24 19:28:02 -04001576 dfprintk(MOUNT, "NFS: unrecognized mount option "
1577 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001578 }
1579 }
1580
Chuck Leverd23c45f2009-06-17 18:02:13 -07001581 if (!sloppy && invalid_option)
1582 return 0;
1583
Weston Andros Adamson571b7552012-02-01 14:06:41 -05001584 if (mnt->minorversion && mnt->version != 4)
1585 goto out_minorversion_mismatch;
1586
Jeff Laytonee671b02009-12-03 15:58:56 -05001587 /*
1588 * verify that any proto=/mountproto= options match the address
1589 * familiies in the addr=/mountaddr= options.
1590 */
1591 if (protofamily != AF_UNSPEC &&
1592 protofamily != mnt->nfs_server.address.ss_family)
1593 goto out_proto_mismatch;
1594
1595 if (mountfamily != AF_UNSPEC) {
1596 if (mnt->mount_server.addrlen) {
1597 if (mountfamily != mnt->mount_server.address.ss_family)
1598 goto out_mountproto_mismatch;
1599 } else {
1600 if (mountfamily != mnt->nfs_server.address.ss_family)
1601 goto out_mountproto_mismatch;
1602 }
1603 }
1604
Chuck Leverbf0fd762007-07-01 12:13:44 -04001605 return 1;
1606
Jeff Laytonee671b02009-12-03 15:58:56 -05001607out_mountproto_mismatch:
1608 printk(KERN_INFO "NFS: mount server address does not match mountproto= "
1609 "option\n");
1610 return 0;
1611out_proto_mismatch:
1612 printk(KERN_INFO "NFS: server address does not match proto= option\n");
1613 return 0;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001614out_invalid_address:
1615 printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
1616 return 0;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001617out_invalid_value:
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001618 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001619 return 0;
Weston Andros Adamson571b7552012-02-01 14:06:41 -05001620out_minorversion_mismatch:
1621 printk(KERN_INFO "NFS: mount option vers=%u does not support "
1622 "minorversion=%u\n", mnt->version, mnt->minorversion);
1623 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001624out_nomem:
1625 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1626 return 0;
Eric Parisf9c3a382008-03-05 14:20:18 -05001627out_security_failure:
1628 free_secdata(secdata);
1629 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1630 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001631}
1632
1633/*
Chuck Leverec88f282009-08-09 15:09:32 -04001634 * Match the requested auth flavors with the list returned by
1635 * the server. Returns zero and sets the mount's authentication
1636 * flavor on success; returns -EACCES if server does not support
1637 * the requested flavor.
1638 */
1639static int nfs_walk_authlist(struct nfs_parsed_mount_data *args,
1640 struct nfs_mount_request *request)
1641{
1642 unsigned int i, j, server_authlist_len = *(request->auth_flav_len);
1643
1644 /*
Chuck Lever5eecfde2009-08-21 17:50:30 -04001645 * Certain releases of Linux's mountd return an empty
1646 * flavor list. To prevent behavioral regression with
1647 * these servers (ie. rejecting mounts that used to
1648 * succeed), revert to pre-2.6.32 behavior (no checking)
1649 * if the returned flavor list is empty.
1650 */
1651 if (server_authlist_len == 0)
1652 return 0;
1653
1654 /*
Chuck Leverec88f282009-08-09 15:09:32 -04001655 * We avoid sophisticated negotiating here, as there are
1656 * plenty of cases where we can get it wrong, providing
1657 * either too little or too much security.
1658 *
1659 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1660 * flavor listed first. However, some servers list
1661 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1662 * preferred default, in args->auth_flavors[0] if user
1663 * didn't specify sec= mount option.
1664 */
1665 for (i = 0; i < args->auth_flavor_len; i++)
1666 for (j = 0; j < server_authlist_len; j++)
1667 if (args->auth_flavors[i] == request->auth_flavs[j]) {
1668 dfprintk(MOUNT, "NFS: using auth flavor %d\n",
1669 request->auth_flavs[j]);
1670 args->auth_flavors[0] = request->auth_flavs[j];
1671 return 0;
1672 }
1673
1674 dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n");
1675 nfs_umount(request);
1676 return -EACCES;
1677}
1678
1679/*
Chuck Lever0076d7b2007-07-01 12:13:49 -04001680 * Use the remote server's MOUNT service to request the NFS file handle
1681 * corresponding to the provided path.
1682 */
1683static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1684 struct nfs_fh *root_fh)
1685{
Chuck Leverec88f282009-08-09 15:09:32 -04001686 rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS];
1687 unsigned int server_authlist_len = ARRAY_SIZE(server_authlist);
Chuck Leverc5d120f2008-12-23 15:21:35 -05001688 struct nfs_mount_request request = {
1689 .sap = (struct sockaddr *)
1690 &args->mount_server.address,
1691 .dirpath = args->nfs_server.export_path,
1692 .protocol = args->mount_server.protocol,
1693 .fh = root_fh,
Chuck Lever50a737f2008-12-23 15:21:37 -05001694 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
Chuck Leverec88f282009-08-09 15:09:32 -04001695 .auth_flav_len = &server_authlist_len,
1696 .auth_flavs = server_authlist,
Stanislav Kinsbursky6d59b8d2012-01-10 16:12:54 +04001697 .net = args->net,
Chuck Leverc5d120f2008-12-23 15:21:35 -05001698 };
Chuck Lever4c568012007-12-10 14:59:28 -05001699 int status;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001700
1701 if (args->mount_server.version == 0) {
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001702 switch (args->version) {
1703 default:
1704 args->mount_server.version = NFS_MNT3_VERSION;
1705 break;
1706 case 2:
1707 args->mount_server.version = NFS_MNT_VERSION;
1708 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001709 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001710 request.version = args->mount_server.version;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001711
Chuck Lever33832032007-12-10 14:59:13 -05001712 if (args->mount_server.hostname)
Chuck Leverc5d120f2008-12-23 15:21:35 -05001713 request.hostname = args->mount_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001714 else
Chuck Leverc5d120f2008-12-23 15:21:35 -05001715 request.hostname = args->nfs_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001716
Chuck Lever0076d7b2007-07-01 12:13:49 -04001717 /*
1718 * Construct the mount server's address.
1719 */
Chuck Lever4c568012007-12-10 14:59:28 -05001720 if (args->mount_server.address.ss_family == AF_UNSPEC) {
Chuck Leverc5d120f2008-12-23 15:21:35 -05001721 memcpy(request.sap, &args->nfs_server.address,
Chuck Lever4c568012007-12-10 14:59:28 -05001722 args->nfs_server.addrlen);
1723 args->mount_server.addrlen = args->nfs_server.addrlen;
1724 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001725 request.salen = args->mount_server.addrlen;
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001726 nfs_set_port(request.sap, &args->mount_server.port, 0);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001727
1728 /*
1729 * Now ask the mount server to map our export path
1730 * to a file handle.
1731 */
Chuck Leverc5d120f2008-12-23 15:21:35 -05001732 status = nfs_mount(&request);
Chuck Leverec88f282009-08-09 15:09:32 -04001733 if (status != 0) {
1734 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1735 request.hostname, status);
1736 return status;
1737 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001738
Chuck Leverec88f282009-08-09 15:09:32 -04001739 /*
1740 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1741 */
1742 if (args->mount_server.version != NFS_MNT3_VERSION)
1743 return 0;
1744 return nfs_walk_authlist(args, &request);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001745}
1746
Rob Landleyc12bace2011-03-09 15:54:13 -06001747/*
1748 * Split "dev_name" into "hostname:export_path".
1749 *
1750 * The leftmost colon demarks the split between the server's hostname
1751 * and the export path. If the hostname starts with a left square
1752 * bracket, then it may contain colons.
1753 *
1754 * Note: caller frees hostname and export path, even on error.
1755 */
1756static int nfs_parse_devname(const char *dev_name,
1757 char **hostname, size_t maxnamlen,
1758 char **export_path, size_t maxpathlen)
Chuck Leverdc045892008-06-23 12:36:37 -04001759{
1760 size_t len;
Rob Landleyc12bace2011-03-09 15:54:13 -06001761 char *end;
Chuck Leverdc045892008-06-23 12:36:37 -04001762
Rob Landleyc12bace2011-03-09 15:54:13 -06001763 /* Is the host name protected with square brakcets? */
1764 if (*dev_name == '[') {
1765 end = strchr(++dev_name, ']');
1766 if (end == NULL || end[1] != ':')
1767 goto out_bad_devname;
Chuck Leverdc045892008-06-23 12:36:37 -04001768
Rob Landleyc12bace2011-03-09 15:54:13 -06001769 len = end - dev_name;
1770 end++;
1771 } else {
1772 char *comma;
1773
1774 end = strchr(dev_name, ':');
1775 if (end == NULL)
1776 goto out_bad_devname;
1777 len = end - dev_name;
1778
1779 /* kill possible hostname list: not supported */
1780 comma = strchr(dev_name, ',');
1781 if (comma != NULL && comma < end)
1782 *comma = 0;
1783 }
1784
Chuck Leverdc045892008-06-23 12:36:37 -04001785 if (len > maxnamlen)
1786 goto out_hostname;
1787
1788 /* N.B. caller will free nfs_server.hostname in all cases */
1789 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
Rob Landleyc12bace2011-03-09 15:54:13 -06001790 if (*hostname == NULL)
Chuck Leverdc045892008-06-23 12:36:37 -04001791 goto out_nomem;
Rob Landleyc12bace2011-03-09 15:54:13 -06001792 len = strlen(++end);
Chuck Leverdc045892008-06-23 12:36:37 -04001793 if (len > maxpathlen)
1794 goto out_path;
Rob Landleyc12bace2011-03-09 15:54:13 -06001795 *export_path = kstrndup(end, len, GFP_KERNEL);
Chuck Leverdc045892008-06-23 12:36:37 -04001796 if (!*export_path)
1797 goto out_nomem;
1798
1799 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1800 return 0;
1801
1802out_bad_devname:
1803 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1804 return -EINVAL;
1805
1806out_nomem:
1807 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1808 return -ENOMEM;
1809
1810out_hostname:
1811 dfprintk(MOUNT, "NFS: server hostname too long\n");
1812 return -ENAMETOOLONG;
1813
1814out_path:
1815 dfprintk(MOUNT, "NFS: export pathname too long\n");
1816 return -ENAMETOOLONG;
1817}
1818
1819/*
David Howells54ceac42006-08-22 20:06:13 -04001820 * Validate the NFS2/NFS3 mount data
1821 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001822 *
1823 * For option strings, user space handles the following behaviors:
1824 *
1825 * + DNS: mapping server host name to IP address ("addr=" option)
1826 *
1827 * + failure mode: how to behave if a mount request can't be handled
1828 * immediately ("fg/bg" option)
1829 *
1830 * + retry: how often to retry a mount request ("retry=" option)
1831 *
1832 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1833 * mountproto=tcp after mountproto=udp, and so on
David Howellsf7b422b2006-06-09 09:34:33 -04001834 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001835static int nfs_validate_mount_data(void *options,
1836 struct nfs_parsed_mount_data *args,
Chuck Lever136d5582007-07-01 12:13:54 -04001837 struct nfs_fh *mntfh,
1838 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001839{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001840 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001841 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
Chuck Lever136d5582007-07-01 12:13:54 -04001842
Chuck Lever5df36e72007-07-01 12:12:56 -04001843 if (data == NULL)
1844 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001845
David Howellsf7b422b2006-06-09 09:34:33 -04001846 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001847 case 1:
1848 data->namlen = 0;
1849 case 2:
1850 data->bsize = 0;
1851 case 3:
1852 if (data->flags & NFS_MOUNT_VER3)
1853 goto out_no_v3;
1854 data->root.size = NFS2_FHSIZE;
1855 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1856 case 4:
1857 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1858 goto out_no_sec;
1859 case 5:
1860 memset(data->context, 0, sizeof(data->context));
1861 case 6:
Trond Myklebustb7e24452008-06-19 15:21:11 -04001862 if (data->flags & NFS_MOUNT_VER3) {
1863 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1864 goto out_invalid_fh;
Chuck Lever5df36e72007-07-01 12:12:56 -04001865 mntfh->size = data->root.size;
Chuck Lever764302c2009-09-08 19:50:03 -04001866 args->version = 3;
1867 } else {
Chuck Lever5df36e72007-07-01 12:12:56 -04001868 mntfh->size = NFS2_FHSIZE;
Chuck Lever764302c2009-09-08 19:50:03 -04001869 args->version = 2;
1870 }
Chuck Lever5df36e72007-07-01 12:12:56 -04001871
Chuck Lever5df36e72007-07-01 12:12:56 -04001872
1873 memcpy(mntfh->data, data->root.data, mntfh->size);
1874 if (mntfh->size < sizeof(mntfh->data))
1875 memset(mntfh->data + mntfh->size, 0,
1876 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001877
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001878 /*
1879 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1880 * can deal with.
1881 */
Trond Myklebustff3525a2008-08-15 16:59:14 -04001882 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
Bryan Schumakerd5eff1a2010-08-03 13:04:00 -04001883 args->flags |= NFS_MOUNT_LEGACY_INTERFACE;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001884 args->rsize = data->rsize;
1885 args->wsize = data->wsize;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001886 args->timeo = data->timeo;
1887 args->retrans = data->retrans;
1888 args->acregmin = data->acregmin;
1889 args->acregmax = data->acregmax;
1890 args->acdirmin = data->acdirmin;
1891 args->acdirmax = data->acdirmax;
Chuck Lever4c568012007-12-10 14:59:28 -05001892
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001893 memcpy(sap, &data->addr, sizeof(data->addr));
Chuck Lever4c568012007-12-10 14:59:28 -05001894 args->nfs_server.addrlen = sizeof(data->addr);
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001895 if (!nfs_verify_server_address(sap))
Chuck Lever4c568012007-12-10 14:59:28 -05001896 goto out_no_address;
1897
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001898 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001899 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001900 /* N.B. caller will free nfs_server.hostname in all cases */
1901 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1902 args->namlen = data->namlen;
1903 args->bsize = data->bsize;
Chuck Leverdd07c942008-06-24 16:33:46 -04001904
1905 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1906 args->auth_flavors[0] = data->pseudoflavor;
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001907 if (!args->nfs_server.hostname)
1908 goto out_nomem;
Eric Parisf9c3a382008-03-05 14:20:18 -05001909
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001910 if (!(data->flags & NFS_MOUNT_NONLM))
1911 args->flags &= ~(NFS_MOUNT_LOCAL_FLOCK|
1912 NFS_MOUNT_LOCAL_FCNTL);
1913 else
1914 args->flags |= (NFS_MOUNT_LOCAL_FLOCK|
1915 NFS_MOUNT_LOCAL_FCNTL);
Eric Parisf9c3a382008-03-05 14:20:18 -05001916 /*
1917 * The legacy version 6 binary mount data from userspace has a
1918 * field used only to transport selinux information into the
1919 * the kernel. To continue to support that functionality we
1920 * have a touch of selinux knowledge here in the NFS code. The
1921 * userspace code converted context=blah to just blah so we are
1922 * converting back to the full string selinux understands.
1923 */
1924 if (data->context[0]){
1925#ifdef CONFIG_SECURITY_SELINUX
1926 int rc;
1927 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1928 if (!opts_str)
1929 return -ENOMEM;
1930 strcpy(opts_str, "context=");
1931 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1932 strcat(opts_str, &data->context[0]);
1933 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1934 kfree(opts_str);
1935 if (rc)
1936 return rc;
1937#else
1938 return -EINVAL;
1939#endif
1940 }
1941
Chuck Lever5df36e72007-07-01 12:12:56 -04001942 break;
Chuck Lever136d5582007-07-01 12:13:54 -04001943 default: {
Chuck Lever136d5582007-07-01 12:13:54 -04001944 int status;
Chuck Lever136d5582007-07-01 12:13:54 -04001945
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001946 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever136d5582007-07-01 12:13:54 -04001947 return -EINVAL;
1948
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001949 if (!nfs_verify_server_address(sap))
Chuck Lever6e88e062007-09-24 15:39:50 -04001950 goto out_no_address;
1951
Chuck Lever764302c2009-09-08 19:50:03 -04001952 if (args->version == 4)
1953#ifdef CONFIG_NFS_V4
1954 return nfs4_validate_text_mount_data(options,
1955 args, dev_name);
1956#else
1957 goto out_v4_not_compiled;
1958#endif
1959
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001960 nfs_set_port(sap, &args->nfs_server.port, 0);
Chuck Levered596a82008-06-26 17:47:05 -04001961
Trond Myklebust259875e2008-07-02 14:43:47 -04001962 nfs_set_mount_transport_protocol(args);
1963
Chuck Leverdc045892008-06-23 12:36:37 -04001964 status = nfs_parse_devname(dev_name,
1965 &args->nfs_server.hostname,
1966 PAGE_SIZE,
1967 &args->nfs_server.export_path,
1968 NFS_MAXPATHLEN);
1969 if (!status)
1970 status = nfs_try_mount(args, mntfh);
Chuck Lever136d5582007-07-01 12:13:54 -04001971
Chuck Leverdc045892008-06-23 12:36:37 -04001972 kfree(args->nfs_server.export_path);
1973 args->nfs_server.export_path = NULL;
Chuck Lever136d5582007-07-01 12:13:54 -04001974
Chuck Lever136d5582007-07-01 12:13:54 -04001975 if (status)
Chuck Leverfdc6e2c2007-08-29 17:58:59 -04001976 return status;
Chuck Lever136d5582007-07-01 12:13:54 -04001977
Chuck Lever136d5582007-07-01 12:13:54 -04001978 break;
1979 }
David Howellsf7b422b2006-06-09 09:34:33 -04001980 }
David Howells54ceac42006-08-22 20:06:13 -04001981
David Howellsf7b422b2006-06-09 09:34:33 -04001982#ifndef CONFIG_NFS_V3
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001983 if (args->version == 3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001984 goto out_v3_not_compiled;
1985#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001986
David Howells54ceac42006-08-22 20:06:13 -04001987 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001988
1989out_no_data:
1990 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1991 return -EINVAL;
1992
1993out_no_v3:
1994 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1995 data->version);
1996 return -EINVAL;
1997
1998out_no_sec:
1999 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
2000 return -EINVAL;
2001
Chuck Lever5df36e72007-07-01 12:12:56 -04002002#ifndef CONFIG_NFS_V3
2003out_v3_not_compiled:
2004 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
2005 return -EPROTONOSUPPORT;
2006#endif /* !CONFIG_NFS_V3 */
2007
Chuck Lever764302c2009-09-08 19:50:03 -04002008#ifndef CONFIG_NFS_V4
2009out_v4_not_compiled:
2010 dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n");
2011 return -EPROTONOSUPPORT;
2012#endif /* !CONFIG_NFS_V4 */
2013
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04002014out_nomem:
2015 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
2016 return -ENOMEM;
2017
Chuck Lever5df36e72007-07-01 12:12:56 -04002018out_no_address:
2019 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
2020 return -EINVAL;
2021
2022out_invalid_fh:
2023 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
2024 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04002025}
2026
Jeff Layton48b605f2008-06-10 15:38:39 -04002027static int
2028nfs_compare_remount_data(struct nfs_server *nfss,
2029 struct nfs_parsed_mount_data *data)
2030{
2031 if (data->flags != nfss->flags ||
2032 data->rsize != nfss->rsize ||
2033 data->wsize != nfss->wsize ||
2034 data->retrans != nfss->client->cl_timeout->to_retries ||
2035 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
2036 data->acregmin != nfss->acregmin / HZ ||
2037 data->acregmax != nfss->acregmax / HZ ||
2038 data->acdirmin != nfss->acdirmin / HZ ||
2039 data->acdirmax != nfss->acdirmax / HZ ||
2040 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
Trond Myklebustbcd2ea12009-10-06 15:41:22 -04002041 data->nfs_server.port != nfss->port ||
Jeff Layton48b605f2008-06-10 15:38:39 -04002042 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
Stefan Richtera1be9ee2009-10-12 11:26:12 -04002043 !rpc_cmp_addr((struct sockaddr *)&data->nfs_server.address,
2044 (struct sockaddr *)&nfss->nfs_client->cl_addr))
Jeff Layton48b605f2008-06-10 15:38:39 -04002045 return -EINVAL;
2046
2047 return 0;
2048}
2049
2050static int
2051nfs_remount(struct super_block *sb, int *flags, char *raw_data)
2052{
2053 int error;
2054 struct nfs_server *nfss = sb->s_fs_info;
2055 struct nfs_parsed_mount_data *data;
2056 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
2057 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
Trond Myklebustcd100722008-06-17 16:12:00 -04002058 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
Jeff Layton48b605f2008-06-10 15:38:39 -04002059
2060 /*
2061 * Userspace mount programs that send binary options generally send
2062 * them populated with default values. We have no way to know which
2063 * ones were explicitly specified. Fall back to legacy behavior and
2064 * just return success.
2065 */
Marc Zyngier31c94462008-07-17 13:21:55 +02002066 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
2067 (nfsvers <= 3 && (!options || (options->version >= 1 &&
2068 options->version <= 6))))
Jeff Layton48b605f2008-06-10 15:38:39 -04002069 return 0;
2070
2071 data = kzalloc(sizeof(*data), GFP_KERNEL);
2072 if (data == NULL)
2073 return -ENOMEM;
2074
2075 /* fill out struct with values from existing mount */
2076 data->flags = nfss->flags;
2077 data->rsize = nfss->rsize;
2078 data->wsize = nfss->wsize;
2079 data->retrans = nfss->client->cl_timeout->to_retries;
2080 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
2081 data->acregmin = nfss->acregmin / HZ;
2082 data->acregmax = nfss->acregmax / HZ;
2083 data->acdirmin = nfss->acdirmin / HZ;
2084 data->acdirmax = nfss->acdirmax / HZ;
2085 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
Trond Myklebustbcd2ea12009-10-06 15:41:22 -04002086 data->nfs_server.port = nfss->port;
Jeff Layton48b605f2008-06-10 15:38:39 -04002087 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
2088 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
2089 data->nfs_server.addrlen);
2090
2091 /* overwrite those values with any that were specified */
2092 error = nfs_parse_mount_options((char *)options, data);
2093 if (error < 0)
2094 goto out;
2095
Jeff Layton26c4c172011-04-27 11:49:09 -04002096 /*
2097 * noac is a special case. It implies -o sync, but that's not
2098 * necessarily reflected in the mtab options. do_remount_sb
2099 * will clear MS_SYNCHRONOUS if -o sync wasn't specified in the
2100 * remount options, so we have to explicitly reset it.
2101 */
2102 if (data->flags & NFS_MOUNT_NOAC)
2103 *flags |= MS_SYNCHRONOUS;
2104
Jeff Layton48b605f2008-06-10 15:38:39 -04002105 /* compare new mount options with old ones */
2106 error = nfs_compare_remount_data(nfss, data);
2107out:
2108 kfree(data);
2109 return error;
2110}
2111
David Howells54ceac42006-08-22 20:06:13 -04002112/*
2113 * Initialise the common bits of the superblock
2114 */
2115static inline void nfs_initialise_sb(struct super_block *sb)
2116{
2117 struct nfs_server *server = NFS_SB(sb);
2118
2119 sb->s_magic = NFS_SUPER_MAGIC;
2120
2121 /* We probably want something more informative here */
2122 snprintf(sb->s_id, sizeof(sb->s_id),
Vivek Trivedi5a7c9ee2012-03-15 23:58:52 +05302123 "%u:%u", MAJOR(sb->s_dev), MINOR(sb->s_dev));
David Howells54ceac42006-08-22 20:06:13 -04002124
2125 if (sb->s_blocksize == 0)
2126 sb->s_blocksize = nfs_block_bits(server->wsize,
2127 &sb->s_blocksize_bits);
2128
Jens Axboe32a88aa2009-09-16 15:02:33 +02002129 sb->s_bdi = &server->backing_dev_info;
2130
David Howells54ceac42006-08-22 20:06:13 -04002131 nfs_super_set_maxbytes(sb, server->maxfilesize);
2132}
2133
2134/*
2135 * Finish setting up an NFS2/3 superblock
2136 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04002137static void nfs_fill_super(struct super_block *sb,
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002138 struct nfs_mount_info *mount_info)
David Howells54ceac42006-08-22 20:06:13 -04002139{
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002140 struct nfs_parsed_mount_data *data = mount_info->parsed;
David Howells54ceac42006-08-22 20:06:13 -04002141 struct nfs_server *server = NFS_SB(sb);
2142
2143 sb->s_blocksize_bits = 0;
2144 sb->s_blocksize = 0;
2145 if (data->bsize)
2146 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
2147
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04002148 if (server->nfs_client->rpc_ops->version == 3) {
David Howells54ceac42006-08-22 20:06:13 -04002149 /* The VFS shouldn't apply the umask to mode bits. We will do
2150 * so ourselves when necessary.
2151 */
2152 sb->s_flags |= MS_POSIXACL;
2153 sb->s_time_gran = 1;
2154 }
2155
2156 sb->s_op = &nfs_sops;
2157 nfs_initialise_sb(sb);
2158}
2159
2160/*
2161 * Finish setting up a cloned NFS2/3 superblock
2162 */
2163static void nfs_clone_super(struct super_block *sb,
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002164 struct nfs_mount_info *mount_info)
David Howells54ceac42006-08-22 20:06:13 -04002165{
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002166 const struct super_block *old_sb = mount_info->cloned->sb;
David Howells54ceac42006-08-22 20:06:13 -04002167 struct nfs_server *server = NFS_SB(sb);
2168
2169 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2170 sb->s_blocksize = old_sb->s_blocksize;
2171 sb->s_maxbytes = old_sb->s_maxbytes;
2172
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04002173 if (server->nfs_client->rpc_ops->version == 3) {
David Howells54ceac42006-08-22 20:06:13 -04002174 /* The VFS shouldn't apply the umask to mode bits. We will do
2175 * so ourselves when necessary.
2176 */
2177 sb->s_flags |= MS_POSIXACL;
2178 sb->s_time_gran = 1;
2179 }
2180
2181 sb->s_op = old_sb->s_op;
2182 nfs_initialise_sb(sb);
2183}
2184
Trond Myklebust275a5d22007-05-16 16:53:28 -04002185static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
2186{
2187 const struct nfs_server *a = s->s_fs_info;
2188 const struct rpc_clnt *clnt_a = a->client;
2189 const struct rpc_clnt *clnt_b = b->client;
2190
2191 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
2192 goto Ebusy;
2193 if (a->nfs_client != b->nfs_client)
2194 goto Ebusy;
2195 if (a->flags != b->flags)
2196 goto Ebusy;
2197 if (a->wsize != b->wsize)
2198 goto Ebusy;
2199 if (a->rsize != b->rsize)
2200 goto Ebusy;
2201 if (a->acregmin != b->acregmin)
2202 goto Ebusy;
2203 if (a->acregmax != b->acregmax)
2204 goto Ebusy;
2205 if (a->acdirmin != b->acdirmin)
2206 goto Ebusy;
2207 if (a->acdirmax != b->acdirmax)
2208 goto Ebusy;
2209 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
2210 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002211 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04002212Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002213 return 0;
2214}
2215
2216struct nfs_sb_mountdata {
2217 struct nfs_server *server;
2218 int mntflags;
2219};
2220
2221static int nfs_set_super(struct super_block *s, void *data)
2222{
2223 struct nfs_sb_mountdata *sb_mntdata = data;
2224 struct nfs_server *server = sb_mntdata->server;
2225 int ret;
2226
2227 s->s_flags = sb_mntdata->mntflags;
2228 s->s_fs_info = server;
Al Viro8b244ff2010-12-18 11:29:39 -05002229 s->s_d_op = server->nfs_client->rpc_ops->dentry_ops;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002230 ret = set_anon_super(s, server);
2231 if (ret == 0)
2232 server->s_dev = s->s_dev;
2233 return ret;
2234}
2235
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002236static int nfs_compare_super_address(struct nfs_server *server1,
2237 struct nfs_server *server2)
2238{
2239 struct sockaddr *sap1, *sap2;
2240
2241 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
2242 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
2243
2244 if (sap1->sa_family != sap2->sa_family)
2245 return 0;
2246
2247 switch (sap1->sa_family) {
2248 case AF_INET: {
2249 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
2250 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
2251 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
2252 return 0;
2253 if (sin1->sin_port != sin2->sin_port)
2254 return 0;
2255 break;
2256 }
2257 case AF_INET6: {
2258 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
2259 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
2260 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
2261 return 0;
2262 if (sin1->sin6_port != sin2->sin6_port)
2263 return 0;
2264 break;
2265 }
2266 default:
2267 return 0;
2268 }
2269
2270 return 1;
2271}
2272
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002273static int nfs_compare_super(struct super_block *sb, void *data)
2274{
2275 struct nfs_sb_mountdata *sb_mntdata = data;
2276 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2277 int mntflags = sb_mntdata->mntflags;
2278
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002279 if (!nfs_compare_super_address(old, server))
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002280 return 0;
2281 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2282 if (old->flags & NFS_MOUNT_UNSHARED)
2283 return 0;
2284 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2285 return 0;
2286 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04002287}
2288
Bryan Schumaker2311b942012-05-10 15:07:32 -04002289static void nfs_get_cache_cookie(struct super_block *sb,
2290 struct nfs_parsed_mount_data *parsed,
2291 struct nfs_clone_mount *cloned)
2292{
2293 char *uniq = NULL;
2294 int ulen = 0;
2295
2296 if (parsed && parsed->fscache_uniq) {
2297 uniq = parsed->fscache_uniq;
2298 ulen = strlen(parsed->fscache_uniq);
2299 } else if (cloned) {
2300 struct nfs_server *mnt_s = NFS_SB(cloned->sb);
2301 if (mnt_s->fscache_key) {
2302 uniq = mnt_s->fscache_key->key.uniquifier;
2303 ulen = mnt_s->fscache_key->key.uniq_len;
2304 };
2305 }
2306
2307 nfs_fscache_get_super_cookie(sb, uniq, ulen);
2308}
2309
Miklos Szeredifa799752008-04-30 00:54:33 -07002310static int nfs_bdi_register(struct nfs_server *server)
2311{
2312 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
2313}
2314
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002315static struct dentry *nfs_fs_mount_common(struct file_system_type *fs_type,
2316 struct nfs_server *server,
2317 int flags, const char *dev_name,
2318 struct nfs_fh *mntfh,
2319 struct nfs_mount_info *mount_info)
David Howells54ceac42006-08-22 20:06:13 -04002320{
David Howells54ceac42006-08-22 20:06:13 -04002321 struct super_block *s;
Al Viro01194982011-03-16 07:25:36 -04002322 struct dentry *mntroot = ERR_PTR(-ENOMEM);
Trond Myklebust75180df2007-05-16 16:53:28 -04002323 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002324 struct nfs_sb_mountdata sb_mntdata = {
2325 .mntflags = flags,
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002326 .server = server,
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002327 };
Al Viro01194982011-03-16 07:25:36 -04002328 int error;
David Howells54ceac42006-08-22 20:06:13 -04002329
Trond Myklebust75180df2007-05-16 16:53:28 -04002330 if (server->flags & NFS_MOUNT_UNSHARED)
2331 compare_super = NULL;
2332
Sachin Prabhufb2088c2011-08-01 12:10:12 +01002333 /* -o noac implies -o sync */
2334 if (server->flags & NFS_MOUNT_NOAC)
2335 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2336
David Howells54ceac42006-08-22 20:06:13 -04002337 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002338 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002339 if (IS_ERR(s)) {
Al Viro01194982011-03-16 07:25:36 -04002340 mntroot = ERR_CAST(s);
David Howells54ceac42006-08-22 20:06:13 -04002341 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04002342 }
2343
David Howells54ceac42006-08-22 20:06:13 -04002344 if (s->s_fs_info != server) {
2345 nfs_free_server(server);
2346 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002347 } else {
2348 error = nfs_bdi_register(server);
Al Viro01194982011-03-16 07:25:36 -04002349 if (error) {
2350 mntroot = ERR_PTR(error);
NeilBrowncfbc0682010-03-11 11:20:17 +11002351 goto error_splat_bdi;
Al Viro01194982011-03-16 07:25:36 -04002352 }
David Howellsf7b422b2006-06-09 09:34:33 -04002353 }
David Howells54ceac42006-08-22 20:06:13 -04002354
2355 if (!s->s_root) {
2356 /* initial superblock/root creation */
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002357 mount_info->fill_super(s, mount_info);
2358 nfs_get_cache_cookie(s, mount_info->parsed, NULL);
David Howells54ceac42006-08-22 20:06:13 -04002359 }
2360
Al Viro0d5839a2011-03-16 05:27:27 -04002361 mntroot = nfs_get_root(s, mntfh, dev_name);
Al Viro01194982011-03-16 07:25:36 -04002362 if (IS_ERR(mntroot))
David Howells54ceac42006-08-22 20:06:13 -04002363 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002364
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002365 error = security_sb_set_mnt_opts(s, &mount_info->parsed->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002366 if (error)
2367 goto error_splat_root;
2368
David Howellsf7b422b2006-06-09 09:34:33 -04002369 s->s_flags |= MS_ACTIVE;
Chuck Lever06559602007-07-01 12:12:35 -04002370
2371out:
Al Viro01194982011-03-16 07:25:36 -04002372 return mntroot;
Trond Myklebust816724e2006-06-24 08:41:41 -04002373
David Howells54ceac42006-08-22 20:06:13 -04002374out_err_nosb:
2375 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04002376 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002377
Eric Parisf9c3a382008-03-05 14:20:18 -05002378error_splat_root:
2379 dput(mntroot);
Al Viro01194982011-03-16 07:25:36 -04002380 mntroot = ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04002381error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002382 if (server && !s->s_root)
2383 bdi_unregister(&server->backing_dev_info);
2384error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002385 deactivate_locked_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04002386 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002387}
2388
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002389static struct dentry *nfs_fs_mount(struct file_system_type *fs_type,
2390 int flags, const char *dev_name, void *raw_data)
2391{
2392 struct nfs_server *server;
2393 struct nfs_parsed_mount_data *data = NULL;
2394 struct nfs_mount_info mount_info = {
2395 .fill_super = nfs_fill_super,
2396 };
2397 struct nfs_fh *mntfh;
2398 struct dentry *mntroot = ERR_PTR(-ENOMEM);
2399 int error;
2400
2401 data = nfs_alloc_parsed_mount_data(NFS_DEFAULT_VERSION);
2402 mntfh = nfs_alloc_fhandle();
2403 if (data == NULL || mntfh == NULL)
2404 goto out;
2405
2406 /* Validate the mount data */
2407 error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
2408 if (error < 0) {
2409 mntroot = ERR_PTR(error);
2410 goto out;
2411 }
2412 mount_info.parsed = data;
2413
2414#ifdef CONFIG_NFS_V4
2415 if (data->version == 4) {
2416 mntroot = nfs4_try_mount(flags, dev_name, data);
2417 goto out;
2418 }
2419#endif /* CONFIG_NFS_V4 */
2420
2421 /* Get a volume representation */
2422 server = nfs_create_server(data, mntfh);
2423 if (IS_ERR(server)) {
2424 mntroot = ERR_CAST(server);
2425 goto out;
2426 }
2427
2428 mntroot = nfs_fs_mount_common(fs_type, server, flags, dev_name, mntfh, &mount_info);
2429out:
2430 nfs_free_parsed_mount_data(data);
2431 nfs_free_fhandle(mntfh);
2432 return mntroot;
2433}
2434
David Howells54ceac42006-08-22 20:06:13 -04002435/*
Trond Myklebust387c1492010-02-03 08:27:35 -05002436 * Ensure that we unregister the bdi before kill_anon_super
2437 * releases the device name
2438 */
2439static void nfs_put_super(struct super_block *s)
2440{
2441 struct nfs_server *server = NFS_SB(s);
2442
2443 bdi_unregister(&server->backing_dev_info);
2444}
2445
2446/*
David Howells54ceac42006-08-22 20:06:13 -04002447 * Destroy an NFS2/3 superblock
2448 */
David Howellsf7b422b2006-06-09 09:34:33 -04002449static void nfs_kill_super(struct super_block *s)
2450{
2451 struct nfs_server *server = NFS_SB(s);
2452
2453 kill_anon_super(s);
David Howells08734042009-04-03 16:42:42 +01002454 nfs_fscache_release_super_cookie(s);
David Howells54ceac42006-08-22 20:06:13 -04002455 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04002456}
2457
David Howells54ceac42006-08-22 20:06:13 -04002458/*
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002459 * Clone an NFS2/3/4 server record on xdev traversal (FSID-change)
David Howells54ceac42006-08-22 20:06:13 -04002460 */
Al Viro31f43472010-10-29 03:38:12 -04002461static struct dentry *
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002462nfs_xdev_mount_common(struct file_system_type *fs_type, int flags,
2463 const char *dev_name, struct nfs_mount_info *mount_info)
David Howellsf7b422b2006-06-09 09:34:33 -04002464{
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002465 struct nfs_clone_mount *data = mount_info->cloned;
David Howells54ceac42006-08-22 20:06:13 -04002466 struct super_block *s;
2467 struct nfs_server *server;
2468 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002469 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002470 struct nfs_sb_mountdata sb_mntdata = {
2471 .mntflags = flags,
2472 };
David Howells54ceac42006-08-22 20:06:13 -04002473 int error;
2474
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002475 dprintk("--> nfs_xdev_mount_common()\n");
David Howells54ceac42006-08-22 20:06:13 -04002476
2477 /* create a new volume representation */
Bryan Schumaker7e6eb682012-04-27 13:27:42 -04002478 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr, data->authflavor);
David Howells54ceac42006-08-22 20:06:13 -04002479 if (IS_ERR(server)) {
2480 error = PTR_ERR(server);
2481 goto out_err_noserver;
2482 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002483 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002484
Trond Myklebust75180df2007-05-16 16:53:28 -04002485 if (server->flags & NFS_MOUNT_UNSHARED)
2486 compare_super = NULL;
2487
Sachin Prabhufb2088c2011-08-01 12:10:12 +01002488 /* -o noac implies -o sync */
2489 if (server->flags & NFS_MOUNT_NOAC)
2490 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2491
David Howells54ceac42006-08-22 20:06:13 -04002492 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002493 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002494 if (IS_ERR(s)) {
2495 error = PTR_ERR(s);
2496 goto out_err_nosb;
2497 }
2498
2499 if (s->s_fs_info != server) {
2500 nfs_free_server(server);
2501 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002502 } else {
2503 error = nfs_bdi_register(server);
2504 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11002505 goto error_splat_bdi;
David Howells54ceac42006-08-22 20:06:13 -04002506 }
2507
2508 if (!s->s_root) {
2509 /* initial superblock/root creation */
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002510 mount_info->fill_super(s, mount_info);
Bryan Schumaker2311b942012-05-10 15:07:32 -04002511 nfs_get_cache_cookie(s, NULL, data);
David Howells54ceac42006-08-22 20:06:13 -04002512 }
2513
Al Viro0d5839a2011-03-16 05:27:27 -04002514 mntroot = nfs_get_root(s, data->fh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04002515 if (IS_ERR(mntroot)) {
2516 error = PTR_ERR(mntroot);
2517 goto error_splat_super;
2518 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002519 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
Neil Brown4c1fe2f2007-11-01 16:50:20 +11002520 dput(mntroot);
2521 error = -ESTALE;
2522 goto error_splat_super;
2523 }
David Howells54ceac42006-08-22 20:06:13 -04002524
2525 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002526
Eric Parisf9c3a382008-03-05 14:20:18 -05002527 /* clone any lsm security options from the parent to the new sb */
2528 security_sb_clone_mnt_opts(data->sb, s);
2529
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002530 dprintk("<-- nfs_xdev_mount_common() = 0\n");
Al Viro31f43472010-10-29 03:38:12 -04002531 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04002532
2533out_err_nosb:
2534 nfs_free_server(server);
2535out_err_noserver:
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002536 dprintk("<-- nfs_xdev_mount_common() = %d [error]\n", error);
Al Viro31f43472010-10-29 03:38:12 -04002537 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04002538
2539error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002540 if (server && !s->s_root)
2541 bdi_unregister(&server->backing_dev_info);
2542error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002543 deactivate_locked_super(s);
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002544 dprintk("<-- nfs_xdev_mount_common() = %d [splat]\n", error);
Al Viro31f43472010-10-29 03:38:12 -04002545 return ERR_PTR(error);
David Howellsf7b422b2006-06-09 09:34:33 -04002546}
2547
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002548/*
2549 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2550 */
2551static struct dentry *
2552nfs_xdev_mount(struct file_system_type *fs_type, int flags,
2553 const char *dev_name, void *raw_data)
2554{
2555 struct nfs_mount_info mount_info = {
2556 .fill_super = nfs_clone_super,
2557 .cloned = raw_data,
2558 };
2559 return nfs_xdev_mount_common(&nfs_fs_type, flags, dev_name, &mount_info);
2560}
2561
David Howellsf7b422b2006-06-09 09:34:33 -04002562#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04002563
2564/*
2565 * Finish setting up a cloned NFS4 superblock
2566 */
2567static void nfs4_clone_super(struct super_block *sb,
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002568 struct nfs_mount_info *mount_info)
David Howellsf7b422b2006-06-09 09:34:33 -04002569{
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002570 const struct super_block *old_sb = mount_info->cloned->sb;
David Howells54ceac42006-08-22 20:06:13 -04002571 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2572 sb->s_blocksize = old_sb->s_blocksize;
2573 sb->s_maxbytes = old_sb->s_maxbytes;
2574 sb->s_time_gran = 1;
2575 sb->s_op = old_sb->s_op;
Aneesh Kumar K.Va8a5da92010-12-09 11:35:14 +00002576 /*
2577 * The VFS shouldn't apply the umask to mode bits. We will do
2578 * so ourselves when necessary.
2579 */
2580 sb->s_flags |= MS_POSIXACL;
Aneesh Kumar K.V64c2ce82010-12-09 11:35:25 +00002581 sb->s_xattr = old_sb->s_xattr;
2582 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002583}
2584
2585/*
2586 * Set up an NFS4 superblock
2587 */
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002588static void nfs4_fill_super(struct super_block *sb,
2589 struct nfs_mount_info *mount_info)
David Howellsf7b422b2006-06-09 09:34:33 -04002590{
David Howellsf7b422b2006-06-09 09:34:33 -04002591 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04002592 sb->s_op = &nfs4_sops;
Aneesh Kumar K.Va8a5da92010-12-09 11:35:14 +00002593 /*
2594 * The VFS shouldn't apply the umask to mode bits. We will do
2595 * so ourselves when necessary.
2596 */
2597 sb->s_flags |= MS_POSIXACL;
Aneesh Kumar K.V64c2ce82010-12-09 11:35:25 +00002598 sb->s_xattr = nfs4_xattr_handlers;
David Howells54ceac42006-08-22 20:06:13 -04002599 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002600}
2601
Trond Myklebust01c3f052009-06-17 13:22:58 -07002602static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2603{
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04002604 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3|
2605 NFS_MOUNT_LOCAL_FLOCK|NFS_MOUNT_LOCAL_FCNTL);
Trond Myklebust01c3f052009-06-17 13:22:58 -07002606}
2607
Chuck Lever7630c852009-09-08 19:49:57 -04002608static int nfs4_validate_text_mount_data(void *options,
2609 struct nfs_parsed_mount_data *args,
2610 const char *dev_name)
2611{
2612 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2613
Trond Myklebustf5855fe2009-10-06 15:40:37 -04002614 nfs_set_port(sap, &args->nfs_server.port, NFS_PORT);
Chuck Lever7630c852009-09-08 19:49:57 -04002615
2616 nfs_validate_transport_protocol(args);
2617
2618 nfs4_validate_mount_flags(args);
2619
Trond Myklebust2ecda722009-09-08 19:50:07 -04002620 if (args->version != 4) {
2621 dfprintk(MOUNT,
2622 "NFS4: Illegal mount version\n");
2623 return -EINVAL;
2624 }
2625
Chuck Lever7630c852009-09-08 19:49:57 -04002626 if (args->auth_flavor_len > 1) {
2627 dfprintk(MOUNT,
2628 "NFS4: Too many RPC auth flavours specified\n");
2629 return -EINVAL;
2630 }
2631
Chuck Lever7630c852009-09-08 19:49:57 -04002632 return nfs_parse_devname(dev_name,
2633 &args->nfs_server.hostname,
2634 NFS4_MAXNAMLEN,
2635 &args->nfs_server.export_path,
2636 NFS4_MAXPATHLEN);
2637}
2638
David Howells54ceac42006-08-22 20:06:13 -04002639/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04002640 * Validate NFSv4 mount options
2641 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002642static int nfs4_validate_mount_data(void *options,
2643 struct nfs_parsed_mount_data *args,
2644 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04002645{
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002646 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002647 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002648 char *c;
2649
2650 if (data == NULL)
2651 goto out_no_data;
2652
2653 switch (data->version) {
2654 case 1:
Chuck Lever4c568012007-12-10 14:59:28 -05002655 if (data->host_addrlen > sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002656 goto out_no_address;
Chuck Lever4c568012007-12-10 14:59:28 -05002657 if (data->host_addrlen == 0)
2658 goto out_no_address;
2659 args->nfs_server.addrlen = data->host_addrlen;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002660 if (copy_from_user(sap, data->host_addr, data->host_addrlen))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002661 return -EFAULT;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002662 if (!nfs_verify_server_address(sap))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002663 goto out_no_address;
2664
Chuck Lever6738b252008-06-24 16:33:54 -04002665 if (data->auth_flavourlen) {
2666 if (data->auth_flavourlen > 1)
2667 goto out_inval_auth;
Trond Myklebust20c71f52007-09-20 20:23:51 -04002668 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002669 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04002670 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002671 return -EFAULT;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002672 }
2673
2674 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2675 if (IS_ERR(c))
2676 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002677 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002678
2679 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2680 if (IS_ERR(c))
2681 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002682 args->nfs_server.export_path = c;
2683 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002684
2685 c = strndup_user(data->client_addr.data, 16);
2686 if (IS_ERR(c))
2687 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002688 args->client_address = c;
2689
2690 /*
2691 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2692 * can deal with.
2693 */
2694
2695 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2696 args->rsize = data->rsize;
2697 args->wsize = data->wsize;
2698 args->timeo = data->timeo;
2699 args->retrans = data->retrans;
2700 args->acregmin = data->acregmin;
2701 args->acregmax = data->acregmax;
2702 args->acdirmin = data->acdirmin;
2703 args->acdirmax = data->acdirmax;
2704 args->nfs_server.protocol = data->proto;
Trond Myklebust259875e2008-07-02 14:43:47 -04002705 nfs_validate_transport_protocol(args);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002706
2707 break;
Chuck Lever7630c852009-09-08 19:49:57 -04002708 default:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002709 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever80071222007-07-01 12:13:59 -04002710 return -EINVAL;
2711
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002712 if (!nfs_verify_server_address(sap))
Chuck Lever80071222007-07-01 12:13:59 -04002713 return -EINVAL;
Chuck Levered596a82008-06-26 17:47:05 -04002714
Chuck Lever7630c852009-09-08 19:49:57 -04002715 return nfs4_validate_text_mount_data(options, args, dev_name);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002716 }
2717
2718 return 0;
2719
2720out_no_data:
2721 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2722 return -EINVAL;
2723
2724out_inval_auth:
2725 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2726 data->auth_flavourlen);
2727 return -EINVAL;
2728
2729out_no_address:
2730 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2731 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002732}
2733
2734/*
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002735 * Get the superblock for the NFS4 root partition
David Howells54ceac42006-08-22 20:06:13 -04002736 */
Al Viro31f43472010-10-29 03:38:12 -04002737static struct dentry *
2738nfs4_remote_mount(struct file_system_type *fs_type, int flags,
2739 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002740{
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002741 struct nfs_mount_info mount_info = {
2742 .fill_super = nfs4_fill_super,
2743 .parsed = raw_data,
2744 };
David Howells54ceac42006-08-22 20:06:13 -04002745 struct nfs_server *server;
Trond Myklebust33852a12008-06-19 14:20:11 -04002746 struct nfs_fh *mntfh;
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002747 struct dentry *mntroot = ERR_PTR(-ENOMEM);
David Howellsf7b422b2006-06-09 09:34:33 -04002748
Trond Myklebustb157b062010-04-19 19:05:48 -04002749 mntfh = nfs_alloc_fhandle();
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002750 if (mount_info.parsed == NULL || mntfh == NULL)
Jeff Layton8a0d5512011-12-20 06:57:45 -05002751 goto out;
Eric Parisf9c3a382008-03-05 14:20:18 -05002752
David Howells54ceac42006-08-22 20:06:13 -04002753 /* Get a volume representation */
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002754 server = nfs4_create_server(mount_info.parsed, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002755 if (IS_ERR(server)) {
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002756 mntroot = ERR_CAST(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04002757 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002758 }
2759
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002760 mntroot = nfs_fs_mount_common(fs_type, server, flags,
2761 dev_name, mntfh, &mount_info);
David Howells54ceac42006-08-22 20:06:13 -04002762
Chuck Lever29eb9812007-07-01 12:12:30 -04002763out:
Trond Myklebustb157b062010-04-19 19:05:48 -04002764 nfs_free_fhandle(mntfh);
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002765 return mntroot;
David Howellsf7b422b2006-06-09 09:34:33 -04002766}
2767
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002768static struct vfsmount *nfs_do_root_mount(struct file_system_type *fs_type,
2769 int flags, void *data, const char *hostname)
2770{
2771 struct vfsmount *root_mnt;
2772 char *root_devname;
2773 size_t len;
2774
Jan Kara98a21392011-09-03 01:09:43 +02002775 len = strlen(hostname) + 5;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002776 root_devname = kmalloc(len, GFP_KERNEL);
2777 if (root_devname == NULL)
2778 return ERR_PTR(-ENOMEM);
Jan Kara98a21392011-09-03 01:09:43 +02002779 /* Does hostname needs to be enclosed in brackets? */
2780 if (strchr(hostname, ':'))
2781 snprintf(root_devname, len, "[%s]:/", hostname);
2782 else
2783 snprintf(root_devname, len, "%s:/", hostname);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002784 root_mnt = vfs_kern_mount(fs_type, flags, root_devname, data);
2785 kfree(root_devname);
2786 return root_mnt;
2787}
2788
Trond Myklebustce587e02010-04-16 16:22:52 -04002789struct nfs_referral_count {
2790 struct list_head list;
2791 const struct task_struct *task;
2792 unsigned int referral_count;
2793};
2794
2795static LIST_HEAD(nfs_referral_count_list);
2796static DEFINE_SPINLOCK(nfs_referral_count_list_lock);
2797
2798static struct nfs_referral_count *nfs_find_referral_count(void)
2799{
2800 struct nfs_referral_count *p;
2801
2802 list_for_each_entry(p, &nfs_referral_count_list, list) {
2803 if (p->task == current)
2804 return p;
2805 }
2806 return NULL;
2807}
2808
2809#define NFS_MAX_NESTED_REFERRALS 2
2810
2811static int nfs_referral_loop_protect(void)
2812{
2813 struct nfs_referral_count *p, *new;
2814 int ret = -ENOMEM;
2815
2816 new = kmalloc(sizeof(*new), GFP_KERNEL);
2817 if (!new)
2818 goto out;
2819 new->task = current;
2820 new->referral_count = 1;
2821
2822 ret = 0;
2823 spin_lock(&nfs_referral_count_list_lock);
2824 p = nfs_find_referral_count();
2825 if (p != NULL) {
2826 if (p->referral_count >= NFS_MAX_NESTED_REFERRALS)
2827 ret = -ELOOP;
2828 else
2829 p->referral_count++;
2830 } else {
2831 list_add(&new->list, &nfs_referral_count_list);
2832 new = NULL;
2833 }
2834 spin_unlock(&nfs_referral_count_list_lock);
2835 kfree(new);
2836out:
2837 return ret;
2838}
2839
2840static void nfs_referral_loop_unprotect(void)
2841{
2842 struct nfs_referral_count *p;
2843
2844 spin_lock(&nfs_referral_count_list_lock);
2845 p = nfs_find_referral_count();
2846 p->referral_count--;
2847 if (p->referral_count == 0)
2848 list_del(&p->list);
2849 else
2850 p = NULL;
2851 spin_unlock(&nfs_referral_count_list_lock);
2852 kfree(p);
2853}
2854
Al Viro01194982011-03-16 07:25:36 -04002855static struct dentry *nfs_follow_remote_path(struct vfsmount *root_mnt,
2856 const char *export_path)
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002857{
Al Viro01194982011-03-16 07:25:36 -04002858 struct dentry *dentry;
Al Viro5352d3b2011-11-16 21:52:06 -05002859 int err;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002860
Al Viro5352d3b2011-11-16 21:52:06 -05002861 if (IS_ERR(root_mnt))
2862 return ERR_CAST(root_mnt);
2863
2864 err = nfs_referral_loop_protect();
2865 if (err) {
Al Viroea441d12011-11-16 21:43:59 -05002866 mntput(root_mnt);
Al Viro5352d3b2011-11-16 21:52:06 -05002867 return ERR_PTR(err);
Al Viroc1334492011-11-16 16:12:14 -05002868 }
Trond Myklebustce587e02010-04-16 16:22:52 -04002869
Al Viroea441d12011-11-16 21:43:59 -05002870 dentry = mount_subtree(root_mnt, export_path);
2871 nfs_referral_loop_unprotect();
Linus Torvaldsa2770d82009-12-17 12:51:05 -08002872
Al Viro01194982011-03-16 07:25:36 -04002873 return dentry;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002874}
2875
Al Viro01194982011-03-16 07:25:36 -04002876static struct dentry *nfs4_try_mount(int flags, const char *dev_name,
2877 struct nfs_parsed_mount_data *data)
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002878{
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002879 char *export_path;
2880 struct vfsmount *root_mnt;
Al Viro01194982011-03-16 07:25:36 -04002881 struct dentry *res;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002882
Chuck Levera6fe23b2009-09-08 19:50:00 -04002883 dfprintk(MOUNT, "--> nfs4_try_mount()\n");
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002884
2885 export_path = data->nfs_server.export_path;
2886 data->nfs_server.export_path = "/";
2887 root_mnt = nfs_do_root_mount(&nfs4_remote_fs_type, flags, data,
2888 data->nfs_server.hostname);
2889 data->nfs_server.export_path = export_path;
2890
Al Viro5352d3b2011-11-16 21:52:06 -05002891 res = nfs_follow_remote_path(root_mnt, export_path);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002892
Al Viro01194982011-03-16 07:25:36 -04002893 dfprintk(MOUNT, "<-- nfs4_try_mount() = %ld%s\n",
2894 IS_ERR(res) ? PTR_ERR(res) : 0,
2895 IS_ERR(res) ? " [error]" : "");
2896 return res;
Chuck Levera6fe23b2009-09-08 19:50:00 -04002897}
2898
2899/*
2900 * Get the superblock for an NFS4 mountpoint
2901 */
Al Viro01194982011-03-16 07:25:36 -04002902static struct dentry *nfs4_mount(struct file_system_type *fs_type,
2903 int flags, const char *dev_name, void *raw_data)
Chuck Levera6fe23b2009-09-08 19:50:00 -04002904{
2905 struct nfs_parsed_mount_data *data;
2906 int error = -ENOMEM;
Al Viro01194982011-03-16 07:25:36 -04002907 struct dentry *res = ERR_PTR(-ENOMEM);
Chuck Levera6fe23b2009-09-08 19:50:00 -04002908
Trond Myklebustc5811db2009-10-06 15:40:15 -04002909 data = nfs_alloc_parsed_mount_data(4);
Chuck Levera6fe23b2009-09-08 19:50:00 -04002910 if (data == NULL)
Jeff Layton8a0d5512011-12-20 06:57:45 -05002911 goto out;
Chuck Levera6fe23b2009-09-08 19:50:00 -04002912
2913 /* Validate the mount data */
2914 error = nfs4_validate_mount_data(raw_data, data, dev_name);
Al Viro01194982011-03-16 07:25:36 -04002915 if (error < 0) {
2916 res = ERR_PTR(error);
Chuck Levera6fe23b2009-09-08 19:50:00 -04002917 goto out;
Al Viro01194982011-03-16 07:25:36 -04002918 }
Chuck Levera6fe23b2009-09-08 19:50:00 -04002919
Al Viro01194982011-03-16 07:25:36 -04002920 res = nfs4_try_mount(flags, dev_name, data);
2921 if (IS_ERR(res))
2922 error = PTR_ERR(res);
Chuck Levera6fe23b2009-09-08 19:50:00 -04002923
2924out:
Jeff Layton8a0d5512011-12-20 06:57:45 -05002925 nfs_free_parsed_mount_data(data);
Al Viro01194982011-03-16 07:25:36 -04002926 dprintk("<-- nfs4_mount() = %d%s\n", error,
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002927 error != 0 ? " [error]" : "");
Al Viro01194982011-03-16 07:25:36 -04002928 return res;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002929}
2930
David Howellsf7b422b2006-06-09 09:34:33 -04002931static void nfs4_kill_super(struct super_block *sb)
2932{
2933 struct nfs_server *server = NFS_SB(sb);
2934
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002935 dprintk("--> %s\n", __func__);
Trond Myklebust515d8612008-12-23 15:21:46 -05002936 nfs_super_return_all_delegations(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002937 kill_anon_super(sb);
David Howells08734042009-04-03 16:42:42 +01002938 nfs_fscache_release_super_cookie(sb);
David Howells54ceac42006-08-22 20:06:13 -04002939 nfs_free_server(server);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002940 dprintk("<-- %s\n", __func__);
David Howellsf7b422b2006-06-09 09:34:33 -04002941}
2942
2943/*
David Howells54ceac42006-08-22 20:06:13 -04002944 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -04002945 */
Al Viro31f43472010-10-29 03:38:12 -04002946static struct dentry *
2947nfs4_xdev_mount(struct file_system_type *fs_type, int flags,
2948 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002949{
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002950 struct nfs_mount_info mount_info = {
2951 .fill_super = nfs4_clone_super,
2952 .cloned = raw_data,
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002953 };
Bryan Schumaker8c958e02012-05-10 15:07:35 -04002954 return nfs_xdev_mount_common(&nfs4_fs_type, flags, dev_name, &mount_info);
David Howellsf7b422b2006-06-09 09:34:33 -04002955}
2956
Al Viro31f43472010-10-29 03:38:12 -04002957static struct dentry *
2958nfs4_remote_referral_mount(struct file_system_type *fs_type, int flags,
2959 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002960{
2961 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002962 struct super_block *s;
2963 struct nfs_server *server;
2964 struct dentry *mntroot;
Trond Myklebust4f727292010-04-16 16:22:48 -04002965 struct nfs_fh *mntfh;
Trond Myklebust75180df2007-05-16 16:53:28 -04002966 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002967 struct nfs_sb_mountdata sb_mntdata = {
2968 .mntflags = flags,
2969 };
Trond Myklebust4f727292010-04-16 16:22:48 -04002970 int error = -ENOMEM;
David Howells54ceac42006-08-22 20:06:13 -04002971
2972 dprintk("--> nfs4_referral_get_sb()\n");
2973
Trond Myklebust4f727292010-04-16 16:22:48 -04002974 mntfh = nfs_alloc_fhandle();
2975 if (mntfh == NULL)
2976 goto out_err_nofh;
2977
David Howells54ceac42006-08-22 20:06:13 -04002978 /* create a new volume representation */
Trond Myklebust4f727292010-04-16 16:22:48 -04002979 server = nfs4_create_referral_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002980 if (IS_ERR(server)) {
2981 error = PTR_ERR(server);
2982 goto out_err_noserver;
2983 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002984 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002985
Bryan Schumaker586f95c2012-05-10 15:07:33 -04002986 if (server->flags & NFS_MOUNT_UNSHARED)
Trond Myklebust75180df2007-05-16 16:53:28 -04002987 compare_super = NULL;
2988
Sachin Prabhufb2088c2011-08-01 12:10:12 +01002989 /* -o noac implies -o sync */
2990 if (server->flags & NFS_MOUNT_NOAC)
2991 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2992
David Howells54ceac42006-08-22 20:06:13 -04002993 /* Get a superblock - note that we may end up sharing one that already exists */
Andy Adamsonec9a05c2008-10-17 10:44:37 -04002994 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002995 if (IS_ERR(s)) {
2996 error = PTR_ERR(s);
2997 goto out_err_nosb;
2998 }
2999
3000 if (s->s_fs_info != server) {
3001 nfs_free_server(server);
3002 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07003003 } else {
3004 error = nfs_bdi_register(server);
3005 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11003006 goto error_splat_bdi;
David Howells54ceac42006-08-22 20:06:13 -04003007 }
3008
3009 if (!s->s_root) {
3010 /* initial superblock/root creation */
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04003011 nfs4_fill_super(s, NULL);
Bryan Schumaker2311b942012-05-10 15:07:32 -04003012 nfs_get_cache_cookie(s, NULL, data);
David Howells54ceac42006-08-22 20:06:13 -04003013 }
3014
Bryan Schumakerbae36242012-05-10 15:07:31 -04003015 mntroot = nfs_get_root(s, mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04003016 if (IS_ERR(mntroot)) {
3017 error = PTR_ERR(mntroot);
3018 goto error_splat_super;
3019 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05003020 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
3021 dput(mntroot);
3022 error = -ESTALE;
3023 goto error_splat_super;
3024 }
David Howells54ceac42006-08-22 20:06:13 -04003025
3026 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04003027
Eric Paris46c8ac72008-05-02 13:42:42 -07003028 security_sb_clone_mnt_opts(data->sb, s);
3029
Trond Myklebust4f727292010-04-16 16:22:48 -04003030 nfs_free_fhandle(mntfh);
David Howells54ceac42006-08-22 20:06:13 -04003031 dprintk("<-- nfs4_referral_get_sb() = 0\n");
Al Viro31f43472010-10-29 03:38:12 -04003032 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04003033
3034out_err_nosb:
3035 nfs_free_server(server);
3036out_err_noserver:
Trond Myklebust4f727292010-04-16 16:22:48 -04003037 nfs_free_fhandle(mntfh);
3038out_err_nofh:
David Howells54ceac42006-08-22 20:06:13 -04003039 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
Al Viro31f43472010-10-29 03:38:12 -04003040 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04003041
3042error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11003043 if (server && !s->s_root)
3044 bdi_unregister(&server->backing_dev_info);
3045error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04003046 deactivate_locked_super(s);
Trond Myklebust4f727292010-04-16 16:22:48 -04003047 nfs_free_fhandle(mntfh);
David Howells54ceac42006-08-22 20:06:13 -04003048 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
Al Viro31f43472010-10-29 03:38:12 -04003049 return ERR_PTR(error);
David Howellsf7b422b2006-06-09 09:34:33 -04003050}
3051
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04003052/*
3053 * Create an NFS4 server record on referral traversal
3054 */
Al Viro01194982011-03-16 07:25:36 -04003055static struct dentry *nfs4_referral_mount(struct file_system_type *fs_type,
3056 int flags, const char *dev_name, void *raw_data)
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04003057{
3058 struct nfs_clone_mount *data = raw_data;
3059 char *export_path;
3060 struct vfsmount *root_mnt;
Al Viro01194982011-03-16 07:25:36 -04003061 struct dentry *res;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04003062
Al Viro01194982011-03-16 07:25:36 -04003063 dprintk("--> nfs4_referral_mount()\n");
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04003064
3065 export_path = data->mnt_path;
3066 data->mnt_path = "/";
3067
3068 root_mnt = nfs_do_root_mount(&nfs4_remote_referral_fs_type,
3069 flags, data, data->hostname);
3070 data->mnt_path = export_path;
3071
Al Viro5352d3b2011-11-16 21:52:06 -05003072 res = nfs_follow_remote_path(root_mnt, export_path);
Al Viro01194982011-03-16 07:25:36 -04003073 dprintk("<-- nfs4_referral_mount() = %ld%s\n",
3074 IS_ERR(res) ? PTR_ERR(res) : 0,
3075 IS_ERR(res) ? " [error]" : "");
3076 return res;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04003077}
3078
David Howells54ceac42006-08-22 20:06:13 -04003079#endif /* CONFIG_NFS_V4 */