blob: e463967aafb8cf1d48be42e8c7b191cba607fbeb [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>
David Howellsf7b422b2006-06-09 09:34:33 -040055
56#include <asm/system.h>
57#include <asm/uaccess.h>
58
59#include "nfs4_fs.h"
60#include "callback.h"
61#include "delegation.h"
62#include "iostat.h"
63#include "internal.h"
David Howells08734042009-04-03 16:42:42 +010064#include "fscache.h"
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +030065#include "pnfs.h"
David Howellsf7b422b2006-06-09 09:34:33 -040066
67#define NFSDBG_FACILITY NFSDBG_VFS
68
Paulius Zaleckas1e657bd2010-10-31 18:21:05 +020069#ifdef CONFIG_NFS_V3
70#define NFS_DEFAULT_VERSION 3
71#else
72#define NFS_DEFAULT_VERSION 2
73#endif
74
Chuck Leverbf0fd762007-07-01 12:13:44 -040075enum {
76 /* Mount options that take no arguments */
77 Opt_soft, Opt_hard,
Chuck Leverbf0fd762007-07-01 12:13:44 -040078 Opt_posix, Opt_noposix,
79 Opt_cto, Opt_nocto,
80 Opt_ac, Opt_noac,
81 Opt_lock, Opt_nolock,
Chuck Lever764302c2009-09-08 19:50:03 -040082 Opt_v2, Opt_v3, Opt_v4,
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -040083 Opt_udp, Opt_tcp, Opt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -040084 Opt_acl, Opt_noacl,
85 Opt_rdirplus, Opt_nordirplus,
Trond Myklebust75180df2007-05-16 16:53:28 -040086 Opt_sharecache, Opt_nosharecache,
Chuck Leverd7403512008-12-23 15:21:37 -050087 Opt_resvport, Opt_noresvport,
David Howellsb797cac2009-04-03 16:42:48 +010088 Opt_fscache, Opt_nofscache,
Chuck Leverbf0fd762007-07-01 12:13:44 -040089
90 /* Mount options that take integer arguments */
91 Opt_port,
92 Opt_rsize, Opt_wsize, Opt_bsize,
93 Opt_timeo, Opt_retrans,
94 Opt_acregmin, Opt_acregmax,
95 Opt_acdirmin, Opt_acdirmax,
96 Opt_actimeo,
97 Opt_namelen,
98 Opt_mountport,
Chuck Levere887cbc2007-10-26 13:32:29 -040099 Opt_mountvers,
Chuck Leverad879ce2007-10-26 13:32:24 -0400100 Opt_nfsvers,
Mike Sager3fd5be92009-04-01 09:21:48 -0400101 Opt_minorversion,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400102
103 /* Mount options that take string arguments */
Chuck Lever33832032007-12-10 14:59:13 -0500104 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
Chuck Lever0ac83772007-09-11 18:01:04 -0400105 Opt_addr, Opt_mountaddr, Opt_clientaddr,
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400106 Opt_lookupcache,
David Howellsb797cac2009-04-03 16:42:48 +0100107 Opt_fscache_uniq,
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400108 Opt_local_lock,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400109
Chuck Leverf45663c2008-06-24 19:28:02 -0400110 /* Special mount options */
111 Opt_userspace, Opt_deprecated, Opt_sloppy,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400112
113 Opt_err
114};
115
Steven Whitehousea447c092008-10-13 10:46:57 +0100116static const match_table_t nfs_mount_option_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400117 { Opt_userspace, "bg" },
118 { Opt_userspace, "fg" },
Chuck Leverecbb3842008-06-12 12:37:33 -0400119 { Opt_userspace, "retry=%s" },
120
Chuck Leverf45663c2008-06-24 19:28:02 -0400121 { Opt_sloppy, "sloppy" },
122
Chuck Leverbf0fd762007-07-01 12:13:44 -0400123 { Opt_soft, "soft" },
124 { Opt_hard, "hard" },
Chuck Leverd33e4df2008-06-12 12:37:41 -0400125 { Opt_deprecated, "intr" },
126 { Opt_deprecated, "nointr" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400127 { Opt_posix, "posix" },
128 { Opt_noposix, "noposix" },
129 { Opt_cto, "cto" },
130 { Opt_nocto, "nocto" },
131 { Opt_ac, "ac" },
132 { Opt_noac, "noac" },
133 { Opt_lock, "lock" },
134 { Opt_nolock, "nolock" },
135 { Opt_v2, "v2" },
136 { Opt_v3, "v3" },
Chuck Lever764302c2009-09-08 19:50:03 -0400137 { Opt_v4, "v4" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400138 { Opt_udp, "udp" },
139 { Opt_tcp, "tcp" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400140 { Opt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400141 { Opt_acl, "acl" },
142 { Opt_noacl, "noacl" },
143 { Opt_rdirplus, "rdirplus" },
144 { Opt_nordirplus, "nordirplus" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400145 { Opt_sharecache, "sharecache" },
146 { Opt_nosharecache, "nosharecache" },
Chuck Leverd7403512008-12-23 15:21:37 -0500147 { Opt_resvport, "resvport" },
148 { Opt_noresvport, "noresvport" },
David Howellsb797cac2009-04-03 16:42:48 +0100149 { Opt_fscache, "fsc" },
David Howellsb797cac2009-04-03 16:42:48 +0100150 { Opt_nofscache, "nofsc" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400151
Chuck Levera5a16ba2009-06-17 18:02:14 -0700152 { Opt_port, "port=%s" },
153 { Opt_rsize, "rsize=%s" },
154 { Opt_wsize, "wsize=%s" },
155 { Opt_bsize, "bsize=%s" },
156 { Opt_timeo, "timeo=%s" },
157 { Opt_retrans, "retrans=%s" },
158 { Opt_acregmin, "acregmin=%s" },
159 { Opt_acregmax, "acregmax=%s" },
160 { Opt_acdirmin, "acdirmin=%s" },
161 { Opt_acdirmax, "acdirmax=%s" },
162 { Opt_actimeo, "actimeo=%s" },
163 { Opt_namelen, "namlen=%s" },
164 { Opt_mountport, "mountport=%s" },
165 { Opt_mountvers, "mountvers=%s" },
166 { Opt_nfsvers, "nfsvers=%s" },
167 { Opt_nfsvers, "vers=%s" },
Chuck Leverf3f4f4e2009-08-09 15:09:29 -0400168 { Opt_minorversion, "minorversion=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400169
170 { Opt_sec, "sec=%s" },
171 { Opt_proto, "proto=%s" },
172 { Opt_mountproto, "mountproto=%s" },
173 { Opt_addr, "addr=%s" },
174 { Opt_clientaddr, "clientaddr=%s" },
Chuck Lever33832032007-12-10 14:59:13 -0500175 { Opt_mounthost, "mounthost=%s" },
Chuck Lever0ac83772007-09-11 18:01:04 -0400176 { Opt_mountaddr, "mountaddr=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400177
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400178 { Opt_lookupcache, "lookupcache=%s" },
Chuck Levera6d5ff62010-05-07 13:33:58 -0400179 { Opt_fscache_uniq, "fsc=%s" },
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400180 { Opt_local_lock, "local_lock=%s" },
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400181
Chuck Leverbf0fd762007-07-01 12:13:44 -0400182 { Opt_err, NULL }
183};
184
185enum {
Jeff Laytonee671b02009-12-03 15:58:56 -0500186 Opt_xprt_udp, Opt_xprt_udp6, Opt_xprt_tcp, Opt_xprt_tcp6, Opt_xprt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400187
188 Opt_xprt_err
189};
190
Steven Whitehousea447c092008-10-13 10:46:57 +0100191static const match_table_t nfs_xprt_protocol_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400192 { Opt_xprt_udp, "udp" },
Jeff Laytonee671b02009-12-03 15:58:56 -0500193 { Opt_xprt_udp6, "udp6" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400194 { Opt_xprt_tcp, "tcp" },
Jeff Laytonee671b02009-12-03 15:58:56 -0500195 { Opt_xprt_tcp6, "tcp6" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400196 { Opt_xprt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400197
198 { Opt_xprt_err, NULL }
199};
200
201enum {
202 Opt_sec_none, Opt_sec_sys,
203 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
204 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
205 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
206
207 Opt_sec_err
208};
209
Steven Whitehousea447c092008-10-13 10:46:57 +0100210static const match_table_t nfs_secflavor_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400211 { Opt_sec_none, "none" },
212 { Opt_sec_none, "null" },
213 { Opt_sec_sys, "sys" },
214
215 { Opt_sec_krb5, "krb5" },
216 { Opt_sec_krb5i, "krb5i" },
217 { Opt_sec_krb5p, "krb5p" },
218
219 { Opt_sec_lkey, "lkey" },
220 { Opt_sec_lkeyi, "lkeyi" },
221 { Opt_sec_lkeyp, "lkeyp" },
222
Olga Kornievskaia8d042212008-02-13 16:47:06 -0500223 { Opt_sec_spkm, "spkm3" },
224 { Opt_sec_spkmi, "spkm3i" },
225 { Opt_sec_spkmp, "spkm3p" },
226
Chuck Leverbf0fd762007-07-01 12:13:44 -0400227 { Opt_sec_err, NULL }
228};
229
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400230enum {
231 Opt_lookupcache_all, Opt_lookupcache_positive,
232 Opt_lookupcache_none,
233
234 Opt_lookupcache_err
235};
236
237static match_table_t nfs_lookupcache_tokens = {
238 { Opt_lookupcache_all, "all" },
239 { Opt_lookupcache_positive, "pos" },
240 { Opt_lookupcache_positive, "positive" },
241 { Opt_lookupcache_none, "none" },
242
243 { Opt_lookupcache_err, NULL }
244};
245
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400246enum {
247 Opt_local_lock_all, Opt_local_lock_flock, Opt_local_lock_posix,
248 Opt_local_lock_none,
249
250 Opt_local_lock_err
251};
252
253static match_table_t nfs_local_lock_tokens = {
254 { Opt_local_lock_all, "all" },
255 { Opt_local_lock_flock, "flock" },
256 { Opt_local_lock_posix, "posix" },
257 { Opt_local_lock_none, "none" },
258
259 { Opt_local_lock_err, NULL }
260};
261
Chuck Leverbf0fd762007-07-01 12:13:44 -0400262
Al Viro42faad92008-04-24 07:21:56 -0400263static void nfs_umount_begin(struct super_block *);
Trond Myklebust816724e2006-06-24 08:41:41 -0400264static int nfs_statfs(struct dentry *, struct kstatfs *);
Al Viro34c80b12011-12-08 21:32:45 -0500265static int nfs_show_options(struct seq_file *, struct dentry *);
Al Virod861c632011-12-08 21:32:45 -0500266static int nfs_show_devname(struct seq_file *, struct dentry *);
Al Viroa6322de2011-12-08 21:37:57 -0500267static int nfs_show_path(struct seq_file *, struct dentry *);
Al Viro64132372011-12-08 20:51:13 -0500268static int nfs_show_stats(struct seq_file *, struct dentry *);
Al Viro01194982011-03-16 07:25:36 -0400269static struct dentry *nfs_fs_mount(struct file_system_type *,
270 int, const char *, void *);
Al Viro31f43472010-10-29 03:38:12 -0400271static struct dentry *nfs_xdev_mount(struct file_system_type *fs_type,
272 int flags, const char *dev_name, void *raw_data);
Trond Myklebust387c1492010-02-03 08:27:35 -0500273static void nfs_put_super(struct super_block *);
David Howellsf7b422b2006-06-09 09:34:33 -0400274static void nfs_kill_super(struct super_block *);
Jeff Layton48b605f2008-06-10 15:38:39 -0400275static int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
David Howellsf7b422b2006-06-09 09:34:33 -0400276
277static struct file_system_type nfs_fs_type = {
278 .owner = THIS_MODULE,
279 .name = "nfs",
Al Viro01194982011-03-16 07:25:36 -0400280 .mount = nfs_fs_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400281 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700282 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400283};
284
David Howells54ceac42006-08-22 20:06:13 -0400285struct file_system_type nfs_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400286 .owner = THIS_MODULE,
287 .name = "nfs",
Al Viro31f43472010-10-29 03:38:12 -0400288 .mount = nfs_xdev_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400289 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700290 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400291};
292
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800293static const struct super_operations nfs_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400294 .alloc_inode = nfs_alloc_inode,
295 .destroy_inode = nfs_destroy_inode,
296 .write_inode = nfs_write_inode,
Trond Myklebust387c1492010-02-03 08:27:35 -0500297 .put_super = nfs_put_super,
David Howellsf7b422b2006-06-09 09:34:33 -0400298 .statfs = nfs_statfs,
Al Virob57922d2010-06-07 14:34:48 -0400299 .evict_inode = nfs_evict_inode,
David Howellsf7b422b2006-06-09 09:34:33 -0400300 .umount_begin = nfs_umount_begin,
301 .show_options = nfs_show_options,
Al Viroc7f404b2011-03-16 06:59:40 -0400302 .show_devname = nfs_show_devname,
303 .show_path = nfs_show_path,
David Howellsf7b422b2006-06-09 09:34:33 -0400304 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400305 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400306};
307
308#ifdef CONFIG_NFS_V4
Chuck Lever7630c852009-09-08 19:49:57 -0400309static int nfs4_validate_text_mount_data(void *options,
310 struct nfs_parsed_mount_data *args, const char *dev_name);
Al Viro01194982011-03-16 07:25:36 -0400311static struct dentry *nfs4_try_mount(int flags, const char *dev_name,
312 struct nfs_parsed_mount_data *data);
313static struct dentry *nfs4_mount(struct file_system_type *fs_type,
314 int flags, const char *dev_name, void *raw_data);
Al Viro31f43472010-10-29 03:38:12 -0400315static struct dentry *nfs4_remote_mount(struct file_system_type *fs_type,
316 int flags, const char *dev_name, void *raw_data);
317static struct dentry *nfs4_xdev_mount(struct file_system_type *fs_type,
318 int flags, const char *dev_name, void *raw_data);
Al Viro01194982011-03-16 07:25:36 -0400319static struct dentry *nfs4_referral_mount(struct file_system_type *fs_type,
320 int flags, const char *dev_name, void *raw_data);
Al Viro31f43472010-10-29 03:38:12 -0400321static struct dentry *nfs4_remote_referral_mount(struct file_system_type *fs_type,
322 int flags, const char *dev_name, void *raw_data);
David Howellsf7b422b2006-06-09 09:34:33 -0400323static void nfs4_kill_super(struct super_block *sb);
324
325static struct file_system_type nfs4_fs_type = {
326 .owner = THIS_MODULE,
327 .name = "nfs4",
Al Viro01194982011-03-16 07:25:36 -0400328 .mount = nfs4_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400329 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700330 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400331};
332
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400333static struct file_system_type nfs4_remote_fs_type = {
334 .owner = THIS_MODULE,
335 .name = "nfs4",
Al Viro31f43472010-10-29 03:38:12 -0400336 .mount = nfs4_remote_mount,
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400337 .kill_sb = nfs4_kill_super,
338 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
339};
340
David Howells54ceac42006-08-22 20:06:13 -0400341struct file_system_type nfs4_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400342 .owner = THIS_MODULE,
343 .name = "nfs4",
Al Viro31f43472010-10-29 03:38:12 -0400344 .mount = nfs4_xdev_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400345 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700346 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400347};
348
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400349static struct file_system_type nfs4_remote_referral_fs_type = {
350 .owner = THIS_MODULE,
351 .name = "nfs4",
Al Viro31f43472010-10-29 03:38:12 -0400352 .mount = nfs4_remote_referral_mount,
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400353 .kill_sb = nfs4_kill_super,
354 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
355};
356
David Howells54ceac42006-08-22 20:06:13 -0400357struct file_system_type nfs4_referral_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400358 .owner = THIS_MODULE,
359 .name = "nfs4",
Al Viro01194982011-03-16 07:25:36 -0400360 .mount = nfs4_referral_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400361 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700362 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400363};
364
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800365static const struct super_operations nfs4_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400366 .alloc_inode = nfs_alloc_inode,
367 .destroy_inode = nfs_destroy_inode,
368 .write_inode = nfs_write_inode,
Trond Myklebust387c1492010-02-03 08:27:35 -0500369 .put_super = nfs_put_super,
David Howellsf7b422b2006-06-09 09:34:33 -0400370 .statfs = nfs_statfs,
Al Virob57922d2010-06-07 14:34:48 -0400371 .evict_inode = nfs4_evict_inode,
David Howellsf7b422b2006-06-09 09:34:33 -0400372 .umount_begin = nfs_umount_begin,
373 .show_options = nfs_show_options,
Al Viroc7f404b2011-03-16 06:59:40 -0400374 .show_devname = nfs_show_devname,
375 .show_path = nfs_show_path,
David Howellsf7b422b2006-06-09 09:34:33 -0400376 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400377 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400378};
379#endif
380
Rusty Russell8e1f9362007-07-17 04:03:17 -0700381static struct shrinker acl_shrinker = {
382 .shrink = nfs_access_cache_shrinker,
383 .seeks = DEFAULT_SEEKS,
384};
Trond Myklebust979df722006-07-25 11:28:19 -0400385
David Howellsf7b422b2006-06-09 09:34:33 -0400386/*
387 * Register the NFS filesystems
388 */
389int __init register_nfs_fs(void)
390{
391 int ret;
392
393 ret = register_filesystem(&nfs_fs_type);
394 if (ret < 0)
395 goto error_0;
396
David Howellsf7b422b2006-06-09 09:34:33 -0400397 ret = nfs_register_sysctl();
398 if (ret < 0)
399 goto error_1;
Peter Zijlstra89a09142007-03-16 13:38:26 -0800400#ifdef CONFIG_NFS_V4
David Howellsf7b422b2006-06-09 09:34:33 -0400401 ret = register_filesystem(&nfs4_fs_type);
402 if (ret < 0)
403 goto error_2;
404#endif
Rusty Russell8e1f9362007-07-17 04:03:17 -0700405 register_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400406 return 0;
407
408#ifdef CONFIG_NFS_V4
409error_2:
410 nfs_unregister_sysctl();
Peter Zijlstra89a09142007-03-16 13:38:26 -0800411#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400412error_1:
413 unregister_filesystem(&nfs_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400414error_0:
415 return ret;
416}
417
418/*
419 * Unregister the NFS filesystems
420 */
421void __exit unregister_nfs_fs(void)
422{
Rusty Russell8e1f9362007-07-17 04:03:17 -0700423 unregister_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400424#ifdef CONFIG_NFS_V4
425 unregister_filesystem(&nfs4_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400426#endif
Alexey Dobriyan49af7ee2007-09-18 22:46:40 -0700427 nfs_unregister_sysctl();
David Howellsf7b422b2006-06-09 09:34:33 -0400428 unregister_filesystem(&nfs_fs_type);
429}
430
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400431void nfs_sb_active(struct super_block *sb)
Steve Dicksonef818a22007-11-08 04:05:04 -0500432{
433 struct nfs_server *server = NFS_SB(sb);
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400434
435 if (atomic_inc_return(&server->active) == 1)
436 atomic_inc(&sb->s_active);
437}
438
439void nfs_sb_deactive(struct super_block *sb)
440{
441 struct nfs_server *server = NFS_SB(sb);
442
443 if (atomic_dec_and_test(&server->active))
444 deactivate_super(sb);
Steve Dicksonef818a22007-11-08 04:05:04 -0500445}
446
David Howellsf7b422b2006-06-09 09:34:33 -0400447/*
448 * Deliver file system statistics to userspace
449 */
Trond Myklebust816724e2006-06-24 08:41:41 -0400450static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
David Howellsf7b422b2006-06-09 09:34:33 -0400451{
David Howells0c7d90c2006-08-22 20:06:10 -0400452 struct nfs_server *server = NFS_SB(dentry->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400453 unsigned char blockbits;
454 unsigned long blockres;
David Howells0c7d90c2006-08-22 20:06:10 -0400455 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400456 struct nfs_fsstat res;
457 int error = -ENOMEM;
458
459 res.fattr = nfs_alloc_fattr();
460 if (res.fattr == NULL)
461 goto out_err;
David Howellsf7b422b2006-06-09 09:34:33 -0400462
David Howells8fa5c002006-08-22 20:06:12 -0400463 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
Menyhart Zoltanfbf3fdd2010-09-12 19:55:26 -0400464 if (unlikely(error == -ESTALE)) {
465 struct dentry *pd_dentry;
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400466
Menyhart Zoltanfbf3fdd2010-09-12 19:55:26 -0400467 pd_dentry = dget_parent(dentry);
468 if (pd_dentry != NULL) {
469 nfs_zap_caches(pd_dentry->d_inode);
470 dput(pd_dentry);
471 }
472 }
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400473 nfs_free_fattr(res.fattr);
David Howellsf7b422b2006-06-09 09:34:33 -0400474 if (error < 0)
475 goto out_err;
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400476
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700477 buf->f_type = NFS_SUPER_MAGIC;
David Howellsf7b422b2006-06-09 09:34:33 -0400478
479 /*
480 * Current versions of glibc do not correctly handle the
481 * case where f_frsize != f_bsize. Eventually we want to
482 * report the value of wtmult in this field.
483 */
David Howells0c7d90c2006-08-22 20:06:10 -0400484 buf->f_frsize = dentry->d_sb->s_blocksize;
David Howellsf7b422b2006-06-09 09:34:33 -0400485
486 /*
487 * On most *nix systems, f_blocks, f_bfree, and f_bavail
488 * are reported in units of f_frsize. Linux hasn't had
489 * an f_frsize field in its statfs struct until recently,
490 * thus historically Linux's sys_statfs reports these
491 * fields in units of f_bsize.
492 */
David Howells0c7d90c2006-08-22 20:06:10 -0400493 buf->f_bsize = dentry->d_sb->s_blocksize;
494 blockbits = dentry->d_sb->s_blocksize_bits;
David Howellsf7b422b2006-06-09 09:34:33 -0400495 blockres = (1 << blockbits) - 1;
496 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
497 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
498 buf->f_bavail = (res.abytes + blockres) >> blockbits;
499
500 buf->f_files = res.tfiles;
501 buf->f_ffree = res.afiles;
502
503 buf->f_namelen = server->namelen;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700504
David Howellsf7b422b2006-06-09 09:34:33 -0400505 return 0;
506
507 out_err:
Harvey Harrison3110ff82008-05-02 13:42:44 -0700508 dprintk("%s: statfs error = %d\n", __func__, -error);
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700509 return error;
David Howellsf7b422b2006-06-09 09:34:33 -0400510}
511
David Howells7d4e2742006-08-22 20:06:07 -0400512/*
513 * Map the security flavour number to a name
514 */
Trond Myklebust81039f12006-06-09 09:34:34 -0400515static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
516{
David Howells7d4e2742006-08-22 20:06:07 -0400517 static const struct {
Trond Myklebust81039f12006-06-09 09:34:34 -0400518 rpc_authflavor_t flavour;
519 const char *str;
520 } sec_flavours[] = {
521 { RPC_AUTH_NULL, "null" },
522 { RPC_AUTH_UNIX, "sys" },
523 { RPC_AUTH_GSS_KRB5, "krb5" },
524 { RPC_AUTH_GSS_KRB5I, "krb5i" },
525 { RPC_AUTH_GSS_KRB5P, "krb5p" },
526 { RPC_AUTH_GSS_LKEY, "lkey" },
527 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
528 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
529 { RPC_AUTH_GSS_SPKM, "spkm" },
530 { RPC_AUTH_GSS_SPKMI, "spkmi" },
531 { RPC_AUTH_GSS_SPKMP, "spkmp" },
Chuck Lever4d81cd12007-07-01 12:12:40 -0400532 { UINT_MAX, "unknown" }
Trond Myklebust81039f12006-06-09 09:34:34 -0400533 };
534 int i;
535
Chuck Lever4d81cd12007-07-01 12:12:40 -0400536 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
Trond Myklebust81039f12006-06-09 09:34:34 -0400537 if (sec_flavours[i].flavour == flavour)
538 break;
539 }
540 return sec_flavours[i].str;
541}
542
Jeff Laytonee671b02009-12-03 15:58:56 -0500543static void nfs_show_mountd_netid(struct seq_file *m, struct nfs_server *nfss,
544 int showdefaults)
545{
546 struct sockaddr *sap = (struct sockaddr *) &nfss->mountd_address;
547
548 seq_printf(m, ",mountproto=");
549 switch (sap->sa_family) {
550 case AF_INET:
551 switch (nfss->mountd_protocol) {
552 case IPPROTO_UDP:
553 seq_printf(m, RPCBIND_NETID_UDP);
554 break;
555 case IPPROTO_TCP:
556 seq_printf(m, RPCBIND_NETID_TCP);
557 break;
558 default:
559 if (showdefaults)
560 seq_printf(m, "auto");
561 }
562 break;
563 case AF_INET6:
564 switch (nfss->mountd_protocol) {
565 case IPPROTO_UDP:
566 seq_printf(m, RPCBIND_NETID_UDP6);
567 break;
568 case IPPROTO_TCP:
569 seq_printf(m, RPCBIND_NETID_TCP6);
570 break;
571 default:
572 if (showdefaults)
573 seq_printf(m, "auto");
574 }
575 break;
576 default:
577 if (showdefaults)
578 seq_printf(m, "auto");
579 }
580}
581
Chuck Lever82d101d2008-03-14 14:10:37 -0400582static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
583 int showdefaults)
584{
585 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
586
Bryan Schumakerd5eff1a2010-08-03 13:04:00 -0400587 if (nfss->flags & NFS_MOUNT_LEGACY_INTERFACE)
588 return;
589
Chuck Lever82d101d2008-03-14 14:10:37 -0400590 switch (sap->sa_family) {
591 case AF_INET: {
592 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
Harvey Harrisonbe859402008-10-31 00:56:28 -0700593 seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400594 break;
595 }
596 case AF_INET6: {
597 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
Chuck Leverd250e192009-12-03 15:58:56 -0500598 seq_printf(m, ",mountaddr=%pI6c", &sin6->sin6_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400599 break;
600 }
601 default:
602 if (showdefaults)
603 seq_printf(m, ",mountaddr=unspecified");
604 }
605
606 if (nfss->mountd_version || showdefaults)
607 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
Stanislav Kinsburskyaa699472010-12-08 12:40:13 +0300608 if ((nfss->mountd_port &&
609 nfss->mountd_port != (unsigned short)NFS_UNSPEC_PORT) ||
610 showdefaults)
Chuck Lever82d101d2008-03-14 14:10:37 -0400611 seq_printf(m, ",mountport=%u", nfss->mountd_port);
612
Jeff Laytonee671b02009-12-03 15:58:56 -0500613 nfs_show_mountd_netid(m, nfss, showdefaults);
Chuck Lever82d101d2008-03-14 14:10:37 -0400614}
615
Trond Myklebust0be81892010-06-18 12:23:58 -0400616#ifdef CONFIG_NFS_V4
617static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
618 int showdefaults)
619{
620 struct nfs_client *clp = nfss->nfs_client;
621
622 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
623 seq_printf(m, ",minorversion=%u", clp->cl_minorversion);
624}
625#else
626static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
627 int showdefaults)
628{
629}
630#endif
631
David Howellsf7b422b2006-06-09 09:34:33 -0400632/*
633 * Describe the mount options in force on this server representation
634 */
Chuck Lever82d101d2008-03-14 14:10:37 -0400635static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
636 int showdefaults)
David Howellsf7b422b2006-06-09 09:34:33 -0400637{
David Howells509de812006-08-22 20:06:11 -0400638 static const struct proc_nfs_info {
David Howellsf7b422b2006-06-09 09:34:33 -0400639 int flag;
David Howells509de812006-08-22 20:06:11 -0400640 const char *str;
641 const char *nostr;
David Howellsf7b422b2006-06-09 09:34:33 -0400642 } nfs_info[] = {
643 { NFS_MOUNT_SOFT, ",soft", ",hard" },
Chuck Lever82d101d2008-03-14 14:10:37 -0400644 { NFS_MOUNT_POSIX, ",posix", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400645 { NFS_MOUNT_NOCTO, ",nocto", "" },
646 { NFS_MOUNT_NOAC, ",noac", "" },
647 { NFS_MOUNT_NONLM, ",nolock", "" },
648 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400649 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
Chuck Leverd7403512008-12-23 15:21:37 -0500650 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
651 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400652 { 0, NULL, NULL }
653 };
David Howells509de812006-08-22 20:06:11 -0400654 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400655 struct nfs_client *clp = nfss->nfs_client;
Chuck Lever82d101d2008-03-14 14:10:37 -0400656 u32 version = clp->rpc_ops->version;
Suresh Jayaraman7c563cc2010-09-23 14:26:48 -0400657 int local_flock, local_fcntl;
David Howellsf7b422b2006-06-09 09:34:33 -0400658
Chuck Lever82d101d2008-03-14 14:10:37 -0400659 seq_printf(m, ",vers=%u", version);
Chuck Lever2d767432008-03-14 14:10:08 -0400660 seq_printf(m, ",rsize=%u", nfss->rsize);
661 seq_printf(m, ",wsize=%u", nfss->wsize);
Chuck Lever82d101d2008-03-14 14:10:37 -0400662 if (nfss->bsize != 0)
663 seq_printf(m, ",bsize=%u", nfss->bsize);
664 seq_printf(m, ",namlen=%u", nfss->namelen);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400665 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400666 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400667 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400668 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400669 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400670 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400671 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400672 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
David Howellsf7b422b2006-06-09 09:34:33 -0400673 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
674 if (nfss->flags & nfs_infop->flag)
675 seq_puts(m, nfs_infop->str);
676 else
677 seq_puts(m, nfs_infop->nostr);
678 }
\"Talpey, Thomas\56928ed2007-09-10 13:48:47 -0400679 seq_printf(m, ",proto=%s",
Jeff Laytonee671b02009-12-03 15:58:56 -0500680 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
Chuck Lever82d101d2008-03-14 14:10:37 -0400681 if (version == 4) {
682 if (nfss->port != NFS_PORT)
683 seq_printf(m, ",port=%u", nfss->port);
684 } else
685 if (nfss->port)
686 seq_printf(m, ",port=%u", nfss->port);
687
Trond Myklebust33170232007-12-20 16:03:59 -0500688 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
689 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
Trond Myklebust81039f12006-06-09 09:34:34 -0400690 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
Chuck Lever82d101d2008-03-14 14:10:37 -0400691
692 if (version != 4)
693 nfs_show_mountd_options(m, nfss, showdefaults);
Trond Myklebust0be81892010-06-18 12:23:58 -0400694 else
695 nfs_show_nfsv4_options(m, nfss, showdefaults);
Chuck Lever82d101d2008-03-14 14:10:37 -0400696
David Howellsb797cac2009-04-03 16:42:48 +0100697 if (nfss->options & NFS_OPTION_FSCACHE)
698 seq_printf(m, ",fsc");
Patrick J. LoPresti9b00c642010-08-10 17:28:01 -0400699
700 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONEG) {
701 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONE)
702 seq_printf(m, ",lookupcache=none");
703 else
704 seq_printf(m, ",lookupcache=pos");
705 }
Suresh Jayaraman7c563cc2010-09-23 14:26:48 -0400706
707 local_flock = nfss->flags & NFS_MOUNT_LOCAL_FLOCK;
708 local_fcntl = nfss->flags & NFS_MOUNT_LOCAL_FCNTL;
709
710 if (!local_flock && !local_fcntl)
711 seq_printf(m, ",local_lock=none");
712 else if (local_flock && local_fcntl)
713 seq_printf(m, ",local_lock=all");
714 else if (local_flock)
715 seq_printf(m, ",local_lock=flock");
716 else
717 seq_printf(m, ",local_lock=posix");
David Howellsf7b422b2006-06-09 09:34:33 -0400718}
719
720/*
721 * Describe the mount options on this VFS mountpoint
722 */
Al Viro34c80b12011-12-08 21:32:45 -0500723static int nfs_show_options(struct seq_file *m, struct dentry *root)
David Howellsf7b422b2006-06-09 09:34:33 -0400724{
Al Viro34c80b12011-12-08 21:32:45 -0500725 struct nfs_server *nfss = NFS_SB(root->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400726
727 nfs_show_mount_options(m, nfss, 0);
728
Chuck Lever5d8515c2007-12-10 14:57:16 -0500729 seq_printf(m, ",addr=%s",
730 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
731 RPC_DISPLAY_ADDR));
David Howellsf7b422b2006-06-09 09:34:33 -0400732
733 return 0;
734}
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700735
736#ifdef CONFIG_NFS_V4
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300737#ifdef CONFIG_NFS_V4_1
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700738static void show_sessions(struct seq_file *m, struct nfs_server *server)
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300739{
740 if (nfs4_has_session(server->nfs_client))
741 seq_printf(m, ",sessions");
742}
743#else
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700744static void show_sessions(struct seq_file *m, struct nfs_server *server) {}
745#endif
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300746#endif
747
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700748#ifdef CONFIG_NFS_V4
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300749#ifdef CONFIG_NFS_V4_1
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700750static void show_pnfs(struct seq_file *m, struct nfs_server *server)
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300751{
752 seq_printf(m, ",pnfs=");
753 if (server->pnfs_curr_ld)
754 seq_printf(m, "%s", server->pnfs_curr_ld->name);
755 else
756 seq_printf(m, "not configured");
757}
H Hartley Sweeten45402c382011-09-02 14:39:12 -0700758#else
759static void show_pnfs(struct seq_file *m, struct nfs_server *server) {}
760#endif
761#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400762
Al Virod861c632011-12-08 21:32:45 -0500763static int nfs_show_devname(struct seq_file *m, struct dentry *root)
Al Viroc7f404b2011-03-16 06:59:40 -0400764{
765 char *page = (char *) __get_free_page(GFP_KERNEL);
766 char *devname, *dummy;
767 int err = 0;
768 if (!page)
769 return -ENOMEM;
Al Virod861c632011-12-08 21:32:45 -0500770 devname = nfs_path(&dummy, root, page, PAGE_SIZE);
Al Viroc7f404b2011-03-16 06:59:40 -0400771 if (IS_ERR(devname))
772 err = PTR_ERR(devname);
773 else
774 seq_escape(m, devname, " \t\n\\");
775 free_page((unsigned long)page);
776 return err;
777}
778
Al Viroa6322de2011-12-08 21:37:57 -0500779static int nfs_show_path(struct seq_file *m, struct dentry *dentry)
Al Viroc7f404b2011-03-16 06:59:40 -0400780{
781 seq_puts(m, "/");
782 return 0;
783}
784
David Howellsf7b422b2006-06-09 09:34:33 -0400785/*
786 * Present statistical information for this VFS mountpoint
787 */
Al Viro64132372011-12-08 20:51:13 -0500788static int nfs_show_stats(struct seq_file *m, struct dentry *root)
David Howellsf7b422b2006-06-09 09:34:33 -0400789{
790 int i, cpu;
Al Viro64132372011-12-08 20:51:13 -0500791 struct nfs_server *nfss = NFS_SB(root->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400792 struct rpc_auth *auth = nfss->client->cl_auth;
793 struct nfs_iostats totals = { };
794
795 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
796
797 /*
798 * Display all mount option settings
799 */
800 seq_printf(m, "\n\topts:\t");
Al Viro64132372011-12-08 20:51:13 -0500801 seq_puts(m, root->d_sb->s_flags & MS_RDONLY ? "ro" : "rw");
802 seq_puts(m, root->d_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
803 seq_puts(m, root->d_sb->s_flags & MS_NOATIME ? ",noatime" : "");
804 seq_puts(m, root->d_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
David Howellsf7b422b2006-06-09 09:34:33 -0400805 nfs_show_mount_options(m, nfss, 1);
806
807 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
808
809 seq_printf(m, "\n\tcaps:\t");
810 seq_printf(m, "caps=0x%x", nfss->caps);
Chuck Lever2d767432008-03-14 14:10:08 -0400811 seq_printf(m, ",wtmult=%u", nfss->wtmult);
812 seq_printf(m, ",dtsize=%u", nfss->dtsize);
813 seq_printf(m, ",bsize=%u", nfss->bsize);
814 seq_printf(m, ",namlen=%u", nfss->namelen);
David Howellsf7b422b2006-06-09 09:34:33 -0400815
816#ifdef CONFIG_NFS_V4
Trond Myklebust40c553192007-12-14 14:56:07 -0500817 if (nfss->nfs_client->rpc_ops->version == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400818 seq_printf(m, "\n\tnfsv4:\t");
819 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
820 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
821 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
J. Bruce Fieldsae50c0b2011-05-22 19:48:21 +0300822 show_sessions(m, nfss);
823 show_pnfs(m, nfss);
David Howellsf7b422b2006-06-09 09:34:33 -0400824 }
825#endif
826
827 /*
828 * Display security flavor in effect for this mount
829 */
Chuck Lever2d767432008-03-14 14:10:08 -0400830 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400831 if (auth->au_flavor)
Chuck Lever2d767432008-03-14 14:10:08 -0400832 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400833
834 /*
835 * Display superblock I/O counters
836 */
837 for_each_possible_cpu(cpu) {
838 struct nfs_iostats *stats;
839
840 preempt_disable();
841 stats = per_cpu_ptr(nfss->io_stats, cpu);
842
843 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
844 totals.events[i] += stats->events[i];
845 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
846 totals.bytes[i] += stats->bytes[i];
David Howells6a510912009-04-03 16:42:43 +0100847#ifdef CONFIG_NFS_FSCACHE
848 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
849 totals.fscache[i] += stats->fscache[i];
850#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400851
852 preempt_enable();
853 }
854
855 seq_printf(m, "\n\tevents:\t");
856 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
857 seq_printf(m, "%lu ", totals.events[i]);
858 seq_printf(m, "\n\tbytes:\t");
859 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
860 seq_printf(m, "%Lu ", totals.bytes[i]);
David Howells6a510912009-04-03 16:42:43 +0100861#ifdef CONFIG_NFS_FSCACHE
862 if (nfss->options & NFS_OPTION_FSCACHE) {
863 seq_printf(m, "\n\tfsc:\t");
864 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
865 seq_printf(m, "%Lu ", totals.bytes[i]);
866 }
867#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400868 seq_printf(m, "\n");
869
870 rpc_print_iostats(m, nfss->client);
871
872 return 0;
873}
874
875/*
876 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400877 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400878 */
Al Viro42faad92008-04-24 07:21:56 -0400879static void nfs_umount_begin(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -0400880{
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200881 struct nfs_server *server;
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400882 struct rpc_clnt *rpc;
883
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200884 server = NFS_SB(sb);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400885 /* -EIO all pending I/O */
886 rpc = server->client_acl;
887 if (!IS_ERR(rpc))
888 rpc_killall_tasks(rpc);
889 rpc = server->client;
890 if (!IS_ERR(rpc))
891 rpc_killall_tasks(rpc);
David Howellsf7b422b2006-06-09 09:34:33 -0400892}
893
Trond Myklebustc5811db2009-10-06 15:40:15 -0400894static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(unsigned int version)
Chuck Lever9423a082009-09-23 14:36:38 -0400895{
896 struct nfs_parsed_mount_data *data;
897
898 data = kzalloc(sizeof(*data), GFP_KERNEL);
899 if (data) {
Chuck Lever9423a082009-09-23 14:36:38 -0400900 data->acregmin = NFS_DEF_ACREGMIN;
901 data->acregmax = NFS_DEF_ACREGMAX;
902 data->acdirmin = NFS_DEF_ACDIRMIN;
903 data->acdirmax = NFS_DEF_ACDIRMAX;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400904 data->mount_server.port = NFS_UNSPEC_PORT;
Chuck Lever9423a082009-09-23 14:36:38 -0400905 data->nfs_server.port = NFS_UNSPEC_PORT;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400906 data->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Lever9423a082009-09-23 14:36:38 -0400907 data->auth_flavors[0] = RPC_AUTH_UNIX;
908 data->auth_flavor_len = 1;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400909 data->version = version;
Chuck Lever9423a082009-09-23 14:36:38 -0400910 data->minorversion = 0;
911 }
912 return data;
913}
914
David Howellsf7b422b2006-06-09 09:34:33 -0400915/*
Chuck Levercdcd7f92007-12-10 14:57:45 -0500916 * Sanity-check a server address provided by the mount command.
917 *
918 * Address family must be initialized, and address must not be
919 * the ANY address for that family.
Chuck Leverfc50d582007-07-01 12:12:46 -0400920 */
921static int nfs_verify_server_address(struct sockaddr *addr)
922{
923 switch (addr->sa_family) {
924 case AF_INET: {
Chuck Levercdcd7f92007-12-10 14:57:45 -0500925 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
Al Viroe6f1ceb2008-03-17 22:44:53 -0700926 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
Chuck Levercdcd7f92007-12-10 14:57:45 -0500927 }
928 case AF_INET6: {
929 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
930 return !ipv6_addr_any(sa);
Chuck Leverfc50d582007-07-01 12:12:46 -0400931 }
932 }
933
Chuck Lever53a0b9c2009-08-09 15:09:36 -0400934 dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
Chuck Leverfc50d582007-07-01 12:12:46 -0400935 return 0;
936}
937
Chuck Lever9412b922007-12-10 14:59:21 -0500938/*
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400939 * Select between a default port value and a user-specified port value.
940 * If a zero value is set, then autobind will be used.
941 */
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400942static void nfs_set_port(struct sockaddr *sap, int *port,
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400943 const unsigned short default_port)
944{
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400945 if (*port == NFS_UNSPEC_PORT)
946 *port = default_port;
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400947
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400948 rpc_set_port(sap, *port);
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400949}
950
951/*
Trond Myklebust259875e2008-07-02 14:43:47 -0400952 * Sanity check the NFS transport protocol.
953 *
954 */
955static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
956{
957 switch (mnt->nfs_server.protocol) {
958 case XPRT_TRANSPORT_UDP:
959 case XPRT_TRANSPORT_TCP:
960 case XPRT_TRANSPORT_RDMA:
961 break;
962 default:
963 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
964 }
965}
966
967/*
968 * For text based NFSv2/v3 mounts, the mount protocol transport default
969 * settings should depend upon the specified NFS transport.
970 */
971static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
972{
973 nfs_validate_transport_protocol(mnt);
974
975 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
976 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
977 return;
978 switch (mnt->nfs_server.protocol) {
979 case XPRT_TRANSPORT_UDP:
980 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
981 break;
982 case XPRT_TRANSPORT_TCP:
983 case XPRT_TRANSPORT_RDMA:
984 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
985 }
986}
987
988/*
Chuck Lever01060c82008-06-24 16:33:38 -0400989 * Parse the value of the 'sec=' option.
Chuck Lever01060c82008-06-24 16:33:38 -0400990 */
991static int nfs_parse_security_flavors(char *value,
992 struct nfs_parsed_mount_data *mnt)
993{
994 substring_t args[MAX_OPT_ARGS];
995
996 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
997
998 switch (match_token(value, nfs_secflavor_tokens, args)) {
999 case Opt_sec_none:
Chuck Lever01060c82008-06-24 16:33:38 -04001000 mnt->auth_flavors[0] = RPC_AUTH_NULL;
1001 break;
1002 case Opt_sec_sys:
Chuck Lever01060c82008-06-24 16:33:38 -04001003 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
1004 break;
1005 case Opt_sec_krb5:
Chuck Lever01060c82008-06-24 16:33:38 -04001006 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
1007 break;
1008 case Opt_sec_krb5i:
Chuck Lever01060c82008-06-24 16:33:38 -04001009 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
1010 break;
1011 case Opt_sec_krb5p:
Chuck Lever01060c82008-06-24 16:33:38 -04001012 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
1013 break;
1014 case Opt_sec_lkey:
Chuck Lever01060c82008-06-24 16:33:38 -04001015 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
1016 break;
1017 case Opt_sec_lkeyi:
Chuck Lever01060c82008-06-24 16:33:38 -04001018 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
1019 break;
1020 case Opt_sec_lkeyp:
Chuck Lever01060c82008-06-24 16:33:38 -04001021 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
1022 break;
1023 case Opt_sec_spkm:
Chuck Lever01060c82008-06-24 16:33:38 -04001024 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
1025 break;
1026 case Opt_sec_spkmi:
Chuck Lever01060c82008-06-24 16:33:38 -04001027 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
1028 break;
1029 case Opt_sec_spkmp:
Chuck Lever01060c82008-06-24 16:33:38 -04001030 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
1031 break;
1032 default:
1033 return 0;
1034 }
1035
Bryan Schumaker9b7160c2011-04-13 14:31:30 -04001036 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
Chuck Lever059f90b2009-08-09 15:09:31 -04001037 mnt->auth_flavor_len = 1;
Chuck Lever01060c82008-06-24 16:33:38 -04001038 return 1;
1039}
1040
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001041static int nfs_get_option_str(substring_t args[], char **option)
1042{
1043 kfree(*option);
1044 *option = match_strdup(args);
1045 return !option;
1046}
1047
1048static int nfs_get_option_ul(substring_t args[], unsigned long *option)
1049{
1050 int rc;
1051 char *string;
1052
1053 string = match_strdup(args);
1054 if (string == NULL)
1055 return -ENOMEM;
1056 rc = strict_strtoul(string, 10, option);
1057 kfree(string);
1058
1059 return rc;
1060}
1061
Chuck Lever01060c82008-06-24 16:33:38 -04001062/*
Chuck Leverbf0fd762007-07-01 12:13:44 -04001063 * Error-check and convert a string of mount options from user space into
Chuck Leverf45663c2008-06-24 19:28:02 -04001064 * a data structure. The whole mount string is processed; bad options are
1065 * skipped as they are encountered. If there were no errors, return 1;
1066 * otherwise return 0 (zero).
Chuck Leverbf0fd762007-07-01 12:13:44 -04001067 */
1068static int nfs_parse_mount_options(char *raw,
1069 struct nfs_parsed_mount_data *mnt)
1070{
Eric Parisf9c3a382008-03-05 14:20:18 -05001071 char *p, *string, *secdata;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001072 int rc, sloppy = 0, invalid_option = 0;
Jeff Laytonee671b02009-12-03 15:58:56 -05001073 unsigned short protofamily = AF_UNSPEC;
1074 unsigned short mountfamily = AF_UNSPEC;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001075
1076 if (!raw) {
1077 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
1078 return 1;
1079 }
1080 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
1081
Eric Parisf9c3a382008-03-05 14:20:18 -05001082 secdata = alloc_secdata();
1083 if (!secdata)
1084 goto out_nomem;
1085
1086 rc = security_sb_copy_data(raw, secdata);
1087 if (rc)
1088 goto out_security_failure;
1089
1090 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
1091 if (rc)
1092 goto out_security_failure;
1093
1094 free_secdata(secdata);
1095
Chuck Leverbf0fd762007-07-01 12:13:44 -04001096 while ((p = strsep(&raw, ",")) != NULL) {
1097 substring_t args[MAX_OPT_ARGS];
Chuck Levera5a16ba2009-06-17 18:02:14 -07001098 unsigned long option;
1099 int token;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001100
1101 if (!*p)
1102 continue;
1103
1104 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
1105
1106 token = match_token(p, nfs_mount_option_tokens, args);
1107 switch (token) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001108
1109 /*
1110 * boolean options: foo/nofoo
1111 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001112 case Opt_soft:
1113 mnt->flags |= NFS_MOUNT_SOFT;
1114 break;
1115 case Opt_hard:
1116 mnt->flags &= ~NFS_MOUNT_SOFT;
1117 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001118 case Opt_posix:
1119 mnt->flags |= NFS_MOUNT_POSIX;
1120 break;
1121 case Opt_noposix:
1122 mnt->flags &= ~NFS_MOUNT_POSIX;
1123 break;
1124 case Opt_cto:
1125 mnt->flags &= ~NFS_MOUNT_NOCTO;
1126 break;
1127 case Opt_nocto:
1128 mnt->flags |= NFS_MOUNT_NOCTO;
1129 break;
1130 case Opt_ac:
1131 mnt->flags &= ~NFS_MOUNT_NOAC;
1132 break;
1133 case Opt_noac:
1134 mnt->flags |= NFS_MOUNT_NOAC;
1135 break;
1136 case Opt_lock:
1137 mnt->flags &= ~NFS_MOUNT_NONLM;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001138 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1139 NFS_MOUNT_LOCAL_FCNTL);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001140 break;
1141 case Opt_nolock:
1142 mnt->flags |= NFS_MOUNT_NONLM;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001143 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1144 NFS_MOUNT_LOCAL_FCNTL);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001145 break;
1146 case Opt_v2:
1147 mnt->flags &= ~NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -04001148 mnt->version = 2;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001149 break;
1150 case Opt_v3:
1151 mnt->flags |= NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -04001152 mnt->version = 3;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001153 break;
Chuck Lever764302c2009-09-08 19:50:03 -04001154 case Opt_v4:
1155 mnt->flags &= ~NFS_MOUNT_VER3;
1156 mnt->version = 4;
1157 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001158 case Opt_udp:
1159 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001160 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001161 break;
1162 case Opt_tcp:
1163 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001164 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001165 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001166 case Opt_rdma:
1167 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1168 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001169 xprt_load_transport(p);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001170 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001171 case Opt_acl:
1172 mnt->flags &= ~NFS_MOUNT_NOACL;
1173 break;
1174 case Opt_noacl:
1175 mnt->flags |= NFS_MOUNT_NOACL;
1176 break;
1177 case Opt_rdirplus:
1178 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1179 break;
1180 case Opt_nordirplus:
1181 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1182 break;
Trond Myklebust75180df2007-05-16 16:53:28 -04001183 case Opt_sharecache:
1184 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1185 break;
1186 case Opt_nosharecache:
1187 mnt->flags |= NFS_MOUNT_UNSHARED;
1188 break;
Chuck Leverd7403512008-12-23 15:21:37 -05001189 case Opt_resvport:
1190 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1191 break;
1192 case Opt_noresvport:
1193 mnt->flags |= NFS_MOUNT_NORESVPORT;
1194 break;
David Howellsb797cac2009-04-03 16:42:48 +01001195 case Opt_fscache:
1196 mnt->options |= NFS_OPTION_FSCACHE;
1197 kfree(mnt->fscache_uniq);
1198 mnt->fscache_uniq = NULL;
1199 break;
1200 case Opt_nofscache:
1201 mnt->options &= ~NFS_OPTION_FSCACHE;
1202 kfree(mnt->fscache_uniq);
1203 mnt->fscache_uniq = NULL;
1204 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001205
Chuck Leverf45663c2008-06-24 19:28:02 -04001206 /*
1207 * options that take numeric values
1208 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001209 case Opt_port:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001210 if (nfs_get_option_ul(args, &option) ||
1211 option > USHRT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001212 goto out_invalid_value;
1213 mnt->nfs_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001214 break;
1215 case Opt_rsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001216 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001217 goto out_invalid_value;
1218 mnt->rsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001219 break;
1220 case Opt_wsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001221 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001222 goto out_invalid_value;
1223 mnt->wsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001224 break;
1225 case Opt_bsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001226 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001227 goto out_invalid_value;
1228 mnt->bsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001229 break;
1230 case Opt_timeo:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001231 if (nfs_get_option_ul(args, &option) || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001232 goto out_invalid_value;
1233 mnt->timeo = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001234 break;
1235 case Opt_retrans:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001236 if (nfs_get_option_ul(args, &option) || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001237 goto out_invalid_value;
1238 mnt->retrans = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001239 break;
1240 case Opt_acregmin:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001241 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001242 goto out_invalid_value;
1243 mnt->acregmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001244 break;
1245 case Opt_acregmax:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001246 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001247 goto out_invalid_value;
1248 mnt->acregmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001249 break;
1250 case Opt_acdirmin:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001251 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001252 goto out_invalid_value;
1253 mnt->acdirmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001254 break;
1255 case Opt_acdirmax:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001256 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001257 goto out_invalid_value;
1258 mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001259 break;
1260 case Opt_actimeo:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001261 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001262 goto out_invalid_value;
1263 mnt->acregmin = mnt->acregmax =
1264 mnt->acdirmin = mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001265 break;
1266 case Opt_namelen:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001267 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001268 goto out_invalid_value;
1269 mnt->namlen = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001270 break;
1271 case Opt_mountport:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001272 if (nfs_get_option_ul(args, &option) ||
1273 option > USHRT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001274 goto out_invalid_value;
1275 mnt->mount_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001276 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001277 case Opt_mountvers:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001278 if (nfs_get_option_ul(args, &option) ||
Chuck Leverf45663c2008-06-24 19:28:02 -04001279 option < NFS_MNT_VERSION ||
Chuck Leverd23c45f2009-06-17 18:02:13 -07001280 option > NFS_MNT3_VERSION)
1281 goto out_invalid_value;
1282 mnt->mount_server.version = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001283 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001284 case Opt_nfsvers:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001285 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001286 goto out_invalid_value;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001287 switch (option) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001288 case NFS2_VERSION:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001289 mnt->flags &= ~NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -04001290 mnt->version = 2;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001291 break;
Chuck Leverf45663c2008-06-24 19:28:02 -04001292 case NFS3_VERSION:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001293 mnt->flags |= NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -04001294 mnt->version = 3;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001295 break;
Chuck Lever764302c2009-09-08 19:50:03 -04001296 case NFS4_VERSION:
1297 mnt->flags &= ~NFS_MOUNT_VER3;
1298 mnt->version = 4;
1299 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001300 default:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001301 goto out_invalid_value;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001302 }
1303 break;
Mike Sager3fd5be92009-04-01 09:21:48 -04001304 case Opt_minorversion:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001305 if (nfs_get_option_ul(args, &option))
Chuck Leverf3f4f4e2009-08-09 15:09:29 -04001306 goto out_invalid_value;
1307 if (option > NFS4_MAX_MINOR_VERSION)
1308 goto out_invalid_value;
1309 mnt->minorversion = option;
Mike Sager3fd5be92009-04-01 09:21:48 -04001310 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001311
Chuck Leverf45663c2008-06-24 19:28:02 -04001312 /*
1313 * options that take text values
1314 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001315 case Opt_sec:
1316 string = match_strdup(args);
1317 if (string == NULL)
1318 goto out_nomem;
Chuck Lever01060c82008-06-24 16:33:38 -04001319 rc = nfs_parse_security_flavors(string, mnt);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001320 kfree(string);
Chuck Leverf45663c2008-06-24 19:28:02 -04001321 if (!rc) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001322 dfprintk(MOUNT, "NFS: unrecognized "
1323 "security flavor\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001324 return 0;
Chuck Leverf45663c2008-06-24 19:28:02 -04001325 }
Chuck Leverbf0fd762007-07-01 12:13:44 -04001326 break;
1327 case Opt_proto:
1328 string = match_strdup(args);
1329 if (string == NULL)
1330 goto out_nomem;
1331 token = match_token(string,
1332 nfs_xprt_protocol_tokens, args);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001333
Jeff Laytonee671b02009-12-03 15:58:56 -05001334 protofamily = AF_INET;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001335 switch (token) {
Jeff Laytonee671b02009-12-03 15:58:56 -05001336 case Opt_xprt_udp6:
1337 protofamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001338 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001339 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001340 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001341 break;
Jeff Laytonee671b02009-12-03 15:58:56 -05001342 case Opt_xprt_tcp6:
1343 protofamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001344 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001345 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001346 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001347 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001348 case Opt_xprt_rdma:
1349 /* vector side protocols to TCP */
1350 mnt->flags |= NFS_MOUNT_TCP;
1351 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001352 xprt_load_transport(string);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001353 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001354 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001355 dfprintk(MOUNT, "NFS: unrecognized "
1356 "transport protocol\n");
Yinghai Lu4223a4a2009-10-20 14:13:46 +09001357 kfree(string);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001358 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001359 }
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001360 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001361 break;
1362 case Opt_mountproto:
1363 string = match_strdup(args);
1364 if (string == NULL)
1365 goto out_nomem;
1366 token = match_token(string,
1367 nfs_xprt_protocol_tokens, args);
Trond Myklebustd508afb2009-04-06 16:41:35 -07001368 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001369
Jeff Laytonee671b02009-12-03 15:58:56 -05001370 mountfamily = 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 mountfamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001374 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001375 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001376 break;
Jeff Laytonee671b02009-12-03 15:58:56 -05001377 case Opt_xprt_tcp6:
1378 mountfamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001379 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001380 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001381 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001382 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001383 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001384 dfprintk(MOUNT, "NFS: unrecognized "
1385 "transport protocol\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001386 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001387 }
1388 break;
1389 case Opt_addr:
1390 string = match_strdup(args);
1391 if (string == NULL)
1392 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001393 mnt->nfs_server.addrlen =
1394 rpc_pton(string, strlen(string),
1395 (struct sockaddr *)
1396 &mnt->nfs_server.address,
1397 sizeof(mnt->nfs_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001398 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001399 if (mnt->nfs_server.addrlen == 0)
1400 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001401 break;
1402 case Opt_clientaddr:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001403 if (nfs_get_option_str(args, &mnt->client_address))
Chuck Leverbf0fd762007-07-01 12:13:44 -04001404 goto out_nomem;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001405 break;
Chuck Lever33832032007-12-10 14:59:13 -05001406 case Opt_mounthost:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001407 if (nfs_get_option_str(args,
1408 &mnt->mount_server.hostname))
Chuck Lever33832032007-12-10 14:59:13 -05001409 goto out_nomem;
Chuck Lever33832032007-12-10 14:59:13 -05001410 break;
Chuck Lever0ac83772007-09-11 18:01:04 -04001411 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001412 string = match_strdup(args);
1413 if (string == NULL)
1414 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001415 mnt->mount_server.addrlen =
1416 rpc_pton(string, strlen(string),
1417 (struct sockaddr *)
1418 &mnt->mount_server.address,
1419 sizeof(mnt->mount_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001420 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001421 if (mnt->mount_server.addrlen == 0)
1422 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001423 break;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001424 case Opt_lookupcache:
1425 string = match_strdup(args);
1426 if (string == NULL)
1427 goto out_nomem;
1428 token = match_token(string,
1429 nfs_lookupcache_tokens, args);
1430 kfree(string);
1431 switch (token) {
1432 case Opt_lookupcache_all:
1433 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1434 break;
1435 case Opt_lookupcache_positive:
1436 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1437 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1438 break;
1439 case Opt_lookupcache_none:
1440 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1441 break;
1442 default:
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001443 dfprintk(MOUNT, "NFS: invalid "
1444 "lookupcache argument\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001445 return 0;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001446 };
1447 break;
Chuck Levera6d5ff62010-05-07 13:33:58 -04001448 case Opt_fscache_uniq:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001449 if (nfs_get_option_str(args, &mnt->fscache_uniq))
Chuck Levera6d5ff62010-05-07 13:33:58 -04001450 goto out_nomem;
Chuck Levera6d5ff62010-05-07 13:33:58 -04001451 mnt->options |= NFS_OPTION_FSCACHE;
1452 break;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001453 case Opt_local_lock:
1454 string = match_strdup(args);
1455 if (string == NULL)
1456 goto out_nomem;
1457 token = match_token(string, nfs_local_lock_tokens,
1458 args);
1459 kfree(string);
1460 switch (token) {
1461 case Opt_local_lock_all:
1462 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1463 NFS_MOUNT_LOCAL_FCNTL);
1464 break;
1465 case Opt_local_lock_flock:
1466 mnt->flags |= NFS_MOUNT_LOCAL_FLOCK;
1467 break;
1468 case Opt_local_lock_posix:
1469 mnt->flags |= NFS_MOUNT_LOCAL_FCNTL;
1470 break;
1471 case Opt_local_lock_none:
1472 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1473 NFS_MOUNT_LOCAL_FCNTL);
1474 break;
1475 default:
1476 dfprintk(MOUNT, "NFS: invalid "
1477 "local_lock argument\n");
1478 return 0;
1479 };
1480 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001481
Chuck Leverf45663c2008-06-24 19:28:02 -04001482 /*
1483 * Special options
1484 */
1485 case Opt_sloppy:
1486 sloppy = 1;
1487 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1488 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001489 case Opt_userspace:
1490 case Opt_deprecated:
Chuck Leverd33e4df2008-06-12 12:37:41 -04001491 dfprintk(MOUNT, "NFS: ignoring mount option "
1492 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001493 break;
1494
1495 default:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001496 invalid_option = 1;
Chuck Leverf45663c2008-06-24 19:28:02 -04001497 dfprintk(MOUNT, "NFS: unrecognized mount option "
1498 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001499 }
1500 }
1501
Chuck Leverd23c45f2009-06-17 18:02:13 -07001502 if (!sloppy && invalid_option)
1503 return 0;
1504
Jeff Laytonee671b02009-12-03 15:58:56 -05001505 /*
1506 * verify that any proto=/mountproto= options match the address
1507 * familiies in the addr=/mountaddr= options.
1508 */
1509 if (protofamily != AF_UNSPEC &&
1510 protofamily != mnt->nfs_server.address.ss_family)
1511 goto out_proto_mismatch;
1512
1513 if (mountfamily != AF_UNSPEC) {
1514 if (mnt->mount_server.addrlen) {
1515 if (mountfamily != mnt->mount_server.address.ss_family)
1516 goto out_mountproto_mismatch;
1517 } else {
1518 if (mountfamily != mnt->nfs_server.address.ss_family)
1519 goto out_mountproto_mismatch;
1520 }
1521 }
1522
Chuck Leverbf0fd762007-07-01 12:13:44 -04001523 return 1;
1524
Jeff Laytonee671b02009-12-03 15:58:56 -05001525out_mountproto_mismatch:
1526 printk(KERN_INFO "NFS: mount server address does not match mountproto= "
1527 "option\n");
1528 return 0;
1529out_proto_mismatch:
1530 printk(KERN_INFO "NFS: server address does not match proto= option\n");
1531 return 0;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001532out_invalid_address:
1533 printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
1534 return 0;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001535out_invalid_value:
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001536 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001537 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001538out_nomem:
1539 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1540 return 0;
Eric Parisf9c3a382008-03-05 14:20:18 -05001541out_security_failure:
1542 free_secdata(secdata);
1543 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1544 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001545}
1546
1547/*
Chuck Leverec88f282009-08-09 15:09:32 -04001548 * Match the requested auth flavors with the list returned by
1549 * the server. Returns zero and sets the mount's authentication
1550 * flavor on success; returns -EACCES if server does not support
1551 * the requested flavor.
1552 */
1553static int nfs_walk_authlist(struct nfs_parsed_mount_data *args,
1554 struct nfs_mount_request *request)
1555{
1556 unsigned int i, j, server_authlist_len = *(request->auth_flav_len);
1557
1558 /*
Chuck Lever5eecfde2009-08-21 17:50:30 -04001559 * Certain releases of Linux's mountd return an empty
1560 * flavor list. To prevent behavioral regression with
1561 * these servers (ie. rejecting mounts that used to
1562 * succeed), revert to pre-2.6.32 behavior (no checking)
1563 * if the returned flavor list is empty.
1564 */
1565 if (server_authlist_len == 0)
1566 return 0;
1567
1568 /*
Chuck Leverec88f282009-08-09 15:09:32 -04001569 * We avoid sophisticated negotiating here, as there are
1570 * plenty of cases where we can get it wrong, providing
1571 * either too little or too much security.
1572 *
1573 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1574 * flavor listed first. However, some servers list
1575 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1576 * preferred default, in args->auth_flavors[0] if user
1577 * didn't specify sec= mount option.
1578 */
1579 for (i = 0; i < args->auth_flavor_len; i++)
1580 for (j = 0; j < server_authlist_len; j++)
1581 if (args->auth_flavors[i] == request->auth_flavs[j]) {
1582 dfprintk(MOUNT, "NFS: using auth flavor %d\n",
1583 request->auth_flavs[j]);
1584 args->auth_flavors[0] = request->auth_flavs[j];
1585 return 0;
1586 }
1587
1588 dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n");
1589 nfs_umount(request);
1590 return -EACCES;
1591}
1592
1593/*
Chuck Lever0076d7b2007-07-01 12:13:49 -04001594 * Use the remote server's MOUNT service to request the NFS file handle
1595 * corresponding to the provided path.
1596 */
1597static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1598 struct nfs_fh *root_fh)
1599{
Chuck Leverec88f282009-08-09 15:09:32 -04001600 rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS];
1601 unsigned int server_authlist_len = ARRAY_SIZE(server_authlist);
Chuck Leverc5d120f2008-12-23 15:21:35 -05001602 struct nfs_mount_request request = {
1603 .sap = (struct sockaddr *)
1604 &args->mount_server.address,
1605 .dirpath = args->nfs_server.export_path,
1606 .protocol = args->mount_server.protocol,
1607 .fh = root_fh,
Chuck Lever50a737f2008-12-23 15:21:37 -05001608 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
Chuck Leverec88f282009-08-09 15:09:32 -04001609 .auth_flav_len = &server_authlist_len,
1610 .auth_flavs = server_authlist,
Chuck Leverc5d120f2008-12-23 15:21:35 -05001611 };
Chuck Lever4c568012007-12-10 14:59:28 -05001612 int status;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001613
1614 if (args->mount_server.version == 0) {
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001615 switch (args->version) {
1616 default:
1617 args->mount_server.version = NFS_MNT3_VERSION;
1618 break;
1619 case 2:
1620 args->mount_server.version = NFS_MNT_VERSION;
1621 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001622 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001623 request.version = args->mount_server.version;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001624
Chuck Lever33832032007-12-10 14:59:13 -05001625 if (args->mount_server.hostname)
Chuck Leverc5d120f2008-12-23 15:21:35 -05001626 request.hostname = args->mount_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001627 else
Chuck Leverc5d120f2008-12-23 15:21:35 -05001628 request.hostname = args->nfs_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001629
Chuck Lever0076d7b2007-07-01 12:13:49 -04001630 /*
1631 * Construct the mount server's address.
1632 */
Chuck Lever4c568012007-12-10 14:59:28 -05001633 if (args->mount_server.address.ss_family == AF_UNSPEC) {
Chuck Leverc5d120f2008-12-23 15:21:35 -05001634 memcpy(request.sap, &args->nfs_server.address,
Chuck Lever4c568012007-12-10 14:59:28 -05001635 args->nfs_server.addrlen);
1636 args->mount_server.addrlen = args->nfs_server.addrlen;
1637 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001638 request.salen = args->mount_server.addrlen;
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001639 nfs_set_port(request.sap, &args->mount_server.port, 0);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001640
1641 /*
1642 * Now ask the mount server to map our export path
1643 * to a file handle.
1644 */
Chuck Leverc5d120f2008-12-23 15:21:35 -05001645 status = nfs_mount(&request);
Chuck Leverec88f282009-08-09 15:09:32 -04001646 if (status != 0) {
1647 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1648 request.hostname, status);
1649 return status;
1650 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001651
Chuck Leverec88f282009-08-09 15:09:32 -04001652 /*
1653 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1654 */
1655 if (args->mount_server.version != NFS_MNT3_VERSION)
1656 return 0;
1657 return nfs_walk_authlist(args, &request);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001658}
1659
Rob Landleyc12bace2011-03-09 15:54:13 -06001660/*
1661 * Split "dev_name" into "hostname:export_path".
1662 *
1663 * The leftmost colon demarks the split between the server's hostname
1664 * and the export path. If the hostname starts with a left square
1665 * bracket, then it may contain colons.
1666 *
1667 * Note: caller frees hostname and export path, even on error.
1668 */
1669static int nfs_parse_devname(const char *dev_name,
1670 char **hostname, size_t maxnamlen,
1671 char **export_path, size_t maxpathlen)
Chuck Leverdc045892008-06-23 12:36:37 -04001672{
1673 size_t len;
Rob Landleyc12bace2011-03-09 15:54:13 -06001674 char *end;
Chuck Leverdc045892008-06-23 12:36:37 -04001675
Rob Landleyc12bace2011-03-09 15:54:13 -06001676 /* Is the host name protected with square brakcets? */
1677 if (*dev_name == '[') {
1678 end = strchr(++dev_name, ']');
1679 if (end == NULL || end[1] != ':')
1680 goto out_bad_devname;
Chuck Leverdc045892008-06-23 12:36:37 -04001681
Rob Landleyc12bace2011-03-09 15:54:13 -06001682 len = end - dev_name;
1683 end++;
1684 } else {
1685 char *comma;
1686
1687 end = strchr(dev_name, ':');
1688 if (end == NULL)
1689 goto out_bad_devname;
1690 len = end - dev_name;
1691
1692 /* kill possible hostname list: not supported */
1693 comma = strchr(dev_name, ',');
1694 if (comma != NULL && comma < end)
1695 *comma = 0;
1696 }
1697
Chuck Leverdc045892008-06-23 12:36:37 -04001698 if (len > maxnamlen)
1699 goto out_hostname;
1700
1701 /* N.B. caller will free nfs_server.hostname in all cases */
1702 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
Rob Landleyc12bace2011-03-09 15:54:13 -06001703 if (*hostname == NULL)
Chuck Leverdc045892008-06-23 12:36:37 -04001704 goto out_nomem;
Rob Landleyc12bace2011-03-09 15:54:13 -06001705 len = strlen(++end);
Chuck Leverdc045892008-06-23 12:36:37 -04001706 if (len > maxpathlen)
1707 goto out_path;
Rob Landleyc12bace2011-03-09 15:54:13 -06001708 *export_path = kstrndup(end, len, GFP_KERNEL);
Chuck Leverdc045892008-06-23 12:36:37 -04001709 if (!*export_path)
1710 goto out_nomem;
1711
1712 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1713 return 0;
1714
1715out_bad_devname:
1716 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1717 return -EINVAL;
1718
1719out_nomem:
1720 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1721 return -ENOMEM;
1722
1723out_hostname:
1724 dfprintk(MOUNT, "NFS: server hostname too long\n");
1725 return -ENAMETOOLONG;
1726
1727out_path:
1728 dfprintk(MOUNT, "NFS: export pathname too long\n");
1729 return -ENAMETOOLONG;
1730}
1731
1732/*
David Howells54ceac42006-08-22 20:06:13 -04001733 * Validate the NFS2/NFS3 mount data
1734 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001735 *
1736 * For option strings, user space handles the following behaviors:
1737 *
1738 * + DNS: mapping server host name to IP address ("addr=" option)
1739 *
1740 * + failure mode: how to behave if a mount request can't be handled
1741 * immediately ("fg/bg" option)
1742 *
1743 * + retry: how often to retry a mount request ("retry=" option)
1744 *
1745 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1746 * mountproto=tcp after mountproto=udp, and so on
David Howellsf7b422b2006-06-09 09:34:33 -04001747 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001748static int nfs_validate_mount_data(void *options,
1749 struct nfs_parsed_mount_data *args,
Chuck Lever136d5582007-07-01 12:13:54 -04001750 struct nfs_fh *mntfh,
1751 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001752{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001753 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001754 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
Chuck Lever136d5582007-07-01 12:13:54 -04001755
Chuck Lever5df36e72007-07-01 12:12:56 -04001756 if (data == NULL)
1757 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001758
David Howellsf7b422b2006-06-09 09:34:33 -04001759 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001760 case 1:
1761 data->namlen = 0;
1762 case 2:
1763 data->bsize = 0;
1764 case 3:
1765 if (data->flags & NFS_MOUNT_VER3)
1766 goto out_no_v3;
1767 data->root.size = NFS2_FHSIZE;
1768 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1769 case 4:
1770 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1771 goto out_no_sec;
1772 case 5:
1773 memset(data->context, 0, sizeof(data->context));
1774 case 6:
Trond Myklebustb7e24452008-06-19 15:21:11 -04001775 if (data->flags & NFS_MOUNT_VER3) {
1776 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1777 goto out_invalid_fh;
Chuck Lever5df36e72007-07-01 12:12:56 -04001778 mntfh->size = data->root.size;
Chuck Lever764302c2009-09-08 19:50:03 -04001779 args->version = 3;
1780 } else {
Chuck Lever5df36e72007-07-01 12:12:56 -04001781 mntfh->size = NFS2_FHSIZE;
Chuck Lever764302c2009-09-08 19:50:03 -04001782 args->version = 2;
1783 }
Chuck Lever5df36e72007-07-01 12:12:56 -04001784
Chuck Lever5df36e72007-07-01 12:12:56 -04001785
1786 memcpy(mntfh->data, data->root.data, mntfh->size);
1787 if (mntfh->size < sizeof(mntfh->data))
1788 memset(mntfh->data + mntfh->size, 0,
1789 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001790
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001791 /*
1792 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1793 * can deal with.
1794 */
Trond Myklebustff3525a2008-08-15 16:59:14 -04001795 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
Bryan Schumakerd5eff1a2010-08-03 13:04:00 -04001796 args->flags |= NFS_MOUNT_LEGACY_INTERFACE;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001797 args->rsize = data->rsize;
1798 args->wsize = data->wsize;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001799 args->timeo = data->timeo;
1800 args->retrans = data->retrans;
1801 args->acregmin = data->acregmin;
1802 args->acregmax = data->acregmax;
1803 args->acdirmin = data->acdirmin;
1804 args->acdirmax = data->acdirmax;
Chuck Lever4c568012007-12-10 14:59:28 -05001805
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001806 memcpy(sap, &data->addr, sizeof(data->addr));
Chuck Lever4c568012007-12-10 14:59:28 -05001807 args->nfs_server.addrlen = sizeof(data->addr);
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001808 if (!nfs_verify_server_address(sap))
Chuck Lever4c568012007-12-10 14:59:28 -05001809 goto out_no_address;
1810
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001811 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001812 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001813 /* N.B. caller will free nfs_server.hostname in all cases */
1814 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1815 args->namlen = data->namlen;
1816 args->bsize = data->bsize;
Chuck Leverdd07c942008-06-24 16:33:46 -04001817
1818 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1819 args->auth_flavors[0] = data->pseudoflavor;
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001820 if (!args->nfs_server.hostname)
1821 goto out_nomem;
Eric Parisf9c3a382008-03-05 14:20:18 -05001822
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001823 if (!(data->flags & NFS_MOUNT_NONLM))
1824 args->flags &= ~(NFS_MOUNT_LOCAL_FLOCK|
1825 NFS_MOUNT_LOCAL_FCNTL);
1826 else
1827 args->flags |= (NFS_MOUNT_LOCAL_FLOCK|
1828 NFS_MOUNT_LOCAL_FCNTL);
Eric Parisf9c3a382008-03-05 14:20:18 -05001829 /*
1830 * The legacy version 6 binary mount data from userspace has a
1831 * field used only to transport selinux information into the
1832 * the kernel. To continue to support that functionality we
1833 * have a touch of selinux knowledge here in the NFS code. The
1834 * userspace code converted context=blah to just blah so we are
1835 * converting back to the full string selinux understands.
1836 */
1837 if (data->context[0]){
1838#ifdef CONFIG_SECURITY_SELINUX
1839 int rc;
1840 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1841 if (!opts_str)
1842 return -ENOMEM;
1843 strcpy(opts_str, "context=");
1844 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1845 strcat(opts_str, &data->context[0]);
1846 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1847 kfree(opts_str);
1848 if (rc)
1849 return rc;
1850#else
1851 return -EINVAL;
1852#endif
1853 }
1854
Chuck Lever5df36e72007-07-01 12:12:56 -04001855 break;
Chuck Lever136d5582007-07-01 12:13:54 -04001856 default: {
Chuck Lever136d5582007-07-01 12:13:54 -04001857 int status;
Chuck Lever136d5582007-07-01 12:13:54 -04001858
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001859 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever136d5582007-07-01 12:13:54 -04001860 return -EINVAL;
1861
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001862 if (!nfs_verify_server_address(sap))
Chuck Lever6e88e062007-09-24 15:39:50 -04001863 goto out_no_address;
1864
Chuck Lever764302c2009-09-08 19:50:03 -04001865 if (args->version == 4)
1866#ifdef CONFIG_NFS_V4
1867 return nfs4_validate_text_mount_data(options,
1868 args, dev_name);
1869#else
1870 goto out_v4_not_compiled;
1871#endif
1872
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001873 nfs_set_port(sap, &args->nfs_server.port, 0);
Chuck Levered596a82008-06-26 17:47:05 -04001874
Trond Myklebust259875e2008-07-02 14:43:47 -04001875 nfs_set_mount_transport_protocol(args);
1876
Chuck Leverdc045892008-06-23 12:36:37 -04001877 status = nfs_parse_devname(dev_name,
1878 &args->nfs_server.hostname,
1879 PAGE_SIZE,
1880 &args->nfs_server.export_path,
1881 NFS_MAXPATHLEN);
1882 if (!status)
1883 status = nfs_try_mount(args, mntfh);
Chuck Lever136d5582007-07-01 12:13:54 -04001884
Chuck Leverdc045892008-06-23 12:36:37 -04001885 kfree(args->nfs_server.export_path);
1886 args->nfs_server.export_path = NULL;
Chuck Lever136d5582007-07-01 12:13:54 -04001887
Chuck Lever136d5582007-07-01 12:13:54 -04001888 if (status)
Chuck Leverfdc6e2c2007-08-29 17:58:59 -04001889 return status;
Chuck Lever136d5582007-07-01 12:13:54 -04001890
Chuck Lever136d5582007-07-01 12:13:54 -04001891 break;
1892 }
David Howellsf7b422b2006-06-09 09:34:33 -04001893 }
David Howells54ceac42006-08-22 20:06:13 -04001894
David Howellsf7b422b2006-06-09 09:34:33 -04001895#ifndef CONFIG_NFS_V3
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001896 if (args->version == 3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001897 goto out_v3_not_compiled;
1898#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001899
David Howells54ceac42006-08-22 20:06:13 -04001900 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001901
1902out_no_data:
1903 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1904 return -EINVAL;
1905
1906out_no_v3:
1907 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1908 data->version);
1909 return -EINVAL;
1910
1911out_no_sec:
1912 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1913 return -EINVAL;
1914
Chuck Lever5df36e72007-07-01 12:12:56 -04001915#ifndef CONFIG_NFS_V3
1916out_v3_not_compiled:
1917 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1918 return -EPROTONOSUPPORT;
1919#endif /* !CONFIG_NFS_V3 */
1920
Chuck Lever764302c2009-09-08 19:50:03 -04001921#ifndef CONFIG_NFS_V4
1922out_v4_not_compiled:
1923 dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n");
1924 return -EPROTONOSUPPORT;
1925#endif /* !CONFIG_NFS_V4 */
1926
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001927out_nomem:
1928 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
1929 return -ENOMEM;
1930
Chuck Lever5df36e72007-07-01 12:12:56 -04001931out_no_address:
1932 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1933 return -EINVAL;
1934
1935out_invalid_fh:
1936 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1937 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04001938}
1939
Jeff Layton48b605f2008-06-10 15:38:39 -04001940static int
1941nfs_compare_remount_data(struct nfs_server *nfss,
1942 struct nfs_parsed_mount_data *data)
1943{
1944 if (data->flags != nfss->flags ||
1945 data->rsize != nfss->rsize ||
1946 data->wsize != nfss->wsize ||
1947 data->retrans != nfss->client->cl_timeout->to_retries ||
1948 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
1949 data->acregmin != nfss->acregmin / HZ ||
1950 data->acregmax != nfss->acregmax / HZ ||
1951 data->acdirmin != nfss->acdirmin / HZ ||
1952 data->acdirmax != nfss->acdirmax / HZ ||
1953 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
Trond Myklebustbcd2ea12009-10-06 15:41:22 -04001954 data->nfs_server.port != nfss->port ||
Jeff Layton48b605f2008-06-10 15:38:39 -04001955 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
Stefan Richtera1be9ee2009-10-12 11:26:12 -04001956 !rpc_cmp_addr((struct sockaddr *)&data->nfs_server.address,
1957 (struct sockaddr *)&nfss->nfs_client->cl_addr))
Jeff Layton48b605f2008-06-10 15:38:39 -04001958 return -EINVAL;
1959
1960 return 0;
1961}
1962
1963static int
1964nfs_remount(struct super_block *sb, int *flags, char *raw_data)
1965{
1966 int error;
1967 struct nfs_server *nfss = sb->s_fs_info;
1968 struct nfs_parsed_mount_data *data;
1969 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
1970 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
Trond Myklebustcd100722008-06-17 16:12:00 -04001971 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
Jeff Layton48b605f2008-06-10 15:38:39 -04001972
1973 /*
1974 * Userspace mount programs that send binary options generally send
1975 * them populated with default values. We have no way to know which
1976 * ones were explicitly specified. Fall back to legacy behavior and
1977 * just return success.
1978 */
Marc Zyngier31c94462008-07-17 13:21:55 +02001979 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
1980 (nfsvers <= 3 && (!options || (options->version >= 1 &&
1981 options->version <= 6))))
Jeff Layton48b605f2008-06-10 15:38:39 -04001982 return 0;
1983
1984 data = kzalloc(sizeof(*data), GFP_KERNEL);
1985 if (data == NULL)
1986 return -ENOMEM;
1987
1988 /* fill out struct with values from existing mount */
1989 data->flags = nfss->flags;
1990 data->rsize = nfss->rsize;
1991 data->wsize = nfss->wsize;
1992 data->retrans = nfss->client->cl_timeout->to_retries;
1993 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
1994 data->acregmin = nfss->acregmin / HZ;
1995 data->acregmax = nfss->acregmax / HZ;
1996 data->acdirmin = nfss->acdirmin / HZ;
1997 data->acdirmax = nfss->acdirmax / HZ;
1998 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
Trond Myklebustbcd2ea12009-10-06 15:41:22 -04001999 data->nfs_server.port = nfss->port;
Jeff Layton48b605f2008-06-10 15:38:39 -04002000 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
2001 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
2002 data->nfs_server.addrlen);
2003
2004 /* overwrite those values with any that were specified */
2005 error = nfs_parse_mount_options((char *)options, data);
2006 if (error < 0)
2007 goto out;
2008
Jeff Layton26c4c172011-04-27 11:49:09 -04002009 /*
2010 * noac is a special case. It implies -o sync, but that's not
2011 * necessarily reflected in the mtab options. do_remount_sb
2012 * will clear MS_SYNCHRONOUS if -o sync wasn't specified in the
2013 * remount options, so we have to explicitly reset it.
2014 */
2015 if (data->flags & NFS_MOUNT_NOAC)
2016 *flags |= MS_SYNCHRONOUS;
2017
Jeff Layton48b605f2008-06-10 15:38:39 -04002018 /* compare new mount options with old ones */
2019 error = nfs_compare_remount_data(nfss, data);
2020out:
2021 kfree(data);
2022 return error;
2023}
2024
David Howells54ceac42006-08-22 20:06:13 -04002025/*
2026 * Initialise the common bits of the superblock
2027 */
2028static inline void nfs_initialise_sb(struct super_block *sb)
2029{
2030 struct nfs_server *server = NFS_SB(sb);
2031
2032 sb->s_magic = NFS_SUPER_MAGIC;
2033
2034 /* We probably want something more informative here */
2035 snprintf(sb->s_id, sizeof(sb->s_id),
2036 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
2037
2038 if (sb->s_blocksize == 0)
2039 sb->s_blocksize = nfs_block_bits(server->wsize,
2040 &sb->s_blocksize_bits);
2041
Jens Axboe32a88aa2009-09-16 15:02:33 +02002042 sb->s_bdi = &server->backing_dev_info;
2043
David Howells54ceac42006-08-22 20:06:13 -04002044 nfs_super_set_maxbytes(sb, server->maxfilesize);
2045}
2046
2047/*
2048 * Finish setting up an NFS2/3 superblock
2049 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04002050static void nfs_fill_super(struct super_block *sb,
2051 struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -04002052{
2053 struct nfs_server *server = NFS_SB(sb);
2054
2055 sb->s_blocksize_bits = 0;
2056 sb->s_blocksize = 0;
2057 if (data->bsize)
2058 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
2059
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04002060 if (server->nfs_client->rpc_ops->version == 3) {
David Howells54ceac42006-08-22 20:06:13 -04002061 /* The VFS shouldn't apply the umask to mode bits. We will do
2062 * so ourselves when necessary.
2063 */
2064 sb->s_flags |= MS_POSIXACL;
2065 sb->s_time_gran = 1;
2066 }
2067
2068 sb->s_op = &nfs_sops;
2069 nfs_initialise_sb(sb);
2070}
2071
2072/*
2073 * Finish setting up a cloned NFS2/3 superblock
2074 */
2075static void nfs_clone_super(struct super_block *sb,
2076 const struct super_block *old_sb)
2077{
2078 struct nfs_server *server = NFS_SB(sb);
2079
2080 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2081 sb->s_blocksize = old_sb->s_blocksize;
2082 sb->s_maxbytes = old_sb->s_maxbytes;
2083
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04002084 if (server->nfs_client->rpc_ops->version == 3) {
David Howells54ceac42006-08-22 20:06:13 -04002085 /* The VFS shouldn't apply the umask to mode bits. We will do
2086 * so ourselves when necessary.
2087 */
2088 sb->s_flags |= MS_POSIXACL;
2089 sb->s_time_gran = 1;
2090 }
2091
2092 sb->s_op = old_sb->s_op;
2093 nfs_initialise_sb(sb);
2094}
2095
Trond Myklebust275a5d22007-05-16 16:53:28 -04002096static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
2097{
2098 const struct nfs_server *a = s->s_fs_info;
2099 const struct rpc_clnt *clnt_a = a->client;
2100 const struct rpc_clnt *clnt_b = b->client;
2101
2102 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
2103 goto Ebusy;
2104 if (a->nfs_client != b->nfs_client)
2105 goto Ebusy;
2106 if (a->flags != b->flags)
2107 goto Ebusy;
2108 if (a->wsize != b->wsize)
2109 goto Ebusy;
2110 if (a->rsize != b->rsize)
2111 goto Ebusy;
2112 if (a->acregmin != b->acregmin)
2113 goto Ebusy;
2114 if (a->acregmax != b->acregmax)
2115 goto Ebusy;
2116 if (a->acdirmin != b->acdirmin)
2117 goto Ebusy;
2118 if (a->acdirmax != b->acdirmax)
2119 goto Ebusy;
2120 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
2121 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002122 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04002123Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002124 return 0;
2125}
2126
2127struct nfs_sb_mountdata {
2128 struct nfs_server *server;
2129 int mntflags;
2130};
2131
2132static int nfs_set_super(struct super_block *s, void *data)
2133{
2134 struct nfs_sb_mountdata *sb_mntdata = data;
2135 struct nfs_server *server = sb_mntdata->server;
2136 int ret;
2137
2138 s->s_flags = sb_mntdata->mntflags;
2139 s->s_fs_info = server;
Al Viro8b244ff2010-12-18 11:29:39 -05002140 s->s_d_op = server->nfs_client->rpc_ops->dentry_ops;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002141 ret = set_anon_super(s, server);
2142 if (ret == 0)
2143 server->s_dev = s->s_dev;
2144 return ret;
2145}
2146
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002147static int nfs_compare_super_address(struct nfs_server *server1,
2148 struct nfs_server *server2)
2149{
2150 struct sockaddr *sap1, *sap2;
2151
2152 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
2153 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
2154
2155 if (sap1->sa_family != sap2->sa_family)
2156 return 0;
2157
2158 switch (sap1->sa_family) {
2159 case AF_INET: {
2160 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
2161 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
2162 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
2163 return 0;
2164 if (sin1->sin_port != sin2->sin_port)
2165 return 0;
2166 break;
2167 }
2168 case AF_INET6: {
2169 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
2170 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
2171 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
2172 return 0;
2173 if (sin1->sin6_port != sin2->sin6_port)
2174 return 0;
2175 break;
2176 }
2177 default:
2178 return 0;
2179 }
2180
2181 return 1;
2182}
2183
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002184static int nfs_compare_super(struct super_block *sb, void *data)
2185{
2186 struct nfs_sb_mountdata *sb_mntdata = data;
2187 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2188 int mntflags = sb_mntdata->mntflags;
2189
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002190 if (!nfs_compare_super_address(old, server))
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002191 return 0;
2192 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2193 if (old->flags & NFS_MOUNT_UNSHARED)
2194 return 0;
2195 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2196 return 0;
2197 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04002198}
2199
Miklos Szeredifa799752008-04-30 00:54:33 -07002200static int nfs_bdi_register(struct nfs_server *server)
2201{
2202 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
2203}
2204
Al Viro01194982011-03-16 07:25:36 -04002205static struct dentry *nfs_fs_mount(struct file_system_type *fs_type,
2206 int flags, const char *dev_name, void *raw_data)
David Howells54ceac42006-08-22 20:06:13 -04002207{
2208 struct nfs_server *server = NULL;
2209 struct super_block *s;
Trond Myklebust33852a12008-06-19 14:20:11 -04002210 struct nfs_parsed_mount_data *data;
2211 struct nfs_fh *mntfh;
Al Viro01194982011-03-16 07:25:36 -04002212 struct dentry *mntroot = ERR_PTR(-ENOMEM);
Trond Myklebust75180df2007-05-16 16:53:28 -04002213 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002214 struct nfs_sb_mountdata sb_mntdata = {
2215 .mntflags = flags,
2216 };
Al Viro01194982011-03-16 07:25:36 -04002217 int error;
David Howells54ceac42006-08-22 20:06:13 -04002218
Paulius Zaleckas1e657bd2010-10-31 18:21:05 +02002219 data = nfs_alloc_parsed_mount_data(NFS_DEFAULT_VERSION);
Trond Myklebustb157b062010-04-19 19:05:48 -04002220 mntfh = nfs_alloc_fhandle();
Trond Myklebust33852a12008-06-19 14:20:11 -04002221 if (data == NULL || mntfh == NULL)
2222 goto out_free_fh;
2223
2224 security_init_mnt_opts(&data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002225
David Howells54ceac42006-08-22 20:06:13 -04002226 /* Validate the mount data */
Trond Myklebust33852a12008-06-19 14:20:11 -04002227 error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
Al Viro01194982011-03-16 07:25:36 -04002228 if (error < 0) {
2229 mntroot = ERR_PTR(error);
Chuck Lever06559602007-07-01 12:12:35 -04002230 goto out;
Al Viro01194982011-03-16 07:25:36 -04002231 }
David Howells54ceac42006-08-22 20:06:13 -04002232
Chuck Lever764302c2009-09-08 19:50:03 -04002233#ifdef CONFIG_NFS_V4
2234 if (data->version == 4) {
Al Viro01194982011-03-16 07:25:36 -04002235 mntroot = nfs4_try_mount(flags, dev_name, data);
Chuck Lever764302c2009-09-08 19:50:03 -04002236 kfree(data->client_address);
Xiaotian Feng9699eda2010-04-22 18:56:17 +08002237 kfree(data->nfs_server.export_path);
Chuck Lever764302c2009-09-08 19:50:03 -04002238 goto out;
2239 }
2240#endif /* CONFIG_NFS_V4 */
2241
David Howells54ceac42006-08-22 20:06:13 -04002242 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002243 server = nfs_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002244 if (IS_ERR(server)) {
Al Viro01194982011-03-16 07:25:36 -04002245 mntroot = ERR_CAST(server);
Chuck Lever06559602007-07-01 12:12:35 -04002246 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002247 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002248 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002249
Trond Myklebust75180df2007-05-16 16:53:28 -04002250 if (server->flags & NFS_MOUNT_UNSHARED)
2251 compare_super = NULL;
2252
Sachin Prabhufb2088c2011-08-01 12:10:12 +01002253 /* -o noac implies -o sync */
2254 if (server->flags & NFS_MOUNT_NOAC)
2255 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2256
David Howells54ceac42006-08-22 20:06:13 -04002257 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002258 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002259 if (IS_ERR(s)) {
Al Viro01194982011-03-16 07:25:36 -04002260 mntroot = ERR_CAST(s);
David Howells54ceac42006-08-22 20:06:13 -04002261 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04002262 }
2263
David Howells54ceac42006-08-22 20:06:13 -04002264 if (s->s_fs_info != server) {
2265 nfs_free_server(server);
2266 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002267 } else {
2268 error = nfs_bdi_register(server);
Al Viro01194982011-03-16 07:25:36 -04002269 if (error) {
2270 mntroot = ERR_PTR(error);
NeilBrowncfbc0682010-03-11 11:20:17 +11002271 goto error_splat_bdi;
Al Viro01194982011-03-16 07:25:36 -04002272 }
David Howellsf7b422b2006-06-09 09:34:33 -04002273 }
David Howells54ceac42006-08-22 20:06:13 -04002274
2275 if (!s->s_root) {
2276 /* initial superblock/root creation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002277 nfs_fill_super(s, data);
Jesper Juhl160bc162011-04-10 17:57:07 +02002278 nfs_fscache_get_super_cookie(s, data->fscache_uniq, NULL);
David Howells54ceac42006-08-22 20:06:13 -04002279 }
2280
Al Viro0d5839a2011-03-16 05:27:27 -04002281 mntroot = nfs_get_root(s, mntfh, dev_name);
Al Viro01194982011-03-16 07:25:36 -04002282 if (IS_ERR(mntroot))
David Howells54ceac42006-08-22 20:06:13 -04002283 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002284
Trond Myklebust33852a12008-06-19 14:20:11 -04002285 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002286 if (error)
2287 goto error_splat_root;
2288
David Howellsf7b422b2006-06-09 09:34:33 -04002289 s->s_flags |= MS_ACTIVE;
Chuck Lever06559602007-07-01 12:12:35 -04002290
2291out:
Trond Myklebust33852a12008-06-19 14:20:11 -04002292 kfree(data->nfs_server.hostname);
2293 kfree(data->mount_server.hostname);
David Howells08734042009-04-03 16:42:42 +01002294 kfree(data->fscache_uniq);
Trond Myklebust33852a12008-06-19 14:20:11 -04002295 security_free_mnt_opts(&data->lsm_opts);
2296out_free_fh:
Trond Myklebustb157b062010-04-19 19:05:48 -04002297 nfs_free_fhandle(mntfh);
Trond Myklebust33852a12008-06-19 14:20:11 -04002298 kfree(data);
Al Viro01194982011-03-16 07:25:36 -04002299 return mntroot;
Trond Myklebust816724e2006-06-24 08:41:41 -04002300
David Howells54ceac42006-08-22 20:06:13 -04002301out_err_nosb:
2302 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04002303 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002304
Eric Parisf9c3a382008-03-05 14:20:18 -05002305error_splat_root:
2306 dput(mntroot);
Al Viro01194982011-03-16 07:25:36 -04002307 mntroot = ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04002308error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002309 if (server && !s->s_root)
2310 bdi_unregister(&server->backing_dev_info);
2311error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002312 deactivate_locked_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04002313 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002314}
2315
David Howells54ceac42006-08-22 20:06:13 -04002316/*
Trond Myklebust387c1492010-02-03 08:27:35 -05002317 * Ensure that we unregister the bdi before kill_anon_super
2318 * releases the device name
2319 */
2320static void nfs_put_super(struct super_block *s)
2321{
2322 struct nfs_server *server = NFS_SB(s);
2323
2324 bdi_unregister(&server->backing_dev_info);
2325}
2326
2327/*
David Howells54ceac42006-08-22 20:06:13 -04002328 * Destroy an NFS2/3 superblock
2329 */
David Howellsf7b422b2006-06-09 09:34:33 -04002330static void nfs_kill_super(struct super_block *s)
2331{
2332 struct nfs_server *server = NFS_SB(s);
2333
2334 kill_anon_super(s);
David Howells08734042009-04-03 16:42:42 +01002335 nfs_fscache_release_super_cookie(s);
David Howells54ceac42006-08-22 20:06:13 -04002336 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04002337}
2338
David Howells54ceac42006-08-22 20:06:13 -04002339/*
2340 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2341 */
Al Viro31f43472010-10-29 03:38:12 -04002342static struct dentry *
2343nfs_xdev_mount(struct file_system_type *fs_type, int flags,
2344 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002345{
2346 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002347 struct super_block *s;
2348 struct nfs_server *server;
2349 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002350 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002351 struct nfs_sb_mountdata sb_mntdata = {
2352 .mntflags = flags,
2353 };
David Howells54ceac42006-08-22 20:06:13 -04002354 int error;
2355
Al Viro31f43472010-10-29 03:38:12 -04002356 dprintk("--> nfs_xdev_mount()\n");
David Howells54ceac42006-08-22 20:06:13 -04002357
2358 /* create a new volume representation */
2359 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2360 if (IS_ERR(server)) {
2361 error = PTR_ERR(server);
2362 goto out_err_noserver;
2363 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002364 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002365
Trond Myklebust75180df2007-05-16 16:53:28 -04002366 if (server->flags & NFS_MOUNT_UNSHARED)
2367 compare_super = NULL;
2368
Sachin Prabhufb2088c2011-08-01 12:10:12 +01002369 /* -o noac implies -o sync */
2370 if (server->flags & NFS_MOUNT_NOAC)
2371 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2372
David Howells54ceac42006-08-22 20:06:13 -04002373 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002374 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002375 if (IS_ERR(s)) {
2376 error = PTR_ERR(s);
2377 goto out_err_nosb;
2378 }
2379
2380 if (s->s_fs_info != server) {
2381 nfs_free_server(server);
2382 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002383 } else {
2384 error = nfs_bdi_register(server);
2385 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11002386 goto error_splat_bdi;
David Howells54ceac42006-08-22 20:06:13 -04002387 }
2388
2389 if (!s->s_root) {
2390 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002391 nfs_clone_super(s, data->sb);
David Howells2df54802009-09-23 14:36:39 -04002392 nfs_fscache_get_super_cookie(s, NULL, data);
David Howells54ceac42006-08-22 20:06:13 -04002393 }
2394
Al Viro0d5839a2011-03-16 05:27:27 -04002395 mntroot = nfs_get_root(s, data->fh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04002396 if (IS_ERR(mntroot)) {
2397 error = PTR_ERR(mntroot);
2398 goto error_splat_super;
2399 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002400 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
Neil Brown4c1fe2f2007-11-01 16:50:20 +11002401 dput(mntroot);
2402 error = -ESTALE;
2403 goto error_splat_super;
2404 }
David Howells54ceac42006-08-22 20:06:13 -04002405
2406 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002407
Eric Parisf9c3a382008-03-05 14:20:18 -05002408 /* clone any lsm security options from the parent to the new sb */
2409 security_sb_clone_mnt_opts(data->sb, s);
2410
Al Viro31f43472010-10-29 03:38:12 -04002411 dprintk("<-- nfs_xdev_mount() = 0\n");
2412 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04002413
2414out_err_nosb:
2415 nfs_free_server(server);
2416out_err_noserver:
Al Viro31f43472010-10-29 03:38:12 -04002417 dprintk("<-- nfs_xdev_mount() = %d [error]\n", error);
2418 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04002419
2420error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002421 if (server && !s->s_root)
2422 bdi_unregister(&server->backing_dev_info);
2423error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002424 deactivate_locked_super(s);
Al Viro31f43472010-10-29 03:38:12 -04002425 dprintk("<-- nfs_xdev_mount() = %d [splat]\n", error);
2426 return ERR_PTR(error);
David Howellsf7b422b2006-06-09 09:34:33 -04002427}
2428
2429#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04002430
2431/*
2432 * Finish setting up a cloned NFS4 superblock
2433 */
2434static void nfs4_clone_super(struct super_block *sb,
2435 const struct super_block *old_sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002436{
David Howells54ceac42006-08-22 20:06:13 -04002437 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2438 sb->s_blocksize = old_sb->s_blocksize;
2439 sb->s_maxbytes = old_sb->s_maxbytes;
2440 sb->s_time_gran = 1;
2441 sb->s_op = old_sb->s_op;
Aneesh Kumar K.Va8a5da92010-12-09 11:35:14 +00002442 /*
2443 * The VFS shouldn't apply the umask to mode bits. We will do
2444 * so ourselves when necessary.
2445 */
2446 sb->s_flags |= MS_POSIXACL;
Aneesh Kumar K.V64c2ce82010-12-09 11:35:25 +00002447 sb->s_xattr = old_sb->s_xattr;
2448 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002449}
2450
2451/*
2452 * Set up an NFS4 superblock
2453 */
David Howells54ceac42006-08-22 20:06:13 -04002454static void nfs4_fill_super(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002455{
David Howellsf7b422b2006-06-09 09:34:33 -04002456 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04002457 sb->s_op = &nfs4_sops;
Aneesh Kumar K.Va8a5da92010-12-09 11:35:14 +00002458 /*
2459 * The VFS shouldn't apply the umask to mode bits. We will do
2460 * so ourselves when necessary.
2461 */
2462 sb->s_flags |= MS_POSIXACL;
Aneesh Kumar K.V64c2ce82010-12-09 11:35:25 +00002463 sb->s_xattr = nfs4_xattr_handlers;
David Howells54ceac42006-08-22 20:06:13 -04002464 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002465}
2466
Trond Myklebust01c3f052009-06-17 13:22:58 -07002467static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2468{
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04002469 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3|
2470 NFS_MOUNT_LOCAL_FLOCK|NFS_MOUNT_LOCAL_FCNTL);
Trond Myklebust01c3f052009-06-17 13:22:58 -07002471}
2472
Chuck Lever7630c852009-09-08 19:49:57 -04002473static int nfs4_validate_text_mount_data(void *options,
2474 struct nfs_parsed_mount_data *args,
2475 const char *dev_name)
2476{
2477 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2478
Trond Myklebustf5855fe2009-10-06 15:40:37 -04002479 nfs_set_port(sap, &args->nfs_server.port, NFS_PORT);
Chuck Lever7630c852009-09-08 19:49:57 -04002480
2481 nfs_validate_transport_protocol(args);
2482
2483 nfs4_validate_mount_flags(args);
2484
Trond Myklebust2ecda722009-09-08 19:50:07 -04002485 if (args->version != 4) {
2486 dfprintk(MOUNT,
2487 "NFS4: Illegal mount version\n");
2488 return -EINVAL;
2489 }
2490
Chuck Lever7630c852009-09-08 19:49:57 -04002491 if (args->auth_flavor_len > 1) {
2492 dfprintk(MOUNT,
2493 "NFS4: Too many RPC auth flavours specified\n");
2494 return -EINVAL;
2495 }
2496
2497 if (args->client_address == NULL) {
2498 dfprintk(MOUNT,
2499 "NFS4: mount program didn't pass callback address\n");
2500 return -EINVAL;
2501 }
2502
2503 return nfs_parse_devname(dev_name,
2504 &args->nfs_server.hostname,
2505 NFS4_MAXNAMLEN,
2506 &args->nfs_server.export_path,
2507 NFS4_MAXPATHLEN);
2508}
2509
David Howells54ceac42006-08-22 20:06:13 -04002510/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04002511 * Validate NFSv4 mount options
2512 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002513static int nfs4_validate_mount_data(void *options,
2514 struct nfs_parsed_mount_data *args,
2515 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04002516{
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002517 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002518 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002519 char *c;
2520
2521 if (data == NULL)
2522 goto out_no_data;
2523
2524 switch (data->version) {
2525 case 1:
Chuck Lever4c568012007-12-10 14:59:28 -05002526 if (data->host_addrlen > sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002527 goto out_no_address;
Chuck Lever4c568012007-12-10 14:59:28 -05002528 if (data->host_addrlen == 0)
2529 goto out_no_address;
2530 args->nfs_server.addrlen = data->host_addrlen;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002531 if (copy_from_user(sap, data->host_addr, data->host_addrlen))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002532 return -EFAULT;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002533 if (!nfs_verify_server_address(sap))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002534 goto out_no_address;
2535
Chuck Lever6738b252008-06-24 16:33:54 -04002536 if (data->auth_flavourlen) {
2537 if (data->auth_flavourlen > 1)
2538 goto out_inval_auth;
Trond Myklebust20c71f52007-09-20 20:23:51 -04002539 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002540 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04002541 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002542 return -EFAULT;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002543 }
2544
2545 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2546 if (IS_ERR(c))
2547 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002548 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002549
2550 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2551 if (IS_ERR(c))
2552 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002553 args->nfs_server.export_path = c;
2554 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002555
2556 c = strndup_user(data->client_addr.data, 16);
2557 if (IS_ERR(c))
2558 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002559 args->client_address = c;
2560
2561 /*
2562 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2563 * can deal with.
2564 */
2565
2566 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2567 args->rsize = data->rsize;
2568 args->wsize = data->wsize;
2569 args->timeo = data->timeo;
2570 args->retrans = data->retrans;
2571 args->acregmin = data->acregmin;
2572 args->acregmax = data->acregmax;
2573 args->acdirmin = data->acdirmin;
2574 args->acdirmax = data->acdirmax;
2575 args->nfs_server.protocol = data->proto;
Trond Myklebust259875e2008-07-02 14:43:47 -04002576 nfs_validate_transport_protocol(args);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002577
2578 break;
Chuck Lever7630c852009-09-08 19:49:57 -04002579 default:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002580 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever80071222007-07-01 12:13:59 -04002581 return -EINVAL;
2582
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002583 if (!nfs_verify_server_address(sap))
Chuck Lever80071222007-07-01 12:13:59 -04002584 return -EINVAL;
Chuck Levered596a82008-06-26 17:47:05 -04002585
Chuck Lever7630c852009-09-08 19:49:57 -04002586 return nfs4_validate_text_mount_data(options, args, dev_name);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002587 }
2588
2589 return 0;
2590
2591out_no_data:
2592 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2593 return -EINVAL;
2594
2595out_inval_auth:
2596 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2597 data->auth_flavourlen);
2598 return -EINVAL;
2599
2600out_no_address:
2601 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2602 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002603}
2604
2605/*
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002606 * Get the superblock for the NFS4 root partition
David Howells54ceac42006-08-22 20:06:13 -04002607 */
Al Viro31f43472010-10-29 03:38:12 -04002608static struct dentry *
2609nfs4_remote_mount(struct file_system_type *fs_type, int flags,
2610 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002611{
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002612 struct nfs_parsed_mount_data *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002613 struct super_block *s;
2614 struct nfs_server *server;
Trond Myklebust33852a12008-06-19 14:20:11 -04002615 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04002616 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002617 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002618 struct nfs_sb_mountdata sb_mntdata = {
2619 .mntflags = flags,
2620 };
Trond Myklebust33852a12008-06-19 14:20:11 -04002621 int error = -ENOMEM;
David Howellsf7b422b2006-06-09 09:34:33 -04002622
Trond Myklebustb157b062010-04-19 19:05:48 -04002623 mntfh = nfs_alloc_fhandle();
Trond Myklebust33852a12008-06-19 14:20:11 -04002624 if (data == NULL || mntfh == NULL)
2625 goto out_free_fh;
2626
2627 security_init_mnt_opts(&data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002628
David Howells54ceac42006-08-22 20:06:13 -04002629 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002630 server = nfs4_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002631 if (IS_ERR(server)) {
2632 error = PTR_ERR(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04002633 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002634 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002635 sb_mntdata.server = server;
David Howellsf7b422b2006-06-09 09:34:33 -04002636
Trond Myklebust75180df2007-05-16 16:53:28 -04002637 if (server->flags & NFS4_MOUNT_UNSHARED)
2638 compare_super = NULL;
2639
Sachin Prabhufb2088c2011-08-01 12:10:12 +01002640 /* -o noac implies -o sync */
2641 if (server->flags & NFS_MOUNT_NOAC)
2642 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2643
David Howells54ceac42006-08-22 20:06:13 -04002644 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002645 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002646 if (IS_ERR(s)) {
2647 error = PTR_ERR(s);
David Howellsf7b422b2006-06-09 09:34:33 -04002648 goto out_free;
Trond Myklebust816724e2006-06-24 08:41:41 -04002649 }
2650
Trond Myklebust5dd31772006-08-24 01:03:05 -04002651 if (s->s_fs_info != server) {
2652 nfs_free_server(server);
2653 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002654 } else {
2655 error = nfs_bdi_register(server);
2656 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11002657 goto error_splat_bdi;
Trond Myklebust5dd31772006-08-24 01:03:05 -04002658 }
2659
David Howells54ceac42006-08-22 20:06:13 -04002660 if (!s->s_root) {
2661 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002662 nfs4_fill_super(s);
David Howells2df54802009-09-23 14:36:39 -04002663 nfs_fscache_get_super_cookie(
2664 s, data ? data->fscache_uniq : NULL, NULL);
Trond Myklebust816724e2006-06-24 08:41:41 -04002665 }
David Howellsf7b422b2006-06-09 09:34:33 -04002666
Al Viro0d5839a2011-03-16 05:27:27 -04002667 mntroot = nfs4_get_root(s, mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04002668 if (IS_ERR(mntroot)) {
2669 error = PTR_ERR(mntroot);
2670 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04002671 }
David Howells54ceac42006-08-22 20:06:13 -04002672
Trond Myklebust33852a12008-06-19 14:20:11 -04002673 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Paris46c8ac72008-05-02 13:42:42 -07002674 if (error)
2675 goto error_splat_root;
2676
David Howellsf7b422b2006-06-09 09:34:33 -04002677 s->s_flags |= MS_ACTIVE;
Al Viro31f43472010-10-29 03:38:12 -04002678
2679 security_free_mnt_opts(&data->lsm_opts);
2680 nfs_free_fhandle(mntfh);
2681 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04002682
Chuck Lever29eb9812007-07-01 12:12:30 -04002683out:
Trond Myklebust33852a12008-06-19 14:20:11 -04002684 security_free_mnt_opts(&data->lsm_opts);
2685out_free_fh:
Trond Myklebustb157b062010-04-19 19:05:48 -04002686 nfs_free_fhandle(mntfh);
Al Viro31f43472010-10-29 03:38:12 -04002687 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04002688
Chuck Lever29eb9812007-07-01 12:12:30 -04002689out_free:
2690 nfs_free_server(server);
2691 goto out;
2692
Eric Paris46c8ac72008-05-02 13:42:42 -07002693error_splat_root:
2694 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04002695error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002696 if (server && !s->s_root)
2697 bdi_unregister(&server->backing_dev_info);
2698error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002699 deactivate_locked_super(s);
Chuck Lever29eb9812007-07-01 12:12:30 -04002700 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002701}
2702
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002703static struct vfsmount *nfs_do_root_mount(struct file_system_type *fs_type,
2704 int flags, void *data, const char *hostname)
2705{
2706 struct vfsmount *root_mnt;
2707 char *root_devname;
2708 size_t len;
2709
2710 len = strlen(hostname) + 3;
2711 root_devname = kmalloc(len, GFP_KERNEL);
2712 if (root_devname == NULL)
2713 return ERR_PTR(-ENOMEM);
2714 snprintf(root_devname, len, "%s:/", hostname);
2715 root_mnt = vfs_kern_mount(fs_type, flags, root_devname, data);
2716 kfree(root_devname);
2717 return root_mnt;
2718}
2719
Trond Myklebustce587e02010-04-16 16:22:52 -04002720struct nfs_referral_count {
2721 struct list_head list;
2722 const struct task_struct *task;
2723 unsigned int referral_count;
2724};
2725
2726static LIST_HEAD(nfs_referral_count_list);
2727static DEFINE_SPINLOCK(nfs_referral_count_list_lock);
2728
2729static struct nfs_referral_count *nfs_find_referral_count(void)
2730{
2731 struct nfs_referral_count *p;
2732
2733 list_for_each_entry(p, &nfs_referral_count_list, list) {
2734 if (p->task == current)
2735 return p;
2736 }
2737 return NULL;
2738}
2739
2740#define NFS_MAX_NESTED_REFERRALS 2
2741
2742static int nfs_referral_loop_protect(void)
2743{
2744 struct nfs_referral_count *p, *new;
2745 int ret = -ENOMEM;
2746
2747 new = kmalloc(sizeof(*new), GFP_KERNEL);
2748 if (!new)
2749 goto out;
2750 new->task = current;
2751 new->referral_count = 1;
2752
2753 ret = 0;
2754 spin_lock(&nfs_referral_count_list_lock);
2755 p = nfs_find_referral_count();
2756 if (p != NULL) {
2757 if (p->referral_count >= NFS_MAX_NESTED_REFERRALS)
2758 ret = -ELOOP;
2759 else
2760 p->referral_count++;
2761 } else {
2762 list_add(&new->list, &nfs_referral_count_list);
2763 new = NULL;
2764 }
2765 spin_unlock(&nfs_referral_count_list_lock);
2766 kfree(new);
2767out:
2768 return ret;
2769}
2770
2771static void nfs_referral_loop_unprotect(void)
2772{
2773 struct nfs_referral_count *p;
2774
2775 spin_lock(&nfs_referral_count_list_lock);
2776 p = nfs_find_referral_count();
2777 p->referral_count--;
2778 if (p->referral_count == 0)
2779 list_del(&p->list);
2780 else
2781 p = NULL;
2782 spin_unlock(&nfs_referral_count_list_lock);
2783 kfree(p);
2784}
2785
Al Viro01194982011-03-16 07:25:36 -04002786static struct dentry *nfs_follow_remote_path(struct vfsmount *root_mnt,
2787 const char *export_path)
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002788{
Al Viro01194982011-03-16 07:25:36 -04002789 struct dentry *dentry;
Al Viro5352d3b2011-11-16 21:52:06 -05002790 int err;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002791
Al Viro5352d3b2011-11-16 21:52:06 -05002792 if (IS_ERR(root_mnt))
2793 return ERR_CAST(root_mnt);
2794
2795 err = nfs_referral_loop_protect();
2796 if (err) {
Al Viroea441d12011-11-16 21:43:59 -05002797 mntput(root_mnt);
Al Viro5352d3b2011-11-16 21:52:06 -05002798 return ERR_PTR(err);
Al Viroc1334492011-11-16 16:12:14 -05002799 }
Trond Myklebustce587e02010-04-16 16:22:52 -04002800
Al Viroea441d12011-11-16 21:43:59 -05002801 dentry = mount_subtree(root_mnt, export_path);
2802 nfs_referral_loop_unprotect();
Linus Torvaldsa2770d82009-12-17 12:51:05 -08002803
Al Viro01194982011-03-16 07:25:36 -04002804 return dentry;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002805}
2806
Al Viro01194982011-03-16 07:25:36 -04002807static struct dentry *nfs4_try_mount(int flags, const char *dev_name,
2808 struct nfs_parsed_mount_data *data)
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002809{
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002810 char *export_path;
2811 struct vfsmount *root_mnt;
Al Viro01194982011-03-16 07:25:36 -04002812 struct dentry *res;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002813
Chuck Levera6fe23b2009-09-08 19:50:00 -04002814 dfprintk(MOUNT, "--> nfs4_try_mount()\n");
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002815
2816 export_path = data->nfs_server.export_path;
2817 data->nfs_server.export_path = "/";
2818 root_mnt = nfs_do_root_mount(&nfs4_remote_fs_type, flags, data,
2819 data->nfs_server.hostname);
2820 data->nfs_server.export_path = export_path;
2821
Al Viro5352d3b2011-11-16 21:52:06 -05002822 res = nfs_follow_remote_path(root_mnt, export_path);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002823
Al Viro01194982011-03-16 07:25:36 -04002824 dfprintk(MOUNT, "<-- nfs4_try_mount() = %ld%s\n",
2825 IS_ERR(res) ? PTR_ERR(res) : 0,
2826 IS_ERR(res) ? " [error]" : "");
2827 return res;
Chuck Levera6fe23b2009-09-08 19:50:00 -04002828}
2829
2830/*
2831 * Get the superblock for an NFS4 mountpoint
2832 */
Al Viro01194982011-03-16 07:25:36 -04002833static struct dentry *nfs4_mount(struct file_system_type *fs_type,
2834 int flags, const char *dev_name, void *raw_data)
Chuck Levera6fe23b2009-09-08 19:50:00 -04002835{
2836 struct nfs_parsed_mount_data *data;
2837 int error = -ENOMEM;
Al Viro01194982011-03-16 07:25:36 -04002838 struct dentry *res = ERR_PTR(-ENOMEM);
Chuck Levera6fe23b2009-09-08 19:50:00 -04002839
Trond Myklebustc5811db2009-10-06 15:40:15 -04002840 data = nfs_alloc_parsed_mount_data(4);
Chuck Levera6fe23b2009-09-08 19:50:00 -04002841 if (data == NULL)
2842 goto out_free_data;
2843
2844 /* Validate the mount data */
2845 error = nfs4_validate_mount_data(raw_data, data, dev_name);
Al Viro01194982011-03-16 07:25:36 -04002846 if (error < 0) {
2847 res = ERR_PTR(error);
Chuck Levera6fe23b2009-09-08 19:50:00 -04002848 goto out;
Al Viro01194982011-03-16 07:25:36 -04002849 }
Chuck Levera6fe23b2009-09-08 19:50:00 -04002850
Al Viro01194982011-03-16 07:25:36 -04002851 res = nfs4_try_mount(flags, dev_name, data);
2852 if (IS_ERR(res))
2853 error = PTR_ERR(res);
Chuck Levera6fe23b2009-09-08 19:50:00 -04002854
2855out:
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002856 kfree(data->client_address);
2857 kfree(data->nfs_server.export_path);
2858 kfree(data->nfs_server.hostname);
2859 kfree(data->fscache_uniq);
2860out_free_data:
2861 kfree(data);
Al Viro01194982011-03-16 07:25:36 -04002862 dprintk("<-- nfs4_mount() = %d%s\n", error,
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002863 error != 0 ? " [error]" : "");
Al Viro01194982011-03-16 07:25:36 -04002864 return res;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002865}
2866
David Howellsf7b422b2006-06-09 09:34:33 -04002867static void nfs4_kill_super(struct super_block *sb)
2868{
2869 struct nfs_server *server = NFS_SB(sb);
2870
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002871 dprintk("--> %s\n", __func__);
Trond Myklebust515d8612008-12-23 15:21:46 -05002872 nfs_super_return_all_delegations(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002873 kill_anon_super(sb);
David Howells08734042009-04-03 16:42:42 +01002874 nfs_fscache_release_super_cookie(sb);
David Howells54ceac42006-08-22 20:06:13 -04002875 nfs_free_server(server);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002876 dprintk("<-- %s\n", __func__);
David Howellsf7b422b2006-06-09 09:34:33 -04002877}
2878
2879/*
David Howells54ceac42006-08-22 20:06:13 -04002880 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -04002881 */
Al Viro31f43472010-10-29 03:38:12 -04002882static struct dentry *
2883nfs4_xdev_mount(struct file_system_type *fs_type, int flags,
2884 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002885{
2886 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002887 struct super_block *s;
2888 struct nfs_server *server;
2889 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002890 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002891 struct nfs_sb_mountdata sb_mntdata = {
2892 .mntflags = flags,
2893 };
David Howells54ceac42006-08-22 20:06:13 -04002894 int error;
2895
Al Viro31f43472010-10-29 03:38:12 -04002896 dprintk("--> nfs4_xdev_mount()\n");
David Howells54ceac42006-08-22 20:06:13 -04002897
2898 /* create a new volume representation */
2899 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2900 if (IS_ERR(server)) {
2901 error = PTR_ERR(server);
2902 goto out_err_noserver;
2903 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002904 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002905
Trond Myklebust75180df2007-05-16 16:53:28 -04002906 if (server->flags & NFS4_MOUNT_UNSHARED)
2907 compare_super = NULL;
2908
Sachin Prabhufb2088c2011-08-01 12:10:12 +01002909 /* -o noac implies -o sync */
2910 if (server->flags & NFS_MOUNT_NOAC)
2911 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
2912
David Howells54ceac42006-08-22 20:06:13 -04002913 /* Get a superblock - note that we may end up sharing one that already exists */
Andy Adamsonec9a05c2008-10-17 10:44:37 -04002914 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002915 if (IS_ERR(s)) {
2916 error = PTR_ERR(s);
2917 goto out_err_nosb;
2918 }
2919
2920 if (s->s_fs_info != server) {
2921 nfs_free_server(server);
2922 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002923 } else {
2924 error = nfs_bdi_register(server);
2925 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11002926 goto error_splat_bdi;
David Howells54ceac42006-08-22 20:06:13 -04002927 }
2928
2929 if (!s->s_root) {
2930 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002931 nfs4_clone_super(s, data->sb);
David Howells2df54802009-09-23 14:36:39 -04002932 nfs_fscache_get_super_cookie(s, NULL, data);
David Howells54ceac42006-08-22 20:06:13 -04002933 }
2934
Al Viro0d5839a2011-03-16 05:27:27 -04002935 mntroot = nfs4_get_root(s, data->fh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04002936 if (IS_ERR(mntroot)) {
2937 error = PTR_ERR(mntroot);
2938 goto error_splat_super;
2939 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002940 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2941 dput(mntroot);
2942 error = -ESTALE;
2943 goto error_splat_super;
2944 }
David Howells54ceac42006-08-22 20:06:13 -04002945
2946 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002947
Eric Paris46c8ac72008-05-02 13:42:42 -07002948 security_sb_clone_mnt_opts(data->sb, s);
2949
Al Viro31f43472010-10-29 03:38:12 -04002950 dprintk("<-- nfs4_xdev_mount() = 0\n");
2951 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04002952
2953out_err_nosb:
2954 nfs_free_server(server);
2955out_err_noserver:
Al Viro31f43472010-10-29 03:38:12 -04002956 dprintk("<-- nfs4_xdev_mount() = %d [error]\n", error);
2957 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04002958
2959error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002960 if (server && !s->s_root)
2961 bdi_unregister(&server->backing_dev_info);
2962error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002963 deactivate_locked_super(s);
Al Viro31f43472010-10-29 03:38:12 -04002964 dprintk("<-- nfs4_xdev_mount() = %d [splat]\n", error);
2965 return ERR_PTR(error);
David Howellsf7b422b2006-06-09 09:34:33 -04002966}
2967
Al Viro31f43472010-10-29 03:38:12 -04002968static struct dentry *
2969nfs4_remote_referral_mount(struct file_system_type *fs_type, int flags,
2970 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002971{
2972 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002973 struct super_block *s;
2974 struct nfs_server *server;
2975 struct dentry *mntroot;
Trond Myklebust4f727292010-04-16 16:22:48 -04002976 struct nfs_fh *mntfh;
Trond Myklebust75180df2007-05-16 16:53:28 -04002977 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002978 struct nfs_sb_mountdata sb_mntdata = {
2979 .mntflags = flags,
2980 };
Trond Myklebust4f727292010-04-16 16:22:48 -04002981 int error = -ENOMEM;
David Howells54ceac42006-08-22 20:06:13 -04002982
2983 dprintk("--> nfs4_referral_get_sb()\n");
2984
Trond Myklebust4f727292010-04-16 16:22:48 -04002985 mntfh = nfs_alloc_fhandle();
2986 if (mntfh == NULL)
2987 goto out_err_nofh;
2988
David Howells54ceac42006-08-22 20:06:13 -04002989 /* create a new volume representation */
Trond Myklebust4f727292010-04-16 16:22:48 -04002990 server = nfs4_create_referral_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002991 if (IS_ERR(server)) {
2992 error = PTR_ERR(server);
2993 goto out_err_noserver;
2994 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002995 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002996
Trond Myklebust75180df2007-05-16 16:53:28 -04002997 if (server->flags & NFS4_MOUNT_UNSHARED)
2998 compare_super = NULL;
2999
Sachin Prabhufb2088c2011-08-01 12:10:12 +01003000 /* -o noac implies -o sync */
3001 if (server->flags & NFS_MOUNT_NOAC)
3002 sb_mntdata.mntflags |= MS_SYNCHRONOUS;
3003
David Howells54ceac42006-08-22 20:06:13 -04003004 /* Get a superblock - note that we may end up sharing one that already exists */
Andy Adamsonec9a05c2008-10-17 10:44:37 -04003005 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04003006 if (IS_ERR(s)) {
3007 error = PTR_ERR(s);
3008 goto out_err_nosb;
3009 }
3010
3011 if (s->s_fs_info != server) {
3012 nfs_free_server(server);
3013 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07003014 } else {
3015 error = nfs_bdi_register(server);
3016 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11003017 goto error_splat_bdi;
David Howells54ceac42006-08-22 20:06:13 -04003018 }
3019
3020 if (!s->s_root) {
3021 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04003022 nfs4_fill_super(s);
David Howells2df54802009-09-23 14:36:39 -04003023 nfs_fscache_get_super_cookie(s, NULL, data);
David Howells54ceac42006-08-22 20:06:13 -04003024 }
3025
Al Viro0d5839a2011-03-16 05:27:27 -04003026 mntroot = nfs4_get_root(s, mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04003027 if (IS_ERR(mntroot)) {
3028 error = PTR_ERR(mntroot);
3029 goto error_splat_super;
3030 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05003031 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
3032 dput(mntroot);
3033 error = -ESTALE;
3034 goto error_splat_super;
3035 }
David Howells54ceac42006-08-22 20:06:13 -04003036
3037 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04003038
Eric Paris46c8ac72008-05-02 13:42:42 -07003039 security_sb_clone_mnt_opts(data->sb, s);
3040
Trond Myklebust4f727292010-04-16 16:22:48 -04003041 nfs_free_fhandle(mntfh);
David Howells54ceac42006-08-22 20:06:13 -04003042 dprintk("<-- nfs4_referral_get_sb() = 0\n");
Al Viro31f43472010-10-29 03:38:12 -04003043 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04003044
3045out_err_nosb:
3046 nfs_free_server(server);
3047out_err_noserver:
Trond Myklebust4f727292010-04-16 16:22:48 -04003048 nfs_free_fhandle(mntfh);
3049out_err_nofh:
David Howells54ceac42006-08-22 20:06:13 -04003050 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
Al Viro31f43472010-10-29 03:38:12 -04003051 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04003052
3053error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11003054 if (server && !s->s_root)
3055 bdi_unregister(&server->backing_dev_info);
3056error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04003057 deactivate_locked_super(s);
Trond Myklebust4f727292010-04-16 16:22:48 -04003058 nfs_free_fhandle(mntfh);
David Howells54ceac42006-08-22 20:06:13 -04003059 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
Al Viro31f43472010-10-29 03:38:12 -04003060 return ERR_PTR(error);
David Howellsf7b422b2006-06-09 09:34:33 -04003061}
3062
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04003063/*
3064 * Create an NFS4 server record on referral traversal
3065 */
Al Viro01194982011-03-16 07:25:36 -04003066static struct dentry *nfs4_referral_mount(struct file_system_type *fs_type,
3067 int flags, const char *dev_name, void *raw_data)
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04003068{
3069 struct nfs_clone_mount *data = raw_data;
3070 char *export_path;
3071 struct vfsmount *root_mnt;
Al Viro01194982011-03-16 07:25:36 -04003072 struct dentry *res;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04003073
Al Viro01194982011-03-16 07:25:36 -04003074 dprintk("--> nfs4_referral_mount()\n");
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04003075
3076 export_path = data->mnt_path;
3077 data->mnt_path = "/";
3078
3079 root_mnt = nfs_do_root_mount(&nfs4_remote_referral_fs_type,
3080 flags, data, data->hostname);
3081 data->mnt_path = export_path;
3082
Al Viro5352d3b2011-11-16 21:52:06 -05003083 res = nfs_follow_remote_path(root_mnt, export_path);
Al Viro01194982011-03-16 07:25:36 -04003084 dprintk("<-- nfs4_referral_mount() = %ld%s\n",
3085 IS_ERR(res) ? PTR_ERR(res) : 0,
3086 IS_ERR(res) ? " [error]" : "");
3087 return res;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04003088}
3089
David Howells54ceac42006-08-22 20:06:13 -04003090#endif /* CONFIG_NFS_V4 */