blob: 64a62da6612df4b587ad19b68ea22c06b86cea00 [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;
283};
284
Al Viro42faad92008-04-24 07:21:56 -0400285static void nfs_umount_begin(struct super_block *);
Trond Myklebust816724e2006-06-24 08:41:41 -0400286static int nfs_statfs(struct dentry *, struct kstatfs *);
Al Viro34c80b12011-12-08 21:32:45 -0500287static int nfs_show_options(struct seq_file *, struct dentry *);
Al Virod861c632011-12-08 21:32:45 -0500288static int nfs_show_devname(struct seq_file *, struct dentry *);
Al Viroa6322de2011-12-08 21:37:57 -0500289static int nfs_show_path(struct seq_file *, struct dentry *);
Al Viro64132372011-12-08 20:51:13 -0500290static int nfs_show_stats(struct seq_file *, struct dentry *);
Al Viro01194982011-03-16 07:25:36 -0400291static struct dentry *nfs_fs_mount(struct file_system_type *,
292 int, const char *, void *);
Al Viro31f43472010-10-29 03:38:12 -0400293static struct dentry *nfs_xdev_mount(struct file_system_type *fs_type,
294 int flags, const char *dev_name, void *raw_data);
Trond Myklebust387c1492010-02-03 08:27:35 -0500295static void nfs_put_super(struct super_block *);
David Howellsf7b422b2006-06-09 09:34:33 -0400296static void nfs_kill_super(struct super_block *);
Jeff Layton48b605f2008-06-10 15:38:39 -0400297static int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
David Howellsf7b422b2006-06-09 09:34:33 -0400298
299static struct file_system_type nfs_fs_type = {
300 .owner = THIS_MODULE,
301 .name = "nfs",
Al Viro01194982011-03-16 07:25:36 -0400302 .mount = nfs_fs_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400303 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700304 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400305};
306
David Howells54ceac42006-08-22 20:06:13 -0400307struct file_system_type nfs_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400308 .owner = THIS_MODULE,
309 .name = "nfs",
Al Viro31f43472010-10-29 03:38:12 -0400310 .mount = nfs_xdev_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400311 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700312 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400313};
314
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800315static const struct super_operations nfs_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400316 .alloc_inode = nfs_alloc_inode,
317 .destroy_inode = nfs_destroy_inode,
318 .write_inode = nfs_write_inode,
Trond Myklebust387c1492010-02-03 08:27:35 -0500319 .put_super = nfs_put_super,
David Howellsf7b422b2006-06-09 09:34:33 -0400320 .statfs = nfs_statfs,
Al Virob57922d2010-06-07 14:34:48 -0400321 .evict_inode = nfs_evict_inode,
David Howellsf7b422b2006-06-09 09:34:33 -0400322 .umount_begin = nfs_umount_begin,
323 .show_options = nfs_show_options,
Al Viroc7f404b2011-03-16 06:59:40 -0400324 .show_devname = nfs_show_devname,
325 .show_path = nfs_show_path,
David Howellsf7b422b2006-06-09 09:34:33 -0400326 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400327 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400328};
329
330#ifdef CONFIG_NFS_V4
Chuck Lever7630c852009-09-08 19:49:57 -0400331static int nfs4_validate_text_mount_data(void *options,
332 struct nfs_parsed_mount_data *args, const char *dev_name);
Al Viro01194982011-03-16 07:25:36 -0400333static struct dentry *nfs4_try_mount(int flags, const char *dev_name,
334 struct nfs_parsed_mount_data *data);
335static struct dentry *nfs4_mount(struct file_system_type *fs_type,
336 int flags, const char *dev_name, void *raw_data);
Al Viro31f43472010-10-29 03:38:12 -0400337static struct dentry *nfs4_remote_mount(struct file_system_type *fs_type,
338 int flags, const char *dev_name, void *raw_data);
339static struct dentry *nfs4_xdev_mount(struct file_system_type *fs_type,
340 int flags, const char *dev_name, void *raw_data);
Al Viro01194982011-03-16 07:25:36 -0400341static struct dentry *nfs4_referral_mount(struct file_system_type *fs_type,
342 int flags, const char *dev_name, void *raw_data);
Al Viro31f43472010-10-29 03:38:12 -0400343static struct dentry *nfs4_remote_referral_mount(struct file_system_type *fs_type,
344 int flags, const char *dev_name, void *raw_data);
David Howellsf7b422b2006-06-09 09:34:33 -0400345static void nfs4_kill_super(struct super_block *sb);
346
347static struct file_system_type nfs4_fs_type = {
348 .owner = THIS_MODULE,
349 .name = "nfs4",
Al Viro01194982011-03-16 07:25:36 -0400350 .mount = nfs4_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400351 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700352 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400353};
354
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400355static struct file_system_type nfs4_remote_fs_type = {
356 .owner = THIS_MODULE,
357 .name = "nfs4",
Al Viro31f43472010-10-29 03:38:12 -0400358 .mount = nfs4_remote_mount,
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400359 .kill_sb = nfs4_kill_super,
360 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
361};
362
David Howells54ceac42006-08-22 20:06:13 -0400363struct file_system_type nfs4_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400364 .owner = THIS_MODULE,
365 .name = "nfs4",
Al Viro31f43472010-10-29 03:38:12 -0400366 .mount = nfs4_xdev_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400367 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700368 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400369};
370
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400371static struct file_system_type nfs4_remote_referral_fs_type = {
372 .owner = THIS_MODULE,
373 .name = "nfs4",
Al Viro31f43472010-10-29 03:38:12 -0400374 .mount = nfs4_remote_referral_mount,
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400375 .kill_sb = nfs4_kill_super,
376 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
377};
378
David Howells54ceac42006-08-22 20:06:13 -0400379struct file_system_type nfs4_referral_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400380 .owner = THIS_MODULE,
381 .name = "nfs4",
Al Viro01194982011-03-16 07:25:36 -0400382 .mount = nfs4_referral_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400383 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700384 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400385};
386
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800387static const struct super_operations nfs4_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400388 .alloc_inode = nfs_alloc_inode,
389 .destroy_inode = nfs_destroy_inode,
390 .write_inode = nfs_write_inode,
Trond Myklebust387c1492010-02-03 08:27:35 -0500391 .put_super = nfs_put_super,
David Howellsf7b422b2006-06-09 09:34:33 -0400392 .statfs = nfs_statfs,
Al Virob57922d2010-06-07 14:34:48 -0400393 .evict_inode = nfs4_evict_inode,
David Howellsf7b422b2006-06-09 09:34:33 -0400394 .umount_begin = nfs_umount_begin,
395 .show_options = nfs_show_options,
Al Viroc7f404b2011-03-16 06:59:40 -0400396 .show_devname = nfs_show_devname,
397 .show_path = nfs_show_path,
David Howellsf7b422b2006-06-09 09:34:33 -0400398 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400399 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400400};
401#endif
402
Rusty Russell8e1f9362007-07-17 04:03:17 -0700403static struct shrinker acl_shrinker = {
404 .shrink = nfs_access_cache_shrinker,
405 .seeks = DEFAULT_SEEKS,
406};
Trond Myklebust979df722006-07-25 11:28:19 -0400407
David Howellsf7b422b2006-06-09 09:34:33 -0400408/*
409 * Register the NFS filesystems
410 */
411int __init register_nfs_fs(void)
412{
413 int ret;
414
415 ret = register_filesystem(&nfs_fs_type);
416 if (ret < 0)
417 goto error_0;
418
David Howellsf7b422b2006-06-09 09:34:33 -0400419 ret = nfs_register_sysctl();
420 if (ret < 0)
421 goto error_1;
Peter Zijlstra89a09142007-03-16 13:38:26 -0800422#ifdef CONFIG_NFS_V4
David Howellsf7b422b2006-06-09 09:34:33 -0400423 ret = register_filesystem(&nfs4_fs_type);
424 if (ret < 0)
425 goto error_2;
426#endif
Rusty Russell8e1f9362007-07-17 04:03:17 -0700427 register_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400428 return 0;
429
430#ifdef CONFIG_NFS_V4
431error_2:
432 nfs_unregister_sysctl();
Peter Zijlstra89a09142007-03-16 13:38:26 -0800433#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400434error_1:
435 unregister_filesystem(&nfs_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400436error_0:
437 return ret;
438}
439
440/*
441 * Unregister the NFS filesystems
442 */
443void __exit unregister_nfs_fs(void)
444{
Rusty Russell8e1f9362007-07-17 04:03:17 -0700445 unregister_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400446#ifdef CONFIG_NFS_V4
447 unregister_filesystem(&nfs4_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400448#endif
Alexey Dobriyan49af7ee2007-09-18 22:46:40 -0700449 nfs_unregister_sysctl();
David Howellsf7b422b2006-06-09 09:34:33 -0400450 unregister_filesystem(&nfs_fs_type);
451}
452
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400453void nfs_sb_active(struct super_block *sb)
Steve Dicksonef818a22007-11-08 04:05:04 -0500454{
455 struct nfs_server *server = NFS_SB(sb);
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400456
457 if (atomic_inc_return(&server->active) == 1)
458 atomic_inc(&sb->s_active);
459}
460
461void nfs_sb_deactive(struct super_block *sb)
462{
463 struct nfs_server *server = NFS_SB(sb);
464
465 if (atomic_dec_and_test(&server->active))
466 deactivate_super(sb);
Steve Dicksonef818a22007-11-08 04:05:04 -0500467}
468
David Howellsf7b422b2006-06-09 09:34:33 -0400469/*
470 * Deliver file system statistics to userspace
471 */
Trond Myklebust816724e2006-06-24 08:41:41 -0400472static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
David Howellsf7b422b2006-06-09 09:34:33 -0400473{
David Howells0c7d90c2006-08-22 20:06:10 -0400474 struct nfs_server *server = NFS_SB(dentry->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400475 unsigned char blockbits;
476 unsigned long blockres;
David Howells0c7d90c2006-08-22 20:06:10 -0400477 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400478 struct nfs_fsstat res;
479 int error = -ENOMEM;
480
481 res.fattr = nfs_alloc_fattr();
482 if (res.fattr == NULL)
483 goto out_err;
David Howellsf7b422b2006-06-09 09:34:33 -0400484
David Howells8fa5c002006-08-22 20:06:12 -0400485 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
Menyhart Zoltanfbf3fdd2010-09-12 19:55:26 -0400486 if (unlikely(error == -ESTALE)) {
487 struct dentry *pd_dentry;
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400488
Menyhart Zoltanfbf3fdd2010-09-12 19:55:26 -0400489 pd_dentry = dget_parent(dentry);
490 if (pd_dentry != NULL) {
491 nfs_zap_caches(pd_dentry->d_inode);
492 dput(pd_dentry);
493 }
494 }
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400495 nfs_free_fattr(res.fattr);
David Howellsf7b422b2006-06-09 09:34:33 -0400496 if (error < 0)
497 goto out_err;
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400498
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700499 buf->f_type = NFS_SUPER_MAGIC;
David Howellsf7b422b2006-06-09 09:34:33 -0400500
501 /*
502 * Current versions of glibc do not correctly handle the
503 * case where f_frsize != f_bsize. Eventually we want to
504 * report the value of wtmult in this field.
505 */
David Howells0c7d90c2006-08-22 20:06:10 -0400506 buf->f_frsize = dentry->d_sb->s_blocksize;
David Howellsf7b422b2006-06-09 09:34:33 -0400507
508 /*
509 * On most *nix systems, f_blocks, f_bfree, and f_bavail
510 * are reported in units of f_frsize. Linux hasn't had
511 * an f_frsize field in its statfs struct until recently,
512 * thus historically Linux's sys_statfs reports these
513 * fields in units of f_bsize.
514 */
David Howells0c7d90c2006-08-22 20:06:10 -0400515 buf->f_bsize = dentry->d_sb->s_blocksize;
516 blockbits = dentry->d_sb->s_blocksize_bits;
David Howellsf7b422b2006-06-09 09:34:33 -0400517 blockres = (1 << blockbits) - 1;
518 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
519 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
520 buf->f_bavail = (res.abytes + blockres) >> blockbits;
521
522 buf->f_files = res.tfiles;
523 buf->f_ffree = res.afiles;
524
525 buf->f_namelen = server->namelen;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700526
David Howellsf7b422b2006-06-09 09:34:33 -0400527 return 0;
528
529 out_err:
Harvey Harrison3110ff82008-05-02 13:42:44 -0700530 dprintk("%s: statfs error = %d\n", __func__, -error);
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700531 return error;
David Howellsf7b422b2006-06-09 09:34:33 -0400532}
533
David Howells7d4e2742006-08-22 20:06:07 -0400534/*
535 * Map the security flavour number to a name
536 */
Trond Myklebust81039f12006-06-09 09:34:34 -0400537static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
538{
David Howells7d4e2742006-08-22 20:06:07 -0400539 static const struct {
Trond Myklebust81039f12006-06-09 09:34:34 -0400540 rpc_authflavor_t flavour;
541 const char *str;
542 } sec_flavours[] = {
543 { RPC_AUTH_NULL, "null" },
544 { RPC_AUTH_UNIX, "sys" },
545 { RPC_AUTH_GSS_KRB5, "krb5" },
546 { RPC_AUTH_GSS_KRB5I, "krb5i" },
547 { RPC_AUTH_GSS_KRB5P, "krb5p" },
548 { RPC_AUTH_GSS_LKEY, "lkey" },
549 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
550 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
551 { RPC_AUTH_GSS_SPKM, "spkm" },
552 { RPC_AUTH_GSS_SPKMI, "spkmi" },
553 { RPC_AUTH_GSS_SPKMP, "spkmp" },
Chuck Lever4d81cd12007-07-01 12:12:40 -0400554 { UINT_MAX, "unknown" }
Trond Myklebust81039f12006-06-09 09:34:34 -0400555 };
556 int i;
557
Chuck Lever4d81cd12007-07-01 12:12:40 -0400558 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
Trond Myklebust81039f12006-06-09 09:34:34 -0400559 if (sec_flavours[i].flavour == flavour)
560 break;
561 }
562 return sec_flavours[i].str;
563}
564
Jeff Laytonee671b02009-12-03 15:58:56 -0500565static void nfs_show_mountd_netid(struct seq_file *m, struct nfs_server *nfss,
566 int showdefaults)
567{
568 struct sockaddr *sap = (struct sockaddr *) &nfss->mountd_address;
569
570 seq_printf(m, ",mountproto=");
571 switch (sap->sa_family) {
572 case AF_INET:
573 switch (nfss->mountd_protocol) {
574 case IPPROTO_UDP:
575 seq_printf(m, RPCBIND_NETID_UDP);
576 break;
577 case IPPROTO_TCP:
578 seq_printf(m, RPCBIND_NETID_TCP);
579 break;
580 default:
581 if (showdefaults)
582 seq_printf(m, "auto");
583 }
584 break;
585 case AF_INET6:
586 switch (nfss->mountd_protocol) {
587 case IPPROTO_UDP:
588 seq_printf(m, RPCBIND_NETID_UDP6);
589 break;
590 case IPPROTO_TCP:
591 seq_printf(m, RPCBIND_NETID_TCP6);
592 break;
593 default:
594 if (showdefaults)
595 seq_printf(m, "auto");
596 }
597 break;
598 default:
599 if (showdefaults)
600 seq_printf(m, "auto");
601 }
602}
603
Chuck Lever82d101d2008-03-14 14:10:37 -0400604static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
605 int showdefaults)
606{
607 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
608
Bryan Schumakerd5eff1a2010-08-03 13:04:00 -0400609 if (nfss->flags & NFS_MOUNT_LEGACY_INTERFACE)
610 return;
611
Chuck Lever82d101d2008-03-14 14:10:37 -0400612 switch (sap->sa_family) {
613 case AF_INET: {
614 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
Harvey Harrisonbe859402008-10-31 00:56:28 -0700615 seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400616 break;
617 }
618 case AF_INET6: {
619 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
Chuck Leverd250e192009-12-03 15:58:56 -0500620 seq_printf(m, ",mountaddr=%pI6c", &sin6->sin6_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400621 break;
622 }
623 default:
624 if (showdefaults)
625 seq_printf(m, ",mountaddr=unspecified");
626 }
627
628 if (nfss->mountd_version || showdefaults)
629 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
Stanislav Kinsburskyaa699472010-12-08 12:40:13 +0300630 if ((nfss->mountd_port &&
631 nfss->mountd_port != (unsigned short)NFS_UNSPEC_PORT) ||
632 showdefaults)
Chuck Lever82d101d2008-03-14 14:10:37 -0400633 seq_printf(m, ",mountport=%u", nfss->mountd_port);
634
Jeff Laytonee671b02009-12-03 15:58:56 -0500635 nfs_show_mountd_netid(m, nfss, showdefaults);
Chuck Lever82d101d2008-03-14 14:10:37 -0400636}
637
Trond Myklebust0be81892010-06-18 12:23:58 -0400638#ifdef CONFIG_NFS_V4
639static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
640 int showdefaults)
641{
642 struct nfs_client *clp = nfss->nfs_client;
643
644 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
Trond Myklebust0be81892010-06-18 12:23:58 -0400645}
646#else
647static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
648 int showdefaults)
649{
650}
651#endif
652
Trond Myklebust7bbceb62012-03-02 14:00:20 -0500653static void nfs_show_nfs_version(struct seq_file *m,
654 unsigned int version,
655 unsigned int minorversion)
656{
657 seq_printf(m, ",vers=%u", version);
658 if (version == 4)
659 seq_printf(m, ".%u", minorversion);
660}
661
David Howellsf7b422b2006-06-09 09:34:33 -0400662/*
663 * Describe the mount options in force on this server representation
664 */
Chuck Lever82d101d2008-03-14 14:10:37 -0400665static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
666 int showdefaults)
David Howellsf7b422b2006-06-09 09:34:33 -0400667{
David Howells509de812006-08-22 20:06:11 -0400668 static const struct proc_nfs_info {
David Howellsf7b422b2006-06-09 09:34:33 -0400669 int flag;
David Howells509de812006-08-22 20:06:11 -0400670 const char *str;
671 const char *nostr;
David Howellsf7b422b2006-06-09 09:34:33 -0400672 } nfs_info[] = {
673 { NFS_MOUNT_SOFT, ",soft", ",hard" },
Chuck Lever82d101d2008-03-14 14:10:37 -0400674 { NFS_MOUNT_POSIX, ",posix", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400675 { NFS_MOUNT_NOCTO, ",nocto", "" },
676 { NFS_MOUNT_NOAC, ",noac", "" },
677 { NFS_MOUNT_NONLM, ",nolock", "" },
678 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400679 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
Chuck Leverd7403512008-12-23 15:21:37 -0500680 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
681 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400682 { 0, NULL, NULL }
683 };
David Howells509de812006-08-22 20:06:11 -0400684 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400685 struct nfs_client *clp = nfss->nfs_client;
Chuck Lever82d101d2008-03-14 14:10:37 -0400686 u32 version = clp->rpc_ops->version;
Suresh Jayaraman7c563cc2010-09-23 14:26:48 -0400687 int local_flock, local_fcntl;
David Howellsf7b422b2006-06-09 09:34:33 -0400688
Trond Myklebust7bbceb62012-03-02 14:00:20 -0500689 nfs_show_nfs_version(m, version, clp->cl_minorversion);
Chuck Lever2d767432008-03-14 14:10:08 -0400690 seq_printf(m, ",rsize=%u", nfss->rsize);
691 seq_printf(m, ",wsize=%u", nfss->wsize);
Chuck Lever82d101d2008-03-14 14:10:37 -0400692 if (nfss->bsize != 0)
693 seq_printf(m, ",bsize=%u", nfss->bsize);
694 seq_printf(m, ",namlen=%u", nfss->namelen);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400695 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400696 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400697 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400698 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400699 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400700 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400701 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400702 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
David Howellsf7b422b2006-06-09 09:34:33 -0400703 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
704 if (nfss->flags & nfs_infop->flag)
705 seq_puts(m, nfs_infop->str);
706 else
707 seq_puts(m, nfs_infop->nostr);
708 }
Trond Myklebust2446ab62012-03-01 17:00:56 -0500709 rcu_read_lock();
\"Talpey, Thomas\56928ed2007-09-10 13:48:47 -0400710 seq_printf(m, ",proto=%s",
Jeff Laytonee671b02009-12-03 15:58:56 -0500711 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
Trond Myklebust2446ab62012-03-01 17:00:56 -0500712 rcu_read_unlock();
Chuck Lever82d101d2008-03-14 14:10:37 -0400713 if (version == 4) {
714 if (nfss->port != NFS_PORT)
715 seq_printf(m, ",port=%u", nfss->port);
716 } else
717 if (nfss->port)
718 seq_printf(m, ",port=%u", nfss->port);
719
Trond Myklebust33170232007-12-20 16:03:59 -0500720 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
721 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
Trond Myklebust81039f12006-06-09 09:34:34 -0400722 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
Chuck Lever82d101d2008-03-14 14:10:37 -0400723
724 if (version != 4)
725 nfs_show_mountd_options(m, nfss, showdefaults);
Trond Myklebust0be81892010-06-18 12:23:58 -0400726 else
727 nfs_show_nfsv4_options(m, nfss, showdefaults);
Chuck Lever82d101d2008-03-14 14:10:37 -0400728
David Howellsb797cac2009-04-03 16:42:48 +0100729 if (nfss->options & NFS_OPTION_FSCACHE)
730 seq_printf(m, ",fsc");
Patrick J. LoPresti9b00c642010-08-10 17:28:01 -0400731
732 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONEG) {
733 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONE)
734 seq_printf(m, ",lookupcache=none");
735 else
736 seq_printf(m, ",lookupcache=pos");
737 }
Suresh Jayaraman7c563cc2010-09-23 14:26:48 -0400738
739 local_flock = nfss->flags & NFS_MOUNT_LOCAL_FLOCK;
740 local_fcntl = nfss->flags & NFS_MOUNT_LOCAL_FCNTL;
741
742 if (!local_flock && !local_fcntl)
743 seq_printf(m, ",local_lock=none");
744 else if (local_flock && local_fcntl)
745 seq_printf(m, ",local_lock=all");
746 else if (local_flock)
747 seq_printf(m, ",local_lock=flock");
748 else
749 seq_printf(m, ",local_lock=posix");
David Howellsf7b422b2006-06-09 09:34:33 -0400750}
751
752/*
753 * Describe the mount options on this VFS mountpoint
754 */
Al Viro34c80b12011-12-08 21:32:45 -0500755static int nfs_show_options(struct seq_file *m, struct dentry *root)
David Howellsf7b422b2006-06-09 09:34:33 -0400756{
Al Viro34c80b12011-12-08 21:32:45 -0500757 struct nfs_server *nfss = NFS_SB(root->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400758
759 nfs_show_mount_options(m, nfss, 0);
760
Trond Myklebust2446ab62012-03-01 17:00:56 -0500761 rcu_read_lock();
Chuck Lever5d8515c2007-12-10 14:57:16 -0500762 seq_printf(m, ",addr=%s",
763 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
764 RPC_DISPLAY_ADDR));
Trond Myklebust2446ab62012-03-01 17:00:56 -0500765 rcu_read_unlock();
David Howellsf7b422b2006-06-09 09:34:33 -0400766
767 return 0;
768}
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700769
770#ifdef CONFIG_NFS_V4
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300771#ifdef CONFIG_NFS_V4_1
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700772static void show_sessions(struct seq_file *m, struct nfs_server *server)
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300773{
774 if (nfs4_has_session(server->nfs_client))
775 seq_printf(m, ",sessions");
776}
777#else
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700778static void show_sessions(struct seq_file *m, struct nfs_server *server) {}
779#endif
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300780#endif
781
782#ifdef CONFIG_NFS_V4_1
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700783static void show_pnfs(struct seq_file *m, struct nfs_server *server)
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300784{
785 seq_printf(m, ",pnfs=");
786 if (server->pnfs_curr_ld)
787 seq_printf(m, "%s", server->pnfs_curr_ld->name);
788 else
789 seq_printf(m, "not configured");
790}
Trond Myklebust7e03b7c2012-03-04 18:12:57 -0500791
792static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
793{
794 if (nfss->nfs_client && nfss->nfs_client->impl_id) {
795 struct nfs41_impl_id *impl_id = nfss->nfs_client->impl_id;
796 seq_printf(m, "\n\timpl_id:\tname='%s',domain='%s',"
797 "date='%llu,%u'",
798 impl_id->name, impl_id->domain,
799 impl_id->date.seconds, impl_id->date.nseconds);
800 }
801}
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700802#else
Trond Myklebust7e03b7c2012-03-04 18:12:57 -0500803#ifdef CONFIG_NFS_V4
804static void show_pnfs(struct seq_file *m, struct nfs_server *server)
805{
806}
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700807#endif
Trond Myklebust7e03b7c2012-03-04 18:12:57 -0500808static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
809{
810}
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700811#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400812
Al Virod861c632011-12-08 21:32:45 -0500813static int nfs_show_devname(struct seq_file *m, struct dentry *root)
Al Viroc7f404b2011-03-16 06:59:40 -0400814{
815 char *page = (char *) __get_free_page(GFP_KERNEL);
816 char *devname, *dummy;
817 int err = 0;
818 if (!page)
819 return -ENOMEM;
Al Virod861c632011-12-08 21:32:45 -0500820 devname = nfs_path(&dummy, root, page, PAGE_SIZE);
Al Viroc7f404b2011-03-16 06:59:40 -0400821 if (IS_ERR(devname))
822 err = PTR_ERR(devname);
823 else
824 seq_escape(m, devname, " \t\n\\");
825 free_page((unsigned long)page);
826 return err;
827}
828
Al Viroa6322de2011-12-08 21:37:57 -0500829static int nfs_show_path(struct seq_file *m, struct dentry *dentry)
Al Viroc7f404b2011-03-16 06:59:40 -0400830{
831 seq_puts(m, "/");
832 return 0;
833}
834
David Howellsf7b422b2006-06-09 09:34:33 -0400835/*
836 * Present statistical information for this VFS mountpoint
837 */
Al Viro64132372011-12-08 20:51:13 -0500838static int nfs_show_stats(struct seq_file *m, struct dentry *root)
David Howellsf7b422b2006-06-09 09:34:33 -0400839{
840 int i, cpu;
Al Viro64132372011-12-08 20:51:13 -0500841 struct nfs_server *nfss = NFS_SB(root->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400842 struct rpc_auth *auth = nfss->client->cl_auth;
843 struct nfs_iostats totals = { };
844
845 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
846
847 /*
848 * Display all mount option settings
849 */
850 seq_printf(m, "\n\topts:\t");
Al Viro64132372011-12-08 20:51:13 -0500851 seq_puts(m, root->d_sb->s_flags & MS_RDONLY ? "ro" : "rw");
852 seq_puts(m, root->d_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
853 seq_puts(m, root->d_sb->s_flags & MS_NOATIME ? ",noatime" : "");
854 seq_puts(m, root->d_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
David Howellsf7b422b2006-06-09 09:34:33 -0400855 nfs_show_mount_options(m, nfss, 1);
856
857 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
858
Trond Myklebust7e03b7c2012-03-04 18:12:57 -0500859 show_implementation_id(m, nfss);
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500860
David Howellsf7b422b2006-06-09 09:34:33 -0400861 seq_printf(m, "\n\tcaps:\t");
862 seq_printf(m, "caps=0x%x", nfss->caps);
Chuck Lever2d767432008-03-14 14:10:08 -0400863 seq_printf(m, ",wtmult=%u", nfss->wtmult);
864 seq_printf(m, ",dtsize=%u", nfss->dtsize);
865 seq_printf(m, ",bsize=%u", nfss->bsize);
866 seq_printf(m, ",namlen=%u", nfss->namelen);
David Howellsf7b422b2006-06-09 09:34:33 -0400867
868#ifdef CONFIG_NFS_V4
Trond Myklebust40c553192007-12-14 14:56:07 -0500869 if (nfss->nfs_client->rpc_ops->version == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400870 seq_printf(m, "\n\tnfsv4:\t");
871 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
872 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
873 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300874 show_sessions(m, nfss);
875 show_pnfs(m, nfss);
David Howellsf7b422b2006-06-09 09:34:33 -0400876 }
877#endif
878
879 /*
880 * Display security flavor in effect for this mount
881 */
Chuck Lever2d767432008-03-14 14:10:08 -0400882 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400883 if (auth->au_flavor)
Chuck Lever2d767432008-03-14 14:10:08 -0400884 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400885
886 /*
887 * Display superblock I/O counters
888 */
889 for_each_possible_cpu(cpu) {
890 struct nfs_iostats *stats;
891
892 preempt_disable();
893 stats = per_cpu_ptr(nfss->io_stats, cpu);
894
895 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
896 totals.events[i] += stats->events[i];
897 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
898 totals.bytes[i] += stats->bytes[i];
David Howells6a510912009-04-03 16:42:43 +0100899#ifdef CONFIG_NFS_FSCACHE
900 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
901 totals.fscache[i] += stats->fscache[i];
902#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400903
904 preempt_enable();
905 }
906
907 seq_printf(m, "\n\tevents:\t");
908 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
909 seq_printf(m, "%lu ", totals.events[i]);
910 seq_printf(m, "\n\tbytes:\t");
911 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
912 seq_printf(m, "%Lu ", totals.bytes[i]);
David Howells6a510912009-04-03 16:42:43 +0100913#ifdef CONFIG_NFS_FSCACHE
914 if (nfss->options & NFS_OPTION_FSCACHE) {
915 seq_printf(m, "\n\tfsc:\t");
916 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
917 seq_printf(m, "%Lu ", totals.bytes[i]);
918 }
919#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400920 seq_printf(m, "\n");
921
922 rpc_print_iostats(m, nfss->client);
923
924 return 0;
925}
926
927/*
928 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400929 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400930 */
Al Viro42faad92008-04-24 07:21:56 -0400931static void nfs_umount_begin(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -0400932{
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200933 struct nfs_server *server;
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400934 struct rpc_clnt *rpc;
935
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200936 server = NFS_SB(sb);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400937 /* -EIO all pending I/O */
938 rpc = server->client_acl;
939 if (!IS_ERR(rpc))
940 rpc_killall_tasks(rpc);
941 rpc = server->client;
942 if (!IS_ERR(rpc))
943 rpc_killall_tasks(rpc);
David Howellsf7b422b2006-06-09 09:34:33 -0400944}
945
Trond Myklebustc5811db2009-10-06 15:40:15 -0400946static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(unsigned int version)
Chuck Lever9423a082009-09-23 14:36:38 -0400947{
948 struct nfs_parsed_mount_data *data;
949
950 data = kzalloc(sizeof(*data), GFP_KERNEL);
951 if (data) {
Chuck Lever9423a082009-09-23 14:36:38 -0400952 data->acregmin = NFS_DEF_ACREGMIN;
953 data->acregmax = NFS_DEF_ACREGMAX;
954 data->acdirmin = NFS_DEF_ACDIRMIN;
955 data->acdirmax = NFS_DEF_ACDIRMAX;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400956 data->mount_server.port = NFS_UNSPEC_PORT;
Chuck Lever9423a082009-09-23 14:36:38 -0400957 data->nfs_server.port = NFS_UNSPEC_PORT;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400958 data->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Lever9423a082009-09-23 14:36:38 -0400959 data->auth_flavors[0] = RPC_AUTH_UNIX;
960 data->auth_flavor_len = 1;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400961 data->version = version;
Chuck Lever9423a082009-09-23 14:36:38 -0400962 data->minorversion = 0;
Trond Myklebust9937347a2012-02-19 08:44:07 +0100963 data->net = current->nsproxy->net_ns;
Jeff Layton8a0d5512011-12-20 06:57:45 -0500964 security_init_mnt_opts(&data->lsm_opts);
Chuck Lever9423a082009-09-23 14:36:38 -0400965 }
966 return data;
967}
968
Jeff Layton8a0d5512011-12-20 06:57:45 -0500969static void nfs_free_parsed_mount_data(struct nfs_parsed_mount_data *data)
970{
971 if (data) {
972 kfree(data->client_address);
973 kfree(data->mount_server.hostname);
974 kfree(data->nfs_server.export_path);
975 kfree(data->nfs_server.hostname);
976 kfree(data->fscache_uniq);
977 security_free_mnt_opts(&data->lsm_opts);
978 kfree(data);
979 }
980}
981
David Howellsf7b422b2006-06-09 09:34:33 -0400982/*
Chuck Levercdcd7f92007-12-10 14:57:45 -0500983 * Sanity-check a server address provided by the mount command.
984 *
985 * Address family must be initialized, and address must not be
986 * the ANY address for that family.
Chuck Leverfc50d582007-07-01 12:12:46 -0400987 */
988static int nfs_verify_server_address(struct sockaddr *addr)
989{
990 switch (addr->sa_family) {
991 case AF_INET: {
Chuck Levercdcd7f92007-12-10 14:57:45 -0500992 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
Al Viroe6f1ceb2008-03-17 22:44:53 -0700993 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
Chuck Levercdcd7f92007-12-10 14:57:45 -0500994 }
995 case AF_INET6: {
996 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
997 return !ipv6_addr_any(sa);
Chuck Leverfc50d582007-07-01 12:12:46 -0400998 }
999 }
1000
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001001 dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
Chuck Leverfc50d582007-07-01 12:12:46 -04001002 return 0;
1003}
1004
Chuck Lever9412b922007-12-10 14:59:21 -05001005/*
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001006 * Select between a default port value and a user-specified port value.
1007 * If a zero value is set, then autobind will be used.
1008 */
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001009static void nfs_set_port(struct sockaddr *sap, int *port,
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001010 const unsigned short default_port)
1011{
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001012 if (*port == NFS_UNSPEC_PORT)
1013 *port = default_port;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001014
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001015 rpc_set_port(sap, *port);
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001016}
1017
1018/*
Trond Myklebust259875e2008-07-02 14:43:47 -04001019 * Sanity check the NFS transport protocol.
1020 *
1021 */
1022static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
1023{
1024 switch (mnt->nfs_server.protocol) {
1025 case XPRT_TRANSPORT_UDP:
1026 case XPRT_TRANSPORT_TCP:
1027 case XPRT_TRANSPORT_RDMA:
1028 break;
1029 default:
1030 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1031 }
1032}
1033
1034/*
1035 * For text based NFSv2/v3 mounts, the mount protocol transport default
1036 * settings should depend upon the specified NFS transport.
1037 */
1038static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
1039{
1040 nfs_validate_transport_protocol(mnt);
1041
1042 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
1043 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
1044 return;
1045 switch (mnt->nfs_server.protocol) {
1046 case XPRT_TRANSPORT_UDP:
1047 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
1048 break;
1049 case XPRT_TRANSPORT_TCP:
1050 case XPRT_TRANSPORT_RDMA:
1051 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
1052 }
1053}
1054
1055/*
Chuck Lever01060c82008-06-24 16:33:38 -04001056 * Parse the value of the 'sec=' option.
Chuck Lever01060c82008-06-24 16:33:38 -04001057 */
1058static int nfs_parse_security_flavors(char *value,
1059 struct nfs_parsed_mount_data *mnt)
1060{
1061 substring_t args[MAX_OPT_ARGS];
1062
1063 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
1064
1065 switch (match_token(value, nfs_secflavor_tokens, args)) {
1066 case Opt_sec_none:
Chuck Lever01060c82008-06-24 16:33:38 -04001067 mnt->auth_flavors[0] = RPC_AUTH_NULL;
1068 break;
1069 case Opt_sec_sys:
Chuck Lever01060c82008-06-24 16:33:38 -04001070 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
1071 break;
1072 case Opt_sec_krb5:
Chuck Lever01060c82008-06-24 16:33:38 -04001073 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
1074 break;
1075 case Opt_sec_krb5i:
Chuck Lever01060c82008-06-24 16:33:38 -04001076 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
1077 break;
1078 case Opt_sec_krb5p:
Chuck Lever01060c82008-06-24 16:33:38 -04001079 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
1080 break;
1081 case Opt_sec_lkey:
Chuck Lever01060c82008-06-24 16:33:38 -04001082 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
1083 break;
1084 case Opt_sec_lkeyi:
Chuck Lever01060c82008-06-24 16:33:38 -04001085 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
1086 break;
1087 case Opt_sec_lkeyp:
Chuck Lever01060c82008-06-24 16:33:38 -04001088 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
1089 break;
1090 case Opt_sec_spkm:
Chuck Lever01060c82008-06-24 16:33:38 -04001091 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
1092 break;
1093 case Opt_sec_spkmi:
Chuck Lever01060c82008-06-24 16:33:38 -04001094 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
1095 break;
1096 case Opt_sec_spkmp:
Chuck Lever01060c82008-06-24 16:33:38 -04001097 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
1098 break;
1099 default:
1100 return 0;
1101 }
1102
Bryan Schumaker9b7160c2011-04-13 14:31:30 -04001103 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
Chuck Lever059f90b2009-08-09 15:09:31 -04001104 mnt->auth_flavor_len = 1;
Chuck Lever01060c82008-06-24 16:33:38 -04001105 return 1;
1106}
1107
Trond Myklebust0d71b052012-03-02 13:59:49 -05001108static int nfs_parse_version_string(char *string,
1109 struct nfs_parsed_mount_data *mnt,
1110 substring_t *args)
1111{
1112 mnt->flags &= ~NFS_MOUNT_VER3;
1113 switch (match_token(string, nfs_vers_tokens, args)) {
1114 case Opt_vers_2:
1115 mnt->version = 2;
1116 break;
1117 case Opt_vers_3:
1118 mnt->flags |= NFS_MOUNT_VER3;
1119 mnt->version = 3;
1120 break;
1121 case Opt_vers_4:
1122 /* Backward compatibility option. In future,
1123 * the mount program should always supply
1124 * a NFSv4 minor version number.
1125 */
1126 mnt->version = 4;
1127 break;
1128 case Opt_vers_4_0:
1129 mnt->version = 4;
1130 mnt->minorversion = 0;
1131 break;
1132 case Opt_vers_4_1:
1133 mnt->version = 4;
1134 mnt->minorversion = 1;
1135 break;
1136 default:
1137 return 0;
1138 }
1139 return 1;
1140}
1141
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001142static int nfs_get_option_str(substring_t args[], char **option)
1143{
1144 kfree(*option);
1145 *option = match_strdup(args);
1146 return !option;
1147}
1148
1149static int nfs_get_option_ul(substring_t args[], unsigned long *option)
1150{
1151 int rc;
1152 char *string;
1153
1154 string = match_strdup(args);
1155 if (string == NULL)
1156 return -ENOMEM;
1157 rc = strict_strtoul(string, 10, option);
1158 kfree(string);
1159
1160 return rc;
1161}
1162
Chuck Lever01060c82008-06-24 16:33:38 -04001163/*
Chuck Leverbf0fd762007-07-01 12:13:44 -04001164 * Error-check and convert a string of mount options from user space into
Chuck Leverf45663c2008-06-24 19:28:02 -04001165 * a data structure. The whole mount string is processed; bad options are
1166 * skipped as they are encountered. If there were no errors, return 1;
1167 * otherwise return 0 (zero).
Chuck Leverbf0fd762007-07-01 12:13:44 -04001168 */
1169static int nfs_parse_mount_options(char *raw,
1170 struct nfs_parsed_mount_data *mnt)
1171{
Eric Parisf9c3a382008-03-05 14:20:18 -05001172 char *p, *string, *secdata;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001173 int rc, sloppy = 0, invalid_option = 0;
Jeff Laytonee671b02009-12-03 15:58:56 -05001174 unsigned short protofamily = AF_UNSPEC;
1175 unsigned short mountfamily = AF_UNSPEC;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001176
1177 if (!raw) {
1178 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
1179 return 1;
1180 }
1181 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
1182
Eric Parisf9c3a382008-03-05 14:20:18 -05001183 secdata = alloc_secdata();
1184 if (!secdata)
1185 goto out_nomem;
1186
1187 rc = security_sb_copy_data(raw, secdata);
1188 if (rc)
1189 goto out_security_failure;
1190
1191 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
1192 if (rc)
1193 goto out_security_failure;
1194
1195 free_secdata(secdata);
1196
Chuck Leverbf0fd762007-07-01 12:13:44 -04001197 while ((p = strsep(&raw, ",")) != NULL) {
1198 substring_t args[MAX_OPT_ARGS];
Chuck Levera5a16ba2009-06-17 18:02:14 -07001199 unsigned long option;
1200 int token;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001201
1202 if (!*p)
1203 continue;
1204
1205 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
1206
1207 token = match_token(p, nfs_mount_option_tokens, args);
1208 switch (token) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001209
1210 /*
1211 * boolean options: foo/nofoo
1212 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001213 case Opt_soft:
1214 mnt->flags |= NFS_MOUNT_SOFT;
1215 break;
1216 case Opt_hard:
1217 mnt->flags &= ~NFS_MOUNT_SOFT;
1218 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001219 case Opt_posix:
1220 mnt->flags |= NFS_MOUNT_POSIX;
1221 break;
1222 case Opt_noposix:
1223 mnt->flags &= ~NFS_MOUNT_POSIX;
1224 break;
1225 case Opt_cto:
1226 mnt->flags &= ~NFS_MOUNT_NOCTO;
1227 break;
1228 case Opt_nocto:
1229 mnt->flags |= NFS_MOUNT_NOCTO;
1230 break;
1231 case Opt_ac:
1232 mnt->flags &= ~NFS_MOUNT_NOAC;
1233 break;
1234 case Opt_noac:
1235 mnt->flags |= NFS_MOUNT_NOAC;
1236 break;
1237 case Opt_lock:
1238 mnt->flags &= ~NFS_MOUNT_NONLM;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001239 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1240 NFS_MOUNT_LOCAL_FCNTL);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001241 break;
1242 case Opt_nolock:
1243 mnt->flags |= NFS_MOUNT_NONLM;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001244 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1245 NFS_MOUNT_LOCAL_FCNTL);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001246 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001247 case Opt_udp:
1248 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001249 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001250 break;
1251 case Opt_tcp:
1252 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001253 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001254 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001255 case Opt_rdma:
1256 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1257 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001258 xprt_load_transport(p);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001259 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001260 case Opt_acl:
1261 mnt->flags &= ~NFS_MOUNT_NOACL;
1262 break;
1263 case Opt_noacl:
1264 mnt->flags |= NFS_MOUNT_NOACL;
1265 break;
1266 case Opt_rdirplus:
1267 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1268 break;
1269 case Opt_nordirplus:
1270 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1271 break;
Trond Myklebust75180df2007-05-16 16:53:28 -04001272 case Opt_sharecache:
1273 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1274 break;
1275 case Opt_nosharecache:
1276 mnt->flags |= NFS_MOUNT_UNSHARED;
1277 break;
Chuck Leverd7403512008-12-23 15:21:37 -05001278 case Opt_resvport:
1279 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1280 break;
1281 case Opt_noresvport:
1282 mnt->flags |= NFS_MOUNT_NORESVPORT;
1283 break;
David Howellsb797cac2009-04-03 16:42:48 +01001284 case Opt_fscache:
1285 mnt->options |= NFS_OPTION_FSCACHE;
1286 kfree(mnt->fscache_uniq);
1287 mnt->fscache_uniq = NULL;
1288 break;
1289 case Opt_nofscache:
1290 mnt->options &= ~NFS_OPTION_FSCACHE;
1291 kfree(mnt->fscache_uniq);
1292 mnt->fscache_uniq = NULL;
1293 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001294
Chuck Leverf45663c2008-06-24 19:28:02 -04001295 /*
1296 * options that take numeric values
1297 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001298 case Opt_port:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001299 if (nfs_get_option_ul(args, &option) ||
1300 option > USHRT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001301 goto out_invalid_value;
1302 mnt->nfs_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001303 break;
1304 case Opt_rsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001305 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001306 goto out_invalid_value;
1307 mnt->rsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001308 break;
1309 case Opt_wsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001310 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001311 goto out_invalid_value;
1312 mnt->wsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001313 break;
1314 case Opt_bsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001315 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001316 goto out_invalid_value;
1317 mnt->bsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001318 break;
1319 case Opt_timeo:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001320 if (nfs_get_option_ul(args, &option) || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001321 goto out_invalid_value;
1322 mnt->timeo = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001323 break;
1324 case Opt_retrans:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001325 if (nfs_get_option_ul(args, &option) || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001326 goto out_invalid_value;
1327 mnt->retrans = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001328 break;
1329 case Opt_acregmin:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001330 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001331 goto out_invalid_value;
1332 mnt->acregmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001333 break;
1334 case Opt_acregmax:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001335 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001336 goto out_invalid_value;
1337 mnt->acregmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001338 break;
1339 case Opt_acdirmin:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001340 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001341 goto out_invalid_value;
1342 mnt->acdirmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001343 break;
1344 case Opt_acdirmax:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001345 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001346 goto out_invalid_value;
1347 mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001348 break;
1349 case Opt_actimeo:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001350 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001351 goto out_invalid_value;
1352 mnt->acregmin = mnt->acregmax =
1353 mnt->acdirmin = mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001354 break;
1355 case Opt_namelen:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001356 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001357 goto out_invalid_value;
1358 mnt->namlen = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001359 break;
1360 case Opt_mountport:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001361 if (nfs_get_option_ul(args, &option) ||
1362 option > USHRT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001363 goto out_invalid_value;
1364 mnt->mount_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001365 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001366 case Opt_mountvers:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001367 if (nfs_get_option_ul(args, &option) ||
Chuck Leverf45663c2008-06-24 19:28:02 -04001368 option < NFS_MNT_VERSION ||
Chuck Leverd23c45f2009-06-17 18:02:13 -07001369 option > NFS_MNT3_VERSION)
1370 goto out_invalid_value;
1371 mnt->mount_server.version = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001372 break;
Mike Sager3fd5be92009-04-01 09:21:48 -04001373 case Opt_minorversion:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001374 if (nfs_get_option_ul(args, &option))
Chuck Leverf3f4f4e2009-08-09 15:09:29 -04001375 goto out_invalid_value;
1376 if (option > NFS4_MAX_MINOR_VERSION)
1377 goto out_invalid_value;
1378 mnt->minorversion = option;
Mike Sager3fd5be92009-04-01 09:21:48 -04001379 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001380
Chuck Leverf45663c2008-06-24 19:28:02 -04001381 /*
1382 * options that take text values
1383 */
Trond Myklebust0d71b052012-03-02 13:59:49 -05001384 case Opt_nfsvers:
1385 string = match_strdup(args);
1386 if (string == NULL)
1387 goto out_nomem;
1388 rc = nfs_parse_version_string(string, mnt, args);
1389 kfree(string);
1390 if (!rc)
1391 goto out_invalid_value;
1392 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001393 case Opt_sec:
1394 string = match_strdup(args);
1395 if (string == NULL)
1396 goto out_nomem;
Chuck Lever01060c82008-06-24 16:33:38 -04001397 rc = nfs_parse_security_flavors(string, mnt);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001398 kfree(string);
Chuck Leverf45663c2008-06-24 19:28:02 -04001399 if (!rc) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001400 dfprintk(MOUNT, "NFS: unrecognized "
1401 "security flavor\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001402 return 0;
Chuck Leverf45663c2008-06-24 19:28:02 -04001403 }
Chuck Leverbf0fd762007-07-01 12:13:44 -04001404 break;
1405 case Opt_proto:
1406 string = match_strdup(args);
1407 if (string == NULL)
1408 goto out_nomem;
1409 token = match_token(string,
1410 nfs_xprt_protocol_tokens, args);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001411
Jeff Laytonee671b02009-12-03 15:58:56 -05001412 protofamily = AF_INET;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001413 switch (token) {
Jeff Laytonee671b02009-12-03 15:58:56 -05001414 case Opt_xprt_udp6:
1415 protofamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001416 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001417 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001418 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001419 break;
Jeff Laytonee671b02009-12-03 15:58:56 -05001420 case Opt_xprt_tcp6:
1421 protofamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001422 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001423 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001424 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001425 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001426 case Opt_xprt_rdma:
1427 /* vector side protocols to TCP */
1428 mnt->flags |= NFS_MOUNT_TCP;
1429 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001430 xprt_load_transport(string);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001431 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001432 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001433 dfprintk(MOUNT, "NFS: unrecognized "
1434 "transport protocol\n");
Yinghai Lu4223a4a2009-10-20 14:13:46 +09001435 kfree(string);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001436 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001437 }
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001438 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001439 break;
1440 case Opt_mountproto:
1441 string = match_strdup(args);
1442 if (string == NULL)
1443 goto out_nomem;
1444 token = match_token(string,
1445 nfs_xprt_protocol_tokens, args);
Trond Myklebustd508afb2009-04-06 16:41:35 -07001446 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001447
Jeff Laytonee671b02009-12-03 15:58:56 -05001448 mountfamily = AF_INET;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001449 switch (token) {
Jeff Laytonee671b02009-12-03 15:58:56 -05001450 case Opt_xprt_udp6:
1451 mountfamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001452 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001453 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001454 break;
Jeff Laytonee671b02009-12-03 15:58:56 -05001455 case Opt_xprt_tcp6:
1456 mountfamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001457 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001458 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001459 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001460 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001461 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001462 dfprintk(MOUNT, "NFS: unrecognized "
1463 "transport protocol\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001464 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001465 }
1466 break;
1467 case Opt_addr:
1468 string = match_strdup(args);
1469 if (string == NULL)
1470 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001471 mnt->nfs_server.addrlen =
Stanislav Kinsburskyb48e1272012-01-26 15:11:57 +04001472 rpc_pton(mnt->net, string, strlen(string),
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001473 (struct sockaddr *)
1474 &mnt->nfs_server.address,
1475 sizeof(mnt->nfs_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001476 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001477 if (mnt->nfs_server.addrlen == 0)
1478 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001479 break;
1480 case Opt_clientaddr:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001481 if (nfs_get_option_str(args, &mnt->client_address))
Chuck Leverbf0fd762007-07-01 12:13:44 -04001482 goto out_nomem;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001483 break;
Chuck Lever33832032007-12-10 14:59:13 -05001484 case Opt_mounthost:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001485 if (nfs_get_option_str(args,
1486 &mnt->mount_server.hostname))
Chuck Lever33832032007-12-10 14:59:13 -05001487 goto out_nomem;
Chuck Lever33832032007-12-10 14:59:13 -05001488 break;
Chuck Lever0ac83772007-09-11 18:01:04 -04001489 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001490 string = match_strdup(args);
1491 if (string == NULL)
1492 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001493 mnt->mount_server.addrlen =
Stanislav Kinsburskyb48e1272012-01-26 15:11:57 +04001494 rpc_pton(mnt->net, string, strlen(string),
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001495 (struct sockaddr *)
1496 &mnt->mount_server.address,
1497 sizeof(mnt->mount_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001498 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001499 if (mnt->mount_server.addrlen == 0)
1500 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001501 break;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001502 case Opt_lookupcache:
1503 string = match_strdup(args);
1504 if (string == NULL)
1505 goto out_nomem;
1506 token = match_token(string,
1507 nfs_lookupcache_tokens, args);
1508 kfree(string);
1509 switch (token) {
1510 case Opt_lookupcache_all:
1511 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1512 break;
1513 case Opt_lookupcache_positive:
1514 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1515 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1516 break;
1517 case Opt_lookupcache_none:
1518 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1519 break;
1520 default:
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001521 dfprintk(MOUNT, "NFS: invalid "
1522 "lookupcache argument\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001523 return 0;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001524 };
1525 break;
Chuck Levera6d5ff62010-05-07 13:33:58 -04001526 case Opt_fscache_uniq:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001527 if (nfs_get_option_str(args, &mnt->fscache_uniq))
Chuck Levera6d5ff62010-05-07 13:33:58 -04001528 goto out_nomem;
Chuck Levera6d5ff62010-05-07 13:33:58 -04001529 mnt->options |= NFS_OPTION_FSCACHE;
1530 break;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001531 case Opt_local_lock:
1532 string = match_strdup(args);
1533 if (string == NULL)
1534 goto out_nomem;
1535 token = match_token(string, nfs_local_lock_tokens,
1536 args);
1537 kfree(string);
1538 switch (token) {
1539 case Opt_local_lock_all:
1540 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1541 NFS_MOUNT_LOCAL_FCNTL);
1542 break;
1543 case Opt_local_lock_flock:
1544 mnt->flags |= NFS_MOUNT_LOCAL_FLOCK;
1545 break;
1546 case Opt_local_lock_posix:
1547 mnt->flags |= NFS_MOUNT_LOCAL_FCNTL;
1548 break;
1549 case Opt_local_lock_none:
1550 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1551 NFS_MOUNT_LOCAL_FCNTL);
1552 break;
1553 default:
1554 dfprintk(MOUNT, "NFS: invalid "
1555 "local_lock argument\n");
1556 return 0;
1557 };
1558 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001559
Chuck Leverf45663c2008-06-24 19:28:02 -04001560 /*
1561 * Special options
1562 */
1563 case Opt_sloppy:
1564 sloppy = 1;
1565 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1566 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001567 case Opt_userspace:
1568 case Opt_deprecated:
Chuck Leverd33e4df2008-06-12 12:37:41 -04001569 dfprintk(MOUNT, "NFS: ignoring mount option "
1570 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001571 break;
1572
1573 default:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001574 invalid_option = 1;
Chuck Leverf45663c2008-06-24 19:28:02 -04001575 dfprintk(MOUNT, "NFS: unrecognized mount option "
1576 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001577 }
1578 }
1579
Chuck Leverd23c45f2009-06-17 18:02:13 -07001580 if (!sloppy && invalid_option)
1581 return 0;
1582
Weston Andros Adamson571b7552012-02-01 14:06:41 -05001583 if (mnt->minorversion && mnt->version != 4)
1584 goto out_minorversion_mismatch;
1585
Jeff Laytonee671b02009-12-03 15:58:56 -05001586 /*
1587 * verify that any proto=/mountproto= options match the address
1588 * familiies in the addr=/mountaddr= options.
1589 */
1590 if (protofamily != AF_UNSPEC &&
1591 protofamily != mnt->nfs_server.address.ss_family)
1592 goto out_proto_mismatch;
1593
1594 if (mountfamily != AF_UNSPEC) {
1595 if (mnt->mount_server.addrlen) {
1596 if (mountfamily != mnt->mount_server.address.ss_family)
1597 goto out_mountproto_mismatch;
1598 } else {
1599 if (mountfamily != mnt->nfs_server.address.ss_family)
1600 goto out_mountproto_mismatch;
1601 }
1602 }
1603
Chuck Leverbf0fd762007-07-01 12:13:44 -04001604 return 1;
1605
Jeff Laytonee671b02009-12-03 15:58:56 -05001606out_mountproto_mismatch:
1607 printk(KERN_INFO "NFS: mount server address does not match mountproto= "
1608 "option\n");
1609 return 0;
1610out_proto_mismatch:
1611 printk(KERN_INFO "NFS: server address does not match proto= option\n");
1612 return 0;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001613out_invalid_address:
1614 printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
1615 return 0;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001616out_invalid_value:
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001617 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001618 return 0;
Weston Andros Adamson571b7552012-02-01 14:06:41 -05001619out_minorversion_mismatch:
1620 printk(KERN_INFO "NFS: mount option vers=%u does not support "
1621 "minorversion=%u\n", mnt->version, mnt->minorversion);
1622 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001623out_nomem:
1624 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1625 return 0;
Eric Parisf9c3a382008-03-05 14:20:18 -05001626out_security_failure:
1627 free_secdata(secdata);
1628 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1629 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001630}
1631
1632/*
Chuck Leverec88f282009-08-09 15:09:32 -04001633 * Match the requested auth flavors with the list returned by
1634 * the server. Returns zero and sets the mount's authentication
1635 * flavor on success; returns -EACCES if server does not support
1636 * the requested flavor.
1637 */
1638static int nfs_walk_authlist(struct nfs_parsed_mount_data *args,
1639 struct nfs_mount_request *request)
1640{
1641 unsigned int i, j, server_authlist_len = *(request->auth_flav_len);
1642
1643 /*
Chuck Lever5eecfde2009-08-21 17:50:30 -04001644 * Certain releases of Linux's mountd return an empty
1645 * flavor list. To prevent behavioral regression with
1646 * these servers (ie. rejecting mounts that used to
1647 * succeed), revert to pre-2.6.32 behavior (no checking)
1648 * if the returned flavor list is empty.
1649 */
1650 if (server_authlist_len == 0)
1651 return 0;
1652
1653 /*
Chuck Leverec88f282009-08-09 15:09:32 -04001654 * We avoid sophisticated negotiating here, as there are
1655 * plenty of cases where we can get it wrong, providing
1656 * either too little or too much security.
1657 *
1658 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1659 * flavor listed first. However, some servers list
1660 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1661 * preferred default, in args->auth_flavors[0] if user
1662 * didn't specify sec= mount option.
1663 */
1664 for (i = 0; i < args->auth_flavor_len; i++)
1665 for (j = 0; j < server_authlist_len; j++)
1666 if (args->auth_flavors[i] == request->auth_flavs[j]) {
1667 dfprintk(MOUNT, "NFS: using auth flavor %d\n",
1668 request->auth_flavs[j]);
1669 args->auth_flavors[0] = request->auth_flavs[j];
1670 return 0;
1671 }
1672
1673 dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n");
1674 nfs_umount(request);
1675 return -EACCES;
1676}
1677
1678/*
Chuck Lever0076d7b2007-07-01 12:13:49 -04001679 * Use the remote server's MOUNT service to request the NFS file handle
1680 * corresponding to the provided path.
1681 */
1682static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1683 struct nfs_fh *root_fh)
1684{
Chuck Leverec88f282009-08-09 15:09:32 -04001685 rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS];
1686 unsigned int server_authlist_len = ARRAY_SIZE(server_authlist);
Chuck Leverc5d120f2008-12-23 15:21:35 -05001687 struct nfs_mount_request request = {
1688 .sap = (struct sockaddr *)
1689 &args->mount_server.address,
1690 .dirpath = args->nfs_server.export_path,
1691 .protocol = args->mount_server.protocol,
1692 .fh = root_fh,
Chuck Lever50a737f2008-12-23 15:21:37 -05001693 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
Chuck Leverec88f282009-08-09 15:09:32 -04001694 .auth_flav_len = &server_authlist_len,
1695 .auth_flavs = server_authlist,
Stanislav Kinsbursky6d59b8d2012-01-10 16:12:54 +04001696 .net = args->net,
Chuck Leverc5d120f2008-12-23 15:21:35 -05001697 };
Chuck Lever4c568012007-12-10 14:59:28 -05001698 int status;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001699
1700 if (args->mount_server.version == 0) {
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001701 switch (args->version) {
1702 default:
1703 args->mount_server.version = NFS_MNT3_VERSION;
1704 break;
1705 case 2:
1706 args->mount_server.version = NFS_MNT_VERSION;
1707 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001708 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001709 request.version = args->mount_server.version;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001710
Chuck Lever33832032007-12-10 14:59:13 -05001711 if (args->mount_server.hostname)
Chuck Leverc5d120f2008-12-23 15:21:35 -05001712 request.hostname = args->mount_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001713 else
Chuck Leverc5d120f2008-12-23 15:21:35 -05001714 request.hostname = args->nfs_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001715
Chuck Lever0076d7b2007-07-01 12:13:49 -04001716 /*
1717 * Construct the mount server's address.
1718 */
Chuck Lever4c568012007-12-10 14:59:28 -05001719 if (args->mount_server.address.ss_family == AF_UNSPEC) {
Chuck Leverc5d120f2008-12-23 15:21:35 -05001720 memcpy(request.sap, &args->nfs_server.address,
Chuck Lever4c568012007-12-10 14:59:28 -05001721 args->nfs_server.addrlen);
1722 args->mount_server.addrlen = args->nfs_server.addrlen;
1723 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001724 request.salen = args->mount_server.addrlen;
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001725 nfs_set_port(request.sap, &args->mount_server.port, 0);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001726
1727 /*
1728 * Now ask the mount server to map our export path
1729 * to a file handle.
1730 */
Chuck Leverc5d120f2008-12-23 15:21:35 -05001731 status = nfs_mount(&request);
Chuck Leverec88f282009-08-09 15:09:32 -04001732 if (status != 0) {
1733 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1734 request.hostname, status);
1735 return status;
1736 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001737
Chuck Leverec88f282009-08-09 15:09:32 -04001738 /*
1739 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1740 */
1741 if (args->mount_server.version != NFS_MNT3_VERSION)
1742 return 0;
1743 return nfs_walk_authlist(args, &request);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001744}
1745
Rob Landleyc12bace2011-03-09 15:54:13 -06001746/*
1747 * Split "dev_name" into "hostname:export_path".
1748 *
1749 * The leftmost colon demarks the split between the server's hostname
1750 * and the export path. If the hostname starts with a left square
1751 * bracket, then it may contain colons.
1752 *
1753 * Note: caller frees hostname and export path, even on error.
1754 */
1755static int nfs_parse_devname(const char *dev_name,
1756 char **hostname, size_t maxnamlen,
1757 char **export_path, size_t maxpathlen)
Chuck Leverdc045892008-06-23 12:36:37 -04001758{
1759 size_t len;
Rob Landleyc12bace2011-03-09 15:54:13 -06001760 char *end;
Chuck Leverdc045892008-06-23 12:36:37 -04001761
Rob Landleyc12bace2011-03-09 15:54:13 -06001762 /* Is the host name protected with square brakcets? */
1763 if (*dev_name == '[') {
1764 end = strchr(++dev_name, ']');
1765 if (end == NULL || end[1] != ':')
1766 goto out_bad_devname;
Chuck Leverdc045892008-06-23 12:36:37 -04001767
Rob Landleyc12bace2011-03-09 15:54:13 -06001768 len = end - dev_name;
1769 end++;
1770 } else {
1771 char *comma;
1772
1773 end = strchr(dev_name, ':');
1774 if (end == NULL)
1775 goto out_bad_devname;
1776 len = end - dev_name;
1777
1778 /* kill possible hostname list: not supported */
1779 comma = strchr(dev_name, ',');
1780 if (comma != NULL && comma < end)
1781 *comma = 0;
1782 }
1783
Chuck Leverdc045892008-06-23 12:36:37 -04001784 if (len > maxnamlen)
1785 goto out_hostname;
1786
1787 /* N.B. caller will free nfs_server.hostname in all cases */
1788 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
Rob Landleyc12bace2011-03-09 15:54:13 -06001789 if (*hostname == NULL)
Chuck Leverdc045892008-06-23 12:36:37 -04001790 goto out_nomem;
Rob Landleyc12bace2011-03-09 15:54:13 -06001791 len = strlen(++end);
Chuck Leverdc045892008-06-23 12:36:37 -04001792 if (len > maxpathlen)
1793 goto out_path;
Rob Landleyc12bace2011-03-09 15:54:13 -06001794 *export_path = kstrndup(end, len, GFP_KERNEL);
Chuck Leverdc045892008-06-23 12:36:37 -04001795 if (!*export_path)
1796 goto out_nomem;
1797
1798 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1799 return 0;
1800
1801out_bad_devname:
1802 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1803 return -EINVAL;
1804
1805out_nomem:
1806 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1807 return -ENOMEM;
1808
1809out_hostname:
1810 dfprintk(MOUNT, "NFS: server hostname too long\n");
1811 return -ENAMETOOLONG;
1812
1813out_path:
1814 dfprintk(MOUNT, "NFS: export pathname too long\n");
1815 return -ENAMETOOLONG;
1816}
1817
1818/*
David Howells54ceac42006-08-22 20:06:13 -04001819 * Validate the NFS2/NFS3 mount data
1820 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001821 *
1822 * For option strings, user space handles the following behaviors:
1823 *
1824 * + DNS: mapping server host name to IP address ("addr=" option)
1825 *
1826 * + failure mode: how to behave if a mount request can't be handled
1827 * immediately ("fg/bg" option)
1828 *
1829 * + retry: how often to retry a mount request ("retry=" option)
1830 *
1831 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1832 * mountproto=tcp after mountproto=udp, and so on
David Howellsf7b422b2006-06-09 09:34:33 -04001833 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001834static int nfs_validate_mount_data(void *options,
1835 struct nfs_parsed_mount_data *args,
Chuck Lever136d5582007-07-01 12:13:54 -04001836 struct nfs_fh *mntfh,
1837 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001838{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001839 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001840 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
Chuck Lever136d5582007-07-01 12:13:54 -04001841
Chuck Lever5df36e72007-07-01 12:12:56 -04001842 if (data == NULL)
1843 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001844
David Howellsf7b422b2006-06-09 09:34:33 -04001845 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001846 case 1:
1847 data->namlen = 0;
1848 case 2:
1849 data->bsize = 0;
1850 case 3:
1851 if (data->flags & NFS_MOUNT_VER3)
1852 goto out_no_v3;
1853 data->root.size = NFS2_FHSIZE;
1854 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1855 case 4:
1856 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1857 goto out_no_sec;
1858 case 5:
1859 memset(data->context, 0, sizeof(data->context));
1860 case 6:
Trond Myklebustb7e24452008-06-19 15:21:11 -04001861 if (data->flags & NFS_MOUNT_VER3) {
1862 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1863 goto out_invalid_fh;
Chuck Lever5df36e72007-07-01 12:12:56 -04001864 mntfh->size = data->root.size;
Chuck Lever764302c2009-09-08 19:50:03 -04001865 args->version = 3;
1866 } else {
Chuck Lever5df36e72007-07-01 12:12:56 -04001867 mntfh->size = NFS2_FHSIZE;
Chuck Lever764302c2009-09-08 19:50:03 -04001868 args->version = 2;
1869 }
Chuck Lever5df36e72007-07-01 12:12:56 -04001870
Chuck Lever5df36e72007-07-01 12:12:56 -04001871
1872 memcpy(mntfh->data, data->root.data, mntfh->size);
1873 if (mntfh->size < sizeof(mntfh->data))
1874 memset(mntfh->data + mntfh->size, 0,
1875 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001876
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001877 /*
1878 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1879 * can deal with.
1880 */
Trond Myklebustff3525a2008-08-15 16:59:14 -04001881 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
Bryan Schumakerd5eff1a2010-08-03 13:04:00 -04001882 args->flags |= NFS_MOUNT_LEGACY_INTERFACE;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001883 args->rsize = data->rsize;
1884 args->wsize = data->wsize;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001885 args->timeo = data->timeo;
1886 args->retrans = data->retrans;
1887 args->acregmin = data->acregmin;
1888 args->acregmax = data->acregmax;
1889 args->acdirmin = data->acdirmin;
1890 args->acdirmax = data->acdirmax;
Chuck Lever4c568012007-12-10 14:59:28 -05001891
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001892 memcpy(sap, &data->addr, sizeof(data->addr));
Chuck Lever4c568012007-12-10 14:59:28 -05001893 args->nfs_server.addrlen = sizeof(data->addr);
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001894 if (!nfs_verify_server_address(sap))
Chuck Lever4c568012007-12-10 14:59:28 -05001895 goto out_no_address;
1896
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001897 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001898 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001899 /* N.B. caller will free nfs_server.hostname in all cases */
1900 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1901 args->namlen = data->namlen;
1902 args->bsize = data->bsize;
Chuck Leverdd07c942008-06-24 16:33:46 -04001903
1904 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1905 args->auth_flavors[0] = data->pseudoflavor;
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001906 if (!args->nfs_server.hostname)
1907 goto out_nomem;
Eric Parisf9c3a382008-03-05 14:20:18 -05001908
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001909 if (!(data->flags & NFS_MOUNT_NONLM))
1910 args->flags &= ~(NFS_MOUNT_LOCAL_FLOCK|
1911 NFS_MOUNT_LOCAL_FCNTL);
1912 else
1913 args->flags |= (NFS_MOUNT_LOCAL_FLOCK|
1914 NFS_MOUNT_LOCAL_FCNTL);
Eric Parisf9c3a382008-03-05 14:20:18 -05001915 /*
1916 * The legacy version 6 binary mount data from userspace has a
1917 * field used only to transport selinux information into the
1918 * the kernel. To continue to support that functionality we
1919 * have a touch of selinux knowledge here in the NFS code. The
1920 * userspace code converted context=blah to just blah so we are
1921 * converting back to the full string selinux understands.
1922 */
1923 if (data->context[0]){
1924#ifdef CONFIG_SECURITY_SELINUX
1925 int rc;
1926 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1927 if (!opts_str)
1928 return -ENOMEM;
1929 strcpy(opts_str, "context=");
1930 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1931 strcat(opts_str, &data->context[0]);
1932 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1933 kfree(opts_str);
1934 if (rc)
1935 return rc;
1936#else
1937 return -EINVAL;
1938#endif
1939 }
1940
Chuck Lever5df36e72007-07-01 12:12:56 -04001941 break;
Chuck Lever136d5582007-07-01 12:13:54 -04001942 default: {
Chuck Lever136d5582007-07-01 12:13:54 -04001943 int status;
Chuck Lever136d5582007-07-01 12:13:54 -04001944
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001945 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever136d5582007-07-01 12:13:54 -04001946 return -EINVAL;
1947
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001948 if (!nfs_verify_server_address(sap))
Chuck Lever6e88e062007-09-24 15:39:50 -04001949 goto out_no_address;
1950
Chuck Lever764302c2009-09-08 19:50:03 -04001951 if (args->version == 4)
1952#ifdef CONFIG_NFS_V4
1953 return nfs4_validate_text_mount_data(options,
1954 args, dev_name);
1955#else
1956 goto out_v4_not_compiled;
1957#endif
1958
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001959 nfs_set_port(sap, &args->nfs_server.port, 0);
Chuck Levered596a82008-06-26 17:47:05 -04001960
Trond Myklebust259875e2008-07-02 14:43:47 -04001961 nfs_set_mount_transport_protocol(args);
1962
Chuck Leverdc045892008-06-23 12:36:37 -04001963 status = nfs_parse_devname(dev_name,
1964 &args->nfs_server.hostname,
1965 PAGE_SIZE,
1966 &args->nfs_server.export_path,
1967 NFS_MAXPATHLEN);
1968 if (!status)
1969 status = nfs_try_mount(args, mntfh);
Chuck Lever136d5582007-07-01 12:13:54 -04001970
Chuck Leverdc045892008-06-23 12:36:37 -04001971 kfree(args->nfs_server.export_path);
1972 args->nfs_server.export_path = NULL;
Chuck Lever136d5582007-07-01 12:13:54 -04001973
Chuck Lever136d5582007-07-01 12:13:54 -04001974 if (status)
Chuck Leverfdc6e2c2007-08-29 17:58:59 -04001975 return status;
Chuck Lever136d5582007-07-01 12:13:54 -04001976
Chuck Lever136d5582007-07-01 12:13:54 -04001977 break;
1978 }
David Howellsf7b422b2006-06-09 09:34:33 -04001979 }
David Howells54ceac42006-08-22 20:06:13 -04001980
David Howellsf7b422b2006-06-09 09:34:33 -04001981#ifndef CONFIG_NFS_V3
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001982 if (args->version == 3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001983 goto out_v3_not_compiled;
1984#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001985
David Howells54ceac42006-08-22 20:06:13 -04001986 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001987
1988out_no_data:
1989 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1990 return -EINVAL;
1991
1992out_no_v3:
1993 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1994 data->version);
1995 return -EINVAL;
1996
1997out_no_sec:
1998 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1999 return -EINVAL;
2000
Chuck Lever5df36e72007-07-01 12:12:56 -04002001#ifndef CONFIG_NFS_V3
2002out_v3_not_compiled:
2003 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
2004 return -EPROTONOSUPPORT;
2005#endif /* !CONFIG_NFS_V3 */
2006
Chuck Lever764302c2009-09-08 19:50:03 -04002007#ifndef CONFIG_NFS_V4
2008out_v4_not_compiled:
2009 dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n");
2010 return -EPROTONOSUPPORT;
2011#endif /* !CONFIG_NFS_V4 */
2012
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04002013out_nomem:
2014 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
2015 return -ENOMEM;
2016
Chuck Lever5df36e72007-07-01 12:12:56 -04002017out_no_address:
2018 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
2019 return -EINVAL;
2020
2021out_invalid_fh:
2022 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
2023 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04002024}
2025
Jeff Layton48b605f2008-06-10 15:38:39 -04002026static int
2027nfs_compare_remount_data(struct nfs_server *nfss,
2028 struct nfs_parsed_mount_data *data)
2029{
2030 if (data->flags != nfss->flags ||
2031 data->rsize != nfss->rsize ||
2032 data->wsize != nfss->wsize ||
2033 data->retrans != nfss->client->cl_timeout->to_retries ||
2034 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
2035 data->acregmin != nfss->acregmin / HZ ||
2036 data->acregmax != nfss->acregmax / HZ ||
2037 data->acdirmin != nfss->acdirmin / HZ ||
2038 data->acdirmax != nfss->acdirmax / HZ ||
2039 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
Trond Myklebustbcd2ea12009-10-06 15:41:22 -04002040 data->nfs_server.port != nfss->port ||
Jeff Layton48b605f2008-06-10 15:38:39 -04002041 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
Stefan Richtera1be9ee2009-10-12 11:26:12 -04002042 !rpc_cmp_addr((struct sockaddr *)&data->nfs_server.address,
2043 (struct sockaddr *)&nfss->nfs_client->cl_addr))
Jeff Layton48b605f2008-06-10 15:38:39 -04002044 return -EINVAL;
2045
2046 return 0;
2047}
2048
2049static int
2050nfs_remount(struct super_block *sb, int *flags, char *raw_data)
2051{
2052 int error;
2053 struct nfs_server *nfss = sb->s_fs_info;
2054 struct nfs_parsed_mount_data *data;
2055 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
2056 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
Trond Myklebustcd100722008-06-17 16:12:00 -04002057 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
Jeff Layton48b605f2008-06-10 15:38:39 -04002058
2059 /*
2060 * Userspace mount programs that send binary options generally send
2061 * them populated with default values. We have no way to know which
2062 * ones were explicitly specified. Fall back to legacy behavior and
2063 * just return success.
2064 */
Marc Zyngier31c94462008-07-17 13:21:55 +02002065 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
2066 (nfsvers <= 3 && (!options || (options->version >= 1 &&
2067 options->version <= 6))))
Jeff Layton48b605f2008-06-10 15:38:39 -04002068 return 0;
2069
2070 data = kzalloc(sizeof(*data), GFP_KERNEL);
2071 if (data == NULL)
2072 return -ENOMEM;
2073
2074 /* fill out struct with values from existing mount */
2075 data->flags = nfss->flags;
2076 data->rsize = nfss->rsize;
2077 data->wsize = nfss->wsize;
2078 data->retrans = nfss->client->cl_timeout->to_retries;
2079 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
2080 data->acregmin = nfss->acregmin / HZ;
2081 data->acregmax = nfss->acregmax / HZ;
2082 data->acdirmin = nfss->acdirmin / HZ;
2083 data->acdirmax = nfss->acdirmax / HZ;
2084 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
Trond Myklebustbcd2ea12009-10-06 15:41:22 -04002085 data->nfs_server.port = nfss->port;
Jeff Layton48b605f2008-06-10 15:38:39 -04002086 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
2087 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
2088 data->nfs_server.addrlen);
2089
2090 /* overwrite those values with any that were specified */
2091 error = nfs_parse_mount_options((char *)options, data);
2092 if (error < 0)
2093 goto out;
2094
Jeff Layton26c4c172011-04-27 11:49:09 -04002095 /*
2096 * noac is a special case. It implies -o sync, but that's not
2097 * necessarily reflected in the mtab options. do_remount_sb
2098 * will clear MS_SYNCHRONOUS if -o sync wasn't specified in the
2099 * remount options, so we have to explicitly reset it.
2100 */
2101 if (data->flags & NFS_MOUNT_NOAC)
2102 *flags |= MS_SYNCHRONOUS;
2103
Jeff Layton48b605f2008-06-10 15:38:39 -04002104 /* compare new mount options with old ones */
2105 error = nfs_compare_remount_data(nfss, data);
2106out:
2107 kfree(data);
2108 return error;
2109}
2110
David Howells54ceac42006-08-22 20:06:13 -04002111/*
2112 * Initialise the common bits of the superblock
2113 */
2114static inline void nfs_initialise_sb(struct super_block *sb)
2115{
2116 struct nfs_server *server = NFS_SB(sb);
2117
2118 sb->s_magic = NFS_SUPER_MAGIC;
2119
2120 /* We probably want something more informative here */
2121 snprintf(sb->s_id, sizeof(sb->s_id),
Vivek Trivedi5a7c9ee2012-03-15 23:58:52 +05302122 "%u:%u", MAJOR(sb->s_dev), MINOR(sb->s_dev));
David Howells54ceac42006-08-22 20:06:13 -04002123
2124 if (sb->s_blocksize == 0)
2125 sb->s_blocksize = nfs_block_bits(server->wsize,
2126 &sb->s_blocksize_bits);
2127
Jens Axboe32a88aa2009-09-16 15:02:33 +02002128 sb->s_bdi = &server->backing_dev_info;
2129
David Howells54ceac42006-08-22 20:06:13 -04002130 nfs_super_set_maxbytes(sb, server->maxfilesize);
2131}
2132
2133/*
2134 * Finish setting up an NFS2/3 superblock
2135 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04002136static void nfs_fill_super(struct super_block *sb,
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002137 struct nfs_mount_info *mount_info)
David Howells54ceac42006-08-22 20:06:13 -04002138{
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002139 struct nfs_parsed_mount_data *data = mount_info->parsed;
David Howells54ceac42006-08-22 20:06:13 -04002140 struct nfs_server *server = NFS_SB(sb);
2141
2142 sb->s_blocksize_bits = 0;
2143 sb->s_blocksize = 0;
2144 if (data->bsize)
2145 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
2146
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04002147 if (server->nfs_client->rpc_ops->version == 3) {
David Howells54ceac42006-08-22 20:06:13 -04002148 /* The VFS shouldn't apply the umask to mode bits. We will do
2149 * so ourselves when necessary.
2150 */
2151 sb->s_flags |= MS_POSIXACL;
2152 sb->s_time_gran = 1;
2153 }
2154
2155 sb->s_op = &nfs_sops;
2156 nfs_initialise_sb(sb);
2157}
2158
2159/*
2160 * Finish setting up a cloned NFS2/3 superblock
2161 */
2162static void nfs_clone_super(struct super_block *sb,
2163 const struct super_block *old_sb)
2164{
2165 struct nfs_server *server = NFS_SB(sb);
2166
2167 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2168 sb->s_blocksize = old_sb->s_blocksize;
2169 sb->s_maxbytes = old_sb->s_maxbytes;
2170
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04002171 if (server->nfs_client->rpc_ops->version == 3) {
David Howells54ceac42006-08-22 20:06:13 -04002172 /* The VFS shouldn't apply the umask to mode bits. We will do
2173 * so ourselves when necessary.
2174 */
2175 sb->s_flags |= MS_POSIXACL;
2176 sb->s_time_gran = 1;
2177 }
2178
2179 sb->s_op = old_sb->s_op;
2180 nfs_initialise_sb(sb);
2181}
2182
Trond Myklebust275a5d22007-05-16 16:53:28 -04002183static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
2184{
2185 const struct nfs_server *a = s->s_fs_info;
2186 const struct rpc_clnt *clnt_a = a->client;
2187 const struct rpc_clnt *clnt_b = b->client;
2188
2189 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
2190 goto Ebusy;
2191 if (a->nfs_client != b->nfs_client)
2192 goto Ebusy;
2193 if (a->flags != b->flags)
2194 goto Ebusy;
2195 if (a->wsize != b->wsize)
2196 goto Ebusy;
2197 if (a->rsize != b->rsize)
2198 goto Ebusy;
2199 if (a->acregmin != b->acregmin)
2200 goto Ebusy;
2201 if (a->acregmax != b->acregmax)
2202 goto Ebusy;
2203 if (a->acdirmin != b->acdirmin)
2204 goto Ebusy;
2205 if (a->acdirmax != b->acdirmax)
2206 goto Ebusy;
2207 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
2208 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002209 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04002210Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002211 return 0;
2212}
2213
2214struct nfs_sb_mountdata {
2215 struct nfs_server *server;
2216 int mntflags;
2217};
2218
2219static int nfs_set_super(struct super_block *s, void *data)
2220{
2221 struct nfs_sb_mountdata *sb_mntdata = data;
2222 struct nfs_server *server = sb_mntdata->server;
2223 int ret;
2224
2225 s->s_flags = sb_mntdata->mntflags;
2226 s->s_fs_info = server;
Al Viro8b244ff2010-12-18 11:29:39 -05002227 s->s_d_op = server->nfs_client->rpc_ops->dentry_ops;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002228 ret = set_anon_super(s, server);
2229 if (ret == 0)
2230 server->s_dev = s->s_dev;
2231 return ret;
2232}
2233
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002234static int nfs_compare_super_address(struct nfs_server *server1,
2235 struct nfs_server *server2)
2236{
2237 struct sockaddr *sap1, *sap2;
2238
2239 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
2240 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
2241
2242 if (sap1->sa_family != sap2->sa_family)
2243 return 0;
2244
2245 switch (sap1->sa_family) {
2246 case AF_INET: {
2247 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
2248 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
2249 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
2250 return 0;
2251 if (sin1->sin_port != sin2->sin_port)
2252 return 0;
2253 break;
2254 }
2255 case AF_INET6: {
2256 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
2257 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
2258 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
2259 return 0;
2260 if (sin1->sin6_port != sin2->sin6_port)
2261 return 0;
2262 break;
2263 }
2264 default:
2265 return 0;
2266 }
2267
2268 return 1;
2269}
2270
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002271static int nfs_compare_super(struct super_block *sb, void *data)
2272{
2273 struct nfs_sb_mountdata *sb_mntdata = data;
2274 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2275 int mntflags = sb_mntdata->mntflags;
2276
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002277 if (!nfs_compare_super_address(old, server))
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002278 return 0;
2279 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2280 if (old->flags & NFS_MOUNT_UNSHARED)
2281 return 0;
2282 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2283 return 0;
2284 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04002285}
2286
Bryan Schumaker2311b942012-05-10 15:07:32 -04002287static void nfs_get_cache_cookie(struct super_block *sb,
2288 struct nfs_parsed_mount_data *parsed,
2289 struct nfs_clone_mount *cloned)
2290{
2291 char *uniq = NULL;
2292 int ulen = 0;
2293
2294 if (parsed && parsed->fscache_uniq) {
2295 uniq = parsed->fscache_uniq;
2296 ulen = strlen(parsed->fscache_uniq);
2297 } else if (cloned) {
2298 struct nfs_server *mnt_s = NFS_SB(cloned->sb);
2299 if (mnt_s->fscache_key) {
2300 uniq = mnt_s->fscache_key->key.uniquifier;
2301 ulen = mnt_s->fscache_key->key.uniq_len;
2302 };
2303 }
2304
2305 nfs_fscache_get_super_cookie(sb, uniq, ulen);
2306}
2307
Miklos Szeredifa799752008-04-30 00:54:33 -07002308static int nfs_bdi_register(struct nfs_server *server)
2309{
2310 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
2311}
2312
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002313static struct dentry *nfs_fs_mount_common(struct file_system_type *fs_type,
2314 struct nfs_server *server,
2315 int flags, const char *dev_name,
2316 struct nfs_fh *mntfh,
2317 struct nfs_mount_info *mount_info)
David Howells54ceac42006-08-22 20:06:13 -04002318{
David Howells54ceac42006-08-22 20:06:13 -04002319 struct super_block *s;
Al Viro01194982011-03-16 07:25:36 -04002320 struct dentry *mntroot = ERR_PTR(-ENOMEM);
Trond Myklebust75180df2007-05-16 16:53:28 -04002321 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002322 struct nfs_sb_mountdata sb_mntdata = {
2323 .mntflags = flags,
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002324 .server = server,
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002325 };
Al Viro01194982011-03-16 07:25:36 -04002326 int error;
David Howells54ceac42006-08-22 20:06:13 -04002327
Trond Myklebust75180df2007-05-16 16:53:28 -04002328 if (server->flags & NFS_MOUNT_UNSHARED)
2329 compare_super = NULL;
2330
Sachin Prabhufb2088c2011-08-01 12:10:12 +01002331 /* -o noac implies -o sync */
2332 if (server->flags & NFS_MOUNT_NOAC)
2333 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2334
David Howells54ceac42006-08-22 20:06:13 -04002335 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002336 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002337 if (IS_ERR(s)) {
Al Viro01194982011-03-16 07:25:36 -04002338 mntroot = ERR_CAST(s);
David Howells54ceac42006-08-22 20:06:13 -04002339 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04002340 }
2341
David Howells54ceac42006-08-22 20:06:13 -04002342 if (s->s_fs_info != server) {
2343 nfs_free_server(server);
2344 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002345 } else {
2346 error = nfs_bdi_register(server);
Al Viro01194982011-03-16 07:25:36 -04002347 if (error) {
2348 mntroot = ERR_PTR(error);
NeilBrowncfbc0682010-03-11 11:20:17 +11002349 goto error_splat_bdi;
Al Viro01194982011-03-16 07:25:36 -04002350 }
David Howellsf7b422b2006-06-09 09:34:33 -04002351 }
David Howells54ceac42006-08-22 20:06:13 -04002352
2353 if (!s->s_root) {
2354 /* initial superblock/root creation */
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002355 mount_info->fill_super(s, mount_info);
2356 nfs_get_cache_cookie(s, mount_info->parsed, NULL);
David Howells54ceac42006-08-22 20:06:13 -04002357 }
2358
Al Viro0d5839a2011-03-16 05:27:27 -04002359 mntroot = nfs_get_root(s, mntfh, dev_name);
Al Viro01194982011-03-16 07:25:36 -04002360 if (IS_ERR(mntroot))
David Howells54ceac42006-08-22 20:06:13 -04002361 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002362
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002363 error = security_sb_set_mnt_opts(s, &mount_info->parsed->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002364 if (error)
2365 goto error_splat_root;
2366
David Howellsf7b422b2006-06-09 09:34:33 -04002367 s->s_flags |= MS_ACTIVE;
Chuck Lever06559602007-07-01 12:12:35 -04002368
2369out:
Al Viro01194982011-03-16 07:25:36 -04002370 return mntroot;
Trond Myklebust816724e2006-06-24 08:41:41 -04002371
David Howells54ceac42006-08-22 20:06:13 -04002372out_err_nosb:
2373 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04002374 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002375
Eric Parisf9c3a382008-03-05 14:20:18 -05002376error_splat_root:
2377 dput(mntroot);
Al Viro01194982011-03-16 07:25:36 -04002378 mntroot = ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04002379error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002380 if (server && !s->s_root)
2381 bdi_unregister(&server->backing_dev_info);
2382error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002383 deactivate_locked_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04002384 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002385}
2386
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002387static struct dentry *nfs_fs_mount(struct file_system_type *fs_type,
2388 int flags, const char *dev_name, void *raw_data)
2389{
2390 struct nfs_server *server;
2391 struct nfs_parsed_mount_data *data = NULL;
2392 struct nfs_mount_info mount_info = {
2393 .fill_super = nfs_fill_super,
2394 };
2395 struct nfs_fh *mntfh;
2396 struct dentry *mntroot = ERR_PTR(-ENOMEM);
2397 int error;
2398
2399 data = nfs_alloc_parsed_mount_data(NFS_DEFAULT_VERSION);
2400 mntfh = nfs_alloc_fhandle();
2401 if (data == NULL || mntfh == NULL)
2402 goto out;
2403
2404 /* Validate the mount data */
2405 error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
2406 if (error < 0) {
2407 mntroot = ERR_PTR(error);
2408 goto out;
2409 }
2410 mount_info.parsed = data;
2411
2412#ifdef CONFIG_NFS_V4
2413 if (data->version == 4) {
2414 mntroot = nfs4_try_mount(flags, dev_name, data);
2415 goto out;
2416 }
2417#endif /* CONFIG_NFS_V4 */
2418
2419 /* Get a volume representation */
2420 server = nfs_create_server(data, mntfh);
2421 if (IS_ERR(server)) {
2422 mntroot = ERR_CAST(server);
2423 goto out;
2424 }
2425
2426 mntroot = nfs_fs_mount_common(fs_type, server, flags, dev_name, mntfh, &mount_info);
2427out:
2428 nfs_free_parsed_mount_data(data);
2429 nfs_free_fhandle(mntfh);
2430 return mntroot;
2431}
2432
David Howells54ceac42006-08-22 20:06:13 -04002433/*
Trond Myklebust387c1492010-02-03 08:27:35 -05002434 * Ensure that we unregister the bdi before kill_anon_super
2435 * releases the device name
2436 */
2437static void nfs_put_super(struct super_block *s)
2438{
2439 struct nfs_server *server = NFS_SB(s);
2440
2441 bdi_unregister(&server->backing_dev_info);
2442}
2443
2444/*
David Howells54ceac42006-08-22 20:06:13 -04002445 * Destroy an NFS2/3 superblock
2446 */
David Howellsf7b422b2006-06-09 09:34:33 -04002447static void nfs_kill_super(struct super_block *s)
2448{
2449 struct nfs_server *server = NFS_SB(s);
2450
2451 kill_anon_super(s);
David Howells08734042009-04-03 16:42:42 +01002452 nfs_fscache_release_super_cookie(s);
David Howells54ceac42006-08-22 20:06:13 -04002453 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04002454}
2455
David Howells54ceac42006-08-22 20:06:13 -04002456/*
2457 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2458 */
Al Viro31f43472010-10-29 03:38:12 -04002459static struct dentry *
2460nfs_xdev_mount(struct file_system_type *fs_type, int flags,
2461 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002462{
2463 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002464 struct super_block *s;
2465 struct nfs_server *server;
2466 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002467 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002468 struct nfs_sb_mountdata sb_mntdata = {
2469 .mntflags = flags,
2470 };
David Howells54ceac42006-08-22 20:06:13 -04002471 int error;
2472
Al Viro31f43472010-10-29 03:38:12 -04002473 dprintk("--> nfs_xdev_mount()\n");
David Howells54ceac42006-08-22 20:06:13 -04002474
2475 /* create a new volume representation */
Bryan Schumaker7e6eb682012-04-27 13:27:42 -04002476 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr, data->authflavor);
David Howells54ceac42006-08-22 20:06:13 -04002477 if (IS_ERR(server)) {
2478 error = PTR_ERR(server);
2479 goto out_err_noserver;
2480 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002481 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002482
Trond Myklebust75180df2007-05-16 16:53:28 -04002483 if (server->flags & NFS_MOUNT_UNSHARED)
2484 compare_super = NULL;
2485
Sachin Prabhufb2088c2011-08-01 12:10:12 +01002486 /* -o noac implies -o sync */
2487 if (server->flags & NFS_MOUNT_NOAC)
2488 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2489
David Howells54ceac42006-08-22 20:06:13 -04002490 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002491 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002492 if (IS_ERR(s)) {
2493 error = PTR_ERR(s);
2494 goto out_err_nosb;
2495 }
2496
2497 if (s->s_fs_info != server) {
2498 nfs_free_server(server);
2499 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002500 } else {
2501 error = nfs_bdi_register(server);
2502 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11002503 goto error_splat_bdi;
David Howells54ceac42006-08-22 20:06:13 -04002504 }
2505
2506 if (!s->s_root) {
2507 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002508 nfs_clone_super(s, data->sb);
Bryan Schumaker2311b942012-05-10 15:07:32 -04002509 nfs_get_cache_cookie(s, NULL, data);
David Howells54ceac42006-08-22 20:06:13 -04002510 }
2511
Al Viro0d5839a2011-03-16 05:27:27 -04002512 mntroot = nfs_get_root(s, data->fh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04002513 if (IS_ERR(mntroot)) {
2514 error = PTR_ERR(mntroot);
2515 goto error_splat_super;
2516 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002517 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
Neil Brown4c1fe2f2007-11-01 16:50:20 +11002518 dput(mntroot);
2519 error = -ESTALE;
2520 goto error_splat_super;
2521 }
David Howells54ceac42006-08-22 20:06:13 -04002522
2523 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002524
Eric Parisf9c3a382008-03-05 14:20:18 -05002525 /* clone any lsm security options from the parent to the new sb */
2526 security_sb_clone_mnt_opts(data->sb, s);
2527
Al Viro31f43472010-10-29 03:38:12 -04002528 dprintk("<-- nfs_xdev_mount() = 0\n");
2529 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04002530
2531out_err_nosb:
2532 nfs_free_server(server);
2533out_err_noserver:
Al Viro31f43472010-10-29 03:38:12 -04002534 dprintk("<-- nfs_xdev_mount() = %d [error]\n", error);
2535 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04002536
2537error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002538 if (server && !s->s_root)
2539 bdi_unregister(&server->backing_dev_info);
2540error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002541 deactivate_locked_super(s);
Al Viro31f43472010-10-29 03:38:12 -04002542 dprintk("<-- nfs_xdev_mount() = %d [splat]\n", error);
2543 return ERR_PTR(error);
David Howellsf7b422b2006-06-09 09:34:33 -04002544}
2545
2546#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04002547
2548/*
2549 * Finish setting up a cloned NFS4 superblock
2550 */
2551static void nfs4_clone_super(struct super_block *sb,
2552 const struct super_block *old_sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002553{
David Howells54ceac42006-08-22 20:06:13 -04002554 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2555 sb->s_blocksize = old_sb->s_blocksize;
2556 sb->s_maxbytes = old_sb->s_maxbytes;
2557 sb->s_time_gran = 1;
2558 sb->s_op = old_sb->s_op;
Aneesh Kumar K.Va8a5da92010-12-09 11:35:14 +00002559 /*
2560 * The VFS shouldn't apply the umask to mode bits. We will do
2561 * so ourselves when necessary.
2562 */
2563 sb->s_flags |= MS_POSIXACL;
Aneesh Kumar K.V64c2ce82010-12-09 11:35:25 +00002564 sb->s_xattr = old_sb->s_xattr;
2565 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002566}
2567
2568/*
2569 * Set up an NFS4 superblock
2570 */
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002571static void nfs4_fill_super(struct super_block *sb,
2572 struct nfs_mount_info *mount_info)
David Howellsf7b422b2006-06-09 09:34:33 -04002573{
David Howellsf7b422b2006-06-09 09:34:33 -04002574 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04002575 sb->s_op = &nfs4_sops;
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 = nfs4_xattr_handlers;
David Howells54ceac42006-08-22 20:06:13 -04002582 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002583}
2584
Trond Myklebust01c3f052009-06-17 13:22:58 -07002585static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2586{
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04002587 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3|
2588 NFS_MOUNT_LOCAL_FLOCK|NFS_MOUNT_LOCAL_FCNTL);
Trond Myklebust01c3f052009-06-17 13:22:58 -07002589}
2590
Chuck Lever7630c852009-09-08 19:49:57 -04002591static int nfs4_validate_text_mount_data(void *options,
2592 struct nfs_parsed_mount_data *args,
2593 const char *dev_name)
2594{
2595 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2596
Trond Myklebustf5855fe2009-10-06 15:40:37 -04002597 nfs_set_port(sap, &args->nfs_server.port, NFS_PORT);
Chuck Lever7630c852009-09-08 19:49:57 -04002598
2599 nfs_validate_transport_protocol(args);
2600
2601 nfs4_validate_mount_flags(args);
2602
Trond Myklebust2ecda722009-09-08 19:50:07 -04002603 if (args->version != 4) {
2604 dfprintk(MOUNT,
2605 "NFS4: Illegal mount version\n");
2606 return -EINVAL;
2607 }
2608
Chuck Lever7630c852009-09-08 19:49:57 -04002609 if (args->auth_flavor_len > 1) {
2610 dfprintk(MOUNT,
2611 "NFS4: Too many RPC auth flavours specified\n");
2612 return -EINVAL;
2613 }
2614
Chuck Lever7630c852009-09-08 19:49:57 -04002615 return nfs_parse_devname(dev_name,
2616 &args->nfs_server.hostname,
2617 NFS4_MAXNAMLEN,
2618 &args->nfs_server.export_path,
2619 NFS4_MAXPATHLEN);
2620}
2621
David Howells54ceac42006-08-22 20:06:13 -04002622/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04002623 * Validate NFSv4 mount options
2624 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002625static int nfs4_validate_mount_data(void *options,
2626 struct nfs_parsed_mount_data *args,
2627 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04002628{
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002629 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002630 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002631 char *c;
2632
2633 if (data == NULL)
2634 goto out_no_data;
2635
2636 switch (data->version) {
2637 case 1:
Chuck Lever4c568012007-12-10 14:59:28 -05002638 if (data->host_addrlen > sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002639 goto out_no_address;
Chuck Lever4c568012007-12-10 14:59:28 -05002640 if (data->host_addrlen == 0)
2641 goto out_no_address;
2642 args->nfs_server.addrlen = data->host_addrlen;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002643 if (copy_from_user(sap, data->host_addr, data->host_addrlen))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002644 return -EFAULT;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002645 if (!nfs_verify_server_address(sap))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002646 goto out_no_address;
2647
Chuck Lever6738b252008-06-24 16:33:54 -04002648 if (data->auth_flavourlen) {
2649 if (data->auth_flavourlen > 1)
2650 goto out_inval_auth;
Trond Myklebust20c71f52007-09-20 20:23:51 -04002651 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002652 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04002653 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002654 return -EFAULT;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002655 }
2656
2657 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2658 if (IS_ERR(c))
2659 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002660 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002661
2662 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2663 if (IS_ERR(c))
2664 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002665 args->nfs_server.export_path = c;
2666 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002667
2668 c = strndup_user(data->client_addr.data, 16);
2669 if (IS_ERR(c))
2670 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002671 args->client_address = c;
2672
2673 /*
2674 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2675 * can deal with.
2676 */
2677
2678 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2679 args->rsize = data->rsize;
2680 args->wsize = data->wsize;
2681 args->timeo = data->timeo;
2682 args->retrans = data->retrans;
2683 args->acregmin = data->acregmin;
2684 args->acregmax = data->acregmax;
2685 args->acdirmin = data->acdirmin;
2686 args->acdirmax = data->acdirmax;
2687 args->nfs_server.protocol = data->proto;
Trond Myklebust259875e2008-07-02 14:43:47 -04002688 nfs_validate_transport_protocol(args);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002689
2690 break;
Chuck Lever7630c852009-09-08 19:49:57 -04002691 default:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002692 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever80071222007-07-01 12:13:59 -04002693 return -EINVAL;
2694
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002695 if (!nfs_verify_server_address(sap))
Chuck Lever80071222007-07-01 12:13:59 -04002696 return -EINVAL;
Chuck Levered596a82008-06-26 17:47:05 -04002697
Chuck Lever7630c852009-09-08 19:49:57 -04002698 return nfs4_validate_text_mount_data(options, args, dev_name);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002699 }
2700
2701 return 0;
2702
2703out_no_data:
2704 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2705 return -EINVAL;
2706
2707out_inval_auth:
2708 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2709 data->auth_flavourlen);
2710 return -EINVAL;
2711
2712out_no_address:
2713 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2714 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002715}
2716
2717/*
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002718 * Get the superblock for the NFS4 root partition
David Howells54ceac42006-08-22 20:06:13 -04002719 */
Al Viro31f43472010-10-29 03:38:12 -04002720static struct dentry *
2721nfs4_remote_mount(struct file_system_type *fs_type, int flags,
2722 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002723{
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002724 struct nfs_mount_info mount_info = {
2725 .fill_super = nfs4_fill_super,
2726 .parsed = raw_data,
2727 };
David Howells54ceac42006-08-22 20:06:13 -04002728 struct nfs_server *server;
Trond Myklebust33852a12008-06-19 14:20:11 -04002729 struct nfs_fh *mntfh;
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002730 struct dentry *mntroot = ERR_PTR(-ENOMEM);
David Howellsf7b422b2006-06-09 09:34:33 -04002731
Trond Myklebustb157b062010-04-19 19:05:48 -04002732 mntfh = nfs_alloc_fhandle();
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002733 if (mount_info.parsed == NULL || mntfh == NULL)
Jeff Layton8a0d5512011-12-20 06:57:45 -05002734 goto out;
Eric Parisf9c3a382008-03-05 14:20:18 -05002735
David Howells54ceac42006-08-22 20:06:13 -04002736 /* Get a volume representation */
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002737 server = nfs4_create_server(mount_info.parsed, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002738 if (IS_ERR(server)) {
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002739 mntroot = ERR_CAST(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04002740 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002741 }
2742
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002743 mntroot = nfs_fs_mount_common(fs_type, server, flags,
2744 dev_name, mntfh, &mount_info);
David Howells54ceac42006-08-22 20:06:13 -04002745
Chuck Lever29eb9812007-07-01 12:12:30 -04002746out:
Trond Myklebustb157b062010-04-19 19:05:48 -04002747 nfs_free_fhandle(mntfh);
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04002748 return mntroot;
David Howellsf7b422b2006-06-09 09:34:33 -04002749}
2750
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002751static struct vfsmount *nfs_do_root_mount(struct file_system_type *fs_type,
2752 int flags, void *data, const char *hostname)
2753{
2754 struct vfsmount *root_mnt;
2755 char *root_devname;
2756 size_t len;
2757
Jan Kara98a21392011-09-03 01:09:43 +02002758 len = strlen(hostname) + 5;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002759 root_devname = kmalloc(len, GFP_KERNEL);
2760 if (root_devname == NULL)
2761 return ERR_PTR(-ENOMEM);
Jan Kara98a21392011-09-03 01:09:43 +02002762 /* Does hostname needs to be enclosed in brackets? */
2763 if (strchr(hostname, ':'))
2764 snprintf(root_devname, len, "[%s]:/", hostname);
2765 else
2766 snprintf(root_devname, len, "%s:/", hostname);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002767 root_mnt = vfs_kern_mount(fs_type, flags, root_devname, data);
2768 kfree(root_devname);
2769 return root_mnt;
2770}
2771
Trond Myklebustce587e02010-04-16 16:22:52 -04002772struct nfs_referral_count {
2773 struct list_head list;
2774 const struct task_struct *task;
2775 unsigned int referral_count;
2776};
2777
2778static LIST_HEAD(nfs_referral_count_list);
2779static DEFINE_SPINLOCK(nfs_referral_count_list_lock);
2780
2781static struct nfs_referral_count *nfs_find_referral_count(void)
2782{
2783 struct nfs_referral_count *p;
2784
2785 list_for_each_entry(p, &nfs_referral_count_list, list) {
2786 if (p->task == current)
2787 return p;
2788 }
2789 return NULL;
2790}
2791
2792#define NFS_MAX_NESTED_REFERRALS 2
2793
2794static int nfs_referral_loop_protect(void)
2795{
2796 struct nfs_referral_count *p, *new;
2797 int ret = -ENOMEM;
2798
2799 new = kmalloc(sizeof(*new), GFP_KERNEL);
2800 if (!new)
2801 goto out;
2802 new->task = current;
2803 new->referral_count = 1;
2804
2805 ret = 0;
2806 spin_lock(&nfs_referral_count_list_lock);
2807 p = nfs_find_referral_count();
2808 if (p != NULL) {
2809 if (p->referral_count >= NFS_MAX_NESTED_REFERRALS)
2810 ret = -ELOOP;
2811 else
2812 p->referral_count++;
2813 } else {
2814 list_add(&new->list, &nfs_referral_count_list);
2815 new = NULL;
2816 }
2817 spin_unlock(&nfs_referral_count_list_lock);
2818 kfree(new);
2819out:
2820 return ret;
2821}
2822
2823static void nfs_referral_loop_unprotect(void)
2824{
2825 struct nfs_referral_count *p;
2826
2827 spin_lock(&nfs_referral_count_list_lock);
2828 p = nfs_find_referral_count();
2829 p->referral_count--;
2830 if (p->referral_count == 0)
2831 list_del(&p->list);
2832 else
2833 p = NULL;
2834 spin_unlock(&nfs_referral_count_list_lock);
2835 kfree(p);
2836}
2837
Al Viro01194982011-03-16 07:25:36 -04002838static struct dentry *nfs_follow_remote_path(struct vfsmount *root_mnt,
2839 const char *export_path)
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002840{
Al Viro01194982011-03-16 07:25:36 -04002841 struct dentry *dentry;
Al Viro5352d3b2011-11-16 21:52:06 -05002842 int err;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002843
Al Viro5352d3b2011-11-16 21:52:06 -05002844 if (IS_ERR(root_mnt))
2845 return ERR_CAST(root_mnt);
2846
2847 err = nfs_referral_loop_protect();
2848 if (err) {
Al Viroea441d12011-11-16 21:43:59 -05002849 mntput(root_mnt);
Al Viro5352d3b2011-11-16 21:52:06 -05002850 return ERR_PTR(err);
Al Viroc1334492011-11-16 16:12:14 -05002851 }
Trond Myklebustce587e02010-04-16 16:22:52 -04002852
Al Viroea441d12011-11-16 21:43:59 -05002853 dentry = mount_subtree(root_mnt, export_path);
2854 nfs_referral_loop_unprotect();
Linus Torvaldsa2770d82009-12-17 12:51:05 -08002855
Al Viro01194982011-03-16 07:25:36 -04002856 return dentry;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002857}
2858
Al Viro01194982011-03-16 07:25:36 -04002859static struct dentry *nfs4_try_mount(int flags, const char *dev_name,
2860 struct nfs_parsed_mount_data *data)
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002861{
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002862 char *export_path;
2863 struct vfsmount *root_mnt;
Al Viro01194982011-03-16 07:25:36 -04002864 struct dentry *res;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002865
Chuck Levera6fe23b2009-09-08 19:50:00 -04002866 dfprintk(MOUNT, "--> nfs4_try_mount()\n");
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002867
2868 export_path = data->nfs_server.export_path;
2869 data->nfs_server.export_path = "/";
2870 root_mnt = nfs_do_root_mount(&nfs4_remote_fs_type, flags, data,
2871 data->nfs_server.hostname);
2872 data->nfs_server.export_path = export_path;
2873
Al Viro5352d3b2011-11-16 21:52:06 -05002874 res = nfs_follow_remote_path(root_mnt, export_path);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002875
Al Viro01194982011-03-16 07:25:36 -04002876 dfprintk(MOUNT, "<-- nfs4_try_mount() = %ld%s\n",
2877 IS_ERR(res) ? PTR_ERR(res) : 0,
2878 IS_ERR(res) ? " [error]" : "");
2879 return res;
Chuck Levera6fe23b2009-09-08 19:50:00 -04002880}
2881
2882/*
2883 * Get the superblock for an NFS4 mountpoint
2884 */
Al Viro01194982011-03-16 07:25:36 -04002885static struct dentry *nfs4_mount(struct file_system_type *fs_type,
2886 int flags, const char *dev_name, void *raw_data)
Chuck Levera6fe23b2009-09-08 19:50:00 -04002887{
2888 struct nfs_parsed_mount_data *data;
2889 int error = -ENOMEM;
Al Viro01194982011-03-16 07:25:36 -04002890 struct dentry *res = ERR_PTR(-ENOMEM);
Chuck Levera6fe23b2009-09-08 19:50:00 -04002891
Trond Myklebustc5811db2009-10-06 15:40:15 -04002892 data = nfs_alloc_parsed_mount_data(4);
Chuck Levera6fe23b2009-09-08 19:50:00 -04002893 if (data == NULL)
Jeff Layton8a0d5512011-12-20 06:57:45 -05002894 goto out;
Chuck Levera6fe23b2009-09-08 19:50:00 -04002895
2896 /* Validate the mount data */
2897 error = nfs4_validate_mount_data(raw_data, data, dev_name);
Al Viro01194982011-03-16 07:25:36 -04002898 if (error < 0) {
2899 res = ERR_PTR(error);
Chuck Levera6fe23b2009-09-08 19:50:00 -04002900 goto out;
Al Viro01194982011-03-16 07:25:36 -04002901 }
Chuck Levera6fe23b2009-09-08 19:50:00 -04002902
Al Viro01194982011-03-16 07:25:36 -04002903 res = nfs4_try_mount(flags, dev_name, data);
2904 if (IS_ERR(res))
2905 error = PTR_ERR(res);
Chuck Levera6fe23b2009-09-08 19:50:00 -04002906
2907out:
Jeff Layton8a0d5512011-12-20 06:57:45 -05002908 nfs_free_parsed_mount_data(data);
Al Viro01194982011-03-16 07:25:36 -04002909 dprintk("<-- nfs4_mount() = %d%s\n", error,
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002910 error != 0 ? " [error]" : "");
Al Viro01194982011-03-16 07:25:36 -04002911 return res;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002912}
2913
David Howellsf7b422b2006-06-09 09:34:33 -04002914static void nfs4_kill_super(struct super_block *sb)
2915{
2916 struct nfs_server *server = NFS_SB(sb);
2917
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002918 dprintk("--> %s\n", __func__);
Trond Myklebust515d8612008-12-23 15:21:46 -05002919 nfs_super_return_all_delegations(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002920 kill_anon_super(sb);
David Howells08734042009-04-03 16:42:42 +01002921 nfs_fscache_release_super_cookie(sb);
David Howells54ceac42006-08-22 20:06:13 -04002922 nfs_free_server(server);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002923 dprintk("<-- %s\n", __func__);
David Howellsf7b422b2006-06-09 09:34:33 -04002924}
2925
2926/*
David Howells54ceac42006-08-22 20:06:13 -04002927 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -04002928 */
Al Viro31f43472010-10-29 03:38:12 -04002929static struct dentry *
2930nfs4_xdev_mount(struct file_system_type *fs_type, int flags,
2931 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002932{
2933 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002934 struct super_block *s;
2935 struct nfs_server *server;
2936 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002937 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002938 struct nfs_sb_mountdata sb_mntdata = {
2939 .mntflags = flags,
2940 };
David Howells54ceac42006-08-22 20:06:13 -04002941 int error;
2942
Al Viro31f43472010-10-29 03:38:12 -04002943 dprintk("--> nfs4_xdev_mount()\n");
David Howells54ceac42006-08-22 20:06:13 -04002944
2945 /* create a new volume representation */
Bryan Schumaker7e6eb682012-04-27 13:27:42 -04002946 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr, data->authflavor);
David Howells54ceac42006-08-22 20:06:13 -04002947 if (IS_ERR(server)) {
2948 error = PTR_ERR(server);
2949 goto out_err_noserver;
2950 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002951 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002952
Bryan Schumaker586f95c2012-05-10 15:07:33 -04002953 if (server->flags & NFS_MOUNT_UNSHARED)
Trond Myklebust75180df2007-05-16 16:53:28 -04002954 compare_super = NULL;
2955
Sachin Prabhufb2088c2011-08-01 12:10:12 +01002956 /* -o noac implies -o sync */
2957 if (server->flags & NFS_MOUNT_NOAC)
2958 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2959
David Howells54ceac42006-08-22 20:06:13 -04002960 /* Get a superblock - note that we may end up sharing one that already exists */
Andy Adamsonec9a05c2008-10-17 10:44:37 -04002961 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002962 if (IS_ERR(s)) {
2963 error = PTR_ERR(s);
2964 goto out_err_nosb;
2965 }
2966
2967 if (s->s_fs_info != server) {
2968 nfs_free_server(server);
2969 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002970 } else {
2971 error = nfs_bdi_register(server);
2972 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11002973 goto error_splat_bdi;
David Howells54ceac42006-08-22 20:06:13 -04002974 }
2975
2976 if (!s->s_root) {
2977 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002978 nfs4_clone_super(s, data->sb);
Bryan Schumaker2311b942012-05-10 15:07:32 -04002979 nfs_get_cache_cookie(s, NULL, data);
David Howells54ceac42006-08-22 20:06:13 -04002980 }
2981
Bryan Schumakerbae36242012-05-10 15:07:31 -04002982 mntroot = nfs_get_root(s, data->fh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04002983 if (IS_ERR(mntroot)) {
2984 error = PTR_ERR(mntroot);
2985 goto error_splat_super;
2986 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002987 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2988 dput(mntroot);
2989 error = -ESTALE;
2990 goto error_splat_super;
2991 }
David Howells54ceac42006-08-22 20:06:13 -04002992
2993 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002994
Eric Paris46c8ac72008-05-02 13:42:42 -07002995 security_sb_clone_mnt_opts(data->sb, s);
2996
Al Viro31f43472010-10-29 03:38:12 -04002997 dprintk("<-- nfs4_xdev_mount() = 0\n");
2998 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04002999
3000out_err_nosb:
3001 nfs_free_server(server);
3002out_err_noserver:
Al Viro31f43472010-10-29 03:38:12 -04003003 dprintk("<-- nfs4_xdev_mount() = %d [error]\n", error);
3004 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04003005
3006error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11003007 if (server && !s->s_root)
3008 bdi_unregister(&server->backing_dev_info);
3009error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04003010 deactivate_locked_super(s);
Al Viro31f43472010-10-29 03:38:12 -04003011 dprintk("<-- nfs4_xdev_mount() = %d [splat]\n", error);
3012 return ERR_PTR(error);
David Howellsf7b422b2006-06-09 09:34:33 -04003013}
3014
Al Viro31f43472010-10-29 03:38:12 -04003015static struct dentry *
3016nfs4_remote_referral_mount(struct file_system_type *fs_type, int flags,
3017 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04003018{
3019 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04003020 struct super_block *s;
3021 struct nfs_server *server;
3022 struct dentry *mntroot;
Trond Myklebust4f727292010-04-16 16:22:48 -04003023 struct nfs_fh *mntfh;
Trond Myklebust75180df2007-05-16 16:53:28 -04003024 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04003025 struct nfs_sb_mountdata sb_mntdata = {
3026 .mntflags = flags,
3027 };
Trond Myklebust4f727292010-04-16 16:22:48 -04003028 int error = -ENOMEM;
David Howells54ceac42006-08-22 20:06:13 -04003029
3030 dprintk("--> nfs4_referral_get_sb()\n");
3031
Trond Myklebust4f727292010-04-16 16:22:48 -04003032 mntfh = nfs_alloc_fhandle();
3033 if (mntfh == NULL)
3034 goto out_err_nofh;
3035
David Howells54ceac42006-08-22 20:06:13 -04003036 /* create a new volume representation */
Trond Myklebust4f727292010-04-16 16:22:48 -04003037 server = nfs4_create_referral_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04003038 if (IS_ERR(server)) {
3039 error = PTR_ERR(server);
3040 goto out_err_noserver;
3041 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04003042 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04003043
Bryan Schumaker586f95c2012-05-10 15:07:33 -04003044 if (server->flags & NFS_MOUNT_UNSHARED)
Trond Myklebust75180df2007-05-16 16:53:28 -04003045 compare_super = NULL;
3046
Sachin Prabhufb2088c2011-08-01 12:10:12 +01003047 /* -o noac implies -o sync */
3048 if (server->flags & NFS_MOUNT_NOAC)
3049 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
3050
David Howells54ceac42006-08-22 20:06:13 -04003051 /* Get a superblock - note that we may end up sharing one that already exists */
Andy Adamsonec9a05c2008-10-17 10:44:37 -04003052 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04003053 if (IS_ERR(s)) {
3054 error = PTR_ERR(s);
3055 goto out_err_nosb;
3056 }
3057
3058 if (s->s_fs_info != server) {
3059 nfs_free_server(server);
3060 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07003061 } else {
3062 error = nfs_bdi_register(server);
3063 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11003064 goto error_splat_bdi;
David Howells54ceac42006-08-22 20:06:13 -04003065 }
3066
3067 if (!s->s_root) {
3068 /* initial superblock/root creation */
Bryan Schumakerc40f8d12012-05-10 15:07:34 -04003069 nfs4_fill_super(s, NULL);
Bryan Schumaker2311b942012-05-10 15:07:32 -04003070 nfs_get_cache_cookie(s, NULL, data);
David Howells54ceac42006-08-22 20:06:13 -04003071 }
3072
Bryan Schumakerbae36242012-05-10 15:07:31 -04003073 mntroot = nfs_get_root(s, mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04003074 if (IS_ERR(mntroot)) {
3075 error = PTR_ERR(mntroot);
3076 goto error_splat_super;
3077 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05003078 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
3079 dput(mntroot);
3080 error = -ESTALE;
3081 goto error_splat_super;
3082 }
David Howells54ceac42006-08-22 20:06:13 -04003083
3084 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04003085
Eric Paris46c8ac72008-05-02 13:42:42 -07003086 security_sb_clone_mnt_opts(data->sb, s);
3087
Trond Myklebust4f727292010-04-16 16:22:48 -04003088 nfs_free_fhandle(mntfh);
David Howells54ceac42006-08-22 20:06:13 -04003089 dprintk("<-- nfs4_referral_get_sb() = 0\n");
Al Viro31f43472010-10-29 03:38:12 -04003090 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04003091
3092out_err_nosb:
3093 nfs_free_server(server);
3094out_err_noserver:
Trond Myklebust4f727292010-04-16 16:22:48 -04003095 nfs_free_fhandle(mntfh);
3096out_err_nofh:
David Howells54ceac42006-08-22 20:06:13 -04003097 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
Al Viro31f43472010-10-29 03:38:12 -04003098 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04003099
3100error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11003101 if (server && !s->s_root)
3102 bdi_unregister(&server->backing_dev_info);
3103error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04003104 deactivate_locked_super(s);
Trond Myklebust4f727292010-04-16 16:22:48 -04003105 nfs_free_fhandle(mntfh);
David Howells54ceac42006-08-22 20:06:13 -04003106 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
Al Viro31f43472010-10-29 03:38:12 -04003107 return ERR_PTR(error);
David Howellsf7b422b2006-06-09 09:34:33 -04003108}
3109
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04003110/*
3111 * Create an NFS4 server record on referral traversal
3112 */
Al Viro01194982011-03-16 07:25:36 -04003113static struct dentry *nfs4_referral_mount(struct file_system_type *fs_type,
3114 int flags, const char *dev_name, void *raw_data)
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04003115{
3116 struct nfs_clone_mount *data = raw_data;
3117 char *export_path;
3118 struct vfsmount *root_mnt;
Al Viro01194982011-03-16 07:25:36 -04003119 struct dentry *res;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04003120
Al Viro01194982011-03-16 07:25:36 -04003121 dprintk("--> nfs4_referral_mount()\n");
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04003122
3123 export_path = data->mnt_path;
3124 data->mnt_path = "/";
3125
3126 root_mnt = nfs_do_root_mount(&nfs4_remote_referral_fs_type,
3127 flags, data, data->hostname);
3128 data->mnt_path = export_path;
3129
Al Viro5352d3b2011-11-16 21:52:06 -05003130 res = nfs_follow_remote_path(root_mnt, export_path);
Al Viro01194982011-03-16 07:25:36 -04003131 dprintk("<-- nfs4_referral_mount() = %ld%s\n",
3132 IS_ERR(res) ? PTR_ERR(res) : 0,
3133 IS_ERR(res) ? " [error]" : "");
3134 return res;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04003135}
3136
David Howells54ceac42006-08-22 20:06:13 -04003137#endif /* CONFIG_NFS_V4 */