blob: 685a8a7bd17baf751a1b788a75af1265f38d8660 [file] [log] [blame]
David Howellsf7b422b2006-06-09 09:34:33 -04001/*
2 * linux/fs/nfs/super.c
3 *
4 * Copyright (C) 1992 Rick Sladkey
5 *
6 * nfs superblock handling functions
7 *
Alan Cox526719b2008-10-27 15:19:48 +00008 * Modularised by Alan Cox <alan@lxorguk.ukuu.org.uk>, while hacking some
David Howellsf7b422b2006-06-09 09:34:33 -04009 * experimental NFS changes. Modularisation taken straight from SYS5 fs.
10 *
11 * Change to nfs_read_super() to permit NFS mounts to multi-homed hosts.
12 * J.S.Peatfield@damtp.cam.ac.uk
13 *
14 * Split from inode.c by David Howells <dhowells@redhat.com>
15 *
David Howells54ceac42006-08-22 20:06:13 -040016 * - superblocks are indexed on server only - all inodes, dentries, etc. associated with a
17 * particular server are held in the same superblock
18 * - NFS superblocks can have several effective roots to the dentry tree
19 * - directory type roots are spliced into the tree when a path from one root reaches the root
20 * of another (see nfs_lookup())
David Howellsf7b422b2006-06-09 09:34:33 -040021 */
22
David Howellsf7b422b2006-06-09 09:34:33 -040023#include <linux/module.h>
24#include <linux/init.h>
25
26#include <linux/time.h>
27#include <linux/kernel.h>
28#include <linux/mm.h>
29#include <linux/string.h>
30#include <linux/stat.h>
31#include <linux/errno.h>
32#include <linux/unistd.h>
33#include <linux/sunrpc/clnt.h>
34#include <linux/sunrpc/stats.h>
35#include <linux/sunrpc/metrics.h>
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -040036#include <linux/sunrpc/xprtsock.h>
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -040037#include <linux/sunrpc/xprtrdma.h>
David Howellsf7b422b2006-06-09 09:34:33 -040038#include <linux/nfs_fs.h>
39#include <linux/nfs_mount.h>
40#include <linux/nfs4_mount.h>
41#include <linux/lockd/bind.h>
David Howellsf7b422b2006-06-09 09:34:33 -040042#include <linux/seq_file.h>
43#include <linux/mount.h>
Trond Myklebustc02d7ad2009-06-22 15:09:14 -040044#include <linux/mnt_namespace.h>
45#include <linux/namei.h>
David Howellsf7b422b2006-06-09 09:34:33 -040046#include <linux/nfs_idmap.h>
47#include <linux/vfs.h>
48#include <linux/inet.h>
Chuck Leverfd00a8f2007-12-10 14:57:38 -050049#include <linux/in6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090050#include <linux/slab.h>
Chuck Leverfd00a8f2007-12-10 14:57:38 -050051#include <net/ipv6.h>
Chuck Leverd8e77482008-06-23 12:37:01 -040052#include <linux/netdevice.h>
David Howellsf7b422b2006-06-09 09:34:33 -040053#include <linux/nfs_xdr.h>
Adrian Bunkb5d5dfb2007-02-12 00:53:40 -080054#include <linux/magic.h>
Chuck Leverbf0fd762007-07-01 12:13:44 -040055#include <linux/parser.h>
David Howellsf7b422b2006-06-09 09:34:33 -040056
57#include <asm/system.h>
58#include <asm/uaccess.h>
59
60#include "nfs4_fs.h"
61#include "callback.h"
62#include "delegation.h"
63#include "iostat.h"
64#include "internal.h"
David Howells08734042009-04-03 16:42:42 +010065#include "fscache.h"
David Howellsf7b422b2006-06-09 09:34:33 -040066
67#define NFSDBG_FACILITY NFSDBG_VFS
68
Paulius Zaleckas1e657bd2010-10-31 18:21:05 +020069#ifdef CONFIG_NFS_V3
70#define NFS_DEFAULT_VERSION 3
71#else
72#define NFS_DEFAULT_VERSION 2
73#endif
74
Chuck Leverbf0fd762007-07-01 12:13:44 -040075enum {
76 /* Mount options that take no arguments */
77 Opt_soft, Opt_hard,
Chuck Leverbf0fd762007-07-01 12:13:44 -040078 Opt_posix, Opt_noposix,
79 Opt_cto, Opt_nocto,
80 Opt_ac, Opt_noac,
81 Opt_lock, Opt_nolock,
Chuck Lever764302c2009-09-08 19:50:03 -040082 Opt_v2, Opt_v3, Opt_v4,
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -040083 Opt_udp, Opt_tcp, Opt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -040084 Opt_acl, Opt_noacl,
85 Opt_rdirplus, Opt_nordirplus,
Trond Myklebust75180df2007-05-16 16:53:28 -040086 Opt_sharecache, Opt_nosharecache,
Chuck Leverd7403512008-12-23 15:21:37 -050087 Opt_resvport, Opt_noresvport,
David Howellsb797cac2009-04-03 16:42:48 +010088 Opt_fscache, Opt_nofscache,
Chuck Leverbf0fd762007-07-01 12:13:44 -040089
90 /* Mount options that take integer arguments */
91 Opt_port,
92 Opt_rsize, Opt_wsize, Opt_bsize,
93 Opt_timeo, Opt_retrans,
94 Opt_acregmin, Opt_acregmax,
95 Opt_acdirmin, Opt_acdirmax,
96 Opt_actimeo,
97 Opt_namelen,
98 Opt_mountport,
Chuck Levere887cbc2007-10-26 13:32:29 -040099 Opt_mountvers,
Chuck Leverad879ce2007-10-26 13:32:24 -0400100 Opt_nfsvers,
Mike Sager3fd5be92009-04-01 09:21:48 -0400101 Opt_minorversion,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400102
103 /* Mount options that take string arguments */
Chuck Lever33832032007-12-10 14:59:13 -0500104 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
Chuck Lever0ac83772007-09-11 18:01:04 -0400105 Opt_addr, Opt_mountaddr, Opt_clientaddr,
Trond Myklebust7973c1f12008-07-15 17:58:14 -0400106 Opt_lookupcache,
David Howellsb797cac2009-04-03 16:42:48 +0100107 Opt_fscache_uniq,
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400108 Opt_local_lock,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400109
Chuck Leverf45663c2008-06-24 19:28:02 -0400110 /* Special mount options */
111 Opt_userspace, Opt_deprecated, Opt_sloppy,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400112
113 Opt_err
114};
115
Steven Whitehousea447c092008-10-13 10:46:57 +0100116static const match_table_t nfs_mount_option_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400117 { Opt_userspace, "bg" },
118 { Opt_userspace, "fg" },
Chuck Leverecbb3842008-06-12 12:37:33 -0400119 { Opt_userspace, "retry=%s" },
120
Chuck Leverf45663c2008-06-24 19:28:02 -0400121 { Opt_sloppy, "sloppy" },
122
Chuck Leverbf0fd762007-07-01 12:13:44 -0400123 { Opt_soft, "soft" },
124 { Opt_hard, "hard" },
Chuck Leverd33e4df2008-06-12 12:37:41 -0400125 { Opt_deprecated, "intr" },
126 { Opt_deprecated, "nointr" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400127 { Opt_posix, "posix" },
128 { Opt_noposix, "noposix" },
129 { Opt_cto, "cto" },
130 { Opt_nocto, "nocto" },
131 { Opt_ac, "ac" },
132 { Opt_noac, "noac" },
133 { Opt_lock, "lock" },
134 { Opt_nolock, "nolock" },
135 { Opt_v2, "v2" },
136 { Opt_v3, "v3" },
Chuck Lever764302c2009-09-08 19:50:03 -0400137 { Opt_v4, "v4" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400138 { Opt_udp, "udp" },
139 { Opt_tcp, "tcp" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400140 { Opt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400141 { Opt_acl, "acl" },
142 { Opt_noacl, "noacl" },
143 { Opt_rdirplus, "rdirplus" },
144 { Opt_nordirplus, "nordirplus" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400145 { Opt_sharecache, "sharecache" },
146 { Opt_nosharecache, "nosharecache" },
Chuck Leverd7403512008-12-23 15:21:37 -0500147 { Opt_resvport, "resvport" },
148 { Opt_noresvport, "noresvport" },
David Howellsb797cac2009-04-03 16:42:48 +0100149 { Opt_fscache, "fsc" },
David Howellsb797cac2009-04-03 16:42:48 +0100150 { Opt_nofscache, "nofsc" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400151
Chuck Levera5a16ba2009-06-17 18:02:14 -0700152 { Opt_port, "port=%s" },
153 { Opt_rsize, "rsize=%s" },
154 { Opt_wsize, "wsize=%s" },
155 { Opt_bsize, "bsize=%s" },
156 { Opt_timeo, "timeo=%s" },
157 { Opt_retrans, "retrans=%s" },
158 { Opt_acregmin, "acregmin=%s" },
159 { Opt_acregmax, "acregmax=%s" },
160 { Opt_acdirmin, "acdirmin=%s" },
161 { Opt_acdirmax, "acdirmax=%s" },
162 { Opt_actimeo, "actimeo=%s" },
163 { Opt_namelen, "namlen=%s" },
164 { Opt_mountport, "mountport=%s" },
165 { Opt_mountvers, "mountvers=%s" },
166 { Opt_nfsvers, "nfsvers=%s" },
167 { Opt_nfsvers, "vers=%s" },
Chuck Leverf3f4f4e2009-08-09 15:09:29 -0400168 { Opt_minorversion, "minorversion=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400169
170 { Opt_sec, "sec=%s" },
171 { Opt_proto, "proto=%s" },
172 { Opt_mountproto, "mountproto=%s" },
173 { Opt_addr, "addr=%s" },
174 { Opt_clientaddr, "clientaddr=%s" },
Chuck Lever33832032007-12-10 14:59:13 -0500175 { Opt_mounthost, "mounthost=%s" },
Chuck Lever0ac83772007-09-11 18:01:04 -0400176 { Opt_mountaddr, "mountaddr=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400177
Trond Myklebust7973c1f12008-07-15 17:58:14 -0400178 { Opt_lookupcache, "lookupcache=%s" },
Chuck Levera6d5ff62010-05-07 13:33:58 -0400179 { Opt_fscache_uniq, "fsc=%s" },
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400180 { Opt_local_lock, "local_lock=%s" },
Trond Myklebust7973c1f12008-07-15 17:58:14 -0400181
Chuck Leverbf0fd762007-07-01 12:13:44 -0400182 { Opt_err, NULL }
183};
184
185enum {
Jeff Laytonee671b02009-12-03 15:58:56 -0500186 Opt_xprt_udp, Opt_xprt_udp6, Opt_xprt_tcp, Opt_xprt_tcp6, Opt_xprt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400187
188 Opt_xprt_err
189};
190
Steven Whitehousea447c092008-10-13 10:46:57 +0100191static const match_table_t nfs_xprt_protocol_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400192 { Opt_xprt_udp, "udp" },
Jeff Laytonee671b02009-12-03 15:58:56 -0500193 { Opt_xprt_udp6, "udp6" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400194 { Opt_xprt_tcp, "tcp" },
Jeff Laytonee671b02009-12-03 15:58:56 -0500195 { Opt_xprt_tcp6, "tcp6" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400196 { Opt_xprt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400197
198 { Opt_xprt_err, NULL }
199};
200
201enum {
202 Opt_sec_none, Opt_sec_sys,
203 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
204 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
205 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
206
207 Opt_sec_err
208};
209
Steven Whitehousea447c092008-10-13 10:46:57 +0100210static const match_table_t nfs_secflavor_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400211 { Opt_sec_none, "none" },
212 { Opt_sec_none, "null" },
213 { Opt_sec_sys, "sys" },
214
215 { Opt_sec_krb5, "krb5" },
216 { Opt_sec_krb5i, "krb5i" },
217 { Opt_sec_krb5p, "krb5p" },
218
219 { Opt_sec_lkey, "lkey" },
220 { Opt_sec_lkeyi, "lkeyi" },
221 { Opt_sec_lkeyp, "lkeyp" },
222
Olga Kornievskaia8d042212008-02-13 16:47:06 -0500223 { Opt_sec_spkm, "spkm3" },
224 { Opt_sec_spkmi, "spkm3i" },
225 { Opt_sec_spkmp, "spkm3p" },
226
Chuck Leverbf0fd762007-07-01 12:13:44 -0400227 { Opt_sec_err, NULL }
228};
229
Trond Myklebust7973c1f12008-07-15 17:58:14 -0400230enum {
231 Opt_lookupcache_all, Opt_lookupcache_positive,
232 Opt_lookupcache_none,
233
234 Opt_lookupcache_err
235};
236
237static match_table_t nfs_lookupcache_tokens = {
238 { Opt_lookupcache_all, "all" },
239 { Opt_lookupcache_positive, "pos" },
240 { Opt_lookupcache_positive, "positive" },
241 { Opt_lookupcache_none, "none" },
242
243 { Opt_lookupcache_err, NULL }
244};
245
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400246enum {
247 Opt_local_lock_all, Opt_local_lock_flock, Opt_local_lock_posix,
248 Opt_local_lock_none,
249
250 Opt_local_lock_err
251};
252
253static match_table_t nfs_local_lock_tokens = {
254 { Opt_local_lock_all, "all" },
255 { Opt_local_lock_flock, "flock" },
256 { Opt_local_lock_posix, "posix" },
257 { Opt_local_lock_none, "none" },
258
259 { Opt_local_lock_err, NULL }
260};
261
Chuck Leverbf0fd762007-07-01 12:13:44 -0400262
Al Viro42faad92008-04-24 07:21:56 -0400263static void nfs_umount_begin(struct super_block *);
Trond Myklebust816724e2006-06-24 08:41:41 -0400264static int nfs_statfs(struct dentry *, struct kstatfs *);
David Howellsf7b422b2006-06-09 09:34:33 -0400265static int nfs_show_options(struct seq_file *, struct vfsmount *);
Al Viroc7f404b2011-03-16 06:59:40 -0400266static int nfs_show_devname(struct seq_file *, struct vfsmount *);
267static int nfs_show_path(struct seq_file *, struct vfsmount *);
David Howellsf7b422b2006-06-09 09:34:33 -0400268static int nfs_show_stats(struct seq_file *, struct vfsmount *);
Al Viro01194982011-03-16 07:25:36 -0400269static struct dentry *nfs_fs_mount(struct file_system_type *,
270 int, const char *, void *);
Al Viro31f43472010-10-29 03:38:12 -0400271static struct dentry *nfs_xdev_mount(struct file_system_type *fs_type,
272 int flags, const char *dev_name, void *raw_data);
Trond Myklebust387c1492010-02-03 08:27:35 -0500273static void nfs_put_super(struct super_block *);
David Howellsf7b422b2006-06-09 09:34:33 -0400274static void nfs_kill_super(struct super_block *);
Jeff Layton48b605f2008-06-10 15:38:39 -0400275static int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
David Howellsf7b422b2006-06-09 09:34:33 -0400276
277static struct file_system_type nfs_fs_type = {
278 .owner = THIS_MODULE,
279 .name = "nfs",
Al Viro01194982011-03-16 07:25:36 -0400280 .mount = nfs_fs_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400281 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700282 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400283};
284
David Howells54ceac42006-08-22 20:06:13 -0400285struct file_system_type nfs_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400286 .owner = THIS_MODULE,
287 .name = "nfs",
Al Viro31f43472010-10-29 03:38:12 -0400288 .mount = nfs_xdev_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400289 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700290 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400291};
292
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800293static const struct super_operations nfs_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400294 .alloc_inode = nfs_alloc_inode,
295 .destroy_inode = nfs_destroy_inode,
296 .write_inode = nfs_write_inode,
Trond Myklebust387c1492010-02-03 08:27:35 -0500297 .put_super = nfs_put_super,
David Howellsf7b422b2006-06-09 09:34:33 -0400298 .statfs = nfs_statfs,
Al Virob57922d2010-06-07 14:34:48 -0400299 .evict_inode = nfs_evict_inode,
David Howellsf7b422b2006-06-09 09:34:33 -0400300 .umount_begin = nfs_umount_begin,
301 .show_options = nfs_show_options,
Al Viroc7f404b2011-03-16 06:59:40 -0400302 .show_devname = nfs_show_devname,
303 .show_path = nfs_show_path,
David Howellsf7b422b2006-06-09 09:34:33 -0400304 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400305 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400306};
307
308#ifdef CONFIG_NFS_V4
Chuck Lever7630c852009-09-08 19:49:57 -0400309static int nfs4_validate_text_mount_data(void *options,
310 struct nfs_parsed_mount_data *args, const char *dev_name);
Al Viro01194982011-03-16 07:25:36 -0400311static struct dentry *nfs4_try_mount(int flags, const char *dev_name,
312 struct nfs_parsed_mount_data *data);
313static struct dentry *nfs4_mount(struct file_system_type *fs_type,
314 int flags, const char *dev_name, void *raw_data);
Al Viro31f43472010-10-29 03:38:12 -0400315static struct dentry *nfs4_remote_mount(struct file_system_type *fs_type,
316 int flags, const char *dev_name, void *raw_data);
317static struct dentry *nfs4_xdev_mount(struct file_system_type *fs_type,
318 int flags, const char *dev_name, void *raw_data);
Al Viro01194982011-03-16 07:25:36 -0400319static struct dentry *nfs4_referral_mount(struct file_system_type *fs_type,
320 int flags, const char *dev_name, void *raw_data);
Al Viro31f43472010-10-29 03:38:12 -0400321static struct dentry *nfs4_remote_referral_mount(struct file_system_type *fs_type,
322 int flags, const char *dev_name, void *raw_data);
David Howellsf7b422b2006-06-09 09:34:33 -0400323static void nfs4_kill_super(struct super_block *sb);
324
325static struct file_system_type nfs4_fs_type = {
326 .owner = THIS_MODULE,
327 .name = "nfs4",
Al Viro01194982011-03-16 07:25:36 -0400328 .mount = nfs4_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400329 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700330 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400331};
332
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400333static struct file_system_type nfs4_remote_fs_type = {
334 .owner = THIS_MODULE,
335 .name = "nfs4",
Al Viro31f43472010-10-29 03:38:12 -0400336 .mount = nfs4_remote_mount,
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400337 .kill_sb = nfs4_kill_super,
338 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
339};
340
David Howells54ceac42006-08-22 20:06:13 -0400341struct file_system_type nfs4_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400342 .owner = THIS_MODULE,
343 .name = "nfs4",
Al Viro31f43472010-10-29 03:38:12 -0400344 .mount = nfs4_xdev_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400345 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700346 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400347};
348
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400349static struct file_system_type nfs4_remote_referral_fs_type = {
350 .owner = THIS_MODULE,
351 .name = "nfs4",
Al Viro31f43472010-10-29 03:38:12 -0400352 .mount = nfs4_remote_referral_mount,
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400353 .kill_sb = nfs4_kill_super,
354 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
355};
356
David Howells54ceac42006-08-22 20:06:13 -0400357struct file_system_type nfs4_referral_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400358 .owner = THIS_MODULE,
359 .name = "nfs4",
Al Viro01194982011-03-16 07:25:36 -0400360 .mount = nfs4_referral_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400361 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700362 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400363};
364
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800365static const struct super_operations nfs4_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400366 .alloc_inode = nfs_alloc_inode,
367 .destroy_inode = nfs_destroy_inode,
368 .write_inode = nfs_write_inode,
Trond Myklebust387c1492010-02-03 08:27:35 -0500369 .put_super = nfs_put_super,
David Howellsf7b422b2006-06-09 09:34:33 -0400370 .statfs = nfs_statfs,
Al Virob57922d2010-06-07 14:34:48 -0400371 .evict_inode = nfs4_evict_inode,
David Howellsf7b422b2006-06-09 09:34:33 -0400372 .umount_begin = nfs_umount_begin,
373 .show_options = nfs_show_options,
Al Viroc7f404b2011-03-16 06:59:40 -0400374 .show_devname = nfs_show_devname,
375 .show_path = nfs_show_path,
David Howellsf7b422b2006-06-09 09:34:33 -0400376 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400377 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400378};
379#endif
380
Rusty Russell8e1f9362007-07-17 04:03:17 -0700381static struct shrinker acl_shrinker = {
382 .shrink = nfs_access_cache_shrinker,
383 .seeks = DEFAULT_SEEKS,
384};
Trond Myklebust979df722006-07-25 11:28:19 -0400385
David Howellsf7b422b2006-06-09 09:34:33 -0400386/*
387 * Register the NFS filesystems
388 */
389int __init register_nfs_fs(void)
390{
391 int ret;
392
393 ret = register_filesystem(&nfs_fs_type);
394 if (ret < 0)
395 goto error_0;
396
David Howellsf7b422b2006-06-09 09:34:33 -0400397 ret = nfs_register_sysctl();
398 if (ret < 0)
399 goto error_1;
Peter Zijlstra89a09142007-03-16 13:38:26 -0800400#ifdef CONFIG_NFS_V4
David Howellsf7b422b2006-06-09 09:34:33 -0400401 ret = register_filesystem(&nfs4_fs_type);
402 if (ret < 0)
403 goto error_2;
404#endif
Rusty Russell8e1f9362007-07-17 04:03:17 -0700405 register_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400406 return 0;
407
408#ifdef CONFIG_NFS_V4
409error_2:
410 nfs_unregister_sysctl();
Peter Zijlstra89a09142007-03-16 13:38:26 -0800411#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400412error_1:
413 unregister_filesystem(&nfs_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400414error_0:
415 return ret;
416}
417
418/*
419 * Unregister the NFS filesystems
420 */
421void __exit unregister_nfs_fs(void)
422{
Rusty Russell8e1f9362007-07-17 04:03:17 -0700423 unregister_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400424#ifdef CONFIG_NFS_V4
425 unregister_filesystem(&nfs4_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400426#endif
Alexey Dobriyan49af7ee2007-09-18 22:46:40 -0700427 nfs_unregister_sysctl();
David Howellsf7b422b2006-06-09 09:34:33 -0400428 unregister_filesystem(&nfs_fs_type);
429}
430
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400431void nfs_sb_active(struct super_block *sb)
Steve Dicksonef818a22007-11-08 04:05:04 -0500432{
433 struct nfs_server *server = NFS_SB(sb);
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400434
435 if (atomic_inc_return(&server->active) == 1)
436 atomic_inc(&sb->s_active);
437}
438
439void nfs_sb_deactive(struct super_block *sb)
440{
441 struct nfs_server *server = NFS_SB(sb);
442
443 if (atomic_dec_and_test(&server->active))
444 deactivate_super(sb);
Steve Dicksonef818a22007-11-08 04:05:04 -0500445}
446
David Howellsf7b422b2006-06-09 09:34:33 -0400447/*
448 * Deliver file system statistics to userspace
449 */
Trond Myklebust816724e2006-06-24 08:41:41 -0400450static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
David Howellsf7b422b2006-06-09 09:34:33 -0400451{
David Howells0c7d90c2006-08-22 20:06:10 -0400452 struct nfs_server *server = NFS_SB(dentry->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400453 unsigned char blockbits;
454 unsigned long blockres;
David Howells0c7d90c2006-08-22 20:06:10 -0400455 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400456 struct nfs_fsstat res;
457 int error = -ENOMEM;
458
459 res.fattr = nfs_alloc_fattr();
460 if (res.fattr == NULL)
461 goto out_err;
David Howellsf7b422b2006-06-09 09:34:33 -0400462
David Howells8fa5c002006-08-22 20:06:12 -0400463 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
Menyhart Zoltanfbf3fdd2010-09-12 19:55:26 -0400464 if (unlikely(error == -ESTALE)) {
465 struct dentry *pd_dentry;
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400466
Menyhart Zoltanfbf3fdd2010-09-12 19:55:26 -0400467 pd_dentry = dget_parent(dentry);
468 if (pd_dentry != NULL) {
469 nfs_zap_caches(pd_dentry->d_inode);
470 dput(pd_dentry);
471 }
472 }
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400473 nfs_free_fattr(res.fattr);
David Howellsf7b422b2006-06-09 09:34:33 -0400474 if (error < 0)
475 goto out_err;
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400476
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700477 buf->f_type = NFS_SUPER_MAGIC;
David Howellsf7b422b2006-06-09 09:34:33 -0400478
479 /*
480 * Current versions of glibc do not correctly handle the
481 * case where f_frsize != f_bsize. Eventually we want to
482 * report the value of wtmult in this field.
483 */
David Howells0c7d90c2006-08-22 20:06:10 -0400484 buf->f_frsize = dentry->d_sb->s_blocksize;
David Howellsf7b422b2006-06-09 09:34:33 -0400485
486 /*
487 * On most *nix systems, f_blocks, f_bfree, and f_bavail
488 * are reported in units of f_frsize. Linux hasn't had
489 * an f_frsize field in its statfs struct until recently,
490 * thus historically Linux's sys_statfs reports these
491 * fields in units of f_bsize.
492 */
David Howells0c7d90c2006-08-22 20:06:10 -0400493 buf->f_bsize = dentry->d_sb->s_blocksize;
494 blockbits = dentry->d_sb->s_blocksize_bits;
David Howellsf7b422b2006-06-09 09:34:33 -0400495 blockres = (1 << blockbits) - 1;
496 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
497 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
498 buf->f_bavail = (res.abytes + blockres) >> blockbits;
499
500 buf->f_files = res.tfiles;
501 buf->f_ffree = res.afiles;
502
503 buf->f_namelen = server->namelen;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700504
David Howellsf7b422b2006-06-09 09:34:33 -0400505 return 0;
506
507 out_err:
Harvey Harrison3110ff82008-05-02 13:42:44 -0700508 dprintk("%s: statfs error = %d\n", __func__, -error);
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700509 return error;
David Howellsf7b422b2006-06-09 09:34:33 -0400510}
511
David Howells7d4e2742006-08-22 20:06:07 -0400512/*
513 * Map the security flavour number to a name
514 */
Trond Myklebust81039f12006-06-09 09:34:34 -0400515static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
516{
David Howells7d4e2742006-08-22 20:06:07 -0400517 static const struct {
Trond Myklebust81039f12006-06-09 09:34:34 -0400518 rpc_authflavor_t flavour;
519 const char *str;
520 } sec_flavours[] = {
521 { RPC_AUTH_NULL, "null" },
522 { RPC_AUTH_UNIX, "sys" },
523 { RPC_AUTH_GSS_KRB5, "krb5" },
524 { RPC_AUTH_GSS_KRB5I, "krb5i" },
525 { RPC_AUTH_GSS_KRB5P, "krb5p" },
526 { RPC_AUTH_GSS_LKEY, "lkey" },
527 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
528 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
529 { RPC_AUTH_GSS_SPKM, "spkm" },
530 { RPC_AUTH_GSS_SPKMI, "spkmi" },
531 { RPC_AUTH_GSS_SPKMP, "spkmp" },
Chuck Lever4d81cd12007-07-01 12:12:40 -0400532 { UINT_MAX, "unknown" }
Trond Myklebust81039f12006-06-09 09:34:34 -0400533 };
534 int i;
535
Chuck Lever4d81cd12007-07-01 12:12:40 -0400536 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
Trond Myklebust81039f12006-06-09 09:34:34 -0400537 if (sec_flavours[i].flavour == flavour)
538 break;
539 }
540 return sec_flavours[i].str;
541}
542
Jeff Laytonee671b02009-12-03 15:58:56 -0500543static void nfs_show_mountd_netid(struct seq_file *m, struct nfs_server *nfss,
544 int showdefaults)
545{
546 struct sockaddr *sap = (struct sockaddr *) &nfss->mountd_address;
547
548 seq_printf(m, ",mountproto=");
549 switch (sap->sa_family) {
550 case AF_INET:
551 switch (nfss->mountd_protocol) {
552 case IPPROTO_UDP:
553 seq_printf(m, RPCBIND_NETID_UDP);
554 break;
555 case IPPROTO_TCP:
556 seq_printf(m, RPCBIND_NETID_TCP);
557 break;
558 default:
559 if (showdefaults)
560 seq_printf(m, "auto");
561 }
562 break;
563 case AF_INET6:
564 switch (nfss->mountd_protocol) {
565 case IPPROTO_UDP:
566 seq_printf(m, RPCBIND_NETID_UDP6);
567 break;
568 case IPPROTO_TCP:
569 seq_printf(m, RPCBIND_NETID_TCP6);
570 break;
571 default:
572 if (showdefaults)
573 seq_printf(m, "auto");
574 }
575 break;
576 default:
577 if (showdefaults)
578 seq_printf(m, "auto");
579 }
580}
581
Chuck Lever82d101d2008-03-14 14:10:37 -0400582static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
583 int showdefaults)
584{
585 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
586
Bryan Schumakerd5eff1a2010-08-03 13:04:00 -0400587 if (nfss->flags & NFS_MOUNT_LEGACY_INTERFACE)
588 return;
589
Chuck Lever82d101d2008-03-14 14:10:37 -0400590 switch (sap->sa_family) {
591 case AF_INET: {
592 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
Harvey Harrisonbe859402008-10-31 00:56:28 -0700593 seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400594 break;
595 }
596 case AF_INET6: {
597 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
Chuck Leverd250e192009-12-03 15:58:56 -0500598 seq_printf(m, ",mountaddr=%pI6c", &sin6->sin6_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400599 break;
600 }
601 default:
602 if (showdefaults)
603 seq_printf(m, ",mountaddr=unspecified");
604 }
605
606 if (nfss->mountd_version || showdefaults)
607 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
Stanislav Kinsburskyaa699472010-12-08 12:40:13 +0300608 if ((nfss->mountd_port &&
609 nfss->mountd_port != (unsigned short)NFS_UNSPEC_PORT) ||
610 showdefaults)
Chuck Lever82d101d2008-03-14 14:10:37 -0400611 seq_printf(m, ",mountport=%u", nfss->mountd_port);
612
Jeff Laytonee671b02009-12-03 15:58:56 -0500613 nfs_show_mountd_netid(m, nfss, showdefaults);
Chuck Lever82d101d2008-03-14 14:10:37 -0400614}
615
Trond Myklebust0be81892010-06-18 12:23:58 -0400616#ifdef CONFIG_NFS_V4
617static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
618 int showdefaults)
619{
620 struct nfs_client *clp = nfss->nfs_client;
621
622 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
623 seq_printf(m, ",minorversion=%u", clp->cl_minorversion);
624}
625#else
626static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
627 int showdefaults)
628{
629}
630#endif
631
David Howellsf7b422b2006-06-09 09:34:33 -0400632/*
633 * Describe the mount options in force on this server representation
634 */
Chuck Lever82d101d2008-03-14 14:10:37 -0400635static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
636 int showdefaults)
David Howellsf7b422b2006-06-09 09:34:33 -0400637{
David Howells509de812006-08-22 20:06:11 -0400638 static const struct proc_nfs_info {
David Howellsf7b422b2006-06-09 09:34:33 -0400639 int flag;
David Howells509de812006-08-22 20:06:11 -0400640 const char *str;
641 const char *nostr;
David Howellsf7b422b2006-06-09 09:34:33 -0400642 } nfs_info[] = {
643 { NFS_MOUNT_SOFT, ",soft", ",hard" },
Chuck Lever82d101d2008-03-14 14:10:37 -0400644 { NFS_MOUNT_POSIX, ",posix", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400645 { NFS_MOUNT_NOCTO, ",nocto", "" },
646 { NFS_MOUNT_NOAC, ",noac", "" },
647 { NFS_MOUNT_NONLM, ",nolock", "" },
648 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400649 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
Chuck Leverd7403512008-12-23 15:21:37 -0500650 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
651 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400652 { 0, NULL, NULL }
653 };
David Howells509de812006-08-22 20:06:11 -0400654 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400655 struct nfs_client *clp = nfss->nfs_client;
Chuck Lever82d101d2008-03-14 14:10:37 -0400656 u32 version = clp->rpc_ops->version;
Suresh Jayaraman7c563cc2010-09-23 14:26:48 -0400657 int local_flock, local_fcntl;
David Howellsf7b422b2006-06-09 09:34:33 -0400658
Chuck Lever82d101d2008-03-14 14:10:37 -0400659 seq_printf(m, ",vers=%u", version);
Chuck Lever2d767432008-03-14 14:10:08 -0400660 seq_printf(m, ",rsize=%u", nfss->rsize);
661 seq_printf(m, ",wsize=%u", nfss->wsize);
Chuck Lever82d101d2008-03-14 14:10:37 -0400662 if (nfss->bsize != 0)
663 seq_printf(m, ",bsize=%u", nfss->bsize);
664 seq_printf(m, ",namlen=%u", nfss->namelen);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400665 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400666 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400667 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400668 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400669 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400670 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400671 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400672 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
David Howellsf7b422b2006-06-09 09:34:33 -0400673 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
674 if (nfss->flags & nfs_infop->flag)
675 seq_puts(m, nfs_infop->str);
676 else
677 seq_puts(m, nfs_infop->nostr);
678 }
\"Talpey, Thomas\56928ed2007-09-10 13:48:47 -0400679 seq_printf(m, ",proto=%s",
Jeff Laytonee671b02009-12-03 15:58:56 -0500680 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
Chuck Lever82d101d2008-03-14 14:10:37 -0400681 if (version == 4) {
682 if (nfss->port != NFS_PORT)
683 seq_printf(m, ",port=%u", nfss->port);
684 } else
685 if (nfss->port)
686 seq_printf(m, ",port=%u", nfss->port);
687
Trond Myklebust33170232007-12-20 16:03:59 -0500688 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
689 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
Trond Myklebust81039f12006-06-09 09:34:34 -0400690 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
Chuck Lever82d101d2008-03-14 14:10:37 -0400691
692 if (version != 4)
693 nfs_show_mountd_options(m, nfss, showdefaults);
Trond Myklebust0be81892010-06-18 12:23:58 -0400694 else
695 nfs_show_nfsv4_options(m, nfss, showdefaults);
Chuck Lever82d101d2008-03-14 14:10:37 -0400696
David Howellsb797cac2009-04-03 16:42:48 +0100697 if (nfss->options & NFS_OPTION_FSCACHE)
698 seq_printf(m, ",fsc");
Patrick J. LoPresti9b00c642010-08-10 17:28:01 -0400699
700 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONEG) {
701 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONE)
702 seq_printf(m, ",lookupcache=none");
703 else
704 seq_printf(m, ",lookupcache=pos");
705 }
Suresh Jayaraman7c563cc2010-09-23 14:26:48 -0400706
707 local_flock = nfss->flags & NFS_MOUNT_LOCAL_FLOCK;
708 local_fcntl = nfss->flags & NFS_MOUNT_LOCAL_FCNTL;
709
710 if (!local_flock && !local_fcntl)
711 seq_printf(m, ",local_lock=none");
712 else if (local_flock && local_fcntl)
713 seq_printf(m, ",local_lock=all");
714 else if (local_flock)
715 seq_printf(m, ",local_lock=flock");
716 else
717 seq_printf(m, ",local_lock=posix");
David Howellsf7b422b2006-06-09 09:34:33 -0400718}
719
720/*
721 * Describe the mount options on this VFS mountpoint
722 */
723static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
724{
725 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
726
727 nfs_show_mount_options(m, nfss, 0);
728
Chuck Lever5d8515c2007-12-10 14:57:16 -0500729 seq_printf(m, ",addr=%s",
730 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
731 RPC_DISPLAY_ADDR));
David Howellsf7b422b2006-06-09 09:34:33 -0400732
733 return 0;
734}
735
Al Viroc7f404b2011-03-16 06:59:40 -0400736static int nfs_show_devname(struct seq_file *m, struct vfsmount *mnt)
737{
738 char *page = (char *) __get_free_page(GFP_KERNEL);
739 char *devname, *dummy;
740 int err = 0;
741 if (!page)
742 return -ENOMEM;
743 devname = nfs_path(&dummy, mnt->mnt_root, page, PAGE_SIZE);
744 if (IS_ERR(devname))
745 err = PTR_ERR(devname);
746 else
747 seq_escape(m, devname, " \t\n\\");
748 free_page((unsigned long)page);
749 return err;
750}
751
752static int nfs_show_path(struct seq_file *m, struct vfsmount *mnt)
753{
754 seq_puts(m, "/");
755 return 0;
756}
757
David Howellsf7b422b2006-06-09 09:34:33 -0400758/*
759 * Present statistical information for this VFS mountpoint
760 */
761static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
762{
763 int i, cpu;
764 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
765 struct rpc_auth *auth = nfss->client->cl_auth;
766 struct nfs_iostats totals = { };
767
768 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
769
770 /*
771 * Display all mount option settings
772 */
773 seq_printf(m, "\n\topts:\t");
774 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
775 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
776 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
777 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
778 nfs_show_mount_options(m, nfss, 1);
779
780 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
781
782 seq_printf(m, "\n\tcaps:\t");
783 seq_printf(m, "caps=0x%x", nfss->caps);
Chuck Lever2d767432008-03-14 14:10:08 -0400784 seq_printf(m, ",wtmult=%u", nfss->wtmult);
785 seq_printf(m, ",dtsize=%u", nfss->dtsize);
786 seq_printf(m, ",bsize=%u", nfss->bsize);
787 seq_printf(m, ",namlen=%u", nfss->namelen);
David Howellsf7b422b2006-06-09 09:34:33 -0400788
789#ifdef CONFIG_NFS_V4
Trond Myklebust40c553192007-12-14 14:56:07 -0500790 if (nfss->nfs_client->rpc_ops->version == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400791 seq_printf(m, "\n\tnfsv4:\t");
792 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
793 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
794 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
795 }
796#endif
797
798 /*
799 * Display security flavor in effect for this mount
800 */
Chuck Lever2d767432008-03-14 14:10:08 -0400801 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400802 if (auth->au_flavor)
Chuck Lever2d767432008-03-14 14:10:08 -0400803 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400804
805 /*
806 * Display superblock I/O counters
807 */
808 for_each_possible_cpu(cpu) {
809 struct nfs_iostats *stats;
810
811 preempt_disable();
812 stats = per_cpu_ptr(nfss->io_stats, cpu);
813
814 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
815 totals.events[i] += stats->events[i];
816 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
817 totals.bytes[i] += stats->bytes[i];
David Howells6a510912009-04-03 16:42:43 +0100818#ifdef CONFIG_NFS_FSCACHE
819 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
820 totals.fscache[i] += stats->fscache[i];
821#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400822
823 preempt_enable();
824 }
825
826 seq_printf(m, "\n\tevents:\t");
827 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
828 seq_printf(m, "%lu ", totals.events[i]);
829 seq_printf(m, "\n\tbytes:\t");
830 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
831 seq_printf(m, "%Lu ", totals.bytes[i]);
David Howells6a510912009-04-03 16:42:43 +0100832#ifdef CONFIG_NFS_FSCACHE
833 if (nfss->options & NFS_OPTION_FSCACHE) {
834 seq_printf(m, "\n\tfsc:\t");
835 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
836 seq_printf(m, "%Lu ", totals.bytes[i]);
837 }
838#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400839 seq_printf(m, "\n");
840
841 rpc_print_iostats(m, nfss->client);
842
843 return 0;
844}
845
846/*
847 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400848 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400849 */
Al Viro42faad92008-04-24 07:21:56 -0400850static void nfs_umount_begin(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -0400851{
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200852 struct nfs_server *server;
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400853 struct rpc_clnt *rpc;
854
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200855 server = NFS_SB(sb);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400856 /* -EIO all pending I/O */
857 rpc = server->client_acl;
858 if (!IS_ERR(rpc))
859 rpc_killall_tasks(rpc);
860 rpc = server->client;
861 if (!IS_ERR(rpc))
862 rpc_killall_tasks(rpc);
David Howellsf7b422b2006-06-09 09:34:33 -0400863}
864
Trond Myklebustc5811db2009-10-06 15:40:15 -0400865static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(unsigned int version)
Chuck Lever9423a082009-09-23 14:36:38 -0400866{
867 struct nfs_parsed_mount_data *data;
868
869 data = kzalloc(sizeof(*data), GFP_KERNEL);
870 if (data) {
Chuck Lever9423a082009-09-23 14:36:38 -0400871 data->acregmin = NFS_DEF_ACREGMIN;
872 data->acregmax = NFS_DEF_ACREGMAX;
873 data->acdirmin = NFS_DEF_ACDIRMIN;
874 data->acdirmax = NFS_DEF_ACDIRMAX;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400875 data->mount_server.port = NFS_UNSPEC_PORT;
Chuck Lever9423a082009-09-23 14:36:38 -0400876 data->nfs_server.port = NFS_UNSPEC_PORT;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400877 data->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Lever9423a082009-09-23 14:36:38 -0400878 data->auth_flavors[0] = RPC_AUTH_UNIX;
879 data->auth_flavor_len = 1;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400880 data->version = version;
Chuck Lever9423a082009-09-23 14:36:38 -0400881 data->minorversion = 0;
882 }
883 return data;
884}
885
David Howellsf7b422b2006-06-09 09:34:33 -0400886/*
Chuck Levercdcd7f92007-12-10 14:57:45 -0500887 * Sanity-check a server address provided by the mount command.
888 *
889 * Address family must be initialized, and address must not be
890 * the ANY address for that family.
Chuck Leverfc50d582007-07-01 12:12:46 -0400891 */
892static int nfs_verify_server_address(struct sockaddr *addr)
893{
894 switch (addr->sa_family) {
895 case AF_INET: {
Chuck Levercdcd7f92007-12-10 14:57:45 -0500896 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
Al Viroe6f1ceb2008-03-17 22:44:53 -0700897 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
Chuck Levercdcd7f92007-12-10 14:57:45 -0500898 }
899 case AF_INET6: {
900 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
901 return !ipv6_addr_any(sa);
Chuck Leverfc50d582007-07-01 12:12:46 -0400902 }
903 }
904
Chuck Lever53a0b9c2009-08-09 15:09:36 -0400905 dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
Chuck Leverfc50d582007-07-01 12:12:46 -0400906 return 0;
907}
908
Chuck Lever9412b922007-12-10 14:59:21 -0500909/*
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400910 * Select between a default port value and a user-specified port value.
911 * If a zero value is set, then autobind will be used.
912 */
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400913static void nfs_set_port(struct sockaddr *sap, int *port,
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400914 const unsigned short default_port)
915{
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400916 if (*port == NFS_UNSPEC_PORT)
917 *port = default_port;
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400918
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400919 rpc_set_port(sap, *port);
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400920}
921
922/*
Trond Myklebust259875e2008-07-02 14:43:47 -0400923 * Sanity check the NFS transport protocol.
924 *
925 */
926static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
927{
928 switch (mnt->nfs_server.protocol) {
929 case XPRT_TRANSPORT_UDP:
930 case XPRT_TRANSPORT_TCP:
931 case XPRT_TRANSPORT_RDMA:
932 break;
933 default:
934 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
935 }
936}
937
938/*
939 * For text based NFSv2/v3 mounts, the mount protocol transport default
940 * settings should depend upon the specified NFS transport.
941 */
942static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
943{
944 nfs_validate_transport_protocol(mnt);
945
946 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
947 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
948 return;
949 switch (mnt->nfs_server.protocol) {
950 case XPRT_TRANSPORT_UDP:
951 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
952 break;
953 case XPRT_TRANSPORT_TCP:
954 case XPRT_TRANSPORT_RDMA:
955 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
956 }
957}
958
959/*
Chuck Lever01060c82008-06-24 16:33:38 -0400960 * Parse the value of the 'sec=' option.
Chuck Lever01060c82008-06-24 16:33:38 -0400961 */
962static int nfs_parse_security_flavors(char *value,
963 struct nfs_parsed_mount_data *mnt)
964{
965 substring_t args[MAX_OPT_ARGS];
966
967 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
968
969 switch (match_token(value, nfs_secflavor_tokens, args)) {
970 case Opt_sec_none:
Chuck Lever01060c82008-06-24 16:33:38 -0400971 mnt->auth_flavors[0] = RPC_AUTH_NULL;
972 break;
973 case Opt_sec_sys:
Chuck Lever01060c82008-06-24 16:33:38 -0400974 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
975 break;
976 case Opt_sec_krb5:
Chuck Lever01060c82008-06-24 16:33:38 -0400977 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
978 break;
979 case Opt_sec_krb5i:
Chuck Lever01060c82008-06-24 16:33:38 -0400980 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
981 break;
982 case Opt_sec_krb5p:
Chuck Lever01060c82008-06-24 16:33:38 -0400983 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
984 break;
985 case Opt_sec_lkey:
Chuck Lever01060c82008-06-24 16:33:38 -0400986 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
987 break;
988 case Opt_sec_lkeyi:
Chuck Lever01060c82008-06-24 16:33:38 -0400989 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
990 break;
991 case Opt_sec_lkeyp:
Chuck Lever01060c82008-06-24 16:33:38 -0400992 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
993 break;
994 case Opt_sec_spkm:
Chuck Lever01060c82008-06-24 16:33:38 -0400995 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
996 break;
997 case Opt_sec_spkmi:
Chuck Lever01060c82008-06-24 16:33:38 -0400998 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
999 break;
1000 case Opt_sec_spkmp:
Chuck Lever01060c82008-06-24 16:33:38 -04001001 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
1002 break;
1003 default:
1004 return 0;
1005 }
1006
Chuck Lever059f90b2009-08-09 15:09:31 -04001007 mnt->auth_flavor_len = 1;
Chuck Lever01060c82008-06-24 16:33:38 -04001008 return 1;
1009}
1010
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001011static int nfs_get_option_str(substring_t args[], char **option)
1012{
1013 kfree(*option);
1014 *option = match_strdup(args);
1015 return !option;
1016}
1017
1018static int nfs_get_option_ul(substring_t args[], unsigned long *option)
1019{
1020 int rc;
1021 char *string;
1022
1023 string = match_strdup(args);
1024 if (string == NULL)
1025 return -ENOMEM;
1026 rc = strict_strtoul(string, 10, option);
1027 kfree(string);
1028
1029 return rc;
1030}
1031
Chuck Lever01060c82008-06-24 16:33:38 -04001032/*
Chuck Leverbf0fd762007-07-01 12:13:44 -04001033 * Error-check and convert a string of mount options from user space into
Chuck Leverf45663c2008-06-24 19:28:02 -04001034 * a data structure. The whole mount string is processed; bad options are
1035 * skipped as they are encountered. If there were no errors, return 1;
1036 * otherwise return 0 (zero).
Chuck Leverbf0fd762007-07-01 12:13:44 -04001037 */
1038static int nfs_parse_mount_options(char *raw,
1039 struct nfs_parsed_mount_data *mnt)
1040{
Eric Parisf9c3a382008-03-05 14:20:18 -05001041 char *p, *string, *secdata;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001042 int rc, sloppy = 0, invalid_option = 0;
Jeff Laytonee671b02009-12-03 15:58:56 -05001043 unsigned short protofamily = AF_UNSPEC;
1044 unsigned short mountfamily = AF_UNSPEC;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001045
1046 if (!raw) {
1047 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
1048 return 1;
1049 }
1050 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
1051
Eric Parisf9c3a382008-03-05 14:20:18 -05001052 secdata = alloc_secdata();
1053 if (!secdata)
1054 goto out_nomem;
1055
1056 rc = security_sb_copy_data(raw, secdata);
1057 if (rc)
1058 goto out_security_failure;
1059
1060 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
1061 if (rc)
1062 goto out_security_failure;
1063
1064 free_secdata(secdata);
1065
Chuck Leverbf0fd762007-07-01 12:13:44 -04001066 while ((p = strsep(&raw, ",")) != NULL) {
1067 substring_t args[MAX_OPT_ARGS];
Chuck Levera5a16ba2009-06-17 18:02:14 -07001068 unsigned long option;
1069 int token;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001070
1071 if (!*p)
1072 continue;
1073
1074 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
1075
1076 token = match_token(p, nfs_mount_option_tokens, args);
1077 switch (token) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001078
1079 /*
1080 * boolean options: foo/nofoo
1081 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001082 case Opt_soft:
1083 mnt->flags |= NFS_MOUNT_SOFT;
1084 break;
1085 case Opt_hard:
1086 mnt->flags &= ~NFS_MOUNT_SOFT;
1087 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001088 case Opt_posix:
1089 mnt->flags |= NFS_MOUNT_POSIX;
1090 break;
1091 case Opt_noposix:
1092 mnt->flags &= ~NFS_MOUNT_POSIX;
1093 break;
1094 case Opt_cto:
1095 mnt->flags &= ~NFS_MOUNT_NOCTO;
1096 break;
1097 case Opt_nocto:
1098 mnt->flags |= NFS_MOUNT_NOCTO;
1099 break;
1100 case Opt_ac:
1101 mnt->flags &= ~NFS_MOUNT_NOAC;
1102 break;
1103 case Opt_noac:
1104 mnt->flags |= NFS_MOUNT_NOAC;
1105 break;
1106 case Opt_lock:
1107 mnt->flags &= ~NFS_MOUNT_NONLM;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001108 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1109 NFS_MOUNT_LOCAL_FCNTL);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001110 break;
1111 case Opt_nolock:
1112 mnt->flags |= NFS_MOUNT_NONLM;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001113 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1114 NFS_MOUNT_LOCAL_FCNTL);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001115 break;
1116 case Opt_v2:
1117 mnt->flags &= ~NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -04001118 mnt->version = 2;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001119 break;
1120 case Opt_v3:
1121 mnt->flags |= NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -04001122 mnt->version = 3;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001123 break;
Chuck Lever764302c2009-09-08 19:50:03 -04001124 case Opt_v4:
1125 mnt->flags &= ~NFS_MOUNT_VER3;
1126 mnt->version = 4;
1127 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001128 case Opt_udp:
1129 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001130 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001131 break;
1132 case Opt_tcp:
1133 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001134 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001135 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001136 case Opt_rdma:
1137 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1138 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001139 xprt_load_transport(p);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001140 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001141 case Opt_acl:
1142 mnt->flags &= ~NFS_MOUNT_NOACL;
1143 break;
1144 case Opt_noacl:
1145 mnt->flags |= NFS_MOUNT_NOACL;
1146 break;
1147 case Opt_rdirplus:
1148 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1149 break;
1150 case Opt_nordirplus:
1151 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1152 break;
Trond Myklebust75180df2007-05-16 16:53:28 -04001153 case Opt_sharecache:
1154 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1155 break;
1156 case Opt_nosharecache:
1157 mnt->flags |= NFS_MOUNT_UNSHARED;
1158 break;
Chuck Leverd7403512008-12-23 15:21:37 -05001159 case Opt_resvport:
1160 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1161 break;
1162 case Opt_noresvport:
1163 mnt->flags |= NFS_MOUNT_NORESVPORT;
1164 break;
David Howellsb797cac2009-04-03 16:42:48 +01001165 case Opt_fscache:
1166 mnt->options |= NFS_OPTION_FSCACHE;
1167 kfree(mnt->fscache_uniq);
1168 mnt->fscache_uniq = NULL;
1169 break;
1170 case Opt_nofscache:
1171 mnt->options &= ~NFS_OPTION_FSCACHE;
1172 kfree(mnt->fscache_uniq);
1173 mnt->fscache_uniq = NULL;
1174 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001175
Chuck Leverf45663c2008-06-24 19:28:02 -04001176 /*
1177 * options that take numeric values
1178 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001179 case Opt_port:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001180 if (nfs_get_option_ul(args, &option) ||
1181 option > USHRT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001182 goto out_invalid_value;
1183 mnt->nfs_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001184 break;
1185 case Opt_rsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001186 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001187 goto out_invalid_value;
1188 mnt->rsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001189 break;
1190 case Opt_wsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001191 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001192 goto out_invalid_value;
1193 mnt->wsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001194 break;
1195 case Opt_bsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001196 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001197 goto out_invalid_value;
1198 mnt->bsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001199 break;
1200 case Opt_timeo:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001201 if (nfs_get_option_ul(args, &option) || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001202 goto out_invalid_value;
1203 mnt->timeo = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001204 break;
1205 case Opt_retrans:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001206 if (nfs_get_option_ul(args, &option) || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001207 goto out_invalid_value;
1208 mnt->retrans = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001209 break;
1210 case Opt_acregmin:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001211 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001212 goto out_invalid_value;
1213 mnt->acregmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001214 break;
1215 case Opt_acregmax:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001216 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001217 goto out_invalid_value;
1218 mnt->acregmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001219 break;
1220 case Opt_acdirmin:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001221 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001222 goto out_invalid_value;
1223 mnt->acdirmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001224 break;
1225 case Opt_acdirmax:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001226 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001227 goto out_invalid_value;
1228 mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001229 break;
1230 case Opt_actimeo:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001231 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001232 goto out_invalid_value;
1233 mnt->acregmin = mnt->acregmax =
1234 mnt->acdirmin = mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001235 break;
1236 case Opt_namelen:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001237 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001238 goto out_invalid_value;
1239 mnt->namlen = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001240 break;
1241 case Opt_mountport:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001242 if (nfs_get_option_ul(args, &option) ||
1243 option > USHRT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001244 goto out_invalid_value;
1245 mnt->mount_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001246 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001247 case Opt_mountvers:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001248 if (nfs_get_option_ul(args, &option) ||
Chuck Leverf45663c2008-06-24 19:28:02 -04001249 option < NFS_MNT_VERSION ||
Chuck Leverd23c45f2009-06-17 18:02:13 -07001250 option > NFS_MNT3_VERSION)
1251 goto out_invalid_value;
1252 mnt->mount_server.version = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001253 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001254 case Opt_nfsvers:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001255 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001256 goto out_invalid_value;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001257 switch (option) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001258 case NFS2_VERSION:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001259 mnt->flags &= ~NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -04001260 mnt->version = 2;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001261 break;
Chuck Leverf45663c2008-06-24 19:28:02 -04001262 case NFS3_VERSION:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001263 mnt->flags |= NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -04001264 mnt->version = 3;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001265 break;
Chuck Lever764302c2009-09-08 19:50:03 -04001266 case NFS4_VERSION:
1267 mnt->flags &= ~NFS_MOUNT_VER3;
1268 mnt->version = 4;
1269 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001270 default:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001271 goto out_invalid_value;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001272 }
1273 break;
Mike Sager3fd5be92009-04-01 09:21:48 -04001274 case Opt_minorversion:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001275 if (nfs_get_option_ul(args, &option))
Chuck Leverf3f4f4e2009-08-09 15:09:29 -04001276 goto out_invalid_value;
1277 if (option > NFS4_MAX_MINOR_VERSION)
1278 goto out_invalid_value;
1279 mnt->minorversion = option;
Mike Sager3fd5be92009-04-01 09:21:48 -04001280 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001281
Chuck Leverf45663c2008-06-24 19:28:02 -04001282 /*
1283 * options that take text values
1284 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001285 case Opt_sec:
1286 string = match_strdup(args);
1287 if (string == NULL)
1288 goto out_nomem;
Chuck Lever01060c82008-06-24 16:33:38 -04001289 rc = nfs_parse_security_flavors(string, mnt);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001290 kfree(string);
Chuck Leverf45663c2008-06-24 19:28:02 -04001291 if (!rc) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001292 dfprintk(MOUNT, "NFS: unrecognized "
1293 "security flavor\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001294 return 0;
Chuck Leverf45663c2008-06-24 19:28:02 -04001295 }
Chuck Leverbf0fd762007-07-01 12:13:44 -04001296 break;
1297 case Opt_proto:
1298 string = match_strdup(args);
1299 if (string == NULL)
1300 goto out_nomem;
1301 token = match_token(string,
1302 nfs_xprt_protocol_tokens, args);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001303
Jeff Laytonee671b02009-12-03 15:58:56 -05001304 protofamily = AF_INET;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001305 switch (token) {
Jeff Laytonee671b02009-12-03 15:58:56 -05001306 case Opt_xprt_udp6:
1307 protofamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001308 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001309 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001310 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001311 break;
Jeff Laytonee671b02009-12-03 15:58:56 -05001312 case Opt_xprt_tcp6:
1313 protofamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001314 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001315 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001316 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001317 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001318 case Opt_xprt_rdma:
1319 /* vector side protocols to TCP */
1320 mnt->flags |= NFS_MOUNT_TCP;
1321 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001322 xprt_load_transport(string);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001323 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001324 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001325 dfprintk(MOUNT, "NFS: unrecognized "
1326 "transport protocol\n");
Yinghai Lu4223a4a2009-10-20 14:13:46 +09001327 kfree(string);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001328 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001329 }
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001330 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001331 break;
1332 case Opt_mountproto:
1333 string = match_strdup(args);
1334 if (string == NULL)
1335 goto out_nomem;
1336 token = match_token(string,
1337 nfs_xprt_protocol_tokens, args);
Trond Myklebustd508afb2009-04-06 16:41:35 -07001338 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001339
Jeff Laytonee671b02009-12-03 15:58:56 -05001340 mountfamily = AF_INET;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001341 switch (token) {
Jeff Laytonee671b02009-12-03 15:58:56 -05001342 case Opt_xprt_udp6:
1343 mountfamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001344 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001345 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001346 break;
Jeff Laytonee671b02009-12-03 15:58:56 -05001347 case Opt_xprt_tcp6:
1348 mountfamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001349 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001350 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001351 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001352 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001353 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001354 dfprintk(MOUNT, "NFS: unrecognized "
1355 "transport protocol\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001356 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001357 }
1358 break;
1359 case Opt_addr:
1360 string = match_strdup(args);
1361 if (string == NULL)
1362 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001363 mnt->nfs_server.addrlen =
1364 rpc_pton(string, strlen(string),
1365 (struct sockaddr *)
1366 &mnt->nfs_server.address,
1367 sizeof(mnt->nfs_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001368 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001369 if (mnt->nfs_server.addrlen == 0)
1370 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001371 break;
1372 case Opt_clientaddr:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001373 if (nfs_get_option_str(args, &mnt->client_address))
Chuck Leverbf0fd762007-07-01 12:13:44 -04001374 goto out_nomem;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001375 break;
Chuck Lever33832032007-12-10 14:59:13 -05001376 case Opt_mounthost:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001377 if (nfs_get_option_str(args,
1378 &mnt->mount_server.hostname))
Chuck Lever33832032007-12-10 14:59:13 -05001379 goto out_nomem;
Chuck Lever33832032007-12-10 14:59:13 -05001380 break;
Chuck Lever0ac83772007-09-11 18:01:04 -04001381 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001382 string = match_strdup(args);
1383 if (string == NULL)
1384 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001385 mnt->mount_server.addrlen =
1386 rpc_pton(string, strlen(string),
1387 (struct sockaddr *)
1388 &mnt->mount_server.address,
1389 sizeof(mnt->mount_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001390 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001391 if (mnt->mount_server.addrlen == 0)
1392 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001393 break;
Trond Myklebust7973c1f12008-07-15 17:58:14 -04001394 case Opt_lookupcache:
1395 string = match_strdup(args);
1396 if (string == NULL)
1397 goto out_nomem;
1398 token = match_token(string,
1399 nfs_lookupcache_tokens, args);
1400 kfree(string);
1401 switch (token) {
1402 case Opt_lookupcache_all:
1403 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1404 break;
1405 case Opt_lookupcache_positive:
1406 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1407 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1408 break;
1409 case Opt_lookupcache_none:
1410 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1411 break;
1412 default:
Trond Myklebust7973c1f12008-07-15 17:58:14 -04001413 dfprintk(MOUNT, "NFS: invalid "
1414 "lookupcache argument\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001415 return 0;
Trond Myklebust7973c1f12008-07-15 17:58:14 -04001416 };
1417 break;
Chuck Levera6d5ff62010-05-07 13:33:58 -04001418 case Opt_fscache_uniq:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001419 if (nfs_get_option_str(args, &mnt->fscache_uniq))
Chuck Levera6d5ff62010-05-07 13:33:58 -04001420 goto out_nomem;
Chuck Levera6d5ff62010-05-07 13:33:58 -04001421 mnt->options |= NFS_OPTION_FSCACHE;
1422 break;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001423 case Opt_local_lock:
1424 string = match_strdup(args);
1425 if (string == NULL)
1426 goto out_nomem;
1427 token = match_token(string, nfs_local_lock_tokens,
1428 args);
1429 kfree(string);
1430 switch (token) {
1431 case Opt_local_lock_all:
1432 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1433 NFS_MOUNT_LOCAL_FCNTL);
1434 break;
1435 case Opt_local_lock_flock:
1436 mnt->flags |= NFS_MOUNT_LOCAL_FLOCK;
1437 break;
1438 case Opt_local_lock_posix:
1439 mnt->flags |= NFS_MOUNT_LOCAL_FCNTL;
1440 break;
1441 case Opt_local_lock_none:
1442 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1443 NFS_MOUNT_LOCAL_FCNTL);
1444 break;
1445 default:
1446 dfprintk(MOUNT, "NFS: invalid "
1447 "local_lock argument\n");
1448 return 0;
1449 };
1450 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001451
Chuck Leverf45663c2008-06-24 19:28:02 -04001452 /*
1453 * Special options
1454 */
1455 case Opt_sloppy:
1456 sloppy = 1;
1457 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1458 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001459 case Opt_userspace:
1460 case Opt_deprecated:
Chuck Leverd33e4df2008-06-12 12:37:41 -04001461 dfprintk(MOUNT, "NFS: ignoring mount option "
1462 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001463 break;
1464
1465 default:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001466 invalid_option = 1;
Chuck Leverf45663c2008-06-24 19:28:02 -04001467 dfprintk(MOUNT, "NFS: unrecognized mount option "
1468 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001469 }
1470 }
1471
Chuck Leverd23c45f2009-06-17 18:02:13 -07001472 if (!sloppy && invalid_option)
1473 return 0;
1474
Jeff Laytonee671b02009-12-03 15:58:56 -05001475 /*
1476 * verify that any proto=/mountproto= options match the address
1477 * familiies in the addr=/mountaddr= options.
1478 */
1479 if (protofamily != AF_UNSPEC &&
1480 protofamily != mnt->nfs_server.address.ss_family)
1481 goto out_proto_mismatch;
1482
1483 if (mountfamily != AF_UNSPEC) {
1484 if (mnt->mount_server.addrlen) {
1485 if (mountfamily != mnt->mount_server.address.ss_family)
1486 goto out_mountproto_mismatch;
1487 } else {
1488 if (mountfamily != mnt->nfs_server.address.ss_family)
1489 goto out_mountproto_mismatch;
1490 }
1491 }
1492
Chuck Leverbf0fd762007-07-01 12:13:44 -04001493 return 1;
1494
Jeff Laytonee671b02009-12-03 15:58:56 -05001495out_mountproto_mismatch:
1496 printk(KERN_INFO "NFS: mount server address does not match mountproto= "
1497 "option\n");
1498 return 0;
1499out_proto_mismatch:
1500 printk(KERN_INFO "NFS: server address does not match proto= option\n");
1501 return 0;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001502out_invalid_address:
1503 printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
1504 return 0;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001505out_invalid_value:
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001506 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001507 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001508out_nomem:
1509 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1510 return 0;
Eric Parisf9c3a382008-03-05 14:20:18 -05001511out_security_failure:
1512 free_secdata(secdata);
1513 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1514 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001515}
1516
1517/*
Chuck Leverec88f282009-08-09 15:09:32 -04001518 * Match the requested auth flavors with the list returned by
1519 * the server. Returns zero and sets the mount's authentication
1520 * flavor on success; returns -EACCES if server does not support
1521 * the requested flavor.
1522 */
1523static int nfs_walk_authlist(struct nfs_parsed_mount_data *args,
1524 struct nfs_mount_request *request)
1525{
1526 unsigned int i, j, server_authlist_len = *(request->auth_flav_len);
1527
1528 /*
Chuck Lever5eecfde2009-08-21 17:50:30 -04001529 * Certain releases of Linux's mountd return an empty
1530 * flavor list. To prevent behavioral regression with
1531 * these servers (ie. rejecting mounts that used to
1532 * succeed), revert to pre-2.6.32 behavior (no checking)
1533 * if the returned flavor list is empty.
1534 */
1535 if (server_authlist_len == 0)
1536 return 0;
1537
1538 /*
Chuck Leverec88f282009-08-09 15:09:32 -04001539 * We avoid sophisticated negotiating here, as there are
1540 * plenty of cases where we can get it wrong, providing
1541 * either too little or too much security.
1542 *
1543 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1544 * flavor listed first. However, some servers list
1545 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1546 * preferred default, in args->auth_flavors[0] if user
1547 * didn't specify sec= mount option.
1548 */
1549 for (i = 0; i < args->auth_flavor_len; i++)
1550 for (j = 0; j < server_authlist_len; j++)
1551 if (args->auth_flavors[i] == request->auth_flavs[j]) {
1552 dfprintk(MOUNT, "NFS: using auth flavor %d\n",
1553 request->auth_flavs[j]);
1554 args->auth_flavors[0] = request->auth_flavs[j];
1555 return 0;
1556 }
1557
1558 dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n");
1559 nfs_umount(request);
1560 return -EACCES;
1561}
1562
1563/*
Chuck Lever0076d7b2007-07-01 12:13:49 -04001564 * Use the remote server's MOUNT service to request the NFS file handle
1565 * corresponding to the provided path.
1566 */
1567static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1568 struct nfs_fh *root_fh)
1569{
Chuck Leverec88f282009-08-09 15:09:32 -04001570 rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS];
1571 unsigned int server_authlist_len = ARRAY_SIZE(server_authlist);
Chuck Leverc5d120f2008-12-23 15:21:35 -05001572 struct nfs_mount_request request = {
1573 .sap = (struct sockaddr *)
1574 &args->mount_server.address,
1575 .dirpath = args->nfs_server.export_path,
1576 .protocol = args->mount_server.protocol,
1577 .fh = root_fh,
Chuck Lever50a737f2008-12-23 15:21:37 -05001578 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
Chuck Leverec88f282009-08-09 15:09:32 -04001579 .auth_flav_len = &server_authlist_len,
1580 .auth_flavs = server_authlist,
Chuck Leverc5d120f2008-12-23 15:21:35 -05001581 };
Chuck Lever4c568012007-12-10 14:59:28 -05001582 int status;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001583
1584 if (args->mount_server.version == 0) {
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001585 switch (args->version) {
1586 default:
1587 args->mount_server.version = NFS_MNT3_VERSION;
1588 break;
1589 case 2:
1590 args->mount_server.version = NFS_MNT_VERSION;
1591 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001592 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001593 request.version = args->mount_server.version;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001594
Chuck Lever33832032007-12-10 14:59:13 -05001595 if (args->mount_server.hostname)
Chuck Leverc5d120f2008-12-23 15:21:35 -05001596 request.hostname = args->mount_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001597 else
Chuck Leverc5d120f2008-12-23 15:21:35 -05001598 request.hostname = args->nfs_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001599
Chuck Lever0076d7b2007-07-01 12:13:49 -04001600 /*
1601 * Construct the mount server's address.
1602 */
Chuck Lever4c568012007-12-10 14:59:28 -05001603 if (args->mount_server.address.ss_family == AF_UNSPEC) {
Chuck Leverc5d120f2008-12-23 15:21:35 -05001604 memcpy(request.sap, &args->nfs_server.address,
Chuck Lever4c568012007-12-10 14:59:28 -05001605 args->nfs_server.addrlen);
1606 args->mount_server.addrlen = args->nfs_server.addrlen;
1607 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001608 request.salen = args->mount_server.addrlen;
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001609 nfs_set_port(request.sap, &args->mount_server.port, 0);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001610
1611 /*
1612 * Now ask the mount server to map our export path
1613 * to a file handle.
1614 */
Chuck Leverc5d120f2008-12-23 15:21:35 -05001615 status = nfs_mount(&request);
Chuck Leverec88f282009-08-09 15:09:32 -04001616 if (status != 0) {
1617 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1618 request.hostname, status);
1619 return status;
1620 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001621
Chuck Leverec88f282009-08-09 15:09:32 -04001622 /*
1623 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1624 */
1625 if (args->mount_server.version != NFS_MNT3_VERSION)
1626 return 0;
1627 return nfs_walk_authlist(args, &request);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001628}
1629
Rob Landleyc12bace2011-03-09 15:54:13 -06001630/*
1631 * Split "dev_name" into "hostname:export_path".
1632 *
1633 * The leftmost colon demarks the split between the server's hostname
1634 * and the export path. If the hostname starts with a left square
1635 * bracket, then it may contain colons.
1636 *
1637 * Note: caller frees hostname and export path, even on error.
1638 */
1639static int nfs_parse_devname(const char *dev_name,
1640 char **hostname, size_t maxnamlen,
1641 char **export_path, size_t maxpathlen)
Chuck Leverdc045892008-06-23 12:36:37 -04001642{
1643 size_t len;
Rob Landleyc12bace2011-03-09 15:54:13 -06001644 char *end;
Chuck Leverdc045892008-06-23 12:36:37 -04001645
Rob Landleyc12bace2011-03-09 15:54:13 -06001646 /* Is the host name protected with square brakcets? */
1647 if (*dev_name == '[') {
1648 end = strchr(++dev_name, ']');
1649 if (end == NULL || end[1] != ':')
1650 goto out_bad_devname;
Chuck Leverdc045892008-06-23 12:36:37 -04001651
Rob Landleyc12bace2011-03-09 15:54:13 -06001652 len = end - dev_name;
1653 end++;
1654 } else {
1655 char *comma;
1656
1657 end = strchr(dev_name, ':');
1658 if (end == NULL)
1659 goto out_bad_devname;
1660 len = end - dev_name;
1661
1662 /* kill possible hostname list: not supported */
1663 comma = strchr(dev_name, ',');
1664 if (comma != NULL && comma < end)
1665 *comma = 0;
1666 }
1667
Chuck Leverdc045892008-06-23 12:36:37 -04001668 if (len > maxnamlen)
1669 goto out_hostname;
1670
1671 /* N.B. caller will free nfs_server.hostname in all cases */
1672 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
Rob Landleyc12bace2011-03-09 15:54:13 -06001673 if (*hostname == NULL)
Chuck Leverdc045892008-06-23 12:36:37 -04001674 goto out_nomem;
Rob Landleyc12bace2011-03-09 15:54:13 -06001675 len = strlen(++end);
Chuck Leverdc045892008-06-23 12:36:37 -04001676 if (len > maxpathlen)
1677 goto out_path;
Rob Landleyc12bace2011-03-09 15:54:13 -06001678 *export_path = kstrndup(end, len, GFP_KERNEL);
Chuck Leverdc045892008-06-23 12:36:37 -04001679 if (!*export_path)
1680 goto out_nomem;
1681
1682 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1683 return 0;
1684
1685out_bad_devname:
1686 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1687 return -EINVAL;
1688
1689out_nomem:
1690 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1691 return -ENOMEM;
1692
1693out_hostname:
1694 dfprintk(MOUNT, "NFS: server hostname too long\n");
1695 return -ENAMETOOLONG;
1696
1697out_path:
1698 dfprintk(MOUNT, "NFS: export pathname too long\n");
1699 return -ENAMETOOLONG;
1700}
1701
1702/*
David Howells54ceac42006-08-22 20:06:13 -04001703 * Validate the NFS2/NFS3 mount data
1704 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001705 *
1706 * For option strings, user space handles the following behaviors:
1707 *
1708 * + DNS: mapping server host name to IP address ("addr=" option)
1709 *
1710 * + failure mode: how to behave if a mount request can't be handled
1711 * immediately ("fg/bg" option)
1712 *
1713 * + retry: how often to retry a mount request ("retry=" option)
1714 *
1715 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1716 * mountproto=tcp after mountproto=udp, and so on
David Howellsf7b422b2006-06-09 09:34:33 -04001717 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001718static int nfs_validate_mount_data(void *options,
1719 struct nfs_parsed_mount_data *args,
Chuck Lever136d5582007-07-01 12:13:54 -04001720 struct nfs_fh *mntfh,
1721 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001722{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001723 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001724 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
Chuck Lever136d5582007-07-01 12:13:54 -04001725
Chuck Lever5df36e72007-07-01 12:12:56 -04001726 if (data == NULL)
1727 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001728
David Howellsf7b422b2006-06-09 09:34:33 -04001729 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001730 case 1:
1731 data->namlen = 0;
1732 case 2:
1733 data->bsize = 0;
1734 case 3:
1735 if (data->flags & NFS_MOUNT_VER3)
1736 goto out_no_v3;
1737 data->root.size = NFS2_FHSIZE;
1738 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1739 case 4:
1740 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1741 goto out_no_sec;
1742 case 5:
1743 memset(data->context, 0, sizeof(data->context));
1744 case 6:
Trond Myklebustb7e24452008-06-19 15:21:11 -04001745 if (data->flags & NFS_MOUNT_VER3) {
1746 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1747 goto out_invalid_fh;
Chuck Lever5df36e72007-07-01 12:12:56 -04001748 mntfh->size = data->root.size;
Chuck Lever764302c2009-09-08 19:50:03 -04001749 args->version = 3;
1750 } else {
Chuck Lever5df36e72007-07-01 12:12:56 -04001751 mntfh->size = NFS2_FHSIZE;
Chuck Lever764302c2009-09-08 19:50:03 -04001752 args->version = 2;
1753 }
Chuck Lever5df36e72007-07-01 12:12:56 -04001754
Chuck Lever5df36e72007-07-01 12:12:56 -04001755
1756 memcpy(mntfh->data, data->root.data, mntfh->size);
1757 if (mntfh->size < sizeof(mntfh->data))
1758 memset(mntfh->data + mntfh->size, 0,
1759 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001760
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001761 /*
1762 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1763 * can deal with.
1764 */
Trond Myklebustff3525a2008-08-15 16:59:14 -04001765 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
Bryan Schumakerd5eff1a2010-08-03 13:04:00 -04001766 args->flags |= NFS_MOUNT_LEGACY_INTERFACE;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001767 args->rsize = data->rsize;
1768 args->wsize = data->wsize;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001769 args->timeo = data->timeo;
1770 args->retrans = data->retrans;
1771 args->acregmin = data->acregmin;
1772 args->acregmax = data->acregmax;
1773 args->acdirmin = data->acdirmin;
1774 args->acdirmax = data->acdirmax;
Chuck Lever4c568012007-12-10 14:59:28 -05001775
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001776 memcpy(sap, &data->addr, sizeof(data->addr));
Chuck Lever4c568012007-12-10 14:59:28 -05001777 args->nfs_server.addrlen = sizeof(data->addr);
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001778 if (!nfs_verify_server_address(sap))
Chuck Lever4c568012007-12-10 14:59:28 -05001779 goto out_no_address;
1780
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001781 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001782 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001783 /* N.B. caller will free nfs_server.hostname in all cases */
1784 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1785 args->namlen = data->namlen;
1786 args->bsize = data->bsize;
Chuck Leverdd07c942008-06-24 16:33:46 -04001787
1788 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1789 args->auth_flavors[0] = data->pseudoflavor;
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001790 if (!args->nfs_server.hostname)
1791 goto out_nomem;
Eric Parisf9c3a382008-03-05 14:20:18 -05001792
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001793 if (!(data->flags & NFS_MOUNT_NONLM))
1794 args->flags &= ~(NFS_MOUNT_LOCAL_FLOCK|
1795 NFS_MOUNT_LOCAL_FCNTL);
1796 else
1797 args->flags |= (NFS_MOUNT_LOCAL_FLOCK|
1798 NFS_MOUNT_LOCAL_FCNTL);
Eric Parisf9c3a382008-03-05 14:20:18 -05001799 /*
1800 * The legacy version 6 binary mount data from userspace has a
1801 * field used only to transport selinux information into the
1802 * the kernel. To continue to support that functionality we
1803 * have a touch of selinux knowledge here in the NFS code. The
1804 * userspace code converted context=blah to just blah so we are
1805 * converting back to the full string selinux understands.
1806 */
1807 if (data->context[0]){
1808#ifdef CONFIG_SECURITY_SELINUX
1809 int rc;
1810 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1811 if (!opts_str)
1812 return -ENOMEM;
1813 strcpy(opts_str, "context=");
1814 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1815 strcat(opts_str, &data->context[0]);
1816 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1817 kfree(opts_str);
1818 if (rc)
1819 return rc;
1820#else
1821 return -EINVAL;
1822#endif
1823 }
1824
Chuck Lever5df36e72007-07-01 12:12:56 -04001825 break;
Chuck Lever136d5582007-07-01 12:13:54 -04001826 default: {
Chuck Lever136d5582007-07-01 12:13:54 -04001827 int status;
Chuck Lever136d5582007-07-01 12:13:54 -04001828
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001829 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever136d5582007-07-01 12:13:54 -04001830 return -EINVAL;
1831
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001832 if (!nfs_verify_server_address(sap))
Chuck Lever6e88e062007-09-24 15:39:50 -04001833 goto out_no_address;
1834
Chuck Lever764302c2009-09-08 19:50:03 -04001835 if (args->version == 4)
1836#ifdef CONFIG_NFS_V4
1837 return nfs4_validate_text_mount_data(options,
1838 args, dev_name);
1839#else
1840 goto out_v4_not_compiled;
1841#endif
1842
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001843 nfs_set_port(sap, &args->nfs_server.port, 0);
Chuck Levered596a82008-06-26 17:47:05 -04001844
Trond Myklebust259875e2008-07-02 14:43:47 -04001845 nfs_set_mount_transport_protocol(args);
1846
Chuck Leverdc045892008-06-23 12:36:37 -04001847 status = nfs_parse_devname(dev_name,
1848 &args->nfs_server.hostname,
1849 PAGE_SIZE,
1850 &args->nfs_server.export_path,
1851 NFS_MAXPATHLEN);
1852 if (!status)
1853 status = nfs_try_mount(args, mntfh);
Chuck Lever136d5582007-07-01 12:13:54 -04001854
Chuck Leverdc045892008-06-23 12:36:37 -04001855 kfree(args->nfs_server.export_path);
1856 args->nfs_server.export_path = NULL;
Chuck Lever136d5582007-07-01 12:13:54 -04001857
Chuck Lever136d5582007-07-01 12:13:54 -04001858 if (status)
Chuck Leverfdc6e2c2007-08-29 17:58:59 -04001859 return status;
Chuck Lever136d5582007-07-01 12:13:54 -04001860
Chuck Lever136d5582007-07-01 12:13:54 -04001861 break;
1862 }
David Howellsf7b422b2006-06-09 09:34:33 -04001863 }
David Howells54ceac42006-08-22 20:06:13 -04001864
David Howellsf7b422b2006-06-09 09:34:33 -04001865#ifndef CONFIG_NFS_V3
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001866 if (args->version == 3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001867 goto out_v3_not_compiled;
1868#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001869
David Howells54ceac42006-08-22 20:06:13 -04001870 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001871
1872out_no_data:
1873 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1874 return -EINVAL;
1875
1876out_no_v3:
1877 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1878 data->version);
1879 return -EINVAL;
1880
1881out_no_sec:
1882 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1883 return -EINVAL;
1884
Chuck Lever5df36e72007-07-01 12:12:56 -04001885#ifndef CONFIG_NFS_V3
1886out_v3_not_compiled:
1887 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1888 return -EPROTONOSUPPORT;
1889#endif /* !CONFIG_NFS_V3 */
1890
Chuck Lever764302c2009-09-08 19:50:03 -04001891#ifndef CONFIG_NFS_V4
1892out_v4_not_compiled:
1893 dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n");
1894 return -EPROTONOSUPPORT;
1895#endif /* !CONFIG_NFS_V4 */
1896
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001897out_nomem:
1898 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
1899 return -ENOMEM;
1900
Chuck Lever5df36e72007-07-01 12:12:56 -04001901out_no_address:
1902 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1903 return -EINVAL;
1904
1905out_invalid_fh:
1906 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1907 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04001908}
1909
Jeff Layton48b605f2008-06-10 15:38:39 -04001910static int
1911nfs_compare_remount_data(struct nfs_server *nfss,
1912 struct nfs_parsed_mount_data *data)
1913{
1914 if (data->flags != nfss->flags ||
1915 data->rsize != nfss->rsize ||
1916 data->wsize != nfss->wsize ||
1917 data->retrans != nfss->client->cl_timeout->to_retries ||
1918 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
1919 data->acregmin != nfss->acregmin / HZ ||
1920 data->acregmax != nfss->acregmax / HZ ||
1921 data->acdirmin != nfss->acdirmin / HZ ||
1922 data->acdirmax != nfss->acdirmax / HZ ||
1923 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
Trond Myklebustbcd2ea12009-10-06 15:41:22 -04001924 data->nfs_server.port != nfss->port ||
Jeff Layton48b605f2008-06-10 15:38:39 -04001925 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
Stefan Richtera1be9ee2009-10-12 11:26:12 -04001926 !rpc_cmp_addr((struct sockaddr *)&data->nfs_server.address,
1927 (struct sockaddr *)&nfss->nfs_client->cl_addr))
Jeff Layton48b605f2008-06-10 15:38:39 -04001928 return -EINVAL;
1929
1930 return 0;
1931}
1932
1933static int
1934nfs_remount(struct super_block *sb, int *flags, char *raw_data)
1935{
1936 int error;
1937 struct nfs_server *nfss = sb->s_fs_info;
1938 struct nfs_parsed_mount_data *data;
1939 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
1940 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
Trond Myklebustcd100722008-06-17 16:12:00 -04001941 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
Jeff Layton48b605f2008-06-10 15:38:39 -04001942
1943 /*
1944 * Userspace mount programs that send binary options generally send
1945 * them populated with default values. We have no way to know which
1946 * ones were explicitly specified. Fall back to legacy behavior and
1947 * just return success.
1948 */
Marc Zyngier31c94462008-07-17 13:21:55 +02001949 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
1950 (nfsvers <= 3 && (!options || (options->version >= 1 &&
1951 options->version <= 6))))
Jeff Layton48b605f2008-06-10 15:38:39 -04001952 return 0;
1953
1954 data = kzalloc(sizeof(*data), GFP_KERNEL);
1955 if (data == NULL)
1956 return -ENOMEM;
1957
1958 /* fill out struct with values from existing mount */
1959 data->flags = nfss->flags;
1960 data->rsize = nfss->rsize;
1961 data->wsize = nfss->wsize;
1962 data->retrans = nfss->client->cl_timeout->to_retries;
1963 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
1964 data->acregmin = nfss->acregmin / HZ;
1965 data->acregmax = nfss->acregmax / HZ;
1966 data->acdirmin = nfss->acdirmin / HZ;
1967 data->acdirmax = nfss->acdirmax / HZ;
1968 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
Trond Myklebustbcd2ea12009-10-06 15:41:22 -04001969 data->nfs_server.port = nfss->port;
Jeff Layton48b605f2008-06-10 15:38:39 -04001970 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
1971 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1972 data->nfs_server.addrlen);
1973
1974 /* overwrite those values with any that were specified */
1975 error = nfs_parse_mount_options((char *)options, data);
1976 if (error < 0)
1977 goto out;
1978
1979 /* compare new mount options with old ones */
1980 error = nfs_compare_remount_data(nfss, data);
1981out:
1982 kfree(data);
1983 return error;
1984}
1985
David Howells54ceac42006-08-22 20:06:13 -04001986/*
1987 * Initialise the common bits of the superblock
1988 */
1989static inline void nfs_initialise_sb(struct super_block *sb)
1990{
1991 struct nfs_server *server = NFS_SB(sb);
1992
1993 sb->s_magic = NFS_SUPER_MAGIC;
1994
1995 /* We probably want something more informative here */
1996 snprintf(sb->s_id, sizeof(sb->s_id),
1997 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1998
1999 if (sb->s_blocksize == 0)
2000 sb->s_blocksize = nfs_block_bits(server->wsize,
2001 &sb->s_blocksize_bits);
2002
2003 if (server->flags & NFS_MOUNT_NOAC)
2004 sb->s_flags |= MS_SYNCHRONOUS;
2005
Jens Axboe32a88aa2009-09-16 15:02:33 +02002006 sb->s_bdi = &server->backing_dev_info;
2007
David Howells54ceac42006-08-22 20:06:13 -04002008 nfs_super_set_maxbytes(sb, server->maxfilesize);
2009}
2010
2011/*
2012 * Finish setting up an NFS2/3 superblock
2013 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04002014static void nfs_fill_super(struct super_block *sb,
2015 struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -04002016{
2017 struct nfs_server *server = NFS_SB(sb);
2018
2019 sb->s_blocksize_bits = 0;
2020 sb->s_blocksize = 0;
2021 if (data->bsize)
2022 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
2023
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04002024 if (server->nfs_client->rpc_ops->version == 3) {
David Howells54ceac42006-08-22 20:06:13 -04002025 /* The VFS shouldn't apply the umask to mode bits. We will do
2026 * so ourselves when necessary.
2027 */
2028 sb->s_flags |= MS_POSIXACL;
2029 sb->s_time_gran = 1;
2030 }
2031
2032 sb->s_op = &nfs_sops;
2033 nfs_initialise_sb(sb);
2034}
2035
2036/*
2037 * Finish setting up a cloned NFS2/3 superblock
2038 */
2039static void nfs_clone_super(struct super_block *sb,
2040 const struct super_block *old_sb)
2041{
2042 struct nfs_server *server = NFS_SB(sb);
2043
2044 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2045 sb->s_blocksize = old_sb->s_blocksize;
2046 sb->s_maxbytes = old_sb->s_maxbytes;
2047
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04002048 if (server->nfs_client->rpc_ops->version == 3) {
David Howells54ceac42006-08-22 20:06:13 -04002049 /* The VFS shouldn't apply the umask to mode bits. We will do
2050 * so ourselves when necessary.
2051 */
2052 sb->s_flags |= MS_POSIXACL;
2053 sb->s_time_gran = 1;
2054 }
2055
2056 sb->s_op = old_sb->s_op;
2057 nfs_initialise_sb(sb);
2058}
2059
Trond Myklebust275a5d22007-05-16 16:53:28 -04002060static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
2061{
2062 const struct nfs_server *a = s->s_fs_info;
2063 const struct rpc_clnt *clnt_a = a->client;
2064 const struct rpc_clnt *clnt_b = b->client;
2065
2066 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
2067 goto Ebusy;
2068 if (a->nfs_client != b->nfs_client)
2069 goto Ebusy;
2070 if (a->flags != b->flags)
2071 goto Ebusy;
2072 if (a->wsize != b->wsize)
2073 goto Ebusy;
2074 if (a->rsize != b->rsize)
2075 goto Ebusy;
2076 if (a->acregmin != b->acregmin)
2077 goto Ebusy;
2078 if (a->acregmax != b->acregmax)
2079 goto Ebusy;
2080 if (a->acdirmin != b->acdirmin)
2081 goto Ebusy;
2082 if (a->acdirmax != b->acdirmax)
2083 goto Ebusy;
2084 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
2085 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002086 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04002087Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002088 return 0;
2089}
2090
2091struct nfs_sb_mountdata {
2092 struct nfs_server *server;
2093 int mntflags;
2094};
2095
2096static int nfs_set_super(struct super_block *s, void *data)
2097{
2098 struct nfs_sb_mountdata *sb_mntdata = data;
2099 struct nfs_server *server = sb_mntdata->server;
2100 int ret;
2101
2102 s->s_flags = sb_mntdata->mntflags;
2103 s->s_fs_info = server;
Al Viro8b244ff2010-12-18 11:29:39 -05002104 s->s_d_op = server->nfs_client->rpc_ops->dentry_ops;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002105 ret = set_anon_super(s, server);
2106 if (ret == 0)
2107 server->s_dev = s->s_dev;
2108 return ret;
2109}
2110
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002111static int nfs_compare_super_address(struct nfs_server *server1,
2112 struct nfs_server *server2)
2113{
2114 struct sockaddr *sap1, *sap2;
2115
2116 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
2117 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
2118
2119 if (sap1->sa_family != sap2->sa_family)
2120 return 0;
2121
2122 switch (sap1->sa_family) {
2123 case AF_INET: {
2124 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
2125 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
2126 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
2127 return 0;
2128 if (sin1->sin_port != sin2->sin_port)
2129 return 0;
2130 break;
2131 }
2132 case AF_INET6: {
2133 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
2134 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
2135 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
2136 return 0;
2137 if (sin1->sin6_port != sin2->sin6_port)
2138 return 0;
2139 break;
2140 }
2141 default:
2142 return 0;
2143 }
2144
2145 return 1;
2146}
2147
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002148static int nfs_compare_super(struct super_block *sb, void *data)
2149{
2150 struct nfs_sb_mountdata *sb_mntdata = data;
2151 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2152 int mntflags = sb_mntdata->mntflags;
2153
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002154 if (!nfs_compare_super_address(old, server))
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002155 return 0;
2156 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2157 if (old->flags & NFS_MOUNT_UNSHARED)
2158 return 0;
2159 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2160 return 0;
2161 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04002162}
2163
Miklos Szeredifa799752008-04-30 00:54:33 -07002164static int nfs_bdi_register(struct nfs_server *server)
2165{
2166 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
2167}
2168
Al Viro01194982011-03-16 07:25:36 -04002169static struct dentry *nfs_fs_mount(struct file_system_type *fs_type,
2170 int flags, const char *dev_name, void *raw_data)
David Howells54ceac42006-08-22 20:06:13 -04002171{
2172 struct nfs_server *server = NULL;
2173 struct super_block *s;
Trond Myklebust33852a12008-06-19 14:20:11 -04002174 struct nfs_parsed_mount_data *data;
2175 struct nfs_fh *mntfh;
Al Viro01194982011-03-16 07:25:36 -04002176 struct dentry *mntroot = ERR_PTR(-ENOMEM);
Trond Myklebust75180df2007-05-16 16:53:28 -04002177 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002178 struct nfs_sb_mountdata sb_mntdata = {
2179 .mntflags = flags,
2180 };
Al Viro01194982011-03-16 07:25:36 -04002181 int error;
David Howells54ceac42006-08-22 20:06:13 -04002182
Paulius Zaleckas1e657bd2010-10-31 18:21:05 +02002183 data = nfs_alloc_parsed_mount_data(NFS_DEFAULT_VERSION);
Trond Myklebustb157b062010-04-19 19:05:48 -04002184 mntfh = nfs_alloc_fhandle();
Trond Myklebust33852a12008-06-19 14:20:11 -04002185 if (data == NULL || mntfh == NULL)
2186 goto out_free_fh;
2187
2188 security_init_mnt_opts(&data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002189
David Howells54ceac42006-08-22 20:06:13 -04002190 /* Validate the mount data */
Trond Myklebust33852a12008-06-19 14:20:11 -04002191 error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
Al Viro01194982011-03-16 07:25:36 -04002192 if (error < 0) {
2193 mntroot = ERR_PTR(error);
Chuck Lever06559602007-07-01 12:12:35 -04002194 goto out;
Al Viro01194982011-03-16 07:25:36 -04002195 }
David Howells54ceac42006-08-22 20:06:13 -04002196
Chuck Lever764302c2009-09-08 19:50:03 -04002197#ifdef CONFIG_NFS_V4
2198 if (data->version == 4) {
Al Viro01194982011-03-16 07:25:36 -04002199 mntroot = nfs4_try_mount(flags, dev_name, data);
Chuck Lever764302c2009-09-08 19:50:03 -04002200 kfree(data->client_address);
Xiaotian Feng9699eda2010-04-22 18:56:17 +08002201 kfree(data->nfs_server.export_path);
Chuck Lever764302c2009-09-08 19:50:03 -04002202 goto out;
2203 }
2204#endif /* CONFIG_NFS_V4 */
2205
David Howells54ceac42006-08-22 20:06:13 -04002206 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002207 server = nfs_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002208 if (IS_ERR(server)) {
Al Viro01194982011-03-16 07:25:36 -04002209 mntroot = ERR_CAST(server);
Chuck Lever06559602007-07-01 12:12:35 -04002210 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002211 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002212 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002213
Trond Myklebust75180df2007-05-16 16:53:28 -04002214 if (server->flags & NFS_MOUNT_UNSHARED)
2215 compare_super = NULL;
2216
David Howells54ceac42006-08-22 20:06:13 -04002217 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002218 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002219 if (IS_ERR(s)) {
Al Viro01194982011-03-16 07:25:36 -04002220 mntroot = ERR_CAST(s);
David Howells54ceac42006-08-22 20:06:13 -04002221 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04002222 }
2223
David Howells54ceac42006-08-22 20:06:13 -04002224 if (s->s_fs_info != server) {
2225 nfs_free_server(server);
2226 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002227 } else {
2228 error = nfs_bdi_register(server);
Al Viro01194982011-03-16 07:25:36 -04002229 if (error) {
2230 mntroot = ERR_PTR(error);
NeilBrowncfbc0682010-03-11 11:20:17 +11002231 goto error_splat_bdi;
Al Viro01194982011-03-16 07:25:36 -04002232 }
David Howellsf7b422b2006-06-09 09:34:33 -04002233 }
David Howells54ceac42006-08-22 20:06:13 -04002234
2235 if (!s->s_root) {
2236 /* initial superblock/root creation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002237 nfs_fill_super(s, data);
Jesper Juhl160bc162011-04-10 17:57:07 +02002238 nfs_fscache_get_super_cookie(s, data->fscache_uniq, NULL);
David Howells54ceac42006-08-22 20:06:13 -04002239 }
2240
Al Viro0d5839a2011-03-16 05:27:27 -04002241 mntroot = nfs_get_root(s, mntfh, dev_name);
Al Viro01194982011-03-16 07:25:36 -04002242 if (IS_ERR(mntroot))
David Howells54ceac42006-08-22 20:06:13 -04002243 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002244
Trond Myklebust33852a12008-06-19 14:20:11 -04002245 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002246 if (error)
2247 goto error_splat_root;
2248
David Howellsf7b422b2006-06-09 09:34:33 -04002249 s->s_flags |= MS_ACTIVE;
Chuck Lever06559602007-07-01 12:12:35 -04002250
2251out:
Trond Myklebust33852a12008-06-19 14:20:11 -04002252 kfree(data->nfs_server.hostname);
2253 kfree(data->mount_server.hostname);
David Howells08734042009-04-03 16:42:42 +01002254 kfree(data->fscache_uniq);
Trond Myklebust33852a12008-06-19 14:20:11 -04002255 security_free_mnt_opts(&data->lsm_opts);
2256out_free_fh:
Trond Myklebustb157b062010-04-19 19:05:48 -04002257 nfs_free_fhandle(mntfh);
Trond Myklebust33852a12008-06-19 14:20:11 -04002258 kfree(data);
Al Viro01194982011-03-16 07:25:36 -04002259 return mntroot;
Trond Myklebust816724e2006-06-24 08:41:41 -04002260
David Howells54ceac42006-08-22 20:06:13 -04002261out_err_nosb:
2262 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04002263 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002264
Eric Parisf9c3a382008-03-05 14:20:18 -05002265error_splat_root:
2266 dput(mntroot);
Al Viro01194982011-03-16 07:25:36 -04002267 mntroot = ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04002268error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002269 if (server && !s->s_root)
2270 bdi_unregister(&server->backing_dev_info);
2271error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002272 deactivate_locked_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04002273 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002274}
2275
David Howells54ceac42006-08-22 20:06:13 -04002276/*
Trond Myklebust387c1492010-02-03 08:27:35 -05002277 * Ensure that we unregister the bdi before kill_anon_super
2278 * releases the device name
2279 */
2280static void nfs_put_super(struct super_block *s)
2281{
2282 struct nfs_server *server = NFS_SB(s);
2283
2284 bdi_unregister(&server->backing_dev_info);
2285}
2286
2287/*
David Howells54ceac42006-08-22 20:06:13 -04002288 * Destroy an NFS2/3 superblock
2289 */
David Howellsf7b422b2006-06-09 09:34:33 -04002290static void nfs_kill_super(struct super_block *s)
2291{
2292 struct nfs_server *server = NFS_SB(s);
2293
2294 kill_anon_super(s);
David Howells08734042009-04-03 16:42:42 +01002295 nfs_fscache_release_super_cookie(s);
David Howells54ceac42006-08-22 20:06:13 -04002296 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04002297}
2298
David Howells54ceac42006-08-22 20:06:13 -04002299/*
2300 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2301 */
Al Viro31f43472010-10-29 03:38:12 -04002302static struct dentry *
2303nfs_xdev_mount(struct file_system_type *fs_type, int flags,
2304 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002305{
2306 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002307 struct super_block *s;
2308 struct nfs_server *server;
2309 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002310 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002311 struct nfs_sb_mountdata sb_mntdata = {
2312 .mntflags = flags,
2313 };
David Howells54ceac42006-08-22 20:06:13 -04002314 int error;
2315
Al Viro31f43472010-10-29 03:38:12 -04002316 dprintk("--> nfs_xdev_mount()\n");
David Howells54ceac42006-08-22 20:06:13 -04002317
2318 /* create a new volume representation */
2319 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2320 if (IS_ERR(server)) {
2321 error = PTR_ERR(server);
2322 goto out_err_noserver;
2323 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002324 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002325
Trond Myklebust75180df2007-05-16 16:53:28 -04002326 if (server->flags & NFS_MOUNT_UNSHARED)
2327 compare_super = NULL;
2328
David Howells54ceac42006-08-22 20:06:13 -04002329 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002330 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002331 if (IS_ERR(s)) {
2332 error = PTR_ERR(s);
2333 goto out_err_nosb;
2334 }
2335
2336 if (s->s_fs_info != server) {
2337 nfs_free_server(server);
2338 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002339 } else {
2340 error = nfs_bdi_register(server);
2341 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11002342 goto error_splat_bdi;
David Howells54ceac42006-08-22 20:06:13 -04002343 }
2344
2345 if (!s->s_root) {
2346 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002347 nfs_clone_super(s, data->sb);
David Howells2df54802009-09-23 14:36:39 -04002348 nfs_fscache_get_super_cookie(s, NULL, data);
David Howells54ceac42006-08-22 20:06:13 -04002349 }
2350
Al Viro0d5839a2011-03-16 05:27:27 -04002351 mntroot = nfs_get_root(s, data->fh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04002352 if (IS_ERR(mntroot)) {
2353 error = PTR_ERR(mntroot);
2354 goto error_splat_super;
2355 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002356 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
Neil Brown4c1fe2f2007-11-01 16:50:20 +11002357 dput(mntroot);
2358 error = -ESTALE;
2359 goto error_splat_super;
2360 }
David Howells54ceac42006-08-22 20:06:13 -04002361
2362 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002363
Eric Parisf9c3a382008-03-05 14:20:18 -05002364 /* clone any lsm security options from the parent to the new sb */
2365 security_sb_clone_mnt_opts(data->sb, s);
2366
Al Viro31f43472010-10-29 03:38:12 -04002367 dprintk("<-- nfs_xdev_mount() = 0\n");
2368 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04002369
2370out_err_nosb:
2371 nfs_free_server(server);
2372out_err_noserver:
Al Viro31f43472010-10-29 03:38:12 -04002373 dprintk("<-- nfs_xdev_mount() = %d [error]\n", error);
2374 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04002375
2376error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002377 if (server && !s->s_root)
2378 bdi_unregister(&server->backing_dev_info);
2379error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002380 deactivate_locked_super(s);
Al Viro31f43472010-10-29 03:38:12 -04002381 dprintk("<-- nfs_xdev_mount() = %d [splat]\n", error);
2382 return ERR_PTR(error);
David Howellsf7b422b2006-06-09 09:34:33 -04002383}
2384
2385#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04002386
2387/*
2388 * Finish setting up a cloned NFS4 superblock
2389 */
2390static void nfs4_clone_super(struct super_block *sb,
2391 const struct super_block *old_sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002392{
David Howells54ceac42006-08-22 20:06:13 -04002393 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2394 sb->s_blocksize = old_sb->s_blocksize;
2395 sb->s_maxbytes = old_sb->s_maxbytes;
2396 sb->s_time_gran = 1;
2397 sb->s_op = old_sb->s_op;
Aneesh Kumar K.Va8a5da92010-12-09 11:35:14 +00002398 /*
2399 * The VFS shouldn't apply the umask to mode bits. We will do
2400 * so ourselves when necessary.
2401 */
2402 sb->s_flags |= MS_POSIXACL;
Aneesh Kumar K.V64c2ce82010-12-09 11:35:25 +00002403 sb->s_xattr = old_sb->s_xattr;
2404 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002405}
2406
2407/*
2408 * Set up an NFS4 superblock
2409 */
David Howells54ceac42006-08-22 20:06:13 -04002410static void nfs4_fill_super(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002411{
David Howellsf7b422b2006-06-09 09:34:33 -04002412 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04002413 sb->s_op = &nfs4_sops;
Aneesh Kumar K.Va8a5da92010-12-09 11:35:14 +00002414 /*
2415 * The VFS shouldn't apply the umask to mode bits. We will do
2416 * so ourselves when necessary.
2417 */
2418 sb->s_flags |= MS_POSIXACL;
Aneesh Kumar K.V64c2ce82010-12-09 11:35:25 +00002419 sb->s_xattr = nfs4_xattr_handlers;
David Howells54ceac42006-08-22 20:06:13 -04002420 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002421}
2422
Trond Myklebust01c3f052009-06-17 13:22:58 -07002423static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2424{
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04002425 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3|
2426 NFS_MOUNT_LOCAL_FLOCK|NFS_MOUNT_LOCAL_FCNTL);
Trond Myklebust01c3f052009-06-17 13:22:58 -07002427}
2428
Chuck Lever7630c852009-09-08 19:49:57 -04002429static int nfs4_validate_text_mount_data(void *options,
2430 struct nfs_parsed_mount_data *args,
2431 const char *dev_name)
2432{
2433 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2434
Trond Myklebustf5855fe2009-10-06 15:40:37 -04002435 nfs_set_port(sap, &args->nfs_server.port, NFS_PORT);
Chuck Lever7630c852009-09-08 19:49:57 -04002436
2437 nfs_validate_transport_protocol(args);
2438
2439 nfs4_validate_mount_flags(args);
2440
Trond Myklebust2ecda722009-09-08 19:50:07 -04002441 if (args->version != 4) {
2442 dfprintk(MOUNT,
2443 "NFS4: Illegal mount version\n");
2444 return -EINVAL;
2445 }
2446
Chuck Lever7630c852009-09-08 19:49:57 -04002447 if (args->auth_flavor_len > 1) {
2448 dfprintk(MOUNT,
2449 "NFS4: Too many RPC auth flavours specified\n");
2450 return -EINVAL;
2451 }
2452
2453 if (args->client_address == NULL) {
2454 dfprintk(MOUNT,
2455 "NFS4: mount program didn't pass callback address\n");
2456 return -EINVAL;
2457 }
2458
2459 return nfs_parse_devname(dev_name,
2460 &args->nfs_server.hostname,
2461 NFS4_MAXNAMLEN,
2462 &args->nfs_server.export_path,
2463 NFS4_MAXPATHLEN);
2464}
2465
David Howells54ceac42006-08-22 20:06:13 -04002466/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04002467 * Validate NFSv4 mount options
2468 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002469static int nfs4_validate_mount_data(void *options,
2470 struct nfs_parsed_mount_data *args,
2471 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04002472{
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002473 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002474 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002475 char *c;
2476
2477 if (data == NULL)
2478 goto out_no_data;
2479
2480 switch (data->version) {
2481 case 1:
Chuck Lever4c568012007-12-10 14:59:28 -05002482 if (data->host_addrlen > sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002483 goto out_no_address;
Chuck Lever4c568012007-12-10 14:59:28 -05002484 if (data->host_addrlen == 0)
2485 goto out_no_address;
2486 args->nfs_server.addrlen = data->host_addrlen;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002487 if (copy_from_user(sap, data->host_addr, data->host_addrlen))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002488 return -EFAULT;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002489 if (!nfs_verify_server_address(sap))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002490 goto out_no_address;
2491
Chuck Lever6738b252008-06-24 16:33:54 -04002492 if (data->auth_flavourlen) {
2493 if (data->auth_flavourlen > 1)
2494 goto out_inval_auth;
Trond Myklebust20c71f52007-09-20 20:23:51 -04002495 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002496 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04002497 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002498 return -EFAULT;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002499 }
2500
2501 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2502 if (IS_ERR(c))
2503 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002504 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002505
2506 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2507 if (IS_ERR(c))
2508 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002509 args->nfs_server.export_path = c;
2510 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002511
2512 c = strndup_user(data->client_addr.data, 16);
2513 if (IS_ERR(c))
2514 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002515 args->client_address = c;
2516
2517 /*
2518 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2519 * can deal with.
2520 */
2521
2522 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2523 args->rsize = data->rsize;
2524 args->wsize = data->wsize;
2525 args->timeo = data->timeo;
2526 args->retrans = data->retrans;
2527 args->acregmin = data->acregmin;
2528 args->acregmax = data->acregmax;
2529 args->acdirmin = data->acdirmin;
2530 args->acdirmax = data->acdirmax;
2531 args->nfs_server.protocol = data->proto;
Trond Myklebust259875e2008-07-02 14:43:47 -04002532 nfs_validate_transport_protocol(args);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002533
2534 break;
Chuck Lever7630c852009-09-08 19:49:57 -04002535 default:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002536 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever80071222007-07-01 12:13:59 -04002537 return -EINVAL;
2538
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002539 if (!nfs_verify_server_address(sap))
Chuck Lever80071222007-07-01 12:13:59 -04002540 return -EINVAL;
Chuck Levered596a82008-06-26 17:47:05 -04002541
Chuck Lever7630c852009-09-08 19:49:57 -04002542 return nfs4_validate_text_mount_data(options, args, dev_name);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002543 }
2544
2545 return 0;
2546
2547out_no_data:
2548 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2549 return -EINVAL;
2550
2551out_inval_auth:
2552 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2553 data->auth_flavourlen);
2554 return -EINVAL;
2555
2556out_no_address:
2557 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2558 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002559}
2560
2561/*
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002562 * Get the superblock for the NFS4 root partition
David Howells54ceac42006-08-22 20:06:13 -04002563 */
Al Viro31f43472010-10-29 03:38:12 -04002564static struct dentry *
2565nfs4_remote_mount(struct file_system_type *fs_type, int flags,
2566 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002567{
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002568 struct nfs_parsed_mount_data *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002569 struct super_block *s;
2570 struct nfs_server *server;
Trond Myklebust33852a12008-06-19 14:20:11 -04002571 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04002572 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002573 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002574 struct nfs_sb_mountdata sb_mntdata = {
2575 .mntflags = flags,
2576 };
Trond Myklebust33852a12008-06-19 14:20:11 -04002577 int error = -ENOMEM;
David Howellsf7b422b2006-06-09 09:34:33 -04002578
Trond Myklebustb157b062010-04-19 19:05:48 -04002579 mntfh = nfs_alloc_fhandle();
Trond Myklebust33852a12008-06-19 14:20:11 -04002580 if (data == NULL || mntfh == NULL)
2581 goto out_free_fh;
2582
2583 security_init_mnt_opts(&data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002584
David Howells54ceac42006-08-22 20:06:13 -04002585 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002586 server = nfs4_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002587 if (IS_ERR(server)) {
2588 error = PTR_ERR(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04002589 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002590 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002591 sb_mntdata.server = server;
David Howellsf7b422b2006-06-09 09:34:33 -04002592
Trond Myklebust75180df2007-05-16 16:53:28 -04002593 if (server->flags & NFS4_MOUNT_UNSHARED)
2594 compare_super = NULL;
2595
David Howells54ceac42006-08-22 20:06:13 -04002596 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002597 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002598 if (IS_ERR(s)) {
2599 error = PTR_ERR(s);
David Howellsf7b422b2006-06-09 09:34:33 -04002600 goto out_free;
Trond Myklebust816724e2006-06-24 08:41:41 -04002601 }
2602
Trond Myklebust5dd31772006-08-24 01:03:05 -04002603 if (s->s_fs_info != server) {
2604 nfs_free_server(server);
2605 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002606 } else {
2607 error = nfs_bdi_register(server);
2608 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11002609 goto error_splat_bdi;
Trond Myklebust5dd31772006-08-24 01:03:05 -04002610 }
2611
David Howells54ceac42006-08-22 20:06:13 -04002612 if (!s->s_root) {
2613 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002614 nfs4_fill_super(s);
David Howells2df54802009-09-23 14:36:39 -04002615 nfs_fscache_get_super_cookie(
2616 s, data ? data->fscache_uniq : NULL, NULL);
Trond Myklebust816724e2006-06-24 08:41:41 -04002617 }
David Howellsf7b422b2006-06-09 09:34:33 -04002618
Al Viro0d5839a2011-03-16 05:27:27 -04002619 mntroot = nfs4_get_root(s, mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04002620 if (IS_ERR(mntroot)) {
2621 error = PTR_ERR(mntroot);
2622 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04002623 }
David Howells54ceac42006-08-22 20:06:13 -04002624
Trond Myklebust33852a12008-06-19 14:20:11 -04002625 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Paris46c8ac72008-05-02 13:42:42 -07002626 if (error)
2627 goto error_splat_root;
2628
David Howellsf7b422b2006-06-09 09:34:33 -04002629 s->s_flags |= MS_ACTIVE;
Al Viro31f43472010-10-29 03:38:12 -04002630
2631 security_free_mnt_opts(&data->lsm_opts);
2632 nfs_free_fhandle(mntfh);
2633 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04002634
Chuck Lever29eb9812007-07-01 12:12:30 -04002635out:
Trond Myklebust33852a12008-06-19 14:20:11 -04002636 security_free_mnt_opts(&data->lsm_opts);
2637out_free_fh:
Trond Myklebustb157b062010-04-19 19:05:48 -04002638 nfs_free_fhandle(mntfh);
Al Viro31f43472010-10-29 03:38:12 -04002639 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04002640
Chuck Lever29eb9812007-07-01 12:12:30 -04002641out_free:
2642 nfs_free_server(server);
2643 goto out;
2644
Eric Paris46c8ac72008-05-02 13:42:42 -07002645error_splat_root:
2646 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04002647error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002648 if (server && !s->s_root)
2649 bdi_unregister(&server->backing_dev_info);
2650error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002651 deactivate_locked_super(s);
Chuck Lever29eb9812007-07-01 12:12:30 -04002652 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002653}
2654
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002655static struct vfsmount *nfs_do_root_mount(struct file_system_type *fs_type,
2656 int flags, void *data, const char *hostname)
2657{
2658 struct vfsmount *root_mnt;
2659 char *root_devname;
2660 size_t len;
2661
2662 len = strlen(hostname) + 3;
2663 root_devname = kmalloc(len, GFP_KERNEL);
2664 if (root_devname == NULL)
2665 return ERR_PTR(-ENOMEM);
2666 snprintf(root_devname, len, "%s:/", hostname);
2667 root_mnt = vfs_kern_mount(fs_type, flags, root_devname, data);
2668 kfree(root_devname);
2669 return root_mnt;
2670}
2671
Trond Myklebustce587e02010-04-16 16:22:52 -04002672struct nfs_referral_count {
2673 struct list_head list;
2674 const struct task_struct *task;
2675 unsigned int referral_count;
2676};
2677
2678static LIST_HEAD(nfs_referral_count_list);
2679static DEFINE_SPINLOCK(nfs_referral_count_list_lock);
2680
2681static struct nfs_referral_count *nfs_find_referral_count(void)
2682{
2683 struct nfs_referral_count *p;
2684
2685 list_for_each_entry(p, &nfs_referral_count_list, list) {
2686 if (p->task == current)
2687 return p;
2688 }
2689 return NULL;
2690}
2691
2692#define NFS_MAX_NESTED_REFERRALS 2
2693
2694static int nfs_referral_loop_protect(void)
2695{
2696 struct nfs_referral_count *p, *new;
2697 int ret = -ENOMEM;
2698
2699 new = kmalloc(sizeof(*new), GFP_KERNEL);
2700 if (!new)
2701 goto out;
2702 new->task = current;
2703 new->referral_count = 1;
2704
2705 ret = 0;
2706 spin_lock(&nfs_referral_count_list_lock);
2707 p = nfs_find_referral_count();
2708 if (p != NULL) {
2709 if (p->referral_count >= NFS_MAX_NESTED_REFERRALS)
2710 ret = -ELOOP;
2711 else
2712 p->referral_count++;
2713 } else {
2714 list_add(&new->list, &nfs_referral_count_list);
2715 new = NULL;
2716 }
2717 spin_unlock(&nfs_referral_count_list_lock);
2718 kfree(new);
2719out:
2720 return ret;
2721}
2722
2723static void nfs_referral_loop_unprotect(void)
2724{
2725 struct nfs_referral_count *p;
2726
2727 spin_lock(&nfs_referral_count_list_lock);
2728 p = nfs_find_referral_count();
2729 p->referral_count--;
2730 if (p->referral_count == 0)
2731 list_del(&p->list);
2732 else
2733 p = NULL;
2734 spin_unlock(&nfs_referral_count_list_lock);
2735 kfree(p);
2736}
2737
Al Viro01194982011-03-16 07:25:36 -04002738static struct dentry *nfs_follow_remote_path(struct vfsmount *root_mnt,
2739 const char *export_path)
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002740{
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002741 struct nameidata *nd = NULL;
Linus Torvaldsa2770d82009-12-17 12:51:05 -08002742 struct mnt_namespace *ns_private;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002743 struct super_block *s;
Al Viro01194982011-03-16 07:25:36 -04002744 struct dentry *dentry;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002745 int ret;
2746
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002747 nd = kmalloc(sizeof(*nd), GFP_KERNEL);
2748 if (nd == NULL)
Al Viro01194982011-03-16 07:25:36 -04002749 return ERR_PTR(-ENOMEM);
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002750
Linus Torvaldsa2770d82009-12-17 12:51:05 -08002751 ns_private = create_mnt_ns(root_mnt);
2752 ret = PTR_ERR(ns_private);
2753 if (IS_ERR(ns_private))
2754 goto out_mntput;
2755
Trond Myklebustce587e02010-04-16 16:22:52 -04002756 ret = nfs_referral_loop_protect();
2757 if (ret != 0)
2758 goto out_put_mnt_ns;
2759
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002760 ret = vfs_path_lookup(root_mnt->mnt_root, root_mnt,
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002761 export_path, LOOKUP_FOLLOW, nd);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002762
Trond Myklebustce587e02010-04-16 16:22:52 -04002763 nfs_referral_loop_unprotect();
Linus Torvaldsa2770d82009-12-17 12:51:05 -08002764 put_mnt_ns(ns_private);
2765
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002766 if (ret != 0)
2767 goto out_err;
2768
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002769 s = nd->path.mnt->mnt_sb;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002770 atomic_inc(&s->s_active);
Al Viro01194982011-03-16 07:25:36 -04002771 dentry = dget(nd->path.dentry);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002772
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002773 path_put(&nd->path);
2774 kfree(nd);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002775 down_write(&s->s_umount);
Al Viro01194982011-03-16 07:25:36 -04002776 return dentry;
Trond Myklebustce587e02010-04-16 16:22:52 -04002777out_put_mnt_ns:
2778 put_mnt_ns(ns_private);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002779out_mntput:
2780 mntput(root_mnt);
2781out_err:
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002782 kfree(nd);
Al Viro01194982011-03-16 07:25:36 -04002783 return ERR_PTR(ret);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002784}
2785
Al Viro01194982011-03-16 07:25:36 -04002786static struct dentry *nfs4_try_mount(int flags, const char *dev_name,
2787 struct nfs_parsed_mount_data *data)
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002788{
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002789 char *export_path;
2790 struct vfsmount *root_mnt;
Al Viro01194982011-03-16 07:25:36 -04002791 struct dentry *res;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002792
Chuck Levera6fe23b2009-09-08 19:50:00 -04002793 dfprintk(MOUNT, "--> nfs4_try_mount()\n");
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002794
2795 export_path = data->nfs_server.export_path;
2796 data->nfs_server.export_path = "/";
2797 root_mnt = nfs_do_root_mount(&nfs4_remote_fs_type, flags, data,
2798 data->nfs_server.hostname);
2799 data->nfs_server.export_path = export_path;
2800
Al Viro01194982011-03-16 07:25:36 -04002801 res = ERR_CAST(root_mnt);
2802 if (!IS_ERR(root_mnt))
2803 res = nfs_follow_remote_path(root_mnt, export_path);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002804
Al Viro01194982011-03-16 07:25:36 -04002805 dfprintk(MOUNT, "<-- nfs4_try_mount() = %ld%s\n",
2806 IS_ERR(res) ? PTR_ERR(res) : 0,
2807 IS_ERR(res) ? " [error]" : "");
2808 return res;
Chuck Levera6fe23b2009-09-08 19:50:00 -04002809}
2810
2811/*
2812 * Get the superblock for an NFS4 mountpoint
2813 */
Al Viro01194982011-03-16 07:25:36 -04002814static struct dentry *nfs4_mount(struct file_system_type *fs_type,
2815 int flags, const char *dev_name, void *raw_data)
Chuck Levera6fe23b2009-09-08 19:50:00 -04002816{
2817 struct nfs_parsed_mount_data *data;
2818 int error = -ENOMEM;
Al Viro01194982011-03-16 07:25:36 -04002819 struct dentry *res = ERR_PTR(-ENOMEM);
Chuck Levera6fe23b2009-09-08 19:50:00 -04002820
Trond Myklebustc5811db2009-10-06 15:40:15 -04002821 data = nfs_alloc_parsed_mount_data(4);
Chuck Levera6fe23b2009-09-08 19:50:00 -04002822 if (data == NULL)
2823 goto out_free_data;
2824
2825 /* Validate the mount data */
2826 error = nfs4_validate_mount_data(raw_data, data, dev_name);
Al Viro01194982011-03-16 07:25:36 -04002827 if (error < 0) {
2828 res = ERR_PTR(error);
Chuck Levera6fe23b2009-09-08 19:50:00 -04002829 goto out;
Al Viro01194982011-03-16 07:25:36 -04002830 }
Chuck Levera6fe23b2009-09-08 19:50:00 -04002831
Al Viro01194982011-03-16 07:25:36 -04002832 res = nfs4_try_mount(flags, dev_name, data);
2833 if (IS_ERR(res))
2834 error = PTR_ERR(res);
Chuck Levera6fe23b2009-09-08 19:50:00 -04002835
2836out:
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002837 kfree(data->client_address);
2838 kfree(data->nfs_server.export_path);
2839 kfree(data->nfs_server.hostname);
2840 kfree(data->fscache_uniq);
2841out_free_data:
2842 kfree(data);
Al Viro01194982011-03-16 07:25:36 -04002843 dprintk("<-- nfs4_mount() = %d%s\n", error,
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002844 error != 0 ? " [error]" : "");
Al Viro01194982011-03-16 07:25:36 -04002845 return res;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002846}
2847
David Howellsf7b422b2006-06-09 09:34:33 -04002848static void nfs4_kill_super(struct super_block *sb)
2849{
2850 struct nfs_server *server = NFS_SB(sb);
2851
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002852 dprintk("--> %s\n", __func__);
Trond Myklebust515d8612008-12-23 15:21:46 -05002853 nfs_super_return_all_delegations(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002854 kill_anon_super(sb);
David Howells08734042009-04-03 16:42:42 +01002855 nfs_fscache_release_super_cookie(sb);
David Howells54ceac42006-08-22 20:06:13 -04002856 nfs_free_server(server);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002857 dprintk("<-- %s\n", __func__);
David Howellsf7b422b2006-06-09 09:34:33 -04002858}
2859
2860/*
David Howells54ceac42006-08-22 20:06:13 -04002861 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -04002862 */
Al Viro31f43472010-10-29 03:38:12 -04002863static struct dentry *
2864nfs4_xdev_mount(struct file_system_type *fs_type, int flags,
2865 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002866{
2867 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002868 struct super_block *s;
2869 struct nfs_server *server;
2870 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002871 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002872 struct nfs_sb_mountdata sb_mntdata = {
2873 .mntflags = flags,
2874 };
David Howells54ceac42006-08-22 20:06:13 -04002875 int error;
2876
Al Viro31f43472010-10-29 03:38:12 -04002877 dprintk("--> nfs4_xdev_mount()\n");
David Howells54ceac42006-08-22 20:06:13 -04002878
2879 /* create a new volume representation */
2880 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2881 if (IS_ERR(server)) {
2882 error = PTR_ERR(server);
2883 goto out_err_noserver;
2884 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002885 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002886
Trond Myklebust75180df2007-05-16 16:53:28 -04002887 if (server->flags & NFS4_MOUNT_UNSHARED)
2888 compare_super = NULL;
2889
David Howells54ceac42006-08-22 20:06:13 -04002890 /* Get a superblock - note that we may end up sharing one that already exists */
Andy Adamsonec9a05c2008-10-17 10:44:37 -04002891 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002892 if (IS_ERR(s)) {
2893 error = PTR_ERR(s);
2894 goto out_err_nosb;
2895 }
2896
2897 if (s->s_fs_info != server) {
2898 nfs_free_server(server);
2899 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002900 } else {
2901 error = nfs_bdi_register(server);
2902 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11002903 goto error_splat_bdi;
David Howells54ceac42006-08-22 20:06:13 -04002904 }
2905
2906 if (!s->s_root) {
2907 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002908 nfs4_clone_super(s, data->sb);
David Howells2df54802009-09-23 14:36:39 -04002909 nfs_fscache_get_super_cookie(s, NULL, data);
David Howells54ceac42006-08-22 20:06:13 -04002910 }
2911
Al Viro0d5839a2011-03-16 05:27:27 -04002912 mntroot = nfs4_get_root(s, data->fh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04002913 if (IS_ERR(mntroot)) {
2914 error = PTR_ERR(mntroot);
2915 goto error_splat_super;
2916 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002917 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2918 dput(mntroot);
2919 error = -ESTALE;
2920 goto error_splat_super;
2921 }
David Howells54ceac42006-08-22 20:06:13 -04002922
2923 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002924
Eric Paris46c8ac72008-05-02 13:42:42 -07002925 security_sb_clone_mnt_opts(data->sb, s);
2926
Al Viro31f43472010-10-29 03:38:12 -04002927 dprintk("<-- nfs4_xdev_mount() = 0\n");
2928 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04002929
2930out_err_nosb:
2931 nfs_free_server(server);
2932out_err_noserver:
Al Viro31f43472010-10-29 03:38:12 -04002933 dprintk("<-- nfs4_xdev_mount() = %d [error]\n", error);
2934 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04002935
2936error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002937 if (server && !s->s_root)
2938 bdi_unregister(&server->backing_dev_info);
2939error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002940 deactivate_locked_super(s);
Al Viro31f43472010-10-29 03:38:12 -04002941 dprintk("<-- nfs4_xdev_mount() = %d [splat]\n", error);
2942 return ERR_PTR(error);
David Howellsf7b422b2006-06-09 09:34:33 -04002943}
2944
Al Viro31f43472010-10-29 03:38:12 -04002945static struct dentry *
2946nfs4_remote_referral_mount(struct file_system_type *fs_type, int flags,
2947 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002948{
2949 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002950 struct super_block *s;
2951 struct nfs_server *server;
2952 struct dentry *mntroot;
Trond Myklebust4f727292010-04-16 16:22:48 -04002953 struct nfs_fh *mntfh;
Trond Myklebust75180df2007-05-16 16:53:28 -04002954 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002955 struct nfs_sb_mountdata sb_mntdata = {
2956 .mntflags = flags,
2957 };
Trond Myklebust4f727292010-04-16 16:22:48 -04002958 int error = -ENOMEM;
David Howells54ceac42006-08-22 20:06:13 -04002959
2960 dprintk("--> nfs4_referral_get_sb()\n");
2961
Trond Myklebust4f727292010-04-16 16:22:48 -04002962 mntfh = nfs_alloc_fhandle();
2963 if (mntfh == NULL)
2964 goto out_err_nofh;
2965
David Howells54ceac42006-08-22 20:06:13 -04002966 /* create a new volume representation */
Trond Myklebust4f727292010-04-16 16:22:48 -04002967 server = nfs4_create_referral_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002968 if (IS_ERR(server)) {
2969 error = PTR_ERR(server);
2970 goto out_err_noserver;
2971 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002972 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002973
Trond Myklebust75180df2007-05-16 16:53:28 -04002974 if (server->flags & NFS4_MOUNT_UNSHARED)
2975 compare_super = NULL;
2976
David Howells54ceac42006-08-22 20:06:13 -04002977 /* Get a superblock - note that we may end up sharing one that already exists */
Andy Adamsonec9a05c2008-10-17 10:44:37 -04002978 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002979 if (IS_ERR(s)) {
2980 error = PTR_ERR(s);
2981 goto out_err_nosb;
2982 }
2983
2984 if (s->s_fs_info != server) {
2985 nfs_free_server(server);
2986 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002987 } else {
2988 error = nfs_bdi_register(server);
2989 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11002990 goto error_splat_bdi;
David Howells54ceac42006-08-22 20:06:13 -04002991 }
2992
2993 if (!s->s_root) {
2994 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002995 nfs4_fill_super(s);
David Howells2df54802009-09-23 14:36:39 -04002996 nfs_fscache_get_super_cookie(s, NULL, data);
David Howells54ceac42006-08-22 20:06:13 -04002997 }
2998
Al Viro0d5839a2011-03-16 05:27:27 -04002999 mntroot = nfs4_get_root(s, mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04003000 if (IS_ERR(mntroot)) {
3001 error = PTR_ERR(mntroot);
3002 goto error_splat_super;
3003 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05003004 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
3005 dput(mntroot);
3006 error = -ESTALE;
3007 goto error_splat_super;
3008 }
David Howells54ceac42006-08-22 20:06:13 -04003009
3010 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04003011
Eric Paris46c8ac72008-05-02 13:42:42 -07003012 security_sb_clone_mnt_opts(data->sb, s);
3013
Trond Myklebust4f727292010-04-16 16:22:48 -04003014 nfs_free_fhandle(mntfh);
David Howells54ceac42006-08-22 20:06:13 -04003015 dprintk("<-- nfs4_referral_get_sb() = 0\n");
Al Viro31f43472010-10-29 03:38:12 -04003016 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04003017
3018out_err_nosb:
3019 nfs_free_server(server);
3020out_err_noserver:
Trond Myklebust4f727292010-04-16 16:22:48 -04003021 nfs_free_fhandle(mntfh);
3022out_err_nofh:
David Howells54ceac42006-08-22 20:06:13 -04003023 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
Al Viro31f43472010-10-29 03:38:12 -04003024 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04003025
3026error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11003027 if (server && !s->s_root)
3028 bdi_unregister(&server->backing_dev_info);
3029error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04003030 deactivate_locked_super(s);
Trond Myklebust4f727292010-04-16 16:22:48 -04003031 nfs_free_fhandle(mntfh);
David Howells54ceac42006-08-22 20:06:13 -04003032 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
Al Viro31f43472010-10-29 03:38:12 -04003033 return ERR_PTR(error);
David Howellsf7b422b2006-06-09 09:34:33 -04003034}
3035
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04003036/*
3037 * Create an NFS4 server record on referral traversal
3038 */
Al Viro01194982011-03-16 07:25:36 -04003039static struct dentry *nfs4_referral_mount(struct file_system_type *fs_type,
3040 int flags, const char *dev_name, void *raw_data)
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04003041{
3042 struct nfs_clone_mount *data = raw_data;
3043 char *export_path;
3044 struct vfsmount *root_mnt;
Al Viro01194982011-03-16 07:25:36 -04003045 struct dentry *res;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04003046
Al Viro01194982011-03-16 07:25:36 -04003047 dprintk("--> nfs4_referral_mount()\n");
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04003048
3049 export_path = data->mnt_path;
3050 data->mnt_path = "/";
3051
3052 root_mnt = nfs_do_root_mount(&nfs4_remote_referral_fs_type,
3053 flags, data, data->hostname);
3054 data->mnt_path = export_path;
3055
Al Viro01194982011-03-16 07:25:36 -04003056 res = ERR_CAST(root_mnt);
3057 if (!IS_ERR(root_mnt))
3058 res = nfs_follow_remote_path(root_mnt, export_path);
3059 dprintk("<-- nfs4_referral_mount() = %ld%s\n",
3060 IS_ERR(res) ? PTR_ERR(res) : 0,
3061 IS_ERR(res) ? " [error]" : "");
3062 return res;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04003063}
3064
David Howells54ceac42006-08-22 20:06:13 -04003065#endif /* CONFIG_NFS_V4 */