blob: 8154accd1168e9ee43c6f972b7c5212e7a1472ba [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,
Weston Andros Adamson7ced2862012-02-07 11:49:11 -050083 Opt_v2, Opt_v3, Opt_v4, Opt_v4_0, Opt_v4_1,
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -040084 Opt_udp, Opt_tcp, Opt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -040085 Opt_acl, Opt_noacl,
86 Opt_rdirplus, Opt_nordirplus,
Trond Myklebust75180df2007-05-16 16:53:28 -040087 Opt_sharecache, Opt_nosharecache,
Chuck Leverd7403512008-12-23 15:21:37 -050088 Opt_resvport, Opt_noresvport,
David Howellsb797cac2009-04-03 16:42:48 +010089 Opt_fscache, Opt_nofscache,
Chuck Leverbf0fd762007-07-01 12:13:44 -040090
91 /* Mount options that take integer arguments */
92 Opt_port,
93 Opt_rsize, Opt_wsize, Opt_bsize,
94 Opt_timeo, Opt_retrans,
95 Opt_acregmin, Opt_acregmax,
96 Opt_acdirmin, Opt_acdirmax,
97 Opt_actimeo,
98 Opt_namelen,
99 Opt_mountport,
Chuck Levere887cbc2007-10-26 13:32:29 -0400100 Opt_mountvers,
Chuck Leverad879ce2007-10-26 13:32:24 -0400101 Opt_nfsvers,
Mike Sager3fd5be92009-04-01 09:21:48 -0400102 Opt_minorversion,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400103
104 /* Mount options that take string arguments */
Chuck Lever33832032007-12-10 14:59:13 -0500105 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
Chuck Lever0ac83772007-09-11 18:01:04 -0400106 Opt_addr, Opt_mountaddr, Opt_clientaddr,
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400107 Opt_lookupcache,
David Howellsb797cac2009-04-03 16:42:48 +0100108 Opt_fscache_uniq,
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400109 Opt_local_lock,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400110
Chuck Leverf45663c2008-06-24 19:28:02 -0400111 /* Special mount options */
112 Opt_userspace, Opt_deprecated, Opt_sloppy,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400113
114 Opt_err
115};
116
Steven Whitehousea447c092008-10-13 10:46:57 +0100117static const match_table_t nfs_mount_option_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400118 { Opt_userspace, "bg" },
119 { Opt_userspace, "fg" },
Chuck Leverecbb3842008-06-12 12:37:33 -0400120 { Opt_userspace, "retry=%s" },
121
Chuck Leverf45663c2008-06-24 19:28:02 -0400122 { Opt_sloppy, "sloppy" },
123
Chuck Leverbf0fd762007-07-01 12:13:44 -0400124 { Opt_soft, "soft" },
125 { Opt_hard, "hard" },
Chuck Leverd33e4df2008-06-12 12:37:41 -0400126 { Opt_deprecated, "intr" },
127 { Opt_deprecated, "nointr" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400128 { Opt_posix, "posix" },
129 { Opt_noposix, "noposix" },
130 { Opt_cto, "cto" },
131 { Opt_nocto, "nocto" },
132 { Opt_ac, "ac" },
133 { Opt_noac, "noac" },
134 { Opt_lock, "lock" },
135 { Opt_nolock, "nolock" },
136 { Opt_v2, "v2" },
137 { Opt_v3, "v3" },
Chuck Lever764302c2009-09-08 19:50:03 -0400138 { Opt_v4, "v4" },
Weston Andros Adamson7ced2862012-02-07 11:49:11 -0500139 { Opt_v4_0, "v4.0" },
140 { Opt_v4_1, "v4.1" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400141 { Opt_udp, "udp" },
142 { Opt_tcp, "tcp" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400143 { Opt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400144 { Opt_acl, "acl" },
145 { Opt_noacl, "noacl" },
146 { Opt_rdirplus, "rdirplus" },
147 { Opt_nordirplus, "nordirplus" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400148 { Opt_sharecache, "sharecache" },
149 { Opt_nosharecache, "nosharecache" },
Chuck Leverd7403512008-12-23 15:21:37 -0500150 { Opt_resvport, "resvport" },
151 { Opt_noresvport, "noresvport" },
David Howellsb797cac2009-04-03 16:42:48 +0100152 { Opt_fscache, "fsc" },
David Howellsb797cac2009-04-03 16:42:48 +0100153 { Opt_nofscache, "nofsc" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400154
Chuck Levera5a16ba2009-06-17 18:02:14 -0700155 { Opt_port, "port=%s" },
156 { Opt_rsize, "rsize=%s" },
157 { Opt_wsize, "wsize=%s" },
158 { Opt_bsize, "bsize=%s" },
159 { Opt_timeo, "timeo=%s" },
160 { Opt_retrans, "retrans=%s" },
161 { Opt_acregmin, "acregmin=%s" },
162 { Opt_acregmax, "acregmax=%s" },
163 { Opt_acdirmin, "acdirmin=%s" },
164 { Opt_acdirmax, "acdirmax=%s" },
165 { Opt_actimeo, "actimeo=%s" },
166 { Opt_namelen, "namlen=%s" },
167 { Opt_mountport, "mountport=%s" },
168 { Opt_mountvers, "mountvers=%s" },
169 { Opt_nfsvers, "nfsvers=%s" },
170 { Opt_nfsvers, "vers=%s" },
Chuck Leverf3f4f4e2009-08-09 15:09:29 -0400171 { Opt_minorversion, "minorversion=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400172
173 { Opt_sec, "sec=%s" },
174 { Opt_proto, "proto=%s" },
175 { Opt_mountproto, "mountproto=%s" },
176 { Opt_addr, "addr=%s" },
177 { Opt_clientaddr, "clientaddr=%s" },
Chuck Lever33832032007-12-10 14:59:13 -0500178 { Opt_mounthost, "mounthost=%s" },
Chuck Lever0ac83772007-09-11 18:01:04 -0400179 { Opt_mountaddr, "mountaddr=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400180
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400181 { Opt_lookupcache, "lookupcache=%s" },
Chuck Levera6d5ff62010-05-07 13:33:58 -0400182 { Opt_fscache_uniq, "fsc=%s" },
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400183 { Opt_local_lock, "local_lock=%s" },
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400184
Chuck Leverbf0fd762007-07-01 12:13:44 -0400185 { Opt_err, NULL }
186};
187
188enum {
Jeff Laytonee671b02009-12-03 15:58:56 -0500189 Opt_xprt_udp, Opt_xprt_udp6, Opt_xprt_tcp, Opt_xprt_tcp6, Opt_xprt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400190
191 Opt_xprt_err
192};
193
Steven Whitehousea447c092008-10-13 10:46:57 +0100194static const match_table_t nfs_xprt_protocol_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400195 { Opt_xprt_udp, "udp" },
Jeff Laytonee671b02009-12-03 15:58:56 -0500196 { Opt_xprt_udp6, "udp6" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400197 { Opt_xprt_tcp, "tcp" },
Jeff Laytonee671b02009-12-03 15:58:56 -0500198 { Opt_xprt_tcp6, "tcp6" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400199 { Opt_xprt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400200
201 { Opt_xprt_err, NULL }
202};
203
204enum {
205 Opt_sec_none, Opt_sec_sys,
206 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
207 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
208 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
209
210 Opt_sec_err
211};
212
Steven Whitehousea447c092008-10-13 10:46:57 +0100213static const match_table_t nfs_secflavor_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400214 { Opt_sec_none, "none" },
215 { Opt_sec_none, "null" },
216 { Opt_sec_sys, "sys" },
217
218 { Opt_sec_krb5, "krb5" },
219 { Opt_sec_krb5i, "krb5i" },
220 { Opt_sec_krb5p, "krb5p" },
221
222 { Opt_sec_lkey, "lkey" },
223 { Opt_sec_lkeyi, "lkeyi" },
224 { Opt_sec_lkeyp, "lkeyp" },
225
Olga Kornievskaia8d042212008-02-13 16:47:06 -0500226 { Opt_sec_spkm, "spkm3" },
227 { Opt_sec_spkmi, "spkm3i" },
228 { Opt_sec_spkmp, "spkm3p" },
229
Chuck Leverbf0fd762007-07-01 12:13:44 -0400230 { Opt_sec_err, NULL }
231};
232
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400233enum {
234 Opt_lookupcache_all, Opt_lookupcache_positive,
235 Opt_lookupcache_none,
236
237 Opt_lookupcache_err
238};
239
240static match_table_t nfs_lookupcache_tokens = {
241 { Opt_lookupcache_all, "all" },
242 { Opt_lookupcache_positive, "pos" },
243 { Opt_lookupcache_positive, "positive" },
244 { Opt_lookupcache_none, "none" },
245
246 { Opt_lookupcache_err, NULL }
247};
248
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400249enum {
250 Opt_local_lock_all, Opt_local_lock_flock, Opt_local_lock_posix,
251 Opt_local_lock_none,
252
253 Opt_local_lock_err
254};
255
256static match_table_t nfs_local_lock_tokens = {
257 { Opt_local_lock_all, "all" },
258 { Opt_local_lock_flock, "flock" },
259 { Opt_local_lock_posix, "posix" },
260 { Opt_local_lock_none, "none" },
261
262 { Opt_local_lock_err, NULL }
263};
264
Chuck Leverbf0fd762007-07-01 12:13:44 -0400265
Al Viro42faad92008-04-24 07:21:56 -0400266static void nfs_umount_begin(struct super_block *);
Trond Myklebust816724e2006-06-24 08:41:41 -0400267static int nfs_statfs(struct dentry *, struct kstatfs *);
Al Viro34c80b12011-12-08 21:32:45 -0500268static int nfs_show_options(struct seq_file *, struct dentry *);
Al Virod861c632011-12-08 21:32:45 -0500269static int nfs_show_devname(struct seq_file *, struct dentry *);
Al Viroa6322de2011-12-08 21:37:57 -0500270static int nfs_show_path(struct seq_file *, struct dentry *);
Al Viro64132372011-12-08 20:51:13 -0500271static int nfs_show_stats(struct seq_file *, struct dentry *);
Al Viro01194982011-03-16 07:25:36 -0400272static struct dentry *nfs_fs_mount(struct file_system_type *,
273 int, const char *, void *);
Al Viro31f43472010-10-29 03:38:12 -0400274static struct dentry *nfs_xdev_mount(struct file_system_type *fs_type,
275 int flags, const char *dev_name, void *raw_data);
Trond Myklebust387c1492010-02-03 08:27:35 -0500276static void nfs_put_super(struct super_block *);
David Howellsf7b422b2006-06-09 09:34:33 -0400277static void nfs_kill_super(struct super_block *);
Jeff Layton48b605f2008-06-10 15:38:39 -0400278static int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
David Howellsf7b422b2006-06-09 09:34:33 -0400279
280static struct file_system_type nfs_fs_type = {
281 .owner = THIS_MODULE,
282 .name = "nfs",
Al Viro01194982011-03-16 07:25:36 -0400283 .mount = nfs_fs_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400284 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700285 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400286};
287
David Howells54ceac42006-08-22 20:06:13 -0400288struct file_system_type nfs_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400289 .owner = THIS_MODULE,
290 .name = "nfs",
Al Viro31f43472010-10-29 03:38:12 -0400291 .mount = nfs_xdev_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400292 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700293 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400294};
295
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800296static const struct super_operations nfs_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400297 .alloc_inode = nfs_alloc_inode,
298 .destroy_inode = nfs_destroy_inode,
299 .write_inode = nfs_write_inode,
Trond Myklebust387c1492010-02-03 08:27:35 -0500300 .put_super = nfs_put_super,
David Howellsf7b422b2006-06-09 09:34:33 -0400301 .statfs = nfs_statfs,
Al Virob57922d2010-06-07 14:34:48 -0400302 .evict_inode = nfs_evict_inode,
David Howellsf7b422b2006-06-09 09:34:33 -0400303 .umount_begin = nfs_umount_begin,
304 .show_options = nfs_show_options,
Al Viroc7f404b2011-03-16 06:59:40 -0400305 .show_devname = nfs_show_devname,
306 .show_path = nfs_show_path,
David Howellsf7b422b2006-06-09 09:34:33 -0400307 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400308 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400309};
310
311#ifdef CONFIG_NFS_V4
Chuck Lever7630c852009-09-08 19:49:57 -0400312static int nfs4_validate_text_mount_data(void *options,
313 struct nfs_parsed_mount_data *args, const char *dev_name);
Al Viro01194982011-03-16 07:25:36 -0400314static struct dentry *nfs4_try_mount(int flags, const char *dev_name,
315 struct nfs_parsed_mount_data *data);
316static struct dentry *nfs4_mount(struct file_system_type *fs_type,
317 int flags, const char *dev_name, void *raw_data);
Al Viro31f43472010-10-29 03:38:12 -0400318static struct dentry *nfs4_remote_mount(struct file_system_type *fs_type,
319 int flags, const char *dev_name, void *raw_data);
320static struct dentry *nfs4_xdev_mount(struct file_system_type *fs_type,
321 int flags, const char *dev_name, void *raw_data);
Al Viro01194982011-03-16 07:25:36 -0400322static struct dentry *nfs4_referral_mount(struct file_system_type *fs_type,
323 int flags, const char *dev_name, void *raw_data);
Al Viro31f43472010-10-29 03:38:12 -0400324static struct dentry *nfs4_remote_referral_mount(struct file_system_type *fs_type,
325 int flags, const char *dev_name, void *raw_data);
David Howellsf7b422b2006-06-09 09:34:33 -0400326static void nfs4_kill_super(struct super_block *sb);
327
328static struct file_system_type nfs4_fs_type = {
329 .owner = THIS_MODULE,
330 .name = "nfs4",
Al Viro01194982011-03-16 07:25:36 -0400331 .mount = nfs4_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400332 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700333 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400334};
335
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400336static struct file_system_type nfs4_remote_fs_type = {
337 .owner = THIS_MODULE,
338 .name = "nfs4",
Al Viro31f43472010-10-29 03:38:12 -0400339 .mount = nfs4_remote_mount,
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400340 .kill_sb = nfs4_kill_super,
341 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
342};
343
David Howells54ceac42006-08-22 20:06:13 -0400344struct file_system_type nfs4_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400345 .owner = THIS_MODULE,
346 .name = "nfs4",
Al Viro31f43472010-10-29 03:38:12 -0400347 .mount = nfs4_xdev_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400348 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700349 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400350};
351
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400352static struct file_system_type nfs4_remote_referral_fs_type = {
353 .owner = THIS_MODULE,
354 .name = "nfs4",
Al Viro31f43472010-10-29 03:38:12 -0400355 .mount = nfs4_remote_referral_mount,
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400356 .kill_sb = nfs4_kill_super,
357 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
358};
359
David Howells54ceac42006-08-22 20:06:13 -0400360struct file_system_type nfs4_referral_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400361 .owner = THIS_MODULE,
362 .name = "nfs4",
Al Viro01194982011-03-16 07:25:36 -0400363 .mount = nfs4_referral_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400364 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700365 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400366};
367
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800368static const struct super_operations nfs4_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400369 .alloc_inode = nfs_alloc_inode,
370 .destroy_inode = nfs_destroy_inode,
371 .write_inode = nfs_write_inode,
Trond Myklebust387c1492010-02-03 08:27:35 -0500372 .put_super = nfs_put_super,
David Howellsf7b422b2006-06-09 09:34:33 -0400373 .statfs = nfs_statfs,
Al Virob57922d2010-06-07 14:34:48 -0400374 .evict_inode = nfs4_evict_inode,
David Howellsf7b422b2006-06-09 09:34:33 -0400375 .umount_begin = nfs_umount_begin,
376 .show_options = nfs_show_options,
Al Viroc7f404b2011-03-16 06:59:40 -0400377 .show_devname = nfs_show_devname,
378 .show_path = nfs_show_path,
David Howellsf7b422b2006-06-09 09:34:33 -0400379 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400380 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400381};
382#endif
383
Rusty Russell8e1f9362007-07-17 04:03:17 -0700384static struct shrinker acl_shrinker = {
385 .shrink = nfs_access_cache_shrinker,
386 .seeks = DEFAULT_SEEKS,
387};
Trond Myklebust979df722006-07-25 11:28:19 -0400388
David Howellsf7b422b2006-06-09 09:34:33 -0400389/*
390 * Register the NFS filesystems
391 */
392int __init register_nfs_fs(void)
393{
394 int ret;
395
396 ret = register_filesystem(&nfs_fs_type);
397 if (ret < 0)
398 goto error_0;
399
David Howellsf7b422b2006-06-09 09:34:33 -0400400 ret = nfs_register_sysctl();
401 if (ret < 0)
402 goto error_1;
Peter Zijlstra89a09142007-03-16 13:38:26 -0800403#ifdef CONFIG_NFS_V4
David Howellsf7b422b2006-06-09 09:34:33 -0400404 ret = register_filesystem(&nfs4_fs_type);
405 if (ret < 0)
406 goto error_2;
407#endif
Rusty Russell8e1f9362007-07-17 04:03:17 -0700408 register_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400409 return 0;
410
411#ifdef CONFIG_NFS_V4
412error_2:
413 nfs_unregister_sysctl();
Peter Zijlstra89a09142007-03-16 13:38:26 -0800414#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400415error_1:
416 unregister_filesystem(&nfs_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400417error_0:
418 return ret;
419}
420
421/*
422 * Unregister the NFS filesystems
423 */
424void __exit unregister_nfs_fs(void)
425{
Rusty Russell8e1f9362007-07-17 04:03:17 -0700426 unregister_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400427#ifdef CONFIG_NFS_V4
428 unregister_filesystem(&nfs4_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400429#endif
Alexey Dobriyan49af7ee2007-09-18 22:46:40 -0700430 nfs_unregister_sysctl();
David Howellsf7b422b2006-06-09 09:34:33 -0400431 unregister_filesystem(&nfs_fs_type);
432}
433
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400434void nfs_sb_active(struct super_block *sb)
Steve Dicksonef818a22007-11-08 04:05:04 -0500435{
436 struct nfs_server *server = NFS_SB(sb);
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400437
438 if (atomic_inc_return(&server->active) == 1)
439 atomic_inc(&sb->s_active);
440}
441
442void nfs_sb_deactive(struct super_block *sb)
443{
444 struct nfs_server *server = NFS_SB(sb);
445
446 if (atomic_dec_and_test(&server->active))
447 deactivate_super(sb);
Steve Dicksonef818a22007-11-08 04:05:04 -0500448}
449
David Howellsf7b422b2006-06-09 09:34:33 -0400450/*
451 * Deliver file system statistics to userspace
452 */
Trond Myklebust816724e2006-06-24 08:41:41 -0400453static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
David Howellsf7b422b2006-06-09 09:34:33 -0400454{
David Howells0c7d90c2006-08-22 20:06:10 -0400455 struct nfs_server *server = NFS_SB(dentry->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400456 unsigned char blockbits;
457 unsigned long blockres;
David Howells0c7d90c2006-08-22 20:06:10 -0400458 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400459 struct nfs_fsstat res;
460 int error = -ENOMEM;
461
462 res.fattr = nfs_alloc_fattr();
463 if (res.fattr == NULL)
464 goto out_err;
David Howellsf7b422b2006-06-09 09:34:33 -0400465
David Howells8fa5c002006-08-22 20:06:12 -0400466 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
Menyhart Zoltanfbf3fdd2010-09-12 19:55:26 -0400467 if (unlikely(error == -ESTALE)) {
468 struct dentry *pd_dentry;
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400469
Menyhart Zoltanfbf3fdd2010-09-12 19:55:26 -0400470 pd_dentry = dget_parent(dentry);
471 if (pd_dentry != NULL) {
472 nfs_zap_caches(pd_dentry->d_inode);
473 dput(pd_dentry);
474 }
475 }
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400476 nfs_free_fattr(res.fattr);
David Howellsf7b422b2006-06-09 09:34:33 -0400477 if (error < 0)
478 goto out_err;
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400479
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700480 buf->f_type = NFS_SUPER_MAGIC;
David Howellsf7b422b2006-06-09 09:34:33 -0400481
482 /*
483 * Current versions of glibc do not correctly handle the
484 * case where f_frsize != f_bsize. Eventually we want to
485 * report the value of wtmult in this field.
486 */
David Howells0c7d90c2006-08-22 20:06:10 -0400487 buf->f_frsize = dentry->d_sb->s_blocksize;
David Howellsf7b422b2006-06-09 09:34:33 -0400488
489 /*
490 * On most *nix systems, f_blocks, f_bfree, and f_bavail
491 * are reported in units of f_frsize. Linux hasn't had
492 * an f_frsize field in its statfs struct until recently,
493 * thus historically Linux's sys_statfs reports these
494 * fields in units of f_bsize.
495 */
David Howells0c7d90c2006-08-22 20:06:10 -0400496 buf->f_bsize = dentry->d_sb->s_blocksize;
497 blockbits = dentry->d_sb->s_blocksize_bits;
David Howellsf7b422b2006-06-09 09:34:33 -0400498 blockres = (1 << blockbits) - 1;
499 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
500 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
501 buf->f_bavail = (res.abytes + blockres) >> blockbits;
502
503 buf->f_files = res.tfiles;
504 buf->f_ffree = res.afiles;
505
506 buf->f_namelen = server->namelen;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700507
David Howellsf7b422b2006-06-09 09:34:33 -0400508 return 0;
509
510 out_err:
Harvey Harrison3110ff82008-05-02 13:42:44 -0700511 dprintk("%s: statfs error = %d\n", __func__, -error);
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700512 return error;
David Howellsf7b422b2006-06-09 09:34:33 -0400513}
514
David Howells7d4e2742006-08-22 20:06:07 -0400515/*
516 * Map the security flavour number to a name
517 */
Trond Myklebust81039f12006-06-09 09:34:34 -0400518static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
519{
David Howells7d4e2742006-08-22 20:06:07 -0400520 static const struct {
Trond Myklebust81039f12006-06-09 09:34:34 -0400521 rpc_authflavor_t flavour;
522 const char *str;
523 } sec_flavours[] = {
524 { RPC_AUTH_NULL, "null" },
525 { RPC_AUTH_UNIX, "sys" },
526 { RPC_AUTH_GSS_KRB5, "krb5" },
527 { RPC_AUTH_GSS_KRB5I, "krb5i" },
528 { RPC_AUTH_GSS_KRB5P, "krb5p" },
529 { RPC_AUTH_GSS_LKEY, "lkey" },
530 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
531 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
532 { RPC_AUTH_GSS_SPKM, "spkm" },
533 { RPC_AUTH_GSS_SPKMI, "spkmi" },
534 { RPC_AUTH_GSS_SPKMP, "spkmp" },
Chuck Lever4d81cd12007-07-01 12:12:40 -0400535 { UINT_MAX, "unknown" }
Trond Myklebust81039f12006-06-09 09:34:34 -0400536 };
537 int i;
538
Chuck Lever4d81cd12007-07-01 12:12:40 -0400539 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
Trond Myklebust81039f12006-06-09 09:34:34 -0400540 if (sec_flavours[i].flavour == flavour)
541 break;
542 }
543 return sec_flavours[i].str;
544}
545
Jeff Laytonee671b02009-12-03 15:58:56 -0500546static void nfs_show_mountd_netid(struct seq_file *m, struct nfs_server *nfss,
547 int showdefaults)
548{
549 struct sockaddr *sap = (struct sockaddr *) &nfss->mountd_address;
550
551 seq_printf(m, ",mountproto=");
552 switch (sap->sa_family) {
553 case AF_INET:
554 switch (nfss->mountd_protocol) {
555 case IPPROTO_UDP:
556 seq_printf(m, RPCBIND_NETID_UDP);
557 break;
558 case IPPROTO_TCP:
559 seq_printf(m, RPCBIND_NETID_TCP);
560 break;
561 default:
562 if (showdefaults)
563 seq_printf(m, "auto");
564 }
565 break;
566 case AF_INET6:
567 switch (nfss->mountd_protocol) {
568 case IPPROTO_UDP:
569 seq_printf(m, RPCBIND_NETID_UDP6);
570 break;
571 case IPPROTO_TCP:
572 seq_printf(m, RPCBIND_NETID_TCP6);
573 break;
574 default:
575 if (showdefaults)
576 seq_printf(m, "auto");
577 }
578 break;
579 default:
580 if (showdefaults)
581 seq_printf(m, "auto");
582 }
583}
584
Chuck Lever82d101d2008-03-14 14:10:37 -0400585static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
586 int showdefaults)
587{
588 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
589
Bryan Schumakerd5eff1a2010-08-03 13:04:00 -0400590 if (nfss->flags & NFS_MOUNT_LEGACY_INTERFACE)
591 return;
592
Chuck Lever82d101d2008-03-14 14:10:37 -0400593 switch (sap->sa_family) {
594 case AF_INET: {
595 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
Harvey Harrisonbe859402008-10-31 00:56:28 -0700596 seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400597 break;
598 }
599 case AF_INET6: {
600 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
Chuck Leverd250e192009-12-03 15:58:56 -0500601 seq_printf(m, ",mountaddr=%pI6c", &sin6->sin6_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400602 break;
603 }
604 default:
605 if (showdefaults)
606 seq_printf(m, ",mountaddr=unspecified");
607 }
608
609 if (nfss->mountd_version || showdefaults)
610 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
Stanislav Kinsburskyaa699472010-12-08 12:40:13 +0300611 if ((nfss->mountd_port &&
612 nfss->mountd_port != (unsigned short)NFS_UNSPEC_PORT) ||
613 showdefaults)
Chuck Lever82d101d2008-03-14 14:10:37 -0400614 seq_printf(m, ",mountport=%u", nfss->mountd_port);
615
Jeff Laytonee671b02009-12-03 15:58:56 -0500616 nfs_show_mountd_netid(m, nfss, showdefaults);
Chuck Lever82d101d2008-03-14 14:10:37 -0400617}
618
Trond Myklebust0be81892010-06-18 12:23:58 -0400619#ifdef CONFIG_NFS_V4
620static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
621 int showdefaults)
622{
623 struct nfs_client *clp = nfss->nfs_client;
624
625 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
626 seq_printf(m, ",minorversion=%u", clp->cl_minorversion);
627}
628#else
629static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
630 int showdefaults)
631{
632}
633#endif
634
David Howellsf7b422b2006-06-09 09:34:33 -0400635/*
636 * Describe the mount options in force on this server representation
637 */
Chuck Lever82d101d2008-03-14 14:10:37 -0400638static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
639 int showdefaults)
David Howellsf7b422b2006-06-09 09:34:33 -0400640{
David Howells509de812006-08-22 20:06:11 -0400641 static const struct proc_nfs_info {
David Howellsf7b422b2006-06-09 09:34:33 -0400642 int flag;
David Howells509de812006-08-22 20:06:11 -0400643 const char *str;
644 const char *nostr;
David Howellsf7b422b2006-06-09 09:34:33 -0400645 } nfs_info[] = {
646 { NFS_MOUNT_SOFT, ",soft", ",hard" },
Chuck Lever82d101d2008-03-14 14:10:37 -0400647 { NFS_MOUNT_POSIX, ",posix", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400648 { NFS_MOUNT_NOCTO, ",nocto", "" },
649 { NFS_MOUNT_NOAC, ",noac", "" },
650 { NFS_MOUNT_NONLM, ",nolock", "" },
651 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400652 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
Chuck Leverd7403512008-12-23 15:21:37 -0500653 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
654 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400655 { 0, NULL, NULL }
656 };
David Howells509de812006-08-22 20:06:11 -0400657 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400658 struct nfs_client *clp = nfss->nfs_client;
Chuck Lever82d101d2008-03-14 14:10:37 -0400659 u32 version = clp->rpc_ops->version;
Suresh Jayaraman7c563cc2010-09-23 14:26:48 -0400660 int local_flock, local_fcntl;
David Howellsf7b422b2006-06-09 09:34:33 -0400661
Chuck Lever82d101d2008-03-14 14:10:37 -0400662 seq_printf(m, ",vers=%u", version);
Chuck Lever2d767432008-03-14 14:10:08 -0400663 seq_printf(m, ",rsize=%u", nfss->rsize);
664 seq_printf(m, ",wsize=%u", nfss->wsize);
Chuck Lever82d101d2008-03-14 14:10:37 -0400665 if (nfss->bsize != 0)
666 seq_printf(m, ",bsize=%u", nfss->bsize);
667 seq_printf(m, ",namlen=%u", nfss->namelen);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400668 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400669 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400670 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400671 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400672 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400673 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400674 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400675 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
David Howellsf7b422b2006-06-09 09:34:33 -0400676 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
677 if (nfss->flags & nfs_infop->flag)
678 seq_puts(m, nfs_infop->str);
679 else
680 seq_puts(m, nfs_infop->nostr);
681 }
\"Talpey, Thomas\56928ed2007-09-10 13:48:47 -0400682 seq_printf(m, ",proto=%s",
Jeff Laytonee671b02009-12-03 15:58:56 -0500683 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
Chuck Lever82d101d2008-03-14 14:10:37 -0400684 if (version == 4) {
685 if (nfss->port != NFS_PORT)
686 seq_printf(m, ",port=%u", nfss->port);
687 } else
688 if (nfss->port)
689 seq_printf(m, ",port=%u", nfss->port);
690
Trond Myklebust33170232007-12-20 16:03:59 -0500691 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
692 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
Trond Myklebust81039f12006-06-09 09:34:34 -0400693 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
Chuck Lever82d101d2008-03-14 14:10:37 -0400694
695 if (version != 4)
696 nfs_show_mountd_options(m, nfss, showdefaults);
Trond Myklebust0be81892010-06-18 12:23:58 -0400697 else
698 nfs_show_nfsv4_options(m, nfss, showdefaults);
Chuck Lever82d101d2008-03-14 14:10:37 -0400699
David Howellsb797cac2009-04-03 16:42:48 +0100700 if (nfss->options & NFS_OPTION_FSCACHE)
701 seq_printf(m, ",fsc");
Patrick J. LoPresti9b00c642010-08-10 17:28:01 -0400702
703 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONEG) {
704 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONE)
705 seq_printf(m, ",lookupcache=none");
706 else
707 seq_printf(m, ",lookupcache=pos");
708 }
Suresh Jayaraman7c563cc2010-09-23 14:26:48 -0400709
710 local_flock = nfss->flags & NFS_MOUNT_LOCAL_FLOCK;
711 local_fcntl = nfss->flags & NFS_MOUNT_LOCAL_FCNTL;
712
713 if (!local_flock && !local_fcntl)
714 seq_printf(m, ",local_lock=none");
715 else if (local_flock && local_fcntl)
716 seq_printf(m, ",local_lock=all");
717 else if (local_flock)
718 seq_printf(m, ",local_lock=flock");
719 else
720 seq_printf(m, ",local_lock=posix");
David Howellsf7b422b2006-06-09 09:34:33 -0400721}
722
723/*
724 * Describe the mount options on this VFS mountpoint
725 */
Al Viro34c80b12011-12-08 21:32:45 -0500726static int nfs_show_options(struct seq_file *m, struct dentry *root)
David Howellsf7b422b2006-06-09 09:34:33 -0400727{
Al Viro34c80b12011-12-08 21:32:45 -0500728 struct nfs_server *nfss = NFS_SB(root->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400729
730 nfs_show_mount_options(m, nfss, 0);
731
Chuck Lever5d8515c2007-12-10 14:57:16 -0500732 seq_printf(m, ",addr=%s",
733 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
734 RPC_DISPLAY_ADDR));
David Howellsf7b422b2006-06-09 09:34:33 -0400735
736 return 0;
737}
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700738
739#ifdef CONFIG_NFS_V4
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300740#ifdef CONFIG_NFS_V4_1
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700741static void show_sessions(struct seq_file *m, struct nfs_server *server)
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300742{
743 if (nfs4_has_session(server->nfs_client))
744 seq_printf(m, ",sessions");
745}
746#else
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700747static void show_sessions(struct seq_file *m, struct nfs_server *server) {}
748#endif
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300749#endif
750
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700751#ifdef CONFIG_NFS_V4
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300752#ifdef CONFIG_NFS_V4_1
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700753static void show_pnfs(struct seq_file *m, struct nfs_server *server)
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300754{
755 seq_printf(m, ",pnfs=");
756 if (server->pnfs_curr_ld)
757 seq_printf(m, "%s", server->pnfs_curr_ld->name);
758 else
759 seq_printf(m, "not configured");
760}
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700761#else
762static void show_pnfs(struct seq_file *m, struct nfs_server *server) {}
763#endif
764#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400765
Al Virod861c632011-12-08 21:32:45 -0500766static int nfs_show_devname(struct seq_file *m, struct dentry *root)
Al Viroc7f404b2011-03-16 06:59:40 -0400767{
768 char *page = (char *) __get_free_page(GFP_KERNEL);
769 char *devname, *dummy;
770 int err = 0;
771 if (!page)
772 return -ENOMEM;
Al Virod861c632011-12-08 21:32:45 -0500773 devname = nfs_path(&dummy, root, page, PAGE_SIZE);
Al Viroc7f404b2011-03-16 06:59:40 -0400774 if (IS_ERR(devname))
775 err = PTR_ERR(devname);
776 else
777 seq_escape(m, devname, " \t\n\\");
778 free_page((unsigned long)page);
779 return err;
780}
781
Al Viroa6322de2011-12-08 21:37:57 -0500782static int nfs_show_path(struct seq_file *m, struct dentry *dentry)
Al Viroc7f404b2011-03-16 06:59:40 -0400783{
784 seq_puts(m, "/");
785 return 0;
786}
787
David Howellsf7b422b2006-06-09 09:34:33 -0400788/*
789 * Present statistical information for this VFS mountpoint
790 */
Al Viro64132372011-12-08 20:51:13 -0500791static int nfs_show_stats(struct seq_file *m, struct dentry *root)
David Howellsf7b422b2006-06-09 09:34:33 -0400792{
793 int i, cpu;
Al Viro64132372011-12-08 20:51:13 -0500794 struct nfs_server *nfss = NFS_SB(root->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400795 struct rpc_auth *auth = nfss->client->cl_auth;
796 struct nfs_iostats totals = { };
797
798 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
799
800 /*
801 * Display all mount option settings
802 */
803 seq_printf(m, "\n\topts:\t");
Al Viro64132372011-12-08 20:51:13 -0500804 seq_puts(m, root->d_sb->s_flags & MS_RDONLY ? "ro" : "rw");
805 seq_puts(m, root->d_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
806 seq_puts(m, root->d_sb->s_flags & MS_NOATIME ? ",noatime" : "");
807 seq_puts(m, root->d_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
David Howellsf7b422b2006-06-09 09:34:33 -0400808 nfs_show_mount_options(m, nfss, 1);
809
810 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
811
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500812 if (nfss->nfs_client && nfss->nfs_client->impl_id) {
813 struct nfs41_impl_id *impl_id = nfss->nfs_client->impl_id;
814 seq_printf(m, "\n\timpl_id:\tname='%s',domain='%s',"
815 "date='%llu,%u'",
816 impl_id->name, impl_id->domain,
817 impl_id->date.seconds, impl_id->date.nseconds);
818 }
819
David Howellsf7b422b2006-06-09 09:34:33 -0400820 seq_printf(m, "\n\tcaps:\t");
821 seq_printf(m, "caps=0x%x", nfss->caps);
Chuck Lever2d767432008-03-14 14:10:08 -0400822 seq_printf(m, ",wtmult=%u", nfss->wtmult);
823 seq_printf(m, ",dtsize=%u", nfss->dtsize);
824 seq_printf(m, ",bsize=%u", nfss->bsize);
825 seq_printf(m, ",namlen=%u", nfss->namelen);
David Howellsf7b422b2006-06-09 09:34:33 -0400826
827#ifdef CONFIG_NFS_V4
Trond Myklebust40c553192007-12-14 14:56:07 -0500828 if (nfss->nfs_client->rpc_ops->version == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400829 seq_printf(m, "\n\tnfsv4:\t");
830 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
831 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
832 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300833 show_sessions(m, nfss);
834 show_pnfs(m, nfss);
David Howellsf7b422b2006-06-09 09:34:33 -0400835 }
836#endif
837
838 /*
839 * Display security flavor in effect for this mount
840 */
Chuck Lever2d767432008-03-14 14:10:08 -0400841 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400842 if (auth->au_flavor)
Chuck Lever2d767432008-03-14 14:10:08 -0400843 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400844
845 /*
846 * Display superblock I/O counters
847 */
848 for_each_possible_cpu(cpu) {
849 struct nfs_iostats *stats;
850
851 preempt_disable();
852 stats = per_cpu_ptr(nfss->io_stats, cpu);
853
854 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
855 totals.events[i] += stats->events[i];
856 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
857 totals.bytes[i] += stats->bytes[i];
David Howells6a510912009-04-03 16:42:43 +0100858#ifdef CONFIG_NFS_FSCACHE
859 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
860 totals.fscache[i] += stats->fscache[i];
861#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400862
863 preempt_enable();
864 }
865
866 seq_printf(m, "\n\tevents:\t");
867 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
868 seq_printf(m, "%lu ", totals.events[i]);
869 seq_printf(m, "\n\tbytes:\t");
870 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
871 seq_printf(m, "%Lu ", totals.bytes[i]);
David Howells6a510912009-04-03 16:42:43 +0100872#ifdef CONFIG_NFS_FSCACHE
873 if (nfss->options & NFS_OPTION_FSCACHE) {
874 seq_printf(m, "\n\tfsc:\t");
875 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
876 seq_printf(m, "%Lu ", totals.bytes[i]);
877 }
878#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400879 seq_printf(m, "\n");
880
881 rpc_print_iostats(m, nfss->client);
882
883 return 0;
884}
885
886/*
887 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400888 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400889 */
Al Viro42faad92008-04-24 07:21:56 -0400890static void nfs_umount_begin(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -0400891{
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200892 struct nfs_server *server;
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400893 struct rpc_clnt *rpc;
894
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200895 server = NFS_SB(sb);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400896 /* -EIO all pending I/O */
897 rpc = server->client_acl;
898 if (!IS_ERR(rpc))
899 rpc_killall_tasks(rpc);
900 rpc = server->client;
901 if (!IS_ERR(rpc))
902 rpc_killall_tasks(rpc);
David Howellsf7b422b2006-06-09 09:34:33 -0400903}
904
Trond Myklebustc5811db2009-10-06 15:40:15 -0400905static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(unsigned int version)
Chuck Lever9423a082009-09-23 14:36:38 -0400906{
907 struct nfs_parsed_mount_data *data;
908
909 data = kzalloc(sizeof(*data), GFP_KERNEL);
910 if (data) {
Chuck Lever9423a082009-09-23 14:36:38 -0400911 data->acregmin = NFS_DEF_ACREGMIN;
912 data->acregmax = NFS_DEF_ACREGMAX;
913 data->acdirmin = NFS_DEF_ACDIRMIN;
914 data->acdirmax = NFS_DEF_ACDIRMAX;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400915 data->mount_server.port = NFS_UNSPEC_PORT;
Chuck Lever9423a082009-09-23 14:36:38 -0400916 data->nfs_server.port = NFS_UNSPEC_PORT;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400917 data->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Lever9423a082009-09-23 14:36:38 -0400918 data->auth_flavors[0] = RPC_AUTH_UNIX;
919 data->auth_flavor_len = 1;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400920 data->version = version;
Chuck Lever9423a082009-09-23 14:36:38 -0400921 data->minorversion = 0;
Trond Myklebust9937347a2012-02-19 08:44:07 +0100922 data->net = current->nsproxy->net_ns;
Jeff Layton8a0d5512011-12-20 06:57:45 -0500923 security_init_mnt_opts(&data->lsm_opts);
Chuck Lever9423a082009-09-23 14:36:38 -0400924 }
925 return data;
926}
927
Jeff Layton8a0d5512011-12-20 06:57:45 -0500928static void nfs_free_parsed_mount_data(struct nfs_parsed_mount_data *data)
929{
930 if (data) {
931 kfree(data->client_address);
932 kfree(data->mount_server.hostname);
933 kfree(data->nfs_server.export_path);
934 kfree(data->nfs_server.hostname);
935 kfree(data->fscache_uniq);
936 security_free_mnt_opts(&data->lsm_opts);
937 kfree(data);
938 }
939}
940
David Howellsf7b422b2006-06-09 09:34:33 -0400941/*
Chuck Levercdcd7f92007-12-10 14:57:45 -0500942 * Sanity-check a server address provided by the mount command.
943 *
944 * Address family must be initialized, and address must not be
945 * the ANY address for that family.
Chuck Leverfc50d582007-07-01 12:12:46 -0400946 */
947static int nfs_verify_server_address(struct sockaddr *addr)
948{
949 switch (addr->sa_family) {
950 case AF_INET: {
Chuck Levercdcd7f92007-12-10 14:57:45 -0500951 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
Al Viroe6f1ceb2008-03-17 22:44:53 -0700952 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
Chuck Levercdcd7f92007-12-10 14:57:45 -0500953 }
954 case AF_INET6: {
955 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
956 return !ipv6_addr_any(sa);
Chuck Leverfc50d582007-07-01 12:12:46 -0400957 }
958 }
959
Chuck Lever53a0b9c2009-08-09 15:09:36 -0400960 dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
Chuck Leverfc50d582007-07-01 12:12:46 -0400961 return 0;
962}
963
Chuck Lever9412b922007-12-10 14:59:21 -0500964/*
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400965 * Select between a default port value and a user-specified port value.
966 * If a zero value is set, then autobind will be used.
967 */
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400968static void nfs_set_port(struct sockaddr *sap, int *port,
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400969 const unsigned short default_port)
970{
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400971 if (*port == NFS_UNSPEC_PORT)
972 *port = default_port;
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400973
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400974 rpc_set_port(sap, *port);
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400975}
976
977/*
Trond Myklebust259875e2008-07-02 14:43:47 -0400978 * Sanity check the NFS transport protocol.
979 *
980 */
981static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
982{
983 switch (mnt->nfs_server.protocol) {
984 case XPRT_TRANSPORT_UDP:
985 case XPRT_TRANSPORT_TCP:
986 case XPRT_TRANSPORT_RDMA:
987 break;
988 default:
989 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
990 }
991}
992
993/*
994 * For text based NFSv2/v3 mounts, the mount protocol transport default
995 * settings should depend upon the specified NFS transport.
996 */
997static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
998{
999 nfs_validate_transport_protocol(mnt);
1000
1001 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
1002 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
1003 return;
1004 switch (mnt->nfs_server.protocol) {
1005 case XPRT_TRANSPORT_UDP:
1006 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
1007 break;
1008 case XPRT_TRANSPORT_TCP:
1009 case XPRT_TRANSPORT_RDMA:
1010 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
1011 }
1012}
1013
1014/*
Chuck Lever01060c82008-06-24 16:33:38 -04001015 * Parse the value of the 'sec=' option.
Chuck Lever01060c82008-06-24 16:33:38 -04001016 */
1017static int nfs_parse_security_flavors(char *value,
1018 struct nfs_parsed_mount_data *mnt)
1019{
1020 substring_t args[MAX_OPT_ARGS];
1021
1022 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
1023
1024 switch (match_token(value, nfs_secflavor_tokens, args)) {
1025 case Opt_sec_none:
Chuck Lever01060c82008-06-24 16:33:38 -04001026 mnt->auth_flavors[0] = RPC_AUTH_NULL;
1027 break;
1028 case Opt_sec_sys:
Chuck Lever01060c82008-06-24 16:33:38 -04001029 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
1030 break;
1031 case Opt_sec_krb5:
Chuck Lever01060c82008-06-24 16:33:38 -04001032 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
1033 break;
1034 case Opt_sec_krb5i:
Chuck Lever01060c82008-06-24 16:33:38 -04001035 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
1036 break;
1037 case Opt_sec_krb5p:
Chuck Lever01060c82008-06-24 16:33:38 -04001038 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
1039 break;
1040 case Opt_sec_lkey:
Chuck Lever01060c82008-06-24 16:33:38 -04001041 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
1042 break;
1043 case Opt_sec_lkeyi:
Chuck Lever01060c82008-06-24 16:33:38 -04001044 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
1045 break;
1046 case Opt_sec_lkeyp:
Chuck Lever01060c82008-06-24 16:33:38 -04001047 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
1048 break;
1049 case Opt_sec_spkm:
Chuck Lever01060c82008-06-24 16:33:38 -04001050 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
1051 break;
1052 case Opt_sec_spkmi:
Chuck Lever01060c82008-06-24 16:33:38 -04001053 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
1054 break;
1055 case Opt_sec_spkmp:
Chuck Lever01060c82008-06-24 16:33:38 -04001056 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
1057 break;
1058 default:
1059 return 0;
1060 }
1061
Bryan Schumaker9b7160c2011-04-13 14:31:30 -04001062 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
Chuck Lever059f90b2009-08-09 15:09:31 -04001063 mnt->auth_flavor_len = 1;
Chuck Lever01060c82008-06-24 16:33:38 -04001064 return 1;
1065}
1066
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001067static int nfs_get_option_str(substring_t args[], char **option)
1068{
1069 kfree(*option);
1070 *option = match_strdup(args);
1071 return !option;
1072}
1073
1074static int nfs_get_option_ul(substring_t args[], unsigned long *option)
1075{
1076 int rc;
1077 char *string;
1078
1079 string = match_strdup(args);
1080 if (string == NULL)
1081 return -ENOMEM;
1082 rc = strict_strtoul(string, 10, option);
1083 kfree(string);
1084
1085 return rc;
1086}
1087
Chuck Lever01060c82008-06-24 16:33:38 -04001088/*
Chuck Leverbf0fd762007-07-01 12:13:44 -04001089 * Error-check and convert a string of mount options from user space into
Chuck Leverf45663c2008-06-24 19:28:02 -04001090 * a data structure. The whole mount string is processed; bad options are
1091 * skipped as they are encountered. If there were no errors, return 1;
1092 * otherwise return 0 (zero).
Chuck Leverbf0fd762007-07-01 12:13:44 -04001093 */
1094static int nfs_parse_mount_options(char *raw,
1095 struct nfs_parsed_mount_data *mnt)
1096{
Eric Parisf9c3a382008-03-05 14:20:18 -05001097 char *p, *string, *secdata;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001098 int rc, sloppy = 0, invalid_option = 0;
Jeff Laytonee671b02009-12-03 15:58:56 -05001099 unsigned short protofamily = AF_UNSPEC;
1100 unsigned short mountfamily = AF_UNSPEC;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001101
1102 if (!raw) {
1103 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
1104 return 1;
1105 }
1106 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
1107
Eric Parisf9c3a382008-03-05 14:20:18 -05001108 secdata = alloc_secdata();
1109 if (!secdata)
1110 goto out_nomem;
1111
1112 rc = security_sb_copy_data(raw, secdata);
1113 if (rc)
1114 goto out_security_failure;
1115
1116 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
1117 if (rc)
1118 goto out_security_failure;
1119
1120 free_secdata(secdata);
1121
Chuck Leverbf0fd762007-07-01 12:13:44 -04001122 while ((p = strsep(&raw, ",")) != NULL) {
1123 substring_t args[MAX_OPT_ARGS];
Chuck Levera5a16ba2009-06-17 18:02:14 -07001124 unsigned long option;
1125 int token;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001126
1127 if (!*p)
1128 continue;
1129
1130 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
1131
1132 token = match_token(p, nfs_mount_option_tokens, args);
1133 switch (token) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001134
1135 /*
1136 * boolean options: foo/nofoo
1137 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001138 case Opt_soft:
1139 mnt->flags |= NFS_MOUNT_SOFT;
1140 break;
1141 case Opt_hard:
1142 mnt->flags &= ~NFS_MOUNT_SOFT;
1143 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001144 case Opt_posix:
1145 mnt->flags |= NFS_MOUNT_POSIX;
1146 break;
1147 case Opt_noposix:
1148 mnt->flags &= ~NFS_MOUNT_POSIX;
1149 break;
1150 case Opt_cto:
1151 mnt->flags &= ~NFS_MOUNT_NOCTO;
1152 break;
1153 case Opt_nocto:
1154 mnt->flags |= NFS_MOUNT_NOCTO;
1155 break;
1156 case Opt_ac:
1157 mnt->flags &= ~NFS_MOUNT_NOAC;
1158 break;
1159 case Opt_noac:
1160 mnt->flags |= NFS_MOUNT_NOAC;
1161 break;
1162 case Opt_lock:
1163 mnt->flags &= ~NFS_MOUNT_NONLM;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001164 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1165 NFS_MOUNT_LOCAL_FCNTL);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001166 break;
1167 case Opt_nolock:
1168 mnt->flags |= NFS_MOUNT_NONLM;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001169 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1170 NFS_MOUNT_LOCAL_FCNTL);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001171 break;
1172 case Opt_v2:
1173 mnt->flags &= ~NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -04001174 mnt->version = 2;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001175 break;
1176 case Opt_v3:
1177 mnt->flags |= NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -04001178 mnt->version = 3;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001179 break;
Chuck Lever764302c2009-09-08 19:50:03 -04001180 case Opt_v4:
1181 mnt->flags &= ~NFS_MOUNT_VER3;
1182 mnt->version = 4;
1183 break;
Weston Andros Adamson7ced2862012-02-07 11:49:11 -05001184 case Opt_v4_0:
1185 mnt->flags &= ~NFS_MOUNT_VER3;
1186 mnt->version = 4;
1187 mnt->minorversion = 0;
1188 break;
1189 case Opt_v4_1:
1190 mnt->flags &= ~NFS_MOUNT_VER3;
1191 mnt->version = 4;
1192 mnt->minorversion = 1;
1193 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001194 case Opt_udp:
1195 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001196 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001197 break;
1198 case Opt_tcp:
1199 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001200 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001201 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001202 case Opt_rdma:
1203 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1204 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001205 xprt_load_transport(p);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001206 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001207 case Opt_acl:
1208 mnt->flags &= ~NFS_MOUNT_NOACL;
1209 break;
1210 case Opt_noacl:
1211 mnt->flags |= NFS_MOUNT_NOACL;
1212 break;
1213 case Opt_rdirplus:
1214 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1215 break;
1216 case Opt_nordirplus:
1217 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1218 break;
Trond Myklebust75180df2007-05-16 16:53:28 -04001219 case Opt_sharecache:
1220 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1221 break;
1222 case Opt_nosharecache:
1223 mnt->flags |= NFS_MOUNT_UNSHARED;
1224 break;
Chuck Leverd7403512008-12-23 15:21:37 -05001225 case Opt_resvport:
1226 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1227 break;
1228 case Opt_noresvport:
1229 mnt->flags |= NFS_MOUNT_NORESVPORT;
1230 break;
David Howellsb797cac2009-04-03 16:42:48 +01001231 case Opt_fscache:
1232 mnt->options |= NFS_OPTION_FSCACHE;
1233 kfree(mnt->fscache_uniq);
1234 mnt->fscache_uniq = NULL;
1235 break;
1236 case Opt_nofscache:
1237 mnt->options &= ~NFS_OPTION_FSCACHE;
1238 kfree(mnt->fscache_uniq);
1239 mnt->fscache_uniq = NULL;
1240 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001241
Chuck Leverf45663c2008-06-24 19:28:02 -04001242 /*
1243 * options that take numeric values
1244 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001245 case Opt_port:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001246 if (nfs_get_option_ul(args, &option) ||
1247 option > USHRT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001248 goto out_invalid_value;
1249 mnt->nfs_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001250 break;
1251 case Opt_rsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001252 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001253 goto out_invalid_value;
1254 mnt->rsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001255 break;
1256 case Opt_wsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001257 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001258 goto out_invalid_value;
1259 mnt->wsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001260 break;
1261 case Opt_bsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001262 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001263 goto out_invalid_value;
1264 mnt->bsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001265 break;
1266 case Opt_timeo:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001267 if (nfs_get_option_ul(args, &option) || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001268 goto out_invalid_value;
1269 mnt->timeo = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001270 break;
1271 case Opt_retrans:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001272 if (nfs_get_option_ul(args, &option) || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001273 goto out_invalid_value;
1274 mnt->retrans = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001275 break;
1276 case Opt_acregmin:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001277 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001278 goto out_invalid_value;
1279 mnt->acregmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001280 break;
1281 case Opt_acregmax:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001282 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001283 goto out_invalid_value;
1284 mnt->acregmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001285 break;
1286 case Opt_acdirmin:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001287 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001288 goto out_invalid_value;
1289 mnt->acdirmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001290 break;
1291 case Opt_acdirmax:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001292 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001293 goto out_invalid_value;
1294 mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001295 break;
1296 case Opt_actimeo:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001297 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001298 goto out_invalid_value;
1299 mnt->acregmin = mnt->acregmax =
1300 mnt->acdirmin = mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001301 break;
1302 case Opt_namelen:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001303 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001304 goto out_invalid_value;
1305 mnt->namlen = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001306 break;
1307 case Opt_mountport:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001308 if (nfs_get_option_ul(args, &option) ||
1309 option > USHRT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001310 goto out_invalid_value;
1311 mnt->mount_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001312 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001313 case Opt_mountvers:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001314 if (nfs_get_option_ul(args, &option) ||
Chuck Leverf45663c2008-06-24 19:28:02 -04001315 option < NFS_MNT_VERSION ||
Chuck Leverd23c45f2009-06-17 18:02:13 -07001316 option > NFS_MNT3_VERSION)
1317 goto out_invalid_value;
1318 mnt->mount_server.version = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001319 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001320 case Opt_nfsvers:
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;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001323 switch (option) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001324 case NFS2_VERSION:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001325 mnt->flags &= ~NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -04001326 mnt->version = 2;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001327 break;
Chuck Leverf45663c2008-06-24 19:28:02 -04001328 case NFS3_VERSION:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001329 mnt->flags |= NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -04001330 mnt->version = 3;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001331 break;
Chuck Lever764302c2009-09-08 19:50:03 -04001332 case NFS4_VERSION:
1333 mnt->flags &= ~NFS_MOUNT_VER3;
1334 mnt->version = 4;
1335 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001336 default:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001337 goto out_invalid_value;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001338 }
1339 break;
Mike Sager3fd5be92009-04-01 09:21:48 -04001340 case Opt_minorversion:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001341 if (nfs_get_option_ul(args, &option))
Chuck Leverf3f4f4e2009-08-09 15:09:29 -04001342 goto out_invalid_value;
1343 if (option > NFS4_MAX_MINOR_VERSION)
1344 goto out_invalid_value;
1345 mnt->minorversion = option;
Mike Sager3fd5be92009-04-01 09:21:48 -04001346 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001347
Chuck Leverf45663c2008-06-24 19:28:02 -04001348 /*
1349 * options that take text values
1350 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001351 case Opt_sec:
1352 string = match_strdup(args);
1353 if (string == NULL)
1354 goto out_nomem;
Chuck Lever01060c82008-06-24 16:33:38 -04001355 rc = nfs_parse_security_flavors(string, mnt);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001356 kfree(string);
Chuck Leverf45663c2008-06-24 19:28:02 -04001357 if (!rc) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001358 dfprintk(MOUNT, "NFS: unrecognized "
1359 "security flavor\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001360 return 0;
Chuck Leverf45663c2008-06-24 19:28:02 -04001361 }
Chuck Leverbf0fd762007-07-01 12:13:44 -04001362 break;
1363 case Opt_proto:
1364 string = match_strdup(args);
1365 if (string == NULL)
1366 goto out_nomem;
1367 token = match_token(string,
1368 nfs_xprt_protocol_tokens, args);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001369
Jeff Laytonee671b02009-12-03 15:58:56 -05001370 protofamily = AF_INET;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001371 switch (token) {
Jeff Laytonee671b02009-12-03 15:58:56 -05001372 case Opt_xprt_udp6:
1373 protofamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001374 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001375 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001376 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001377 break;
Jeff Laytonee671b02009-12-03 15:58:56 -05001378 case Opt_xprt_tcp6:
1379 protofamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001380 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001381 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001382 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001383 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001384 case Opt_xprt_rdma:
1385 /* vector side protocols to TCP */
1386 mnt->flags |= NFS_MOUNT_TCP;
1387 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001388 xprt_load_transport(string);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001389 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001390 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001391 dfprintk(MOUNT, "NFS: unrecognized "
1392 "transport protocol\n");
Yinghai Lu4223a4a2009-10-20 14:13:46 +09001393 kfree(string);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001394 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001395 }
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001396 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001397 break;
1398 case Opt_mountproto:
1399 string = match_strdup(args);
1400 if (string == NULL)
1401 goto out_nomem;
1402 token = match_token(string,
1403 nfs_xprt_protocol_tokens, args);
Trond Myklebustd508afb2009-04-06 16:41:35 -07001404 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001405
Jeff Laytonee671b02009-12-03 15:58:56 -05001406 mountfamily = AF_INET;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001407 switch (token) {
Jeff Laytonee671b02009-12-03 15:58:56 -05001408 case Opt_xprt_udp6:
1409 mountfamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001410 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001411 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001412 break;
Jeff Laytonee671b02009-12-03 15:58:56 -05001413 case Opt_xprt_tcp6:
1414 mountfamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001415 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001416 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001417 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001418 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001419 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001420 dfprintk(MOUNT, "NFS: unrecognized "
1421 "transport protocol\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001422 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001423 }
1424 break;
1425 case Opt_addr:
1426 string = match_strdup(args);
1427 if (string == NULL)
1428 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001429 mnt->nfs_server.addrlen =
Stanislav Kinsburskyb48e1272012-01-26 15:11:57 +04001430 rpc_pton(mnt->net, string, strlen(string),
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001431 (struct sockaddr *)
1432 &mnt->nfs_server.address,
1433 sizeof(mnt->nfs_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001434 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001435 if (mnt->nfs_server.addrlen == 0)
1436 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001437 break;
1438 case Opt_clientaddr:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001439 if (nfs_get_option_str(args, &mnt->client_address))
Chuck Leverbf0fd762007-07-01 12:13:44 -04001440 goto out_nomem;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001441 break;
Chuck Lever33832032007-12-10 14:59:13 -05001442 case Opt_mounthost:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001443 if (nfs_get_option_str(args,
1444 &mnt->mount_server.hostname))
Chuck Lever33832032007-12-10 14:59:13 -05001445 goto out_nomem;
Chuck Lever33832032007-12-10 14:59:13 -05001446 break;
Chuck Lever0ac83772007-09-11 18:01:04 -04001447 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001448 string = match_strdup(args);
1449 if (string == NULL)
1450 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001451 mnt->mount_server.addrlen =
Stanislav Kinsburskyb48e1272012-01-26 15:11:57 +04001452 rpc_pton(mnt->net, string, strlen(string),
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001453 (struct sockaddr *)
1454 &mnt->mount_server.address,
1455 sizeof(mnt->mount_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001456 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001457 if (mnt->mount_server.addrlen == 0)
1458 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001459 break;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001460 case Opt_lookupcache:
1461 string = match_strdup(args);
1462 if (string == NULL)
1463 goto out_nomem;
1464 token = match_token(string,
1465 nfs_lookupcache_tokens, args);
1466 kfree(string);
1467 switch (token) {
1468 case Opt_lookupcache_all:
1469 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1470 break;
1471 case Opt_lookupcache_positive:
1472 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1473 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1474 break;
1475 case Opt_lookupcache_none:
1476 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1477 break;
1478 default:
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001479 dfprintk(MOUNT, "NFS: invalid "
1480 "lookupcache argument\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001481 return 0;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001482 };
1483 break;
Chuck Levera6d5ff62010-05-07 13:33:58 -04001484 case Opt_fscache_uniq:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001485 if (nfs_get_option_str(args, &mnt->fscache_uniq))
Chuck Levera6d5ff62010-05-07 13:33:58 -04001486 goto out_nomem;
Chuck Levera6d5ff62010-05-07 13:33:58 -04001487 mnt->options |= NFS_OPTION_FSCACHE;
1488 break;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001489 case Opt_local_lock:
1490 string = match_strdup(args);
1491 if (string == NULL)
1492 goto out_nomem;
1493 token = match_token(string, nfs_local_lock_tokens,
1494 args);
1495 kfree(string);
1496 switch (token) {
1497 case Opt_local_lock_all:
1498 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1499 NFS_MOUNT_LOCAL_FCNTL);
1500 break;
1501 case Opt_local_lock_flock:
1502 mnt->flags |= NFS_MOUNT_LOCAL_FLOCK;
1503 break;
1504 case Opt_local_lock_posix:
1505 mnt->flags |= NFS_MOUNT_LOCAL_FCNTL;
1506 break;
1507 case Opt_local_lock_none:
1508 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1509 NFS_MOUNT_LOCAL_FCNTL);
1510 break;
1511 default:
1512 dfprintk(MOUNT, "NFS: invalid "
1513 "local_lock argument\n");
1514 return 0;
1515 };
1516 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001517
Chuck Leverf45663c2008-06-24 19:28:02 -04001518 /*
1519 * Special options
1520 */
1521 case Opt_sloppy:
1522 sloppy = 1;
1523 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1524 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001525 case Opt_userspace:
1526 case Opt_deprecated:
Chuck Leverd33e4df2008-06-12 12:37:41 -04001527 dfprintk(MOUNT, "NFS: ignoring mount option "
1528 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001529 break;
1530
1531 default:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001532 invalid_option = 1;
Chuck Leverf45663c2008-06-24 19:28:02 -04001533 dfprintk(MOUNT, "NFS: unrecognized mount option "
1534 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001535 }
1536 }
1537
Chuck Leverd23c45f2009-06-17 18:02:13 -07001538 if (!sloppy && invalid_option)
1539 return 0;
1540
Weston Andros Adamson571b7552012-02-01 14:06:41 -05001541 if (mnt->minorversion && mnt->version != 4)
1542 goto out_minorversion_mismatch;
1543
Jeff Laytonee671b02009-12-03 15:58:56 -05001544 /*
1545 * verify that any proto=/mountproto= options match the address
1546 * familiies in the addr=/mountaddr= options.
1547 */
1548 if (protofamily != AF_UNSPEC &&
1549 protofamily != mnt->nfs_server.address.ss_family)
1550 goto out_proto_mismatch;
1551
1552 if (mountfamily != AF_UNSPEC) {
1553 if (mnt->mount_server.addrlen) {
1554 if (mountfamily != mnt->mount_server.address.ss_family)
1555 goto out_mountproto_mismatch;
1556 } else {
1557 if (mountfamily != mnt->nfs_server.address.ss_family)
1558 goto out_mountproto_mismatch;
1559 }
1560 }
1561
Chuck Leverbf0fd762007-07-01 12:13:44 -04001562 return 1;
1563
Jeff Laytonee671b02009-12-03 15:58:56 -05001564out_mountproto_mismatch:
1565 printk(KERN_INFO "NFS: mount server address does not match mountproto= "
1566 "option\n");
1567 return 0;
1568out_proto_mismatch:
1569 printk(KERN_INFO "NFS: server address does not match proto= option\n");
1570 return 0;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001571out_invalid_address:
1572 printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
1573 return 0;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001574out_invalid_value:
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001575 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001576 return 0;
Weston Andros Adamson571b7552012-02-01 14:06:41 -05001577out_minorversion_mismatch:
1578 printk(KERN_INFO "NFS: mount option vers=%u does not support "
1579 "minorversion=%u\n", mnt->version, mnt->minorversion);
1580 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001581out_nomem:
1582 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1583 return 0;
Eric Parisf9c3a382008-03-05 14:20:18 -05001584out_security_failure:
1585 free_secdata(secdata);
1586 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1587 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001588}
1589
1590/*
Chuck Leverec88f282009-08-09 15:09:32 -04001591 * Match the requested auth flavors with the list returned by
1592 * the server. Returns zero and sets the mount's authentication
1593 * flavor on success; returns -EACCES if server does not support
1594 * the requested flavor.
1595 */
1596static int nfs_walk_authlist(struct nfs_parsed_mount_data *args,
1597 struct nfs_mount_request *request)
1598{
1599 unsigned int i, j, server_authlist_len = *(request->auth_flav_len);
1600
1601 /*
Chuck Lever5eecfde2009-08-21 17:50:30 -04001602 * Certain releases of Linux's mountd return an empty
1603 * flavor list. To prevent behavioral regression with
1604 * these servers (ie. rejecting mounts that used to
1605 * succeed), revert to pre-2.6.32 behavior (no checking)
1606 * if the returned flavor list is empty.
1607 */
1608 if (server_authlist_len == 0)
1609 return 0;
1610
1611 /*
Chuck Leverec88f282009-08-09 15:09:32 -04001612 * We avoid sophisticated negotiating here, as there are
1613 * plenty of cases where we can get it wrong, providing
1614 * either too little or too much security.
1615 *
1616 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1617 * flavor listed first. However, some servers list
1618 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1619 * preferred default, in args->auth_flavors[0] if user
1620 * didn't specify sec= mount option.
1621 */
1622 for (i = 0; i < args->auth_flavor_len; i++)
1623 for (j = 0; j < server_authlist_len; j++)
1624 if (args->auth_flavors[i] == request->auth_flavs[j]) {
1625 dfprintk(MOUNT, "NFS: using auth flavor %d\n",
1626 request->auth_flavs[j]);
1627 args->auth_flavors[0] = request->auth_flavs[j];
1628 return 0;
1629 }
1630
1631 dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n");
1632 nfs_umount(request);
1633 return -EACCES;
1634}
1635
1636/*
Chuck Lever0076d7b2007-07-01 12:13:49 -04001637 * Use the remote server's MOUNT service to request the NFS file handle
1638 * corresponding to the provided path.
1639 */
1640static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1641 struct nfs_fh *root_fh)
1642{
Chuck Leverec88f282009-08-09 15:09:32 -04001643 rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS];
1644 unsigned int server_authlist_len = ARRAY_SIZE(server_authlist);
Chuck Leverc5d120f2008-12-23 15:21:35 -05001645 struct nfs_mount_request request = {
1646 .sap = (struct sockaddr *)
1647 &args->mount_server.address,
1648 .dirpath = args->nfs_server.export_path,
1649 .protocol = args->mount_server.protocol,
1650 .fh = root_fh,
Chuck Lever50a737f2008-12-23 15:21:37 -05001651 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
Chuck Leverec88f282009-08-09 15:09:32 -04001652 .auth_flav_len = &server_authlist_len,
1653 .auth_flavs = server_authlist,
Stanislav Kinsbursky6d59b8d2012-01-10 16:12:54 +04001654 .net = args->net,
Chuck Leverc5d120f2008-12-23 15:21:35 -05001655 };
Chuck Lever4c568012007-12-10 14:59:28 -05001656 int status;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001657
1658 if (args->mount_server.version == 0) {
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001659 switch (args->version) {
1660 default:
1661 args->mount_server.version = NFS_MNT3_VERSION;
1662 break;
1663 case 2:
1664 args->mount_server.version = NFS_MNT_VERSION;
1665 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001666 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001667 request.version = args->mount_server.version;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001668
Chuck Lever33832032007-12-10 14:59:13 -05001669 if (args->mount_server.hostname)
Chuck Leverc5d120f2008-12-23 15:21:35 -05001670 request.hostname = args->mount_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001671 else
Chuck Leverc5d120f2008-12-23 15:21:35 -05001672 request.hostname = args->nfs_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001673
Chuck Lever0076d7b2007-07-01 12:13:49 -04001674 /*
1675 * Construct the mount server's address.
1676 */
Chuck Lever4c568012007-12-10 14:59:28 -05001677 if (args->mount_server.address.ss_family == AF_UNSPEC) {
Chuck Leverc5d120f2008-12-23 15:21:35 -05001678 memcpy(request.sap, &args->nfs_server.address,
Chuck Lever4c568012007-12-10 14:59:28 -05001679 args->nfs_server.addrlen);
1680 args->mount_server.addrlen = args->nfs_server.addrlen;
1681 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001682 request.salen = args->mount_server.addrlen;
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001683 nfs_set_port(request.sap, &args->mount_server.port, 0);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001684
1685 /*
1686 * Now ask the mount server to map our export path
1687 * to a file handle.
1688 */
Chuck Leverc5d120f2008-12-23 15:21:35 -05001689 status = nfs_mount(&request);
Chuck Leverec88f282009-08-09 15:09:32 -04001690 if (status != 0) {
1691 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1692 request.hostname, status);
1693 return status;
1694 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001695
Chuck Leverec88f282009-08-09 15:09:32 -04001696 /*
1697 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1698 */
1699 if (args->mount_server.version != NFS_MNT3_VERSION)
1700 return 0;
1701 return nfs_walk_authlist(args, &request);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001702}
1703
Rob Landleyc12bace2011-03-09 15:54:13 -06001704/*
1705 * Split "dev_name" into "hostname:export_path".
1706 *
1707 * The leftmost colon demarks the split between the server's hostname
1708 * and the export path. If the hostname starts with a left square
1709 * bracket, then it may contain colons.
1710 *
1711 * Note: caller frees hostname and export path, even on error.
1712 */
1713static int nfs_parse_devname(const char *dev_name,
1714 char **hostname, size_t maxnamlen,
1715 char **export_path, size_t maxpathlen)
Chuck Leverdc045892008-06-23 12:36:37 -04001716{
1717 size_t len;
Rob Landleyc12bace2011-03-09 15:54:13 -06001718 char *end;
Chuck Leverdc045892008-06-23 12:36:37 -04001719
Rob Landleyc12bace2011-03-09 15:54:13 -06001720 /* Is the host name protected with square brakcets? */
1721 if (*dev_name == '[') {
1722 end = strchr(++dev_name, ']');
1723 if (end == NULL || end[1] != ':')
1724 goto out_bad_devname;
Chuck Leverdc045892008-06-23 12:36:37 -04001725
Rob Landleyc12bace2011-03-09 15:54:13 -06001726 len = end - dev_name;
1727 end++;
1728 } else {
1729 char *comma;
1730
1731 end = strchr(dev_name, ':');
1732 if (end == NULL)
1733 goto out_bad_devname;
1734 len = end - dev_name;
1735
1736 /* kill possible hostname list: not supported */
1737 comma = strchr(dev_name, ',');
1738 if (comma != NULL && comma < end)
1739 *comma = 0;
1740 }
1741
Chuck Leverdc045892008-06-23 12:36:37 -04001742 if (len > maxnamlen)
1743 goto out_hostname;
1744
1745 /* N.B. caller will free nfs_server.hostname in all cases */
1746 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
Rob Landleyc12bace2011-03-09 15:54:13 -06001747 if (*hostname == NULL)
Chuck Leverdc045892008-06-23 12:36:37 -04001748 goto out_nomem;
Rob Landleyc12bace2011-03-09 15:54:13 -06001749 len = strlen(++end);
Chuck Leverdc045892008-06-23 12:36:37 -04001750 if (len > maxpathlen)
1751 goto out_path;
Rob Landleyc12bace2011-03-09 15:54:13 -06001752 *export_path = kstrndup(end, len, GFP_KERNEL);
Chuck Leverdc045892008-06-23 12:36:37 -04001753 if (!*export_path)
1754 goto out_nomem;
1755
1756 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1757 return 0;
1758
1759out_bad_devname:
1760 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1761 return -EINVAL;
1762
1763out_nomem:
1764 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1765 return -ENOMEM;
1766
1767out_hostname:
1768 dfprintk(MOUNT, "NFS: server hostname too long\n");
1769 return -ENAMETOOLONG;
1770
1771out_path:
1772 dfprintk(MOUNT, "NFS: export pathname too long\n");
1773 return -ENAMETOOLONG;
1774}
1775
1776/*
David Howells54ceac42006-08-22 20:06:13 -04001777 * Validate the NFS2/NFS3 mount data
1778 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001779 *
1780 * For option strings, user space handles the following behaviors:
1781 *
1782 * + DNS: mapping server host name to IP address ("addr=" option)
1783 *
1784 * + failure mode: how to behave if a mount request can't be handled
1785 * immediately ("fg/bg" option)
1786 *
1787 * + retry: how often to retry a mount request ("retry=" option)
1788 *
1789 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1790 * mountproto=tcp after mountproto=udp, and so on
David Howellsf7b422b2006-06-09 09:34:33 -04001791 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001792static int nfs_validate_mount_data(void *options,
1793 struct nfs_parsed_mount_data *args,
Chuck Lever136d5582007-07-01 12:13:54 -04001794 struct nfs_fh *mntfh,
1795 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001796{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001797 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001798 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
Chuck Lever136d5582007-07-01 12:13:54 -04001799
Chuck Lever5df36e72007-07-01 12:12:56 -04001800 if (data == NULL)
1801 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001802
David Howellsf7b422b2006-06-09 09:34:33 -04001803 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001804 case 1:
1805 data->namlen = 0;
1806 case 2:
1807 data->bsize = 0;
1808 case 3:
1809 if (data->flags & NFS_MOUNT_VER3)
1810 goto out_no_v3;
1811 data->root.size = NFS2_FHSIZE;
1812 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1813 case 4:
1814 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1815 goto out_no_sec;
1816 case 5:
1817 memset(data->context, 0, sizeof(data->context));
1818 case 6:
Trond Myklebustb7e24452008-06-19 15:21:11 -04001819 if (data->flags & NFS_MOUNT_VER3) {
1820 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1821 goto out_invalid_fh;
Chuck Lever5df36e72007-07-01 12:12:56 -04001822 mntfh->size = data->root.size;
Chuck Lever764302c2009-09-08 19:50:03 -04001823 args->version = 3;
1824 } else {
Chuck Lever5df36e72007-07-01 12:12:56 -04001825 mntfh->size = NFS2_FHSIZE;
Chuck Lever764302c2009-09-08 19:50:03 -04001826 args->version = 2;
1827 }
Chuck Lever5df36e72007-07-01 12:12:56 -04001828
Chuck Lever5df36e72007-07-01 12:12:56 -04001829
1830 memcpy(mntfh->data, data->root.data, mntfh->size);
1831 if (mntfh->size < sizeof(mntfh->data))
1832 memset(mntfh->data + mntfh->size, 0,
1833 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001834
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001835 /*
1836 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1837 * can deal with.
1838 */
Trond Myklebustff3525a2008-08-15 16:59:14 -04001839 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
Bryan Schumakerd5eff1a2010-08-03 13:04:00 -04001840 args->flags |= NFS_MOUNT_LEGACY_INTERFACE;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001841 args->rsize = data->rsize;
1842 args->wsize = data->wsize;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001843 args->timeo = data->timeo;
1844 args->retrans = data->retrans;
1845 args->acregmin = data->acregmin;
1846 args->acregmax = data->acregmax;
1847 args->acdirmin = data->acdirmin;
1848 args->acdirmax = data->acdirmax;
Chuck Lever4c568012007-12-10 14:59:28 -05001849
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001850 memcpy(sap, &data->addr, sizeof(data->addr));
Chuck Lever4c568012007-12-10 14:59:28 -05001851 args->nfs_server.addrlen = sizeof(data->addr);
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001852 if (!nfs_verify_server_address(sap))
Chuck Lever4c568012007-12-10 14:59:28 -05001853 goto out_no_address;
1854
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001855 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001856 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001857 /* N.B. caller will free nfs_server.hostname in all cases */
1858 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1859 args->namlen = data->namlen;
1860 args->bsize = data->bsize;
Chuck Leverdd07c942008-06-24 16:33:46 -04001861
1862 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1863 args->auth_flavors[0] = data->pseudoflavor;
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001864 if (!args->nfs_server.hostname)
1865 goto out_nomem;
Eric Parisf9c3a382008-03-05 14:20:18 -05001866
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001867 if (!(data->flags & NFS_MOUNT_NONLM))
1868 args->flags &= ~(NFS_MOUNT_LOCAL_FLOCK|
1869 NFS_MOUNT_LOCAL_FCNTL);
1870 else
1871 args->flags |= (NFS_MOUNT_LOCAL_FLOCK|
1872 NFS_MOUNT_LOCAL_FCNTL);
Eric Parisf9c3a382008-03-05 14:20:18 -05001873 /*
1874 * The legacy version 6 binary mount data from userspace has a
1875 * field used only to transport selinux information into the
1876 * the kernel. To continue to support that functionality we
1877 * have a touch of selinux knowledge here in the NFS code. The
1878 * userspace code converted context=blah to just blah so we are
1879 * converting back to the full string selinux understands.
1880 */
1881 if (data->context[0]){
1882#ifdef CONFIG_SECURITY_SELINUX
1883 int rc;
1884 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1885 if (!opts_str)
1886 return -ENOMEM;
1887 strcpy(opts_str, "context=");
1888 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1889 strcat(opts_str, &data->context[0]);
1890 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1891 kfree(opts_str);
1892 if (rc)
1893 return rc;
1894#else
1895 return -EINVAL;
1896#endif
1897 }
1898
Chuck Lever5df36e72007-07-01 12:12:56 -04001899 break;
Chuck Lever136d5582007-07-01 12:13:54 -04001900 default: {
Chuck Lever136d5582007-07-01 12:13:54 -04001901 int status;
Chuck Lever136d5582007-07-01 12:13:54 -04001902
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001903 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever136d5582007-07-01 12:13:54 -04001904 return -EINVAL;
1905
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001906 if (!nfs_verify_server_address(sap))
Chuck Lever6e88e062007-09-24 15:39:50 -04001907 goto out_no_address;
1908
Chuck Lever764302c2009-09-08 19:50:03 -04001909 if (args->version == 4)
1910#ifdef CONFIG_NFS_V4
1911 return nfs4_validate_text_mount_data(options,
1912 args, dev_name);
1913#else
1914 goto out_v4_not_compiled;
1915#endif
1916
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001917 nfs_set_port(sap, &args->nfs_server.port, 0);
Chuck Levered596a82008-06-26 17:47:05 -04001918
Trond Myklebust259875e2008-07-02 14:43:47 -04001919 nfs_set_mount_transport_protocol(args);
1920
Chuck Leverdc045892008-06-23 12:36:37 -04001921 status = nfs_parse_devname(dev_name,
1922 &args->nfs_server.hostname,
1923 PAGE_SIZE,
1924 &args->nfs_server.export_path,
1925 NFS_MAXPATHLEN);
1926 if (!status)
1927 status = nfs_try_mount(args, mntfh);
Chuck Lever136d5582007-07-01 12:13:54 -04001928
Chuck Leverdc045892008-06-23 12:36:37 -04001929 kfree(args->nfs_server.export_path);
1930 args->nfs_server.export_path = NULL;
Chuck Lever136d5582007-07-01 12:13:54 -04001931
Chuck Lever136d5582007-07-01 12:13:54 -04001932 if (status)
Chuck Leverfdc6e2c2007-08-29 17:58:59 -04001933 return status;
Chuck Lever136d5582007-07-01 12:13:54 -04001934
Chuck Lever136d5582007-07-01 12:13:54 -04001935 break;
1936 }
David Howellsf7b422b2006-06-09 09:34:33 -04001937 }
David Howells54ceac42006-08-22 20:06:13 -04001938
David Howellsf7b422b2006-06-09 09:34:33 -04001939#ifndef CONFIG_NFS_V3
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001940 if (args->version == 3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001941 goto out_v3_not_compiled;
1942#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001943
David Howells54ceac42006-08-22 20:06:13 -04001944 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001945
1946out_no_data:
1947 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1948 return -EINVAL;
1949
1950out_no_v3:
1951 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1952 data->version);
1953 return -EINVAL;
1954
1955out_no_sec:
1956 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1957 return -EINVAL;
1958
Chuck Lever5df36e72007-07-01 12:12:56 -04001959#ifndef CONFIG_NFS_V3
1960out_v3_not_compiled:
1961 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1962 return -EPROTONOSUPPORT;
1963#endif /* !CONFIG_NFS_V3 */
1964
Chuck Lever764302c2009-09-08 19:50:03 -04001965#ifndef CONFIG_NFS_V4
1966out_v4_not_compiled:
1967 dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n");
1968 return -EPROTONOSUPPORT;
1969#endif /* !CONFIG_NFS_V4 */
1970
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001971out_nomem:
1972 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
1973 return -ENOMEM;
1974
Chuck Lever5df36e72007-07-01 12:12:56 -04001975out_no_address:
1976 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1977 return -EINVAL;
1978
1979out_invalid_fh:
1980 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1981 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04001982}
1983
Jeff Layton48b605f2008-06-10 15:38:39 -04001984static int
1985nfs_compare_remount_data(struct nfs_server *nfss,
1986 struct nfs_parsed_mount_data *data)
1987{
1988 if (data->flags != nfss->flags ||
1989 data->rsize != nfss->rsize ||
1990 data->wsize != nfss->wsize ||
1991 data->retrans != nfss->client->cl_timeout->to_retries ||
1992 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
1993 data->acregmin != nfss->acregmin / HZ ||
1994 data->acregmax != nfss->acregmax / HZ ||
1995 data->acdirmin != nfss->acdirmin / HZ ||
1996 data->acdirmax != nfss->acdirmax / HZ ||
1997 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
Trond Myklebustbcd2ea12009-10-06 15:41:22 -04001998 data->nfs_server.port != nfss->port ||
Jeff Layton48b605f2008-06-10 15:38:39 -04001999 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
Stefan Richtera1be9ee2009-10-12 11:26:12 -04002000 !rpc_cmp_addr((struct sockaddr *)&data->nfs_server.address,
2001 (struct sockaddr *)&nfss->nfs_client->cl_addr))
Jeff Layton48b605f2008-06-10 15:38:39 -04002002 return -EINVAL;
2003
2004 return 0;
2005}
2006
2007static int
2008nfs_remount(struct super_block *sb, int *flags, char *raw_data)
2009{
2010 int error;
2011 struct nfs_server *nfss = sb->s_fs_info;
2012 struct nfs_parsed_mount_data *data;
2013 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
2014 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
Trond Myklebustcd100722008-06-17 16:12:00 -04002015 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
Jeff Layton48b605f2008-06-10 15:38:39 -04002016
2017 /*
2018 * Userspace mount programs that send binary options generally send
2019 * them populated with default values. We have no way to know which
2020 * ones were explicitly specified. Fall back to legacy behavior and
2021 * just return success.
2022 */
Marc Zyngier31c94462008-07-17 13:21:55 +02002023 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
2024 (nfsvers <= 3 && (!options || (options->version >= 1 &&
2025 options->version <= 6))))
Jeff Layton48b605f2008-06-10 15:38:39 -04002026 return 0;
2027
2028 data = kzalloc(sizeof(*data), GFP_KERNEL);
2029 if (data == NULL)
2030 return -ENOMEM;
2031
2032 /* fill out struct with values from existing mount */
2033 data->flags = nfss->flags;
2034 data->rsize = nfss->rsize;
2035 data->wsize = nfss->wsize;
2036 data->retrans = nfss->client->cl_timeout->to_retries;
2037 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
2038 data->acregmin = nfss->acregmin / HZ;
2039 data->acregmax = nfss->acregmax / HZ;
2040 data->acdirmin = nfss->acdirmin / HZ;
2041 data->acdirmax = nfss->acdirmax / HZ;
2042 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
Trond Myklebustbcd2ea12009-10-06 15:41:22 -04002043 data->nfs_server.port = nfss->port;
Jeff Layton48b605f2008-06-10 15:38:39 -04002044 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
2045 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
2046 data->nfs_server.addrlen);
2047
2048 /* overwrite those values with any that were specified */
2049 error = nfs_parse_mount_options((char *)options, data);
2050 if (error < 0)
2051 goto out;
2052
Jeff Layton26c4c172011-04-27 11:49:09 -04002053 /*
2054 * noac is a special case. It implies -o sync, but that's not
2055 * necessarily reflected in the mtab options. do_remount_sb
2056 * will clear MS_SYNCHRONOUS if -o sync wasn't specified in the
2057 * remount options, so we have to explicitly reset it.
2058 */
2059 if (data->flags & NFS_MOUNT_NOAC)
2060 *flags |= MS_SYNCHRONOUS;
2061
Jeff Layton48b605f2008-06-10 15:38:39 -04002062 /* compare new mount options with old ones */
2063 error = nfs_compare_remount_data(nfss, data);
2064out:
2065 kfree(data);
2066 return error;
2067}
2068
David Howells54ceac42006-08-22 20:06:13 -04002069/*
2070 * Initialise the common bits of the superblock
2071 */
2072static inline void nfs_initialise_sb(struct super_block *sb)
2073{
2074 struct nfs_server *server = NFS_SB(sb);
2075
2076 sb->s_magic = NFS_SUPER_MAGIC;
2077
2078 /* We probably want something more informative here */
2079 snprintf(sb->s_id, sizeof(sb->s_id),
2080 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
2081
2082 if (sb->s_blocksize == 0)
2083 sb->s_blocksize = nfs_block_bits(server->wsize,
2084 &sb->s_blocksize_bits);
2085
Jens Axboe32a88aa2009-09-16 15:02:33 +02002086 sb->s_bdi = &server->backing_dev_info;
2087
David Howells54ceac42006-08-22 20:06:13 -04002088 nfs_super_set_maxbytes(sb, server->maxfilesize);
2089}
2090
2091/*
2092 * Finish setting up an NFS2/3 superblock
2093 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04002094static void nfs_fill_super(struct super_block *sb,
2095 struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -04002096{
2097 struct nfs_server *server = NFS_SB(sb);
2098
2099 sb->s_blocksize_bits = 0;
2100 sb->s_blocksize = 0;
2101 if (data->bsize)
2102 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
2103
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04002104 if (server->nfs_client->rpc_ops->version == 3) {
David Howells54ceac42006-08-22 20:06:13 -04002105 /* The VFS shouldn't apply the umask to mode bits. We will do
2106 * so ourselves when necessary.
2107 */
2108 sb->s_flags |= MS_POSIXACL;
2109 sb->s_time_gran = 1;
2110 }
2111
2112 sb->s_op = &nfs_sops;
2113 nfs_initialise_sb(sb);
2114}
2115
2116/*
2117 * Finish setting up a cloned NFS2/3 superblock
2118 */
2119static void nfs_clone_super(struct super_block *sb,
2120 const struct super_block *old_sb)
2121{
2122 struct nfs_server *server = NFS_SB(sb);
2123
2124 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2125 sb->s_blocksize = old_sb->s_blocksize;
2126 sb->s_maxbytes = old_sb->s_maxbytes;
2127
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04002128 if (server->nfs_client->rpc_ops->version == 3) {
David Howells54ceac42006-08-22 20:06:13 -04002129 /* The VFS shouldn't apply the umask to mode bits. We will do
2130 * so ourselves when necessary.
2131 */
2132 sb->s_flags |= MS_POSIXACL;
2133 sb->s_time_gran = 1;
2134 }
2135
2136 sb->s_op = old_sb->s_op;
2137 nfs_initialise_sb(sb);
2138}
2139
Trond Myklebust275a5d22007-05-16 16:53:28 -04002140static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
2141{
2142 const struct nfs_server *a = s->s_fs_info;
2143 const struct rpc_clnt *clnt_a = a->client;
2144 const struct rpc_clnt *clnt_b = b->client;
2145
2146 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
2147 goto Ebusy;
2148 if (a->nfs_client != b->nfs_client)
2149 goto Ebusy;
2150 if (a->flags != b->flags)
2151 goto Ebusy;
2152 if (a->wsize != b->wsize)
2153 goto Ebusy;
2154 if (a->rsize != b->rsize)
2155 goto Ebusy;
2156 if (a->acregmin != b->acregmin)
2157 goto Ebusy;
2158 if (a->acregmax != b->acregmax)
2159 goto Ebusy;
2160 if (a->acdirmin != b->acdirmin)
2161 goto Ebusy;
2162 if (a->acdirmax != b->acdirmax)
2163 goto Ebusy;
2164 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
2165 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002166 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04002167Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002168 return 0;
2169}
2170
2171struct nfs_sb_mountdata {
2172 struct nfs_server *server;
2173 int mntflags;
2174};
2175
2176static int nfs_set_super(struct super_block *s, void *data)
2177{
2178 struct nfs_sb_mountdata *sb_mntdata = data;
2179 struct nfs_server *server = sb_mntdata->server;
2180 int ret;
2181
2182 s->s_flags = sb_mntdata->mntflags;
2183 s->s_fs_info = server;
Al Viro8b244ff2010-12-18 11:29:39 -05002184 s->s_d_op = server->nfs_client->rpc_ops->dentry_ops;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002185 ret = set_anon_super(s, server);
2186 if (ret == 0)
2187 server->s_dev = s->s_dev;
2188 return ret;
2189}
2190
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002191static int nfs_compare_super_address(struct nfs_server *server1,
2192 struct nfs_server *server2)
2193{
2194 struct sockaddr *sap1, *sap2;
2195
2196 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
2197 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
2198
2199 if (sap1->sa_family != sap2->sa_family)
2200 return 0;
2201
2202 switch (sap1->sa_family) {
2203 case AF_INET: {
2204 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
2205 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
2206 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
2207 return 0;
2208 if (sin1->sin_port != sin2->sin_port)
2209 return 0;
2210 break;
2211 }
2212 case AF_INET6: {
2213 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
2214 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
2215 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
2216 return 0;
2217 if (sin1->sin6_port != sin2->sin6_port)
2218 return 0;
2219 break;
2220 }
2221 default:
2222 return 0;
2223 }
2224
2225 return 1;
2226}
2227
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002228static int nfs_compare_super(struct super_block *sb, void *data)
2229{
2230 struct nfs_sb_mountdata *sb_mntdata = data;
2231 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2232 int mntflags = sb_mntdata->mntflags;
2233
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002234 if (!nfs_compare_super_address(old, server))
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002235 return 0;
2236 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2237 if (old->flags & NFS_MOUNT_UNSHARED)
2238 return 0;
2239 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2240 return 0;
2241 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04002242}
2243
Miklos Szeredifa799752008-04-30 00:54:33 -07002244static int nfs_bdi_register(struct nfs_server *server)
2245{
2246 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
2247}
2248
Al Viro01194982011-03-16 07:25:36 -04002249static struct dentry *nfs_fs_mount(struct file_system_type *fs_type,
2250 int flags, const char *dev_name, void *raw_data)
David Howells54ceac42006-08-22 20:06:13 -04002251{
2252 struct nfs_server *server = NULL;
2253 struct super_block *s;
Trond Myklebust33852a12008-06-19 14:20:11 -04002254 struct nfs_parsed_mount_data *data;
2255 struct nfs_fh *mntfh;
Al Viro01194982011-03-16 07:25:36 -04002256 struct dentry *mntroot = ERR_PTR(-ENOMEM);
Trond Myklebust75180df2007-05-16 16:53:28 -04002257 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002258 struct nfs_sb_mountdata sb_mntdata = {
2259 .mntflags = flags,
2260 };
Al Viro01194982011-03-16 07:25:36 -04002261 int error;
David Howells54ceac42006-08-22 20:06:13 -04002262
Paulius Zaleckas1e657bd2010-10-31 18:21:05 +02002263 data = nfs_alloc_parsed_mount_data(NFS_DEFAULT_VERSION);
Trond Myklebustb157b062010-04-19 19:05:48 -04002264 mntfh = nfs_alloc_fhandle();
Trond Myklebust33852a12008-06-19 14:20:11 -04002265 if (data == NULL || mntfh == NULL)
Jeff Layton8a0d5512011-12-20 06:57:45 -05002266 goto out;
Eric Parisf9c3a382008-03-05 14:20:18 -05002267
David Howells54ceac42006-08-22 20:06:13 -04002268 /* Validate the mount data */
Trond Myklebust33852a12008-06-19 14:20:11 -04002269 error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
Al Viro01194982011-03-16 07:25:36 -04002270 if (error < 0) {
2271 mntroot = ERR_PTR(error);
Chuck Lever06559602007-07-01 12:12:35 -04002272 goto out;
Al Viro01194982011-03-16 07:25:36 -04002273 }
David Howells54ceac42006-08-22 20:06:13 -04002274
Chuck Lever764302c2009-09-08 19:50:03 -04002275#ifdef CONFIG_NFS_V4
2276 if (data->version == 4) {
Al Viro01194982011-03-16 07:25:36 -04002277 mntroot = nfs4_try_mount(flags, dev_name, data);
Chuck Lever764302c2009-09-08 19:50:03 -04002278 goto out;
2279 }
2280#endif /* CONFIG_NFS_V4 */
2281
David Howells54ceac42006-08-22 20:06:13 -04002282 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002283 server = nfs_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002284 if (IS_ERR(server)) {
Al Viro01194982011-03-16 07:25:36 -04002285 mntroot = ERR_CAST(server);
Chuck Lever06559602007-07-01 12:12:35 -04002286 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002287 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002288 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002289
Trond Myklebust75180df2007-05-16 16:53:28 -04002290 if (server->flags & NFS_MOUNT_UNSHARED)
2291 compare_super = NULL;
2292
Sachin Prabhufb2088c2011-08-01 12:10:12 +01002293 /* -o noac implies -o sync */
2294 if (server->flags & NFS_MOUNT_NOAC)
2295 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2296
David Howells54ceac42006-08-22 20:06:13 -04002297 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002298 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002299 if (IS_ERR(s)) {
Al Viro01194982011-03-16 07:25:36 -04002300 mntroot = ERR_CAST(s);
David Howells54ceac42006-08-22 20:06:13 -04002301 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04002302 }
2303
David Howells54ceac42006-08-22 20:06:13 -04002304 if (s->s_fs_info != server) {
2305 nfs_free_server(server);
2306 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002307 } else {
2308 error = nfs_bdi_register(server);
Al Viro01194982011-03-16 07:25:36 -04002309 if (error) {
2310 mntroot = ERR_PTR(error);
NeilBrowncfbc0682010-03-11 11:20:17 +11002311 goto error_splat_bdi;
Al Viro01194982011-03-16 07:25:36 -04002312 }
David Howellsf7b422b2006-06-09 09:34:33 -04002313 }
David Howells54ceac42006-08-22 20:06:13 -04002314
2315 if (!s->s_root) {
2316 /* initial superblock/root creation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002317 nfs_fill_super(s, data);
Jesper Juhl160bc162011-04-10 17:57:07 +02002318 nfs_fscache_get_super_cookie(s, data->fscache_uniq, NULL);
David Howells54ceac42006-08-22 20:06:13 -04002319 }
2320
Al Viro0d5839a2011-03-16 05:27:27 -04002321 mntroot = nfs_get_root(s, mntfh, dev_name);
Al Viro01194982011-03-16 07:25:36 -04002322 if (IS_ERR(mntroot))
David Howells54ceac42006-08-22 20:06:13 -04002323 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002324
Trond Myklebust33852a12008-06-19 14:20:11 -04002325 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002326 if (error)
2327 goto error_splat_root;
2328
David Howellsf7b422b2006-06-09 09:34:33 -04002329 s->s_flags |= MS_ACTIVE;
Chuck Lever06559602007-07-01 12:12:35 -04002330
2331out:
Jeff Layton8a0d5512011-12-20 06:57:45 -05002332 nfs_free_parsed_mount_data(data);
Trond Myklebustb157b062010-04-19 19:05:48 -04002333 nfs_free_fhandle(mntfh);
Al Viro01194982011-03-16 07:25:36 -04002334 return mntroot;
Trond Myklebust816724e2006-06-24 08:41:41 -04002335
David Howells54ceac42006-08-22 20:06:13 -04002336out_err_nosb:
2337 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04002338 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002339
Eric Parisf9c3a382008-03-05 14:20:18 -05002340error_splat_root:
2341 dput(mntroot);
Al Viro01194982011-03-16 07:25:36 -04002342 mntroot = ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04002343error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002344 if (server && !s->s_root)
2345 bdi_unregister(&server->backing_dev_info);
2346error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002347 deactivate_locked_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04002348 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002349}
2350
David Howells54ceac42006-08-22 20:06:13 -04002351/*
Trond Myklebust387c1492010-02-03 08:27:35 -05002352 * Ensure that we unregister the bdi before kill_anon_super
2353 * releases the device name
2354 */
2355static void nfs_put_super(struct super_block *s)
2356{
2357 struct nfs_server *server = NFS_SB(s);
2358
2359 bdi_unregister(&server->backing_dev_info);
2360}
2361
2362/*
David Howells54ceac42006-08-22 20:06:13 -04002363 * Destroy an NFS2/3 superblock
2364 */
David Howellsf7b422b2006-06-09 09:34:33 -04002365static void nfs_kill_super(struct super_block *s)
2366{
2367 struct nfs_server *server = NFS_SB(s);
2368
2369 kill_anon_super(s);
David Howells08734042009-04-03 16:42:42 +01002370 nfs_fscache_release_super_cookie(s);
David Howells54ceac42006-08-22 20:06:13 -04002371 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04002372}
2373
David Howells54ceac42006-08-22 20:06:13 -04002374/*
2375 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2376 */
Al Viro31f43472010-10-29 03:38:12 -04002377static struct dentry *
2378nfs_xdev_mount(struct file_system_type *fs_type, int flags,
2379 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002380{
2381 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002382 struct super_block *s;
2383 struct nfs_server *server;
2384 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002385 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002386 struct nfs_sb_mountdata sb_mntdata = {
2387 .mntflags = flags,
2388 };
David Howells54ceac42006-08-22 20:06:13 -04002389 int error;
2390
Al Viro31f43472010-10-29 03:38:12 -04002391 dprintk("--> nfs_xdev_mount()\n");
David Howells54ceac42006-08-22 20:06:13 -04002392
2393 /* create a new volume representation */
2394 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2395 if (IS_ERR(server)) {
2396 error = PTR_ERR(server);
2397 goto out_err_noserver;
2398 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002399 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002400
Trond Myklebust75180df2007-05-16 16:53:28 -04002401 if (server->flags & NFS_MOUNT_UNSHARED)
2402 compare_super = NULL;
2403
Sachin Prabhufb2088c2011-08-01 12:10:12 +01002404 /* -o noac implies -o sync */
2405 if (server->flags & NFS_MOUNT_NOAC)
2406 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2407
David Howells54ceac42006-08-22 20:06:13 -04002408 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002409 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002410 if (IS_ERR(s)) {
2411 error = PTR_ERR(s);
2412 goto out_err_nosb;
2413 }
2414
2415 if (s->s_fs_info != server) {
2416 nfs_free_server(server);
2417 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002418 } else {
2419 error = nfs_bdi_register(server);
2420 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11002421 goto error_splat_bdi;
David Howells54ceac42006-08-22 20:06:13 -04002422 }
2423
2424 if (!s->s_root) {
2425 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002426 nfs_clone_super(s, data->sb);
David Howells2df54802009-09-23 14:36:39 -04002427 nfs_fscache_get_super_cookie(s, NULL, data);
David Howells54ceac42006-08-22 20:06:13 -04002428 }
2429
Al Viro0d5839a2011-03-16 05:27:27 -04002430 mntroot = nfs_get_root(s, data->fh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04002431 if (IS_ERR(mntroot)) {
2432 error = PTR_ERR(mntroot);
2433 goto error_splat_super;
2434 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002435 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
Neil Brown4c1fe2f2007-11-01 16:50:20 +11002436 dput(mntroot);
2437 error = -ESTALE;
2438 goto error_splat_super;
2439 }
David Howells54ceac42006-08-22 20:06:13 -04002440
2441 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002442
Eric Parisf9c3a382008-03-05 14:20:18 -05002443 /* clone any lsm security options from the parent to the new sb */
2444 security_sb_clone_mnt_opts(data->sb, s);
2445
Al Viro31f43472010-10-29 03:38:12 -04002446 dprintk("<-- nfs_xdev_mount() = 0\n");
2447 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04002448
2449out_err_nosb:
2450 nfs_free_server(server);
2451out_err_noserver:
Al Viro31f43472010-10-29 03:38:12 -04002452 dprintk("<-- nfs_xdev_mount() = %d [error]\n", error);
2453 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04002454
2455error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002456 if (server && !s->s_root)
2457 bdi_unregister(&server->backing_dev_info);
2458error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002459 deactivate_locked_super(s);
Al Viro31f43472010-10-29 03:38:12 -04002460 dprintk("<-- nfs_xdev_mount() = %d [splat]\n", error);
2461 return ERR_PTR(error);
David Howellsf7b422b2006-06-09 09:34:33 -04002462}
2463
2464#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04002465
2466/*
2467 * Finish setting up a cloned NFS4 superblock
2468 */
2469static void nfs4_clone_super(struct super_block *sb,
2470 const struct super_block *old_sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002471{
David Howells54ceac42006-08-22 20:06:13 -04002472 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2473 sb->s_blocksize = old_sb->s_blocksize;
2474 sb->s_maxbytes = old_sb->s_maxbytes;
2475 sb->s_time_gran = 1;
2476 sb->s_op = old_sb->s_op;
Aneesh Kumar K.Va8a5da92010-12-09 11:35:14 +00002477 /*
2478 * The VFS shouldn't apply the umask to mode bits. We will do
2479 * so ourselves when necessary.
2480 */
2481 sb->s_flags |= MS_POSIXACL;
Aneesh Kumar K.V64c2ce82010-12-09 11:35:25 +00002482 sb->s_xattr = old_sb->s_xattr;
2483 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002484}
2485
2486/*
2487 * Set up an NFS4 superblock
2488 */
David Howells54ceac42006-08-22 20:06:13 -04002489static void nfs4_fill_super(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002490{
David Howellsf7b422b2006-06-09 09:34:33 -04002491 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04002492 sb->s_op = &nfs4_sops;
Aneesh Kumar K.Va8a5da92010-12-09 11:35:14 +00002493 /*
2494 * The VFS shouldn't apply the umask to mode bits. We will do
2495 * so ourselves when necessary.
2496 */
2497 sb->s_flags |= MS_POSIXACL;
Aneesh Kumar K.V64c2ce82010-12-09 11:35:25 +00002498 sb->s_xattr = nfs4_xattr_handlers;
David Howells54ceac42006-08-22 20:06:13 -04002499 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002500}
2501
Trond Myklebust01c3f052009-06-17 13:22:58 -07002502static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2503{
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04002504 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3|
2505 NFS_MOUNT_LOCAL_FLOCK|NFS_MOUNT_LOCAL_FCNTL);
Trond Myklebust01c3f052009-06-17 13:22:58 -07002506}
2507
Chuck Lever7630c852009-09-08 19:49:57 -04002508static int nfs4_validate_text_mount_data(void *options,
2509 struct nfs_parsed_mount_data *args,
2510 const char *dev_name)
2511{
2512 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2513
Trond Myklebustf5855fe2009-10-06 15:40:37 -04002514 nfs_set_port(sap, &args->nfs_server.port, NFS_PORT);
Chuck Lever7630c852009-09-08 19:49:57 -04002515
2516 nfs_validate_transport_protocol(args);
2517
2518 nfs4_validate_mount_flags(args);
2519
Trond Myklebust2ecda722009-09-08 19:50:07 -04002520 if (args->version != 4) {
2521 dfprintk(MOUNT,
2522 "NFS4: Illegal mount version\n");
2523 return -EINVAL;
2524 }
2525
Chuck Lever7630c852009-09-08 19:49:57 -04002526 if (args->auth_flavor_len > 1) {
2527 dfprintk(MOUNT,
2528 "NFS4: Too many RPC auth flavours specified\n");
2529 return -EINVAL;
2530 }
2531
2532 if (args->client_address == NULL) {
2533 dfprintk(MOUNT,
2534 "NFS4: mount program didn't pass callback address\n");
2535 return -EINVAL;
2536 }
2537
2538 return nfs_parse_devname(dev_name,
2539 &args->nfs_server.hostname,
2540 NFS4_MAXNAMLEN,
2541 &args->nfs_server.export_path,
2542 NFS4_MAXPATHLEN);
2543}
2544
David Howells54ceac42006-08-22 20:06:13 -04002545/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04002546 * Validate NFSv4 mount options
2547 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002548static int nfs4_validate_mount_data(void *options,
2549 struct nfs_parsed_mount_data *args,
2550 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04002551{
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002552 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002553 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002554 char *c;
2555
2556 if (data == NULL)
2557 goto out_no_data;
2558
2559 switch (data->version) {
2560 case 1:
Chuck Lever4c568012007-12-10 14:59:28 -05002561 if (data->host_addrlen > sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002562 goto out_no_address;
Chuck Lever4c568012007-12-10 14:59:28 -05002563 if (data->host_addrlen == 0)
2564 goto out_no_address;
2565 args->nfs_server.addrlen = data->host_addrlen;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002566 if (copy_from_user(sap, data->host_addr, data->host_addrlen))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002567 return -EFAULT;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002568 if (!nfs_verify_server_address(sap))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002569 goto out_no_address;
2570
Chuck Lever6738b252008-06-24 16:33:54 -04002571 if (data->auth_flavourlen) {
2572 if (data->auth_flavourlen > 1)
2573 goto out_inval_auth;
Trond Myklebust20c71f52007-09-20 20:23:51 -04002574 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002575 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04002576 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002577 return -EFAULT;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002578 }
2579
2580 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2581 if (IS_ERR(c))
2582 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002583 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002584
2585 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2586 if (IS_ERR(c))
2587 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002588 args->nfs_server.export_path = c;
2589 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002590
2591 c = strndup_user(data->client_addr.data, 16);
2592 if (IS_ERR(c))
2593 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002594 args->client_address = c;
2595
2596 /*
2597 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2598 * can deal with.
2599 */
2600
2601 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2602 args->rsize = data->rsize;
2603 args->wsize = data->wsize;
2604 args->timeo = data->timeo;
2605 args->retrans = data->retrans;
2606 args->acregmin = data->acregmin;
2607 args->acregmax = data->acregmax;
2608 args->acdirmin = data->acdirmin;
2609 args->acdirmax = data->acdirmax;
2610 args->nfs_server.protocol = data->proto;
Trond Myklebust259875e2008-07-02 14:43:47 -04002611 nfs_validate_transport_protocol(args);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002612
2613 break;
Chuck Lever7630c852009-09-08 19:49:57 -04002614 default:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002615 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever80071222007-07-01 12:13:59 -04002616 return -EINVAL;
2617
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002618 if (!nfs_verify_server_address(sap))
Chuck Lever80071222007-07-01 12:13:59 -04002619 return -EINVAL;
Chuck Levered596a82008-06-26 17:47:05 -04002620
Chuck Lever7630c852009-09-08 19:49:57 -04002621 return nfs4_validate_text_mount_data(options, args, dev_name);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002622 }
2623
2624 return 0;
2625
2626out_no_data:
2627 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2628 return -EINVAL;
2629
2630out_inval_auth:
2631 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2632 data->auth_flavourlen);
2633 return -EINVAL;
2634
2635out_no_address:
2636 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2637 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002638}
2639
2640/*
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002641 * Get the superblock for the NFS4 root partition
David Howells54ceac42006-08-22 20:06:13 -04002642 */
Al Viro31f43472010-10-29 03:38:12 -04002643static struct dentry *
2644nfs4_remote_mount(struct file_system_type *fs_type, int flags,
2645 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002646{
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002647 struct nfs_parsed_mount_data *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002648 struct super_block *s;
2649 struct nfs_server *server;
Trond Myklebust33852a12008-06-19 14:20:11 -04002650 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04002651 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002652 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002653 struct nfs_sb_mountdata sb_mntdata = {
2654 .mntflags = flags,
2655 };
Trond Myklebust33852a12008-06-19 14:20:11 -04002656 int error = -ENOMEM;
David Howellsf7b422b2006-06-09 09:34:33 -04002657
Trond Myklebustb157b062010-04-19 19:05:48 -04002658 mntfh = nfs_alloc_fhandle();
Trond Myklebust33852a12008-06-19 14:20:11 -04002659 if (data == NULL || mntfh == NULL)
Jeff Layton8a0d5512011-12-20 06:57:45 -05002660 goto out;
Eric Parisf9c3a382008-03-05 14:20:18 -05002661
David Howells54ceac42006-08-22 20:06:13 -04002662 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002663 server = nfs4_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002664 if (IS_ERR(server)) {
2665 error = PTR_ERR(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04002666 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002667 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002668 sb_mntdata.server = server;
David Howellsf7b422b2006-06-09 09:34:33 -04002669
Trond Myklebust75180df2007-05-16 16:53:28 -04002670 if (server->flags & NFS4_MOUNT_UNSHARED)
2671 compare_super = NULL;
2672
Sachin Prabhufb2088c2011-08-01 12:10:12 +01002673 /* -o noac implies -o sync */
2674 if (server->flags & NFS_MOUNT_NOAC)
2675 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2676
David Howells54ceac42006-08-22 20:06:13 -04002677 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002678 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002679 if (IS_ERR(s)) {
2680 error = PTR_ERR(s);
David Howellsf7b422b2006-06-09 09:34:33 -04002681 goto out_free;
Trond Myklebust816724e2006-06-24 08:41:41 -04002682 }
2683
Trond Myklebust5dd31772006-08-24 01:03:05 -04002684 if (s->s_fs_info != server) {
2685 nfs_free_server(server);
2686 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002687 } else {
2688 error = nfs_bdi_register(server);
2689 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11002690 goto error_splat_bdi;
Trond Myklebust5dd31772006-08-24 01:03:05 -04002691 }
2692
David Howells54ceac42006-08-22 20:06:13 -04002693 if (!s->s_root) {
2694 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002695 nfs4_fill_super(s);
Jeff Laytonc15c9282012-01-24 16:35:00 +00002696 nfs_fscache_get_super_cookie(s, data->fscache_uniq, NULL);
Trond Myklebust816724e2006-06-24 08:41:41 -04002697 }
David Howellsf7b422b2006-06-09 09:34:33 -04002698
Al Viro0d5839a2011-03-16 05:27:27 -04002699 mntroot = nfs4_get_root(s, mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04002700 if (IS_ERR(mntroot)) {
2701 error = PTR_ERR(mntroot);
2702 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04002703 }
David Howells54ceac42006-08-22 20:06:13 -04002704
Trond Myklebust33852a12008-06-19 14:20:11 -04002705 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Paris46c8ac72008-05-02 13:42:42 -07002706 if (error)
2707 goto error_splat_root;
2708
David Howellsf7b422b2006-06-09 09:34:33 -04002709 s->s_flags |= MS_ACTIVE;
Al Viro31f43472010-10-29 03:38:12 -04002710
Al Viro31f43472010-10-29 03:38:12 -04002711 nfs_free_fhandle(mntfh);
2712 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04002713
Chuck Lever29eb9812007-07-01 12:12:30 -04002714out:
Trond Myklebustb157b062010-04-19 19:05:48 -04002715 nfs_free_fhandle(mntfh);
Al Viro31f43472010-10-29 03:38:12 -04002716 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04002717
Chuck Lever29eb9812007-07-01 12:12:30 -04002718out_free:
2719 nfs_free_server(server);
2720 goto out;
2721
Eric Paris46c8ac72008-05-02 13:42:42 -07002722error_splat_root:
2723 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04002724error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002725 if (server && !s->s_root)
2726 bdi_unregister(&server->backing_dev_info);
2727error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002728 deactivate_locked_super(s);
Chuck Lever29eb9812007-07-01 12:12:30 -04002729 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002730}
2731
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002732static struct vfsmount *nfs_do_root_mount(struct file_system_type *fs_type,
2733 int flags, void *data, const char *hostname)
2734{
2735 struct vfsmount *root_mnt;
2736 char *root_devname;
2737 size_t len;
2738
2739 len = strlen(hostname) + 3;
2740 root_devname = kmalloc(len, GFP_KERNEL);
2741 if (root_devname == NULL)
2742 return ERR_PTR(-ENOMEM);
2743 snprintf(root_devname, len, "%s:/", hostname);
2744 root_mnt = vfs_kern_mount(fs_type, flags, root_devname, data);
2745 kfree(root_devname);
2746 return root_mnt;
2747}
2748
Trond Myklebustce587e02010-04-16 16:22:52 -04002749struct nfs_referral_count {
2750 struct list_head list;
2751 const struct task_struct *task;
2752 unsigned int referral_count;
2753};
2754
2755static LIST_HEAD(nfs_referral_count_list);
2756static DEFINE_SPINLOCK(nfs_referral_count_list_lock);
2757
2758static struct nfs_referral_count *nfs_find_referral_count(void)
2759{
2760 struct nfs_referral_count *p;
2761
2762 list_for_each_entry(p, &nfs_referral_count_list, list) {
2763 if (p->task == current)
2764 return p;
2765 }
2766 return NULL;
2767}
2768
2769#define NFS_MAX_NESTED_REFERRALS 2
2770
2771static int nfs_referral_loop_protect(void)
2772{
2773 struct nfs_referral_count *p, *new;
2774 int ret = -ENOMEM;
2775
2776 new = kmalloc(sizeof(*new), GFP_KERNEL);
2777 if (!new)
2778 goto out;
2779 new->task = current;
2780 new->referral_count = 1;
2781
2782 ret = 0;
2783 spin_lock(&nfs_referral_count_list_lock);
2784 p = nfs_find_referral_count();
2785 if (p != NULL) {
2786 if (p->referral_count >= NFS_MAX_NESTED_REFERRALS)
2787 ret = -ELOOP;
2788 else
2789 p->referral_count++;
2790 } else {
2791 list_add(&new->list, &nfs_referral_count_list);
2792 new = NULL;
2793 }
2794 spin_unlock(&nfs_referral_count_list_lock);
2795 kfree(new);
2796out:
2797 return ret;
2798}
2799
2800static void nfs_referral_loop_unprotect(void)
2801{
2802 struct nfs_referral_count *p;
2803
2804 spin_lock(&nfs_referral_count_list_lock);
2805 p = nfs_find_referral_count();
2806 p->referral_count--;
2807 if (p->referral_count == 0)
2808 list_del(&p->list);
2809 else
2810 p = NULL;
2811 spin_unlock(&nfs_referral_count_list_lock);
2812 kfree(p);
2813}
2814
Al Viro01194982011-03-16 07:25:36 -04002815static struct dentry *nfs_follow_remote_path(struct vfsmount *root_mnt,
2816 const char *export_path)
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002817{
Al Viro01194982011-03-16 07:25:36 -04002818 struct dentry *dentry;
Al Viro5352d3b2011-11-16 21:52:06 -05002819 int err;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002820
Al Viro5352d3b2011-11-16 21:52:06 -05002821 if (IS_ERR(root_mnt))
2822 return ERR_CAST(root_mnt);
2823
2824 err = nfs_referral_loop_protect();
2825 if (err) {
Al Viroea441d12011-11-16 21:43:59 -05002826 mntput(root_mnt);
Al Viro5352d3b2011-11-16 21:52:06 -05002827 return ERR_PTR(err);
Al Viroc1334492011-11-16 16:12:14 -05002828 }
Trond Myklebustce587e02010-04-16 16:22:52 -04002829
Al Viroea441d12011-11-16 21:43:59 -05002830 dentry = mount_subtree(root_mnt, export_path);
2831 nfs_referral_loop_unprotect();
Linus Torvaldsa2770d82009-12-17 12:51:05 -08002832
Al Viro01194982011-03-16 07:25:36 -04002833 return dentry;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002834}
2835
Al Viro01194982011-03-16 07:25:36 -04002836static struct dentry *nfs4_try_mount(int flags, const char *dev_name,
2837 struct nfs_parsed_mount_data *data)
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002838{
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002839 char *export_path;
2840 struct vfsmount *root_mnt;
Al Viro01194982011-03-16 07:25:36 -04002841 struct dentry *res;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002842
Chuck Levera6fe23b2009-09-08 19:50:00 -04002843 dfprintk(MOUNT, "--> nfs4_try_mount()\n");
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002844
2845 export_path = data->nfs_server.export_path;
2846 data->nfs_server.export_path = "/";
2847 root_mnt = nfs_do_root_mount(&nfs4_remote_fs_type, flags, data,
2848 data->nfs_server.hostname);
2849 data->nfs_server.export_path = export_path;
2850
Al Viro5352d3b2011-11-16 21:52:06 -05002851 res = nfs_follow_remote_path(root_mnt, export_path);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002852
Al Viro01194982011-03-16 07:25:36 -04002853 dfprintk(MOUNT, "<-- nfs4_try_mount() = %ld%s\n",
2854 IS_ERR(res) ? PTR_ERR(res) : 0,
2855 IS_ERR(res) ? " [error]" : "");
2856 return res;
Chuck Levera6fe23b2009-09-08 19:50:00 -04002857}
2858
2859/*
2860 * Get the superblock for an NFS4 mountpoint
2861 */
Al Viro01194982011-03-16 07:25:36 -04002862static struct dentry *nfs4_mount(struct file_system_type *fs_type,
2863 int flags, const char *dev_name, void *raw_data)
Chuck Levera6fe23b2009-09-08 19:50:00 -04002864{
2865 struct nfs_parsed_mount_data *data;
2866 int error = -ENOMEM;
Al Viro01194982011-03-16 07:25:36 -04002867 struct dentry *res = ERR_PTR(-ENOMEM);
Chuck Levera6fe23b2009-09-08 19:50:00 -04002868
Trond Myklebustc5811db2009-10-06 15:40:15 -04002869 data = nfs_alloc_parsed_mount_data(4);
Chuck Levera6fe23b2009-09-08 19:50:00 -04002870 if (data == NULL)
Jeff Layton8a0d5512011-12-20 06:57:45 -05002871 goto out;
Chuck Levera6fe23b2009-09-08 19:50:00 -04002872
2873 /* Validate the mount data */
2874 error = nfs4_validate_mount_data(raw_data, data, dev_name);
Al Viro01194982011-03-16 07:25:36 -04002875 if (error < 0) {
2876 res = ERR_PTR(error);
Chuck Levera6fe23b2009-09-08 19:50:00 -04002877 goto out;
Al Viro01194982011-03-16 07:25:36 -04002878 }
Chuck Levera6fe23b2009-09-08 19:50:00 -04002879
Al Viro01194982011-03-16 07:25:36 -04002880 res = nfs4_try_mount(flags, dev_name, data);
2881 if (IS_ERR(res))
2882 error = PTR_ERR(res);
Chuck Levera6fe23b2009-09-08 19:50:00 -04002883
2884out:
Jeff Layton8a0d5512011-12-20 06:57:45 -05002885 nfs_free_parsed_mount_data(data);
Al Viro01194982011-03-16 07:25:36 -04002886 dprintk("<-- nfs4_mount() = %d%s\n", error,
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002887 error != 0 ? " [error]" : "");
Al Viro01194982011-03-16 07:25:36 -04002888 return res;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002889}
2890
David Howellsf7b422b2006-06-09 09:34:33 -04002891static void nfs4_kill_super(struct super_block *sb)
2892{
2893 struct nfs_server *server = NFS_SB(sb);
2894
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002895 dprintk("--> %s\n", __func__);
Trond Myklebust515d8612008-12-23 15:21:46 -05002896 nfs_super_return_all_delegations(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002897 kill_anon_super(sb);
David Howells08734042009-04-03 16:42:42 +01002898 nfs_fscache_release_super_cookie(sb);
David Howells54ceac42006-08-22 20:06:13 -04002899 nfs_free_server(server);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002900 dprintk("<-- %s\n", __func__);
David Howellsf7b422b2006-06-09 09:34:33 -04002901}
2902
2903/*
David Howells54ceac42006-08-22 20:06:13 -04002904 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -04002905 */
Al Viro31f43472010-10-29 03:38:12 -04002906static struct dentry *
2907nfs4_xdev_mount(struct file_system_type *fs_type, int flags,
2908 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002909{
2910 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002911 struct super_block *s;
2912 struct nfs_server *server;
2913 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002914 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002915 struct nfs_sb_mountdata sb_mntdata = {
2916 .mntflags = flags,
2917 };
David Howells54ceac42006-08-22 20:06:13 -04002918 int error;
2919
Al Viro31f43472010-10-29 03:38:12 -04002920 dprintk("--> nfs4_xdev_mount()\n");
David Howells54ceac42006-08-22 20:06:13 -04002921
2922 /* create a new volume representation */
2923 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2924 if (IS_ERR(server)) {
2925 error = PTR_ERR(server);
2926 goto out_err_noserver;
2927 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002928 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002929
Trond Myklebust75180df2007-05-16 16:53:28 -04002930 if (server->flags & NFS4_MOUNT_UNSHARED)
2931 compare_super = NULL;
2932
Sachin Prabhufb2088c2011-08-01 12:10:12 +01002933 /* -o noac implies -o sync */
2934 if (server->flags & NFS_MOUNT_NOAC)
2935 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2936
David Howells54ceac42006-08-22 20:06:13 -04002937 /* Get a superblock - note that we may end up sharing one that already exists */
Andy Adamsonec9a05c2008-10-17 10:44:37 -04002938 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002939 if (IS_ERR(s)) {
2940 error = PTR_ERR(s);
2941 goto out_err_nosb;
2942 }
2943
2944 if (s->s_fs_info != server) {
2945 nfs_free_server(server);
2946 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002947 } else {
2948 error = nfs_bdi_register(server);
2949 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11002950 goto error_splat_bdi;
David Howells54ceac42006-08-22 20:06:13 -04002951 }
2952
2953 if (!s->s_root) {
2954 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002955 nfs4_clone_super(s, data->sb);
David Howells2df54802009-09-23 14:36:39 -04002956 nfs_fscache_get_super_cookie(s, NULL, data);
David Howells54ceac42006-08-22 20:06:13 -04002957 }
2958
Al Viro0d5839a2011-03-16 05:27:27 -04002959 mntroot = nfs4_get_root(s, data->fh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04002960 if (IS_ERR(mntroot)) {
2961 error = PTR_ERR(mntroot);
2962 goto error_splat_super;
2963 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002964 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2965 dput(mntroot);
2966 error = -ESTALE;
2967 goto error_splat_super;
2968 }
David Howells54ceac42006-08-22 20:06:13 -04002969
2970 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002971
Eric Paris46c8ac72008-05-02 13:42:42 -07002972 security_sb_clone_mnt_opts(data->sb, s);
2973
Al Viro31f43472010-10-29 03:38:12 -04002974 dprintk("<-- nfs4_xdev_mount() = 0\n");
2975 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04002976
2977out_err_nosb:
2978 nfs_free_server(server);
2979out_err_noserver:
Al Viro31f43472010-10-29 03:38:12 -04002980 dprintk("<-- nfs4_xdev_mount() = %d [error]\n", error);
2981 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04002982
2983error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002984 if (server && !s->s_root)
2985 bdi_unregister(&server->backing_dev_info);
2986error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002987 deactivate_locked_super(s);
Al Viro31f43472010-10-29 03:38:12 -04002988 dprintk("<-- nfs4_xdev_mount() = %d [splat]\n", error);
2989 return ERR_PTR(error);
David Howellsf7b422b2006-06-09 09:34:33 -04002990}
2991
Al Viro31f43472010-10-29 03:38:12 -04002992static struct dentry *
2993nfs4_remote_referral_mount(struct file_system_type *fs_type, int flags,
2994 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002995{
2996 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002997 struct super_block *s;
2998 struct nfs_server *server;
2999 struct dentry *mntroot;
Trond Myklebust4f727292010-04-16 16:22:48 -04003000 struct nfs_fh *mntfh;
Trond Myklebust75180df2007-05-16 16:53:28 -04003001 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04003002 struct nfs_sb_mountdata sb_mntdata = {
3003 .mntflags = flags,
3004 };
Trond Myklebust4f727292010-04-16 16:22:48 -04003005 int error = -ENOMEM;
David Howells54ceac42006-08-22 20:06:13 -04003006
3007 dprintk("--> nfs4_referral_get_sb()\n");
3008
Trond Myklebust4f727292010-04-16 16:22:48 -04003009 mntfh = nfs_alloc_fhandle();
3010 if (mntfh == NULL)
3011 goto out_err_nofh;
3012
David Howells54ceac42006-08-22 20:06:13 -04003013 /* create a new volume representation */
Trond Myklebust4f727292010-04-16 16:22:48 -04003014 server = nfs4_create_referral_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04003015 if (IS_ERR(server)) {
3016 error = PTR_ERR(server);
3017 goto out_err_noserver;
3018 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04003019 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04003020
Trond Myklebust75180df2007-05-16 16:53:28 -04003021 if (server->flags & NFS4_MOUNT_UNSHARED)
3022 compare_super = NULL;
3023
Sachin Prabhufb2088c2011-08-01 12:10:12 +01003024 /* -o noac implies -o sync */
3025 if (server->flags & NFS_MOUNT_NOAC)
3026 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
3027
David Howells54ceac42006-08-22 20:06:13 -04003028 /* Get a superblock - note that we may end up sharing one that already exists */
Andy Adamsonec9a05c2008-10-17 10:44:37 -04003029 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04003030 if (IS_ERR(s)) {
3031 error = PTR_ERR(s);
3032 goto out_err_nosb;
3033 }
3034
3035 if (s->s_fs_info != server) {
3036 nfs_free_server(server);
3037 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07003038 } else {
3039 error = nfs_bdi_register(server);
3040 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11003041 goto error_splat_bdi;
David Howells54ceac42006-08-22 20:06:13 -04003042 }
3043
3044 if (!s->s_root) {
3045 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04003046 nfs4_fill_super(s);
David Howells2df54802009-09-23 14:36:39 -04003047 nfs_fscache_get_super_cookie(s, NULL, data);
David Howells54ceac42006-08-22 20:06:13 -04003048 }
3049
Al Viro0d5839a2011-03-16 05:27:27 -04003050 mntroot = nfs4_get_root(s, mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04003051 if (IS_ERR(mntroot)) {
3052 error = PTR_ERR(mntroot);
3053 goto error_splat_super;
3054 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05003055 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
3056 dput(mntroot);
3057 error = -ESTALE;
3058 goto error_splat_super;
3059 }
David Howells54ceac42006-08-22 20:06:13 -04003060
3061 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04003062
Eric Paris46c8ac72008-05-02 13:42:42 -07003063 security_sb_clone_mnt_opts(data->sb, s);
3064
Trond Myklebust4f727292010-04-16 16:22:48 -04003065 nfs_free_fhandle(mntfh);
David Howells54ceac42006-08-22 20:06:13 -04003066 dprintk("<-- nfs4_referral_get_sb() = 0\n");
Al Viro31f43472010-10-29 03:38:12 -04003067 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04003068
3069out_err_nosb:
3070 nfs_free_server(server);
3071out_err_noserver:
Trond Myklebust4f727292010-04-16 16:22:48 -04003072 nfs_free_fhandle(mntfh);
3073out_err_nofh:
David Howells54ceac42006-08-22 20:06:13 -04003074 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
Al Viro31f43472010-10-29 03:38:12 -04003075 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04003076
3077error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11003078 if (server && !s->s_root)
3079 bdi_unregister(&server->backing_dev_info);
3080error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04003081 deactivate_locked_super(s);
Trond Myklebust4f727292010-04-16 16:22:48 -04003082 nfs_free_fhandle(mntfh);
David Howells54ceac42006-08-22 20:06:13 -04003083 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
Al Viro31f43472010-10-29 03:38:12 -04003084 return ERR_PTR(error);
David Howellsf7b422b2006-06-09 09:34:33 -04003085}
3086
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04003087/*
3088 * Create an NFS4 server record on referral traversal
3089 */
Al Viro01194982011-03-16 07:25:36 -04003090static struct dentry *nfs4_referral_mount(struct file_system_type *fs_type,
3091 int flags, const char *dev_name, void *raw_data)
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04003092{
3093 struct nfs_clone_mount *data = raw_data;
3094 char *export_path;
3095 struct vfsmount *root_mnt;
Al Viro01194982011-03-16 07:25:36 -04003096 struct dentry *res;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04003097
Al Viro01194982011-03-16 07:25:36 -04003098 dprintk("--> nfs4_referral_mount()\n");
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04003099
3100 export_path = data->mnt_path;
3101 data->mnt_path = "/";
3102
3103 root_mnt = nfs_do_root_mount(&nfs4_remote_referral_fs_type,
3104 flags, data, data->hostname);
3105 data->mnt_path = export_path;
3106
Al Viro5352d3b2011-11-16 21:52:06 -05003107 res = nfs_follow_remote_path(root_mnt, export_path);
Al Viro01194982011-03-16 07:25:36 -04003108 dprintk("<-- nfs4_referral_mount() = %ld%s\n",
3109 IS_ERR(res) ? PTR_ERR(res) : 0,
3110 IS_ERR(res) ? " [error]" : "");
3111 return res;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04003112}
3113
David Howells54ceac42006-08-22 20:06:13 -04003114#endif /* CONFIG_NFS_V4 */