blob: f4ccdae6a0cfef40bc5608671acba4e3178e265b [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>
David Howellsf7b422b2006-06-09 09:34:33 -040056
57#include <asm/system.h>
58#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
Al Viro42faad92008-04-24 07:21:56 -0400280static void nfs_umount_begin(struct super_block *);
Trond Myklebust816724e2006-06-24 08:41:41 -0400281static int nfs_statfs(struct dentry *, struct kstatfs *);
Al Viro34c80b12011-12-08 21:32:45 -0500282static int nfs_show_options(struct seq_file *, struct dentry *);
Al Virod861c632011-12-08 21:32:45 -0500283static int nfs_show_devname(struct seq_file *, struct dentry *);
Al Viroa6322de2011-12-08 21:37:57 -0500284static int nfs_show_path(struct seq_file *, struct dentry *);
Al Viro64132372011-12-08 20:51:13 -0500285static int nfs_show_stats(struct seq_file *, struct dentry *);
Al Viro01194982011-03-16 07:25:36 -0400286static struct dentry *nfs_fs_mount(struct file_system_type *,
287 int, const char *, void *);
Al Viro31f43472010-10-29 03:38:12 -0400288static struct dentry *nfs_xdev_mount(struct file_system_type *fs_type,
289 int flags, const char *dev_name, void *raw_data);
Trond Myklebust387c1492010-02-03 08:27:35 -0500290static void nfs_put_super(struct super_block *);
David Howellsf7b422b2006-06-09 09:34:33 -0400291static void nfs_kill_super(struct super_block *);
Jeff Layton48b605f2008-06-10 15:38:39 -0400292static int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
David Howellsf7b422b2006-06-09 09:34:33 -0400293
294static struct file_system_type nfs_fs_type = {
295 .owner = THIS_MODULE,
296 .name = "nfs",
Al Viro01194982011-03-16 07:25:36 -0400297 .mount = nfs_fs_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400298 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700299 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400300};
301
David Howells54ceac42006-08-22 20:06:13 -0400302struct file_system_type nfs_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400303 .owner = THIS_MODULE,
304 .name = "nfs",
Al Viro31f43472010-10-29 03:38:12 -0400305 .mount = nfs_xdev_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400306 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700307 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400308};
309
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800310static const struct super_operations nfs_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400311 .alloc_inode = nfs_alloc_inode,
312 .destroy_inode = nfs_destroy_inode,
313 .write_inode = nfs_write_inode,
Trond Myklebust387c1492010-02-03 08:27:35 -0500314 .put_super = nfs_put_super,
David Howellsf7b422b2006-06-09 09:34:33 -0400315 .statfs = nfs_statfs,
Al Virob57922d2010-06-07 14:34:48 -0400316 .evict_inode = nfs_evict_inode,
David Howellsf7b422b2006-06-09 09:34:33 -0400317 .umount_begin = nfs_umount_begin,
318 .show_options = nfs_show_options,
Al Viroc7f404b2011-03-16 06:59:40 -0400319 .show_devname = nfs_show_devname,
320 .show_path = nfs_show_path,
David Howellsf7b422b2006-06-09 09:34:33 -0400321 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400322 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400323};
324
325#ifdef CONFIG_NFS_V4
Chuck Lever7630c852009-09-08 19:49:57 -0400326static int nfs4_validate_text_mount_data(void *options,
327 struct nfs_parsed_mount_data *args, const char *dev_name);
Al Viro01194982011-03-16 07:25:36 -0400328static struct dentry *nfs4_try_mount(int flags, const char *dev_name,
329 struct nfs_parsed_mount_data *data);
330static struct dentry *nfs4_mount(struct file_system_type *fs_type,
331 int flags, const char *dev_name, void *raw_data);
Al Viro31f43472010-10-29 03:38:12 -0400332static struct dentry *nfs4_remote_mount(struct file_system_type *fs_type,
333 int flags, const char *dev_name, void *raw_data);
334static struct dentry *nfs4_xdev_mount(struct file_system_type *fs_type,
335 int flags, const char *dev_name, void *raw_data);
Al Viro01194982011-03-16 07:25:36 -0400336static struct dentry *nfs4_referral_mount(struct file_system_type *fs_type,
337 int flags, const char *dev_name, void *raw_data);
Al Viro31f43472010-10-29 03:38:12 -0400338static struct dentry *nfs4_remote_referral_mount(struct file_system_type *fs_type,
339 int flags, const char *dev_name, void *raw_data);
David Howellsf7b422b2006-06-09 09:34:33 -0400340static void nfs4_kill_super(struct super_block *sb);
341
342static struct file_system_type nfs4_fs_type = {
343 .owner = THIS_MODULE,
344 .name = "nfs4",
Al Viro01194982011-03-16 07:25:36 -0400345 .mount = nfs4_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400346 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700347 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400348};
349
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400350static struct file_system_type nfs4_remote_fs_type = {
351 .owner = THIS_MODULE,
352 .name = "nfs4",
Al Viro31f43472010-10-29 03:38:12 -0400353 .mount = nfs4_remote_mount,
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400354 .kill_sb = nfs4_kill_super,
355 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
356};
357
David Howells54ceac42006-08-22 20:06:13 -0400358struct file_system_type nfs4_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400359 .owner = THIS_MODULE,
360 .name = "nfs4",
Al Viro31f43472010-10-29 03:38:12 -0400361 .mount = nfs4_xdev_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400362 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700363 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400364};
365
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400366static struct file_system_type nfs4_remote_referral_fs_type = {
367 .owner = THIS_MODULE,
368 .name = "nfs4",
Al Viro31f43472010-10-29 03:38:12 -0400369 .mount = nfs4_remote_referral_mount,
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400370 .kill_sb = nfs4_kill_super,
371 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
372};
373
David Howells54ceac42006-08-22 20:06:13 -0400374struct file_system_type nfs4_referral_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400375 .owner = THIS_MODULE,
376 .name = "nfs4",
Al Viro01194982011-03-16 07:25:36 -0400377 .mount = nfs4_referral_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400378 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700379 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400380};
381
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800382static const struct super_operations nfs4_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400383 .alloc_inode = nfs_alloc_inode,
384 .destroy_inode = nfs_destroy_inode,
385 .write_inode = nfs_write_inode,
Trond Myklebust387c1492010-02-03 08:27:35 -0500386 .put_super = nfs_put_super,
David Howellsf7b422b2006-06-09 09:34:33 -0400387 .statfs = nfs_statfs,
Al Virob57922d2010-06-07 14:34:48 -0400388 .evict_inode = nfs4_evict_inode,
David Howellsf7b422b2006-06-09 09:34:33 -0400389 .umount_begin = nfs_umount_begin,
390 .show_options = nfs_show_options,
Al Viroc7f404b2011-03-16 06:59:40 -0400391 .show_devname = nfs_show_devname,
392 .show_path = nfs_show_path,
David Howellsf7b422b2006-06-09 09:34:33 -0400393 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400394 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400395};
396#endif
397
Rusty Russell8e1f9362007-07-17 04:03:17 -0700398static struct shrinker acl_shrinker = {
399 .shrink = nfs_access_cache_shrinker,
400 .seeks = DEFAULT_SEEKS,
401};
Trond Myklebust979df722006-07-25 11:28:19 -0400402
David Howellsf7b422b2006-06-09 09:34:33 -0400403/*
404 * Register the NFS filesystems
405 */
406int __init register_nfs_fs(void)
407{
408 int ret;
409
410 ret = register_filesystem(&nfs_fs_type);
411 if (ret < 0)
412 goto error_0;
413
David Howellsf7b422b2006-06-09 09:34:33 -0400414 ret = nfs_register_sysctl();
415 if (ret < 0)
416 goto error_1;
Peter Zijlstra89a09142007-03-16 13:38:26 -0800417#ifdef CONFIG_NFS_V4
David Howellsf7b422b2006-06-09 09:34:33 -0400418 ret = register_filesystem(&nfs4_fs_type);
419 if (ret < 0)
420 goto error_2;
421#endif
Rusty Russell8e1f9362007-07-17 04:03:17 -0700422 register_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400423 return 0;
424
425#ifdef CONFIG_NFS_V4
426error_2:
427 nfs_unregister_sysctl();
Peter Zijlstra89a09142007-03-16 13:38:26 -0800428#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400429error_1:
430 unregister_filesystem(&nfs_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400431error_0:
432 return ret;
433}
434
435/*
436 * Unregister the NFS filesystems
437 */
438void __exit unregister_nfs_fs(void)
439{
Rusty Russell8e1f9362007-07-17 04:03:17 -0700440 unregister_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400441#ifdef CONFIG_NFS_V4
442 unregister_filesystem(&nfs4_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400443#endif
Alexey Dobriyan49af7ee2007-09-18 22:46:40 -0700444 nfs_unregister_sysctl();
David Howellsf7b422b2006-06-09 09:34:33 -0400445 unregister_filesystem(&nfs_fs_type);
446}
447
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400448void nfs_sb_active(struct super_block *sb)
Steve Dicksonef818a22007-11-08 04:05:04 -0500449{
450 struct nfs_server *server = NFS_SB(sb);
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400451
452 if (atomic_inc_return(&server->active) == 1)
453 atomic_inc(&sb->s_active);
454}
455
456void nfs_sb_deactive(struct super_block *sb)
457{
458 struct nfs_server *server = NFS_SB(sb);
459
460 if (atomic_dec_and_test(&server->active))
461 deactivate_super(sb);
Steve Dicksonef818a22007-11-08 04:05:04 -0500462}
463
David Howellsf7b422b2006-06-09 09:34:33 -0400464/*
465 * Deliver file system statistics to userspace
466 */
Trond Myklebust816724e2006-06-24 08:41:41 -0400467static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
David Howellsf7b422b2006-06-09 09:34:33 -0400468{
David Howells0c7d90c2006-08-22 20:06:10 -0400469 struct nfs_server *server = NFS_SB(dentry->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400470 unsigned char blockbits;
471 unsigned long blockres;
David Howells0c7d90c2006-08-22 20:06:10 -0400472 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400473 struct nfs_fsstat res;
474 int error = -ENOMEM;
475
476 res.fattr = nfs_alloc_fattr();
477 if (res.fattr == NULL)
478 goto out_err;
David Howellsf7b422b2006-06-09 09:34:33 -0400479
David Howells8fa5c002006-08-22 20:06:12 -0400480 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
Menyhart Zoltanfbf3fdd2010-09-12 19:55:26 -0400481 if (unlikely(error == -ESTALE)) {
482 struct dentry *pd_dentry;
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400483
Menyhart Zoltanfbf3fdd2010-09-12 19:55:26 -0400484 pd_dentry = dget_parent(dentry);
485 if (pd_dentry != NULL) {
486 nfs_zap_caches(pd_dentry->d_inode);
487 dput(pd_dentry);
488 }
489 }
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400490 nfs_free_fattr(res.fattr);
David Howellsf7b422b2006-06-09 09:34:33 -0400491 if (error < 0)
492 goto out_err;
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400493
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700494 buf->f_type = NFS_SUPER_MAGIC;
David Howellsf7b422b2006-06-09 09:34:33 -0400495
496 /*
497 * Current versions of glibc do not correctly handle the
498 * case where f_frsize != f_bsize. Eventually we want to
499 * report the value of wtmult in this field.
500 */
David Howells0c7d90c2006-08-22 20:06:10 -0400501 buf->f_frsize = dentry->d_sb->s_blocksize;
David Howellsf7b422b2006-06-09 09:34:33 -0400502
503 /*
504 * On most *nix systems, f_blocks, f_bfree, and f_bavail
505 * are reported in units of f_frsize. Linux hasn't had
506 * an f_frsize field in its statfs struct until recently,
507 * thus historically Linux's sys_statfs reports these
508 * fields in units of f_bsize.
509 */
David Howells0c7d90c2006-08-22 20:06:10 -0400510 buf->f_bsize = dentry->d_sb->s_blocksize;
511 blockbits = dentry->d_sb->s_blocksize_bits;
David Howellsf7b422b2006-06-09 09:34:33 -0400512 blockres = (1 << blockbits) - 1;
513 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
514 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
515 buf->f_bavail = (res.abytes + blockres) >> blockbits;
516
517 buf->f_files = res.tfiles;
518 buf->f_ffree = res.afiles;
519
520 buf->f_namelen = server->namelen;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700521
David Howellsf7b422b2006-06-09 09:34:33 -0400522 return 0;
523
524 out_err:
Harvey Harrison3110ff82008-05-02 13:42:44 -0700525 dprintk("%s: statfs error = %d\n", __func__, -error);
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700526 return error;
David Howellsf7b422b2006-06-09 09:34:33 -0400527}
528
David Howells7d4e2742006-08-22 20:06:07 -0400529/*
530 * Map the security flavour number to a name
531 */
Trond Myklebust81039f12006-06-09 09:34:34 -0400532static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
533{
David Howells7d4e2742006-08-22 20:06:07 -0400534 static const struct {
Trond Myklebust81039f12006-06-09 09:34:34 -0400535 rpc_authflavor_t flavour;
536 const char *str;
537 } sec_flavours[] = {
538 { RPC_AUTH_NULL, "null" },
539 { RPC_AUTH_UNIX, "sys" },
540 { RPC_AUTH_GSS_KRB5, "krb5" },
541 { RPC_AUTH_GSS_KRB5I, "krb5i" },
542 { RPC_AUTH_GSS_KRB5P, "krb5p" },
543 { RPC_AUTH_GSS_LKEY, "lkey" },
544 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
545 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
546 { RPC_AUTH_GSS_SPKM, "spkm" },
547 { RPC_AUTH_GSS_SPKMI, "spkmi" },
548 { RPC_AUTH_GSS_SPKMP, "spkmp" },
Chuck Lever4d81cd12007-07-01 12:12:40 -0400549 { UINT_MAX, "unknown" }
Trond Myklebust81039f12006-06-09 09:34:34 -0400550 };
551 int i;
552
Chuck Lever4d81cd12007-07-01 12:12:40 -0400553 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
Trond Myklebust81039f12006-06-09 09:34:34 -0400554 if (sec_flavours[i].flavour == flavour)
555 break;
556 }
557 return sec_flavours[i].str;
558}
559
Jeff Laytonee671b02009-12-03 15:58:56 -0500560static void nfs_show_mountd_netid(struct seq_file *m, struct nfs_server *nfss,
561 int showdefaults)
562{
563 struct sockaddr *sap = (struct sockaddr *) &nfss->mountd_address;
564
565 seq_printf(m, ",mountproto=");
566 switch (sap->sa_family) {
567 case AF_INET:
568 switch (nfss->mountd_protocol) {
569 case IPPROTO_UDP:
570 seq_printf(m, RPCBIND_NETID_UDP);
571 break;
572 case IPPROTO_TCP:
573 seq_printf(m, RPCBIND_NETID_TCP);
574 break;
575 default:
576 if (showdefaults)
577 seq_printf(m, "auto");
578 }
579 break;
580 case AF_INET6:
581 switch (nfss->mountd_protocol) {
582 case IPPROTO_UDP:
583 seq_printf(m, RPCBIND_NETID_UDP6);
584 break;
585 case IPPROTO_TCP:
586 seq_printf(m, RPCBIND_NETID_TCP6);
587 break;
588 default:
589 if (showdefaults)
590 seq_printf(m, "auto");
591 }
592 break;
593 default:
594 if (showdefaults)
595 seq_printf(m, "auto");
596 }
597}
598
Chuck Lever82d101d2008-03-14 14:10:37 -0400599static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
600 int showdefaults)
601{
602 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
603
Bryan Schumakerd5eff1a2010-08-03 13:04:00 -0400604 if (nfss->flags & NFS_MOUNT_LEGACY_INTERFACE)
605 return;
606
Chuck Lever82d101d2008-03-14 14:10:37 -0400607 switch (sap->sa_family) {
608 case AF_INET: {
609 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
Harvey Harrisonbe859402008-10-31 00:56:28 -0700610 seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400611 break;
612 }
613 case AF_INET6: {
614 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
Chuck Leverd250e192009-12-03 15:58:56 -0500615 seq_printf(m, ",mountaddr=%pI6c", &sin6->sin6_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400616 break;
617 }
618 default:
619 if (showdefaults)
620 seq_printf(m, ",mountaddr=unspecified");
621 }
622
623 if (nfss->mountd_version || showdefaults)
624 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
Stanislav Kinsburskyaa699472010-12-08 12:40:13 +0300625 if ((nfss->mountd_port &&
626 nfss->mountd_port != (unsigned short)NFS_UNSPEC_PORT) ||
627 showdefaults)
Chuck Lever82d101d2008-03-14 14:10:37 -0400628 seq_printf(m, ",mountport=%u", nfss->mountd_port);
629
Jeff Laytonee671b02009-12-03 15:58:56 -0500630 nfs_show_mountd_netid(m, nfss, showdefaults);
Chuck Lever82d101d2008-03-14 14:10:37 -0400631}
632
Trond Myklebust0be81892010-06-18 12:23:58 -0400633#ifdef CONFIG_NFS_V4
634static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
635 int showdefaults)
636{
637 struct nfs_client *clp = nfss->nfs_client;
638
639 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
Trond Myklebust0be81892010-06-18 12:23:58 -0400640}
641#else
642static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
643 int showdefaults)
644{
645}
646#endif
647
Trond Myklebust7bbceb62012-03-02 14:00:20 -0500648static void nfs_show_nfs_version(struct seq_file *m,
649 unsigned int version,
650 unsigned int minorversion)
651{
652 seq_printf(m, ",vers=%u", version);
653 if (version == 4)
654 seq_printf(m, ".%u", minorversion);
655}
656
David Howellsf7b422b2006-06-09 09:34:33 -0400657/*
658 * Describe the mount options in force on this server representation
659 */
Chuck Lever82d101d2008-03-14 14:10:37 -0400660static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
661 int showdefaults)
David Howellsf7b422b2006-06-09 09:34:33 -0400662{
David Howells509de812006-08-22 20:06:11 -0400663 static const struct proc_nfs_info {
David Howellsf7b422b2006-06-09 09:34:33 -0400664 int flag;
David Howells509de812006-08-22 20:06:11 -0400665 const char *str;
666 const char *nostr;
David Howellsf7b422b2006-06-09 09:34:33 -0400667 } nfs_info[] = {
668 { NFS_MOUNT_SOFT, ",soft", ",hard" },
Chuck Lever82d101d2008-03-14 14:10:37 -0400669 { NFS_MOUNT_POSIX, ",posix", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400670 { NFS_MOUNT_NOCTO, ",nocto", "" },
671 { NFS_MOUNT_NOAC, ",noac", "" },
672 { NFS_MOUNT_NONLM, ",nolock", "" },
673 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400674 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
Chuck Leverd7403512008-12-23 15:21:37 -0500675 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
676 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400677 { 0, NULL, NULL }
678 };
David Howells509de812006-08-22 20:06:11 -0400679 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400680 struct nfs_client *clp = nfss->nfs_client;
Chuck Lever82d101d2008-03-14 14:10:37 -0400681 u32 version = clp->rpc_ops->version;
Suresh Jayaraman7c563cc2010-09-23 14:26:48 -0400682 int local_flock, local_fcntl;
David Howellsf7b422b2006-06-09 09:34:33 -0400683
Trond Myklebust7bbceb62012-03-02 14:00:20 -0500684 nfs_show_nfs_version(m, version, clp->cl_minorversion);
Chuck Lever2d767432008-03-14 14:10:08 -0400685 seq_printf(m, ",rsize=%u", nfss->rsize);
686 seq_printf(m, ",wsize=%u", nfss->wsize);
Chuck Lever82d101d2008-03-14 14:10:37 -0400687 if (nfss->bsize != 0)
688 seq_printf(m, ",bsize=%u", nfss->bsize);
689 seq_printf(m, ",namlen=%u", nfss->namelen);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400690 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400691 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400692 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400693 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400694 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400695 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400696 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400697 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
David Howellsf7b422b2006-06-09 09:34:33 -0400698 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
699 if (nfss->flags & nfs_infop->flag)
700 seq_puts(m, nfs_infop->str);
701 else
702 seq_puts(m, nfs_infop->nostr);
703 }
\"Talpey, Thomas\56928ed2007-09-10 13:48:47 -0400704 seq_printf(m, ",proto=%s",
Jeff Laytonee671b02009-12-03 15:58:56 -0500705 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
Chuck Lever82d101d2008-03-14 14:10:37 -0400706 if (version == 4) {
707 if (nfss->port != NFS_PORT)
708 seq_printf(m, ",port=%u", nfss->port);
709 } else
710 if (nfss->port)
711 seq_printf(m, ",port=%u", nfss->port);
712
Trond Myklebust33170232007-12-20 16:03:59 -0500713 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
714 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
Trond Myklebust81039f12006-06-09 09:34:34 -0400715 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
Chuck Lever82d101d2008-03-14 14:10:37 -0400716
717 if (version != 4)
718 nfs_show_mountd_options(m, nfss, showdefaults);
Trond Myklebust0be81892010-06-18 12:23:58 -0400719 else
720 nfs_show_nfsv4_options(m, nfss, showdefaults);
Chuck Lever82d101d2008-03-14 14:10:37 -0400721
David Howellsb797cac2009-04-03 16:42:48 +0100722 if (nfss->options & NFS_OPTION_FSCACHE)
723 seq_printf(m, ",fsc");
Patrick J. LoPresti9b00c642010-08-10 17:28:01 -0400724
725 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONEG) {
726 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONE)
727 seq_printf(m, ",lookupcache=none");
728 else
729 seq_printf(m, ",lookupcache=pos");
730 }
Suresh Jayaraman7c563cc2010-09-23 14:26:48 -0400731
732 local_flock = nfss->flags & NFS_MOUNT_LOCAL_FLOCK;
733 local_fcntl = nfss->flags & NFS_MOUNT_LOCAL_FCNTL;
734
735 if (!local_flock && !local_fcntl)
736 seq_printf(m, ",local_lock=none");
737 else if (local_flock && local_fcntl)
738 seq_printf(m, ",local_lock=all");
739 else if (local_flock)
740 seq_printf(m, ",local_lock=flock");
741 else
742 seq_printf(m, ",local_lock=posix");
David Howellsf7b422b2006-06-09 09:34:33 -0400743}
744
745/*
746 * Describe the mount options on this VFS mountpoint
747 */
Al Viro34c80b12011-12-08 21:32:45 -0500748static int nfs_show_options(struct seq_file *m, struct dentry *root)
David Howellsf7b422b2006-06-09 09:34:33 -0400749{
Al Viro34c80b12011-12-08 21:32:45 -0500750 struct nfs_server *nfss = NFS_SB(root->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400751
752 nfs_show_mount_options(m, nfss, 0);
753
Chuck Lever5d8515c2007-12-10 14:57:16 -0500754 seq_printf(m, ",addr=%s",
755 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
756 RPC_DISPLAY_ADDR));
David Howellsf7b422b2006-06-09 09:34:33 -0400757
758 return 0;
759}
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700760
761#ifdef CONFIG_NFS_V4
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300762#ifdef CONFIG_NFS_V4_1
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700763static void show_sessions(struct seq_file *m, struct nfs_server *server)
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300764{
765 if (nfs4_has_session(server->nfs_client))
766 seq_printf(m, ",sessions");
767}
768#else
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700769static void show_sessions(struct seq_file *m, struct nfs_server *server) {}
770#endif
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300771#endif
772
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700773#ifdef CONFIG_NFS_V4
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300774#ifdef CONFIG_NFS_V4_1
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700775static void show_pnfs(struct seq_file *m, struct nfs_server *server)
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300776{
777 seq_printf(m, ",pnfs=");
778 if (server->pnfs_curr_ld)
779 seq_printf(m, "%s", server->pnfs_curr_ld->name);
780 else
781 seq_printf(m, "not configured");
782}
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700783#else
784static void show_pnfs(struct seq_file *m, struct nfs_server *server) {}
785#endif
786#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400787
Al Virod861c632011-12-08 21:32:45 -0500788static int nfs_show_devname(struct seq_file *m, struct dentry *root)
Al Viroc7f404b2011-03-16 06:59:40 -0400789{
790 char *page = (char *) __get_free_page(GFP_KERNEL);
791 char *devname, *dummy;
792 int err = 0;
793 if (!page)
794 return -ENOMEM;
Al Virod861c632011-12-08 21:32:45 -0500795 devname = nfs_path(&dummy, root, page, PAGE_SIZE);
Al Viroc7f404b2011-03-16 06:59:40 -0400796 if (IS_ERR(devname))
797 err = PTR_ERR(devname);
798 else
799 seq_escape(m, devname, " \t\n\\");
800 free_page((unsigned long)page);
801 return err;
802}
803
Al Viroa6322de2011-12-08 21:37:57 -0500804static int nfs_show_path(struct seq_file *m, struct dentry *dentry)
Al Viroc7f404b2011-03-16 06:59:40 -0400805{
806 seq_puts(m, "/");
807 return 0;
808}
809
David Howellsf7b422b2006-06-09 09:34:33 -0400810/*
811 * Present statistical information for this VFS mountpoint
812 */
Al Viro64132372011-12-08 20:51:13 -0500813static int nfs_show_stats(struct seq_file *m, struct dentry *root)
David Howellsf7b422b2006-06-09 09:34:33 -0400814{
815 int i, cpu;
Al Viro64132372011-12-08 20:51:13 -0500816 struct nfs_server *nfss = NFS_SB(root->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400817 struct rpc_auth *auth = nfss->client->cl_auth;
818 struct nfs_iostats totals = { };
819
820 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
821
822 /*
823 * Display all mount option settings
824 */
825 seq_printf(m, "\n\topts:\t");
Al Viro64132372011-12-08 20:51:13 -0500826 seq_puts(m, root->d_sb->s_flags & MS_RDONLY ? "ro" : "rw");
827 seq_puts(m, root->d_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
828 seq_puts(m, root->d_sb->s_flags & MS_NOATIME ? ",noatime" : "");
829 seq_puts(m, root->d_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
David Howellsf7b422b2006-06-09 09:34:33 -0400830 nfs_show_mount_options(m, nfss, 1);
831
832 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
833
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500834 if (nfss->nfs_client && nfss->nfs_client->impl_id) {
835 struct nfs41_impl_id *impl_id = nfss->nfs_client->impl_id;
836 seq_printf(m, "\n\timpl_id:\tname='%s',domain='%s',"
837 "date='%llu,%u'",
838 impl_id->name, impl_id->domain,
839 impl_id->date.seconds, impl_id->date.nseconds);
840 }
841
David Howellsf7b422b2006-06-09 09:34:33 -0400842 seq_printf(m, "\n\tcaps:\t");
843 seq_printf(m, "caps=0x%x", nfss->caps);
Chuck Lever2d767432008-03-14 14:10:08 -0400844 seq_printf(m, ",wtmult=%u", nfss->wtmult);
845 seq_printf(m, ",dtsize=%u", nfss->dtsize);
846 seq_printf(m, ",bsize=%u", nfss->bsize);
847 seq_printf(m, ",namlen=%u", nfss->namelen);
David Howellsf7b422b2006-06-09 09:34:33 -0400848
849#ifdef CONFIG_NFS_V4
Trond Myklebust40c553192007-12-14 14:56:07 -0500850 if (nfss->nfs_client->rpc_ops->version == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400851 seq_printf(m, "\n\tnfsv4:\t");
852 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
853 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
854 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300855 show_sessions(m, nfss);
856 show_pnfs(m, nfss);
David Howellsf7b422b2006-06-09 09:34:33 -0400857 }
858#endif
859
860 /*
861 * Display security flavor in effect for this mount
862 */
Chuck Lever2d767432008-03-14 14:10:08 -0400863 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400864 if (auth->au_flavor)
Chuck Lever2d767432008-03-14 14:10:08 -0400865 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400866
867 /*
868 * Display superblock I/O counters
869 */
870 for_each_possible_cpu(cpu) {
871 struct nfs_iostats *stats;
872
873 preempt_disable();
874 stats = per_cpu_ptr(nfss->io_stats, cpu);
875
876 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
877 totals.events[i] += stats->events[i];
878 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
879 totals.bytes[i] += stats->bytes[i];
David Howells6a510912009-04-03 16:42:43 +0100880#ifdef CONFIG_NFS_FSCACHE
881 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
882 totals.fscache[i] += stats->fscache[i];
883#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400884
885 preempt_enable();
886 }
887
888 seq_printf(m, "\n\tevents:\t");
889 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
890 seq_printf(m, "%lu ", totals.events[i]);
891 seq_printf(m, "\n\tbytes:\t");
892 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
893 seq_printf(m, "%Lu ", totals.bytes[i]);
David Howells6a510912009-04-03 16:42:43 +0100894#ifdef CONFIG_NFS_FSCACHE
895 if (nfss->options & NFS_OPTION_FSCACHE) {
896 seq_printf(m, "\n\tfsc:\t");
897 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
898 seq_printf(m, "%Lu ", totals.bytes[i]);
899 }
900#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400901 seq_printf(m, "\n");
902
903 rpc_print_iostats(m, nfss->client);
904
905 return 0;
906}
907
908/*
909 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400910 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400911 */
Al Viro42faad92008-04-24 07:21:56 -0400912static void nfs_umount_begin(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -0400913{
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200914 struct nfs_server *server;
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400915 struct rpc_clnt *rpc;
916
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200917 server = NFS_SB(sb);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400918 /* -EIO all pending I/O */
919 rpc = server->client_acl;
920 if (!IS_ERR(rpc))
921 rpc_killall_tasks(rpc);
922 rpc = server->client;
923 if (!IS_ERR(rpc))
924 rpc_killall_tasks(rpc);
David Howellsf7b422b2006-06-09 09:34:33 -0400925}
926
Trond Myklebustc5811db2009-10-06 15:40:15 -0400927static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(unsigned int version)
Chuck Lever9423a082009-09-23 14:36:38 -0400928{
929 struct nfs_parsed_mount_data *data;
930
931 data = kzalloc(sizeof(*data), GFP_KERNEL);
932 if (data) {
Chuck Lever9423a082009-09-23 14:36:38 -0400933 data->acregmin = NFS_DEF_ACREGMIN;
934 data->acregmax = NFS_DEF_ACREGMAX;
935 data->acdirmin = NFS_DEF_ACDIRMIN;
936 data->acdirmax = NFS_DEF_ACDIRMAX;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400937 data->mount_server.port = NFS_UNSPEC_PORT;
Chuck Lever9423a082009-09-23 14:36:38 -0400938 data->nfs_server.port = NFS_UNSPEC_PORT;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400939 data->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Lever9423a082009-09-23 14:36:38 -0400940 data->auth_flavors[0] = RPC_AUTH_UNIX;
941 data->auth_flavor_len = 1;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400942 data->version = version;
Chuck Lever9423a082009-09-23 14:36:38 -0400943 data->minorversion = 0;
Trond Myklebust9937347a2012-02-19 08:44:07 +0100944 data->net = current->nsproxy->net_ns;
Jeff Layton8a0d5512011-12-20 06:57:45 -0500945 security_init_mnt_opts(&data->lsm_opts);
Chuck Lever9423a082009-09-23 14:36:38 -0400946 }
947 return data;
948}
949
Jeff Layton8a0d5512011-12-20 06:57:45 -0500950static void nfs_free_parsed_mount_data(struct nfs_parsed_mount_data *data)
951{
952 if (data) {
953 kfree(data->client_address);
954 kfree(data->mount_server.hostname);
955 kfree(data->nfs_server.export_path);
956 kfree(data->nfs_server.hostname);
957 kfree(data->fscache_uniq);
958 security_free_mnt_opts(&data->lsm_opts);
959 kfree(data);
960 }
961}
962
David Howellsf7b422b2006-06-09 09:34:33 -0400963/*
Chuck Levercdcd7f92007-12-10 14:57:45 -0500964 * Sanity-check a server address provided by the mount command.
965 *
966 * Address family must be initialized, and address must not be
967 * the ANY address for that family.
Chuck Leverfc50d582007-07-01 12:12:46 -0400968 */
969static int nfs_verify_server_address(struct sockaddr *addr)
970{
971 switch (addr->sa_family) {
972 case AF_INET: {
Chuck Levercdcd7f92007-12-10 14:57:45 -0500973 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
Al Viroe6f1ceb2008-03-17 22:44:53 -0700974 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
Chuck Levercdcd7f92007-12-10 14:57:45 -0500975 }
976 case AF_INET6: {
977 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
978 return !ipv6_addr_any(sa);
Chuck Leverfc50d582007-07-01 12:12:46 -0400979 }
980 }
981
Chuck Lever53a0b9c2009-08-09 15:09:36 -0400982 dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
Chuck Leverfc50d582007-07-01 12:12:46 -0400983 return 0;
984}
985
Chuck Lever9412b922007-12-10 14:59:21 -0500986/*
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400987 * Select between a default port value and a user-specified port value.
988 * If a zero value is set, then autobind will be used.
989 */
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400990static void nfs_set_port(struct sockaddr *sap, int *port,
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400991 const unsigned short default_port)
992{
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400993 if (*port == NFS_UNSPEC_PORT)
994 *port = default_port;
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400995
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400996 rpc_set_port(sap, *port);
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400997}
998
999/*
Trond Myklebust259875e2008-07-02 14:43:47 -04001000 * Sanity check the NFS transport protocol.
1001 *
1002 */
1003static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
1004{
1005 switch (mnt->nfs_server.protocol) {
1006 case XPRT_TRANSPORT_UDP:
1007 case XPRT_TRANSPORT_TCP:
1008 case XPRT_TRANSPORT_RDMA:
1009 break;
1010 default:
1011 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1012 }
1013}
1014
1015/*
1016 * For text based NFSv2/v3 mounts, the mount protocol transport default
1017 * settings should depend upon the specified NFS transport.
1018 */
1019static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
1020{
1021 nfs_validate_transport_protocol(mnt);
1022
1023 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
1024 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
1025 return;
1026 switch (mnt->nfs_server.protocol) {
1027 case XPRT_TRANSPORT_UDP:
1028 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
1029 break;
1030 case XPRT_TRANSPORT_TCP:
1031 case XPRT_TRANSPORT_RDMA:
1032 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
1033 }
1034}
1035
1036/*
Chuck Lever01060c82008-06-24 16:33:38 -04001037 * Parse the value of the 'sec=' option.
Chuck Lever01060c82008-06-24 16:33:38 -04001038 */
1039static int nfs_parse_security_flavors(char *value,
1040 struct nfs_parsed_mount_data *mnt)
1041{
1042 substring_t args[MAX_OPT_ARGS];
1043
1044 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
1045
1046 switch (match_token(value, nfs_secflavor_tokens, args)) {
1047 case Opt_sec_none:
Chuck Lever01060c82008-06-24 16:33:38 -04001048 mnt->auth_flavors[0] = RPC_AUTH_NULL;
1049 break;
1050 case Opt_sec_sys:
Chuck Lever01060c82008-06-24 16:33:38 -04001051 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
1052 break;
1053 case Opt_sec_krb5:
Chuck Lever01060c82008-06-24 16:33:38 -04001054 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
1055 break;
1056 case Opt_sec_krb5i:
Chuck Lever01060c82008-06-24 16:33:38 -04001057 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
1058 break;
1059 case Opt_sec_krb5p:
Chuck Lever01060c82008-06-24 16:33:38 -04001060 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
1061 break;
1062 case Opt_sec_lkey:
Chuck Lever01060c82008-06-24 16:33:38 -04001063 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
1064 break;
1065 case Opt_sec_lkeyi:
Chuck Lever01060c82008-06-24 16:33:38 -04001066 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
1067 break;
1068 case Opt_sec_lkeyp:
Chuck Lever01060c82008-06-24 16:33:38 -04001069 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
1070 break;
1071 case Opt_sec_spkm:
Chuck Lever01060c82008-06-24 16:33:38 -04001072 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
1073 break;
1074 case Opt_sec_spkmi:
Chuck Lever01060c82008-06-24 16:33:38 -04001075 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
1076 break;
1077 case Opt_sec_spkmp:
Chuck Lever01060c82008-06-24 16:33:38 -04001078 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
1079 break;
1080 default:
1081 return 0;
1082 }
1083
Bryan Schumaker9b7160c2011-04-13 14:31:30 -04001084 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
Chuck Lever059f90b2009-08-09 15:09:31 -04001085 mnt->auth_flavor_len = 1;
Chuck Lever01060c82008-06-24 16:33:38 -04001086 return 1;
1087}
1088
Trond Myklebust0d71b052012-03-02 13:59:49 -05001089static int nfs_parse_version_string(char *string,
1090 struct nfs_parsed_mount_data *mnt,
1091 substring_t *args)
1092{
1093 mnt->flags &= ~NFS_MOUNT_VER3;
1094 switch (match_token(string, nfs_vers_tokens, args)) {
1095 case Opt_vers_2:
1096 mnt->version = 2;
1097 break;
1098 case Opt_vers_3:
1099 mnt->flags |= NFS_MOUNT_VER3;
1100 mnt->version = 3;
1101 break;
1102 case Opt_vers_4:
1103 /* Backward compatibility option. In future,
1104 * the mount program should always supply
1105 * a NFSv4 minor version number.
1106 */
1107 mnt->version = 4;
1108 break;
1109 case Opt_vers_4_0:
1110 mnt->version = 4;
1111 mnt->minorversion = 0;
1112 break;
1113 case Opt_vers_4_1:
1114 mnt->version = 4;
1115 mnt->minorversion = 1;
1116 break;
1117 default:
1118 return 0;
1119 }
1120 return 1;
1121}
1122
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001123static int nfs_get_option_str(substring_t args[], char **option)
1124{
1125 kfree(*option);
1126 *option = match_strdup(args);
1127 return !option;
1128}
1129
1130static int nfs_get_option_ul(substring_t args[], unsigned long *option)
1131{
1132 int rc;
1133 char *string;
1134
1135 string = match_strdup(args);
1136 if (string == NULL)
1137 return -ENOMEM;
1138 rc = strict_strtoul(string, 10, option);
1139 kfree(string);
1140
1141 return rc;
1142}
1143
Chuck Lever01060c82008-06-24 16:33:38 -04001144/*
Chuck Leverbf0fd762007-07-01 12:13:44 -04001145 * Error-check and convert a string of mount options from user space into
Chuck Leverf45663c2008-06-24 19:28:02 -04001146 * a data structure. The whole mount string is processed; bad options are
1147 * skipped as they are encountered. If there were no errors, return 1;
1148 * otherwise return 0 (zero).
Chuck Leverbf0fd762007-07-01 12:13:44 -04001149 */
1150static int nfs_parse_mount_options(char *raw,
1151 struct nfs_parsed_mount_data *mnt)
1152{
Eric Parisf9c3a382008-03-05 14:20:18 -05001153 char *p, *string, *secdata;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001154 int rc, sloppy = 0, invalid_option = 0;
Jeff Laytonee671b02009-12-03 15:58:56 -05001155 unsigned short protofamily = AF_UNSPEC;
1156 unsigned short mountfamily = AF_UNSPEC;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001157
1158 if (!raw) {
1159 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
1160 return 1;
1161 }
1162 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
1163
Eric Parisf9c3a382008-03-05 14:20:18 -05001164 secdata = alloc_secdata();
1165 if (!secdata)
1166 goto out_nomem;
1167
1168 rc = security_sb_copy_data(raw, secdata);
1169 if (rc)
1170 goto out_security_failure;
1171
1172 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
1173 if (rc)
1174 goto out_security_failure;
1175
1176 free_secdata(secdata);
1177
Chuck Leverbf0fd762007-07-01 12:13:44 -04001178 while ((p = strsep(&raw, ",")) != NULL) {
1179 substring_t args[MAX_OPT_ARGS];
Chuck Levera5a16ba2009-06-17 18:02:14 -07001180 unsigned long option;
1181 int token;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001182
1183 if (!*p)
1184 continue;
1185
1186 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
1187
1188 token = match_token(p, nfs_mount_option_tokens, args);
1189 switch (token) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001190
1191 /*
1192 * boolean options: foo/nofoo
1193 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001194 case Opt_soft:
1195 mnt->flags |= NFS_MOUNT_SOFT;
1196 break;
1197 case Opt_hard:
1198 mnt->flags &= ~NFS_MOUNT_SOFT;
1199 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001200 case Opt_posix:
1201 mnt->flags |= NFS_MOUNT_POSIX;
1202 break;
1203 case Opt_noposix:
1204 mnt->flags &= ~NFS_MOUNT_POSIX;
1205 break;
1206 case Opt_cto:
1207 mnt->flags &= ~NFS_MOUNT_NOCTO;
1208 break;
1209 case Opt_nocto:
1210 mnt->flags |= NFS_MOUNT_NOCTO;
1211 break;
1212 case Opt_ac:
1213 mnt->flags &= ~NFS_MOUNT_NOAC;
1214 break;
1215 case Opt_noac:
1216 mnt->flags |= NFS_MOUNT_NOAC;
1217 break;
1218 case Opt_lock:
1219 mnt->flags &= ~NFS_MOUNT_NONLM;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001220 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1221 NFS_MOUNT_LOCAL_FCNTL);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001222 break;
1223 case Opt_nolock:
1224 mnt->flags |= NFS_MOUNT_NONLM;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001225 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1226 NFS_MOUNT_LOCAL_FCNTL);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001227 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001228 case Opt_udp:
1229 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001230 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001231 break;
1232 case Opt_tcp:
1233 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001234 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001235 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001236 case Opt_rdma:
1237 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1238 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001239 xprt_load_transport(p);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001240 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001241 case Opt_acl:
1242 mnt->flags &= ~NFS_MOUNT_NOACL;
1243 break;
1244 case Opt_noacl:
1245 mnt->flags |= NFS_MOUNT_NOACL;
1246 break;
1247 case Opt_rdirplus:
1248 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1249 break;
1250 case Opt_nordirplus:
1251 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1252 break;
Trond Myklebust75180df2007-05-16 16:53:28 -04001253 case Opt_sharecache:
1254 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1255 break;
1256 case Opt_nosharecache:
1257 mnt->flags |= NFS_MOUNT_UNSHARED;
1258 break;
Chuck Leverd7403512008-12-23 15:21:37 -05001259 case Opt_resvport:
1260 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1261 break;
1262 case Opt_noresvport:
1263 mnt->flags |= NFS_MOUNT_NORESVPORT;
1264 break;
David Howellsb797cac2009-04-03 16:42:48 +01001265 case Opt_fscache:
1266 mnt->options |= NFS_OPTION_FSCACHE;
1267 kfree(mnt->fscache_uniq);
1268 mnt->fscache_uniq = NULL;
1269 break;
1270 case Opt_nofscache:
1271 mnt->options &= ~NFS_OPTION_FSCACHE;
1272 kfree(mnt->fscache_uniq);
1273 mnt->fscache_uniq = NULL;
1274 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001275
Chuck Leverf45663c2008-06-24 19:28:02 -04001276 /*
1277 * options that take numeric values
1278 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001279 case Opt_port:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001280 if (nfs_get_option_ul(args, &option) ||
1281 option > USHRT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001282 goto out_invalid_value;
1283 mnt->nfs_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001284 break;
1285 case Opt_rsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001286 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001287 goto out_invalid_value;
1288 mnt->rsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001289 break;
1290 case Opt_wsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001291 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001292 goto out_invalid_value;
1293 mnt->wsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001294 break;
1295 case Opt_bsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001296 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001297 goto out_invalid_value;
1298 mnt->bsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001299 break;
1300 case Opt_timeo:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001301 if (nfs_get_option_ul(args, &option) || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001302 goto out_invalid_value;
1303 mnt->timeo = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001304 break;
1305 case Opt_retrans:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001306 if (nfs_get_option_ul(args, &option) || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001307 goto out_invalid_value;
1308 mnt->retrans = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001309 break;
1310 case Opt_acregmin:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001311 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001312 goto out_invalid_value;
1313 mnt->acregmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001314 break;
1315 case Opt_acregmax:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001316 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001317 goto out_invalid_value;
1318 mnt->acregmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001319 break;
1320 case Opt_acdirmin:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001321 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001322 goto out_invalid_value;
1323 mnt->acdirmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001324 break;
1325 case Opt_acdirmax:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001326 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001327 goto out_invalid_value;
1328 mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001329 break;
1330 case Opt_actimeo:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001331 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001332 goto out_invalid_value;
1333 mnt->acregmin = mnt->acregmax =
1334 mnt->acdirmin = mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001335 break;
1336 case Opt_namelen:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001337 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001338 goto out_invalid_value;
1339 mnt->namlen = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001340 break;
1341 case Opt_mountport:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001342 if (nfs_get_option_ul(args, &option) ||
1343 option > USHRT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001344 goto out_invalid_value;
1345 mnt->mount_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001346 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001347 case Opt_mountvers:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001348 if (nfs_get_option_ul(args, &option) ||
Chuck Leverf45663c2008-06-24 19:28:02 -04001349 option < NFS_MNT_VERSION ||
Chuck Leverd23c45f2009-06-17 18:02:13 -07001350 option > NFS_MNT3_VERSION)
1351 goto out_invalid_value;
1352 mnt->mount_server.version = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001353 break;
Mike Sager3fd5be92009-04-01 09:21:48 -04001354 case Opt_minorversion:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001355 if (nfs_get_option_ul(args, &option))
Chuck Leverf3f4f4e2009-08-09 15:09:29 -04001356 goto out_invalid_value;
1357 if (option > NFS4_MAX_MINOR_VERSION)
1358 goto out_invalid_value;
1359 mnt->minorversion = option;
Mike Sager3fd5be92009-04-01 09:21:48 -04001360 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001361
Chuck Leverf45663c2008-06-24 19:28:02 -04001362 /*
1363 * options that take text values
1364 */
Trond Myklebust0d71b052012-03-02 13:59:49 -05001365 case Opt_nfsvers:
1366 string = match_strdup(args);
1367 if (string == NULL)
1368 goto out_nomem;
1369 rc = nfs_parse_version_string(string, mnt, args);
1370 kfree(string);
1371 if (!rc)
1372 goto out_invalid_value;
1373 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001374 case Opt_sec:
1375 string = match_strdup(args);
1376 if (string == NULL)
1377 goto out_nomem;
Chuck Lever01060c82008-06-24 16:33:38 -04001378 rc = nfs_parse_security_flavors(string, mnt);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001379 kfree(string);
Chuck Leverf45663c2008-06-24 19:28:02 -04001380 if (!rc) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001381 dfprintk(MOUNT, "NFS: unrecognized "
1382 "security flavor\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001383 return 0;
Chuck Leverf45663c2008-06-24 19:28:02 -04001384 }
Chuck Leverbf0fd762007-07-01 12:13:44 -04001385 break;
1386 case Opt_proto:
1387 string = match_strdup(args);
1388 if (string == NULL)
1389 goto out_nomem;
1390 token = match_token(string,
1391 nfs_xprt_protocol_tokens, args);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001392
Jeff Laytonee671b02009-12-03 15:58:56 -05001393 protofamily = AF_INET;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001394 switch (token) {
Jeff Laytonee671b02009-12-03 15:58:56 -05001395 case Opt_xprt_udp6:
1396 protofamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001397 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001398 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001399 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001400 break;
Jeff Laytonee671b02009-12-03 15:58:56 -05001401 case Opt_xprt_tcp6:
1402 protofamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001403 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001404 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001405 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001406 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001407 case Opt_xprt_rdma:
1408 /* vector side protocols to TCP */
1409 mnt->flags |= NFS_MOUNT_TCP;
1410 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001411 xprt_load_transport(string);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001412 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001413 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001414 dfprintk(MOUNT, "NFS: unrecognized "
1415 "transport protocol\n");
Yinghai Lu4223a4a2009-10-20 14:13:46 +09001416 kfree(string);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001417 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001418 }
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001419 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001420 break;
1421 case Opt_mountproto:
1422 string = match_strdup(args);
1423 if (string == NULL)
1424 goto out_nomem;
1425 token = match_token(string,
1426 nfs_xprt_protocol_tokens, args);
Trond Myklebustd508afb2009-04-06 16:41:35 -07001427 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001428
Jeff Laytonee671b02009-12-03 15:58:56 -05001429 mountfamily = AF_INET;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001430 switch (token) {
Jeff Laytonee671b02009-12-03 15:58:56 -05001431 case Opt_xprt_udp6:
1432 mountfamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001433 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001434 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001435 break;
Jeff Laytonee671b02009-12-03 15:58:56 -05001436 case Opt_xprt_tcp6:
1437 mountfamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001438 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001439 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001440 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001441 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001442 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001443 dfprintk(MOUNT, "NFS: unrecognized "
1444 "transport protocol\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001445 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001446 }
1447 break;
1448 case Opt_addr:
1449 string = match_strdup(args);
1450 if (string == NULL)
1451 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001452 mnt->nfs_server.addrlen =
Stanislav Kinsburskyb48e1272012-01-26 15:11:57 +04001453 rpc_pton(mnt->net, string, strlen(string),
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001454 (struct sockaddr *)
1455 &mnt->nfs_server.address,
1456 sizeof(mnt->nfs_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001457 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001458 if (mnt->nfs_server.addrlen == 0)
1459 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001460 break;
1461 case Opt_clientaddr:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001462 if (nfs_get_option_str(args, &mnt->client_address))
Chuck Leverbf0fd762007-07-01 12:13:44 -04001463 goto out_nomem;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001464 break;
Chuck Lever33832032007-12-10 14:59:13 -05001465 case Opt_mounthost:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001466 if (nfs_get_option_str(args,
1467 &mnt->mount_server.hostname))
Chuck Lever33832032007-12-10 14:59:13 -05001468 goto out_nomem;
Chuck Lever33832032007-12-10 14:59:13 -05001469 break;
Chuck Lever0ac83772007-09-11 18:01:04 -04001470 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001471 string = match_strdup(args);
1472 if (string == NULL)
1473 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001474 mnt->mount_server.addrlen =
Stanislav Kinsburskyb48e1272012-01-26 15:11:57 +04001475 rpc_pton(mnt->net, string, strlen(string),
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001476 (struct sockaddr *)
1477 &mnt->mount_server.address,
1478 sizeof(mnt->mount_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001479 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001480 if (mnt->mount_server.addrlen == 0)
1481 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001482 break;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001483 case Opt_lookupcache:
1484 string = match_strdup(args);
1485 if (string == NULL)
1486 goto out_nomem;
1487 token = match_token(string,
1488 nfs_lookupcache_tokens, args);
1489 kfree(string);
1490 switch (token) {
1491 case Opt_lookupcache_all:
1492 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1493 break;
1494 case Opt_lookupcache_positive:
1495 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1496 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1497 break;
1498 case Opt_lookupcache_none:
1499 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1500 break;
1501 default:
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001502 dfprintk(MOUNT, "NFS: invalid "
1503 "lookupcache argument\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001504 return 0;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001505 };
1506 break;
Chuck Levera6d5ff62010-05-07 13:33:58 -04001507 case Opt_fscache_uniq:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001508 if (nfs_get_option_str(args, &mnt->fscache_uniq))
Chuck Levera6d5ff62010-05-07 13:33:58 -04001509 goto out_nomem;
Chuck Levera6d5ff62010-05-07 13:33:58 -04001510 mnt->options |= NFS_OPTION_FSCACHE;
1511 break;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001512 case Opt_local_lock:
1513 string = match_strdup(args);
1514 if (string == NULL)
1515 goto out_nomem;
1516 token = match_token(string, nfs_local_lock_tokens,
1517 args);
1518 kfree(string);
1519 switch (token) {
1520 case Opt_local_lock_all:
1521 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1522 NFS_MOUNT_LOCAL_FCNTL);
1523 break;
1524 case Opt_local_lock_flock:
1525 mnt->flags |= NFS_MOUNT_LOCAL_FLOCK;
1526 break;
1527 case Opt_local_lock_posix:
1528 mnt->flags |= NFS_MOUNT_LOCAL_FCNTL;
1529 break;
1530 case Opt_local_lock_none:
1531 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1532 NFS_MOUNT_LOCAL_FCNTL);
1533 break;
1534 default:
1535 dfprintk(MOUNT, "NFS: invalid "
1536 "local_lock argument\n");
1537 return 0;
1538 };
1539 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001540
Chuck Leverf45663c2008-06-24 19:28:02 -04001541 /*
1542 * Special options
1543 */
1544 case Opt_sloppy:
1545 sloppy = 1;
1546 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1547 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001548 case Opt_userspace:
1549 case Opt_deprecated:
Chuck Leverd33e4df2008-06-12 12:37:41 -04001550 dfprintk(MOUNT, "NFS: ignoring mount option "
1551 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001552 break;
1553
1554 default:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001555 invalid_option = 1;
Chuck Leverf45663c2008-06-24 19:28:02 -04001556 dfprintk(MOUNT, "NFS: unrecognized mount option "
1557 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001558 }
1559 }
1560
Chuck Leverd23c45f2009-06-17 18:02:13 -07001561 if (!sloppy && invalid_option)
1562 return 0;
1563
Weston Andros Adamson571b7552012-02-01 14:06:41 -05001564 if (mnt->minorversion && mnt->version != 4)
1565 goto out_minorversion_mismatch;
1566
Jeff Laytonee671b02009-12-03 15:58:56 -05001567 /*
1568 * verify that any proto=/mountproto= options match the address
1569 * familiies in the addr=/mountaddr= options.
1570 */
1571 if (protofamily != AF_UNSPEC &&
1572 protofamily != mnt->nfs_server.address.ss_family)
1573 goto out_proto_mismatch;
1574
1575 if (mountfamily != AF_UNSPEC) {
1576 if (mnt->mount_server.addrlen) {
1577 if (mountfamily != mnt->mount_server.address.ss_family)
1578 goto out_mountproto_mismatch;
1579 } else {
1580 if (mountfamily != mnt->nfs_server.address.ss_family)
1581 goto out_mountproto_mismatch;
1582 }
1583 }
1584
Chuck Leverbf0fd762007-07-01 12:13:44 -04001585 return 1;
1586
Jeff Laytonee671b02009-12-03 15:58:56 -05001587out_mountproto_mismatch:
1588 printk(KERN_INFO "NFS: mount server address does not match mountproto= "
1589 "option\n");
1590 return 0;
1591out_proto_mismatch:
1592 printk(KERN_INFO "NFS: server address does not match proto= option\n");
1593 return 0;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001594out_invalid_address:
1595 printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
1596 return 0;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001597out_invalid_value:
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001598 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001599 return 0;
Weston Andros Adamson571b7552012-02-01 14:06:41 -05001600out_minorversion_mismatch:
1601 printk(KERN_INFO "NFS: mount option vers=%u does not support "
1602 "minorversion=%u\n", mnt->version, mnt->minorversion);
1603 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001604out_nomem:
1605 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1606 return 0;
Eric Parisf9c3a382008-03-05 14:20:18 -05001607out_security_failure:
1608 free_secdata(secdata);
1609 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1610 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001611}
1612
1613/*
Chuck Leverec88f282009-08-09 15:09:32 -04001614 * Match the requested auth flavors with the list returned by
1615 * the server. Returns zero and sets the mount's authentication
1616 * flavor on success; returns -EACCES if server does not support
1617 * the requested flavor.
1618 */
1619static int nfs_walk_authlist(struct nfs_parsed_mount_data *args,
1620 struct nfs_mount_request *request)
1621{
1622 unsigned int i, j, server_authlist_len = *(request->auth_flav_len);
1623
1624 /*
Chuck Lever5eecfde2009-08-21 17:50:30 -04001625 * Certain releases of Linux's mountd return an empty
1626 * flavor list. To prevent behavioral regression with
1627 * these servers (ie. rejecting mounts that used to
1628 * succeed), revert to pre-2.6.32 behavior (no checking)
1629 * if the returned flavor list is empty.
1630 */
1631 if (server_authlist_len == 0)
1632 return 0;
1633
1634 /*
Chuck Leverec88f282009-08-09 15:09:32 -04001635 * We avoid sophisticated negotiating here, as there are
1636 * plenty of cases where we can get it wrong, providing
1637 * either too little or too much security.
1638 *
1639 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1640 * flavor listed first. However, some servers list
1641 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1642 * preferred default, in args->auth_flavors[0] if user
1643 * didn't specify sec= mount option.
1644 */
1645 for (i = 0; i < args->auth_flavor_len; i++)
1646 for (j = 0; j < server_authlist_len; j++)
1647 if (args->auth_flavors[i] == request->auth_flavs[j]) {
1648 dfprintk(MOUNT, "NFS: using auth flavor %d\n",
1649 request->auth_flavs[j]);
1650 args->auth_flavors[0] = request->auth_flavs[j];
1651 return 0;
1652 }
1653
1654 dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n");
1655 nfs_umount(request);
1656 return -EACCES;
1657}
1658
1659/*
Chuck Lever0076d7b2007-07-01 12:13:49 -04001660 * Use the remote server's MOUNT service to request the NFS file handle
1661 * corresponding to the provided path.
1662 */
1663static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1664 struct nfs_fh *root_fh)
1665{
Chuck Leverec88f282009-08-09 15:09:32 -04001666 rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS];
1667 unsigned int server_authlist_len = ARRAY_SIZE(server_authlist);
Chuck Leverc5d120f2008-12-23 15:21:35 -05001668 struct nfs_mount_request request = {
1669 .sap = (struct sockaddr *)
1670 &args->mount_server.address,
1671 .dirpath = args->nfs_server.export_path,
1672 .protocol = args->mount_server.protocol,
1673 .fh = root_fh,
Chuck Lever50a737f2008-12-23 15:21:37 -05001674 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
Chuck Leverec88f282009-08-09 15:09:32 -04001675 .auth_flav_len = &server_authlist_len,
1676 .auth_flavs = server_authlist,
Stanislav Kinsbursky6d59b8d2012-01-10 16:12:54 +04001677 .net = args->net,
Chuck Leverc5d120f2008-12-23 15:21:35 -05001678 };
Chuck Lever4c568012007-12-10 14:59:28 -05001679 int status;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001680
1681 if (args->mount_server.version == 0) {
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001682 switch (args->version) {
1683 default:
1684 args->mount_server.version = NFS_MNT3_VERSION;
1685 break;
1686 case 2:
1687 args->mount_server.version = NFS_MNT_VERSION;
1688 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001689 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001690 request.version = args->mount_server.version;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001691
Chuck Lever33832032007-12-10 14:59:13 -05001692 if (args->mount_server.hostname)
Chuck Leverc5d120f2008-12-23 15:21:35 -05001693 request.hostname = args->mount_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001694 else
Chuck Leverc5d120f2008-12-23 15:21:35 -05001695 request.hostname = args->nfs_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001696
Chuck Lever0076d7b2007-07-01 12:13:49 -04001697 /*
1698 * Construct the mount server's address.
1699 */
Chuck Lever4c568012007-12-10 14:59:28 -05001700 if (args->mount_server.address.ss_family == AF_UNSPEC) {
Chuck Leverc5d120f2008-12-23 15:21:35 -05001701 memcpy(request.sap, &args->nfs_server.address,
Chuck Lever4c568012007-12-10 14:59:28 -05001702 args->nfs_server.addrlen);
1703 args->mount_server.addrlen = args->nfs_server.addrlen;
1704 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001705 request.salen = args->mount_server.addrlen;
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001706 nfs_set_port(request.sap, &args->mount_server.port, 0);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001707
1708 /*
1709 * Now ask the mount server to map our export path
1710 * to a file handle.
1711 */
Chuck Leverc5d120f2008-12-23 15:21:35 -05001712 status = nfs_mount(&request);
Chuck Leverec88f282009-08-09 15:09:32 -04001713 if (status != 0) {
1714 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1715 request.hostname, status);
1716 return status;
1717 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001718
Chuck Leverec88f282009-08-09 15:09:32 -04001719 /*
1720 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1721 */
1722 if (args->mount_server.version != NFS_MNT3_VERSION)
1723 return 0;
1724 return nfs_walk_authlist(args, &request);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001725}
1726
Rob Landleyc12bace2011-03-09 15:54:13 -06001727/*
1728 * Split "dev_name" into "hostname:export_path".
1729 *
1730 * The leftmost colon demarks the split between the server's hostname
1731 * and the export path. If the hostname starts with a left square
1732 * bracket, then it may contain colons.
1733 *
1734 * Note: caller frees hostname and export path, even on error.
1735 */
1736static int nfs_parse_devname(const char *dev_name,
1737 char **hostname, size_t maxnamlen,
1738 char **export_path, size_t maxpathlen)
Chuck Leverdc045892008-06-23 12:36:37 -04001739{
1740 size_t len;
Rob Landleyc12bace2011-03-09 15:54:13 -06001741 char *end;
Chuck Leverdc045892008-06-23 12:36:37 -04001742
Rob Landleyc12bace2011-03-09 15:54:13 -06001743 /* Is the host name protected with square brakcets? */
1744 if (*dev_name == '[') {
1745 end = strchr(++dev_name, ']');
1746 if (end == NULL || end[1] != ':')
1747 goto out_bad_devname;
Chuck Leverdc045892008-06-23 12:36:37 -04001748
Rob Landleyc12bace2011-03-09 15:54:13 -06001749 len = end - dev_name;
1750 end++;
1751 } else {
1752 char *comma;
1753
1754 end = strchr(dev_name, ':');
1755 if (end == NULL)
1756 goto out_bad_devname;
1757 len = end - dev_name;
1758
1759 /* kill possible hostname list: not supported */
1760 comma = strchr(dev_name, ',');
1761 if (comma != NULL && comma < end)
1762 *comma = 0;
1763 }
1764
Chuck Leverdc045892008-06-23 12:36:37 -04001765 if (len > maxnamlen)
1766 goto out_hostname;
1767
1768 /* N.B. caller will free nfs_server.hostname in all cases */
1769 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
Rob Landleyc12bace2011-03-09 15:54:13 -06001770 if (*hostname == NULL)
Chuck Leverdc045892008-06-23 12:36:37 -04001771 goto out_nomem;
Rob Landleyc12bace2011-03-09 15:54:13 -06001772 len = strlen(++end);
Chuck Leverdc045892008-06-23 12:36:37 -04001773 if (len > maxpathlen)
1774 goto out_path;
Rob Landleyc12bace2011-03-09 15:54:13 -06001775 *export_path = kstrndup(end, len, GFP_KERNEL);
Chuck Leverdc045892008-06-23 12:36:37 -04001776 if (!*export_path)
1777 goto out_nomem;
1778
1779 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1780 return 0;
1781
1782out_bad_devname:
1783 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1784 return -EINVAL;
1785
1786out_nomem:
1787 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1788 return -ENOMEM;
1789
1790out_hostname:
1791 dfprintk(MOUNT, "NFS: server hostname too long\n");
1792 return -ENAMETOOLONG;
1793
1794out_path:
1795 dfprintk(MOUNT, "NFS: export pathname too long\n");
1796 return -ENAMETOOLONG;
1797}
1798
1799/*
David Howells54ceac42006-08-22 20:06:13 -04001800 * Validate the NFS2/NFS3 mount data
1801 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001802 *
1803 * For option strings, user space handles the following behaviors:
1804 *
1805 * + DNS: mapping server host name to IP address ("addr=" option)
1806 *
1807 * + failure mode: how to behave if a mount request can't be handled
1808 * immediately ("fg/bg" option)
1809 *
1810 * + retry: how often to retry a mount request ("retry=" option)
1811 *
1812 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1813 * mountproto=tcp after mountproto=udp, and so on
David Howellsf7b422b2006-06-09 09:34:33 -04001814 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001815static int nfs_validate_mount_data(void *options,
1816 struct nfs_parsed_mount_data *args,
Chuck Lever136d5582007-07-01 12:13:54 -04001817 struct nfs_fh *mntfh,
1818 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001819{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001820 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001821 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
Chuck Lever136d5582007-07-01 12:13:54 -04001822
Chuck Lever5df36e72007-07-01 12:12:56 -04001823 if (data == NULL)
1824 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001825
David Howellsf7b422b2006-06-09 09:34:33 -04001826 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001827 case 1:
1828 data->namlen = 0;
1829 case 2:
1830 data->bsize = 0;
1831 case 3:
1832 if (data->flags & NFS_MOUNT_VER3)
1833 goto out_no_v3;
1834 data->root.size = NFS2_FHSIZE;
1835 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1836 case 4:
1837 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1838 goto out_no_sec;
1839 case 5:
1840 memset(data->context, 0, sizeof(data->context));
1841 case 6:
Trond Myklebustb7e24452008-06-19 15:21:11 -04001842 if (data->flags & NFS_MOUNT_VER3) {
1843 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1844 goto out_invalid_fh;
Chuck Lever5df36e72007-07-01 12:12:56 -04001845 mntfh->size = data->root.size;
Chuck Lever764302c2009-09-08 19:50:03 -04001846 args->version = 3;
1847 } else {
Chuck Lever5df36e72007-07-01 12:12:56 -04001848 mntfh->size = NFS2_FHSIZE;
Chuck Lever764302c2009-09-08 19:50:03 -04001849 args->version = 2;
1850 }
Chuck Lever5df36e72007-07-01 12:12:56 -04001851
Chuck Lever5df36e72007-07-01 12:12:56 -04001852
1853 memcpy(mntfh->data, data->root.data, mntfh->size);
1854 if (mntfh->size < sizeof(mntfh->data))
1855 memset(mntfh->data + mntfh->size, 0,
1856 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001857
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001858 /*
1859 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1860 * can deal with.
1861 */
Trond Myklebustff3525a2008-08-15 16:59:14 -04001862 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
Bryan Schumakerd5eff1a2010-08-03 13:04:00 -04001863 args->flags |= NFS_MOUNT_LEGACY_INTERFACE;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001864 args->rsize = data->rsize;
1865 args->wsize = data->wsize;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001866 args->timeo = data->timeo;
1867 args->retrans = data->retrans;
1868 args->acregmin = data->acregmin;
1869 args->acregmax = data->acregmax;
1870 args->acdirmin = data->acdirmin;
1871 args->acdirmax = data->acdirmax;
Chuck Lever4c568012007-12-10 14:59:28 -05001872
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001873 memcpy(sap, &data->addr, sizeof(data->addr));
Chuck Lever4c568012007-12-10 14:59:28 -05001874 args->nfs_server.addrlen = sizeof(data->addr);
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001875 if (!nfs_verify_server_address(sap))
Chuck Lever4c568012007-12-10 14:59:28 -05001876 goto out_no_address;
1877
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001878 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001879 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001880 /* N.B. caller will free nfs_server.hostname in all cases */
1881 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1882 args->namlen = data->namlen;
1883 args->bsize = data->bsize;
Chuck Leverdd07c942008-06-24 16:33:46 -04001884
1885 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1886 args->auth_flavors[0] = data->pseudoflavor;
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001887 if (!args->nfs_server.hostname)
1888 goto out_nomem;
Eric Parisf9c3a382008-03-05 14:20:18 -05001889
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001890 if (!(data->flags & NFS_MOUNT_NONLM))
1891 args->flags &= ~(NFS_MOUNT_LOCAL_FLOCK|
1892 NFS_MOUNT_LOCAL_FCNTL);
1893 else
1894 args->flags |= (NFS_MOUNT_LOCAL_FLOCK|
1895 NFS_MOUNT_LOCAL_FCNTL);
Eric Parisf9c3a382008-03-05 14:20:18 -05001896 /*
1897 * The legacy version 6 binary mount data from userspace has a
1898 * field used only to transport selinux information into the
1899 * the kernel. To continue to support that functionality we
1900 * have a touch of selinux knowledge here in the NFS code. The
1901 * userspace code converted context=blah to just blah so we are
1902 * converting back to the full string selinux understands.
1903 */
1904 if (data->context[0]){
1905#ifdef CONFIG_SECURITY_SELINUX
1906 int rc;
1907 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1908 if (!opts_str)
1909 return -ENOMEM;
1910 strcpy(opts_str, "context=");
1911 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1912 strcat(opts_str, &data->context[0]);
1913 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1914 kfree(opts_str);
1915 if (rc)
1916 return rc;
1917#else
1918 return -EINVAL;
1919#endif
1920 }
1921
Chuck Lever5df36e72007-07-01 12:12:56 -04001922 break;
Chuck Lever136d5582007-07-01 12:13:54 -04001923 default: {
Chuck Lever136d5582007-07-01 12:13:54 -04001924 int status;
Chuck Lever136d5582007-07-01 12:13:54 -04001925
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001926 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever136d5582007-07-01 12:13:54 -04001927 return -EINVAL;
1928
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001929 if (!nfs_verify_server_address(sap))
Chuck Lever6e88e062007-09-24 15:39:50 -04001930 goto out_no_address;
1931
Chuck Lever764302c2009-09-08 19:50:03 -04001932 if (args->version == 4)
1933#ifdef CONFIG_NFS_V4
1934 return nfs4_validate_text_mount_data(options,
1935 args, dev_name);
1936#else
1937 goto out_v4_not_compiled;
1938#endif
1939
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001940 nfs_set_port(sap, &args->nfs_server.port, 0);
Chuck Levered596a82008-06-26 17:47:05 -04001941
Trond Myklebust259875e2008-07-02 14:43:47 -04001942 nfs_set_mount_transport_protocol(args);
1943
Chuck Leverdc045892008-06-23 12:36:37 -04001944 status = nfs_parse_devname(dev_name,
1945 &args->nfs_server.hostname,
1946 PAGE_SIZE,
1947 &args->nfs_server.export_path,
1948 NFS_MAXPATHLEN);
1949 if (!status)
1950 status = nfs_try_mount(args, mntfh);
Chuck Lever136d5582007-07-01 12:13:54 -04001951
Chuck Leverdc045892008-06-23 12:36:37 -04001952 kfree(args->nfs_server.export_path);
1953 args->nfs_server.export_path = NULL;
Chuck Lever136d5582007-07-01 12:13:54 -04001954
Chuck Lever136d5582007-07-01 12:13:54 -04001955 if (status)
Chuck Leverfdc6e2c2007-08-29 17:58:59 -04001956 return status;
Chuck Lever136d5582007-07-01 12:13:54 -04001957
Chuck Lever136d5582007-07-01 12:13:54 -04001958 break;
1959 }
David Howellsf7b422b2006-06-09 09:34:33 -04001960 }
David Howells54ceac42006-08-22 20:06:13 -04001961
David Howellsf7b422b2006-06-09 09:34:33 -04001962#ifndef CONFIG_NFS_V3
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001963 if (args->version == 3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001964 goto out_v3_not_compiled;
1965#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001966
David Howells54ceac42006-08-22 20:06:13 -04001967 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001968
1969out_no_data:
1970 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1971 return -EINVAL;
1972
1973out_no_v3:
1974 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1975 data->version);
1976 return -EINVAL;
1977
1978out_no_sec:
1979 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1980 return -EINVAL;
1981
Chuck Lever5df36e72007-07-01 12:12:56 -04001982#ifndef CONFIG_NFS_V3
1983out_v3_not_compiled:
1984 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1985 return -EPROTONOSUPPORT;
1986#endif /* !CONFIG_NFS_V3 */
1987
Chuck Lever764302c2009-09-08 19:50:03 -04001988#ifndef CONFIG_NFS_V4
1989out_v4_not_compiled:
1990 dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n");
1991 return -EPROTONOSUPPORT;
1992#endif /* !CONFIG_NFS_V4 */
1993
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001994out_nomem:
1995 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
1996 return -ENOMEM;
1997
Chuck Lever5df36e72007-07-01 12:12:56 -04001998out_no_address:
1999 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
2000 return -EINVAL;
2001
2002out_invalid_fh:
2003 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
2004 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04002005}
2006
Jeff Layton48b605f2008-06-10 15:38:39 -04002007static int
2008nfs_compare_remount_data(struct nfs_server *nfss,
2009 struct nfs_parsed_mount_data *data)
2010{
2011 if (data->flags != nfss->flags ||
2012 data->rsize != nfss->rsize ||
2013 data->wsize != nfss->wsize ||
2014 data->retrans != nfss->client->cl_timeout->to_retries ||
2015 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
2016 data->acregmin != nfss->acregmin / HZ ||
2017 data->acregmax != nfss->acregmax / HZ ||
2018 data->acdirmin != nfss->acdirmin / HZ ||
2019 data->acdirmax != nfss->acdirmax / HZ ||
2020 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
Trond Myklebustbcd2ea12009-10-06 15:41:22 -04002021 data->nfs_server.port != nfss->port ||
Jeff Layton48b605f2008-06-10 15:38:39 -04002022 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
Stefan Richtera1be9ee2009-10-12 11:26:12 -04002023 !rpc_cmp_addr((struct sockaddr *)&data->nfs_server.address,
2024 (struct sockaddr *)&nfss->nfs_client->cl_addr))
Jeff Layton48b605f2008-06-10 15:38:39 -04002025 return -EINVAL;
2026
2027 return 0;
2028}
2029
2030static int
2031nfs_remount(struct super_block *sb, int *flags, char *raw_data)
2032{
2033 int error;
2034 struct nfs_server *nfss = sb->s_fs_info;
2035 struct nfs_parsed_mount_data *data;
2036 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
2037 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
Trond Myklebustcd100722008-06-17 16:12:00 -04002038 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
Jeff Layton48b605f2008-06-10 15:38:39 -04002039
2040 /*
2041 * Userspace mount programs that send binary options generally send
2042 * them populated with default values. We have no way to know which
2043 * ones were explicitly specified. Fall back to legacy behavior and
2044 * just return success.
2045 */
Marc Zyngier31c94462008-07-17 13:21:55 +02002046 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
2047 (nfsvers <= 3 && (!options || (options->version >= 1 &&
2048 options->version <= 6))))
Jeff Layton48b605f2008-06-10 15:38:39 -04002049 return 0;
2050
2051 data = kzalloc(sizeof(*data), GFP_KERNEL);
2052 if (data == NULL)
2053 return -ENOMEM;
2054
2055 /* fill out struct with values from existing mount */
2056 data->flags = nfss->flags;
2057 data->rsize = nfss->rsize;
2058 data->wsize = nfss->wsize;
2059 data->retrans = nfss->client->cl_timeout->to_retries;
2060 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
2061 data->acregmin = nfss->acregmin / HZ;
2062 data->acregmax = nfss->acregmax / HZ;
2063 data->acdirmin = nfss->acdirmin / HZ;
2064 data->acdirmax = nfss->acdirmax / HZ;
2065 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
Trond Myklebustbcd2ea12009-10-06 15:41:22 -04002066 data->nfs_server.port = nfss->port;
Jeff Layton48b605f2008-06-10 15:38:39 -04002067 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
2068 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
2069 data->nfs_server.addrlen);
2070
2071 /* overwrite those values with any that were specified */
2072 error = nfs_parse_mount_options((char *)options, data);
2073 if (error < 0)
2074 goto out;
2075
Jeff Layton26c4c172011-04-27 11:49:09 -04002076 /*
2077 * noac is a special case. It implies -o sync, but that's not
2078 * necessarily reflected in the mtab options. do_remount_sb
2079 * will clear MS_SYNCHRONOUS if -o sync wasn't specified in the
2080 * remount options, so we have to explicitly reset it.
2081 */
2082 if (data->flags & NFS_MOUNT_NOAC)
2083 *flags |= MS_SYNCHRONOUS;
2084
Jeff Layton48b605f2008-06-10 15:38:39 -04002085 /* compare new mount options with old ones */
2086 error = nfs_compare_remount_data(nfss, data);
2087out:
2088 kfree(data);
2089 return error;
2090}
2091
David Howells54ceac42006-08-22 20:06:13 -04002092/*
2093 * Initialise the common bits of the superblock
2094 */
2095static inline void nfs_initialise_sb(struct super_block *sb)
2096{
2097 struct nfs_server *server = NFS_SB(sb);
2098
2099 sb->s_magic = NFS_SUPER_MAGIC;
2100
2101 /* We probably want something more informative here */
2102 snprintf(sb->s_id, sizeof(sb->s_id),
2103 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
2104
2105 if (sb->s_blocksize == 0)
2106 sb->s_blocksize = nfs_block_bits(server->wsize,
2107 &sb->s_blocksize_bits);
2108
Jens Axboe32a88aa2009-09-16 15:02:33 +02002109 sb->s_bdi = &server->backing_dev_info;
2110
David Howells54ceac42006-08-22 20:06:13 -04002111 nfs_super_set_maxbytes(sb, server->maxfilesize);
2112}
2113
2114/*
2115 * Finish setting up an NFS2/3 superblock
2116 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04002117static void nfs_fill_super(struct super_block *sb,
2118 struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -04002119{
2120 struct nfs_server *server = NFS_SB(sb);
2121
2122 sb->s_blocksize_bits = 0;
2123 sb->s_blocksize = 0;
2124 if (data->bsize)
2125 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
2126
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04002127 if (server->nfs_client->rpc_ops->version == 3) {
David Howells54ceac42006-08-22 20:06:13 -04002128 /* The VFS shouldn't apply the umask to mode bits. We will do
2129 * so ourselves when necessary.
2130 */
2131 sb->s_flags |= MS_POSIXACL;
2132 sb->s_time_gran = 1;
2133 }
2134
2135 sb->s_op = &nfs_sops;
2136 nfs_initialise_sb(sb);
2137}
2138
2139/*
2140 * Finish setting up a cloned NFS2/3 superblock
2141 */
2142static void nfs_clone_super(struct super_block *sb,
2143 const struct super_block *old_sb)
2144{
2145 struct nfs_server *server = NFS_SB(sb);
2146
2147 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2148 sb->s_blocksize = old_sb->s_blocksize;
2149 sb->s_maxbytes = old_sb->s_maxbytes;
2150
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04002151 if (server->nfs_client->rpc_ops->version == 3) {
David Howells54ceac42006-08-22 20:06:13 -04002152 /* The VFS shouldn't apply the umask to mode bits. We will do
2153 * so ourselves when necessary.
2154 */
2155 sb->s_flags |= MS_POSIXACL;
2156 sb->s_time_gran = 1;
2157 }
2158
2159 sb->s_op = old_sb->s_op;
2160 nfs_initialise_sb(sb);
2161}
2162
Trond Myklebust275a5d22007-05-16 16:53:28 -04002163static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
2164{
2165 const struct nfs_server *a = s->s_fs_info;
2166 const struct rpc_clnt *clnt_a = a->client;
2167 const struct rpc_clnt *clnt_b = b->client;
2168
2169 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
2170 goto Ebusy;
2171 if (a->nfs_client != b->nfs_client)
2172 goto Ebusy;
2173 if (a->flags != b->flags)
2174 goto Ebusy;
2175 if (a->wsize != b->wsize)
2176 goto Ebusy;
2177 if (a->rsize != b->rsize)
2178 goto Ebusy;
2179 if (a->acregmin != b->acregmin)
2180 goto Ebusy;
2181 if (a->acregmax != b->acregmax)
2182 goto Ebusy;
2183 if (a->acdirmin != b->acdirmin)
2184 goto Ebusy;
2185 if (a->acdirmax != b->acdirmax)
2186 goto Ebusy;
2187 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
2188 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002189 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04002190Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002191 return 0;
2192}
2193
2194struct nfs_sb_mountdata {
2195 struct nfs_server *server;
2196 int mntflags;
2197};
2198
2199static int nfs_set_super(struct super_block *s, void *data)
2200{
2201 struct nfs_sb_mountdata *sb_mntdata = data;
2202 struct nfs_server *server = sb_mntdata->server;
2203 int ret;
2204
2205 s->s_flags = sb_mntdata->mntflags;
2206 s->s_fs_info = server;
Al Viro8b244ff2010-12-18 11:29:39 -05002207 s->s_d_op = server->nfs_client->rpc_ops->dentry_ops;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002208 ret = set_anon_super(s, server);
2209 if (ret == 0)
2210 server->s_dev = s->s_dev;
2211 return ret;
2212}
2213
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002214static int nfs_compare_super_address(struct nfs_server *server1,
2215 struct nfs_server *server2)
2216{
2217 struct sockaddr *sap1, *sap2;
2218
2219 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
2220 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
2221
2222 if (sap1->sa_family != sap2->sa_family)
2223 return 0;
2224
2225 switch (sap1->sa_family) {
2226 case AF_INET: {
2227 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
2228 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
2229 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
2230 return 0;
2231 if (sin1->sin_port != sin2->sin_port)
2232 return 0;
2233 break;
2234 }
2235 case AF_INET6: {
2236 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
2237 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
2238 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
2239 return 0;
2240 if (sin1->sin6_port != sin2->sin6_port)
2241 return 0;
2242 break;
2243 }
2244 default:
2245 return 0;
2246 }
2247
2248 return 1;
2249}
2250
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002251static int nfs_compare_super(struct super_block *sb, void *data)
2252{
2253 struct nfs_sb_mountdata *sb_mntdata = data;
2254 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2255 int mntflags = sb_mntdata->mntflags;
2256
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002257 if (!nfs_compare_super_address(old, server))
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002258 return 0;
2259 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2260 if (old->flags & NFS_MOUNT_UNSHARED)
2261 return 0;
2262 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2263 return 0;
2264 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04002265}
2266
Miklos Szeredifa799752008-04-30 00:54:33 -07002267static int nfs_bdi_register(struct nfs_server *server)
2268{
2269 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
2270}
2271
Al Viro01194982011-03-16 07:25:36 -04002272static struct dentry *nfs_fs_mount(struct file_system_type *fs_type,
2273 int flags, const char *dev_name, void *raw_data)
David Howells54ceac42006-08-22 20:06:13 -04002274{
2275 struct nfs_server *server = NULL;
2276 struct super_block *s;
Trond Myklebust33852a12008-06-19 14:20:11 -04002277 struct nfs_parsed_mount_data *data;
2278 struct nfs_fh *mntfh;
Al Viro01194982011-03-16 07:25:36 -04002279 struct dentry *mntroot = ERR_PTR(-ENOMEM);
Trond Myklebust75180df2007-05-16 16:53:28 -04002280 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002281 struct nfs_sb_mountdata sb_mntdata = {
2282 .mntflags = flags,
2283 };
Al Viro01194982011-03-16 07:25:36 -04002284 int error;
David Howells54ceac42006-08-22 20:06:13 -04002285
Paulius Zaleckas1e657bd2010-10-31 18:21:05 +02002286 data = nfs_alloc_parsed_mount_data(NFS_DEFAULT_VERSION);
Trond Myklebustb157b062010-04-19 19:05:48 -04002287 mntfh = nfs_alloc_fhandle();
Trond Myklebust33852a12008-06-19 14:20:11 -04002288 if (data == NULL || mntfh == NULL)
Jeff Layton8a0d5512011-12-20 06:57:45 -05002289 goto out;
Eric Parisf9c3a382008-03-05 14:20:18 -05002290
David Howells54ceac42006-08-22 20:06:13 -04002291 /* Validate the mount data */
Trond Myklebust33852a12008-06-19 14:20:11 -04002292 error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
Al Viro01194982011-03-16 07:25:36 -04002293 if (error < 0) {
2294 mntroot = ERR_PTR(error);
Chuck Lever06559602007-07-01 12:12:35 -04002295 goto out;
Al Viro01194982011-03-16 07:25:36 -04002296 }
David Howells54ceac42006-08-22 20:06:13 -04002297
Chuck Lever764302c2009-09-08 19:50:03 -04002298#ifdef CONFIG_NFS_V4
2299 if (data->version == 4) {
Al Viro01194982011-03-16 07:25:36 -04002300 mntroot = nfs4_try_mount(flags, dev_name, data);
Chuck Lever764302c2009-09-08 19:50:03 -04002301 goto out;
2302 }
2303#endif /* CONFIG_NFS_V4 */
2304
David Howells54ceac42006-08-22 20:06:13 -04002305 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002306 server = nfs_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002307 if (IS_ERR(server)) {
Al Viro01194982011-03-16 07:25:36 -04002308 mntroot = ERR_CAST(server);
Chuck Lever06559602007-07-01 12:12:35 -04002309 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002310 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002311 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002312
Trond Myklebust75180df2007-05-16 16:53:28 -04002313 if (server->flags & NFS_MOUNT_UNSHARED)
2314 compare_super = NULL;
2315
Sachin Prabhufb2088c2011-08-01 12:10:12 +01002316 /* -o noac implies -o sync */
2317 if (server->flags & NFS_MOUNT_NOAC)
2318 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2319
David Howells54ceac42006-08-22 20:06:13 -04002320 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002321 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002322 if (IS_ERR(s)) {
Al Viro01194982011-03-16 07:25:36 -04002323 mntroot = ERR_CAST(s);
David Howells54ceac42006-08-22 20:06:13 -04002324 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04002325 }
2326
David Howells54ceac42006-08-22 20:06:13 -04002327 if (s->s_fs_info != server) {
2328 nfs_free_server(server);
2329 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002330 } else {
2331 error = nfs_bdi_register(server);
Al Viro01194982011-03-16 07:25:36 -04002332 if (error) {
2333 mntroot = ERR_PTR(error);
NeilBrowncfbc0682010-03-11 11:20:17 +11002334 goto error_splat_bdi;
Al Viro01194982011-03-16 07:25:36 -04002335 }
David Howellsf7b422b2006-06-09 09:34:33 -04002336 }
David Howells54ceac42006-08-22 20:06:13 -04002337
2338 if (!s->s_root) {
2339 /* initial superblock/root creation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002340 nfs_fill_super(s, data);
Jesper Juhl160bc162011-04-10 17:57:07 +02002341 nfs_fscache_get_super_cookie(s, data->fscache_uniq, NULL);
David Howells54ceac42006-08-22 20:06:13 -04002342 }
2343
Al Viro0d5839a2011-03-16 05:27:27 -04002344 mntroot = nfs_get_root(s, mntfh, dev_name);
Al Viro01194982011-03-16 07:25:36 -04002345 if (IS_ERR(mntroot))
David Howells54ceac42006-08-22 20:06:13 -04002346 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002347
Trond Myklebust33852a12008-06-19 14:20:11 -04002348 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002349 if (error)
2350 goto error_splat_root;
2351
David Howellsf7b422b2006-06-09 09:34:33 -04002352 s->s_flags |= MS_ACTIVE;
Chuck Lever06559602007-07-01 12:12:35 -04002353
2354out:
Jeff Layton8a0d5512011-12-20 06:57:45 -05002355 nfs_free_parsed_mount_data(data);
Trond Myklebustb157b062010-04-19 19:05:48 -04002356 nfs_free_fhandle(mntfh);
Al Viro01194982011-03-16 07:25:36 -04002357 return mntroot;
Trond Myklebust816724e2006-06-24 08:41:41 -04002358
David Howells54ceac42006-08-22 20:06:13 -04002359out_err_nosb:
2360 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04002361 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002362
Eric Parisf9c3a382008-03-05 14:20:18 -05002363error_splat_root:
2364 dput(mntroot);
Al Viro01194982011-03-16 07:25:36 -04002365 mntroot = ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04002366error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002367 if (server && !s->s_root)
2368 bdi_unregister(&server->backing_dev_info);
2369error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002370 deactivate_locked_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04002371 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002372}
2373
David Howells54ceac42006-08-22 20:06:13 -04002374/*
Trond Myklebust387c1492010-02-03 08:27:35 -05002375 * Ensure that we unregister the bdi before kill_anon_super
2376 * releases the device name
2377 */
2378static void nfs_put_super(struct super_block *s)
2379{
2380 struct nfs_server *server = NFS_SB(s);
2381
2382 bdi_unregister(&server->backing_dev_info);
2383}
2384
2385/*
David Howells54ceac42006-08-22 20:06:13 -04002386 * Destroy an NFS2/3 superblock
2387 */
David Howellsf7b422b2006-06-09 09:34:33 -04002388static void nfs_kill_super(struct super_block *s)
2389{
2390 struct nfs_server *server = NFS_SB(s);
2391
2392 kill_anon_super(s);
David Howells08734042009-04-03 16:42:42 +01002393 nfs_fscache_release_super_cookie(s);
David Howells54ceac42006-08-22 20:06:13 -04002394 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04002395}
2396
David Howells54ceac42006-08-22 20:06:13 -04002397/*
2398 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2399 */
Al Viro31f43472010-10-29 03:38:12 -04002400static struct dentry *
2401nfs_xdev_mount(struct file_system_type *fs_type, int flags,
2402 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002403{
2404 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002405 struct super_block *s;
2406 struct nfs_server *server;
2407 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002408 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002409 struct nfs_sb_mountdata sb_mntdata = {
2410 .mntflags = flags,
2411 };
David Howells54ceac42006-08-22 20:06:13 -04002412 int error;
2413
Al Viro31f43472010-10-29 03:38:12 -04002414 dprintk("--> nfs_xdev_mount()\n");
David Howells54ceac42006-08-22 20:06:13 -04002415
2416 /* create a new volume representation */
2417 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2418 if (IS_ERR(server)) {
2419 error = PTR_ERR(server);
2420 goto out_err_noserver;
2421 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002422 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002423
Trond Myklebust75180df2007-05-16 16:53:28 -04002424 if (server->flags & NFS_MOUNT_UNSHARED)
2425 compare_super = NULL;
2426
Sachin Prabhufb2088c2011-08-01 12:10:12 +01002427 /* -o noac implies -o sync */
2428 if (server->flags & NFS_MOUNT_NOAC)
2429 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2430
David Howells54ceac42006-08-22 20:06:13 -04002431 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002432 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002433 if (IS_ERR(s)) {
2434 error = PTR_ERR(s);
2435 goto out_err_nosb;
2436 }
2437
2438 if (s->s_fs_info != server) {
2439 nfs_free_server(server);
2440 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002441 } else {
2442 error = nfs_bdi_register(server);
2443 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11002444 goto error_splat_bdi;
David Howells54ceac42006-08-22 20:06:13 -04002445 }
2446
2447 if (!s->s_root) {
2448 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002449 nfs_clone_super(s, data->sb);
David Howells2df54802009-09-23 14:36:39 -04002450 nfs_fscache_get_super_cookie(s, NULL, data);
David Howells54ceac42006-08-22 20:06:13 -04002451 }
2452
Al Viro0d5839a2011-03-16 05:27:27 -04002453 mntroot = nfs_get_root(s, data->fh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04002454 if (IS_ERR(mntroot)) {
2455 error = PTR_ERR(mntroot);
2456 goto error_splat_super;
2457 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002458 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
Neil Brown4c1fe2f2007-11-01 16:50:20 +11002459 dput(mntroot);
2460 error = -ESTALE;
2461 goto error_splat_super;
2462 }
David Howells54ceac42006-08-22 20:06:13 -04002463
2464 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002465
Eric Parisf9c3a382008-03-05 14:20:18 -05002466 /* clone any lsm security options from the parent to the new sb */
2467 security_sb_clone_mnt_opts(data->sb, s);
2468
Al Viro31f43472010-10-29 03:38:12 -04002469 dprintk("<-- nfs_xdev_mount() = 0\n");
2470 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04002471
2472out_err_nosb:
2473 nfs_free_server(server);
2474out_err_noserver:
Al Viro31f43472010-10-29 03:38:12 -04002475 dprintk("<-- nfs_xdev_mount() = %d [error]\n", error);
2476 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04002477
2478error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002479 if (server && !s->s_root)
2480 bdi_unregister(&server->backing_dev_info);
2481error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002482 deactivate_locked_super(s);
Al Viro31f43472010-10-29 03:38:12 -04002483 dprintk("<-- nfs_xdev_mount() = %d [splat]\n", error);
2484 return ERR_PTR(error);
David Howellsf7b422b2006-06-09 09:34:33 -04002485}
2486
2487#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04002488
2489/*
2490 * Finish setting up a cloned NFS4 superblock
2491 */
2492static void nfs4_clone_super(struct super_block *sb,
2493 const struct super_block *old_sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002494{
David Howells54ceac42006-08-22 20:06:13 -04002495 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2496 sb->s_blocksize = old_sb->s_blocksize;
2497 sb->s_maxbytes = old_sb->s_maxbytes;
2498 sb->s_time_gran = 1;
2499 sb->s_op = old_sb->s_op;
Aneesh Kumar K.Va8a5da92010-12-09 11:35:14 +00002500 /*
2501 * The VFS shouldn't apply the umask to mode bits. We will do
2502 * so ourselves when necessary.
2503 */
2504 sb->s_flags |= MS_POSIXACL;
Aneesh Kumar K.V64c2ce82010-12-09 11:35:25 +00002505 sb->s_xattr = old_sb->s_xattr;
2506 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002507}
2508
2509/*
2510 * Set up an NFS4 superblock
2511 */
David Howells54ceac42006-08-22 20:06:13 -04002512static void nfs4_fill_super(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002513{
David Howellsf7b422b2006-06-09 09:34:33 -04002514 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04002515 sb->s_op = &nfs4_sops;
Aneesh Kumar K.Va8a5da92010-12-09 11:35:14 +00002516 /*
2517 * The VFS shouldn't apply the umask to mode bits. We will do
2518 * so ourselves when necessary.
2519 */
2520 sb->s_flags |= MS_POSIXACL;
Aneesh Kumar K.V64c2ce82010-12-09 11:35:25 +00002521 sb->s_xattr = nfs4_xattr_handlers;
David Howells54ceac42006-08-22 20:06:13 -04002522 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002523}
2524
Trond Myklebust01c3f052009-06-17 13:22:58 -07002525static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2526{
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04002527 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3|
2528 NFS_MOUNT_LOCAL_FLOCK|NFS_MOUNT_LOCAL_FCNTL);
Trond Myklebust01c3f052009-06-17 13:22:58 -07002529}
2530
Chuck Lever7630c852009-09-08 19:49:57 -04002531static int nfs4_validate_text_mount_data(void *options,
2532 struct nfs_parsed_mount_data *args,
2533 const char *dev_name)
2534{
2535 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2536
Trond Myklebustf5855fe2009-10-06 15:40:37 -04002537 nfs_set_port(sap, &args->nfs_server.port, NFS_PORT);
Chuck Lever7630c852009-09-08 19:49:57 -04002538
2539 nfs_validate_transport_protocol(args);
2540
2541 nfs4_validate_mount_flags(args);
2542
Trond Myklebust2ecda722009-09-08 19:50:07 -04002543 if (args->version != 4) {
2544 dfprintk(MOUNT,
2545 "NFS4: Illegal mount version\n");
2546 return -EINVAL;
2547 }
2548
Chuck Lever7630c852009-09-08 19:49:57 -04002549 if (args->auth_flavor_len > 1) {
2550 dfprintk(MOUNT,
2551 "NFS4: Too many RPC auth flavours specified\n");
2552 return -EINVAL;
2553 }
2554
2555 if (args->client_address == NULL) {
2556 dfprintk(MOUNT,
2557 "NFS4: mount program didn't pass callback address\n");
2558 return -EINVAL;
2559 }
2560
2561 return nfs_parse_devname(dev_name,
2562 &args->nfs_server.hostname,
2563 NFS4_MAXNAMLEN,
2564 &args->nfs_server.export_path,
2565 NFS4_MAXPATHLEN);
2566}
2567
David Howells54ceac42006-08-22 20:06:13 -04002568/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04002569 * Validate NFSv4 mount options
2570 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002571static int nfs4_validate_mount_data(void *options,
2572 struct nfs_parsed_mount_data *args,
2573 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04002574{
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002575 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002576 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002577 char *c;
2578
2579 if (data == NULL)
2580 goto out_no_data;
2581
2582 switch (data->version) {
2583 case 1:
Chuck Lever4c568012007-12-10 14:59:28 -05002584 if (data->host_addrlen > sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002585 goto out_no_address;
Chuck Lever4c568012007-12-10 14:59:28 -05002586 if (data->host_addrlen == 0)
2587 goto out_no_address;
2588 args->nfs_server.addrlen = data->host_addrlen;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002589 if (copy_from_user(sap, data->host_addr, data->host_addrlen))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002590 return -EFAULT;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002591 if (!nfs_verify_server_address(sap))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002592 goto out_no_address;
2593
Chuck Lever6738b252008-06-24 16:33:54 -04002594 if (data->auth_flavourlen) {
2595 if (data->auth_flavourlen > 1)
2596 goto out_inval_auth;
Trond Myklebust20c71f52007-09-20 20:23:51 -04002597 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002598 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04002599 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002600 return -EFAULT;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002601 }
2602
2603 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2604 if (IS_ERR(c))
2605 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002606 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002607
2608 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2609 if (IS_ERR(c))
2610 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002611 args->nfs_server.export_path = c;
2612 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002613
2614 c = strndup_user(data->client_addr.data, 16);
2615 if (IS_ERR(c))
2616 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002617 args->client_address = c;
2618
2619 /*
2620 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2621 * can deal with.
2622 */
2623
2624 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2625 args->rsize = data->rsize;
2626 args->wsize = data->wsize;
2627 args->timeo = data->timeo;
2628 args->retrans = data->retrans;
2629 args->acregmin = data->acregmin;
2630 args->acregmax = data->acregmax;
2631 args->acdirmin = data->acdirmin;
2632 args->acdirmax = data->acdirmax;
2633 args->nfs_server.protocol = data->proto;
Trond Myklebust259875e2008-07-02 14:43:47 -04002634 nfs_validate_transport_protocol(args);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002635
2636 break;
Chuck Lever7630c852009-09-08 19:49:57 -04002637 default:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002638 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever80071222007-07-01 12:13:59 -04002639 return -EINVAL;
2640
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002641 if (!nfs_verify_server_address(sap))
Chuck Lever80071222007-07-01 12:13:59 -04002642 return -EINVAL;
Chuck Levered596a82008-06-26 17:47:05 -04002643
Chuck Lever7630c852009-09-08 19:49:57 -04002644 return nfs4_validate_text_mount_data(options, args, dev_name);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002645 }
2646
2647 return 0;
2648
2649out_no_data:
2650 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2651 return -EINVAL;
2652
2653out_inval_auth:
2654 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2655 data->auth_flavourlen);
2656 return -EINVAL;
2657
2658out_no_address:
2659 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2660 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002661}
2662
2663/*
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002664 * Get the superblock for the NFS4 root partition
David Howells54ceac42006-08-22 20:06:13 -04002665 */
Al Viro31f43472010-10-29 03:38:12 -04002666static struct dentry *
2667nfs4_remote_mount(struct file_system_type *fs_type, int flags,
2668 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002669{
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002670 struct nfs_parsed_mount_data *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002671 struct super_block *s;
2672 struct nfs_server *server;
Trond Myklebust33852a12008-06-19 14:20:11 -04002673 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04002674 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002675 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002676 struct nfs_sb_mountdata sb_mntdata = {
2677 .mntflags = flags,
2678 };
Trond Myklebust33852a12008-06-19 14:20:11 -04002679 int error = -ENOMEM;
David Howellsf7b422b2006-06-09 09:34:33 -04002680
Trond Myklebustb157b062010-04-19 19:05:48 -04002681 mntfh = nfs_alloc_fhandle();
Trond Myklebust33852a12008-06-19 14:20:11 -04002682 if (data == NULL || mntfh == NULL)
Jeff Layton8a0d5512011-12-20 06:57:45 -05002683 goto out;
Eric Parisf9c3a382008-03-05 14:20:18 -05002684
David Howells54ceac42006-08-22 20:06:13 -04002685 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002686 server = nfs4_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002687 if (IS_ERR(server)) {
2688 error = PTR_ERR(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04002689 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002690 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002691 sb_mntdata.server = server;
David Howellsf7b422b2006-06-09 09:34:33 -04002692
Trond Myklebust75180df2007-05-16 16:53:28 -04002693 if (server->flags & NFS4_MOUNT_UNSHARED)
2694 compare_super = NULL;
2695
Sachin Prabhufb2088c2011-08-01 12:10:12 +01002696 /* -o noac implies -o sync */
2697 if (server->flags & NFS_MOUNT_NOAC)
2698 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2699
David Howells54ceac42006-08-22 20:06:13 -04002700 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002701 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002702 if (IS_ERR(s)) {
2703 error = PTR_ERR(s);
David Howellsf7b422b2006-06-09 09:34:33 -04002704 goto out_free;
Trond Myklebust816724e2006-06-24 08:41:41 -04002705 }
2706
Trond Myklebust5dd31772006-08-24 01:03:05 -04002707 if (s->s_fs_info != server) {
2708 nfs_free_server(server);
2709 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002710 } else {
2711 error = nfs_bdi_register(server);
2712 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11002713 goto error_splat_bdi;
Trond Myklebust5dd31772006-08-24 01:03:05 -04002714 }
2715
David Howells54ceac42006-08-22 20:06:13 -04002716 if (!s->s_root) {
2717 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002718 nfs4_fill_super(s);
Jeff Laytonc15c9282012-01-24 16:35:00 +00002719 nfs_fscache_get_super_cookie(s, data->fscache_uniq, NULL);
Trond Myklebust816724e2006-06-24 08:41:41 -04002720 }
David Howellsf7b422b2006-06-09 09:34:33 -04002721
Al Viro0d5839a2011-03-16 05:27:27 -04002722 mntroot = nfs4_get_root(s, mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04002723 if (IS_ERR(mntroot)) {
2724 error = PTR_ERR(mntroot);
2725 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04002726 }
David Howells54ceac42006-08-22 20:06:13 -04002727
Trond Myklebust33852a12008-06-19 14:20:11 -04002728 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Paris46c8ac72008-05-02 13:42:42 -07002729 if (error)
2730 goto error_splat_root;
2731
David Howellsf7b422b2006-06-09 09:34:33 -04002732 s->s_flags |= MS_ACTIVE;
Al Viro31f43472010-10-29 03:38:12 -04002733
Al Viro31f43472010-10-29 03:38:12 -04002734 nfs_free_fhandle(mntfh);
2735 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04002736
Chuck Lever29eb9812007-07-01 12:12:30 -04002737out:
Trond Myklebustb157b062010-04-19 19:05:48 -04002738 nfs_free_fhandle(mntfh);
Al Viro31f43472010-10-29 03:38:12 -04002739 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04002740
Chuck Lever29eb9812007-07-01 12:12:30 -04002741out_free:
2742 nfs_free_server(server);
2743 goto out;
2744
Eric Paris46c8ac72008-05-02 13:42:42 -07002745error_splat_root:
2746 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04002747error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002748 if (server && !s->s_root)
2749 bdi_unregister(&server->backing_dev_info);
2750error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002751 deactivate_locked_super(s);
Chuck Lever29eb9812007-07-01 12:12:30 -04002752 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002753}
2754
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002755static struct vfsmount *nfs_do_root_mount(struct file_system_type *fs_type,
2756 int flags, void *data, const char *hostname)
2757{
2758 struct vfsmount *root_mnt;
2759 char *root_devname;
2760 size_t len;
2761
2762 len = strlen(hostname) + 3;
2763 root_devname = kmalloc(len, GFP_KERNEL);
2764 if (root_devname == NULL)
2765 return ERR_PTR(-ENOMEM);
2766 snprintf(root_devname, len, "%s:/", hostname);
2767 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 */
2946 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2947 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
Trond Myklebust75180df2007-05-16 16:53:28 -04002953 if (server->flags & NFS4_MOUNT_UNSHARED)
2954 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);
David Howells2df54802009-09-23 14:36:39 -04002979 nfs_fscache_get_super_cookie(s, NULL, data);
David Howells54ceac42006-08-22 20:06:13 -04002980 }
2981
Al Viro0d5839a2011-03-16 05:27:27 -04002982 mntroot = nfs4_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
Trond Myklebust75180df2007-05-16 16:53:28 -04003044 if (server->flags & NFS4_MOUNT_UNSHARED)
3045 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 */
David Howells54ceac42006-08-22 20:06:13 -04003069 nfs4_fill_super(s);
David Howells2df54802009-09-23 14:36:39 -04003070 nfs_fscache_get_super_cookie(s, NULL, data);
David Howells54ceac42006-08-22 20:06:13 -04003071 }
3072
Al Viro0d5839a2011-03-16 05:27:27 -04003073 mntroot = nfs4_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 */