blob: 9587506d493c320b36249de69495359f51d721c0 [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>
42#include <linux/smp_lock.h>
43#include <linux/seq_file.h>
44#include <linux/mount.h>
Trond Myklebustc02d7ad2009-06-22 15:09:14 -040045#include <linux/mnt_namespace.h>
46#include <linux/namei.h>
David Howellsf7b422b2006-06-09 09:34:33 -040047#include <linux/nfs_idmap.h>
48#include <linux/vfs.h>
49#include <linux/inet.h>
Chuck Leverfd00a8f2007-12-10 14:57:38 -050050#include <linux/in6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090051#include <linux/slab.h>
Chuck Leverfd00a8f2007-12-10 14:57:38 -050052#include <net/ipv6.h>
Chuck Leverd8e77482008-06-23 12:37:01 -040053#include <linux/netdevice.h>
David Howellsf7b422b2006-06-09 09:34:33 -040054#include <linux/nfs_xdr.h>
Adrian Bunkb5d5dfb2007-02-12 00:53:40 -080055#include <linux/magic.h>
Chuck Leverbf0fd762007-07-01 12:13:44 -040056#include <linux/parser.h>
David Howellsf7b422b2006-06-09 09:34:33 -040057
58#include <asm/system.h>
59#include <asm/uaccess.h>
60
61#include "nfs4_fs.h"
62#include "callback.h"
63#include "delegation.h"
64#include "iostat.h"
65#include "internal.h"
David Howells08734042009-04-03 16:42:42 +010066#include "fscache.h"
David Howellsf7b422b2006-06-09 09:34:33 -040067
68#define NFSDBG_FACILITY NFSDBG_VFS
69
Paulius Zaleckas1e657bd2010-10-31 18:21:05 +020070#ifdef CONFIG_NFS_V3
71#define NFS_DEFAULT_VERSION 3
72#else
73#define NFS_DEFAULT_VERSION 2
74#endif
75
Chuck Leverbf0fd762007-07-01 12:13:44 -040076enum {
77 /* Mount options that take no arguments */
78 Opt_soft, Opt_hard,
Chuck Leverbf0fd762007-07-01 12:13:44 -040079 Opt_posix, Opt_noposix,
80 Opt_cto, Opt_nocto,
81 Opt_ac, Opt_noac,
82 Opt_lock, Opt_nolock,
Chuck Lever764302c2009-09-08 19:50:03 -040083 Opt_v2, Opt_v3, Opt_v4,
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -040084 Opt_udp, Opt_tcp, Opt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -040085 Opt_acl, Opt_noacl,
86 Opt_rdirplus, Opt_nordirplus,
Trond Myklebust75180df2007-05-16 16:53:28 -040087 Opt_sharecache, Opt_nosharecache,
Chuck Leverd7403512008-12-23 15:21:37 -050088 Opt_resvport, Opt_noresvport,
David Howellsb797cac2009-04-03 16:42:48 +010089 Opt_fscache, Opt_nofscache,
Chuck Leverbf0fd762007-07-01 12:13:44 -040090
91 /* Mount options that take integer arguments */
92 Opt_port,
93 Opt_rsize, Opt_wsize, Opt_bsize,
94 Opt_timeo, Opt_retrans,
95 Opt_acregmin, Opt_acregmax,
96 Opt_acdirmin, Opt_acdirmax,
97 Opt_actimeo,
98 Opt_namelen,
99 Opt_mountport,
Chuck Levere887cbc2007-10-26 13:32:29 -0400100 Opt_mountvers,
Chuck Leverad879ce2007-10-26 13:32:24 -0400101 Opt_nfsvers,
Mike Sager3fd5be92009-04-01 09:21:48 -0400102 Opt_minorversion,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400103
104 /* Mount options that take string arguments */
Chuck Lever33832032007-12-10 14:59:13 -0500105 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
Chuck Lever0ac83772007-09-11 18:01:04 -0400106 Opt_addr, Opt_mountaddr, Opt_clientaddr,
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400107 Opt_lookupcache,
David Howellsb797cac2009-04-03 16:42:48 +0100108 Opt_fscache_uniq,
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400109 Opt_local_lock,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400110
Chuck Leverf45663c2008-06-24 19:28:02 -0400111 /* Special mount options */
112 Opt_userspace, Opt_deprecated, Opt_sloppy,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400113
114 Opt_err
115};
116
Steven Whitehousea447c092008-10-13 10:46:57 +0100117static const match_table_t nfs_mount_option_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400118 { Opt_userspace, "bg" },
119 { Opt_userspace, "fg" },
Chuck Leverecbb3842008-06-12 12:37:33 -0400120 { Opt_userspace, "retry=%s" },
121
Chuck Leverf45663c2008-06-24 19:28:02 -0400122 { Opt_sloppy, "sloppy" },
123
Chuck Leverbf0fd762007-07-01 12:13:44 -0400124 { Opt_soft, "soft" },
125 { Opt_hard, "hard" },
Chuck Leverd33e4df2008-06-12 12:37:41 -0400126 { Opt_deprecated, "intr" },
127 { Opt_deprecated, "nointr" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400128 { Opt_posix, "posix" },
129 { Opt_noposix, "noposix" },
130 { Opt_cto, "cto" },
131 { Opt_nocto, "nocto" },
132 { Opt_ac, "ac" },
133 { Opt_noac, "noac" },
134 { Opt_lock, "lock" },
135 { Opt_nolock, "nolock" },
136 { Opt_v2, "v2" },
137 { Opt_v3, "v3" },
Chuck Lever764302c2009-09-08 19:50:03 -0400138 { Opt_v4, "v4" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400139 { Opt_udp, "udp" },
140 { Opt_tcp, "tcp" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400141 { Opt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400142 { Opt_acl, "acl" },
143 { Opt_noacl, "noacl" },
144 { Opt_rdirplus, "rdirplus" },
145 { Opt_nordirplus, "nordirplus" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400146 { Opt_sharecache, "sharecache" },
147 { Opt_nosharecache, "nosharecache" },
Chuck Leverd7403512008-12-23 15:21:37 -0500148 { Opt_resvport, "resvport" },
149 { Opt_noresvport, "noresvport" },
David Howellsb797cac2009-04-03 16:42:48 +0100150 { Opt_fscache, "fsc" },
David Howellsb797cac2009-04-03 16:42:48 +0100151 { Opt_nofscache, "nofsc" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400152
Chuck Levera5a16ba2009-06-17 18:02:14 -0700153 { Opt_port, "port=%s" },
154 { Opt_rsize, "rsize=%s" },
155 { Opt_wsize, "wsize=%s" },
156 { Opt_bsize, "bsize=%s" },
157 { Opt_timeo, "timeo=%s" },
158 { Opt_retrans, "retrans=%s" },
159 { Opt_acregmin, "acregmin=%s" },
160 { Opt_acregmax, "acregmax=%s" },
161 { Opt_acdirmin, "acdirmin=%s" },
162 { Opt_acdirmax, "acdirmax=%s" },
163 { Opt_actimeo, "actimeo=%s" },
164 { Opt_namelen, "namlen=%s" },
165 { Opt_mountport, "mountport=%s" },
166 { Opt_mountvers, "mountvers=%s" },
167 { Opt_nfsvers, "nfsvers=%s" },
168 { Opt_nfsvers, "vers=%s" },
Chuck Leverf3f4f4e2009-08-09 15:09:29 -0400169 { Opt_minorversion, "minorversion=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400170
171 { Opt_sec, "sec=%s" },
172 { Opt_proto, "proto=%s" },
173 { Opt_mountproto, "mountproto=%s" },
174 { Opt_addr, "addr=%s" },
175 { Opt_clientaddr, "clientaddr=%s" },
Chuck Lever33832032007-12-10 14:59:13 -0500176 { Opt_mounthost, "mounthost=%s" },
Chuck Lever0ac83772007-09-11 18:01:04 -0400177 { Opt_mountaddr, "mountaddr=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400178
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400179 { Opt_lookupcache, "lookupcache=%s" },
Chuck Levera6d5ff62010-05-07 13:33:58 -0400180 { Opt_fscache_uniq, "fsc=%s" },
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400181 { Opt_local_lock, "local_lock=%s" },
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400182
Chuck Leverbf0fd762007-07-01 12:13:44 -0400183 { Opt_err, NULL }
184};
185
186enum {
Jeff Laytonee671b02009-12-03 15:58:56 -0500187 Opt_xprt_udp, Opt_xprt_udp6, Opt_xprt_tcp, Opt_xprt_tcp6, Opt_xprt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400188
189 Opt_xprt_err
190};
191
Steven Whitehousea447c092008-10-13 10:46:57 +0100192static const match_table_t nfs_xprt_protocol_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400193 { Opt_xprt_udp, "udp" },
Jeff Laytonee671b02009-12-03 15:58:56 -0500194 { Opt_xprt_udp6, "udp6" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400195 { Opt_xprt_tcp, "tcp" },
Jeff Laytonee671b02009-12-03 15:58:56 -0500196 { Opt_xprt_tcp6, "tcp6" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400197 { Opt_xprt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400198
199 { Opt_xprt_err, NULL }
200};
201
202enum {
203 Opt_sec_none, Opt_sec_sys,
204 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
205 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
206 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
207
208 Opt_sec_err
209};
210
Steven Whitehousea447c092008-10-13 10:46:57 +0100211static const match_table_t nfs_secflavor_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400212 { Opt_sec_none, "none" },
213 { Opt_sec_none, "null" },
214 { Opt_sec_sys, "sys" },
215
216 { Opt_sec_krb5, "krb5" },
217 { Opt_sec_krb5i, "krb5i" },
218 { Opt_sec_krb5p, "krb5p" },
219
220 { Opt_sec_lkey, "lkey" },
221 { Opt_sec_lkeyi, "lkeyi" },
222 { Opt_sec_lkeyp, "lkeyp" },
223
Olga Kornievskaia8d042212008-02-13 16:47:06 -0500224 { Opt_sec_spkm, "spkm3" },
225 { Opt_sec_spkmi, "spkm3i" },
226 { Opt_sec_spkmp, "spkm3p" },
227
Chuck Leverbf0fd762007-07-01 12:13:44 -0400228 { Opt_sec_err, NULL }
229};
230
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400231enum {
232 Opt_lookupcache_all, Opt_lookupcache_positive,
233 Opt_lookupcache_none,
234
235 Opt_lookupcache_err
236};
237
238static match_table_t nfs_lookupcache_tokens = {
239 { Opt_lookupcache_all, "all" },
240 { Opt_lookupcache_positive, "pos" },
241 { Opt_lookupcache_positive, "positive" },
242 { Opt_lookupcache_none, "none" },
243
244 { Opt_lookupcache_err, NULL }
245};
246
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400247enum {
248 Opt_local_lock_all, Opt_local_lock_flock, Opt_local_lock_posix,
249 Opt_local_lock_none,
250
251 Opt_local_lock_err
252};
253
254static match_table_t nfs_local_lock_tokens = {
255 { Opt_local_lock_all, "all" },
256 { Opt_local_lock_flock, "flock" },
257 { Opt_local_lock_posix, "posix" },
258 { Opt_local_lock_none, "none" },
259
260 { Opt_local_lock_err, NULL }
261};
262
Chuck Leverbf0fd762007-07-01 12:13:44 -0400263
Al Viro42faad92008-04-24 07:21:56 -0400264static void nfs_umount_begin(struct super_block *);
Trond Myklebust816724e2006-06-24 08:41:41 -0400265static int nfs_statfs(struct dentry *, struct kstatfs *);
David Howellsf7b422b2006-06-09 09:34:33 -0400266static int nfs_show_options(struct seq_file *, struct vfsmount *);
267static int nfs_show_stats(struct seq_file *, struct vfsmount *);
Trond Myklebust816724e2006-06-24 08:41:41 -0400268static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
Al Viro31f43472010-10-29 03:38:12 -0400269static struct dentry *nfs_xdev_mount(struct file_system_type *fs_type,
270 int flags, const char *dev_name, void *raw_data);
Trond Myklebust387c1492010-02-03 08:27:35 -0500271static void nfs_put_super(struct super_block *);
David Howellsf7b422b2006-06-09 09:34:33 -0400272static void nfs_kill_super(struct super_block *);
Jeff Layton48b605f2008-06-10 15:38:39 -0400273static int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
David Howellsf7b422b2006-06-09 09:34:33 -0400274
275static struct file_system_type nfs_fs_type = {
276 .owner = THIS_MODULE,
277 .name = "nfs",
278 .get_sb = nfs_get_sb,
279 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700280 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400281};
282
David Howells54ceac42006-08-22 20:06:13 -0400283struct file_system_type nfs_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400284 .owner = THIS_MODULE,
285 .name = "nfs",
Al Viro31f43472010-10-29 03:38:12 -0400286 .mount = nfs_xdev_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400287 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700288 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400289};
290
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800291static const struct super_operations nfs_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400292 .alloc_inode = nfs_alloc_inode,
293 .destroy_inode = nfs_destroy_inode,
294 .write_inode = nfs_write_inode,
Trond Myklebust387c1492010-02-03 08:27:35 -0500295 .put_super = nfs_put_super,
David Howellsf7b422b2006-06-09 09:34:33 -0400296 .statfs = nfs_statfs,
Al Virob57922d2010-06-07 14:34:48 -0400297 .evict_inode = nfs_evict_inode,
David Howellsf7b422b2006-06-09 09:34:33 -0400298 .umount_begin = nfs_umount_begin,
299 .show_options = nfs_show_options,
300 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400301 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400302};
303
304#ifdef CONFIG_NFS_V4
Chuck Lever7630c852009-09-08 19:49:57 -0400305static int nfs4_validate_text_mount_data(void *options,
306 struct nfs_parsed_mount_data *args, const char *dev_name);
Chuck Levera6fe23b2009-09-08 19:50:00 -0400307static int nfs4_try_mount(int flags, const char *dev_name,
308 struct nfs_parsed_mount_data *data, struct vfsmount *mnt);
Trond Myklebust816724e2006-06-24 08:41:41 -0400309static int nfs4_get_sb(struct file_system_type *fs_type,
310 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
Al Viro31f43472010-10-29 03:38:12 -0400311static struct dentry *nfs4_remote_mount(struct file_system_type *fs_type,
312 int flags, const char *dev_name, void *raw_data);
313static struct dentry *nfs4_xdev_mount(struct file_system_type *fs_type,
314 int flags, const char *dev_name, void *raw_data);
David Howells54ceac42006-08-22 20:06:13 -0400315static int nfs4_referral_get_sb(struct file_system_type *fs_type,
316 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
Al Viro31f43472010-10-29 03:38:12 -0400317static struct dentry *nfs4_remote_referral_mount(struct file_system_type *fs_type,
318 int flags, const char *dev_name, void *raw_data);
David Howellsf7b422b2006-06-09 09:34:33 -0400319static void nfs4_kill_super(struct super_block *sb);
320
321static struct file_system_type nfs4_fs_type = {
322 .owner = THIS_MODULE,
323 .name = "nfs4",
324 .get_sb = nfs4_get_sb,
325 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700326 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400327};
328
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400329static struct file_system_type nfs4_remote_fs_type = {
330 .owner = THIS_MODULE,
331 .name = "nfs4",
Al Viro31f43472010-10-29 03:38:12 -0400332 .mount = nfs4_remote_mount,
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400333 .kill_sb = nfs4_kill_super,
334 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
335};
336
David Howells54ceac42006-08-22 20:06:13 -0400337struct file_system_type nfs4_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400338 .owner = THIS_MODULE,
339 .name = "nfs4",
Al Viro31f43472010-10-29 03:38:12 -0400340 .mount = nfs4_xdev_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400341 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700342 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400343};
344
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400345static struct file_system_type nfs4_remote_referral_fs_type = {
346 .owner = THIS_MODULE,
347 .name = "nfs4",
Al Viro31f43472010-10-29 03:38:12 -0400348 .mount = nfs4_remote_referral_mount,
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400349 .kill_sb = nfs4_kill_super,
350 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
351};
352
David Howells54ceac42006-08-22 20:06:13 -0400353struct file_system_type nfs4_referral_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400354 .owner = THIS_MODULE,
355 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400356 .get_sb = nfs4_referral_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400357 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700358 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400359};
360
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800361static const struct super_operations nfs4_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400362 .alloc_inode = nfs_alloc_inode,
363 .destroy_inode = nfs_destroy_inode,
364 .write_inode = nfs_write_inode,
Trond Myklebust387c1492010-02-03 08:27:35 -0500365 .put_super = nfs_put_super,
David Howellsf7b422b2006-06-09 09:34:33 -0400366 .statfs = nfs_statfs,
Al Virob57922d2010-06-07 14:34:48 -0400367 .evict_inode = nfs4_evict_inode,
David Howellsf7b422b2006-06-09 09:34:33 -0400368 .umount_begin = nfs_umount_begin,
369 .show_options = nfs_show_options,
370 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400371 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400372};
373#endif
374
Rusty Russell8e1f9362007-07-17 04:03:17 -0700375static struct shrinker acl_shrinker = {
376 .shrink = nfs_access_cache_shrinker,
377 .seeks = DEFAULT_SEEKS,
378};
Trond Myklebust979df722006-07-25 11:28:19 -0400379
David Howellsf7b422b2006-06-09 09:34:33 -0400380/*
381 * Register the NFS filesystems
382 */
383int __init register_nfs_fs(void)
384{
385 int ret;
386
387 ret = register_filesystem(&nfs_fs_type);
388 if (ret < 0)
389 goto error_0;
390
David Howellsf7b422b2006-06-09 09:34:33 -0400391 ret = nfs_register_sysctl();
392 if (ret < 0)
393 goto error_1;
Peter Zijlstra89a09142007-03-16 13:38:26 -0800394#ifdef CONFIG_NFS_V4
David Howellsf7b422b2006-06-09 09:34:33 -0400395 ret = register_filesystem(&nfs4_fs_type);
396 if (ret < 0)
397 goto error_2;
398#endif
Rusty Russell8e1f9362007-07-17 04:03:17 -0700399 register_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400400 return 0;
401
402#ifdef CONFIG_NFS_V4
403error_2:
404 nfs_unregister_sysctl();
Peter Zijlstra89a09142007-03-16 13:38:26 -0800405#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400406error_1:
407 unregister_filesystem(&nfs_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400408error_0:
409 return ret;
410}
411
412/*
413 * Unregister the NFS filesystems
414 */
415void __exit unregister_nfs_fs(void)
416{
Rusty Russell8e1f9362007-07-17 04:03:17 -0700417 unregister_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400418#ifdef CONFIG_NFS_V4
419 unregister_filesystem(&nfs4_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400420#endif
Alexey Dobriyan49af7ee2007-09-18 22:46:40 -0700421 nfs_unregister_sysctl();
David Howellsf7b422b2006-06-09 09:34:33 -0400422 unregister_filesystem(&nfs_fs_type);
423}
424
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400425void nfs_sb_active(struct super_block *sb)
Steve Dicksonef818a22007-11-08 04:05:04 -0500426{
427 struct nfs_server *server = NFS_SB(sb);
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400428
429 if (atomic_inc_return(&server->active) == 1)
430 atomic_inc(&sb->s_active);
431}
432
433void nfs_sb_deactive(struct super_block *sb)
434{
435 struct nfs_server *server = NFS_SB(sb);
436
437 if (atomic_dec_and_test(&server->active))
438 deactivate_super(sb);
Steve Dicksonef818a22007-11-08 04:05:04 -0500439}
440
David Howellsf7b422b2006-06-09 09:34:33 -0400441/*
442 * Deliver file system statistics to userspace
443 */
Trond Myklebust816724e2006-06-24 08:41:41 -0400444static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
David Howellsf7b422b2006-06-09 09:34:33 -0400445{
David Howells0c7d90c2006-08-22 20:06:10 -0400446 struct nfs_server *server = NFS_SB(dentry->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400447 unsigned char blockbits;
448 unsigned long blockres;
David Howells0c7d90c2006-08-22 20:06:10 -0400449 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400450 struct nfs_fsstat res;
451 int error = -ENOMEM;
452
453 res.fattr = nfs_alloc_fattr();
454 if (res.fattr == NULL)
455 goto out_err;
David Howellsf7b422b2006-06-09 09:34:33 -0400456
David Howells8fa5c002006-08-22 20:06:12 -0400457 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
Menyhart Zoltanfbf3fdd2010-09-12 19:55:26 -0400458 if (unlikely(error == -ESTALE)) {
459 struct dentry *pd_dentry;
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400460
Menyhart Zoltanfbf3fdd2010-09-12 19:55:26 -0400461 pd_dentry = dget_parent(dentry);
462 if (pd_dentry != NULL) {
463 nfs_zap_caches(pd_dentry->d_inode);
464 dput(pd_dentry);
465 }
466 }
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400467 nfs_free_fattr(res.fattr);
David Howellsf7b422b2006-06-09 09:34:33 -0400468 if (error < 0)
469 goto out_err;
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400470
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700471 buf->f_type = NFS_SUPER_MAGIC;
David Howellsf7b422b2006-06-09 09:34:33 -0400472
473 /*
474 * Current versions of glibc do not correctly handle the
475 * case where f_frsize != f_bsize. Eventually we want to
476 * report the value of wtmult in this field.
477 */
David Howells0c7d90c2006-08-22 20:06:10 -0400478 buf->f_frsize = dentry->d_sb->s_blocksize;
David Howellsf7b422b2006-06-09 09:34:33 -0400479
480 /*
481 * On most *nix systems, f_blocks, f_bfree, and f_bavail
482 * are reported in units of f_frsize. Linux hasn't had
483 * an f_frsize field in its statfs struct until recently,
484 * thus historically Linux's sys_statfs reports these
485 * fields in units of f_bsize.
486 */
David Howells0c7d90c2006-08-22 20:06:10 -0400487 buf->f_bsize = dentry->d_sb->s_blocksize;
488 blockbits = dentry->d_sb->s_blocksize_bits;
David Howellsf7b422b2006-06-09 09:34:33 -0400489 blockres = (1 << blockbits) - 1;
490 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
491 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
492 buf->f_bavail = (res.abytes + blockres) >> blockbits;
493
494 buf->f_files = res.tfiles;
495 buf->f_ffree = res.afiles;
496
497 buf->f_namelen = server->namelen;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700498
David Howellsf7b422b2006-06-09 09:34:33 -0400499 return 0;
500
501 out_err:
Harvey Harrison3110ff82008-05-02 13:42:44 -0700502 dprintk("%s: statfs error = %d\n", __func__, -error);
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700503 return error;
David Howellsf7b422b2006-06-09 09:34:33 -0400504}
505
David Howells7d4e2742006-08-22 20:06:07 -0400506/*
507 * Map the security flavour number to a name
508 */
Trond Myklebust81039f12006-06-09 09:34:34 -0400509static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
510{
David Howells7d4e2742006-08-22 20:06:07 -0400511 static const struct {
Trond Myklebust81039f12006-06-09 09:34:34 -0400512 rpc_authflavor_t flavour;
513 const char *str;
514 } sec_flavours[] = {
515 { RPC_AUTH_NULL, "null" },
516 { RPC_AUTH_UNIX, "sys" },
517 { RPC_AUTH_GSS_KRB5, "krb5" },
518 { RPC_AUTH_GSS_KRB5I, "krb5i" },
519 { RPC_AUTH_GSS_KRB5P, "krb5p" },
520 { RPC_AUTH_GSS_LKEY, "lkey" },
521 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
522 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
523 { RPC_AUTH_GSS_SPKM, "spkm" },
524 { RPC_AUTH_GSS_SPKMI, "spkmi" },
525 { RPC_AUTH_GSS_SPKMP, "spkmp" },
Chuck Lever4d81cd12007-07-01 12:12:40 -0400526 { UINT_MAX, "unknown" }
Trond Myklebust81039f12006-06-09 09:34:34 -0400527 };
528 int i;
529
Chuck Lever4d81cd12007-07-01 12:12:40 -0400530 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
Trond Myklebust81039f12006-06-09 09:34:34 -0400531 if (sec_flavours[i].flavour == flavour)
532 break;
533 }
534 return sec_flavours[i].str;
535}
536
Jeff Laytonee671b02009-12-03 15:58:56 -0500537static void nfs_show_mountd_netid(struct seq_file *m, struct nfs_server *nfss,
538 int showdefaults)
539{
540 struct sockaddr *sap = (struct sockaddr *) &nfss->mountd_address;
541
542 seq_printf(m, ",mountproto=");
543 switch (sap->sa_family) {
544 case AF_INET:
545 switch (nfss->mountd_protocol) {
546 case IPPROTO_UDP:
547 seq_printf(m, RPCBIND_NETID_UDP);
548 break;
549 case IPPROTO_TCP:
550 seq_printf(m, RPCBIND_NETID_TCP);
551 break;
552 default:
553 if (showdefaults)
554 seq_printf(m, "auto");
555 }
556 break;
557 case AF_INET6:
558 switch (nfss->mountd_protocol) {
559 case IPPROTO_UDP:
560 seq_printf(m, RPCBIND_NETID_UDP6);
561 break;
562 case IPPROTO_TCP:
563 seq_printf(m, RPCBIND_NETID_TCP6);
564 break;
565 default:
566 if (showdefaults)
567 seq_printf(m, "auto");
568 }
569 break;
570 default:
571 if (showdefaults)
572 seq_printf(m, "auto");
573 }
574}
575
Chuck Lever82d101d2008-03-14 14:10:37 -0400576static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
577 int showdefaults)
578{
579 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
580
Bryan Schumakerd5eff1a2010-08-03 13:04:00 -0400581 if (nfss->flags & NFS_MOUNT_LEGACY_INTERFACE)
582 return;
583
Chuck Lever82d101d2008-03-14 14:10:37 -0400584 switch (sap->sa_family) {
585 case AF_INET: {
586 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
Harvey Harrisonbe859402008-10-31 00:56:28 -0700587 seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400588 break;
589 }
590 case AF_INET6: {
591 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
Chuck Leverd250e192009-12-03 15:58:56 -0500592 seq_printf(m, ",mountaddr=%pI6c", &sin6->sin6_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400593 break;
594 }
595 default:
596 if (showdefaults)
597 seq_printf(m, ",mountaddr=unspecified");
598 }
599
600 if (nfss->mountd_version || showdefaults)
601 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
602 if (nfss->mountd_port || showdefaults)
603 seq_printf(m, ",mountport=%u", nfss->mountd_port);
604
Jeff Laytonee671b02009-12-03 15:58:56 -0500605 nfs_show_mountd_netid(m, nfss, showdefaults);
Chuck Lever82d101d2008-03-14 14:10:37 -0400606}
607
Trond Myklebust0be81892010-06-18 12:23:58 -0400608#ifdef CONFIG_NFS_V4
609static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
610 int showdefaults)
611{
612 struct nfs_client *clp = nfss->nfs_client;
613
614 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
615 seq_printf(m, ",minorversion=%u", clp->cl_minorversion);
616}
617#else
618static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
619 int showdefaults)
620{
621}
622#endif
623
David Howellsf7b422b2006-06-09 09:34:33 -0400624/*
625 * Describe the mount options in force on this server representation
626 */
Chuck Lever82d101d2008-03-14 14:10:37 -0400627static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
628 int showdefaults)
David Howellsf7b422b2006-06-09 09:34:33 -0400629{
David Howells509de812006-08-22 20:06:11 -0400630 static const struct proc_nfs_info {
David Howellsf7b422b2006-06-09 09:34:33 -0400631 int flag;
David Howells509de812006-08-22 20:06:11 -0400632 const char *str;
633 const char *nostr;
David Howellsf7b422b2006-06-09 09:34:33 -0400634 } nfs_info[] = {
635 { NFS_MOUNT_SOFT, ",soft", ",hard" },
Chuck Lever82d101d2008-03-14 14:10:37 -0400636 { NFS_MOUNT_POSIX, ",posix", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400637 { NFS_MOUNT_NOCTO, ",nocto", "" },
638 { NFS_MOUNT_NOAC, ",noac", "" },
639 { NFS_MOUNT_NONLM, ",nolock", "" },
640 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400641 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
Chuck Leverd7403512008-12-23 15:21:37 -0500642 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
643 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400644 { 0, NULL, NULL }
645 };
David Howells509de812006-08-22 20:06:11 -0400646 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400647 struct nfs_client *clp = nfss->nfs_client;
Chuck Lever82d101d2008-03-14 14:10:37 -0400648 u32 version = clp->rpc_ops->version;
Suresh Jayaraman7c563cc2010-09-23 14:26:48 -0400649 int local_flock, local_fcntl;
David Howellsf7b422b2006-06-09 09:34:33 -0400650
Chuck Lever82d101d2008-03-14 14:10:37 -0400651 seq_printf(m, ",vers=%u", version);
Chuck Lever2d767432008-03-14 14:10:08 -0400652 seq_printf(m, ",rsize=%u", nfss->rsize);
653 seq_printf(m, ",wsize=%u", nfss->wsize);
Chuck Lever82d101d2008-03-14 14:10:37 -0400654 if (nfss->bsize != 0)
655 seq_printf(m, ",bsize=%u", nfss->bsize);
656 seq_printf(m, ",namlen=%u", nfss->namelen);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400657 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400658 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400659 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400660 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400661 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400662 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400663 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400664 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
David Howellsf7b422b2006-06-09 09:34:33 -0400665 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
666 if (nfss->flags & nfs_infop->flag)
667 seq_puts(m, nfs_infop->str);
668 else
669 seq_puts(m, nfs_infop->nostr);
670 }
\"Talpey, Thomas\56928ed2007-09-10 13:48:47 -0400671 seq_printf(m, ",proto=%s",
Jeff Laytonee671b02009-12-03 15:58:56 -0500672 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
Chuck Lever82d101d2008-03-14 14:10:37 -0400673 if (version == 4) {
674 if (nfss->port != NFS_PORT)
675 seq_printf(m, ",port=%u", nfss->port);
676 } else
677 if (nfss->port)
678 seq_printf(m, ",port=%u", nfss->port);
679
Trond Myklebust33170232007-12-20 16:03:59 -0500680 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
681 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
Trond Myklebust81039f12006-06-09 09:34:34 -0400682 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
Chuck Lever82d101d2008-03-14 14:10:37 -0400683
684 if (version != 4)
685 nfs_show_mountd_options(m, nfss, showdefaults);
Trond Myklebust0be81892010-06-18 12:23:58 -0400686 else
687 nfs_show_nfsv4_options(m, nfss, showdefaults);
Chuck Lever82d101d2008-03-14 14:10:37 -0400688
David Howellsb797cac2009-04-03 16:42:48 +0100689 if (nfss->options & NFS_OPTION_FSCACHE)
690 seq_printf(m, ",fsc");
Patrick J. LoPresti9b00c642010-08-10 17:28:01 -0400691
692 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONEG) {
693 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONE)
694 seq_printf(m, ",lookupcache=none");
695 else
696 seq_printf(m, ",lookupcache=pos");
697 }
Suresh Jayaraman7c563cc2010-09-23 14:26:48 -0400698
699 local_flock = nfss->flags & NFS_MOUNT_LOCAL_FLOCK;
700 local_fcntl = nfss->flags & NFS_MOUNT_LOCAL_FCNTL;
701
702 if (!local_flock && !local_fcntl)
703 seq_printf(m, ",local_lock=none");
704 else if (local_flock && local_fcntl)
705 seq_printf(m, ",local_lock=all");
706 else if (local_flock)
707 seq_printf(m, ",local_lock=flock");
708 else
709 seq_printf(m, ",local_lock=posix");
David Howellsf7b422b2006-06-09 09:34:33 -0400710}
711
712/*
713 * Describe the mount options on this VFS mountpoint
714 */
715static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
716{
717 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
718
719 nfs_show_mount_options(m, nfss, 0);
720
Chuck Lever5d8515c2007-12-10 14:57:16 -0500721 seq_printf(m, ",addr=%s",
722 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
723 RPC_DISPLAY_ADDR));
David Howellsf7b422b2006-06-09 09:34:33 -0400724
725 return 0;
726}
727
728/*
729 * Present statistical information for this VFS mountpoint
730 */
731static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
732{
733 int i, cpu;
734 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
735 struct rpc_auth *auth = nfss->client->cl_auth;
736 struct nfs_iostats totals = { };
737
738 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
739
740 /*
741 * Display all mount option settings
742 */
743 seq_printf(m, "\n\topts:\t");
744 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
745 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
746 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
747 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
748 nfs_show_mount_options(m, nfss, 1);
749
750 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
751
752 seq_printf(m, "\n\tcaps:\t");
753 seq_printf(m, "caps=0x%x", nfss->caps);
Chuck Lever2d767432008-03-14 14:10:08 -0400754 seq_printf(m, ",wtmult=%u", nfss->wtmult);
755 seq_printf(m, ",dtsize=%u", nfss->dtsize);
756 seq_printf(m, ",bsize=%u", nfss->bsize);
757 seq_printf(m, ",namlen=%u", nfss->namelen);
David Howellsf7b422b2006-06-09 09:34:33 -0400758
759#ifdef CONFIG_NFS_V4
Trond Myklebust40c553192007-12-14 14:56:07 -0500760 if (nfss->nfs_client->rpc_ops->version == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400761 seq_printf(m, "\n\tnfsv4:\t");
762 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
763 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
764 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
765 }
766#endif
767
768 /*
769 * Display security flavor in effect for this mount
770 */
Chuck Lever2d767432008-03-14 14:10:08 -0400771 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400772 if (auth->au_flavor)
Chuck Lever2d767432008-03-14 14:10:08 -0400773 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400774
775 /*
776 * Display superblock I/O counters
777 */
778 for_each_possible_cpu(cpu) {
779 struct nfs_iostats *stats;
780
781 preempt_disable();
782 stats = per_cpu_ptr(nfss->io_stats, cpu);
783
784 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
785 totals.events[i] += stats->events[i];
786 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
787 totals.bytes[i] += stats->bytes[i];
David Howells6a510912009-04-03 16:42:43 +0100788#ifdef CONFIG_NFS_FSCACHE
789 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
790 totals.fscache[i] += stats->fscache[i];
791#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400792
793 preempt_enable();
794 }
795
796 seq_printf(m, "\n\tevents:\t");
797 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
798 seq_printf(m, "%lu ", totals.events[i]);
799 seq_printf(m, "\n\tbytes:\t");
800 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
801 seq_printf(m, "%Lu ", totals.bytes[i]);
David Howells6a510912009-04-03 16:42:43 +0100802#ifdef CONFIG_NFS_FSCACHE
803 if (nfss->options & NFS_OPTION_FSCACHE) {
804 seq_printf(m, "\n\tfsc:\t");
805 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
806 seq_printf(m, "%Lu ", totals.bytes[i]);
807 }
808#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400809 seq_printf(m, "\n");
810
811 rpc_print_iostats(m, nfss->client);
812
813 return 0;
814}
815
816/*
817 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400818 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400819 */
Al Viro42faad92008-04-24 07:21:56 -0400820static void nfs_umount_begin(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -0400821{
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200822 struct nfs_server *server;
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400823 struct rpc_clnt *rpc;
824
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200825 server = NFS_SB(sb);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400826 /* -EIO all pending I/O */
827 rpc = server->client_acl;
828 if (!IS_ERR(rpc))
829 rpc_killall_tasks(rpc);
830 rpc = server->client;
831 if (!IS_ERR(rpc))
832 rpc_killall_tasks(rpc);
David Howellsf7b422b2006-06-09 09:34:33 -0400833}
834
Trond Myklebustc5811db2009-10-06 15:40:15 -0400835static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(unsigned int version)
Chuck Lever9423a082009-09-23 14:36:38 -0400836{
837 struct nfs_parsed_mount_data *data;
838
839 data = kzalloc(sizeof(*data), GFP_KERNEL);
840 if (data) {
Chuck Lever9423a082009-09-23 14:36:38 -0400841 data->acregmin = NFS_DEF_ACREGMIN;
842 data->acregmax = NFS_DEF_ACREGMAX;
843 data->acdirmin = NFS_DEF_ACDIRMIN;
844 data->acdirmax = NFS_DEF_ACDIRMAX;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400845 data->mount_server.port = NFS_UNSPEC_PORT;
Chuck Lever9423a082009-09-23 14:36:38 -0400846 data->nfs_server.port = NFS_UNSPEC_PORT;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400847 data->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Lever9423a082009-09-23 14:36:38 -0400848 data->auth_flavors[0] = RPC_AUTH_UNIX;
849 data->auth_flavor_len = 1;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400850 data->version = version;
Chuck Lever9423a082009-09-23 14:36:38 -0400851 data->minorversion = 0;
852 }
853 return data;
854}
855
David Howellsf7b422b2006-06-09 09:34:33 -0400856/*
Chuck Levercdcd7f92007-12-10 14:57:45 -0500857 * Sanity-check a server address provided by the mount command.
858 *
859 * Address family must be initialized, and address must not be
860 * the ANY address for that family.
Chuck Leverfc50d582007-07-01 12:12:46 -0400861 */
862static int nfs_verify_server_address(struct sockaddr *addr)
863{
864 switch (addr->sa_family) {
865 case AF_INET: {
Chuck Levercdcd7f92007-12-10 14:57:45 -0500866 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
Al Viroe6f1ceb2008-03-17 22:44:53 -0700867 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
Chuck Levercdcd7f92007-12-10 14:57:45 -0500868 }
869 case AF_INET6: {
870 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
871 return !ipv6_addr_any(sa);
Chuck Leverfc50d582007-07-01 12:12:46 -0400872 }
873 }
874
Chuck Lever53a0b9c2009-08-09 15:09:36 -0400875 dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
Chuck Leverfc50d582007-07-01 12:12:46 -0400876 return 0;
877}
878
Chuck Lever9412b922007-12-10 14:59:21 -0500879/*
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400880 * Select between a default port value and a user-specified port value.
881 * If a zero value is set, then autobind will be used.
882 */
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400883static void nfs_set_port(struct sockaddr *sap, int *port,
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400884 const unsigned short default_port)
885{
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400886 if (*port == NFS_UNSPEC_PORT)
887 *port = default_port;
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400888
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400889 rpc_set_port(sap, *port);
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400890}
891
892/*
Trond Myklebust259875e2008-07-02 14:43:47 -0400893 * Sanity check the NFS transport protocol.
894 *
895 */
896static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
897{
898 switch (mnt->nfs_server.protocol) {
899 case XPRT_TRANSPORT_UDP:
900 case XPRT_TRANSPORT_TCP:
901 case XPRT_TRANSPORT_RDMA:
902 break;
903 default:
904 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
905 }
906}
907
908/*
909 * For text based NFSv2/v3 mounts, the mount protocol transport default
910 * settings should depend upon the specified NFS transport.
911 */
912static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
913{
914 nfs_validate_transport_protocol(mnt);
915
916 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
917 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
918 return;
919 switch (mnt->nfs_server.protocol) {
920 case XPRT_TRANSPORT_UDP:
921 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
922 break;
923 case XPRT_TRANSPORT_TCP:
924 case XPRT_TRANSPORT_RDMA:
925 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
926 }
927}
928
929/*
Chuck Lever01060c82008-06-24 16:33:38 -0400930 * Parse the value of the 'sec=' option.
Chuck Lever01060c82008-06-24 16:33:38 -0400931 */
932static int nfs_parse_security_flavors(char *value,
933 struct nfs_parsed_mount_data *mnt)
934{
935 substring_t args[MAX_OPT_ARGS];
936
937 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
938
939 switch (match_token(value, nfs_secflavor_tokens, args)) {
940 case Opt_sec_none:
Chuck Lever01060c82008-06-24 16:33:38 -0400941 mnt->auth_flavors[0] = RPC_AUTH_NULL;
942 break;
943 case Opt_sec_sys:
Chuck Lever01060c82008-06-24 16:33:38 -0400944 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
945 break;
946 case Opt_sec_krb5:
Chuck Lever01060c82008-06-24 16:33:38 -0400947 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
948 break;
949 case Opt_sec_krb5i:
Chuck Lever01060c82008-06-24 16:33:38 -0400950 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
951 break;
952 case Opt_sec_krb5p:
Chuck Lever01060c82008-06-24 16:33:38 -0400953 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
954 break;
955 case Opt_sec_lkey:
Chuck Lever01060c82008-06-24 16:33:38 -0400956 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
957 break;
958 case Opt_sec_lkeyi:
Chuck Lever01060c82008-06-24 16:33:38 -0400959 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
960 break;
961 case Opt_sec_lkeyp:
Chuck Lever01060c82008-06-24 16:33:38 -0400962 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
963 break;
964 case Opt_sec_spkm:
Chuck Lever01060c82008-06-24 16:33:38 -0400965 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
966 break;
967 case Opt_sec_spkmi:
Chuck Lever01060c82008-06-24 16:33:38 -0400968 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
969 break;
970 case Opt_sec_spkmp:
Chuck Lever01060c82008-06-24 16:33:38 -0400971 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
972 break;
973 default:
974 return 0;
975 }
976
Chuck Lever059f90b2009-08-09 15:09:31 -0400977 mnt->auth_flavor_len = 1;
Chuck Lever01060c82008-06-24 16:33:38 -0400978 return 1;
979}
980
981/*
Chuck Leverbf0fd762007-07-01 12:13:44 -0400982 * Error-check and convert a string of mount options from user space into
Chuck Leverf45663c2008-06-24 19:28:02 -0400983 * a data structure. The whole mount string is processed; bad options are
984 * skipped as they are encountered. If there were no errors, return 1;
985 * otherwise return 0 (zero).
Chuck Leverbf0fd762007-07-01 12:13:44 -0400986 */
987static int nfs_parse_mount_options(char *raw,
988 struct nfs_parsed_mount_data *mnt)
989{
Eric Parisf9c3a382008-03-05 14:20:18 -0500990 char *p, *string, *secdata;
Chuck Leverd23c45f2009-06-17 18:02:13 -0700991 int rc, sloppy = 0, invalid_option = 0;
Jeff Laytonee671b02009-12-03 15:58:56 -0500992 unsigned short protofamily = AF_UNSPEC;
993 unsigned short mountfamily = AF_UNSPEC;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400994
995 if (!raw) {
996 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
997 return 1;
998 }
999 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
1000
Eric Parisf9c3a382008-03-05 14:20:18 -05001001 secdata = alloc_secdata();
1002 if (!secdata)
1003 goto out_nomem;
1004
1005 rc = security_sb_copy_data(raw, secdata);
1006 if (rc)
1007 goto out_security_failure;
1008
1009 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
1010 if (rc)
1011 goto out_security_failure;
1012
1013 free_secdata(secdata);
1014
Chuck Leverbf0fd762007-07-01 12:13:44 -04001015 while ((p = strsep(&raw, ",")) != NULL) {
1016 substring_t args[MAX_OPT_ARGS];
Chuck Levera5a16ba2009-06-17 18:02:14 -07001017 unsigned long option;
1018 int token;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001019
1020 if (!*p)
1021 continue;
1022
1023 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
1024
1025 token = match_token(p, nfs_mount_option_tokens, args);
1026 switch (token) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001027
1028 /*
1029 * boolean options: foo/nofoo
1030 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001031 case Opt_soft:
1032 mnt->flags |= NFS_MOUNT_SOFT;
1033 break;
1034 case Opt_hard:
1035 mnt->flags &= ~NFS_MOUNT_SOFT;
1036 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001037 case Opt_posix:
1038 mnt->flags |= NFS_MOUNT_POSIX;
1039 break;
1040 case Opt_noposix:
1041 mnt->flags &= ~NFS_MOUNT_POSIX;
1042 break;
1043 case Opt_cto:
1044 mnt->flags &= ~NFS_MOUNT_NOCTO;
1045 break;
1046 case Opt_nocto:
1047 mnt->flags |= NFS_MOUNT_NOCTO;
1048 break;
1049 case Opt_ac:
1050 mnt->flags &= ~NFS_MOUNT_NOAC;
1051 break;
1052 case Opt_noac:
1053 mnt->flags |= NFS_MOUNT_NOAC;
1054 break;
1055 case Opt_lock:
1056 mnt->flags &= ~NFS_MOUNT_NONLM;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001057 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1058 NFS_MOUNT_LOCAL_FCNTL);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001059 break;
1060 case Opt_nolock:
1061 mnt->flags |= NFS_MOUNT_NONLM;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001062 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1063 NFS_MOUNT_LOCAL_FCNTL);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001064 break;
1065 case Opt_v2:
1066 mnt->flags &= ~NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -04001067 mnt->version = 2;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001068 break;
1069 case Opt_v3:
1070 mnt->flags |= NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -04001071 mnt->version = 3;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001072 break;
Chuck Lever764302c2009-09-08 19:50:03 -04001073#ifdef CONFIG_NFS_V4
1074 case Opt_v4:
1075 mnt->flags &= ~NFS_MOUNT_VER3;
1076 mnt->version = 4;
1077 break;
1078#endif
Chuck Leverbf0fd762007-07-01 12:13:44 -04001079 case Opt_udp:
1080 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001081 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001082 break;
1083 case Opt_tcp:
1084 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001085 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001086 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001087 case Opt_rdma:
1088 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1089 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001090 xprt_load_transport(p);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001091 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001092 case Opt_acl:
1093 mnt->flags &= ~NFS_MOUNT_NOACL;
1094 break;
1095 case Opt_noacl:
1096 mnt->flags |= NFS_MOUNT_NOACL;
1097 break;
1098 case Opt_rdirplus:
1099 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1100 break;
1101 case Opt_nordirplus:
1102 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1103 break;
Trond Myklebust75180df2007-05-16 16:53:28 -04001104 case Opt_sharecache:
1105 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1106 break;
1107 case Opt_nosharecache:
1108 mnt->flags |= NFS_MOUNT_UNSHARED;
1109 break;
Chuck Leverd7403512008-12-23 15:21:37 -05001110 case Opt_resvport:
1111 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1112 break;
1113 case Opt_noresvport:
1114 mnt->flags |= NFS_MOUNT_NORESVPORT;
1115 break;
David Howellsb797cac2009-04-03 16:42:48 +01001116 case Opt_fscache:
1117 mnt->options |= NFS_OPTION_FSCACHE;
1118 kfree(mnt->fscache_uniq);
1119 mnt->fscache_uniq = NULL;
1120 break;
1121 case Opt_nofscache:
1122 mnt->options &= ~NFS_OPTION_FSCACHE;
1123 kfree(mnt->fscache_uniq);
1124 mnt->fscache_uniq = NULL;
1125 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001126
Chuck Leverf45663c2008-06-24 19:28:02 -04001127 /*
1128 * options that take numeric values
1129 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001130 case Opt_port:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001131 string = match_strdup(args);
1132 if (string == NULL)
1133 goto out_nomem;
1134 rc = strict_strtoul(string, 10, &option);
1135 kfree(string);
Alexey Dobriyan4be929b2010-05-24 14:33:03 -07001136 if (rc != 0 || option > USHRT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001137 goto out_invalid_value;
1138 mnt->nfs_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001139 break;
1140 case Opt_rsize:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001141 string = match_strdup(args);
1142 if (string == NULL)
1143 goto out_nomem;
1144 rc = strict_strtoul(string, 10, &option);
1145 kfree(string);
1146 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001147 goto out_invalid_value;
1148 mnt->rsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001149 break;
1150 case Opt_wsize:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001151 string = match_strdup(args);
1152 if (string == NULL)
1153 goto out_nomem;
1154 rc = strict_strtoul(string, 10, &option);
1155 kfree(string);
1156 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001157 goto out_invalid_value;
1158 mnt->wsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001159 break;
1160 case Opt_bsize:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001161 string = match_strdup(args);
1162 if (string == NULL)
1163 goto out_nomem;
1164 rc = strict_strtoul(string, 10, &option);
1165 kfree(string);
1166 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001167 goto out_invalid_value;
1168 mnt->bsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001169 break;
1170 case Opt_timeo:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001171 string = match_strdup(args);
1172 if (string == NULL)
1173 goto out_nomem;
1174 rc = strict_strtoul(string, 10, &option);
1175 kfree(string);
1176 if (rc != 0 || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001177 goto out_invalid_value;
1178 mnt->timeo = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001179 break;
1180 case Opt_retrans:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001181 string = match_strdup(args);
1182 if (string == NULL)
1183 goto out_nomem;
1184 rc = strict_strtoul(string, 10, &option);
1185 kfree(string);
1186 if (rc != 0 || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001187 goto out_invalid_value;
1188 mnt->retrans = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001189 break;
1190 case Opt_acregmin:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001191 string = match_strdup(args);
1192 if (string == NULL)
1193 goto out_nomem;
1194 rc = strict_strtoul(string, 10, &option);
1195 kfree(string);
1196 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001197 goto out_invalid_value;
1198 mnt->acregmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001199 break;
1200 case Opt_acregmax:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001201 string = match_strdup(args);
1202 if (string == NULL)
1203 goto out_nomem;
1204 rc = strict_strtoul(string, 10, &option);
1205 kfree(string);
1206 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001207 goto out_invalid_value;
1208 mnt->acregmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001209 break;
1210 case Opt_acdirmin:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001211 string = match_strdup(args);
1212 if (string == NULL)
1213 goto out_nomem;
1214 rc = strict_strtoul(string, 10, &option);
1215 kfree(string);
1216 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001217 goto out_invalid_value;
1218 mnt->acdirmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001219 break;
1220 case Opt_acdirmax:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001221 string = match_strdup(args);
1222 if (string == NULL)
1223 goto out_nomem;
1224 rc = strict_strtoul(string, 10, &option);
1225 kfree(string);
1226 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001227 goto out_invalid_value;
1228 mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001229 break;
1230 case Opt_actimeo:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001231 string = match_strdup(args);
1232 if (string == NULL)
1233 goto out_nomem;
1234 rc = strict_strtoul(string, 10, &option);
1235 kfree(string);
1236 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001237 goto out_invalid_value;
1238 mnt->acregmin = mnt->acregmax =
1239 mnt->acdirmin = mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001240 break;
1241 case Opt_namelen:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001242 string = match_strdup(args);
1243 if (string == NULL)
1244 goto out_nomem;
1245 rc = strict_strtoul(string, 10, &option);
1246 kfree(string);
1247 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001248 goto out_invalid_value;
1249 mnt->namlen = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001250 break;
1251 case Opt_mountport:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001252 string = match_strdup(args);
1253 if (string == NULL)
1254 goto out_nomem;
1255 rc = strict_strtoul(string, 10, &option);
1256 kfree(string);
Alexey Dobriyan4be929b2010-05-24 14:33:03 -07001257 if (rc != 0 || option > USHRT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001258 goto out_invalid_value;
1259 mnt->mount_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001260 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001261 case Opt_mountvers:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001262 string = match_strdup(args);
1263 if (string == NULL)
1264 goto out_nomem;
1265 rc = strict_strtoul(string, 10, &option);
1266 kfree(string);
1267 if (rc != 0 ||
Chuck Leverf45663c2008-06-24 19:28:02 -04001268 option < NFS_MNT_VERSION ||
Chuck Leverd23c45f2009-06-17 18:02:13 -07001269 option > NFS_MNT3_VERSION)
1270 goto out_invalid_value;
1271 mnt->mount_server.version = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001272 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001273 case Opt_nfsvers:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001274 string = match_strdup(args);
1275 if (string == NULL)
1276 goto out_nomem;
1277 rc = strict_strtoul(string, 10, &option);
1278 kfree(string);
1279 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001280 goto out_invalid_value;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001281 switch (option) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001282 case NFS2_VERSION:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001283 mnt->flags &= ~NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -04001284 mnt->version = 2;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001285 break;
Chuck Leverf45663c2008-06-24 19:28:02 -04001286 case NFS3_VERSION:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001287 mnt->flags |= NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -04001288 mnt->version = 3;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001289 break;
Chuck Lever764302c2009-09-08 19:50:03 -04001290#ifdef CONFIG_NFS_V4
1291 case NFS4_VERSION:
1292 mnt->flags &= ~NFS_MOUNT_VER3;
1293 mnt->version = 4;
1294 break;
1295#endif
Chuck Leverbf0fd762007-07-01 12:13:44 -04001296 default:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001297 goto out_invalid_value;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001298 }
1299 break;
Mike Sager3fd5be92009-04-01 09:21:48 -04001300 case Opt_minorversion:
Chuck Leverf3f4f4e2009-08-09 15:09:29 -04001301 string = match_strdup(args);
1302 if (string == NULL)
1303 goto out_nomem;
1304 rc = strict_strtoul(string, 10, &option);
1305 kfree(string);
1306 if (rc != 0)
1307 goto out_invalid_value;
1308 if (option > NFS4_MAX_MINOR_VERSION)
1309 goto out_invalid_value;
1310 mnt->minorversion = option;
Mike Sager3fd5be92009-04-01 09:21:48 -04001311 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001312
Chuck Leverf45663c2008-06-24 19:28:02 -04001313 /*
1314 * options that take text values
1315 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001316 case Opt_sec:
1317 string = match_strdup(args);
1318 if (string == NULL)
1319 goto out_nomem;
Chuck Lever01060c82008-06-24 16:33:38 -04001320 rc = nfs_parse_security_flavors(string, mnt);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001321 kfree(string);
Chuck Leverf45663c2008-06-24 19:28:02 -04001322 if (!rc) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001323 dfprintk(MOUNT, "NFS: unrecognized "
1324 "security flavor\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001325 return 0;
Chuck Leverf45663c2008-06-24 19:28:02 -04001326 }
Chuck Leverbf0fd762007-07-01 12:13:44 -04001327 break;
1328 case Opt_proto:
1329 string = match_strdup(args);
1330 if (string == NULL)
1331 goto out_nomem;
1332 token = match_token(string,
1333 nfs_xprt_protocol_tokens, args);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001334
Jeff Laytonee671b02009-12-03 15:58:56 -05001335 protofamily = AF_INET;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001336 switch (token) {
Jeff Laytonee671b02009-12-03 15:58:56 -05001337 case Opt_xprt_udp6:
1338 protofamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001339 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001340 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001341 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001342 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001343 break;
Jeff Laytonee671b02009-12-03 15:58:56 -05001344 case Opt_xprt_tcp6:
1345 protofamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001346 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001347 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001348 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001349 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001350 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001351 case Opt_xprt_rdma:
1352 /* vector side protocols to TCP */
1353 mnt->flags |= NFS_MOUNT_TCP;
1354 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001355 xprt_load_transport(string);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001356 kfree(string);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001357 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001358 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001359 dfprintk(MOUNT, "NFS: unrecognized "
1360 "transport protocol\n");
Yinghai Lu4223a4a2009-10-20 14:13:46 +09001361 kfree(string);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001362 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001363 }
1364 break;
1365 case Opt_mountproto:
1366 string = match_strdup(args);
1367 if (string == NULL)
1368 goto out_nomem;
1369 token = match_token(string,
1370 nfs_xprt_protocol_tokens, args);
Trond Myklebustd508afb2009-04-06 16:41:35 -07001371 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001372
Jeff Laytonee671b02009-12-03 15:58:56 -05001373 mountfamily = AF_INET;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001374 switch (token) {
Jeff Laytonee671b02009-12-03 15:58:56 -05001375 case Opt_xprt_udp6:
1376 mountfamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001377 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001378 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001379 break;
Jeff Laytonee671b02009-12-03 15:58:56 -05001380 case Opt_xprt_tcp6:
1381 mountfamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001382 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001383 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001384 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001385 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001386 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001387 dfprintk(MOUNT, "NFS: unrecognized "
1388 "transport protocol\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001389 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001390 }
1391 break;
1392 case Opt_addr:
1393 string = match_strdup(args);
1394 if (string == NULL)
1395 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001396 mnt->nfs_server.addrlen =
1397 rpc_pton(string, strlen(string),
1398 (struct sockaddr *)
1399 &mnt->nfs_server.address,
1400 sizeof(mnt->nfs_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001401 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001402 if (mnt->nfs_server.addrlen == 0)
1403 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001404 break;
1405 case Opt_clientaddr:
1406 string = match_strdup(args);
1407 if (string == NULL)
1408 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001409 kfree(mnt->client_address);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001410 mnt->client_address = string;
1411 break;
Chuck Lever33832032007-12-10 14:59:13 -05001412 case Opt_mounthost:
1413 string = match_strdup(args);
1414 if (string == NULL)
1415 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001416 kfree(mnt->mount_server.hostname);
Chuck Lever33832032007-12-10 14:59:13 -05001417 mnt->mount_server.hostname = string;
1418 break;
Chuck Lever0ac83772007-09-11 18:01:04 -04001419 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001420 string = match_strdup(args);
1421 if (string == NULL)
1422 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001423 mnt->mount_server.addrlen =
1424 rpc_pton(string, strlen(string),
1425 (struct sockaddr *)
1426 &mnt->mount_server.address,
1427 sizeof(mnt->mount_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001428 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001429 if (mnt->mount_server.addrlen == 0)
1430 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001431 break;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001432 case Opt_lookupcache:
1433 string = match_strdup(args);
1434 if (string == NULL)
1435 goto out_nomem;
1436 token = match_token(string,
1437 nfs_lookupcache_tokens, args);
1438 kfree(string);
1439 switch (token) {
1440 case Opt_lookupcache_all:
1441 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1442 break;
1443 case Opt_lookupcache_positive:
1444 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1445 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1446 break;
1447 case Opt_lookupcache_none:
1448 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1449 break;
1450 default:
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001451 dfprintk(MOUNT, "NFS: invalid "
1452 "lookupcache argument\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001453 return 0;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001454 };
1455 break;
Chuck Levera6d5ff62010-05-07 13:33:58 -04001456 case Opt_fscache_uniq:
1457 string = match_strdup(args);
1458 if (string == NULL)
1459 goto out_nomem;
1460 kfree(mnt->fscache_uniq);
1461 mnt->fscache_uniq = string;
1462 mnt->options |= NFS_OPTION_FSCACHE;
1463 break;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001464 case Opt_local_lock:
1465 string = match_strdup(args);
1466 if (string == NULL)
1467 goto out_nomem;
1468 token = match_token(string, nfs_local_lock_tokens,
1469 args);
1470 kfree(string);
1471 switch (token) {
1472 case Opt_local_lock_all:
1473 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1474 NFS_MOUNT_LOCAL_FCNTL);
1475 break;
1476 case Opt_local_lock_flock:
1477 mnt->flags |= NFS_MOUNT_LOCAL_FLOCK;
1478 break;
1479 case Opt_local_lock_posix:
1480 mnt->flags |= NFS_MOUNT_LOCAL_FCNTL;
1481 break;
1482 case Opt_local_lock_none:
1483 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1484 NFS_MOUNT_LOCAL_FCNTL);
1485 break;
1486 default:
1487 dfprintk(MOUNT, "NFS: invalid "
1488 "local_lock argument\n");
1489 return 0;
1490 };
1491 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001492
Chuck Leverf45663c2008-06-24 19:28:02 -04001493 /*
1494 * Special options
1495 */
1496 case Opt_sloppy:
1497 sloppy = 1;
1498 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1499 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001500 case Opt_userspace:
1501 case Opt_deprecated:
Chuck Leverd33e4df2008-06-12 12:37:41 -04001502 dfprintk(MOUNT, "NFS: ignoring mount option "
1503 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001504 break;
1505
1506 default:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001507 invalid_option = 1;
Chuck Leverf45663c2008-06-24 19:28:02 -04001508 dfprintk(MOUNT, "NFS: unrecognized mount option "
1509 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001510 }
1511 }
1512
Chuck Leverd23c45f2009-06-17 18:02:13 -07001513 if (!sloppy && invalid_option)
1514 return 0;
1515
Jeff Laytonee671b02009-12-03 15:58:56 -05001516 /*
1517 * verify that any proto=/mountproto= options match the address
1518 * familiies in the addr=/mountaddr= options.
1519 */
1520 if (protofamily != AF_UNSPEC &&
1521 protofamily != mnt->nfs_server.address.ss_family)
1522 goto out_proto_mismatch;
1523
1524 if (mountfamily != AF_UNSPEC) {
1525 if (mnt->mount_server.addrlen) {
1526 if (mountfamily != mnt->mount_server.address.ss_family)
1527 goto out_mountproto_mismatch;
1528 } else {
1529 if (mountfamily != mnt->nfs_server.address.ss_family)
1530 goto out_mountproto_mismatch;
1531 }
1532 }
1533
Chuck Leverbf0fd762007-07-01 12:13:44 -04001534 return 1;
1535
Jeff Laytonee671b02009-12-03 15:58:56 -05001536out_mountproto_mismatch:
1537 printk(KERN_INFO "NFS: mount server address does not match mountproto= "
1538 "option\n");
1539 return 0;
1540out_proto_mismatch:
1541 printk(KERN_INFO "NFS: server address does not match proto= option\n");
1542 return 0;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001543out_invalid_address:
1544 printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
1545 return 0;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001546out_invalid_value:
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001547 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001548 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001549out_nomem:
1550 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1551 return 0;
Eric Parisf9c3a382008-03-05 14:20:18 -05001552out_security_failure:
1553 free_secdata(secdata);
1554 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1555 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001556}
1557
1558/*
Chuck Leverec88f282009-08-09 15:09:32 -04001559 * Match the requested auth flavors with the list returned by
1560 * the server. Returns zero and sets the mount's authentication
1561 * flavor on success; returns -EACCES if server does not support
1562 * the requested flavor.
1563 */
1564static int nfs_walk_authlist(struct nfs_parsed_mount_data *args,
1565 struct nfs_mount_request *request)
1566{
1567 unsigned int i, j, server_authlist_len = *(request->auth_flav_len);
1568
1569 /*
Chuck Lever5eecfde2009-08-21 17:50:30 -04001570 * Certain releases of Linux's mountd return an empty
1571 * flavor list. To prevent behavioral regression with
1572 * these servers (ie. rejecting mounts that used to
1573 * succeed), revert to pre-2.6.32 behavior (no checking)
1574 * if the returned flavor list is empty.
1575 */
1576 if (server_authlist_len == 0)
1577 return 0;
1578
1579 /*
Chuck Leverec88f282009-08-09 15:09:32 -04001580 * We avoid sophisticated negotiating here, as there are
1581 * plenty of cases where we can get it wrong, providing
1582 * either too little or too much security.
1583 *
1584 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1585 * flavor listed first. However, some servers list
1586 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1587 * preferred default, in args->auth_flavors[0] if user
1588 * didn't specify sec= mount option.
1589 */
1590 for (i = 0; i < args->auth_flavor_len; i++)
1591 for (j = 0; j < server_authlist_len; j++)
1592 if (args->auth_flavors[i] == request->auth_flavs[j]) {
1593 dfprintk(MOUNT, "NFS: using auth flavor %d\n",
1594 request->auth_flavs[j]);
1595 args->auth_flavors[0] = request->auth_flavs[j];
1596 return 0;
1597 }
1598
1599 dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n");
1600 nfs_umount(request);
1601 return -EACCES;
1602}
1603
1604/*
Chuck Lever0076d7b2007-07-01 12:13:49 -04001605 * Use the remote server's MOUNT service to request the NFS file handle
1606 * corresponding to the provided path.
1607 */
1608static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1609 struct nfs_fh *root_fh)
1610{
Chuck Leverec88f282009-08-09 15:09:32 -04001611 rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS];
1612 unsigned int server_authlist_len = ARRAY_SIZE(server_authlist);
Chuck Leverc5d120f2008-12-23 15:21:35 -05001613 struct nfs_mount_request request = {
1614 .sap = (struct sockaddr *)
1615 &args->mount_server.address,
1616 .dirpath = args->nfs_server.export_path,
1617 .protocol = args->mount_server.protocol,
1618 .fh = root_fh,
Chuck Lever50a737f2008-12-23 15:21:37 -05001619 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
Chuck Leverec88f282009-08-09 15:09:32 -04001620 .auth_flav_len = &server_authlist_len,
1621 .auth_flavs = server_authlist,
Chuck Leverc5d120f2008-12-23 15:21:35 -05001622 };
Chuck Lever4c568012007-12-10 14:59:28 -05001623 int status;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001624
1625 if (args->mount_server.version == 0) {
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001626 switch (args->version) {
1627 default:
1628 args->mount_server.version = NFS_MNT3_VERSION;
1629 break;
1630 case 2:
1631 args->mount_server.version = NFS_MNT_VERSION;
1632 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001633 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001634 request.version = args->mount_server.version;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001635
Chuck Lever33832032007-12-10 14:59:13 -05001636 if (args->mount_server.hostname)
Chuck Leverc5d120f2008-12-23 15:21:35 -05001637 request.hostname = args->mount_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001638 else
Chuck Leverc5d120f2008-12-23 15:21:35 -05001639 request.hostname = args->nfs_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001640
Chuck Lever0076d7b2007-07-01 12:13:49 -04001641 /*
1642 * Construct the mount server's address.
1643 */
Chuck Lever4c568012007-12-10 14:59:28 -05001644 if (args->mount_server.address.ss_family == AF_UNSPEC) {
Chuck Leverc5d120f2008-12-23 15:21:35 -05001645 memcpy(request.sap, &args->nfs_server.address,
Chuck Lever4c568012007-12-10 14:59:28 -05001646 args->nfs_server.addrlen);
1647 args->mount_server.addrlen = args->nfs_server.addrlen;
1648 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001649 request.salen = args->mount_server.addrlen;
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001650 nfs_set_port(request.sap, &args->mount_server.port, 0);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001651
1652 /*
1653 * Now ask the mount server to map our export path
1654 * to a file handle.
1655 */
Chuck Leverc5d120f2008-12-23 15:21:35 -05001656 status = nfs_mount(&request);
Chuck Leverec88f282009-08-09 15:09:32 -04001657 if (status != 0) {
1658 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1659 request.hostname, status);
1660 return status;
1661 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001662
Chuck Leverec88f282009-08-09 15:09:32 -04001663 /*
1664 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1665 */
1666 if (args->mount_server.version != NFS_MNT3_VERSION)
1667 return 0;
1668 return nfs_walk_authlist(args, &request);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001669}
1670
Chuck Leverd1aa0822008-06-23 12:36:45 -04001671static int nfs_parse_simple_hostname(const char *dev_name,
1672 char **hostname, size_t maxnamlen,
1673 char **export_path, size_t maxpathlen)
Chuck Leverdc045892008-06-23 12:36:37 -04001674{
1675 size_t len;
1676 char *colon, *comma;
1677
1678 colon = strchr(dev_name, ':');
1679 if (colon == NULL)
1680 goto out_bad_devname;
1681
1682 len = colon - dev_name;
1683 if (len > maxnamlen)
1684 goto out_hostname;
1685
1686 /* N.B. caller will free nfs_server.hostname in all cases */
1687 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
1688 if (!*hostname)
1689 goto out_nomem;
1690
1691 /* kill possible hostname list: not supported */
1692 comma = strchr(*hostname, ',');
1693 if (comma != NULL) {
1694 if (comma == *hostname)
1695 goto out_bad_devname;
1696 *comma = '\0';
1697 }
1698
1699 colon++;
1700 len = strlen(colon);
1701 if (len > maxpathlen)
1702 goto out_path;
1703 *export_path = kstrndup(colon, len, GFP_KERNEL);
1704 if (!*export_path)
1705 goto out_nomem;
1706
1707 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1708 return 0;
1709
1710out_bad_devname:
1711 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1712 return -EINVAL;
1713
1714out_nomem:
1715 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1716 return -ENOMEM;
1717
1718out_hostname:
1719 dfprintk(MOUNT, "NFS: server hostname too long\n");
1720 return -ENAMETOOLONG;
1721
1722out_path:
1723 dfprintk(MOUNT, "NFS: export pathname too long\n");
1724 return -ENAMETOOLONG;
1725}
1726
1727/*
Chuck Leverd1aa0822008-06-23 12:36:45 -04001728 * Hostname has square brackets around it because it contains one or
1729 * more colons. We look for the first closing square bracket, and a
1730 * colon must follow it.
1731 */
1732static int nfs_parse_protected_hostname(const char *dev_name,
1733 char **hostname, size_t maxnamlen,
1734 char **export_path, size_t maxpathlen)
1735{
1736 size_t len;
1737 char *start, *end;
1738
1739 start = (char *)(dev_name + 1);
1740
1741 end = strchr(start, ']');
1742 if (end == NULL)
1743 goto out_bad_devname;
1744 if (*(end + 1) != ':')
1745 goto out_bad_devname;
1746
1747 len = end - start;
1748 if (len > maxnamlen)
1749 goto out_hostname;
1750
1751 /* N.B. caller will free nfs_server.hostname in all cases */
1752 *hostname = kstrndup(start, len, GFP_KERNEL);
1753 if (*hostname == NULL)
1754 goto out_nomem;
1755
1756 end += 2;
1757 len = strlen(end);
1758 if (len > maxpathlen)
1759 goto out_path;
1760 *export_path = kstrndup(end, len, GFP_KERNEL);
1761 if (!*export_path)
1762 goto out_nomem;
1763
1764 return 0;
1765
1766out_bad_devname:
1767 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1768 return -EINVAL;
1769
1770out_nomem:
1771 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1772 return -ENOMEM;
1773
1774out_hostname:
1775 dfprintk(MOUNT, "NFS: server hostname too long\n");
1776 return -ENAMETOOLONG;
1777
1778out_path:
1779 dfprintk(MOUNT, "NFS: export pathname too long\n");
1780 return -ENAMETOOLONG;
1781}
1782
1783/*
1784 * Split "dev_name" into "hostname:export_path".
1785 *
1786 * The leftmost colon demarks the split between the server's hostname
1787 * and the export path. If the hostname starts with a left square
1788 * bracket, then it may contain colons.
1789 *
1790 * Note: caller frees hostname and export path, even on error.
1791 */
1792static int nfs_parse_devname(const char *dev_name,
1793 char **hostname, size_t maxnamlen,
1794 char **export_path, size_t maxpathlen)
1795{
1796 if (*dev_name == '[')
1797 return nfs_parse_protected_hostname(dev_name,
1798 hostname, maxnamlen,
1799 export_path, maxpathlen);
1800
1801 return nfs_parse_simple_hostname(dev_name,
1802 hostname, maxnamlen,
1803 export_path, maxpathlen);
1804}
1805
1806/*
David Howells54ceac42006-08-22 20:06:13 -04001807 * Validate the NFS2/NFS3 mount data
1808 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001809 *
1810 * For option strings, user space handles the following behaviors:
1811 *
1812 * + DNS: mapping server host name to IP address ("addr=" option)
1813 *
1814 * + failure mode: how to behave if a mount request can't be handled
1815 * immediately ("fg/bg" option)
1816 *
1817 * + retry: how often to retry a mount request ("retry=" option)
1818 *
1819 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1820 * mountproto=tcp after mountproto=udp, and so on
David Howellsf7b422b2006-06-09 09:34:33 -04001821 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001822static int nfs_validate_mount_data(void *options,
1823 struct nfs_parsed_mount_data *args,
Chuck Lever136d5582007-07-01 12:13:54 -04001824 struct nfs_fh *mntfh,
1825 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001826{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001827 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001828 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
Chuck Lever136d5582007-07-01 12:13:54 -04001829
Chuck Lever5df36e72007-07-01 12:12:56 -04001830 if (data == NULL)
1831 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001832
David Howellsf7b422b2006-06-09 09:34:33 -04001833 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001834 case 1:
1835 data->namlen = 0;
1836 case 2:
1837 data->bsize = 0;
1838 case 3:
1839 if (data->flags & NFS_MOUNT_VER3)
1840 goto out_no_v3;
1841 data->root.size = NFS2_FHSIZE;
1842 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1843 case 4:
1844 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1845 goto out_no_sec;
1846 case 5:
1847 memset(data->context, 0, sizeof(data->context));
1848 case 6:
Trond Myklebustb7e24452008-06-19 15:21:11 -04001849 if (data->flags & NFS_MOUNT_VER3) {
1850 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1851 goto out_invalid_fh;
Chuck Lever5df36e72007-07-01 12:12:56 -04001852 mntfh->size = data->root.size;
Chuck Lever764302c2009-09-08 19:50:03 -04001853 args->version = 3;
1854 } else {
Chuck Lever5df36e72007-07-01 12:12:56 -04001855 mntfh->size = NFS2_FHSIZE;
Chuck Lever764302c2009-09-08 19:50:03 -04001856 args->version = 2;
1857 }
Chuck Lever5df36e72007-07-01 12:12:56 -04001858
Chuck Lever5df36e72007-07-01 12:12:56 -04001859
1860 memcpy(mntfh->data, data->root.data, mntfh->size);
1861 if (mntfh->size < sizeof(mntfh->data))
1862 memset(mntfh->data + mntfh->size, 0,
1863 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001864
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001865 /*
1866 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1867 * can deal with.
1868 */
Trond Myklebustff3525a2008-08-15 16:59:14 -04001869 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
Bryan Schumakerd5eff1a2010-08-03 13:04:00 -04001870 args->flags |= NFS_MOUNT_LEGACY_INTERFACE;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001871 args->rsize = data->rsize;
1872 args->wsize = data->wsize;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001873 args->timeo = data->timeo;
1874 args->retrans = data->retrans;
1875 args->acregmin = data->acregmin;
1876 args->acregmax = data->acregmax;
1877 args->acdirmin = data->acdirmin;
1878 args->acdirmax = data->acdirmax;
Chuck Lever4c568012007-12-10 14:59:28 -05001879
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001880 memcpy(sap, &data->addr, sizeof(data->addr));
Chuck Lever4c568012007-12-10 14:59:28 -05001881 args->nfs_server.addrlen = sizeof(data->addr);
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001882 if (!nfs_verify_server_address(sap))
Chuck Lever4c568012007-12-10 14:59:28 -05001883 goto out_no_address;
1884
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001885 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001886 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001887 /* N.B. caller will free nfs_server.hostname in all cases */
1888 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1889 args->namlen = data->namlen;
1890 args->bsize = data->bsize;
Chuck Leverdd07c942008-06-24 16:33:46 -04001891
1892 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1893 args->auth_flavors[0] = data->pseudoflavor;
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001894 if (!args->nfs_server.hostname)
1895 goto out_nomem;
Eric Parisf9c3a382008-03-05 14:20:18 -05001896
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001897 if (!(data->flags & NFS_MOUNT_NONLM))
1898 args->flags &= ~(NFS_MOUNT_LOCAL_FLOCK|
1899 NFS_MOUNT_LOCAL_FCNTL);
1900 else
1901 args->flags |= (NFS_MOUNT_LOCAL_FLOCK|
1902 NFS_MOUNT_LOCAL_FCNTL);
Eric Parisf9c3a382008-03-05 14:20:18 -05001903 /*
1904 * The legacy version 6 binary mount data from userspace has a
1905 * field used only to transport selinux information into the
1906 * the kernel. To continue to support that functionality we
1907 * have a touch of selinux knowledge here in the NFS code. The
1908 * userspace code converted context=blah to just blah so we are
1909 * converting back to the full string selinux understands.
1910 */
1911 if (data->context[0]){
1912#ifdef CONFIG_SECURITY_SELINUX
1913 int rc;
1914 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1915 if (!opts_str)
1916 return -ENOMEM;
1917 strcpy(opts_str, "context=");
1918 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1919 strcat(opts_str, &data->context[0]);
1920 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1921 kfree(opts_str);
1922 if (rc)
1923 return rc;
1924#else
1925 return -EINVAL;
1926#endif
1927 }
1928
Chuck Lever5df36e72007-07-01 12:12:56 -04001929 break;
Chuck Lever136d5582007-07-01 12:13:54 -04001930 default: {
Chuck Lever136d5582007-07-01 12:13:54 -04001931 int status;
Chuck Lever136d5582007-07-01 12:13:54 -04001932
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001933 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever136d5582007-07-01 12:13:54 -04001934 return -EINVAL;
1935
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001936 if (!nfs_verify_server_address(sap))
Chuck Lever6e88e062007-09-24 15:39:50 -04001937 goto out_no_address;
1938
Chuck Lever764302c2009-09-08 19:50:03 -04001939 if (args->version == 4)
1940#ifdef CONFIG_NFS_V4
1941 return nfs4_validate_text_mount_data(options,
1942 args, dev_name);
1943#else
1944 goto out_v4_not_compiled;
1945#endif
1946
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001947 nfs_set_port(sap, &args->nfs_server.port, 0);
Chuck Levered596a82008-06-26 17:47:05 -04001948
Trond Myklebust259875e2008-07-02 14:43:47 -04001949 nfs_set_mount_transport_protocol(args);
1950
Chuck Leverdc045892008-06-23 12:36:37 -04001951 status = nfs_parse_devname(dev_name,
1952 &args->nfs_server.hostname,
1953 PAGE_SIZE,
1954 &args->nfs_server.export_path,
1955 NFS_MAXPATHLEN);
1956 if (!status)
1957 status = nfs_try_mount(args, mntfh);
Chuck Lever136d5582007-07-01 12:13:54 -04001958
Chuck Leverdc045892008-06-23 12:36:37 -04001959 kfree(args->nfs_server.export_path);
1960 args->nfs_server.export_path = NULL;
Chuck Lever136d5582007-07-01 12:13:54 -04001961
Chuck Lever136d5582007-07-01 12:13:54 -04001962 if (status)
Chuck Leverfdc6e2c2007-08-29 17:58:59 -04001963 return status;
Chuck Lever136d5582007-07-01 12:13:54 -04001964
Chuck Lever136d5582007-07-01 12:13:54 -04001965 break;
1966 }
David Howellsf7b422b2006-06-09 09:34:33 -04001967 }
David Howells54ceac42006-08-22 20:06:13 -04001968
David Howellsf7b422b2006-06-09 09:34:33 -04001969#ifndef CONFIG_NFS_V3
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001970 if (args->version == 3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001971 goto out_v3_not_compiled;
1972#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001973
David Howells54ceac42006-08-22 20:06:13 -04001974 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001975
1976out_no_data:
1977 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1978 return -EINVAL;
1979
1980out_no_v3:
1981 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1982 data->version);
1983 return -EINVAL;
1984
1985out_no_sec:
1986 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1987 return -EINVAL;
1988
Chuck Lever5df36e72007-07-01 12:12:56 -04001989#ifndef CONFIG_NFS_V3
1990out_v3_not_compiled:
1991 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1992 return -EPROTONOSUPPORT;
1993#endif /* !CONFIG_NFS_V3 */
1994
Chuck Lever764302c2009-09-08 19:50:03 -04001995#ifndef CONFIG_NFS_V4
1996out_v4_not_compiled:
1997 dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n");
1998 return -EPROTONOSUPPORT;
1999#endif /* !CONFIG_NFS_V4 */
2000
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04002001out_nomem:
2002 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
2003 return -ENOMEM;
2004
Chuck Lever5df36e72007-07-01 12:12:56 -04002005out_no_address:
2006 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
2007 return -EINVAL;
2008
2009out_invalid_fh:
2010 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
2011 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04002012}
2013
Jeff Layton48b605f2008-06-10 15:38:39 -04002014static int
2015nfs_compare_remount_data(struct nfs_server *nfss,
2016 struct nfs_parsed_mount_data *data)
2017{
2018 if (data->flags != nfss->flags ||
2019 data->rsize != nfss->rsize ||
2020 data->wsize != nfss->wsize ||
2021 data->retrans != nfss->client->cl_timeout->to_retries ||
2022 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
2023 data->acregmin != nfss->acregmin / HZ ||
2024 data->acregmax != nfss->acregmax / HZ ||
2025 data->acdirmin != nfss->acdirmin / HZ ||
2026 data->acdirmax != nfss->acdirmax / HZ ||
2027 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
Trond Myklebustbcd2ea12009-10-06 15:41:22 -04002028 data->nfs_server.port != nfss->port ||
Jeff Layton48b605f2008-06-10 15:38:39 -04002029 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
Stefan Richtera1be9ee2009-10-12 11:26:12 -04002030 !rpc_cmp_addr((struct sockaddr *)&data->nfs_server.address,
2031 (struct sockaddr *)&nfss->nfs_client->cl_addr))
Jeff Layton48b605f2008-06-10 15:38:39 -04002032 return -EINVAL;
2033
2034 return 0;
2035}
2036
2037static int
2038nfs_remount(struct super_block *sb, int *flags, char *raw_data)
2039{
2040 int error;
2041 struct nfs_server *nfss = sb->s_fs_info;
2042 struct nfs_parsed_mount_data *data;
2043 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
2044 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
Trond Myklebustcd100722008-06-17 16:12:00 -04002045 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
Jeff Layton48b605f2008-06-10 15:38:39 -04002046
2047 /*
2048 * Userspace mount programs that send binary options generally send
2049 * them populated with default values. We have no way to know which
2050 * ones were explicitly specified. Fall back to legacy behavior and
2051 * just return success.
2052 */
Marc Zyngier31c94462008-07-17 13:21:55 +02002053 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
2054 (nfsvers <= 3 && (!options || (options->version >= 1 &&
2055 options->version <= 6))))
Jeff Layton48b605f2008-06-10 15:38:39 -04002056 return 0;
2057
2058 data = kzalloc(sizeof(*data), GFP_KERNEL);
2059 if (data == NULL)
2060 return -ENOMEM;
2061
2062 /* fill out struct with values from existing mount */
2063 data->flags = nfss->flags;
2064 data->rsize = nfss->rsize;
2065 data->wsize = nfss->wsize;
2066 data->retrans = nfss->client->cl_timeout->to_retries;
2067 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
2068 data->acregmin = nfss->acregmin / HZ;
2069 data->acregmax = nfss->acregmax / HZ;
2070 data->acdirmin = nfss->acdirmin / HZ;
2071 data->acdirmax = nfss->acdirmax / HZ;
2072 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
Trond Myklebustbcd2ea12009-10-06 15:41:22 -04002073 data->nfs_server.port = nfss->port;
Jeff Layton48b605f2008-06-10 15:38:39 -04002074 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
2075 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
2076 data->nfs_server.addrlen);
2077
2078 /* overwrite those values with any that were specified */
2079 error = nfs_parse_mount_options((char *)options, data);
2080 if (error < 0)
2081 goto out;
2082
2083 /* compare new mount options with old ones */
2084 error = nfs_compare_remount_data(nfss, data);
2085out:
2086 kfree(data);
2087 return error;
2088}
2089
David Howells54ceac42006-08-22 20:06:13 -04002090/*
2091 * Initialise the common bits of the superblock
2092 */
2093static inline void nfs_initialise_sb(struct super_block *sb)
2094{
2095 struct nfs_server *server = NFS_SB(sb);
2096
2097 sb->s_magic = NFS_SUPER_MAGIC;
2098
2099 /* We probably want something more informative here */
2100 snprintf(sb->s_id, sizeof(sb->s_id),
2101 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
2102
2103 if (sb->s_blocksize == 0)
2104 sb->s_blocksize = nfs_block_bits(server->wsize,
2105 &sb->s_blocksize_bits);
2106
2107 if (server->flags & NFS_MOUNT_NOAC)
2108 sb->s_flags |= MS_SYNCHRONOUS;
2109
Jens Axboe32a88aa2009-09-16 15:02:33 +02002110 sb->s_bdi = &server->backing_dev_info;
2111
David Howells54ceac42006-08-22 20:06:13 -04002112 nfs_super_set_maxbytes(sb, server->maxfilesize);
2113}
2114
2115/*
2116 * Finish setting up an NFS2/3 superblock
2117 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04002118static void nfs_fill_super(struct super_block *sb,
2119 struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -04002120{
2121 struct nfs_server *server = NFS_SB(sb);
2122
2123 sb->s_blocksize_bits = 0;
2124 sb->s_blocksize = 0;
2125 if (data->bsize)
2126 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
2127
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04002128 if (server->nfs_client->rpc_ops->version == 3) {
David Howells54ceac42006-08-22 20:06:13 -04002129 /* The VFS shouldn't apply the umask to mode bits. We will do
2130 * so ourselves when necessary.
2131 */
2132 sb->s_flags |= MS_POSIXACL;
2133 sb->s_time_gran = 1;
2134 }
2135
2136 sb->s_op = &nfs_sops;
2137 nfs_initialise_sb(sb);
2138}
2139
2140/*
2141 * Finish setting up a cloned NFS2/3 superblock
2142 */
2143static void nfs_clone_super(struct super_block *sb,
2144 const struct super_block *old_sb)
2145{
2146 struct nfs_server *server = NFS_SB(sb);
2147
2148 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2149 sb->s_blocksize = old_sb->s_blocksize;
2150 sb->s_maxbytes = old_sb->s_maxbytes;
2151
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04002152 if (server->nfs_client->rpc_ops->version == 3) {
David Howells54ceac42006-08-22 20:06:13 -04002153 /* The VFS shouldn't apply the umask to mode bits. We will do
2154 * so ourselves when necessary.
2155 */
2156 sb->s_flags |= MS_POSIXACL;
2157 sb->s_time_gran = 1;
2158 }
2159
2160 sb->s_op = old_sb->s_op;
2161 nfs_initialise_sb(sb);
2162}
2163
Trond Myklebust275a5d22007-05-16 16:53:28 -04002164static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
2165{
2166 const struct nfs_server *a = s->s_fs_info;
2167 const struct rpc_clnt *clnt_a = a->client;
2168 const struct rpc_clnt *clnt_b = b->client;
2169
2170 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
2171 goto Ebusy;
2172 if (a->nfs_client != b->nfs_client)
2173 goto Ebusy;
2174 if (a->flags != b->flags)
2175 goto Ebusy;
2176 if (a->wsize != b->wsize)
2177 goto Ebusy;
2178 if (a->rsize != b->rsize)
2179 goto Ebusy;
2180 if (a->acregmin != b->acregmin)
2181 goto Ebusy;
2182 if (a->acregmax != b->acregmax)
2183 goto Ebusy;
2184 if (a->acdirmin != b->acdirmin)
2185 goto Ebusy;
2186 if (a->acdirmax != b->acdirmax)
2187 goto Ebusy;
2188 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
2189 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002190 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04002191Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002192 return 0;
2193}
2194
2195struct nfs_sb_mountdata {
2196 struct nfs_server *server;
2197 int mntflags;
2198};
2199
2200static int nfs_set_super(struct super_block *s, void *data)
2201{
2202 struct nfs_sb_mountdata *sb_mntdata = data;
2203 struct nfs_server *server = sb_mntdata->server;
2204 int ret;
2205
2206 s->s_flags = sb_mntdata->mntflags;
2207 s->s_fs_info = server;
2208 ret = set_anon_super(s, server);
2209 if (ret == 0)
2210 server->s_dev = s->s_dev;
2211 return ret;
2212}
2213
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002214static int nfs_compare_super_address(struct nfs_server *server1,
2215 struct nfs_server *server2)
2216{
2217 struct sockaddr *sap1, *sap2;
2218
2219 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
2220 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
2221
2222 if (sap1->sa_family != sap2->sa_family)
2223 return 0;
2224
2225 switch (sap1->sa_family) {
2226 case AF_INET: {
2227 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
2228 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
2229 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
2230 return 0;
2231 if (sin1->sin_port != sin2->sin_port)
2232 return 0;
2233 break;
2234 }
2235 case AF_INET6: {
2236 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
2237 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
2238 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
2239 return 0;
2240 if (sin1->sin6_port != sin2->sin6_port)
2241 return 0;
2242 break;
2243 }
2244 default:
2245 return 0;
2246 }
2247
2248 return 1;
2249}
2250
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002251static int nfs_compare_super(struct super_block *sb, void *data)
2252{
2253 struct nfs_sb_mountdata *sb_mntdata = data;
2254 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2255 int mntflags = sb_mntdata->mntflags;
2256
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002257 if (!nfs_compare_super_address(old, server))
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002258 return 0;
2259 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2260 if (old->flags & NFS_MOUNT_UNSHARED)
2261 return 0;
2262 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2263 return 0;
2264 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04002265}
2266
Miklos Szeredifa799752008-04-30 00:54:33 -07002267static int nfs_bdi_register(struct nfs_server *server)
2268{
2269 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
2270}
2271
David Howells54ceac42006-08-22 20:06:13 -04002272static int nfs_get_sb(struct file_system_type *fs_type,
2273 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2274{
2275 struct nfs_server *server = NULL;
2276 struct super_block *s;
Trond Myklebust33852a12008-06-19 14:20:11 -04002277 struct nfs_parsed_mount_data *data;
2278 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04002279 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002280 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002281 struct nfs_sb_mountdata sb_mntdata = {
2282 .mntflags = flags,
2283 };
Trond Myklebust33852a12008-06-19 14:20:11 -04002284 int error = -ENOMEM;
David Howells54ceac42006-08-22 20:06:13 -04002285
Paulius Zaleckas1e657bd2010-10-31 18:21:05 +02002286 data = nfs_alloc_parsed_mount_data(NFS_DEFAULT_VERSION);
Trond Myklebustb157b062010-04-19 19:05:48 -04002287 mntfh = nfs_alloc_fhandle();
Trond Myklebust33852a12008-06-19 14:20:11 -04002288 if (data == NULL || mntfh == NULL)
2289 goto out_free_fh;
2290
2291 security_init_mnt_opts(&data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002292
David Howells54ceac42006-08-22 20:06:13 -04002293 /* Validate the mount data */
Trond Myklebust33852a12008-06-19 14:20:11 -04002294 error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04002295 if (error < 0)
Chuck Lever06559602007-07-01 12:12:35 -04002296 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002297
Chuck Lever764302c2009-09-08 19:50:03 -04002298#ifdef CONFIG_NFS_V4
2299 if (data->version == 4) {
2300 error = nfs4_try_mount(flags, dev_name, data, mnt);
2301 kfree(data->client_address);
Xiaotian Feng9699eda2010-04-22 18:56:17 +08002302 kfree(data->nfs_server.export_path);
Chuck Lever764302c2009-09-08 19:50:03 -04002303 goto out;
2304 }
2305#endif /* CONFIG_NFS_V4 */
2306
David Howells54ceac42006-08-22 20:06:13 -04002307 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002308 server = nfs_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002309 if (IS_ERR(server)) {
2310 error = PTR_ERR(server);
Chuck Lever06559602007-07-01 12:12:35 -04002311 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002312 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002313 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002314
Trond Myklebust75180df2007-05-16 16:53:28 -04002315 if (server->flags & NFS_MOUNT_UNSHARED)
2316 compare_super = NULL;
2317
David Howells54ceac42006-08-22 20:06:13 -04002318 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002319 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002320 if (IS_ERR(s)) {
2321 error = PTR_ERR(s);
David Howells54ceac42006-08-22 20:06:13 -04002322 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04002323 }
2324
David Howells54ceac42006-08-22 20:06:13 -04002325 if (s->s_fs_info != server) {
2326 nfs_free_server(server);
2327 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002328 } else {
2329 error = nfs_bdi_register(server);
2330 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11002331 goto error_splat_bdi;
David Howellsf7b422b2006-06-09 09:34:33 -04002332 }
David Howells54ceac42006-08-22 20:06:13 -04002333
2334 if (!s->s_root) {
2335 /* initial superblock/root creation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002336 nfs_fill_super(s, data);
David Howells2df54802009-09-23 14:36:39 -04002337 nfs_fscache_get_super_cookie(
2338 s, data ? data->fscache_uniq : NULL, NULL);
David Howells54ceac42006-08-22 20:06:13 -04002339 }
2340
Trond Myklebust33852a12008-06-19 14:20:11 -04002341 mntroot = nfs_get_root(s, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002342 if (IS_ERR(mntroot)) {
2343 error = PTR_ERR(mntroot);
2344 goto error_splat_super;
2345 }
2346
Trond Myklebust33852a12008-06-19 14:20:11 -04002347 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002348 if (error)
2349 goto error_splat_root;
2350
David Howellsf7b422b2006-06-09 09:34:33 -04002351 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002352 mnt->mnt_sb = s;
2353 mnt->mnt_root = mntroot;
Chuck Lever06559602007-07-01 12:12:35 -04002354 error = 0;
2355
2356out:
Trond Myklebust33852a12008-06-19 14:20:11 -04002357 kfree(data->nfs_server.hostname);
2358 kfree(data->mount_server.hostname);
David Howells08734042009-04-03 16:42:42 +01002359 kfree(data->fscache_uniq);
Trond Myklebust33852a12008-06-19 14:20:11 -04002360 security_free_mnt_opts(&data->lsm_opts);
2361out_free_fh:
Trond Myklebustb157b062010-04-19 19:05:48 -04002362 nfs_free_fhandle(mntfh);
Trond Myklebust33852a12008-06-19 14:20:11 -04002363 kfree(data);
Chuck Lever06559602007-07-01 12:12:35 -04002364 return error;
Trond Myklebust816724e2006-06-24 08:41:41 -04002365
David Howells54ceac42006-08-22 20:06:13 -04002366out_err_nosb:
2367 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04002368 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002369
Eric Parisf9c3a382008-03-05 14:20:18 -05002370error_splat_root:
2371 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04002372error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002373 if (server && !s->s_root)
2374 bdi_unregister(&server->backing_dev_info);
2375error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002376 deactivate_locked_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04002377 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002378}
2379
David Howells54ceac42006-08-22 20:06:13 -04002380/*
Trond Myklebust387c1492010-02-03 08:27:35 -05002381 * Ensure that we unregister the bdi before kill_anon_super
2382 * releases the device name
2383 */
2384static void nfs_put_super(struct super_block *s)
2385{
2386 struct nfs_server *server = NFS_SB(s);
2387
2388 bdi_unregister(&server->backing_dev_info);
2389}
2390
2391/*
David Howells54ceac42006-08-22 20:06:13 -04002392 * Destroy an NFS2/3 superblock
2393 */
David Howellsf7b422b2006-06-09 09:34:33 -04002394static void nfs_kill_super(struct super_block *s)
2395{
2396 struct nfs_server *server = NFS_SB(s);
2397
2398 kill_anon_super(s);
David Howells08734042009-04-03 16:42:42 +01002399 nfs_fscache_release_super_cookie(s);
David Howells54ceac42006-08-22 20:06:13 -04002400 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04002401}
2402
David Howells54ceac42006-08-22 20:06:13 -04002403/*
2404 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2405 */
Al Viro31f43472010-10-29 03:38:12 -04002406static struct dentry *
2407nfs_xdev_mount(struct file_system_type *fs_type, int flags,
2408 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002409{
2410 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002411 struct super_block *s;
2412 struct nfs_server *server;
2413 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002414 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002415 struct nfs_sb_mountdata sb_mntdata = {
2416 .mntflags = flags,
2417 };
David Howells54ceac42006-08-22 20:06:13 -04002418 int error;
2419
Al Viro31f43472010-10-29 03:38:12 -04002420 dprintk("--> nfs_xdev_mount()\n");
David Howells54ceac42006-08-22 20:06:13 -04002421
2422 /* create a new volume representation */
2423 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2424 if (IS_ERR(server)) {
2425 error = PTR_ERR(server);
2426 goto out_err_noserver;
2427 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002428 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002429
Trond Myklebust75180df2007-05-16 16:53:28 -04002430 if (server->flags & NFS_MOUNT_UNSHARED)
2431 compare_super = NULL;
2432
David Howells54ceac42006-08-22 20:06:13 -04002433 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002434 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002435 if (IS_ERR(s)) {
2436 error = PTR_ERR(s);
2437 goto out_err_nosb;
2438 }
2439
2440 if (s->s_fs_info != server) {
2441 nfs_free_server(server);
2442 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002443 } else {
2444 error = nfs_bdi_register(server);
2445 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11002446 goto error_splat_bdi;
David Howells54ceac42006-08-22 20:06:13 -04002447 }
2448
2449 if (!s->s_root) {
2450 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002451 nfs_clone_super(s, data->sb);
David Howells2df54802009-09-23 14:36:39 -04002452 nfs_fscache_get_super_cookie(s, NULL, data);
David Howells54ceac42006-08-22 20:06:13 -04002453 }
2454
2455 mntroot = nfs_get_root(s, data->fh);
2456 if (IS_ERR(mntroot)) {
2457 error = PTR_ERR(mntroot);
2458 goto error_splat_super;
2459 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002460 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
Neil Brown4c1fe2f2007-11-01 16:50:20 +11002461 dput(mntroot);
2462 error = -ESTALE;
2463 goto error_splat_super;
2464 }
David Howells54ceac42006-08-22 20:06:13 -04002465
2466 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002467
Eric Parisf9c3a382008-03-05 14:20:18 -05002468 /* clone any lsm security options from the parent to the new sb */
2469 security_sb_clone_mnt_opts(data->sb, s);
2470
Al Viro31f43472010-10-29 03:38:12 -04002471 dprintk("<-- nfs_xdev_mount() = 0\n");
2472 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04002473
2474out_err_nosb:
2475 nfs_free_server(server);
2476out_err_noserver:
Al Viro31f43472010-10-29 03:38:12 -04002477 dprintk("<-- nfs_xdev_mount() = %d [error]\n", error);
2478 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04002479
2480error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002481 if (server && !s->s_root)
2482 bdi_unregister(&server->backing_dev_info);
2483error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002484 deactivate_locked_super(s);
Al Viro31f43472010-10-29 03:38:12 -04002485 dprintk("<-- nfs_xdev_mount() = %d [splat]\n", error);
2486 return ERR_PTR(error);
David Howellsf7b422b2006-06-09 09:34:33 -04002487}
2488
2489#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04002490
2491/*
2492 * Finish setting up a cloned NFS4 superblock
2493 */
2494static void nfs4_clone_super(struct super_block *sb,
2495 const struct super_block *old_sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002496{
David Howells54ceac42006-08-22 20:06:13 -04002497 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2498 sb->s_blocksize = old_sb->s_blocksize;
2499 sb->s_maxbytes = old_sb->s_maxbytes;
2500 sb->s_time_gran = 1;
2501 sb->s_op = old_sb->s_op;
2502 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002503}
2504
2505/*
2506 * Set up an NFS4 superblock
2507 */
David Howells54ceac42006-08-22 20:06:13 -04002508static void nfs4_fill_super(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002509{
David Howellsf7b422b2006-06-09 09:34:33 -04002510 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04002511 sb->s_op = &nfs4_sops;
David Howells54ceac42006-08-22 20:06:13 -04002512 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002513}
2514
Trond Myklebust01c3f052009-06-17 13:22:58 -07002515static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2516{
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04002517 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3|
2518 NFS_MOUNT_LOCAL_FLOCK|NFS_MOUNT_LOCAL_FCNTL);
Trond Myklebust01c3f052009-06-17 13:22:58 -07002519}
2520
Chuck Lever7630c852009-09-08 19:49:57 -04002521static int nfs4_validate_text_mount_data(void *options,
2522 struct nfs_parsed_mount_data *args,
2523 const char *dev_name)
2524{
2525 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2526
Trond Myklebustf5855fe2009-10-06 15:40:37 -04002527 nfs_set_port(sap, &args->nfs_server.port, NFS_PORT);
Chuck Lever7630c852009-09-08 19:49:57 -04002528
2529 nfs_validate_transport_protocol(args);
2530
2531 nfs4_validate_mount_flags(args);
2532
Trond Myklebust2ecda722009-09-08 19:50:07 -04002533 if (args->version != 4) {
2534 dfprintk(MOUNT,
2535 "NFS4: Illegal mount version\n");
2536 return -EINVAL;
2537 }
2538
Chuck Lever7630c852009-09-08 19:49:57 -04002539 if (args->auth_flavor_len > 1) {
2540 dfprintk(MOUNT,
2541 "NFS4: Too many RPC auth flavours specified\n");
2542 return -EINVAL;
2543 }
2544
2545 if (args->client_address == NULL) {
2546 dfprintk(MOUNT,
2547 "NFS4: mount program didn't pass callback address\n");
2548 return -EINVAL;
2549 }
2550
2551 return nfs_parse_devname(dev_name,
2552 &args->nfs_server.hostname,
2553 NFS4_MAXNAMLEN,
2554 &args->nfs_server.export_path,
2555 NFS4_MAXPATHLEN);
2556}
2557
David Howells54ceac42006-08-22 20:06:13 -04002558/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04002559 * Validate NFSv4 mount options
2560 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002561static int nfs4_validate_mount_data(void *options,
2562 struct nfs_parsed_mount_data *args,
2563 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04002564{
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002565 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002566 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002567 char *c;
2568
2569 if (data == NULL)
2570 goto out_no_data;
2571
2572 switch (data->version) {
2573 case 1:
Chuck Lever4c568012007-12-10 14:59:28 -05002574 if (data->host_addrlen > sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002575 goto out_no_address;
Chuck Lever4c568012007-12-10 14:59:28 -05002576 if (data->host_addrlen == 0)
2577 goto out_no_address;
2578 args->nfs_server.addrlen = data->host_addrlen;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002579 if (copy_from_user(sap, data->host_addr, data->host_addrlen))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002580 return -EFAULT;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002581 if (!nfs_verify_server_address(sap))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002582 goto out_no_address;
2583
Chuck Lever6738b252008-06-24 16:33:54 -04002584 if (data->auth_flavourlen) {
2585 if (data->auth_flavourlen > 1)
2586 goto out_inval_auth;
Trond Myklebust20c71f52007-09-20 20:23:51 -04002587 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002588 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04002589 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002590 return -EFAULT;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002591 }
2592
2593 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2594 if (IS_ERR(c))
2595 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002596 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002597
2598 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2599 if (IS_ERR(c))
2600 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002601 args->nfs_server.export_path = c;
2602 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002603
2604 c = strndup_user(data->client_addr.data, 16);
2605 if (IS_ERR(c))
2606 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002607 args->client_address = c;
2608
2609 /*
2610 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2611 * can deal with.
2612 */
2613
2614 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2615 args->rsize = data->rsize;
2616 args->wsize = data->wsize;
2617 args->timeo = data->timeo;
2618 args->retrans = data->retrans;
2619 args->acregmin = data->acregmin;
2620 args->acregmax = data->acregmax;
2621 args->acdirmin = data->acdirmin;
2622 args->acdirmax = data->acdirmax;
2623 args->nfs_server.protocol = data->proto;
Trond Myklebust259875e2008-07-02 14:43:47 -04002624 nfs_validate_transport_protocol(args);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002625
2626 break;
Chuck Lever7630c852009-09-08 19:49:57 -04002627 default:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002628 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever80071222007-07-01 12:13:59 -04002629 return -EINVAL;
2630
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002631 if (!nfs_verify_server_address(sap))
Chuck Lever80071222007-07-01 12:13:59 -04002632 return -EINVAL;
Chuck Levered596a82008-06-26 17:47:05 -04002633
Chuck Lever7630c852009-09-08 19:49:57 -04002634 return nfs4_validate_text_mount_data(options, args, dev_name);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002635 }
2636
2637 return 0;
2638
2639out_no_data:
2640 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2641 return -EINVAL;
2642
2643out_inval_auth:
2644 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2645 data->auth_flavourlen);
2646 return -EINVAL;
2647
2648out_no_address:
2649 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2650 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002651}
2652
2653/*
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002654 * Get the superblock for the NFS4 root partition
David Howells54ceac42006-08-22 20:06:13 -04002655 */
Al Viro31f43472010-10-29 03:38:12 -04002656static struct dentry *
2657nfs4_remote_mount(struct file_system_type *fs_type, int flags,
2658 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002659{
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002660 struct nfs_parsed_mount_data *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002661 struct super_block *s;
2662 struct nfs_server *server;
Trond Myklebust33852a12008-06-19 14:20:11 -04002663 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04002664 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002665 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002666 struct nfs_sb_mountdata sb_mntdata = {
2667 .mntflags = flags,
2668 };
Trond Myklebust33852a12008-06-19 14:20:11 -04002669 int error = -ENOMEM;
David Howellsf7b422b2006-06-09 09:34:33 -04002670
Trond Myklebustb157b062010-04-19 19:05:48 -04002671 mntfh = nfs_alloc_fhandle();
Trond Myklebust33852a12008-06-19 14:20:11 -04002672 if (data == NULL || mntfh == NULL)
2673 goto out_free_fh;
2674
2675 security_init_mnt_opts(&data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002676
David Howells54ceac42006-08-22 20:06:13 -04002677 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002678 server = nfs4_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002679 if (IS_ERR(server)) {
2680 error = PTR_ERR(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04002681 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002682 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002683 sb_mntdata.server = server;
David Howellsf7b422b2006-06-09 09:34:33 -04002684
Trond Myklebust75180df2007-05-16 16:53:28 -04002685 if (server->flags & NFS4_MOUNT_UNSHARED)
2686 compare_super = NULL;
2687
David Howells54ceac42006-08-22 20:06:13 -04002688 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002689 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002690 if (IS_ERR(s)) {
2691 error = PTR_ERR(s);
David Howellsf7b422b2006-06-09 09:34:33 -04002692 goto out_free;
Trond Myklebust816724e2006-06-24 08:41:41 -04002693 }
2694
Trond Myklebust5dd31772006-08-24 01:03:05 -04002695 if (s->s_fs_info != server) {
2696 nfs_free_server(server);
2697 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002698 } else {
2699 error = nfs_bdi_register(server);
2700 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11002701 goto error_splat_bdi;
Trond Myklebust5dd31772006-08-24 01:03:05 -04002702 }
2703
David Howells54ceac42006-08-22 20:06:13 -04002704 if (!s->s_root) {
2705 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002706 nfs4_fill_super(s);
David Howells2df54802009-09-23 14:36:39 -04002707 nfs_fscache_get_super_cookie(
2708 s, data ? data->fscache_uniq : NULL, NULL);
Trond Myklebust816724e2006-06-24 08:41:41 -04002709 }
David Howellsf7b422b2006-06-09 09:34:33 -04002710
Trond Myklebust33852a12008-06-19 14:20:11 -04002711 mntroot = nfs4_get_root(s, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002712 if (IS_ERR(mntroot)) {
2713 error = PTR_ERR(mntroot);
2714 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04002715 }
David Howells54ceac42006-08-22 20:06:13 -04002716
Trond Myklebust33852a12008-06-19 14:20:11 -04002717 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Paris46c8ac72008-05-02 13:42:42 -07002718 if (error)
2719 goto error_splat_root;
2720
David Howellsf7b422b2006-06-09 09:34:33 -04002721 s->s_flags |= MS_ACTIVE;
Al Viro31f43472010-10-29 03:38:12 -04002722
2723 security_free_mnt_opts(&data->lsm_opts);
2724 nfs_free_fhandle(mntfh);
2725 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04002726
Chuck Lever29eb9812007-07-01 12:12:30 -04002727out:
Trond Myklebust33852a12008-06-19 14:20:11 -04002728 security_free_mnt_opts(&data->lsm_opts);
2729out_free_fh:
Trond Myklebustb157b062010-04-19 19:05:48 -04002730 nfs_free_fhandle(mntfh);
Al Viro31f43472010-10-29 03:38:12 -04002731 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04002732
Chuck Lever29eb9812007-07-01 12:12:30 -04002733out_free:
2734 nfs_free_server(server);
2735 goto out;
2736
Eric Paris46c8ac72008-05-02 13:42:42 -07002737error_splat_root:
2738 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04002739error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002740 if (server && !s->s_root)
2741 bdi_unregister(&server->backing_dev_info);
2742error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002743 deactivate_locked_super(s);
Chuck Lever29eb9812007-07-01 12:12:30 -04002744 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002745}
2746
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002747static struct vfsmount *nfs_do_root_mount(struct file_system_type *fs_type,
2748 int flags, void *data, const char *hostname)
2749{
2750 struct vfsmount *root_mnt;
2751 char *root_devname;
2752 size_t len;
2753
2754 len = strlen(hostname) + 3;
2755 root_devname = kmalloc(len, GFP_KERNEL);
2756 if (root_devname == NULL)
2757 return ERR_PTR(-ENOMEM);
2758 snprintf(root_devname, len, "%s:/", hostname);
2759 root_mnt = vfs_kern_mount(fs_type, flags, root_devname, data);
2760 kfree(root_devname);
2761 return root_mnt;
2762}
2763
Trond Myklebustb88f8a52009-06-22 15:09:14 -04002764static void nfs_fix_devname(const struct path *path, struct vfsmount *mnt)
2765{
2766 char *page = (char *) __get_free_page(GFP_KERNEL);
2767 char *devname, *tmp;
2768
2769 if (page == NULL)
2770 return;
2771 devname = nfs_path(path->mnt->mnt_devname,
2772 path->mnt->mnt_root, path->dentry,
2773 page, PAGE_SIZE);
Dan Carpentercdd29ec2010-04-22 15:35:56 -04002774 if (IS_ERR(devname))
Trond Myklebustb88f8a52009-06-22 15:09:14 -04002775 goto out_freepage;
2776 tmp = kstrdup(devname, GFP_KERNEL);
2777 if (tmp == NULL)
2778 goto out_freepage;
2779 kfree(mnt->mnt_devname);
2780 mnt->mnt_devname = tmp;
2781out_freepage:
2782 free_page((unsigned long)page);
2783}
2784
Trond Myklebustce587e02010-04-16 16:22:52 -04002785struct nfs_referral_count {
2786 struct list_head list;
2787 const struct task_struct *task;
2788 unsigned int referral_count;
2789};
2790
2791static LIST_HEAD(nfs_referral_count_list);
2792static DEFINE_SPINLOCK(nfs_referral_count_list_lock);
2793
2794static struct nfs_referral_count *nfs_find_referral_count(void)
2795{
2796 struct nfs_referral_count *p;
2797
2798 list_for_each_entry(p, &nfs_referral_count_list, list) {
2799 if (p->task == current)
2800 return p;
2801 }
2802 return NULL;
2803}
2804
2805#define NFS_MAX_NESTED_REFERRALS 2
2806
2807static int nfs_referral_loop_protect(void)
2808{
2809 struct nfs_referral_count *p, *new;
2810 int ret = -ENOMEM;
2811
2812 new = kmalloc(sizeof(*new), GFP_KERNEL);
2813 if (!new)
2814 goto out;
2815 new->task = current;
2816 new->referral_count = 1;
2817
2818 ret = 0;
2819 spin_lock(&nfs_referral_count_list_lock);
2820 p = nfs_find_referral_count();
2821 if (p != NULL) {
2822 if (p->referral_count >= NFS_MAX_NESTED_REFERRALS)
2823 ret = -ELOOP;
2824 else
2825 p->referral_count++;
2826 } else {
2827 list_add(&new->list, &nfs_referral_count_list);
2828 new = NULL;
2829 }
2830 spin_unlock(&nfs_referral_count_list_lock);
2831 kfree(new);
2832out:
2833 return ret;
2834}
2835
2836static void nfs_referral_loop_unprotect(void)
2837{
2838 struct nfs_referral_count *p;
2839
2840 spin_lock(&nfs_referral_count_list_lock);
2841 p = nfs_find_referral_count();
2842 p->referral_count--;
2843 if (p->referral_count == 0)
2844 list_del(&p->list);
2845 else
2846 p = NULL;
2847 spin_unlock(&nfs_referral_count_list_lock);
2848 kfree(p);
2849}
2850
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002851static int nfs_follow_remote_path(struct vfsmount *root_mnt,
2852 const char *export_path, struct vfsmount *mnt_target)
2853{
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002854 struct nameidata *nd = NULL;
Linus Torvaldsa2770d82009-12-17 12:51:05 -08002855 struct mnt_namespace *ns_private;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002856 struct super_block *s;
2857 int ret;
2858
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002859 nd = kmalloc(sizeof(*nd), GFP_KERNEL);
2860 if (nd == NULL)
2861 return -ENOMEM;
2862
Linus Torvaldsa2770d82009-12-17 12:51:05 -08002863 ns_private = create_mnt_ns(root_mnt);
2864 ret = PTR_ERR(ns_private);
2865 if (IS_ERR(ns_private))
2866 goto out_mntput;
2867
Trond Myklebustce587e02010-04-16 16:22:52 -04002868 ret = nfs_referral_loop_protect();
2869 if (ret != 0)
2870 goto out_put_mnt_ns;
2871
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002872 ret = vfs_path_lookup(root_mnt->mnt_root, root_mnt,
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002873 export_path, LOOKUP_FOLLOW, nd);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002874
Trond Myklebustce587e02010-04-16 16:22:52 -04002875 nfs_referral_loop_unprotect();
Linus Torvaldsa2770d82009-12-17 12:51:05 -08002876 put_mnt_ns(ns_private);
2877
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002878 if (ret != 0)
2879 goto out_err;
2880
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002881 s = nd->path.mnt->mnt_sb;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002882 atomic_inc(&s->s_active);
2883 mnt_target->mnt_sb = s;
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002884 mnt_target->mnt_root = dget(nd->path.dentry);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002885
Trond Myklebustb88f8a52009-06-22 15:09:14 -04002886 /* Correct the device pathname */
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002887 nfs_fix_devname(&nd->path, mnt_target);
Trond Myklebustb88f8a52009-06-22 15:09:14 -04002888
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002889 path_put(&nd->path);
2890 kfree(nd);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002891 down_write(&s->s_umount);
2892 return 0;
Trond Myklebustce587e02010-04-16 16:22:52 -04002893out_put_mnt_ns:
2894 put_mnt_ns(ns_private);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002895out_mntput:
2896 mntput(root_mnt);
2897out_err:
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002898 kfree(nd);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002899 return ret;
2900}
2901
Chuck Levera6fe23b2009-09-08 19:50:00 -04002902static int nfs4_try_mount(int flags, const char *dev_name,
2903 struct nfs_parsed_mount_data *data,
2904 struct vfsmount *mnt)
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002905{
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002906 char *export_path;
2907 struct vfsmount *root_mnt;
Chuck Levera6fe23b2009-09-08 19:50:00 -04002908 int error;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002909
Chuck Levera6fe23b2009-09-08 19:50:00 -04002910 dfprintk(MOUNT, "--> nfs4_try_mount()\n");
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002911
2912 export_path = data->nfs_server.export_path;
2913 data->nfs_server.export_path = "/";
2914 root_mnt = nfs_do_root_mount(&nfs4_remote_fs_type, flags, data,
2915 data->nfs_server.hostname);
2916 data->nfs_server.export_path = export_path;
2917
2918 error = PTR_ERR(root_mnt);
2919 if (IS_ERR(root_mnt))
2920 goto out;
2921
2922 error = nfs_follow_remote_path(root_mnt, export_path, mnt);
2923
2924out:
Chuck Levera6fe23b2009-09-08 19:50:00 -04002925 dfprintk(MOUNT, "<-- nfs4_try_mount() = %d%s\n", error,
2926 error != 0 ? " [error]" : "");
2927 return error;
2928}
2929
2930/*
2931 * Get the superblock for an NFS4 mountpoint
2932 */
2933static int nfs4_get_sb(struct file_system_type *fs_type,
2934 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2935{
2936 struct nfs_parsed_mount_data *data;
2937 int error = -ENOMEM;
2938
Trond Myklebustc5811db2009-10-06 15:40:15 -04002939 data = nfs_alloc_parsed_mount_data(4);
Chuck Levera6fe23b2009-09-08 19:50:00 -04002940 if (data == NULL)
2941 goto out_free_data;
2942
2943 /* Validate the mount data */
2944 error = nfs4_validate_mount_data(raw_data, data, dev_name);
2945 if (error < 0)
2946 goto out;
2947
2948 error = nfs4_try_mount(flags, dev_name, data, mnt);
2949
2950out:
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002951 kfree(data->client_address);
2952 kfree(data->nfs_server.export_path);
2953 kfree(data->nfs_server.hostname);
2954 kfree(data->fscache_uniq);
2955out_free_data:
2956 kfree(data);
2957 dprintk("<-- nfs4_get_sb() = %d%s\n", error,
2958 error != 0 ? " [error]" : "");
2959 return error;
2960}
2961
David Howellsf7b422b2006-06-09 09:34:33 -04002962static void nfs4_kill_super(struct super_block *sb)
2963{
2964 struct nfs_server *server = NFS_SB(sb);
2965
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002966 dprintk("--> %s\n", __func__);
Trond Myklebust515d8612008-12-23 15:21:46 -05002967 nfs_super_return_all_delegations(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002968 kill_anon_super(sb);
David Howells08734042009-04-03 16:42:42 +01002969 nfs_fscache_release_super_cookie(sb);
David Howells54ceac42006-08-22 20:06:13 -04002970 nfs_free_server(server);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002971 dprintk("<-- %s\n", __func__);
David Howellsf7b422b2006-06-09 09:34:33 -04002972}
2973
2974/*
David Howells54ceac42006-08-22 20:06:13 -04002975 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -04002976 */
Al Viro31f43472010-10-29 03:38:12 -04002977static struct dentry *
2978nfs4_xdev_mount(struct file_system_type *fs_type, int flags,
2979 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002980{
2981 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002982 struct super_block *s;
2983 struct nfs_server *server;
2984 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002985 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002986 struct nfs_sb_mountdata sb_mntdata = {
2987 .mntflags = flags,
2988 };
David Howells54ceac42006-08-22 20:06:13 -04002989 int error;
2990
Al Viro31f43472010-10-29 03:38:12 -04002991 dprintk("--> nfs4_xdev_mount()\n");
David Howells54ceac42006-08-22 20:06:13 -04002992
2993 /* create a new volume representation */
2994 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2995 if (IS_ERR(server)) {
2996 error = PTR_ERR(server);
2997 goto out_err_noserver;
2998 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002999 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04003000
Trond Myklebust75180df2007-05-16 16:53:28 -04003001 if (server->flags & NFS4_MOUNT_UNSHARED)
3002 compare_super = NULL;
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_clone_super(s, data->sb);
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
3026 mntroot = nfs4_get_root(s, data->fh);
3027 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
Al Viro31f43472010-10-29 03:38:12 -04003041 dprintk("<-- nfs4_xdev_mount() = 0\n");
3042 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04003043
3044out_err_nosb:
3045 nfs_free_server(server);
3046out_err_noserver:
Al Viro31f43472010-10-29 03:38:12 -04003047 dprintk("<-- nfs4_xdev_mount() = %d [error]\n", error);
3048 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04003049
3050error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11003051 if (server && !s->s_root)
3052 bdi_unregister(&server->backing_dev_info);
3053error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04003054 deactivate_locked_super(s);
Al Viro31f43472010-10-29 03:38:12 -04003055 dprintk("<-- nfs4_xdev_mount() = %d [splat]\n", error);
3056 return ERR_PTR(error);
David Howellsf7b422b2006-06-09 09:34:33 -04003057}
3058
Al Viro31f43472010-10-29 03:38:12 -04003059static struct dentry *
3060nfs4_remote_referral_mount(struct file_system_type *fs_type, int flags,
3061 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04003062{
3063 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04003064 struct super_block *s;
3065 struct nfs_server *server;
3066 struct dentry *mntroot;
Trond Myklebust4f727292010-04-16 16:22:48 -04003067 struct nfs_fh *mntfh;
Trond Myklebust75180df2007-05-16 16:53:28 -04003068 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04003069 struct nfs_sb_mountdata sb_mntdata = {
3070 .mntflags = flags,
3071 };
Trond Myklebust4f727292010-04-16 16:22:48 -04003072 int error = -ENOMEM;
David Howells54ceac42006-08-22 20:06:13 -04003073
3074 dprintk("--> nfs4_referral_get_sb()\n");
3075
Trond Myklebust4f727292010-04-16 16:22:48 -04003076 mntfh = nfs_alloc_fhandle();
3077 if (mntfh == NULL)
3078 goto out_err_nofh;
3079
David Howells54ceac42006-08-22 20:06:13 -04003080 /* create a new volume representation */
Trond Myklebust4f727292010-04-16 16:22:48 -04003081 server = nfs4_create_referral_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04003082 if (IS_ERR(server)) {
3083 error = PTR_ERR(server);
3084 goto out_err_noserver;
3085 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04003086 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04003087
Trond Myklebust75180df2007-05-16 16:53:28 -04003088 if (server->flags & NFS4_MOUNT_UNSHARED)
3089 compare_super = NULL;
3090
David Howells54ceac42006-08-22 20:06:13 -04003091 /* Get a superblock - note that we may end up sharing one that already exists */
Andy Adamsonec9a05c2008-10-17 10:44:37 -04003092 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04003093 if (IS_ERR(s)) {
3094 error = PTR_ERR(s);
3095 goto out_err_nosb;
3096 }
3097
3098 if (s->s_fs_info != server) {
3099 nfs_free_server(server);
3100 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07003101 } else {
3102 error = nfs_bdi_register(server);
3103 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11003104 goto error_splat_bdi;
David Howells54ceac42006-08-22 20:06:13 -04003105 }
3106
3107 if (!s->s_root) {
3108 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04003109 nfs4_fill_super(s);
David Howells2df54802009-09-23 14:36:39 -04003110 nfs_fscache_get_super_cookie(s, NULL, data);
David Howells54ceac42006-08-22 20:06:13 -04003111 }
3112
Trond Myklebust4f727292010-04-16 16:22:48 -04003113 mntroot = nfs4_get_root(s, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04003114 if (IS_ERR(mntroot)) {
3115 error = PTR_ERR(mntroot);
3116 goto error_splat_super;
3117 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05003118 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
3119 dput(mntroot);
3120 error = -ESTALE;
3121 goto error_splat_super;
3122 }
David Howells54ceac42006-08-22 20:06:13 -04003123
3124 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04003125
Eric Paris46c8ac72008-05-02 13:42:42 -07003126 security_sb_clone_mnt_opts(data->sb, s);
3127
Trond Myklebust4f727292010-04-16 16:22:48 -04003128 nfs_free_fhandle(mntfh);
David Howells54ceac42006-08-22 20:06:13 -04003129 dprintk("<-- nfs4_referral_get_sb() = 0\n");
Al Viro31f43472010-10-29 03:38:12 -04003130 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04003131
3132out_err_nosb:
3133 nfs_free_server(server);
3134out_err_noserver:
Trond Myklebust4f727292010-04-16 16:22:48 -04003135 nfs_free_fhandle(mntfh);
3136out_err_nofh:
David Howells54ceac42006-08-22 20:06:13 -04003137 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
Al Viro31f43472010-10-29 03:38:12 -04003138 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04003139
3140error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11003141 if (server && !s->s_root)
3142 bdi_unregister(&server->backing_dev_info);
3143error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04003144 deactivate_locked_super(s);
Trond Myklebust4f727292010-04-16 16:22:48 -04003145 nfs_free_fhandle(mntfh);
David Howells54ceac42006-08-22 20:06:13 -04003146 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
Al Viro31f43472010-10-29 03:38:12 -04003147 return ERR_PTR(error);
David Howellsf7b422b2006-06-09 09:34:33 -04003148}
3149
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04003150/*
3151 * Create an NFS4 server record on referral traversal
3152 */
3153static int nfs4_referral_get_sb(struct file_system_type *fs_type,
3154 int flags, const char *dev_name, void *raw_data,
3155 struct vfsmount *mnt)
3156{
3157 struct nfs_clone_mount *data = raw_data;
3158 char *export_path;
3159 struct vfsmount *root_mnt;
3160 int error;
3161
3162 dprintk("--> nfs4_referral_get_sb()\n");
3163
3164 export_path = data->mnt_path;
3165 data->mnt_path = "/";
3166
3167 root_mnt = nfs_do_root_mount(&nfs4_remote_referral_fs_type,
3168 flags, data, data->hostname);
3169 data->mnt_path = export_path;
3170
3171 error = PTR_ERR(root_mnt);
3172 if (IS_ERR(root_mnt))
3173 goto out;
3174
3175 error = nfs_follow_remote_path(root_mnt, export_path, mnt);
3176out:
3177 dprintk("<-- nfs4_referral_get_sb() = %d%s\n", error,
3178 error != 0 ? " [error]" : "");
3179 return error;
3180}
3181
David Howells54ceac42006-08-22 20:06:13 -04003182#endif /* CONFIG_NFS_V4 */